[patch] gl: fix gradient color texture generation
"Henry (Yu) Song - SISA" <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <3955FA337689574EB32F94B12A7E6E9E16364B89@sisaex01sj> |
Hi, Chris and Soren Please discard my previous patch on offsetting to get gradient color. The pixman behavior is correct, except we have problem if first few stops offset at 0 - then we should pick the first stop's color for the first pixel. To do that, we need to increase the first stop offset a little such that pixman gradient walker picks the first stop color when it starts to walk through. Here is the patch, test case linear-gradient-large From c749d938a71ff9045e264f618b09bb99ced16ee8 Mon Sep 17 00:00:00 2001 From: Henry Song <[email protected]> Date: Thu, 26 Jul 2012 14:10:19 -0700 Subject: [PATCH] gl: fix gradient color generation if first few stops are offset at 0 --- src/cairo-gl-gradient.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/cairo-gl-gradient.c b/src/cairo-gl-gradient.c index 76920da..8cf3d6b 100644 --- a/src/cairo-gl-gradient.c +++ b/src/cairo-gl-gradient.c @@ -97,6 +97,7 @@ _cairo_gl_gradient_render (const cairo_gl_context_t *ctx, pixman_point_fixed_t p1, p2; unsigned int i; pixman_format_code_t gradient_pixman_format; + double offset = 0.00001; /* * Ensure that the order of the gradient's components in memory is BGRA. @@ -116,7 +117,23 @@ _cairo_gl_gradient_render (const cairo_gl_context_t *ctx, return _cairo_error (CAIRO_STATUS_NO_MEMORY); } - for (i = 0; i < n_stops; i++) { + /* pixman always picks color at the right most side of stops if + * multiple stops have a same offset. This is actually a correct + * behaviro. However, this means if we have two + * first stops at (0, 1, 1, 1, 1) and (0, 0, 0, 0, 1), the first + * pixel generated is black color instead of white color. To + * compensate that we need to increase the first stop offset a little + * such that pixman picks up the first stop at first pixel. + */ + if (n_stops > 2 && (stops[0].offset == stops[1].offset) && + (stops[0].offset == 0)) { + pixman_stops[0].x = _cairo_fixed_16_16_from_double (stops[0].offset + offset); + pixman_stops[0].color.red = stops[0].color.red_short; + pixman_stops[0].color.green = stops[0].color.green_short; + pixman_stops[0].color.blue = stops[0].color.blue_short; + pixman_stops[0].color.alpha = stops[0].color.alpha_short; + } + for (i = 1; i < n_stops; i++) { pixman_stops[i].x = _cairo_fixed_16_16_from_double (stops[i].offset); pixman_stops[i].color.red = stops[i].color.red_short; pixman_stops[i].color.green = stops[i].color.green_short; -- 1.7.9.5 -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo