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.6 by greg, Wed May 5 10:18:05 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 175 | Line 181 | register int   box[3][2];
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])
# Line 231 | Line 237 | mktabent(p, box)       /* compute average color for box and
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, n;
242 >        register unsigned       b, c;
243                                                  /* sum pixels in box */
244          n = 0;
245          sum[RED] = sum[GRN] = sum[BLU] = 0;
# Line 248 | Line 254 | register int   box[3][2];
254                      }
255                      histo[r][g][b] = p;         /* assign pixel */
256                  }
257 +        if (n >= (1<<23)/HMAX) {                /* avoid overflow */
258 +                sum[RED] /= n;
259 +                sum[GRN] /= n;
260 +                sum[BLU] /= n;
261 +                n = 1;
262 +        }
263          if (n) {                                /* compute average */
264                  clrtab[p][RED] = sum[RED]*256/NRED/n;
265                  clrtab[p][GRN] = sum[GRN]*256/NGRN/n;
# Line 279 | Line 291 | int    n;
291                  neigh[i][0] = i;                /* identity is terminator */
292          }
293                                          /* make neighbor lists */
294 <        for (r = 0; r < NRED-1; r++)
295 <            for (g = 0; g < NGRN-1; g++)
296 <                for (b = 0; b < NBLU-1; b++) {
297 <                    if (histo[r][g][b] != histo[r+1][g][b])
294 >        for (r = 0; r < NRED; r++)
295 >            for (g = 0; g < NGRN; g++)
296 >                for (b = 0; b < NBLU; b++) {
297 >                    if (r < NRED-1 && histo[r][g][b] != histo[r+1][g][b])
298                          addneigh(neigh, histo[r][g][b], histo[r+1][g][b]);
299 <                    if (histo[r][g][b] != histo[r][g+1][b])
299 >                    if (g < NGRN-1 && histo[r][g][b] != histo[r][g+1][b])
300                          addneigh(neigh, histo[r][g][b], histo[r][g+1][b]);
301 <                    if (histo[r][g][b] != histo[r][g][b+1])
301 >                    if (b < NBLU-1 && histo[r][g][b] != histo[r][g][b+1])
302                          addneigh(neigh, histo[r][g][b], histo[r][g][b+1]);
303                  }
304                                          /* assign closest values */
# Line 335 | Line 347 | dist(col, r, g, b)             /* find distance from clrtab entry
347   register BYTE   col[3];
348   int     r, g, b;
349   {
350 <        register unsigned       tmp;
350 >        register int    tmp;
351          register unsigned       sum;
352          
353          tmp = col[RED]*NRED/256 - r;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines