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.29 by greg, Sat Dec 23 17:27:46 2006 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  pvalue.c - program to print pixel values.
6   *
7   *     4/23/86
8   */
9  
10 < #include  <stdio.h>
11 <
10 > #include  "platform.h"
11 > #include  "standard.h"
12   #include  "color.h"
13 + #include  "resolu.h"
14 + #include  "view.h"
15  
16 < #define  min(a,b)               ((a)<(b)?(a):(b))
16 > #define  min(a,b)               ((a)<(b)?(a):(b))
17  
18 < int  xres = 0;                  /* resolution of input */
19 < int  yres = 0;
18 >                                /* what to put out (also RED, GRN, BLU) */
19 > #define  ALL            3
20 > #define  BRIGHT         4
21  
22 + RESOLU  picres;                 /* resolution of picture */
23   int  uniq = 0;                  /* print only unique values? */
24 <
24 < int  original = 0;              /* convert back to original values? */
25 <
24 > int  doexposure = 0;            /* exposure change? (>100 to print) */
25   int  dataonly = 0;              /* data only format? */
26 <
28 < int  brightonly = 0;            /* only brightness values? */
29 <
26 > int  putprim = ALL;             /* what to put out */
27   int  reverse = 0;               /* reverse conversion? */
31
28   int  format = 'a';              /* input/output format */
29   char  *fmtid = "ascii";         /* format identifier for header */
30 <
31 < int  header = 1;                /* do header */
32 <
30 > int  header = 1;                /* do header? */
31 > long  skipbytes = 0;            /* skip bytes in input? */
32 > int  swapbytes = 0;             /* swap bytes? */
33 > int  interleave = 1;            /* file is interleaved? */
34 > int  resolution = 1;            /* put/get resolution string? */
35 > int  original = 0;              /* convert to original values? */
36   int  wrongformat = 0;           /* wrong input format? */
37 + double  gamcor = 1.0;           /* gamma correction */
38  
39 < double  gamma = 1.0;            /* gamma correction */
39 > int  ord[3] = {RED, GRN, BLU};  /* RGB ordering */
40 > int  rord[4];                   /* reverse ordering */
41  
42   COLOR  exposure = WHTCOLOR;
43  
44   char  *progname;
45  
46   FILE  *fin;
47 + FILE  *fin2 = NULL, *fin3 = NULL;       /* for other color channels */
48  
47 extern double  atof(), pow();
49  
50 < int  (*getval)(), (*putval)();
50 > typedef int getfunc_t(COLOR  col);
51 > typedef int putfunc_t(COLOR  col);
52 > typedef double brightfunc_t(COLOR  col);
53  
54 + getfunc_t *getval;
55 + putfunc_t *putval;
56 + brightfunc_t *mybright;
57  
58 < main(argc, argv)
59 < int  argc;
60 < char  **argv;
58 > static gethfunc checkhead;
59 > static brightfunc_t rgb_bright, xyz_bright;
60 > static getfunc_t getbascii, getbint, getbdouble, getbfloat, getbbyte, getbword;
61 > static getfunc_t getcascii, getcint, getcdouble, getcfloat, getcbyte, getcword;
62 > static putfunc_t putbascii, putbint, putbdouble, putbfloat, putbbyte, putbword;
63 > static putfunc_t putcascii, putcint, putcdouble, putcfloat, putcbyte, putcword;
64 > static putfunc_t putpascii, putpint, putpdouble, putpfloat, putpbyte, putpword;
65 >
66 > static void set_io(void);
67 > static void pixtoval(void);
68 > static void valtopix(void);
69 >
70 >
71 > static double
72 > rgb_bright(
73 >        COLOR  clr
74 > )
75   {
76 <        extern int  checkhead();
76 >        return(bright(clr));
77 > }
78 >
79 > static double
80 > xyz_bright(
81 >        COLOR  clr
82 > )
83 > {
84 >        return(clr[CIEY]);
85 > }
86 >
87 > int
88 > main(
89 >        int  argc,
90 >        char  **argv
91 > )
92 > {
93 >        double  d, expval = 1.0;
94          int  i;
95  
96          progname = argv[0];
97 +        mybright = &rgb_bright; /* default */
98  
99          for (i = 1; i < argc; i++)
100 <                if (argv[i][0] == '-')
100 >                if (argv[i][0] == '-' || argv[i][0] == '+')
101                          switch (argv[i][1]) {
102 <                        case 'h':               /* no header */
103 <                                header = 0;
102 >                        case 'h':               /* header */
103 >                                header = argv[i][0] == '+';
104                                  break;
105 +                        case 'H':               /* resolution string */
106 +                                resolution = argv[i][0] == '+';
107 +                                break;
108 +                        case 's':               /* skip bytes in header */
109 +                                skipbytes = atol(argv[++i]);
110 +                                break;
111                          case 'u':               /* unique values */
112 <                                uniq = 1;
112 >                                uniq = argv[i][0] == '-';
113                                  break;
114                          case 'o':               /* original values */
115 <                                original = 1;
115 >                                original = argv[i][0] == '-';
116                                  break;
117                          case 'g':               /* gamma correction */
118 <                                gamma = atof(argv[++i]);
118 >                                gamcor = atof(argv[i+1]);
119 >                                if (argv[i][0] == '+')
120 >                                        gamcor = 1.0/gamcor;
121 >                                i++;
122                                  break;
123 +                        case 'e':               /* exposure correction */
124 +                                d = atof(argv[i+1]);
125 +                                if (argv[i+1][0] == '-' || argv[i+1][0] == '+')
126 +                                        d = pow(2.0, d);
127 +                                if (argv[i][0] == '-')
128 +                                        expval *= d;
129 +                                scalecolor(exposure, d);
130 +                                doexposure++;
131 +                                i++;
132 +                                break;
133 +                        case 'R':               /* reverse byte sequence */
134 +                                if (argv[i][0] == '-') {
135 +                                        ord[0]=BLU; ord[1]=GRN; ord[2]=RED;
136 +                                } else {
137 +                                        ord[0]=RED; ord[1]=GRN; ord[2]=BLU;
138 +                                }
139 +                                break;
140                          case 'r':               /* reverse conversion */
141 <                                reverse = 1;
141 >                                reverse = argv[i][0] == '-';
142                                  break;
143 +                        case 'n':               /* non-interleaved RGB */
144 +                                interleave = argv[i][0] == '+';
145 +                                break;
146                          case 'b':               /* brightness values */
147 <                                brightonly = 1;
147 >                                putprim = argv[i][0] == '-' ? BRIGHT : ALL;
148                                  break;
149 +                        case 'p':               /* put primary */
150 +                                switch (argv[i][2]) {
151 +                                case 'r': case 'R': putprim = RED; break;
152 +                                case 'g': case 'G': putprim = GRN; break;
153 +                                case 'b': case 'B': putprim = BLU; break;
154 +                                default: goto unkopt;
155 +                                }
156 +                                break;
157                          case 'd':               /* data only (no indices) */
158 <                                dataonly = 1;
158 >                                dataonly = argv[i][0] == '-';
159                                  switch (argv[i][2]) {
160                                  case '\0':
161                                  case 'a':               /* ascii */
# Line 92 | Line 167 | char  **argv;
167                                          fmtid = "ascii";
168                                          break;
169                                  case 'b':               /* byte */
170 +                                        dataonly = 1;
171                                          format = 'b';
172                                          fmtid = "byte";
173                                          break;
174 +                                case 'W':               /* 16-bit swapped */
175 +                                        swapbytes = 1;
176 +                                case 'w':               /* 16-bit */
177 +                                        dataonly = 1;
178 +                                        format = 'w';
179 +                                        fmtid = "16-bit";
180 +                                        break;
181 +                                case 'F':               /* swapped floats */
182 +                                        swapbytes = 1;
183                                  case 'f':               /* float */
184 +                                        dataonly = 1;
185                                          format = 'f';
186                                          fmtid = "float";
187                                          break;
188 +                                case 'D':               /* swapped doubles */
189 +                                        swapbytes = 1;
190                                  case 'd':               /* double */
191 +                                        dataonly = 1;
192                                          format = 'd';
193                                          fmtid = "double";
194                                          break;
# Line 108 | Line 197 | char  **argv;
197                                  }
198                                  break;
199                          case 'x':               /* x resolution */
200 <                                xres = atoi(argv[++i]);
200 >                        case 'X':               /* x resolution */
201 >                                resolution = 0;
202 >                                if (argv[i][0] == '-')
203 >                                        picres.rt |= XDECR;
204 >                                picres.xr = atoi(argv[++i]);
205                                  break;
206                          case 'y':               /* y resolution */
207 <                                yres = atoi(argv[++i]);
207 >                        case 'Y':               /* y resolution */
208 >                                resolution = 0;
209 >                                if (argv[i][0] == '-')
210 >                                        picres.rt |= YDECR;
211 >                                if (picres.xr == 0)
212 >                                        picres.rt |= YMAJOR;
213 >                                picres.yr = atoi(argv[++i]);
214                                  break;
215                          default:
216   unkopt:
# Line 123 | Line 222 | unkopt:
222                  else
223                          break;
224                                          /* recognize special formats */
225 <        if (dataonly && format == 'b')
226 <                if (brightonly)
225 >        if (dataonly && format == 'b') {
226 >                if (putprim == ALL)
227 >                        fmtid = "24-bit_rgb";
228 >                else
229                          fmtid = "8-bit_grey";
230 +        }
231 +        if (dataonly && format == 'w') {
232 +                if (putprim == ALL)
233 +                        fmtid = "48-bit_rgb";
234                  else
235 <                        fmtid = "24-bit_rgb";
236 <
235 >                        fmtid = "16-bit_grey";
236 >        }
237 >                                        /* assign reverse ordering */
238 >        rord[ord[0]] = 0;
239 >        rord[ord[1]] = 1;
240 >        rord[ord[2]] = 2;
241 >                                        /* get input */
242          if (i == argc) {
243                  fin = stdin;
244 <        } else if (i == argc-1) {
244 >        } else if (i < argc) {
245                  if ((fin = fopen(argv[i], "r")) == NULL) {
246                          fprintf(stderr, "%s: can't open file \"%s\"\n",
247                                                  progname, argv[i]);
248                          quit(1);
249                  }
250 <        } else {
250 >                if (reverse && putprim != BRIGHT && i == argc-3) {
251 >                        if ((fin2 = fopen(argv[i+1], "r")) == NULL) {
252 >                                fprintf(stderr, "%s: can't open file \"%s\"\n",
253 >                                                progname, argv[i+1]);
254 >                                quit(1);
255 >                        }
256 >                        if ((fin3 = fopen(argv[i+2], "r")) == NULL) {
257 >                                fprintf(stderr, "%s: can't open file \"%s\"\n",
258 >                                                progname, argv[i+2]);
259 >                                quit(1);
260 >                        }
261 >                        interleave = -1;
262 >                } else if (i != argc-1)
263 >                        fin = NULL;
264 >                if (reverse && putprim != BRIGHT && !interleave) {
265 >                        fin2 = fopen(argv[i], "r");
266 >                        fin3 = fopen(argv[i], "r");
267 >                }
268 >                if (skipbytes && (fseek(fin, skipbytes, 0) || (fin2 != NULL &&
269 >                                (fseek(fin2, skipbytes, 0) ||
270 >                                fseek(fin3, skipbytes, 0))))) {
271 >                        fprintf(stderr, "%s: cannot skip %ld bytes on input\n",
272 >                                        progname, skipbytes);
273 >                        quit(1);
274 >                }
275 >        }
276 >        if (fin == NULL) {
277                  fprintf(stderr, "%s: bad # file arguments\n", progname);
278                  quit(1);
279          }
280  
145        set_io();
146
281          if (reverse) {
282 <                if (yres <= 0 || xres <= 0) {
283 <                        fprintf(stderr, "%s: missing x and y resolution\n",
284 <                                        progname);
285 <                        quit(1);
286 <                }
282 > #ifdef _WIN32
283 >                SET_FILE_BINARY(stdout);
284 >                if (format != 'a' && format != 'i')
285 >                        SET_FILE_BINARY(fin);
286 > #endif
287                                          /* get header */
288 <                if (header && checkheader(fin, fmtid, stdout) < 0) {
289 <                        fprintf(stderr, "%s: wrong input format\n", progname);
288 >                if (header) {
289 >                        if (checkheader(fin, fmtid, stdout) < 0) {
290 >                                fprintf(stderr, "%s: wrong input format\n",
291 >                                                progname);
292 >                                quit(1);
293 >                        }
294 >                        if (fin2 != NULL) {
295 >                                getheader(fin2, NULL, NULL);
296 >                                getheader(fin3, NULL, NULL);
297 >                        }
298 >                } else
299 >                        newheader("RADIANCE", stdout);
300 >                                        /* get resolution */
301 >                if ((resolution && !fgetsresolu(&picres, fin)) ||
302 >                                picres.xr <= 0 || picres.yr <= 0) {
303 >                        fprintf(stderr, "%s: missing resolution\n", progname);
304                          quit(1);
305                  }
306 +                if (resolution && fin2 != NULL) {
307 +                        RESOLU  pres2;
308 +                        if (!fgetsresolu(&pres2, fin2) ||
309 +                                        pres2.rt != picres.rt ||
310 +                                        pres2.xr != picres.xr ||
311 +                                        pres2.yr != picres.yr ||
312 +                                        !fgetsresolu(&pres2, fin3) ||
313 +                                        pres2.rt != picres.rt ||
314 +                                        pres2.xr != picres.xr ||
315 +                                        pres2.yr != picres.yr) {
316 +                                fprintf(stderr, "%s: resolution mismatch\n",
317 +                                                progname);
318 +                                quit(1);
319 +                        }
320 +                }
321                                                  /* add to header */
322                  printargs(i, argv, stdout);
323 +                if (expval < .99 || expval > 1.01)
324 +                        fputexpos(expval, stdout);
325                  fputformat(COLRFMT, stdout);
326 <                printf("\n");
327 <                fputresolu(YMAJOR|YDECR, xres, yres, stdout);
326 >                putchar('\n');
327 >                fputsresolu(&picres, stdout);   /* always put resolution */
328                  valtopix();
329          } else {
330 + #ifdef _WIN32
331 +                SET_FILE_BINARY(fin);
332 +                if (format != 'a' && format != 'i')
333 +                        SET_FILE_BINARY(stdout);
334 + #endif
335                                                  /* get header */
336                  getheader(fin, checkhead, NULL);
337                  if (wrongformat) {
338 <                        fprintf(stderr, "%s: input not a Radiance picture\n",
338 >                        fprintf(stderr,
339 >                                "%s: input not a Radiance RGBE picture\n",
340                                          progname);
341                          quit(1);
342                  }
343 <
344 <                if (xres <= 0 || yres <= 0)             /* get picture size */
345 <                        if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) {
346 <                                fprintf(stderr,
176 <                                "%s: missing x and y resolution\n",
177 <                                                progname);
178 <                                quit(1);
179 <                        }
343 >                if (!fgetsresolu(&picres, fin)) {
344 >                        fprintf(stderr, "%s: missing resolution\n", progname);
345 >                        quit(1);
346 >                }
347                  if (header) {
348                          printargs(i, argv, stdout);
349 +                        if (expval < .99 || expval > 1.01)
350 +                                fputexpos(expval, stdout);
351                          fputformat(fmtid, stdout);
352 <                        printf("\n");
352 >                        putchar('\n');
353                  }
354 +                if (resolution)                 /* put resolution */
355 +                        fputsresolu(&picres, stdout);
356                  pixtoval();
357          }
358  
359          quit(0);
360 +        return 0; /* pro forma return */
361   }
362  
363  
364 < checkhead(line)                         /* deal with line from header */
365 < char  *line;
364 > static int
365 > checkhead(                              /* deal with line from header */
366 >        char    *line,
367 >        void    *p
368 > )
369   {
370          char    fmt[32];
371          double  d;
372          COLOR   ctmp;
373  
374 <        if (isformat(line)) {
375 <                formatval(fmt, line);
376 <                wrongformat = strcmp(fmt, COLRFMT);
374 >        if (formatval(fmt, line)) {
375 >                if (!strcmp(fmt, CIEFMT))
376 >                        mybright = &xyz_bright;
377 >                else if (!strcmp(fmt, COLRFMT))
378 >                        mybright = &rgb_bright;
379 >                else
380 >                        wrongformat++;
381          } else if (original && isexpos(line)) {
382                  d = 1.0/exposval(line);
383                  scalecolor(exposure, d);
384 +                doexposure++;
385          } else if (original && iscolcor(line)) {
386                  colcorval(ctmp, line);
387                  setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED),
388                                  colval(exposure,GRN)/colval(ctmp,GRN),
389                                  colval(exposure,BLU)/colval(ctmp,BLU));
390 +                doexposure++;
391          } else if (header)
392                  fputs(line, stdout);
393 +        return(0);
394   }
395  
396  
397 < pixtoval()                              /* convert picture to values */
397 > static void
398 > pixtoval(void)                          /* convert picture to values */
399   {
400 <        register COLOR  *scanln;
400 >        register COLOR  *scanln;
401          int  dogamma;
402          COLOR  lastc;
403 +        RREAL  hv[2];
404 +        int  startprim, endprim;
405 +        long  startpos;
406          int  y;
407          register int  x;
408  
409 <        scanln = (COLOR *)malloc(xres*sizeof(COLOR));
409 >        scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
410          if (scanln == NULL) {
411                  fprintf(stderr, "%s: out of memory\n", progname);
412                  quit(1);
413          }
414 <        dogamma = gamma < .95 || gamma > 1.05;
415 <        setcolor(lastc, 0.0, 0.0, 0.0);
416 <        for (y = yres-1; y >= 0; y--) {
417 <                if (freadscan(scanln, xres, fin) < 0) {
418 <                        fprintf(stderr, "%s: read error\n", progname);
414 >        dogamma = gamcor < .95 || gamcor > 1.05;
415 >        if (putprim == ALL && !interleave) {
416 >                startprim = RED; endprim = BLU;
417 >                startpos = ftell(fin);
418 >        } else {
419 >                startprim = putprim; endprim = putprim;
420 >        }
421 >        for (putprim = startprim; putprim <= endprim; putprim++) {
422 >                if (putprim != startprim && fseek(fin, startpos, 0)) {
423 >                        fprintf(stderr, "%s: seek error on input file\n",
424 >                                        progname);
425                          quit(1);
426                  }
427 <                for (x = 0; x < xres; x++) {
428 <                        if (uniq)
429 <                                if (    colval(scanln[x],RED) ==
430 <                                                colval(lastc,RED) &&
431 <                                        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) {
256 <                                fprintf(stderr, "%s: write error\n", progname);
427 >                set_io();
428 >                setcolor(lastc, 0.0, 0.0, 0.0);
429 >                for (y = 0; y < numscans(&picres); y++) {
430 >                        if (freadscan(scanln, scanlen(&picres), fin) < 0) {
431 >                                fprintf(stderr, "%s: read error\n", progname);
432                                  quit(1);
433                          }
434 +                        for (x = 0; x < scanlen(&picres); x++) {
435 +                                if (uniq) {
436 +                                        if (    colval(scanln[x],RED) ==
437 +                                                        colval(lastc,RED) &&
438 +                                                colval(scanln[x],GRN) ==
439 +                                                        colval(lastc,GRN) &&
440 +                                                colval(scanln[x],BLU) ==
441 +                                                        colval(lastc,BLU)       )
442 +                                                continue;
443 +                                        else
444 +                                                copycolor(lastc, scanln[x]);
445 +                                }
446 +                                if (doexposure)
447 +                                        multcolor(scanln[x], exposure);
448 +                                if (dogamma)
449 +                                        setcolor(scanln[x],
450 +                                        pow(colval(scanln[x],RED), 1.0/gamcor),
451 +                                        pow(colval(scanln[x],GRN), 1.0/gamcor),
452 +                                        pow(colval(scanln[x],BLU), 1.0/gamcor));
453 +                                if (!dataonly) {
454 +                                        pix2loc(hv, &picres, x, y);
455 +                                        printf("%7d %7d ",
456 +                                                        (int)(hv[0]*picres.xr),
457 +                                                        (int)(hv[1]*picres.yr));
458 +                                }
459 +                                if ((*putval)(scanln[x]) < 0) {
460 +                                        fprintf(stderr, "%s: write error\n",
461 +                                                        progname);
462 +                                        quit(1);
463 +                                }
464 +                        }
465                  }
466          }
467 <        free((char *)scanln);
467 >        free((void *)scanln);
468   }
469  
470  
471 < valtopix()                      /* convert values to a pixel file */
471 > static void
472 > valtopix(void)                  /* convert values to a pixel file */
473   {
474          int  dogamma;
475 <        register COLOR  *scanln;
475 >        register COLOR  *scanln;
476          int  y;
477          register int  x;
478  
479 <        scanln = (COLOR *)malloc(xres*sizeof(COLOR));
479 >        scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
480          if (scanln == NULL) {
481                  fprintf(stderr, "%s: out of memory\n", progname);
482                  quit(1);
483          }
484 <        dogamma = gamma < .95 || gamma > 1.05;
485 <        for (y = yres-1; y >= 0; y--) {
486 <                for (x = 0; x < xres; x++) {
487 <                        if (!dataonly)
484 >        dogamma = gamcor < .95 || gamcor > 1.05;
485 >        set_io();
486 >        for (y = 0; y < numscans(&picres); y++) {
487 >                for (x = 0; x < scanlen(&picres); x++) {
488 >                        if (!dataonly) {
489                                  fscanf(fin, "%*d %*d");
490 <                        if ((*getval)(scanln[x], fin) < 0) {
490 >                                if (fin2 != NULL) {
491 >                                        fscanf(fin2, "%*d %*d");
492 >                                        fscanf(fin3, "%*d %*d");
493 >                                }
494 >                        }
495 >                        if ((*getval)(scanln[x]) < 0) {
496                                  fprintf(stderr, "%s: read error\n", progname);
497                                  quit(1);
498                          }
499                          if (dogamma)
500                                  setcolor(scanln[x],
501 <                                        pow(colval(scanln[x],RED), gamma),
502 <                                        pow(colval(scanln[x],GRN), gamma),
503 <                                        pow(colval(scanln[x],BLU), gamma));
501 >                                        pow(colval(scanln[x],RED), gamcor),
502 >                                        pow(colval(scanln[x],GRN), gamcor),
503 >                                        pow(colval(scanln[x],BLU), gamcor));
504 >                        if (doexposure)
505 >                                multcolor(scanln[x], exposure);
506                  }
507 <                if (fwritescan(scanln, xres, stdout) < 0) {
507 >                if (fwritescan(scanln, scanlen(&picres), stdout) < 0) {
508                          fprintf(stderr, "%s: write error\n", progname);
509                          quit(1);
510                  }
511          }
512 <        free((char *)scanln);
512 >        free((void *)scanln);
513   }
514  
515  
516 + void
517   quit(code)
518   int  code;
519   {
# Line 305 | Line 521 | int  code;
521   }
522  
523  
524 < getcascii(col, fp)              /* get an ascii color value from fp */
525 < COLOR  col;
526 < FILE  *fp;
524 > static int
525 > getcascii(              /* get an ascii color value from stream(s) */
526 >        COLOR  col
527 > )
528   {
529 <        double  vd[3];
529 >        double  vd[3];
530  
531 <        if (fscanf(fp, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3)
532 <                return(-1);
533 <        setcolor(col, vd[0], vd[1], vd[2]);
531 >        if (fin2 == NULL) {
532 >                if (fscanf(fin, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3)
533 >                        return(-1);
534 >        } else {
535 >                if (fscanf(fin, "%lf", &vd[0]) != 1 ||
536 >                                fscanf(fin2, "%lf", &vd[1]) != 1 ||
537 >                                fscanf(fin3, "%lf", &vd[2]) != 1)
538 >                        return(-1);
539 >        }
540 >        setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]);
541          return(0);
542   }
543  
544  
545 < getcdouble(col, fp)             /* get a double color value from fp */
546 < COLOR  col;
547 < FILE  *fp;
545 > static int
546 > getcdouble(             /* get a double color value from stream(s) */
547 >        COLOR  col
548 > )
549   {
550 <        double  vd[3];
550 >        double  vd[3];
551  
552 <        if (fread((char *)vd, sizeof(double), 3, fp) != 3)
553 <                return(-1);
554 <        setcolor(col, vd[0], vd[1], vd[2]);
552 >        if (fin2 == NULL) {
553 >                if (fread((char *)vd, sizeof(double), 3, fin) != 3)
554 >                        return(-1);
555 >        } else {
556 >                if (fread((char *)vd, sizeof(double), 1, fin) != 1 ||
557 >                        fread((char *)(vd+1), sizeof(double), 1, fin2) != 1 ||
558 >                        fread((char *)(vd+2), sizeof(double), 1, fin3) != 1)
559 >                        return(-1);
560 >        }
561 >        if (swapbytes)
562 >                swap64((char *)vd, 3);
563 >        setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]);
564          return(0);
565   }
566  
567  
568 < getcfloat(col, fp)              /* get a float color value from fp */
569 < COLOR  col;
570 < FILE  *fp;
568 > static int
569 > getcfloat(              /* get a float color value from stream(s) */
570 >        COLOR  col
571 > )
572   {
573          float  vf[3];
574  
575 <        if (fread((char *)vf, sizeof(float), 3, fp) != 3)
576 <                return(-1);
577 <        setcolor(col, vf[0], vf[1], vf[2]);
575 >        if (fin2 == NULL) {
576 >                if (fread((char *)vf, sizeof(float), 3, fin) != 3)
577 >                        return(-1);
578 >        } else {
579 >                if (fread((char *)vf, sizeof(float), 1, fin) != 1 ||
580 >                        fread((char *)(vf+1), sizeof(float), 1, fin2) != 1 ||
581 >                        fread((char *)(vf+2), sizeof(float), 1, fin3) != 1)
582 >                        return(-1);
583 >        }
584 >        if (swapbytes)
585 >                swap32((char *)vf, 3);
586 >        setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]);
587          return(0);
588   }
589  
590  
591 < getcint(col, fp)                /* get an int color value from fp */
592 < COLOR  col;
593 < FILE  *fp;
591 > static int
592 > getcint(                /* get an int color value from stream(s) */
593 >        COLOR  col
594 > )
595   {
596          int  vi[3];
597  
598 <        if (fscanf(fp, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3)
599 <                return(-1);
600 <        setcolor(col,(vi[0]+.5)/256.,(vi[1]+.5)/256.,(vi[2]+.5)/256.);
598 >        if (fin2 == NULL) {
599 >                if (fscanf(fin, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3)
600 >                        return(-1);
601 >        } else {
602 >                if (fscanf(fin, "%d", &vi[0]) != 1 ||
603 >                                fscanf(fin2, "%d", &vi[1]) != 1 ||
604 >                                fscanf(fin3, "%d", &vi[2]) != 1)
605 >                        return(-1);
606 >        }
607 >        setcolor(col, (vi[rord[RED]]+.5)/256.,
608 >                        (vi[rord[GRN]]+.5)/256., (vi[rord[BLU]]+.5)/256.);
609          return(0);
610   }
611  
612  
613 < getcbyte(col, fp)               /* get a byte color value from fp */
614 < COLOR  col;
615 < FILE  *fp;
613 > static int
614 > getcbyte(               /* get a byte color value from stream(s) */
615 >        COLOR  col
616 > )
617   {
618          BYTE  vb[3];
619  
620 <        if (fread((char *)vb, sizeof(BYTE), 3, fp) != 3)
621 <                return(-1);
622 <        setcolor(col,(vb[0]+.5)/256.,(vb[1]+.5)/256.,(vb[2]+.5)/256.);
620 >        if (fin2 == NULL) {
621 >                if (fread((char *)vb, sizeof(BYTE), 3, fin) != 3)
622 >                        return(-1);
623 >        } else {
624 >                if (fread((char *)vb, sizeof(BYTE), 1, fin) != 1 ||
625 >                        fread((char *)(vb+1), sizeof(BYTE), 1, fin2) != 1 ||
626 >                        fread((char *)(vb+2), sizeof(BYTE), 1, fin3) != 1)
627 >                        return(-1);
628 >        }
629 >        setcolor(col, (vb[rord[RED]]+.5)/256.,
630 >                        (vb[rord[GRN]]+.5)/256., (vb[rord[BLU]]+.5)/256.);
631          return(0);
632   }
633  
634  
635 < getbascii(col, fp)              /* get an ascii brightness value from fp */
636 < COLOR  col;
637 < FILE  *fp;
635 > static int
636 > getcword(               /* get a 16-bit color value from stream(s) */
637 >        COLOR  col
638 > )
639   {
640 <        double  vd;
640 >        uint16  vw[3];
641  
642 <        if (fscanf(fp, "%lf", &vd) != 1)
642 >        if (fin2 == NULL) {
643 >                if (fread((char *)vw, sizeof(uint16), 3, fin) != 3)
644 >                        return(-1);
645 >        } else {
646 >                if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 ||
647 >                        fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 ||
648 >                        fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1)
649 >                        return(-1);
650 >        }
651 >        if (swapbytes)
652 >                swap16((char *)vw, 3);
653 >        setcolor(col, (vw[rord[RED]]+.5)/65536.,
654 >                        (vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.);
655 >        return(0);
656 > }
657 >
658 >
659 > static int
660 > getbascii(              /* get an ascii brightness value from fin */
661 >        COLOR  col
662 > )
663 > {
664 >        double  vd;
665 >
666 >        if (fscanf(fin, "%lf", &vd) != 1)
667                  return(-1);
668          setcolor(col, vd, vd, vd);
669          return(0);
670   }
671  
672  
673 < getbdouble(col, fp)             /* get a double brightness value from fp */
674 < COLOR  col;
675 < FILE  *fp;
673 > static int
674 > getbdouble(             /* get a double brightness value from fin */
675 >        COLOR  col
676 > )
677   {
678 <        double  vd;
678 >        double  vd;
679  
680 <        if (fread((char *)&vd, sizeof(double), 1, fp) != 1)
680 >        if (fread((char *)&vd, sizeof(double), 1, fin) != 1)
681                  return(-1);
682 +        if (swapbytes)
683 +                swap64((char *)&vd, 1);
684          setcolor(col, vd, vd, vd);
685          return(0);
686   }
687  
688  
689 < getbfloat(col, fp)              /* get a float brightness value from fp */
690 < COLOR  col;
691 < FILE  *fp;
689 > static int
690 > getbfloat(              /* get a float brightness value from fin */
691 >        COLOR  col
692 > )
693   {
694          float  vf;
695  
696 <        if (fread((char *)&vf, sizeof(float), 1, fp) != 1)
696 >        if (fread((char *)&vf, sizeof(float), 1, fin) != 1)
697                  return(-1);
698 +        if (swapbytes)
699 +                swap32((char *)&vf, 1);
700          setcolor(col, vf, vf, vf);
701          return(0);
702   }
703  
704  
705 < getbint(col, fp)                /* get an int brightness value from fp */
706 < COLOR  col;
707 < FILE  *fp;
705 > static int
706 > getbint(                /* get an int brightness value from fin */
707 >        COLOR  col
708 > )
709   {
710          int  vi;
711 <        double  d;
711 >        double  d;
712  
713 <        if (fscanf(fp, "%d", &vi) != 1)
713 >        if (fscanf(fin, "%d", &vi) != 1)
714                  return(-1);
715          d = (vi+.5)/256.;
716          setcolor(col, d, d, d);
# Line 424 | Line 718 | FILE  *fp;
718   }
719  
720  
721 < getbbyte(col, fp)               /* get a byte brightness value from fp */
722 < COLOR  col;
723 < FILE  *fp;
721 > static int
722 > getbbyte(               /* get a byte brightness value from fin */
723 >        COLOR  col
724 > )
725   {
726          BYTE  vb;
727 <        double  d;
727 >        double  d;
728  
729 <        if (fread((char *)&vb, sizeof(BYTE), 1, fp) != 1)
729 >        if (fread((char *)&vb, sizeof(BYTE), 1, fin) != 1)
730                  return(-1);
731          d = (vb+.5)/256.;
732          setcolor(col, d, d, d);
# Line 439 | Line 734 | FILE  *fp;
734   }
735  
736  
737 < putcascii(col, fp)                      /* put an ascii color to fp */
738 < COLOR  col;
739 < FILE  *fp;
737 > static int
738 > getbword(               /* get a 16-bit brightness value from fin */
739 >        COLOR  col
740 > )
741   {
742 <        fprintf(fp, "%15.3e %15.3e %15.3e\n",
743 <                        colval(col,RED),
448 <                        colval(col,GRN),
449 <                        colval(col,BLU));
742 >        uint16  vw;
743 >        double  d;
744  
745 <        return(ferror(fp) ? -1 : 0);
745 >        if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1)
746 >                return(-1);
747 >        if (swapbytes)
748 >                swap16((char *)&vw, 1);
749 >        d = (vw+.5)/65536.;
750 >        setcolor(col, d, d, d);
751 >        return(0);
752   }
753  
754  
755 < putcfloat(col, fp)                      /* put a float color to fp */
756 < COLOR  col;
757 < FILE  *fp;
755 > static int
756 > putcascii(                      /* put an ascii color to stdout */
757 >        COLOR  col
758 > )
759   {
760 +        fprintf(stdout, "%15.3e %15.3e %15.3e\n",
761 +                        colval(col,ord[0]),
762 +                        colval(col,ord[1]),
763 +                        colval(col,ord[2]));
764 +
765 +        return(ferror(stdout) ? -1 : 0);
766 + }
767 +
768 +
769 + static int
770 + putcfloat(                      /* put a float color to stdout */
771 +        COLOR  col
772 + )
773 + {
774          float  vf[3];
775  
776 <        vf[0] = colval(col,RED);
777 <        vf[1] = colval(col,GRN);
778 <        vf[2] = colval(col,BLU);
779 <        fwrite((char *)vf, sizeof(float), 3, fp);
776 >        vf[0] = colval(col,ord[0]);
777 >        vf[1] = colval(col,ord[1]);
778 >        vf[2] = colval(col,ord[2]);
779 >        if (swapbytes)
780 >                swap32((char *)vf, 3);
781 >        fwrite((char *)vf, sizeof(float), 3, stdout);
782  
783 <        return(ferror(fp) ? -1 : 0);
783 >        return(ferror(stdout) ? -1 : 0);
784   }
785  
786  
787 < putcdouble(col, fp)                     /* put a double color to fp */
788 < COLOR  col;
789 < FILE  *fp;
787 > static int
788 > putcdouble(                     /* put a double color to stdout */
789 >        COLOR  col
790 > )
791   {
792 <        double  vd[3];
792 >        double  vd[3];
793  
794 <        vd[0] = colval(col,RED);
795 <        vd[1] = colval(col,GRN);
796 <        vd[2] = colval(col,BLU);
797 <        fwrite((char *)vd, sizeof(double), 3, fp);
794 >        vd[0] = colval(col,ord[0]);
795 >        vd[1] = colval(col,ord[1]);
796 >        vd[2] = colval(col,ord[2]);
797 >        if (swapbytes)
798 >                swap64((char *)vd, 3);
799 >        fwrite((char *)vd, sizeof(double), 3, stdout);
800  
801 <        return(ferror(fp) ? -1 : 0);
801 >        return(ferror(stdout) ? -1 : 0);
802   }
803  
804  
805 < putcint(col, fp)                        /* put an int color to fp */
806 < COLOR  col;
807 < FILE  *fp;
805 > static int
806 > putcint(                        /* put an int color to stdout */
807 >        COLOR  col
808 > )
809   {
810 <        fprintf(fp, "%d %d %d\n",
811 <                        (int)(colval(col,RED)*256.),
812 <                        (int)(colval(col,GRN)*256.),
813 <                        (int)(colval(col,BLU)*256.));
810 >        fprintf(stdout, "%d %d %d\n",
811 >                        (int)(colval(col,ord[0])*256.),
812 >                        (int)(colval(col,ord[1])*256.),
813 >                        (int)(colval(col,ord[2])*256.));
814  
815 <        return(ferror(fp) ? -1 : 0);
815 >        return(ferror(stdout) ? -1 : 0);
816   }
817  
818  
819 < putcbyte(col, fp)                       /* put a byte color to fp */
820 < COLOR  col;
821 < FILE  *fp;
819 > static int
820 > putcbyte(                       /* put a byte color to stdout */
821 >        COLOR  col
822 > )
823   {
824 <        register int  i;
824 >        long  i;
825          BYTE  vb[3];
826  
827 <        i = colval(col,RED)*256.;
827 >        i = colval(col,ord[0])*256.;
828          vb[0] = min(i,255);
829 <        i = colval(col,GRN)*256.;
829 >        i = colval(col,ord[1])*256.;
830          vb[1] = min(i,255);
831 <        i = colval(col,BLU)*256.;
831 >        i = colval(col,ord[2])*256.;
832          vb[2] = min(i,255);
833 <        fwrite((char *)vb, sizeof(BYTE), 3, fp);
833 >        fwrite((char *)vb, sizeof(BYTE), 3, stdout);
834  
835 <        return(ferror(fp) ? -1 : 0);
835 >        return(ferror(stdout) ? -1 : 0);
836   }
837  
838  
839 < putbascii(col, fp)                      /* put an ascii brightness to fp */
840 < COLOR  col;
841 < FILE  *fp;
839 > static int
840 > putcword(                       /* put a 16-bit color to stdout */
841 >        COLOR  col
842 > )
843   {
844 <        fprintf(fp, "%15.3e\n", bright(col));
844 >        long  i;
845 >        uint16  vw[3];
846  
847 <        return(ferror(fp) ? -1 : 0);
847 >        i = colval(col,ord[0])*65536.;
848 >        vw[0] = min(i,65535);
849 >        i = colval(col,ord[1])*65536.;
850 >        vw[1] = min(i,65535);
851 >        i = colval(col,ord[2])*65536.;
852 >        vw[2] = min(i,65535);
853 >        if (swapbytes)
854 >                swap16((char *)vw, 3);
855 >        fwrite((char *)vw, sizeof(uint16), 3, stdout);
856 >
857 >        return(ferror(stdout) ? -1 : 0);
858   }
859  
860  
861 < putbfloat(col, fp)                      /* put a float brightness to fp */
862 < COLOR  col;
863 < FILE  *fp;
861 > static int
862 > putbascii(                      /* put an ascii brightness to stdout */
863 >        COLOR  col
864 > )
865   {
866 +        fprintf(stdout, "%15.3e\n", (*mybright)(col));
867 +
868 +        return(ferror(stdout) ? -1 : 0);
869 + }
870 +
871 +
872 + static int
873 + putbfloat(                      /* put a float brightness to stdout */
874 +        COLOR  col
875 + )
876 + {
877          float  vf;
878  
879 <        vf = bright(col);
880 <        fwrite((char *)&vf, sizeof(float), 1, fp);
879 >        vf = (*mybright)(col);
880 >        if (swapbytes)
881 >                swap32((char *)&vf, 1);
882 >        fwrite((char *)&vf, sizeof(float), 1, stdout);
883  
884 <        return(ferror(fp) ? -1 : 0);
884 >        return(ferror(stdout) ? -1 : 0);
885   }
886  
887  
888 < putbdouble(col, fp)                     /* put a double brightness to fp */
889 < COLOR  col;
890 < FILE  *fp;
888 > static int
889 > putbdouble(                     /* put a double brightness to stdout */
890 >        COLOR  col
891 > )
892   {
893 <        double  vd;
893 >        double  vd;
894  
895 <        vd = bright(col);
896 <        fwrite((char *)&vd, sizeof(double), 1, fp);
895 >        vd = (*mybright)(col);
896 >        if (swapbytes)
897 >                swap64((char *)&vd, 1);
898 >        fwrite((char *)&vd, sizeof(double), 1, stdout);
899  
900 <        return(ferror(fp) ? -1 : 0);
900 >        return(ferror(stdout) ? -1 : 0);
901   }
902  
903  
904 < putbint(col, fp)                        /* put an int brightness to fp */
905 < COLOR  col;
906 < FILE  *fp;
904 > static int
905 > putbint(                        /* put an int brightness to stdout */
906 >        COLOR  col
907 > )
908   {
909 <        fprintf(fp, "%d\n", (int)(bright(col)*256.));
909 >        fprintf(stdout, "%d\n", (int)((*mybright)(col)*256.));
910  
911 <        return(ferror(fp) ? -1 : 0);
911 >        return(ferror(stdout) ? -1 : 0);
912   }
913  
914  
915 < putbbyte(col, fp)                       /* put a byte brightness to fp */
916 < COLOR  col;
917 < FILE  *fp;
915 > static int
916 > putbbyte(                       /* put a byte brightness to stdout */
917 >        COLOR  col
918 > )
919   {
920          register int  i;
921          BYTE  vb;
922  
923 <        i = bright(col)*256.;
923 >        i = (*mybright)(col)*256.;
924          vb = min(i,255);
925 <        fwrite((char *)&vb, sizeof(BYTE), 1, fp);
925 >        fwrite((char *)&vb, sizeof(BYTE), 1, stdout);
926  
927 <        return(ferror(fp) ? -1 : 0);
927 >        return(ferror(stdout) ? -1 : 0);
928   }
929  
930  
931 < set_io()                        /* set put and get functions */
931 > static int
932 > putbword(                       /* put a 16-bit brightness to stdout */
933 >        COLOR  col
934 > )
935   {
936 +        long  i;
937 +        uint16  vw;
938 +
939 +        i = (*mybright)(col)*65536.;
940 +        vw = min(i,65535);
941 +        if (swapbytes)
942 +                swap16((char *)&vw, 1);
943 +        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
944 +
945 +        return(ferror(stdout) ? -1 : 0);
946 + }
947 +
948 +
949 + static int
950 + putpascii(                      /* put an ascii primary to stdout */
951 +        COLOR  col
952 + )
953 + {
954 +        fprintf(stdout, "%15.3e\n", colval(col,putprim));
955 +
956 +        return(ferror(stdout) ? -1 : 0);
957 + }
958 +
959 +
960 + static int
961 + putpfloat(                      /* put a float primary to stdout */
962 +        COLOR  col
963 + )
964 + {
965 +        float  vf;
966 +
967 +        vf = colval(col,putprim);
968 +        if (swapbytes)
969 +                swap32((char *)&vf, 1);
970 +        fwrite((char *)&vf, sizeof(float), 1, stdout);
971 +
972 +        return(ferror(stdout) ? -1 : 0);
973 + }
974 +
975 +
976 + static int
977 + putpdouble(                     /* put a double primary to stdout */
978 +        COLOR  col
979 + )
980 + {
981 +        double  vd;
982 +
983 +        vd = colval(col,putprim);
984 +        if (swapbytes)
985 +                swap64((char *)&vd, 1);
986 +        fwrite((char *)&vd, sizeof(double), 1, stdout);
987 +
988 +        return(ferror(stdout) ? -1 : 0);
989 + }
990 +
991 +
992 + static int
993 + putpint(                        /* put an int primary to stdout */
994 +        COLOR  col
995 + )
996 + {
997 +        fprintf(stdout, "%d\n", (int)(colval(col,putprim)*256.));
998 +
999 +        return(ferror(stdout) ? -1 : 0);
1000 + }
1001 +
1002 +
1003 + static int
1004 + putpbyte(                       /* put a byte primary to stdout */
1005 +        COLOR  col
1006 + )
1007 + {
1008 +        long  i;
1009 +        BYTE  vb;
1010 +
1011 +        i = colval(col,putprim)*256.;
1012 +        vb = min(i,255);
1013 +        fwrite((char *)&vb, sizeof(BYTE), 1, stdout);
1014 +
1015 +        return(ferror(stdout) ? -1 : 0);
1016 + }
1017 +
1018 +
1019 + static int
1020 + putpword(                       /* put a 16-bit primary to stdout */
1021 +        COLOR  col
1022 + )
1023 + {
1024 +        long  i;
1025 +        uint16  vw;
1026 +
1027 +        i = colval(col,putprim)*65536.;
1028 +        vw = min(i,65535);
1029 +        if (swapbytes)
1030 +                swap16((char *)&vw, 1);
1031 +        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
1032 +
1033 +        return(ferror(stdout) ? -1 : 0);
1034 + }
1035 +
1036 +
1037 + static void
1038 + set_io(void)                    /* set put and get functions */
1039 + {
1040          switch (format) {
1041          case 'a':                                       /* ascii */
1042 <                if (brightonly) {
1042 >                if (putprim == BRIGHT) {
1043                          getval = getbascii;
1044                          putval = putbascii;
1045 +                } else if (putprim != ALL) {
1046 +                        getval = getbascii;
1047 +                        putval = putpascii;
1048                  } else {
1049                          getval = getcascii;
1050                          putval = putcascii;
1051 +                        if (reverse && !interleave) {
1052 +                                fprintf(stderr,
1053 +                                "%s: ASCII input files must be interleaved\n",
1054 +                                                progname);
1055 +                                quit(1);
1056 +                        }
1057                  }
1058                  return;
1059          case 'f':                                       /* binary float */
1060 <                if (brightonly) {
1060 >                if (putprim == BRIGHT) {
1061                          getval = getbfloat;
1062                          putval = putbfloat;
1063 +                } else if (putprim != ALL) {
1064 +                        getval = getbfloat;
1065 +                        putval = putpfloat;
1066                  } else {
1067                          getval = getcfloat;
1068                          putval = putcfloat;
1069 +                        if (reverse && !interleave) {
1070 +                                if (fin2 == NULL)
1071 +                                        goto namerr;
1072 +                                if (fseek(fin2,
1073 +                                (long)sizeof(float)*picres.xr*picres.yr, 1))
1074 +                                        goto seekerr;
1075 +                                if (fseek(fin3,
1076 +                                (long)sizeof(float)*2*picres.xr*picres.yr, 1))
1077 +                                        goto seekerr;
1078 +                        }
1079                  }
1080                  return;
1081          case 'd':                                       /* binary double */
1082 <                if (brightonly) {
1082 >                if (putprim == BRIGHT) {
1083                          getval = getbdouble;
1084                          putval = putbdouble;
1085 +                } else if (putprim != ALL) {
1086 +                        getval = getbdouble;
1087 +                        putval = putpdouble;
1088                  } else {
1089                          getval = getcdouble;
1090                          putval = putcdouble;
1091 +                        if (reverse && !interleave) {
1092 +                                if (fin2 == NULL)
1093 +                                        goto namerr;
1094 +                                if (fseek(fin2,
1095 +                                (long)sizeof(double)*picres.xr*picres.yr, 1))
1096 +                                        goto seekerr;
1097 +                                if (fseek(fin3,
1098 +                                (long)sizeof(double)*2*picres.xr*picres.yr, 1))
1099 +                                        goto seekerr;
1100 +                        }
1101                  }
1102                  return;
1103          case 'i':                                       /* integer */
1104 <                if (brightonly) {
1104 >                if (putprim == BRIGHT) {
1105                          getval = getbint;
1106                          putval = putbint;
1107 +                } else if (putprim != ALL) {
1108 +                        getval = getbint;
1109 +                        putval = putpint;
1110                  } else {
1111                          getval = getcint;
1112                          putval = putcint;
1113 +                        if (reverse && !interleave) {
1114 +                                fprintf(stderr,
1115 +                                "%s: integer input files must be interleaved\n",
1116 +                                                progname);
1117 +                                quit(1);
1118 +                        }
1119                  }
1120                  return;
1121          case 'b':                                       /* byte */
1122 <                if (brightonly) {
1122 >                if (putprim == BRIGHT) {
1123                          getval = getbbyte;
1124                          putval = putbbyte;
1125 +                } else if (putprim != ALL) {
1126 +                        getval = getbbyte;
1127 +                        putval = putpbyte;
1128                  } else {
1129                          getval = getcbyte;
1130                          putval = putcbyte;
1131 +                        if (reverse && !interleave) {
1132 +                                if (fin2 == NULL)
1133 +                                        goto namerr;
1134 +                                if (fseek(fin2,
1135 +                                (long)sizeof(BYTE)*picres.xr*picres.yr, 1))
1136 +                                        goto seekerr;
1137 +                                if (fseek(fin3,
1138 +                                (long)sizeof(BYTE)*2*picres.xr*picres.yr, 1))
1139 +                                        goto seekerr;
1140 +                        }
1141                  }
1142                  return;
1143 +        case 'w':                                       /* 16-bit */
1144 +                if (putprim == BRIGHT) {
1145 +                        getval = getbword;
1146 +                        putval = putbword;
1147 +                } else if (putprim != ALL) {
1148 +                        getval = getbword;
1149 +                        putval = putpword;
1150 +                } else {
1151 +                        getval = getcword;
1152 +                        putval = putcword;
1153 +                        if (reverse && !interleave) {
1154 +                                if (fin2 == NULL)
1155 +                                        goto namerr;
1156 +                                if (fseek(fin2,
1157 +                                (long)sizeof(uint16)*picres.xr*picres.yr, 1))
1158 +                                        goto seekerr;
1159 +                                if (fseek(fin3,
1160 +                                (long)sizeof(uint16)*2*picres.xr*picres.yr, 1))
1161 +                                        goto seekerr;
1162 +                        }
1163 +                }
1164 +                return;
1165          }
1166 + /* badopt: */ /* label not used */
1167 +        fprintf(stderr, "%s: botched file type\n", progname);
1168 +        quit(1);
1169 + namerr:
1170 +        fprintf(stderr, "%s: non-interleaved file(s) must be named\n",
1171 +                        progname);
1172 +        quit(1);
1173 + seekerr:
1174 +        fprintf(stderr, "%s: cannot seek on interleaved input file\n",
1175 +                        progname);
1176 +        quit(1);
1177   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines