|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object O2Plib.image.MedianCut
class MedianCut
MedianCut converts an RGB image to 8-bit index color using Heckbert's median-cut color quantization algorithm. Based on median.c by Anton Kruger from the September, 1994 issue of Dr. Dobbs Journal. Notes on the algorithm: 1. It takes the 24-bit (r,g,b) pixel, clips the bottom 3 bits of each color to make a packed 15-bit pixel (2**15=32768). 2. It then builds a build 32x32x32 RGB histogram hist15[0:32768]. 3. Calling code invokes cvtImg24toImg8() to cvt color space defined by hist15[] into maxcubes cubes. 3.1 Create initial cube from hist15[] data. 3.2 Search cubeList[] for next cube to split, lowest level cube. 3.2.1 Check if split cubes 3.2.2 Find longest dimension of this cube 3.2.3 Sort along "longdim" by: reorderColors(), quickSort(), restoreColorOrder(). 3.2.4 Find median 3.2.5 Now split "cube" at the median and add the two new cubes to the list of cubes. 3.3 Compute the color map, inverse color map. 3.4 Convert 24-bit RGB image to an 8-bit image. 4. The caller gets the return data from the MedianCut instance: pixels8[], rLUT[], gLUT[], and bLUT[].
Field Summary | |
---|---|
(package private) byte[] |
bLUT
[0:255] Blue Color map look up table |
(package private) int |
colorMax
# of non-zero bins in hist15[] |
private MC_Cube[] |
cubeList
list of cubes |
(package private) byte[] |
gLUT
[0:255] Green Color map look up table |
(package private) int |
height
width size of image |
private int[] |
hist15
[0:32K] 15-bit RGB hist. |
private int[] |
histPtr
[0:colorMax-1] points to colors in "hist15[]" |
(package private) static int |
HSIZE
max size of image histogram |
(package private) static int |
MAXCOLORS
maximum # of output colors |
(package private) int |
ncubes
# of color cubes |
private int[] |
pixels32
32-bit image[width*height] (Alpha,Red,Green,Blue) pixels |
(package private) byte[] |
pixels8
8-bit image[width*height] using LUTs |
(package private) byte[] |
rLUT
[0:255] Red Color map look up table |
(package private) int |
width
width size of image |
Constructor Summary | |
---|---|
MedianCut(int[] pixels,
int width,
int height)
MedianCut() - Constructor Then call cvtImg24toImg8() to get the 8-bit image. |
Method Summary | |
---|---|
private int |
blueBits(int x)
blueBits() - Get 8-bit blue component of a 15-bit color 8-bit pixel with low 3 bits zero. |
(package private) boolean |
cvtImg24toImg8(int maxcubes)
cvtImg24toImg8() - Uses Heckbert's median-cut algorithm to divide the color space defined by "hist15[]" into "maxcubes" cubes. |
private int |
greenBits(int x)
greenBits() - Get 8-bit green component of a 15-bit color 8-bit pixel with low 3 bits zero. |
(package private) void |
make8BitImage()
make8BitImage() - Generate 8-bit image from interla 15-bit image. |
(package private) void |
makeInverseMap(int[] hist15,
int ncubes)
makeInverseMap() - for all cubes, compute centroid of colors in cube. |
(package private) void |
quickSort(int[] a,
int lo0,
int hi0)
quickSort() - sort the map Based on the QuickSort method by James Gosling from Sun's SortDemo applet |
private int |
redBits(int x)
redBits() - Get 8-bit red component of a 15-bit color 8-bit pixel with low 3 bits zero. |
(package private) void |
reorderColors(int[] histP,
int lo,
int hi,
int longDim)
reorderColors() - Change ordering of 5-bit colors in each word of int[] so we can sort on the 'longDim' color |
(package private) void |
restoreColorOrder(int[] histP,
int lo,
int hi,
int longDim)
restoreColorOrder() - Restore the 5-bit colors to original order |
private int |
rgb15(int c)
rgb15() - convert from 24-bit (ignore alpha) to 15-bit color. |
private void |
shrinkCube(MC_Cube cube)
shrinkCube() - Encloses "cube" with a tight-fitting cube by updating the (rmin,gmin,bmin) and (rmax,gmax,bmax) members of "cube". |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static final int MAXCOLORS
static final int HSIZE
private int[] hist15
private int[] histPtr
private int[] pixels32
private MC_Cube[] cubeList
int ncubes
int colorMax
int width
int height
byte[] pixels8
byte[] rLUT
byte[] gLUT
byte[] bLUT
Constructor Detail |
---|
MedianCut(int[] pixels, int width, int height)
pixels
- array of 32-bit Java Color pixelwidth
- is the image sizeheight
- is the image sizeMethod Detail |
---|
private final int rgb15(int c)
c
- is the RGB 24-bit Java Color pixel
private final int redBits(int x)
x
- 15-bit color component
private final int greenBits(int x)
x
- 15-bit color component
private final int blueBits(int x)
x
- 15-bit color component
boolean cvtImg24toImg8(int maxcubes)
maxcubes
- to use
private void shrinkCube(MC_Cube cube)
cube
- is the cube to usevoid makeInverseMap(int[] hist15, int ncubes)
hist15
- is the histogram to computencubes
- is the number of cubes to usevoid reorderColors(int[] histP, int lo, int hi, int longDim)
void restoreColorOrder(int[] histP, int lo, int hi, int longDim)
void quickSort(int[] a, int lo0, int hi0)
void make8BitImage()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |