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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines