Class SVGRadialGradientPaintContext
java.lang.Object
com.github.weisj.jsvg.paint.impl.jdk.SVGMultipleGradientPaintContext
com.github.weisj.jsvg.paint.impl.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 floatVariables representing center and focus points.private final floatprivate final floatConstant part of X, Y user space coordinates.private final floatprivate static final floatAmount for offset when clamping focus.private final floatprivate final floatprivate floatprivate floatprivate final floatConstant second order delta for simple loop.private final booleanTrue when (cycleMethod == NO_CYCLE).private final booleanTrue when (focus == center) and (focus radius == 0).private final floatRadius of the gradient circle an focus circle squared.private static final intprivate static final float[]private final floatThis value represents the solution when focusX == X.Fields inherited from class 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 floatcomputeGradientPosition(float currentToFocusSq, float intersectToFocusSq) private voidcyclicCircularGradientFillRaster(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 voidfillRaster(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 intgetColorAtPoint(float userX, float userY, float solutionX, float solutionY) private intgetColorAtPointOutsideFocusCircle(float solutionX, float solutionY, float currentToFocusSq) private floatgetCurrentToFocusSq(float x, float y) private voidsimpleNonCyclicFillRaster(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 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- theRadialGradientPaintfrom which this context is createdt- theAffineTransformfrom 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:
fillRasterin 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.
-
getColorAtPoint
private int getColorAtPoint(float userX, float userY, float solutionX, float solutionY) -
getCurrentToFocusSq
private float getCurrentToFocusSq(float x, float y) -
getColorAtPointOutsideFocusCircle
private int getColorAtPointOutsideFocusCircle(float solutionX, float solutionY, float currentToFocusSq) -
computeGradientPosition
private float computeGradientPosition(float currentToFocusSq, float intersectToFocusSq)
-