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.8 by greg, Thu Oct 12 11:32:09 1989 UTC vs.
Revision 1.14 by greg, Thu Mar 29 12:43:07 1990 UTC

# Line 51 | Line 51 | 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];
54 > static unsigned short   histo[NRED][NGRN][NBLU];
55                                  /* initial color cube boundary */
56   static int      CLRCUBE[3][2] = {0,NRED,0,NGRN,0,NBLU};
57  
# Line 80 | Line 80 | int    ncolors;
80                                  /* partition color space */
81          cut(ctree, 0, CLRCUBE, 0, ncolors);
82                                  /* clear histogram */
83 <        bzero(histo, sizeof(histo));
83 >        bzero((char *)histo, sizeof(histo));
84                                  /* return number of colors used */
85          return(ncolors);
86   }
# Line 91 | Line 91 | get_pixel(col, set_pixel)      /* get pixel for color */
91   COLOR   col;
92   int     (*set_pixel)();
93   {
94 +        extern char     errmsg[];
95          int     r, g, b;
96          int     cv[3];
97 <        register union { CNODE *t; struct tabent *e; }  p;
97 >        register CNODE  *tp;
98          register int    h;
99                                                  /* map color */
100          r = map_col(col,RED);
# Line 106 | Line 107 | int    (*set_pixel)();
107                                                  /* add to histogram */
108          histo[cv[RED]][cv[GRN]][cv[BLU]]++;
109                                                  /* find pixel in tree */
110 <        for (p.t = ctree, h = 0; is_branch(*p.t); h++)
111 <                if (cv[prim(*p.t)] < part(*p.t))
112 <                        p.t += 1<<h;            /* left branch */
110 >        for (tp = ctree, h = 0; is_branch(*tp); h++)
111 >                if (cv[prim(*tp)] < part(*tp))
112 >                        tp += 1<<h;             /* left branch */
113                  else
114 <                        p.t += 1<<(h+1);        /* right branch */
115 <        h = pval(*p.t);
114 >                        tp += 1<<(h+1); /* right branch */
115 >        h = pval(*tp);
116                                                  /* add to color table */
117 <        p.e = clrtab + h;
118 <                                        /* add to sum */
119 <        p.e->sum[RED] += r;
120 <        p.e->sum[GRN] += g;
120 <        p.e->sum[BLU] += b;
121 <        p.e->n++;
117 >        clrtab[h].sum[RED] += r;
118 >        clrtab[h].sum[GRN] += g;
119 >        clrtab[h].sum[BLU] += b;
120 >        clrtab[h].n++;
121                                          /* recompute average */
122 <        r = p.e->sum[RED] / p.e->n;
123 <        g = p.e->sum[GRN] / p.e->n;
124 <        b = p.e->sum[BLU] / p.e->n;
122 >        r = clrtab[h].sum[RED] / clrtab[h].n;
123 >        g = clrtab[h].sum[GRN] / clrtab[h].n;
124 >        b = clrtab[h].sum[BLU] / clrtab[h].n;
125                                          /* check for movement */
126 <        if (p.e->n == 1 ||
127 <                        (r-p.e->ent[RED])*(r-p.e->ent[RED]) +
128 <                        (g-p.e->ent[GRN])*(g-p.e->ent[GRN]) +
129 <                        (b-p.e->ent[BLU])*(b-p.e->ent[BLU]) > MAXDST2) {
130 <                p.e->ent[RED] = r;
131 <                p.e->ent[GRN] = g;      /* reassign pixel */
132 <                p.e->ent[BLU] = b;
133 < #ifdef notdef
134 <                printf("pixel %d = (%d,%d,%d) (%d refs)\n",
135 <                                h, r, g, b, p.e->n);
126 >        if (clrtab[h].n == 1 ||
127 >                        (r-clrtab[h].ent[RED])*(r-clrtab[h].ent[RED]) +
128 >                        (g-clrtab[h].ent[GRN])*(g-clrtab[h].ent[GRN]) +
129 >                        (b-clrtab[h].ent[BLU])*(b-clrtab[h].ent[BLU]) > MAXDST2) {
130 >                clrtab[h].ent[RED] = r;
131 >                clrtab[h].ent[GRN] = g; /* reassign pixel */
132 >                clrtab[h].ent[BLU] = b;
133 > #ifdef DEBUG
134 >                sprintf(errmsg, "pixel %d = (%d,%d,%d) (%d refs)\n",
135 >                                h, r, g, b, clrtab[h].n);
136 >                eputs(errmsg);
137   #endif
138                  (*set_pixel)(h, r, g, b);
139          }
# Line 157 | Line 157 | double  gam;
157   set_cmap(rmap, gmap, bmap)      /* set custom color correction map */
158   BYTE    *rmap, *gmap, *bmap;
159   {
160 <        bcopy(rmap, clrmap[RED], 256);
161 <        bcopy(gmap, clrmap[GRN], 256);
162 <        bcopy(bmap, clrmap[BLU], 256);
160 >        bcopy((char *)rmap, (char *)clrmap[RED], 256);
161 >        bcopy((char *)gmap, (char *)clrmap[GRN], 256);
162 >        bcopy((char *)bmap, (char *)clrmap[BLU], 256);
163   }
164  
165  
166 + map_color(rgb, col)             /* map a color to a byte triplet */
167 + BYTE    rgb[3];
168 + COLOR   col;
169 + {
170 +        rgb[RED] = map_col(col,RED);
171 +        rgb[GRN] = map_col(col,GRN);
172 +        rgb[BLU] = map_col(col,BLU);
173 + }
174 +
175 +
176   static
177   cut(tree, level, box, c0, c1)           /* partition color space */
178   register CNODE  *tree;
# Line 178 | Line 188 | int    c0, c1;
188          }
189                                          /* split box */
190          *tree = split(box);
191 <        bcopy(box, kb, sizeof(kb));
191 >        bcopy((char *)box, (char *)kb, sizeof(kb));
192                                                  /* do left (lesser) branch */
193          kb[prim(*tree)][1] = part(*tree);
194          cut(tree+(1<<level), level+1, kb, c0, (c0+c1)>>1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines