--- ray/src/px/macbethcal.c 2003/02/22 02:07:27 2.17 +++ ray/src/px/macbethcal.c 2004/12/15 06:30:36 2.24 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: macbethcal.c,v 2.17 2003/02/22 02:07:27 greg Exp $"; +static const char RCSid[] = "$Id: macbethcal.c,v 2.24 2004/12/15 06:30:36 greg Exp $"; #endif /* * Calibrate a scanned MacBeth Color Checker Chart @@ -12,14 +12,16 @@ static const char RCSid[] = "$Id: macbethcal.c,v 2.17 #include #include -#ifdef MSDOS -#include -#endif -#include +#include + +#include "platform.h" +#include "rtprocess.h" +#include "rtio.h" #include "color.h" #include "resolu.h" #include "pmap.h" #include "warp3d.h" +#include "mx3.h" /* MacBeth colors */ #define DarkSkin 0 @@ -99,7 +101,7 @@ short mbneu[NMBNEU] = {Black,Neutral35,Neutral5,Neutra #define RG_CORR 04 /* corrected color region */ #ifndef DISPCOM -#define DISPCOM "ximage -op %s" +#define DISPCOM "ximage -op \"%s\"" #endif int scanning = 1; /* scanned input (or recorded output)? */ @@ -123,10 +125,29 @@ WARP3D *wcor = NULL; /* color space warp */ FILE *debugfp = NULL; /* debug output picture */ char *progname; +static void init(void); +static int chartndx(int x, int y, int *np); +static void getpicture(void); +static void getcolors(void); +static void bresp(COLOR y, COLOR x); +static void compute(void); +static void putmapping(void); +static void compsoln(COLOR cin[], COLOR cout[], int n); +static void cwarp(void); +static int cvtcolor(COLOR cout, COLOR cin); +static int cresp(COLOR cout, COLOR cin); +static void xyY2RGB(COLOR rgbout, float xyYin[3]); +static void picdebug(void); +static void clrdebug(void); +static void getpos(char *name, int bnds[2], FILE *fp); +static void pickchartpos(char *pfn); -main(argc, argv) -int argc; -char **argv; + +int +main( + int argc, + char **argv +) { int i; @@ -141,9 +162,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; @@ -188,9 +207,7 @@ 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); @@ -246,11 +263,12 @@ 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, @@ -259,10 +277,12 @@ userr: fprintf(stderr, " or: %s [-d dbg.pic][-i irrad][-m] -c [xyY.dat [output.{cal|cwp}]]\n", progname); exit(1); + return 1; /* pro forma return */ } -init() /* initialize */ +static void +init(void) /* initialize */ { double quad[4][2]; register int i; @@ -288,10 +308,12 @@ init() /* initialize */ } -int -chartndx(x, y, np) /* find color number for position */ -int x, y; -int *np; +static int +chartndx( /* find color number for position */ + int x, + int y, + int *np +) { double ipos[3], cpos[3]; int ix, iy; @@ -320,7 +342,8 @@ int *np; } -getpicture() /* load in picture colors */ +static void +getpicture(void) /* load in picture colors */ { COLR *scanln; COLOR pval; @@ -362,7 +385,8 @@ getpicture() /* load in picture colors */ } -getcolors() /* get xyY colors from standard input */ +static void +getcolors(void) /* get xyY colors from standard input */ { int gotwhite = 0; COLOR whiteclr; @@ -370,11 +394,11 @@ getcolors() /* get xyY colors from standard input */ float xyYin[3]; while (fgetval(stdin, 'i', &n) == 1) { /* read colors */ - if (n < 0 | n > 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); @@ -410,8 +434,11 @@ getcolors() /* get xyY colors from standard input */ } -bresp(y, x) /* piecewise linear interpolation of primaries */ -COLOR y, x; +static void +bresp( /* piecewise linear interpolation of primaries */ + COLOR y, + COLOR x +) { register int i, n; @@ -428,7 +455,8 @@ COLOR y, x; } -compute() /* compute color mapping */ +static void +compute(void) /* compute color mapping */ { COLOR clrin[24], clrout[24]; long cflags; @@ -443,6 +471,13 @@ compute() /* compute color mapping */ /* compute piecewise luminance curve */ for (i = 0; i < NMBNEU; i++) { copycolor(bramp[i][0], inpRGB[mbneu[i]]); + for (n = i ? 3 : 0; n--; ) + if (colval(bramp[i][0],n) <= + colval(bramp[i-1][0],n)+1e-7) { + fprintf(stderr, + "%s: non-increasing neutral patch\n", progname); + exit(1); + } copycolor(bramp[i][1], mbRGB[mbneu[i]]); } /* compute color space gamut */ @@ -486,7 +521,8 @@ compute() /* compute color mapping */ } -putmapping() /* put out color mapping */ +static void +putmapping(void) /* put out color mapping */ { static char cchar[3] = {'r', 'g', 'b'}; register int i, j; @@ -534,9 +570,12 @@ putmapping() /* put out color mapping */ } -compsoln(cin, cout, n) /* solve 3xN system using least-squares */ -COLOR cin[], cout[]; -int n; +static void +compsoln( /* solve 3xN system using least-squares */ + COLOR cin[], + COLOR cout[], + int n +) { extern double mx3d_adjoint(), fabs(); double mat[3][3], invmat[3][3]; @@ -594,7 +633,8 @@ int n; } -cwarp() /* compute color warp map */ +static void +cwarp(void) /* compute color warp map */ { register int i; @@ -610,9 +650,11 @@ memerr: } -int -cvtcolor(cout, cin) /* convert color according to our mapping */ -COLOR cout, cin; +static int +cvtcolor( /* convert color according to our mapping */ + COLOR cout, + COLOR cin +) { COLOR ctmp; int clipped; @@ -631,18 +673,22 @@ COLOR cout, cin; } -int -cresp(cout, cin) /* transform color according to matrix */ -COLOR cout, cin; +static int +cresp( /* transform color according to matrix */ + COLOR cout, + COLOR cin +) { colortrans(cout, solmat, cin); return(clipgamut(cout, bright(cout), CGAMUT, colmin, colmax)); } -xyY2RGB(rgbout, xyYin) /* convert xyY to RGB */ -COLOR rgbout; -register float xyYin[3]; +static void +xyY2RGB( /* convert xyY to RGB */ + COLOR rgbout, + register float xyYin[3] +) { COLOR ctmp; double d; @@ -656,7 +702,8 @@ register float xyYin[3]; } -picdebug() /* put out debugging picture */ +static void +picdebug(void) /* put out debugging picture */ { static COLOR blkcol = BLKCOLOR; COLOR *scan; @@ -712,7 +759,8 @@ picdebug() /* put out debugging picture */ } -clrdebug() /* put out debug picture from color input */ +static void +clrdebug(void) /* put out debug picture from color input */ { static COLR blkclr = BLKCOLR; COLR mbclr[24], cvclr[24], orclr[24]; @@ -782,10 +830,12 @@ clrdebug() /* put out debug picture from color input } -getpos(name, bnds, fp) /* get boundary position */ -char *name; -int bnds[2]; -FILE *fp; +static void +getpos( /* get boundary position */ + char *name, + int bnds[2], + FILE *fp +) { char buf[64]; @@ -799,10 +849,12 @@ FILE *fp; } -pickchartpos(pfn) /* display picture and pick chart location */ -char *pfn; +static void +pickchartpos( /* display picture and pick chart location */ + char *pfn +) { - char combuf[512]; + char combuf[PATH_MAX]; FILE *pfp; sprintf(combuf, DISPCOM, pfn);