ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/clrtab.c
(Generate patch)

Comparing ray/src/px/clrtab.c (file contents):
Revision 2.2 by greg, Tue Oct 13 09:07:51 1992 UTC vs.
Revision 2.9 by greg, Thu Dec 9 12:04:23 1993 UTC

# Line 1 | Line 1
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";
# Line 32 | Line 32 | static int     CLRCUBE[3][2] = {0,NRED,0,NGRN,0,NBLU};
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 */
# Line 71 | Line 77 | int    ncolors;
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   }
# Line 101 | Line 109 | register BYTE  *bs;
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;
# Line 175 | Line 184 | register int   box[3][2];
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])
# Line 231 | Line 240 | mktabent(p, box)       /* compute average color for box and
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;
# Line 248 | Line 258 | register int   box[3][2];
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;
# Line 279 | Line 295 | int    n;
295                  neigh[i][0] = i;                /* identity is terminator */
296          }
297                                          /* make neighbor lists */
298 <        for (r = 0; r < NRED-1; r++)
299 <            for (g = 0; g < NGRN-1; g++)
300 <                for (b = 0; b < NBLU-1; b++) {
301 <                    if (histo[r][g][b] != histo[r+1][g][b])
298 >        for (r = 0; r < NRED; r++)
299 >            for (g = 0; g < NGRN; g++)
300 >                for (b = 0; b < NBLU; b++) {
301 >                    if (r < NRED-1 && histo[r][g][b] != histo[r+1][g][b])
302                          addneigh(neigh, histo[r][g][b], histo[r+1][g][b]);
303 <                    if (histo[r][g][b] != histo[r][g+1][b])
303 >                    if (g < NGRN-1 && histo[r][g][b] != histo[r][g+1][b])
304                          addneigh(neigh, histo[r][g][b], histo[r][g+1][b]);
305 <                    if (histo[r][g][b] != histo[r][g][b+1])
305 >                    if (b < NBLU-1 && histo[r][g][b] != histo[r][g][b+1])
306                          addneigh(neigh, histo[r][g][b], histo[r][g][b+1]);
307                  }
308                                          /* assign closest values */
# Line 335 | Line 351 | dist(col, r, g, b)             /* find distance from clrtab entry
351   register BYTE   col[3];
352   int     r, g, b;
353   {
354 <        register unsigned       tmp;
354 >        register int    tmp;
355          register unsigned       sum;
356          
357          tmp = col[RED]*NRED/256 - r;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines