Merge branch 'dim-and-brighten-via-hsl'

This commit is contained in:
Daniel Eklöf 2020-11-17 18:52:21 +01:00
commit 7554895674
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -18,6 +18,7 @@
#include "log.h" #include "log.h"
#include "config.h" #include "config.h"
#include "grid.h" #include "grid.h"
#include "hsl.h"
#include "quirks.h" #include "quirks.h"
#include "selection.h" #include "selection.h"
#include "sixel.h" #include "sixel.h"
@ -231,20 +232,20 @@ color_hex_to_pixman(uint32_t color)
return color_hex_to_pixman_with_alpha(color, 0xffff); return color_hex_to_pixman_with_alpha(color, 0xffff);
} }
static inline void static inline uint32_t
color_dim(pixman_color_t *color) color_dim(uint32_t color)
{ {
color->red /= 2; int hue, sat, lum;
color->green /= 2; rgb_to_hsl(color, &hue, &sat, &lum);
color->blue /= 2; return hsl_to_rgb(hue, sat, lum / 1.5);
} }
static inline void static inline uint32_t
color_brighten(pixman_color_t *color) color_brighten(uint32_t color)
{ {
color->red = color->red * 2 <= 0xffff ? color->red * 2 : 0xffff; int hue, sat, lum;
color->green = color->green * 2 <= 0xffff ? color->green * 2 : 0xffff; rgb_to_hsl(color, &hue, &sat, &lum);
color->blue = color->blue * 2 <= 0xffff ? color->blue * 2 : 0xffff; return hsl_to_rgb(hue, sat, min(100, lum * 1.3));
} }
static inline void 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 fg = color_hex_to_pixman(_fg);
pixman_color_t bg = color_hex_to_pixman_with_alpha( pixman_color_t bg = color_hex_to_pixman_with_alpha(
_bg, _bg,
(_bg == (term->reverse ? term->colors.fg : term->colors.bg) (_bg == (term->reverse ? term->colors.fg : term->colors.bg)
? term->colors.alpha : 0xffff)); ? 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) { if (term->is_searching && !is_selected) {
color_dim_for_search(&fg); color_dim_for_search(&fg);
color_dim_for_search(&bg); color_dim_for_search(&bg);
@ -556,10 +557,11 @@ static void
render_urgency(struct terminal *term, struct buffer *buf) render_urgency(struct terminal *term, struct buffer *buf)
{ {
uint32_t red = term->colors.table[1]; uint32_t red = term->colors.table[1];
if (term->is_searching)
red = color_dim(red);
pixman_color_t bg = color_hex_to_pixman(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), int width = min(min(term->margins.left, term->margins.right),
min(term->margins.top, term->margins.bottom)); 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; const int line_count = end_line - start_line;
uint32_t _bg = !term->reverse ? term->colors.bg : term->colors.fg; 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( pixman_color_t bg = color_hex_to_pixman_with_alpha(
_bg, _bg,
(_bg == (term->reverse ? term->colors.fg : term->colors.bg) (_bg == (term->reverse ? term->colors.fg : term->colors.bg)
? term->colors.alpha : 0xffff)); ? term->colors.alpha : 0xffff));
if (term->is_searching)
color_dim(&bg);
pixman_image_fill_rectangles( pixman_image_fill_rectangles(
PIXMAN_OP_SRC, buf->pix[0], &bg, 4, PIXMAN_OP_SRC, buf->pix[0], &bg, 4,
(pixman_rectangle16_t[]){ (pixman_rectangle16_t[]){
@ -1177,9 +1178,10 @@ render_csd_title(struct terminal *term)
alpha = _color >> 24 | (_color >> 24 << 8); alpha = _color >> 24 | (_color >> 24 << 8);
} }
pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha);
if (!term->visual_focus) 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); render_csd_part(term, surf, buf, info.width, info.height, &color);
csd_commit(term, surf, buf); csd_commit(term, surf, buf);
} }
@ -1412,9 +1414,10 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx)
alpha = 0; alpha = 0;
} }
pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha);
if (!term->visual_focus) 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); render_csd_part(term, surf, buf, info.width, info.height, &color);
switch (surf_idx) { switch (surf_idx) {