diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2012-04-07 10:01:01 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2012-04-07 10:02:23 +0100 |
commit | 1ecf17b2507f95e1fefea15833fa9f57ec256a2e (patch) | |
tree | 29657c98939763748f35377e191348d33fb6665f | |
parent | 4356fae72db3a33935b575edf95c84fbb48072a7 (diff) |
sna/gradient: Compute the absolute delta between color stops
Otherwise we do not detect gradients that start from white!
Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48407
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r-- | src/sna/sna_gradient.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/sna/sna_gradient.c b/src/sna/sna_gradient.c index 943cbf96..32d26c8d 100644 --- a/src/sna/sna_gradient.c +++ b/src/sna/sna_gradient.c @@ -44,39 +44,48 @@ sna_gradient_sample_width(PictGradient *gradient) { int n, width; - width = 2; + width = 0; for (n = 1; n < gradient->nstops; n++) { xFixed dx = gradient->stops[n].x - gradient->stops[n-1].x; - uint16_t delta, max; - int ramp; + int delta, max, ramp; if (dx == 0) return 1024; max = gradient->stops[n].color.red - gradient->stops[n-1].color.red; + if (max < 0) + max = -max; delta = gradient->stops[n].color.green - gradient->stops[n-1].color.green; + if (delta < 0) + delta = -delta; if (delta > max) max = delta; delta = gradient->stops[n].color.blue - gradient->stops[n-1].color.blue; + if (delta < 0) + delta = -delta; if (delta > max) max = delta; delta = gradient->stops[n].color.alpha - gradient->stops[n-1].color.alpha; + if (delta < 0) + delta = -delta; if (delta > max) max = delta; - ramp = 128 * max / dx; + ramp = 256 * max / dx; if (ramp > width) width = ramp; } - width *= gradient->nstops-1; + if (width == 0) + return 1; + width = (width + 7) & -8; return min(width, 1024); } |