--- ray/src/px/ra_tiff.c 2003/07/16 01:32:53 2.24 +++ ray/src/px/ra_tiff.c 2005/03/22 15:26:05 2.30 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: ra_tiff.c,v 2.24 2003/07/16 01:32:53 greg Exp $"; +static const char RCSid[] = "$Id: ra_tiff.c,v 2.30 2005/03/22 15:26:05 greg Exp $"; #endif /* * Program to convert between RADIANCE and TIFF files. @@ -11,6 +11,8 @@ static const char RCSid[] = "$Id: ra_tiff.c,v 2.24 200 #include #include #include +#include + #include "tiffio.h" #include "color.h" #include "resolu.h" @@ -28,6 +30,8 @@ static const char RCSid[] = "$Id: ra_tiff.c,v 2.24 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 */ @@ -56,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., @@ -67,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 @@ -95,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; @@ -161,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; @@ -186,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); @@ -197,7 +213,8 @@ char *err; } -allocbufs() /* allocate scanline buffers */ +static void +allocbufs(void) /* allocate scanline buffers */ { int rsiz, tsiz; @@ -207,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; @@ -257,7 +275,7 @@ initfromtif() /* initialize conversion from TIFF inpu cpcolormat(cvts.cmat, xyz2rgbmat); SET(C_CXFM|C_GAMUT); } else if (cvts.comp == COMPRESSION_SGILOG) - SET(C_GAMUT); + SET(C_GAMUT); /* may be outside XYZ gamut */ if (cvts.pconf != PLANARCONFIG_CONTIG) quiterr("cannot handle separate Luv planes"); TIFFSetField(cvts.tif, TIFFTAG_SGILOGDATAFMT, @@ -380,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 */ @@ -410,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; @@ -469,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 */ @@ -546,6 +569,7 @@ initfromrad() /* initialize input from a Radiance pi SAMPLEFORMAT_IEEEFP); cvts.tf = Color2RfGfBf; SET(C_RFLT); + CLR(C_GAMUT); } else cvts.tf = Colr2RGB; break; @@ -596,9 +620,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 */ @@ -620,9 +646,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; @@ -655,11 +682,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; @@ -682,9 +710,6 @@ uint32 y; if (CHK(C_CXFM)) colortrans(cvts.r.colors[x], cvts.cmat, cvts.r.colors[x]); - if (CHK(C_GAMUT)) - clipgamut(cvts.r.colors[x], cvts.t.fp[3*x + 1], - CGAMUT_LOWER, cblack, cwhite); } if (cvts.bradj) { d = pow(2.,(double)cvts.bradj); @@ -697,9 +722,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; @@ -720,9 +746,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; @@ -776,9 +803,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; @@ -802,11 +830,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; @@ -832,11 +861,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; @@ -866,9 +896,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; @@ -888,9 +919,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; @@ -921,11 +953,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; @@ -935,7 +968,14 @@ uint32 y; if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) quiterr("error reading Radiance picture"); - for (x = cvts.xmax; x--; ) + for (x = cvts.xmax; x--; ) { + if (CHK(C_CXFM)) { + colortrans(cvts.r.colors[x], cvts.cmat, + cvts.r.colors[x]); + if (CHK(C_GAMUT)) + clipgamut(cvts.r.colors[x], bright(cvts.r.colors[x]), + CGAMUT_LOWER, cblack, cwhite); + } for (i = 3; i--; ) { register float f = m*colval(cvts.r.colors[x],i); if (f <= 0) @@ -948,15 +988,17 @@ uint32 y; else cvts.t.wp[3*x + i] = (int)((float)(1L<<16)*f); } + } if (TIFFWriteScanline(cvts.tif, cvts.t.p, y, 0) < 0) quiterr("error writing TIFF output"); } -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; @@ -980,9 +1022,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;