fixup! feat(core): refactor display drivers

cepetr 3 weeks ago
parent a664599a62
commit 0cee1236c8

@ -57,6 +57,7 @@ typedef uint32_t gl_color32_t;
#define gl_color16_to_color(c) (gl_color16_to_color32(c))
#define gl_color_to_color32(c) (c)
#define gl_color32_to_color(c) (c)
#define gl_color_lum(c) (gl_color32_lum(c))
#else
#error "GL_COLOR_16BIT/32BIT not specified"
#endif
@ -121,6 +122,16 @@ static inline uint8_t gl_color16_lum(gl_color16_t color) {
return (r + g + b) / 3;
}
// Converts 32-bit color into luminance (ranging from 0 to 255)
static inline uint8_t gl_color32_lum(gl_color16_t color) {
uint32_t r = gl_color32_to_r(color);
uint32_t g = gl_color32_to_g(color);
uint32_t b = gl_color32_to_b(color);
return (r + g + b) / 3;
}
#ifdef GL_COLOR_16BIT
// Blends foreground and background colors with 4-bit alpha
//
@ -236,7 +247,7 @@ static inline gl_color16_t gl_color16_blend_a4(gl_color32_t fg, gl_color32_t bg,
uint16_t bg_b = gl_color32_to_b(bg);
uint16_t b = a4_lerp(fg_b, bg_b, alpha);
return gl_color16_rgb(r, g, b)
return gl_color16_rgb(r, g, b);
}
// Blends foreground and background colors with 8-bit alpha
@ -259,7 +270,7 @@ static inline gl_color16_t gl_color16_blend_a8(gl_color32_t fg, gl_color32_t bg,
uint16_t bg_b = gl_color32_to_b(bg);
uint16_t b = g = a8_lerp(fg_b, bg_b, alpha);
return gl_color16_rgb(r, g, b)
return gl_color16_rgb(r, g, b);
}
// Blends foreground and background colors with 4-bit alpha
@ -272,7 +283,7 @@ static inline gl_color32_t gl_color32_blend_a4(gl_color32_t fg, gl_color32_t bg,
uint8_t alpha) {
uint16_t fg_r = gl_color32_to_r(fg);
uint16_t bg_r = gl_color32_to_r(bg);
uint16_t r = g = a4_lerp(fg_r, bg_r, alpha);
uint16_t r = a4_lerp(fg_r, bg_r, alpha);
uint16_t fg_g = gl_color32_to_g(fg);
uint16_t bg_g = gl_color32_to_g(bg);
@ -285,6 +296,29 @@ static inline gl_color32_t gl_color32_blend_a4(gl_color32_t fg, gl_color32_t bg,
return gl_color32_rgb(r, g, b);
}
// Blends foreground and background colors with 8-bit alpha
//
// Returns a color in 32-bit format
//
// If `alpha` is 0, the function returns the background color
// If `alpha` is 15, the function returns the foreground color
static inline gl_color32_t gl_color32_blend_a8(gl_color32_t fg, gl_color32_t bg,
uint8_t alpha) {
uint16_t fg_r = gl_color32_to_r(fg);
uint16_t bg_r = gl_color32_to_r(bg);
uint16_t r = a8_lerp(fg_r, bg_r, alpha);
uint16_t fg_g = gl_color32_to_g(fg);
uint16_t bg_g = gl_color32_to_g(bg);
uint16_t g = a8_lerp(fg_g, bg_g, alpha);
uint16_t fg_b = gl_color32_to_b(fg);
uint16_t bg_b = gl_color32_to_b(bg);
uint16_t b = a8_lerp(fg_b, bg_b, alpha);
return gl_color32_rgb(r, g, b);
}
#else
#error "GL_COLOR_16BIT/32BIT not specified"
#endif

Loading…
Cancel
Save