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.15 by greg, Tue Feb 25 16:22:05 2003 UTC

# Line 15 | Line 15 | static const char      RCSid[] = "$Id$";
15  
16   #include  "resolu.h"
17  
18 + typedef unsigned short uint16;  /* sizeof (uint16) must == 2 */
19 +
20   #define  min(a,b)               ((a)<(b)?(a):(b))
21  
22                                  /* what to put out (also RED, GRN, BLU) */
# Line 167 | Line 169 | char  **argv;
169                                          format = 'b';
170                                          fmtid = "byte";
171                                          break;
172 +                                case 'w':               /* 16-bit */
173 +                                        dataonly = 1;
174 +                                        format = 'w';
175 +                                        fmtid = "16-bit";
176 +                                        break;
177                                  case 'f':               /* float */
178                                          dataonly = 1;
179                                          format = 'f';
# Line 212 | Line 219 | unkopt:
219                          fmtid = "8-bit_grey";
220                  else
221                          fmtid = "24-bit_rgb";
222 +        if (dataonly && format == 'w')
223 +                if (brightonly)
224 +                        fmtid = "16-bit_grey";
225 +                else
226 +                        fmtid = "48-bit_rgb";
227                                          /* assign reverse ordering */
228          rord[ord[0]] = 0;
229          rord[ord[1]] = 1;
# Line 594 | Line 606 | COLOR  col;
606   }
607  
608  
609 + getcword(col)           /* get a 16-bit color value from stream(s) */
610 + COLOR  col;
611 + {
612 +        uint16  vw[3];
613 +
614 +        if (fin2 == NULL) {
615 +                if (fread((char *)vw, sizeof(uint16), 3, fin) != 3)
616 +                        return(-1);
617 +        } else {
618 +                if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 ||
619 +                        fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 ||
620 +                        fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1)
621 +                        return(-1);
622 +        }
623 +        setcolor(col, (vw[rord[RED]]+.5)/65536.,
624 +                        (vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.);
625 +        return(0);
626 + }
627 +
628 +
629   getbascii(col)          /* get an ascii brightness value from fin */
630   COLOR  col;
631   {
# Line 658 | Line 690 | COLOR  col;
690   }
691  
692  
693 + getbword(col)           /* get a 16-bit brightness value from fin */
694 + COLOR  col;
695 + {
696 +        uint16  vw;
697 +        double  d;
698 +
699 +        if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1)
700 +                return(-1);
701 +        d = (vw+.5)/65536.;
702 +        setcolor(col, d, d, d);
703 +        return(0);
704 + }
705 +
706 +
707   putcascii(col)                  /* put an ascii color to stdout */
708   COLOR  col;
709   {
# Line 713 | Line 759 | COLOR  col;
759   putcbyte(col)                   /* put a byte color to stdout */
760   COLOR  col;
761   {
762 <        register int  i;
762 >        long  i;
763          BYTE  vb[3];
764  
765          i = colval(col,ord[0])*256.;
# Line 728 | Line 774 | COLOR  col;
774   }
775  
776  
777 + putcword(col)                   /* put a 16-bit color to stdout */
778 + COLOR  col;
779 + {
780 +        long  i;
781 +        uint16  vw[3];
782 +
783 +        i = colval(col,ord[0])*65536.;
784 +        vw[0] = min(i,65535);
785 +        i = colval(col,ord[1])*65536.;
786 +        vw[1] = min(i,65535);
787 +        i = colval(col,ord[2])*65536.;
788 +        vw[2] = min(i,65535);
789 +        fwrite((char *)vw, sizeof(uint16), 3, stdout);
790 +
791 +        return(ferror(stdout) ? -1 : 0);
792 + }
793 +
794 +
795   putbascii(col)                  /* put an ascii brightness to stdout */
796   COLOR  col;
797   {
# Line 784 | Line 848 | COLOR  col;
848   }
849  
850  
851 + putbword(col)                   /* put a 16-bit brightness to stdout */
852 + COLOR  col;
853 + {
854 +        long  i;
855 +        uint16  vw;
856 +
857 +        i = (*mybright)(col)*65536.;
858 +        vw = min(i,65535);
859 +        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
860 +
861 +        return(ferror(stdout) ? -1 : 0);
862 + }
863 +
864 +
865   putpascii(col)                  /* put an ascii primary to stdout */
866   COLOR  col;
867   {
# Line 829 | Line 907 | COLOR  col;
907   putpbyte(col)                   /* put a byte primary to stdout */
908   COLOR  col;
909   {
910 <        register int  i;
910 >        long  i;
911          BYTE  vb;
912  
913          i = colval(col,putprim)*256.;
# Line 840 | Line 918 | COLOR  col;
918   }
919  
920  
921 + putpword(col)                   /* put a 16-bit primary to stdout */
922 + COLOR  col;
923 + {
924 +        long  i;
925 +        uint16  vw;
926 +
927 +        i = colval(col,putprim)*65536.;
928 +        vw = min(i,65535);
929 +        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
930 +
931 +        return(ferror(stdout) ? -1 : 0);
932 + }
933 +
934 +
935   set_io()                        /* set put and get functions */
936   {
937          switch (format) {
# Line 941 | Line 1033 | set_io()                       /* set put and get functions */
1033                                          goto seekerr;
1034                                  if (fseek(fin3,
1035                                  (long)sizeof(BYTE)*2*picres.xr*picres.yr, 1))
1036 +                                        goto seekerr;
1037 +                        }
1038 +                }
1039 +                return;
1040 +        case 'w':                                       /* 16-bit */
1041 +                if (putprim == BRIGHT) {
1042 +                        getval = getbword;
1043 +                        putval = putbword;
1044 +                } else if (putprim != ALL) {
1045 +                        getval = getbword;
1046 +                        putval = putpword;
1047 +                } else {
1048 +                        getval = getcword;
1049 +                        putval = putcword;
1050 +                        if (reverse && !interleave) {
1051 +                                if (fin2 == NULL)
1052 +                                        goto namerr;
1053 +                                if (fseek(fin2,
1054 +                                (long)sizeof(uint16)*picres.xr*picres.yr, 1))
1055 +                                        goto seekerr;
1056 +                                if (fseek(fin3,
1057 +                                (long)sizeof(uint16)*2*picres.xr*picres.yr, 1))
1058                                          goto seekerr;
1059                          }
1060                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines