--- ray/src/px/ciq.c 1989/04/07 13:30:09 1.3 +++ ray/src/px/ciq.c 2003/06/30 14:59:12 2.4 @@ -1,9 +1,6 @@ -/* Copyright 1988 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: ciq.c,v 2.4 2003/06/30 14:59:12 schorsch Exp $"; #endif - /* CIQ - main program for color image quantization options for Floyd-Steinberg dithering by minimization of accumulated error @@ -13,6 +10,9 @@ Paul Heckbert 16 April 82, cleaned up 8 June 86 Greg Ward 1 March 88, modified for arbitrary picture sizes */ +#include + +#include "standard.h" #include "ciq.h" #define table(m,r,g,b) hist[m[0][r]|m[1][g]|m[2][b]] /* histogram/pvtable */ @@ -22,6 +22,9 @@ int hist[len]; /* list of frequencies or pixelvalues colormap color; /* quantization colormap */ int n; /* number of colors in it */ +#define ERRMAX 20 /* maximum allowed propagated error, + if >=255 then no clamping */ + /*----------------------------------------------------------------------*/ ciq(dith,nw,synth,cm) @@ -40,7 +43,7 @@ colormap cm; /* quantization colormap */ if (synth) n = makecm(nw,&na); /* analyze histogram and synthesize colormap */ else { - bcopy(cm,color,sizeof color); + memcpy((void *)color,(void *)cm,sizeof color); n = nw; na = 0; for (i=0; ir,lp->g,lp->b)++; } - free((char *)line); + free((void *)line); } convertmap(in,out) /* convert to shifted color map */ @@ -115,8 +119,8 @@ colormap ocm; /* colormap for orig */ oline[x] = table(map,lp->r,lp->g,lp->b); picwriteline(y,oline); } - free((char *)iline); - free((char *)oline); + free((void *)iline); + free((void *)oline); } draw_dith(ocm) /* quantize with dithering */ @@ -139,9 +143,16 @@ colormap ocm; /* colormap for orig */ Q[0] = Q[1] = Q[2] = 0; picreadline3(y,iline); for (p=P, q=Q, x=0; xERRMAX) rr = ERRMAX; + gg = p[1]; + if (gg<-ERRMAX) gg = -ERRMAX; else if (gg>ERRMAX) gg = ERRMAX; + bb = p[2]; + if (bb<-ERRMAX) bb = -ERRMAX; else if (bb>ERRMAX) bb = ERRMAX; + /* now rr,gg,bb is propagated color */ + rr += ocm[0][iline[x].r]; + gg += ocm[1][iline[x].g]; /* ideal */ + bb += ocm[2][iline[x].b]; if (rr<0) rr = 0; else if (rr>255) rr = 255; if (gg<0) gg = 0; else if (gg>255) gg = 255; if (bb<0) bb = 0; else if (bb>255) bb = 255; @@ -158,7 +169,7 @@ colormap ocm; /* colormap for orig */ } picwriteline(y,oline); } - free((char *)iline); - free((char *)oline); - free((char *)buf); + free((void *)iline); + free((void *)oline); + free((void *)buf); }