--- ray/src/px/macbethcal.c 1995/10/23 10:19:40 2.8 +++ ray/src/px/macbethcal.c 1997/01/30 19:14:11 2.12 @@ -1,4 +1,4 @@ -/* Copyright (c) 1995 Regents of the University of California */ +/* Copyright (c) 1997 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -90,9 +90,13 @@ short mbneu[NMBNEU] = {Black,Neutral35,Neutral5,Neutra #define REQFLGS NEUFLGS /* need these colors */ #define MODFLGS (NEUFLGS|UNSFLGS) /* should be in gamut */ -#define CENTCVG 0.3 /* measured coverage of square sample */ -#define FULLCVG 0.9 /* coverage of entire square */ +#define RG_BORD 0 /* patch border */ +#define RG_CENT 01 /* central region of patch */ +#define RG_ORIG 02 /* original color region */ +#define RG_CORR 04 /* corrected color region */ +int scanning = 1; /* scanned input (or recorded output)? */ + int xmax, ymax; /* input image dimensions */ int bounds[4][2]; /* image coordinates of chart corners */ double imgxfm[3][3]; /* coordinate transformation matrix */ @@ -114,7 +118,6 @@ main(argc, argv) int argc; char **argv; { - int inpispic = 1; int i; progname = argv[0]; @@ -145,10 +148,10 @@ char **argv; bounds[2][1] = atoi(argv[++i]); bounds[3][0] = atoi(argv[++i]); bounds[3][1] = atoi(argv[++i]); - inpispic = 2; + scanning = 2; break; case 'c': /* color input */ - inpispic = 0; + scanning = 0; break; default: goto userr; @@ -162,7 +165,7 @@ char **argv; perror(argv[2]); exit(1); } - if (inpispic) { /* load input picture header */ + if (scanning) { /* load input picture header */ #ifdef MSDOS setmode(fileno(stdin), O_BINARY); #endif @@ -175,25 +178,30 @@ char **argv; xmax = 512; ymax = 2*512/3; } - if (inpispic != 2) { /* use default boundaries */ + if (scanning != 2) { /* use default boundaries */ bounds[0][0] = bounds[2][0] = .029*xmax + .5; bounds[0][1] = bounds[1][1] = .956*ymax + .5; bounds[1][0] = bounds[3][0] = .971*xmax + .5; bounds[2][1] = bounds[3][1] = .056*ymax + .5; } init(); /* initialize */ - if (inpispic) /* get picture colors */ + if (scanning) /* get picture colors */ getpicture(); else getcolors(); compute(); /* compute color mapping */ /* print comment */ - printf("{ Color correction file computed by:\n\t"); + printf("{\n\tColor correction file computed by:\n\t\t"); printargs(argc, argv, stdout); + printf("\n\tUsage: pcomb -f %s uncorrected.pic > corrected.pic\n", + i+1 < argc ? argv[i+1] : "{this_file}"); + if (!scanning) + printf("\t Or: pcond [options] -f %s orig.pic > output.pic\n", + i+1 < argc ? argv[i+1] : "{this_file}"); printf("}\n"); putmapping(); /* put out color mapping */ if (debugfp != NULL) /* put out debug picture */ - if (inpispic) + if (scanning) picdebug(); else clrdebug(); @@ -233,14 +241,13 @@ init() /* initialize */ int -chartndx(x, y, cvg) /* find color number for position */ +chartndx(x, y, np) /* find color number for position */ int x, y; -double cvg; +int *np; { double ipos[3], cpos[3]; int ix, iy; double fx, fy; - double cmin, cmax; ipos[0] = x; ipos[1] = y; @@ -249,16 +256,19 @@ double cvg; cpos[0] /= cpos[2]; cpos[1] /= cpos[2]; if (cpos[0] < 0. || cpos[0] >= 6. || cpos[1] < 0. || cpos[1] >= 4.) - return(-1); + return(RG_BORD); ix = cpos[0]; iy = cpos[1]; fx = cpos[0] - ix; fy = cpos[1] - iy; - cmin = .5*(1.-cvg); - cmax = 1. - cmin; - if (fx < cmin || fx >= cmax || fy < cmin || fy >= cmax) - return(-1); - return(iy*6 + ix); + *np = iy*6 + ix; + if (fx >= 0.35 && fx < 0.65 && fy >= 0.35 && fy < 0.65) + return(RG_CENT); + if (fx < 0.05 || fx >= 0.95 || fy < 0.05 || fy >= 0.95) + return(RG_BORD); + if (fx >= 0.5) /* right side is corrected */ + return(RG_CORR); + return(RG_ORIG); /* left side is original */ } @@ -268,8 +278,8 @@ getpicture() /* load in picture colors */ COLOR pval; int ccount[24]; double d; - int y; - register int x, i; + int y, i; + register int x; scanln = (COLR *)malloc(xmax*sizeof(COLR)); if (scanln == NULL) { @@ -286,14 +296,12 @@ getpicture() /* load in picture colors */ progname); exit(1); } - for (x = 0; x < xmax; x++) { - i = chartndx(x, y, CENTCVG); - if (i >= 0) { + for (x = 0; x < xmax; x++) + if (chartndx(x, y, &i) == RG_CENT) { colr_color(pval, scanln[x]); addcolor(inpRGB[i], pval); ccount[i]++; } - } } for (i = 0; i < 24; i++) { /* compute averages */ if (ccount[i] == 0) @@ -318,8 +326,8 @@ getcolors() /* get xyY colors from standard input */ fgetval(stdin, 'f', &xyYin[0]) != 1 || fgetval(stdin, 'f', &xyYin[1]) != 1 || fgetval(stdin, 'f', &xyYin[2]) != 1 || - xyYin[0] < 0. | xyYin[0] > 1. | - xyYin[1] < 0. | xyYin[1] > 1.) { + xyYin[0] < 0. | xyYin[1] < 0. || + xyYin[0] + xyYin[1] > 1.) { fprintf(stderr, "%s: bad color input data\n", progname); exit(1); @@ -403,10 +411,10 @@ compute() /* compute color mapping */ /* check out-of-gamut colors */ for (i = 0; i < 24; i++) if (cflags & 1L<= 1.) { + if (colval(ctmp,j) <= 1e-6 || + colval(ctmp,j) >= 1.-1e-6) { gmtflags |= 1L<= 0; y--) { - for (x = 0; x < xmax; x++) - if ((i = chartndx(x, y, CENTCVG)) >= 0) { + for (x = 0; x < xmax; x++) { + rg = chartndx(x, y, &i); + if (rg == RG_CENT) { if (!(1L<= 0 && - inpflags & 1L<