A Fast Radial Gradient Fill


#1

Eliminate the per-pixel square root!

(ignore the “Unsafe Website” warning)


#2

Nice trick! (Unfortunately, as soon as you add an affine transform…)


#3

Affine transforms are no problem at all. First, produce the radial gradient using the fast technique into an Image without any transform (including an alpha mask).

Then apply the affine transform using the skew method from Graphics Gems, “A Fast Algorithm for General Raster Rotation”:

http://www.cipprs.org/papers/VI/VI1986/pp077-081-Paeth-1986.pdf

A simple modification to the algorithm described in the paper allows for scaling and rotation to be performed together, with anti-aliasing. This implementation is faster than the current method used in the JUCE software renderer (it’s linear).

After the application of the transform then just draw the image.

Linear blends can be similarly improved. If you look at the cross-section of any scanline of a linear blend, its just a series of solid colours at the beginning and end, and a linear ramp in the middle. The linear ramp is easily computed using a Bresenham style line walking routine that uses integer-only state variables, with zero error. A special case would be used for vertical blends.