--- ray/src/px/ciq.c 1989/02/02 14:10:33 1.2 +++ ray/src/px/ciq.c 1991/11/12 16:04:10 2.1 @@ -13,6 +13,7 @@ Paul Heckbert 16 April 82, cleaned up 8 June 86 Greg Ward 1 March 88, modified for arbitrary picture sizes */ +#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 +23,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 +44,7 @@ colormap cm; /* quantization colormap */ if (synth) n = makecm(nw,&na); /* analyze histogram and synthesize colormap */ else { - bcopy(cm,color,sizeof color); + bcopy((char *)cm,(char *)color,sizeof color); n = nw; na = 0; for (i=0; iERRMAX) 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;