Package com.twelvemonkeys.image
Class InverseColorMapIndexColorModel
- java.lang.Object
-
- java.awt.image.ColorModel
-
- java.awt.image.IndexColorModel
-
- com.twelvemonkeys.image.InverseColorMapIndexColorModel
-
- All Implemented Interfaces:
java.awt.Transparency
public class InverseColorMapIndexColorModel extends java.awt.image.IndexColorModelA faster implementation ofIndexColorModel, that is backed by an inverse color-map, for fast look-ups.- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/image/InverseColorMapIndexColorModel.java#1 $
-
-
Field Summary
Fields Modifier and Type Field Description private static intALPHA_THRESHOLDprotected InverseColorMapinverseMapprotected intmapSizeprivate static intRGB_MASKprotected int[]rgbsprivate static intWHITEprivate intwhiteIndex
-
Constructor Summary
Constructors Modifier Constructor Description InverseColorMapIndexColorModel(int pNumBits, int pSize, byte[] pReds, byte[] pGreens, byte[] pBlues)Creates anInverseColorMapIndexColorModelfrom the given arrays of red, green, and blue components.InverseColorMapIndexColorModel(int pNumBits, int pSize, byte[] pReds, byte[] pGreens, byte[] pBlues, int pTransparentIndex)Creates anInverseColorMapIndexColorModelfrom the given arrays of red, green, and blue components, plus one transparent index.InverseColorMapIndexColorModel(int pNumBits, int pSize, int[] pRGBs, int pStart, boolean pAlpha, int pTransparentIndex, int pTransferType)Creates anInverseColorMapIndexColorModelfrom the given array of RGB components, plus one transparent index.InverseColorMapIndexColorModel(java.awt.image.IndexColorModel pColorModel)Creates anInverseColorMapIndexColorModelfrom an existingIndexColorModel.privateInverseColorMapIndexColorModel(java.awt.image.IndexColorModel pColorModel, int[] pRGBs)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.awt.image.IndexColorModelcreate(java.awt.Image pImage, int pNumCols, int pFlags)Creates anIndexColorModeloptimized for the givenImage.java.lang.ObjectgetDataElements(int rgb, java.lang.Object pixel)Returns a data element array representation of a pixel in this ColorModel, given an integer pixel representation in the default RGB color model.private static int[]getRGBs(java.awt.image.IndexColorModel pColorModel)Creates a defensive copy of the RGB color map in the givenIndexColorModel.private intgetWhiteIndex()private java.lang.Objectinstallpixel(java.lang.Object pixel, int pix)java.lang.StringtoString()-
Methods inherited from class java.awt.image.IndexColorModel
convertToIntDiscrete, createCompatibleSampleModel, createCompatibleWritableRaster, equals, finalize, getAlpha, getAlphas, getBlue, getBlues, getComponents, getComponents, getComponentSize, getDataElement, getDataElements, getGreen, getGreens, getMapSize, getRed, getReds, getRGB, getRGBs, getTransparency, getTransparentPixel, getValidPixels, hashCode, isCompatibleRaster, isCompatibleSampleModel, isValid, isValid
-
Methods inherited from class java.awt.image.ColorModel
coerceData, getAlpha, getAlphaRaster, getBlue, getColorSpace, getComponentSize, getDataElement, getDataElements, getGreen, getNormalizedComponents, getNormalizedComponents, getNumColorComponents, getNumComponents, getPixelSize, getRed, getRGB, getRGBdefault, getTransferType, getUnnormalizedComponents, hasAlpha, isAlphaPremultiplied
-
-
-
-
Field Detail
-
rgbs
protected int[] rgbs
-
mapSize
protected int mapSize
-
inverseMap
protected InverseColorMap inverseMap
-
ALPHA_THRESHOLD
private static final int ALPHA_THRESHOLD
- See Also:
- Constant Field Values
-
whiteIndex
private int whiteIndex
-
WHITE
private static final int WHITE
- See Also:
- Constant Field Values
-
RGB_MASK
private static final int RGB_MASK
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
InverseColorMapIndexColorModel
public InverseColorMapIndexColorModel(java.awt.image.IndexColorModel pColorModel)
Creates anInverseColorMapIndexColorModelfrom an existingIndexColorModel.- Parameters:
pColorModel- the color model to create from.- Throws:
java.lang.IllegalArgumentException- ifpColorModelisnull
-
InverseColorMapIndexColorModel
private InverseColorMapIndexColorModel(java.awt.image.IndexColorModel pColorModel, int[] pRGBs)
-
InverseColorMapIndexColorModel
public InverseColorMapIndexColorModel(int pNumBits, int pSize, int[] pRGBs, int pStart, boolean pAlpha, int pTransparentIndex, int pTransferType)Creates anInverseColorMapIndexColorModelfrom the given array of RGB components, plus one transparent index.- Parameters:
pNumBits- the number of bits each pixel occupiespSize- the size of the color component arrayspRGBs- the array of packed RGB color componentspStart- the starting offset of the first color componentpAlpha- indicates whether alpha values are contained inpRGBspTransparentIndex- the index of the transparent pixelpTransferType- the data type of the array used to represent pixels- Throws:
java.lang.IllegalArgumentException- if bits is less than 1 or greater than 16, or if size is less than 1- See Also:
IndexColorModel(int, int, int[], int, boolean, int, int)
-
InverseColorMapIndexColorModel
public InverseColorMapIndexColorModel(int pNumBits, int pSize, byte[] pReds, byte[] pGreens, byte[] pBlues, int pTransparentIndex)Creates anInverseColorMapIndexColorModelfrom the given arrays of red, green, and blue components, plus one transparent index.- Parameters:
pNumBits- the number of bits each pixel occupiespSize- the size of the color component arrayspReds- the array of red color componentspGreens- the array of green color componentspBlues- the array of blue color componentspTransparentIndex- the index of the transparent pixel- Throws:
java.lang.IllegalArgumentException- if bits is less than 1 or greater than 16, or if size is less than 1- See Also:
IndexColorModel(int, int, byte[], byte[], byte[], int)
-
InverseColorMapIndexColorModel
public InverseColorMapIndexColorModel(int pNumBits, int pSize, byte[] pReds, byte[] pGreens, byte[] pBlues)Creates anInverseColorMapIndexColorModelfrom the given arrays of red, green, and blue components.- Parameters:
pNumBits- the number of bits each pixel occupiespSize- the size of the color component arrayspReds- the array of red color componentspGreens- the array of green color componentspBlues- the array of blue color components- Throws:
java.lang.IllegalArgumentException- if bits is less than 1 or greater than 16, or if size is less than 1- See Also:
IndexColorModel(int, int, byte[], byte[], byte[])
-
-
Method Detail
-
getRGBs
private static int[] getRGBs(java.awt.image.IndexColorModel pColorModel)
Creates a defensive copy of the RGB color map in the givenIndexColorModel.- Parameters:
pColorModel- the indexed color model to get RGB values from- Returns:
- the RGB color map
-
getWhiteIndex
private int getWhiteIndex()
-
create
public static java.awt.image.IndexColorModel create(java.awt.Image pImage, int pNumCols, int pFlags)Creates anIndexColorModeloptimized for the givenImage.- Parameters:
pImage- theImagecontaining the RGB samplespNumCols- the maximum number of colors in theIndexColorModelpFlags- flags- Returns:
- a new optimized
IndexColorModel
-
getDataElements
public java.lang.Object getDataElements(int rgb, java.lang.Object pixel)Returns a data element array representation of a pixel in this ColorModel, given an integer pixel representation in the default RGB color model. This array can then be passed to thesetDataElementsmethod of aWritableRasterobject. If the pixel variable isnull, a new array is allocated. Ifpixelis notnull, it must be a primitive array of typetransferType; otherwise, aClassCastExceptionis thrown. AnArrayIndexOutOfBoundsExceptionis thrown ifpixelis not large enough to hold a pixel value for thisColorModel. The pixel array is returned.Since
OpaqueIndexColorModelcan be subclassed, subclasses inherit the implementation of this method and if they don't override it then they throw an exception if they use an unsupportedtransferType. #param rgb the integer pixel representation in the default RGB color model #param pixel the specified pixel #return an array representation of the specified pixel in thisOpaqueIndexColorModel. #throws ClassCastException ifpixelis not a primitive array of typetransferType#throws ArrayIndexOutOfBoundsException ifpixelis not large enough to hold a pixel value for thisColorModel#throws UnsupportedOperationException iftransferTypeis invalid- Overrides:
getDataElementsin classjava.awt.image.IndexColorModel- See Also:
WritableRaster.setDataElements(int, int, java.lang.Object),SampleModel.setDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)
-
installpixel
private java.lang.Object installpixel(java.lang.Object pixel, int pix)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.awt.image.IndexColorModel
-
-