|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.geotools.resources.image.ColorUtilities
public final class ColorUtilities
A set of static methods for handling of colors informations. Some of those methods are useful, but not really rigorous. This is why they do not appear in any "official" package, but instead in this private one. Do not rely on this API! It may change in incompatible way in any future version.
Method Summary | |
---|---|
static float |
colorDistance(float[] lab1,
float[] lab2)
Computes the distance E (CIE 1994) between two colors in LAB color space. |
static void |
expand(java.awt.Color[] colors,
int[] ARGB,
int lower,
int upper)
Copies colors into array ARGB from index lower
inclusive to index upper exclusive. |
static int |
findColorIndex(java.awt.Color bgColor,
java.awt.image.IndexColorModel icm)
Looks for the specified color in the color model |
static int |
getBitCount(int mapSize)
Returns a bit count for an IndexColorModel mapping mapSize colors. |
static int |
getColorIndex(java.awt.image.IndexColorModel colors,
java.awt.Color color,
int exclude)
Returns the index of the specified color, excluding the specified one. |
static java.awt.image.IndexColorModel |
getIndexColorModel(int[] ARGB)
Returns an index color model for specified ARGB codes. |
static java.awt.image.IndexColorModel |
getIndexColorModel(int[] ARGB,
int numBands,
int visibleBand)
Returns a tolerant index color model for the specified ARGB code. |
static int |
getIntFromColor(int r,
int g,
int b,
int a)
Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255). |
static double |
getMaximum(int dataType)
Provide the maximum allowe value for a certain data type. |
static double |
getMinimum(int dataType)
Provide the minimum allowe value for a certain data type. |
static int |
getNumBands(java.awt.image.ColorModel model)
Tries to guess the number of bands from the specified color model. |
static double |
getThreshold(int dataType)
Returns a suitable threshold depending on the DataBuffer type. |
static int |
getTransferType(int mapSize)
Returns a suggered type for an IndexColorModel
of mapSize colors. |
static int |
getTransparentPixel(java.awt.image.IndexColorModel colors)
Returns the most transparent pixel in the specified color model. |
static boolean |
isGrayPalette(java.awt.image.IndexColorModel icm,
boolean ignoreTransparents)
Tells us if a specific IndexColorModel contains only gray color
or not, ignoring alpha information. |
static int |
roundByte(double value)
Rounds a float value and clamp the result between 0 and 255 inclusive. |
static java.awt.Color[] |
subarray(java.awt.Color[] palette,
int lower,
int upper)
Returns a subarray of the specified color array. |
static float[] |
XYZtoLAB(float[] color)
Transforms a color from XYZ color space to LAB. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static int getIntFromColor(int r, int g, int b, int a)
r
- the red componentg
- the green componentb
- the blue componenta
- the alpha component
java.lang.IllegalArgumentException
- if , g
, b
or a
are outside of the range 0 to 255, inclusive.public static java.awt.Color[] subarray(java.awt.Color[] palette, int lower, int upper)
lower
and
upper
index will be clamb into the palette
range.
If they are completly out of range, or if they would result in an empty array,
then null
is returned.
This method is used by org.geotools.cv.SampleDimension
as an heuristic
approach for distributing palette colors into a list of categories.
palette
- The color array (may be null
).lower
- The lower index, inclusive.upper
- The upper index, inclusive.
palette
if the original array already fit),
or null
if the lower
and upper
index
are out of palette
bounds.public static void expand(java.awt.Color[] colors, int[] ARGB, int lower, int upper)
colors
into array ARGB
from index lower
inclusive to index upper
exclusive. If upper-lower
is not
equals to the length of colors
array, then colors will be interpolated.
Note: Profiling shows that this method is a "hot spot". It needs to be fast, which is why the implementation is not as straight-forward as it could.
colors
- Colors to copy into the ARGB
array.ARGB
- Array of integer to write ARGB values to.lower
- Index (inclusive) of the first element of ARGB
to change.upper
- Index (exclusive) of the last element of ARGB
to change.public static int roundByte(double value)
public static java.awt.image.IndexColorModel getIndexColorModel(int[] ARGB)
ARGB
- An array of ARGB values.
public static java.awt.image.IndexColorModel getIndexColorModel(int[] ARGB, int numBands, int visibleBand)
ARGB
- An array of ARGB values.numBands
- The number of bands.visibleBand
- The band to display.
public static int getBitCount(int mapSize)
IndexColorModel
mapping mapSize
colors.
It is guaranteed that the following relation is hold:
(1 << getBitCount(mapSize)) >= mapSize
public static int getTransferType(int mapSize)
IndexColorModel
of mapSize
colors. This method returns
DataBuffer.TYPE_BYTE
or DataBuffer.TYPE_USHORT
.
public static float[] XYZtoLAB(float[] color)
color
for convenience.
Reference: http://www.brucelindbloom.com/index.html?ColorDifferenceCalc.html
public static float colorDistance(float[] lab1, float[] lab2)
public static int getTransparentPixel(java.awt.image.IndexColorModel colors)
colors
- The color model in which to look for a transparent color.
public static int getColorIndex(java.awt.image.IndexColorModel colors, java.awt.Color color, int exclude)
colors
- The color model in which to look for a color index.color
- The color to search for.exclude
- An index to exclude from the search (usually the background or the
transparent pixel), or -1 if none.
public static int getNumBands(java.awt.image.ColorModel model)
SampleModel.getNumBands()
. This method should be used only
as a fallback when the sample model is not available. This method uses some heuristic rules
for guessing the number of bands, so the return value may not be exact in all cases.
public static boolean isGrayPalette(java.awt.image.IndexColorModel icm, boolean ignoreTransparents)
IndexColorModel
contains only gray color
or not, ignoring alpha information.
icm
- IndexColorModel
to be inspected.ignoreTransparents
- true
if the RGB values of fully transparent pixels
(the ones with an alpha value of 0)
should not be taken in account during the check for gray color.
true
if the palette is grayscale, false
otherwise.public static double getMinimum(int dataType)
dataType
- the data type to suggest a maximum value for.
public static double getThreshold(int dataType)
DataBuffer
type.
Remember that the threshold works with >=.
dataType
- to create a low threshold for.
public static int findColorIndex(java.awt.Color bgColor, java.awt.image.IndexColorModel icm)
bgColor
- The color to be searchedicm
- The color model to be searched into
public static double getMaximum(int dataType)
dataType
- the data type to suggest a maximum value for.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |