--- ray/src/px/ra_tiff.c 2003/07/01 19:04:08 2.21 +++ ray/src/px/ra_tiff.c 2004/01/02 12:47:01 2.27 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: ra_tiff.c,v 2.21 2003/07/01 19:04:08 greg Exp $"; +static const char RCSid[] = "$Id: ra_tiff.c,v 2.27 2004/01/02 12:47:01 schorsch Exp $"; #endif /* * Program to convert between RADIANCE and TIFF files. @@ -9,7 +9,10 @@ static const char RCSid[] = "$Id: ra_tiff.c,v 2.21 200 #include #include +#include #include +#include + #include "tiffio.h" #include "color.h" #include "resolu.h" @@ -29,6 +32,8 @@ static const char RCSid[] = "$Id: ra_tiff.c,v 2.21 200 struct { uint16 flags; /* conversion flags (defined above) */ + char capdate[20]; /* capture date/time */ + char owner[256]; /* content owner */ uint16 comp; /* TIFF compression type */ uint16 phot; /* TIFF photometric type */ uint16 pconf; /* TIFF planar configuration */ @@ -55,7 +60,7 @@ struct { } t; /* TIFF scanline */ void (*tf)(); /* translation procedure */ } cvts = { /* conversion structure */ - 0, COMPRESSION_NONE, PHOTOMETRIC_RGB, + 0, "", "", COMPRESSION_NONE, PHOTOMETRIC_RGB, PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1., }; @@ -86,9 +91,14 @@ short ortab[8] = { /* orientation conversion table */ #define pixorder() ortab[cvts.orient-1] +extern char TMSTR[]; /* "CAPDATE=" from header.c */ +char OWNSTR[] = "OWNER="; + char *progname; +static gethfunc headline; + main(argc, argv) int argc; char *argv[]; @@ -155,13 +165,14 @@ doneopts: if (i != argc-2) goto userr; /* consistency checks */ - if (CHK(C_GRY)) + if (CHK(C_GRY)) { if (cvts.phot == PHOTOMETRIC_RGB) cvts.phot = PHOTOMETRIC_MINISBLACK; else { cvts.phot = PHOTOMETRIC_LOGL; cvts.comp = COMPRESSION_SGILOG; } + } if (CHK(C_TWRD|C_TFLT) == (C_TWRD|C_TFLT)) goto userr; @@ -201,7 +212,7 @@ allocbufs() /* allocate scanline buffers */ (CHK(C_GRY) ? 1 : 3); cvts.r.p = (char *)malloc(rsiz*cvts.xmax); cvts.t.p = (char *)malloc(tsiz*cvts.xmax); - if (cvts.r.p == NULL | cvts.t.p == NULL) + if ((cvts.r.p == NULL) | (cvts.t.p == NULL)) quiterr("no memory to allocate scanline buffers"); } @@ -209,6 +220,7 @@ allocbufs() /* allocate scanline buffers */ initfromtif() /* initialize conversion from TIFF input */ { uint16 hi; + char *cp; float *fa, f1, f2; CLR(C_GRY|C_GAMMA|C_PRIM|C_RFLT|C_TFLT|C_TWRD|C_CXFM); @@ -338,6 +350,19 @@ initfromtif() /* initialize conversion from TIFF inpu if (!TIFFGetField(cvts.tif, TIFFTAG_STONITS, &cvts.stonits)) cvts.stonits = 1.; + + if (!TIFFGetField(cvts.tif, TIFFTAG_DATETIME, &cp)) + cvts.capdate[0] = '\0'; + else { + strncpy(cvts.capdate, cp, 19); + cvts.capdate[19] = '\0'; + } + if (!TIFFGetField(cvts.tif, TIFFTAG_ARTIST, &cp)) + cvts.owner[0] = '\0'; + else { + strncpy(cvts.owner, cp, sizeof(cvts.owner)); + cvts.owner[sizeof(cvts.owner)-1] = '\0'; + } /* add to Radiance header */ if (cvts.pixrat < .99 || cvts.pixrat > 1.01) fputaspect(cvts.pixrat, cvts.rfp); @@ -351,6 +376,10 @@ initfromtif() /* initialize conversion from TIFF inpu cvts.rfp); fputformat(COLRFMT, cvts.rfp); } + if (cvts.capdate[0]) + fprintf(cvts.rfp, "%s %s\n", TMSTR, cvts.capdate); + if (cvts.owner[0]) + fprintf(cvts.rfp, "%s %s\n", OWNSTR, cvts.owner); allocbufs(); /* allocate scanline buffers */ } @@ -386,12 +415,20 @@ char *av[]; } -int -headline(s) /* process Radiance input header line */ -char *s; +static int +headline( /* process Radiance input header line */ + char *s, + void *p +) { + static int tmstrlen = 0; + static int ownstrlen = 0; char fmt[32]; + if (!tmstrlen) + tmstrlen = strlen(TMSTR); + if (!ownstrlen) + ownstrlen = strlen(OWNSTR); if (formatval(fmt, s)) { if (!strcmp(fmt, COLRFMT)) CLR(C_XYZE); @@ -414,6 +451,27 @@ char *s; SET(C_PRIM); return(1); } + if (isdate(s)) { + if (s[tmstrlen] == ' ') + strncpy(cvts.capdate, s+tmstrlen+1, 19); + else + strncpy(cvts.capdate, s+tmstrlen, 19); + cvts.capdate[19] = '\0'; + return(1); + } + if (!strncmp(s, OWNSTR, ownstrlen)) { + register char *cp = s + ownstrlen; + + while (isspace(*cp)) + ++cp; + strncpy(cvts.owner, cp, sizeof(cvts.owner)); + cvts.owner[sizeof(cvts.owner)-1] = '\0'; + for (cp = cvts.owner; *cp; cp++) + ; + while (cp > cvts.owner && isspace(cp[-1])) + *--cp = '\0'; + return(1); + } return(0); } @@ -423,6 +481,8 @@ initfromrad() /* initialize input from a Radiance pi int i1, i2, po; /* read Radiance header */ CLR(C_RFLT|C_XYZE|C_PRIM|C_GAMMA|C_CXFM); + cvts.capdate[0] = '\0'; + cvts.owner[0] = '\0'; cvts.stonits = 1.; cvts.pixrat = 1.; cvts.pconf = PLANARCONFIG_CONTIG; @@ -489,6 +549,8 @@ initfromrad() /* initialize input from a Radiance pi cvts.tf = Color2RRGGBB; SET(C_RFLT); } else if (CHK(C_TFLT)) { + TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT, + SAMPLEFORMAT_IEEEFP); cvts.tf = Color2RfGfBf; SET(C_RFLT); } else @@ -501,6 +563,8 @@ initfromrad() /* initialize input from a Radiance pi cvts.tf = Color2GGry; SET(C_RFLT); } else if (CHK(C_TFLT)) { + TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT, + SAMPLEFORMAT_IEEEFP); cvts.tf = Color2Gryf; SET(C_RFLT); } else @@ -523,6 +587,10 @@ initfromrad() /* initialize input from a Radiance pi TIFFSetField(cvts.tif, TIFFTAG_PLANARCONFIG, cvts.pconf); TIFFSetField(cvts.tif, TIFFTAG_STONITS, cvts.stonits/pow(2.,(double)cvts.bradj)); + if (cvts.capdate[0]) + TIFFSetField(cvts.tif, TIFFTAG_DATETIME, cvts.capdate); + if (cvts.owner[0]) + TIFFSetField(cvts.tif, TIFFTAG_ARTIST, cvts.owner); if (cvts.comp == COMPRESSION_NONE) i1 = TIFFScanlineSize(cvts.tif); else @@ -598,7 +666,7 @@ void RRGGBB2Color(y) /* read/convert/write RGB16->COLOR scanline */ uint32 y; { - int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; + int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); register double d; register int x; @@ -745,7 +813,7 @@ void GGry2Color(y) /* read/convert/write G16->COLOR scanline */ uint32 y; { - int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; + int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); double m; register double d; register int x; @@ -775,7 +843,7 @@ void Color2GGry(y) /* read/convert/write COLOR->G16 scanline */ uint32 y; { - int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; + int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); float m = pow(2.,(double)cvts.bradj); register int x; @@ -864,7 +932,7 @@ void Color2RRGGBB(y) /* read/convert/write COLOR->RGB16 scanline */ uint32 y; { - int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; + int dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01); float m = pow(2.,(double)cvts.bradj); register int x, i;