ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pvalue.c
(Generate patch)

Comparing ray/src/px/pvalue.c (file contents):
Revision 1.5 by greg, Fri Dec 14 16:33:19 1990 UTC vs.
Revision 2.37 by greg, Wed Aug 14 18:20:02 2019 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines