Bug 29521

Summary: Incorrect radial gradients when focus is outside of outermost circle
Product: cairo Reporter: Krzysztof Kosiński <tweenk.pl>
Component: image backendAssignee: Carl Worth <cworth>
Status: RESOLVED FIXED QA Contact: cairo-bugs mailing list <cairo-bugs>
Severity: normal    
Priority: medium CC: soren.sandmann
Version: 1.9.15   
Hardware: All   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: Test case
Test case output
Test case output - wip/radial branch

Description Krzysztof Kosiński 2010-08-11 18:00:10 UTC
When the inner circle of a radial gradient is outside the outer circle, the rendering is incorrect.
Comment 1 Krzysztof Kosiński 2010-08-11 18:01:20 UTC
Created attachment 37803 [details]
Test case

Compile with
gcc radial.c -o radial `pkg-config --cflags --libs cairo`
and look at radial.png
Comment 2 Krzysztof Kosiński 2010-08-11 18:02:25 UTC
Created attachment 37804 [details]
Test case output

Output of test case with Cairo 1.9.15. The rendered gradient is outside the outermost circle.
Comment 3 James Cloos 2010-08-12 06:44:29 UTC
When dealing with this issue, is there any chance of backing out the
definign cairo gradients to be the same as ps/pdf, so that cairo stops
creating wasteful image fallbacks?

With the possible expection of ps vs trasnparency groups, anthing which
is vector in cairo ought to be vector in ps/pdf.  Otherwise why use it?
Comment 4 James Cloos 2010-08-13 04:19:42 UTC
Ouch.  I didn't notice a single one of those typos before sending. ☹

The first ¶ should read:

  When dealing with this issue, is there any chance of backing out the
  change which forces image fallbacks for these sorts of gradients, and
  defining cairo gradients to be the same as ps/pdf, so that cairo stops
  creating wasteful image fallbacks?
Comment 5 Andrea Canciani 2010-08-16 01:13:20 UTC
I started writing an implementation of pdf-like radial gradents in http://cgit.freedesktop.org/~ranma42/pixman/log/?h=wip/radial

I didn't try to optimize it yet (beside avoiding redundant multiplication), so its performance is probably lower than what we actually want, but the output should be "correct".
Right now it makes use of __int128_t, so it probably won't compile on 32-bit architectures.

Is the output correct?
Comment 6 Krzysztof Kosiński 2010-08-17 09:50:04 UTC
(In reply to comment #5)
> I started writing an implementation of pdf-like radial gradents in
> http://cgit.freedesktop.org/~ranma42/pixman/log/?h=wip/radial
> 
> Is the output correct?

No, the result is still wrong. The gradient is still completely outside of the outer circle.
Comment 7 Krzysztof Kosiński 2010-08-17 09:53:00 UTC
Created attachment 37921 [details]
Test case output - wip/radial branch

Output of test case for the new branch
Comment 8 Andrea Canciani 2010-08-17 09:56:06 UTC
(In reply to comment #7)
> Created an attachment (id=37921) [details]
> Test case output - wip/radial branch
> 
> Output of test case for the new branch
(In reply to comment #6)
> (In reply to comment #5)
> > I started writing an implementation of pdf-like radial gradents in
> > http://cgit.freedesktop.org/~ranma42/pixman/log/?h=wip/radial
> > 
> > Is the output correct?
> 
> No, the result is still wrong. The gradient is still completely outside of the
> outer circle.
This is expected, since you are using CAIRO_EXTEND_PAD.
See http://www.cairographics.org/manual/cairo-pattern.html#cairo-pattern-set-extend
Comment 9 Krzysztof Kosiński 2010-08-17 10:03:02 UTC
Oops, I didn't look at the test results close enough. it's definitely more sensible than the previous one.

I've only now noticed that how this kind of gradient is rendered is not detailed in the SVG specification. So I'm not sure whether the output is correct or not. If it matches the PDF specification, it's probably correct.
Comment 10 Andrea Canciani 2010-10-12 13:15:00 UTC
This commit in pixman introduces the PDF radial gradients.
Most cairo backends now correctly use them, the other ones
will be fixed soon.

commit 1ca715ed1e6914e9bd9f050065e827d7a9e2efc9
Author: Andrea Canciani <ranma42@gmail.com>
Date:   Sun Aug 15 09:07:33 2010 +0200

    Draw radial gradients with PDF semantics
    
    Change radial gradient computations and definition to reflect the
    radial gradients in PDF specifications (see section 8.7.4.5.4,
    Type 3 (Radial) Shadings of the PDF Reference Manual).
    
    Instead of having a valid interpolation parameter value for every
    point of the plane, define it only for points withing the area
    covered by the family of circles generated by interpolating or
    extrapolating the start and end circles.
    
    Points outside this area are now transparent black (rgba 0 0 0 0).
    Points within this area have the color assiciated with the maximum
    value of the interpolation parameter in that point (if multiple
    solutions exist within the range specified by the extend mode).

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.