static int cresp( /* transform color according to matrix */ COLOR cout, COLOR cin ) { colortrans(cout, solmat, cin); return(clipgamut(cout, bright(cout), CGAMUT, colmin, colmax)); }
static void picdebug(void) /* put out debugging picture */ { static COLOR blkcol = BLKCOLOR; COLOR *scan; int y, i; register int x, rg; if (fseek(stdin, 0L, 0) == EOF) { fprintf(stderr, "%s: cannot seek on input picture\n", progname); exit(1); } getheader(stdin, NULL, NULL); /* skip input header */ fgetresolu(&xmax, &ymax, stdin); /* allocate scanline */ scan = (COLOR *)malloc(xmax*sizeof(COLOR)); if (scan == NULL) { perror(progname); exit(1); } /* finish debug header */ fputformat(COLRFMT, debugfp); putc('\n', debugfp); fprtresolu(xmax, ymax, debugfp); /* write debug picture */ for (y = ymax-1; y >= 0; y--) { if (freadscan(scan, xmax, stdin) < 0) { fprintf(stderr, "%s: error rereading input picture\n", progname); exit(1); } for (x = 0; x < xmax; x++) { rg = chartndx(x, y, &i); if (rg == RG_CENT) { if (!(1L<<i & gmtflags) || (x+y)&07) { copycolor(scan[x], mbRGB[i]); clipgamut(scan[x], bright(scan[x]), CGAMUT, colmin, colmax); } else copycolor(scan[x], blkcol); } else if (rg == RG_CORR) cvtcolor(scan[x], scan[x]); else if (rg != RG_ORIG) copycolor(scan[x], blkcol); } if (fwritescan(scan, xmax, debugfp) < 0) { fprintf(stderr, "%s: error writing debugging picture\n", progname); exit(1); } } /* clean up */ fclose(debugfp); free((void *)scan); }
static void matscan( /* apply color matrix to scaline */ register COLOR *sl, int len, COLORMAT mat ) { while (len--) { colortrans(sl[0], mat, sl[0]); clipgamut(sl[0], greypoint(sl[0]), CGAMUT, cblack, cwhite); sl++; } }
static int cvtcolor( /* convert color according to our mapping */ COLOR cout, COLOR cin ) { COLOR ctmp; int clipped; if (wcor != NULL) { clipped = warp3d(cout, cin, wcor); clipped |= clipgamut(cout,bright(cout),CGAMUT,colmin,colmax); } else if (scanning) { bresp(ctmp, cin); clipped = cresp(cout, ctmp); } else { clipped = cresp(ctmp, cin); bresp(cout, ctmp); } return(clipped); }
static void cwscan( /* apply color space warp to scaline */ COLOR *sl, int len, WARP3D *wp ) { int rval; while (len--) { rval = warp3d(sl[0], sl[0], wp); if (rval & W3ERROR) syserror("warp3d"); if (rval & W3BADMAP) { fprintf(stderr, "%s: %s: bad color space map\n", progname, cwarpfile); exit(1); } clipgamut(sl[0], greypoint(sl[0]), CGAMUT, cblack, cwhite); sl++; } }
static void mbscan( /* apply macbethcal adj. to scaline */ COLOR *sl, int len, register struct mbc *mb ) { double d; register int i, j; while (len--) { colortrans(sl[0], mb->cmat, sl[0]); clipgamut(sl[0], greypoint(sl[0]), CGAMUT, mb->cmin, mb->cmax); for (i = 0; i < 3; i++) { d = colval(sl[0],i); for (j = 0; j < 4 && mb->xa[i][j+1] <= d; j++) ; colval(sl[0],i) = ( (mb->xa[i][j+1] - d)*mb->ya[i][j] + (d - mb->xa[i][j])*mb->ya[i][j+1] ) / (mb->xa[i][j+1] - mb->xa[i][j]); } sl++; } }
static void clrdebug(void) /* put out debug picture from color input */ { static COLR blkclr = BLKCOLR; COLR mbclr[24], cvclr[24], orclr[24]; COLR *scan; COLOR ctmp, ct2; int y, i; register int x, rg; /* convert colors */ for (i = 0; i < 24; i++) { copycolor(ctmp, mbRGB[i]); clipgamut(ctmp, bright(ctmp), CGAMUT, cblack, cwhite); setcolr(mbclr[i], colval(ctmp,RED), colval(ctmp,GRN), colval(ctmp,BLU)); if (inpflags & 1L<<i) { copycolor(ctmp, inpRGB[i]); clipgamut(ctmp, bright(ctmp), CGAMUT, cblack, cwhite); setcolr(orclr[i], colval(ctmp,RED), colval(ctmp,GRN), colval(ctmp,BLU)); if (rawmap) copycolr(cvclr[i], mbclr[i]); else { bresp(ctmp, inpRGB[i]); colortrans(ct2, solmat, ctmp); clipgamut(ct2, bright(ct2), CGAMUT, cblack, cwhite); setcolr(cvclr[i], colval(ct2,RED), colval(ct2,GRN), colval(ct2,BLU)); } } } /* allocate scanline */ scan = (COLR *)malloc(xmax*sizeof(COLR)); if (scan == NULL) { perror(progname); exit(1); } /* finish debug header */ fputformat(COLRFMT, debugfp); putc('\n', debugfp); fprtresolu(xmax, ymax, debugfp); /* write debug picture */ for (y = ymax-1; y >= 0; y--) { for (x = 0; x < xmax; x++) { rg = chartndx(x, y, &i); if (rg == RG_CENT) { if (!(1L<<i & gmtflags) || (x+y)&07) copycolr(scan[x], mbclr[i]); else copycolr(scan[x], blkclr); } else if (rg == RG_BORD || !(1L<<i & inpflags)) copycolr(scan[x], blkclr); else if (rg == RG_ORIG) copycolr(scan[x], orclr[i]); else /* rg == RG_CORR */ copycolr(scan[x], cvclr[i]); } if (fwritecolrs(scan, xmax, debugfp) < 0) { fprintf(stderr, "%s: error writing debugging picture\n", progname); exit(1); } } /* clean up */ fclose(debugfp); free((void *)scan); }