summaryrefslogtreecommitdiff
path: root/include/netsurf/plot_style.h
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2020-02-23 16:57:23 +0000
committerMichael Drake <michael.drake@codethink.co.uk>2020-02-23 17:38:14 +0000
commit475d397b8c3aa5ca672b7ec984a41302449b7727 (patch)
tree369f0d101d3a6fdfb3b117d9f481233c9c5ca3aa /include/netsurf/plot_style.h
parent6783deba4e209461fd8105b9b46dbcacefed6b6f (diff)
downloadnetsurf-475d397b8c3aa5ca672b7ec984a41302449b7727.tar.gz
netsurf-475d397b8c3aa5ca672b7ec984a41302449b7727.tar.bz2
Plot style: Add function to engorge a colour channel.
This can be used to exaggerate the red, green, or blue component.
Diffstat (limited to 'include/netsurf/plot_style.h')
-rw-r--r--include/netsurf/plot_style.h33
1 files changed, 33 insertions, 0 deletions
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;