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.3 by greg, Fri Apr 7 13:30:09 1989 UTC vs.
Revision 2.4 by schorsch, Mon Jun 30 14:59:12 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 <string.h>
14 +
15 + #include "standard.h"
16   #include "ciq.h"
17  
18   #define table(m,r,g,b) hist[m[0][r]|m[1][g]|m[2][b]]  /* histogram/pvtable */
# Line 22 | Line 22 | int hist[len];         /* list of frequencies or pixelvalues
22   colormap color;         /* quantization colormap */
23   int n;                  /* number of colors in it */
24  
25 + #define ERRMAX 20       /* maximum allowed propagated error,
26 +                           if >=255 then no clamping */
27 +
28   /*----------------------------------------------------------------------*/
29  
30   ciq(dith,nw,synth,cm)
# Line 40 | Line 43 | colormap cm;           /* quantization colormap */
43      if (synth)
44          n = makecm(nw,&na);     /* analyze histogram and synthesize colormap */
45      else {
46 <        bcopy(cm,color,sizeof color);
46 >        memcpy((void *)color,(void *)cm,sizeof color);
47          n = nw;
48          na = 0;
49          for (i=0; i<len; i++) if (hist[i]) na++;
# Line 48 | Line 51 | colormap cm;           /* quantization colormap */
51      }
52      picwritecm(color);
53  
54 +    initializeclosest();
55      if (dith)
56          draw_dith(ocm);
57      else {
# Line 56 | Line 60 | colormap cm;           /* quantization colormap */
60          draw_nodith(ocm);
61      }
62  
63 <    bcopy(color,cm,sizeof color);
63 >    memcpy((void *)cm,(void *)color,sizeof color);
64      /*endclosest();*/
65   }
66  
# Line 81 | Line 85 | colormap ocm;
85          for (lp=line, x=0; x<xmax; x++, lp++)
86              table(map,lp->r,lp->g,lp->b)++;
87      }
88 <    free((char *)line);
88 >    free((void *)line);
89   }
90  
91   convertmap(in,out)              /* convert to shifted color map */
# Line 115 | Line 119 | colormap ocm;                  /* colormap for orig */
119              oline[x] = table(map,lp->r,lp->g,lp->b);
120          picwriteline(y,oline);
121      }
122 <    free((char *)iline);
123 <    free((char *)oline);
122 >    free((void *)iline);
123 >    free((void *)oline);
124   }
125  
126   draw_dith(ocm)                  /* quantize with dithering */
# Line 139 | Line 143 | colormap ocm;                  /* colormap for orig */
143          Q[0] = Q[1] = Q[2] = 0;
144          picreadline3(y,iline);
145          for (p=P, q=Q, x=0; x<xmax; x++, p+=3, q+=3) {
146 <            rr = ocm[0][iline[x].r]+p[0];
147 <            gg = ocm[1][iline[x].g]+p[1];       /* ideal */
148 <            bb = ocm[2][iline[x].b]+p[2];
146 >            rr = p[0];
147 >            if (rr<-ERRMAX) rr = -ERRMAX; else if (rr>ERRMAX) rr = ERRMAX;
148 >            gg = p[1];
149 >            if (gg<-ERRMAX) gg = -ERRMAX; else if (gg>ERRMAX) gg = ERRMAX;
150 >            bb = p[2];
151 >            if (bb<-ERRMAX) bb = -ERRMAX; else if (bb>ERRMAX) bb = ERRMAX;
152 >            /* now rr,gg,bb is propagated color */
153 >            rr += ocm[0][iline[x].r];
154 >            gg += ocm[1][iline[x].g];   /* ideal */
155 >            bb += ocm[2][iline[x].b];
156              if (rr<0) rr = 0; else if (rr>255) rr = 255;
157              if (gg<0) gg = 0; else if (gg>255) gg = 255;
158              if (bb<0) bb = 0; else if (bb>255) bb = 255;
# Line 158 | Line 169 | colormap ocm;                  /* colormap for orig */
169          }
170          picwriteline(y,oline);
171      }
172 <    free((char *)iline);
173 <    free((char *)oline);
174 <    free((char *)buf);
172 >    free((void *)iline);
173 >    free((void *)oline);
174 >    free((void *)buf);
175   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines