|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.davisor.graphics.ColorReducer
ColorReducer implements an abstract base class for color reducers that approximate larger color sets with smaller ones. Color reduction is frequently needed for example when RGB image are converted to palette images that support only limited sized palettes. For example, the ageing GIF(tm) image format supports only 256 colors in its palette.
ColorReducer offers a common interface for different color quantization or reduction methods. It also provides a generic color reduction filter interface that uses the services implemented by spesific sub-classes, and a set of tools to help to filter out selected color component bits in order to further quantize the colors in a reduced color set.
Color masks are simple 24 bit bit patterns that seleted color reducer operations will use to filter out color bits from given or generated color values. This may be used in particular to reduce the number of color shades the color reducer has to work with in the first place. All operations that apply the color mask are expected to explicitly document this in their own method documentation. Finally, please note, that color masks apply on color alpha components as well on the RGB components. In particular, a failure to set color mask alpha bits properly will result to loss of color transparency information.
| Field Summary | |
static int |
COLORMASK_12BITS
alpha + 12 bit color quantization mask (4 bits/component). |
static int |
COLORMASK_18BITS
alpha + 18 bit color quantization mask (6 bits/component). |
static int |
COLORMASK_24BITS
alpha + 24 bit color quantization mask (8 bits/component). |
static int |
COLORMASK_6BITS
alpha + 6 bit color quantization mask (2 bits/component). |
protected int |
M_colorMask
Color quantization bitmask. |
| Constructor Summary | |
ColorReducer()
Creates a new color reducer with a default 24 bit pass-through color quantization mask. |
|
ColorReducer(int colorMask)
Creates a new color reducer with given color quantization mask. |
|
| Method Summary | |
java.awt.image.BufferedImage |
createCompatibleDestImage(java.awt.image.BufferedImage src,
java.awt.image.ColorModel destCM)
Creates a zeroed destination image with the correct size and number of bands. |
java.awt.image.BufferedImage |
filter(java.awt.image.BufferedImage src,
java.awt.image.BufferedImage dest)
Reduces the colors of given source image, and copies the result into given destination image. |
java.awt.geom.Rectangle2D |
getBounds2D(java.awt.image.BufferedImage src)
Returns the bounding box of the filtered destination image. |
abstract int |
getColor(int argb)
Gets the replacement color value from the current palette for the given color. |
int |
getColor(int argb,
boolean quantize)
Gets an optionally quantized replacement color value from the current palette for the given color. |
protected static int |
getColorBits(int bits)
Gets a 8 -bit bitmask containing given number of most significant '1' bits. |
int |
getColorMask()
Gets current color quantization mask. |
static int |
getColorMask(int bits)
Computes a color quantization mask, with equal number of bits for each color component. |
static int |
getColorMask(int redBits,
int greenBits,
int blueBits)
Computes a color quantization mask. |
abstract int |
getIndex(int argb)
Gets the replacement color index in current palette for the given color. |
abstract java.awt.image.IndexColorModel |
getPalette()
Gets current reduced color palette. |
java.awt.geom.Point2D |
getPoint2D(java.awt.geom.Point2D srcPoint,
java.awt.geom.Point2D dstPoint)
Returns the location of the destination point given a point in the source image. |
java.awt.RenderingHints |
getRenderingHints()
Returns the rendering hints for this BufferdImageOp. |
void |
setAlphaBits(int bits)
Sets alpha color quantization bits. |
void |
setAlphaMask(int mask)
Sets alpha component quantization mask. |
void |
setBlueBits(int bits)
Sets blue color quantization bits. |
void |
setBlueMask(int mask)
Sets blue component quantization mask. |
void |
setColorBits(int bits)
Sets color quantization bits for all color components, but not for the alpha component. |
void |
setColorMask(int colorMask)
Sets color quantization mask. |
void |
setGreenBits(int bits)
Sets green color quantization bits. |
void |
setGreenMask(int mask)
Sets green component quantization mask. |
void |
setRedBits(int bits)
Sets red color quantization bits. |
void |
setRedMask(int mask)
Sets red component quantization mask. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int COLORMASK_24BITS
public static final int COLORMASK_18BITS
public static final int COLORMASK_12BITS
public static final int COLORMASK_6BITS
protected int M_colorMask
| Constructor Detail |
public ColorReducer()
setColorMask(int)public ColorReducer(int colorMask)
colorMask - color quantization masksetColorMask(int)| Method Detail |
public abstract int getColor(int argb)
Color palettes provide typically only limited set of transparent colors, as typical color palette contains only fully opaque colors, and only one fully transparent color, if even that. The transparency component of the returned palette color may therefore be significantly different that of the source color.
argb - standard sRGB color value (with alpha)
getColor(int,boolean),
getPalette()public abstract int getIndex(int argb)
getPalette() method.
Color palettes provide typically only limited set of transparent colors, as typical color palette contains only fully opaque colors, and only one fully transparent color, if even that. The transparency component of the returned palette color may therefore be significantly different that of the source color.
argb - standard sRGB color value (with alpha)
getColor(int),
getPalette()public abstract java.awt.image.IndexColorModel getPalette()
protected static int getColorBits(int bits)
| bits | mask | # of intensity levels |
|---|---|---|
| 0 | 00000000 | 1 |
| 1 | 10000000 | 2 |
| 2 | 11000000 | 4 |
| 3 | 11100000 | 8 |
| 4 | 11110000 | 16 |
| 5 | 11111000 | 32 |
| 6 | 11111100 | 64 |
| 7 | 11111110 | 128 |
| 8 | 11111111 | 256 |
bits - number of significant color bits (0-8)
setBlueMask(int),
setGreenMask(int),
setRedMask(int)
public int getColor(int argb,
boolean quantize)
This method seeks first a proper replacement color for given
source color with getColor(int) method. If so requested,
the replacement color is then filtered against current color mask
before it is returned.
argb - standard sRGB color value (with alpha)quantize - mask the result color against current color mask or not
getColor(int),
setColorMask(int)public int getColorMask()
public static int getColorMask(int bits)
bits - number of significant color bits (0-8)
getColorMask(int,int,int)
public static int getColorMask(int redBits,
int greenBits,
int blueBits)
redBits - number of significant red color bits (0-8)greenBits - number of significant green color bits (0-8)blueBits - number of significant blue color bits (0-8)
getColorMask(int)public void setAlphaBits(int bits)
bits - number of alpha bits (0-8)getColorBits(int),
setAlphaMask(int)public void setAlphaMask(int mask)
mask - alpha component quantization mask, residing in
the 8 least significant bits of given valuegetColorBits(int),
setAlphaBits(int)public void setBlueBits(int bits)
bits - number of blue bits (0-8)getColorBits(int),
setBlueMask(int)public void setBlueMask(int mask)
mask - blue component quantization mask, residing in
the 8 least significant bits of given valuegetColorBits(int),
setBlueBits(int)public void setColorBits(int bits)
bits - number of color component bits (0-8)getColorBits(int),
setBlueMask(int),
setGreenMask(int),
setRedMask(int)public void setColorMask(int colorMask)
The 24 bit mask is expected to contain 8 bits masks for each color component: alpha, red, green, and blue. For more information about color masks and quantization, please see class documentation.
colorMask - color quantization mask (0xAARRGGBB)getColor(int,boolean),
getColorMask(),
setColorBits(int)public void setGreenBits(int bits)
bits - number of green bits (0-8)getColorBits(int),
setGreenMask(int)public void setGreenMask(int mask)
mask - green component quantization mask, residing in
the 8 least significant bits of given valuegetColorBits(int),
setGreenBits(int)public void setRedBits(int bits)
bits - number of red bits (0-8)getColorBits(int),
setRedMask(int)public void setRedMask(int mask)
mask - red component quantization mask, residing in
the 8 least significant bits of given valuegetColorBits(int),
setRedBits(int)
public java.awt.image.BufferedImage createCompatibleDestImage(java.awt.image.BufferedImage src,
java.awt.image.ColorModel destCM)
IndexColorModel palette.
createCompatibleDestImage in interface java.awt.image.BufferedImageOpsrc - the source imagedestCM - ColorModel of the destination (ignored)
getPalette()
public java.awt.image.BufferedImage filter(java.awt.image.BufferedImage src,
java.awt.image.BufferedImage dest)
filter in interface java.awt.image.BufferedImageOpsrc - the image to be filtereddest - the imaget in which to store the results (may be null)
public java.awt.geom.Rectangle2D getBounds2D(java.awt.image.BufferedImage src)
Color reduction does not alter image bounds, so therefore the bounds from given source image are returned.
getBounds2D in interface java.awt.image.BufferedImageOpsrc - the source image
public java.awt.geom.Point2D getPoint2D(java.awt.geom.Point2D srcPoint,
java.awt.geom.Point2D dstPoint)
Color reduction does not alter the geometry of the source image, so therefore th source point is always returned.
getPoint2D in interface java.awt.image.BufferedImageOpsrcPoint - the source Point2DdstPoint - the destination Point2D
public java.awt.RenderingHints getRenderingHints()
null if no hints have been set.
getRenderingHints in interface java.awt.image.BufferedImageOpnull
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||