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 2.10 by greg, Wed Jan 8 07:43:49 1997 UTC vs.
Revision 2.40 by greg, Tue Jun 30 22:30:29 2020 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines