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

Comparing ray/src/px/ciq.c (file contents):
Revision 1.2 by greg, Thu Feb 2 14:10:33 1989 UTC vs.
Revision 2.2 by greg, Sat Feb 22 02:07:27 2003 UTC

# Line 1 | Line 1
1 /* Copyright 1988 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   CIQ - main program for color image quantization
6   options for Floyd-Steinberg dithering by minimization of accumulated error
# Line 13 | Line 10 | Paul Heckbert  16 April 82, cleaned up 8 June 86
10   Greg Ward       1 March 88, modified for arbitrary picture sizes
11   */
12  
13 + #include "standard.h"
14   #include "ciq.h"
15  
16   #define table(m,r,g,b) hist[m[0][r]|m[1][g]|m[2][b]]  /* histogram/pvtable */
# Line 22 | Line 20 | int hist[len];         /* list of frequencies or pixelvalues
20   colormap color;         /* quantization colormap */
21   int n;                  /* number of colors in it */
22  
23 + #define ERRMAX 20       /* maximum allowed propagated error,
24 +                           if >=255 then no clamping */
25 +
26   /*----------------------------------------------------------------------*/
27  
28   ciq(dith,nw,synth,cm)
# Line 40 | Line 41 | colormap cm;           /* quantization colormap */
41      if (synth)
42          n = makecm(nw,&na);     /* analyze histogram and synthesize colormap */
43      else {
44 <        bcopy(cm,color,sizeof color);
44 >        bcopy((char *)cm,(char *)color,sizeof color);
45          n = nw;
46          na = 0;
47          for (i=0; i<len; i++) if (hist[i]) na++;
# Line 48 | Line 49 | colormap cm;           /* quantization colormap */
49      }
50      picwritecm(color);
51  
52 +    initializeclosest();
53      if (dith)
54          draw_dith(ocm);
55      else {
# Line 56 | Line 58 | colormap cm;           /* quantization colormap */
58          draw_nodith(ocm);
59      }
60  
61 <    bcopy(color,cm,sizeof color);
61 >    bcopy((char *)color,(char *)cm,sizeof color);
62      /*endclosest();*/
63   }
64  
# Line 70 | Line 72 | colormap ocm;
72      rgbpixel *line;
73      colormap map;
74  
75 +    for (x = 0; x < len; x++)   /* clear histogram */
76 +        hist[x] = 0;
77 +
78      line = line3alloc(xmax);
79      convertmap(ocm,map);
80  
# Line 78 | Line 83 | colormap ocm;
83          for (lp=line, x=0; x<xmax; x++, lp++)
84              table(map,lp->r,lp->g,lp->b)++;
85      }
86 <    free((char *)line);
86 >    free((void *)line);
87   }
88  
89   convertmap(in,out)              /* convert to shifted color map */
# Line 112 | Line 117 | colormap ocm;                  /* colormap for orig */
117              oline[x] = table(map,lp->r,lp->g,lp->b);
118          picwriteline(y,oline);
119      }
120 <    free((char *)iline);
121 <    free((char *)oline);
120 >    free((void *)iline);
121 >    free((void *)oline);
122   }
123  
124   draw_dith(ocm)                  /* quantize with dithering */
# Line 136 | Line 141 | colormap ocm;                  /* colormap for orig */
141          Q[0] = Q[1] = Q[2] = 0;
142          picreadline3(y,iline);
143          for (p=P, q=Q, x=0; x<xmax; x++, p+=3, q+=3) {
144 <            rr = ocm[0][iline[x].r]+p[0];
145 <            gg = ocm[1][iline[x].g]+p[1];       /* ideal */
146 <            bb = ocm[2][iline[x].b]+p[2];
144 >            rr = p[0];
145 >            if (rr<-ERRMAX) rr = -ERRMAX; else if (rr>ERRMAX) rr = ERRMAX;
146 >            gg = p[1];
147 >            if (gg<-ERRMAX) gg = -ERRMAX; else if (gg>ERRMAX) gg = ERRMAX;
148 >            bb = p[2];
149 >            if (bb<-ERRMAX) bb = -ERRMAX; else if (bb>ERRMAX) bb = ERRMAX;
150 >            /* now rr,gg,bb is propagated color */
151 >            rr += ocm[0][iline[x].r];
152 >            gg += ocm[1][iline[x].g];   /* ideal */
153 >            bb += ocm[2][iline[x].b];
154              if (rr<0) rr = 0; else if (rr>255) rr = 255;
155              if (gg<0) gg = 0; else if (gg>255) gg = 255;
156              if (bb<0) bb = 0; else if (bb>255) bb = 255;
# Line 155 | Line 167 | colormap ocm;                  /* colormap for orig */
167          }
168          picwriteline(y,oline);
169      }
170 <    free((char *)iline);
171 <    free((char *)oline);
172 <    free((char *)buf);
170 >    free((void *)iline);
171 >    free((void *)oline);
172 >    free((void *)buf);
173   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines