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.39 by greg, Mon Mar 30 19:02:26 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 +                                fputendian(stdout);
391                          fputformat(fmtid, stdout);
392                          putchar('\n');
393                  }
# Line 309 | Line 397 | unkopt:
397          }
398  
399          quit(0);
400 < seekerr:
313 <        fprintf(stderr, "%s: cannot skip %ld bytes on input\n",
314 <                        progname, skipbytes);
315 <        quit(1);
400 >        return 0; /* pro forma return */
401   }
402  
403  
404 < checkhead(line)                         /* deal with line from header */
405 < char  *line;
404 > static int
405 > checkhead(                              /* deal with line from header */
406 >        char    *line,
407 >        void    *p
408 > )
409   {
410 <        char    fmt[32];
410 >        FILE    *fout = (FILE *)p;
411 >        char    fmt[MAXFMTLEN];
412          double  d;
413          COLOR   ctmp;
414 +        int     rv;
415  
416 <        if (formatval(fmt, line))
417 <                wrongformat = strcmp(fmt, COLRFMT);
418 <        else if (original && isexpos(line)) {
416 >        if (formatval(fmt, line)) {
417 >                if (reverse)
418 >                        wrongformat = strcmp(fmt, fmtid);
419 >                else if (!strcmp(fmt, CIEFMT))
420 >                        mybright = &xyz_bright;
421 >                else if (!strcmp(fmt, COLRFMT))
422 >                        mybright = &rgb_bright;
423 >                else
424 >                        wrongformat++;
425 >                return(1);
426 >        }
427 >        if (original && isexpos(line)) {
428                  d = 1.0/exposval(line);
429                  scalecolor(exposure, d);
430                  doexposure++;
431 <        } else if (original && iscolcor(line)) {
431 >                return(1);
432 >        }
433 >        if (original && iscolcor(line)) {
434                  colcorval(ctmp, line);
435                  setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED),
436                                  colval(exposure,GRN)/colval(ctmp,GRN),
437                                  colval(exposure,BLU)/colval(ctmp,BLU));
438                  doexposure++;
439 <        } else if (header)
440 <                fputs(line, stdout);
439 >                return(1);
440 >        }
441 >        if ((rv = isbigendian(line)) >= 0) {
442 >                if (reverse)
443 >                        swapbytes = (nativebigendian() != rv);
444 >                return(1);
445 >        }
446 >        if (fout != NULL)
447 >                fputs(line, fout);
448 >        return(0);
449   }
450  
451  
452 < pixtoval()                              /* convert picture to values */
452 > static void
453 > pixtoval(void)                          /* convert picture to values */
454   {
455 <        register COLOR  *scanln;
455 >        COLOR   *scanln;
456          int  dogamma;
457          COLOR  lastc;
458 <        FLOAT  hv[2];
459 <        int  y;
460 <        register int  x;
458 >        RREAL  hv[2];
459 >        int  startprim, endprim;
460 >        long  startpos;
461 >        int  x, y;
462  
463          scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
464          if (scanln == NULL) {
# Line 355 | Line 466 | pixtoval()                             /* convert picture to values */
466                  quit(1);
467          }
468          dogamma = gamcor < .95 || gamcor > 1.05;
469 <        setcolor(lastc, 0.0, 0.0, 0.0);
470 <        for (y = 0; y < numscans(&picres); y++) {
471 <                if (freadscan(scanln, scanlen(&picres), fin) < 0) {
472 <                        fprintf(stderr, "%s: read error\n", progname);
469 >        if ((putprim == ALL) & !interleave) {
470 >                startprim = RED; endprim = BLU;
471 >                startpos = ftell(fin);
472 >        } else {
473 >                startprim = putprim; endprim = putprim;
474 >        }
475 >        for (putprim = startprim; putprim <= endprim; putprim++) {
476 >                if (putprim != startprim && fseek(fin, startpos, SEEK_SET)) {
477 >                        fprintf(stderr, "%s: seek error on input file\n",
478 >                                        progname);
479                          quit(1);
480                  }
481 <                for (x = 0; x < scanlen(&picres); x++) {
482 <                        if (uniq)
483 <                                if (    colval(scanln[x],RED) ==
484 <                                                colval(lastc,RED) &&
485 <                                        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);
481 >                set_io();
482 >                setcolor(lastc, 0.0, 0.0, 0.0);
483 >                for (y = 0; y < numscans(&picres); y++) {
484 >                        if (freadscan(scanln, scanlen(&picres), fin) < 0) {
485 >                                fprintf(stderr, "%s: read error\n", progname);
486                                  quit(1);
487                          }
488 +                        for (x = 0; x < scanlen(&picres); x++) {
489 +                                if (uniq) {
490 +                                        if (    colval(scanln[x],RED) ==
491 +                                                        colval(lastc,RED) &&
492 +                                                colval(scanln[x],GRN) ==
493 +                                                        colval(lastc,GRN) &&
494 +                                                colval(scanln[x],BLU) ==
495 +                                                        colval(lastc,BLU)       )
496 +                                                continue;
497 +                                        else
498 +                                                copycolor(lastc, scanln[x]);
499 +                                }
500 +                                if (doexposure)
501 +                                        multcolor(scanln[x], exposure);
502 +                                if (dogamma)
503 +                                        setcolor(scanln[x],
504 +                                        pow(colval(scanln[x],RED), 1.0/gamcor),
505 +                                        pow(colval(scanln[x],GRN), 1.0/gamcor),
506 +                                        pow(colval(scanln[x],BLU), 1.0/gamcor));
507 +                                if (!dataonly) {
508 +                                        pix2loc(hv, &picres, x, y);
509 +                                        printf("%7d %7d ",
510 +                                                        (int)(hv[0]*picres.xr),
511 +                                                        (int)(hv[1]*picres.yr));
512 +                                }
513 +                                if ((*putval)(scanln[x]) < 0) {
514 +                                        fprintf(stderr, "%s: write error\n",
515 +                                                        progname);
516 +                                        quit(1);
517 +                                }
518 +                        }
519                  }
520          }
521 <        free((char *)scanln);
521 >        free((void *)scanln);
522   }
523  
524  
525 < valtopix()                      /* convert values to a pixel file */
525 > static void
526 > valtopix(void)                  /* convert values to a pixel file */
527   {
528 <        int  dogamma;
529 <        register COLOR  *scanln;
530 <        int  y;
531 <        register int  x;
528 >        int     dogamma;
529 >        COLOR   *scanln;
530 >        COLR    rgbe;
531 >        int     x, y;
532  
533          scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
534          if (scanln == NULL) {
# Line 407 | Line 536 | valtopix()                     /* convert values to a pixel file */
536                  quit(1);
537          }
538          dogamma = gamcor < .95 || gamcor > 1.05;
539 +        set_io();
540          for (y = 0; y < numscans(&picres); y++) {
541                  for (x = 0; x < scanlen(&picres); x++) {
542                          if (!dataonly) {
# Line 416 | Line 546 | valtopix()                     /* convert values to a pixel file */
546                                          fscanf(fin3, "%*d %*d");
547                                  }
548                          }
549 <                        if ((*getval)(scanln[x], fin, fin2, fin3) < 0) {
549 >                        if ((*getval)(scanln[x]) < 0) {
550                                  fprintf(stderr, "%s: read error\n", progname);
551                                  quit(1);
552                          }
# Line 427 | Line 557 | valtopix()                     /* convert values to a pixel file */
557                                          pow(colval(scanln[x],BLU), gamcor));
558                          if (doexposure)
559                                  multcolor(scanln[x], exposure);
560 +                        if (uniq) {             /* uncompressed? */
561 +                                setcolr(rgbe,   scanln[x][RED],
562 +                                                scanln[x][GRN],
563 +                                                scanln[x][BLU]);
564 +                                if (putbinary(rgbe, sizeof(COLR), 1, stdout) != 1)
565 +                                        goto writerr;
566 +                        }
567                  }
568 <                if (fwritescan(scanln, scanlen(&picres), stdout) < 0) {
569 <                        fprintf(stderr, "%s: write error\n", progname);
570 <                        quit(1);
434 <                }
568 >                                                /* write scan if compressed */
569 >                if (!uniq && fwritescan(scanln, scanlen(&picres), stdout) < 0)
570 >                        goto writerr;
571          }
572 <        free((char *)scanln);
572 >        free((void *)scanln);
573 >        return;
574 > writerr:
575 >        fprintf(stderr, "%s: write error\n", progname);
576 >        quit(1);
577   }
578  
579  
580 + void
581   quit(code)
582   int  code;
583   {
# Line 444 | Line 585 | int  code;
585   }
586  
587  
588 < getcascii(col, f1, f2, f3)      /* get an ascii color value from stream(s) */
589 < COLOR  col;
590 < FILE  *f1, *f2, *f3;
588 > static int
589 > getcascii(              /* get an ascii color value from stream(s) */
590 >        COLOR  col
591 > )
592   {
593          double  vd[3];
594  
595 <        if (f2 == NULL) {
596 <                if (fscanf(f1, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3)
595 >        if (fin2 == NULL) {
596 >                if (fscanf(fin, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3)
597                          return(-1);
598          } else {
599 <                if (fscanf(f1, "%lf", &vd[0]) != 1 ||
600 <                                fscanf(f2, "%lf", &vd[1]) != 1 ||
601 <                                fscanf(f3, "%lf", &vd[2]) != 1)
599 >                if (fscanf(fin, "%lf", &vd[0]) != 1 ||
600 >                                fscanf(fin2, "%lf", &vd[1]) != 1 ||
601 >                                fscanf(fin3, "%lf", &vd[2]) != 1)
602                          return(-1);
603          }
604          setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]);
# Line 464 | Line 606 | FILE  *f1, *f2, *f3;
606   }
607  
608  
609 < getcdouble(col, f1, f2, f3)     /* get a double color value from stream(s) */
610 < COLOR  col;
611 < FILE  *f1, *f2, *f3;
609 > static int
610 > getcdouble(             /* get a double color value from stream(s) */
611 >        COLOR  col
612 > )
613   {
614          double  vd[3];
615  
616 <        if (f2 == NULL) {
617 <                if (fread((char *)vd, sizeof(double), 3, f1) != 3)
616 >        if (fin2 == NULL) {
617 >                if (getbinary(vd, sizeof(double), 3, fin) != 3)
618                          return(-1);
619          } else {
620 <                if (fread((char *)vd, sizeof(double), 1, f1) != 1 ||
621 <                        fread((char *)(vd+1), sizeof(double), 1, f2) != 1 ||
622 <                        fread((char *)(vd+2), sizeof(double), 1, f3) != 1)
620 >                if (getbinary(vd, sizeof(double), 1, fin) != 1 ||
621 >                        getbinary(vd+1, sizeof(double), 1, fin2) != 1 ||
622 >                        getbinary(vd+2, sizeof(double), 1, fin3) != 1)
623                          return(-1);
624          }
625 +        if (swapbytes)
626 +                swap64((char *)vd, 3);
627          setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]);
628          return(0);
629   }
630  
631  
632 < getcfloat(col, f1, f2, f3)      /* get a float color value from stream(s) */
633 < COLOR  col;
634 < FILE  *f1, *f2, *f3;
632 > static int
633 > getcfloat(              /* get a float color value from stream(s) */
634 >        COLOR  col
635 > )
636   {
637          float  vf[3];
638  
639 <        if (f2 == NULL) {
640 <                if (fread((char *)vf, sizeof(float), 3, f1) != 3)
639 >        if (fin2 == NULL) {
640 >                if (getbinary(vf, sizeof(float), 3, fin) != 3)
641                          return(-1);
642          } else {
643 <                if (fread((char *)vf, sizeof(float), 1, f1) != 1 ||
644 <                        fread((char *)(vf+1), sizeof(float), 1, f2) != 1 ||
645 <                        fread((char *)(vf+2), sizeof(float), 1, f3) != 1)
643 >                if (getbinary(vf, sizeof(float), 1, fin) != 1 ||
644 >                        getbinary(vf+1, sizeof(float), 1, fin2) != 1 ||
645 >                        getbinary(vf+2, sizeof(float), 1, fin3) != 1)
646                          return(-1);
647          }
648 +        if (swapbytes)
649 +                swap32((char *)vf, 3);
650          setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]);
651          return(0);
652   }
653  
654  
655 < getcint(col, f1, f2, f3)        /* get an int color value from stream(s) */
656 < COLOR  col;
657 < FILE  *f1, *f2, *f3;
655 > static int
656 > getcint(                /* get an int color value from stream(s) */
657 >        COLOR  col
658 > )
659   {
660          int  vi[3];
661  
662 <        if (f2 == NULL) {
663 <                if (fscanf(f1, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3)
662 >        if (fin2 == NULL) {
663 >                if (fscanf(fin, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3)
664                          return(-1);
665          } else {
666 <                if (fscanf(f1, "%d", &vi[0]) != 1 ||
667 <                                fscanf(f2, "%d", &vi[1]) != 1 ||
668 <                                fscanf(f3, "%d", &vi[2]) != 1)
666 >                if (fscanf(fin, "%d", &vi[0]) != 1 ||
667 >                                fscanf(fin2, "%d", &vi[1]) != 1 ||
668 >                                fscanf(fin3, "%d", &vi[2]) != 1)
669                          return(-1);
670          }
671          setcolor(col, (vi[rord[RED]]+.5)/256.,
# Line 525 | Line 674 | FILE  *f1, *f2, *f3;
674   }
675  
676  
677 < getcbyte(col, f1, f2, f3)       /* get a byte color value from stream(s) */
678 < COLOR  col;
679 < FILE  *f1, *f2, *f3;
677 > static int
678 > getcbyte(               /* get a byte color value from stream(s) */
679 >        COLOR  col
680 > )
681   {
682 <        BYTE  vb[3];
682 >        uby8  vb[3];
683  
684 <        if (f2 == NULL) {
685 <                if (fread((char *)vb, sizeof(BYTE), 3, f1) != 3)
684 >        if (fin2 == NULL) {
685 >                if (getbinary(vb, sizeof(uby8), 3, fin) != 3)
686                          return(-1);
687          } else {
688 <                if (fread((char *)vb, sizeof(BYTE), 1, f1) != 1 ||
689 <                        fread((char *)(vb+1), sizeof(BYTE), 1, f2) != 1 ||
690 <                        fread((char *)(vb+2), sizeof(BYTE), 1, f3) != 1)
688 >                if (getbinary(vb, sizeof(uby8), 1, fin) != 1 ||
689 >                        getbinary(vb+1, sizeof(uby8), 1, fin2) != 1 ||
690 >                        getbinary(vb+2, sizeof(uby8), 1, fin3) != 1)
691                          return(-1);
692          }
693          setcolor(col, (vb[rord[RED]]+.5)/256.,
# Line 546 | Line 696 | FILE  *f1, *f2, *f3;
696   }
697  
698  
699 < getbascii(col, fp)              /* get an ascii brightness value from fp */
700 < COLOR  col;
701 < FILE  *fp;
699 > static int
700 > getcword(               /* get a 16-bit color value from stream(s) */
701 >        COLOR  col
702 > )
703   {
704 +        uint16  vw[3];
705 +
706 +        if (fin2 == NULL) {
707 +                if (getbinary(vw, sizeof(uint16), 3, fin) != 3)
708 +                        return(-1);
709 +        } else {
710 +                if (getbinary(vw, sizeof(uint16), 1, fin) != 1 ||
711 +                        getbinary(vw+1, sizeof(uint16), 1, fin2) != 1 ||
712 +                        getbinary(vw+2, sizeof(uint16), 1, fin3) != 1)
713 +                        return(-1);
714 +        }
715 +        if (swapbytes)
716 +                swap16((char *)vw, 3);
717 +        setcolor(col, (vw[rord[RED]]+.5)/65536.,
718 +                        (vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.);
719 +        return(0);
720 + }
721 +
722 +
723 + static int
724 + getbascii(              /* get an ascii brightness value from fin */
725 +        COLOR  col
726 + )
727 + {
728          double  vd;
729  
730 <        if (fscanf(fp, "%lf", &vd) != 1)
730 >        if (fscanf(fin, "%lf", &vd) != 1)
731                  return(-1);
732          setcolor(col, vd, vd, vd);
733          return(0);
734   }
735  
736  
737 < getbdouble(col, fp)             /* get a double brightness value from fp */
738 < COLOR  col;
739 < FILE  *fp;
737 > static int
738 > getbdouble(             /* get a double brightness value from fin */
739 >        COLOR  col
740 > )
741   {
742          double  vd;
743  
744 <        if (fread((char *)&vd, sizeof(double), 1, fp) != 1)
744 >        if (getbinary(&vd, sizeof(double), 1, fin) != 1)
745                  return(-1);
746 +        if (swapbytes)
747 +                swap64((char *)&vd, 1);
748          setcolor(col, vd, vd, vd);
749          return(0);
750   }
751  
752  
753 < getbfloat(col, fp)              /* get a float brightness value from fp */
754 < COLOR  col;
755 < FILE  *fp;
753 > static int
754 > getbfloat(              /* get a float brightness value from fin */
755 >        COLOR  col
756 > )
757   {
758          float  vf;
759  
760 <        if (fread((char *)&vf, sizeof(float), 1, fp) != 1)
760 >        if (getbinary(&vf, sizeof(float), 1, fin) != 1)
761                  return(-1);
762 +        if (swapbytes)
763 +                swap32((char *)&vf, 1);
764          setcolor(col, vf, vf, vf);
765          return(0);
766   }
767  
768  
769 < getbint(col, fp)                /* get an int brightness value from fp */
770 < COLOR  col;
771 < FILE  *fp;
769 > static int
770 > getbint(                /* get an int brightness value from fin */
771 >        COLOR  col
772 > )
773   {
774          int  vi;
775          double  d;
776  
777 <        if (fscanf(fp, "%d", &vi) != 1)
777 >        if (fscanf(fin, "%d", &vi) != 1)
778                  return(-1);
779          d = (vi+.5)/256.;
780          setcolor(col, d, d, d);
# Line 600 | Line 782 | FILE  *fp;
782   }
783  
784  
785 < getbbyte(col, fp)               /* get a byte brightness value from fp */
786 < COLOR  col;
787 < FILE  *fp;
785 > static int
786 > getbbyte(               /* get a byte brightness value from fin */
787 >        COLOR  col
788 > )
789   {
790 <        BYTE  vb;
790 >        uby8  vb;
791          double  d;
792  
793 <        if (fread((char *)&vb, sizeof(BYTE), 1, fp) != 1)
793 >        if (getbinary(&vb, sizeof(uby8), 1, fin) != 1)
794                  return(-1);
795          d = (vb+.5)/256.;
796          setcolor(col, d, d, d);
# Line 615 | Line 798 | FILE  *fp;
798   }
799  
800  
801 < putcascii(col, fp)                      /* put an ascii color to fp */
802 < COLOR  col;
803 < FILE  *fp;
801 > static int
802 > getbword(               /* get a 16-bit brightness value from fin */
803 >        COLOR  col
804 > )
805   {
806 <        fprintf(fp, "%15.3e %15.3e %15.3e\n",
806 >        uint16  vw;
807 >        double  d;
808 >
809 >        if (getbinary(&vw, sizeof(uint16), 1, fin) != 1)
810 >                return(-1);
811 >        if (swapbytes)
812 >                swap16((char *)&vw, 1);
813 >        d = (vw+.5)/65536.;
814 >        setcolor(col, d, d, d);
815 >        return(0);
816 > }
817 >
818 >
819 > static int
820 > putcascii(                      /* put an ascii color to stdout */
821 >        COLOR  col
822 > )
823 > {
824 >        fprintf(stdout, "%15.3e %15.3e %15.3e\n",
825                          colval(col,ord[0]),
826                          colval(col,ord[1]),
827                          colval(col,ord[2]));
828  
829 <        return(ferror(fp) ? -1 : 0);
829 >        return(ferror(stdout) ? -1 : 0);
830   }
831  
832  
833 < putcfloat(col, fp)                      /* put a float color to fp */
834 < COLOR  col;
835 < FILE  *fp;
833 > static int
834 > putcfloat(                      /* put a float color to stdout */
835 >        COLOR  col
836 > )
837   {
838          float  vf[3];
839  
840          vf[0] = colval(col,ord[0]);
841          vf[1] = colval(col,ord[1]);
842          vf[2] = colval(col,ord[2]);
843 <        fwrite((char *)vf, sizeof(float), 3, fp);
843 >        if (swapbytes)
844 >                swap32((char *)vf, 3);
845 >        putbinary(vf, sizeof(float), 3, stdout);
846  
847 <        return(ferror(fp) ? -1 : 0);
847 >        return(ferror(stdout) ? -1 : 0);
848   }
849  
850  
851 < putcdouble(col, fp)                     /* put a double color to fp */
852 < COLOR  col;
853 < FILE  *fp;
851 > static int
852 > putcdouble(                     /* put a double color to stdout */
853 >        COLOR  col
854 > )
855   {
856          double  vd[3];
857  
858          vd[0] = colval(col,ord[0]);
859          vd[1] = colval(col,ord[1]);
860          vd[2] = colval(col,ord[2]);
861 <        fwrite((char *)vd, sizeof(double), 3, fp);
861 >        if (swapbytes)
862 >                swap64((char *)vd, 3);
863 >        putbinary(vd, sizeof(double), 3, stdout);
864  
865 <        return(ferror(fp) ? -1 : 0);
865 >        return(ferror(stdout) ? -1 : 0);
866   }
867  
868  
869 < putcint(col, fp)                        /* put an int color to fp */
870 < COLOR  col;
871 < FILE  *fp;
869 > static int
870 > putcint(                        /* put an int color to stdout */
871 >        COLOR  col
872 > )
873   {
874 <        fprintf(fp, "%d %d %d\n",
874 >        fprintf(stdout, "%d %d %d\n",
875                          (int)(colval(col,ord[0])*256.),
876                          (int)(colval(col,ord[1])*256.),
877                          (int)(colval(col,ord[2])*256.));
878  
879 <        return(ferror(fp) ? -1 : 0);
879 >        return(ferror(stdout) ? -1 : 0);
880   }
881  
882  
883 < putcbyte(col, fp)                       /* put a byte color to fp */
884 < COLOR  col;
885 < FILE  *fp;
883 > static int
884 > putcbyte(                       /* put a byte color to stdout */
885 >        COLOR  col
886 > )
887   {
888 <        register int  i;
889 <        BYTE  vb[3];
888 >        long  i;
889 >        uby8  vb[3];
890  
891          i = colval(col,ord[0])*256.;
892          vb[0] = min(i,255);
# Line 684 | Line 894 | FILE  *fp;
894          vb[1] = min(i,255);
895          i = colval(col,ord[2])*256.;
896          vb[2] = min(i,255);
897 <        fwrite((char *)vb, sizeof(BYTE), 3, fp);
897 >        putbinary(vb, sizeof(uby8), 3, stdout);
898  
899 <        return(ferror(fp) ? -1 : 0);
899 >        return(ferror(stdout) ? -1 : 0);
900   }
901  
902  
903 < putbascii(col, fp)                      /* put an ascii brightness to fp */
904 < COLOR  col;
905 < FILE  *fp;
903 > static int
904 > putcword(                       /* put a 16-bit color to stdout */
905 >        COLOR  col
906 > )
907   {
908 <        fprintf(fp, "%15.3e\n", bright(col));
908 >        long  i;
909 >        uint16  vw[3];
910  
911 <        return(ferror(fp) ? -1 : 0);
911 >        i = colval(col,ord[0])*65536.;
912 >        vw[0] = min(i,65535);
913 >        i = colval(col,ord[1])*65536.;
914 >        vw[1] = min(i,65535);
915 >        i = colval(col,ord[2])*65536.;
916 >        vw[2] = min(i,65535);
917 >        if (swapbytes)
918 >                swap16((char *)vw, 3);
919 >        putbinary(vw, sizeof(uint16), 3, stdout);
920 >
921 >        return(ferror(stdout) ? -1 : 0);
922   }
923  
924  
925 < putbfloat(col, fp)                      /* put a float brightness to fp */
926 < COLOR  col;
927 < FILE  *fp;
925 > static int
926 > putbascii(                      /* put an ascii brightness to stdout */
927 >        COLOR  col
928 > )
929   {
930 +        fprintf(stdout, "%15.3e\n", (*mybright)(col));
931 +
932 +        return(ferror(stdout) ? -1 : 0);
933 + }
934 +
935 +
936 + static int
937 + putbfloat(                      /* put a float brightness to stdout */
938 +        COLOR  col
939 + )
940 + {
941          float  vf;
942  
943 <        vf = bright(col);
944 <        fwrite((char *)&vf, sizeof(float), 1, fp);
943 >        vf = (*mybright)(col);
944 >        if (swapbytes)
945 >                swap32((char *)&vf, 1);
946 >        putbinary(&vf, sizeof(float), 1, stdout);
947  
948 <        return(ferror(fp) ? -1 : 0);
948 >        return(ferror(stdout) ? -1 : 0);
949   }
950  
951  
952 < putbdouble(col, fp)                     /* put a double brightness to fp */
953 < COLOR  col;
954 < FILE  *fp;
952 > static int
953 > putbdouble(                     /* put a double brightness to stdout */
954 >        COLOR  col
955 > )
956   {
957          double  vd;
958  
959 <        vd = bright(col);
960 <        fwrite((char *)&vd, sizeof(double), 1, fp);
959 >        vd = (*mybright)(col);
960 >        if (swapbytes)
961 >                swap64((char *)&vd, 1);
962 >        putbinary(&vd, sizeof(double), 1, stdout);
963  
964 <        return(ferror(fp) ? -1 : 0);
964 >        return(ferror(stdout) ? -1 : 0);
965   }
966  
967  
968 < putbint(col, fp)                        /* put an int brightness to fp */
969 < COLOR  col;
970 < FILE  *fp;
968 > static int
969 > putbint(                        /* put an int brightness to stdout */
970 >        COLOR  col
971 > )
972   {
973 <        fprintf(fp, "%d\n", (int)(bright(col)*256.));
973 >        fprintf(stdout, "%d\n", (int)((*mybright)(col)*256.));
974  
975 <        return(ferror(fp) ? -1 : 0);
975 >        return(ferror(stdout) ? -1 : 0);
976   }
977  
978  
979 < putbbyte(col, fp)                       /* put a byte brightness to fp */
980 < COLOR  col;
981 < FILE  *fp;
979 > static int
980 > putbbyte(                       /* put a byte brightness to stdout */
981 >        COLOR  col
982 > )
983   {
984 <        register int  i;
985 <        BYTE  vb;
984 >        int  i;
985 >        uby8  vb;
986  
987 <        i = bright(col)*256.;
987 >        i = (*mybright)(col)*256.;
988          vb = min(i,255);
989 <        fwrite((char *)&vb, sizeof(BYTE), 1, fp);
989 >        putbinary(&vb, sizeof(uby8), 1, stdout);
990  
991 <        return(ferror(fp) ? -1 : 0);
991 >        return(ferror(stdout) ? -1 : 0);
992   }
993  
994  
995 < putpascii(col, fp)                      /* put an ascii primary to fp */
996 < COLOR  col;
997 < FILE  *fp;
995 > static int
996 > putbword(                       /* put a 16-bit brightness to stdout */
997 >        COLOR  col
998 > )
999   {
1000 <        fprintf(fp, "%15.3e\n", colval(col,putprim));
1000 >        long  i;
1001 >        uint16  vw;
1002  
1003 <        return(ferror(fp) ? -1 : 0);
1003 >        i = (*mybright)(col)*65536.;
1004 >        vw = min(i,65535);
1005 >        if (swapbytes)
1006 >                swap16((char *)&vw, 1);
1007 >        putbinary(&vw, sizeof(uint16), 1, stdout);
1008 >
1009 >        return(ferror(stdout) ? -1 : 0);
1010   }
1011  
1012  
1013 < putpfloat(col, fp)                      /* put a float primary to fp */
1014 < COLOR  col;
1015 < FILE  *fp;
1013 > static int
1014 > putpascii(                      /* put an ascii primary to stdout */
1015 >        COLOR  col
1016 > )
1017   {
1018 +        fprintf(stdout, "%15.3e\n", colval(col,putprim));
1019 +
1020 +        return(ferror(stdout) ? -1 : 0);
1021 + }
1022 +
1023 +
1024 + static int
1025 + putpfloat(                      /* put a float primary to stdout */
1026 +        COLOR  col
1027 + )
1028 + {
1029          float  vf;
1030  
1031          vf = colval(col,putprim);
1032 <        fwrite((char *)&vf, sizeof(float), 1, fp);
1032 >        if (swapbytes)
1033 >                swap32((char *)&vf, 1);
1034 >        putbinary(&vf, sizeof(float), 1, stdout);
1035  
1036 <        return(ferror(fp) ? -1 : 0);
1036 >        return(ferror(stdout) ? -1 : 0);
1037   }
1038  
1039  
1040 < putpdouble(col, fp)                     /* put a double primary to fp */
1041 < COLOR  col;
1042 < FILE  *fp;
1040 > static int
1041 > putpdouble(                     /* put a double primary to stdout */
1042 >        COLOR  col
1043 > )
1044   {
1045          double  vd;
1046  
1047          vd = colval(col,putprim);
1048 <        fwrite((char *)&vd, sizeof(double), 1, fp);
1048 >        if (swapbytes)
1049 >                swap64((char *)&vd, 1);
1050 >        putbinary(&vd, sizeof(double), 1, stdout);
1051  
1052 <        return(ferror(fp) ? -1 : 0);
1052 >        return(ferror(stdout) ? -1 : 0);
1053   }
1054  
1055  
1056 < putpint(col, fp)                        /* put an int primary to fp */
1057 < COLOR  col;
1058 < FILE  *fp;
1056 > static int
1057 > putpint(                        /* put an int primary to stdout */
1058 >        COLOR  col
1059 > )
1060   {
1061 <        fprintf(fp, "%d\n", (int)(colval(col,putprim)*256.));
1061 >        fprintf(stdout, "%d\n", (int)(colval(col,putprim)*256.));
1062  
1063 <        return(ferror(fp) ? -1 : 0);
1063 >        return(ferror(stdout) ? -1 : 0);
1064   }
1065  
1066  
1067 < putpbyte(col, fp)                       /* put a byte primary to fp */
1068 < COLOR  col;
1069 < FILE  *fp;
1067 > static int
1068 > putpbyte(                       /* put a byte primary to stdout */
1069 >        COLOR  col
1070 > )
1071   {
1072 <        register int  i;
1073 <        BYTE  vb;
1072 >        long  i;
1073 >        uby8  vb;
1074  
1075          i = colval(col,putprim)*256.;
1076          vb = min(i,255);
1077 <        fwrite((char *)&vb, sizeof(BYTE), 1, fp);
1077 >        putbinary(&vb, sizeof(uby8), 1, stdout);
1078  
1079 <        return(ferror(fp) ? -1 : 0);
1079 >        return(ferror(stdout) ? -1 : 0);
1080   }
1081  
1082  
1083 < set_io()                        /* set put and get functions */
1083 > static int
1084 > putpword(                       /* put a 16-bit primary to stdout */
1085 >        COLOR  col
1086 > )
1087   {
1088 +        long  i;
1089 +        uint16  vw;
1090 +
1091 +        i = colval(col,putprim)*65536.;
1092 +        vw = min(i,65535);
1093 +        if (swapbytes)
1094 +                swap16((char *)&vw, 1);
1095 +        putbinary(&vw, sizeof(uint16), 1, stdout);
1096 +
1097 +        return(ferror(stdout) ? -1 : 0);
1098 + }
1099 +
1100 +
1101 + static void
1102 + set_io(void)                    /* set put and get functions */
1103 + {
1104          switch (format) {
1105          case 'a':                                       /* ascii */
1106                  if (putprim == BRIGHT) {
# Line 825 | Line 1112 | set_io()                       /* set put and get functions */
1112                  } else {
1113                          getval = getcascii;
1114                          putval = putcascii;
1115 +                        if (reverse && !interleave) {
1116 +                                fprintf(stderr,
1117 +                                "%s: ASCII input files must be interleaved\n",
1118 +                                                progname);
1119 +                                quit(1);
1120 +                        }
1121                  }
1122                  return;
1123          case 'f':                                       /* binary float */
# Line 837 | Line 1130 | set_io()                       /* set put and get functions */
1130                  } else {
1131                          getval = getcfloat;
1132                          putval = putcfloat;
1133 +                        if (reverse && !interleave) {
1134 +                                if (fin2 == NULL)
1135 +                                        goto namerr;
1136 +                                if (fseek(fin2,
1137 +                                (long)sizeof(float)*picres.xr*picres.yr, SEEK_CUR))
1138 +                                        goto seekerr;
1139 +                                if (fseek(fin3,
1140 +                                (long)sizeof(float)*2*picres.xr*picres.yr, SEEK_CUR))
1141 +                                        goto seekerr;
1142 +                        }
1143                  }
1144                  return;
1145          case 'd':                                       /* binary double */
# Line 849 | Line 1152 | set_io()                       /* set put and get functions */
1152                  } else {
1153                          getval = getcdouble;
1154                          putval = putcdouble;
1155 +                        if (reverse && !interleave) {
1156 +                                if (fin2 == NULL)
1157 +                                        goto namerr;
1158 +                                if (fseek(fin2,
1159 +                                (long)sizeof(double)*picres.xr*picres.yr, SEEK_CUR))
1160 +                                        goto seekerr;
1161 +                                if (fseek(fin3,
1162 +                                (long)sizeof(double)*2*picres.xr*picres.yr, SEEK_CUR))
1163 +                                        goto seekerr;
1164 +                        }
1165                  }
1166                  return;
1167          case 'i':                                       /* integer */
# Line 861 | Line 1174 | set_io()                       /* set put and get functions */
1174                  } else {
1175                          getval = getcint;
1176                          putval = putcint;
1177 +                        if (reverse && !interleave) {
1178 +                                fprintf(stderr,
1179 +                                "%s: integer input files must be interleaved\n",
1180 +                                                progname);
1181 +                                quit(1);
1182 +                        }
1183                  }
1184                  return;
1185          case 'b':                                       /* byte */
# Line 873 | Line 1192 | set_io()                       /* set put and get functions */
1192                  } else {
1193                          getval = getcbyte;
1194                          putval = putcbyte;
1195 +                        if (reverse && !interleave) {
1196 +                                if (fin2 == NULL)
1197 +                                        goto namerr;
1198 +                                if (fseek(fin2,
1199 +                                (long)sizeof(uby8)*picres.xr*picres.yr, SEEK_CUR))
1200 +                                        goto seekerr;
1201 +                                if (fseek(fin3,
1202 +                                (long)sizeof(uby8)*2*picres.xr*picres.yr, SEEK_CUR))
1203 +                                        goto seekerr;
1204 +                        }
1205                  }
1206                  return;
1207 +        case 'w':                                       /* 16-bit */
1208 +                if (putprim == BRIGHT) {
1209 +                        getval = getbword;
1210 +                        putval = putbword;
1211 +                } else if (putprim != ALL) {
1212 +                        getval = getbword;
1213 +                        putval = putpword;
1214 +                } else {
1215 +                        getval = getcword;
1216 +                        putval = putcword;
1217 +                        if (reverse && !interleave) {
1218 +                                if (fin2 == NULL)
1219 +                                        goto namerr;
1220 +                                if (fseek(fin2,
1221 +                                (long)sizeof(uint16)*picres.xr*picres.yr, SEEK_CUR))
1222 +                                        goto seekerr;
1223 +                                if (fseek(fin3,
1224 +                                (long)sizeof(uint16)*2*picres.xr*picres.yr, SEEK_CUR))
1225 +                                        goto seekerr;
1226 +                        }
1227 +                }
1228 +                return;
1229          }
1230 + /* badopt: */ /* label not used */
1231 +        fprintf(stderr, "%s: botched file type\n", progname);
1232 +        quit(1);
1233 + namerr:
1234 +        fprintf(stderr, "%s: non-interleaved file(s) must be named\n",
1235 +                        progname);
1236 +        quit(1);
1237 + seekerr:
1238 +        fprintf(stderr, "%s: cannot seek on interleaved input file\n",
1239 +                        progname);
1240 +        quit(1);
1241   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines