--- ray/src/px/pvalue.c 1992/05/08 11:55:42 2.4 +++ ray/src/px/pvalue.c 1994/10/06 13:27:16 2.9 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -16,13 +16,13 @@ static char SCCSid[] = "$SunId$ LBL"; #include "resolu.h" -#define min(a,b) ((a)<(b)?(a):(b)) +#define min(a,b) ((a)<(b)?(a):(b)) -RESOLU picres; /* resolution of picture */ +RESOLU picres; /* resolution of picture */ int uniq = 0; /* print only unique values? */ -int original = 0; /* convert back to original values? */ +int doexposure = 0; /* exposure change? (>100 to print) */ int dataonly = 0; /* data only format? */ @@ -37,9 +37,11 @@ int header = 1; /* do header? */ int resolution = 1; /* put/get resolution string? */ +int original = 0; /* convert to original values? */ + int wrongformat = 0; /* wrong input format? */ -double gamcor = 1.0; /* gamma correction */ +double gamcor = 1.0; /* gamma correction */ int ord[3] = {RED, GRN, BLU}; /* RGB ordering */ int rord[4]; /* reverse ordering */ @@ -58,6 +60,7 @@ int argc; char **argv; { extern int checkhead(); + double d, expval = 1.0; int i; progname = argv[0]; @@ -78,10 +81,21 @@ char **argv; original = argv[i][0] == '-'; break; case 'g': /* gamma correction */ - gamcor = atof(argv[++i]); + gamcor = atof(argv[i+1]); if (argv[i][0] == '+') gamcor = 1.0/gamcor; + i++; break; + case 'e': /* exposure correction */ + d = atof(argv[i+1]); + if (argv[i+1][0] == '-' || argv[i+1][0] == '+') + d = pow(2.0, d); + if (argv[i][0] == '-') + expval *= d; + scalecolor(exposure, d); + doexposure++; + i++; + break; case 'R': /* reverse byte sequence */ if (argv[i][0] == '-') { ord[0]=BLU; ord[1]=GRN; ord[2]=RED; @@ -127,12 +141,14 @@ char **argv; } break; case 'x': /* x resolution */ + case 'X': /* x resolution */ resolution = 0; if (argv[i][0] == '-') picres.or |= XDECR; picres.xr = atoi(argv[++i]); break; case 'y': /* y resolution */ + case 'Y': /* y resolution */ resolution = 0; if (argv[i][0] == '-') picres.or |= YDECR; @@ -176,11 +192,20 @@ unkopt: set_io(); if (reverse) { +#ifdef MSDOS + setmode(fileno(stdout), O_BINARY); + if (format != 'a' && format != 'i') + setmode(fileno(fin), O_BINARY); +#endif /* get header */ - if (header && checkheader(fin, fmtid, stdout) < 0) { - fprintf(stderr, "%s: wrong input format\n", progname); - quit(1); - } + if (header) { + if (checkheader(fin, fmtid, stdout) < 0) { + fprintf(stderr, "%s: wrong input format\n", + progname); + quit(1); + } + } else + newheader("RADIANCE", stdout); /* get resolution */ if ((resolution && !fgetsresolu(&picres, fin)) || picres.xr <= 0 || picres.yr <= 0) { @@ -189,11 +214,18 @@ unkopt: } /* add to header */ printargs(i, argv, stdout); + if (expval < .99 || expval > 1.01) + fputexpos(expval, stdout); fputformat(COLRFMT, stdout); putchar('\n'); fputsresolu(&picres, stdout); /* always put resolution */ valtopix(); } else { +#ifdef MSDOS + setmode(fileno(fin), O_BINARY); + if (format != 'a' && format != 'i') + setmode(fileno(stdout), O_BINARY); +#endif /* get header */ getheader(fin, checkhead, NULL); if (wrongformat) { @@ -207,6 +239,8 @@ unkopt: } if (header) { printargs(i, argv, stdout); + if (expval < .99 || expval > 1.01) + fputexpos(expval, stdout); fputformat(fmtid, stdout); putchar('\n'); } @@ -226,17 +260,18 @@ char *line; double d; COLOR ctmp; - if (isformat(line)) { - formatval(fmt, line); + if (formatval(fmt, line)) wrongformat = strcmp(fmt, COLRFMT); - } else if (original && isexpos(line)) { + else if (original && isexpos(line)) { d = 1.0/exposval(line); scalecolor(exposure, d); + doexposure++; } else if (original && iscolcor(line)) { colcorval(ctmp, line); setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED), colval(exposure,GRN)/colval(ctmp,GRN), colval(exposure,BLU)/colval(ctmp,BLU)); + doexposure++; } else if (header) fputs(line, stdout); } @@ -244,7 +279,7 @@ char *line; pixtoval() /* convert picture to values */ { - register COLOR *scanln; + register COLOR *scanln; int dogamma; COLOR lastc; FLOAT hv[2]; @@ -274,7 +309,7 @@ pixtoval() /* convert picture to values */ continue; else copycolor(lastc, scanln[x]); - if (original) + if (doexposure) multcolor(scanln[x], exposure); if (dogamma) setcolor(scanln[x], @@ -299,7 +334,7 @@ pixtoval() /* convert picture to values */ valtopix() /* convert values to a pixel file */ { int dogamma; - register COLOR *scanln; + register COLOR *scanln; int y; register int x; @@ -322,6 +357,8 @@ valtopix() /* convert values to a pixel file */ pow(colval(scanln[x],RED), gamcor), pow(colval(scanln[x],GRN), gamcor), pow(colval(scanln[x],BLU), gamcor)); + if (doexposure) + multcolor(scanln[x], exposure); } if (fwritescan(scanln, scanlen(&picres), stdout) < 0) { fprintf(stderr, "%s: write error\n", progname); @@ -343,7 +380,7 @@ getcascii(col, fp) /* get an ascii color value from f COLOR col; FILE *fp; { - double vd[3]; + double vd[3]; if (fscanf(fp, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3) return(-1); @@ -356,7 +393,7 @@ getcdouble(col, fp) /* get a double color value from COLOR col; FILE *fp; { - double vd[3]; + double vd[3]; if (fread((char *)vd, sizeof(double), 3, fp) != 3) return(-1); @@ -410,7 +447,7 @@ getbascii(col, fp) /* get an ascii brightness value f COLOR col; FILE *fp; { - double vd; + double vd; if (fscanf(fp, "%lf", &vd) != 1) return(-1); @@ -423,7 +460,7 @@ getbdouble(col, fp) /* get a double brightness value COLOR col; FILE *fp; { - double vd; + double vd; if (fread((char *)&vd, sizeof(double), 1, fp) != 1) return(-1); @@ -450,7 +487,7 @@ COLOR col; FILE *fp; { int vi; - double d; + double d; if (fscanf(fp, "%d", &vi) != 1) return(-1); @@ -465,7 +502,7 @@ COLOR col; FILE *fp; { BYTE vb; - double d; + double d; if (fread((char *)&vb, sizeof(BYTE), 1, fp) != 1) return(-1); @@ -507,7 +544,7 @@ putcdouble(col, fp) /* put a double color to fp */ COLOR col; FILE *fp; { - double vd[3]; + double vd[3]; vd[0] = colval(col,ord[0]); vd[1] = colval(col,ord[1]); @@ -577,7 +614,7 @@ putbdouble(col, fp) /* put a double brightness to fp COLOR col; FILE *fp; { - double vd; + double vd; vd = bright(col); fwrite((char *)&vd, sizeof(double), 1, fp);