From 475d397b8c3aa5ca672b7ec984a41302449b7727 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 23 Feb 2020 16:57:23 +0000 Subject: Plot style: Add function to engorge a colour channel. This can be used to exaggerate the red, green, or blue component. --- include/netsurf/plot_style.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'include/netsurf/plot_style.h') diff --git a/include/netsurf/plot_style.h b/include/netsurf/plot_style.h index 692192f17..bc8604114 100644 --- a/include/netsurf/plot_style.h +++ b/include/netsurf/plot_style.h @@ -188,6 +188,39 @@ typedef struct plot_font_style { #define blue_from_colour(c) \ ((c >> 16) & 0xff) +/** Colour components */ +enum plot_colour_component { + PLOT_COLOUR_COMPONENT_RED, + PLOT_COLOUR_COMPONENT_GREEN, + PLOT_COLOUR_COMPONENT_BLUE, + PLOT_COLOUR_COMPONENT_ALPHA, +}; + +/** + * Engorge a particular colour channel. + * + * \param[in] col The colour to engorge a component of. + * \param[in] dark Whether col is a dark colour. + * \param[in] comp Colour component to engorge. + */ +static inline colour colour_engorge_component( + colour col, + bool dark, + enum plot_colour_component comp) +{ + static const colour mask[PLOT_COLOUR_COMPONENT_ALPHA] = { + [PLOT_COLOUR_COMPONENT_RED] = 0x0000ff, + [PLOT_COLOUR_COMPONENT_GREEN] = 0x00ff00, + [PLOT_COLOUR_COMPONENT_BLUE] = 0xff0000, + }; + colour d = dark ? darken_colour(col) : double_darken_colour(col); + colour l = dark ? double_lighten_colour(col) : lighten_colour(col); + + assert(comp < PLOT_COLOUR_COMPONENT_ALPHA); + + return (mask[comp] & l) | (~mask[comp] & d); +} + /* global fill styles */ extern plot_style_t *plot_style_fill_white; -- cgit v1.2.3