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.14 by greg, Sat Feb 22 02:07:27 2003 UTC vs.
Revision 2.30 by greg, Thu Dec 16 21:34:41 2010 UTC

# Line 1 | Line 1
1   #ifndef lint
2 < static const char       RCSid[] = "$Id$";
2 > static const char RCSid[] = "$Id$";
3   #endif
4   /*
5   *  pvalue.c - program to print pixel values.
# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *     4/23/86
8   */
9  
10 + #include  "platform.h"
11   #include  "standard.h"
11
12   #include  "color.h"
13
14 #include  <time.h>
15
13   #include  "resolu.h"
14 + #include  "view.h"
15  
16   #define  min(a,b)               ((a)<(b)?(a):(b))
17  
# Line 21 | Line 19 | static const char      RCSid[] = "$Id$";
19   #define  ALL            3
20   #define  BRIGHT         4
21  
24 #define  brightonly     (putprim==BRIGHT)
25
22   RESOLU  picres;                 /* resolution of picture */
27
23   int  uniq = 0;                  /* print only unique values? */
29
24   int  doexposure = 0;            /* exposure change? (>100 to print) */
31
25   int  dataonly = 0;              /* data only format? */
33
26   int  putprim = ALL;             /* what to put out */
35
27   int  reverse = 0;               /* reverse conversion? */
37
28   int  format = 'a';              /* input/output format */
29   char  *fmtid = "ascii";         /* format identifier for header */
40
30   int  header = 1;                /* do header? */
42
31   long  skipbytes = 0;            /* skip bytes in input? */
32 <
32 > int  swapbytes = 0;             /* swap bytes? */
33   int  interleave = 1;            /* file is interleaved? */
46
34   int  resolution = 1;            /* put/get resolution string? */
48
35   int  original = 0;              /* convert to original values? */
50
36   int  wrongformat = 0;           /* wrong input format? */
52
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 62 | Line 49 | char  *progname;
49   FILE  *fin;
50   FILE  *fin2 = NULL, *fin3 = NULL;       /* for other color channels */
51  
65 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;
86 < char  **argv;
90 > int
91 > main(
92 >        int  argc,
93 >        char  **argv
94 > )
95   {
88        extern int  checkhead();
89        extern long  atol();
96          double  d, expval = 1.0;
97          int  i;
98  
99          progname = argv[0];
100 +        mybright = &rgb_bright; /* default */
101  
102          for (i = 1; i < argc; i++)
103                  if (argv[i][0] == '-' || argv[i][0] == '+')
# Line 142 | Line 149 | char  **argv;
149                          case 'b':               /* brightness values */
150                                  putprim = argv[i][0] == '-' ? BRIGHT : ALL;
151                                  break;
152 <                        case 'p':               /* put primary */
152 >                        case 'p':               /* primary controls */
153                                  switch (argv[i][2]) {
154 +                                /* these two options affect -r conversion */
155 +                                case '\0':
156 +                                        myprims[RED][CIEX] = atof(argv[++i]);
157 +                                        myprims[RED][CIEY] = atof(argv[++i]);
158 +                                        myprims[GRN][CIEX] = atof(argv[++i]);
159 +                                        myprims[GRN][CIEY] = atof(argv[++i]);
160 +                                        myprims[BLU][CIEX] = atof(argv[++i]);
161 +                                        myprims[BLU][CIEY] = atof(argv[++i]);
162 +                                        myprims[WHT][CIEX] = atof(argv[++i]);
163 +                                        myprims[WHT][CIEY] = atof(argv[++i]);
164 +                                        outprims = myprims;
165 +                                        break;
166 +                                case 'x': case 'X': outprims = NULL; break;
167 +                                /* the following options affect +r only */
168                                  case 'r': case 'R': putprim = RED; break;
169                                  case 'g': case 'G': putprim = GRN; break;
170                                  case 'b': case 'B': putprim = BLU; break;
# Line 167 | Line 188 | char  **argv;
188                                          format = 'b';
189                                          fmtid = "byte";
190                                          break;
191 +                                case 'W':               /* 16-bit swapped */
192 +                                        swapbytes = 1;
193 +                                case 'w':               /* 16-bit */
194 +                                        dataonly = 1;
195 +                                        format = 'w';
196 +                                        fmtid = "16-bit";
197 +                                        break;
198 +                                case 'F':               /* swapped floats */
199 +                                        swapbytes = 1;
200                                  case 'f':               /* float */
201                                          dataonly = 1;
202                                          format = 'f';
203                                          fmtid = "float";
204                                          break;
205 +                                case 'D':               /* swapped doubles */
206 +                                        swapbytes = 1;
207                                  case 'd':               /* double */
208                                          dataonly = 1;
209                                          format = 'd';
# Line 207 | Line 239 | unkopt:
239                  else
240                          break;
241                                          /* recognize special formats */
242 <        if (dataonly && format == 'b')
243 <                if (brightonly)
242 >        if (dataonly && format == 'b') {
243 >                if (putprim == ALL)
244 >                        fmtid = "24-bit_rgb";
245 >                else
246                          fmtid = "8-bit_grey";
247 +        }
248 +        if (dataonly && format == 'w') {
249 +                if (putprim == ALL)
250 +                        fmtid = "48-bit_rgb";
251                  else
252 <                        fmtid = "24-bit_rgb";
252 >                        fmtid = "16-bit_grey";
253 >        }
254                                          /* assign reverse ordering */
255          rord[ord[0]] = 0;
256          rord[ord[1]] = 1;
# Line 225 | Line 264 | unkopt:
264                                                  progname, argv[i]);
265                          quit(1);
266                  }
267 <                if (reverse && !brightonly && i == argc-3) {
267 >                if (reverse && putprim != BRIGHT && i == argc-3) {
268                          if ((fin2 = fopen(argv[i+1], "r")) == NULL) {
269                                  fprintf(stderr, "%s: can't open file \"%s\"\n",
270                                                  progname, argv[i+1]);
# Line 239 | Line 278 | unkopt:
278                          interleave = -1;
279                  } else if (i != argc-1)
280                          fin = NULL;
281 <                if (reverse && !brightonly && !interleave) {
281 >                if (reverse && putprim != BRIGHT && !interleave) {
282                          fin2 = fopen(argv[i], "r");
283                          fin3 = fopen(argv[i], "r");
284                  }
# Line 257 | Line 296 | unkopt:
296          }
297  
298          if (reverse) {
299 < #ifdef MSDOS
300 <                setmode(fileno(stdout), O_BINARY);
299 > #ifdef _WIN32
300 >                SET_FILE_BINARY(stdout);
301                  if (format != 'a' && format != 'i')
302 <                        setmode(fileno(fin), O_BINARY);
302 >                        SET_FILE_BINARY(fin);
303   #endif
304                                          /* get header */
305                  if (header) {
# Line 300 | Line 339 | unkopt:
339                  printargs(i, argv, stdout);
340                  if (expval < .99 || expval > 1.01)
341                          fputexpos(expval, stdout);
342 <                fputformat(COLRFMT, stdout);
342 >                if (outprims != NULL) {
343 >                        if (outprims != stdprims)
344 >                                fputprims(outprims, stdout);
345 >                        fputformat(COLRFMT, stdout);
346 >                } else                          /* XYZ data */
347 >                        fputformat(CIEFMT, stdout);
348                  putchar('\n');
349                  fputsresolu(&picres, stdout);   /* always put resolution */
350                  valtopix();
351          } else {
352 < #ifdef MSDOS
353 <                setmode(fileno(fin), O_BINARY);
352 > #ifdef _WIN32
353 >                SET_FILE_BINARY(fin);
354                  if (format != 'a' && format != 'i')
355 <                        setmode(fileno(stdout), O_BINARY);
355 >                        SET_FILE_BINARY(stdout);
356   #endif
357                                                  /* get header */
358                  getheader(fin, checkhead, NULL);
# Line 335 | Line 379 | unkopt:
379          }
380  
381          quit(0);
382 +        return 0; /* pro forma return */
383   }
384  
385  
386 < int
387 < checkhead(line)                         /* deal with line from header */
388 < char  *line;
386 > static int
387 > checkhead(                              /* deal with line from header */
388 >        char    *line,
389 >        void    *p
390 > )
391   {
392          char    fmt[32];
393          double  d;
394          COLOR   ctmp;
395  
396          if (formatval(fmt, line)) {
397 <                if (!strcmp(fmt, CIEFMT)) {
397 >                if (!strcmp(fmt, CIEFMT))
398                          mybright = &xyz_bright;
399 <                        if (original) {
353 <                                scalecolor(exposure, 1./WHTEFFICACY);
354 <                                doexposure++;
355 <                        }
356 <                } else if (!strcmp(fmt, COLRFMT))
399 >                else if (!strcmp(fmt, COLRFMT))
400                          mybright = &rgb_bright;
401                  else
402                          wrongformat++;
# Line 373 | Line 416 | char  *line;
416   }
417  
418  
419 < pixtoval()                              /* convert picture to values */
419 > static void
420 > pixtoval(void)                          /* convert picture to values */
421   {
422          register COLOR  *scanln;
423          int  dogamma;
424          COLOR  lastc;
425 <        FLOAT  hv[2];
425 >        RREAL  hv[2];
426          int  startprim, endprim;
427          long  startpos;
428          int  y;
# Line 410 | Line 454 | pixtoval()                             /* convert picture to values */
454                                  quit(1);
455                          }
456                          for (x = 0; x < scanlen(&picres); x++) {
457 <                                if (uniq)
457 >                                if (uniq) {
458                                          if (    colval(scanln[x],RED) ==
459                                                          colval(lastc,RED) &&
460                                                  colval(scanln[x],GRN) ==
# Line 420 | Line 464 | pixtoval()                             /* convert picture to values */
464                                                  continue;
465                                          else
466                                                  copycolor(lastc, scanln[x]);
467 +                                }
468                                  if (doexposure)
469                                          multcolor(scanln[x], exposure);
470                                  if (dogamma)
# Line 445 | Line 490 | pixtoval()                             /* convert picture to values */
490   }
491  
492  
493 < valtopix()                      /* convert values to a pixel file */
493 > static void
494 > valtopix(void)                  /* convert values to a pixel file */
495   {
496          int  dogamma;
497          register COLOR  *scanln;
# Line 497 | Line 543 | int  code;
543   }
544  
545  
546 < getcascii(col)          /* get an ascii color value from stream(s) */
547 < COLOR  col;
546 > static int
547 > getcascii(              /* get an ascii color value from stream(s) */
548 >        COLOR  col
549 > )
550   {
551          double  vd[3];
552  
# Line 516 | Line 564 | COLOR  col;
564   }
565  
566  
567 < getcdouble(col)         /* get a double color value from stream(s) */
568 < COLOR  col;
567 > static int
568 > getcdouble(             /* get a double color value from stream(s) */
569 >        COLOR  col
570 > )
571   {
572          double  vd[3];
573  
# Line 530 | Line 580 | COLOR  col;
580                          fread((char *)(vd+2), sizeof(double), 1, fin3) != 1)
581                          return(-1);
582          }
583 +        if (swapbytes)
584 +                swap64((char *)vd, 3);
585          setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]);
586          return(0);
587   }
588  
589  
590 < getcfloat(col)          /* get a float color value from stream(s) */
591 < COLOR  col;
590 > static int
591 > getcfloat(              /* get a float color value from stream(s) */
592 >        COLOR  col
593 > )
594   {
595          float  vf[3];
596  
# Line 549 | Line 603 | COLOR  col;
603                          fread((char *)(vf+2), sizeof(float), 1, fin3) != 1)
604                          return(-1);
605          }
606 +        if (swapbytes)
607 +                swap32((char *)vf, 3);
608          setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]);
609          return(0);
610   }
611  
612  
613 < getcint(col)            /* get an int color value from stream(s) */
614 < COLOR  col;
613 > static int
614 > getcint(                /* get an int color value from stream(s) */
615 >        COLOR  col
616 > )
617   {
618          int  vi[3];
619  
# Line 574 | Line 632 | COLOR  col;
632   }
633  
634  
635 < getcbyte(col)           /* get a byte color value from stream(s) */
636 < COLOR  col;
635 > static int
636 > getcbyte(               /* get a byte color value from stream(s) */
637 >        COLOR  col
638 > )
639   {
640          BYTE  vb[3];
641  
# Line 594 | Line 654 | COLOR  col;
654   }
655  
656  
657 < getbascii(col)          /* get an ascii brightness value from fin */
658 < COLOR  col;
657 > static int
658 > getcword(               /* get a 16-bit color value from stream(s) */
659 >        COLOR  col
660 > )
661   {
662 +        uint16  vw[3];
663 +
664 +        if (fin2 == NULL) {
665 +                if (fread((char *)vw, sizeof(uint16), 3, fin) != 3)
666 +                        return(-1);
667 +        } else {
668 +                if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 ||
669 +                        fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 ||
670 +                        fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1)
671 +                        return(-1);
672 +        }
673 +        if (swapbytes)
674 +                swap16((char *)vw, 3);
675 +        setcolor(col, (vw[rord[RED]]+.5)/65536.,
676 +                        (vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.);
677 +        return(0);
678 + }
679 +
680 +
681 + static int
682 + getbascii(              /* get an ascii brightness value from fin */
683 +        COLOR  col
684 + )
685 + {
686          double  vd;
687  
688          if (fscanf(fin, "%lf", &vd) != 1)
# Line 606 | Line 692 | COLOR  col;
692   }
693  
694  
695 < getbdouble(col)         /* get a double brightness value from fin */
696 < COLOR  col;
695 > static int
696 > getbdouble(             /* get a double brightness value from fin */
697 >        COLOR  col
698 > )
699   {
700          double  vd;
701  
702          if (fread((char *)&vd, sizeof(double), 1, fin) != 1)
703                  return(-1);
704 +        if (swapbytes)
705 +                swap64((char *)&vd, 1);
706          setcolor(col, vd, vd, vd);
707          return(0);
708   }
709  
710  
711 < getbfloat(col)          /* get a float brightness value from fin */
712 < COLOR  col;
711 > static int
712 > getbfloat(              /* get a float brightness value from fin */
713 >        COLOR  col
714 > )
715   {
716          float  vf;
717  
718          if (fread((char *)&vf, sizeof(float), 1, fin) != 1)
719                  return(-1);
720 +        if (swapbytes)
721 +                swap32((char *)&vf, 1);
722          setcolor(col, vf, vf, vf);
723          return(0);
724   }
725  
726  
727 < getbint(col)            /* get an int brightness value from fin */
728 < COLOR  col;
727 > static int
728 > getbint(                /* get an int brightness value from fin */
729 >        COLOR  col
730 > )
731   {
732          int  vi;
733          double  d;
# Line 644 | Line 740 | COLOR  col;
740   }
741  
742  
743 < getbbyte(col)           /* get a byte brightness value from fin */
744 < COLOR  col;
743 > static int
744 > getbbyte(               /* get a byte brightness value from fin */
745 >        COLOR  col
746 > )
747   {
748          BYTE  vb;
749          double  d;
# Line 658 | Line 756 | COLOR  col;
756   }
757  
758  
759 < putcascii(col)                  /* put an ascii color to stdout */
760 < COLOR  col;
759 > static int
760 > getbword(               /* get a 16-bit brightness value from fin */
761 >        COLOR  col
762 > )
763   {
764 +        uint16  vw;
765 +        double  d;
766 +
767 +        if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1)
768 +                return(-1);
769 +        if (swapbytes)
770 +                swap16((char *)&vw, 1);
771 +        d = (vw+.5)/65536.;
772 +        setcolor(col, d, d, d);
773 +        return(0);
774 + }
775 +
776 +
777 + static int
778 + putcascii(                      /* put an ascii color to stdout */
779 +        COLOR  col
780 + )
781 + {
782          fprintf(stdout, "%15.3e %15.3e %15.3e\n",
783                          colval(col,ord[0]),
784                          colval(col,ord[1]),
# Line 670 | Line 788 | COLOR  col;
788   }
789  
790  
791 < putcfloat(col)                  /* put a float color to stdout */
792 < COLOR  col;
791 > static int
792 > putcfloat(                      /* put a float color to stdout */
793 >        COLOR  col
794 > )
795   {
796          float  vf[3];
797  
798          vf[0] = colval(col,ord[0]);
799          vf[1] = colval(col,ord[1]);
800          vf[2] = colval(col,ord[2]);
801 +        if (swapbytes)
802 +                swap32((char *)vf, 3);
803          fwrite((char *)vf, sizeof(float), 3, stdout);
804  
805          return(ferror(stdout) ? -1 : 0);
806   }
807  
808  
809 < putcdouble(col)                 /* put a double color to stdout */
810 < COLOR  col;
809 > static int
810 > putcdouble(                     /* put a double color to stdout */
811 >        COLOR  col
812 > )
813   {
814          double  vd[3];
815  
816          vd[0] = colval(col,ord[0]);
817          vd[1] = colval(col,ord[1]);
818          vd[2] = colval(col,ord[2]);
819 +        if (swapbytes)
820 +                swap64((char *)vd, 3);
821          fwrite((char *)vd, sizeof(double), 3, stdout);
822  
823          return(ferror(stdout) ? -1 : 0);
824   }
825  
826  
827 < putcint(col)                    /* put an int color to stdout */
828 < COLOR  col;
827 > static int
828 > putcint(                        /* put an int color to stdout */
829 >        COLOR  col
830 > )
831   {
832          fprintf(stdout, "%d %d %d\n",
833                          (int)(colval(col,ord[0])*256.),
# Line 710 | Line 838 | COLOR  col;
838   }
839  
840  
841 < putcbyte(col)                   /* put a byte color to stdout */
842 < COLOR  col;
841 > static int
842 > putcbyte(                       /* put a byte color to stdout */
843 >        COLOR  col
844 > )
845   {
846 <        register int  i;
846 >        long  i;
847          BYTE  vb[3];
848  
849          i = colval(col,ord[0])*256.;
# Line 728 | Line 858 | COLOR  col;
858   }
859  
860  
861 < putbascii(col)                  /* put an ascii brightness to stdout */
862 < COLOR  col;
861 > static int
862 > putcword(                       /* put a 16-bit color to stdout */
863 >        COLOR  col
864 > )
865   {
866 +        long  i;
867 +        uint16  vw[3];
868 +
869 +        i = colval(col,ord[0])*65536.;
870 +        vw[0] = min(i,65535);
871 +        i = colval(col,ord[1])*65536.;
872 +        vw[1] = min(i,65535);
873 +        i = colval(col,ord[2])*65536.;
874 +        vw[2] = min(i,65535);
875 +        if (swapbytes)
876 +                swap16((char *)vw, 3);
877 +        fwrite((char *)vw, sizeof(uint16), 3, stdout);
878 +
879 +        return(ferror(stdout) ? -1 : 0);
880 + }
881 +
882 +
883 + static int
884 + putbascii(                      /* put an ascii brightness to stdout */
885 +        COLOR  col
886 + )
887 + {
888          fprintf(stdout, "%15.3e\n", (*mybright)(col));
889  
890          return(ferror(stdout) ? -1 : 0);
891   }
892  
893  
894 < putbfloat(col)                  /* put a float brightness to stdout */
895 < COLOR  col;
894 > static int
895 > putbfloat(                      /* put a float brightness to stdout */
896 >        COLOR  col
897 > )
898   {
899          float  vf;
900  
901          vf = (*mybright)(col);
902 +        if (swapbytes)
903 +                swap32((char *)&vf, 1);
904          fwrite((char *)&vf, sizeof(float), 1, stdout);
905  
906          return(ferror(stdout) ? -1 : 0);
907   }
908  
909  
910 < putbdouble(col)                 /* put a double brightness to stdout */
911 < COLOR  col;
910 > static int
911 > putbdouble(                     /* put a double brightness to stdout */
912 >        COLOR  col
913 > )
914   {
915          double  vd;
916  
917          vd = (*mybright)(col);
918 +        if (swapbytes)
919 +                swap64((char *)&vd, 1);
920          fwrite((char *)&vd, sizeof(double), 1, stdout);
921  
922          return(ferror(stdout) ? -1 : 0);
923   }
924  
925  
926 < putbint(col)                    /* put an int brightness to stdout */
927 < COLOR  col;
926 > static int
927 > putbint(                        /* put an int brightness to stdout */
928 >        COLOR  col
929 > )
930   {
931          fprintf(stdout, "%d\n", (int)((*mybright)(col)*256.));
932  
# Line 770 | Line 934 | COLOR  col;
934   }
935  
936  
937 < putbbyte(col)                   /* put a byte brightness to stdout */
938 < COLOR  col;
937 > static int
938 > putbbyte(                       /* put a byte brightness to stdout */
939 >        COLOR  col
940 > )
941   {
942          register int  i;
943          BYTE  vb;
# Line 784 | Line 950 | COLOR  col;
950   }
951  
952  
953 < putpascii(col)                  /* put an ascii primary to stdout */
954 < COLOR  col;
953 > static int
954 > putbword(                       /* put a 16-bit brightness to stdout */
955 >        COLOR  col
956 > )
957   {
958 +        long  i;
959 +        uint16  vw;
960 +
961 +        i = (*mybright)(col)*65536.;
962 +        vw = min(i,65535);
963 +        if (swapbytes)
964 +                swap16((char *)&vw, 1);
965 +        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
966 +
967 +        return(ferror(stdout) ? -1 : 0);
968 + }
969 +
970 +
971 + static int
972 + putpascii(                      /* put an ascii primary to stdout */
973 +        COLOR  col
974 + )
975 + {
976          fprintf(stdout, "%15.3e\n", colval(col,putprim));
977  
978          return(ferror(stdout) ? -1 : 0);
979   }
980  
981  
982 < putpfloat(col)                  /* put a float primary to stdout */
983 < COLOR  col;
982 > static int
983 > putpfloat(                      /* put a float primary to stdout */
984 >        COLOR  col
985 > )
986   {
987          float  vf;
988  
989          vf = colval(col,putprim);
990 +        if (swapbytes)
991 +                swap32((char *)&vf, 1);
992          fwrite((char *)&vf, sizeof(float), 1, stdout);
993  
994          return(ferror(stdout) ? -1 : 0);
995   }
996  
997  
998 < putpdouble(col)                 /* put a double primary to stdout */
999 < COLOR  col;
998 > static int
999 > putpdouble(                     /* put a double primary to stdout */
1000 >        COLOR  col
1001 > )
1002   {
1003          double  vd;
1004  
1005          vd = colval(col,putprim);
1006 +        if (swapbytes)
1007 +                swap64((char *)&vd, 1);
1008          fwrite((char *)&vd, sizeof(double), 1, stdout);
1009  
1010          return(ferror(stdout) ? -1 : 0);
1011   }
1012  
1013  
1014 < putpint(col)                    /* put an int primary to stdout */
1015 < COLOR  col;
1014 > static int
1015 > putpint(                        /* put an int primary to stdout */
1016 >        COLOR  col
1017 > )
1018   {
1019          fprintf(stdout, "%d\n", (int)(colval(col,putprim)*256.));
1020  
# Line 826 | Line 1022 | COLOR  col;
1022   }
1023  
1024  
1025 < putpbyte(col)                   /* put a byte primary to stdout */
1026 < COLOR  col;
1025 > static int
1026 > putpbyte(                       /* put a byte primary to stdout */
1027 >        COLOR  col
1028 > )
1029   {
1030 <        register int  i;
1030 >        long  i;
1031          BYTE  vb;
1032  
1033          i = colval(col,putprim)*256.;
# Line 840 | Line 1038 | COLOR  col;
1038   }
1039  
1040  
1041 < set_io()                        /* set put and get functions */
1041 > static int
1042 > putpword(                       /* put a 16-bit primary to stdout */
1043 >        COLOR  col
1044 > )
1045   {
1046 +        long  i;
1047 +        uint16  vw;
1048 +
1049 +        i = colval(col,putprim)*65536.;
1050 +        vw = min(i,65535);
1051 +        if (swapbytes)
1052 +                swap16((char *)&vw, 1);
1053 +        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
1054 +
1055 +        return(ferror(stdout) ? -1 : 0);
1056 + }
1057 +
1058 +
1059 + static void
1060 + set_io(void)                    /* set put and get functions */
1061 + {
1062          switch (format) {
1063          case 'a':                                       /* ascii */
1064                  if (putprim == BRIGHT) {
# Line 945 | Line 1162 | set_io()                       /* set put and get functions */
1162                          }
1163                  }
1164                  return;
1165 +        case 'w':                                       /* 16-bit */
1166 +                if (putprim == BRIGHT) {
1167 +                        getval = getbword;
1168 +                        putval = putbword;
1169 +                } else if (putprim != ALL) {
1170 +                        getval = getbword;
1171 +                        putval = putpword;
1172 +                } else {
1173 +                        getval = getcword;
1174 +                        putval = putcword;
1175 +                        if (reverse && !interleave) {
1176 +                                if (fin2 == NULL)
1177 +                                        goto namerr;
1178 +                                if (fseek(fin2,
1179 +                                (long)sizeof(uint16)*picres.xr*picres.yr, 1))
1180 +                                        goto seekerr;
1181 +                                if (fseek(fin3,
1182 +                                (long)sizeof(uint16)*2*picres.xr*picres.yr, 1))
1183 +                                        goto seekerr;
1184 +                        }
1185 +                }
1186 +                return;
1187          }
1188 < badopt:
1188 > /* badopt: */ /* label not used */
1189          fprintf(stderr, "%s: botched file type\n", progname);
1190          quit(1);
1191   namerr:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines