23 |
|
#define part(cn) ((cn)>>2) |
24 |
|
#define prim(cn) ((cn)&3) |
25 |
|
/* our color table (global) */ |
26 |
< |
BYTE clrtab[256][3]; |
26 |
> |
extern BYTE clrtab[256][3]; |
27 |
|
/* histogram of colors / color assignments */ |
28 |
|
static unsigned histo[NRED][NGRN][NBLU]; |
29 |
|
#define cndx(c) histo[((c)[RED]*NRED)>>8][((c)[GRN]*NGRN)>>8][((c)[BLU]*NBLU)>>8] |
41 |
|
#endif |
42 |
|
|
43 |
|
|
44 |
< |
new_histo() /* clear our histogram */ |
44 |
> |
new_histo(n) /* clear our histogram */ |
45 |
> |
int n; |
46 |
|
{ |
47 |
|
bzero((char *)histo, sizeof(histo)); |
48 |
+ |
return(0); |
49 |
|
} |
50 |
|
|
51 |
|
|
79 |
|
#ifdef CLOSEST |
80 |
|
closest(ncolors); /* ensure colors picked are closest */ |
81 |
|
#endif |
82 |
+ |
/* reset dithering function */ |
83 |
+ |
dith_colrs((BYTE *)NULL, (COLR *)NULL, 0); |
84 |
|
/* return new color table size */ |
85 |
|
return(ncolors); |
86 |
|
} |
111 |
|
register COLR *cs; |
112 |
|
int n; |
113 |
|
{ |
114 |
< |
static short (*cerr)[3]; |
114 |
> |
static short (*cerr)[3] = NULL; |
115 |
|
static int N = 0; |
116 |
|
int err[3], errp[3]; |
117 |
|
register int x, i; |
118 |
|
|
119 |
|
if (n != N) { /* get error propogation array */ |
120 |
< |
if (N) |
121 |
< |
cerr = (short (*)[3])realloc((char *)cerr, |
122 |
< |
3*n*sizeof(short)); |
123 |
< |
else |
120 |
> |
if (N) { |
121 |
> |
free((char *)cerr); |
122 |
> |
cerr = NULL; |
123 |
> |
} |
124 |
> |
if (n) |
125 |
|
cerr = (short (*)[3])malloc(3*n*sizeof(short)); |
126 |
|
if (cerr == NULL) { |
127 |
|
N = 0; |
186 |
|
#define c0 r |
187 |
|
register int r, g, b; |
188 |
|
int pri; |
189 |
< |
int t[HMAX], med; |
189 |
> |
long t[HMAX], med; |
190 |
|
/* find dominant axis */ |
191 |
|
pri = RED; |
192 |
|
if (box[GRN][1]-box[GRN][0] > box[pri][1]-box[pri][0]) |
242 |
|
int p; |
243 |
|
register int box[3][2]; |
244 |
|
{ |
245 |
< |
long sum[3]; |
246 |
< |
int r, g, n; |
247 |
< |
register int b, c; |
245 |
> |
unsigned long sum[3]; |
246 |
> |
unsigned r, g; |
247 |
> |
unsigned long n; |
248 |
> |
register unsigned b, c; |
249 |
|
/* sum pixels in box */ |
250 |
|
n = 0; |
251 |
|
sum[RED] = sum[GRN] = sum[BLU] = 0; |
260 |
|
} |
261 |
|
histo[r][g][b] = p; /* assign pixel */ |
262 |
|
} |
263 |
+ |
if (n >= (1L<<23)/HMAX) { /* avoid overflow */ |
264 |
+ |
sum[RED] /= n; |
265 |
+ |
sum[GRN] /= n; |
266 |
+ |
sum[BLU] /= n; |
267 |
+ |
n = 1; |
268 |
+ |
} |
269 |
|
if (n) { /* compute average */ |
270 |
|
clrtab[p][RED] = sum[RED]*256/NRED/n; |
271 |
|
clrtab[p][GRN] = sum[GRN]*256/NGRN/n; |