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.9 by greg, Thu Oct 6 13:27:16 1994 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 +                                        expval *= d;
95 +                                scalecolor(exposure, d);
96 +                                doexposure++;
97 +                                i++;
98 +                                break;
99                          case 'R':               /* reverse byte sequence */
100                                  if (argv[i][0] == '-') {
101                                          ord[0]=BLU; ord[1]=GRN; ord[2]=RED;
# Line 127 | Line 141 | char  **argv;
141                                  }
142                                  break;
143                          case 'x':               /* x resolution */
144 +                        case 'X':               /* x resolution */
145                                  resolution = 0;
146                                  if (argv[i][0] == '-')
147                                          picres.or |= XDECR;
148                                  picres.xr = atoi(argv[++i]);
149                                  break;
150                          case 'y':               /* y resolution */
151 +                        case 'Y':               /* y resolution */
152                                  resolution = 0;
153                                  if (argv[i][0] == '-')
154                                          picres.or |= YDECR;
# Line 176 | Line 192 | unkopt:
192          set_io();
193  
194          if (reverse) {
195 + #ifdef MSDOS
196 +                setmode(fileno(stdout), O_BINARY);
197 +                if (format != 'a' && format != 'i')
198 +                        setmode(fileno(fin), O_BINARY);
199 + #endif
200                                          /* get header */
201 <                if (header && checkheader(fin, fmtid, stdout) < 0) {
202 <                        fprintf(stderr, "%s: wrong input format\n", progname);
203 <                        quit(1);
204 <                }
201 >                if (header) {
202 >                        if (checkheader(fin, fmtid, stdout) < 0) {
203 >                                fprintf(stderr, "%s: wrong input format\n",
204 >                                                progname);
205 >                                quit(1);
206 >                        }
207 >                } else
208 >                        newheader("RADIANCE", stdout);
209                                          /* get resolution */
210                  if ((resolution && !fgetsresolu(&picres, fin)) ||
211                                  picres.xr <= 0 || picres.yr <= 0) {
# Line 189 | Line 214 | unkopt:
214                  }
215                                                  /* add to header */
216                  printargs(i, argv, stdout);
217 +                if (expval < .99 || expval > 1.01)
218 +                        fputexpos(expval, stdout);
219                  fputformat(COLRFMT, stdout);
220                  putchar('\n');
221                  fputsresolu(&picres, stdout);   /* always put resolution */
222                  valtopix();
223          } else {
224 + #ifdef MSDOS
225 +                setmode(fileno(fin), O_BINARY);
226 +                if (format != 'a' && format != 'i')
227 +                        setmode(fileno(stdout), O_BINARY);
228 + #endif
229                                                  /* get header */
230                  getheader(fin, checkhead, NULL);
231                  if (wrongformat) {
# Line 207 | Line 239 | unkopt:
239                  }
240                  if (header) {
241                          printargs(i, argv, stdout);
242 +                        if (expval < .99 || expval > 1.01)
243 +                                fputexpos(expval, stdout);
244                          fputformat(fmtid, stdout);
245                          putchar('\n');
246                  }
# Line 226 | Line 260 | char  *line;
260          double  d;
261          COLOR   ctmp;
262  
263 <        if (isformat(line)) {
230 <                formatval(fmt, line);
263 >        if (formatval(fmt, line))
264                  wrongformat = strcmp(fmt, COLRFMT);
265 <        } else if (original && isexpos(line)) {
265 >        else if (original && isexpos(line)) {
266                  d = 1.0/exposval(line);
267                  scalecolor(exposure, d);
268 +                doexposure++;
269          } else if (original && iscolcor(line)) {
270                  colcorval(ctmp, line);
271                  setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED),
272                                  colval(exposure,GRN)/colval(ctmp,GRN),
273                                  colval(exposure,BLU)/colval(ctmp,BLU));
274 +                doexposure++;
275          } else if (header)
276                  fputs(line, stdout);
277   }
# Line 244 | Line 279 | char  *line;
279  
280   pixtoval()                              /* convert picture to values */
281   {
282 <        register COLOR  *scanln;
282 >        register COLOR  *scanln;
283          int  dogamma;
284          COLOR  lastc;
285          FLOAT  hv[2];
# Line 274 | Line 309 | pixtoval()                             /* convert picture to values */
309                                          continue;
310                                  else
311                                          copycolor(lastc, scanln[x]);
312 <                        if (original)
312 >                        if (doexposure)
313                                  multcolor(scanln[x], exposure);
314                          if (dogamma)
315                                  setcolor(scanln[x],
# Line 299 | Line 334 | pixtoval()                             /* convert picture to values */
334   valtopix()                      /* convert values to a pixel file */
335   {
336          int  dogamma;
337 <        register COLOR  *scanln;
337 >        register COLOR  *scanln;
338          int  y;
339          register int  x;
340  
# Line 322 | Line 357 | valtopix()                     /* convert values to a pixel file */
357                                          pow(colval(scanln[x],RED), gamcor),
358                                          pow(colval(scanln[x],GRN), gamcor),
359                                          pow(colval(scanln[x],BLU), gamcor));
360 +                        if (doexposure)
361 +                                multcolor(scanln[x], exposure);
362                  }
363                  if (fwritescan(scanln, scanlen(&picres), stdout) < 0) {
364                          fprintf(stderr, "%s: write error\n", progname);
# Line 343 | Line 380 | getcascii(col, fp)             /* get an ascii color value from f
380   COLOR  col;
381   FILE  *fp;
382   {
383 <        double  vd[3];
383 >        double  vd[3];
384  
385          if (fscanf(fp, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3)
386                  return(-1);
# Line 356 | Line 393 | getcdouble(col, fp)            /* get a double color value from
393   COLOR  col;
394   FILE  *fp;
395   {
396 <        double  vd[3];
396 >        double  vd[3];
397  
398          if (fread((char *)vd, sizeof(double), 3, fp) != 3)
399                  return(-1);
# Line 410 | Line 447 | getbascii(col, fp)             /* get an ascii brightness value f
447   COLOR  col;
448   FILE  *fp;
449   {
450 <        double  vd;
450 >        double  vd;
451  
452          if (fscanf(fp, "%lf", &vd) != 1)
453                  return(-1);
# Line 423 | Line 460 | getbdouble(col, fp)            /* get a double brightness value
460   COLOR  col;
461   FILE  *fp;
462   {
463 <        double  vd;
463 >        double  vd;
464  
465          if (fread((char *)&vd, sizeof(double), 1, fp) != 1)
466                  return(-1);
# Line 450 | Line 487 | COLOR  col;
487   FILE  *fp;
488   {
489          int  vi;
490 <        double  d;
490 >        double  d;
491  
492          if (fscanf(fp, "%d", &vi) != 1)
493                  return(-1);
# Line 465 | Line 502 | COLOR  col;
502   FILE  *fp;
503   {
504          BYTE  vb;
505 <        double  d;
505 >        double  d;
506  
507          if (fread((char *)&vb, sizeof(BYTE), 1, fp) != 1)
508                  return(-1);
# Line 507 | Line 544 | putcdouble(col, fp)                    /* put a double color to fp */
544   COLOR  col;
545   FILE  *fp;
546   {
547 <        double  vd[3];
547 >        double  vd[3];
548  
549          vd[0] = colval(col,ord[0]);
550          vd[1] = colval(col,ord[1]);
# Line 577 | Line 614 | putbdouble(col, fp)                    /* put a double brightness to fp
614   COLOR  col;
615   FILE  *fp;
616   {
617 <        double  vd;
617 >        double  vd;
618  
619          vd = bright(col);
620          fwrite((char *)&vd, sizeof(double), 1, fp);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines