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 2.11 by greg, Wed Jan 8 08:00:23 1997 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1992 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 < #define  min(a,b)               ((a)<(b)?(a):(b))
17 > #include  "resolu.h"
18  
19 < int  xres = 0;                  /* resolution of input */
20 < int  yres = 0;
19 > #define  min(a,b)               ((a)<(b)?(a):(b))
20  
21 < int  uniq = 0;                  /* unique values? */
21 >                                /* what to put out (also RED, GRN, BLU) */
22 > #define  ALL            3
23 > #define  BRIGHT         4
24  
25 < int  original = 0;              /* original values? */
25 > #define  brightonly     (putprim==BRIGHT)
26  
27 + RESOLU  picres;                 /* resolution of picture */
28 +
29 + int  uniq = 0;                  /* print only unique values? */
30 +
31 + int  doexposure = 0;            /* exposure change? (>100 to print) */
32 +
33   int  dataonly = 0;              /* data only format? */
34  
35 < int  brightonly = 0;            /* only brightness values? */
35 > int  putprim = ALL;             /* what to put out */
36  
37   int  reverse = 0;               /* reverse conversion? */
38  
39   int  format = 'a';              /* input/output format */
40 + char  *fmtid = "ascii";         /* format identifier for header */
41  
42 < int  header = 1;                /* do header */
42 > int  header = 1;                /* do header? */
43  
44 < double  exposure = 1.0;
44 > long  skipbytes = 0;            /* skip bytes in input? */
45  
46 + int  resolution = 1;            /* put/get resolution string? */
47 +
48 + int  original = 0;              /* convert to original values? */
49 +
50 + int  wrongformat = 0;           /* wrong input format? */
51 +
52 + double  gamcor = 1.0;           /* gamma correction */
53 +
54 + int  ord[3] = {RED, GRN, BLU};  /* RGB ordering */
55 + int  rord[4];                   /* reverse ordering */
56 +
57 + COLOR  exposure = WHTCOLOR;
58 +
59   char  *progname;
60  
61   FILE  *fin;
62 + FILE  *fin2 = NULL, *fin3 = NULL;       /* for other color channels */
63  
64   int  (*getval)(), (*putval)();
65  
# Line 46 | Line 68 | main(argc, argv)
68   int  argc;
69   char  **argv;
70   {
49        extern double  atof();
71          extern int  checkhead();
72 +        extern long  atol();
73 +        double  d, expval = 1.0;
74          int  i;
75  
76          progname = argv[0];
77  
78          for (i = 1; i < argc; i++)
79 <                if (argv[i][0] == '-')
79 >                if (argv[i][0] == '-' || argv[i][0] == '+')
80                          switch (argv[i][1]) {
81 <                        case 'h':               /* no header */
82 <                                header = 0;
81 >                        case 'h':               /* header */
82 >                                header = argv[i][0] == '+';
83                                  break;
84 +                        case 'H':               /* resolution string */
85 +                                resolution = argv[i][0] == '+';
86 +                                break;
87 +                        case 's':               /* skip bytes in header */
88 +                                skipbytes = atol(argv[++i]);
89 +                                break;
90                          case 'u':               /* unique values */
91 <                                uniq = 1;
91 >                                uniq = argv[i][0] == '-';
92                                  break;
93                          case 'o':               /* original values */
94 <                                original = 1;
94 >                                original = argv[i][0] == '-';
95                                  break;
96 +                        case 'g':               /* gamma correction */
97 +                                gamcor = atof(argv[i+1]);
98 +                                if (argv[i][0] == '+')
99 +                                        gamcor = 1.0/gamcor;
100 +                                i++;
101 +                                break;
102 +                        case 'e':               /* exposure correction */
103 +                                d = atof(argv[i+1]);
104 +                                if (argv[i+1][0] == '-' || argv[i+1][0] == '+')
105 +                                        d = pow(2.0, d);
106 +                                if (argv[i][0] == '-')
107 +                                        expval *= d;
108 +                                scalecolor(exposure, d);
109 +                                doexposure++;
110 +                                i++;
111 +                                break;
112 +                        case 'R':               /* reverse byte sequence */
113 +                                if (argv[i][0] == '-') {
114 +                                        ord[0]=BLU; ord[1]=GRN; ord[2]=RED;
115 +                                } else {
116 +                                        ord[0]=RED; ord[1]=GRN; ord[2]=BLU;
117 +                                }
118 +                                break;
119                          case 'r':               /* reverse conversion */
120 <                                reverse = 1;
120 >                                reverse = argv[i][0] == '-';
121                                  break;
122                          case 'b':               /* brightness values */
123 <                                brightonly = 1;
123 >                                putprim = argv[i][0] == '-' ? BRIGHT : ALL;
124                                  break;
125 +                        case 'p':               /* put primary */
126 +                                switch (argv[i][2]) {
127 +                                case 'r': case 'R': putprim = RED; break;
128 +                                case 'g': case 'G': putprim = GRN; break;
129 +                                case 'b': case 'B': putprim = BLU; break;
130 +                                default: goto unkopt;
131 +                                }
132 +                                break;
133                          case 'd':               /* data only (no indices) */
134 <                                dataonly = 1;
134 >                                dataonly = argv[i][0] == '-';
135                                  switch (argv[i][2]) {
136                                  case '\0':
137                                  case 'a':               /* ascii */
138                                          format = 'a';
139 +                                        fmtid = "ascii";
140                                          break;
141                                  case 'i':               /* integer */
142 +                                        format = 'i';
143 +                                        fmtid = "ascii";
144 +                                        break;
145                                  case 'b':               /* byte */
146 +                                        dataonly = 1;
147 +                                        format = 'b';
148 +                                        fmtid = "byte";
149 +                                        break;
150                                  case 'f':               /* float */
151 +                                        dataonly = 1;
152 +                                        format = 'f';
153 +                                        fmtid = "float";
154 +                                        break;
155                                  case 'd':               /* double */
156 <                                        format = argv[i][2];
156 >                                        dataonly = 1;
157 >                                        format = 'd';
158 >                                        fmtid = "double";
159                                          break;
160                                  default:
161                                          goto unkopt;
162                                  }
163                                  break;
164                          case 'x':               /* x resolution */
165 <                                xres = atoi(argv[++i]);
165 >                        case 'X':               /* x resolution */
166 >                                resolution = 0;
167 >                                if (argv[i][0] == '-')
168 >                                        picres.or |= XDECR;
169 >                                picres.xr = atoi(argv[++i]);
170                                  break;
171                          case 'y':               /* y resolution */
172 <                                yres = atoi(argv[++i]);
172 >                        case 'Y':               /* y resolution */
173 >                                resolution = 0;
174 >                                if (argv[i][0] == '-')
175 >                                        picres.or |= YDECR;
176 >                                if (picres.xr == 0)
177 >                                        picres.or |= YMAJOR;
178 >                                picres.yr = atoi(argv[++i]);
179                                  break;
180                          default:
181   unkopt:
# Line 102 | Line 186 | unkopt:
186                          }
187                  else
188                          break;
189 <                        
189 >                                        /* recognize special formats */
190 >        if (dataonly && format == 'b')
191 >                if (brightonly)
192 >                        fmtid = "8-bit_grey";
193 >                else
194 >                        fmtid = "24-bit_rgb";
195 >                                        /* assign reverse ordering */
196 >        rord[ord[0]] = 0;
197 >        rord[ord[1]] = 1;
198 >        rord[ord[2]] = 2;
199 >                                        /* get input */
200          if (i == argc) {
201                  fin = stdin;
202 <        } else if (i == argc-1) {
202 >        } else if (i < argc) {
203                  if ((fin = fopen(argv[i], "r")) == NULL) {
204                          fprintf(stderr, "%s: can't open file \"%s\"\n",
205                                                  progname, argv[i]);
206                          quit(1);
207                  }
208 <        } else {
208 >                if (skipbytes && fseek(fin, skipbytes, 0))
209 >                        goto seekerr;
210 >                if (reverse && !brightonly && i == argc-3) {
211 >                        if ((fin2 = fopen(argv[i+1], "r")) == NULL) {
212 >                                fprintf(stderr, "%s: can't open file \"%s\"\n",
213 >                                                progname, argv[i+1]);
214 >                                quit(1);
215 >                        }
216 >                        if ((fin3 = fopen(argv[i+2], "r")) == NULL) {
217 >                                fprintf(stderr, "%s: can't open file \"%s\"\n",
218 >                                                progname, argv[i+2]);
219 >                                quit(1);
220 >                        }
221 >                        if (skipbytes && (fseek(fin2, skipbytes, 0) ||
222 >                                        fseek(fin3, skipbytes, 0)))
223 >                                goto seekerr;
224 >                } else if (i != argc-1)
225 >                        fin = NULL;
226 >        }
227 >        if (fin == NULL) {
228                  fprintf(stderr, "%s: bad # file arguments\n", progname);
229                  quit(1);
230          }
# Line 119 | Line 232 | unkopt:
232          set_io();
233  
234          if (reverse) {
235 <                if (header)                     /* get header */
236 <                        copyheader(fin, stdout);
237 <                                                /* add to header */
238 <                printargs(i, argv, stdout);
239 <                printf("\n");
240 <                if (yres <= 0 || xres <= 0) {
241 <                        fprintf(stderr, "%s: missing x and y resolution\n",
242 <                                        progname);
235 > #ifdef MSDOS
236 >                setmode(fileno(stdout), O_BINARY);
237 >                if (format != 'a' && format != 'i')
238 >                        setmode(fileno(fin), O_BINARY);
239 > #endif
240 >                                        /* get header */
241 >                if (header) {
242 >                        if (checkheader(fin, fmtid, stdout) < 0) {
243 >                                fprintf(stderr, "%s: wrong input format\n",
244 >                                                progname);
245 >                                quit(1);
246 >                        }
247 >                        if (fin2 != NULL) {
248 >                                getheader(fin2, NULL, NULL);
249 >                                getheader(fin3, NULL, NULL);
250 >                        }
251 >                } else
252 >                        newheader("RADIANCE", stdout);
253 >                                        /* get resolution */
254 >                if ((resolution && !fgetsresolu(&picres, fin)) ||
255 >                                picres.xr <= 0 || picres.yr <= 0) {
256 >                        fprintf(stderr, "%s: missing resolution\n", progname);
257                          quit(1);
258                  }
259 <                fputresolu(YMAJOR|YDECR, xres, yres, stdout);
260 <                valtopix();
261 <        } else {
262 <                                                /* get header */
263 <                getheader(fin, checkhead);
264 <
265 <                if (xres <= 0 || yres <= 0)             /* get picture size */
266 <                        if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) {
267 <                                fprintf(stderr,
268 <                                "%s: missing x and y resolution\n",
259 >                if (resolution && fin2 != NULL) {
260 >                        RESOLU  pres2;
261 >                        if (!fgetsresolu(&pres2, fin2) ||
262 >                                        pres2.or != picres.or ||
263 >                                        pres2.xr != picres.xr ||
264 >                                        pres2.yr != picres.yr ||
265 >                                        !fgetsresolu(&pres2, fin3) ||
266 >                                        pres2.or != picres.or ||
267 >                                        pres2.xr != picres.xr ||
268 >                                        pres2.yr != picres.yr) {
269 >                                fprintf(stderr, "%s: resolution mismatch\n",
270                                                  progname);
271                                  quit(1);
272                          }
273 +                }
274 +                                                /* add to header */
275 +                printargs(i, argv, stdout);
276 +                if (expval < .99 || expval > 1.01)
277 +                        fputexpos(expval, stdout);
278 +                fputformat(COLRFMT, stdout);
279 +                putchar('\n');
280 +                fputsresolu(&picres, stdout);   /* always put resolution */
281 +                valtopix();
282 +        } else {
283 + #ifdef MSDOS
284 +                setmode(fileno(fin), O_BINARY);
285 +                if (format != 'a' && format != 'i')
286 +                        setmode(fileno(stdout), O_BINARY);
287 + #endif
288 +                                                /* get header */
289 +                getheader(fin, checkhead, NULL);
290 +                if (wrongformat) {
291 +                        fprintf(stderr, "%s: input not a Radiance picture\n",
292 +                                        progname);
293 +                        quit(1);
294 +                }
295 +                if (!fgetsresolu(&picres, fin)) {
296 +                        fprintf(stderr, "%s: missing resolution\n", progname);
297 +                        quit(1);
298 +                }
299                  if (header) {
300                          printargs(i, argv, stdout);
301 <                        printf("\n");
301 >                        if (expval < .99 || expval > 1.01)
302 >                                fputexpos(expval, stdout);
303 >                        fputformat(fmtid, stdout);
304 >                        putchar('\n');
305                  }
306 +                if (resolution)                 /* put resolution */
307 +                        fputsresolu(&picres, stdout);
308                  pixtoval();
309          }
310  
311          quit(0);
312 + seekerr:
313 +        fprintf(stderr, "%s: cannot skip %ld bytes on input\n",
314 +                        progname, skipbytes);
315 +        quit(1);
316   }
317  
318  
319   checkhead(line)                         /* deal with line from header */
320   char  *line;
321   {
322 <        if (header)
322 >        char    fmt[32];
323 >        double  d;
324 >        COLOR   ctmp;
325 >
326 >        if (formatval(fmt, line))
327 >                wrongformat = strcmp(fmt, COLRFMT);
328 >        else if (original && isexpos(line)) {
329 >                d = 1.0/exposval(line);
330 >                scalecolor(exposure, d);
331 >                doexposure++;
332 >        } else if (original && iscolcor(line)) {
333 >                colcorval(ctmp, line);
334 >                setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED),
335 >                                colval(exposure,GRN)/colval(ctmp,GRN),
336 >                                colval(exposure,BLU)/colval(ctmp,BLU));
337 >                doexposure++;
338 >        } else if (header)
339                  fputs(line, stdout);
161        if (!strncmp(line, "EXPOSURE=", 9))
162                exposure *= atof(line+9);
340   }
341  
342  
343   pixtoval()                              /* convert picture to values */
344   {
345 <        COLOR  *scanln;
345 >        register COLOR  *scanln;
346 >        int  dogamma;
347          COLOR  lastc;
348 +        FLOAT  hv[2];
349          int  y;
350          register int  x;
351  
352 <        scanln = (COLOR *)malloc(xres*sizeof(COLOR));
352 >        scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
353          if (scanln == NULL) {
354                  fprintf(stderr, "%s: out of memory\n", progname);
355                  quit(1);
356          }
357 +        dogamma = gamcor < .95 || gamcor > 1.05;
358          setcolor(lastc, 0.0, 0.0, 0.0);
359 <        for (y = yres-1; y >= 0; y--) {
360 <                if (freadscan(scanln, xres, fin) < 0) {
359 >        for (y = 0; y < numscans(&picres); y++) {
360 >                if (freadscan(scanln, scanlen(&picres), fin) < 0) {
361                          fprintf(stderr, "%s: read error\n", progname);
362                          quit(1);
363                  }
364 <                for (x = 0; x < xres; x++) {
364 >                for (x = 0; x < scanlen(&picres); x++) {
365                          if (uniq)
366 <                                if (    scanln[x][RED] == lastc[RED] &&
367 <                                        scanln[x][GRN] == lastc[GRN] &&
368 <                                        scanln[x][BLU] == lastc[BLU]    )
366 >                                if (    colval(scanln[x],RED) ==
367 >                                                colval(lastc,RED) &&
368 >                                        colval(scanln[x],GRN) ==
369 >                                                colval(lastc,GRN) &&
370 >                                        colval(scanln[x],BLU) ==
371 >                                                colval(lastc,BLU)       )
372                                          continue;
373                                  else
374                                          copycolor(lastc, scanln[x]);
375 <                        if (original)
376 <                                scalecolor(scanln[x], 1.0/exposure);
377 <                        if (!dataonly)
378 <                                printf("%7d %7d ", x, y);
379 <                        if ((*putval)(scanln[x], stdout) < 0) {
375 >                        if (doexposure)
376 >                                multcolor(scanln[x], exposure);
377 >                        if (dogamma)
378 >                                setcolor(scanln[x],
379 >                                pow(colval(scanln[x],RED), 1.0/gamcor),
380 >                                pow(colval(scanln[x],GRN), 1.0/gamcor),
381 >                                pow(colval(scanln[x],BLU), 1.0/gamcor));
382 >                        if (!dataonly) {
383 >                                pix2loc(hv, &picres, x, y);
384 >                                printf("%7d %7d ", (int)(hv[0]*picres.xr),
385 >                                                (int)(hv[1]*picres.yr));
386 >                        }
387 >                        if ((*putval)(scanln[x]) < 0) {
388                                  fprintf(stderr, "%s: write error\n", progname);
389                                  quit(1);
390                          }
# Line 205 | Line 396 | pixtoval()                             /* convert picture to values */
396  
397   valtopix()                      /* convert values to a pixel file */
398   {
399 <        COLOR  *scanln;
399 >        int  dogamma;
400 >        register COLOR  *scanln;
401          int  y;
402          register int  x;
403  
404 <        scanln = (COLOR *)malloc(xres*sizeof(COLOR));
404 >        scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
405          if (scanln == NULL) {
406                  fprintf(stderr, "%s: out of memory\n", progname);
407                  quit(1);
408          }
409 <        for (y = yres-1; y >= 0; y--) {
410 <                for (x = 0; x < xres; x++) {
411 <                        if (!dataonly)
409 >        dogamma = gamcor < .95 || gamcor > 1.05;
410 >        for (y = 0; y < numscans(&picres); y++) {
411 >                for (x = 0; x < scanlen(&picres); x++) {
412 >                        if (!dataonly) {
413                                  fscanf(fin, "%*d %*d");
414 <                        if ((*getval)(scanln[x], fin) < 0) {
414 >                                if (fin2 != NULL) {
415 >                                        fscanf(fin2, "%*d %*d");
416 >                                        fscanf(fin3, "%*d %*d");
417 >                                }
418 >                        }
419 >                        if ((*getval)(scanln[x]) < 0) {
420                                  fprintf(stderr, "%s: read error\n", progname);
421                                  quit(1);
422                          }
423 +                        if (dogamma)
424 +                                setcolor(scanln[x],
425 +                                        pow(colval(scanln[x],RED), gamcor),
426 +                                        pow(colval(scanln[x],GRN), gamcor),
427 +                                        pow(colval(scanln[x],BLU), gamcor));
428 +                        if (doexposure)
429 +                                multcolor(scanln[x], exposure);
430                  }
431 <                if (fwritescan(scanln, xres, stdout) < 0
227 <                                || fflush(stdout) < 0) {
431 >                if (fwritescan(scanln, scanlen(&picres), stdout) < 0) {
432                          fprintf(stderr, "%s: write error\n", progname);
433                          quit(1);
434                  }
# Line 240 | Line 444 | int  code;
444   }
445  
446  
447 < getcascii(col, fp)              /* get an ascii color value from fp */
447 > getcascii(col)          /* get an ascii color value from stream(s) */
448   COLOR  col;
245 FILE  *fp;
449   {
450 <        double  vd[3];
450 >        double  vd[3];
451  
452 <        if (fscanf(fp, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3)
453 <                return(-1);
454 <        setcolor(col, vd[0], vd[1], vd[2]);
452 >        if (fin2 == NULL) {
453 >                if (fscanf(fin, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3)
454 >                        return(-1);
455 >        } else {
456 >                if (fscanf(fin, "%lf", &vd[0]) != 1 ||
457 >                                fscanf(fin2, "%lf", &vd[1]) != 1 ||
458 >                                fscanf(fin3, "%lf", &vd[2]) != 1)
459 >                        return(-1);
460 >        }
461 >        setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]);
462          return(0);
463   }
464  
465  
466 < getcdouble(col, fp)             /* get a double color value from fp */
466 > getcdouble(col)         /* get a double color value from stream(s) */
467   COLOR  col;
258 FILE  *fp;
468   {
469 <        double  vd[3];
469 >        double  vd[3];
470  
471 <        if (fread(vd, sizeof(double), 3, fp) != 3)
472 <                return(-1);
473 <        setcolor(col, vd[0], vd[1], vd[2]);
471 >        if (fin2 == NULL) {
472 >                if (fread((char *)vd, sizeof(double), 3, fin) != 3)
473 >                        return(-1);
474 >        } else {
475 >                if (fread((char *)vd, sizeof(double), 1, fin) != 1 ||
476 >                        fread((char *)(vd+1), sizeof(double), 1, fin2) != 1 ||
477 >                        fread((char *)(vd+2), sizeof(double), 1, fin3) != 1)
478 >                        return(-1);
479 >        }
480 >        setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]);
481          return(0);
482   }
483  
484  
485 < getcfloat(col, fp)              /* get a float color value from fp */
485 > getcfloat(col)          /* get a float color value from stream(s) */
486   COLOR  col;
271 FILE  *fp;
487   {
488          float  vf[3];
489  
490 <        if (fread(vf, sizeof(float), 3, fp) != 3)
491 <                return(-1);
492 <        setcolor(col, vf[0], vf[1], vf[2]);
490 >        if (fin2 == NULL) {
491 >                if (fread((char *)vf, sizeof(float), 3, fin) != 3)
492 >                        return(-1);
493 >        } else {
494 >                if (fread((char *)vf, sizeof(float), 1, fin) != 1 ||
495 >                        fread((char *)(vf+1), sizeof(float), 1, fin2) != 1 ||
496 >                        fread((char *)(vf+2), sizeof(float), 1, fin3) != 1)
497 >                        return(-1);
498 >        }
499 >        setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]);
500          return(0);
501   }
502  
503  
504 < getcint(col, fp)                /* get an int color value from fp */
504 > getcint(col)            /* get an int color value from stream(s) */
505   COLOR  col;
284 FILE  *fp;
506   {
507          int  vi[3];
508  
509 <        if (fscanf(fp, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3)
510 <                return(-1);
511 <        setcolor(col,(vi[0]+.5)/256.,(vi[1]+.5)/256.,(vi[2]+.5)/256.);
509 >        if (fin2 == NULL) {
510 >                if (fscanf(fin, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3)
511 >                        return(-1);
512 >        } else {
513 >                if (fscanf(fin, "%d", &vi[0]) != 1 ||
514 >                                fscanf(fin2, "%d", &vi[1]) != 1 ||
515 >                                fscanf(fin3, "%d", &vi[2]) != 1)
516 >                        return(-1);
517 >        }
518 >        setcolor(col, (vi[rord[RED]]+.5)/256.,
519 >                        (vi[rord[GRN]]+.5)/256., (vi[rord[BLU]]+.5)/256.);
520          return(0);
521   }
522  
523  
524 < getcbyte(col, fp)               /* get a byte color value from fp */
524 > getcbyte(col)           /* get a byte color value from stream(s) */
525   COLOR  col;
297 FILE  *fp;
526   {
527          BYTE  vb[3];
528  
529 <        if (fread(vb, sizeof(BYTE), 3, fp) != 3)
530 <                return(-1);
531 <        setcolor(col,(vb[0]+.5)/256.,(vb[1]+.5)/256.,(vb[2]+.5)/256.);
529 >        if (fin2 == NULL) {
530 >                if (fread((char *)vb, sizeof(BYTE), 3, fin) != 3)
531 >                        return(-1);
532 >        } else {
533 >                if (fread((char *)vb, sizeof(BYTE), 1, fin) != 1 ||
534 >                        fread((char *)(vb+1), sizeof(BYTE), 1, fin2) != 1 ||
535 >                        fread((char *)(vb+2), sizeof(BYTE), 1, fin3) != 1)
536 >                        return(-1);
537 >        }
538 >        setcolor(col, (vb[rord[RED]]+.5)/256.,
539 >                        (vb[rord[GRN]]+.5)/256., (vb[rord[BLU]]+.5)/256.);
540          return(0);
541   }
542  
543  
544 < getbascii(col, fp)              /* get an ascii brightness value from fp */
544 > getbascii(col)          /* get an ascii brightness value from fin */
545   COLOR  col;
310 FILE  *fp;
546   {
547 <        double  vd;
547 >        double  vd;
548  
549 <        if (fscanf(fp, "%lf", &vd) != 1)
549 >        if (fscanf(fin, "%lf", &vd) != 1)
550                  return(-1);
551          setcolor(col, vd, vd, vd);
552          return(0);
553   }
554  
555  
556 < getbdouble(col, fp)             /* get a double brightness value from fp */
556 > getbdouble(col)         /* get a double brightness value from fin */
557   COLOR  col;
323 FILE  *fp;
558   {
559 <        double  vd;
559 >        double  vd;
560  
561 <        if (fread(&vd, sizeof(double), 1, fp) != 1)
561 >        if (fread((char *)&vd, sizeof(double), 1, fin) != 1)
562                  return(-1);
563          setcolor(col, vd, vd, vd);
564          return(0);
565   }
566  
567  
568 < getbfloat(col, fp)              /* get a float brightness value from fp */
568 > getbfloat(col)          /* get a float brightness value from fin */
569   COLOR  col;
336 FILE  *fp;
570   {
571          float  vf;
572  
573 <        if (fread(&vf, sizeof(float), 1, fp) != 1)
573 >        if (fread((char *)&vf, sizeof(float), 1, fin) != 1)
574                  return(-1);
575          setcolor(col, vf, vf, vf);
576          return(0);
577   }
578  
579  
580 < getbint(col, fp)                /* get an int brightness value from fp */
580 > getbint(col)            /* get an int brightness value from fin */
581   COLOR  col;
349 FILE  *fp;
582   {
583          int  vi;
584 <        double  d;
584 >        double  d;
585  
586 <        if (fscanf(fp, "%d", &vi) != 1)
586 >        if (fscanf(fin, "%d", &vi) != 1)
587                  return(-1);
588          d = (vi+.5)/256.;
589          setcolor(col, d, d, d);
# Line 359 | Line 591 | FILE  *fp;
591   }
592  
593  
594 < getbbyte(col, fp)               /* get a byte brightness value from fp */
594 > getbbyte(col)           /* get a byte brightness value from fin */
595   COLOR  col;
364 FILE  *fp;
596   {
597          BYTE  vb;
598 <        double  d;
598 >        double  d;
599  
600 <        if (fread(&vb, sizeof(BYTE), 1, fp) != 1)
600 >        if (fread((char *)&vb, sizeof(BYTE), 1, fin) != 1)
601                  return(-1);
602          d = (vb+.5)/256.;
603          setcolor(col, d, d, d);
# Line 374 | Line 605 | FILE  *fp;
605   }
606  
607  
608 < putcascii(col, fp)                      /* put an ascii color to fp */
608 > putcascii(col)                  /* put an ascii color to stdout */
609   COLOR  col;
379 FILE  *fp;
610   {
611 <        fprintf(fp, "%15.3e %15.3e %15.3e\n",
612 <                        colval(col,RED),
613 <                        colval(col,GRN),
614 <                        colval(col,BLU));
611 >        fprintf(stdout, "%15.3e %15.3e %15.3e\n",
612 >                        colval(col,ord[0]),
613 >                        colval(col,ord[1]),
614 >                        colval(col,ord[2]));
615  
616 <        return(ferror(fp) ? -1 : 0);
616 >        return(ferror(stdout) ? -1 : 0);
617   }
618  
619  
620 < putcfloat(col, fp)                      /* put a float color to fp */
620 > putcfloat(col)                  /* put a float color to stdout */
621   COLOR  col;
392 FILE  *fp;
622   {
623          float  vf[3];
624  
625 <        vf[0] = colval(col,RED);
626 <        vf[1] = colval(col,GRN);
627 <        vf[2] = colval(col,BLU);
628 <        fwrite(vf, sizeof(float), 3, fp);
625 >        vf[0] = colval(col,ord[0]);
626 >        vf[1] = colval(col,ord[1]);
627 >        vf[2] = colval(col,ord[2]);
628 >        fwrite((char *)vf, sizeof(float), 3, stdout);
629  
630 <        return(ferror(fp) ? -1 : 0);
630 >        return(ferror(stdout) ? -1 : 0);
631   }
632  
633  
634 < putcdouble(col, fp)                     /* put a double color to fp */
634 > putcdouble(col)                 /* put a double color to stdout */
635   COLOR  col;
407 FILE  *fp;
636   {
637 <        double  vd[3];
637 >        double  vd[3];
638  
639 <        vd[0] = colval(col,RED);
640 <        vd[1] = colval(col,GRN);
641 <        vd[2] = colval(col,BLU);
642 <        fwrite(vd, sizeof(double), 3, fp);
639 >        vd[0] = colval(col,ord[0]);
640 >        vd[1] = colval(col,ord[1]);
641 >        vd[2] = colval(col,ord[2]);
642 >        fwrite((char *)vd, sizeof(double), 3, stdout);
643  
644 <        return(ferror(fp) ? -1 : 0);
644 >        return(ferror(stdout) ? -1 : 0);
645   }
646  
647  
648 < putcint(col, fp)                        /* put an int color to fp */
648 > putcint(col)                    /* put an int color to stdout */
649   COLOR  col;
422 FILE  *fp;
650   {
651 <        fprintf(fp, "%d %d %d\n",
652 <                        (int)(colval(col,RED)*256.),
653 <                        (int)(colval(col,GRN)*256.),
654 <                        (int)(colval(col,BLU)*256.));
651 >        fprintf(stdout, "%d %d %d\n",
652 >                        (int)(colval(col,ord[0])*256.),
653 >                        (int)(colval(col,ord[1])*256.),
654 >                        (int)(colval(col,ord[2])*256.));
655  
656 <        return(ferror(fp) ? -1 : 0);
656 >        return(ferror(stdout) ? -1 : 0);
657   }
658  
659  
660 < putcbyte(col, fp)                       /* put a byte color to fp */
660 > putcbyte(col)                   /* put a byte color to stdout */
661   COLOR  col;
435 FILE  *fp;
662   {
663          register int  i;
664          BYTE  vb[3];
665  
666 <        i = colval(col,RED)*256.;
666 >        i = colval(col,ord[0])*256.;
667          vb[0] = min(i,255);
668 <        i = colval(col,GRN)*256.;
668 >        i = colval(col,ord[1])*256.;
669          vb[1] = min(i,255);
670 <        i = colval(col,BLU)*256.;
670 >        i = colval(col,ord[2])*256.;
671          vb[2] = min(i,255);
672 <        fwrite(vb, sizeof(BYTE), 3, fp);
672 >        fwrite((char *)vb, sizeof(BYTE), 3, stdout);
673  
674 <        return(ferror(fp) ? -1 : 0);
674 >        return(ferror(stdout) ? -1 : 0);
675   }
676  
677  
678 < putbascii(col, fp)                      /* put an ascii brightness to fp */
678 > putbascii(col)                  /* put an ascii brightness to stdout */
679   COLOR  col;
454 FILE  *fp;
680   {
681 <        fprintf(fp, "%15.3e\n", bright(col));
681 >        fprintf(stdout, "%15.3e\n", bright(col));
682  
683 <        return(ferror(fp) ? -1 : 0);
683 >        return(ferror(stdout) ? -1 : 0);
684   }
685  
686  
687 < putbfloat(col, fp)                      /* put a float brightness to fp */
687 > putbfloat(col)                  /* put a float brightness to stdout */
688   COLOR  col;
464 FILE  *fp;
689   {
690          float  vf;
691  
692          vf = bright(col);
693 <        fwrite(&vf, sizeof(float), 1, fp);
693 >        fwrite((char *)&vf, sizeof(float), 1, stdout);
694  
695 <        return(ferror(fp) ? -1 : 0);
695 >        return(ferror(stdout) ? -1 : 0);
696   }
697  
698  
699 < putbdouble(col, fp)                     /* put a double brightness to fp */
699 > putbdouble(col)                 /* put a double brightness to stdout */
700   COLOR  col;
477 FILE  *fp;
701   {
702 <        double  vd;
702 >        double  vd;
703  
704          vd = bright(col);
705 <        fwrite(&vd, sizeof(double), 1, fp);
705 >        fwrite((char *)&vd, sizeof(double), 1, stdout);
706  
707 <        return(ferror(fp) ? -1 : 0);
707 >        return(ferror(stdout) ? -1 : 0);
708   }
709  
710  
711 < putbint(col, fp)                        /* put an int brightness to fp */
711 > putbint(col)                    /* put an int brightness to stdout */
712   COLOR  col;
490 FILE  *fp;
713   {
714 <        fprintf(fp, "%d\n", (int)(bright(col)*256.));
714 >        fprintf(stdout, "%d\n", (int)(bright(col)*256.));
715  
716 <        return(ferror(fp) ? -1 : 0);
716 >        return(ferror(stdout) ? -1 : 0);
717   }
718  
719  
720 < putbbyte(col, fp)                       /* put a byte brightness to fp */
720 > putbbyte(col)                   /* put a byte brightness to stdout */
721   COLOR  col;
500 FILE  *fp;
722   {
723          register int  i;
724          BYTE  vb;
725  
726          i = bright(col)*256.;
727          vb = min(i,255);
728 <        fwrite(&vb, sizeof(BYTE), 1, fp);
728 >        fwrite((char *)&vb, sizeof(BYTE), 1, stdout);
729  
730 <        return(ferror(fp) ? -1 : 0);
730 >        return(ferror(stdout) ? -1 : 0);
731   }
732  
733  
734 + putpascii(col)                  /* put an ascii primary to stdout */
735 + COLOR  col;
736 + {
737 +        fprintf(stdout, "%15.3e\n", colval(col,putprim));
738 +
739 +        return(ferror(stdout) ? -1 : 0);
740 + }
741 +
742 +
743 + putpfloat(col)                  /* put a float primary to stdout */
744 + COLOR  col;
745 + {
746 +        float  vf;
747 +
748 +        vf = colval(col,putprim);
749 +        fwrite((char *)&vf, sizeof(float), 1, stdout);
750 +
751 +        return(ferror(stdout) ? -1 : 0);
752 + }
753 +
754 +
755 + putpdouble(col)                 /* put a double primary to stdout */
756 + COLOR  col;
757 + {
758 +        double  vd;
759 +
760 +        vd = colval(col,putprim);
761 +        fwrite((char *)&vd, sizeof(double), 1, stdout);
762 +
763 +        return(ferror(stdout) ? -1 : 0);
764 + }
765 +
766 +
767 + putpint(col)                    /* put an int primary to stdout */
768 + COLOR  col;
769 + {
770 +        fprintf(stdout, "%d\n", (int)(colval(col,putprim)*256.));
771 +
772 +        return(ferror(stdout) ? -1 : 0);
773 + }
774 +
775 +
776 + putpbyte(col)                   /* put a byte primary to stdout */
777 + COLOR  col;
778 + {
779 +        register int  i;
780 +        BYTE  vb;
781 +
782 +        i = colval(col,putprim)*256.;
783 +        vb = min(i,255);
784 +        fwrite((char *)&vb, sizeof(BYTE), 1, stdout);
785 +
786 +        return(ferror(stdout) ? -1 : 0);
787 + }
788 +
789 +
790   set_io()                        /* set put and get functions */
791   {
792          switch (format) {
793          case 'a':                                       /* ascii */
794 <                if (brightonly) {
794 >                if (putprim == BRIGHT) {
795                          getval = getbascii;
796                          putval = putbascii;
797 +                } else if (putprim != ALL) {
798 +                        getval = getbascii;
799 +                        putval = putpascii;
800                  } else {
801                          getval = getcascii;
802                          putval = putcascii;
803                  }
804                  return;
805          case 'f':                                       /* binary float */
806 <                if (brightonly) {
806 >                if (putprim == BRIGHT) {
807                          getval = getbfloat;
808                          putval = putbfloat;
809 +                } else if (putprim != ALL) {
810 +                        getval = getbfloat;
811 +                        putval = putpfloat;
812                  } else {
813                          getval = getcfloat;
814                          putval = putcfloat;
815                  }
816                  return;
817          case 'd':                                       /* binary double */
818 <                if (brightonly) {
818 >                if (putprim == BRIGHT) {
819                          getval = getbdouble;
820                          putval = putbdouble;
821 +                } else if (putprim != ALL) {
822 +                        getval = getbdouble;
823 +                        putval = putpdouble;
824                  } else {
825                          getval = getcdouble;
826                          putval = putcdouble;
827                  }
828                  return;
829          case 'i':                                       /* integer */
830 <                if (brightonly) {
830 >                if (putprim == BRIGHT) {
831                          getval = getbint;
832                          putval = putbint;
833 +                } else if (putprim != ALL) {
834 +                        getval = getbint;
835 +                        putval = putpint;
836                  } else {
837                          getval = getcint;
838                          putval = putcint;
839                  }
840                  return;
841          case 'b':                                       /* byte */
842 <                if (brightonly) {
842 >                if (putprim == BRIGHT) {
843                          getval = getbbyte;
844                          putval = putbbyte;
845 +                } else if (putprim != ALL) {
846 +                        getval = getbbyte;
847 +                        putval = putpbyte;
848                  } else {
849                          getval = getcbyte;
850                          putval = putcbyte;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines