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

Comparing ray/src/rt/colortab.c (file contents):
Revision 1.7 by greg, Thu Oct 12 11:12:48 1989 UTC vs.
Revision 1.8 by greg, Thu Oct 12 11:32:09 1989 UTC

# Line 28 | Line 28 | static char SCCSid[] = "$SunId$ LBL";
28   #define MINSAMP         7
29                                  /* maximum distance^2 before color reassign */
30   #define MAXDST2         12
31                                /* maximum frame buffer depth */
32 #define FBDEPTH         8
31                                  /* map a color */
32   #define map_col(c,p)    clrmap[p][ colval(c,p)<1. ? \
33                                  (int)(colval(c,p)*256.) : 255 ]
# Line 47 | Line 45 | static struct tabent {
45          long    sum[3];         /* sum of colors using this entry */
46          long    n;              /* number of colors */
47          short   ent[3];         /* current table value */
48 < }       clrtab[1<<FBDEPTH];
48 > }       *clrtab = NULL;
49 >                                /* color cube partition */
50 > static CNODE    *ctree = NULL;
51                                  /* our color correction map */
52   static BYTE     clrmap[3][256];
53                                  /* histogram of colors used */
54   static unsigned histo[NRED][NGRN][NBLU];
55 <                                /* initial color cube boundaries */
55 >                                /* initial color cube boundary */
56   static int      CLRCUBE[3][2] = {0,NRED,0,NGRN,0,NBLU};
57                                /* color cube partition */
58 static CNODE    ctree[1<<(FBDEPTH+1)];
57  
58  
59   int
60   new_ctab(ncolors)               /* start new color table with max ncolors */
61   int     ncolors;
62   {
63 +        int     treesize;
64 +
65          if (ncolors < 1)
66                  return(0);
67 <        if (ncolors > 1<<FBDEPTH)
68 <                ncolors = 1<<FBDEPTH;
69 <                                /* clear color table */
70 <        bzero(clrtab, sizeof(clrtab));
67 >                                /* free old tables */
68 >        if (clrtab != NULL)
69 >                free((char *)clrtab);
70 >        if (ctree != NULL)
71 >                free((char *)ctree);
72 >                                /* get new tables */
73 >        for (treesize = 1; treesize < ncolors; treesize <<= 1)
74 >                ;
75 >        treesize <<= 1;
76 >        clrtab = (struct tabent *)calloc(ncolors, sizeof(struct tabent));
77 >        ctree = (CNODE *)malloc(treesize*sizeof(CNODE));
78 >        if (clrtab == NULL || ctree == NULL)
79 >                return(0);
80                                  /* partition color space */
81          cut(ctree, 0, CLRCUBE, 0, ncolors);
82                                  /* clear histogram */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines