--- ray/src/px/ra_tiff.c 2003/07/01 22:44:02 2.22 +++ ray/src/px/ra_tiff.c 2004/03/28 20:33:14 2.28 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: ra_tiff.c,v 2.22 2003/07/01 22:44:02 greg Exp $"; +static const char RCSid[] = "$Id: ra_tiff.c,v 2.28 2004/03/28 20:33:14 schorsch Exp $"; #endif /* * Program to convert between RADIANCE and TIFF files. @@ -10,6 +10,9 @@ static const char RCSid[] = "$Id: ra_tiff.c,v 2.22 200 #include #include #include +#include +#include + #include "tiffio.h" #include "color.h" #include "resolu.h" @@ -27,6 +30,8 @@ static const char RCSid[] = "$Id: ra_tiff.c,v 2.22 200 #define C_TWRD 0x80 /* TIFF data is 16-bit */ #define C_PRIM 0x100 /* has assigned primaries */ +typedef void colcvf_t(uint32 y); + struct { uint16 flags; /* conversion flags (defined above) */ char capdate[20]; /* capture date/time */ @@ -55,7 +60,7 @@ struct { float *fp; /* float pointer */ char *p; /* generic pointer */ } t; /* TIFF scanline */ - void (*tf)(); /* translation procedure */ + colcvf_t *tf; /* translation procedure */ } cvts = { /* conversion structure */ 0, "", "", COMPRESSION_NONE, PHOTOMETRIC_RGB, PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1., @@ -66,10 +71,20 @@ struct { #define CLR(f) (cvts.flags &= ~(f)) #define TGL(f) (cvts.flags ^= (f)) -void Luv2Color(), L2Color(), RGB2Colr(), Gry2Colr(); -void Color2Luv(), Color2L(), Colr2RGB(), Colr2Gry(); -void RRGGBB2Color(), GGry2Color(), Color2RRGGBB(), Color2GGry(); +static colcvf_t Luv2Color, L2Color, RGB2Colr, Gry2Colr; +static colcvf_t Color2Luv, Color2L, Colr2RGB, Colr2Gry; +static colcvf_t RRGGBB2Color, GGry2Color, Color2RRGGBB, Color2GGry; +static gethfunc headline; +static void quiterr(char *err); +static void allocbufs(void); +static void initfromtif(void); +static void tiff2ra(int ac, char *av[]); +static void initfromrad(void); +static void ra2tiff(int ac, char *av[]); + + + #define RfGfBf2Color Luv2Color #define Gryf2Color L2Color #define Color2Gryf Color2L @@ -94,9 +109,8 @@ char OWNSTR[] = "OWNER="; char *progname; -main(argc, argv) -int argc; -char *argv[]; +int +main(int argc, char *argv[]) { int reverse = 0; int i; @@ -160,13 +174,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; @@ -185,8 +200,10 @@ userr: } -quiterr(err) /* print message and exit */ -char *err; +static void +quiterr( /* print message and exit */ + char *err +) { if (err != NULL) { fprintf(stderr, "%s: %s\n", progname, err); @@ -196,7 +213,8 @@ char *err; } -allocbufs() /* allocate scanline buffers */ +static void +allocbufs(void) /* allocate scanline buffers */ { int rsiz, tsiz; @@ -206,12 +224,13 @@ 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"); } -initfromtif() /* initialize conversion from TIFF input */ +static void +initfromtif(void) /* initialize conversion from TIFF input */ { uint16 hi; char *cp; @@ -379,9 +398,11 @@ initfromtif() /* initialize conversion from TIFF inpu } -tiff2ra(ac, av) /* convert TIFF image to Radiance picture */ -int ac; -char *av[]; +static void +tiff2ra( /* convert TIFF image to Radiance picture */ + int ac, + char *av[] +) { int32 y; /* open TIFF input */ @@ -409,9 +430,11 @@ 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; @@ -468,7 +491,8 @@ char *s; } -initfromrad() /* initialize input from a Radiance picture */ +static void +initfromrad(void) /* initialize input from a Radiance picture */ { int i1, i2, po; /* read Radiance header */ @@ -541,6 +565,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 @@ -553,6 +579,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 @@ -591,9 +619,11 @@ initfromrad() /* initialize input from a Radiance pi } -ra2tiff(ac, av) /* convert Radiance picture to TIFF image */ -int ac; -char *av[]; +static void +ra2tiff( /* convert Radiance picture to TIFF image */ + int ac, + char *av[] +) { uint32 y; /* open Radiance file */ @@ -615,9 +645,10 @@ char *av[]; } -void -Luv2Color(y) /* read/convert/write Luv->COLOR scanline */ -uint32 y; +static void +Luv2Color( /* read/convert/write Luv->COLOR scanline */ + uint32 y +) { register int x; @@ -650,11 +681,12 @@ uint32 y; } -void -RRGGBB2Color(y) /* read/convert/write RGB16->COLOR scanline */ -uint32 y; +static void +RRGGBB2Color( /* 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; @@ -692,9 +724,10 @@ uint32 y; } -void -L2Color(y) /* read/convert/write Lfloat->COLOR scanline */ -uint32 y; +static void +L2Color( /* read/convert/write Lfloat->COLOR scanline */ + uint32 y +) { float m = pow(2., (double)cvts.bradj); register int x; @@ -715,9 +748,10 @@ uint32 y; } -void -RGB2Colr(y) /* read/convert/write RGB->COLR scanline */ -uint32 y; +static void +RGB2Colr( /* read/convert/write RGB->COLR scanline */ + uint32 y +) { COLOR ctmp; register int x; @@ -771,9 +805,10 @@ readerr: } -void -Gry2Colr(y) /* read/convert/write G8->COLR scanline */ -uint32 y; +static void +Gry2Colr( /* read/convert/write G8->COLR scanline */ + uint32 y +) { register int x; @@ -797,11 +832,12 @@ uint32 y; } -void -GGry2Color(y) /* read/convert/write G16->COLOR scanline */ -uint32 y; +static void +GGry2Color( /* 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; @@ -827,11 +863,12 @@ uint32 y; } -void -Color2GGry(y) /* read/convert/write COLOR->G16 scanline */ -uint32 y; +static void +Color2GGry( /* 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; @@ -861,9 +898,10 @@ uint32 y; } -void -Color2L(y) /* read/convert/write COLOR->Lfloat scanline */ -uint32 y; +static void +Color2L( /* read/convert/write COLOR->Lfloat scanline */ + uint32 y +) { float m = pow(2.,(double)cvts.bradj); register int x; @@ -883,9 +921,10 @@ uint32 y; } -void -Color2Luv(y) /* read/convert/write COLOR->Luv scanline */ -uint32 y; +static void +Color2Luv( /* read/convert/write COLOR->Luv scanline */ + uint32 y +) { register int x; @@ -916,11 +955,12 @@ uint32 y; } -void -Color2RRGGBB(y) /* read/convert/write COLOR->RGB16 scanline */ -uint32 y; +static void +Color2RRGGBB( /* 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; @@ -949,9 +989,10 @@ uint32 y; } -void -Colr2Gry(y) /* read/convert/write COLR->RGB scanline */ -uint32 y; +static void +Colr2Gry( /* read/convert/write COLR->RGB scanline */ + uint32 y +) { register int x; @@ -975,9 +1016,10 @@ uint32 y; } -void -Colr2RGB(y) /* read/convert/write COLR->RGB scanline */ -uint32 y; +static void +Colr2RGB( /* read/convert/write COLR->RGB scanline */ + uint32 y +) { COLOR ctmp; register int x;