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.21 by greg, Tue Jul 1 19:04:08 2003 UTC vs.
Revision 2.27 by schorsch, Fri Jan 2 12:47:01 2004 UTC

# Line 9 | Line 9 | static const char      RCSid[] = "$Id$";
9  
10   #include  <stdio.h>
11   #include  <math.h>
12 + #include  <ctype.h>
13   #include  <time.h>
14 + #include  <string.h>
15 +
16   #include  "tiffio.h"
17   #include  "color.h"
18   #include  "resolu.h"
# Line 29 | Line 32 | static const char      RCSid[] = "$Id$";
32  
33   struct {
34          uint16  flags;          /* conversion flags (defined above) */
35 +        char    capdate[20];    /* capture date/time */
36 +        char    owner[256];     /* content owner */
37          uint16  comp;           /* TIFF compression type */
38          uint16  phot;           /* TIFF photometric type */
39          uint16  pconf;          /* TIFF planar configuration */
# Line 55 | Line 60 | struct {
60          } t;                    /* TIFF scanline */
61          void    (*tf)();        /* translation procedure */
62   }       cvts = {        /* conversion structure */
63 <        0, COMPRESSION_NONE, PHOTOMETRIC_RGB,
63 >        0, "", "", COMPRESSION_NONE, PHOTOMETRIC_RGB,
64          PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1.,
65   };
66  
# Line 86 | Line 91 | short  ortab[8] = {            /* orientation conversion table */
91  
92   #define pixorder()      ortab[cvts.orient-1]
93  
94 + extern char     TMSTR[];        /* "CAPDATE=" from header.c */
95 + char            OWNSTR[] = "OWNER=";
96 +
97   char  *progname;
98  
99 + static gethfunc headline;
100  
101 +
102   main(argc, argv)
103   int  argc;
104   char  *argv[];
# Line 155 | Line 165 | doneopts:
165                  if (i != argc-2)
166                          goto userr;
167                                                  /* consistency checks */
168 <                if (CHK(C_GRY))
168 >                if (CHK(C_GRY)) {
169                          if (cvts.phot == PHOTOMETRIC_RGB)
170                                  cvts.phot = PHOTOMETRIC_MINISBLACK;
171                          else {
172                                  cvts.phot = PHOTOMETRIC_LOGL;
173                                  cvts.comp = COMPRESSION_SGILOG;
174                          }
175 +                }
176                  if (CHK(C_TWRD|C_TFLT) == (C_TWRD|C_TFLT))
177                          goto userr;
178  
# Line 201 | Line 212 | allocbufs()                    /* allocate scanline buffers */
212                          (CHK(C_GRY) ? 1 : 3);
213          cvts.r.p = (char *)malloc(rsiz*cvts.xmax);
214          cvts.t.p = (char *)malloc(tsiz*cvts.xmax);
215 <        if (cvts.r.p == NULL | cvts.t.p == NULL)
215 >        if ((cvts.r.p == NULL) | (cvts.t.p == NULL))
216                  quiterr("no memory to allocate scanline buffers");
217   }
218  
# Line 209 | Line 220 | allocbufs()                    /* allocate scanline buffers */
220   initfromtif()           /* initialize conversion from TIFF input */
221   {
222          uint16  hi;
223 +        char    *cp;
224          float   *fa, f1, f2;
225  
226          CLR(C_GRY|C_GAMMA|C_PRIM|C_RFLT|C_TFLT|C_TWRD|C_CXFM);
# Line 338 | Line 350 | initfromtif()          /* initialize conversion from TIFF inpu
350  
351          if (!TIFFGetField(cvts.tif, TIFFTAG_STONITS, &cvts.stonits))
352                  cvts.stonits = 1.;
353 +
354 +        if (!TIFFGetField(cvts.tif, TIFFTAG_DATETIME, &cp))
355 +                cvts.capdate[0] = '\0';
356 +        else {
357 +                strncpy(cvts.capdate, cp, 19);
358 +                cvts.capdate[19] = '\0';
359 +        }
360 +        if (!TIFFGetField(cvts.tif, TIFFTAG_ARTIST, &cp))
361 +                cvts.owner[0] = '\0';
362 +        else {
363 +                strncpy(cvts.owner, cp, sizeof(cvts.owner));
364 +                cvts.owner[sizeof(cvts.owner)-1] = '\0';
365 +        }
366                                          /* add to Radiance header */
367          if (cvts.pixrat < .99 || cvts.pixrat > 1.01)
368                  fputaspect(cvts.pixrat, cvts.rfp);
# Line 351 | Line 376 | initfromtif()          /* initialize conversion from TIFF inpu
376                                  cvts.rfp);
377                  fputformat(COLRFMT, cvts.rfp);
378          }
379 +        if (cvts.capdate[0])
380 +                fprintf(cvts.rfp, "%s %s\n", TMSTR, cvts.capdate);
381 +        if (cvts.owner[0])
382 +                fprintf(cvts.rfp, "%s %s\n", OWNSTR, cvts.owner);
383  
384          allocbufs();                    /* allocate scanline buffers */
385   }
# Line 386 | Line 415 | char  *av[];
415   }
416  
417  
418 < int
419 < headline(s)                     /* process Radiance input header line */
420 < char    *s;
418 > static int
419 > headline(                       /* process Radiance input header line */
420 >        char    *s,
421 >        void    *p
422 > )
423   {
424 +        static int      tmstrlen = 0;
425 +        static int      ownstrlen = 0;
426          char    fmt[32];
427  
428 +        if (!tmstrlen)
429 +                tmstrlen = strlen(TMSTR);
430 +        if (!ownstrlen)
431 +                ownstrlen = strlen(OWNSTR);
432          if (formatval(fmt, s)) {
433                  if (!strcmp(fmt, COLRFMT))
434                          CLR(C_XYZE);
# Line 414 | Line 451 | char   *s;
451                  SET(C_PRIM);
452                  return(1);
453          }
454 +        if (isdate(s)) {
455 +                if (s[tmstrlen] == ' ')
456 +                        strncpy(cvts.capdate, s+tmstrlen+1, 19);
457 +                else
458 +                        strncpy(cvts.capdate, s+tmstrlen, 19);
459 +                cvts.capdate[19] = '\0';
460 +                return(1);
461 +        }
462 +        if (!strncmp(s, OWNSTR, ownstrlen)) {
463 +                register char   *cp = s + ownstrlen;
464 +
465 +                while (isspace(*cp))
466 +                        ++cp;
467 +                strncpy(cvts.owner, cp, sizeof(cvts.owner));
468 +                cvts.owner[sizeof(cvts.owner)-1] = '\0';
469 +                for (cp = cvts.owner; *cp; cp++)
470 +                        ;
471 +                while (cp > cvts.owner && isspace(cp[-1]))
472 +                        *--cp = '\0';
473 +                return(1);
474 +        }
475          return(0);
476   }
477  
# Line 423 | Line 481 | initfromrad()                  /* initialize input from a Radiance pi
481          int     i1, i2, po;
482                                                  /* read Radiance header */
483          CLR(C_RFLT|C_XYZE|C_PRIM|C_GAMMA|C_CXFM);
484 +        cvts.capdate[0] = '\0';
485 +        cvts.owner[0] = '\0';
486          cvts.stonits = 1.;
487          cvts.pixrat = 1.;
488          cvts.pconf = PLANARCONFIG_CONTIG;
# Line 489 | Line 549 | initfromrad()                  /* initialize input from a Radiance pi
549                          cvts.tf = Color2RRGGBB;
550                          SET(C_RFLT);
551                  } else if (CHK(C_TFLT)) {
552 +                        TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT,
553 +                                        SAMPLEFORMAT_IEEEFP);
554                          cvts.tf = Color2RfGfBf;
555                          SET(C_RFLT);
556                  } else
# Line 501 | Line 563 | initfromrad()                  /* initialize input from a Radiance pi
563                          cvts.tf = Color2GGry;
564                          SET(C_RFLT);
565                  } else if (CHK(C_TFLT)) {
566 +                        TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT,
567 +                                        SAMPLEFORMAT_IEEEFP);
568                          cvts.tf = Color2Gryf;
569                          SET(C_RFLT);
570                  } else
# Line 523 | Line 587 | initfromrad()                  /* initialize input from a Radiance pi
587          TIFFSetField(cvts.tif, TIFFTAG_PLANARCONFIG, cvts.pconf);
588          TIFFSetField(cvts.tif, TIFFTAG_STONITS,
589                          cvts.stonits/pow(2.,(double)cvts.bradj));
590 +        if (cvts.capdate[0])
591 +                TIFFSetField(cvts.tif, TIFFTAG_DATETIME, cvts.capdate);
592 +        if (cvts.owner[0])
593 +                TIFFSetField(cvts.tif, TIFFTAG_ARTIST, cvts.owner);
594          if (cvts.comp == COMPRESSION_NONE)
595                  i1 = TIFFScanlineSize(cvts.tif);
596          else
# Line 598 | Line 666 | void
666   RRGGBB2Color(y)                 /* read/convert/write RGB16->COLOR scanline */
667   uint32  y;
668   {
669 <        int     dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01;
669 >        int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
670          register double d;
671          register int    x;
672  
# Line 745 | Line 813 | void
813   GGry2Color(y)                   /* read/convert/write G16->COLOR scanline */
814   uint32  y;
815   {
816 <        int     dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01;
816 >        int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
817          double  m;
818          register double d;
819          register int    x;
# Line 775 | Line 843 | void
843   Color2GGry(y)                   /* read/convert/write COLOR->G16 scanline */
844   uint32  y;
845   {
846 <        int     dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01;
846 >        int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
847          float   m = pow(2.,(double)cvts.bradj);
848          register int    x;
849  
# Line 864 | Line 932 | void
932   Color2RRGGBB(y)                 /* read/convert/write COLOR->RGB16 scanline */
933   uint32  y;
934   {
935 <        int     dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01;
935 >        int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
936          float   m = pow(2.,(double)cvts.bradj);
937          register int    x, i;
938  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines