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.7 by greg, Fri May 10 08:51:53 1991 UTC vs.
Revision 2.3 by greg, Fri May 8 10:58:52 1992 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10   *     4/23/86
11   */
12  
13 < #include  <stdio.h>
13 > #include  "standard.h"
14  
15   #include  "color.h"
16  
17 + #include  "resolu.h"
18 +
19   #define  min(a,b)               ((a)<(b)?(a):(b))
20  
21 < int  xres = 0;                  /* resolution of input */
20 < int  yres = 0;
21 > RESOLU  picres;                 /* resolution of picture */
22  
23   int  uniq = 0;                  /* print only unique values? */
24  
# Line 32 | Line 33 | int  reverse = 0;              /* reverse conversion? */
33   int  format = 'a';              /* input/output format */
34   char  *fmtid = "ascii";         /* format identifier for header */
35  
36 < int  header = 1;                /* do header */
36 > int  header = 1;                /* do header? */
37  
38 + int  resolution = 1;            /* put/get resolution string? */
39 +
40   int  wrongformat = 0;           /* wrong input format? */
41  
42 < double  gamma = 1.0;            /* gamma correction */
42 > double  gamcor = 1.0;           /* gamma correction */
43  
44   COLOR  exposure = WHTCOLOR;
45  
# Line 44 | Line 47 | char  *progname;
47  
48   FILE  *fin;
49  
47 extern double  atof(), pow();
48
50   int  (*getval)(), (*putval)();
51  
52  
# Line 59 | Line 60 | char  **argv;
60          progname = argv[0];
61  
62          for (i = 1; i < argc; i++)
63 <                if (argv[i][0] == '-')
63 >                if (argv[i][0] == '-' || argv[i][0] == '+')
64                          switch (argv[i][1]) {
65 <                        case 'h':               /* no header */
66 <                                header = 0;
65 >                        case 'h':               /* header */
66 >                                header = argv[i][0] == '+';
67                                  break;
68 +                        case 'H':               /* resolution string */
69 +                                resolution = argv[i][0] == '+';
70 +                                break;
71                          case 'u':               /* unique values */
72 <                                uniq = 1;
72 >                                uniq = argv[i][0] == '-';
73                                  break;
74                          case 'o':               /* original values */
75 <                                original = 1;
75 >                                original = argv[i][0] == '-';
76                                  break;
77                          case 'g':               /* gamma correction */
78 <                                gamma = atof(argv[++i]);
78 >                                gamcor = atof(argv[++i]);
79 >                                if (argv[i][0] == '+')
80 >                                        gamcor = 1.0/gamcor;
81                                  break;
82                          case 'r':               /* reverse conversion */
83 <                                reverse = 1;
83 >                                reverse = argv[i][0] == '-';
84                                  break;
85                          case 'b':               /* brightness values */
86 <                                brightonly = 1;
86 >                                brightonly = argv[i][0] == '-';
87                                  break;
88                          case 'd':               /* data only (no indices) */
89 <                                dataonly = 1;
89 >                                dataonly = argv[i][0] == '-';
90                                  switch (argv[i][2]) {
91                                  case '\0':
92                                  case 'a':               /* ascii */
# Line 92 | Line 98 | char  **argv;
98                                          fmtid = "ascii";
99                                          break;
100                                  case 'b':               /* byte */
101 +                                        dataonly = 1;
102                                          format = 'b';
103                                          fmtid = "byte";
104                                          break;
105                                  case 'f':               /* float */
106 +                                        dataonly = 1;
107                                          format = 'f';
108                                          fmtid = "float";
109                                          break;
110                                  case 'd':               /* double */
111 +                                        dataonly = 1;
112                                          format = 'd';
113                                          fmtid = "double";
114                                          break;
# Line 108 | Line 117 | char  **argv;
117                                  }
118                                  break;
119                          case 'x':               /* x resolution */
120 <                                xres = atoi(argv[++i]);
120 >                                resolution = 0;
121 >                                if (argv[i][0] == '-')
122 >                                        picres.or |= XDECR;
123 >                                picres.xr = atoi(argv[++i]);
124                                  break;
125                          case 'y':               /* y resolution */
126 <                                yres = atoi(argv[++i]);
126 >                                resolution = 0;
127 >                                if (argv[i][0] == '-')
128 >                                        picres.or |= YDECR;
129 >                                if (picres.xr == 0)
130 >                                        picres.or |= YMAJOR;
131 >                                picres.yr = atoi(argv[++i]);
132                                  break;
133                          default:
134   unkopt:
# Line 145 | Line 162 | unkopt:
162          set_io();
163  
164          if (reverse) {
148                if (yres <= 0 || xres <= 0) {
149                        fprintf(stderr, "%s: missing x and y resolution\n",
150                                        progname);
151                        quit(1);
152                }
165                                          /* get header */
166                  if (header && checkheader(fin, fmtid, stdout) < 0) {
167                          fprintf(stderr, "%s: wrong input format\n", progname);
168                          quit(1);
169                  }
170 +                                        /* get resolution */
171 +                if ((resolution && !fgetsresolu(&picres, fin)) ||
172 +                                picres.xr <= 0 || picres.yr <= 0) {
173 +                        fprintf(stderr, "%s: missing resolution\n", progname);
174 +                        quit(1);
175 +                }
176                                                  /* add to header */
177                  printargs(i, argv, stdout);
178                  fputformat(COLRFMT, stdout);
179 <                printf("\n");
180 <                fputresolu(YMAJOR|YDECR, xres, yres, stdout);
179 >                putchar('\n');
180 >                fputsresolu(&picres, stdout);   /* always put resolution */
181                  valtopix();
182          } else {
183                                                  /* get header */
# Line 169 | Line 187 | unkopt:
187                                          progname);
188                          quit(1);
189                  }
190 <
191 <                if (xres <= 0 || yres <= 0)             /* get picture size */
192 <                        if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) {
193 <                                fprintf(stderr,
176 <                                "%s: missing x and y resolution\n",
177 <                                                progname);
178 <                                quit(1);
179 <                        }
190 >                if (!fgetsresolu(&picres, fin)) {
191 >                        fprintf(stderr, "%s: missing resolution\n", progname);
192 >                        quit(1);
193 >                }
194                  if (header) {
195                          printargs(i, argv, stdout);
196                          fputformat(fmtid, stdout);
197 <                        printf("\n");
197 >                        putchar('\n');
198                  }
199 +                if (resolution)                 /* put resolution */
200 +                        fputsresolu(&picres, stdout);
201                  pixtoval();
202          }
203  
# Line 217 | Line 233 | pixtoval()                             /* convert picture to values */
233          register COLOR  *scanln;
234          int  dogamma;
235          COLOR  lastc;
236 +        FLOAT  hv[2];
237          int  y;
238          register int  x;
239  
240 <        scanln = (COLOR *)malloc(xres*sizeof(COLOR));
240 >        scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
241          if (scanln == NULL) {
242                  fprintf(stderr, "%s: out of memory\n", progname);
243                  quit(1);
244          }
245 <        dogamma = gamma < .95 || gamma > 1.05;
245 >        dogamma = gamcor < .95 || gamcor > 1.05;
246          setcolor(lastc, 0.0, 0.0, 0.0);
247 <        for (y = yres-1; y >= 0; y--) {
248 <                if (freadscan(scanln, xres, fin) < 0) {
247 >        for (y = 0; y < numscans(&picres); y++) {
248 >                if (freadscan(scanln, scanlen(&picres), fin) < 0) {
249                          fprintf(stderr, "%s: read error\n", progname);
250                          quit(1);
251                  }
252 <                for (x = 0; x < xres; x++) {
252 >                for (x = 0; x < scanlen(&picres); x++) {
253                          if (uniq)
254                                  if (    colval(scanln[x],RED) ==
255                                                  colval(lastc,RED) &&
# Line 247 | Line 264 | pixtoval()                             /* convert picture to values */
264                                  multcolor(scanln[x], exposure);
265                          if (dogamma)
266                                  setcolor(scanln[x],
267 <                                        pow(colval(scanln[x],RED), 1.0/gamma),
268 <                                        pow(colval(scanln[x],GRN), 1.0/gamma),
269 <                                        pow(colval(scanln[x],BLU), 1.0/gamma));
270 <                        if (!dataonly)
271 <                                printf("%7d %7d ", x, y);
267 >                                pow(colval(scanln[x],RED), 1.0/gamcor),
268 >                                pow(colval(scanln[x],GRN), 1.0/gamcor),
269 >                                pow(colval(scanln[x],BLU), 1.0/gamcor));
270 >                        if (!dataonly) {
271 >                                pix2loc(hv, &picres, x, y);
272 >                                printf("%7d %7d ", (int)(hv[0]*picres.xr),
273 >                                                (int)(hv[1]*picres.yr));
274 >                        }
275                          if ((*putval)(scanln[x], stdout) < 0) {
276                                  fprintf(stderr, "%s: write error\n", progname);
277                                  quit(1);
# Line 269 | Line 289 | valtopix()                     /* convert values to a pixel file */
289          int  y;
290          register int  x;
291  
292 <        scanln = (COLOR *)malloc(xres*sizeof(COLOR));
292 >        scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
293          if (scanln == NULL) {
294                  fprintf(stderr, "%s: out of memory\n", progname);
295                  quit(1);
296          }
297 <        dogamma = gamma < .95 || gamma > 1.05;
298 <        for (y = yres-1; y >= 0; y--) {
299 <                for (x = 0; x < xres; x++) {
297 >        dogamma = gamcor < .95 || gamcor > 1.05;
298 >        for (y = 0; y < numscans(&picres); y++) {
299 >                for (x = 0; x < scanlen(&picres); x++) {
300                          if (!dataonly)
301                                  fscanf(fin, "%*d %*d");
302                          if ((*getval)(scanln[x], fin) < 0) {
# Line 285 | Line 305 | valtopix()                     /* convert values to a pixel file */
305                          }
306                          if (dogamma)
307                                  setcolor(scanln[x],
308 <                                        pow(colval(scanln[x],RED), gamma),
309 <                                        pow(colval(scanln[x],GRN), gamma),
310 <                                        pow(colval(scanln[x],BLU), gamma));
308 >                                        pow(colval(scanln[x],RED), gamcor),
309 >                                        pow(colval(scanln[x],GRN), gamcor),
310 >                                        pow(colval(scanln[x],BLU), gamcor));
311                  }
312 <                if (fwritescan(scanln, xres, stdout) < 0) {
312 >                if (fwritescan(scanln, scanlen(&picres), stdout) < 0) {
313                          fprintf(stderr, "%s: write error\n", progname);
314                          quit(1);
315                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines