| 1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1993 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 32 |
|
/* maximum propagated error during dithering */ |
| 33 |
|
#define MAXERR 20 |
| 34 |
|
/* define CLOSEST to get closest colors */ |
| 35 |
< |
#define CLOSEST 1 |
| 35 |
> |
#ifndef CLOSEST |
| 36 |
> |
#ifdef SPEED |
| 37 |
> |
#if SPEED > 8 |
| 38 |
> |
#define CLOSEST 1 /* this step takes a little longer */ |
| 39 |
> |
#endif |
| 40 |
> |
#endif |
| 41 |
> |
#endif |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
new_histo() /* clear our histogram */ |
| 181 |
|
#define c0 r |
| 182 |
|
register int r, g, b; |
| 183 |
|
int pri; |
| 184 |
< |
int t[HMAX], med; |
| 184 |
> |
long t[HMAX], med; |
| 185 |
|
/* find dominant axis */ |
| 186 |
|
pri = RED; |
| 187 |
|
if (box[GRN][1]-box[GRN][0] > box[pri][1]-box[pri][0]) |
| 237 |
|
int p; |
| 238 |
|
register int box[3][2]; |
| 239 |
|
{ |
| 240 |
< |
long sum[3]; |
| 241 |
< |
int r, g, n; |
| 242 |
< |
register int b, c; |
| 240 |
> |
unsigned long sum[3]; |
| 241 |
> |
unsigned r, g; |
| 242 |
> |
unsigned long n; |
| 243 |
> |
register unsigned b, c; |
| 244 |
|
/* sum pixels in box */ |
| 245 |
|
n = 0; |
| 246 |
|
sum[RED] = sum[GRN] = sum[BLU] = 0; |
| 255 |
|
} |
| 256 |
|
histo[r][g][b] = p; /* assign pixel */ |
| 257 |
|
} |
| 258 |
+ |
if (n >= (1L<<23)/HMAX) { /* avoid overflow */ |
| 259 |
+ |
sum[RED] /= n; |
| 260 |
+ |
sum[GRN] /= n; |
| 261 |
+ |
sum[BLU] /= n; |
| 262 |
+ |
n = 1; |
| 263 |
+ |
} |
| 264 |
|
if (n) { /* compute average */ |
| 265 |
|
clrtab[p][RED] = sum[RED]*256/NRED/n; |
| 266 |
|
clrtab[p][GRN] = sum[GRN]*256/NGRN/n; |
| 292 |
|
neigh[i][0] = i; /* identity is terminator */ |
| 293 |
|
} |
| 294 |
|
/* make neighbor lists */ |
| 295 |
< |
for (r = 0; r < NRED-1; r++) |
| 296 |
< |
for (g = 0; g < NGRN-1; g++) |
| 297 |
< |
for (b = 0; b < NBLU-1; b++) { |
| 298 |
< |
if (histo[r][g][b] != histo[r+1][g][b]) |
| 295 |
> |
for (r = 0; r < NRED; r++) |
| 296 |
> |
for (g = 0; g < NGRN; g++) |
| 297 |
> |
for (b = 0; b < NBLU; b++) { |
| 298 |
> |
if (r < NRED-1 && histo[r][g][b] != histo[r+1][g][b]) |
| 299 |
|
addneigh(neigh, histo[r][g][b], histo[r+1][g][b]); |
| 300 |
< |
if (histo[r][g][b] != histo[r][g+1][b]) |
| 300 |
> |
if (g < NGRN-1 && histo[r][g][b] != histo[r][g+1][b]) |
| 301 |
|
addneigh(neigh, histo[r][g][b], histo[r][g+1][b]); |
| 302 |
< |
if (histo[r][g][b] != histo[r][g][b+1]) |
| 302 |
> |
if (b < NBLU-1 && histo[r][g][b] != histo[r][g][b+1]) |
| 303 |
|
addneigh(neigh, histo[r][g][b], histo[r][g][b+1]); |
| 304 |
|
} |
| 305 |
|
/* assign closest values */ |
| 348 |
|
register BYTE col[3]; |
| 349 |
|
int r, g, b; |
| 350 |
|
{ |
| 351 |
< |
register unsigned tmp; |
| 351 |
> |
register int tmp; |
| 352 |
|
register unsigned sum; |
| 353 |
|
|
| 354 |
|
tmp = col[RED]*NRED/256 - r; |