diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-11-17 17:52:21 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-11-17 17:52:21 +0000 |
| commit | 7554895674ce3cf9385359f85ab4527d8fd48b70 (patch) | |
| tree | ad4d3cb9827597e0b1567b5cf7b3d82118c4c745 /render.c | |
| parent | hsl: add our own implementations of rgb-to-hsl and hsl-to-rgb (diff) | |
| parent | render: dim/brighten: multiply/divide instead of add/subtract (diff) | |
Merge branch 'dim-and-brighten-via-hsl'
Diffstat (limited to 'render.c')
| -rw-r--r-- | render.c | 57 |
1 files changed, 30 insertions, 27 deletions
@@ -18,6 +18,7 @@ #include "log.h" #include "config.h" #include "grid.h" +#include "hsl.h" #include "quirks.h" #include "selection.h" #include "sixel.h" @@ -231,20 +232,20 @@ color_hex_to_pixman(uint32_t color) return color_hex_to_pixman_with_alpha(color, 0xffff); } -static inline void -color_dim(pixman_color_t *color) +static inline uint32_t +color_dim(uint32_t color) { - color->red /= 2; - color->green /= 2; - color->blue /= 2; + int hue, sat, lum; + rgb_to_hsl(color, &hue, &sat, &lum); + return hsl_to_rgb(hue, sat, lum / 1.5); } -static inline void -color_brighten(pixman_color_t *color) +static inline uint32_t +color_brighten(uint32_t color) { - color->red = color->red * 2 <= 0xffff ? color->red * 2 : 0xffff; - color->green = color->green * 2 <= 0xffff ? color->green * 2 : 0xffff; - color->blue = color->blue * 2 <= 0xffff ? color->blue * 2 : 0xffff; + int hue, sat, lum; + rgb_to_hsl(color, &hue, &sat, &lum); + return hsl_to_rgb(hue, sat, min(100, lum * 1.3)); } static inline void @@ -407,20 +408,20 @@ render_cell(struct terminal *term, pixman_image_t *pix, } } + if (cell->attrs.dim) + _fg = color_dim(_fg); + if (term->conf->bold_in_bright && cell->attrs.bold) + _fg = color_brighten(_fg); + + if (cell->attrs.blink && term->blink.state == BLINK_OFF) + _fg = color_dim(_fg); + pixman_color_t fg = color_hex_to_pixman(_fg); pixman_color_t bg = color_hex_to_pixman_with_alpha( _bg, (_bg == (term->reverse ? term->colors.fg : term->colors.bg) ? term->colors.alpha : 0xffff)); - if (cell->attrs.dim) - color_dim(&fg); - if (term->conf->bold_in_bright && cell->attrs.bold) - color_brighten(&fg); - - if (cell->attrs.blink && term->blink.state == BLINK_OFF) - color_dim(&fg); - if (term->is_searching && !is_selected) { color_dim_for_search(&fg); color_dim_for_search(&bg); @@ -556,10 +557,11 @@ static void render_urgency(struct terminal *term, struct buffer *buf) { uint32_t red = term->colors.table[1]; + if (term->is_searching) + red = color_dim(red); + pixman_color_t bg = color_hex_to_pixman(red); - if (term->is_searching) - color_dim(&bg); int width = min(min(term->margins.left, term->margins.right), min(term->margins.top, term->margins.bottom)); @@ -591,15 +593,14 @@ render_margin(struct terminal *term, struct buffer *buf, const int line_count = end_line - start_line; uint32_t _bg = !term->reverse ? term->colors.bg : term->colors.fg; + if (term->is_searching) + _bg = color_dim(_bg); pixman_color_t bg = color_hex_to_pixman_with_alpha( _bg, (_bg == (term->reverse ? term->colors.fg : term->colors.bg) ? term->colors.alpha : 0xffff)); - if (term->is_searching) - color_dim(&bg); - pixman_image_fill_rectangles( PIXMAN_OP_SRC, buf->pix[0], &bg, 4, (pixman_rectangle16_t[]){ @@ -1177,9 +1178,10 @@ render_csd_title(struct terminal *term) alpha = _color >> 24 | (_color >> 24 << 8); } - pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha); if (!term->visual_focus) - color_dim(&color); + _color = color_dim(_color); + + pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha); render_csd_part(term, surf, buf, info.width, info.height, &color); csd_commit(term, surf, buf); } @@ -1412,9 +1414,10 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx) alpha = 0; } - pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha); if (!term->visual_focus) - color_dim(&color); + _color = color_dim(_color); + + pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha); render_csd_part(term, surf, buf, info.width, info.height, &color); switch (surf_idx) { |
