aboutsummaryrefslogtreecommitdiff
path: root/host/color.c
diff options
context:
space:
mode:
authorjaseg <jaseg@jaseg.net>2014-01-03 13:19:44 +0100
committerjaseg <jaseg@jaseg.net>2014-01-03 13:19:44 +0100
commit9ef5c135e894b2da95940e2556f4df9ce2205552 (patch)
tree3e6538ec4ac69caa9f4db16dad36265fcf5637eb /host/color.c
parent3fd92ee838b39de097ce2b03ebdd37659708e157 (diff)
downloadmatelight-9ef5c135e894b2da95940e2556f4df9ce2205552.tar.gz
matelight-9ef5c135e894b2da95940e2556f4df9ce2205552.tar.bz2
matelight-9ef5c135e894b2da95940e2556f4df9ce2205552.zip
Re-organized the host software directory layout
Diffstat (limited to 'host/color.c')
-rw-r--r--host/color.c296
1 files changed, 296 insertions, 0 deletions
diff --git a/host/color.c b/host/color.c
new file mode 100644
index 0000000..e0be99f
--- /dev/null
+++ b/host/color.c
@@ -0,0 +1,296 @@
+
+#include "color.h"
+#include <stdlib.h>
+#include <stdio.h>
+
+/* Bonus points for time wasted on C golf for improving the efficiency of this part */
+int xterm_color_index(color_t c){
+ int candidate = 0;
+ int best_distance = 0x7fffffff;
+ for(int i=0; i<256; i++){
+ color_t k = colortable[i];
+ int tmp = abs(c.r - k.r);
+ tmp *= tmp;
+ int distance = tmp;
+ if(distance > best_distance)
+ continue;
+ tmp = abs(c.g - k.g);
+ tmp *= tmp;
+ distance += tmp;
+ if(distance > best_distance)
+ continue;
+ tmp = abs(c.b - k.b);
+ tmp *= tmp;
+ distance += tmp;
+ if(distance > best_distance)
+ continue;
+ best_distance = distance;
+ candidate = i;
+ }
+ return candidate;
+}
+
+/* Generated by genpal.py */
+color_t colortable[256] = {
+ /* 16 default ANSI colors */
+ {0x00, 0x00, 0x00},
+ {0xa8, 0x00, 0x00},
+ {0x00, 0xa8, 0x00},
+ {0xa8, 0x54, 0x00},
+ {0x00, 0x00, 0xa8},
+ {0xa8, 0x00, 0xa8},
+ {0x00, 0xa8, 0xa8},
+ {0xa8, 0xa8, 0xa8},
+ {0x54, 0x54, 0x54},
+ {0xfc, 0x54, 0x54},
+ {0x54, 0xfc, 0x54},
+ {0xfc, 0xfc, 0x54},
+ {0x54, 0x54, 0xfc},
+ {0xfc, 0x54, 0xfc},
+ {0x54, 0xfc, 0xfc},
+ {0xfc, 0xfc, 0xfc},
+ /* 6x6x6 color cube */
+ {0x00, 0x00, 0x00},
+ {0x00, 0x00, 0x5f},
+ {0x00, 0x00, 0x87},
+ {0x00, 0x00, 0xaf},
+ {0x00, 0x00, 0xd7},
+ {0x00, 0x00, 0xff},
+ {0x00, 0x5f, 0x00},
+ {0x00, 0x5f, 0x5f},
+ {0x00, 0x5f, 0x87},
+ {0x00, 0x5f, 0xaf},
+ {0x00, 0x5f, 0xd7},
+ {0x00, 0x5f, 0xff},
+ {0x00, 0x87, 0x00},
+ {0x00, 0x87, 0x5f},
+ {0x00, 0x87, 0x87},
+ {0x00, 0x87, 0xaf},
+ {0x00, 0x87, 0xd7},
+ {0x00, 0x87, 0xff},
+ {0x00, 0xaf, 0x00},
+ {0x00, 0xaf, 0x5f},
+ {0x00, 0xaf, 0x87},
+ {0x00, 0xaf, 0xaf},
+ {0x00, 0xaf, 0xd7},
+ {0x00, 0xaf, 0xff},
+ {0x00, 0xd7, 0x00},
+ {0x00, 0xd7, 0x5f},
+ {0x00, 0xd7, 0x87},
+ {0x00, 0xd7, 0xaf},
+ {0x00, 0xd7, 0xd7},
+ {0x00, 0xd7, 0xff},
+ {0x00, 0xff, 0x00},
+ {0x00, 0xff, 0x5f},
+ {0x00, 0xff, 0x87},
+ {0x00, 0xff, 0xaf},
+ {0x00, 0xff, 0xd7},
+ {0x00, 0xff, 0xff},
+ {0x5f, 0x00, 0x00},
+ {0x5f, 0x00, 0x5f},
+ {0x5f, 0x00, 0x87},
+ {0x5f, 0x00, 0xaf},
+ {0x5f, 0x00, 0xd7},
+ {0x5f, 0x00, 0xff},
+ {0x5f, 0x5f, 0x00},
+ {0x5f, 0x5f, 0x5f},
+ {0x5f, 0x5f, 0x87},
+ {0x5f, 0x5f, 0xaf},
+ {0x5f, 0x5f, 0xd7},
+ {0x5f, 0x5f, 0xff},
+ {0x5f, 0x87, 0x00},
+ {0x5f, 0x87, 0x5f},
+ {0x5f, 0x87, 0x87},
+ {0x5f, 0x87, 0xaf},
+ {0x5f, 0x87, 0xd7},
+ {0x5f, 0x87, 0xff},
+ {0x5f, 0xaf, 0x00},
+ {0x5f, 0xaf, 0x5f},
+ {0x5f, 0xaf, 0x87},
+ {0x5f, 0xaf, 0xaf},
+ {0x5f, 0xaf, 0xd7},
+ {0x5f, 0xaf, 0xff},
+ {0x5f, 0xd7, 0x00},
+ {0x5f, 0xd7, 0x5f},
+ {0x5f, 0xd7, 0x87},
+ {0x5f, 0xd7, 0xaf},
+ {0x5f, 0xd7, 0xd7},
+ {0x5f, 0xd7, 0xff},
+ {0x5f, 0xff, 0x00},
+ {0x5f, 0xff, 0x5f},
+ {0x5f, 0xff, 0x87},
+ {0x5f, 0xff, 0xaf},
+ {0x5f, 0xff, 0xd7},
+ {0x5f, 0xff, 0xff},
+ {0x87, 0x00, 0x00},
+ {0x87, 0x00, 0x5f},
+ {0x87, 0x00, 0x87},
+ {0x87, 0x00, 0xaf},
+ {0x87, 0x00, 0xd7},
+ {0x87, 0x00, 0xff},
+ {0x87, 0x5f, 0x00},
+ {0x87, 0x5f, 0x5f},
+ {0x87, 0x5f, 0x87},
+ {0x87, 0x5f, 0xaf},
+ {0x87, 0x5f, 0xd7},
+ {0x87, 0x5f, 0xff},
+ {0x87, 0x87, 0x00},
+ {0x87, 0x87, 0x5f},
+ {0x87, 0x87, 0x87},
+ {0x87, 0x87, 0xaf},
+ {0x87, 0x87, 0xd7},
+ {0x87, 0x87, 0xff},
+ {0x87, 0xaf, 0x00},
+ {0x87, 0xaf, 0x5f},
+ {0x87, 0xaf, 0x87},
+ {0x87, 0xaf, 0xaf},
+ {0x87, 0xaf, 0xd7},
+ {0x87, 0xaf, 0xff},
+ {0x87, 0xd7, 0x00},
+ {0x87, 0xd7, 0x5f},
+ {0x87, 0xd7, 0x87},
+ {0x87, 0xd7, 0xaf},
+ {0x87, 0xd7, 0xd7},
+ {0x87, 0xd7, 0xff},
+ {0x87, 0xff, 0x00},
+ {0x87, 0xff, 0x5f},
+ {0x87, 0xff, 0x87},
+ {0x87, 0xff, 0xaf},
+ {0x87, 0xff, 0xd7},
+ {0x87, 0xff, 0xff},
+ {0xaf, 0x00, 0x00},
+ {0xaf, 0x00, 0x5f},
+ {0xaf, 0x00, 0x87},
+ {0xaf, 0x00, 0xaf},
+ {0xaf, 0x00, 0xd7},
+ {0xaf, 0x00, 0xff},
+ {0xaf, 0x5f, 0x00},
+ {0xaf, 0x5f, 0x5f},
+ {0xaf, 0x5f, 0x87},
+ {0xaf, 0x5f, 0xaf},
+ {0xaf, 0x5f, 0xd7},
+ {0xaf, 0x5f, 0xff},
+ {0xaf, 0x87, 0x00},
+ {0xaf, 0x87, 0x5f},
+ {0xaf, 0x87, 0x87},
+ {0xaf, 0x87, 0xaf},
+ {0xaf, 0x87, 0xd7},
+ {0xaf, 0x87, 0xff},
+ {0xaf, 0xaf, 0x00},
+ {0xaf, 0xaf, 0x5f},
+ {0xaf, 0xaf, 0x87},
+ {0xaf, 0xaf, 0xaf},
+ {0xaf, 0xaf, 0xd7},
+ {0xaf, 0xaf, 0xff},
+ {0xaf, 0xd7, 0x00},
+ {0xaf, 0xd7, 0x5f},
+ {0xaf, 0xd7, 0x87},
+ {0xaf, 0xd7, 0xaf},
+ {0xaf, 0xd7, 0xd7},
+ {0xaf, 0xd7, 0xff},
+ {0xaf, 0xff, 0x00},
+ {0xaf, 0xff, 0x5f},
+ {0xaf, 0xff, 0x87},
+ {0xaf, 0xff, 0xaf},
+ {0xaf, 0xff, 0xd7},
+ {0xaf, 0xff, 0xff},
+ {0xd7, 0x00, 0x00},
+ {0xd7, 0x00, 0x5f},
+ {0xd7, 0x00, 0x87},
+ {0xd7, 0x00, 0xaf},
+ {0xd7, 0x00, 0xd7},
+ {0xd7, 0x00, 0xff},
+ {0xd7, 0x5f, 0x00},
+ {0xd7, 0x5f, 0x5f},
+ {0xd7, 0x5f, 0x87},
+ {0xd7, 0x5f, 0xaf},
+ {0xd7, 0x5f, 0xd7},
+ {0xd7, 0x5f, 0xff},
+ {0xd7, 0x87, 0x00},
+ {0xd7, 0x87, 0x5f},
+ {0xd7, 0x87, 0x87},
+ {0xd7, 0x87, 0xaf},
+ {0xd7, 0x87, 0xd7},
+ {0xd7, 0x87, 0xff},
+ {0xd7, 0xaf, 0x00},
+ {0xd7, 0xaf, 0x5f},
+ {0xd7, 0xaf, 0x87},
+ {0xd7, 0xaf, 0xaf},
+ {0xd7, 0xaf, 0xd7},
+ {0xd7, 0xaf, 0xff},
+ {0xd7, 0xd7, 0x00},
+ {0xd7, 0xd7, 0x5f},
+ {0xd7, 0xd7, 0x87},
+ {0xd7, 0xd7, 0xaf},
+ {0xd7, 0xd7, 0xd7},
+ {0xd7, 0xd7, 0xff},
+ {0xd7, 0xff, 0x00},
+ {0xd7, 0xff, 0x5f},
+ {0xd7, 0xff, 0x87},
+ {0xd7, 0xff, 0xaf},
+ {0xd7, 0xff, 0xd7},
+ {0xd7, 0xff, 0xff},
+ {0xff, 0x00, 0x00},
+ {0xff, 0x00, 0x5f},
+ {0xff, 0x00, 0x87},
+ {0xff, 0x00, 0xaf},
+ {0xff, 0x00, 0xd7},
+ {0xff, 0x00, 0xff},
+ {0xff, 0x5f, 0x00},
+ {0xff, 0x5f, 0x5f},
+ {0xff, 0x5f, 0x87},
+ {0xff, 0x5f, 0xaf},
+ {0xff, 0x5f, 0xd7},
+ {0xff, 0x5f, 0xff},
+ {0xff, 0x87, 0x00},
+ {0xff, 0x87, 0x5f},
+ {0xff, 0x87, 0x87},
+ {0xff, 0x87, 0xaf},
+ {0xff, 0x87, 0xd7},
+ {0xff, 0x87, 0xff},
+ {0xff, 0xaf, 0x00},
+ {0xff, 0xaf, 0x5f},
+ {0xff, 0xaf, 0x87},
+ {0xff, 0xaf, 0xaf},
+ {0xff, 0xaf, 0xd7},
+ {0xff, 0xaf, 0xff},
+ {0xff, 0xd7, 0x00},
+ {0xff, 0xd7, 0x5f},
+ {0xff, 0xd7, 0x87},
+ {0xff, 0xd7, 0xaf},
+ {0xff, 0xd7, 0xd7},
+ {0xff, 0xd7, 0xff},
+ {0xff, 0xff, 0x00},
+ {0xff, 0xff, 0x5f},
+ {0xff, 0xff, 0x87},
+ {0xff, 0xff, 0xaf},
+ {0xff, 0xff, 0xd7},
+ {0xff, 0xff, 0xff},
+ /* 24-Grayscale slide */
+ {0x00, 0x00, 0x00},
+ {0x12, 0x12, 0x12},
+ {0x1c, 0x1c, 0x1c},
+ {0x26, 0x26, 0x26},
+ {0x30, 0x30, 0x30},
+ {0x3a, 0x3a, 0x3a},
+ {0x44, 0x44, 0x44},
+ {0x4e, 0x4e, 0x4e},
+ {0x58, 0x58, 0x58},
+ {0x62, 0x62, 0x62},
+ {0x6c, 0x6c, 0x6c},
+ {0x76, 0x76, 0x76},
+ {0x80, 0x80, 0x80},
+ {0x8a, 0x8a, 0x8a},
+ {0x94, 0x94, 0x94},
+ {0x9e, 0x9e, 0x9e},
+ {0xa8, 0xa8, 0xa8},
+ {0xb2, 0xb2, 0xb2},
+ {0xbc, 0xbc, 0xbc},
+ {0xc6, 0xc6, 0xc6},
+ {0xd0, 0xd0, 0xd0},
+ {0xda, 0xda, 0xda},
+ {0xe4, 0xe4, 0xe4},
+ {0xee, 0xee, 0xee}
+};
+
+