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 1.2 by greg, Tue Sep 12 13:04:30 1989 UTC vs.
Revision 1.6 by greg, Fri Apr 19 09:00:55 1991 UTC

# Line 19 | Line 19 | static char SCCSid[] = "$SunId$ LBL";
19   int  xres = 0;                  /* resolution of input */
20   int  yres = 0;
21  
22 < int  uniq = 0;                  /* unique values? */
22 > int  uniq = 0;                  /* print only unique values? */
23  
24 < int  original = 0;              /* original values? */
24 > int  original = 0;              /* convert back to original values? */
25  
26   int  dataonly = 0;              /* data only format? */
27  
# Line 30 | Line 30 | int  brightonly = 0;           /* only brightness values? */
30   int  reverse = 0;               /* reverse conversion? */
31  
32   int  format = 'a';              /* input/output format */
33 + char  *fmtid = "ascii";         /* format identifier for header */
34  
35   int  header = 1;                /* do header */
36  
37 < double  exposure = 1.0;
37 > int  wrongformat = 0;           /* wrong input format? */
38  
39 + COLOR  exposure = WHTCOLOR;
40 +
41   char  *progname;
42  
43   FILE  *fin;
# Line 76 | Line 79 | char  **argv;
79                                  case '\0':
80                                  case 'a':               /* ascii */
81                                          format = 'a';
82 +                                        fmtid = "ascii";
83                                          break;
84                                  case 'i':               /* integer */
85 +                                        format = 'i';
86 +                                        fmtid = "ascii";
87 +                                        break;
88                                  case 'b':               /* byte */
89 +                                        format = 'b';
90 +                                        fmtid = "byte";
91 +                                        break;
92                                  case 'f':               /* float */
93 +                                        format = 'f';
94 +                                        fmtid = "float";
95 +                                        break;
96                                  case 'd':               /* double */
97 <                                        format = argv[i][2];
97 >                                        format = 'd';
98 >                                        fmtid = "double";
99                                          break;
100                                  default:
101                                          goto unkopt;
# Line 102 | Line 116 | unkopt:
116                          }
117                  else
118                          break;
119 <                        
119 >                                        /* recognize special formats */
120 >        if (dataonly && format == 'b')
121 >                if (brightonly)
122 >                        fmtid = "8-bit_grey";
123 >                else
124 >                        fmtid = "24-bit_rgb";
125 >
126          if (i == argc) {
127                  fin = stdin;
128          } else if (i == argc-1) {
# Line 119 | Line 139 | unkopt:
139          set_io();
140  
141          if (reverse) {
122                if (header)                     /* get header */
123                        copyheader(fin, stdout);
124                                                /* add to header */
125                printargs(i, argv, stdout);
126                printf("\n");
142                  if (yres <= 0 || xres <= 0) {
143                          fprintf(stderr, "%s: missing x and y resolution\n",
144                                          progname);
145                          quit(1);
146                  }
147 +                                        /* get header */
148 +                if (header && checkheader(fin, fmtid, stdout) < 0) {
149 +                        fprintf(stderr, "%s: wrong input format\n", progname);
150 +                        quit(1);
151 +                }
152 +                                                /* add to header */
153 +                printargs(i, argv, stdout);
154 +                fputformat(COLRFMT, stdout);
155 +                printf("\n");
156                  fputresolu(YMAJOR|YDECR, xres, yres, stdout);
157                  valtopix();
158          } else {
159                                                  /* get header */
160 <                getheader(fin, checkhead);
160 >                getheader(fin, checkhead, NULL);
161 >                if (wrongformat) {
162 >                        fprintf(stderr, "%s: input not a Radiance picture\n",
163 >                                        progname);
164 >                        quit(1);
165 >                }
166  
167                  if (xres <= 0 || yres <= 0)             /* get picture size */
168                          if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) {
# Line 144 | Line 173 | unkopt:
173                          }
174                  if (header) {
175                          printargs(i, argv, stdout);
176 +                        fputformat(fmtid, stdout);
177                          printf("\n");
178                  }
179                  pixtoval();
# Line 156 | Line 186 | unkopt:
186   checkhead(line)                         /* deal with line from header */
187   char  *line;
188   {
189 <        if (header)
189 >        char    fmt[32];
190 >        double  d;
191 >        COLOR   ctmp;
192 >
193 >        if (isformat(line)) {
194 >                formatval(fmt, line);
195 >                wrongformat = strcmp(fmt, COLRFMT);
196 >        } else if (original && isexpos(line)) {
197 >                d = 1.0/exposval(line);
198 >                scalecolor(exposure, d);
199 >        } else if (original && iscolcor(line)) {
200 >                colcorval(ctmp, line);
201 >                colval(exposure,RED) /= colval(ctmp,RED);
202 >                colval(exposure,GRN) /= colval(ctmp,GRN);
203 >                colval(exposure,BLU) /= colval(ctmp,BLU);
204 >        } else if (header)
205                  fputs(line, stdout);
161        if (!strncmp(line, "EXPOSURE=", 9))
162                exposure *= atof(line+9);
206   }
207  
208  
# Line 190 | Line 233 | pixtoval()                             /* convert picture to values */
233                                  else
234                                          copycolor(lastc, scanln[x]);
235                          if (original)
236 <                                scalecolor(scanln[x], 1.0/exposure);
236 >                                multcolor(scanln[x], exposure);
237                          if (!dataonly)
238                                  printf("%7d %7d ", x, y);
239                          if ((*putval)(scanln[x], stdout) < 0) {
# Line 259 | Line 302 | FILE  *fp;
302   {
303          double  vd[3];
304  
305 <        if (fread(vd, sizeof(double), 3, fp) != 3)
305 >        if (fread((char *)vd, sizeof(double), 3, fp) != 3)
306                  return(-1);
307          setcolor(col, vd[0], vd[1], vd[2]);
308          return(0);
# Line 272 | Line 315 | FILE  *fp;
315   {
316          float  vf[3];
317  
318 <        if (fread(vf, sizeof(float), 3, fp) != 3)
318 >        if (fread((char *)vf, sizeof(float), 3, fp) != 3)
319                  return(-1);
320          setcolor(col, vf[0], vf[1], vf[2]);
321          return(0);
# Line 298 | Line 341 | FILE  *fp;
341   {
342          BYTE  vb[3];
343  
344 <        if (fread(vb, sizeof(BYTE), 3, fp) != 3)
344 >        if (fread((char *)vb, sizeof(BYTE), 3, fp) != 3)
345                  return(-1);
346          setcolor(col,(vb[0]+.5)/256.,(vb[1]+.5)/256.,(vb[2]+.5)/256.);
347          return(0);
# Line 324 | Line 367 | FILE  *fp;
367   {
368          double  vd;
369  
370 <        if (fread(&vd, sizeof(double), 1, fp) != 1)
370 >        if (fread((char *)&vd, sizeof(double), 1, fp) != 1)
371                  return(-1);
372          setcolor(col, vd, vd, vd);
373          return(0);
# Line 337 | Line 380 | FILE  *fp;
380   {
381          float  vf;
382  
383 <        if (fread(&vf, sizeof(float), 1, fp) != 1)
383 >        if (fread((char *)&vf, sizeof(float), 1, fp) != 1)
384                  return(-1);
385          setcolor(col, vf, vf, vf);
386          return(0);
# Line 366 | Line 409 | FILE  *fp;
409          BYTE  vb;
410          double  d;
411  
412 <        if (fread(&vb, sizeof(BYTE), 1, fp) != 1)
412 >        if (fread((char *)&vb, sizeof(BYTE), 1, fp) != 1)
413                  return(-1);
414          d = (vb+.5)/256.;
415          setcolor(col, d, d, d);
# Line 396 | Line 439 | FILE  *fp;
439          vf[0] = colval(col,RED);
440          vf[1] = colval(col,GRN);
441          vf[2] = colval(col,BLU);
442 <        fwrite(vf, sizeof(float), 3, fp);
442 >        fwrite((char *)vf, sizeof(float), 3, fp);
443  
444          return(ferror(fp) ? -1 : 0);
445   }
# Line 411 | Line 454 | FILE  *fp;
454          vd[0] = colval(col,RED);
455          vd[1] = colval(col,GRN);
456          vd[2] = colval(col,BLU);
457 <        fwrite(vd, sizeof(double), 3, fp);
457 >        fwrite((char *)vd, sizeof(double), 3, fp);
458  
459          return(ferror(fp) ? -1 : 0);
460   }
# Line 443 | Line 486 | FILE  *fp;
486          vb[1] = min(i,255);
487          i = colval(col,BLU)*256.;
488          vb[2] = min(i,255);
489 <        fwrite(vb, sizeof(BYTE), 3, fp);
489 >        fwrite((char *)vb, sizeof(BYTE), 3, fp);
490  
491          return(ferror(fp) ? -1 : 0);
492   }
# Line 466 | Line 509 | FILE  *fp;
509          float  vf;
510  
511          vf = bright(col);
512 <        fwrite(&vf, sizeof(float), 1, fp);
512 >        fwrite((char *)&vf, sizeof(float), 1, fp);
513  
514          return(ferror(fp) ? -1 : 0);
515   }
# Line 479 | Line 522 | FILE  *fp;
522          double  vd;
523  
524          vd = bright(col);
525 <        fwrite(&vd, sizeof(double), 1, fp);
525 >        fwrite((char *)&vd, sizeof(double), 1, fp);
526  
527          return(ferror(fp) ? -1 : 0);
528   }
# Line 504 | Line 547 | FILE  *fp;
547  
548          i = bright(col)*256.;
549          vb = min(i,255);
550 <        fwrite(&vb, sizeof(BYTE), 1, fp);
550 >        fwrite((char *)&vb, sizeof(BYTE), 1, fp);
551  
552          return(ferror(fp) ? -1 : 0);
553   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines