1 |
< |
/* Copyright (c) 1989 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
16 |
|
* distribution is correlated to the last. |
17 |
|
*/ |
18 |
|
|
19 |
< |
#include "color.h" |
19 |
> |
#include "standard.h" |
20 |
|
|
21 |
< |
#define NULL 0 |
21 |
> |
#include "color.h" |
22 |
|
/* histogram resolution */ |
23 |
|
#define NRED 24 |
24 |
|
#define NGRN 32 |
33 |
|
(int)(colval(c,p)*256.) : 255 ] |
34 |
|
/* color partition tree */ |
35 |
|
#define CNODE short |
36 |
< |
#define set_branch(p,c) ((c)<<2|(p)) |
36 |
> |
#define set_branch(p,c) ((c)<<2|(p)) |
37 |
|
#define set_pval(pv) ((pv)<<2|3) |
38 |
|
#define is_branch(cn) (((cn)&3)!=3) |
39 |
|
#define is_pval(cn) (((cn)&3)==3) |
43 |
|
/* our color table */ |
44 |
|
static struct tabent { |
45 |
|
long sum[3]; /* sum of colors using this entry */ |
46 |
< |
long n; /* number of colors */ |
47 |
< |
short ent[3]; /* current table value */ |
46 |
> |
int n; /* number of colors */ |
47 |
> |
BYTE ent[3]; /* current table value */ |
48 |
|
} *clrtab = NULL; |
49 |
|
/* color cube partition */ |
50 |
|
static CNODE *ctree = NULL; |
91 |
|
COLOR col; |
92 |
|
int (*set_pixel)(); |
93 |
|
{ |
94 |
+ |
extern char errmsg[]; |
95 |
|
int r, g, b; |
96 |
|
int cv[3]; |
97 |
|
register CNODE *tp; |
111 |
|
if (cv[prim(*tp)] < part(*tp)) |
112 |
|
tp += 1<<h; /* left branch */ |
113 |
|
else |
114 |
< |
tp += 1<<(h+1); /* right branch */ |
114 |
> |
tp += 1<<(h+1); /* right branch */ |
115 |
|
h = pval(*tp); |
116 |
|
/* add to color table */ |
117 |
|
clrtab[h].sum[RED] += r; |
128 |
|
(g-clrtab[h].ent[GRN])*(g-clrtab[h].ent[GRN]) + |
129 |
|
(b-clrtab[h].ent[BLU])*(b-clrtab[h].ent[BLU]) > MAXDST2) { |
130 |
|
clrtab[h].ent[RED] = r; |
131 |
< |
clrtab[h].ent[GRN] = g; /* reassign pixel */ |
131 |
> |
clrtab[h].ent[GRN] = g; /* reassign pixel */ |
132 |
|
clrtab[h].ent[BLU] = b; |
133 |
|
#ifdef DEBUG |
134 |
|
sprintf(errmsg, "pixel %d = (%d,%d,%d) (%d refs)\n", |
142 |
|
|
143 |
|
|
144 |
|
make_gmap(gam) /* make gamma correction map */ |
145 |
< |
double gam; |
145 |
> |
double gam; |
146 |
|
{ |
146 |
– |
extern double pow(); |
147 |
|
register int i; |
148 |
|
|
149 |
|
for (i = 0; i < 256; i++) |
150 |
|
clrmap[RED][i] = |
151 |
|
clrmap[GRN][i] = |
152 |
< |
clrmap[BLU][i] = 256.0 * pow(i/256.0, 1.0/gam); |
152 |
> |
clrmap[BLU][i] = 256.0 * pow((i+0.5)/256.0, 1.0/gam); |
153 |
|
} |
154 |
|
|
155 |
|
|