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.21 by schorsch, Thu Jun 26 00:58: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   #define  min(a,b)               ((a)<(b)?(a):(b))
# Line 21 | Line 20 | static const char      RCSid[] = "$Id$";
20   #define  ALL            3
21   #define  BRIGHT         4
22  
24 #define  brightonly     (putprim==BRIGHT)
25
23   RESOLU  picres;                 /* resolution of picture */
24  
25   int  uniq = 0;                  /* print only unique values? */
# Line 42 | Line 39 | int  header = 1;               /* do header? */
39  
40   long  skipbytes = 0;            /* skip bytes in input? */
41  
42 + int  swapbytes = 0;             /* swap bytes in 16-bit words? */
43 +
44   int  interleave = 1;            /* file is interleaved? */
45  
46   int  resolution = 1;            /* put/get resolution string? */
# Line 167 | Line 166 | char  **argv;
166                                          format = 'b';
167                                          fmtid = "byte";
168                                          break;
169 +                                case 'W':               /* 16-bit swapped */
170 +                                        swapbytes = 1;
171 +                                case 'w':               /* 16-bit */
172 +                                        dataonly = 1;
173 +                                        format = 'w';
174 +                                        fmtid = "16-bit";
175 +                                        break;
176                                  case 'f':               /* float */
177                                          dataonly = 1;
178                                          format = 'f';
# Line 208 | Line 214 | unkopt:
214                          break;
215                                          /* recognize special formats */
216          if (dataonly && format == 'b')
217 <                if (brightonly)
217 >                if (putprim == ALL)
218 >                        fmtid = "24-bit_rgb";
219 >                else
220                          fmtid = "8-bit_grey";
221 +        if (dataonly && format == 'w')
222 +                if (putprim == ALL)
223 +                        fmtid = "48-bit_rgb";
224                  else
225 <                        fmtid = "24-bit_rgb";
225 >                        fmtid = "16-bit_grey";
226                                          /* assign reverse ordering */
227          rord[ord[0]] = 0;
228          rord[ord[1]] = 1;
# Line 225 | Line 236 | unkopt:
236                                                  progname, argv[i]);
237                          quit(1);
238                  }
239 <                if (reverse && !brightonly && i == argc-3) {
239 >                if (reverse && putprim != BRIGHT && i == argc-3) {
240                          if ((fin2 = fopen(argv[i+1], "r")) == NULL) {
241                                  fprintf(stderr, "%s: can't open file \"%s\"\n",
242                                                  progname, argv[i+1]);
# Line 239 | Line 250 | unkopt:
250                          interleave = -1;
251                  } else if (i != argc-1)
252                          fin = NULL;
253 <                if (reverse && !brightonly && !interleave) {
253 >                if (reverse && putprim != BRIGHT && !interleave) {
254                          fin2 = fopen(argv[i], "r");
255                          fin3 = fopen(argv[i], "r");
256                  }
# Line 257 | Line 268 | unkopt:
268          }
269  
270          if (reverse) {
271 < #ifdef MSDOS
272 <                setmode(fileno(stdout), O_BINARY);
271 > #ifdef _WIN32
272 >                SET_FILE_BINARY(stdout);
273                  if (format != 'a' && format != 'i')
274 <                        setmode(fileno(fin), O_BINARY);
274 >                        SET_FILE_BINARY(fin);
275   #endif
276                                          /* get header */
277                  if (header) {
# Line 305 | Line 316 | unkopt:
316                  fputsresolu(&picres, stdout);   /* always put resolution */
317                  valtopix();
318          } else {
319 < #ifdef MSDOS
320 <                setmode(fileno(fin), O_BINARY);
319 > #ifdef _WIN32
320 >                SET_FILE_BINARY(fin);
321                  if (format != 'a' && format != 'i')
322 <                        setmode(fileno(stdout), O_BINARY);
322 >                        SET_FILE_BINARY(stdout);
323   #endif
324                                                  /* get header */
325                  getheader(fin, checkhead, NULL);
# Line 378 | Line 389 | pixtoval()                             /* convert picture to values */
389          register COLOR  *scanln;
390          int  dogamma;
391          COLOR  lastc;
392 <        FLOAT  hv[2];
392 >        RREAL  hv[2];
393          int  startprim, endprim;
394          long  startpos;
395          int  y;
# Line 497 | Line 508 | int  code;
508   }
509  
510  
511 + swap16(wp, n)           /* swap n 16-bit words */
512 + register uint16  *wp;
513 + int  n;
514 + {
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   {
# Line 594 | Line 615 | COLOR  col;
615   }
616  
617  
618 + getcword(col)           /* get a 16-bit color value from stream(s) */
619 + COLOR  col;
620 + {
621 +        uint16  vw[3];
622 +
623 +        if (fin2 == NULL) {
624 +                if (fread((char *)vw, sizeof(uint16), 3, fin) != 3)
625 +                        return(-1);
626 +        } else {
627 +                if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 ||
628 +                        fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 ||
629 +                        fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1)
630 +                        return(-1);
631 +        }
632 +        if (swapbytes)
633 +                swap16(vw, 3);
634 +        setcolor(col, (vw[rord[RED]]+.5)/65536.,
635 +                        (vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.);
636 +        return(0);
637 + }
638 +
639 +
640   getbascii(col)          /* get an ascii brightness value from fin */
641   COLOR  col;
642   {
# Line 658 | Line 701 | COLOR  col;
701   }
702  
703  
704 + getbword(col)           /* get a 16-bit brightness value from fin */
705 + COLOR  col;
706 + {
707 +        uint16  vw;
708 +        double  d;
709 +
710 +        if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1)
711 +                return(-1);
712 +        if (swapbytes)
713 +                swap16(&vw, 1);
714 +        d = (vw+.5)/65536.;
715 +        setcolor(col, d, d, d);
716 +        return(0);
717 + }
718 +
719 +
720   putcascii(col)                  /* put an ascii color to stdout */
721   COLOR  col;
722   {
# Line 713 | Line 772 | COLOR  col;
772   putcbyte(col)                   /* put a byte color to stdout */
773   COLOR  col;
774   {
775 <        register int  i;
775 >        long  i;
776          BYTE  vb[3];
777  
778          i = colval(col,ord[0])*256.;
# Line 728 | Line 787 | COLOR  col;
787   }
788  
789  
790 + putcword(col)                   /* put a 16-bit color to stdout */
791 + COLOR  col;
792 + {
793 +        long  i;
794 +        uint16  vw[3];
795 +
796 +        i = colval(col,ord[0])*65536.;
797 +        vw[0] = min(i,65535);
798 +        i = colval(col,ord[1])*65536.;
799 +        vw[1] = min(i,65535);
800 +        i = colval(col,ord[2])*65536.;
801 +        vw[2] = min(i,65535);
802 +        if (swapbytes)
803 +                swap16(vw, 3);
804 +        fwrite((char *)vw, sizeof(uint16), 3, stdout);
805 +
806 +        return(ferror(stdout) ? -1 : 0);
807 + }
808 +
809 +
810   putbascii(col)                  /* put an ascii brightness to stdout */
811   COLOR  col;
812   {
# Line 784 | Line 863 | COLOR  col;
863   }
864  
865  
866 + putbword(col)                   /* put a 16-bit brightness to stdout */
867 + COLOR  col;
868 + {
869 +        long  i;
870 +        uint16  vw;
871 +
872 +        i = (*mybright)(col)*65536.;
873 +        vw = min(i,65535);
874 +        if (swapbytes)
875 +                swap16(&vw, 1);
876 +        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
877 +
878 +        return(ferror(stdout) ? -1 : 0);
879 + }
880 +
881 +
882   putpascii(col)                  /* put an ascii primary to stdout */
883   COLOR  col;
884   {
# Line 829 | Line 924 | COLOR  col;
924   putpbyte(col)                   /* put a byte primary to stdout */
925   COLOR  col;
926   {
927 <        register int  i;
927 >        long  i;
928          BYTE  vb;
929  
930          i = colval(col,putprim)*256.;
# Line 840 | Line 935 | COLOR  col;
935   }
936  
937  
938 + putpword(col)                   /* put a 16-bit primary to stdout */
939 + COLOR  col;
940 + {
941 +        long  i;
942 +        uint16  vw;
943 +
944 +        i = colval(col,putprim)*65536.;
945 +        vw = min(i,65535);
946 +        if (swapbytes)
947 +                swap16(&vw, 1);
948 +        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
949 +
950 +        return(ferror(stdout) ? -1 : 0);
951 + }
952 +
953 +
954   set_io()                        /* set put and get functions */
955   {
956          switch (format) {
# Line 941 | Line 1052 | set_io()                       /* set put and get functions */
1052                                          goto seekerr;
1053                                  if (fseek(fin3,
1054                                  (long)sizeof(BYTE)*2*picres.xr*picres.yr, 1))
1055 +                                        goto seekerr;
1056 +                        }
1057 +                }
1058 +                return;
1059 +        case 'w':                                       /* 16-bit */
1060 +                if (putprim == BRIGHT) {
1061 +                        getval = getbword;
1062 +                        putval = putbword;
1063 +                } else if (putprim != ALL) {
1064 +                        getval = getbword;
1065 +                        putval = putpword;
1066 +                } else {
1067 +                        getval = getcword;
1068 +                        putval = putcword;
1069 +                        if (reverse && !interleave) {
1070 +                                if (fin2 == NULL)
1071 +                                        goto namerr;
1072 +                                if (fseek(fin2,
1073 +                                (long)sizeof(uint16)*picres.xr*picres.yr, 1))
1074 +                                        goto seekerr;
1075 +                                if (fseek(fin3,
1076 +                                (long)sizeof(uint16)*2*picres.xr*picres.yr, 1))
1077                                          goto seekerr;
1078                          }
1079                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines