org.geotools.resources.image
Class ColorUtilities

java.lang.Object
  extended byorg.geotools.resources.image.ColorUtilities

public final class ColorUtilities
extends java.lang.Object

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.

Since:
2.0
Version:
$Id: ColorUtilities.java 18160 2006-02-22 03:19:53Z desruisseaux $
Author:
Martin Desruisseaux

Method Summary
static void expand(java.awt.Color[] colors, int[] ARGB, int lower, int upper)
          Copy into array from index inclusive to index exclusive.
static int getBitCount(int mapSize)
          Returns a bit count for an IndexColorModel mapping 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 getNumBands(java.awt.image.ColorModel model)
          Tries to guess the number of bands from the specified color model.
static int getTransparentPixel(java.awt.image.IndexColorModel colors)
          Returns the most transparent pixel in the specified color model.
static java.awt.Color[] subarray(java.awt.Color[] palette, int lower, int upper)
          Returns a subarray of the specified color array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

subarray

public static java.awt.Color[] subarray(java.awt.Color[] palette,
                                        int lower,
                                        int upper)
Returns a subarray of the specified color array. The and index will be clamb into the range. If they are completly out of range, or if they would result in an empty array, then is returned. This method is used by SampleDimension as an heuristic approach for distributing palette colors into a list of categories.

Parameters:
palette - The color array (may be ).
lower - The lower index, inclusive.
upper - The upper index, inclusive.
Returns:
The subarray (may be if the original array already fit), or if the and index are out of bounds.

expand

public static void expand(java.awt.Color[] colors,
                          int[] ARGB,
                          int lower,
                          int upper)
Copy into array from index inclusive to index exclusive. If is not equals to the length of array, then colors will be interpolated.

Parameters:
colors - Colors to copy into the array.
ARGB - Array of integer to write ARGB values to.
lower - Index (inclusive) of the first element of to change.
upper - Index (exclusive) of the last element of to change.

getIndexColorModel

public static java.awt.image.IndexColorModel getIndexColorModel(int[] ARGB)
Returns an index color model for specified ARGB codes. If the specified array has not transparent color (i.e. all alpha values are 255), then the returned color model will be opaque. Otherwise, if the specified array has one and only one color with alpha value of 0, the returned color model will have only this transparent color. Otherwise, the returned color model will be translucide.

Parameters:
ARGB - An array of ARGB values.
Returns:
An index color model for the specified array.

getIndexColorModel

public static java.awt.image.IndexColorModel getIndexColorModel(int[] ARGB,
                                                                int numBands,
                                                                int visibleBand)
Returns a tolerant index color model for the specified ARGB code. This color model accept image with the specified number of bands.

Parameters:
ARGB - An array of ARGB values.
numBands - The number of bands.
visibleBand - The band to display.
Returns:
An index color model for the specified array.

getBitCount

public static int getBitCount(int mapSize)
Returns a bit count for an IndexColorModel mapping colors. It is guaranteed that the following relation is hold:
(1 << getBitCount(mapSize)) >= mapSize


getTransparentPixel

public static int getTransparentPixel(java.awt.image.IndexColorModel colors)
Returns the most transparent pixel in the specified color model. If many colors has the same alpha value, than the darkest one is returned. This method never returns a negative value (0 is returned if the color model has no colors).

Parameters:
colors - The color model in which to look for a transparent color.
Returns:
The index of a transparent color, or 0.

getColorIndex

public 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. If the color is not explicitly found, a close color is returned. This method never returns a negative value (0 is returned if the color model has no colors).

Parameters:
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.
Returns:
The index of the color, or 0.

getNumBands

public static int getNumBands(java.awt.image.ColorModel model)
Tries to guess the number of bands from the specified color model. The recommanded approach is to invoke 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.



Copyright © GeoTools. All Rights Reserved.