| 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 */ |
| 107 |
|
register COLR *cs; |
| 108 |
|
int n; |
| 109 |
|
{ |
| 110 |
< |
static short (*cerr)[3]; |
| 110 |
> |
static short (*cerr)[3] = NULL; |
| 111 |
|
static int N = 0; |
| 112 |
|
int err[3], errp[3]; |
| 113 |
|
register int x, i; |
| 114 |
|
|
| 115 |
|
if (n != N) { /* get error propogation array */ |
| 116 |
< |
if (N) |
| 117 |
< |
cerr = (short (*)[3])realloc((char *)cerr, |
| 118 |
< |
3*n*sizeof(short)); |
| 119 |
< |
else |
| 116 |
> |
if (N) { |
| 117 |
> |
free((char *)cerr); |
| 118 |
> |
cerr = NULL; |
| 119 |
> |
} |
| 120 |
> |
if (n) |
| 121 |
|
cerr = (short (*)[3])malloc(3*n*sizeof(short)); |
| 122 |
|
if (cerr == NULL) { |
| 123 |
|
N = 0; |
| 182 |
|
#define c0 r |
| 183 |
|
register int r, g, b; |
| 184 |
|
int pri; |
| 185 |
< |
int t[HMAX], med; |
| 185 |
> |
long t[HMAX], med; |
| 186 |
|
/* find dominant axis */ |
| 187 |
|
pri = RED; |
| 188 |
|
if (box[GRN][1]-box[GRN][0] > box[pri][1]-box[pri][0]) |
| 238 |
|
int p; |
| 239 |
|
register int box[3][2]; |
| 240 |
|
{ |
| 241 |
< |
long sum[3]; |
| 242 |
< |
int r, g, n; |
| 243 |
< |
register int b, c; |
| 241 |
> |
unsigned long sum[3]; |
| 242 |
> |
unsigned r, g; |
| 243 |
> |
unsigned long n; |
| 244 |
> |
register unsigned b, c; |
| 245 |
|
/* sum pixels in box */ |
| 246 |
|
n = 0; |
| 247 |
|
sum[RED] = sum[GRN] = sum[BLU] = 0; |
| 256 |
|
} |
| 257 |
|
histo[r][g][b] = p; /* assign pixel */ |
| 258 |
|
} |
| 259 |
+ |
if (n >= (1L<<23)/HMAX) { /* avoid overflow */ |
| 260 |
+ |
sum[RED] /= n; |
| 261 |
+ |
sum[GRN] /= n; |
| 262 |
+ |
sum[BLU] /= n; |
| 263 |
+ |
n = 1; |
| 264 |
+ |
} |
| 265 |
|
if (n) { /* compute average */ |
| 266 |
|
clrtab[p][RED] = sum[RED]*256/NRED/n; |
| 267 |
|
clrtab[p][GRN] = sum[GRN]*256/NGRN/n; |
| 349 |
|
register BYTE col[3]; |
| 350 |
|
int r, g, b; |
| 351 |
|
{ |
| 352 |
< |
register unsigned tmp; |
| 352 |
> |
register int tmp; |
| 353 |
|
register unsigned sum; |
| 354 |
|
|
| 355 |
|
tmp = col[RED]*NRED/256 - r; |