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.26 by schorsch, Sun Jul 27 22:12:03 2003 UTC vs.
Revision 2.34 by greg, Sat Dec 4 00:24:43 2010 UTC

# Line 11 | Line 11 | static const char      RCSid[] = "$Id$";
11   #include  <math.h>
12   #include  <ctype.h>
13   #include  <time.h>
14 + #include  <string.h>
15 +
16 + #include  "platform.h"
17   #include  "tiffio.h"
18   #include  "color.h"
19   #include  "resolu.h"
# Line 28 | Line 31 | static const char      RCSid[] = "$Id$";
31   #define C_TWRD          0x80            /* TIFF data is 16-bit */
32   #define C_PRIM          0x100           /* has assigned primaries */
33  
34 + typedef void colcvf_t(uint32 y);
35 +
36   struct {
37          uint16  flags;          /* conversion flags (defined above) */
38          char    capdate[20];    /* capture date/time */
# Line 56 | Line 61 | struct {
61                  float   *fp;            /* float pointer */
62                  char    *p;             /* generic pointer */
63          } t;                    /* TIFF scanline */
64 <        void    (*tf)();        /* translation procedure */
64 >        colcvf_t *tf;   /* translation procedure */
65   }       cvts = {        /* conversion structure */
66          0, "", "", COMPRESSION_NONE, PHOTOMETRIC_RGB,
67          PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1.,
# Line 67 | Line 72 | struct {
72   #define CLR(f)          (cvts.flags &= ~(f))
73   #define TGL(f)          (cvts.flags ^= (f))
74  
75 < void    Luv2Color(), L2Color(), RGB2Colr(), Gry2Colr();
76 < void    Color2Luv(), Color2L(), Colr2RGB(), Colr2Gry();
77 < void    RRGGBB2Color(), GGry2Color(), Color2RRGGBB(), Color2GGry();
75 > static colcvf_t Luv2Color, L2Color, RGB2Colr, Gry2Colr;
76 > static colcvf_t Color2Luv, Color2L, Colr2RGB, Colr2Gry;
77 > static colcvf_t RRGGBB2Color, GGry2Color, Color2RRGGBB, Color2GGry;
78  
79 + static gethfunc headline;
80 + static void quiterr(char *err);
81 + static void allocbufs(void);
82 + static void initfromtif(void);
83 + static void tiff2ra(int  ac, char  *av[]);
84 + static void initfromrad(void);
85 + static void ra2tiff(int  ac, char  *av[]);
86 +
87 +
88 +
89   #define RfGfBf2Color    Luv2Color
90   #define Gryf2Color      L2Color
91   #define Color2Gryf      Color2L
# Line 95 | Line 110 | char           OWNSTR[] = "OWNER=";
110   char  *progname;
111  
112  
113 < main(argc, argv)
114 < int  argc;
100 < char  *argv[];
113 > int
114 > main(int  argc, char  *argv[])
115   {
116          int  reverse = 0;
117          int  i;
# Line 178 | Line 192 | doneopts:
192          exit(0);
193   userr:
194          fprintf(stderr,
195 <        "Usage: %s [-z|-L|-l|-f|-w][-b][-e +/-stops][-g gamma] {in.pic|-} out.tif\n",
195 >        "Usage: %s [-z|-L|-l|-f|-w][-b][-e +/-stops][-g gamma] {in.hdr|-} out.tif\n",
196                          progname);
197          fprintf(stderr,
198 <        "   Or: %s -r [-x][-e +/-stops][-g gamma] in.tif [out.pic|-]\n",
198 >        "   Or: %s -r [-x][-e +/-stops][-g gamma] in.tif [out.hdr|-]\n",
199                          progname);
200          exit(1);
201   }
202  
203  
204 < quiterr(err)            /* print message and exit */
205 < char  *err;
204 > static void
205 > quiterr(                /* print message and exit */
206 >        char  *err
207 > )
208   {
209          if (err != NULL) {
210                  fprintf(stderr, "%s: %s\n", progname, err);
# Line 198 | Line 214 | char  *err;
214   }
215  
216  
217 < allocbufs()                     /* allocate scanline buffers */
217 > static void
218 > allocbufs(void)                 /* allocate scanline buffers */
219   {
220          int     rsiz, tsiz;
221  
# Line 213 | Line 230 | allocbufs()                    /* allocate scanline buffers */
230   }
231  
232  
233 < initfromtif()           /* initialize conversion from TIFF input */
233 > static void
234 > initfromtif(void)               /* initialize conversion from TIFF input */
235   {
236          uint16  hi;
237          char    *cp;
# Line 258 | Line 276 | initfromtif()          /* initialize conversion from TIFF inpu
276                          cpcolormat(cvts.cmat, xyz2rgbmat);
277                          SET(C_CXFM|C_GAMUT);
278                  } else if (cvts.comp == COMPRESSION_SGILOG)
279 <                        SET(C_GAMUT);
279 >                        SET(C_GAMUT);           /* may be outside XYZ gamut */
280                  if (cvts.pconf != PLANARCONFIG_CONTIG)
281                          quiterr("cannot handle separate Luv planes");
282                  TIFFSetField(cvts.tif, TIFFTAG_SGILOGDATAFMT,
# Line 345 | Line 363 | initfromtif()          /* initialize conversion from TIFF inpu
363                  quiterr("unknown input image resolution");
364  
365          if (!TIFFGetField(cvts.tif, TIFFTAG_STONITS, &cvts.stonits))
366 <                cvts.stonits = 1.;
366 >                cvts.stonits = -1.;
367  
368          if (!TIFFGetField(cvts.tif, TIFFTAG_DATETIME, &cp))
369                  cvts.capdate[0] = '\0';
# Line 363 | Line 381 | initfromtif()          /* initialize conversion from TIFF inpu
381          if (cvts.pixrat < .99 || cvts.pixrat > 1.01)
382                  fputaspect(cvts.pixrat, cvts.rfp);
383          if (CHK(C_XYZE)) {
384 <                fputexpos(pow(2.,(double)cvts.bradj)/cvts.stonits, cvts.rfp);
384 >                if (cvts.stonits > .0)
385 >                        fputexpos(pow(2.,(double)cvts.bradj)/cvts.stonits, cvts.rfp);
386                  fputformat(CIEFMT, cvts.rfp);
387          } else {
388                  if (CHK(C_PRIM))
389                          fputprims(cvts.prims, cvts.rfp);
390 <                fputexpos(WHTEFFICACY*pow(2.,(double)cvts.bradj)/cvts.stonits,
391 <                                cvts.rfp);
390 >                if (cvts.stonits > .0)
391 >                        fputexpos(WHTEFFICACY*pow(2.,(double)cvts.bradj)/cvts.stonits,
392 >                                        cvts.rfp);
393                  fputformat(COLRFMT, cvts.rfp);
394          }
395          if (cvts.capdate[0])
# Line 381 | Line 401 | initfromtif()          /* initialize conversion from TIFF inpu
401   }
402  
403  
404 < tiff2ra(ac, av)         /* convert TIFF image to Radiance picture */
405 < int  ac;
406 < char  *av[];
404 > static void
405 > tiff2ra(                /* convert TIFF image to Radiance picture */
406 >        int  ac,
407 >        char  *av[]
408 > )
409   {
410          int32   y;
411                                          /* open TIFF input */
# Line 394 | Line 416 | char  *av[];
416                  cvts.rfp = stdout;
417          else if ((cvts.rfp = fopen(av[ac+1], "w")) == NULL)
418                  quiterr("cannot open Radiance output picture");
419 +        SET_FILE_BINARY(cvts.rfp);
420                                          /* start output header */
421          newheader("RADIANCE", cvts.rfp);
422          printargs(ac, av, cvts.rfp);
# Line 411 | Line 434 | char  *av[];
434   }
435  
436  
437 < int
438 < headline(s)                     /* process Radiance input header line */
439 < char    *s;
437 > static int
438 > headline(                       /* process Radiance input header line */
439 >        char    *s,
440 >        void    *p
441 > )
442   {
443          static int      tmstrlen = 0;
444          static int      ownstrlen = 0;
# Line 470 | Line 495 | char   *s;
495   }
496  
497  
498 < initfromrad()                   /* initialize input from a Radiance picture */
498 > static void
499 > initfromrad(void)                       /* initialize input from a Radiance picture */
500   {
501          int     i1, i2, po;
502                                                  /* read Radiance header */
# Line 547 | Line 573 | initfromrad()                  /* initialize input from a Radiance pi
573                                          SAMPLEFORMAT_IEEEFP);
574                          cvts.tf = Color2RfGfBf;
575                          SET(C_RFLT);
576 +                        CLR(C_GAMUT);
577                  } else
578                          cvts.tf = Colr2RGB;
579                  break;
# Line 597 | Line 624 | initfromrad()                  /* initialize input from a Radiance pi
624   }
625  
626  
627 < ra2tiff(ac, av)         /* convert Radiance picture to TIFF image */
628 < int  ac;
629 < char  *av[];
627 > static void
628 > ra2tiff(                /* convert Radiance picture to TIFF image */
629 >        int  ac,
630 >        char  *av[]
631 > )
632   {
633          uint32  y;
634                                                  /* open Radiance file */
# Line 607 | Line 636 | char  *av[];
636                  cvts.rfp = stdin;
637          else if ((cvts.rfp = fopen(av[ac], "r")) == NULL)
638                  quiterr("cannot open Radiance input picture");
639 +        SET_FILE_BINARY(cvts.rfp);
640                                                  /* open TIFF file */
641          if ((cvts.tif = TIFFOpen(av[ac+1], "w")) == NULL)
642                  quiterr("cannot open TIFF output");
# Line 621 | Line 651 | char  *av[];
651   }
652  
653  
654 < void
655 < Luv2Color(y)                    /* read/convert/write Luv->COLOR scanline */
656 < uint32  y;
654 > static void
655 > Luv2Color(                      /* read/convert/write Luv->COLOR scanline */
656 >        uint32  y
657 > )
658   {
659          register int    x;
660  
661          if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT))
662                  quiterr("internal error 1 in Luv2Color");
663  
664 +        if (cvts.pconf != PLANARCONFIG_CONTIG)
665 +                quiterr("cannot handle separate 32-bit color planes");
666 +
667          if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0)
668                  quiterr("error reading TIFF input");
669                                          /* also works for float RGB */
# Line 656 | Line 690 | uint32 y;
690   }
691  
692  
693 < void
694 < RRGGBB2Color(y)                 /* read/convert/write RGB16->COLOR scanline */
695 < uint32  y;
693 > static void
694 > RRGGBB2Color(                   /* read/convert/write RGB16->COLOR scanline */
695 >        uint32  y
696 > )
697   {
698          int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
699          register double d;
# Line 667 | Line 702 | uint32 y;
702          if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_TWRD|C_RFLT))
703                  quiterr("internal error 1 in RRGGBB2Color");
704  
705 +        if (cvts.pconf != PLANARCONFIG_CONTIG)
706 +                quiterr("cannot handle separate 16-bit color planes");
707 +
708          if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0)
709                  quiterr("error reading TIFF input");
710          
# Line 683 | Line 721 | uint32 y;
721                  if (CHK(C_CXFM))
722                          colortrans(cvts.r.colors[x], cvts.cmat,
723                                          cvts.r.colors[x]);
686                if (CHK(C_GAMUT))
687                        clipgamut(cvts.r.colors[x], cvts.t.fp[3*x + 1],
688                                        CGAMUT_LOWER, cblack, cwhite);
724          }
725          if (cvts.bradj) {
726                  d = pow(2.,(double)cvts.bradj);
# Line 698 | Line 733 | uint32 y;
733   }
734  
735  
736 < void
737 < L2Color(y)                      /* read/convert/write Lfloat->COLOR scanline */
738 < uint32  y;
736 > static void
737 > L2Color(                        /* read/convert/write Lfloat->COLOR scanline */
738 >        uint32  y
739 > )
740   {
741          float   m = pow(2., (double)cvts.bradj);
742          register int    x;
# Line 721 | Line 757 | uint32 y;
757   }
758  
759  
760 < void
761 < RGB2Colr(y)                     /* read/convert/write RGB->COLR scanline */
762 < uint32  y;
760 > static void
761 > RGB2Colr(                       /* read/convert/write RGB->COLR scanline */
762 >        uint32  y
763 > )
764   {
765          COLOR   ctmp;
766          register int    x;
# Line 777 | Line 814 | readerr:
814   }
815  
816  
817 < void
818 < Gry2Colr(y)                     /* read/convert/write G8->COLR scanline */
819 < uint32  y;
817 > static void
818 > Gry2Colr(                       /* read/convert/write G8->COLR scanline */
819 >        uint32  y
820 > )
821   {
822          register int    x;
823  
# Line 803 | Line 841 | uint32 y;
841   }
842  
843  
844 < void
845 < GGry2Color(y)                   /* read/convert/write G16->COLOR scanline */
846 < uint32  y;
844 > static void
845 > GGry2Color(                     /* read/convert/write G16->COLOR scanline */
846 >        uint32  y
847 > )
848   {
849          int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
850          double  m;
# Line 833 | Line 872 | uint32 y;
872   }
873  
874  
875 < void
876 < Color2GGry(y)                   /* read/convert/write COLOR->G16 scanline */
877 < uint32  y;
875 > static void
876 > Color2GGry(                     /* read/convert/write COLOR->G16 scanline */
877 >        uint32  y
878 > )
879   {
880          int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
881          float   m = pow(2.,(double)cvts.bradj);
# Line 867 | Line 907 | uint32 y;
907   }
908  
909  
910 < void
911 < Color2L(y)                      /* read/convert/write COLOR->Lfloat scanline */
912 < uint32  y;
910 > static void
911 > Color2L(                        /* read/convert/write COLOR->Lfloat scanline */
912 >        uint32  y
913 > )
914   {
915          float   m = pow(2.,(double)cvts.bradj);
916          register int    x;
# Line 889 | Line 930 | uint32 y;
930   }
931  
932  
933 < void
934 < Color2Luv(y)                    /* read/convert/write COLOR->Luv scanline */
935 < uint32  y;
933 > static void
934 > Color2Luv(                      /* read/convert/write COLOR->Luv scanline */
935 >        uint32  y
936 > )
937   {
938          register int    x;
939  
# Line 922 | Line 964 | uint32 y;
964   }
965  
966  
967 < void
968 < Color2RRGGBB(y)                 /* read/convert/write COLOR->RGB16 scanline */
969 < uint32  y;
967 > static void
968 > Color2RRGGBB(                   /* read/convert/write COLOR->RGB16 scanline */
969 >        uint32  y
970 > )
971   {
972          int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
973          float   m = pow(2.,(double)cvts.bradj);
# Line 936 | Line 979 | uint32 y;
979          if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0)
980                  quiterr("error reading Radiance picture");
981  
982 <        for (x = cvts.xmax; x--; )
982 >        for (x = cvts.xmax; x--; ) {
983 >            if (CHK(C_CXFM)) {
984 >                        colortrans(cvts.r.colors[x], cvts.cmat,
985 >                                        cvts.r.colors[x]);
986 >                if (CHK(C_GAMUT))
987 >                        clipgamut(cvts.r.colors[x], bright(cvts.r.colors[x]),
988 >                                        CGAMUT_LOWER, cblack, cwhite);
989 >            }
990              for (i = 3; i--; ) {
991                  register float  f = m*colval(cvts.r.colors[x],i);
992                  if (f <= 0)
# Line 949 | Line 999 | uint32 y;
999                  else
1000                          cvts.t.wp[3*x + i] = (int)((float)(1L<<16)*f);
1001              }
1002 +        }
1003  
1004          if (TIFFWriteScanline(cvts.tif, cvts.t.p, y, 0) < 0)
1005                  quiterr("error writing TIFF output");
1006   }
1007  
1008  
1009 < void
1010 < Colr2Gry(y)                     /* read/convert/write COLR->RGB scanline */
1011 < uint32  y;
1009 > static void
1010 > Colr2Gry(                       /* read/convert/write COLR->RGB scanline */
1011 >        uint32  y
1012 > )
1013   {
1014          register int    x;
1015  
# Line 981 | Line 1033 | uint32 y;
1033   }
1034  
1035  
1036 < void
1037 < Colr2RGB(y)                     /* read/convert/write COLR->RGB scanline */
1038 < uint32  y;
1036 > static void
1037 > Colr2RGB(                       /* read/convert/write COLR->RGB scanline */
1038 >        uint32  y
1039 > )
1040   {
1041          COLOR   ctmp;
1042          register int    x;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines