ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_tiff.c
(Generate patch)

Comparing ray/src/px/ra_tiff.c (file contents):
Revision 2.27 by schorsch, Fri Jan 2 12:47:01 2004 UTC vs.
Revision 2.36 by greg, Fri Jul 19 17:37:56 2019 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *  Added white-balance adjustment 10/01 (GW).
8   */
9  
10 #include  <stdio.h>
10   #include  <math.h>
11   #include  <ctype.h>
13 #include  <time.h>
14 #include  <string.h>
12  
13 + #include  "rtio.h"
14 + #include  "platform.h"
15   #include  "tiffio.h"
16   #include  "color.h"
17   #include  "resolu.h"
# Line 30 | Line 29 | static const char      RCSid[] = "$Id$";
29   #define C_TWRD          0x80            /* TIFF data is 16-bit */
30   #define C_PRIM          0x100           /* has assigned primaries */
31  
32 + typedef void colcvf_t(uint32 y);
33 +
34   struct {
35          uint16  flags;          /* conversion flags (defined above) */
36          char    capdate[20];    /* capture date/time */
# Line 58 | Line 59 | struct {
59                  float   *fp;            /* float pointer */
60                  char    *p;             /* generic pointer */
61          } t;                    /* TIFF scanline */
62 <        void    (*tf)();        /* translation procedure */
62 >        colcvf_t *tf;   /* translation procedure */
63   }       cvts = {        /* conversion structure */
64          0, "", "", COMPRESSION_NONE, PHOTOMETRIC_RGB,
65          PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1.,
# Line 69 | Line 70 | struct {
70   #define CLR(f)          (cvts.flags &= ~(f))
71   #define TGL(f)          (cvts.flags ^= (f))
72  
73 < void    Luv2Color(), L2Color(), RGB2Colr(), Gry2Colr();
74 < void    Color2Luv(), Color2L(), Colr2RGB(), Colr2Gry();
75 < void    RRGGBB2Color(), GGry2Color(), Color2RRGGBB(), Color2GGry();
73 > static colcvf_t Luv2Color, L2Color, RGB2Colr, Gry2Colr;
74 > static colcvf_t Color2Luv, Color2L, Colr2RGB, Colr2Gry;
75 > static colcvf_t RRGGBB2Color, GGry2Color, Color2RRGGBB, Color2GGry;
76  
77 + static gethfunc headline;
78 + static void quiterr(char *err);
79 + static void allocbufs(void);
80 + static void initfromtif(void);
81 + static void tiff2ra(int  ac, char  *av[]);
82 + static void initfromrad(void);
83 + static void ra2tiff(int  ac, char  *av[]);
84 +
85 +
86 +
87   #define RfGfBf2Color    Luv2Color
88   #define Gryf2Color      L2Color
89   #define Color2Gryf      Color2L
# Line 96 | Line 107 | char           OWNSTR[] = "OWNER=";
107  
108   char  *progname;
109  
99 static gethfunc headline;
110  
111 <
112 < main(argc, argv)
103 < int  argc;
104 < char  *argv[];
111 > int
112 > main(int  argc, char  *argv[])
113   {
114          int  reverse = 0;
115          int  i;
# Line 182 | Line 190 | doneopts:
190          exit(0);
191   userr:
192          fprintf(stderr,
193 <        "Usage: %s [-z|-L|-l|-f|-w][-b][-e +/-stops][-g gamma] {in.pic|-} out.tif\n",
193 >        "Usage: %s [-z|-L|-l|-f|-w][-b][-e +/-stops][-g gamma] {in.hdr|-} out.tif\n",
194                          progname);
195          fprintf(stderr,
196 <        "   Or: %s -r [-x][-e +/-stops][-g gamma] in.tif [out.pic|-]\n",
196 >        "   Or: %s -r [-x][-e +/-stops][-g gamma] in.tif [out.hdr|-]\n",
197                          progname);
198          exit(1);
199   }
200  
201  
202 < quiterr(err)            /* print message and exit */
203 < char  *err;
202 > static void
203 > quiterr(                /* print message and exit */
204 >        char  *err
205 > )
206   {
207          if (err != NULL) {
208                  fprintf(stderr, "%s: %s\n", progname, err);
# Line 202 | Line 212 | char  *err;
212   }
213  
214  
215 < allocbufs()                     /* allocate scanline buffers */
215 > static void
216 > allocbufs(void)                 /* allocate scanline buffers */
217   {
218          int     rsiz, tsiz;
219  
# Line 217 | Line 228 | allocbufs()                    /* allocate scanline buffers */
228   }
229  
230  
231 < initfromtif()           /* initialize conversion from TIFF input */
231 > static void
232 > initfromtif(void)               /* initialize conversion from TIFF input */
233   {
234          uint16  hi;
235          char    *cp;
# Line 262 | Line 274 | initfromtif()          /* initialize conversion from TIFF inpu
274                          cpcolormat(cvts.cmat, xyz2rgbmat);
275                          SET(C_CXFM|C_GAMUT);
276                  } else if (cvts.comp == COMPRESSION_SGILOG)
277 <                        SET(C_GAMUT);
277 >                        SET(C_GAMUT);           /* may be outside XYZ gamut */
278                  if (cvts.pconf != PLANARCONFIG_CONTIG)
279                          quiterr("cannot handle separate Luv planes");
280                  TIFFSetField(cvts.tif, TIFFTAG_SGILOGDATAFMT,
# Line 349 | Line 361 | initfromtif()          /* initialize conversion from TIFF inpu
361                  quiterr("unknown input image resolution");
362  
363          if (!TIFFGetField(cvts.tif, TIFFTAG_STONITS, &cvts.stonits))
364 <                cvts.stonits = 1.;
364 >                cvts.stonits = -1.;
365  
366          if (!TIFFGetField(cvts.tif, TIFFTAG_DATETIME, &cp))
367                  cvts.capdate[0] = '\0';
# Line 367 | Line 379 | initfromtif()          /* initialize conversion from TIFF inpu
379          if (cvts.pixrat < .99 || cvts.pixrat > 1.01)
380                  fputaspect(cvts.pixrat, cvts.rfp);
381          if (CHK(C_XYZE)) {
382 <                fputexpos(pow(2.,(double)cvts.bradj)/cvts.stonits, cvts.rfp);
382 >                if (cvts.stonits > .0)
383 >                        fputexpos(pow(2.,(double)cvts.bradj)/cvts.stonits, cvts.rfp);
384                  fputformat(CIEFMT, cvts.rfp);
385          } else {
386                  if (CHK(C_PRIM))
387                          fputprims(cvts.prims, cvts.rfp);
388 <                fputexpos(WHTEFFICACY*pow(2.,(double)cvts.bradj)/cvts.stonits,
389 <                                cvts.rfp);
388 >                if (cvts.stonits > .0)
389 >                        fputexpos(WHTEFFICACY*pow(2.,(double)cvts.bradj)/cvts.stonits,
390 >                                        cvts.rfp);
391                  fputformat(COLRFMT, cvts.rfp);
392          }
393          if (cvts.capdate[0])
# Line 385 | Line 399 | initfromtif()          /* initialize conversion from TIFF inpu
399   }
400  
401  
402 < tiff2ra(ac, av)         /* convert TIFF image to Radiance picture */
403 < int  ac;
404 < char  *av[];
402 > static void
403 > tiff2ra(                /* convert TIFF image to Radiance picture */
404 >        int  ac,
405 >        char  *av[]
406 > )
407   {
408          int32   y;
409                                          /* open TIFF input */
# Line 398 | Line 414 | char  *av[];
414                  cvts.rfp = stdout;
415          else if ((cvts.rfp = fopen(av[ac+1], "w")) == NULL)
416                  quiterr("cannot open Radiance output picture");
417 +        SET_FILE_BINARY(cvts.rfp);
418                                          /* start output header */
419          newheader("RADIANCE", cvts.rfp);
420          printargs(ac, av, cvts.rfp);
# Line 423 | Line 440 | headline(                      /* process Radiance input header line */
440   {
441          static int      tmstrlen = 0;
442          static int      ownstrlen = 0;
443 <        char    fmt[32];
443 >        char    fmt[MAXFMTLEN];
444  
445          if (!tmstrlen)
446                  tmstrlen = strlen(TMSTR);
# Line 476 | Line 493 | headline(                      /* process Radiance input header line */
493   }
494  
495  
496 < initfromrad()                   /* initialize input from a Radiance picture */
496 > static void
497 > initfromrad(void)                       /* initialize input from a Radiance picture */
498   {
499          int     i1, i2, po;
500                                                  /* read Radiance header */
# Line 553 | Line 571 | initfromrad()                  /* initialize input from a Radiance pi
571                                          SAMPLEFORMAT_IEEEFP);
572                          cvts.tf = Color2RfGfBf;
573                          SET(C_RFLT);
574 +                        CLR(C_GAMUT);
575                  } else
576                          cvts.tf = Colr2RGB;
577                  break;
# Line 603 | Line 622 | initfromrad()                  /* initialize input from a Radiance pi
622   }
623  
624  
625 < ra2tiff(ac, av)         /* convert Radiance picture to TIFF image */
626 < int  ac;
627 < char  *av[];
625 > static void
626 > ra2tiff(                /* convert Radiance picture to TIFF image */
627 >        int  ac,
628 >        char  *av[]
629 > )
630   {
631          uint32  y;
632                                                  /* open Radiance file */
# Line 613 | Line 634 | char  *av[];
634                  cvts.rfp = stdin;
635          else if ((cvts.rfp = fopen(av[ac], "r")) == NULL)
636                  quiterr("cannot open Radiance input picture");
637 +        SET_FILE_BINARY(cvts.rfp);
638                                                  /* open TIFF file */
639          if ((cvts.tif = TIFFOpen(av[ac+1], "w")) == NULL)
640                  quiterr("cannot open TIFF output");
# Line 627 | Line 649 | char  *av[];
649   }
650  
651  
652 < void
653 < Luv2Color(y)                    /* read/convert/write Luv->COLOR scanline */
654 < uint32  y;
652 > static void
653 > Luv2Color(                      /* read/convert/write Luv->COLOR scanline */
654 >        uint32  y
655 > )
656   {
657          register int    x;
658  
659          if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT))
660                  quiterr("internal error 1 in Luv2Color");
661  
662 +        if (cvts.pconf != PLANARCONFIG_CONTIG)
663 +                quiterr("cannot handle separate 32-bit color planes");
664 +
665          if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0)
666                  quiterr("error reading TIFF input");
667                                          /* also works for float RGB */
# Line 662 | Line 688 | uint32 y;
688   }
689  
690  
691 < void
692 < RRGGBB2Color(y)                 /* read/convert/write RGB16->COLOR scanline */
693 < uint32  y;
691 > static void
692 > RRGGBB2Color(                   /* read/convert/write RGB16->COLOR scanline */
693 >        uint32  y
694 > )
695   {
696          int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
697          register double d;
# Line 673 | Line 700 | uint32 y;
700          if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_TWRD|C_RFLT))
701                  quiterr("internal error 1 in RRGGBB2Color");
702  
703 +        if (cvts.pconf != PLANARCONFIG_CONTIG)
704 +                quiterr("cannot handle separate 16-bit color planes");
705 +
706          if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0)
707                  quiterr("error reading TIFF input");
708          
# Line 689 | Line 719 | uint32 y;
719                  if (CHK(C_CXFM))
720                          colortrans(cvts.r.colors[x], cvts.cmat,
721                                          cvts.r.colors[x]);
692                if (CHK(C_GAMUT))
693                        clipgamut(cvts.r.colors[x], cvts.t.fp[3*x + 1],
694                                        CGAMUT_LOWER, cblack, cwhite);
722          }
723          if (cvts.bradj) {
724                  d = pow(2.,(double)cvts.bradj);
# Line 704 | Line 731 | uint32 y;
731   }
732  
733  
734 < void
735 < L2Color(y)                      /* read/convert/write Lfloat->COLOR scanline */
736 < uint32  y;
734 > static void
735 > L2Color(                        /* read/convert/write Lfloat->COLOR scanline */
736 >        uint32  y
737 > )
738   {
739          float   m = pow(2., (double)cvts.bradj);
740          register int    x;
# Line 727 | Line 755 | uint32 y;
755   }
756  
757  
758 < void
759 < RGB2Colr(y)                     /* read/convert/write RGB->COLR scanline */
760 < uint32  y;
758 > static void
759 > RGB2Colr(                       /* read/convert/write RGB->COLR scanline */
760 >        uint32  y
761 > )
762   {
763          COLOR   ctmp;
764          register int    x;
# Line 783 | Line 812 | readerr:
812   }
813  
814  
815 < void
816 < Gry2Colr(y)                     /* read/convert/write G8->COLR scanline */
817 < uint32  y;
815 > static void
816 > Gry2Colr(                       /* read/convert/write G8->COLR scanline */
817 >        uint32  y
818 > )
819   {
820          register int    x;
821  
# Line 809 | Line 839 | uint32 y;
839   }
840  
841  
842 < void
843 < GGry2Color(y)                   /* read/convert/write G16->COLOR scanline */
844 < uint32  y;
842 > static void
843 > GGry2Color(                     /* read/convert/write G16->COLOR scanline */
844 >        uint32  y
845 > )
846   {
847          int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
848          double  m;
# Line 839 | Line 870 | uint32 y;
870   }
871  
872  
873 < void
874 < Color2GGry(y)                   /* read/convert/write COLOR->G16 scanline */
875 < uint32  y;
873 > static void
874 > Color2GGry(                     /* read/convert/write COLOR->G16 scanline */
875 >        uint32  y
876 > )
877   {
878          int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
879          float   m = pow(2.,(double)cvts.bradj);
# Line 873 | Line 905 | uint32 y;
905   }
906  
907  
908 < void
909 < Color2L(y)                      /* read/convert/write COLOR->Lfloat scanline */
910 < uint32  y;
908 > static void
909 > Color2L(                        /* read/convert/write COLOR->Lfloat scanline */
910 >        uint32  y
911 > )
912   {
913          float   m = pow(2.,(double)cvts.bradj);
914          register int    x;
# Line 895 | Line 928 | uint32 y;
928   }
929  
930  
931 < void
932 < Color2Luv(y)                    /* read/convert/write COLOR->Luv scanline */
933 < uint32  y;
931 > static void
932 > Color2Luv(                      /* read/convert/write COLOR->Luv scanline */
933 >        uint32  y
934 > )
935   {
936          register int    x;
937  
# Line 928 | Line 962 | uint32 y;
962   }
963  
964  
965 < void
966 < Color2RRGGBB(y)                 /* read/convert/write COLOR->RGB16 scanline */
967 < uint32  y;
965 > static void
966 > Color2RRGGBB(                   /* read/convert/write COLOR->RGB16 scanline */
967 >        uint32  y
968 > )
969   {
970          int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
971          float   m = pow(2.,(double)cvts.bradj);
# Line 942 | Line 977 | uint32 y;
977          if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0)
978                  quiterr("error reading Radiance picture");
979  
980 <        for (x = cvts.xmax; x--; )
980 >        for (x = cvts.xmax; x--; ) {
981 >            if (CHK(C_CXFM)) {
982 >                        colortrans(cvts.r.colors[x], cvts.cmat,
983 >                                        cvts.r.colors[x]);
984 >                if (CHK(C_GAMUT))
985 >                        clipgamut(cvts.r.colors[x], bright(cvts.r.colors[x]),
986 >                                        CGAMUT_LOWER, cblack, cwhite);
987 >            }
988              for (i = 3; i--; ) {
989                  register float  f = m*colval(cvts.r.colors[x],i);
990                  if (f <= 0)
# Line 955 | Line 997 | uint32 y;
997                  else
998                          cvts.t.wp[3*x + i] = (int)((float)(1L<<16)*f);
999              }
1000 +        }
1001  
1002          if (TIFFWriteScanline(cvts.tif, cvts.t.p, y, 0) < 0)
1003                  quiterr("error writing TIFF output");
1004   }
1005  
1006  
1007 < void
1008 < Colr2Gry(y)                     /* read/convert/write COLR->RGB scanline */
1009 < uint32  y;
1007 > static void
1008 > Colr2Gry(                       /* read/convert/write COLR->RGB scanline */
1009 >        uint32  y
1010 > )
1011   {
1012          register int    x;
1013  
# Line 987 | Line 1031 | uint32 y;
1031   }
1032  
1033  
1034 < void
1035 < Colr2RGB(y)                     /* read/convert/write COLR->RGB scanline */
1036 < uint32  y;
1034 > static void
1035 > Colr2RGB(                       /* read/convert/write COLR->RGB scanline */
1036 >        uint32  y
1037 > )
1038   {
1039          COLOR   ctmp;
1040          register int    x;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines