From 6783deba4e209461fd8105b9b46dbcacefed6b6f Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 23 Feb 2020 16:56:15 +0000 Subject: Plot style: Split lightness calc out of colour_to_bw_furthest macro. --- include/netsurf/plot_style.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'include/netsurf/plot_style.h') diff --git a/include/netsurf/plot_style.h b/include/netsurf/plot_style.h index f1b617231..692192f17 100644 --- a/include/netsurf/plot_style.h +++ b/include/netsurf/plot_style.h @@ -153,13 +153,16 @@ typedef struct plot_font_style { (((((c0 & 0xff00ff) + (c1 & 0xff00ff)) >> 1) & 0xff00ff) | \ ((((c0 & 0x00ff00) + (c1 & 0x00ff00)) >> 1) & 0x00ff00)) +/* Get the percieved lightness of the supplied colour, c0. */ +#define colour_lightness(c0) \ + ((((c0 & 0x0000ff) * 77) >> 8) + \ + (((c0 & 0x00ff00) * 151) >> 16) + \ + (((c0 & 0xff0000) * 28) >> 24)) + /* Choose either black or white, depending on which is furthest from the * percieved lightness of the supplied colour, c0. */ #define colour_to_bw_furthest(c0) \ - ((((((c0 & 0x0000ff) * 77) >> 8) + \ - (((c0 & 0x00ff00) * 151) >> 16) + \ - (((c0 & 0xff0000) * 28) >> 24)) > \ - (0xff / 2)) ? 0x000000 : 0xffffff) + ((colour_lightness(c0) > (0xff / 2)) ? 0x000000 : 0xffffff) /* Mix two colours according to the proportion given by p, where 0 <= p <= 255 * p = 0 gives result ==> c1, p = 255 gives result ==> c0 */ -- cgit v1.2.3