1 |
– |
/* Copyright (c) 1993 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Simple median-cut color quantization based on colortab.c |
6 |
|
*/ |
20 |
|
#define part(cn) ((cn)>>2) |
21 |
|
#define prim(cn) ((cn)&3) |
22 |
|
/* our color table (global) */ |
23 |
< |
BYTE clrtab[256][3]; |
23 |
> |
extern BYTE clrtab[256][3]; |
24 |
|
/* histogram of colors / color assignments */ |
25 |
|
static unsigned histo[NRED][NGRN][NBLU]; |
26 |
|
#define cndx(c) histo[((c)[RED]*NRED)>>8][((c)[GRN]*NGRN)>>8][((c)[BLU]*NBLU)>>8] |
37 |
|
#endif |
38 |
|
#endif |
39 |
|
|
40 |
+ |
static cut(), mktabent(), closest(), addneigh(), setclosest(); |
41 |
+ |
static int split(); |
42 |
+ |
static unsigned dist(); |
43 |
|
|
44 |
< |
new_histo() /* clear our histogram */ |
44 |
> |
|
45 |
> |
new_histo(n) /* clear our histogram */ |
46 |
> |
int n; |
47 |
|
{ |
48 |
|
bzero((char *)histo, sizeof(histo)); |
49 |
+ |
return(0); |
50 |
|
} |
51 |
|
|
52 |
|
|
80 |
|
#ifdef CLOSEST |
81 |
|
closest(ncolors); /* ensure colors picked are closest */ |
82 |
|
#endif |
83 |
+ |
/* reset dithering function */ |
84 |
+ |
dith_colrs((BYTE *)NULL, (COLR *)NULL, 0); |
85 |
|
/* return new color table size */ |
86 |
|
return(ncolors); |
87 |
|
} |
112 |
|
register COLR *cs; |
113 |
|
int n; |
114 |
|
{ |
115 |
< |
static short (*cerr)[3]; |
115 |
> |
static short (*cerr)[3] = NULL; |
116 |
|
static int N = 0; |
117 |
|
int err[3], errp[3]; |
118 |
|
register int x, i; |
119 |
|
|
120 |
|
if (n != N) { /* get error propogation array */ |
121 |
< |
if (N) |
122 |
< |
cerr = (short (*)[3])realloc((char *)cerr, |
123 |
< |
3*n*sizeof(short)); |
124 |
< |
else |
121 |
> |
if (N) { |
122 |
> |
free((void *)cerr); |
123 |
> |
cerr = NULL; |
124 |
> |
} |
125 |
> |
if (n) |
126 |
|
cerr = (short (*)[3])malloc(3*n*sizeof(short)); |
127 |
|
if (cerr == NULL) { |
128 |
|
N = 0; |
187 |
|
#define c0 r |
188 |
|
register int r, g, b; |
189 |
|
int pri; |
190 |
< |
int t[HMAX], med; |
190 |
> |
long t[HMAX], med; |
191 |
|
/* find dominant axis */ |
192 |
|
pri = RED; |
193 |
|
if (box[GRN][1]-box[GRN][0] > box[pri][1]-box[pri][0]) |
244 |
|
register int box[3][2]; |
245 |
|
{ |
246 |
|
unsigned long sum[3]; |
247 |
< |
unsigned r, g, n; |
247 |
> |
unsigned r, g; |
248 |
> |
unsigned long n; |
249 |
|
register unsigned b, c; |
250 |
|
/* sum pixels in box */ |
251 |
|
n = 0; |
261 |
|
} |
262 |
|
histo[r][g][b] = p; /* assign pixel */ |
263 |
|
} |
264 |
< |
if (n >= (1<<23)/HMAX) { /* avoid overflow */ |
264 |
> |
if (n >= (1L<<23)/HMAX) { /* avoid overflow */ |
265 |
|
sum[RED] /= n; |
266 |
|
sum[GRN] /= n; |
267 |
|
sum[BLU] /= n; |