--- ray/src/px/normtiff.c 1998/10/27 08:54:37 3.3 +++ ray/src/px/normtiff.c 2005/06/14 22:23:31 3.9 @@ -1,21 +1,19 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: normtiff.c,v 3.9 2005/06/14 22:23:31 greg Exp $"; #endif - /* * Tone map SGILOG TIFF or Radiance picture and output 24-bit RGB TIFF */ -#undef NOPROTO -#define NOPROTO 1 - #include #include +#include +#include + #include "tiffio.h" #include "color.h" #include "tonemap.h" +#include "tmaptiff.h" #include "resolu.h" @@ -45,14 +43,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((char *)(p))) +#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, BYTE *pd); + + +int +main( + int argc, + char *argv[] +) { PICTURE *pin = NULL; TIFF *tin = NULL; @@ -87,6 +96,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]); @@ -125,16 +137,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|pic} 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; @@ -142,16 +155,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; @@ -190,10 +204,11 @@ 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; int xsiz, ysiz; @@ -204,7 +219,7 @@ register PICTURE *pp; return(-1); /* figure out TIFF orientation */ for (orient = 8; --orient; ) - if (ortab[orient] == pp->rs.or) + if (ortab[orient] == pp->rs.rt) break; orient++; /* put out our image */ @@ -212,14 +227,16 @@ register PICTURE *pp; 72., 72./pp->pa, 2, pix) != 0) return(-1); /* free data and we're done */ - free((char *)pix); + free((void *)pix); return(0); } -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; @@ -227,14 +244,7 @@ TIFF *tp; BYTE *pix; /* check to make sure it's SGILOG */ TIFFGetFieldDefaulted(tp, TIFFTAG_PHOTOMETRIC, &phot); - if (phot != PHOTOMETRIC_LOGLUV && phot != PHOTOMETRIC_LOGL) { - if (!(flags & TM_F_NOSTDERR)) { - fputs(fname, stderr); - fputs(": TIFF must be in SGILOG format\n", stderr); - } - return(-1); - } - if (phot == PHOTOMETRIC_LOGL) + if ((phot == PHOTOMETRIC_LOGL) | (phot == PHOTOMETRIC_MINISBLACK)) flags |= TM_F_BW; /* read and tone map TIFF */ if (tmMapTIFF(&pix, &xsiz, &ysiz, flags, @@ -250,17 +260,21 @@ TIFF *tp; xres, yres, resunit, pix) != 0) return(-1); /* free data and we're done */ - free((char *)pix); + free((void *)pix); return(0); } -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, + BYTE *pd +) { register int y; uint32 rowsperstrip; @@ -283,6 +297,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);