#include <math.h>
#include <stdio.h>
#include "rle_config.h"
#include "colorquant.h"
Go to the source code of this file.
|
static void | QuantHistogram () |
|
static void | BoxStats () |
|
static void | UpdateFrequencies () |
|
static void | ComputeRGBMap () |
|
static void | SetRGBmap () |
|
void | inv_cmap () |
|
static int | CutBoxes () |
|
static int | CutBox () |
|
static int | GreatestVariance () |
|
static int | FindCutpoint () |
|
int | colorquant (unsigned char *red, unsigned char *green, unsigned char *blue, unsigned long pixels, colormap, int colors, int bits, unsigned char *rgbmap, int flags, int accum_hist) |
|
static void | QuantHistogram (unsigned char *r, unsigned char *g, unsigned char *b, Box *box, int quantize) |
|
static int | CutBoxes (Box *boxes, int colors) |
|
static int | GreatestVariance (Box *boxes, int n) |
|
static void | BoxStats (Box *box) |
|
static int | CutBox (Box *box, Box *newbox) |
|
static int | FindCutpoint (Box *box, int color, Box *newbox1, Box *newbox2) |
|
static void | UpdateFrequencies (Box *box1, Box *box2) |
|
static void | ComputeRGBMap (Box *boxes, int colors, unsigned char *rgbmap, int bits, colormap, int fast) |
|
static void | SetRGBmap (int boxnum, Box *box, unsigned char *rgbmap, int bits) |
|
#define FULLINTENSITY 255 |
#define MAX |
( |
|
x, |
|
|
|
y |
|
) |
| ((x) > (y) ? (x) : (y)) |
static void BoxStats |
( |
Box * |
box | ) |
|
|
static |
Definition at line 408 of file colorquant.c.
411 register int i, color;
421 for (color = 0; color < 3; color++) {
424 freq = &box->
freq[color][
i];
425 for (; i < box->
high[color]; i++, freq++) {
429 box->
mean[color] = mean / (double)box->
weight;
unsigned long freq[3][256]
static unsigned long SumPixels
static struct Requester freq
int colorquant |
( |
unsigned char * |
red, |
|
|
unsigned char * |
green, |
|
|
unsigned char * |
blue, |
|
|
unsigned long |
pixels, |
|
|
colormap |
, |
|
|
int |
colors, |
|
|
int |
bits, |
|
|
unsigned char * |
rgbmap, |
|
|
int |
flags, |
|
|
int |
accum_hist |
|
) |
| |
Definition at line 242 of file colorquant.c.
256 fprintf(stderr,
"colorquant: bad value for accum_hist\n");
264 if (! accum_hist || accum_hist ==
INIT_HIST) {
271 bzero(
Boxes->
freq[0], ColormaxI *
sizeof(
unsigned long));
272 bzero(
Boxes->
freq[1], ColormaxI *
sizeof(
unsigned long));
273 bzero(
Boxes->
freq[2], ColormaxI *
sizeof(
unsigned long));
279 if ( accum_hist != PROCESS_HIST )
282 if ( !accum_hist || accum_hist == PROCESS_HIST) {
290 for (i = 0; i < OutColors; i++) {
292 (
unsigned char)(
Boxes[i].mean[
REDI] * Cfactor + 0.5);
294 (
unsigned char)(
Boxes[i].mean[
GREENI] * Cfactor + 0.5);
296 (
unsigned char)(
Boxes[i].mean[
BLUEI] * Cfactor + 0.5);
static void ComputeRGBMap()
static unsigned char blue[256]
unsigned long freq[3][256]
static unsigned int ColormaxI
static unsigned long NPixels
static unsigned char green[256]
static unsigned long SumPixels
static unsigned long * Histogram
static void QuantHistogram()
static unsigned char red[256]
static void ComputeRGBMap |
( |
| ) |
|
|
static |
static void ComputeRGBMap |
( |
Box * |
boxes, |
|
|
int |
colors, |
|
|
unsigned char * |
rgbmap, |
|
|
int |
bits, |
|
|
colormap |
, |
|
|
int |
fast |
|
) |
| |
|
static |
Definition at line 580 of file colorquant.c.
593 for (i = 0; i < colors; i++)
600 #ifdef slow_color_map
601 find_colors(boxes, colors, rgbmap, bits,
colormap, 1);
static unsigned long * Histogram
static int CutBox |
( |
Box * |
box, |
|
|
Box * |
newbox |
|
) |
| |
|
static |
Definition at line 440 of file colorquant.c.
459 for (i = 0; i < 3; i++) {
460 if (
FindCutpoint(box, i, &newboxes[i][0], &newboxes[i][1]))
473 *box = newboxes[
REDI][0];
474 *newbox = newboxes[
REDI][1];
475 }
else if (totalvar[
GREENI] <= totalvar[
REDI] &&
476 totalvar[
GREENI] <= totalvar[BLUEI]) {
477 *box = newboxes[
GREENI][0];
478 *newbox = newboxes[
GREENI][1];
480 *box = newboxes[
BLUEI][0];
481 *newbox = newboxes[
BLUEI][1];
static int FindCutpoint()
static int CutBoxes |
( |
Box * |
boxes, |
|
|
int |
colors |
|
) |
| |
|
static |
Definition at line 360 of file colorquant.c.
373 for (curbox = 1; curbox < colors; curbox++) {
375 &boxes[curbox]) ==
FALSE)
static unsigned int ColormaxI
static unsigned long SumPixels
static int GreatestVariance()
static int FindCutpoint |
( |
| ) |
|
|
static |
static int FindCutpoint |
( |
Box * |
box, |
|
|
int |
color, |
|
|
Box * |
newbox1, |
|
|
Box * |
newbox2 |
|
) |
| |
|
static |
Definition at line 493 of file colorquant.c.
498 int i, maxindex, minindex, cutpoint;
499 unsigned long optweight, curweight;
501 if (box->
low[color] + 1 == box->
high[color])
503 minindex = (
int)((box->
low[color] + box->
mean[color]) * 0.5);
504 maxindex = (
int)((box->
mean[color] + box->
high[color]) * 0.5);
510 for (i = box->
low[color] ; i < minindex ; i++)
511 curweight += box->
freq[color][
i];
514 for (i = minindex; i <= maxindex ; i++) {
515 curweight += box->
freq[color][
i];
516 if (curweight == box->
weight)
518 u += (float)(i * box->
freq[color][i]) /
520 v = ((
float)curweight / (float)(box->
weight-curweight)) *
521 (box->
mean[color]-u)*(box->
mean[color]-u);
525 optweight = curweight;
529 *newbox1 = *newbox2 = *box;
530 newbox1->
weight = optweight;
531 newbox2->
weight -= optweight;
532 newbox1->
high[color] = cutpoint;
533 newbox2->
low[color] = cutpoint;
unsigned long freq[3][256]
static void UpdateFrequencies()
static int GreatestVariance |
( |
| ) |
|
|
static |
static int GreatestVariance |
( |
Box * |
boxes, |
|
|
int |
n |
|
) |
| |
|
static |
Definition at line 387 of file colorquant.c.
391 register int i, whichbox = 0;
395 for (i = 0; i < n; i++) {
396 if (boxes[i].weightedvar > max) {
static void QuantHistogram |
( |
| ) |
|
|
static |
static void QuantHistogram |
( |
unsigned char * |
r, |
|
|
unsigned char * |
g, |
|
|
unsigned char * |
b, |
|
|
Box * |
box, |
|
|
int |
quantize |
|
) |
| |
|
static |
Definition at line 315 of file colorquant.c.
320 register unsigned long *rf, *gf, *bf;
334 for (i = 0; i <
NPixels; i++) {
342 unsigned char rr, gg, bb;
343 for (i = 0; i <
NPixels; i++) {
344 rr = (*
r++)>>(8-
Bits);
345 gg = (*
g++)>>(8-
Bits);
346 bb = (*
b++)>>(8-
Bits);
unsigned long freq[3][256]
static unsigned long NPixels
static unsigned long * Histogram
static void SetRGBmap |
( |
| ) |
|
|
static |
static void SetRGBmap |
( |
int |
boxnum, |
|
|
Box * |
box, |
|
|
unsigned char * |
rgbmap, |
|
|
int |
bits |
|
) |
| |
|
static |
Definition at line 612 of file colorquant.c.
618 register int r,
g,
b;
620 for (r = box->
low[
REDI]; r < box->high[
REDI]; r++) {
623 rgbmap[(((r<<bits)|g)<<bits)|b]=(
char)boxnum;
static void UpdateFrequencies |
( |
| ) |
|
|
static |
static void UpdateFrequencies |
( |
Box * |
box1, |
|
|
Box * |
box2 |
|
) |
| |
|
static |
Definition at line 546 of file colorquant.c.
549 register unsigned long myfreq, *h;
550 register int b,
g,
r;
557 for (r = box1->
low[0]; r < box1->high[0]; r++) {
559 for (g = box1->
low[1];g < box1->high[1]; g++) {
562 for (; b < box1->
high[2]; b++) {
563 if ((myfreq = *h++) == 0)
565 box1->
freq[0][
r] += myfreq;
566 box1->
freq[1][
g] += myfreq;
567 box1->
freq[2][
b] += myfreq;
568 box2->
freq[0][
r] -= myfreq;
569 box2->
freq[1][
g] -= myfreq;
570 box2->
freq[2][
b] -= myfreq;
unsigned long freq[3][256]
static unsigned int ColormaxI
static unsigned long * Histogram
char rcsid[] = "$Header: /l/spencer/src/urt/lib/RCS/colorquant.c,v 3.0.1.4 1992/04/30 14:06:48 spencer Exp $" |
|
static |