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.24 by greg, Wed Oct 22 02:06:35 2003 UTC vs.
Revision 2.36 by greg, Mon Jul 15 23:42:44 2019 UTC

# Line 11 | Line 11 | static const char RCSid[] = "$Id$";
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 19 | Line 20 | static const char RCSid[] = "$Id$";
20   #define  BRIGHT         4
21  
22   RESOLU  picres;                 /* resolution of picture */
22
23   int  uniq = 0;                  /* print only unique values? */
24
24   int  doexposure = 0;            /* exposure change? (>100 to print) */
26
25   int  dataonly = 0;              /* data only format? */
28
26   int  putprim = ALL;             /* what to put out */
30
27   int  reverse = 0;               /* reverse conversion? */
32
28   int  format = 'a';              /* input/output format */
29   char  *fmtid = "ascii";         /* format identifier for header */
35
30   int  header = 1;                /* do header? */
37
31   long  skipbytes = 0;            /* skip bytes in input? */
39
32   int  swapbytes = 0;             /* swap bytes? */
41
33   int  interleave = 1;            /* file is interleaved? */
43
34   int  resolution = 1;            /* put/get resolution string? */
45
35   int  original = 0;              /* convert to original values? */
47
36   int  wrongformat = 0;           /* wrong input format? */
49
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 59 | Line 49 | char  *progname;
49   FILE  *fin;
50   FILE  *fin2 = NULL, *fin3 = NULL;       /* for other color channels */
51  
62 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;
83 < 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;
88 <        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 139 | 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 227 | Line 252 | unkopt:
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 255 | 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 272 | Line 309 | unkopt:
309          }
310  
311          if (reverse) {
275 #ifdef _WIN32
312                  SET_FILE_BINARY(stdout);
277                if (format != 'a' && format != 'i')
278                        SET_FILE_BINARY(fin);
279 #endif
313                                          /* get header */
314                  if (header) {
315                          if (checkheader(fin, fmtid, stdout) < 0) {
# Line 315 | 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
324 <                SET_FILE_BINARY(fin);
325 <                if (format != 'a' && format != 'i')
361 >                if ((format != 'a') & (format != 'i'))
362                          SET_FILE_BINARY(stdout);
327 #endif
363                                                  /* get header */
364                  getheader(fin, checkhead, NULL);
365                  if (wrongformat) {
# Line 350 | Line 385 | unkopt:
385          }
386  
387          quit(0);
388 +        return 0; /* pro forma return */
389   }
390  
391  
392 < int
393 < checkhead(line)                         /* deal with line from header */
394 < char  *line;
392 > static int
393 > checkhead(                              /* deal with line from header */
394 >        char    *line,
395 >        void    *p
396 > )
397   {
398 <        char    fmt[32];
398 >        char    fmt[MAXFMTLEN];
399          double  d;
400          COLOR   ctmp;
401  
402          if (formatval(fmt, line)) {
403 <                if (!strcmp(fmt, CIEFMT)) {
403 >                if (!strcmp(fmt, CIEFMT))
404                          mybright = &xyz_bright;
405 <                        if (original) {
368 <                                scalecolor(exposure, 1./WHTEFFICACY);
369 <                                doexposure++;
370 <                        }
371 <                } else if (!strcmp(fmt, COLRFMT))
405 >                else if (!strcmp(fmt, COLRFMT))
406                          mybright = &rgb_bright;
407                  else
408                          wrongformat++;
# Line 388 | Line 422 | char  *line;
422   }
423  
424  
425 < pixtoval()                              /* convert picture to values */
425 > static void
426 > pixtoval(void)                          /* convert picture to values */
427   {
428 <        register COLOR  *scanln;
428 >        COLOR   *scanln;
429          int  dogamma;
430          COLOR  lastc;
431          RREAL  hv[2];
432          int  startprim, endprim;
433          long  startpos;
434 <        int  y;
400 <        register int  x;
434 >        int  x, y;
435  
436          scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
437          if (scanln == NULL) {
# Line 405 | Line 439 | pixtoval()                             /* convert picture to values */
439                  quit(1);
440          }
441          dogamma = gamcor < .95 || gamcor > 1.05;
442 <        if (putprim == ALL && !interleave) {
442 >        if ((putprim == ALL) & !interleave) {
443                  startprim = RED; endprim = BLU;
444                  startpos = ftell(fin);
445          } else {
446                  startprim = putprim; endprim = putprim;
447          }
448          for (putprim = startprim; putprim <= endprim; putprim++) {
449 <                if (putprim != startprim && fseek(fin, startpos, 0)) {
449 >                if (putprim != startprim && fseek(fin, startpos, SEEK_SET)) {
450                          fprintf(stderr, "%s: seek error on input file\n",
451                                          progname);
452                          quit(1);
# Line 461 | Line 495 | pixtoval()                             /* convert picture to values */
495   }
496  
497  
498 < valtopix()                      /* convert values to a pixel file */
498 > static void
499 > valtopix(void)                  /* convert values to a pixel file */
500   {
501 <        int  dogamma;
502 <        register COLOR  *scanln;
503 <        int  y;
504 <        register int  x;
501 >        int     dogamma;
502 >        COLOR   *scanln;
503 >        COLR    rgbe;
504 >        int     x, y;
505  
506          scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
507          if (scanln == NULL) {
# Line 495 | Line 530 | valtopix()                     /* convert values to a pixel file */
530                                          pow(colval(scanln[x],BLU), gamcor));
531                          if (doexposure)
532                                  multcolor(scanln[x], exposure);
533 +                        if (uniq) {             /* uncompressed? */
534 +                                setcolr(rgbe,   scanln[x][RED],
535 +                                                scanln[x][GRN],
536 +                                                scanln[x][BLU]);
537 +                                if (putbinary(rgbe, sizeof(COLR), 1, stdout) != 1)
538 +                                        goto writerr;
539 +                        }
540                  }
541 <                if (fwritescan(scanln, scanlen(&picres), stdout) < 0) {
542 <                        fprintf(stderr, "%s: write error\n", progname);
543 <                        quit(1);
502 <                }
541 >                                                /* write scan if compressed */
542 >                if (!uniq && fwritescan(scanln, scanlen(&picres), stdout) < 0)
543 >                        goto writerr;
544          }
545          free((void *)scanln);
546 +        return;
547 + writerr:
548 +        fprintf(stderr, "%s: write error\n", progname);
549 +        quit(1);
550   }
551  
552  
# Line 513 | Line 558 | int  code;
558   }
559  
560  
561 < swap16(wp, n)           /* swap n 16-bit words */
562 < register uint16  *wp;
563 < int  n;
561 > static int
562 > getcascii(              /* get an ascii color value from stream(s) */
563 >        COLOR  col
564 > )
565   {
520        while (n-- > 0) {
521                *wp = *wp << 8 | ((*wp >> 8) & 0xff);
522                wp++;
523        }
524 }
525
526
527 swap32(wp, n)           /* swap n 32-bit words */
528 register uint32  *wp;
529 int  n;
530 {
531        while (n-- > 0) {
532                *wp = *wp << 24 | ((*wp >> 24) & 0xff) |
533                        (*wp & 0xff00) << 8 | (*wp & 0xff0000) >> 8;
534                wp++;
535        }
536 }
537
538
539 swap64(wp, n)           /* swap n 64-bit words */
540 register char  *wp;
541 int  n;
542 {
543        register int    t;
544
545        while (n-- > 0) {
546                t = wp[0]; wp[0] = wp[7]; wp[7] = t;
547                t = wp[1]; wp[1] = wp[6]; wp[6] = t;
548                t = wp[2]; wp[2] = wp[5]; wp[5] = t;
549                t = wp[3]; wp[3] = wp[4]; wp[4] = t;
550                wp += 8;
551        }
552 }
553
554
555 getcascii(col)          /* get an ascii color value from stream(s) */
556 COLOR  col;
557 {
566          double  vd[3];
567  
568          if (fin2 == NULL) {
# Line 571 | Line 579 | COLOR  col;
579   }
580  
581  
582 < getcdouble(col)         /* get a double color value from stream(s) */
583 < COLOR  col;
582 > static int
583 > getcdouble(             /* get a double color value from stream(s) */
584 >        COLOR  col
585 > )
586   {
587          double  vd[3];
588  
589          if (fin2 == NULL) {
590 <                if (fread((char *)vd, sizeof(double), 3, fin) != 3)
590 >                if (getbinary(vd, sizeof(double), 3, fin) != 3)
591                          return(-1);
592          } else {
593 <                if (fread((char *)vd, sizeof(double), 1, fin) != 1 ||
594 <                        fread((char *)(vd+1), sizeof(double), 1, fin2) != 1 ||
595 <                        fread((char *)(vd+2), sizeof(double), 1, fin3) != 1)
593 >                if (getbinary(vd, sizeof(double), 1, fin) != 1 ||
594 >                        getbinary(vd+1, sizeof(double), 1, fin2) != 1 ||
595 >                        getbinary(vd+2, sizeof(double), 1, fin3) != 1)
596                          return(-1);
597          }
598          if (swapbytes)
# Line 592 | Line 602 | COLOR  col;
602   }
603  
604  
605 < getcfloat(col)          /* get a float color value from stream(s) */
606 < COLOR  col;
605 > static int
606 > getcfloat(              /* get a float color value from stream(s) */
607 >        COLOR  col
608 > )
609   {
610          float  vf[3];
611  
612          if (fin2 == NULL) {
613 <                if (fread((char *)vf, sizeof(float), 3, fin) != 3)
613 >                if (getbinary(vf, sizeof(float), 3, fin) != 3)
614                          return(-1);
615          } else {
616 <                if (fread((char *)vf, sizeof(float), 1, fin) != 1 ||
617 <                        fread((char *)(vf+1), sizeof(float), 1, fin2) != 1 ||
618 <                        fread((char *)(vf+2), sizeof(float), 1, fin3) != 1)
616 >                if (getbinary(vf, sizeof(float), 1, fin) != 1 ||
617 >                        getbinary(vf+1, sizeof(float), 1, fin2) != 1 ||
618 >                        getbinary(vf+2, sizeof(float), 1, fin3) != 1)
619                          return(-1);
620          }
621          if (swapbytes)
622 <                swap32((uint32 *)vf, 3);
622 >                swap32((char *)vf, 3);
623          setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]);
624          return(0);
625   }
626  
627  
628 < getcint(col)            /* get an int color value from stream(s) */
629 < COLOR  col;
628 > static int
629 > getcint(                /* get an int color value from stream(s) */
630 >        COLOR  col
631 > )
632   {
633          int  vi[3];
634  
# Line 633 | Line 647 | COLOR  col;
647   }
648  
649  
650 < getcbyte(col)           /* get a byte color value from stream(s) */
651 < COLOR  col;
650 > static int
651 > getcbyte(               /* get a byte color value from stream(s) */
652 >        COLOR  col
653 > )
654   {
655 <        BYTE  vb[3];
655 >        uby8  vb[3];
656  
657          if (fin2 == NULL) {
658 <                if (fread((char *)vb, sizeof(BYTE), 3, fin) != 3)
658 >                if (getbinary(vb, sizeof(uby8), 3, fin) != 3)
659                          return(-1);
660          } else {
661 <                if (fread((char *)vb, sizeof(BYTE), 1, fin) != 1 ||
662 <                        fread((char *)(vb+1), sizeof(BYTE), 1, fin2) != 1 ||
663 <                        fread((char *)(vb+2), sizeof(BYTE), 1, fin3) != 1)
661 >                if (getbinary(vb, sizeof(uby8), 1, fin) != 1 ||
662 >                        getbinary(vb+1, sizeof(uby8), 1, fin2) != 1 ||
663 >                        getbinary(vb+2, sizeof(uby8), 1, fin3) != 1)
664                          return(-1);
665          }
666          setcolor(col, (vb[rord[RED]]+.5)/256.,
# Line 653 | Line 669 | COLOR  col;
669   }
670  
671  
672 < getcword(col)           /* get a 16-bit color value from stream(s) */
673 < COLOR  col;
672 > static int
673 > getcword(               /* get a 16-bit color value from stream(s) */
674 >        COLOR  col
675 > )
676   {
677          uint16  vw[3];
678  
679          if (fin2 == NULL) {
680 <                if (fread((char *)vw, sizeof(uint16), 3, fin) != 3)
680 >                if (getbinary(vw, sizeof(uint16), 3, fin) != 3)
681                          return(-1);
682          } else {
683 <                if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 ||
684 <                        fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 ||
685 <                        fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1)
683 >                if (getbinary(vw, sizeof(uint16), 1, fin) != 1 ||
684 >                        getbinary(vw+1, sizeof(uint16), 1, fin2) != 1 ||
685 >                        getbinary(vw+2, sizeof(uint16), 1, fin3) != 1)
686                          return(-1);
687          }
688          if (swapbytes)
689 <                swap16(vw, 3);
689 >                swap16((char *)vw, 3);
690          setcolor(col, (vw[rord[RED]]+.5)/65536.,
691                          (vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.);
692          return(0);
693   }
694  
695  
696 < getbascii(col)          /* get an ascii brightness value from fin */
697 < COLOR  col;
696 > static int
697 > getbascii(              /* get an ascii brightness value from fin */
698 >        COLOR  col
699 > )
700   {
701          double  vd;
702  
# Line 687 | Line 707 | COLOR  col;
707   }
708  
709  
710 < getbdouble(col)         /* get a double brightness value from fin */
711 < COLOR  col;
710 > static int
711 > getbdouble(             /* get a double brightness value from fin */
712 >        COLOR  col
713 > )
714   {
715          double  vd;
716  
717 <        if (fread((char *)&vd, sizeof(double), 1, fin) != 1)
717 >        if (getbinary(&vd, sizeof(double), 1, fin) != 1)
718                  return(-1);
719          if (swapbytes)
720                  swap64((char *)&vd, 1);
# Line 701 | Line 723 | COLOR  col;
723   }
724  
725  
726 < getbfloat(col)          /* get a float brightness value from fin */
727 < COLOR  col;
726 > static int
727 > getbfloat(              /* get a float brightness value from fin */
728 >        COLOR  col
729 > )
730   {
731          float  vf;
732  
733 <        if (fread((char *)&vf, sizeof(float), 1, fin) != 1)
733 >        if (getbinary(&vf, sizeof(float), 1, fin) != 1)
734                  return(-1);
735          if (swapbytes)
736 <                swap32((uint32 *)&vf, 1);
736 >                swap32((char *)&vf, 1);
737          setcolor(col, vf, vf, vf);
738          return(0);
739   }
740  
741  
742 < getbint(col)            /* get an int brightness value from fin */
743 < COLOR  col;
742 > static int
743 > getbint(                /* get an int brightness value from fin */
744 >        COLOR  col
745 > )
746   {
747          int  vi;
748          double  d;
# Line 729 | Line 755 | COLOR  col;
755   }
756  
757  
758 < getbbyte(col)           /* get a byte brightness value from fin */
759 < COLOR  col;
758 > static int
759 > getbbyte(               /* get a byte brightness value from fin */
760 >        COLOR  col
761 > )
762   {
763 <        BYTE  vb;
763 >        uby8  vb;
764          double  d;
765  
766 <        if (fread((char *)&vb, sizeof(BYTE), 1, fin) != 1)
766 >        if (getbinary(&vb, sizeof(uby8), 1, fin) != 1)
767                  return(-1);
768          d = (vb+.5)/256.;
769          setcolor(col, d, d, d);
# Line 743 | Line 771 | COLOR  col;
771   }
772  
773  
774 < getbword(col)           /* get a 16-bit brightness value from fin */
775 < COLOR  col;
774 > static int
775 > getbword(               /* get a 16-bit brightness value from fin */
776 >        COLOR  col
777 > )
778   {
779          uint16  vw;
780          double  d;
781  
782 <        if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1)
782 >        if (getbinary(&vw, sizeof(uint16), 1, fin) != 1)
783                  return(-1);
784          if (swapbytes)
785 <                swap16(&vw, 1);
785 >                swap16((char *)&vw, 1);
786          d = (vw+.5)/65536.;
787          setcolor(col, d, d, d);
788          return(0);
789   }
790  
791  
792 < putcascii(col)                  /* put an ascii color to stdout */
793 < COLOR  col;
792 > static int
793 > putcascii(                      /* put an ascii color to stdout */
794 >        COLOR  col
795 > )
796   {
797          fprintf(stdout, "%15.3e %15.3e %15.3e\n",
798                          colval(col,ord[0]),
# Line 771 | Line 803 | COLOR  col;
803   }
804  
805  
806 < putcfloat(col)                  /* put a float color to stdout */
807 < COLOR  col;
806 > static int
807 > putcfloat(                      /* put a float color to stdout */
808 >        COLOR  col
809 > )
810   {
811          float  vf[3];
812  
# Line 780 | Line 814 | COLOR  col;
814          vf[1] = colval(col,ord[1]);
815          vf[2] = colval(col,ord[2]);
816          if (swapbytes)
817 <                swap32((uint32 *)vf, 3);
818 <        fwrite((char *)vf, sizeof(float), 3, stdout);
817 >                swap32((char *)vf, 3);
818 >        putbinary(vf, sizeof(float), 3, stdout);
819  
820          return(ferror(stdout) ? -1 : 0);
821   }
822  
823  
824 < putcdouble(col)                 /* put a double color to stdout */
825 < COLOR  col;
824 > static int
825 > putcdouble(                     /* put a double color to stdout */
826 >        COLOR  col
827 > )
828   {
829          double  vd[3];
830  
# Line 797 | Line 833 | COLOR  col;
833          vd[2] = colval(col,ord[2]);
834          if (swapbytes)
835                  swap64((char *)vd, 3);
836 <        fwrite((char *)vd, sizeof(double), 3, stdout);
836 >        putbinary(vd, sizeof(double), 3, stdout);
837  
838          return(ferror(stdout) ? -1 : 0);
839   }
840  
841  
842 < putcint(col)                    /* put an int color to stdout */
843 < COLOR  col;
842 > static int
843 > putcint(                        /* put an int color to stdout */
844 >        COLOR  col
845 > )
846   {
847          fprintf(stdout, "%d %d %d\n",
848                          (int)(colval(col,ord[0])*256.),
# Line 815 | Line 853 | COLOR  col;
853   }
854  
855  
856 < putcbyte(col)                   /* put a byte color to stdout */
857 < COLOR  col;
856 > static int
857 > putcbyte(                       /* put a byte color to stdout */
858 >        COLOR  col
859 > )
860   {
861          long  i;
862 <        BYTE  vb[3];
862 >        uby8  vb[3];
863  
864          i = colval(col,ord[0])*256.;
865          vb[0] = min(i,255);
# Line 827 | Line 867 | COLOR  col;
867          vb[1] = min(i,255);
868          i = colval(col,ord[2])*256.;
869          vb[2] = min(i,255);
870 <        fwrite((char *)vb, sizeof(BYTE), 3, stdout);
870 >        putbinary(vb, sizeof(uby8), 3, stdout);
871  
872          return(ferror(stdout) ? -1 : 0);
873   }
874  
875  
876 < putcword(col)                   /* put a 16-bit color to stdout */
877 < COLOR  col;
876 > static int
877 > putcword(                       /* put a 16-bit color to stdout */
878 >        COLOR  col
879 > )
880   {
881          long  i;
882          uint16  vw[3];
# Line 846 | Line 888 | COLOR  col;
888          i = colval(col,ord[2])*65536.;
889          vw[2] = min(i,65535);
890          if (swapbytes)
891 <                swap16(vw, 3);
892 <        fwrite((char *)vw, sizeof(uint16), 3, stdout);
891 >                swap16((char *)vw, 3);
892 >        putbinary(vw, sizeof(uint16), 3, stdout);
893  
894          return(ferror(stdout) ? -1 : 0);
895   }
896  
897  
898 < putbascii(col)                  /* put an ascii brightness to stdout */
899 < COLOR  col;
898 > static int
899 > putbascii(                      /* put an ascii brightness to stdout */
900 >        COLOR  col
901 > )
902   {
903          fprintf(stdout, "%15.3e\n", (*mybright)(col));
904  
# Line 862 | Line 906 | COLOR  col;
906   }
907  
908  
909 < putbfloat(col)                  /* put a float brightness to stdout */
910 < COLOR  col;
909 > static int
910 > putbfloat(                      /* put a float brightness to stdout */
911 >        COLOR  col
912 > )
913   {
914          float  vf;
915  
916          vf = (*mybright)(col);
917          if (swapbytes)
918 <                swap32((uint32 *)&vf, 1);
919 <        fwrite((char *)&vf, sizeof(float), 1, stdout);
918 >                swap32((char *)&vf, 1);
919 >        putbinary(&vf, sizeof(float), 1, stdout);
920  
921          return(ferror(stdout) ? -1 : 0);
922   }
923  
924  
925 < putbdouble(col)                 /* put a double brightness to stdout */
926 < COLOR  col;
925 > static int
926 > putbdouble(                     /* put a double brightness to stdout */
927 >        COLOR  col
928 > )
929   {
930          double  vd;
931  
932          vd = (*mybright)(col);
933          if (swapbytes)
934                  swap64((char *)&vd, 1);
935 <        fwrite((char *)&vd, sizeof(double), 1, stdout);
935 >        putbinary(&vd, sizeof(double), 1, stdout);
936  
937          return(ferror(stdout) ? -1 : 0);
938   }
939  
940  
941 < putbint(col)                    /* put an int brightness to stdout */
942 < COLOR  col;
941 > static int
942 > putbint(                        /* put an int brightness to stdout */
943 >        COLOR  col
944 > )
945   {
946          fprintf(stdout, "%d\n", (int)((*mybright)(col)*256.));
947  
# Line 899 | Line 949 | COLOR  col;
949   }
950  
951  
952 < putbbyte(col)                   /* put a byte brightness to stdout */
953 < COLOR  col;
952 > static int
953 > putbbyte(                       /* put a byte brightness to stdout */
954 >        COLOR  col
955 > )
956   {
957 <        register int  i;
958 <        BYTE  vb;
957 >        int  i;
958 >        uby8  vb;
959  
960          i = (*mybright)(col)*256.;
961          vb = min(i,255);
962 <        fwrite((char *)&vb, sizeof(BYTE), 1, stdout);
962 >        putbinary(&vb, sizeof(uby8), 1, stdout);
963  
964          return(ferror(stdout) ? -1 : 0);
965   }
966  
967  
968 < putbword(col)                   /* put a 16-bit brightness to stdout */
969 < COLOR  col;
968 > static int
969 > putbword(                       /* put a 16-bit brightness to stdout */
970 >        COLOR  col
971 > )
972   {
973          long  i;
974          uint16  vw;
# Line 922 | Line 976 | COLOR  col;
976          i = (*mybright)(col)*65536.;
977          vw = min(i,65535);
978          if (swapbytes)
979 <                swap16(&vw, 1);
980 <        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
979 >                swap16((char *)&vw, 1);
980 >        putbinary(&vw, sizeof(uint16), 1, stdout);
981  
982          return(ferror(stdout) ? -1 : 0);
983   }
984  
985  
986 < putpascii(col)                  /* put an ascii primary to stdout */
987 < COLOR  col;
986 > static int
987 > putpascii(                      /* put an ascii primary to stdout */
988 >        COLOR  col
989 > )
990   {
991          fprintf(stdout, "%15.3e\n", colval(col,putprim));
992  
# Line 938 | Line 994 | COLOR  col;
994   }
995  
996  
997 < putpfloat(col)                  /* put a float primary to stdout */
998 < COLOR  col;
997 > static int
998 > putpfloat(                      /* put a float primary to stdout */
999 >        COLOR  col
1000 > )
1001   {
1002          float  vf;
1003  
1004          vf = colval(col,putprim);
1005          if (swapbytes)
1006 <                swap32((uint32 *)&vf, 1);
1007 <        fwrite((char *)&vf, sizeof(float), 1, stdout);
1006 >                swap32((char *)&vf, 1);
1007 >        putbinary(&vf, sizeof(float), 1, stdout);
1008  
1009          return(ferror(stdout) ? -1 : 0);
1010   }
1011  
1012  
1013 < putpdouble(col)                 /* put a double primary to stdout */
1014 < COLOR  col;
1013 > static int
1014 > putpdouble(                     /* put a double primary to stdout */
1015 >        COLOR  col
1016 > )
1017   {
1018          double  vd;
1019  
1020          vd = colval(col,putprim);
1021          if (swapbytes)
1022                  swap64((char *)&vd, 1);
1023 <        fwrite((char *)&vd, sizeof(double), 1, stdout);
1023 >        putbinary(&vd, sizeof(double), 1, stdout);
1024  
1025          return(ferror(stdout) ? -1 : 0);
1026   }
1027  
1028  
1029 < putpint(col)                    /* put an int primary to stdout */
1030 < COLOR  col;
1029 > static int
1030 > putpint(                        /* put an int primary to stdout */
1031 >        COLOR  col
1032 > )
1033   {
1034          fprintf(stdout, "%d\n", (int)(colval(col,putprim)*256.));
1035  
# Line 975 | Line 1037 | COLOR  col;
1037   }
1038  
1039  
1040 < putpbyte(col)                   /* put a byte primary to stdout */
1041 < COLOR  col;
1040 > static int
1041 > putpbyte(                       /* put a byte primary to stdout */
1042 >        COLOR  col
1043 > )
1044   {
1045          long  i;
1046 <        BYTE  vb;
1046 >        uby8  vb;
1047  
1048          i = colval(col,putprim)*256.;
1049          vb = min(i,255);
1050 <        fwrite((char *)&vb, sizeof(BYTE), 1, stdout);
1050 >        putbinary(&vb, sizeof(uby8), 1, stdout);
1051  
1052          return(ferror(stdout) ? -1 : 0);
1053   }
1054  
1055  
1056 < putpword(col)                   /* put a 16-bit primary to stdout */
1057 < COLOR  col;
1056 > static int
1057 > putpword(                       /* put a 16-bit primary to stdout */
1058 >        COLOR  col
1059 > )
1060   {
1061          long  i;
1062          uint16  vw;
# Line 998 | Line 1064 | COLOR  col;
1064          i = colval(col,putprim)*65536.;
1065          vw = min(i,65535);
1066          if (swapbytes)
1067 <                swap16(&vw, 1);
1068 <        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
1067 >                swap16((char *)&vw, 1);
1068 >        putbinary(&vw, sizeof(uint16), 1, stdout);
1069  
1070          return(ferror(stdout) ? -1 : 0);
1071   }
1072  
1073  
1074 < set_io()                        /* set put and get functions */
1074 > static void
1075 > set_io(void)                    /* set put and get functions */
1076   {
1077          switch (format) {
1078          case 'a':                                       /* ascii */
# Line 1040 | Line 1107 | set_io()                       /* set put and get functions */
1107                                  if (fin2 == NULL)
1108                                          goto namerr;
1109                                  if (fseek(fin2,
1110 <                                (long)sizeof(float)*picres.xr*picres.yr, 1))
1110 >                                (long)sizeof(float)*picres.xr*picres.yr, SEEK_CUR))
1111                                          goto seekerr;
1112                                  if (fseek(fin3,
1113 <                                (long)sizeof(float)*2*picres.xr*picres.yr, 1))
1113 >                                (long)sizeof(float)*2*picres.xr*picres.yr, SEEK_CUR))
1114                                          goto seekerr;
1115                          }
1116                  }
# Line 1062 | Line 1129 | set_io()                       /* set put and get functions */
1129                                  if (fin2 == NULL)
1130                                          goto namerr;
1131                                  if (fseek(fin2,
1132 <                                (long)sizeof(double)*picres.xr*picres.yr, 1))
1132 >                                (long)sizeof(double)*picres.xr*picres.yr, SEEK_CUR))
1133                                          goto seekerr;
1134                                  if (fseek(fin3,
1135 <                                (long)sizeof(double)*2*picres.xr*picres.yr, 1))
1135 >                                (long)sizeof(double)*2*picres.xr*picres.yr, SEEK_CUR))
1136                                          goto seekerr;
1137                          }
1138                  }
# Line 1102 | Line 1169 | set_io()                       /* set put and get functions */
1169                                  if (fin2 == NULL)
1170                                          goto namerr;
1171                                  if (fseek(fin2,
1172 <                                (long)sizeof(BYTE)*picres.xr*picres.yr, 1))
1172 >                                (long)sizeof(uby8)*picres.xr*picres.yr, SEEK_CUR))
1173                                          goto seekerr;
1174                                  if (fseek(fin3,
1175 <                                (long)sizeof(BYTE)*2*picres.xr*picres.yr, 1))
1175 >                                (long)sizeof(uby8)*2*picres.xr*picres.yr, SEEK_CUR))
1176                                          goto seekerr;
1177                          }
1178                  }
# Line 1124 | Line 1191 | set_io()                       /* set put and get functions */
1191                                  if (fin2 == NULL)
1192                                          goto namerr;
1193                                  if (fseek(fin2,
1194 <                                (long)sizeof(uint16)*picres.xr*picres.yr, 1))
1194 >                                (long)sizeof(uint16)*picres.xr*picres.yr, SEEK_CUR))
1195                                          goto seekerr;
1196                                  if (fseek(fin3,
1197 <                                (long)sizeof(uint16)*2*picres.xr*picres.yr, 1))
1197 >                                (long)sizeof(uint16)*2*picres.xr*picres.yr, SEEK_CUR))
1198                                          goto seekerr;
1199                          }
1200                  }
1201                  return;
1202          }
1203 < badopt:
1203 > /* badopt: */ /* label not used */
1204          fprintf(stderr, "%s: botched file type\n", progname);
1205          quit(1);
1206   namerr:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines