org.apache.batik.ext.awt
Class RadialGradientPaintContext

java.lang.Object
  extended by org.apache.batik.ext.awt.MultipleGradientPaintContext
      extended by org.apache.batik.ext.awt.RadialGradientPaintContext
All Implemented Interfaces:
java.awt.PaintContext

final class RadialGradientPaintContext
extends MultipleGradientPaintContext

Provides the actual implementation for the RadialGradientPaint. This is where the pixel processing is done. A RadialGradienPaint only supports circular gradients, but it should be possible to scale the circle to look approximately elliptical, by means of a gradient transform passed into the RadialGradientPaint constructor.

Version:
$Id: RadialGradientPaintContext.java,v 1.11 2004/08/18 07:13:41 vhardy Exp $
Author:
Nicholas Talian, Vincent Hardy, Jim Graham, Jerry Evans, Vincent Hardy

Field Summary
private static int ANTI_ALIAS_IMPL
           
private  float centerX
          Variables representing center and focus points.
private  float centerY
          Variables representing center and focus points.
private  float constA
          Constant part of X, Y user space coordinates.
private  float constB
          Constant part of X, Y user space coordinates.
private static int DEFAULT_IMPL
           
private  int fillMethod
           
private static int FIXED_POINT_IMPL
           
private  float focusX
          Variables representing center and focus points.
private  float focusY
          Variables representing center and focus points.
private  float invSqStepFloat
          Length of a square distance intervale in the lookup table
private  boolean isNonCyclic
          True when (cycleMethod == NO_CYCLE)
private  boolean isSimpleFocus
          True when (focus == center)
private  int MAX_PRECISION
          Used to limit the size of the square root lookup table
private  float radius
          Radius of the outermost circle defining the 100% gradient stop.
private  float radiusSq
          Radius of the gradient circle squared.
private static float SCALEBACK
          Amount for offset when clamping focus.
private  int[] sqrtLutFixed
          Square root lookup table
private  float trivial
          This value represents the solution when focusX == X.
 
Fields inherited from class org.apache.batik.ext.awt.MultipleGradientPaintContext
a00, a01, a02, a10, a11, a12, cached, cachedModel, colorSpace, cycleMethod, dataModel, DEBUG, fastGradientArraySize, fractions, gradient, GRADIENT_SIZE, GRADIENT_SIZE_INDEX, gradientAverage, gradientOverflow, gradients, gradientsLength, gradientUnderflow, hasDiscontinuity, isSimpleLookup, model, normalizedIntervals, saved
 
Constructor Summary
RadialGradientPaintContext(java.awt.image.ColorModel cm, java.awt.Rectangle deviceBounds, java.awt.geom.Rectangle2D userBounds, java.awt.geom.AffineTransform t, java.awt.RenderingHints hints, float cx, float cy, float r, float fx, float fy, float[] fractions, java.awt.Color[] colors, MultipleGradientPaint.CycleMethodEnum cycleMethod, MultipleGradientPaint.ColorSpaceEnum colorSpace)
          Constructor for RadialGradientPaintContext.
 
Method Summary
private  void antiAliasFillRaster(int[] pixels, int off, int adjust, int x, int y, int w, int h)
          Fill the raster, cycling the gradient colors when a point falls outside of the perimeter of the 100% stop circle.
private  void calculateFixedPointSqrtLookupTable()
          Build square root lookup table
private  void cyclicCircularGradientFillRaster(int[] pixels, int off, int adjust, int x, int y, int w, int h)
          Fill the raster, cycling the gradient colors when a point falls outside of the perimeter of the 100% stop circle.
protected  void fillRaster(int[] pixels, int off, int adjust, int x, int y, int w, int h)
          Return a Raster containing the colors generated for the graphics operation.
private  void fixedPointSimplestCaseNonCyclicFillRaster(int[] pixels, int off, int adjust, int x, int y, int w, int h)
          This code works in the simplest of cases, where the focus == center point, the gradient is noncyclic, and the gradient lookup method is fast (single array index, no conversion necessary).
 
Methods inherited from class org.apache.batik.ext.awt.MultipleGradientPaintContext
calculateGradientFractions, dispose, getCachedRaster, getColorModel, getRaster, indexGradientAntiAlias, indexIntoGradientsArrays, putCachedRaster
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isSimpleFocus

private boolean isSimpleFocus
True when (focus == center)


isNonCyclic

private boolean isNonCyclic
True when (cycleMethod == NO_CYCLE)


radius

private float radius
Radius of the outermost circle defining the 100% gradient stop.


centerX

private float centerX
Variables representing center and focus points.


centerY

private float centerY
Variables representing center and focus points.


focusX

private float focusX
Variables representing center and focus points.


focusY

private float focusY
Variables representing center and focus points.


radiusSq

private float radiusSq
Radius of the gradient circle squared.


constA

private float constA
Constant part of X, Y user space coordinates.


constB

private float constB
Constant part of X, Y user space coordinates.


trivial

private float trivial
This value represents the solution when focusX == X. It is called trivial because it is easier to calculate than the general case.


FIXED_POINT_IMPL

private static final int FIXED_POINT_IMPL
See Also:
Constant Field Values

DEFAULT_IMPL

private static final int DEFAULT_IMPL
See Also:
Constant Field Values

ANTI_ALIAS_IMPL

private static final int ANTI_ALIAS_IMPL
See Also:
Constant Field Values

fillMethod

private int fillMethod

SCALEBACK

private static final float SCALEBACK
Amount for offset when clamping focus.

See Also:
Constant Field Values

invSqStepFloat

private float invSqStepFloat
Length of a square distance intervale in the lookup table


MAX_PRECISION

private int MAX_PRECISION
Used to limit the size of the square root lookup table


sqrtLutFixed

private int[] sqrtLutFixed
Square root lookup table

Constructor Detail

RadialGradientPaintContext

public RadialGradientPaintContext(java.awt.image.ColorModel cm,
                                  java.awt.Rectangle deviceBounds,
                                  java.awt.geom.Rectangle2D userBounds,
                                  java.awt.geom.AffineTransform t,
                                  java.awt.RenderingHints hints,
                                  float cx,
                                  float cy,
                                  float r,
                                  float fx,
                                  float fy,
                                  float[] fractions,
                                  java.awt.Color[] colors,
                                  MultipleGradientPaint.CycleMethodEnum cycleMethod,
                                  MultipleGradientPaint.ColorSpaceEnum colorSpace)
                           throws java.awt.geom.NoninvertibleTransformException
Constructor for RadialGradientPaintContext.

Parameters:
cm - ColorModel that receives the Paint data. This is used only as a hint.
deviceBounds - the device space bounding box of the graphics primitive being rendered
userBounds - the user space bounding box of the graphics primitive being rendered
t - the AffineTransform from user space into device space (gradientTransform should be concatenated with this)
hints - the hints that the context object uses to choose between rendering alternatives
cx - the center point in user space of the circle defining the gradient. The last color of the gradient is mapped to the perimeter of this circle X coordinate
cy - the center point in user space of the circle defining the gradient. The last color of the gradient is mapped to the perimeter of this circle Y coordinate
r - the radius of the circle defining the extents of the color gradient
fx - the point in user space to which the first color is mapped X coordinate
fy - the point in user space to which the first color is mapped Y coordinate
fractions - the fractions specifying the gradient distribution
colors - the gradient colors
cycleMethod - either NO_CYCLE, REFLECT, or REPEAT
colorSpace - which colorspace to use for interpolation, either SRGB or LINEAR_RGB
Throws:
java.awt.geom.NoninvertibleTransformException
Method Detail

fillRaster

protected void fillRaster(int[] pixels,
                          int off,
                          int adjust,
                          int x,
                          int y,
                          int w,
                          int h)
Return a Raster containing the colors generated for the graphics operation.

Specified by:
fillRaster in class MultipleGradientPaintContext
Parameters:
x - The area in device space for which colors are generated.
y - The area in device space for which colors are generated.
w - The area in device space for which colors are generated.
h - The area in device space for which colors are generated.

fixedPointSimplestCaseNonCyclicFillRaster

private void fixedPointSimplestCaseNonCyclicFillRaster(int[] pixels,
                                                       int off,
                                                       int adjust,
                                                       int x,
                                                       int y,
                                                       int w,
                                                       int h)
This code works in the simplest of cases, where the focus == center point, the gradient is noncyclic, and the gradient lookup method is fast (single array index, no conversion necessary).


calculateFixedPointSqrtLookupTable

private void calculateFixedPointSqrtLookupTable()
Build square root lookup table


cyclicCircularGradientFillRaster

private void cyclicCircularGradientFillRaster(int[] pixels,
                                              int off,
                                              int adjust,
                                              int x,
                                              int y,
                                              int w,
                                              int h)
Fill the raster, cycling the gradient colors when a point falls outside of the perimeter of the 100% stop circle. This calculation first computes the intersection point of the line from the focus through the current point in the raster, and the perimeter of the gradient circle. Then it determines the percentage distance of the current point along that line (focus is 0%, perimeter is 100%). Equation of a circle centered at (a,b) with radius r: (x-a)^2 + (y-b)^2 = r^2 Equation of a line with slope m and y-intercept b y = mx + b replacing y in the cirlce equation and solving using the quadratic formula produces the following set of equations. Constant factors have been extracted out of the inner loop.


antiAliasFillRaster

private void antiAliasFillRaster(int[] pixels,
                                 int off,
                                 int adjust,
                                 int x,
                                 int y,
                                 int w,
                                 int h)
Fill the raster, cycling the gradient colors when a point falls outside of the perimeter of the 100% stop circle. Use the anti-aliased gradient lookup. This calculation first computes the intersection point of the line from the focus through the current point in the raster, and the perimeter of the gradient circle. Then it determines the percentage distance of the current point along that line (focus is 0%, perimeter is 100%). Equation of a circle centered at (a,b) with radius r: (x-a)^2 + (y-b)^2 = r^2 Equation of a line with slope m and y-intercept b y = mx + b replacing y in the cirlce equation and solving using the quadratic formula produces the following set of equations. Constant factors have been extracted out of the inner loop.