kusano 7d535a
/* $Id: tiff2bw.c,v 1.15 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 <stdlib.h></stdlib.h>
kusano 7d535a
#include <string.h></string.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
/* x% weighting -> fraction of full color */
kusano 7d535a
#define	PCT(x)	(((x)*255+127)/100)
kusano 7d535a
int	RED = PCT(30);		/* 30% */
kusano 7d535a
int	GREEN = PCT(59);	/* 59% */
kusano 7d535a
int	BLUE = PCT(11);		/* 11% */
kusano 7d535a
kusano 7d535a
static	void usage(void);
kusano 7d535a
static	int processCompressOptions(char*);
kusano 7d535a
kusano 7d535a
static void
kusano 7d535a
compresscontig(unsigned char* out, unsigned char* rgb, uint32 n)
kusano 7d535a
{
kusano 7d535a
	register int v, red = RED, green = GREEN, blue = BLUE;
kusano 7d535a
kusano 7d535a
	while (n-- > 0) {
kusano 7d535a
		v = red*(*rgb++);
kusano 7d535a
		v += green*(*rgb++);
kusano 7d535a
		v += blue*(*rgb++);
kusano 7d535a
		*out++ = v>>8;
kusano 7d535a
	}
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
static void
kusano 7d535a
compresssep(unsigned char* out,
kusano 7d535a
	    unsigned char* r, unsigned char* g, unsigned char* b, uint32 n)
kusano 7d535a
{
kusano 7d535a
	register uint32 red = RED, green = GREEN, blue = BLUE;
kusano 7d535a
kusano 7d535a
	while (n-- > 0)
kusano 7d535a
		*out++ = (unsigned char)
kusano 7d535a
			((red*(*r++) + green*(*g++) + blue*(*b++)) >> 8);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
static int
kusano 7d535a
checkcmap(TIFF* tif, 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
	TIFFWarning(TIFFFileName(tif), "Assuming 8-bit colormap");
kusano 7d535a
	return (8);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
static void
kusano 7d535a
compresspalette(unsigned char* out, unsigned char* data, uint32 n, uint16* rmap, uint16* gmap, uint16* bmap)
kusano 7d535a
{
kusano 7d535a
	register int v, red = RED, green = GREEN, blue = BLUE;
kusano 7d535a
kusano 7d535a
	while (n-- > 0) {
kusano 7d535a
		unsigned int ix = *data++;
kusano 7d535a
		v = red*rmap[ix];
kusano 7d535a
		v += green*gmap[ix];
kusano 7d535a
		v += blue*bmap[ix];
kusano 7d535a
		*out++ = v>>8;
kusano 7d535a
	}
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
static	uint16 compression = (uint16) -1;
kusano 7d535a
static	uint16 predictor = 0;
kusano 7d535a
static	int jpegcolormode = JPEGCOLORMODE_RGB;
kusano 7d535a
static	int quality = 75;		/* JPEG quality */
kusano 7d535a
kusano 7d535a
static	void cpTags(TIFF* in, TIFF* out);
kusano 7d535a
kusano 7d535a
int
kusano 7d535a
main(int argc, char* argv[])
kusano 7d535a
{
kusano 7d535a
	uint32 rowsperstrip = (uint32) -1;
kusano 7d535a
	TIFF *in, *out;
kusano 7d535a
	uint32 w, h;
kusano 7d535a
	uint16 samplesperpixel;
kusano 7d535a
	uint16 bitspersample;
kusano 7d535a
	uint16 config;
kusano 7d535a
	uint16 photometric;
kusano 7d535a
	uint16* red;
kusano 7d535a
	uint16* green;
kusano 7d535a
	uint16* blue;
kusano 7d535a
	tsize_t rowsize;
kusano 7d535a
	register uint32 row;
kusano 7d535a
	register tsample_t s;
kusano 7d535a
	unsigned char *inbuf, *outbuf;
kusano 7d535a
	char thing[1024];
kusano 7d535a
	int c;
kusano 7d535a
	extern int optind;
kusano 7d535a
	extern char *optarg;
kusano 7d535a
kusano 7d535a
	while ((c = getopt(argc, argv, "c:r:R:G:B:")) != -1)
kusano 7d535a
		switch (c) {
kusano 7d535a
		case 'c':		/* compression scheme */
kusano 7d535a
			if (!processCompressOptions(optarg))
kusano 7d535a
				usage();
kusano 7d535a
			break;
kusano 7d535a
		case 'r':		/* rows/strip */
kusano 7d535a
			rowsperstrip = atoi(optarg);
kusano 7d535a
			break;
kusano 7d535a
		case 'R':
kusano 7d535a
			RED = PCT(atoi(optarg));
kusano 7d535a
			break;
kusano 7d535a
		case 'G':
kusano 7d535a
			GREEN = PCT(atoi(optarg));
kusano 7d535a
			break;
kusano 7d535a
		case 'B':
kusano 7d535a
			BLUE = PCT(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
	photometric = 0;
kusano 7d535a
	TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &photometric);
kusano 7d535a
	if (photometric != PHOTOMETRIC_RGB && photometric != PHOTOMETRIC_PALETTE ) {
kusano 7d535a
		fprintf(stderr,
kusano 7d535a
	    "%s: Bad photometric; can only handle RGB and Palette images.\n",
kusano 7d535a
		    argv[optind]);
kusano 7d535a
		return (-1);
kusano 7d535a
	}
kusano 7d535a
	TIFFGetField(in, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel);
kusano 7d535a
	if (samplesperpixel != 1 && samplesperpixel != 3) {
kusano 7d535a
		fprintf(stderr, "%s: Bad samples/pixel %u.\n",
kusano 7d535a
		    argv[optind], samplesperpixel);
kusano 7d535a
		return (-1);
kusano 7d535a
	}
kusano 7d535a
	TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bitspersample);
kusano 7d535a
	if (bitspersample != 8) {
kusano 7d535a
		fprintf(stderr,
kusano 7d535a
		    " %s: Sorry, only handle 8-bit samples.\n", argv[optind]);
kusano 7d535a
		return (-1);
kusano 7d535a
	}
kusano 7d535a
	TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &w);
kusano 7d535a
	TIFFGetField(in, TIFFTAG_IMAGELENGTH, &h);
kusano 7d535a
	TIFFGetField(in, TIFFTAG_PLANARCONFIG, &config);
kusano 7d535a
kusano 7d535a
	out = TIFFOpen(argv[optind+1], "w");
kusano 7d535a
	if (out == NULL)
kusano 7d535a
		return (-1);
kusano 7d535a
	TIFFSetField(out, TIFFTAG_IMAGEWIDTH, w);
kusano 7d535a
	TIFFSetField(out, TIFFTAG_IMAGELENGTH, h);
kusano 7d535a
	TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
kusano 7d535a
	TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 1);
kusano 7d535a
	TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
kusano 7d535a
	cpTags(in, out);
kusano 7d535a
	if (compression != (uint16) -1) {
kusano 7d535a
		TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
kusano 7d535a
		switch (compression) {
kusano 7d535a
		case COMPRESSION_JPEG:
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
	}
kusano 7d535a
	TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
kusano 7d535a
	sprintf(thing, "B&W version of %s", argv[optind]);
kusano 7d535a
	TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION, thing);
kusano 7d535a
	TIFFSetField(out, TIFFTAG_SOFTWARE, "tiff2bw");
kusano 7d535a
	outbuf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out));
kusano 7d535a
	TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
kusano 7d535a
	    TIFFDefaultStripSize(out, rowsperstrip));
kusano 7d535a
kusano 7d535a
#define	pack(a,b)	((a)<<8 | (b))
kusano 7d535a
	switch (pack(photometric, config)) {
kusano 7d535a
	case pack(PHOTOMETRIC_PALETTE, PLANARCONFIG_CONTIG):
kusano 7d535a
	case pack(PHOTOMETRIC_PALETTE, PLANARCONFIG_SEPARATE):
kusano 7d535a
		TIFFGetField(in, TIFFTAG_COLORMAP, &red, &green, &blue);
kusano 7d535a
		/*
kusano 7d535a
		 * Convert 16-bit colormap to 8-bit (unless it looks
kusano 7d535a
		 * like an old-style 8-bit colormap).
kusano 7d535a
		 */
kusano 7d535a
		if (checkcmap(in, 1<
kusano 7d535a
			int i;
kusano 7d535a
#define	CVT(x)		(((x) * 255L) / ((1L<<16)-1))
kusano 7d535a
			for (i = (1<<bitspersample)-1; i="">= 0; i--) {</bitspersample)-1;>
kusano 7d535a
				red[i] = CVT(red[i]);
kusano 7d535a
				green[i] = CVT(green[i]);
kusano 7d535a
				blue[i] = CVT(blue[i]);
kusano 7d535a
			}
kusano 7d535a
#undef CVT
kusano 7d535a
		}
kusano 7d535a
		inbuf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(in));
kusano 7d535a
		for (row = 0; row < h; row++) {
kusano 7d535a
			if (TIFFReadScanline(in, inbuf, row, 0) < 0)
kusano 7d535a
				break;
kusano 7d535a
			compresspalette(outbuf, inbuf, w, red, green, blue);
kusano 7d535a
			if (TIFFWriteScanline(out, outbuf, row, 0) < 0)
kusano 7d535a
				break;
kusano 7d535a
		}
kusano 7d535a
		break;
kusano 7d535a
	case pack(PHOTOMETRIC_RGB, PLANARCONFIG_CONTIG):
kusano 7d535a
		inbuf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(in));
kusano 7d535a
		for (row = 0; row < h; row++) {
kusano 7d535a
			if (TIFFReadScanline(in, inbuf, row, 0) < 0)
kusano 7d535a
				break;
kusano 7d535a
			compresscontig(outbuf, inbuf, w);
kusano 7d535a
			if (TIFFWriteScanline(out, outbuf, row, 0) < 0)
kusano 7d535a
				break;
kusano 7d535a
		}
kusano 7d535a
		break;
kusano 7d535a
	case pack(PHOTOMETRIC_RGB, PLANARCONFIG_SEPARATE):
kusano 7d535a
		rowsize = TIFFScanlineSize(in);
kusano 7d535a
		inbuf = (unsigned char *)_TIFFmalloc(3*rowsize);
kusano 7d535a
		for (row = 0; row < h; row++) {
kusano 7d535a
			for (s = 0; s < 3; s++)
kusano 7d535a
				if (TIFFReadScanline(in,
kusano 7d535a
				    inbuf+s*rowsize, row, s) < 0)
kusano 7d535a
					 return (-1);
kusano 7d535a
			compresssep(outbuf,
kusano 7d535a
			    inbuf, inbuf+rowsize, inbuf+2*rowsize, w);
kusano 7d535a
			if (TIFFWriteScanline(out, outbuf, row, 0) < 0)
kusano 7d535a
				break;
kusano 7d535a
		}
kusano 7d535a
		break;
kusano 7d535a
	}
kusano 7d535a
#undef pack
kusano 7d535a
	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_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_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_RESOLUTIONUNIT,	1, 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_INKSET,		1, TIFF_SHORT },
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
	{ TIFFTAG_EXTRASAMPLES,		(uint16) -1, TIFF_SHORT },
kusano 7d535a
	{ TIFFTAG_SMINSAMPLEVALUE,	1, TIFF_DOUBLE },
kusano 7d535a
	{ TIFFTAG_SMAXSAMPLEVALUE,	1, TIFF_DOUBLE },
kusano 7d535a
	{ TIFFTAG_STONITS,		1, TIFF_DOUBLE },
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: tiff2bw [options] input.tif output.tif",
kusano 7d535a
"where options are:",
kusano 7d535a
" -R %		use #% from red channel",
kusano 7d535a
" -G %		use #% from green channel",
kusano 7d535a
" -B %		use #% from blue channel",
kusano 7d535a
"",
kusano 7d535a
" -r #		make each strip have no more than # rows",
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 g3[:opts]	compress output with CCITT Group 3 encoding",
kusano 7d535a
" -c g4		compress output with CCITT Group 4 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
 */