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.20 by greg, Fri Jun 20 00:25:50 2003 UTC vs.
Revision 2.37 by greg, Wed Aug 14 18:20:02 2019 UTC

# Line 7 | Line 7 | static const char RCSid[] = "$Id$";
7   *     4/23/86
8   */
9  
10 #include  <time.h>
11
12 #include  "standard.h"
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))
17  
# Line 21 | Line 20 | static const char RCSid[] = "$Id$";
20   #define  BRIGHT         4
21  
22   RESOLU  picres;                 /* resolution of picture */
24
23   int  uniq = 0;                  /* print only unique values? */
26
24   int  doexposure = 0;            /* exposure change? (>100 to print) */
28
25   int  dataonly = 0;              /* data only format? */
30
26   int  putprim = ALL;             /* what to put out */
32
27   int  reverse = 0;               /* reverse conversion? */
34
28   int  format = 'a';              /* input/output format */
29   char  *fmtid = "ascii";         /* format identifier for header */
37
30   int  header = 1;                /* do header? */
39
31   long  skipbytes = 0;            /* skip bytes in input? */
32 <
42 < int  swapbytes = 0;             /* swap bytes in 16-bit words? */
43 <
32 > int  swapbytes = 0;             /* swap bytes? */
33   int  interleave = 1;            /* file is interleaved? */
45
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 < double
54 < rgb_bright(clr)
55 < COLOR  clr;
53 > typedef int getfunc_t(COLOR  col);
54 > typedef int putfunc_t(COLOR  col);
55 > typedef double brightfunc_t(COLOR  col);
56 >
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          return(bright(clr));
80   }
81  
82 < double
83 < xyz_bright(clr)
84 < COLOR  clr;
82 > static double
83 > xyz_bright(
84 >        COLOR  clr
85 > )
86   {
87          return(clr[CIEY]);
88   }
89  
90 < double  (*mybright)() = &rgb_bright;
91 <
92 <
93 < main(argc, argv)
94 < int  argc;
85 < char  **argv;
90 > int
91 > main(
92 >        int  argc,
93 >        char  **argv
94 > )
95   {
96 <        extern int  checkhead();
97 <        extern long  atol();
98 <        double  d, expval = 1.0;
90 <        int  i;
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 141 | Line 150 | char  **argv;
150                          case 'b':               /* brightness values */
151                                  putprim = argv[i][0] == '-' ? BRIGHT : ALL;
152                                  break;
153 <                        case 'p':               /* put primary */
153 >                        case 'p':               /* primary controls */
154                                  switch (argv[i][2]) {
155 +                                /* these two options affect -r conversion */
156 +                                case '\0':
157 +                                        myprims[RED][CIEX] = atof(argv[++i]);
158 +                                        myprims[RED][CIEY] = atof(argv[++i]);
159 +                                        myprims[GRN][CIEX] = atof(argv[++i]);
160 +                                        myprims[GRN][CIEY] = atof(argv[++i]);
161 +                                        myprims[BLU][CIEX] = atof(argv[++i]);
162 +                                        myprims[BLU][CIEY] = atof(argv[++i]);
163 +                                        myprims[WHT][CIEX] = atof(argv[++i]);
164 +                                        myprims[WHT][CIEY] = atof(argv[++i]);
165 +                                        outprims = myprims;
166 +                                        break;
167 +                                case 'x': case 'X': outprims = NULL; break;
168 +                                /* the following options affect +r only */
169                                  case 'r': case 'R': putprim = RED; break;
170                                  case 'g': case 'G': putprim = GRN; break;
171                                  case 'b': case 'B': putprim = BLU; break;
# Line 173 | Line 196 | char  **argv;
196                                          format = 'w';
197                                          fmtid = "16-bit";
198                                          break;
199 +                                case 'F':               /* swapped floats */
200 +                                        swapbytes = 1;
201                                  case 'f':               /* float */
202                                          dataonly = 1;
203                                          format = 'f';
204                                          fmtid = "float";
205                                          break;
206 +                                case 'D':               /* swapped doubles */
207 +                                        swapbytes = 1;
208                                  case 'd':               /* double */
209                                          dataonly = 1;
210                                          format = 'd';
# Line 213 | Line 240 | unkopt:
240                  else
241                          break;
242                                          /* recognize special formats */
243 <        if (dataonly && format == 'b')
243 >        if (dataonly && format == 'b') {
244                  if (putprim == ALL)
245                          fmtid = "24-bit_rgb";
246                  else
247                          fmtid = "8-bit_grey";
248 <        if (dataonly && format == 'w')
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) {
275 <                if ((fin = fopen(argv[i], "r")) == NULL) {
275 >                if ((fin = fopen(argv[i], inpmode)) == NULL) {
276                          fprintf(stderr, "%s: can't open file \"%s\"\n",
277                                                  progname, argv[i]);
278                          quit(1);
279                  }
280                  if (reverse && putprim != BRIGHT && i == argc-3) {
281 <                        if ((fin2 = fopen(argv[i+1], "r")) == NULL) {
281 >                        if ((fin2 = fopen(argv[i+1], inpmode)) == NULL) {
282                                  fprintf(stderr, "%s: can't open file \"%s\"\n",
283                                                  progname, argv[i+1]);
284                                  quit(1);
285                          }
286 <                        if ((fin3 = fopen(argv[i+2], "r")) == NULL) {
286 >                        if ((fin3 = fopen(argv[i+2], inpmode)) == NULL) {
287                                  fprintf(stderr, "%s: can't open file \"%s\"\n",
288                                                  progname, argv[i+2]);
289                                  quit(1);
# Line 251 | Line 292 | unkopt:
292                  } else if (i != argc-1)
293                          fin = NULL;
294                  if (reverse && putprim != BRIGHT && !interleave) {
295 <                        fin2 = fopen(argv[i], "r");
296 <                        fin3 = fopen(argv[i], "r");
295 >                        fin2 = fopen(argv[i], inpmode);
296 >                        fin3 = fopen(argv[i], inpmode);
297                  }
298 <                if (skipbytes && (fseek(fin, skipbytes, 0) || (fin2 != NULL &&
299 <                                (fseek(fin2, skipbytes, 0) ||
300 <                                fseek(fin3, skipbytes, 0))))) {
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);
# Line 268 | Line 309 | unkopt:
309          }
310  
311          if (reverse) {
271 #ifdef _WIN32
312                  SET_FILE_BINARY(stdout);
273                if (format != 'a' && format != 'i')
274                        SET_FILE_BINARY(fin);
275 #endif
313                                          /* get header */
314                  if (header) {
315                          if (checkheader(fin, fmtid, stdout) < 0) {
# Line 311 | Line 348 | unkopt:
348                  printargs(i, argv, stdout);
349                  if (expval < .99 || expval > 1.01)
350                          fputexpos(expval, stdout);
351 <                fputformat(COLRFMT, 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 < #ifdef _WIN32
320 <                SET_FILE_BINARY(fin);
321 <                if (format != 'a' && format != 'i')
361 >                if ((format != 'a') & (format != 'i'))
362                          SET_FILE_BINARY(stdout);
323 #endif
363                                                  /* get header */
364                  getheader(fin, checkhead, NULL);
365                  if (wrongformat) {
# Line 337 | Line 376 | unkopt:
376                          printargs(i, argv, stdout);
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                  }
# Line 346 | Line 392 | unkopt:
392          }
393  
394          quit(0);
395 +        return 0; /* pro forma return */
396   }
397  
398  
399 < int
400 < checkhead(line)                         /* deal with line from header */
401 < char  *line;
399 > static int
400 > checkhead(                              /* deal with line from header */
401 >        char    *line,
402 >        void    *p
403 > )
404   {
405 <        char    fmt[32];
405 >        char    fmt[MAXFMTLEN];
406          double  d;
407          COLOR   ctmp;
408 +        int     rv;
409  
410          if (formatval(fmt, line)) {
411 <                if (!strcmp(fmt, CIEFMT)) {
411 >                if (!strcmp(fmt, CIEFMT))
412                          mybright = &xyz_bright;
413 <                        if (original) {
364 <                                scalecolor(exposure, 1./WHTEFFICACY);
365 <                                doexposure++;
366 <                        }
367 <                } else if (!strcmp(fmt, COLRFMT))
413 >                else if (!strcmp(fmt, COLRFMT))
414                          mybright = &rgb_bright;
415                  else
416                          wrongformat++;
# Line 378 | Line 424 | char  *line;
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 <        register COLOR  *scanln;
438 >        COLOR   *scanln;
439          int  dogamma;
440          COLOR  lastc;
441 <        FLOAT  hv[2];
441 >        RREAL  hv[2];
442          int  startprim, endprim;
443          long  startpos;
444 <        int  y;
396 <        register int  x;
444 >        int  x, y;
445  
446          scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
447          if (scanln == NULL) {
# Line 401 | Line 449 | pixtoval()                             /* convert picture to values */
449                  quit(1);
450          }
451          dogamma = gamcor < .95 || gamcor > 1.05;
452 <        if (putprim == ALL && !interleave) {
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, 0)) {
459 >                if (putprim != startprim && fseek(fin, startpos, SEEK_SET)) {
460                          fprintf(stderr, "%s: seek error on input file\n",
461                                          progname);
462                          quit(1);
# Line 421 | Line 469 | pixtoval()                             /* convert picture to values */
469                                  quit(1);
470                          }
471                          for (x = 0; x < scanlen(&picres); x++) {
472 <                                if (uniq)
472 >                                if (uniq) {
473                                          if (    colval(scanln[x],RED) ==
474                                                          colval(lastc,RED) &&
475                                                  colval(scanln[x],GRN) ==
# Line 431 | Line 479 | pixtoval()                             /* convert picture to values */
479                                                  continue;
480                                          else
481                                                  copycolor(lastc, scanln[x]);
482 +                                }
483                                  if (doexposure)
484                                          multcolor(scanln[x], exposure);
485                                  if (dogamma)
# Line 456 | Line 505 | pixtoval()                             /* convert picture to values */
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 <        int  dogamma;
512 <        register COLOR  *scanln;
513 <        int  y;
514 <        register int  x;
511 >        int     dogamma;
512 >        COLOR   *scanln;
513 >        COLR    rgbe;
514 >        int     x, y;
515  
516          scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
517          if (scanln == NULL) {
# Line 490 | Line 540 | valtopix()                     /* convert values to a pixel file */
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, scanlen(&picres), stdout) < 0) {
552 <                        fprintf(stderr, "%s: write error\n", progname);
553 <                        quit(1);
497 <                }
551 >                                                /* write scan if compressed */
552 >                if (!uniq && fwritescan(scanln, scanlen(&picres), stdout) < 0)
553 >                        goto writerr;
554          }
555          free((void *)scanln);
556 +        return;
557 + writerr:
558 +        fprintf(stderr, "%s: write error\n", progname);
559 +        quit(1);
560   }
561  
562  
# Line 508 | Line 568 | int  code;
568   }
569  
570  
571 < swap16(wp, n)           /* swap n 16-bit words */
572 < register uint16  *wp;
573 < int  n;
571 > static int
572 > getcascii(              /* get an ascii color value from stream(s) */
573 >        COLOR  col
574 > )
575   {
515        while (n-- > 0) {
516                *wp = *wp << 8 | ((*wp >> 8) & 0xff);
517                wp++;
518        }
519 }
520
521 getcascii(col)          /* get an ascii color value from stream(s) */
522 COLOR  col;
523 {
576          double  vd[3];
577  
578          if (fin2 == NULL) {
# Line 537 | Line 589 | COLOR  col;
589   }
590  
591  
592 < getcdouble(col)         /* get a double color value from stream(s) */
593 < COLOR  col;
592 > static int
593 > getcdouble(             /* get a double color value from stream(s) */
594 >        COLOR  col
595 > )
596   {
597          double  vd[3];
598  
599          if (fin2 == NULL) {
600 <                if (fread((char *)vd, sizeof(double), 3, fin) != 3)
600 >                if (getbinary(vd, sizeof(double), 3, fin) != 3)
601                          return(-1);
602          } else {
603 <                if (fread((char *)vd, sizeof(double), 1, fin) != 1 ||
604 <                        fread((char *)(vd+1), sizeof(double), 1, fin2) != 1 ||
605 <                        fread((char *)(vd+2), sizeof(double), 1, fin3) != 1)
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)          /* get a float color value from stream(s) */
616 < COLOR  col;
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 (fin2 == NULL) {
623 <                if (fread((char *)vf, sizeof(float), 3, fin) != 3)
623 >                if (getbinary(vf, sizeof(float), 3, fin) != 3)
624                          return(-1);
625          } else {
626 <                if (fread((char *)vf, sizeof(float), 1, fin) != 1 ||
627 <                        fread((char *)(vf+1), sizeof(float), 1, fin2) != 1 ||
628 <                        fread((char *)(vf+2), sizeof(float), 1, fin3) != 1)
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)            /* get an int color value from stream(s) */
639 < COLOR  col;
638 > static int
639 > getcint(                /* get an int color value from stream(s) */
640 >        COLOR  col
641 > )
642   {
643          int  vi[3];
644  
# Line 595 | Line 657 | COLOR  col;
657   }
658  
659  
660 < getcbyte(col)           /* get a byte color value from stream(s) */
661 < COLOR  col;
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 (fin2 == NULL) {
668 <                if (fread((char *)vb, sizeof(BYTE), 3, fin) != 3)
668 >                if (getbinary(vb, sizeof(uby8), 3, fin) != 3)
669                          return(-1);
670          } else {
671 <                if (fread((char *)vb, sizeof(BYTE), 1, fin) != 1 ||
672 <                        fread((char *)(vb+1), sizeof(BYTE), 1, fin2) != 1 ||
673 <                        fread((char *)(vb+2), sizeof(BYTE), 1, fin3) != 1)
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.,
# Line 615 | Line 679 | COLOR  col;
679   }
680  
681  
682 < getcword(col)           /* get a 16-bit color value from stream(s) */
683 < COLOR  col;
682 > static int
683 > getcword(               /* get a 16-bit color value from stream(s) */
684 >        COLOR  col
685 > )
686   {
687          uint16  vw[3];
688  
689          if (fin2 == NULL) {
690 <                if (fread((char *)vw, sizeof(uint16), 3, fin) != 3)
690 >                if (getbinary(vw, sizeof(uint16), 3, fin) != 3)
691                          return(-1);
692          } else {
693 <                if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 ||
694 <                        fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 ||
695 <                        fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1)
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(vw, 3);
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 < getbascii(col)          /* get an ascii brightness value from fin */
707 < COLOR  col;
706 > static int
707 > getbascii(              /* get an ascii brightness value from fin */
708 >        COLOR  col
709 > )
710   {
711          double  vd;
712  
# Line 649 | Line 717 | COLOR  col;
717   }
718  
719  
720 < getbdouble(col)         /* get a double brightness value from fin */
721 < COLOR  col;
720 > static int
721 > getbdouble(             /* get a double brightness value from fin */
722 >        COLOR  col
723 > )
724   {
725          double  vd;
726  
727 <        if (fread((char *)&vd, sizeof(double), 1, fin) != 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)          /* get a float brightness value from fin */
737 < COLOR  col;
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, fin) != 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)            /* get an int brightness value from fin */
753 < COLOR  col;
752 > static int
753 > getbint(                /* get an int brightness value from fin */
754 >        COLOR  col
755 > )
756   {
757          int  vi;
758          double  d;
# Line 687 | Line 765 | COLOR  col;
765   }
766  
767  
768 < getbbyte(col)           /* get a byte brightness value from fin */
769 < COLOR  col;
768 > static int
769 > getbbyte(               /* get a byte brightness value from fin */
770 >        COLOR  col
771 > )
772   {
773 <        BYTE  vb;
773 >        uby8  vb;
774          double  d;
775  
776 <        if (fread((char *)&vb, sizeof(BYTE), 1, fin) != 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 701 | Line 781 | COLOR  col;
781   }
782  
783  
784 < getbword(col)           /* get a 16-bit brightness value from fin */
785 < COLOR  col;
784 > static int
785 > getbword(               /* get a 16-bit brightness value from fin */
786 >        COLOR  col
787 > )
788   {
789          uint16  vw;
790          double  d;
791  
792 <        if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1)
792 >        if (getbinary(&vw, sizeof(uint16), 1, fin) != 1)
793                  return(-1);
794          if (swapbytes)
795 <                swap16(&vw, 1);
795 >                swap16((char *)&vw, 1);
796          d = (vw+.5)/65536.;
797          setcolor(col, d, d, d);
798          return(0);
799   }
800  
801  
802 < putcascii(col)                  /* put an ascii color to stdout */
803 < COLOR  col;
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]),
# Line 729 | Line 813 | COLOR  col;
813   }
814  
815  
816 < putcfloat(col)                  /* put a float color to stdout */
817 < COLOR  col;
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,ord[0]);
824          vf[1] = colval(col,ord[1]);
825          vf[2] = colval(col,ord[2]);
826 <        fwrite((char *)vf, sizeof(float), 3, stdout);
826 >        if (swapbytes)
827 >                swap32((char *)vf, 3);
828 >        putbinary(vf, sizeof(float), 3, stdout);
829  
830          return(ferror(stdout) ? -1 : 0);
831   }
832  
833  
834 < putcdouble(col)                 /* put a double color to stdout */
835 < COLOR  col;
834 > static int
835 > putcdouble(                     /* put a double color to stdout */
836 >        COLOR  col
837 > )
838   {
839          double  vd[3];
840  
841          vd[0] = colval(col,ord[0]);
842          vd[1] = colval(col,ord[1]);
843          vd[2] = colval(col,ord[2]);
844 <        fwrite((char *)vd, sizeof(double), 3, stdout);
844 >        if (swapbytes)
845 >                swap64((char *)vd, 3);
846 >        putbinary(vd, sizeof(double), 3, stdout);
847  
848          return(ferror(stdout) ? -1 : 0);
849   }
850  
851  
852 < putcint(col)                    /* put an int color to stdout */
853 < COLOR  col;
852 > static int
853 > putcint(                        /* put an int color to stdout */
854 >        COLOR  col
855 > )
856   {
857          fprintf(stdout, "%d %d %d\n",
858                          (int)(colval(col,ord[0])*256.),
# Line 769 | Line 863 | COLOR  col;
863   }
864  
865  
866 < putcbyte(col)                   /* put a byte color to stdout */
867 < COLOR  col;
866 > static int
867 > putcbyte(                       /* put a byte color to stdout */
868 >        COLOR  col
869 > )
870   {
871          long  i;
872 <        BYTE  vb[3];
872 >        uby8  vb[3];
873  
874          i = colval(col,ord[0])*256.;
875          vb[0] = min(i,255);
# Line 781 | Line 877 | COLOR  col;
877          vb[1] = min(i,255);
878          i = colval(col,ord[2])*256.;
879          vb[2] = min(i,255);
880 <        fwrite((char *)vb, sizeof(BYTE), 3, stdout);
880 >        putbinary(vb, sizeof(uby8), 3, stdout);
881  
882          return(ferror(stdout) ? -1 : 0);
883   }
884  
885  
886 < putcword(col)                   /* put a 16-bit color to stdout */
887 < COLOR  col;
886 > static int
887 > putcword(                       /* put a 16-bit color to stdout */
888 >        COLOR  col
889 > )
890   {
891          long  i;
892          uint16  vw[3];
# Line 800 | Line 898 | COLOR  col;
898          i = colval(col,ord[2])*65536.;
899          vw[2] = min(i,65535);
900          if (swapbytes)
901 <                swap16(vw, 3);
902 <        fwrite((char *)vw, sizeof(uint16), 3, stdout);
901 >                swap16((char *)vw, 3);
902 >        putbinary(vw, sizeof(uint16), 3, stdout);
903  
904          return(ferror(stdout) ? -1 : 0);
905   }
906  
907  
908 < putbascii(col)                  /* put an ascii brightness to stdout */
909 < COLOR  col;
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  
# Line 816 | Line 916 | COLOR  col;
916   }
917  
918  
919 < putbfloat(col)                  /* put a float brightness to stdout */
920 < COLOR  col;
919 > static int
920 > putbfloat(                      /* put a float brightness to stdout */
921 >        COLOR  col
922 > )
923   {
924          float  vf;
925  
926          vf = (*mybright)(col);
927 <        fwrite((char *)&vf, sizeof(float), 1, stdout);
927 >        if (swapbytes)
928 >                swap32((char *)&vf, 1);
929 >        putbinary(&vf, sizeof(float), 1, stdout);
930  
931          return(ferror(stdout) ? -1 : 0);
932   }
933  
934  
935 < putbdouble(col)                 /* put a double brightness to stdout */
936 < COLOR  col;
935 > static int
936 > putbdouble(                     /* put a double brightness to stdout */
937 >        COLOR  col
938 > )
939   {
940          double  vd;
941  
942          vd = (*mybright)(col);
943 <        fwrite((char *)&vd, sizeof(double), 1, stdout);
943 >        if (swapbytes)
944 >                swap64((char *)&vd, 1);
945 >        putbinary(&vd, sizeof(double), 1, stdout);
946  
947          return(ferror(stdout) ? -1 : 0);
948   }
949  
950  
951 < putbint(col)                    /* put an int brightness to stdout */
952 < COLOR  col;
951 > static int
952 > putbint(                        /* put an int brightness to stdout */
953 >        COLOR  col
954 > )
955   {
956          fprintf(stdout, "%d\n", (int)((*mybright)(col)*256.));
957  
# Line 849 | Line 959 | COLOR  col;
959   }
960  
961  
962 < putbbyte(col)                   /* put a byte brightness to stdout */
963 < COLOR  col;
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 = (*mybright)(col)*256.;
971          vb = min(i,255);
972 <        fwrite((char *)&vb, sizeof(BYTE), 1, stdout);
972 >        putbinary(&vb, sizeof(uby8), 1, stdout);
973  
974          return(ferror(stdout) ? -1 : 0);
975   }
976  
977  
978 < putbword(col)                   /* put a 16-bit brightness to stdout */
979 < COLOR  col;
978 > static int
979 > putbword(                       /* put a 16-bit brightness to stdout */
980 >        COLOR  col
981 > )
982   {
983          long  i;
984          uint16  vw;
# Line 872 | Line 986 | COLOR  col;
986          i = (*mybright)(col)*65536.;
987          vw = min(i,65535);
988          if (swapbytes)
989 <                swap16(&vw, 1);
990 <        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
989 >                swap16((char *)&vw, 1);
990 >        putbinary(&vw, sizeof(uint16), 1, stdout);
991  
992          return(ferror(stdout) ? -1 : 0);
993   }
994  
995  
996 < putpascii(col)                  /* put an ascii primary to stdout */
997 < COLOR  col;
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  
# Line 888 | Line 1004 | COLOR  col;
1004   }
1005  
1006  
1007 < putpfloat(col)                  /* put a float primary to stdout */
1008 < COLOR  col;
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 <        fwrite((char *)&vf, sizeof(float), 1, stdout);
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 < putpdouble(col)                 /* put a double primary to stdout */
1024 < COLOR  col;
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 <        fwrite((char *)&vd, sizeof(double), 1, stdout);
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 < putpint(col)                    /* put an int primary to stdout */
1040 < COLOR  col;
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  
# Line 921 | Line 1047 | COLOR  col;
1047   }
1048  
1049  
1050 < putpbyte(col)                   /* put a byte primary to stdout */
1051 < COLOR  col;
1050 > static int
1051 > putpbyte(                       /* put a byte primary to stdout */
1052 >        COLOR  col
1053 > )
1054   {
1055          long  i;
1056 <        BYTE  vb;
1056 >        uby8  vb;
1057  
1058          i = colval(col,putprim)*256.;
1059          vb = min(i,255);
1060 <        fwrite((char *)&vb, sizeof(BYTE), 1, stdout);
1060 >        putbinary(&vb, sizeof(uby8), 1, stdout);
1061  
1062          return(ferror(stdout) ? -1 : 0);
1063   }
1064  
1065  
1066 < putpword(col)                   /* put a 16-bit primary to stdout */
1067 < COLOR  col;
1066 > static int
1067 > putpword(                       /* put a 16-bit primary to stdout */
1068 >        COLOR  col
1069 > )
1070   {
1071          long  i;
1072          uint16  vw;
# Line 944 | Line 1074 | COLOR  col;
1074          i = colval(col,putprim)*65536.;
1075          vw = min(i,65535);
1076          if (swapbytes)
1077 <                swap16(&vw, 1);
1078 <        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
1077 >                swap16((char *)&vw, 1);
1078 >        putbinary(&vw, sizeof(uint16), 1, stdout);
1079  
1080          return(ferror(stdout) ? -1 : 0);
1081   }
1082  
1083  
1084 < set_io()                        /* set put and get functions */
1084 > static void
1085 > set_io(void)                    /* set put and get functions */
1086   {
1087          switch (format) {
1088          case 'a':                                       /* ascii */
# Line 986 | Line 1117 | set_io()                       /* set put and get functions */
1117                                  if (fin2 == NULL)
1118                                          goto namerr;
1119                                  if (fseek(fin2,
1120 <                                (long)sizeof(float)*picres.xr*picres.yr, 1))
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, 1))
1123 >                                (long)sizeof(float)*2*picres.xr*picres.yr, SEEK_CUR))
1124                                          goto seekerr;
1125                          }
1126                  }
# Line 1008 | Line 1139 | set_io()                       /* set put and get functions */
1139                                  if (fin2 == NULL)
1140                                          goto namerr;
1141                                  if (fseek(fin2,
1142 <                                (long)sizeof(double)*picres.xr*picres.yr, 1))
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, 1))
1145 >                                (long)sizeof(double)*2*picres.xr*picres.yr, SEEK_CUR))
1146                                          goto seekerr;
1147                          }
1148                  }
# Line 1048 | Line 1179 | set_io()                       /* set put and get functions */
1179                                  if (fin2 == NULL)
1180                                          goto namerr;
1181                                  if (fseek(fin2,
1182 <                                (long)sizeof(BYTE)*picres.xr*picres.yr, 1))
1182 >                                (long)sizeof(uby8)*picres.xr*picres.yr, SEEK_CUR))
1183                                          goto seekerr;
1184                                  if (fseek(fin3,
1185 <                                (long)sizeof(BYTE)*2*picres.xr*picres.yr, 1))
1185 >                                (long)sizeof(uby8)*2*picres.xr*picres.yr, SEEK_CUR))
1186                                          goto seekerr;
1187                          }
1188                  }
# Line 1070 | Line 1201 | set_io()                       /* set put and get functions */
1201                                  if (fin2 == NULL)
1202                                          goto namerr;
1203                                  if (fseek(fin2,
1204 <                                (long)sizeof(uint16)*picres.xr*picres.yr, 1))
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, 1))
1207 >                                (long)sizeof(uint16)*2*picres.xr*picres.yr, SEEK_CUR))
1208                                          goto seekerr;
1209                          }
1210                  }
1211                  return;
1212          }
1213 < badopt:
1213 > /* badopt: */ /* label not used */
1214          fprintf(stderr, "%s: botched file type\n", progname);
1215          quit(1);
1216   namerr:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines