Depending on the depth of the image, the PaletteData can take one of two forms, indicated by the isDirect field:
false, this palette is an indexed
palette which maps pixel values to RGBs. The actual RGB values
may be retrieved by using the getRGBs() method.
true, this palette is a direct color
palette. Instead of containing RGB values, it contains red,
green and blue mask and shift information which indicates how
the color components may be extracted from a given pixel.
This means that the RGB value is actually encoded in the pixel value.
In this case, the shift data is the number of bits required to shift the RGB value to the left in order to align the high bit of the corresponding mask with the high bit of the first byte. This number may be negative, so care must be taken when shifting. For example, with a red mask of 0xFF0000, the red shift would be -16. With a red mask of 0x1F, the red shift would be 3.
Image, RGB, Sample code and further information
| Modifier and Type | Field and Description |
|---|---|
| public int | blueMask
the blue mask for a direct palette |
| public int | blueShift
the blue shift for a direct palette |
| public RGB[] | colors
the RGB values for an indexed palette, where the indices of the array correspond to pixel values |
| public int | greenMask
the green mask for a direct palette |
| public int | greenShift
the green shift for a direct palette |
| public boolean | isDirect
true if the receiver is a direct palette, and false otherwise |
| public int | redMask
the red mask for a direct palette |
| public int | redShift
the red shift for a direct palette |
| Access | Constructor and Description |
|---|---|
| public | PaletteData(RGB...
the array of colors)RGBs for the paletteConstructs a new indexed palette given an array of RGB values. |
| public | PaletteData(int
the red mask redMask, int the green mask greenMask, int the blue mask blueMask)Constructs a new direct palette given the red, green and blue masks. |
| Modifier and Type | Method and Description |
|---|---|
| public int | |
| public RGB | Returns: the RGB value for the given pixelthe pixel to get the RGB value for pixel)Returns an |
| public RGB[] | Returns: theRGBs for the receiver or nullReturns all the RGB values in the receiver if it is an indexed palette, or null if it is a direct palette. |
| pack-priv int | Returns: the shift amountthe mask to compute the shift for mask)Computes the shift value for a given mask. |
| blueMask | back to summary |
|---|---|
| public int blueMask the blue mask for a direct palette | |
| blueShift | back to summary |
|---|---|
| public int blueShift the blue shift for a direct palette | |
| colors | back to summary |
|---|---|
| public RGB[] colors the RGB values for an indexed palette, where the indices of the array correspond to pixel values | |
| greenMask | back to summary |
|---|---|
| public int greenMask the green mask for a direct palette | |
| greenShift | back to summary |
|---|---|
| public int greenShift the green shift for a direct palette | |
| isDirect | back to summary |
|---|---|
| public boolean isDirect true if the receiver is a direct palette, and false otherwise | |
| redMask | back to summary |
|---|---|
| public int redMask the red mask for a direct palette | |
| redShift | back to summary |
|---|---|
| public int redShift the red shift for a direct palette | |
| PaletteData | back to summary |
|---|---|
| public PaletteData(RGB... colors) Constructs a new indexed palette given an array of RGB values.
| |
| PaletteData | back to summary |
|---|---|
| public PaletteData(int redMask, int greenMask, int blueMask) Constructs a new direct palette given the red, green and blue masks.
| |
| getPixel | back to summary |
|---|---|
| public int getPixel(RGB rgb) Returns the pixel value corresponding to the given
| |
| getRGB | back to summary |
|---|---|
| public RGB getRGB(int pixel) Returns an
| |
| getRGBs | back to summary |
|---|---|
| public RGB[] getRGBs() Returns all the RGB values in the receiver if it is an indexed palette, or null if it is a direct palette.
| |
| shiftForMask | back to summary |
|---|---|
| pack-priv int shiftForMask(int mask) Computes the shift value for a given mask.
| |