diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-07-27 01:18:32 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-07-27 01:29:44 +0200 |
commit | a912b3f28cd1c3df86bb4af74b839a275a7dc7d9 (patch) | |
tree | 4b52fae87f5ecab70de275a7b66d8d51e2586e37 /degesch.c | |
parent | 27cd8b3a63485df4994b311281669c94e0f43a37 (diff) | |
download | xK-a912b3f28cd1c3df86bb4af74b839a275a7dc7d9.tar.gz xK-a912b3f28cd1c3df86bb4af74b839a275a7dc7d9.tar.xz xK-a912b3f28cd1c3df86bb4af74b839a275a7dc7d9.zip |
degesch: use hopefully better colors for nicks
- exclude white from the 16-color range
- use colors from the 256-color cube when available
Diffstat (limited to 'degesch.c')
-rw-r--r-- | degesch.c | 37 |
1 files changed, 32 insertions, 5 deletions
@@ -2438,18 +2438,45 @@ formatter_parse_mirc (struct formatter *self, const char *s) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +static int * +filter_color_cube_for_acceptable_nick_colors (size_t *len) +{ + static int table[6 * 6 * 6]; + size_t len_counter = 0; + for (int x = 0; x < 6 * 6 * 6; x++) + { + int r = x / 36; + int g = (x / 6) % 6; + int b = (x % 6); + + // Use the luma value of colours within the cube to filter colours that + // look okay-ish on terminals with both black and white backgrounds + double luma = 0.2126 * r / 6. + 0.7152 * g / 6. + 0.0722 * b / 6.; + if (luma >= .3 && luma <= .5) + table[len_counter++] = 16 + x; + } + *len = len_counter; + return table; +} + static void formatter_parse_nick (struct formatter *self, char *s) { char *nick = irc_cut_nickname (s); - int color = siphash_wrapper (nick, strlen (nick)) % 8; + int color = siphash_wrapper (nick, strlen (nick)) % 7; - // We always use the default color for ourselves - if (self->s && irc_is_this_us (self->s, nick)) + // Never use the black colour, could become transparent on black terminals; + // white is similarly excluded from the range + if (color == COLOR_BLACK) color = -1; - // Never use the black colour, could become transparent on black terminals - if (color == COLOR_BLACK) + size_t len; + // TODO: precompute this table + int *colors = filter_color_cube_for_acceptable_nick_colors (&len); + color |= colors[siphash_wrapper (nick, strlen (nick)) % len] << 16; + + // We always use the default color for ourselves + if (self->s && irc_is_this_us (self->s, nick)) color = -1; FORMATTER_ADD_ITEM (self, FG_COLOR, .color = color); |