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.15 by greg, Tue Feb 25 16:22:05 2003 UTC vs.
Revision 2.22 by schorsch, Mon Jul 21 22:30:19 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  
18 typedef unsigned short uint16;  /* sizeof (uint16) must == 2 */
19
17   #define  min(a,b)               ((a)<(b)?(a):(b))
18  
19                                  /* what to put out (also RED, GRN, BLU) */
20   #define  ALL            3
21   #define  BRIGHT         4
22  
26 #define  brightonly     (putprim==BRIGHT)
27
23   RESOLU  picres;                 /* resolution of picture */
24  
25   int  uniq = 0;                  /* print only unique values? */
# Line 44 | 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 169 | 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';
# Line 214 | Line 213 | unkopt:
213                  else
214                          break;
215                                          /* recognize special formats */
216 <        if (dataonly && format == 'b')
217 <                if (brightonly)
219 <                        fmtid = "8-bit_grey";
220 <                else
216 >        if (dataonly && format == 'b') {
217 >                if (putprim == ALL)
218                          fmtid = "24-bit_rgb";
222        if (dataonly && format == 'w')
223                if (brightonly)
224                        fmtid = "16-bit_grey";
219                  else
220 +                        fmtid = "8-bit_grey";
221 +        }
222 +        if (dataonly && format == 'w') {
223 +                if (putprim == ALL)
224                          fmtid = "48-bit_rgb";
225 +                else
226 +                        fmtid = "16-bit_grey";
227 +        }
228                                          /* assign reverse ordering */
229          rord[ord[0]] = 0;
230          rord[ord[1]] = 1;
# Line 237 | 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 251 | 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 269 | 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 317 | 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 390 | Line 391 | pixtoval()                             /* convert picture to values */
391          register COLOR  *scanln;
392          int  dogamma;
393          COLOR  lastc;
394 <        FLOAT  hv[2];
394 >        RREAL  hv[2];
395          int  startprim, endprim;
396          long  startpos;
397          int  y;
# Line 422 | Line 423 | pixtoval()                             /* convert picture to values */
423                                  quit(1);
424                          }
425                          for (x = 0; x < scanlen(&picres); x++) {
426 <                                if (uniq)
426 >                                if (uniq) {
427                                          if (    colval(scanln[x],RED) ==
428                                                          colval(lastc,RED) &&
429                                                  colval(scanln[x],GRN) ==
# Line 432 | Line 433 | pixtoval()                             /* convert picture to values */
433                                                  continue;
434                                          else
435                                                  copycolor(lastc, scanln[x]);
436 +                                }
437                                  if (doexposure)
438                                          multcolor(scanln[x], exposure);
439                                  if (dogamma)
# Line 509 | Line 511 | int  code;
511   }
512  
513  
514 + swap16(wp, n)           /* swap n 16-bit words */
515 + register uint16  *wp;
516 + int  n;
517 + {
518 +        while (n-- > 0) {
519 +                *wp = *wp << 8 | ((*wp >> 8) & 0xff);
520 +                wp++;
521 +        }
522 + }
523 +
524   getcascii(col)          /* get an ascii color value from stream(s) */
525   COLOR  col;
526   {
# Line 620 | Line 632 | COLOR  col;
632                          fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1)
633                          return(-1);
634          }
635 +        if (swapbytes)
636 +                swap16(vw, 3);
637          setcolor(col, (vw[rord[RED]]+.5)/65536.,
638                          (vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.);
639          return(0);
# Line 698 | Line 712 | COLOR  col;
712  
713          if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1)
714                  return(-1);
715 +        if (swapbytes)
716 +                swap16(&vw, 1);
717          d = (vw+.5)/65536.;
718          setcolor(col, d, d, d);
719          return(0);
# Line 786 | Line 802 | COLOR  col;
802          vw[1] = min(i,65535);
803          i = colval(col,ord[2])*65536.;
804          vw[2] = min(i,65535);
805 +        if (swapbytes)
806 +                swap16(vw, 3);
807          fwrite((char *)vw, sizeof(uint16), 3, stdout);
808  
809          return(ferror(stdout) ? -1 : 0);
# Line 856 | Line 874 | COLOR  col;
874  
875          i = (*mybright)(col)*65536.;
876          vw = min(i,65535);
877 +        if (swapbytes)
878 +                swap16(&vw, 1);
879          fwrite((char *)&vw, sizeof(uint16), 1, stdout);
880  
881          return(ferror(stdout) ? -1 : 0);
# Line 926 | Line 946 | COLOR  col;
946  
947          i = colval(col,putprim)*65536.;
948          vw = min(i,65535);
949 +        if (swapbytes)
950 +                swap16(&vw, 1);
951          fwrite((char *)&vw, sizeof(uint16), 1, stdout);
952  
953          return(ferror(stdout) ? -1 : 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines