--- ray/src/px/normtiff.c 2003/07/14 04:56:54 3.5 +++ 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.5 2003/07/14 04:56:54 greg 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 @@ -8,9 +8,13 @@ static const char RCSid[] = "$Id: normtiff.c,v 3.5 200 #include #include #include +#include + +#include "platform.h" #include "tiffio.h" #include "color.h" #include "tonemap.h" +#include "tmaptiff.h" #include "resolu.h" @@ -40,14 +44,25 @@ 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; -main(argc, argv) -int argc; -char *argv[]; +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, + char *argv[] +) { PICTURE *pin = NULL; TIFF *tin = NULL; @@ -82,6 +97,9 @@ char *argv[]; 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]); @@ -120,16 +138,17 @@ char *argv[]; 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); } -int -headline(s, pp) /* process line from header */ -char *s; -register PICTURE *pp; +static int +headline( /* process line from header */ + char *s, + void *pp +) { register char *cp; @@ -137,16 +156,17 @@ register PICTURE *pp; if (*cp & 0x80) return(-1); /* non-ascii in header */ if (isaspect(s)) - pp->pa *= aspectval(s); + ((PICTURE *)pp)->pa *= aspectval(s); else - formatval(pp->fmt, s); + formatval(((PICTURE *)pp)->fmt, s); return(0); } -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; @@ -165,12 +185,13 @@ 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? */ pp->fp = fp; pp->fmt[0] = '\0'; pp->pa = 1.; /* load header */ - if (getheader(fp, headline, (char *)pp) < 0) { + if (getheader(fp, headline, pp) < 0) { closepicture(pp); return(NULL); } @@ -185,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) @@ -204,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); @@ -212,17 +235,19 @@ 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) + if ((phot == PHOTOMETRIC_LOGL) | (phot == PHOTOMETRIC_MINISBLACK)) flags |= TM_F_BW; /* read and tone map TIFF */ if (tmMapTIFF(&pix, &xsiz, &ysiz, flags, @@ -243,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; @@ -271,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);