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.2 by greg, Thu Dec 19 14:52:04 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 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 36 | Line 37 | int  header = 1;               /* do header */
37  
38   int  wrongformat = 0;           /* wrong input format? */
39  
40 + double  gamcor = 1.0;           /* gamma correction */
41 +
42   COLOR  exposure = WHTCOLOR;
43  
44   char  *progname;
# Line 49 | Line 52 | main(argc, argv)
52   int  argc;
53   char  **argv;
54   {
52        extern double  atof();
55          extern int  checkhead();
56          int  i;
57  
58          progname = argv[0];
59  
60          for (i = 1; i < argc; i++)
61 <                if (argv[i][0] == '-')
61 >                if (argv[i][0] == '-' || argv[i][0] == '+')
62                          switch (argv[i][1]) {
63 <                        case 'h':               /* no header */
64 <                                header = 0;
63 >                        case 'h':               /* header */
64 >                                header = argv[i][0] == '+';
65                                  break;
66                          case 'u':               /* unique values */
67 <                                uniq = 1;
67 >                                uniq = argv[i][0] == '-';
68                                  break;
69                          case 'o':               /* original values */
70 <                                original = 1;
70 >                                original = argv[i][0] == '-';
71                                  break;
72 +                        case 'g':               /* gamma correction */
73 +                                gamcor = atof(argv[++i]);
74 +                                if (argv[i][0] == '+')
75 +                                        gamcor = 1.0/gamcor;
76 +                                break;
77                          case 'r':               /* reverse conversion */
78 <                                reverse = 1;
78 >                                reverse = argv[i][0] == '-';
79                                  break;
80                          case 'b':               /* brightness values */
81 <                                brightonly = 1;
81 >                                brightonly = argv[i][0] == '-';
82                                  break;
83                          case 'd':               /* data only (no indices) */
84 <                                dataonly = 1;
84 >                                dataonly = argv[i][0] == '-';
85                                  switch (argv[i][2]) {
86                                  case '\0':
87                                  case 'a':               /* ascii */
# Line 86 | Line 93 | char  **argv;
93                                          fmtid = "ascii";
94                                          break;
95                                  case 'b':               /* byte */
96 +                                        dataonly = 1;
97                                          format = 'b';
98                                          fmtid = "byte";
99                                          break;
100                                  case 'f':               /* float */
101 +                                        dataonly = 1;
102                                          format = 'f';
103                                          fmtid = "float";
104                                          break;
105                                  case 'd':               /* double */
106 +                                        dataonly = 1;
107                                          format = 'd';
108                                          fmtid = "double";
109                                          break;
# Line 102 | Line 112 | char  **argv;
112                                  }
113                                  break;
114                          case 'x':               /* x resolution */
115 <                                xres = atoi(argv[++i]);
115 >                                if (argv[i][0] == '-')
116 >                                        picres.or |= XDECR;
117 >                                picres.xr = atoi(argv[++i]);
118                                  break;
119                          case 'y':               /* y resolution */
120 <                                yres = atoi(argv[++i]);
120 >                                if (argv[i][0] == '-')
121 >                                        picres.or |= YDECR;
122 >                                if (picres.xr == 0)
123 >                                        picres.or |= YMAJOR;
124 >                                picres.yr = atoi(argv[++i]);
125                                  break;
126                          default:
127   unkopt:
# Line 139 | Line 155 | unkopt:
155          set_io();
156  
157          if (reverse) {
142                if (yres <= 0 || xres <= 0) {
143                        fprintf(stderr, "%s: missing x and y resolution\n",
144                                        progname);
145                        quit(1);
146                }
158                                          /* get header */
159                  if (header && checkheader(fin, fmtid, stdout) < 0) {
160                          fprintf(stderr, "%s: wrong input format\n", progname);
161                          quit(1);
162                  }
163 +                if (picres.xr <= 0 || picres.yr <= 0)   /* get resolution */
164 +                        if (!fgetsresolu(&picres, fin)) {
165 +                                fprintf(stderr, "%s: missing resolution\n",
166 +                                                progname);
167 +                                quit(1);
168 +                        }
169                                                  /* add to header */
170                  printargs(i, argv, stdout);
171                  fputformat(COLRFMT, stdout);
172 <                printf("\n");
173 <                fputresolu(YMAJOR|YDECR, xres, yres, stdout);
172 >                putchar('\n');
173 >                fputsresolu(&picres, stdout);
174                  valtopix();
175          } else {
176                                                  /* get header */
# Line 164 | Line 181 | unkopt:
181                          quit(1);
182                  }
183  
184 <                if (xres <= 0 || yres <= 0)             /* get picture size */
185 <                        if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) {
186 <                                fprintf(stderr,
170 <                                "%s: missing x and y resolution\n",
184 >                if (picres.xr <= 0 || picres.yr <= 0)   /* get picture size */
185 >                        if (!fgetsresolu(&picres, fin)) {
186 >                                fprintf(stderr, "%s: missing resolution\n",
187                                                  progname);
188                                  quit(1);
189                          }
190                  if (header) {
191                          printargs(i, argv, stdout);
192                          fputformat(fmtid, stdout);
193 <                        printf("\n");
193 >                        putchar('\n');
194                  }
195                  pixtoval();
196          }
# Line 198 | Line 214 | char  *line;
214                  scalecolor(exposure, d);
215          } else if (original && iscolcor(line)) {
216                  colcorval(ctmp, line);
217 <                colval(exposure,RED) /= colval(ctmp,RED);
218 <                colval(exposure,GRN) /= colval(ctmp,GRN);
219 <                colval(exposure,BLU) /= colval(ctmp,BLU);
217 >                setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED),
218 >                                colval(exposure,GRN)/colval(ctmp,GRN),
219 >                                colval(exposure,BLU)/colval(ctmp,BLU));
220          } else if (header)
221                  fputs(line, stdout);
222   }
# Line 208 | Line 224 | char  *line;
224  
225   pixtoval()                              /* convert picture to values */
226   {
227 <        COLOR  *scanln;
227 >        register COLOR  *scanln;
228 >        int  dogamma;
229          COLOR  lastc;
230 +        FLOAT  hv[2];
231          int  y;
232          register int  x;
233  
234 <        scanln = (COLOR *)malloc(xres*sizeof(COLOR));
234 >        scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
235          if (scanln == NULL) {
236                  fprintf(stderr, "%s: out of memory\n", progname);
237                  quit(1);
238          }
239 +        dogamma = gamcor < .95 || gamcor > 1.05;
240          setcolor(lastc, 0.0, 0.0, 0.0);
241 <        for (y = yres-1; y >= 0; y--) {
242 <                if (freadscan(scanln, xres, fin) < 0) {
241 >        for (y = 0; y < numscans(&picres); y++) {
242 >                if (freadscan(scanln, scanlen(&picres), fin) < 0) {
243                          fprintf(stderr, "%s: read error\n", progname);
244                          quit(1);
245                  }
246 <                for (x = 0; x < xres; x++) {
246 >                for (x = 0; x < scanlen(&picres); x++) {
247                          if (uniq)
248 <                                if (    scanln[x][RED] == lastc[RED] &&
249 <                                        scanln[x][GRN] == lastc[GRN] &&
250 <                                        scanln[x][BLU] == lastc[BLU]    )
248 >                                if (    colval(scanln[x],RED) ==
249 >                                                colval(lastc,RED) &&
250 >                                        colval(scanln[x],GRN) ==
251 >                                                colval(lastc,GRN) &&
252 >                                        colval(scanln[x],BLU) ==
253 >                                                colval(lastc,BLU)       )
254                                          continue;
255                                  else
256                                          copycolor(lastc, scanln[x]);
257                          if (original)
258                                  multcolor(scanln[x], exposure);
259 <                        if (!dataonly)
260 <                                printf("%7d %7d ", x, y);
259 >                        if (dogamma)
260 >                                setcolor(scanln[x],
261 >                                pow(colval(scanln[x],RED), 1.0/gamcor),
262 >                                pow(colval(scanln[x],GRN), 1.0/gamcor),
263 >                                pow(colval(scanln[x],BLU), 1.0/gamcor));
264 >                        if (!dataonly) {
265 >                                pix2loc(hv, &picres, x, y);
266 >                                printf("%7d %7d ", (int)(hv[0]*picres.xr),
267 >                                                (int)(hv[1]*picres.yr));
268 >                        }
269                          if ((*putval)(scanln[x], stdout) < 0) {
270                                  fprintf(stderr, "%s: write error\n", progname);
271                                  quit(1);
# Line 248 | Line 278 | pixtoval()                             /* convert picture to values */
278  
279   valtopix()                      /* convert values to a pixel file */
280   {
281 <        COLOR  *scanln;
281 >        int  dogamma;
282 >        register COLOR  *scanln;
283          int  y;
284          register int  x;
285  
286 <        scanln = (COLOR *)malloc(xres*sizeof(COLOR));
286 >        scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
287          if (scanln == NULL) {
288                  fprintf(stderr, "%s: out of memory\n", progname);
289                  quit(1);
290          }
291 <        for (y = yres-1; y >= 0; y--) {
292 <                for (x = 0; x < xres; x++) {
291 >        dogamma = gamcor < .95 || gamcor > 1.05;
292 >        for (y = 0; y < numscans(&picres); y++) {
293 >                for (x = 0; x < scanlen(&picres); x++) {
294                          if (!dataonly)
295                                  fscanf(fin, "%*d %*d");
296                          if ((*getval)(scanln[x], fin) < 0) {
297                                  fprintf(stderr, "%s: read error\n", progname);
298                                  quit(1);
299                          }
300 +                        if (dogamma)
301 +                                setcolor(scanln[x],
302 +                                        pow(colval(scanln[x],RED), gamcor),
303 +                                        pow(colval(scanln[x],GRN), gamcor),
304 +                                        pow(colval(scanln[x],BLU), gamcor));
305                  }
306 <                if (fwritescan(scanln, xres, stdout) < 0
270 <                                || fflush(stdout) < 0) {
306 >                if (fwritescan(scanln, scanlen(&picres), stdout) < 0) {
307                          fprintf(stderr, "%s: write error\n", progname);
308                          quit(1);
309                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines