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.12 by greg, Wed Jan 8 08:51:43 1997 UTC vs.
Revision 2.21 by schorsch, Thu Jun 26 00:58:10 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  pvalue.c - program to print pixel values.
6   *
7   *     4/23/86
8   */
9  
10 < #include  "standard.h"
10 > #include  <time.h>
11  
12 + #include  "standard.h"
13 + #include  "platform.h"
14   #include  "color.h"
16
15   #include  "resolu.h"
16  
17   #define  min(a,b)               ((a)<(b)?(a):(b))
# Line 22 | Line 20 | static char SCCSid[] = "$SunId$ LBL";
20   #define  ALL            3
21   #define  BRIGHT         4
22  
25 #define  brightonly     (putprim==BRIGHT)
26
23   RESOLU  picres;                 /* resolution of picture */
24  
25   int  uniq = 0;                  /* print only unique values? */
# Line 43 | 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 65 | Line 63 | FILE  *fin2 = NULL, *fin3 = NULL;      /* for other color c
63  
64   int  (*getval)(), (*putval)();
65  
66 + double
67 + rgb_bright(clr)
68 + COLOR  clr;
69 + {
70 +        return(bright(clr));
71 + }
72  
73 + double
74 + xyz_bright(clr)
75 + COLOR  clr;
76 + {
77 +        return(clr[CIEY]);
78 + }
79 +
80 + double  (*mybright)() = &rgb_bright;
81 +
82 +
83   main(argc, argv)
84   int  argc;
85   char  **argv;
# Line 152 | 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 170 | Line 191 | char  **argv;
191                          case 'X':               /* x resolution */
192                                  resolution = 0;
193                                  if (argv[i][0] == '-')
194 <                                        picres.or |= XDECR;
194 >                                        picres.rt |= XDECR;
195                                  picres.xr = atoi(argv[++i]);
196                                  break;
197                          case 'y':               /* y resolution */
198                          case 'Y':               /* y resolution */
199                                  resolution = 0;
200                                  if (argv[i][0] == '-')
201 <                                        picres.or |= YDECR;
201 >                                        picres.rt |= YDECR;
202                                  if (picres.xr == 0)
203 <                                        picres.or |= YMAJOR;
203 >                                        picres.rt |= YMAJOR;
204                                  picres.yr = atoi(argv[++i]);
205                                  break;
206                          default:
# Line 193 | 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 210 | 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 224 | 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 242 | 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 269 | Line 295 | unkopt:
295                  if (resolution && fin2 != NULL) {
296                          RESOLU  pres2;
297                          if (!fgetsresolu(&pres2, fin2) ||
298 <                                        pres2.or != picres.or ||
298 >                                        pres2.rt != picres.rt ||
299                                          pres2.xr != picres.xr ||
300                                          pres2.yr != picres.yr ||
301                                          !fgetsresolu(&pres2, fin3) ||
302 <                                        pres2.or != picres.or ||
302 >                                        pres2.rt != picres.rt ||
303                                          pres2.xr != picres.xr ||
304                                          pres2.yr != picres.yr) {
305                                  fprintf(stderr, "%s: resolution mismatch\n",
# Line 290 | 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);
326                  if (wrongformat) {
327 <                        fprintf(stderr, "%s: input not a Radiance picture\n",
327 >                        fprintf(stderr,
328 >                                "%s: input not a Radiance RGBE picture\n",
329                                          progname);
330                          quit(1);
331                  }
# Line 322 | Line 349 | unkopt:
349   }
350  
351  
352 + int
353   checkhead(line)                         /* deal with line from header */
354   char  *line;
355   {
# Line 329 | Line 357 | char  *line;
357          double  d;
358          COLOR   ctmp;
359  
360 <        if (formatval(fmt, line))
361 <                wrongformat = strcmp(fmt, COLRFMT);
362 <        else if (original && isexpos(line)) {
360 >        if (formatval(fmt, line)) {
361 >                if (!strcmp(fmt, CIEFMT)) {
362 >                        mybright = &xyz_bright;
363 >                        if (original) {
364 >                                scalecolor(exposure, 1./WHTEFFICACY);
365 >                                doexposure++;
366 >                        }
367 >                } else if (!strcmp(fmt, COLRFMT))
368 >                        mybright = &rgb_bright;
369 >                else
370 >                        wrongformat++;
371 >        } else if (original && isexpos(line)) {
372                  d = 1.0/exposval(line);
373                  scalecolor(exposure, d);
374                  doexposure++;
# Line 343 | Line 380 | char  *line;
380                  doexposure++;
381          } else if (header)
382                  fputs(line, stdout);
383 +        return(0);
384   }
385  
386  
# Line 351 | 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 414 | Line 452 | pixtoval()                             /* convert picture to values */
452                          }
453                  }
454          }
455 <        free((char *)scanln);
455 >        free((void *)scanln);
456   }
457  
458  
# Line 458 | Line 496 | valtopix()                     /* convert values to a pixel file */
496                          quit(1);
497                  }
498          }
499 <        free((char *)scanln);
499 >        free((void *)scanln);
500   }
501  
502  
503 + void
504   quit(code)
505   int  code;
506   {
# Line 469 | 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 566 | 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 630 | 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 685 | 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 700 | 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   {
813 <        fprintf(stdout, "%15.3e\n", bright(col));
813 >        fprintf(stdout, "%15.3e\n", (*mybright)(col));
814  
815          return(ferror(stdout) ? -1 : 0);
816   }
# Line 714 | Line 821 | COLOR  col;
821   {
822          float  vf;
823  
824 <        vf = bright(col);
824 >        vf = (*mybright)(col);
825          fwrite((char *)&vf, sizeof(float), 1, stdout);
826  
827          return(ferror(stdout) ? -1 : 0);
# Line 726 | Line 833 | COLOR  col;
833   {
834          double  vd;
835  
836 <        vd = bright(col);
836 >        vd = (*mybright)(col);
837          fwrite((char *)&vd, sizeof(double), 1, stdout);
838  
839          return(ferror(stdout) ? -1 : 0);
# Line 736 | Line 843 | COLOR  col;
843   putbint(col)                    /* put an int brightness to stdout */
844   COLOR  col;
845   {
846 <        fprintf(stdout, "%d\n", (int)(bright(col)*256.));
846 >        fprintf(stdout, "%d\n", (int)((*mybright)(col)*256.));
847  
848          return(ferror(stdout) ? -1 : 0);
849   }
# Line 748 | Line 855 | COLOR  col;
855          register int  i;
856          BYTE  vb;
857  
858 <        i = bright(col)*256.;
858 >        i = (*mybright)(col)*256.;
859          vb = min(i,255);
860          fwrite((char *)&vb, sizeof(BYTE), 1, stdout);
861  
# Line 756 | 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 801 | 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 812 | 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 913 | 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