77 |
|
#ifdef CLOSEST |
78 |
|
closest(ncolors); /* ensure colors picked are closest */ |
79 |
|
#endif |
80 |
+ |
/* reset dithering function */ |
81 |
+ |
dith_colrs((BYTE *)NULL, (COLR *)NULL, 0); |
82 |
|
/* return new color table size */ |
83 |
|
return(ncolors); |
84 |
|
} |
109 |
|
register COLR *cs; |
110 |
|
int n; |
111 |
|
{ |
112 |
< |
static short (*cerr)[3]; |
112 |
> |
static short (*cerr)[3] = NULL; |
113 |
|
static int N = 0; |
114 |
|
int err[3], errp[3]; |
115 |
|
register int x, i; |
116 |
|
|
117 |
|
if (n != N) { /* get error propogation array */ |
118 |
< |
if (N) |
119 |
< |
cerr = (short (*)[3])realloc((char *)cerr, |
120 |
< |
3*n*sizeof(short)); |
121 |
< |
else |
118 |
> |
if (N) { |
119 |
> |
free((char *)cerr); |
120 |
> |
cerr = NULL; |
121 |
> |
} |
122 |
> |
if (n) |
123 |
|
cerr = (short (*)[3])malloc(3*n*sizeof(short)); |
124 |
|
if (cerr == NULL) { |
125 |
|
N = 0; |
184 |
|
#define c0 r |
185 |
|
register int r, g, b; |
186 |
|
int pri; |
187 |
< |
int t[HMAX], med; |
187 |
> |
long t[HMAX], med; |
188 |
|
/* find dominant axis */ |
189 |
|
pri = RED; |
190 |
|
if (box[GRN][1]-box[GRN][0] > box[pri][1]-box[pri][0]) |
240 |
|
int p; |
241 |
|
register int box[3][2]; |
242 |
|
{ |
243 |
< |
long sum[3]; |
244 |
< |
int r, g, n; |
245 |
< |
register int b, c; |
243 |
> |
unsigned long sum[3]; |
244 |
> |
unsigned r, g; |
245 |
> |
unsigned long n; |
246 |
> |
register unsigned b, c; |
247 |
|
/* sum pixels in box */ |
248 |
|
n = 0; |
249 |
|
sum[RED] = sum[GRN] = sum[BLU] = 0; |
258 |
|
} |
259 |
|
histo[r][g][b] = p; /* assign pixel */ |
260 |
|
} |
261 |
+ |
if (n >= (1L<<23)/HMAX) { /* avoid overflow */ |
262 |
+ |
sum[RED] /= n; |
263 |
+ |
sum[GRN] /= n; |
264 |
+ |
sum[BLU] /= n; |
265 |
+ |
n = 1; |
266 |
+ |
} |
267 |
|
if (n) { /* compute average */ |
268 |
|
clrtab[p][RED] = sum[RED]*256/NRED/n; |
269 |
|
clrtab[p][GRN] = sum[GRN]*256/NGRN/n; |