Yu-Ping Wu has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/44375 )
Change subject: libpayload: cbgfx: Add color mapping functionality ......................................................................
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.
BRANCH=puff BUG=b:146399181, b:162357639 TEST=emerge-puff libpayload
Change-Id: I640ff3e8455cd4aaa5a41d03a0183dff282648a5 Signed-off-by: Yu-Ping Wu yupingso@chromium.org --- M payloads/libpayload/drivers/video/graphics.c M payloads/libpayload/include/cbgfx.h 2 files changed, 64 insertions(+), 5 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/75/44375/1
diff --git a/payloads/libpayload/drivers/video/graphics.c b/payloads/libpayload/drivers/video/graphics.c index b52bd99..49a05fc 100644 --- a/payloads/libpayload/drivers/video/graphics.c +++ b/payloads/libpayload/drivers/video/graphics.c @@ -61,6 +61,32 @@ .y = 0, };
+struct color_mapping { + struct rgb_color bg; + struct rgb_color fg; + int enabled; +}; + +static struct color_mapping color_map; + +int set_color_map(const struct rgb_color *background, + const struct rgb_color *foreground) +{ + if (background == NULL || foreground == NULL) + return CBGFX_ERROR_INVALID_PARAMETER; + + color_map.bg = *background; + color_map.fg = *foreground; + 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; @@ -185,6 +211,17 @@ return -1; }
+/* Helper function that applies color_map to the color. */ +static inline uint8_t apply_map(uint8_t color, + uint8_t bg_color, uint8_t fg_color) +{ + if (!color_map.enabled) + return color; + + return ((int16_t)bg_color * (UINT8_MAX - color) + + (int16_t)fg_color * color) / UINT8_MAX; +} + /* * Helper function that applies color and opacity from blend struct * into the color. @@ -203,13 +240,19 @@ { uint32_t color = 0;
- color |= (apply_blend(rgb->red, blend.rgb.red) + color |= (apply_blend(apply_map(rgb->red, + color_map.bg.red, color_map.fg.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.bg.green, color_map.fg.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.bg.blue, color_map.fg.blue), + blend.rgb.blue) >> (8 - fbinfo->blue_mask_size)) << fbinfo->blue_mask_pos; if (invert) diff --git a/payloads/libpayload/include/cbgfx.h b/payloads/libpayload/include/cbgfx.h index f2883b0..85b61a7 100644 --- a/payloads/libpayload/include/cbgfx.h +++ b/payloads/libpayload/include/cbgfx.h @@ -228,6 +228,24 @@ int get_bitmap_dimension(const void *bitmap, size_t sz, struct scale *dim_rel);
/** + * Setup color mappings of background and foreground colors. Black and white + * pixels will be mapped to the background and foreground colors, respectively. + * Call clear_color_map() to disabled color mapping. + * + * @param[in] background Background color. + * @param[in] foreground Foreground color. + * + * @return CBGFX_* error codes + */ +int set_color_map(const struct rgb_color *background, + const struct rgb_color *foreground); + +/** + * Clear color mappings. + */ +void clear_color_map(void); + +/** * Setup alpha and rgb values for alpha blending. When alpha is != 0, * this enables a translucent layer of color (defined by rgb) to be * blended at a given translucency (alpha) to all things drawn. Call @@ -244,8 +262,6 @@
/** * Clear alpha and rgb values, thus disabling any alpha blending. - * - * @return CBGFX_* error codes */ void clear_blend(void);