com.jhlabs.image

Class Gradient

Implemented Interfaces:
Cloneable, Colormap

public class Gradient
extends ArrayColormap
implements 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.
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
setKnotType(int n, int type)
Set a knot type.
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
splitSpan(int n)
Split a span into two by adding a knot in the middle.

Methods inherited from class com.jhlabs.image.ArrayColormap

clone, getColor, getMap, setColor, setColorInterpolated, setColorRange, setColorRange, setMap

Field Details

CIRCLE_DOWN

public static final int CIRCLE_DOWN
Interpolate with a falling circle shape curve.
Field Value:
64

CIRCLE_UP

public static final int CIRCLE_UP
Interpolate with a rising circle shape curve.
Field Value:
48

CONSTANT

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

HUE_CCW

public static final int HUE_CCW
Interpolate hue counter clockwise.
Field Value:
2

HUE_CW

public static final int HUE_CW
Interpolate hue clockwise.
Field Value:
1

LINEAR

public static final int LINEAR
Interpolate linearly.
Field Value:
16

RGB

public static final int RGB
Interpolate in RGB space.
Field Value:
0

SPLINE

public static final int SPLINE
Interpolate using a spline.
Field Value:
32

Constructor Details

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 Details

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

clone

public Object clone()
Overrides:
clone in interface ArrayColormap

copyTo

public void copyTo(Gradient g)
Copy one Gradient into another.
Parameters:
g - the Gradient to copy into

getKnot

public int getKnot(int n)
Get a knot color.
Parameters:
n - the knot index
Returns:
the knot color

getKnotBlend

public byte getKnotBlend(int n)
Get a knot blend type.
Parameters:
n - the knot index
Returns:
the knot blend type

getKnotPosition

public int getKnotPosition(int n)
Get a knot position.
Parameters:
n - the knot index
Returns:
the knot position

getKnotType

public int getKnotType(int n)
Get a knot type.
Parameters:
n - the knot index
Returns:
the knot type

getNumKnots

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

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

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

randomize

public void randomize()
Randomize the gradient.

removeKnot

public void removeKnot(int n)
Remove a knot.
Parameters:
n - the knot index

setColor

public void setColor(int n,
                     int color)
Set a knot color.
Overrides:
setColor in interface ArrayColormap
Parameters:
n - the knot index
color - the color

setKnot

public void setKnot(int n,
                    int color)
Set a knot color.
Parameters:
n - the knot index
color - the color

setKnotBlend

public void setKnotBlend(int n,
                         int type)
Set a knot blend type.
Parameters:
n - the knot index
type - the knot blend type

setKnotPosition

public void setKnotPosition(int n,
                            int x)
Set a knot position.
Parameters:
n - the knot index
x - the knot position

setKnotType

public void setKnotType(int n,
                        int type)
Set a knot type.
Parameters:
n - the knot index
type - the type

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