Module com.github.weisj.jsvg
Class SVGRadialGradientPaintContext
java.lang.Object
com.github.weisj.jsvg.renderer.jdk.SVGMultipleGradientPaintContext
com.github.weisj.jsvg.renderer.jdk.SVGRadialGradientPaintContext
- All Implemented Interfaces:
PaintContext
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
FieldsModifier and TypeFieldDescriptionprivate final float
Variables representing center and focus points.private final float
private final float
Constant part of X, Y user space coordinates.private final float
private static final float
Amount for offset when clamping focus.private final float
private final float
private float
private float
private final float
Constant second order delta for simple loop.private final boolean
True when (cycleMethod == NO_CYCLE).private final boolean
True when (focus == center) and (focus radius == 0).private final float
Radius of the gradient circle an focus circle squared.private static final int
private static final float[]
private final float
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
ConstructorsConstructorDescriptionSVGRadialGradientPaintContext
(@NotNull SVGRadialGradientPaint paint, @NotNull AffineTransform t, float cx, float cy, float r, float fx, float fy, float fr, float @NotNull [] fractions, @NotNull Color @NotNull [] colors, MultipleGradientPaint.CycleMethod cycleMethod, MultipleGradientPaint.ColorSpaceType colorSpace) Constructor for RadialGradientPaintContext. -
Method Summary
Modifier and TypeMethodDescriptionprivate 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 Details
-
isSimpleFocus
private final boolean isSimpleFocusTrue when (focus == center) and (focus radius == 0). -
isNonCyclic
private final boolean isNonCyclicTrue when (cycleMethod == NO_CYCLE). -
centerX
private final float centerXVariables representing center and focus points. -
centerY
private final float centerY -
focusX
private float focusX -
focusY
private float focusY -
radiusSq
private final float radiusSqRadius of the gradient circle an focus circle squared. -
focusRadius
private final float focusRadius -
focusRadiusSq
private final float focusRadiusSq -
constA
private final float constAConstant part of X, Y user space coordinates. -
constB
private final float constB -
gDeltaDelta
private final float gDeltaDeltaConstant second order delta for simple loop. -
trivial
private final float trivialThis 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_DOWNSCALEAmount for offset when clamping focus.- See Also:
-
SQRT_LUT_SIZE
private static final int SQRT_LUT_SIZE- See Also:
-
sqrtLookup
private static final float[] sqrtLookup
-
-
Constructor Details
-
SVGRadialGradientPaintContext
SVGRadialGradientPaintContext(@NotNull @NotNull SVGRadialGradientPaint paint, @NotNull @NotNull AffineTransform t, float cx, float cy, float r, float fx, float fy, float fr, float @NotNull [] fractions, @NotNull @NotNull Color @NotNull [] colors, MultipleGradientPaint.CycleMethod cycleMethod, 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 Details
-
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.
-