--- ray/src/px/macbethcal.c 1997/02/04 16:04:23 2.14 +++ ray/src/px/macbethcal.c 2003/11/10 12:28:56 2.22 @@ -1,9 +1,6 @@ -/* Copyright (c) 1997 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: macbethcal.c,v 2.22 2003/11/10 12:28:56 schorsch Exp $"; #endif - /* * Calibrate a scanned MacBeth Color Checker Chart * @@ -15,9 +12,10 @@ static char SCCSid[] = "$SunId$ LBL"; #include #include -#ifdef MSDOS -#include -#endif +#include + +#include "platform.h" +#include "rtprocess.h" #include "color.h" #include "resolu.h" #include "pmap.h" @@ -100,6 +98,10 @@ short mbneu[NMBNEU] = {Black,Neutral35,Neutral5,Neutra #define RG_ORIG 02 /* original color region */ #define RG_CORR 04 /* corrected color region */ +#ifndef DISPCOM +#define DISPCOM "ximage -op \"%s\"" +#endif + int scanning = 1; /* scanned input (or recorded output)? */ double irrad = 1.0; /* irradiance multiplication factor */ int rawmap = 0; /* put out raw color mapping? */ @@ -121,9 +123,7 @@ WARP3D *wcor = NULL; /* color space warp */ FILE *debugfp = NULL; /* debug output picture */ char *progname; -extern char *malloc(); - main(argc, argv) int argc; char **argv; @@ -141,9 +141,7 @@ char **argv; perror(argv[i]); exit(1); } -#ifdef MSDOS - setmode(fileno(debugfp), O_BINARY); -#endif + SET_FILE_BINARY(debugfp); newheader("RADIANCE", debugfp); /* start */ printargs(argc, argv, debugfp); /* header */ break; @@ -160,6 +158,9 @@ char **argv; bounds[3][1] = atoi(argv[++i]); scanning = 2; break; + case 'P': /* pick position */ + scanning = 3; + break; case 'i': /* irradiance factor */ i++; if (badarg(argc-i, argv+i, "f")) @@ -185,14 +186,18 @@ char **argv; exit(1); } if (scanning) { /* load input picture header */ -#ifdef MSDOS - setmode(fileno(stdin), O_BINARY); -#endif + SET_FILE_BINARY(stdin); if (checkheader(stdin, COLRFMT, NULL) < 0 || fgetresolu(&xmax, &ymax, stdin) < 0) { fprintf(stderr, "%s: bad input picture\n", progname); exit(1); } + if (scanning == 3) { + if (i >= argc) + goto userr; + pickchartpos(argv[i]); + scanning = 2; + } } else { /* else set default xmax and ymax */ xmax = 512; ymax = 2*512/3; @@ -214,7 +219,7 @@ char **argv; printf("# Color correspondence produced by:\n#\t\t"); printargs(argc, argv, stdout); - printf("#\tUsage: pcwarp -m %s uncorrected.pic > corrected.pic\n", + printf("#\tUsage: pcwarp %s uncorrected.pic > corrected.pic\n", i+1 < argc ? argv[i+1] : "{this_file}"); printf("#\t Or: pcond [options] -m %s orig.pic > output.pic\n", i+1 < argc ? argv[i+1] : "{this_file}"); @@ -237,15 +242,16 @@ char **argv; printf("}\n"); putmapping(); /* put out color mapping */ } - if (debugfp != NULL) /* put out debug picture */ + if (debugfp != NULL) { /* put out debug picture */ if (scanning) picdebug(); else clrdebug(); + } exit(0); userr: fprintf(stderr, -"Usage: %s [-d dbg.pic][-p xul yul xur yur xll yll xlr ylr][-i irrad][-m] input.pic [output.{cal|cwp}]\n", +"Usage: %s [-d dbg.pic][-P | -p xul yul xur yur xll yll xlr ylr][-i irrad][-m] input.pic [output.{cal|cwp}]\n", progname); fprintf(stderr, " or: %s [-d dbg.pic][-i irrad][-m] -c [xyY.dat [output.{cal|cwp}]]\n", progname); @@ -349,7 +355,7 @@ getpicture() /* load in picture colors */ scalecolor(inpRGB[i], d); inpflags |= 1L< 24 || + if ((n < 0) | (n > 24) || fgetval(stdin, 'f', &xyYin[0]) != 1 || fgetval(stdin, 'f', &xyYin[1]) != 1 || fgetval(stdin, 'f', &xyYin[2]) != 1 || - xyYin[0] < 0. | xyYin[1] < 0. || + (xyYin[0] < 0.) | (xyYin[1] < 0.) || xyYin[0] + xyYin[1] > 1.) { fprintf(stderr, "%s: bad color input data\n", progname); @@ -699,7 +705,7 @@ picdebug() /* put out debugging picture */ } /* clean up */ fclose(debugfp); - free((char *)scan); + free((void *)scan); } @@ -769,5 +775,43 @@ clrdebug() /* put out debug picture from color input } /* clean up */ fclose(debugfp); - free((char *)scan); + free((void *)scan); +} + + +getpos(name, bnds, fp) /* get boundary position */ +char *name; +int bnds[2]; +FILE *fp; +{ + char buf[64]; + + fprintf(stderr, "\tSelect corner: %s\n", name); + if (fgets(buf, sizeof(buf), fp) == NULL || + sscanf(buf, "%d %d", &bnds[0], &bnds[1]) != 2) { + fprintf(stderr, "%s: read error from display process\n", + progname); + exit(1); + } +} + + +pickchartpos(pfn) /* display picture and pick chart location */ +char *pfn; +{ + char combuf[PATH_MAX]; + FILE *pfp; + + sprintf(combuf, DISPCOM, pfn); + if ((pfp = popen(combuf, "r")) == NULL) { + perror(combuf); + exit(1); + } + fputs("Use middle mouse button to select chart corners:\n", stderr); + getpos("upper left (dark skin)", bounds[0], pfp); + getpos("upper right (bluish green)", bounds[1], pfp); + getpos("lower left (white)", bounds[2], pfp); + getpos("lower right (black)", bounds[3], pfp); + fputs("Got it -- quit display program.\n", stderr); + pclose(pfp); }