--- ray/src/px/pvalue.c 2004/03/28 20:33:14 2.26 +++ ray/src/px/pvalue.c 2010/12/16 21:34:41 2.30 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: pvalue.c,v 2.26 2004/03/28 20:33:14 schorsch Exp $"; +static const char RCSid[] = "$Id: pvalue.c,v 2.30 2010/12/16 21:34:41 greg Exp $"; #endif /* * pvalue.c - program to print pixel values. @@ -36,6 +36,9 @@ int original = 0; /* convert to original values? */ int wrongformat = 0; /* wrong input format? */ double gamcor = 1.0; /* gamma correction */ +RGBPRIMP outprims = stdprims; /* output primaries for reverse conversion */ +RGBPRIMS myprims; + int ord[3] = {RED, GRN, BLU}; /* RGB ordering */ int rord[4]; /* reverse ordering */ @@ -66,9 +69,6 @@ static putfunc_t putpascii, putpint, putpdouble, putpf static void set_io(void); static void pixtoval(void); static void valtopix(void); -static void swap16(uint16 *wp, int n); -static void swap32(uint32 *wp, int n); -static void swap64(char *wp, int n); static double @@ -149,8 +149,22 @@ main( case 'b': /* brightness values */ putprim = argv[i][0] == '-' ? BRIGHT : ALL; break; - case 'p': /* put primary */ + case 'p': /* primary controls */ switch (argv[i][2]) { + /* these two options affect -r conversion */ + case '\0': + myprims[RED][CIEX] = atof(argv[++i]); + myprims[RED][CIEY] = atof(argv[++i]); + myprims[GRN][CIEX] = atof(argv[++i]); + myprims[GRN][CIEY] = atof(argv[++i]); + myprims[BLU][CIEX] = atof(argv[++i]); + myprims[BLU][CIEY] = atof(argv[++i]); + myprims[WHT][CIEX] = atof(argv[++i]); + myprims[WHT][CIEY] = atof(argv[++i]); + outprims = myprims; + break; + case 'x': case 'X': outprims = NULL; break; + /* the following options affect +r only */ case 'r': case 'R': putprim = RED; break; case 'g': case 'G': putprim = GRN; break; case 'b': case 'B': putprim = BLU; break; @@ -325,7 +339,12 @@ unkopt: printargs(i, argv, stdout); if (expval < .99 || expval > 1.01) fputexpos(expval, stdout); - fputformat(COLRFMT, stdout); + if (outprims != NULL) { + if (outprims != stdprims) + fputprims(outprims, stdout); + fputformat(COLRFMT, stdout); + } else /* XYZ data */ + fputformat(CIEFMT, stdout); putchar('\n'); fputsresolu(&picres, stdout); /* always put resolution */ valtopix(); @@ -375,13 +394,9 @@ checkhead( /* deal with line from header */ COLOR ctmp; if (formatval(fmt, line)) { - if (!strcmp(fmt, CIEFMT)) { + if (!strcmp(fmt, CIEFMT)) mybright = &xyz_bright; - if (original) { - scalecolor(exposure, 1./WHTEFFICACY); - doexposure++; - } - } else if (!strcmp(fmt, COLRFMT)) + else if (!strcmp(fmt, COLRFMT)) mybright = &rgb_bright; else wrongformat++; @@ -528,51 +543,6 @@ int code; } -static void -swap16( /* swap n 16-bit words */ - register uint16 *wp, - int n -) -{ - while (n-- > 0) { - *wp = *wp << 8 | ((*wp >> 8) & 0xff); - wp++; - } -} - - -static void -swap32( /* swap n 32-bit words */ - register uint32 *wp, - int n -) -{ - while (n-- > 0) { - *wp = *wp << 24 | ((*wp >> 24) & 0xff) | - (*wp & 0xff00) << 8 | (*wp & 0xff0000) >> 8; - wp++; - } -} - - -static void -swap64( /* swap n 64-bit words */ - register char *wp, - int n -) -{ - register int t; - - while (n-- > 0) { - t = wp[0]; wp[0] = wp[7]; wp[7] = t; - t = wp[1]; wp[1] = wp[6]; wp[6] = t; - t = wp[2]; wp[2] = wp[5]; wp[5] = t; - t = wp[3]; wp[3] = wp[4]; wp[4] = t; - wp += 8; - } -} - - static int getcascii( /* get an ascii color value from stream(s) */ COLOR col @@ -634,7 +604,7 @@ getcfloat( /* get a float color value from stream(s) return(-1); } if (swapbytes) - swap32((uint32 *)vf, 3); + swap32((char *)vf, 3); setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]); return(0); } @@ -701,7 +671,7 @@ getcword( /* get a 16-bit color value from stream(s) return(-1); } if (swapbytes) - swap16(vw, 3); + swap16((char *)vw, 3); setcolor(col, (vw[rord[RED]]+.5)/65536., (vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.); return(0); @@ -748,7 +718,7 @@ getbfloat( /* get a float brightness value from fin * if (fread((char *)&vf, sizeof(float), 1, fin) != 1) return(-1); if (swapbytes) - swap32((uint32 *)&vf, 1); + swap32((char *)&vf, 1); setcolor(col, vf, vf, vf); return(0); } @@ -797,7 +767,7 @@ getbword( /* get a 16-bit brightness value from fin * if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1) return(-1); if (swapbytes) - swap16(&vw, 1); + swap16((char *)&vw, 1); d = (vw+.5)/65536.; setcolor(col, d, d, d); return(0); @@ -829,7 +799,7 @@ putcfloat( /* put a float color to stdout */ vf[1] = colval(col,ord[1]); vf[2] = colval(col,ord[2]); if (swapbytes) - swap32((uint32 *)vf, 3); + swap32((char *)vf, 3); fwrite((char *)vf, sizeof(float), 3, stdout); return(ferror(stdout) ? -1 : 0); @@ -903,7 +873,7 @@ putcword( /* put a 16-bit color to stdout */ i = colval(col,ord[2])*65536.; vw[2] = min(i,65535); if (swapbytes) - swap16(vw, 3); + swap16((char *)vw, 3); fwrite((char *)vw, sizeof(uint16), 3, stdout); return(ferror(stdout) ? -1 : 0); @@ -930,7 +900,7 @@ putbfloat( /* put a float brightness to stdout */ vf = (*mybright)(col); if (swapbytes) - swap32((uint32 *)&vf, 1); + swap32((char *)&vf, 1); fwrite((char *)&vf, sizeof(float), 1, stdout); return(ferror(stdout) ? -1 : 0); @@ -991,7 +961,7 @@ putbword( /* put a 16-bit brightness to stdout */ i = (*mybright)(col)*65536.; vw = min(i,65535); if (swapbytes) - swap16(&vw, 1); + swap16((char *)&vw, 1); fwrite((char *)&vw, sizeof(uint16), 1, stdout); return(ferror(stdout) ? -1 : 0); @@ -1018,7 +988,7 @@ putpfloat( /* put a float primary to stdout */ vf = colval(col,putprim); if (swapbytes) - swap32((uint32 *)&vf, 1); + swap32((char *)&vf, 1); fwrite((char *)&vf, sizeof(float), 1, stdout); return(ferror(stdout) ? -1 : 0); @@ -1079,7 +1049,7 @@ putpword( /* put a 16-bit primary to stdout */ i = colval(col,putprim)*65536.; vw = min(i,65535); if (swapbytes) - swap16(&vw, 1); + swap16((char *)&vw, 1); fwrite((char *)&vw, sizeof(uint16), 1, stdout); return(ferror(stdout) ? -1 : 0);