#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "allheaders.h"
#define DEBUG_MC_COLORS 0 |
#define DEBUG_SPLIT_AXES 0 |
static L_BOX3D * box3dCreate | ( | l_int32 | r1, | |
l_int32 | r2, | |||
l_int32 | g1, | |||
l_int32 | g2, | |||
l_int32 | b1, | |||
l_int32 | b2 | |||
) | [static] |
static void getColorIndexMedianCut | ( | l_uint32 | pixel, | |
l_int32 | rshift, | |||
l_uint32 | mask, | |||
l_int32 | sigbits, | |||
l_int32 * | pindex | |||
) | [static] |
Input: pixel (32 bit rgb) rshift (of component: 8 - sigbits) mask (over sigbits) sigbits &index (<return> rgb index value) Return: void
Notes: (1) This is used on each pixel in the source image. No checking is done on input values.
static l_int32 medianCutApply | ( | l_int32 * | histo, | |
l_int32 | sigbits, | |||
L_BOX3D * | vbox, | |||
L_BOX3D ** | pvbox1, | |||
L_BOX3D ** | pvbox2 | |||
) | [static] |
Input: histo (array; in rgb colorspace) sigbits vbox (input 3D box) &vbox1, vbox2 (<return> vbox split in two parts) Return: 0 if OK, 1 on error
static PIXCMAP * pixcmapGenerateFromHisto | ( | PIX * | pixs, | |
l_int32 | depth, | |||
l_int32 * | histo, | |||
l_int32 | histosize, | |||
l_int32 | sigbits | |||
) | [static] |
Input: pixs (32 bpp; rgb color) depth (of colormap) histo histosize sigbits Return: colormap, or null on error
Notes: (1) This is used when the number of colors in the histo is not greater than maxcolors. (2) As a side-effect, the histo becomes an inverse colormap, labeling the cmap indices for each existing color.
static PIXCMAP * pixcmapGenerateFromMedianCuts | ( | L_HEAP * | lh, | |
l_int32 * | histo, | |||
l_int32 | sigbits | |||
) | [static] |
pixcmapGenerateFromMedianCuts()
Input: lh (priority queue of pointers to vboxes) histo sigbits (valid: 5 or 6) Return: cmap, or null on error
Notes: (1) Each vbox in the heap represents a color in the colormap. (2) As a side-effect, the histo becomes an inverse colormap, where the part of the array correpsonding to each vbox is labeled with the cmap index for that vbox. Then for each rgb pixel, the colormap index is found directly by mapping the rgb value to the histo array index.
Input: pixs (32 bpp; rgb color) sigbits (valid: 5, 6) subsample (integer > 0) Return: vbox (minimum 3D box in color space enclosing all pixels), or null on error
Notes: (1) Computes the minimum 3D box in color space enclosing all pixels in the image.
Input: pixs (32 bpp; rgb color) sigbits (valid: 5 or 6) subsample (integer > 0) Return: histo (1-d array, giving the number of pixels in each quantized region of color space), or null on error
Notes: (1) Array is indexed by (3 * sigbits) bits. The array size is 2^(3 * sigbits). (2) Indexing into the array from rgb uses red sigbits as most significant and blue as least.
Input: pixs (32 bpp; rgb color) ditherflag (1 for dither; 0 for no dither) Return: pixd (8 bit with colormap), or null on error
Notes: (1) Simple interface. See pixMedianCutQuantGeneral() for use of defaulted parameters.
PIX* pixMedianCutQuantGeneral | ( | PIX * | pixs, | |
l_int32 | ditherflag, | |||
l_int32 | outdepth, | |||
l_int32 | maxcolors, | |||
l_int32 | sigbits, | |||
l_int32 | maxsub | |||
) |
Input: pixs (32 bpp; rgb color) ditherflag (1 for dither; 0 for no dither) outdepth (output depth; valid: 0, 1, 2, 4, 8) maxcolors (between 2 and 256) sigbits (valid: 5 or 6; use 0 for default) maxsub (max subsampling, integer; use 0 for default; 1 for no subsampling) Return: pixd (8 bit with colormap), or null on error
Notes: (1) must be in the range [2 ... 256]. (2) Use = 0 to have the output depth computed as the minimum required to hold the actual colors found, given the constraint. (3) Use = 1, 2, 4 or 8 to specify the output depth. In that case, must not exceed 2^(outdepth). (4) If there are fewer quantized colors in the image than , the colormap is simply generated from those colors. (5) is the maximum allowed subsampling to be used in the computation of the color histogram and region of occupied color space. The subsampling is chosen internally for efficiency, based on the image size, but this parameter limits it. Use = 0 for the internal default, which is the maximum allowed subsampling. Use = 1 to prevent subsampling. In general use >= 1 to specify the maximum subsampling to be allowed, where the actual subsampling will be the minimum of this value and the internally determined default value. (6) If the image appears gray because either most of the pixels are gray or most of the pixels are essentially black or white, the image is trivially quantized with a grayscale colormap. The reason is that median cut divides the color space into rectangular regions, and it does a very poor job if all the pixels are near the diagonal of the color space cube.
static PIX * pixQuantizeWithColormap | ( | PIX * | pixs, | |
l_int32 | ditherflag, | |||
l_int32 | outdepth, | |||
PIXCMAP * | cmap, | |||
l_int32 * | indexmap, | |||
l_int32 | mapsize, | |||
l_int32 | sigbits | |||
) | [static] |
Input: pixs (32 bpp; rgb color) ditherflag (1 for dither; 0 for no dither) outdepth cmap indexmap histosize sigbits Return: pixd (quantized to colormap), or null on error
Notes: (1) The indexmap is a LUT that takes the rgb indices of the pixel and returns the index into the colormap. (2) If ditherflag is 1, is ignored and the output depth is set to 8.
static l_int32 vboxGetAverageColor | ( | L_BOX3D * | vbox, | |
l_int32 * | histo, | |||
l_int32 | sigbits, | |||
l_int32 | index, | |||
l_int32 * | prval, | |||
l_int32 * | pgval, | |||
l_int32 * | pbval | |||
) | [static] |
Input: vbox (3d region of color space for one quantized color) histo sigbits (valid: 5 or 6) index (if >= 0, assign to all colors in histo in this vbox) &rval, &gval, &bval (<returned> average color) Return: cmap, or null on error
Notes: (1) The vbox represents one color in the colormap. (2) If index >= 0, as a side-effect, all array elements in the histo corresponding to the vbox are labeled with this cmap index for that vbox. Otherwise, the histo array is not changed.
Input: vbox (3d region of color space for one quantized color) histo sigbits (valid: 5 or 6) Return: number of image pixels in this region, or 0 on error
Input: vbox (3d region of color space for one quantized color) Return: quantized volume of vbox, or 0 on error
const l_int32 DEFAULT_SIG_BITS = 5 [static] |
const l_float32 FRACT_BY_POPULATION = 0.85 [static] |
const l_int32 MAX_ITERS_ALLOWED = 5000 [static] |