--- ray/src/px/clrtab.c 1993/05/05 10:18:05 2.6 +++ ray/src/px/clrtab.c 1994/06/10 12:51:16 2.10 @@ -23,7 +23,7 @@ static char SCCSid[] = "$SunId$ LBL"; #define part(cn) ((cn)>>2) #define prim(cn) ((cn)&3) /* our color table (global) */ -BYTE clrtab[256][3]; +extern BYTE clrtab[256][3]; /* histogram of colors / color assignments */ static unsigned histo[NRED][NGRN][NBLU]; #define cndx(c) histo[((c)[RED]*NRED)>>8][((c)[GRN]*NGRN)>>8][((c)[BLU]*NBLU)>>8] @@ -41,9 +41,11 @@ static int CLRCUBE[3][2] = {0,NRED,0,NGRN,0,NBLU}; #endif -new_histo() /* clear our histogram */ +new_histo(n) /* clear our histogram */ +int n; { bzero((char *)histo, sizeof(histo)); + return(0); } @@ -77,6 +79,8 @@ int ncolors; #ifdef CLOSEST closest(ncolors); /* ensure colors picked are closest */ #endif + /* reset dithering function */ + dith_colrs((BYTE *)NULL, (COLR *)NULL, 0); /* return new color table size */ return(ncolors); } @@ -107,16 +111,17 @@ register BYTE *bs; register COLR *cs; int n; { - static short (*cerr)[3]; + static short (*cerr)[3] = NULL; static int N = 0; int err[3], errp[3]; register int x, i; if (n != N) { /* get error propogation array */ - if (N) - cerr = (short (*)[3])realloc((char *)cerr, - 3*n*sizeof(short)); - else + if (N) { + free((char *)cerr); + cerr = NULL; + } + if (n) cerr = (short (*)[3])malloc(3*n*sizeof(short)); if (cerr == NULL) { N = 0; @@ -238,7 +243,8 @@ int p; register int box[3][2]; { unsigned long sum[3]; - unsigned r, g, n; + unsigned r, g; + unsigned long n; register unsigned b, c; /* sum pixels in box */ n = 0; @@ -254,7 +260,7 @@ register int box[3][2]; } histo[r][g][b] = p; /* assign pixel */ } - if (n >= (1<<23)/HMAX) { /* avoid overflow */ + if (n >= (1L<<23)/HMAX) { /* avoid overflow */ sum[RED] /= n; sum[GRN] /= n; sum[BLU] /= n;