- java.lang.Object
-
- java.awt.image.ColorModel
-
- java.awt.image.IndexColorModel
-
- All Implemented Interfaces:
Transparency
public class IndexColorModel extends ColorModel
TheIndexColorModelclass is aColorModelclass that works with pixel values consisting of a single sample that is an index into a fixed colormap in the default sRGB color space. The colormap specifies red, green, blue, and optional alpha components corresponding to each index. All components are represented in the colormap as 8-bit unsigned integral values. Some constructors allow the caller to specify "holes" in the colormap by indicating which colormap entries are valid and which represent unusable colors via the bits set in aBigIntegerobject. This color model is similar to an X11 PseudoColor visual.Some constructors provide a means to specify an alpha component for each pixel in the colormap, while others either provide no such means or, in some cases, a flag to indicate whether the colormap data contains alpha values. If no alpha is supplied to the constructor, an opaque alpha component (alpha = 1.0) is assumed for each entry. An optional transparent pixel value can be supplied that indicates a pixel to be made completely transparent, regardless of any alpha component supplied or assumed for that pixel value. Note that the color components in the colormap of an
IndexColorModelobjects are never pre-multiplied with the alpha components.If an
IndexColorModelobject has a transparency value ofTransparency.OPAQUE, then thehasAlphaandgetNumComponentsmethods (both inherited fromColorModel) return false and 3, respectively. For any other transparency value,hasAlphareturns true andgetNumComponentsreturns 4.For those methods that use a primitive array pixel representation of type
transferType, the array length is always one. The transfer types supported areDataBuffer.TYPE_BYTEandDataBuffer.TYPE_USHORT. A single int pixel representation is valid for all objects of this class, since it is always possible to represent pixel values used with this class in a single int. Therefore, methods that use this representation do not throw anIllegalArgumentExceptiondue to an invalid pixel value.Many of the methods in this class are final. The reason for this is that the underlying native graphics code makes assumptions about the layout and operation of this class and those assumptions are reflected in the implementations of the methods here that are marked final. You can subclass this class for other reasons, but you cannot override or modify the behaviour of those methods.
- See Also:
ColorModel,ColorSpace,DataBuffer
-
-
Field Summary
-
Fields declared in class java.awt.image.ColorModel
pixel_bits, transferType
-
Fields declared in interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
-
-
Constructor Summary
Constructors Constructor Description IndexColorModel(int bits, int size, byte[] r, byte[] g, byte[] b)Constructs anIndexColorModelfrom the specified arrays of red, green, and blue components.IndexColorModel(int bits, int size, byte[] r, byte[] g, byte[] b, byte[] a)Constructs anIndexColorModelfrom the given arrays of red, green, blue and alpha components.IndexColorModel(int bits, int size, byte[] r, byte[] g, byte[] b, int trans)Constructs anIndexColorModelfrom the given arrays of red, green, and blue components.IndexColorModel(int bits, int size, byte[] cmap, int start, boolean hasalpha)Constructs anIndexColorModelfrom a single array of interleaved red, green, blue and optional alpha components.IndexColorModel(int bits, int size, byte[] cmap, int start, boolean hasalpha, int trans)Constructs anIndexColorModelfrom a single array of interleaved red, green, blue and optional alpha components.IndexColorModel(int bits, int size, int[] cmap, int start, boolean hasalpha, int trans, int transferType)Constructs anIndexColorModelfrom an array of ints where each int is comprised of red, green, blue, and optional alpha components in the default RGB color model format.IndexColorModel(int bits, int size, int[] cmap, int start, int transferType, BigInteger validBits)Constructs anIndexColorModelfrom anintarray where eachintis comprised of red, green, blue, and alpha components in the default RGB color model format.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description BufferedImageconvertToIntDiscrete(Raster raster, boolean forceARGB)Returns a newBufferedImageof TYPE_INT_ARGB or TYPE_INT_RGB that has aRasterwith pixel data computed by expanding the indices in the sourceRasterusing the color/alpha component arrays of thisColorModel.SampleModelcreateCompatibleSampleModel(int w, int h)Creates aSampleModelwith the specified width and height that has a data layout compatible with thisColorModel.WritableRastercreateCompatibleWritableRaster(int w, int h)Creates aWritableRasterwith the specified width and height that has a data layout (SampleModel) compatible with thisColorModel.booleanequals(Object obj)Tests if the specifiedObjectis an instance ofIndexColorModeland if it equals thisIndexColorModelvoidfinalize()Deprecated.Thefinalizemethod has been deprecated.intgetAlpha(int pixel)Returns the alpha component for the specified pixel, scaled from 0 to 255.voidgetAlphas(byte[] a)Copies the array of alpha transparency components into the specified array.intgetBlue(int pixel)Returns the blue color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB.voidgetBlues(byte[] b)Copies the array of blue color components into the specified array.int[]getComponents(int pixel, int[] components, int offset)Returns an array of unnormalized color/alpha components for a specified pixel in thisColorModel.int[]getComponents(Object pixel, int[] components, int offset)Returns an array of unnormalized color/alpha components for a specified pixel in thisColorModel.int[]getComponentSize()Returns an array of the number of bits for each color/alpha component.intgetDataElement(int[] components, int offset)Returns a pixel value represented as an int in thisColorModelgiven an array of unnormalized color/alpha components.ObjectgetDataElements(int[] components, int offset, Object pixel)Returns a data element array representation of a pixel in thisColorModelgiven an array of unnormalized color/alpha components.ObjectgetDataElements(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.intgetGreen(int pixel)Returns the green color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB.voidgetGreens(byte[] g)Copies the array of green color components into the specified array.intgetMapSize()Returns the size of the color/alpha component arrays in thisIndexColorModel.intgetRed(int pixel)Returns the red color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB.voidgetReds(byte[] r)Copies the array of red color components into the specified array.intgetRGB(int pixel)Returns the color/alpha components of the pixel in the default RGB color model format.voidgetRGBs(int[] rgb)Converts data for each index from the color and alpha component arrays to an int in the default RGB ColorModel format and copies the resulting 32-bit ARGB values into the specified array.intgetTransparency()Returns the transparency.intgetTransparentPixel()Returns the index of a transparent pixel in thisIndexColorModelor -1 if there is no pixel with an alpha value of 0.BigIntegergetValidPixels()Returns aBigIntegerthat indicates the valid/invalid pixels in the colormap.inthashCode()Returns the hash code for IndexColorModel.booleanisCompatibleRaster(Raster raster)Returnstrueifrasteris compatible with thisColorModelorfalseif it is not compatible with thisColorModel.booleanisCompatibleSampleModel(SampleModel sm)Checks if the specifiedSampleModelis compatible with thisColorModel.booleanisValid()Returns whether or not all of the pixels are valid.booleanisValid(int pixel)Returns whether or not the pixel is valid.StringtoString()Returns theStringrepresentation of the contents of thisColorModelobject.-
Methods declared in 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
-
-
-
-
Constructor Detail
-
IndexColorModel
public IndexColorModel(int bits, int size, byte[] r, byte[] g, byte[] b)Constructs anIndexColorModelfrom the specified arrays of red, green, and blue components. Pixels described by this color model all have alpha components of 255 unnormalized (1.0 normalized), which means they are fully opaque. All of the arrays specifying the color components must have at least the specified number of entries. TheColorSpaceis the default sRGB space. Since there is no alpha information in any of the arguments to this constructor, the transparency value is alwaysTransparency.OPAQUE. The transfer type is the smallest ofDataBuffer.TYPE_BYTEorDataBuffer.TYPE_USHORTthat can hold a single pixel.- Parameters:
bits- the number of bits each pixel occupiessize- the size of the color component arraysr- the array of red color componentsg- the array of green color componentsb- the array of blue color components- Throws:
IllegalArgumentException- ifbitsis less than 1 or greater than 16IllegalArgumentException- ifsizeis less than 1
-
IndexColorModel
public IndexColorModel(int bits, int size, byte[] r, byte[] g, byte[] b, int trans)Constructs anIndexColorModelfrom the given arrays of red, green, and blue components. Pixels described by this color model all have alpha components of 255 unnormalized (1.0 normalized), which means they are fully opaque, except for the indicated pixel to be made transparent. All of the arrays specifying the color components must have at least the specified number of entries. TheColorSpaceis the default sRGB space. The transparency value may beTransparency.OPAQUEorTransparency.BITMASKdepending on the arguments, as specified in the class description above. The transfer type is the smallest ofDataBuffer.TYPE_BYTEorDataBuffer.TYPE_USHORTthat can hold a single pixel.- Parameters:
bits- the number of bits each pixel occupiessize- the size of the color component arraysr- the array of red color componentsg- the array of green color componentsb- the array of blue color componentstrans- the index of the transparent pixel- Throws:
IllegalArgumentException- ifbitsis less than 1 or greater than 16IllegalArgumentException- ifsizeis less than 1
-
IndexColorModel
public IndexColorModel(int bits, int size, byte[] r, byte[] g, byte[] b, byte[] a)Constructs anIndexColorModelfrom the given arrays of red, green, blue and alpha components. All of the arrays specifying the components must have at least the specified number of entries. TheColorSpaceis the default sRGB space. The transparency value may be any ofTransparency.OPAQUE,Transparency.BITMASK, orTransparency.TRANSLUCENTdepending on the arguments, as specified in the class description above. The transfer type is the smallest ofDataBuffer.TYPE_BYTEorDataBuffer.TYPE_USHORTthat can hold a single pixel.- Parameters:
bits- the number of bits each pixel occupiessize- the size of the color component arraysr- the array of red color componentsg- the array of green color componentsb- the array of blue color componentsa- the array of alpha value components- Throws:
IllegalArgumentException- ifbitsis less than 1 or greater than 16IllegalArgumentException- ifsizeis less than 1
-
IndexColorModel
public IndexColorModel(int bits, int size, byte[] cmap, int start, boolean hasalpha)Constructs anIndexColorModelfrom a single array of interleaved red, green, blue and optional alpha components. The array must have enough values in it to fill all of the needed component arrays of the specified size. TheColorSpaceis the default sRGB space. The transparency value may be any ofTransparency.OPAQUE,Transparency.BITMASK, orTransparency.TRANSLUCENTdepending on the arguments, as specified in the class description above. The transfer type is the smallest ofDataBuffer.TYPE_BYTEorDataBuffer.TYPE_USHORTthat can hold a single pixel.- Parameters:
bits- the number of bits each pixel occupiessize- the size of the color component arrayscmap- the array of color componentsstart- the starting offset of the first color componenthasalpha- indicates whether alpha values are contained in thecmaparray- Throws:
IllegalArgumentException- ifbitsis less than 1 or greater than 16IllegalArgumentException- ifsizeis less than 1
-
IndexColorModel
public IndexColorModel(int bits, int size, byte[] cmap, int start, boolean hasalpha, int trans)Constructs anIndexColorModelfrom a single array of interleaved red, green, blue and optional alpha components. The specified transparent index represents a pixel that is made entirely transparent regardless of any alpha value specified for it. The array must have enough values in it to fill all of the needed component arrays of the specified size. TheColorSpaceis the default sRGB space. The transparency value may be any ofTransparency.OPAQUE,Transparency.BITMASK, orTransparency.TRANSLUCENTdepending on the arguments, as specified in the class description above. The transfer type is the smallest ofDataBuffer.TYPE_BYTEorDataBuffer.TYPE_USHORTthat can hold a single pixel.- Parameters:
bits- the number of bits each pixel occupiessize- the size of the color component arrayscmap- the array of color componentsstart- the starting offset of the first color componenthasalpha- indicates whether alpha values are contained in thecmaparraytrans- the index of the fully transparent pixel- Throws:
IllegalArgumentException- ifbitsis less than 1 or greater than 16IllegalArgumentException- ifsizeis less than 1
-
IndexColorModel
public IndexColorModel(int bits, int size, int[] cmap, int start, boolean hasalpha, int trans, int transferType)Constructs anIndexColorModelfrom an array of ints where each int is comprised of red, green, blue, and optional alpha components in the default RGB color model format. The specified transparent index represents a pixel that is made entirely transparent regardless of any alpha value specified for it. The array must have enough values in it to fill all of the needed component arrays of the specified size. TheColorSpaceis the default sRGB space. The transparency value may be any ofTransparency.OPAQUE,Transparency.BITMASK, orTransparency.TRANSLUCENTdepending on the arguments, as specified in the class description above.- Parameters:
bits- the number of bits each pixel occupiessize- the size of the color component arrayscmap- the array of color componentsstart- the starting offset of the first color componenthasalpha- indicates whether alpha values are contained in thecmaparraytrans- the index of the fully transparent pixeltransferType- the data type of the array used to represent pixel values. The data type must be eitherDataBuffer.TYPE_BYTEorDataBuffer.TYPE_USHORT.- Throws:
IllegalArgumentException- ifbitsis less than 1 or greater than 16IllegalArgumentException- ifsizeis less than 1IllegalArgumentException- iftransferTypeis not one ofDataBuffer.TYPE_BYTEorDataBuffer.TYPE_USHORT
-
IndexColorModel
public IndexColorModel(int bits, int size, int[] cmap, int start, int transferType, BigInteger validBits)Constructs anIndexColorModelfrom anintarray where eachintis comprised of red, green, blue, and alpha components in the default RGB color model format. The array must have enough values in it to fill all of the needed component arrays of the specified size. TheColorSpaceis the default sRGB space. The transparency value may be any ofTransparency.OPAQUE,Transparency.BITMASK, orTransparency.TRANSLUCENTdepending on the arguments, as specified in the class description above. The transfer type must be one ofDataBuffer.TYPE_BYTEDataBuffer.TYPE_USHORT. TheBigIntegerobject specifies the valid/invalid pixels in thecmaparray. A pixel is valid if theBigIntegervalue at that index is set, and is invalid if theBigIntegerbit at that index is not set.- Parameters:
bits- the number of bits each pixel occupiessize- the size of the color component arraycmap- the array of color componentsstart- the starting offset of the first color componenttransferType- the specified data typevalidBits- aBigIntegerobject. If a bit is set in the BigInteger, the pixel at that index is valid. If a bit is not set, the pixel at that index is considered invalid. If null, all pixels are valid. Only bits from 0 to the map size are considered.- Throws:
IllegalArgumentException- ifbitsis less than 1 or greater than 16IllegalArgumentException- ifsizeis less than 1IllegalArgumentException- iftransferTypeis not one ofDataBuffer.TYPE_BYTEorDataBuffer.TYPE_USHORT- Since:
- 1.3
-
-
Method Detail
-
getTransparency
public int getTransparency()
Returns the transparency. Returns either OPAQUE, BITMASK, or TRANSLUCENT- Specified by:
getTransparencyin interfaceTransparency- Overrides:
getTransparencyin classColorModel- Returns:
- the transparency of this
IndexColorModel - See Also:
Transparency.OPAQUE,Transparency.BITMASK,Transparency.TRANSLUCENT
-
getComponentSize
public int[] getComponentSize()
Returns an array of the number of bits for each color/alpha component. The array contains the color components in the order red, green, blue, followed by the alpha component, if present.- Overrides:
getComponentSizein classColorModel- Returns:
- an array containing the number of bits of each color
and alpha component of this
IndexColorModel
-
getMapSize
public final int getMapSize()
Returns the size of the color/alpha component arrays in thisIndexColorModel.- Returns:
- the size of the color and alpha component arrays.
-
getTransparentPixel
public final int getTransparentPixel()
Returns the index of a transparent pixel in thisIndexColorModelor -1 if there is no pixel with an alpha value of 0. If a transparent pixel was explicitly specified in one of the constructors by its index, then that index will be preferred, otherwise, the index of any pixel which happens to be fully transparent may be returned.- Returns:
- the index of a transparent pixel in this
IndexColorModelobject, or -1 if there is no such pixel
-
getReds
public final void getReds(byte[] r)
Copies the array of red color components into the specified array. Only the initial entries of the array as specified bygetMapSizeare written.- Parameters:
r- the specified array into which the elements of the array of red color components are copied
-
getGreens
public final void getGreens(byte[] g)
Copies the array of green color components into the specified array. Only the initial entries of the array as specified bygetMapSizeare written.- Parameters:
g- the specified array into which the elements of the array of green color components are copied
-
getBlues
public final void getBlues(byte[] b)
Copies the array of blue color components into the specified array. Only the initial entries of the array as specified bygetMapSizeare written.- Parameters:
b- the specified array into which the elements of the array of blue color components are copied
-
getAlphas
public final void getAlphas(byte[] a)
Copies the array of alpha transparency components into the specified array. Only the initial entries of the array as specified bygetMapSizeare written.- Parameters:
a- the specified array into which the elements of the array of alpha components are copied
-
getRGBs
public final void getRGBs(int[] rgb)
Converts data for each index from the color and alpha component arrays to an int in the default RGB ColorModel format and copies the resulting 32-bit ARGB values into the specified array. Only the initial entries of the array as specified bygetMapSizeare written.- Parameters:
rgb- the specified array into which the converted ARGB values from this array of color and alpha components are copied.
-
getRed
public final int getRed(int pixel)
Returns the red color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB. The pixel value is specified as an int. Only the lower n bits of the pixel value, as specified in the class description above, are used to calculate the returned value. The returned value is a non pre-multiplied value.- Specified by:
getRedin classColorModel- Parameters:
pixel- the specified pixel- Returns:
- the value of the red color component for the specified pixel
-
getGreen
public final int getGreen(int pixel)
Returns the green color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB. The pixel value is specified as an int. Only the lower n bits of the pixel value, as specified in the class description above, are used to calculate the returned value. The returned value is a non pre-multiplied value.- Specified by:
getGreenin classColorModel- Parameters:
pixel- the specified pixel- Returns:
- the value of the green color component for the specified pixel
-
getBlue
public final int getBlue(int pixel)
Returns the blue color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace, sRGB. The pixel value is specified as an int. Only the lower n bits of the pixel value, as specified in the class description above, are used to calculate the returned value. The returned value is a non pre-multiplied value.- Specified by:
getBluein classColorModel- Parameters:
pixel- the specified pixel- Returns:
- the value of the blue color component for the specified pixel
-
getAlpha
public final int getAlpha(int pixel)
Returns the alpha component for the specified pixel, scaled from 0 to 255. The pixel value is specified as an int. Only the lower n bits of the pixel value, as specified in the class description above, are used to calculate the returned value.- Specified by:
getAlphain classColorModel- Parameters:
pixel- the specified pixel- Returns:
- the value of the alpha component for the specified pixel
-
getRGB
public final int getRGB(int pixel)
Returns the color/alpha components of the pixel in the default RGB color model format. The pixel value is specified as an int. Only the lower n bits of the pixel value, as specified in the class description above, are used to calculate the returned value. The returned value is in a non pre-multiplied format.- Overrides:
getRGBin classColorModel- Parameters:
pixel- the specified pixel- Returns:
- the color and alpha components of the specified pixel
- See Also:
ColorModel.getRGBdefault()
-
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 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
IndexColorModelcan 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.- Overrides:
getDataElementsin classColorModel- Parameters:
rgb- the integer pixel representation in the default RGB color modelpixel- the specified pixel- Returns:
- an array representation of the specified pixel in this
IndexColorModel. - Throws:
ClassCastException- ifpixelis not a primitive array of typetransferTypeArrayIndexOutOfBoundsException- ifpixelis not large enough to hold a pixel value for thisColorModelUnsupportedOperationException- iftransferTypeis invalid- See Also:
WritableRaster.setDataElements(int, int, java.lang.Object),SampleModel.setDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)
-
getComponents
public int[] getComponents(int pixel, int[] components, int offset)Returns an array of unnormalized color/alpha components for a specified pixel in thisColorModel. The pixel value is specified as an int. If thecomponentsarray isnull, a new array is allocated that containsoffset + getNumComponents()elements. Thecomponentsarray is returned, with the alpha component included only ifhasAlphareturns true. Color/alpha components are stored in thecomponentsarray starting atoffseteven if the array is allocated by this method. AnArrayIndexOutOfBoundsExceptionis thrown if thecomponentsarray is notnulland is not large enough to hold all the color and alpha components starting atoffset.- Overrides:
getComponentsin classColorModel- Parameters:
pixel- the specified pixelcomponents- the array to receive the color and alpha components of the specified pixeloffset- the offset into thecomponentsarray at which to start storing the color and alpha components- Returns:
- an array containing the color and alpha components of the specified pixel starting at the specified offset.
- See Also:
ColorModel.hasAlpha(),ColorModel.getNumComponents()
-
getComponents
public int[] getComponents(Object pixel, int[] components, int offset)
Returns an array of unnormalized color/alpha components for a specified pixel in thisColorModel. The pixel value is specified by an array of data elements of typetransferTypepassed in as an object reference. Ifpixelis not a primitive array of typetransferType, aClassCastExceptionis thrown. AnArrayIndexOutOfBoundsExceptionis thrown ifpixelis not large enough to hold a pixel value for thisColorModel. If thecomponentsarray isnull, a new array is allocated that containsoffset + getNumComponents()elements. Thecomponentsarray is returned, with the alpha component included only ifhasAlphareturns true. Color/alpha components are stored in thecomponentsarray starting atoffseteven if the array is allocated by this method. AnArrayIndexOutOfBoundsExceptionis also thrown if thecomponentsarray is notnulland is not large enough to hold all the color and alpha components starting atoffset.Since
IndexColorModelcan 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.- Overrides:
getComponentsin classColorModel- Parameters:
pixel- the specified pixelcomponents- an array that receives the color and alpha components of the specified pixeloffset- the index into thecomponentsarray at which to begin storing the color and alpha components of the specified pixel- Returns:
- an array containing the color and alpha components of the specified pixel starting at the specified offset.
- Throws:
ArrayIndexOutOfBoundsException- ifpixelis not large enough to hold a pixel value for thisColorModelor if thecomponentsarray is notnulland is not large enough to hold all the color and alpha components starting atoffsetClassCastException- ifpixelis not a primitive array of typetransferTypeUnsupportedOperationException- iftransferTypeis not one of the supported transfer types- See Also:
ColorModel.hasAlpha(),ColorModel.getNumComponents()
-
getDataElement
public int getDataElement(int[] components, int offset)Returns a pixel value represented as an int in thisColorModelgiven an array of unnormalized color/alpha components. AnArrayIndexOutOfBoundsExceptionis thrown if thecomponentsarray is not large enough to hold all of the color and alpha components starting atoffset. SinceColorModelcan 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.- Overrides:
getDataElementin classColorModel- Parameters:
components- an array of unnormalized color and alpha componentsoffset- the index intocomponentsat which to begin retrieving the color and alpha components- Returns:
- an
intpixel value in thisColorModelcorresponding to the specified components. - Throws:
ArrayIndexOutOfBoundsException- if thecomponentsarray is not large enough to hold all of the color and alpha components starting atoffsetUnsupportedOperationException- iftransferTypeis invalid
-
getDataElements
public Object getDataElements(int[] components, int offset, Object pixel)
Returns a data element array representation of a pixel in thisColorModelgiven an array of unnormalized color/alpha components. This array can then be passed to thesetDataElementsmethod of aWritableRasterobject. AnArrayIndexOutOfBoundsExceptionis thrown if thecomponentsarray is not large enough to hold all of the color and alpha components starting atoffset. 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 if pixel is not large enough to hold a pixel value for thisColorModel.Since
IndexColorModelcan 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- Overrides:
getDataElementsin classColorModel- Parameters:
components- an array of unnormalized color and alpha componentsoffset- the index intocomponentsat which to begin retrieving color and alpha componentspixel- theObjectrepresenting an array of color and alpha components- Returns:
- an
Objectrepresenting an array of color and alpha components. - Throws:
ClassCastException- ifpixelis not a primitive array of typetransferTypeArrayIndexOutOfBoundsException- ifpixelis not large enough to hold a pixel value for thisColorModelor thecomponentsarray is not large enough to hold all of the color and alpha components starting atoffsetUnsupportedOperationException- iftransferTypeis not one of the supported transfer types- See Also:
WritableRaster.setDataElements(int, int, java.lang.Object),SampleModel.setDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)
-
createCompatibleWritableRaster
public WritableRaster createCompatibleWritableRaster(int w, int h)
Creates aWritableRasterwith the specified width and height that has a data layout (SampleModel) compatible with thisColorModel. This method only works for color models with 16 or fewer bits per pixel.Since
IndexColorModelcan be subclassed, any subclass that supports greater than 16 bits per pixel must override this method.- Overrides:
createCompatibleWritableRasterin classColorModel- Parameters:
w- the width to apply to the newWritableRasterh- the height to apply to the newWritableRaster- Returns:
- a
WritableRasterobject with the specified width and height. - Throws:
UnsupportedOperationException- if the number of bits in a pixel is greater than 16- See Also:
WritableRaster,SampleModel
-
isCompatibleRaster
public boolean isCompatibleRaster(Raster raster)
Returnstrueifrasteris compatible with thisColorModelorfalseif it is not compatible with thisColorModel.- Overrides:
isCompatibleRasterin classColorModel- Parameters:
raster- theRasterobject to test for compatibility- Returns:
trueifrasteris compatible with thisColorModel;falseotherwise.
-
createCompatibleSampleModel
public SampleModel createCompatibleSampleModel(int w, int h)
Creates aSampleModelwith the specified width and height that has a data layout compatible with thisColorModel.- Overrides:
createCompatibleSampleModelin classColorModel- Parameters:
w- the width to apply to the newSampleModelh- the height to apply to the newSampleModel- Returns:
- a
SampleModelobject with the specified width and height. - Throws:
IllegalArgumentException- ifworhis not greater than 0- See Also:
SampleModel
-
isCompatibleSampleModel
public boolean isCompatibleSampleModel(SampleModel sm)
Checks if the specifiedSampleModelis compatible with thisColorModel. Ifsmisnull, this method returnsfalse.- Overrides:
isCompatibleSampleModelin classColorModel- Parameters:
sm- the specifiedSampleModel, ornull- Returns:
trueif the specifiedSampleModelis compatible with thisColorModel;falseotherwise.- See Also:
SampleModel
-
convertToIntDiscrete
public BufferedImage convertToIntDiscrete(Raster raster, boolean forceARGB)
Returns a newBufferedImageof TYPE_INT_ARGB or TYPE_INT_RGB that has aRasterwith pixel data computed by expanding the indices in the sourceRasterusing the color/alpha component arrays of thisColorModel. Only the lower n bits of each index value in the sourceRaster, as specified in the class description above, are used to compute the color/alpha values in the returned image. IfforceARGBistrue, a TYPE_INT_ARGB image is returned regardless of whether or not thisColorModelhas an alpha component array or a transparent pixel.- Parameters:
raster- the specifiedRasterforceARGB- iftrue, the returnedBufferedImageis TYPE_INT_ARGB; otherwise it is TYPE_INT_RGB- Returns:
- a
BufferedImagecreated with the specifiedRaster - Throws:
IllegalArgumentException- if the raster argument is not compatible with this IndexColorModel
-
isValid
public boolean isValid(int pixel)
Returns whether or not the pixel is valid.- Parameters:
pixel- the specified pixel value- Returns:
trueifpixelis valid;falseotherwise.- Since:
- 1.3
-
isValid
public boolean isValid()
Returns whether or not all of the pixels are valid.- Returns:
trueif all pixels are valid;falseotherwise.- Since:
- 1.3
-
getValidPixels
public BigInteger getValidPixels()
Returns aBigIntegerthat indicates the valid/invalid pixels in the colormap. A bit is valid if theBigIntegervalue at that index is set, and is invalid if theBigIntegervalue at that index is not set. The only valid ranges to query in theBigIntegerare between 0 and the map size.- Returns:
- a
BigIntegerindicating the valid/invalid pixels. - Since:
- 1.3
-
finalize
@Deprecated(since="9") public void finalize()
Deprecated.Thefinalizemethod has been deprecated. Subclasses that overridefinalizein order to perform cleanup should be modified to use alternative cleanup mechanisms and to remove the overridingfinalizemethod. When overriding thefinalizemethod, its implementation must explicitly ensure thatsuper.finalize()is invoked as described inObject.finalize(). See the specification forObject.finalize()for further information about migration options.Disposes of system resources associated with thisColorModelonce thisColorModelis no longer referenced.- Overrides:
finalizein classColorModel- See Also:
WeakReference,PhantomReference
-
toString
public String toString()
Returns theStringrepresentation of the contents of thisColorModelobject.- Overrides:
toStringin classColorModel- Returns:
- a
Stringrepresenting the contents of thisColorModelobject.
-
equals
public boolean equals(Object obj)
Tests if the specifiedObjectis an instance ofIndexColorModeland if it equals thisIndexColorModel- Overrides:
equalsin classColorModel- Parameters:
obj- theObjectto test for equality- Returns:
trueif the specifiedObjectequals thisIndexColorModel;falseotherwise.- See Also:
Object.hashCode(),HashMap
-
hashCode
public int hashCode()
Returns the hash code for IndexColorModel.- Overrides:
hashCodein classColorModel- Returns:
- a hash code for IndexColorModel
- See Also:
Object.equals(java.lang.Object),System.identityHashCode(java.lang.Object)
-
-