--- ray/src/px/ra_tiff.c 1991/11/11 14:01:23 1.6 +++ ray/src/px/ra_tiff.c 1995/10/30 10:56:57 2.8 @@ -10,21 +10,24 @@ static char SCCSid[] = "$SunId$ LBL"; #include +#include + #include "tiffio.h" #include "color.h" #include "resolu.h" -extern double atof(); +#define GAMCOR 2.2 /* default gamma */ + extern char *malloc(), *realloc(); int lzcomp = 0; /* use Lempel-Ziv compression? */ int greyscale = 0; /* produce greyscale image? */ -double gamma = 2.2; /* gamma correction */ +double gamcor = GAMCOR; /* gamma correction */ int bradj = 0; /* brightness adjustment */ @@ -44,7 +47,7 @@ char *argv[]; if (argv[i][0] == '-') switch (argv[i][1]) { case 'g': - gamma = atof(argv[++i]); + gamcor = atof(argv[++i]); break; case 'z': lzcomp = !lzcomp; @@ -68,7 +71,7 @@ char *argv[]; else break; doneopts: - setcolrgam(gamma); + setcolrgam(gamcor); if (reverse) if (i != argc-2 && i != argc-1) @@ -121,10 +124,12 @@ char *inpf, *outf; if (!TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &hi) || hi != 8) quiterr("unsupported bits per sample"); if (TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &hi) && - hi != (nsamps==1 ? 1 : 2)) + hi != (nsamps==1 ? PHOTOMETRIC_MINISBLACK : + PHOTOMETRIC_RGB)) quiterr("unsupported photometric interpretation"); if (!TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &pconfig) || - (pconfig != 1 && pconfig != 2)) + (pconfig != PLANARCONFIG_CONTIG && + pconfig != PLANARCONFIG_SEPARATE)) quiterr("unsupported planar configuration"); if (!TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &xmax) || !TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &ymax)) @@ -138,13 +143,16 @@ char *inpf, *outf; if (outf != NULL && strcmp(outf, "-") && freopen(outf, "w", stdout) == NULL) quiterr("cannot open Radiance output file"); + newheader("RADIANCE", stdout); fputs(progname, stdout); if (bradj) printf(" -e %+d", bradj); + if (gamcor != GAMCOR) + printf(" -g %f", gamcor); fputs(" -r\n", stdout); fputformat(COLRFMT, stdout); putchar('\n'); - fprtresolu(xmax, ymax, stdout); + fprtresolu((int)xmax, (int)ymax, stdout); /* convert image */ if (nsamps == 1) pconfig = 1; @@ -215,10 +223,13 @@ char *inpf, *outf; TIFFSetField(tif, TIFFTAG_IMAGELENGTH, (unsigned long)ymax); TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, greyscale ? 1 : 3); TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8); - TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, greyscale ? 1 : 2); - TIFFSetField(tif, TIFFTAG_PLANARCONFIG, 1); + TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, + greyscale ? PHOTOMETRIC_MINISBLACK : + PHOTOMETRIC_RGB); + TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); if (lzcomp) - TIFFSetField(tif, TIFFTAG_COMPRESSION, (unsigned short)5); + TIFFSetField(tif, TIFFTAG_COMPRESSION, + (unsigned short)COMPRESSION_LZW); /* allocate scanlines */ scanin = (COLR *)malloc(xmax*sizeof(COLR)); scanout = (BYTE *)malloc(TIFFScanlineSize(tif));