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.19 by schorsch, Sun Jun 8 12:03:10 2003 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  "standard.h"
11
12 #include  "color.h"
13
10   #include  <time.h>
11  
12 + #include  "standard.h"
13 + #include  "platform.h"
14 + #include  "color.h"
15   #include  "resolu.h"
16  
17 + typedef unsigned short uint16;  /* sizeof (uint16) must == 2 */
18 +
19   #define  min(a,b)               ((a)<(b)?(a):(b))
20  
21                                  /* what to put out (also RED, GRN, BLU) */
22   #define  ALL            3
23   #define  BRIGHT         4
24  
24 #define  brightonly     (putprim==BRIGHT)
25
25   RESOLU  picres;                 /* resolution of picture */
26  
27   int  uniq = 0;                  /* print only unique values? */
# Line 42 | Line 41 | int  header = 1;               /* do header? */
41  
42   long  skipbytes = 0;            /* skip bytes in input? */
43  
44 + int  swapbytes = 0;             /* swap bytes in 16-bit words? */
45 +
46   int  interleave = 1;            /* file is interleaved? */
47  
48   int  resolution = 1;            /* put/get resolution string? */
# Line 167 | Line 168 | char  **argv;
168                                          format = 'b';
169                                          fmtid = "byte";
170                                          break;
171 +                                case 'W':               /* 16-bit swapped */
172 +                                        swapbytes = 1;
173 +                                case 'w':               /* 16-bit */
174 +                                        dataonly = 1;
175 +                                        format = 'w';
176 +                                        fmtid = "16-bit";
177 +                                        break;
178                                  case 'f':               /* float */
179                                          dataonly = 1;
180                                          format = 'f';
# Line 208 | Line 216 | unkopt:
216                          break;
217                                          /* recognize special formats */
218          if (dataonly && format == 'b')
219 <                if (brightonly)
219 >                if (putprim == ALL)
220 >                        fmtid = "24-bit_rgb";
221 >                else
222                          fmtid = "8-bit_grey";
223 +        if (dataonly && format == 'w')
224 +                if (putprim == ALL)
225 +                        fmtid = "48-bit_rgb";
226                  else
227 <                        fmtid = "24-bit_rgb";
227 >                        fmtid = "16-bit_grey";
228                                          /* assign reverse ordering */
229          rord[ord[0]] = 0;
230          rord[ord[1]] = 1;
# Line 225 | Line 238 | unkopt:
238                                                  progname, argv[i]);
239                          quit(1);
240                  }
241 <                if (reverse && !brightonly && i == argc-3) {
241 >                if (reverse && putprim != BRIGHT && i == argc-3) {
242                          if ((fin2 = fopen(argv[i+1], "r")) == NULL) {
243                                  fprintf(stderr, "%s: can't open file \"%s\"\n",
244                                                  progname, argv[i+1]);
# Line 239 | Line 252 | unkopt:
252                          interleave = -1;
253                  } else if (i != argc-1)
254                          fin = NULL;
255 <                if (reverse && !brightonly && !interleave) {
255 >                if (reverse && putprim != BRIGHT && !interleave) {
256                          fin2 = fopen(argv[i], "r");
257                          fin3 = fopen(argv[i], "r");
258                  }
# Line 257 | Line 270 | unkopt:
270          }
271  
272          if (reverse) {
273 < #ifdef MSDOS
274 <                setmode(fileno(stdout), O_BINARY);
273 > #ifdef _WIN32
274 >                SET_FILE_BINARY(stdout);
275                  if (format != 'a' && format != 'i')
276 <                        setmode(fileno(fin), O_BINARY);
276 >                        SET_FILE_BINARY(fin);
277   #endif
278                                          /* get header */
279                  if (header) {
# Line 305 | Line 318 | unkopt:
318                  fputsresolu(&picres, stdout);   /* always put resolution */
319                  valtopix();
320          } else {
321 < #ifdef MSDOS
322 <                setmode(fileno(fin), O_BINARY);
321 > #ifdef _WIN32
322 >                SET_FILE_BINARY(fin);
323                  if (format != 'a' && format != 'i')
324 <                        setmode(fileno(stdout), O_BINARY);
324 >                        SET_FILE_BINARY(stdout);
325   #endif
326                                                  /* get header */
327                  getheader(fin, checkhead, NULL);
# Line 497 | Line 510 | int  code;
510   }
511  
512  
513 + swap16(wp, n)           /* swap n 16-bit words */
514 + register uint16  *wp;
515 + int  n;
516 + {
517 +        while (n-- > 0) {
518 +                *wp = *wp << 8 | ((*wp >> 8) & 0xff);
519 +                wp++;
520 +        }
521 + }
522 +
523   getcascii(col)          /* get an ascii color value from stream(s) */
524   COLOR  col;
525   {
# Line 594 | Line 617 | COLOR  col;
617   }
618  
619  
620 + getcword(col)           /* get a 16-bit color value from stream(s) */
621 + COLOR  col;
622 + {
623 +        uint16  vw[3];
624 +
625 +        if (fin2 == NULL) {
626 +                if (fread((char *)vw, sizeof(uint16), 3, fin) != 3)
627 +                        return(-1);
628 +        } else {
629 +                if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 ||
630 +                        fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 ||
631 +                        fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1)
632 +                        return(-1);
633 +        }
634 +        if (swapbytes)
635 +                swap16(vw, 3);
636 +        setcolor(col, (vw[rord[RED]]+.5)/65536.,
637 +                        (vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.);
638 +        return(0);
639 + }
640 +
641 +
642   getbascii(col)          /* get an ascii brightness value from fin */
643   COLOR  col;
644   {
# Line 658 | Line 703 | COLOR  col;
703   }
704  
705  
706 + getbword(col)           /* get a 16-bit brightness value from fin */
707 + COLOR  col;
708 + {
709 +        uint16  vw;
710 +        double  d;
711 +
712 +        if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1)
713 +                return(-1);
714 +        if (swapbytes)
715 +                swap16(&vw, 1);
716 +        d = (vw+.5)/65536.;
717 +        setcolor(col, d, d, d);
718 +        return(0);
719 + }
720 +
721 +
722   putcascii(col)                  /* put an ascii color to stdout */
723   COLOR  col;
724   {
# Line 713 | Line 774 | COLOR  col;
774   putcbyte(col)                   /* put a byte color to stdout */
775   COLOR  col;
776   {
777 <        register int  i;
777 >        long  i;
778          BYTE  vb[3];
779  
780          i = colval(col,ord[0])*256.;
# Line 728 | Line 789 | COLOR  col;
789   }
790  
791  
792 + putcword(col)                   /* put a 16-bit color to stdout */
793 + COLOR  col;
794 + {
795 +        long  i;
796 +        uint16  vw[3];
797 +
798 +        i = colval(col,ord[0])*65536.;
799 +        vw[0] = min(i,65535);
800 +        i = colval(col,ord[1])*65536.;
801 +        vw[1] = min(i,65535);
802 +        i = colval(col,ord[2])*65536.;
803 +        vw[2] = min(i,65535);
804 +        if (swapbytes)
805 +                swap16(vw, 3);
806 +        fwrite((char *)vw, sizeof(uint16), 3, stdout);
807 +
808 +        return(ferror(stdout) ? -1 : 0);
809 + }
810 +
811 +
812   putbascii(col)                  /* put an ascii brightness to stdout */
813   COLOR  col;
814   {
# Line 784 | Line 865 | COLOR  col;
865   }
866  
867  
868 + putbword(col)                   /* put a 16-bit brightness to stdout */
869 + COLOR  col;
870 + {
871 +        long  i;
872 +        uint16  vw;
873 +
874 +        i = (*mybright)(col)*65536.;
875 +        vw = min(i,65535);
876 +        if (swapbytes)
877 +                swap16(&vw, 1);
878 +        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
879 +
880 +        return(ferror(stdout) ? -1 : 0);
881 + }
882 +
883 +
884   putpascii(col)                  /* put an ascii primary to stdout */
885   COLOR  col;
886   {
# Line 829 | Line 926 | COLOR  col;
926   putpbyte(col)                   /* put a byte primary to stdout */
927   COLOR  col;
928   {
929 <        register int  i;
929 >        long  i;
930          BYTE  vb;
931  
932          i = colval(col,putprim)*256.;
# Line 840 | Line 937 | COLOR  col;
937   }
938  
939  
940 + putpword(col)                   /* put a 16-bit primary to stdout */
941 + COLOR  col;
942 + {
943 +        long  i;
944 +        uint16  vw;
945 +
946 +        i = colval(col,putprim)*65536.;
947 +        vw = min(i,65535);
948 +        if (swapbytes)
949 +                swap16(&vw, 1);
950 +        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
951 +
952 +        return(ferror(stdout) ? -1 : 0);
953 + }
954 +
955 +
956   set_io()                        /* set put and get functions */
957   {
958          switch (format) {
# Line 941 | Line 1054 | set_io()                       /* set put and get functions */
1054                                          goto seekerr;
1055                                  if (fseek(fin3,
1056                                  (long)sizeof(BYTE)*2*picres.xr*picres.yr, 1))
1057 +                                        goto seekerr;
1058 +                        }
1059 +                }
1060 +                return;
1061 +        case 'w':                                       /* 16-bit */
1062 +                if (putprim == BRIGHT) {
1063 +                        getval = getbword;
1064 +                        putval = putbword;
1065 +                } else if (putprim != ALL) {
1066 +                        getval = getbword;
1067 +                        putval = putpword;
1068 +                } else {
1069 +                        getval = getcword;
1070 +                        putval = putcword;
1071 +                        if (reverse && !interleave) {
1072 +                                if (fin2 == NULL)
1073 +                                        goto namerr;
1074 +                                if (fseek(fin2,
1075 +                                (long)sizeof(uint16)*picres.xr*picres.yr, 1))
1076 +                                        goto seekerr;
1077 +                                if (fseek(fin3,
1078 +                                (long)sizeof(uint16)*2*picres.xr*picres.yr, 1))
1079                                          goto seekerr;
1080                          }
1081                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines