- java.lang.Object
-
- java.awt.image.ColorModel
-
- java.awt.image.PackedColorModel
-
- All Implemented Interfaces:
- Transparency
- Direct Known Subclasses:
- DirectColorModel
public abstract class PackedColorModel extends ColorModel
ThePackedColorModel
class is an abstractColorModel
class that works with pixel values which represent color and alpha information as separate samples and which pack all samples for a single pixel into a single int, short, or byte quantity. This class can be used with an arbitraryColorSpace
. The number of color samples in the pixel values must be the same as the number of color components in theColorSpace
. There can be a single alpha sample. The array length is always 1 for those methods that use a primitive array pixel representation of typetransferType
. The transfer types supported are DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, and DataBuffer.TYPE_INT. Color and alpha samples are stored in the single element of the array in bits indicated by bit masks. Each bit mask must be contiguous and masks must not overlap. The same masks apply to the single int pixel representation used by other methods. The correspondence of masks and color/alpha samples is as follows:- Masks are identified by indices running from 0 through
getNumComponents
- 1. - The first
getNumColorComponents
indices refer to color samples. - If an alpha sample is present, it corresponds the last index.
- The order of the color indices is specified
by the
ColorSpace
. Typically, this reflects the name of the color space type (for example, TYPE_RGB), index 0 corresponds to red, index 1 to green, and index 2 to blue.
The translation from pixel values to color/alpha components for display or processing purposes is a one-to-one correspondence of samples to components. A
PackedColorModel
is typically used with image data that uses masks to define packed samples. For example, aPackedColorModel
can be used in conjunction with aSinglePixelPackedSampleModel
to construct aBufferedImage
. Normally the masks used by theSampleModel
and theColorModel
would be the same. However, if they are different, the color interpretation of pixel data is done according to the masks of theColorModel
.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 singleint
. Therefore, methods that use this representation do not throw anIllegalArgumentException
due to an invalid pixel value.A subclass of
PackedColorModel
isDirectColorModel
, which is similar to an X11 TrueColor visual.
-
-
Field Summary
-
Fields inherited from class java.awt.image.ColorModel
pixel_bits, transferType
-
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
-
-
Constructor Summary
Constructors Constructor and Description PackedColorModel(ColorSpace space, int bits, int[] colorMaskArray, int alphaMask, boolean isAlphaPremultiplied, int trans, int transferType)
Constructs aPackedColorModel
from a color mask array, which specifies which bits in anint
pixel representation contain each of the color samples, and an alpha mask.PackedColorModel(ColorSpace space, int bits, int rmask, int gmask, int bmask, int amask, boolean isAlphaPremultiplied, int trans, int transferType)
Constructs aPackedColorModel
from the specified masks which indicate which bits in anint
pixel representation contain the alpha, red, green and blue color samples.
-
Method Summary
Methods Modifier and Type Method and Description SampleModel
createCompatibleSampleModel(int w, int h)
Creates aSampleModel
with the specified width and height that has a data layout compatible with thisColorModel
.boolean
equals(Object obj)
Tests if the specifiedObject
is an instance ofPackedColorModel
and equals thisPackedColorModel
.WritableRaster
getAlphaRaster(WritableRaster raster)
Returns aWritableRaster
representing the alpha channel of an image, extracted from the inputWritableRaster
.int
getMask(int index)
Returns the mask indicating which bits in a pixel contain the specified color/alpha sample.int[]
getMasks()
Returns a mask array indicating which bits in a pixel contain the color and alpha samples.boolean
isCompatibleSampleModel(SampleModel sm)
Checks if the specifiedSampleModel
is compatible with thisColorModel
.-
Methods inherited from class java.awt.image.ColorModel
coerceData, createCompatibleWritableRaster, finalize, getAlpha, getAlpha, getBlue, getBlue, getColorSpace, getComponents, getComponents, getComponentSize, getComponentSize, getDataElement, getDataElement, getDataElements, getDataElements, getDataElements, getGreen, getGreen, getNormalizedComponents, getNormalizedComponents, getNumColorComponents, getNumComponents, getPixelSize, getRed, getRed, getRGB, getRGB, getRGBdefault, getTransferType, getTransparency, getUnnormalizedComponents, hasAlpha, hashCode, isAlphaPremultiplied, isCompatibleRaster, toString
-
-
-
-
Constructor Detail
-
PackedColorModel
public PackedColorModel(ColorSpace space, int bits, int[] colorMaskArray, int alphaMask, boolean isAlphaPremultiplied, int trans, int transferType)
Constructs aPackedColorModel
from a color mask array, which specifies which bits in anint
pixel representation contain each of the color samples, and an alpha mask. Color components are in the specifiedColorSpace
. The length ofcolorMaskArray
should be the number of components in theColorSpace
. All of the bits in each mask must be contiguous and fit in the specified number of least significant bits of anint
pixel representation. If thealphaMask
is 0, there is no alpha. If there is alpha, theboolean
isAlphaPremultiplied
specifies how to interpret color and alpha samples in pixel values. If theboolean
istrue
, color samples are assumed to have been multiplied by the alpha sample. The transparency,trans
, specifies what alpha values can be represented by this color model. The transfer type is the type of primitive array used to represent pixel values.- Parameters:
space
- the specifiedColorSpace
bits
- the number of bits in the pixel valuescolorMaskArray
- array that specifies the masks representing the bits of the pixel values that represent the color componentsalphaMask
- specifies the mask representing the bits of the pixel values that represent the alpha componentisAlphaPremultiplied
-true
if color samples are premultiplied by the alpha sample;false
otherwisetrans
- specifies the alpha value that can be represented by this color modeltransferType
- the type of array used to represent pixel values- Throws:
IllegalArgumentException
- ifbits
is less than 1 or greater than 32
-
PackedColorModel
public PackedColorModel(ColorSpace space, int bits, int rmask, int gmask, int bmask, int amask, boolean isAlphaPremultiplied, int trans, int transferType)
Constructs aPackedColorModel
from the specified masks which indicate which bits in anint
pixel representation contain the alpha, red, green and blue color samples. Color components are in the specifiedColorSpace
, which must be of type ColorSpace.TYPE_RGB. All of the bits in each mask must be contiguous and fit in the specified number of least significant bits of anint
pixel representation. Ifamask
is 0, there is no alpha. If there is alpha, theboolean
isAlphaPremultiplied
specifies how to interpret color and alpha samples in pixel values. If theboolean
istrue
, color samples are assumed to have been multiplied by the alpha sample. The transparency,trans
, specifies what alpha values can be represented by this color model. The transfer type is the type of primitive array used to represent pixel values.- Parameters:
space
- the specifiedColorSpace
bits
- the number of bits in the pixel valuesrmask
- specifies the mask representing the bits of the pixel values that represent the red color componentgmask
- specifies the mask representing the bits of the pixel values that represent the green color componentbmask
- specifies the mask representing the bits of the pixel values that represent the blue color componentamask
- specifies the mask representing the bits of the pixel values that represent the alpha componentisAlphaPremultiplied
-true
if color samples are premultiplied by the alpha sample;false
otherwisetrans
- specifies the alpha value that can be represented by this color modeltransferType
- the type of array used to represent pixel values- Throws:
IllegalArgumentException
- ifspace
is not a TYPE_RGB space- See Also:
ColorSpace
-
-
Method Detail
-
getMask
public final int getMask(int index)
Returns the mask indicating which bits in a pixel contain the specified color/alpha sample. For color samples,index
corresponds to the placement of color sample names in the color space. Thus, anindex
equal to 0 for a CMYK ColorSpace would correspond to Cyan and anindex
equal to 1 would correspond to Magenta. If there is alpha, the alphaindex
would be:alphaIndex = numComponents() - 1;
- Parameters:
index
- the specified color or alpha sample- Returns:
- the mask, which indicates which bits of the
int
pixel representation contain the color or alpha sample specified byindex
. - Throws:
ArrayIndexOutOfBoundsException
- ifindex
is greater than the number of components minus 1 in thisPackedColorModel
or ifindex
is less than zero
-
getMasks
public final int[] getMasks()
Returns a mask array indicating which bits in a pixel contain the color and alpha samples.- Returns:
- the mask array , which indicates which bits of the
int
pixel representation contain the color or alpha samples.
-
createCompatibleSampleModel
public SampleModel createCompatibleSampleModel(int w, int h)
Creates aSampleModel
with the specified width and height that has a data layout compatible with thisColorModel
.- Overrides:
createCompatibleSampleModel
in classColorModel
- Parameters:
w
- the width (in pixels) of the region of the image data describedh
- the height (in pixels) of the region of the image data described- Returns:
- the newly created
SampleModel
. - Throws:
IllegalArgumentException
- ifw
orh
is not greater than 0- See Also:
SampleModel
-
isCompatibleSampleModel
public boolean isCompatibleSampleModel(SampleModel sm)
Checks if the specifiedSampleModel
is compatible with thisColorModel
. Ifsm
isnull
, this method returnsfalse
.- Overrides:
isCompatibleSampleModel
in classColorModel
- Parameters:
sm
- the specifiedSampleModel
, ornull
- Returns:
true
if the specifiedSampleModel
is compatible with thisColorModel
;false
otherwise.- See Also:
SampleModel
-
getAlphaRaster
public WritableRaster getAlphaRaster(WritableRaster raster)
Returns aWritableRaster
representing the alpha channel of an image, extracted from the inputWritableRaster
. This method assumes thatWritableRaster
objects associated with thisColorModel
store the alpha band, if present, as the last band of image data. Returnsnull
if there is no separate spatial alpha channel associated with thisColorModel
. This method creates a newWritableRaster
, but shares the data array.- Overrides:
getAlphaRaster
in classColorModel
- Parameters:
raster
- aWritableRaster
containing an image- Returns:
- a
WritableRaster
that represents the alpha channel of the image contained inraster
.
-
equals
public boolean equals(Object obj)
Tests if the specifiedObject
is an instance ofPackedColorModel
and equals thisPackedColorModel
.- Overrides:
equals
in classColorModel
- Parameters:
obj
- theObject
to test for equality- Returns:
true
if the specifiedObject
is an instance ofPackedColorModel
and equals thisPackedColorModel
;false
otherwise.- See Also:
Object.hashCode()
,HashMap
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-java/awt/image/PackedColorModel.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.