Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.batik.ext.awt
Class LinearGradientPaintContext  view LinearGradientPaintContext download LinearGradientPaintContext.java

java.lang.Object
  extended byorg.apache.batik.ext.awt.MultipleGradientPaintContext
      extended byorg.apache.batik.ext.awt.LinearGradientPaintContext
All Implemented Interfaces:
java.awt.PaintContext

final class LinearGradientPaintContext
extends MultipleGradientPaintContext

Provides the actual implementation for the LinearGradientPaint This is where the pixel processing is done.

Version:
$Id: LinearGradientPaintContext.java,v 1.13 2005/03/27 08:58:32 cam Exp $

Field Summary
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.
private static int ANTI_ALIAS_IMPL
           
protected static java.lang.ref.WeakReference cached
          The cached raster, which is reusable among instances
protected static java.awt.image.ColorModel cachedModel
          The cached colorModel
protected  MultipleGradientPaint.ColorSpaceEnum colorSpace
          The colorSpace in which to perform the interpolation
protected  MultipleGradientPaint.CycleMethodEnum cycleMethod
          The method to use when painting out of the gradient bounds.
protected  java.awt.image.ColorModel dataModel
          The color model data is generated in (always un premult).
protected static boolean DEBUG
           
private static int DEFAULT_IMPL
           
private  float dgdX
          The following invariants are used to process the gradient value from a device space coordinate, (X, Y): g(X, Y) = dgdX*X + dgdY*Y + gc
private  float dgdY
          The following invariants are used to process the gradient value from a device space coordinate, (X, Y): g(X, Y) = dgdX*X + dgdY*Y + gc
protected  int fastGradientArraySize
          Size of gradients array for scaling the 0-1 index when looking up colors the fast way.
private  int fillMethod
           
protected  float[] fractions
          fractions array
private  float gc
          The following invariants are used to process the gradient value from a device space coordinate, (X, Y): g(X, Y) = dgdX*X + dgdY*Y + gc
protected  int[] gradient
          Array which contains the interpolated color values for each interval, used by calculateSingleArrayGradient().
protected static int GRADIENT_SIZE
          Constant number of max colors between any 2 arbitrary colors.
protected static int GRADIENT_SIZE_INDEX
           
protected  int gradientAverage
          This holds the blend of all colors in the gradient.
protected  int gradientOverflow
          This holds the color to use when we are off the top of the gradient
protected  int[][] gradients
          Array of gradient arrays, one array for each interval.
protected  int gradientsLength
          Length of the 2D slow lookup gradients array.
protected  int gradientUnderflow
          This holds the color to use when we are off the bottom of the gradient
protected  boolean hasDiscontinuity
          This boolean indicates if the gradient appears to have sudden discontinuities in it, this may be because of multiple stops at the same location or use of the REPEATE mode.
protected  boolean isSimpleLookup
          This boolean specifies wether 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.
protected  java.awt.image.ColorModel model
          PaintContext's output ColorModel ARGB if colors are not all opaque, RGB otherwise.
protected  float[] normalizedIntervals
          Normalized intervals array
private  float pixSz
          The following invariants are used to process the gradient value from a device space coordinate, (X, Y): g(X, Y) = dgdX*X + dgdY*Y + gc
protected  java.awt.image.WritableRaster saved
          Raster is reused whenever possible
 
Constructor Summary
LinearGradientPaintContext(java.awt.image.ColorModel cm, java.awt.Rectangle deviceBounds, java.awt.geom.Rectangle2D userBounds, java.awt.geom.AffineTransform t, java.awt.RenderingHints hints, java.awt.geom.Point2D dStart, java.awt.geom.Point2D dEnd, float[] fractions, java.awt.Color[] colors, MultipleGradientPaint.CycleMethodEnum cycleMethod, MultipleGradientPaint.ColorSpaceEnum colorSpace)
          Constructor for LinearGradientPaintContext.
 
Method Summary
protected  void calculateGradientFractions(java.awt.Color[] loColors, java.awt.Color[] hiColors)
          This function is the meat of this class.
 void dispose()
          Release the resources allocated for the operation.
protected  void fillHardNoCycle(int[] pixels, int off, int adjust, int x, int y, int w, int h)
           
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.
protected  void fillSimpleNoCycle(int[] pixels, int off, int adjust, int x, int y, int w, int h)
           
protected  void fillSimpleReflect(int[] pixels, int off, int adjust, int x, int y, int w, int h)
           
protected  void fillSimpleRepeat(int[] pixels, int off, int adjust, int x, int y, int w, int h)
           
protected static java.awt.image.WritableRaster getCachedRaster(java.awt.image.ColorModel cm, int w, int h)
          Took this cacheRaster code from GradientPaint.
 java.awt.image.ColorModel getColorModel()
          Return the ColorModel of the output.
 java.awt.image.Raster getRaster(int x, int y, int w, int h)
          Superclass getRaster...
protected  int indexGradientAntiAlias(float position, float sz)
          Helper function to index into the gradients array.
protected  int indexIntoGradientsArrays(float position)
          Helper function to index into the gradients array.
protected static void putCachedRaster(java.awt.image.ColorModel cm, java.awt.image.WritableRaster ras)
          Took this cacheRaster code from GradientPaint.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dgdX

private float dgdX
The following invariants are used to process the gradient value from a device space coordinate, (X, Y): g(X, Y) = dgdX*X + dgdY*Y + gc


dgdY

private float dgdY
The following invariants are used to process the gradient value from a device space coordinate, (X, Y): g(X, Y) = dgdX*X + dgdY*Y + gc


gc

private float gc
The following invariants are used to process the gradient value from a device space coordinate, (X, Y): g(X, Y) = dgdX*X + dgdY*Y + gc


pixSz

private float pixSz
The following invariants are used to process the gradient value from a device space coordinate, (X, Y): g(X, Y) = dgdX*X + dgdY*Y + gc


DEFAULT_IMPL

private static final int DEFAULT_IMPL
See Also:
Constant Field Values

ANTI_ALIAS_IMPL

private static final int ANTI_ALIAS_IMPL
See Also:
Constant Field Values

fillMethod

private int fillMethod

DEBUG

protected static final boolean DEBUG
See Also:
Constant Field Values

dataModel

protected java.awt.image.ColorModel dataModel
The color model data is generated in (always un premult).


model

protected java.awt.image.ColorModel model
PaintContext's output ColorModel ARGB if colors are not all opaque, RGB otherwise. Linear and premult are matched to output ColorModel.


cachedModel

protected static java.awt.image.ColorModel cachedModel
The cached colorModel


cached

protected static java.lang.ref.WeakReference cached
The cached raster, which is reusable among instances


saved

protected java.awt.image.WritableRaster saved
Raster is reused whenever possible


cycleMethod

protected MultipleGradientPaint.CycleMethodEnum cycleMethod
The method to use when painting out of the gradient bounds.


colorSpace

protected MultipleGradientPaint.ColorSpaceEnum colorSpace
The colorSpace in which to perform the interpolation


a00

protected float a00
Elements of the inverse transform matrix.


a01

protected float a01
Elements of the inverse transform matrix.


a10

protected float a10
Elements of the inverse transform matrix.


a11

protected float a11
Elements of the inverse transform matrix.


a02

protected float a02
Elements of the inverse transform matrix.


a12

protected float a12
Elements of the inverse transform matrix.


isSimpleLookup

protected boolean isSimpleLookup
This boolean specifies wether 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.


hasDiscontinuity

protected boolean hasDiscontinuity
This boolean indicates if the gradient appears to have sudden discontinuities in it, this may be because of multiple stops at the same location or use of the REPEATE mode.


fastGradientArraySize

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


gradient

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.


gradients

protected int[][] gradients
Array of gradient arrays, one array for each interval. Used by calculateMultipleArrayGradient().


gradientAverage

protected int gradientAverage
This holds the blend of all colors in the gradient. we use this at extreamly low resolutions to ensure we get a decent blend of the colors.


gradientUnderflow

protected int gradientUnderflow
This holds the color to use when we are off the bottom of the gradient


gradientOverflow

protected int gradientOverflow
This holds the color to use when we are off the top of the gradient


gradientsLength

protected int gradientsLength
Length of the 2D slow lookup gradients array.


normalizedIntervals

protected float[] normalizedIntervals
Normalized intervals array


fractions

protected float[] fractions
fractions array


GRADIENT_SIZE

protected static final int GRADIENT_SIZE
Constant number of max colors between any 2 arbitrary colors. Used for creating and indexing gradients arrays.

See Also:
Constant Field Values

GRADIENT_SIZE_INDEX

protected static final int GRADIENT_SIZE_INDEX
See Also:
Constant Field Values
Constructor Detail

LinearGradientPaintContext

public LinearGradientPaintContext(java.awt.image.ColorModel cm,
                                  java.awt.Rectangle deviceBounds,
                                  java.awt.geom.Rectangle2D userBounds,
                                  java.awt.geom.AffineTransform t,
                                  java.awt.RenderingHints hints,
                                  java.awt.geom.Point2D dStart,
                                  java.awt.geom.Point2D dEnd,
                                  float[] fractions,
                                  java.awt.Color[] colors,
                                  MultipleGradientPaint.CycleMethodEnum cycleMethod,
                                  MultipleGradientPaint.ColorSpaceEnum colorSpace)
                           throws java.awt.geom.NoninvertibleTransformException
Constructor for LinearGradientPaintContext.

Method Detail

fillHardNoCycle

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

fillSimpleNoCycle

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

fillSimpleRepeat

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

fillSimpleReflect

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

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. This is where the area is filled with colors distributed linearly.

Specified by:
fillRaster in class MultipleGradientPaintContext

calculateGradientFractions

protected final void calculateGradientFractions(java.awt.Color[] loColors,
                                                java.awt.Color[] hiColors)
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.


indexIntoGradientsArrays

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.


indexGradientAntiAlias

protected final int indexGradientAntiAlias(float position,
                                           float sz)
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. This version also does anti-aliasing by averaging the gradient over position+/-(sz/2).


getRaster

public final java.awt.image.Raster getRaster(int x,
                                             int y,
                                             int w,
                                             int h)
Superclass getRaster...

Specified by:
getRaster in interface java.awt.PaintContext

getCachedRaster

protected static final java.awt.image.WritableRaster getCachedRaster(java.awt.image.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.


putCachedRaster

protected static final void putCachedRaster(java.awt.image.ColorModel cm,
                                            java.awt.image.WritableRaster 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.


dispose

public final void dispose()
Release the resources allocated for the operation.

Specified by:
dispose in interface java.awt.PaintContext

getColorModel

public final java.awt.image.ColorModel getColorModel()
Return the ColorModel of the output.

Specified by:
getColorModel in interface java.awt.PaintContext