com.jhlabs.image
Class Gradient

java.lang.Object
  extended by com.jhlabs.image.ArrayColormap
      extended by com.jhlabs.image.Gradient
All Implemented Interfaces:
Colormap, java.lang.Cloneable

public class Gradient
extends ArrayColormap
implements java.lang.Cloneable

A Colormap implemented using Catmull-Rom colour splines. The map has a variable number of knots with a minimum of four. The first and last knots give the tangent at the end of the spline, and colours are interpolated from the second to the second-last knots. Each knot can be given a type of interpolation. These are:


Field Summary
static int CIRCLE_DOWN
          Interpolate with a falling circle shape curve.
static int CIRCLE_UP
          Interpolate with a rising circle shape curve.
static int CONSTANT
          Don't tnterpolate - just use the starting value.
static int HUE_CCW
          Interpolate hue counter clockwise.
static int HUE_CW
          Interpolate hue clockwise.
static int LINEAR
          Interpolate linearly.
static int RGB
          Interpolate in RGB space.
static int SPLINE
          Interpolate using a spline.
 
Fields inherited from class com.jhlabs.image.ArrayColormap
map
 
Constructor Summary
Gradient()
          Construct a Gradient.
Gradient(int[] rgb)
          Construct a Gradient with the given colors.
Gradient(int[] x, int[] rgb)
          Construct a Gradient with the given colors and knot positions.
Gradient(int[] x, int[] rgb, byte[] types)
          Construct a Gradient with the given colors, knot positions and interpolation types.
 
Method Summary
 void addKnot(int x, int color, int type)
          Add a new knot.
 java.lang.Object clone()
           
 void copyTo(Gradient g)
          Copy one Gradient into another.
 int getKnot(int n)
          Get a knot color.
 byte getKnotBlend(int n)
          Get a knot blend type.
 int getKnotPosition(int n)
          Get a knot position.
 int getKnotType(int n)
          Get a knot type.
 int getNumKnots()
          Get the number of knots in the gradient.
 int knotAt(int x)
          Return the knot at a given position.
 void mutate(float amount)
          Mutate the gradient.
static Gradient randomGradient()
          Build a random gradient.
 void randomize()
          Randomize the gradient.
 void removeKnot(int n)
          Remove a knot.
 void setColor(int n, int color)
          Set a knot color.
 void setKnot(int n, int color)
          Set a knot color.
 void setKnotBlend(int n, int type)
          Set a knot blend type.
 void setKnotPosition(int n, int x)
          Set a knot position.
 void setKnots(int[] x, int[] rgb, byte[] types)
          Set the values of all the knots.
 void setKnots(int[] x, int[] y, byte[] types, int offset, int count)
          Set the values of a set of knots.
 void setKnotType(int n, int type)
          Set a knot type.
 void splitSpan(int n)
          Split a span into two by adding a knot in the middle.
 
Methods inherited from class com.jhlabs.image.ArrayColormap
getColor, getMap, setColorInterpolated, setColorRange, setColorRange, setMap
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RGB

public static final int RGB
Interpolate in RGB space.

See Also:
Constant Field Values

HUE_CW

public static final int HUE_CW
Interpolate hue clockwise.

See Also:
Constant Field Values

HUE_CCW

public static final int HUE_CCW
Interpolate hue counter clockwise.

See Also:
Constant Field Values

LINEAR

public static final int LINEAR
Interpolate linearly.

See Also:
Constant Field Values

SPLINE

public static final int SPLINE
Interpolate using a spline.

See Also:
Constant Field Values

CIRCLE_UP

public static final int CIRCLE_UP
Interpolate with a rising circle shape curve.

See Also:
Constant Field Values

CIRCLE_DOWN

public static final int CIRCLE_DOWN
Interpolate with a falling circle shape curve.

See Also:
Constant Field Values

CONSTANT

public static final int CONSTANT
Don't tnterpolate - just use the starting value.

See Also:
Constant Field Values
Constructor Detail

Gradient

public Gradient()
Construct a Gradient.


Gradient

public Gradient(int[] rgb)
Construct a Gradient with the given colors.

Parameters:
rgb - the colors

Gradient

public Gradient(int[] x,
                int[] rgb)
Construct a Gradient with the given colors and knot positions.

Parameters:
x - the knot positions
rgb - the colors

Gradient

public Gradient(int[] x,
                int[] rgb,
                byte[] types)
Construct a Gradient with the given colors, knot positions and interpolation types.

Parameters:
x - the knot positions
rgb - the colors
types - interpolation types
Method Detail

clone

public java.lang.Object clone()
Overrides:
clone in class ArrayColormap

copyTo

public void copyTo(Gradient g)
Copy one Gradient into another.

Parameters:
g - the Gradient to copy into

setColor

public void setColor(int n,
                     int color)
Set a knot color.

Overrides:
setColor in class ArrayColormap
Parameters:
n - the knot index
color - the color
See Also:
ArrayColormap.getColor(float)

getNumKnots

public int getNumKnots()
Get the number of knots in the gradient.

Returns:
the number of knots.

setKnot

public void setKnot(int n,
                    int color)
Set a knot color.

Parameters:
n - the knot index
color - the color
See Also:
getKnot(int)

getKnot

public int getKnot(int n)
Get a knot color.

Parameters:
n - the knot index
Returns:
the knot color
See Also:
setKnot(int, int)

setKnotType

public void setKnotType(int n,
                        int type)
Set a knot type.

Parameters:
n - the knot index
type - the type
See Also:
getKnotType(int)

getKnotType

public int getKnotType(int n)
Get a knot type.

Parameters:
n - the knot index
Returns:
the knot type
See Also:
setKnotType(int, int)

setKnotBlend

public void setKnotBlend(int n,
                         int type)
Set a knot blend type.

Parameters:
n - the knot index
type - the knot blend type
See Also:
getKnotBlend(int)

getKnotBlend

public byte getKnotBlend(int n)
Get a knot blend type.

Parameters:
n - the knot index
Returns:
the knot blend type
See Also:
setKnotBlend(int, int)

addKnot

public void addKnot(int x,
                    int color,
                    int type)
Add a new knot.

Parameters:
x - the knot position
color - the color
type - the knot type
See Also:
removeKnot(int)

removeKnot

public void removeKnot(int n)
Remove a knot.

Parameters:
n - the knot index
See Also:
addKnot(int, int, int)

setKnots

public void setKnots(int[] x,
                     int[] rgb,
                     byte[] types)
Set the values of all the knots. This version does not require the "extra" knots at -1 and 256

Parameters:
x - the knot positions
rgb - the knot colors
types - the knot types

setKnots

public void setKnots(int[] x,
                     int[] y,
                     byte[] types,
                     int offset,
                     int count)
Set the values of a set of knots.

Parameters:
x - the knot positions
y - the knot colors
types - the knot types
offset - the first knot to set
count - the number of knots

splitSpan

public void splitSpan(int n)
Split a span into two by adding a knot in the middle.

Parameters:
n - the span index

setKnotPosition

public void setKnotPosition(int n,
                            int x)
Set a knot position.

Parameters:
n - the knot index
x - the knot position
See Also:
setKnotPosition(int, int)

getKnotPosition

public int getKnotPosition(int n)
Get a knot position.

Parameters:
n - the knot index
Returns:
the knot position
See Also:
setKnotPosition(int, int)

knotAt

public int knotAt(int x)
Return the knot at a given position.

Parameters:
x - the position
Returns:
the knot number, or 1 if no knot found

randomize

public void randomize()
Randomize the gradient.


mutate

public void mutate(float amount)
Mutate the gradient.

Parameters:
amount - the amount in the range zero to one

randomGradient

public static Gradient randomGradient()
Build a random gradient.

Returns:
the new Gradient