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.26 by schorsch, Sun Jul 27 22:12:03 2003 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  "tiffio.h"
15   #include  "color.h"
# Line 29 | Line 30 | static const char      RCSid[] = "$Id$";
30  
31   struct {
32          uint16  flags;          /* conversion flags (defined above) */
33 +        char    capdate[20];    /* capture date/time */
34 +        char    owner[256];     /* content owner */
35          uint16  comp;           /* TIFF compression type */
36          uint16  phot;           /* TIFF photometric type */
37          uint16  pconf;          /* TIFF planar configuration */
# Line 55 | Line 58 | struct {
58          } t;                    /* TIFF scanline */
59          void    (*tf)();        /* translation procedure */
60   }       cvts = {        /* conversion structure */
61 <        0, COMPRESSION_NONE, PHOTOMETRIC_RGB,
61 >        0, "", "", COMPRESSION_NONE, PHOTOMETRIC_RGB,
62          PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1.,
63   };
64  
# Line 86 | Line 89 | short  ortab[8] = {            /* orientation conversion table */
89  
90   #define pixorder()      ortab[cvts.orient-1]
91  
92 + extern char     TMSTR[];        /* "CAPDATE=" from header.c */
93 + char            OWNSTR[] = "OWNER=";
94 +
95   char  *progname;
96  
97  
# Line 155 | Line 161 | doneopts:
161                  if (i != argc-2)
162                          goto userr;
163                                                  /* consistency checks */
164 <                if (CHK(C_GRY))
164 >                if (CHK(C_GRY)) {
165                          if (cvts.phot == PHOTOMETRIC_RGB)
166                                  cvts.phot = PHOTOMETRIC_MINISBLACK;
167                          else {
168                                  cvts.phot = PHOTOMETRIC_LOGL;
169                                  cvts.comp = COMPRESSION_SGILOG;
170                          }
171 +                }
172                  if (CHK(C_TWRD|C_TFLT) == (C_TWRD|C_TFLT))
173                          goto userr;
174  
# Line 201 | Line 208 | allocbufs()                    /* allocate scanline buffers */
208                          (CHK(C_GRY) ? 1 : 3);
209          cvts.r.p = (char *)malloc(rsiz*cvts.xmax);
210          cvts.t.p = (char *)malloc(tsiz*cvts.xmax);
211 <        if (cvts.r.p == NULL | cvts.t.p == NULL)
211 >        if ((cvts.r.p == NULL) | (cvts.t.p == NULL))
212                  quiterr("no memory to allocate scanline buffers");
213   }
214  
# Line 209 | Line 216 | allocbufs()                    /* allocate scanline buffers */
216   initfromtif()           /* initialize conversion from TIFF input */
217   {
218          uint16  hi;
219 +        char    *cp;
220          float   *fa, f1, f2;
221  
222          CLR(C_GRY|C_GAMMA|C_PRIM|C_RFLT|C_TFLT|C_TWRD|C_CXFM);
# Line 338 | Line 346 | initfromtif()          /* initialize conversion from TIFF inpu
346  
347          if (!TIFFGetField(cvts.tif, TIFFTAG_STONITS, &cvts.stonits))
348                  cvts.stonits = 1.;
349 +
350 +        if (!TIFFGetField(cvts.tif, TIFFTAG_DATETIME, &cp))
351 +                cvts.capdate[0] = '\0';
352 +        else {
353 +                strncpy(cvts.capdate, cp, 19);
354 +                cvts.capdate[19] = '\0';
355 +        }
356 +        if (!TIFFGetField(cvts.tif, TIFFTAG_ARTIST, &cp))
357 +                cvts.owner[0] = '\0';
358 +        else {
359 +                strncpy(cvts.owner, cp, sizeof(cvts.owner));
360 +                cvts.owner[sizeof(cvts.owner)-1] = '\0';
361 +        }
362                                          /* add to Radiance header */
363          if (cvts.pixrat < .99 || cvts.pixrat > 1.01)
364                  fputaspect(cvts.pixrat, cvts.rfp);
# Line 351 | Line 372 | initfromtif()          /* initialize conversion from TIFF inpu
372                                  cvts.rfp);
373                  fputformat(COLRFMT, cvts.rfp);
374          }
375 +        if (cvts.capdate[0])
376 +                fprintf(cvts.rfp, "%s %s\n", TMSTR, cvts.capdate);
377 +        if (cvts.owner[0])
378 +                fprintf(cvts.rfp, "%s %s\n", OWNSTR, cvts.owner);
379  
380          allocbufs();                    /* allocate scanline buffers */
381   }
# Line 390 | Line 415 | int
415   headline(s)                     /* process Radiance input header line */
416   char    *s;
417   {
418 +        static int      tmstrlen = 0;
419 +        static int      ownstrlen = 0;
420          char    fmt[32];
421  
422 +        if (!tmstrlen)
423 +                tmstrlen = strlen(TMSTR);
424 +        if (!ownstrlen)
425 +                ownstrlen = strlen(OWNSTR);
426          if (formatval(fmt, s)) {
427                  if (!strcmp(fmt, COLRFMT))
428                          CLR(C_XYZE);
# Line 414 | Line 445 | char   *s;
445                  SET(C_PRIM);
446                  return(1);
447          }
448 +        if (isdate(s)) {
449 +                if (s[tmstrlen] == ' ')
450 +                        strncpy(cvts.capdate, s+tmstrlen+1, 19);
451 +                else
452 +                        strncpy(cvts.capdate, s+tmstrlen, 19);
453 +                cvts.capdate[19] = '\0';
454 +                return(1);
455 +        }
456 +        if (!strncmp(s, OWNSTR, ownstrlen)) {
457 +                register char   *cp = s + ownstrlen;
458 +
459 +                while (isspace(*cp))
460 +                        ++cp;
461 +                strncpy(cvts.owner, cp, sizeof(cvts.owner));
462 +                cvts.owner[sizeof(cvts.owner)-1] = '\0';
463 +                for (cp = cvts.owner; *cp; cp++)
464 +                        ;
465 +                while (cp > cvts.owner && isspace(cp[-1]))
466 +                        *--cp = '\0';
467 +                return(1);
468 +        }
469          return(0);
470   }
471  
# Line 423 | Line 475 | initfromrad()                  /* initialize input from a Radiance pi
475          int     i1, i2, po;
476                                                  /* read Radiance header */
477          CLR(C_RFLT|C_XYZE|C_PRIM|C_GAMMA|C_CXFM);
478 +        cvts.capdate[0] = '\0';
479 +        cvts.owner[0] = '\0';
480          cvts.stonits = 1.;
481          cvts.pixrat = 1.;
482          cvts.pconf = PLANARCONFIG_CONTIG;
# Line 489 | Line 543 | initfromrad()                  /* initialize input from a Radiance pi
543                          cvts.tf = Color2RRGGBB;
544                          SET(C_RFLT);
545                  } else if (CHK(C_TFLT)) {
546 +                        TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT,
547 +                                        SAMPLEFORMAT_IEEEFP);
548                          cvts.tf = Color2RfGfBf;
549                          SET(C_RFLT);
550                  } else
# Line 501 | Line 557 | initfromrad()                  /* initialize input from a Radiance pi
557                          cvts.tf = Color2GGry;
558                          SET(C_RFLT);
559                  } else if (CHK(C_TFLT)) {
560 +                        TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT,
561 +                                        SAMPLEFORMAT_IEEEFP);
562                          cvts.tf = Color2Gryf;
563                          SET(C_RFLT);
564                  } else
# Line 523 | Line 581 | initfromrad()                  /* initialize input from a Radiance pi
581          TIFFSetField(cvts.tif, TIFFTAG_PLANARCONFIG, cvts.pconf);
582          TIFFSetField(cvts.tif, TIFFTAG_STONITS,
583                          cvts.stonits/pow(2.,(double)cvts.bradj));
584 +        if (cvts.capdate[0])
585 +                TIFFSetField(cvts.tif, TIFFTAG_DATETIME, cvts.capdate);
586 +        if (cvts.owner[0])
587 +                TIFFSetField(cvts.tif, TIFFTAG_ARTIST, cvts.owner);
588          if (cvts.comp == COMPRESSION_NONE)
589                  i1 = TIFFScanlineSize(cvts.tif);
590          else
# Line 598 | Line 660 | void
660   RRGGBB2Color(y)                 /* read/convert/write RGB16->COLOR scanline */
661   uint32  y;
662   {
663 <        int     dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01;
663 >        int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
664          register double d;
665          register int    x;
666  
# Line 745 | Line 807 | void
807   GGry2Color(y)                   /* read/convert/write G16->COLOR scanline */
808   uint32  y;
809   {
810 <        int     dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01;
810 >        int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
811          double  m;
812          register double d;
813          register int    x;
# Line 775 | Line 837 | void
837   Color2GGry(y)                   /* read/convert/write COLOR->G16 scanline */
838   uint32  y;
839   {
840 <        int     dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01;
840 >        int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
841          float   m = pow(2.,(double)cvts.bradj);
842          register int    x;
843  
# Line 864 | Line 926 | void
926   Color2RRGGBB(y)                 /* read/convert/write COLOR->RGB16 scanline */
927   uint32  y;
928   {
929 <        int     dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01;
929 >        int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
930          float   m = pow(2.,(double)cvts.bradj);
931          register int    x, i;
932  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines