--- ray/src/px/normtiff.c 2004/01/02 11:42:37 3.7 +++ ray/src/px/normtiff.c 2011/05/20 02:06:39 3.13 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: normtiff.c,v 3.7 2004/01/02 11:42:37 schorsch Exp $"; +static const char RCSid[] = "$Id: normtiff.c,v 3.13 2011/05/20 02:06:39 greg Exp $"; #endif /* * Tone map SGILOG TIFF or Radiance picture and output 24-bit RGB TIFF @@ -10,9 +10,11 @@ static const char RCSid[] = "$Id: normtiff.c,v 3.7 200 #include #include +#include "platform.h" #include "tiffio.h" #include "color.h" #include "tonemap.h" +#include "tmaptiff.h" #include "resolu.h" @@ -42,13 +44,20 @@ typedef struct { RESOLU rs; /* picture resolution */ } PICTURE; -extern PICTURE *openpicture(); +uint16 comp = COMPRESSION_NONE; /* TIFF compression mode */ #define closepicture(p) (fclose((p)->fp),free((void *)(p))) static gethfunc headline; +static int headline(char *s, void *pp); +static PICTURE *openpicture(char *fname); +static int tmap_picture(char *fname, PICTURE *pp); +static int tmap_tiff(char *fname, TIFF *tp); +static int putimage(uint16 or, uint32 xs, uint32 ys, float xr, float yr, + uint16 ru, uby8 *pd); + int main( int argc, @@ -88,6 +97,9 @@ main( if (argc-i < 2) goto userr; lddyn = atof(argv[++i]); break; + case 'z': /* LZW compression */ + comp = COMPRESSION_LZW; + break; case 'p': /* set display primaries */ if (argc-i < 9) goto userr; myprims[RED][CIEX] = atof(argv[++i]); @@ -126,7 +138,7 @@ main( exit(rval==0 ? 0 : 1); userr: fprintf(stderr, -"Usage: %s [-h][-s][-c][-l][-b][-g gv][-d ld][-u lm][-p xr yr xg yg xb yb xw yw] input.{tif|pic} output.tif\n", +"Usage: %s [-h][-s][-c][-l][-b][-g gv][-d ld][-u lm][-z][-p xr yr xg yg xb yb xw yw] input.{tif|hdr} output.tif\n", argv[0]); exit(1); } @@ -151,9 +163,10 @@ headline( /* process line from header */ } -PICTURE * -openpicture(fname) /* open/check Radiance picture file */ -char *fname; +static PICTURE * +openpicture( /* open/check Radiance picture file */ + char *fname +) { FILE *fp; register PICTURE *pp; @@ -172,6 +185,7 @@ char *fname; /* else try opening it */ if ((fp = fopen(fname, "r")) == NULL) return(NULL); + SET_FILE_BINARY(fp); /* allocate struct */ if ((pp = (PICTURE *)malloc(sizeof(PICTURE))) == NULL) return(NULL); /* serious error -- should exit? */ @@ -192,14 +206,16 @@ char *fname; } -int -tmap_picture(fname, pp) /* tone map Radiance picture */ -char *fname; -register PICTURE *pp; +static int +tmap_picture( /* tone map Radiance picture */ + char *fname, + register PICTURE *pp +) { uint16 orient; + double paspect = (pp->rs.rt & YMAJOR) ? pp->pa : 1./pp->pa; int xsiz, ysiz; - BYTE *pix; + uby8 *pix; /* read and tone map picture */ if (tmMapPicture(&pix, &xsiz, &ysiz, flags, rgbp, gamv, lddyn, ldmax, fname, pp->fp) != TM_E_OK) @@ -211,7 +227,7 @@ register PICTURE *pp; orient++; /* put out our image */ if (putimage(orient, (uint32)xsiz, (uint32)ysiz, - 72., 72./pp->pa, 2, pix) != 0) + 72., 72./paspect, 2, pix) != 0) return(-1); /* free data and we're done */ free((void *)pix); @@ -219,14 +235,16 @@ register PICTURE *pp; } -tmap_tiff(fname, tp) /* tone map SGILOG TIFF */ -char *fname; -TIFF *tp; +static int +tmap_tiff( /* tone map SGILOG TIFF */ + char *fname, + TIFF *tp +) { float xres, yres; uint16 orient, resunit, phot; int xsiz, ysiz; - BYTE *pix; + uby8 *pix; /* check to make sure it's SGILOG */ TIFFGetFieldDefaulted(tp, TIFFTAG_PHOTOMETRIC, &phot); if ((phot == PHOTOMETRIC_LOGL) | (phot == PHOTOMETRIC_MINISBLACK)) @@ -250,12 +268,16 @@ TIFF *tp; } -putimage(or, xs, ys, xr, yr, ru, pd) /* write out our image */ -uint16 or; -uint32 xs, ys; -float xr, yr; -uint16 ru; -BYTE *pd; +static int +putimage( /* write out our image */ + uint16 or, + uint32 xs, + uint32 ys, + float xr, + float yr, + uint16 ru, + uby8 *pd +) { register int y; uint32 rowsperstrip; @@ -278,6 +300,7 @@ BYTE *pd; TIFFSetField(tifout, TIFFTAG_IMAGEWIDTH, xs); TIFFSetField(tifout, TIFFTAG_IMAGELENGTH, ys); TIFFSetField(tifout, TIFFTAG_RESOLUTIONUNIT, ru); + TIFFSetField(tifout, TIFFTAG_COMPRESSION, comp); TIFFSetField(tifout, TIFFTAG_XRESOLUTION, xr); TIFFSetField(tifout, TIFFTAG_YRESOLUTION, yr); TIFFSetField(tifout, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);