Package com.jhlabs.image
Class Gradient
java.lang.Object
com.jhlabs.image.ArrayColormap
com.jhlabs.image.Gradient
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:
- LINEAR - linear interpolation to next knot
- SPLINE - spline interpolation to next knot
- CONSTANT - no interpolation - the colour is constant to the next knot
- HUE_CW - interpolation of hue clockwise to next knot
- HUE_CCW - interpolation of hue counter-clockwise to next knot
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Interpolate with a falling circle shape curve.static final int
Interpolate with a rising circle shape curve.static final int
Don't tnterpolate - just use the starting value.static final int
Interpolate hue counter clockwise.static final int
Interpolate hue clockwise.static final int
Interpolate linearly.static final int
Interpolate in RGB space.static final int
Interpolate using a spline.Fields inherited from class com.jhlabs.image.ArrayColormap
map
-
Constructor Summary
ConstructorsConstructorDescriptionGradient()
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
Modifier and TypeMethodDescriptionvoid
addKnot
(int x, int color, int type) Add a new knot.clone()
void
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
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
Build a random gradient.void
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
-
Field Details
-
RGB
public static final int RGBInterpolate in RGB space.- See Also:
-
HUE_CW
public static final int HUE_CWInterpolate hue clockwise.- See Also:
-
HUE_CCW
public static final int HUE_CCWInterpolate hue counter clockwise.- See Also:
-
LINEAR
public static final int LINEARInterpolate linearly.- See Also:
-
SPLINE
public static final int SPLINEInterpolate using a spline.- See Also:
-
CIRCLE_UP
public static final int CIRCLE_UPInterpolate with a rising circle shape curve.- See Also:
-
CIRCLE_DOWN
public static final int CIRCLE_DOWNInterpolate with a falling circle shape curve.- See Also:
-
CONSTANT
public static final int CONSTANTDon't tnterpolate - just use the starting value.- See Also:
-
-
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 positionsrgb
- 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 positionsrgb
- the colorstypes
- interpolation types
-
-
Method Details
-
clone
- Overrides:
clone
in classArrayColormap
-
copyTo
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 classArrayColormap
- Parameters:
n
- the knot indexcolor
- the color- See Also:
-
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 indexcolor
- the color- See Also:
-
getKnot
public int getKnot(int n) Get a knot color.- Parameters:
n
- the knot index- Returns:
- the knot color
- See Also:
-
setKnotType
public void setKnotType(int n, int type) Set a knot type.- Parameters:
n
- the knot indextype
- the type- See Also:
-
getKnotType
public int getKnotType(int n) Get a knot type.- Parameters:
n
- the knot index- Returns:
- the knot type
- See Also:
-
setKnotBlend
public void setKnotBlend(int n, int type) Set a knot blend type.- Parameters:
n
- the knot indextype
- the knot blend type- See Also:
-
getKnotBlend
public byte getKnotBlend(int n) Get a knot blend type.- Parameters:
n
- the knot index- Returns:
- the knot blend type
- See Also:
-
addKnot
public void addKnot(int x, int color, int type) Add a new knot.- Parameters:
x
- the knot positioncolor
- the colortype
- the knot type- See Also:
-
removeKnot
public void removeKnot(int n) Remove a knot.- Parameters:
n
- the knot index- See Also:
-
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 positionsrgb
- the knot colorstypes
- 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 positionsy
- the knot colorstypes
- the knot typesoffset
- the first knot to setcount
- 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 indexx
- the knot position- See Also:
-
getKnotPosition
public int getKnotPosition(int n) Get a knot position.- Parameters:
n
- the knot index- Returns:
- the knot position
- See Also:
-
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
Build a random gradient.- Returns:
- the new Gradient
-