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.5 by greg, Fri Dec 14 16:33:19 1990 UTC vs.
Revision 1.7 by greg, Fri May 10 08:51:53 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# 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 + int  wrongformat = 0;           /* wrong input format? */
38 +
39 + double  gamma = 1.0;            /* gamma correction */
40 +
41   COLOR  exposure = WHTCOLOR;
42  
43   char  *progname;
44  
45   FILE  *fin;
46  
47 + extern double  atof(), pow();
48 +
49   int  (*getval)(), (*putval)();
50  
51  
# Line 46 | Line 53 | main(argc, argv)
53   int  argc;
54   char  **argv;
55   {
49        extern double  atof();
56          extern int  checkhead();
57          int  i;
58  
# Line 64 | Line 70 | char  **argv;
70                          case 'o':               /* original values */
71                                  original = 1;
72                                  break;
73 +                        case 'g':               /* gamma correction */
74 +                                gamma = atof(argv[++i]);
75 +                                break;
76                          case 'r':               /* reverse conversion */
77                                  reverse = 1;
78                                  break;
# Line 76 | Line 85 | char  **argv;
85                                  case '\0':
86                                  case 'a':               /* ascii */
87                                          format = 'a';
88 +                                        fmtid = "ascii";
89                                          break;
90                                  case 'i':               /* integer */
91 +                                        format = 'i';
92 +                                        fmtid = "ascii";
93 +                                        break;
94                                  case 'b':               /* byte */
95 +                                        format = 'b';
96 +                                        fmtid = "byte";
97 +                                        break;
98                                  case 'f':               /* float */
99 +                                        format = 'f';
100 +                                        fmtid = "float";
101 +                                        break;
102                                  case 'd':               /* double */
103 <                                        format = argv[i][2];
103 >                                        format = 'd';
104 >                                        fmtid = "double";
105                                          break;
106                                  default:
107                                          goto unkopt;
# Line 102 | Line 122 | unkopt:
122                          }
123                  else
124                          break;
125 <                        
125 >                                        /* recognize special formats */
126 >        if (dataonly && format == 'b')
127 >                if (brightonly)
128 >                        fmtid = "8-bit_grey";
129 >                else
130 >                        fmtid = "24-bit_rgb";
131 >
132          if (i == argc) {
133                  fin = stdin;
134          } else if (i == argc-1) {
# Line 119 | Line 145 | unkopt:
145          set_io();
146  
147          if (reverse) {
122                if (header)                     /* get header */
123                        copyheader(fin, stdout);
124                                                /* add to header */
125                printargs(i, argv, stdout);
126                printf("\n");
148                  if (yres <= 0 || xres <= 0) {
149                          fprintf(stderr, "%s: missing x and y resolution\n",
150                                          progname);
151                          quit(1);
152                  }
153 +                                        /* get header */
154 +                if (header && checkheader(fin, fmtid, stdout) < 0) {
155 +                        fprintf(stderr, "%s: wrong input format\n", progname);
156 +                        quit(1);
157 +                }
158 +                                                /* add to header */
159 +                printargs(i, argv, stdout);
160 +                fputformat(COLRFMT, stdout);
161 +                printf("\n");
162                  fputresolu(YMAJOR|YDECR, xres, yres, stdout);
163                  valtopix();
164          } else {
165                                                  /* get header */
166 <                getheader(fin, checkhead);
166 >                getheader(fin, checkhead, NULL);
167 >                if (wrongformat) {
168 >                        fprintf(stderr, "%s: input not a Radiance picture\n",
169 >                                        progname);
170 >                        quit(1);
171 >                }
172  
173                  if (xres <= 0 || yres <= 0)             /* get picture size */
174                          if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) {
# Line 144 | Line 179 | unkopt:
179                          }
180                  if (header) {
181                          printargs(i, argv, stdout);
182 +                        fputformat(fmtid, stdout);
183                          printf("\n");
184                  }
185                  pixtoval();
# Line 156 | Line 192 | unkopt:
192   checkhead(line)                         /* deal with line from header */
193   char  *line;
194   {
195 +        char    fmt[32];
196          double  d;
197          COLOR   ctmp;
198  
199 <        if (header)
200 <                fputs(line, stdout);
201 <        if (isexpos(line)) {
199 >        if (isformat(line)) {
200 >                formatval(fmt, line);
201 >                wrongformat = strcmp(fmt, COLRFMT);
202 >        } else if (original && isexpos(line)) {
203                  d = 1.0/exposval(line);
204                  scalecolor(exposure, d);
205 <        } else if (iscolcor(line)) {
205 >        } else if (original && iscolcor(line)) {
206                  colcorval(ctmp, line);
207 <                colval(exposure,RED) /= colval(ctmp,RED);
208 <                colval(exposure,GRN) /= colval(ctmp,GRN);
209 <                colval(exposure,BLU) /= colval(ctmp,BLU);
210 <        }
207 >                setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED),
208 >                                colval(exposure,GRN)/colval(ctmp,GRN),
209 >                                colval(exposure,BLU)/colval(ctmp,BLU));
210 >        } else if (header)
211 >                fputs(line, stdout);
212   }
213  
214  
215   pixtoval()                              /* convert picture to values */
216   {
217 <        COLOR  *scanln;
217 >        register COLOR  *scanln;
218 >        int  dogamma;
219          COLOR  lastc;
220          int  y;
221          register int  x;
# Line 185 | Line 225 | pixtoval()                             /* convert picture to values */
225                  fprintf(stderr, "%s: out of memory\n", progname);
226                  quit(1);
227          }
228 +        dogamma = gamma < .95 || gamma > 1.05;
229          setcolor(lastc, 0.0, 0.0, 0.0);
230          for (y = yres-1; y >= 0; y--) {
231                  if (freadscan(scanln, xres, fin) < 0) {
# Line 193 | Line 234 | pixtoval()                             /* convert picture to values */
234                  }
235                  for (x = 0; x < xres; x++) {
236                          if (uniq)
237 <                                if (    scanln[x][RED] == lastc[RED] &&
238 <                                        scanln[x][GRN] == lastc[GRN] &&
239 <                                        scanln[x][BLU] == lastc[BLU]    )
237 >                                if (    colval(scanln[x],RED) ==
238 >                                                colval(lastc,RED) &&
239 >                                        colval(scanln[x],GRN) ==
240 >                                                colval(lastc,GRN) &&
241 >                                        colval(scanln[x],BLU) ==
242 >                                                colval(lastc,BLU)       )
243                                          continue;
244                                  else
245                                          copycolor(lastc, scanln[x]);
246                          if (original)
247                                  multcolor(scanln[x], exposure);
248 +                        if (dogamma)
249 +                                setcolor(scanln[x],
250 +                                        pow(colval(scanln[x],RED), 1.0/gamma),
251 +                                        pow(colval(scanln[x],GRN), 1.0/gamma),
252 +                                        pow(colval(scanln[x],BLU), 1.0/gamma));
253                          if (!dataonly)
254                                  printf("%7d %7d ", x, y);
255                          if ((*putval)(scanln[x], stdout) < 0) {
# Line 215 | Line 264 | pixtoval()                             /* convert picture to values */
264  
265   valtopix()                      /* convert values to a pixel file */
266   {
267 <        COLOR  *scanln;
267 >        int  dogamma;
268 >        register COLOR  *scanln;
269          int  y;
270          register int  x;
271  
# Line 224 | Line 274 | valtopix()                     /* convert values to a pixel file */
274                  fprintf(stderr, "%s: out of memory\n", progname);
275                  quit(1);
276          }
277 +        dogamma = gamma < .95 || gamma > 1.05;
278          for (y = yres-1; y >= 0; y--) {
279                  for (x = 0; x < xres; x++) {
280                          if (!dataonly)
# Line 232 | Line 283 | valtopix()                     /* convert values to a pixel file */
283                                  fprintf(stderr, "%s: read error\n", progname);
284                                  quit(1);
285                          }
286 +                        if (dogamma)
287 +                                setcolor(scanln[x],
288 +                                        pow(colval(scanln[x],RED), gamma),
289 +                                        pow(colval(scanln[x],GRN), gamma),
290 +                                        pow(colval(scanln[x],BLU), gamma));
291                  }
292 <                if (fwritescan(scanln, xres, stdout) < 0
237 <                                || fflush(stdout) < 0) {
292 >                if (fwritescan(scanln, xres, stdout) < 0) {
293                          fprintf(stderr, "%s: write error\n", progname);
294                          quit(1);
295                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines