Class SVGRadialGradientPaintContext
- java.lang.Object
-
- com.github.weisj.jsvg.renderer.jdk.SVGMultipleGradientPaintContext
-
- com.github.weisj.jsvg.renderer.jdk.SVGRadialGradientPaintContext
-
- All Implemented Interfaces:
java.awt.PaintContext
final class SVGRadialGradientPaintContext extends SVGMultipleGradientPaintContext
Provides the actual implementation for the RadialGradientPaint. This is where the pixel processing is done. A RadialGradientPaint 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.
-
-
Field Summary
Fields Modifier and Type Field Description private float
centerX
Variables representing center and focus points.private float
centerY
private float
constA
Constant part of X, Y user space coordinates.private float
constB
private static float
FOCUS_CLAMP_DOWNSCALE
Amount for offset when clamping focus.private float
focusRadius
private float
focusRadiusSq
private float
focusX
private float
focusY
private float
gDeltaDelta
Constant second order delta for simple loop.private boolean
isNonCyclic
True when (cycleMethod == NO_CYCLE).private boolean
isSimpleFocus
True when (focus == center) and (focus radius == 0).private float
radiusSq
Radius of the gradient circle an focus circle squared.private static int
SQRT_LUT_SIZE
private static float[]
sqrtLookup
private float
trivial
This value represents the solution when focusX == X.-
Fields inherited from class com.github.weisj.jsvg.renderer.jdk.SVGMultipleGradientPaintContext
a00, a01, a02, a10, a11, a12, cached, cachedModel, colorSpace, cycleMethod, fastGradientArraySize, gradient, GRADIENT_SIZE, GRADIENT_SIZE_INDEX, isSimpleLookup, model, saved
-
-
Constructor Summary
Constructors Constructor Description SVGRadialGradientPaintContext(@NotNull SVGRadialGradientPaint paint, @NotNull java.awt.geom.AffineTransform t, float cx, float cy, float r, float fx, float fy, float fr, float @NotNull [] fractions, @NotNull java.awt.Color @NotNull [] colors, java.awt.MultipleGradientPaint.CycleMethod cycleMethod, java.awt.MultipleGradientPaint.ColorSpaceType colorSpace)
Constructor for RadialGradientPaintContext.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 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
simpleNonCyclicFillRaster(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 non-cyclic, and the gradient lookup method is fast (single array index, no conversion necessary).-
Methods inherited from class com.github.weisj.jsvg.renderer.jdk.SVGMultipleGradientPaintContext
dispose, getColorModel, getRaster, indexIntoGradientsArrays
-
-
-
-
Field Detail
-
isSimpleFocus
private final boolean isSimpleFocus
True when (focus == center) and (focus radius == 0).
-
isNonCyclic
private final boolean isNonCyclic
True when (cycleMethod == NO_CYCLE).
-
centerX
private final float centerX
Variables representing center and focus points.
-
centerY
private final float centerY
-
focusX
private float focusX
-
focusY
private float focusY
-
radiusSq
private final float radiusSq
Radius of the gradient circle an focus circle squared.
-
focusRadius
private final float focusRadius
-
focusRadiusSq
private final float focusRadiusSq
-
constA
private final float constA
Constant part of X, Y user space coordinates.
-
constB
private final float constB
-
gDeltaDelta
private final float gDeltaDelta
Constant second order delta for simple loop.
-
trivial
private final float trivial
This value represents the solution when focusX == X. It is called trivial because it is easier to calculate than the general case.
-
FOCUS_CLAMP_DOWNSCALE
private static final float FOCUS_CLAMP_DOWNSCALE
Amount for offset when clamping focus.- See Also:
- Constant Field Values
-
SQRT_LUT_SIZE
private static final int SQRT_LUT_SIZE
- See Also:
- Constant Field Values
-
sqrtLookup
private static final float[] sqrtLookup
-
-
Constructor Detail
-
SVGRadialGradientPaintContext
SVGRadialGradientPaintContext(@NotNull @NotNull SVGRadialGradientPaint paint, @NotNull @NotNull java.awt.geom.AffineTransform t, float cx, float cy, float r, float fx, float fy, float fr, float @NotNull [] fractions, @NotNull @NotNull java.awt.Color @NotNull [] colors, java.awt.MultipleGradientPaint.CycleMethod cycleMethod, java.awt.MultipleGradientPaint.ColorSpaceType colorSpace)
Constructor for RadialGradientPaintContext.- Parameters:
paint
- theRadialGradientPaint
from which this context is createdt
- theAffineTransform
from user space into device space (gradientTransform should be concatenated with this)cx
- the center X coordinate in user space of the circle defining the gradient. The last color of the gradient is mapped to the perimeter of this circle.cy
- the center Y coordinate in user space of the circle defining the gradient. The last color of the gradient is mapped to the perimeter of this circle.r
- the radius of the circle defining the extents of the color gradientfx
- the X coordinate in user space to which the first color is mappedfy
- the Y coordinate in user space to which the first color is mappedfractions
- the fractions specifying the gradient distributioncolors
- the gradient colorscycleMethod
- either NO_CYCLE, REFLECT, or REPEATcolorSpace
- which colorspace to use for interpolation, either SRGB or LINEAR_RGB
-
-
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 classSVGMultipleGradientPaintContext
- Parameters:
x
- ,y,w,h the area in device space for which colors are generated.
-
simpleNonCyclicFillRaster
private void simpleNonCyclicFillRaster(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 non-cyclic, and the gradient lookup method is fast (single array index, no conversion necessary).
-
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 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 circle equation and solving using the quadratic formula produces the following set of equations. Constant factors have been extracted out of the inner loop.
-
-