1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-02-02 15:09:23 -05:00

[colors] Added _node for 88 colors

Now 88 and 256 colors have inefficient check in add_chars256.
This commit is contained in:
Witold Filipczyk 2022-03-20 13:43:58 +01:00
parent ed4175a4a7
commit b2ea78617e
3 changed files with 86 additions and 3 deletions

View File

@ -29,11 +29,13 @@ struct bfu_color_entry {
unsigned int was_mono:1;
unsigned int was_color16:1;
unsigned int was_color88:1;
unsigned int was_color256:1;
unsigned int was_color24:1;
struct screen_char mono;
struct screen_char c16;
struct screen_char c88;
struct screen_char c256;
struct screen_char c24;
};
@ -81,6 +83,32 @@ get_bfu_foreground_color16_node(unsigned int node_number)
return &entry->c16.c.color[0];
}
unsigned char
get_bfu_background_color88_node(unsigned int node_number)
{
struct bfu_color_entry *entry = node_entries[node_number];
if (!entry->was_color88) {
set_term_color(&entry->c88, &entry->colors, 0, COLOR_MODE_88);
entry->was_color88 = 1;
}
return TERM_COLOR_BACKGROUND_256(entry->c88.c.color);
}
unsigned char
get_bfu_foreground_color88_node(unsigned int node_number)
{
struct bfu_color_entry *entry = node_entries[node_number];
if (!entry->was_color88) {
set_term_color(&entry->c88, &entry->colors, 0, COLOR_MODE_88);
entry->was_color88 = 1;
}
return TERM_COLOR_FOREGROUND_256(entry->c88.c.color);
}
unsigned char
get_bfu_background_color256_node(unsigned int node_number)
{
@ -107,7 +135,6 @@ get_bfu_foreground_color256_node(unsigned int node_number)
return TERM_COLOR_FOREGROUND_256(entry->c256.c.color);
}
unsigned char *
get_bfu_background_color_true_node(unsigned int node_number)
{

View File

@ -31,6 +31,8 @@ unsigned int get_bfu_color_node(struct terminal *term, const char *stylename);
struct screen_char *get_bfu_mono_node(unsigned int node_number);
unsigned char *get_bfu_background_color16_node(unsigned int node_number);
unsigned char *get_bfu_foreground_color16_node(unsigned int node_number);
unsigned char get_bfu_background_color88_node(unsigned int node_number);
unsigned char get_bfu_foreground_color88_node(unsigned int node_number);
unsigned char get_bfu_background_color256_node(unsigned int node_number);
unsigned char get_bfu_foreground_color256_node(unsigned int node_number);
unsigned char *get_bfu_background_color_true_node(unsigned int node_number);

View File

@ -1100,6 +1100,31 @@ get_foreground_color_from_node(struct screen_char *ch)
return ch->c.color[0];
}
static unsigned char
get_background_color88_from_node(struct screen_char *ch)
{
unsigned int node_number = ch->c.node_number;
if (node_number < 1024) {
return get_bfu_background_color88_node(node_number);
}
return ch->c.color[1];
}
static unsigned char
get_foreground_color88_from_node(struct screen_char *ch)
{
unsigned int node_number = ch->c.node_number;
if (node_number < 1024) {
return get_bfu_foreground_color88_node(node_number);
}
return ch->c.color[0];
}
static struct screen_char *
get_mono_from_node(struct screen_char *ch)
{
@ -1162,6 +1187,27 @@ add_foreground_color(struct string *str, const struct string *seq, struct screen
}
}
static inline void
add_background_color88(struct string *str, const struct string *seq, struct screen_char *ch)
{
if (ch->is_node) {
add_char_color(str, &(seq)[1], get_background_color88_from_node(ch));
} else {
add_char_color(str, &(seq)[1], ch->c.color[1]);
}
}
static inline void
add_foreground_color88(struct string *str, const struct string *seq, struct screen_char *ch)
{
if (ch->is_node) {
add_char_color(str, (&seq)[0], get_foreground_color88_from_node(ch));
} else {
add_char_color(str, &(seq)[0], ch->c.color[0]);
}
}
#if 0
#define add_background_color(str, seq, chr) add_char_color(str, &(seq)[1], (chr)->c.color[1])
#define add_foreground_color(str, seq, chr) add_char_color(str, &(seq)[0], (chr)->c.color[0])
@ -1253,9 +1299,17 @@ add_char256(struct string *screen, struct screen_driver *driver,
} else
#endif
{
add_foreground_color(screen, driver->opt.color256_seqs, ch);
if (driver->opt.color_mode == COLOR_MODE_88) {
add_foreground_color88(screen, driver->opt.color256_seqs, ch);
} else {
add_foreground_color(screen, driver->opt.color256_seqs, ch);
}
if (!driver->opt.transparent || ch->c.color[1] != 0) {
add_background_color(screen, driver->opt.color256_seqs, ch);
if (driver->opt.color_mode == COLOR_MODE_88) {
add_background_color88(screen, driver->opt.color256_seqs, ch);
} else {
add_background_color(screen, driver->opt.color256_seqs, ch);
}
}
if (ch->attr & SCREEN_ATTR_BOLD)