From e0a4b50e87504bdc4f0bed8d68e3e2bd4798642c Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 10 Jul 2009 19:53:30 +0000 Subject: Move colour blend routine from html_redraw to plot_style and make it a define. svn path=/trunk/netsurf/; revision=8451 --- desktop/plot_style.h | 33 +++++++++++++++++++++------------ render/html_redraw.c | 35 ++++++++++------------------------- 2 files changed, 31 insertions(+), 37 deletions(-) diff --git a/desktop/plot_style.h b/desktop/plot_style.h index 03bb69f91..9de9cbf97 100644 --- a/desktop/plot_style.h +++ b/desktop/plot_style.h @@ -28,31 +28,40 @@ #define WIDGET_BLOBC 0x000000 /* Darken a colour by taking three quaters of each channels intensity */ -#define darken_colour(c1) \ - ((((3 * (c1 >> 16)) >> 2) << 16) | \ - (((3 * ((c1 >> 8) & 0xff)) >> 2) << 8) | \ +#define darken_colour(c1) \ + ((((3 * (c1 >> 16)) >> 2) << 16) | \ + (((3 * ((c1 >> 8) & 0xff)) >> 2) << 8) | \ (((3 * (c1 & 0xff)) >> 2) << 0)) /* Darken a colour by taking nine sixteenths of each channels intensity */ -#define double_darken_colour(c1) \ - ((((9 * (c1 >> 16)) >> 4) << 16) | \ - (((9 * ((c1 >> 8) & 0xff)) >> 4) << 8) | \ +#define double_darken_colour(c1) \ + ((((9 * (c1 >> 16)) >> 4) << 16) | \ + (((9 * ((c1 >> 8) & 0xff)) >> 4) << 8) | \ (((9 * (c1 & 0xff)) >> 4) << 0)) /* Lighten a colour by taking three quaters of each channels intensity - * and adding a full quater + * and adding a full quater */ #define lighten_colour(c1) \ (((((3 * (c1 >> 16)) >> 2) + 64) << 16) | \ ((((3 * ((c1 >> 8) & 0xff)) >> 2) + 64) << 8) | \ ((((3 * (c1 & 0xff)) >> 2) + 64) << 0)) -/* Lighten a colour by taking nine sixteenths of each channels intensity and adding a full intensity 7/16ths */ -#define double_lighten_colour(c1) \ - (((((9 * (c1 >> 16)) >> 4) + 112) << 16) | \ - ((((9 * ((c1 >> 8) & 0xff)) >> 4) + 112) << 8) | \ +/* Lighten a colour by taking nine sixteenths of each channels intensity and + * adding a full intensity 7/16ths */ +#define double_lighten_colour(c1) \ + (((((9 * (c1 >> 16)) >> 4) + 112) << 16) | \ + ((((9 * ((c1 >> 8) & 0xff)) >> 4) + 112) << 8) | \ ((((9 * (c1 & 0xff)) >> 4) + 112) << 0)) +/* Blend two colours by taking half the intensity of each channel in the first + * colour and adding them to half the intensity of each channel in the second + * colour */ +#define blend_colour(c0, c1) \ + ((((c0 >> 16) + (c1 >> 16)) >> 1) << 16) | \ + (((((c0 >> 8) & 0xff) + ((c1 >> 8) & 0xff)) >> 1) << 8) | \ + ((((c0 & 0xff) + (c1 & 0xff)) >> 1) << 0) + typedef enum { PLOT_OP_TYPE_NONE = 0, /**< No operation */ PLOT_OP_TYPE_SOLID, /**< Solid colour */ @@ -64,7 +73,7 @@ typedef struct { plot_operation_type_t stroke_type; int stroke_width; colour stroke_colour; - plot_operation_type_t fill_type; + plot_operation_type_t fill_type; colour fill_colour; } plot_style_t; diff --git a/render/html_redraw.c b/render/html_redraw.c index 9c5e72cd2..e3338f121 100644 --- a/render/html_redraw.c +++ b/render/html_redraw.c @@ -70,7 +70,6 @@ static bool html_redraw_border_plot(int i, int *p, colour c, css_border_style style, int thickness); static colour html_redraw_darker(colour c); static colour html_redraw_lighter(colour c); -static colour html_redraw_blend(colour c0, colour c1); static bool html_redraw_checkbox(int x, int y, int width, int height, bool selected); static bool html_redraw_radio(int x, int y, int width, int height, @@ -1252,22 +1251,6 @@ colour html_redraw_lighter(colour c) } -/** - * Blend two colours. - * - * \param c0 colour - * \param c1 colour - * \return a blended colour, half way between c0 and c1 - */ - -colour html_redraw_blend(colour c0, colour c1) -{ - return ((((c0 >> 16) + (c1 >> 16)) / 2) << 16) | - (((((c0 >> 8) & 0xff) + ((c1 >> 8) & 0xff)) / 2) << 8) | - ((((c0 & 0xff) + (c1 & 0xff)) / 2) << 0); -} - - /** * Plot a checkbox. * @@ -1286,11 +1269,14 @@ bool html_redraw_checkbox(int x, int y, int width, int height, if (z == 0) z = 1; - if (!(plot.rectangle(x, y, x + width, y + height, plot_style_fill_wbasec) && + if (!(plot.rectangle(x, y, x + width, y + height, + plot_style_fill_wbasec) && plot.line(x, y, x + width, y, plot_style_stroke_darkwbasec) && plot.line(x, y, x, y + height, plot_style_stroke_darkwbasec) && - plot.line(x + width, y, x + width, y + height, plot_style_stroke_lightwbasec) && - plot.line(x, y + height, x + width, y + height, plot_style_stroke_lightwbasec))) + plot.line(x + width, y, x + width, y + height, + plot_style_stroke_lightwbasec) && + plot.line(x, y + height, x + width, y + height, + plot_style_stroke_lightwbasec))) return false; if (selected) { @@ -1813,8 +1799,7 @@ bool html_redraw_text_decoration(struct box *box, if (html_redraw_printing) colour = box->style->color; else - colour = html_redraw_blend(background_colour, - box->style->color); + colour = blend_colour(background_colour, box->style->color); if (box->type == BOX_INLINE) { if (!box->inline_end) @@ -1919,7 +1904,8 @@ bool html_redraw_text_decoration_block(struct box *box, int x, int y, } static inline bool -html_redraw_scrollbar_rectangle(int x0, int y0, int x1, int y1, colour c, bool inset) +html_redraw_scrollbar_rectangle(int x0, int y0, int x1, int y1, colour c, + bool inset) { static plot_style_t c0 = { .stroke_type = PLOT_OP_TYPE_SOLID, @@ -1943,8 +1929,7 @@ html_redraw_scrollbar_rectangle(int x0, int y0, int x1, int y1, colour c, bool i c0.stroke_colour = lighten_colour(c); c1.stroke_colour = darken_colour(c); } - c2.stroke_colour = html_redraw_blend(c0.stroke_colour, - c1.stroke_colour); + c2.stroke_colour = blend_colour(c0.stroke_colour, c1.stroke_colour); if (!plot.line(x0, y0, x1, y0, &c0)) return false; if (!plot.line(x1, y0, x1, y1 + 1, &c1)) return false; -- cgit v1.2.3