APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.prism.j2d.paint

pack-priv abstract Class MultipleGradientPaintContext

extends Object
implements PaintContext
Class Inheritance
All Implemented Interfaces
java.awt.PaintContext
Known Direct Subclasses
com.sun.prism.j2d.paint.RadialGradientPaintContext
Imports
com.sun.prism.j2d.paint.MultipleGradientPaint.ColorSpaceType, .MultipleGradientPaint.CycleMethod, java.awt.Color, .PaintContext, .Rectangle, .RenderingHints, java.awt.geom.AffineTransform, .NoninvertibleTransformException, .Rectangle2D, java.awt.image.ColorModel, .DataBufferInt, .DirectColorModel, .Raster, .SinglePixelPackedSampleModel, java.lang.ref.SoftReference, .WeakReference

This is the superclass for all PaintContexts which use a multiple color gradient to fill in their raster. It provides the actual color interpolation functionality. Subclasses only have to deal with using the gradient to fill pixels in a raster.

Field Summary

Modifier and TypeField and Description
protected float
a00

Elements of the inverse transform matrix.

protected float
a01

Elements of the inverse transform matrix.

protected float
a02

Elements of the inverse transform matrix.

protected float
a10

Elements of the inverse transform matrix.

protected float
a11

Elements of the inverse transform matrix.

protected float
a12

Elements of the inverse transform matrix.

protected static WeakReference<Raster>
cached

The cached raster, which is reusable among instances.

protected static ColorModel
cachedModel

The cached ColorModel.

protected MultipleGradientPaint.ColorSpaceType
colorSpace

The ColorSpace in which to perform the interpolation

protected MultipleGradientPaint.CycleMethod
cycleMethod

The method to use when painting out of the gradient bounds.

protected int
fastGradientArraySize

Size of gradients array for scaling the 0-1 index when looking up colors the fast way.

private float[]
fractions

Fractions array.

protected int[]
gradient

Array which contains the interpolated color values for each interval, used by calculateSingleArrayGradient().

protected static final int
GRADIENT_SIZE

Constant number of max colors between any 2 arbitrary colors.

protected static final int
private int[][]
gradients

Array of gradient arrays, one array for each interval.

protected boolean
isSimpleLookup

This boolean specifies whether we are in simple lookup mode, where an input value between 0 and 1 may be used to directly index into a single array of gradient colors.

private static final int[]
private static final int
MAX_GRADIENT_ARRAY_SIZE

Maximum length of the fast single-array.

protected ColorModel
model

The PaintContext's ColorModel.

private float[]
normalizedIntervals

Normalized intervals array.

protected Raster
saved

Raster is reused whenever possible.

private static final int[]
SRGBtoLinearRGB

Color space conversion lookup tables.

private int
transparencyTest

Used to determine if gradient colors are all opaque.

private static ColorModel
xrgbmodel

Color model used if gradient colors are all opaque.

Constructor Summary

AccessConstructor and Description
protected
MultipleGradientPaintContext(MultipleGradientPaint mgp, ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform t, RenderingHints hints, float[] fractions, Color[] colors, MultipleGradientPaint.CycleMethod cycleMethod, MultipleGradientPaint.ColorSpaceType colorSpace)

Constructor for MultipleGradientPaintContext superclass.

Method Summary

Modifier and TypeMethod and Description
private void
calculateLookupData(Color[] colors)

This function is the meat of this class.

private void
calculateMultipleArrayGradient(Color[] colors)

SLOW LOOKUP METHOD This method calculates the gradient color values for each interval and places each into its own 255 size array.

private void
calculateSingleArrayGradient(Color[] colors, float
the size of the smallest interval
Imin
)

FAST LOOKUP METHOD This method calculates the gradient color values and places them in a single int array, gradient[].

private int
convertEntireColorLinearRGBtoSRGB(int rgb)

Yet another helper function.

private static int
convertLinearRGBtoSRGB(int color)

Helper function to convert a color component in linear RGB space to SRGB space.

private static int
convertSRGBtoLinearRGB(int color)

Helper function to convert a color component in sRGB space to linear RGB space.

public final void
dispose()

Implements java.awt.PaintContext.dispose.

Releases the resources allocated for the operation.

protected abstract void
fillRaster(int[] pixels, int off, int adjust, int x, int y, int w, int h)

private static synchronized Raster
getCachedRaster(ColorModel cm, int w, int h)

Took this cacheRaster code from GradientPaint.

public final ColorModel
getColorModel()

Implements java.awt.PaintContext.getColorModel.

Returns the ColorModel of the output.

public final Raster
getRaster(int x, int y, int w, int h)

Implements java.awt.PaintContext.getRaster.

Returns a Raster containing the colors generated for the graphics operation.

protected final int

Returns:

integer color to display
indexIntoGradientsArrays
(float
the unmanipulated position, which will be mapped into the range 0 to 1
position
)

Helper function to index into the gradients array.

private void
interpolate(int
the start color
rgb1
,
int
the end color
rgb2
,
int[]
the output array of colors; must not be null
output
)

Yet another helper function.

private static synchronized void
putCachedRaster(ColorModel cm, Raster ras)

Took this cacheRaster code from GradientPaint.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

a00back to summary
protected float a00

Elements of the inverse transform matrix.

a01back to summary
protected float a01

Elements of the inverse transform matrix.

a02back to summary
protected float a02

Elements of the inverse transform matrix.

a10back to summary
protected float a10

Elements of the inverse transform matrix.

a11back to summary
protected float a11

Elements of the inverse transform matrix.

a12back to summary
protected float a12

Elements of the inverse transform matrix.

cachedback to summary
protected static WeakReference<Raster> cached

The cached raster, which is reusable among instances.

cachedModelback to summary
protected static ColorModel cachedModel

The cached ColorModel.

colorSpaceback to summary
protected MultipleGradientPaint.ColorSpaceType colorSpace

The ColorSpace in which to perform the interpolation

cycleMethodback to summary
protected MultipleGradientPaint.CycleMethod cycleMethod

The method to use when painting out of the gradient bounds.

fastGradientArraySizeback to summary
protected int fastGradientArraySize

Size of gradients array for scaling the 0-1 index when looking up colors the fast way.

fractionsback to summary
private float[] fractions

Fractions array.

gradientback to summary
protected int[] gradient

Array which contains the interpolated color values for each interval, used by calculateSingleArrayGradient(). It is protected for possible direct access by subclasses.

GRADIENT_SIZEback to summary
protected static final int GRADIENT_SIZE

Constant number of max colors between any 2 arbitrary colors. Used for creating and indexing gradients arrays.

GRADIENT_SIZE_INDEXback to summary
protected static final int GRADIENT_SIZE_INDEX
gradientsback to summary
private int[][] gradients

Array of gradient arrays, one array for each interval. Used by calculateMultipleArrayGradient().

isSimpleLookupback to summary
protected boolean isSimpleLookup

This boolean specifies whether we are in simple lookup mode, where an input value between 0 and 1 may be used to directly index into a single array of gradient colors. If this boolean value is false, then we have to use a 2-step process where we have to determine which gradient array we fall into, then determine the index into that array.

LinearRGBtoSRGBback to summary
private static final int[] LinearRGBtoSRGB
MAX_GRADIENT_ARRAY_SIZEback to summary
private static final int MAX_GRADIENT_ARRAY_SIZE

Maximum length of the fast single-array. If the estimated array size is greater than this, switch over to the slow lookup method. No particular reason for choosing this number, but it seems to provide satisfactory performance for the common case (fast lookup).

modelback to summary
protected ColorModel model

The PaintContext's ColorModel. This is ARGB if colors are not all opaque, otherwise it is RGB.

normalizedIntervalsback to summary
private float[] normalizedIntervals

Normalized intervals array.

savedback to summary
protected Raster saved

Raster is reused whenever possible.

SRGBtoLinearRGBback to summary
private static final int[] SRGBtoLinearRGB

Color space conversion lookup tables.

transparencyTestback to summary
private int transparencyTest

Used to determine if gradient colors are all opaque.

xrgbmodelback to summary
private static ColorModel xrgbmodel

Color model used if gradient colors are all opaque.

Constructor Detail

MultipleGradientPaintContextback to summary
protected MultipleGradientPaintContext(MultipleGradientPaint mgp, ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform t, RenderingHints hints, float[] fractions, Color[] colors, MultipleGradientPaint.CycleMethod cycleMethod, MultipleGradientPaint.ColorSpaceType colorSpace)

Constructor for MultipleGradientPaintContext superclass.

Method Detail

calculateLookupDataback to summary
private void calculateLookupData(Color[] colors)

This function is the meat of this class. It calculates an array of gradient colors based on an array of fractions and color values at those fractions.

calculateMultipleArrayGradientback to summary
private void calculateMultipleArrayGradient(Color[] colors)

SLOW LOOKUP METHOD This method calculates the gradient color values for each interval and places each into its own 255 size array. The arrays are stored in gradients[][]. (255 is used because this is the maximum number of unique colors between 2 arbitrary colors in a 24 bit color system.) This method uses the minimum amount of space (only 255 * number of intervals), but it aggravates the lookup procedure, because now we have to find out which interval to select, then calculate the index within that interval. This causes a significant performance hit, because it requires this calculation be done for every point in the rendering loop. For those of you who are interested, this is a classic example of the time-space tradeoff.

calculateSingleArrayGradientback to summary
private void calculateSingleArrayGradient(Color[] colors, float Imin)

FAST LOOKUP METHOD This method calculates the gradient color values and places them in a single int array, gradient[]. It does this by allocating space for each interval based on its size relative to the smallest interval in the array. The smallest interval is allocated 255 interpolated values (the maximum number of unique in-between colors in a 24 bit color system), and all other intervals are allocated size = (255 * the ratio of their size to the smallest interval). This scheme expedites a speedy retrieval because the colors are distributed along the array according to their user-specified distribution. All that is needed is a relative index from 0 to 1. The only problem with this method is that the possibility exists for the array size to balloon in the case where there is a disproportionately small gradient interval. In this case the other intervals will be allocated huge space, but much of that data is redundant. We thus need to use the space conserving scheme below.

Parameters
Imin:float

the size of the smallest interval

convertEntireColorLinearRGBtoSRGBback to summary
private int convertEntireColorLinearRGBtoSRGB(int rgb)

Yet another helper function. This one extracts the color components of an integer RGB triple, converts them from LinearRGB to SRGB, then recompacts them into an int.

convertLinearRGBtoSRGBback to summary
private static int convertLinearRGBtoSRGB(int color)

Helper function to convert a color component in linear RGB space to SRGB space. Used to build a static lookup table.

convertSRGBtoLinearRGBback to summary
private static int convertSRGBtoLinearRGB(int color)

Helper function to convert a color component in sRGB space to linear RGB space. Used to build a static lookup table.

disposeback to summary
public final void dispose()

Implements java.awt.PaintContext.dispose.

Doc from java.awt.PaintContext.dispose.

Releases the resources allocated for the operation.

Annotations
@Override
fillRasterback to summary
protected abstract void fillRaster(int[] pixels, int off, int adjust, int x, int y, int w, int h)
getCachedRasterback to summary
private static synchronized Raster getCachedRaster(ColorModel cm, int w, int h)

Took this cacheRaster code from GradientPaint. It appears to recycle rasters for use by any other instance, as long as they are sufficiently large.

getColorModelback to summary
public final ColorModel getColorModel()

Implements java.awt.PaintContext.getColorModel.

Doc from java.awt.PaintContext.getColorModel.

Returns the ColorModel of the output. Note that this ColorModel might be different from the hint specified in the createContext method of Paint. Not all PaintContext objects are capable of generating color patterns in an arbitrary ColorModel.

Annotations
@Override
getRasterback to summary
public final Raster getRaster(int x, int y, int w, int h)

Implements java.awt.PaintContext.getRaster.

Doc from java.awt.PaintContext.getRaster.

Returns a Raster containing the colors generated for the graphics operation.

Annotations
@Override
indexIntoGradientsArraysback to summary
protected final int indexIntoGradientsArrays(float position)

Helper function to index into the gradients array. This is necessary because each interval has an array of colors with uniform size 255. However, the color intervals are not necessarily of uniform length, so a conversion is required.

Parameters
position:float

the unmanipulated position, which will be mapped into the range 0 to 1

Returns:int

integer color to display

interpolateback to summary
private void interpolate(int rgb1, int rgb2, int[] output)

Yet another helper function. This one linearly interpolates between 2 colors, filling up the output array.

Parameters
rgb1:int

the start color

rgb2:int

the end color

output:int[]

the output array of colors; must not be null

putCachedRasterback to summary
private static synchronized void putCachedRaster(ColorModel cm, Raster ras)

Took this cacheRaster code from GradientPaint. It appears to recycle rasters for use by any other instance, as long as they are sufficiently large.