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