com.twelvemonkeys.image
Class InverseColorMapIndexColorModel

java.lang.Object
  extended by java.awt.image.ColorModel
      extended by java.awt.image.IndexColorModel
          extended by com.twelvemonkeys.image.InverseColorMapIndexColorModel
All Implemented Interfaces:
Transparency

public class InverseColorMapIndexColorModel
extends IndexColorModel

A faster implementation of IndexColorModel, 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 $
Author:
Harald Kuhr, $Author: haku $

Field Summary
protected  com.twelvemonkeys.image.InverseColorMap inverseMap
           
protected  int mapSize
           
protected  int[] rgbs
           
 
Fields inherited from class java.awt.image.ColorModel
pixel_bits, transferType
 
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
 
Constructor Summary
InverseColorMapIndexColorModel(IndexColorModel pColorModel)
          Creates an InverseColorMapIndexColorModel from an existing IndexColorModel.
InverseColorMapIndexColorModel(int pNumBits, int pSize, byte[] pReds, byte[] pGreens, byte[] pBlues)
          Creates an InverseColorMapIndexColorModel from the given arrays of red, green, and blue components.
InverseColorMapIndexColorModel(int pNumBits, int pSize, byte[] pReds, byte[] pGreens, byte[] pBlues, int pTransparentIndex)
          Creates an InverseColorMapIndexColorModel from 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 an InverseColorMapIndexColorModel from the given array of RGB components, plus one transparent index.
 
Method Summary
static IndexColorModel create(Image pImage, int pNumCols, int pFlags)
          Creates an IndexColorModel optimized for the given Image.
 Object getDataElements(int rgb, 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.
 String toString()
           
 
Methods inherited from class java.awt.image.IndexColorModel
convertToIntDiscrete, createCompatibleSampleModel, createCompatibleWritableRaster, finalize, getAlpha, getAlphas, getBlue, getBlues, getComponents, getComponents, getComponentSize, getDataElement, getDataElements, getGreen, getGreens, getMapSize, getRed, getReds, getRGB, getRGBs, getTransparency, getTransparentPixel, getValidPixels, isCompatibleRaster, isCompatibleSampleModel, isValid, isValid
 
Methods inherited from class java.awt.image.ColorModel
coerceData, equals, getAlpha, getAlphaRaster, getBlue, getColorSpace, getComponentSize, getDataElement, getDataElements, getGreen, getNormalizedComponents, getNormalizedComponents, getNumColorComponents, getNumComponents, getPixelSize, getRed, getRGB, getRGBdefault, getTransferType, getUnnormalizedComponents, hasAlpha, hashCode, isAlphaPremultiplied
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

rgbs

protected int[] rgbs

mapSize

protected int mapSize

inverseMap

protected com.twelvemonkeys.image.InverseColorMap inverseMap
Constructor Detail

InverseColorMapIndexColorModel

public InverseColorMapIndexColorModel(IndexColorModel pColorModel)
Creates an InverseColorMapIndexColorModel from an existing IndexColorModel.

Parameters:
pColorModel - the color model to create from.
Throws:
IllegalArgumentException - if pColorModel is null

InverseColorMapIndexColorModel

public InverseColorMapIndexColorModel(int pNumBits,
                                      int pSize,
                                      int[] pRGBs,
                                      int pStart,
                                      boolean pAlpha,
                                      int pTransparentIndex,
                                      int pTransferType)
Creates an InverseColorMapIndexColorModel from the given array of RGB components, plus one transparent index.

Parameters:
pNumBits - the number of bits each pixel occupies
pSize - the size of the color component arrays
pRGBs - the array of packed RGB color components
pStart - the starting offset of the first color component
pAlpha - indicates whether alpha values are contained in pRGBs
pTransparentIndex - the index of the transparent pixel
pTransferType - the data type of the array used to represent pixels
Throws:
IllegalArgumentException - if bits is less than 1 or greater than 16, or if size is less than 1
See Also:
IndexColorModel.IndexColorModel(int, int, int[], int, boolean, int, int)

InverseColorMapIndexColorModel

public InverseColorMapIndexColorModel(int pNumBits,
                                      int pSize,
                                      byte[] pReds,
                                      byte[] pGreens,
                                      byte[] pBlues,
                                      int pTransparentIndex)
Creates an InverseColorMapIndexColorModel from the given arrays of red, green, and blue components, plus one transparent index.

Parameters:
pNumBits - the number of bits each pixel occupies
pSize - the size of the color component arrays
pReds - the array of red color components
pGreens - the array of green color components
pBlues - the array of blue color components
pTransparentIndex - the index of the transparent pixel
Throws:
IllegalArgumentException - if bits is less than 1 or greater than 16, or if size is less than 1
See Also:
IndexColorModel.IndexColorModel(int, int, byte[], byte[], byte[], int)

InverseColorMapIndexColorModel

public InverseColorMapIndexColorModel(int pNumBits,
                                      int pSize,
                                      byte[] pReds,
                                      byte[] pGreens,
                                      byte[] pBlues)
Creates an InverseColorMapIndexColorModel from the given arrays of red, green, and blue components.

Parameters:
pNumBits - the number of bits each pixel occupies
pSize - the size of the color component arrays
pReds - the array of red color components
pGreens - the array of green color components
pBlues - the array of blue color components
Throws:
IllegalArgumentException - if bits is less than 1 or greater than 16, or if size is less than 1
See Also:
IndexColorModel.IndexColorModel(int, int, byte[], byte[], byte[])
Method Detail

create

public static IndexColorModel create(Image pImage,
                                     int pNumCols,
                                     int pFlags)
Creates an IndexColorModel optimized for the given Image.

Parameters:
pImage - the Image containing the RGB samples
pNumCols - the maximum number of colors in the IndexColorModel
pFlags - flags
Returns:
a new optimized IndexColorModel

getDataElements

public Object getDataElements(int rgb,
                              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 the setDataElements method of a WritableRaster object. If the pixel variable is null, a new array is allocated. If pixel is not null, it must be a primitive array of type transferType; otherwise, a ClassCastException is thrown. An ArrayIndexOutOfBoundsException is thrown if pixel is not large enough to hold a pixel value for this ColorModel. The pixel array is returned.

Since OpaqueIndexColorModel can 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 unsupported transferType. #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 this OpaqueIndexColorModel. #throws ClassCastException if pixel is not a primitive array of type transferType #throws ArrayIndexOutOfBoundsException if pixel is not large enough to hold a pixel value for this ColorModel #throws UnsupportedOperationException if transferType is invalid

Overrides:
getDataElements in class IndexColorModel
See Also:
WritableRaster.setDataElements(int, int, java.lang.Object), SampleModel.setDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)

toString

public String toString()
Overrides:
toString in class IndexColorModel


Copyright © 2015. All Rights Reserved.