Package com.jhlabs.image
Class ArrayColormap
- java.lang.Object
-
- com.jhlabs.image.ArrayColormap
-
- All Implemented Interfaces:
Colormap
,java.lang.Cloneable
- Direct Known Subclasses:
Gradient
,SplineColormap
public class ArrayColormap extends java.lang.Object implements Colormap, java.lang.Cloneable
A colormap implemented with an array of colors. This corresponds to the IndexColorModel class.
-
-
Field Summary
Fields Modifier and Type Field Description protected int[]
map
The array of colors.
-
Constructor Summary
Constructors Constructor Description ArrayColormap()
Construct an all-black colormap.ArrayColormap(int[] map)
Construct a colormap with the given map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
int
getColor(float v)
Convert a value in the range 0..1 to an RGB color.int[]
getMap()
Get the array of colors for the colormap.void
setColor(int index, int color)
Set one element of the colormap to a given color.void
setColorInterpolated(int index, int firstIndex, int lastIndex, int color)
Set the color at "index" to "color".void
setColorRange(int firstIndex, int lastIndex, int color)
Set a range of the colormap to a single color.void
setColorRange(int firstIndex, int lastIndex, int color1, int color2)
Set a range of the colormap, interpolating between two colors.void
setMap(int[] map)
Set the array of colors for the colormap.
-
-
-
Method Detail
-
clone
public java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
setMap
public void setMap(int[] map)
Set the array of colors for the colormap.- Parameters:
map
- the colors- See Also:
getMap()
-
getMap
public int[] getMap()
Get the array of colors for the colormap.- Returns:
- the colors
- See Also:
setMap(int[])
-
getColor
public int getColor(float v)
Convert a value in the range 0..1 to an RGB color.- Specified by:
getColor
in interfaceColormap
- Parameters:
v
- a value in the range 0..1- Returns:
- an RGB color
- See Also:
setColor(int, int)
-
setColorInterpolated
public void setColorInterpolated(int index, int firstIndex, int lastIndex, int color)
Set the color at "index" to "color". Entries are interpolated linearly from the existing entries at "firstIndex" and "lastIndex" to the new entry. firstIndex < index < lastIndex must hold.- Parameters:
index
- the position to setfirstIndex
- the position of the first color from which to interpolatelastIndex
- the position of the second color from which to interpolatecolor
- the color to set
-
setColorRange
public void setColorRange(int firstIndex, int lastIndex, int color1, int color2)
Set a range of the colormap, interpolating between two colors.- Parameters:
firstIndex
- the position of the first colorlastIndex
- the position of the second colorcolor1
- the first colorcolor2
- the second color
-
setColorRange
public void setColorRange(int firstIndex, int lastIndex, int color)
Set a range of the colormap to a single color.- Parameters:
firstIndex
- the position of the first colorlastIndex
- the position of the second colorcolor
- the color
-
setColor
public void setColor(int index, int color)
Set one element of the colormap to a given color.- Parameters:
index
- the position of the colorcolor
- the color- See Also:
getColor(float)
-
-