33 #ifndef NO_INV_CMAP_TRACKING
36 static int cred, cgreen, cblue;
37 static int red, green;
38 static unsigned char *zrgbp;
49 static long outercount = 0, innercount = 0;
53 static void maxfill(
unsigned long *,
long );
54 static int redloop(
void );
55 static int greenloop(
int );
56 static int blueloop(
int );
216 unsigned char *colormap[3], *
rgbmap;
217 unsigned long *dist_buf;
219 int nbits = 8 - bits;
223 xsqr = 1 << (2 * nbits);
260 cred = colormap[0][cindex];
261 cgreen = colormap[1][cindex];
262 cblue = colormap[2][cindex];
263 fprintf( stderr,
"---Starting %d: %d,%d,%d -> %d,%d,%d\n",
264 cindex, cred, cgreen, cblue,
265 rcenter, gcenter, bcenter );
285 fprintf( stderr,
"K = %d, N = %d, outer count = %ld, inner count = %ld\n",
286 colors, colormax, outercount, innercount );
307 rdist += rxx, rxx += txsqr, first = 0 )
323 rxx -= txsqr,
rdist -= rxx, first = 0 )
346 static int here, min, max;
348 static int prevmax, prevmin;
349 int thismax, thismin;
351 static long ginc, gxx, gcdist;
352 static unsigned long *gcdp;
353 static unsigned char *gcrgbp;
375 for ( g = here, gcdist =
gdist =
rdist, gxx = ginc,
379 gdist += gxx, gcdist += gxx, gxx += txsqr, first = 0 )
400 fprintf( stderr,
"===Adjusting green here up at %d,%d\n",
417 for ( g = here - 1, gxx = ginc - txsqr, gcdist =
gdist =
rdist - gxx,
422 gxx -= txsqr,
gdist -= gxx, gcdist -= gxx, first = 0 )
441 fprintf( stderr,
"===Adjusting green here down at %d,%d\n",
463 if ( thismax < prevmax )
468 if ( thismin > prevmin )
484 register unsigned long *dp;
485 register unsigned char *rgbp;
486 register long bdist, bxx;
487 register int b, i =
cindex;
490 static int here, min, max;
492 static int prevmin, prevmax;
493 int thismin, thismax;
494 #ifdef DMIN_DMAX_TRACK
495 static int dmin, dmax;
512 #ifdef DMIN_DMAX_TRACK
525 tdist = cred - red * x - x/2;
527 tdist = cgreen - green * x - x/2;
529 tdist = cblue - here * x - x/2;
532 fprintf( stderr,
"*** At %d,%d,%d; dist = %ld != gdist = %ld\n",
533 red, green, here, dist, gdist );
534 if ( grgbp != zrgbp + red*rstride + green*gstride + here )
535 fprintf( stderr,
"*** At %d,%d,%d: buffer pointer is at %d,%d,%d\n",
537 (grgbp - zrgbp) / rstride,
538 ((grgbp - zrgbp) % rstride) / gstride,
539 (grgbp - zrgbp) % gstride );
544 for ( b = here, bdist =
gdist, bxx = binc, dp =
gdp, rgbp =
grgbp, lim = max;
547 bdist += bxx, bxx += txsqr )
566 fprintf( stderr,
"===Adjusting blue here up at %d,%d,%d\n",
569 tdist = cred - red * x - x/2;
571 tdist = cgreen - green * x - x/2;
573 tdist = cblue - here * x - x/2;
577 "*** Adjusting here up at %d,%d,%d; dist = %ld != gdist = %ld\n",
578 red, green, here, dist, gdist );
592 bdist += bxx, bxx += txsqr )
614 tdist = cred - red * x - x/2;
616 tdist = cgreen - green * x - x/2;
618 tdist = cblue - b * x - x/2;
622 "*** After up loop at %d,%d,%d; dist = %ld != bdist = %ld\n",
623 red, green, b, dist, bdist );
643 bxx -= txsqr, bdist -= bxx )
664 fprintf( stderr,
"===Adjusting blue here down at %d,%d,%d\n",
666 tdist = cred - red * x - x/2;
668 tdist = cgreen - green * x - x/2;
670 tdist = cblue - here * x - x/2;
674 "*** Adjusting here down at %d,%d,%d; dist = %ld != gdist = %ld\n",
675 red, green, here, dist, gdist );
687 bxx -= txsqr, bdist -= bxx )
710 tdist = cred - red * x - x/2;
712 tdist = cgreen - green * x - x/2;
714 tdist = cblue - b * x - x/2;
718 "*** After down loop at %d,%d,%d; dist = %ld != bdist = %ld\n",
719 red, green, b, dist, bdist );
726 #ifdef DMIN_DMAX_TRACK
729 if ( prevmax >= prevmin )
732 dmin = thismin - prevmin - 1;
735 if ( thismax < colormax - 1 )
736 dmax = thismax - prevmax + 1;
740 max = thismax + dmax;
741 if ( max >= colormax )
743 min = thismin + dmin;
751 if ( thismax < prevmax )
754 if ( thismin > prevmin )
769 unsigned long *buffer;
772 register unsigned long maxv = ~0L;
774 register unsigned long *bp;
820 inv_cmap( colors, colormap, bits, dist_buf, rgbmap )
822 unsigned char *colormap[3], *rgbmap;
823 unsigned long *dist_buf;
825 register unsigned long *dp;
826 register unsigned char *rgbp;
827 register long bdist, bxx;
829 int nbits = 8 - bits;
830 register int colormax = 1 << bits;
831 register long xsqr = 1 << (2 * nbits);
833 int rinc, ginc, binc, r, g;
834 long rdist, gdist, rxx, gxx;
836 long outercount = 0, innercount = 0;
839 for ( i = 0; i < colors; i++ )
857 rdist = colormap[0][i] - x/2;
858 gdist = colormap[1][i] - x/2;
859 bdist = colormap[2][i] - x/2;
860 rdist = rdist*rdist + gdist*gdist + bdist*bdist;
862 rinc = 2 * (xsqr - (colormap[0][i] << nbits));
863 ginc = 2 * (xsqr - (colormap[1][i] << nbits));
864 binc = 2 * (xsqr - (colormap[2][i] << nbits));
867 for ( r = 0, rxx = rinc;
869 rdist += rxx, r++, rxx += xsqr + xsqr )
870 for ( g = 0, gdist = rdist, gxx = ginc;
872 gdist += gxx, g++, gxx += xsqr + xsqr )
873 for ( b = 0, bdist = gdist, bxx = binc;
875 bdist += bxx, b++, dp++, rgbp++,
881 if ( i == 0 || *dp > bdist )
892 fprintf( stderr,
"K = %d, N = %d, outer count = %ld, inner count = %ld\n",
893 colors, colormax, outercount, innercount );
static int greenloop(int restart)
static unsigned char * rrgbp
static unsigned long * gdp
static void maxfill(unsigned long *buffer, long side)
static unsigned char * grgbp
void inv_cmap(int colors, colormap, int bits, unsigned long *dist_buf,*rgbmap)
static unsigned long * cdp
static int blueloop(int restart)
static unsigned long * rdp
static unsigned char * crgbp