[cairo] Radii of radial gradients
Carl Worth
cworth at cworth.org
Thu Mar 1 10:58:51 PST 2007
On Sat, 24 Feb 2007 12:46:35 -0600, "Michael Urman" wrote:
> wall of the cone is pointing. However with an infinite range of t,
> there's a magic spot by that egde where the entire range t > 1 flips
> from outside the "inner" radius to by all on one side of the inner
> center. Since often all of t > 1 has the same solid color, suddenly a
> section of your infinite background is no longer infinite;
Yes, you've got the problem. And of course, when you derive the proper
mathematics for the radial gradient, the "magic spot" is conveniently
identified by the determinant passing through zero and that
hard-to-define region is exactly where the determinant is negative.
I derived all the math this weekend, and I'll be landing that to cairo
now.
Keith suggested just forcing the determinant to 0 when it is
negative. I've implemented that and was quite pleased by the result it
provides:
http://cairographics.org/~cworth/images/gradient-extreme.png
It's space-filling and without any objectionable color
discontinuities.
In the image above, the gradient is drawn from a small circle to a
large circle. Things also work great if you draw from a large circle
to a small circle, giving a slightly different effect, (very similar
to what PDF defines):
http://cairographics.org/~cworth/images/gradient-extreme2.png
So the big difference between what PDF does and what cairo does here
is that the "infinite" portions that look like a linear gradient here
are "uninked" in PDF. Someone should be able to implement that just
fine by computing the path of the "cone" formed by the two circles and
clipping to it.
Another thing that PDF provides that doesn't have explicit support in
cairo's radial gradients is gradient that extend from only one end or
the other. For that, what I'd like to suggest is simply using
EXTEND_REPEAT, (which affects both ends), and then using a transparent
color stop the end where the extension is undesired.
For that to work, we'll only need one little addition to the current
implementation. Right now, it only uses one real root of the quadratic
equation, even if there is a second one available---it simply chooses
the root that results in a larger value for the gradient's parametric
control, (this gives the "last circle drawn wins" effect that PDF
defines).
To refine this, we'll simply need to check the second root if the
first root results in a non-opaque color value and simply blend the
two colors. This should give an interesting effect when transparency
is used for interior stops, (an effect not expressible in PDF nor
SVG), but should also allow for emulating the PDF single-sided
extended gradients with a transparent stop on one end or the other.
-Carl
PS. You don't even want to know what kind of effects result if you try
drawing some of these cases with cairo 1.0 or 1.2. Let's just say they
are not pretty.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20070301/c73e6b21/attachment.pgp
More information about the cairo
mailing list