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.22 by schorsch, Mon Jul 21 22:30:19 2003 UTC vs.
Revision 2.23 by greg, Sat Sep 13 15:24:13 2003 UTC

# Line 7 | Line 7 | static const char RCSid[] = "$Id$";
7   *     4/23/86
8   */
9  
10 #include  <time.h>
11
10   #include  "standard.h"
11   #include  "platform.h"
12   #include  "color.h"
# Line 39 | Line 37 | int  header = 1;               /* do header? */
37  
38   long  skipbytes = 0;            /* skip bytes in input? */
39  
40 < int  swapbytes = 0;             /* swap bytes in 16-bit words? */
40 > int  swapbytes = 0;             /* swap bytes? */
41  
42   int  interleave = 1;            /* file is interleaved? */
43  
# Line 173 | Line 171 | char  **argv;
171                                          format = 'w';
172                                          fmtid = "16-bit";
173                                          break;
174 +                                case 'F':               /* swapped floats */
175 +                                        swapbytes = 1;
176                                  case 'f':               /* float */
177                                          dataonly = 1;
178                                          format = 'f';
179                                          fmtid = "float";
180                                          break;
181 +                                case 'D':               /* swapped doubles */
182 +                                        swapbytes = 1;
183                                  case 'd':               /* double */
184                                          dataonly = 1;
185                                          format = 'd';
# Line 521 | Line 523 | int  n;
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   {
# Line 554 | Line 585 | COLOR  col;
585                          fread((char *)(vd+2), sizeof(double), 1, fin3) != 1)
586                          return(-1);
587          }
588 +        if (swapbytes)
589 +                swap64((char *)vd, 3);
590          setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]);
591          return(0);
592   }
# Line 573 | Line 606 | COLOR  col;
606                          fread((char *)(vf+2), sizeof(float), 1, fin3) != 1)
607                          return(-1);
608          }
609 +        if (swapbytes)
610 +                swap32((uint32 *)vf, 3);
611          setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]);
612          return(0);
613   }
# Line 659 | Line 694 | COLOR  col;
694  
695          if (fread((char *)&vd, sizeof(double), 1, fin) != 1)
696                  return(-1);
697 +        if (swapbytes)
698 +                swap64((char *)&vd, 1);
699          setcolor(col, vd, vd, vd);
700          return(0);
701   }
# Line 671 | Line 708 | COLOR  col;
708  
709          if (fread((char *)&vf, sizeof(float), 1, fin) != 1)
710                  return(-1);
711 +        if (swapbytes)
712 +                swap32((uint32 *)&vf, 1);
713          setcolor(col, vf, vf, vf);
714          return(0);
715   }
# Line 740 | Line 779 | COLOR  col;
779          vf[0] = colval(col,ord[0]);
780          vf[1] = colval(col,ord[1]);
781          vf[2] = colval(col,ord[2]);
782 +        if (swapbytes)
783 +                swap32((uint32 *)vf, 3);
784          fwrite((char *)vf, sizeof(float), 3, stdout);
785  
786          return(ferror(stdout) ? -1 : 0);
# Line 754 | Line 795 | COLOR  col;
795          vd[0] = colval(col,ord[0]);
796          vd[1] = colval(col,ord[1]);
797          vd[2] = colval(col,ord[2]);
798 +        if (swapbytes)
799 +                swap64((char *)vd, 3);
800          fwrite((char *)vd, sizeof(double), 3, stdout);
801  
802          return(ferror(stdout) ? -1 : 0);
# Line 825 | Line 868 | COLOR  col;
868          float  vf;
869  
870          vf = (*mybright)(col);
871 +        if (swapbytes)
872 +                swap32((uint32 *)&vf, 1);
873          fwrite((char *)&vf, sizeof(float), 1, stdout);
874  
875          return(ferror(stdout) ? -1 : 0);
# Line 837 | Line 882 | COLOR  col;
882          double  vd;
883  
884          vd = (*mybright)(col);
885 +        if (swapbytes)
886 +                swap64((char *)&vd, 1);
887          fwrite((char *)&vd, sizeof(double), 1, stdout);
888  
889          return(ferror(stdout) ? -1 : 0);
# Line 897 | Line 944 | COLOR  col;
944          float  vf;
945  
946          vf = colval(col,putprim);
947 +        if (swapbytes)
948 +                swap32((uint32 *)&vf, 1);
949          fwrite((char *)&vf, sizeof(float), 1, stdout);
950  
951          return(ferror(stdout) ? -1 : 0);
# Line 909 | Line 958 | COLOR  col;
958          double  vd;
959  
960          vd = colval(col,putprim);
961 +        if (swapbytes)
962 +                swap64((char *)&vd, 1);
963          fwrite((char *)&vd, sizeof(double), 1, stdout);
964  
965          return(ferror(stdout) ? -1 : 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines