[cairo] gl: fix gradient color generation where two stops have same offset
Henry (Yu) Song - SISA
hsong at sisa.samsung.com
Thu Jul 26 10:21:14 PDT 2012
I think we still need to offset. You can experiment linear-gradient-large by commenting out offseting code, but leave dx = 0.01 in - this will use max texture width of 1024. Try that. I think the image does not come out right. This because at the end of stops
stop and stop both have offset at 0, pixman picks stop color which is black for the first pixel.
From: Chris Wilson [chris at chris-wilson.co.uk]
Sent: Thursday, July 26, 2012 10:14 AM
To: Henry (Yu) Song - SISA; cairo at cairographics.org
Subject: Re: [cairo] gl: fix gradient color generation where two stops have same offset
On Thu, 26 Jul 2012 17:02:16 +0000, "Henry (Yu) Song - SISA" <hsong at sisa.samsung.com> wrote:
> Hi, Chris
> Based on your comments, I am re-working the patch. The first patch is about fixing gradient color generation when multiple stops have a same offset but different color. This patch brings test case linear-gradient-large closer to reference image
> From 29f4412c0a2454c36828b4dce826d9f29e6b0739 Mon Sep 17 00:00:00 2001
> From: Henry Song <henry.song at samsung.com>
> Date: Wed, 25 Jul 2012 15:34:52 -0700
> Subject: [PATCH] gl: fix gradient color generation for GL in cases where
> there are stops that have same offset but different color.
> bring test case: linear-gradient-large closer to reference image
> src/cairo-gl-gradient.c | 51 ++++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 48 insertions(+), 3 deletions(-)
> diff --git a/src/cairo-gl-gradient.c b/src/cairo-gl-gradient.c
> index ffb5468..a66f26d 100644
> --- a/src/cairo-gl-gradient.c
> +++ b/src/cairo-gl-gradient.c
> @@ -44,6 +44,7 @@
> #include "cairo-gl-gradient-private.h"
> #include "cairo-gl-private.h"
> +#define OFFSET_TOLERANCE 0.00001
> static int
> _cairo_gl_gradient_sample_width (unsigned int n_stops,
> @@ -57,9 +58,10 @@ _cairo_gl_gradient_sample_width (unsigned int n_stops,
> double dx = stops[n].offset - stops[n-1].offset;
> double delta, max;
> int ramp;
> + /* in case two stops offsets are same, and colors for different. */
> if (dx == 0)
> - continue;
> + dx = 0.01;
I had forgotten about that issue. The solution I choose was to use a
maximum texture size ramp in such (frequent) cases.
If we do that do we still need to fudge the offsets? As the transistion
will be as sharp as the sampler allows, and the only other solution
would be to do the gradient interpolation within the shader.
Chris Wilson, Intel Open Source Technology Centre
More information about the cairo