ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pvalue.c
(Generate patch)

Comparing ray/src/px/pvalue.c (file contents):
Revision 2.4 by greg, Fri May 8 11:55:42 1992 UTC vs.
Revision 2.7 by greg, Tue Nov 9 15:21:00 1993 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16  
17   #include  "resolu.h"
18  
19 < #define  min(a,b)               ((a)<(b)?(a):(b))
19 > #define  min(a,b)               ((a)<(b)?(a):(b))
20  
21 < RESOLU  picres;                 /* resolution of picture */
21 > RESOLU  picres;                 /* resolution of picture */
22  
23   int  uniq = 0;                  /* print only unique values? */
24  
25 < int  original = 0;              /* convert back to original values? */
25 > int  doexposure = 0;            /* exposure change? (>100 to print) */
26  
27   int  dataonly = 0;              /* data only format? */
28  
# Line 37 | Line 37 | int  header = 1;               /* do header? */
37  
38   int  resolution = 1;            /* put/get resolution string? */
39  
40 + int  original = 0;              /* convert to original values? */
41 +
42   int  wrongformat = 0;           /* wrong input format? */
43  
44 < double  gamcor = 1.0;           /* gamma correction */
44 > double  gamcor = 1.0;           /* gamma correction */
45  
46   int  ord[3] = {RED, GRN, BLU};  /* RGB ordering */
47   int  rord[4];                   /* reverse ordering */
# Line 58 | Line 60 | int  argc;
60   char  **argv;
61   {
62          extern int  checkhead();
63 +        double  d, expval = 1.0;
64          int  i;
65  
66          progname = argv[0];
# Line 78 | Line 81 | char  **argv;
81                                  original = argv[i][0] == '-';
82                                  break;
83                          case 'g':               /* gamma correction */
84 <                                gamcor = atof(argv[++i]);
84 >                                gamcor = atof(argv[i+1]);
85                                  if (argv[i][0] == '+')
86                                          gamcor = 1.0/gamcor;
87 +                                i++;
88                                  break;
89 +                        case 'e':               /* exposure correction */
90 +                                d = atof(argv[i+1]);
91 +                                if (argv[i+1][0] == '-' || argv[i+1][0] == '+')
92 +                                        d = pow(2.0, d);
93 +                                if (argv[i][0] == '-')
94 +                                        doexposure = 100;
95 +                                scalecolor(exposure, d);
96 +                                expval *= d;
97 +                                doexposure++;
98 +                                i++;
99 +                                break;
100                          case 'R':               /* reverse byte sequence */
101                                  if (argv[i][0] == '-') {
102                                          ord[0]=BLU; ord[1]=GRN; ord[2]=RED;
# Line 127 | Line 142 | char  **argv;
142                                  }
143                                  break;
144                          case 'x':               /* x resolution */
145 +                        case 'X':               /* x resolution */
146                                  resolution = 0;
147                                  if (argv[i][0] == '-')
148                                          picres.or |= XDECR;
149                                  picres.xr = atoi(argv[++i]);
150                                  break;
151                          case 'y':               /* y resolution */
152 +                        case 'Y':               /* y resolution */
153                                  resolution = 0;
154                                  if (argv[i][0] == '-')
155                                          picres.or |= YDECR;
# Line 176 | Line 193 | unkopt:
193          set_io();
194  
195          if (reverse) {
196 + #ifdef MSDOS
197 +                setmode(fileno(stdout), O_BINARY);
198 +                if (format != 'a' && format != 'i')
199 +                        setmode(fileno(fin), O_BINARY);
200 + #endif
201                                          /* get header */
202                  if (header && checkheader(fin, fmtid, stdout) < 0) {
203                          fprintf(stderr, "%s: wrong input format\n", progname);
# Line 189 | Line 211 | unkopt:
211                  }
212                                                  /* add to header */
213                  printargs(i, argv, stdout);
214 +                if (doexposure > 100)
215 +                        fputexpos(expval, stdout);
216                  fputformat(COLRFMT, stdout);
217                  putchar('\n');
218                  fputsresolu(&picres, stdout);   /* always put resolution */
219                  valtopix();
220          } else {
221 + #ifdef MSDOS
222 +                setmode(fileno(fin), O_BINARY);
223 +                if (format != 'a' && format != 'i')
224 +                        setmode(fileno(stdout), O_BINARY);
225 + #endif
226                                                  /* get header */
227                  getheader(fin, checkhead, NULL);
228                  if (wrongformat) {
# Line 207 | Line 236 | unkopt:
236                  }
237                  if (header) {
238                          printargs(i, argv, stdout);
239 +                        if (doexposure > 100)
240 +                                fputexpos(expval, stdout);
241                          fputformat(fmtid, stdout);
242                          putchar('\n');
243                  }
# Line 232 | Line 263 | char  *line;
263          } else if (original && isexpos(line)) {
264                  d = 1.0/exposval(line);
265                  scalecolor(exposure, d);
266 +                doexposure++;
267          } else if (original && iscolcor(line)) {
268                  colcorval(ctmp, line);
269                  setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED),
270                                  colval(exposure,GRN)/colval(ctmp,GRN),
271                                  colval(exposure,BLU)/colval(ctmp,BLU));
272 +                doexposure++;
273          } else if (header)
274                  fputs(line, stdout);
275   }
# Line 244 | Line 277 | char  *line;
277  
278   pixtoval()                              /* convert picture to values */
279   {
280 <        register COLOR  *scanln;
280 >        register COLOR  *scanln;
281          int  dogamma;
282          COLOR  lastc;
283          FLOAT  hv[2];
# Line 274 | Line 307 | pixtoval()                             /* convert picture to values */
307                                          continue;
308                                  else
309                                          copycolor(lastc, scanln[x]);
310 <                        if (original)
310 >                        if (doexposure)
311                                  multcolor(scanln[x], exposure);
312                          if (dogamma)
313                                  setcolor(scanln[x],
# Line 299 | Line 332 | pixtoval()                             /* convert picture to values */
332   valtopix()                      /* convert values to a pixel file */
333   {
334          int  dogamma;
335 <        register COLOR  *scanln;
335 >        register COLOR  *scanln;
336          int  y;
337          register int  x;
338  
# Line 322 | Line 355 | valtopix()                     /* convert values to a pixel file */
355                                          pow(colval(scanln[x],RED), gamcor),
356                                          pow(colval(scanln[x],GRN), gamcor),
357                                          pow(colval(scanln[x],BLU), gamcor));
358 +                        if (doexposure)
359 +                                multcolor(scanln[x], exposure);
360                  }
361                  if (fwritescan(scanln, scanlen(&picres), stdout) < 0) {
362                          fprintf(stderr, "%s: write error\n", progname);
# Line 343 | Line 378 | getcascii(col, fp)             /* get an ascii color value from f
378   COLOR  col;
379   FILE  *fp;
380   {
381 <        double  vd[3];
381 >        double  vd[3];
382  
383          if (fscanf(fp, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3)
384                  return(-1);
# Line 356 | Line 391 | getcdouble(col, fp)            /* get a double color value from
391   COLOR  col;
392   FILE  *fp;
393   {
394 <        double  vd[3];
394 >        double  vd[3];
395  
396          if (fread((char *)vd, sizeof(double), 3, fp) != 3)
397                  return(-1);
# Line 410 | Line 445 | getbascii(col, fp)             /* get an ascii brightness value f
445   COLOR  col;
446   FILE  *fp;
447   {
448 <        double  vd;
448 >        double  vd;
449  
450          if (fscanf(fp, "%lf", &vd) != 1)
451                  return(-1);
# Line 423 | Line 458 | getbdouble(col, fp)            /* get a double brightness value
458   COLOR  col;
459   FILE  *fp;
460   {
461 <        double  vd;
461 >        double  vd;
462  
463          if (fread((char *)&vd, sizeof(double), 1, fp) != 1)
464                  return(-1);
# Line 450 | Line 485 | COLOR  col;
485   FILE  *fp;
486   {
487          int  vi;
488 <        double  d;
488 >        double  d;
489  
490          if (fscanf(fp, "%d", &vi) != 1)
491                  return(-1);
# Line 465 | Line 500 | COLOR  col;
500   FILE  *fp;
501   {
502          BYTE  vb;
503 <        double  d;
503 >        double  d;
504  
505          if (fread((char *)&vb, sizeof(BYTE), 1, fp) != 1)
506                  return(-1);
# Line 507 | Line 542 | putcdouble(col, fp)                    /* put a double color to fp */
542   COLOR  col;
543   FILE  *fp;
544   {
545 <        double  vd[3];
545 >        double  vd[3];
546  
547          vd[0] = colval(col,ord[0]);
548          vd[1] = colval(col,ord[1]);
# Line 577 | Line 612 | putbdouble(col, fp)                    /* put a double brightness to fp
612   COLOR  col;
613   FILE  *fp;
614   {
615 <        double  vd;
615 >        double  vd;
616  
617          vd = bright(col);
618          fwrite((char *)&vd, sizeof(double), 1, fp);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines