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.16 by greg, Tue Feb 25 16:47:23 2003 UTC vs.
Revision 2.25 by schorsch, Fri Jan 2 12:47:01 2004 UTC

# 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  
18 typedef unsigned short uint16;  /* sizeof (uint16) must == 2 */
19
15   #define  min(a,b)               ((a)<(b)?(a):(b))
16  
17                                  /* what to put out (also RED, GRN, BLU) */
18   #define  ALL            3
19   #define  BRIGHT         4
20  
26 #define  brightonly     (putprim==BRIGHT)
27
21   RESOLU  picres;                 /* resolution of picture */
22  
23   int  uniq = 0;                  /* print only unique values? */
# Line 44 | 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 68 | Line 61 | FILE  *fin2 = NULL, *fin3 = NULL;      /* for other color c
61  
62   int  (*getval)(), (*putval)();
63  
64 + static gethfunc checkhead;
65 +
66 +
67   double
68   rgb_bright(clr)
69   COLOR  clr;
# Line 89 | Line 85 | main(argc, argv)
85   int  argc;
86   char  **argv;
87   {
92        extern int  checkhead();
88          extern long  atol();
89          double  d, expval = 1.0;
90          int  i;
# Line 178 | Line 173 | char  **argv;
173                                          format = 'w';
174                                          fmtid = "16-bit";
175                                          break;
176 +                                case 'F':               /* swapped floats */
177 +                                        swapbytes = 1;
178                                  case 'f':               /* float */
179                                          dataonly = 1;
180                                          format = 'f';
181                                          fmtid = "float";
182                                          break;
183 +                                case 'D':               /* swapped doubles */
184 +                                        swapbytes = 1;
185                                  case 'd':               /* double */
186                                          dataonly = 1;
187                                          format = 'd';
# Line 218 | Line 217 | unkopt:
217                  else
218                          break;
219                                          /* recognize special formats */
220 <        if (dataonly && format == 'b')
221 <                if (brightonly)
223 <                        fmtid = "8-bit_grey";
224 <                else
220 >        if (dataonly && format == 'b') {
221 >                if (putprim == ALL)
222                          fmtid = "24-bit_rgb";
226        if (dataonly && format == 'w')
227                if (brightonly)
228                        fmtid = "16-bit_grey";
223                  else
224 +                        fmtid = "8-bit_grey";
225 +        }
226 +        if (dataonly && format == 'w') {
227 +                if (putprim == ALL)
228                          fmtid = "48-bit_rgb";
229 +                else
230 +                        fmtid = "16-bit_grey";
231 +        }
232                                          /* assign reverse ordering */
233          rord[ord[0]] = 0;
234          rord[ord[1]] = 1;
# Line 241 | Line 242 | unkopt:
242                                                  progname, argv[i]);
243                          quit(1);
244                  }
245 <                if (reverse && !brightonly && i == argc-3) {
245 >                if (reverse && putprim != BRIGHT && i == argc-3) {
246                          if ((fin2 = fopen(argv[i+1], "r")) == NULL) {
247                                  fprintf(stderr, "%s: can't open file \"%s\"\n",
248                                                  progname, argv[i+1]);
# Line 255 | Line 256 | unkopt:
256                          interleave = -1;
257                  } else if (i != argc-1)
258                          fin = NULL;
259 <                if (reverse && !brightonly && !interleave) {
259 >                if (reverse && putprim != BRIGHT && !interleave) {
260                          fin2 = fopen(argv[i], "r");
261                          fin3 = fopen(argv[i], "r");
262                  }
# Line 273 | Line 274 | unkopt:
274          }
275  
276          if (reverse) {
277 < #ifdef MSDOS
278 <                setmode(fileno(stdout), O_BINARY);
277 > #ifdef _WIN32
278 >                SET_FILE_BINARY(stdout);
279                  if (format != 'a' && format != 'i')
280 <                        setmode(fileno(fin), O_BINARY);
280 >                        SET_FILE_BINARY(fin);
281   #endif
282                                          /* get header */
283                  if (header) {
# Line 321 | Line 322 | unkopt:
322                  fputsresolu(&picres, stdout);   /* always put resolution */
323                  valtopix();
324          } else {
325 < #ifdef MSDOS
326 <                setmode(fileno(fin), O_BINARY);
325 > #ifdef _WIN32
326 >                SET_FILE_BINARY(fin);
327                  if (format != 'a' && format != 'i')
328 <                        setmode(fileno(stdout), O_BINARY);
328 >                        SET_FILE_BINARY(stdout);
329   #endif
330                                                  /* get header */
331                  getheader(fin, checkhead, NULL);
# Line 354 | Line 355 | unkopt:
355   }
356  
357  
358 < int
359 < checkhead(line)                         /* deal with line from header */
360 < char  *line;
358 > static int
359 > checkhead(                              /* deal with line from header */
360 >        char    *line,
361 >        void    *p
362 > )
363   {
364          char    fmt[32];
365          double  d;
# Line 394 | Line 397 | pixtoval()                             /* convert picture to values */
397          register COLOR  *scanln;
398          int  dogamma;
399          COLOR  lastc;
400 <        FLOAT  hv[2];
400 >        RREAL  hv[2];
401          int  startprim, endprim;
402          long  startpos;
403          int  y;
# Line 426 | Line 429 | pixtoval()                             /* convert picture to values */
429                                  quit(1);
430                          }
431                          for (x = 0; x < scanlen(&picres); x++) {
432 <                                if (uniq)
432 >                                if (uniq) {
433                                          if (    colval(scanln[x],RED) ==
434                                                          colval(lastc,RED) &&
435                                                  colval(scanln[x],GRN) ==
# Line 436 | Line 439 | pixtoval()                             /* convert picture to values */
439                                                  continue;
440                                          else
441                                                  copycolor(lastc, scanln[x]);
442 +                                }
443                                  if (doexposure)
444                                          multcolor(scanln[x], exposure);
445                                  if (dogamma)
# Line 523 | Line 527 | int  n;
527          }
528   }
529  
530 +
531 + swap32(wp, n)           /* swap n 32-bit words */
532 + register uint32  *wp;
533 + int  n;
534 + {
535 +        while (n-- > 0) {
536 +                *wp = *wp << 24 | ((*wp >> 24) & 0xff) |
537 +                        (*wp & 0xff00) << 8 | (*wp & 0xff0000) >> 8;
538 +                wp++;
539 +        }
540 + }
541 +
542 +
543 + swap64(wp, n)           /* swap n 64-bit words */
544 + register char  *wp;
545 + int  n;
546 + {
547 +        register int    t;
548 +
549 +        while (n-- > 0) {
550 +                t = wp[0]; wp[0] = wp[7]; wp[7] = t;
551 +                t = wp[1]; wp[1] = wp[6]; wp[6] = t;
552 +                t = wp[2]; wp[2] = wp[5]; wp[5] = t;
553 +                t = wp[3]; wp[3] = wp[4]; wp[4] = t;
554 +                wp += 8;
555 +        }
556 + }
557 +
558 +
559   getcascii(col)          /* get an ascii color value from stream(s) */
560   COLOR  col;
561   {
# Line 556 | Line 589 | COLOR  col;
589                          fread((char *)(vd+2), sizeof(double), 1, fin3) != 1)
590                          return(-1);
591          }
592 +        if (swapbytes)
593 +                swap64((char *)vd, 3);
594          setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]);
595          return(0);
596   }
# Line 575 | Line 610 | COLOR  col;
610                          fread((char *)(vf+2), sizeof(float), 1, fin3) != 1)
611                          return(-1);
612          }
613 +        if (swapbytes)
614 +                swap32((uint32 *)vf, 3);
615          setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]);
616          return(0);
617   }
# Line 661 | Line 698 | COLOR  col;
698  
699          if (fread((char *)&vd, sizeof(double), 1, fin) != 1)
700                  return(-1);
701 +        if (swapbytes)
702 +                swap64((char *)&vd, 1);
703          setcolor(col, vd, vd, vd);
704          return(0);
705   }
# Line 673 | Line 712 | COLOR  col;
712  
713          if (fread((char *)&vf, sizeof(float), 1, fin) != 1)
714                  return(-1);
715 +        if (swapbytes)
716 +                swap32((uint32 *)&vf, 1);
717          setcolor(col, vf, vf, vf);
718          return(0);
719   }
# Line 742 | Line 783 | COLOR  col;
783          vf[0] = colval(col,ord[0]);
784          vf[1] = colval(col,ord[1]);
785          vf[2] = colval(col,ord[2]);
786 +        if (swapbytes)
787 +                swap32((uint32 *)vf, 3);
788          fwrite((char *)vf, sizeof(float), 3, stdout);
789  
790          return(ferror(stdout) ? -1 : 0);
# Line 756 | Line 799 | COLOR  col;
799          vd[0] = colval(col,ord[0]);
800          vd[1] = colval(col,ord[1]);
801          vd[2] = colval(col,ord[2]);
802 +        if (swapbytes)
803 +                swap64((char *)vd, 3);
804          fwrite((char *)vd, sizeof(double), 3, stdout);
805  
806          return(ferror(stdout) ? -1 : 0);
# Line 827 | Line 872 | COLOR  col;
872          float  vf;
873  
874          vf = (*mybright)(col);
875 +        if (swapbytes)
876 +                swap32((uint32 *)&vf, 1);
877          fwrite((char *)&vf, sizeof(float), 1, stdout);
878  
879          return(ferror(stdout) ? -1 : 0);
# Line 839 | Line 886 | COLOR  col;
886          double  vd;
887  
888          vd = (*mybright)(col);
889 +        if (swapbytes)
890 +                swap64((char *)&vd, 1);
891          fwrite((char *)&vd, sizeof(double), 1, stdout);
892  
893          return(ferror(stdout) ? -1 : 0);
# Line 899 | Line 948 | COLOR  col;
948          float  vf;
949  
950          vf = colval(col,putprim);
951 +        if (swapbytes)
952 +                swap32((uint32 *)&vf, 1);
953          fwrite((char *)&vf, sizeof(float), 1, stdout);
954  
955          return(ferror(stdout) ? -1 : 0);
# Line 911 | Line 962 | COLOR  col;
962          double  vd;
963  
964          vd = colval(col,putprim);
965 +        if (swapbytes)
966 +                swap64((char *)&vd, 1);
967          fwrite((char *)&vd, sizeof(double), 1, stdout);
968  
969          return(ferror(stdout) ? -1 : 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines