|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.gif4j.quantizer.Quantizer
Java implementation of Wu's Color Quantizer algorithm (see Graphics Gems vol. II, pp. 126-133, Author: Xiaolin Wu wu@csd.uwo.ca).
Algorithm description: "Greedy orthogonal bipartition of RGB space for variance minimization aided by inclusion-exclusion tricks."
Quantizer reduces the number of unique colors (quantizes) of BufferedImage
instances to the specified number of colors
(this parameter is set by color bit depth (hereinafter CBD
) value).
The available CBD values are between 2 (4 colors) and 16 (65536 colors).
Quantized BufferedImage
instances have IndexColorModel
as ColorModel (if CBD less than or equal to 8)
or DirectColorModel
for CBD values more than 8.
Quantizer
automatically detects the presence of alpha-channel
(image transparency) and retains it unchangeable if CBD more than 8 (result - DirectColorModel
based
BufferedImage
instance) or converts Transparency.TRANSLUCENT
transparency to Transparency.BITMASK
transparency.
Please note, that GIF format support images with CBD less than
or equal to 8 and one transparent color which equals (from the viewpoint of Java)
to IndexColorModel
based BufferedImage
(s)
with Transparency.BITMASK
or Transparency.OPAQUE
transparency.
This implementation supports 2 memory-oriented modes and 4 optimization-oriented
modes. The final processing mode is received by combination of one memory and one
optimization modes.
In LOW MEMORY mode Quantizer
uses less memory (up to 4 times) but usually (not always!) generates
coarser results.
In NORMAL MEMORY mode Quantizer
works more accurately but slower (up to 2 times).
Optimization-oriented modes are the next:
Quantizer
executes additional error dispersion operation
based on Floyd-Steinberg dithering algorithm.
Please note that due to speed-targeting implementation some small color errors can be occured.
Quantizer
executes additional error dispersion operation
based on Floyd-Steinberg dithering algorithm.
Within the Gif4J Library Quantizer
is used by default.
The default quantizer mode is initialized by MEMORY_LOW_FAST_DITHER
and can be changed using setDefaultMode(int)
method.
Field Summary | |
static int |
MEMORY_LOW_FAST
fast low memory mode. |
static int |
MEMORY_LOW_FAST_DITHER
fast low memory mode + dithering. |
static int |
MEMORY_LOW_OPTIMIZED
optimized low memory mode. |
static int |
MEMORY_LOW_OPTIMIZED_DITHER
optimized low memory mode + dithering. |
static int |
MEMORY_NORMAL_FAST
fast normal memory mode. |
static int |
MEMORY_NORMAL_FAST_DITHER
fast normal memory mode + dithering. |
static int |
MEMORY_NORMAL_OPTIMIZED
optimized normal memory mode. |
static int |
MEMORY_NORMAL_OPTIMIZED_DITHER
optimized normal memory mode + dithering. |
Constructor Summary | |
Quantizer()
|
Method Summary | |
static java.awt.image.BufferedImage |
quantize(java.awt.image.BufferedImage source,
int colorBitDepth)
Quantize the specified image using the default mode. |
static java.awt.image.BufferedImage |
quantize(java.awt.image.BufferedImage source,
int colorBitDepth,
boolean forceTransparency)
Quantize the specified image with transparency forcing using the default mode. |
static java.awt.image.BufferedImage |
quantize(int quantizerMode,
java.awt.image.BufferedImage source,
int colorBitDepth)
Quantize the specified image using the specified quantizer mode. |
static java.awt.image.BufferedImage |
quantize(int quantizerMode,
java.awt.image.BufferedImage source,
int colorBitDepth,
boolean forceTransparency)
Quantize the specified image with transparency forcing using the specified quantizer mode. |
static void |
setDefaultMode(int quantizerMode)
Set the default quantizer mode. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int MEMORY_LOW_FAST
public static final int MEMORY_NORMAL_FAST
public static final int MEMORY_LOW_OPTIMIZED
public static final int MEMORY_NORMAL_OPTIMIZED
public static final int MEMORY_LOW_OPTIMIZED_DITHER
public static final int MEMORY_NORMAL_OPTIMIZED_DITHER
public static final int MEMORY_LOW_FAST_DITHER
public static final int MEMORY_NORMAL_FAST_DITHER
Constructor Detail |
public Quantizer()
Method Detail |
public static java.awt.image.BufferedImage quantize(java.awt.image.BufferedImage source, int colorBitDepth)
source
- the image to quantizecolorBitDepth
- desired color table bit depth. Should be between 2 and 16.
To determine actual size of the color table, raise 2 to this parameter: for example, to quantize the specified image to 256 colors this parameter has to be equal to 8 (raise 2 to 8 = 256).
java.lang.IllegalArgumentException
- If color bit depth less than 2 or more than 16;
java.lang.NullPointerException
- If source image is nullpublic static java.awt.image.BufferedImage quantize(java.awt.image.BufferedImage source, int colorBitDepth, boolean forceTransparency)
MorphingFilter
sub-classes.)
source
- the image to quantizecolorBitDepth
- desired color table bit depth. Should be between 2 and 16.
To determine actual size of the color table, raise 2 to this parameter: for example, to quantize the specified image to 256 colors this parameter has to be equal to 8 (raise 2 to 8 = 256).forceTransparency
- if true force transparency in returned BufferedImage
instance
java.lang.IllegalArgumentException
- If color bit depth less than 2 or more than 16;
java.lang.NullPointerException
- If source image is nullpublic static java.awt.image.BufferedImage quantize(int quantizerMode, java.awt.image.BufferedImage source, int colorBitDepth)
quantizerMode
- one of the predefined quantizer modes:
MEMORY_LOW_FAST
,
MEMORY_LOW_FAST_DITHER
,
MEMORY_LOW_OPTIMIZED
,
MEMORY_LOW_OPTIMIZED_DITHER
,
MEMORY_NORMAL_FAST
,
MEMORY_NORMAL_FAST_DITHER
,
MEMORY_NORMAL_OPTIMIZED
,
MEMORY_NORMAL_OPTIMIZED_DITHER
source
- the specified image to quantizecolorBitDepth
- desired color bit depth. Should be between 2 and 16.
To determine actual size of the color table, raise 2 to this parameter: for example, to quantize the specified image to 256 colors this parameter has to be equal to 8 (raise 2 to 8 = 256).
java.lang.IllegalArgumentException
- If color bit depth less than 2 or more than 16;
java.lang.IllegalArgumentException
- If unknown quantizer mode;
java.lang.NullPointerException
- If source image is nullpublic static java.awt.image.BufferedImage quantize(int quantizerMode, java.awt.image.BufferedImage source, int colorBitDepth, boolean forceTransparency)
MorphingFilter
sub-classes.)
quantizerMode
- one of the predefined quantizer modes:
MEMORY_LOW_FAST
,
MEMORY_LOW_FAST_DITHER
,
MEMORY_LOW_OPTIMIZED
,
MEMORY_LOW_OPTIMIZED_DITHER
,
MEMORY_NORMAL_FAST
,
MEMORY_NORMAL_FAST_DITHER
,
MEMORY_NORMAL_OPTIMIZED
,
MEMORY_NORMAL_OPTIMIZED_DITHER
source
- the specified image to quantizecolorBitDepth
- desired color table bit depth. Should be between 2 and 16.
To determine actual size of the color table, raise 2 to this parameter: for example, to quantize the specified image to 256 colors this parameter has to be equal to 8 (raise 2 to 8 = 256).forceTransparency
- if true force transparency in returned BufferedImage
instance
java.lang.IllegalArgumentException
- If color bit depth less than 2 or more than 16;
java.lang.IllegalArgumentException
- If unknown quantizer mode;
java.lang.NullPointerException
- If source image is nullpublic static void setDefaultMode(int quantizerMode)
quantizerMode
- one of the predefined quantizer modes:
MEMORY_LOW_FAST
,
MEMORY_LOW_FAST_DITHER
,
MEMORY_LOW_OPTIMIZED
,
MEMORY_LOW_OPTIMIZED_DITHER
,
MEMORY_NORMAL_FAST
,
MEMORY_NORMAL_FAST_DITHER
,
MEMORY_NORMAL_OPTIMIZED
,
MEMORY_NORMAL_OPTIMIZED_DITHER
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |