Bug 7685

Summary: Radial Gradients with nonzero inner radius misplace stops
Product: cairo Reporter: Michael Urman <murman+freedesktopbugs>
Component: png functionsAssignee: Carl Worth <cworth>
Status: RESOLVED FIXED QA Contact: cairo-bugs mailing list <cairo-bugs>
Severity: blocker    
Priority: high    
Version: 1.2.0   
Hardware: x86 (IA32)   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:

Description Michael Urman 2006-07-29 09:40:58 UTC
The following code sample creates two files: gradientbug.png and
gradientbug.svg. The svg is what I expect; the png is not. Change rmin = 1 to
rmin = 0 to have the images become identical. (Swap rmin and rmax to reveal
different behavior entirely; it appears radius0 must be less than radius1 for
radial gradients to work correctly in png or to work at all in svg.)

#! /usr/bin/env python

import cairo
from math import pi

size = 600
surface = cairo.SVGSurface('gradientbug.svg', size, size)
cr = cairo.Context(surface)
cr.scale(size/10, size/10)

# create a gradient with r=1 to r=5; add stops every 1
# the alternate rmin=0 creates r=0 to r=5, with stops every 1.25
rmin = 1 # the image difference is proportional to rmin; 0 makes it go away
rmax = 5
gradient = cairo.RadialGradient(5, 5, rmin,  5, 5, rmax)
gradient.add_color_stop_rgb(0.0,  1, 0, 0)
gradient.add_color_stop_rgb(0.25,  1, 1, 0)
gradient.add_color_stop_rgb(0.5,  0, 1, 0)
gradient.add_color_stop_rgb(0.75,  0, 1, 1)
gradient.add_color_stop_rgb(1.0,  0, 0, 1)

cr.set_source(gradient)
cr.paint()

# the arcs are optional, but highlight where the stops are
cr.set_line_width(max(cr.device_to_user_distance(1, 1)))
cr.set_dash([0.1], 0)

cr.set_source_rgba(0, 0, 0, 0.3)
for r in range(5):
    cr.arc(5, 5, r * (rmax - rmin) / 4.0 + rmin, 0, 2 * pi)
    cr.stroke()

surface.write_to_png('gradientbug.png')
cr.show_page()
Comment 1 Carl Worth 2007-03-01 20:22:15 UTC
I've just pushed out a branch which fixes the original problem:

http://gitweb.freedesktop.org/?p=cairo;a=commit;h=df2d42ac7fb71997abd406fb5716c0bd85037c04

I've tested with your program and the PNG and SVG results now match even with non-zero rmin.

(The case with the rmin and rmax values reversed does not match yet, so that
may need further investigation.)

-Carl

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.