diff options
author | Yu-Ping Wu <yupingso@chromium.org> | 2020-08-03 12:32:43 +0800 |
---|---|---|
committer | Julius Werner <jwerner@chromium.org> | 2020-08-13 22:25:18 +0000 |
commit | 7b54c15a676636961ae7d449e439a89acf669ec6 (patch) | |
tree | 8ce1091eda1b54fab2853d2697b1b3f6e65189b4 /payloads/libpayload/drivers/video/graphics.c | |
parent | e7ef6c380d0878dcce434c05e00943ad51abe093 (diff) |
libpayload: cbgfx: Add color mapping functionality
Similar to set_blend(), add set_color_map() for mapping background and
foreground colors of a bitmap. Also add clear_color_map() for clearing
the saved color mappings.
Note that when drawing a bitmap, the color mapping will be applied
before blending.
Also remove unnecessary initialization for static variable 'blend'.
BRANCH=puff
BUG=b:146399181, b:162357639
TEST=emerge-puff libpayload
Change-Id: I640ff3e8455cd4aaa5a41d03a0183dff282648a5
Signed-off-by: Yu-Ping Wu <yupingso@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/44375
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Joel Kitching <kitching@google.com>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'payloads/libpayload/drivers/video/graphics.c')
-rw-r--r-- | payloads/libpayload/drivers/video/graphics.c | 66 |
1 files changed, 57 insertions, 9 deletions
diff --git a/payloads/libpayload/drivers/video/graphics.c b/payloads/libpayload/drivers/video/graphics.c index b52bd99103..21f520c290 100644 --- a/payloads/libpayload/drivers/video/graphics.c +++ b/payloads/libpayload/drivers/video/graphics.c @@ -61,17 +61,53 @@ static const struct vector vzero = { .y = 0, }; +struct color_transformation { + uint8_t base; + int16_t scale; +}; + +struct color_mapping { + struct color_transformation red; + struct color_transformation green; + struct color_transformation blue; + int enabled; +}; + +static struct color_mapping color_map; + +static inline void set_color_trans(struct color_transformation *trans, + uint8_t bg_color, uint8_t fg_color) +{ + trans->base = bg_color; + trans->scale = fg_color - bg_color; +} + +int set_color_map(const struct rgb_color *background, + const struct rgb_color *foreground) +{ + if (background == NULL || foreground == NULL) + return CBGFX_ERROR_INVALID_PARAMETER; + + set_color_trans(&color_map.red, background->red, foreground->red); + set_color_trans(&color_map.green, background->green, + foreground->green); + set_color_trans(&color_map.blue, background->blue, foreground->blue); + color_map.enabled = 1; + + return CBGFX_SUCCESS; +} + +void clear_color_map(void) +{ + color_map.enabled = 0; +} + struct blend_value { uint8_t alpha; struct rgb_color rgb; }; -static struct blend_value blend = { - .alpha = 0, - .rgb.red = 0, - .rgb.green = 0, - .rgb.blue = 0, -}; +static struct blend_value blend; int set_blend(const struct rgb_color *rgb, uint8_t alpha) { @@ -185,6 +221,15 @@ static int within_box(const struct vector *v, const struct rect *bound) return -1; } +/* Helper function that applies color_map to the color. */ +static inline uint8_t apply_map(uint8_t color, + const struct color_transformation *trans) +{ + if (!color_map.enabled) + return color; + return trans->base + trans->scale * color / UINT8_MAX; +} + /* * Helper function that applies color and opacity from blend struct * into the color. @@ -203,13 +248,16 @@ static inline uint32_t calculate_color(const struct rgb_color *rgb, { uint32_t color = 0; - color |= (apply_blend(rgb->red, blend.rgb.red) + color |= (apply_blend(apply_map(rgb->red, &color_map.red), + blend.rgb.red) >> (8 - fbinfo->red_mask_size)) << fbinfo->red_mask_pos; - color |= (apply_blend(rgb->green, blend.rgb.green) + color |= (apply_blend(apply_map(rgb->green, &color_map.green), + blend.rgb.green) >> (8 - fbinfo->green_mask_size)) << fbinfo->green_mask_pos; - color |= (apply_blend(rgb->blue, blend.rgb.blue) + color |= (apply_blend(apply_map(rgb->blue, &color_map.blue), + blend.rgb.blue) >> (8 - fbinfo->blue_mask_size)) << fbinfo->blue_mask_pos; if (invert) |