mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-18 05:34:02 -04:00
render: break out color conversion
This commit is contained in:
parent
df929a251a
commit
c9803a2018
1 changed files with 26 additions and 36 deletions
62
render.c
62
render.c
|
|
@ -34,20 +34,31 @@ struct glyph_sequence {
|
||||||
|
|
||||||
static struct glyph_sequence gseq;
|
static struct glyph_sequence gseq;
|
||||||
|
|
||||||
|
static inline struct rgb
|
||||||
|
color_hex_to_rgb(uint32_t color)
|
||||||
|
{
|
||||||
|
return (struct rgb){
|
||||||
|
((color >> 16) & 0xff) / 255.,
|
||||||
|
((color >> 8) & 0xff) / 255.,
|
||||||
|
((color >> 0) & 0xff) / 255.,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
color_dim(struct rgb *rgb)
|
||||||
|
{
|
||||||
|
rgb->r /= 2.;
|
||||||
|
rgb->g /= 2.;
|
||||||
|
rgb->b /= 2.;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gseq_flush(struct terminal *term, struct buffer *buf)
|
gseq_flush(struct terminal *term, struct buffer *buf)
|
||||||
{
|
{
|
||||||
struct rgb fg = {
|
struct rgb fg = color_hex_to_rgb(gseq.foreground);
|
||||||
((gseq.foreground >> 16) & 0xff) / 255.,
|
|
||||||
((gseq.foreground >> 8) & 0xff) / 255.,
|
|
||||||
((gseq.foreground >> 0) & 0xff) / 255.,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (gseq.attrs.dim) {
|
if (gseq.attrs.dim)
|
||||||
fg.r /= 2.;
|
color_dim(&fg);
|
||||||
fg.g /= 2.;
|
|
||||||
fg.b /= 2.;
|
|
||||||
}
|
|
||||||
|
|
||||||
cairo_set_scaled_font(buf->cairo, attrs_to_font(term, &gseq.attrs)->font);
|
cairo_set_scaled_font(buf->cairo, attrs_to_font(term, &gseq.attrs)->font);
|
||||||
cairo_set_source_rgb(buf->cairo, fg.r, fg.g, fg.b);
|
cairo_set_source_rgb(buf->cairo, fg.r, fg.g, fg.b);
|
||||||
|
|
@ -106,23 +117,11 @@ render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell,
|
||||||
_bg = swap;
|
_bg = swap;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct rgb fg = {
|
struct rgb fg = color_hex_to_rgb(_fg);
|
||||||
((_fg >> 16) & 0xff) / 255.,
|
struct rgb bg = color_hex_to_rgb(_bg);
|
||||||
((_fg >> 8) & 0xff) / 255.,
|
|
||||||
((_fg >> 0) & 0xff) / 255.,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct rgb bg = {
|
if (cell->attrs.dim)
|
||||||
((_bg >> 16) & 0xff) / 255.,
|
color_dim(&fg);
|
||||||
((_bg >> 8) & 0xff) / 255.,
|
|
||||||
((_bg >> 0) & 0xff) / 255.,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (cell->attrs.dim) {
|
|
||||||
fg.r /= 2.;
|
|
||||||
fg.g /= 2.;
|
|
||||||
fg.b /= 2.;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Background */
|
/* Background */
|
||||||
cairo_set_source_rgb(buf->cairo, bg.r, bg.g, bg.b);
|
cairo_set_source_rgb(buf->cairo, bg.r, bg.g, bg.b);
|
||||||
|
|
@ -286,17 +285,8 @@ grid_render(struct terminal *term)
|
||||||
int rmargin_width = term->width - rmargin;
|
int rmargin_width = term->width - rmargin;
|
||||||
int bmargin_height = term->height - bmargin;
|
int bmargin_height = term->height - bmargin;
|
||||||
|
|
||||||
#if 0
|
|
||||||
const struct rgb *bg = !term->reverse ?
|
|
||||||
&term->background : &term->foreground;
|
|
||||||
#else
|
|
||||||
uint32_t _bg = !term->reverse ? term->background : term->foreground;
|
uint32_t _bg = !term->reverse ? term->background : term->foreground;
|
||||||
struct rgb bg = {
|
struct rgb bg = color_hex_to_rgb(_bg);
|
||||||
((_bg >> 16) & 0xff) / 255.,
|
|
||||||
((_bg >> 8) & 0xff) / 255.,
|
|
||||||
((_bg >> 0) & 0xff) / 255.,
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
cairo_set_source_rgb(buf->cairo, bg.r, bg.g, bg.b);
|
cairo_set_source_rgb(buf->cairo, bg.r, bg.g, bg.b);
|
||||||
|
|
||||||
cairo_rectangle(buf->cairo, rmargin, 0, rmargin_width, term->height);
|
cairo_rectangle(buf->cairo, rmargin, 0, rmargin_width, term->height);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue