roentgen b75cab
/* $Id: pal2rgb.c,v 1.13 2010-07-02 12:02:56 dron Exp $ */
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * Copyright (c) 1988-1997 Sam Leffler
roentgen b75cab
 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
roentgen b75cab
 *
roentgen b75cab
 * Permission to use, copy, modify, distribute, and sell this software and 
roentgen b75cab
 * its documentation for any purpose is hereby granted without fee, provided
roentgen b75cab
 * that (i) the above copyright notices and this permission notice appear in
roentgen b75cab
 * all copies of the software and related documentation, and (ii) the names of
roentgen b75cab
 * Sam Leffler and Silicon Graphics may not be used in any advertising or
roentgen b75cab
 * publicity relating to the software without the specific, prior written
roentgen b75cab
 * permission of Sam Leffler and Silicon Graphics.
roentgen b75cab
 * 
roentgen b75cab
 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
roentgen b75cab
 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
roentgen b75cab
 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
roentgen b75cab
 * 
roentgen b75cab
 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
roentgen b75cab
 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
roentgen b75cab
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
roentgen b75cab
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
roentgen b75cab
 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
roentgen b75cab
 * OF THIS SOFTWARE.
roentgen b75cab
 */
roentgen b75cab
roentgen b75cab
#include "tif_config.h"
roentgen b75cab
roentgen b75cab
#include <stdio.h></stdio.h>
roentgen b75cab
#include <string.h></string.h>
roentgen b75cab
#include <stdlib.h></stdlib.h>
roentgen b75cab
#include <ctype.h></ctype.h>
roentgen b75cab
roentgen b75cab
#ifdef HAVE_UNISTD_H
roentgen b75cab
# include <unistd.h></unistd.h>
roentgen b75cab
#endif
roentgen b75cab
roentgen b75cab
#ifdef NEED_LIBPORT
roentgen b75cab
# include "libport.h"
roentgen b75cab
#endif
roentgen b75cab
roentgen b75cab
#include "tiffio.h"
roentgen b75cab
roentgen b75cab
#define	streq(a,b)	(strcmp(a,b) == 0)
roentgen b75cab
#define	strneq(a,b,n)	(strncmp(a,b,n) == 0)
roentgen b75cab
roentgen b75cab
static	void usage(void);
roentgen b75cab
static	void cpTags(TIFF* in, TIFF* out);
roentgen b75cab
roentgen b75cab
static int
roentgen b75cab
checkcmap(int n, uint16* r, uint16* g, uint16* b)
roentgen b75cab
{
roentgen b75cab
	while (n-- > 0)
roentgen b75cab
	    if (*r++ >= 256 || *g++ >= 256 || *b++ >= 256)
roentgen b75cab
		return (16);
roentgen b75cab
	fprintf(stderr, "Warning, assuming 8-bit colormap.\n");
roentgen b75cab
	return (8);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
#define	CopyField(tag, v) \
roentgen b75cab
    if (TIFFGetField(in, tag, &v)) TIFFSetField(out, tag, v)
roentgen b75cab
#define	CopyField3(tag, v1, v2, v3) \
roentgen b75cab
    if (TIFFGetField(in, tag, &v1, &v2, &v3)) TIFFSetField(out, tag, v1, v2, v3)
roentgen b75cab
roentgen b75cab
static	uint16 compression = (uint16) -1;
roentgen b75cab
static	uint16 predictor = 0;
roentgen b75cab
static	int quality = 75;	/* JPEG quality */
roentgen b75cab
static	int jpegcolormode = JPEGCOLORMODE_RGB;
roentgen b75cab
static	int processCompressOptions(char*);
roentgen b75cab
roentgen b75cab
int
roentgen b75cab
main(int argc, char* argv[])
roentgen b75cab
{
roentgen b75cab
	uint16 bitspersample, shortv;
roentgen b75cab
	uint32 imagewidth, imagelength;
roentgen b75cab
	uint16 config = PLANARCONFIG_CONTIG;
roentgen b75cab
	uint32 rowsperstrip = (uint32) -1;
roentgen b75cab
	uint16 photometric = PHOTOMETRIC_RGB;
roentgen b75cab
	uint16 *rmap, *gmap, *bmap;
roentgen b75cab
	uint32 row;
roentgen b75cab
	int cmap = -1;
roentgen b75cab
	TIFF *in, *out;
roentgen b75cab
	int c;
roentgen b75cab
	extern int optind;
roentgen b75cab
	extern char* optarg;
roentgen b75cab
roentgen b75cab
	while ((c = getopt(argc, argv, "C:c:p:r:")) != -1)
roentgen b75cab
		switch (c) {
roentgen b75cab
		case 'C':		/* force colormap interpretation */
roentgen b75cab
			cmap = atoi(optarg);
roentgen b75cab
			break;
roentgen b75cab
		case 'c':		/* compression scheme */
roentgen b75cab
			if (!processCompressOptions(optarg))
roentgen b75cab
				usage();
roentgen b75cab
			break;
roentgen b75cab
		case 'p':		/* planar configuration */
roentgen b75cab
			if (streq(optarg, "separate"))
roentgen b75cab
				config = PLANARCONFIG_SEPARATE;
roentgen b75cab
			else if (streq(optarg, "contig"))
roentgen b75cab
				config = PLANARCONFIG_CONTIG;
roentgen b75cab
			else
roentgen b75cab
				usage();
roentgen b75cab
			break;
roentgen b75cab
		case 'r':		/* rows/strip */
roentgen b75cab
			rowsperstrip = atoi(optarg);
roentgen b75cab
			break;
roentgen b75cab
		case '?':
roentgen b75cab
			usage();
roentgen b75cab
			/*NOTREACHED*/
roentgen b75cab
		}
roentgen b75cab
	if (argc - optind != 2)
roentgen b75cab
		usage();
roentgen b75cab
	in = TIFFOpen(argv[optind], "r");
roentgen b75cab
	if (in == NULL)
roentgen b75cab
		return (-1);
roentgen b75cab
	if (!TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &shortv) ||
roentgen b75cab
	    shortv != PHOTOMETRIC_PALETTE) {
roentgen b75cab
		fprintf(stderr, "%s: Expecting a palette image.\n",
roentgen b75cab
		    argv[optind]);
roentgen b75cab
		return (-1);
roentgen b75cab
	}
roentgen b75cab
	if (!TIFFGetField(in, TIFFTAG_COLORMAP, &rmap, &gmap, &bmap)) {
roentgen b75cab
		fprintf(stderr,
roentgen b75cab
		    "%s: No colormap (not a valid palette image).\n",
roentgen b75cab
		    argv[optind]);
roentgen b75cab
		return (-1);
roentgen b75cab
	}
roentgen b75cab
	bitspersample = 0;
roentgen b75cab
	TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bitspersample);
roentgen b75cab
	if (bitspersample != 8) {
roentgen b75cab
		fprintf(stderr, "%s: Sorry, can only handle 8-bit images.\n",
roentgen b75cab
		    argv[optind]);
roentgen b75cab
		return (-1);
roentgen b75cab
	}
roentgen b75cab
	out = TIFFOpen(argv[optind+1], "w");
roentgen b75cab
	if (out == NULL)
roentgen b75cab
		return (-2);
roentgen b75cab
	cpTags(in, out);
roentgen b75cab
	TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &imagewidth);
roentgen b75cab
	TIFFGetField(in, TIFFTAG_IMAGELENGTH, &imagelength);
roentgen b75cab
	if (compression != (uint16)-1)
roentgen b75cab
		TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
roentgen b75cab
	else
roentgen b75cab
		TIFFGetField(in, TIFFTAG_COMPRESSION, &compression);
roentgen b75cab
	switch (compression) {
roentgen b75cab
	case COMPRESSION_JPEG:
roentgen b75cab
		if (jpegcolormode == JPEGCOLORMODE_RGB)
roentgen b75cab
			photometric = PHOTOMETRIC_YCBCR;
roentgen b75cab
		else
roentgen b75cab
			photometric = PHOTOMETRIC_RGB;
roentgen b75cab
		TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality);
roentgen b75cab
		TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, jpegcolormode);
roentgen b75cab
		break;
roentgen b75cab
	case COMPRESSION_LZW:
roentgen b75cab
	case COMPRESSION_DEFLATE:
roentgen b75cab
		if (predictor != 0)
roentgen b75cab
			TIFFSetField(out, TIFFTAG_PREDICTOR, predictor);
roentgen b75cab
		break;
roentgen b75cab
	}
roentgen b75cab
	TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photometric);
roentgen b75cab
	TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 3);
roentgen b75cab
	TIFFSetField(out, TIFFTAG_PLANARCONFIG, config);
roentgen b75cab
	TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
roentgen b75cab
	    rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip));
roentgen b75cab
	(void) TIFFGetField(in, TIFFTAG_PLANARCONFIG, &shortv);
roentgen b75cab
	if (cmap == -1)
roentgen b75cab
		cmap = checkcmap(1<
roentgen b75cab
	if (cmap == 16) {
roentgen b75cab
		/*
roentgen b75cab
		 * Convert 16-bit colormap to 8-bit.
roentgen b75cab
		 */
roentgen b75cab
		int i;
roentgen b75cab
roentgen b75cab
		for (i = (1<<bitspersample)-1; i="">= 0; i--) {</bitspersample)-1;>
roentgen b75cab
#define	CVT(x)		(((x) * 255) / ((1L<<16)-1))
roentgen b75cab
			rmap[i] = CVT(rmap[i]);
roentgen b75cab
			gmap[i] = CVT(gmap[i]);
roentgen b75cab
			bmap[i] = CVT(bmap[i]);
roentgen b75cab
		}
roentgen b75cab
	}
roentgen b75cab
	{ unsigned char *ibuf, *obuf;
roentgen b75cab
	  register unsigned char* pp;
roentgen b75cab
	  register uint32 x;
roentgen b75cab
	  ibuf = (unsigned char*)_TIFFmalloc(TIFFScanlineSize(in));
roentgen b75cab
	  obuf = (unsigned char*)_TIFFmalloc(TIFFScanlineSize(out));
roentgen b75cab
	  switch (config) {
roentgen b75cab
	  case PLANARCONFIG_CONTIG:
roentgen b75cab
		for (row = 0; row < imagelength; row++) {
roentgen b75cab
			if (!TIFFReadScanline(in, ibuf, row, 0))
roentgen b75cab
				goto done;
roentgen b75cab
			pp = obuf;
roentgen b75cab
			for (x = 0; x < imagewidth; x++) {
roentgen b75cab
				*pp++ = (unsigned char) rmap[ibuf[x]];
roentgen b75cab
				*pp++ = (unsigned char) gmap[ibuf[x]];
roentgen b75cab
				*pp++ = (unsigned char) bmap[ibuf[x]];
roentgen b75cab
			}
roentgen b75cab
			if (!TIFFWriteScanline(out, obuf, row, 0))
roentgen b75cab
				goto done;
roentgen b75cab
		}
roentgen b75cab
		break;
roentgen b75cab
	  case PLANARCONFIG_SEPARATE:
roentgen b75cab
		for (row = 0; row < imagelength; row++) {
roentgen b75cab
			if (!TIFFReadScanline(in, ibuf, row, 0))
roentgen b75cab
				goto done;
roentgen b75cab
			for (pp = obuf, x = 0; x < imagewidth; x++)
roentgen b75cab
				*pp++ = (unsigned char) rmap[ibuf[x]];
roentgen b75cab
			if (!TIFFWriteScanline(out, obuf, row, 0))
roentgen b75cab
				goto done;
roentgen b75cab
			for (pp = obuf, x = 0; x < imagewidth; x++)
roentgen b75cab
				*pp++ = (unsigned char) gmap[ibuf[x]];
roentgen b75cab
			if (!TIFFWriteScanline(out, obuf, row, 0))
roentgen b75cab
				goto done;
roentgen b75cab
			for (pp = obuf, x = 0; x < imagewidth; x++)
roentgen b75cab
				*pp++ = (unsigned char) bmap[ibuf[x]];
roentgen b75cab
			if (!TIFFWriteScanline(out, obuf, row, 0))
roentgen b75cab
				goto done;
roentgen b75cab
		}
roentgen b75cab
		break;
roentgen b75cab
	  }
roentgen b75cab
	  _TIFFfree(ibuf);
roentgen b75cab
	  _TIFFfree(obuf);
roentgen b75cab
	}
roentgen b75cab
done:
roentgen b75cab
	(void) TIFFClose(in);
roentgen b75cab
	(void) TIFFClose(out);
roentgen b75cab
	return (0);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
static int
roentgen b75cab
processCompressOptions(char* opt)
roentgen b75cab
{
roentgen b75cab
	if (streq(opt, "none"))
roentgen b75cab
		compression = COMPRESSION_NONE;
roentgen b75cab
	else if (streq(opt, "packbits"))
roentgen b75cab
		compression = COMPRESSION_PACKBITS;
roentgen b75cab
	else if (strneq(opt, "jpeg", 4)) {
roentgen b75cab
		char* cp = strchr(opt, ':');
roentgen b75cab
roentgen b75cab
                compression = COMPRESSION_JPEG;
roentgen b75cab
                while( cp )
roentgen b75cab
                {
roentgen b75cab
                    if (isdigit((int)cp[1]))
roentgen b75cab
			quality = atoi(cp+1);
roentgen b75cab
                    else if (cp[1] == 'r' )
roentgen b75cab
			jpegcolormode = JPEGCOLORMODE_RAW;
roentgen b75cab
                    else
roentgen b75cab
                        usage();
roentgen b75cab
roentgen b75cab
                    cp = strchr(cp+1,':');
roentgen b75cab
                }
roentgen b75cab
	} else if (strneq(opt, "lzw", 3)) {
roentgen b75cab
		char* cp = strchr(opt, ':');
roentgen b75cab
		if (cp)
roentgen b75cab
			predictor = atoi(cp+1);
roentgen b75cab
		compression = COMPRESSION_LZW;
roentgen b75cab
	} else if (strneq(opt, "zip", 3)) {
roentgen b75cab
		char* cp = strchr(opt, ':');
roentgen b75cab
		if (cp)
roentgen b75cab
			predictor = atoi(cp+1);
roentgen b75cab
		compression = COMPRESSION_DEFLATE;
roentgen b75cab
	} else
roentgen b75cab
		return (0);
roentgen b75cab
	return (1);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
#define	CopyField(tag, v) \
roentgen b75cab
    if (TIFFGetField(in, tag, &v)) TIFFSetField(out, tag, v)
roentgen b75cab
#define	CopyField2(tag, v1, v2) \
roentgen b75cab
    if (TIFFGetField(in, tag, &v1, &v2)) TIFFSetField(out, tag, v1, v2)
roentgen b75cab
#define	CopyField3(tag, v1, v2, v3) \
roentgen b75cab
    if (TIFFGetField(in, tag, &v1, &v2, &v3)) TIFFSetField(out, tag, v1, v2, v3)
roentgen b75cab
#define	CopyField4(tag, v1, v2, v3, v4) \
roentgen b75cab
    if (TIFFGetField(in, tag, &v1, &v2, &v3, &v4)) TIFFSetField(out, tag, v1, v2, v3, v4)
roentgen b75cab
roentgen b75cab
static void
roentgen b75cab
cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type)
roentgen b75cab
{
roentgen b75cab
	switch (type) {
roentgen b75cab
	case TIFF_SHORT:
roentgen b75cab
		if (count == 1) {
roentgen b75cab
			uint16 shortv;
roentgen b75cab
			CopyField(tag, shortv);
roentgen b75cab
		} else if (count == 2) {
roentgen b75cab
			uint16 shortv1, shortv2;
roentgen b75cab
			CopyField2(tag, shortv1, shortv2);
roentgen b75cab
		} else if (count == 4) {
roentgen b75cab
			uint16 *tr, *tg, *tb, *ta;
roentgen b75cab
			CopyField4(tag, tr, tg, tb, ta);
roentgen b75cab
		} else if (count == (uint16) -1) {
roentgen b75cab
			uint16 shortv1;
roentgen b75cab
			uint16* shortav;
roentgen b75cab
			CopyField2(tag, shortv1, shortav);
roentgen b75cab
		}
roentgen b75cab
		break;
roentgen b75cab
	case TIFF_LONG:
roentgen b75cab
		{ uint32 longv;
roentgen b75cab
		  CopyField(tag, longv);
roentgen b75cab
		}
roentgen b75cab
		break;
roentgen b75cab
	case TIFF_RATIONAL:
roentgen b75cab
		if (count == 1) {
roentgen b75cab
			float floatv;
roentgen b75cab
			CopyField(tag, floatv);
roentgen b75cab
		} else if (count == (uint16) -1) {
roentgen b75cab
			float* floatav;
roentgen b75cab
			CopyField(tag, floatav);
roentgen b75cab
		}
roentgen b75cab
		break;
roentgen b75cab
	case TIFF_ASCII:
roentgen b75cab
		{ char* stringv;
roentgen b75cab
		  CopyField(tag, stringv);
roentgen b75cab
		}
roentgen b75cab
		break;
roentgen b75cab
	case TIFF_DOUBLE:
roentgen b75cab
		if (count == 1) {
roentgen b75cab
			double doublev;
roentgen b75cab
			CopyField(tag, doublev);
roentgen b75cab
		} else if (count == (uint16) -1) {
roentgen b75cab
			double* doubleav;
roentgen b75cab
			CopyField(tag, doubleav);
roentgen b75cab
		}
roentgen b75cab
		break;
roentgen b75cab
          default:
roentgen b75cab
                TIFFError(TIFFFileName(in),
roentgen b75cab
                          "Data type %d is not supported, tag %d skipped.",
roentgen b75cab
                          tag, type);
roentgen b75cab
	}
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
#undef CopyField4
roentgen b75cab
#undef CopyField3
roentgen b75cab
#undef CopyField2
roentgen b75cab
#undef CopyField
roentgen b75cab
roentgen b75cab
static struct cpTag {
roentgen b75cab
    uint16	tag;
roentgen b75cab
    uint16	count;
roentgen b75cab
    TIFFDataType type;
roentgen b75cab
} tags[] = {
roentgen b75cab
    { TIFFTAG_IMAGEWIDTH,		1, TIFF_LONG },
roentgen b75cab
    { TIFFTAG_IMAGELENGTH,		1, TIFF_LONG },
roentgen b75cab
    { TIFFTAG_BITSPERSAMPLE,		1, TIFF_SHORT },
roentgen b75cab
    { TIFFTAG_COMPRESSION,		1, TIFF_SHORT },
roentgen b75cab
    { TIFFTAG_FILLORDER,		1, TIFF_SHORT },
roentgen b75cab
    { TIFFTAG_ROWSPERSTRIP,		1, TIFF_LONG },
roentgen b75cab
    { TIFFTAG_GROUP3OPTIONS,		1, TIFF_LONG },
roentgen b75cab
    { TIFFTAG_SUBFILETYPE,		1, TIFF_LONG },
roentgen b75cab
    { TIFFTAG_THRESHHOLDING,		1, TIFF_SHORT },
roentgen b75cab
    { TIFFTAG_DOCUMENTNAME,		1, TIFF_ASCII },
roentgen b75cab
    { TIFFTAG_IMAGEDESCRIPTION,		1, TIFF_ASCII },
roentgen b75cab
    { TIFFTAG_MAKE,			1, TIFF_ASCII },
roentgen b75cab
    { TIFFTAG_MODEL,			1, TIFF_ASCII },
roentgen b75cab
    { TIFFTAG_ORIENTATION,		1, TIFF_SHORT },
roentgen b75cab
    { TIFFTAG_MINSAMPLEVALUE,		1, TIFF_SHORT },
roentgen b75cab
    { TIFFTAG_MAXSAMPLEVALUE,		1, TIFF_SHORT },
roentgen b75cab
    { TIFFTAG_XRESOLUTION,		1, TIFF_RATIONAL },
roentgen b75cab
    { TIFFTAG_YRESOLUTION,		1, TIFF_RATIONAL },
roentgen b75cab
    { TIFFTAG_PAGENAME,			1, TIFF_ASCII },
roentgen b75cab
    { TIFFTAG_XPOSITION,		1, TIFF_RATIONAL },
roentgen b75cab
    { TIFFTAG_YPOSITION,		1, TIFF_RATIONAL },
roentgen b75cab
    { TIFFTAG_GROUP4OPTIONS,		1, TIFF_LONG },
roentgen b75cab
    { TIFFTAG_RESOLUTIONUNIT,		1, TIFF_SHORT },
roentgen b75cab
    { TIFFTAG_PAGENUMBER,		2, TIFF_SHORT },
roentgen b75cab
    { TIFFTAG_SOFTWARE,			1, TIFF_ASCII },
roentgen b75cab
    { TIFFTAG_DATETIME,			1, TIFF_ASCII },
roentgen b75cab
    { TIFFTAG_ARTIST,			1, TIFF_ASCII },
roentgen b75cab
    { TIFFTAG_HOSTCOMPUTER,		1, TIFF_ASCII },
roentgen b75cab
    { TIFFTAG_WHITEPOINT,		2, TIFF_RATIONAL },
roentgen b75cab
    { TIFFTAG_PRIMARYCHROMATICITIES,	(uint16) -1,TIFF_RATIONAL },
roentgen b75cab
    { TIFFTAG_HALFTONEHINTS,		2, TIFF_SHORT },
roentgen b75cab
    { TIFFTAG_BADFAXLINES,		1, TIFF_LONG },
roentgen b75cab
    { TIFFTAG_CLEANFAXDATA,		1, TIFF_SHORT },
roentgen b75cab
    { TIFFTAG_CONSECUTIVEBADFAXLINES,	1, TIFF_LONG },
roentgen b75cab
    { TIFFTAG_INKSET,			1, TIFF_SHORT },
roentgen b75cab
    { TIFFTAG_INKNAMES,			1, TIFF_ASCII },
roentgen b75cab
    { TIFFTAG_DOTRANGE,			2, TIFF_SHORT },
roentgen b75cab
    { TIFFTAG_TARGETPRINTER,		1, TIFF_ASCII },
roentgen b75cab
    { TIFFTAG_SAMPLEFORMAT,		1, TIFF_SHORT },
roentgen b75cab
    { TIFFTAG_YCBCRCOEFFICIENTS,	(uint16) -1,TIFF_RATIONAL },
roentgen b75cab
    { TIFFTAG_YCBCRSUBSAMPLING,		2, TIFF_SHORT },
roentgen b75cab
    { TIFFTAG_YCBCRPOSITIONING,		1, TIFF_SHORT },
roentgen b75cab
    { TIFFTAG_REFERENCEBLACKWHITE,	(uint16) -1,TIFF_RATIONAL },
roentgen b75cab
};
roentgen b75cab
#define	NTAGS	(sizeof (tags) / sizeof (tags[0]))
roentgen b75cab
roentgen b75cab
static void
roentgen b75cab
cpTags(TIFF* in, TIFF* out)
roentgen b75cab
{
roentgen b75cab
    struct cpTag *p;
roentgen b75cab
    for (p = tags; p < &tags[NTAGS]; p++)
roentgen b75cab
	cpTag(in, out, p->tag, p->count, p->type);
roentgen b75cab
}
roentgen b75cab
#undef NTAGS
roentgen b75cab
roentgen b75cab
char* stuff[] = {
roentgen b75cab
"usage: pal2rgb [options] input.tif output.tif",
roentgen b75cab
"where options are:",
roentgen b75cab
" -p contig	pack samples contiguously (e.g. RGBRGB...)",
roentgen b75cab
" -p separate	store samples separately (e.g. RRR...GGG...BBB...)",
roentgen b75cab
" -r #		make each strip have no more than # rows",
roentgen b75cab
" -C 8		assume 8-bit colormap values (instead of 16-bit)",
roentgen b75cab
" -C 16		assume 16-bit colormap values",
roentgen b75cab
"",
roentgen b75cab
" -c lzw[:opts]	compress output with Lempel-Ziv & Welch encoding",
roentgen b75cab
" -c zip[:opts]	compress output with deflate encoding",
roentgen b75cab
" -c packbits	compress output with packbits encoding",
roentgen b75cab
" -c none	use no compression algorithm on output",
roentgen b75cab
"",
roentgen b75cab
"LZW and deflate options:",
roentgen b75cab
" #		set predictor value",
roentgen b75cab
"For example, -c lzw:2 to get LZW-encoded data with horizontal differencing",
roentgen b75cab
NULL
roentgen b75cab
};
roentgen b75cab
roentgen b75cab
static void
roentgen b75cab
usage(void)
roentgen b75cab
{
roentgen b75cab
	char buf[BUFSIZ];
roentgen b75cab
	int i;
roentgen b75cab
roentgen b75cab
	setbuf(stderr, buf);
roentgen b75cab
        fprintf(stderr, "%s\n\n", TIFFGetVersion());
roentgen b75cab
	for (i = 0; stuff[i] != NULL; i++)
roentgen b75cab
		fprintf(stderr, "%s\n", stuff[i]);
roentgen b75cab
	exit(-1);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
/* vim: set ts=8 sts=8 sw=8 noet: */
roentgen b75cab
/*
roentgen b75cab
 * Local Variables:
roentgen b75cab
 * mode: c
roentgen b75cab
 * c-basic-offset: 8
roentgen b75cab
 * fill-column: 78
roentgen b75cab
 * End:
roentgen b75cab
 */