1 /* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */ 2 3 #ifndef __VT_COLOR_H__ 4 #define __VT_COLOR_H__ 5 6 #include <pobl/bl_types.h> 7 8 #define MAX_VTSYS_COLORS 16 9 #define MAX_BASIC_VTSYS_COLORS 8 10 #define MAX_256_COLORS 240 11 #define MAX_EXT_COLORS 240 12 #define MAX_256EXT_COLORS (MAX_256_COLORS + MAX_EXT_COLORS) 13 14 /* same as 0 <= color <= 0x7 */ 15 #define IS_VTSYS_BASE_COLOR(color) ((unsigned int)(color) <= 0x7) 16 /* same as 0 <= color <= 0xf */ 17 #define IS_VTSYS_COLOR(color) ((unsigned int)(color) <= 0xf) 18 #define IS_256_COLOR(color) (0x10 <= (color) && (color) <= 0xff) 19 #define IS_VTSYS256_COLOR(color) ((unsigned int)(color) <= 0xff) 20 #define IS_EXT_COLOR(color) (0x100 <= (color) && (color) <= 0x1ef) 21 #define IS_256EXT_COLOR(color) (0x10 <= (color) && (color) <= 0x1ef) 22 #define IS_VALID_COLOR_EXCEPT_SPECIAL_COLORS(color) ((unsigned int)(color) <= 0x1ef) 23 #define IS_FG_BG_COLOR(color) (0x1f0 <= (color) && (color) <= 0x1f1) 24 #define IS_ALT_COLOR(color) (0x1f2 <= (color)) 25 #define EXT_COLOR_TO_INDEX(color) ((color) - MAX_VTSYS_COLORS - MAX_256_COLORS) 26 #define INDEX_TO_EXT_COLOR(color) ((color) + MAX_VTSYS_COLORS + MAX_256_COLORS) 27 #define COLOR_DISTANCE(diff_r, diff_g, diff_b) \ 28 ((diff_r) * (diff_r)*9 + (diff_g) * (diff_g)*30 + (diff_b) * (diff_b)) 29 /* no one may notice the difference (4[2^3/2]*4*9+4*4*30+4*4) */ 30 #define COLOR_DISTANCE_THRESHOLD 640 31 32 /* XXX If these members are changed, modify init() in MLTerm.java. */ 33 typedef enum vt_color { 34 VT_UNKNOWN_COLOR = -1, 35 36 /* 37 * Don't change this order, which vt_parser.c(change_char_attr etc) and 38 * x_color_cache.c etc depend on. 39 */ 40 VT_BLACK = 0x0, 41 VT_RED = 0x1, 42 VT_GREEN = 0x2, 43 VT_YELLOW = 0x3, 44 VT_BLUE = 0x4, 45 VT_MAGENTA = 0x5, 46 VT_CYAN = 0x6, 47 VT_WHITE = 0x7, 48 49 VT_BOLD_COLOR_MASK = 0x8, 50 51 /* 52 * 0x8 - 0xf: bold vt colors. 53 */ 54 55 /* 56 * 0x10 - 0xff: 240 colors. 57 */ 58 59 /* 60 * 0x100 - 0x1ef: 241-480 colors. 61 */ 62 63 VT_FG_COLOR = 0x1f0, 64 VT_BG_COLOR = 0x1f1, 65 66 VT_BOLD_COLOR = 0x1f2, 67 VT_UNDERLINE_COLOR = 0x1f3, 68 VT_BLINKING_COLOR = 0x1f4, 69 VT_REVERSE_COLOR = 0x1f5, 70 VT_ITALIC_COLOR = 0x1f6, 71 VT_CROSSED_OUT_COLOR = 0x1f7, 72 73 } vt_color_t; 74 75 void vt_set_color_mode(const char *mode); 76 77 char *vt_get_color_mode(void); 78 79 void vt_color_config_init(void); 80 81 void vt_color_config_final(void); 82 83 int vt_customize_color_file(char *color, char *rgb, int save); 84 85 char *vt_get_color_name(vt_color_t color); 86 87 vt_color_t vt_get_color(const char *name); 88 89 int vt_get_color_rgba(vt_color_t color, u_int8_t *red, u_int8_t *green, u_int8_t *blue, 90 u_int8_t *alpha); 91 92 int vt_color_parse_rgb_name(u_int8_t *red, u_int8_t *green, u_int8_t *blue, u_int8_t *alpha, 93 const char *name); 94 95 void vt_color_force_linear_search(int flag); 96 97 u_int vt_get_closest_256_color(vt_color_t *closest, u_int *min_diff, u_int8_t red, u_int8_t green, 98 u_int8_t blue, int threshold); 99 100 vt_color_t vt_get_closest_color(u_int8_t red, u_int8_t green, u_int8_t blue); 101 102 int vt_ext_color_is_changed(vt_color_t color); 103 104 #endif 105