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.6 by greg, Fri Apr 19 09:00:55 1991 UTC vs.
Revision 2.3 by greg, Fri May 8 10:58:52 1992 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 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  gamcor = 1.0;           /* gamma correction */
43 +
44   COLOR  exposure = WHTCOLOR;
45  
46   char  *progname;
# Line 49 | Line 54 | main(argc, argv)
54   int  argc;
55   char  **argv;
56   {
52        extern double  atof();
57          extern int  checkhead();
58          int  i;
59  
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 +                                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 86 | 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 102 | 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 139 | Line 162 | unkopt:
162          set_io();
163  
164          if (reverse) {
142                if (yres <= 0 || xres <= 0) {
143                        fprintf(stderr, "%s: missing x and y resolution\n",
144                                        progname);
145                        quit(1);
146                }
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 163 | 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,
170 <                                "%s: missing x and y resolution\n",
171 <                                                progname);
172 <                                quit(1);
173 <                        }
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 198 | Line 220 | char  *line;
220                  scalecolor(exposure, d);
221          } else if (original && iscolcor(line)) {
222                  colcorval(ctmp, line);
223 <                colval(exposure,RED) /= colval(ctmp,RED);
224 <                colval(exposure,GRN) /= colval(ctmp,GRN);
225 <                colval(exposure,BLU) /= colval(ctmp,BLU);
223 >                setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED),
224 >                                colval(exposure,GRN)/colval(ctmp,GRN),
225 >                                colval(exposure,BLU)/colval(ctmp,BLU));
226          } else if (header)
227                  fputs(line, stdout);
228   }
# Line 208 | Line 230 | char  *line;
230  
231   pixtoval()                              /* convert picture to values */
232   {
233 <        COLOR  *scanln;
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 = 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 (    scanln[x][RED] == lastc[RED] &&
255 <                                        scanln[x][GRN] == lastc[GRN] &&
256 <                                        scanln[x][BLU] == lastc[BLU]    )
254 >                                if (    colval(scanln[x],RED) ==
255 >                                                colval(lastc,RED) &&
256 >                                        colval(scanln[x],GRN) ==
257 >                                                colval(lastc,GRN) &&
258 >                                        colval(scanln[x],BLU) ==
259 >                                                colval(lastc,BLU)       )
260                                          continue;
261                                  else
262                                          copycolor(lastc, scanln[x]);
263                          if (original)
264                                  multcolor(scanln[x], exposure);
265 <                        if (!dataonly)
266 <                                printf("%7d %7d ", x, y);
265 >                        if (dogamma)
266 >                                setcolor(scanln[x],
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 248 | Line 284 | pixtoval()                             /* convert picture to values */
284  
285   valtopix()                      /* convert values to a pixel file */
286   {
287 <        COLOR  *scanln;
287 >        int  dogamma;
288 >        register COLOR  *scanln;
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 <        for (y = yres-1; y >= 0; y--) {
298 <                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) {
303                                  fprintf(stderr, "%s: read error\n", progname);
304                                  quit(1);
305                          }
306 +                        if (dogamma)
307 +                                setcolor(scanln[x],
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
270 <                                || fflush(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