Class SVGRadialGradientPaintContext

java.lang.Object
com.github.weisj.jsvg.renderer.jdk.SVGMultipleGradientPaintContext
com.github.weisj.jsvg.renderer.jdk.SVGRadialGradientPaintContext
All Implemented Interfaces:
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 Details

    • 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:
    • 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 - the RadialGradientPaint from which this context is created
      t - the AffineTransform 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 gradient
      fx - the X coordinate in user space to which the first color is mapped
      fy - the Y coordinate in user space to which the first color is mapped
      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
  • 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 class SVGMultipleGradientPaintContext
      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.