Top Description Fields Constructors Methods
com.sun.prism.impl.paint

pack-priv abstract Class MultipleGradientContext

extends Object
Class Inheritance
Known Direct Subclasses
com.sun.prism.impl.paint.RadialGradientContext, com.sun.prism.impl.paint.LinearGradientContext
Imports
com.sun.javafx.geom.transform.BaseTransform, .NoninvertibleTransformException, com.sun.prism.paint.Color, .Gradient

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 int
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
MAX_GRADIENT_ARRAY_SIZE

Maximum length of the fast single-array.

private float[]
normalizedIntervals

Normalized intervals array.

private int
transparencyTest

Used to determine if gradient colors are all opaque.

Constructor Summary

AccessConstructor and Description
protected
MultipleGradientContext(Gradient mgp, BaseTransform t, float[] fractions, Color[] colors, int cycleMethod)

Constructor for MultipleGradientContext 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[].

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

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.

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.

cycleMethodback to summary
protected int 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.

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).

normalizedIntervalsback to summary
private float[] normalizedIntervals

Normalized intervals array.

transparencyTestback to summary
private int transparencyTest

Used to determine if gradient colors are all opaque.

Constructor Detail

MultipleGradientContextback to summary
protected MultipleGradientContext(Gradient mgp, BaseTransform t, float[] fractions, Color[] colors, int cycleMethod)

Constructor for MultipleGradientContext 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

fillRasterback to summary
protected abstract void fillRaster(int[] pixels, int off, int adjust, int x, int y, int w, int h)
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