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.15 by greg, Tue Feb 25 16:22:05 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   *
# Line 14 | Line 11 | static char SCCSid[] = "$SunId$ LBL";
11  
12   #include  "color.h"
13  
14 + #include  <time.h>
15 +
16   #include  "resolu.h"
17  
18 + typedef unsigned short uint16;  /* sizeof (uint16) must == 2 */
19 +
20   #define  min(a,b)               ((a)<(b)?(a):(b))
21  
22                                  /* what to put out (also RED, GRN, BLU) */
# Line 65 | Line 66 | FILE  *fin2 = NULL, *fin3 = NULL;      /* for other color c
66  
67   int  (*getval)(), (*putval)();
68  
69 + double
70 + rgb_bright(clr)
71 + COLOR  clr;
72 + {
73 +        return(bright(clr));
74 + }
75  
76 + double
77 + xyz_bright(clr)
78 + COLOR  clr;
79 + {
80 +        return(clr[CIEY]);
81 + }
82 +
83 + double  (*mybright)() = &rgb_bright;
84 +
85 +
86   main(argc, argv)
87   int  argc;
88   char  **argv;
# Line 152 | Line 169 | char  **argv;
169                                          format = 'b';
170                                          fmtid = "byte";
171                                          break;
172 +                                case 'w':               /* 16-bit */
173 +                                        dataonly = 1;
174 +                                        format = 'w';
175 +                                        fmtid = "16-bit";
176 +                                        break;
177                                  case 'f':               /* float */
178                                          dataonly = 1;
179                                          format = 'f';
# Line 170 | Line 192 | char  **argv;
192                          case 'X':               /* x resolution */
193                                  resolution = 0;
194                                  if (argv[i][0] == '-')
195 <                                        picres.or |= XDECR;
195 >                                        picres.rt |= XDECR;
196                                  picres.xr = atoi(argv[++i]);
197                                  break;
198                          case 'y':               /* y resolution */
199                          case 'Y':               /* y resolution */
200                                  resolution = 0;
201                                  if (argv[i][0] == '-')
202 <                                        picres.or |= YDECR;
202 >                                        picres.rt |= YDECR;
203                                  if (picres.xr == 0)
204 <                                        picres.or |= YMAJOR;
204 >                                        picres.rt |= YMAJOR;
205                                  picres.yr = atoi(argv[++i]);
206                                  break;
207                          default:
# Line 197 | Line 219 | unkopt:
219                          fmtid = "8-bit_grey";
220                  else
221                          fmtid = "24-bit_rgb";
222 +        if (dataonly && format == 'w')
223 +                if (brightonly)
224 +                        fmtid = "16-bit_grey";
225 +                else
226 +                        fmtid = "48-bit_rgb";
227                                          /* assign reverse ordering */
228          rord[ord[0]] = 0;
229          rord[ord[1]] = 1;
# Line 269 | Line 296 | unkopt:
296                  if (resolution && fin2 != NULL) {
297                          RESOLU  pres2;
298                          if (!fgetsresolu(&pres2, fin2) ||
299 <                                        pres2.or != picres.or ||
299 >                                        pres2.rt != picres.rt ||
300                                          pres2.xr != picres.xr ||
301                                          pres2.yr != picres.yr ||
302                                          !fgetsresolu(&pres2, fin3) ||
303 <                                        pres2.or != picres.or ||
303 >                                        pres2.rt != picres.rt ||
304                                          pres2.xr != picres.xr ||
305                                          pres2.yr != picres.yr) {
306                                  fprintf(stderr, "%s: resolution mismatch\n",
# Line 298 | Line 325 | unkopt:
325                                                  /* get header */
326                  getheader(fin, checkhead, NULL);
327                  if (wrongformat) {
328 <                        fprintf(stderr, "%s: input not a Radiance picture\n",
328 >                        fprintf(stderr,
329 >                                "%s: input not a Radiance RGBE picture\n",
330                                          progname);
331                          quit(1);
332                  }
# Line 322 | Line 350 | unkopt:
350   }
351  
352  
353 + int
354   checkhead(line)                         /* deal with line from header */
355   char  *line;
356   {
# Line 329 | Line 358 | char  *line;
358          double  d;
359          COLOR   ctmp;
360  
361 <        if (formatval(fmt, line))
362 <                wrongformat = strcmp(fmt, COLRFMT);
363 <        else if (original && isexpos(line)) {
361 >        if (formatval(fmt, line)) {
362 >                if (!strcmp(fmt, CIEFMT)) {
363 >                        mybright = &xyz_bright;
364 >                        if (original) {
365 >                                scalecolor(exposure, 1./WHTEFFICACY);
366 >                                doexposure++;
367 >                        }
368 >                } else if (!strcmp(fmt, COLRFMT))
369 >                        mybright = &rgb_bright;
370 >                else
371 >                        wrongformat++;
372 >        } else if (original && isexpos(line)) {
373                  d = 1.0/exposval(line);
374                  scalecolor(exposure, d);
375                  doexposure++;
# Line 343 | Line 381 | char  *line;
381                  doexposure++;
382          } else if (header)
383                  fputs(line, stdout);
384 +        return(0);
385   }
386  
387  
# Line 414 | Line 453 | pixtoval()                             /* convert picture to values */
453                          }
454                  }
455          }
456 <        free((char *)scanln);
456 >        free((void *)scanln);
457   }
458  
459  
# Line 458 | Line 497 | valtopix()                     /* convert values to a pixel file */
497                          quit(1);
498                  }
499          }
500 <        free((char *)scanln);
500 >        free((void *)scanln);
501   }
502  
503  
504 + void
505   quit(code)
506   int  code;
507   {
# Line 566 | Line 606 | COLOR  col;
606   }
607  
608  
609 + getcword(col)           /* get a 16-bit color value from stream(s) */
610 + COLOR  col;
611 + {
612 +        uint16  vw[3];
613 +
614 +        if (fin2 == NULL) {
615 +                if (fread((char *)vw, sizeof(uint16), 3, fin) != 3)
616 +                        return(-1);
617 +        } else {
618 +                if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 ||
619 +                        fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 ||
620 +                        fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1)
621 +                        return(-1);
622 +        }
623 +        setcolor(col, (vw[rord[RED]]+.5)/65536.,
624 +                        (vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.);
625 +        return(0);
626 + }
627 +
628 +
629   getbascii(col)          /* get an ascii brightness value from fin */
630   COLOR  col;
631   {
# Line 630 | Line 690 | COLOR  col;
690   }
691  
692  
693 + getbword(col)           /* get a 16-bit brightness value from fin */
694 + COLOR  col;
695 + {
696 +        uint16  vw;
697 +        double  d;
698 +
699 +        if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1)
700 +                return(-1);
701 +        d = (vw+.5)/65536.;
702 +        setcolor(col, d, d, d);
703 +        return(0);
704 + }
705 +
706 +
707   putcascii(col)                  /* put an ascii color to stdout */
708   COLOR  col;
709   {
# Line 685 | Line 759 | COLOR  col;
759   putcbyte(col)                   /* put a byte color to stdout */
760   COLOR  col;
761   {
762 <        register int  i;
762 >        long  i;
763          BYTE  vb[3];
764  
765          i = colval(col,ord[0])*256.;
# Line 700 | Line 774 | COLOR  col;
774   }
775  
776  
777 + putcword(col)                   /* put a 16-bit color to stdout */
778 + COLOR  col;
779 + {
780 +        long  i;
781 +        uint16  vw[3];
782 +
783 +        i = colval(col,ord[0])*65536.;
784 +        vw[0] = min(i,65535);
785 +        i = colval(col,ord[1])*65536.;
786 +        vw[1] = min(i,65535);
787 +        i = colval(col,ord[2])*65536.;
788 +        vw[2] = min(i,65535);
789 +        fwrite((char *)vw, sizeof(uint16), 3, stdout);
790 +
791 +        return(ferror(stdout) ? -1 : 0);
792 + }
793 +
794 +
795   putbascii(col)                  /* put an ascii brightness to stdout */
796   COLOR  col;
797   {
798 <        fprintf(stdout, "%15.3e\n", bright(col));
798 >        fprintf(stdout, "%15.3e\n", (*mybright)(col));
799  
800          return(ferror(stdout) ? -1 : 0);
801   }
# Line 714 | Line 806 | COLOR  col;
806   {
807          float  vf;
808  
809 <        vf = bright(col);
809 >        vf = (*mybright)(col);
810          fwrite((char *)&vf, sizeof(float), 1, stdout);
811  
812          return(ferror(stdout) ? -1 : 0);
# Line 726 | Line 818 | COLOR  col;
818   {
819          double  vd;
820  
821 <        vd = bright(col);
821 >        vd = (*mybright)(col);
822          fwrite((char *)&vd, sizeof(double), 1, stdout);
823  
824          return(ferror(stdout) ? -1 : 0);
# Line 736 | Line 828 | COLOR  col;
828   putbint(col)                    /* put an int brightness to stdout */
829   COLOR  col;
830   {
831 <        fprintf(stdout, "%d\n", (int)(bright(col)*256.));
831 >        fprintf(stdout, "%d\n", (int)((*mybright)(col)*256.));
832  
833          return(ferror(stdout) ? -1 : 0);
834   }
# Line 748 | Line 840 | COLOR  col;
840          register int  i;
841          BYTE  vb;
842  
843 <        i = bright(col)*256.;
843 >        i = (*mybright)(col)*256.;
844          vb = min(i,255);
845          fwrite((char *)&vb, sizeof(BYTE), 1, stdout);
846  
# Line 756 | Line 848 | COLOR  col;
848   }
849  
850  
851 + putbword(col)                   /* put a 16-bit brightness to stdout */
852 + COLOR  col;
853 + {
854 +        long  i;
855 +        uint16  vw;
856 +
857 +        i = (*mybright)(col)*65536.;
858 +        vw = min(i,65535);
859 +        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
860 +
861 +        return(ferror(stdout) ? -1 : 0);
862 + }
863 +
864 +
865   putpascii(col)                  /* put an ascii primary to stdout */
866   COLOR  col;
867   {
# Line 801 | Line 907 | COLOR  col;
907   putpbyte(col)                   /* put a byte primary to stdout */
908   COLOR  col;
909   {
910 <        register int  i;
910 >        long  i;
911          BYTE  vb;
912  
913          i = colval(col,putprim)*256.;
# Line 812 | Line 918 | COLOR  col;
918   }
919  
920  
921 + putpword(col)                   /* put a 16-bit primary to stdout */
922 + COLOR  col;
923 + {
924 +        long  i;
925 +        uint16  vw;
926 +
927 +        i = colval(col,putprim)*65536.;
928 +        vw = min(i,65535);
929 +        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
930 +
931 +        return(ferror(stdout) ? -1 : 0);
932 + }
933 +
934 +
935   set_io()                        /* set put and get functions */
936   {
937          switch (format) {
# Line 913 | Line 1033 | set_io()                       /* set put and get functions */
1033                                          goto seekerr;
1034                                  if (fseek(fin3,
1035                                  (long)sizeof(BYTE)*2*picres.xr*picres.yr, 1))
1036 +                                        goto seekerr;
1037 +                        }
1038 +                }
1039 +                return;
1040 +        case 'w':                                       /* 16-bit */
1041 +                if (putprim == BRIGHT) {
1042 +                        getval = getbword;
1043 +                        putval = putbword;
1044 +                } else if (putprim != ALL) {
1045 +                        getval = getbword;
1046 +                        putval = putpword;
1047 +                } else {
1048 +                        getval = getcword;
1049 +                        putval = putcword;
1050 +                        if (reverse && !interleave) {
1051 +                                if (fin2 == NULL)
1052 +                                        goto namerr;
1053 +                                if (fseek(fin2,
1054 +                                (long)sizeof(uint16)*picres.xr*picres.yr, 1))
1055 +                                        goto seekerr;
1056 +                                if (fseek(fin3,
1057 +                                (long)sizeof(uint16)*2*picres.xr*picres.yr, 1))
1058                                          goto seekerr;
1059                          }
1060                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines