roentgen b75cab
/* $Id: tif_zip.c,v 1.31 2011-01-06 16:00:23 fwarmerdam Exp $ */
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * Copyright (c) 1995-1997 Sam Leffler
roentgen b75cab
 * Copyright (c) 1995-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 "tiffiop.h"
roentgen b75cab
#ifdef ZIP_SUPPORT
roentgen b75cab
/*
roentgen b75cab
 * TIFF Library.
roentgen b75cab
 *
roentgen b75cab
 * ZIP (aka Deflate) Compression Support
roentgen b75cab
 *
roentgen b75cab
 * This file is simply an interface to the zlib library written by
roentgen b75cab
 * Jean-loup Gailly and Mark Adler.  You must use version 1.0 or later
roentgen b75cab
 * of the library: this code assumes the 1.0 API and also depends on
roentgen b75cab
 * the ability to write the zlib header multiple times (one per strip)
roentgen b75cab
 * which was not possible with versions prior to 0.95.  Note also that
roentgen b75cab
 * older versions of this codec avoided this bug by supressing the header
roentgen b75cab
 * entirely.  This means that files written with the old library cannot
roentgen b75cab
 * be read; they should be converted to a different compression scheme
roentgen b75cab
 * and then reconverted.
roentgen b75cab
 *
roentgen b75cab
 * The data format used by the zlib library is described in the files
roentgen b75cab
 * zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available in the
roentgen b75cab
 * directory ftp://ftp.uu.net/pub/archiving/zip/doc.  The library was
roentgen b75cab
 * last found at ftp://ftp.uu.net/pub/archiving/zip/zlib/zlib-0.99.tar.gz.
roentgen b75cab
 */
roentgen b75cab
#include "tif_predict.h"
roentgen b75cab
#include "zlib.h"
roentgen b75cab
roentgen b75cab
#include <stdio.h></stdio.h>
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * Sigh, ZLIB_VERSION is defined as a string so there's no
roentgen b75cab
 * way to do a proper check here.  Instead we guess based
roentgen b75cab
 * on the presence of #defines that were added between the
roentgen b75cab
 * 0.95 and 1.0 distributions.
roentgen b75cab
 */
roentgen b75cab
#if !defined(Z_NO_COMPRESSION) || !defined(Z_DEFLATED)
roentgen b75cab
#error "Antiquated ZLIB software; you must use version 1.0 or later"
roentgen b75cab
#endif
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * State block for each open TIFF
roentgen b75cab
 * file using ZIP compression/decompression.
roentgen b75cab
 */
roentgen b75cab
typedef struct {
roentgen b75cab
	TIFFPredictorState predict;
roentgen b75cab
        z_stream        stream;
roentgen b75cab
	int             zipquality;            /* compression level */
roentgen b75cab
	int             state;                 /* state flags */
roentgen b75cab
#define ZSTATE_INIT_DECODE 0x01
roentgen b75cab
#define ZSTATE_INIT_ENCODE 0x02
roentgen b75cab
roentgen b75cab
	TIFFVGetMethod  vgetparent;            /* super-class method */
roentgen b75cab
	TIFFVSetMethod  vsetparent;            /* super-class method */
roentgen b75cab
} ZIPState;
roentgen b75cab
roentgen b75cab
#define ZState(tif)             ((ZIPState*) (tif)->tif_data)
roentgen b75cab
#define DecoderState(tif)       ZState(tif)
roentgen b75cab
#define EncoderState(tif)       ZState(tif)
roentgen b75cab
roentgen b75cab
static int ZIPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s);
roentgen b75cab
static int ZIPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s);
roentgen b75cab
roentgen b75cab
static int
roentgen b75cab
ZIPFixupTags(TIFF* tif)
roentgen b75cab
{
roentgen b75cab
	(void) tif;
roentgen b75cab
	return (1);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
static int
roentgen b75cab
ZIPSetupDecode(TIFF* tif)
roentgen b75cab
{
roentgen b75cab
	static const char module[] = "ZIPSetupDecode";
roentgen b75cab
	ZIPState* sp = DecoderState(tif);
roentgen b75cab
roentgen b75cab
	assert(sp != NULL);
roentgen b75cab
        
roentgen b75cab
        /* if we were last encoding, terminate this mode */
roentgen b75cab
	if (sp->state & ZSTATE_INIT_ENCODE) {
roentgen b75cab
	    deflateEnd(&sp->stream);
roentgen b75cab
	    sp->state = 0;
roentgen b75cab
	}
roentgen b75cab
roentgen b75cab
	if (inflateInit(&sp->stream) != Z_OK) {
roentgen b75cab
		TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg);
roentgen b75cab
		return (0);
roentgen b75cab
	} else {
roentgen b75cab
		sp->state |= ZSTATE_INIT_DECODE;
roentgen b75cab
		return (1);
roentgen b75cab
	}
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * Setup state for decoding a strip.
roentgen b75cab
 */
roentgen b75cab
static int
roentgen b75cab
ZIPPreDecode(TIFF* tif, uint16 s)
roentgen b75cab
{
roentgen b75cab
	static const char module[] = "ZIPPreDecode";
roentgen b75cab
	ZIPState* sp = DecoderState(tif);
roentgen b75cab
roentgen b75cab
	(void) s;
roentgen b75cab
	assert(sp != NULL);
roentgen b75cab
roentgen b75cab
	if( (sp->state & ZSTATE_INIT_DECODE) == 0 )
roentgen b75cab
            tif->tif_setupdecode( tif );
roentgen b75cab
roentgen b75cab
	sp->stream.next_in = tif->tif_rawdata;
roentgen b75cab
	assert(sizeof(sp->stream.avail_in)==4);  /* if this assert gets raised,
roentgen b75cab
	    we need to simplify this code to reflect a ZLib that is likely updated
roentgen b75cab
	    to deal with 8byte memory sizes, though this code will respond
roentgen b75cab
	    apropriately even before we simplify it */
roentgen b75cab
	sp->stream.avail_in = (uInt) tif->tif_rawcc;
roentgen b75cab
	if ((tmsize_t)sp->stream.avail_in != tif->tif_rawcc)
roentgen b75cab
	{
roentgen b75cab
		TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size");
roentgen b75cab
		return (0);
roentgen b75cab
	}
roentgen b75cab
	return (inflateReset(&sp->stream) == Z_OK);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
static int
roentgen b75cab
ZIPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
roentgen b75cab
{
roentgen b75cab
	static const char module[] = "ZIPDecode";
roentgen b75cab
	ZIPState* sp = DecoderState(tif);
roentgen b75cab
roentgen b75cab
	(void) s;
roentgen b75cab
	assert(sp != NULL);
roentgen b75cab
	assert(sp->state == ZSTATE_INIT_DECODE);
roentgen b75cab
roentgen b75cab
        sp->stream.next_in = tif->tif_rawcp;
roentgen b75cab
	sp->stream.avail_in = (uInt) tif->tif_rawcc;
roentgen b75cab
        
roentgen b75cab
	sp->stream.next_out = op;
roentgen b75cab
	assert(sizeof(sp->stream.avail_out)==4);  /* if this assert gets raised,
roentgen b75cab
	    we need to simplify this code to reflect a ZLib that is likely updated
roentgen b75cab
	    to deal with 8byte memory sizes, though this code will respond
roentgen b75cab
	    apropriately even before we simplify it */
roentgen b75cab
	sp->stream.avail_out = (uInt) occ;
roentgen b75cab
	if ((tmsize_t)sp->stream.avail_out != occ)
roentgen b75cab
	{
roentgen b75cab
		TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size");
roentgen b75cab
		return (0);
roentgen b75cab
	}
roentgen b75cab
	do {
roentgen b75cab
		int state = inflate(&sp->stream, Z_PARTIAL_FLUSH);
roentgen b75cab
		if (state == Z_STREAM_END)
roentgen b75cab
			break;
roentgen b75cab
		if (state == Z_DATA_ERROR) {
roentgen b75cab
			TIFFErrorExt(tif->tif_clientdata, module,
roentgen b75cab
			    "Decoding error at scanline %lu, %s",
roentgen b75cab
			    (unsigned long) tif->tif_row, sp->stream.msg);
roentgen b75cab
			if (inflateSync(&sp->stream) != Z_OK)
roentgen b75cab
				return (0);
roentgen b75cab
			continue;
roentgen b75cab
		}
roentgen b75cab
		if (state != Z_OK) {
roentgen b75cab
			TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s",
roentgen b75cab
			    sp->stream.msg);
roentgen b75cab
			return (0);
roentgen b75cab
		}
roentgen b75cab
	} while (sp->stream.avail_out > 0);
roentgen b75cab
	if (sp->stream.avail_out != 0) {
roentgen b75cab
		TIFFErrorExt(tif->tif_clientdata, module,
roentgen b75cab
		    "Not enough data at scanline %lu (short " TIFF_UINT64_FORMAT " bytes)",
roentgen b75cab
		    (unsigned long) tif->tif_row, (TIFF_UINT64_T) sp->stream.avail_out);
roentgen b75cab
		return (0);
roentgen b75cab
	}
roentgen b75cab
roentgen b75cab
        tif->tif_rawcp = sp->stream.next_in;
roentgen b75cab
        tif->tif_rawcc = sp->stream.avail_in;
roentgen b75cab
roentgen b75cab
	return (1);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
static int
roentgen b75cab
ZIPSetupEncode(TIFF* tif)
roentgen b75cab
{
roentgen b75cab
	static const char module[] = "ZIPSetupEncode";
roentgen b75cab
	ZIPState* sp = EncoderState(tif);
roentgen b75cab
roentgen b75cab
	assert(sp != NULL);
roentgen b75cab
	if (sp->state & ZSTATE_INIT_DECODE) {
roentgen b75cab
		inflateEnd(&sp->stream);
roentgen b75cab
		sp->state = 0;
roentgen b75cab
	}
roentgen b75cab
roentgen b75cab
	if (deflateInit(&sp->stream, sp->zipquality) != Z_OK) {
roentgen b75cab
		TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg);
roentgen b75cab
		return (0);
roentgen b75cab
	} else {
roentgen b75cab
		sp->state |= ZSTATE_INIT_ENCODE;
roentgen b75cab
		return (1);
roentgen b75cab
	}
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * Reset encoding state at the start of a strip.
roentgen b75cab
 */
roentgen b75cab
static int
roentgen b75cab
ZIPPreEncode(TIFF* tif, uint16 s)
roentgen b75cab
{
roentgen b75cab
	static const char module[] = "ZIPPreEncode";
roentgen b75cab
	ZIPState *sp = EncoderState(tif);
roentgen b75cab
roentgen b75cab
	(void) s;
roentgen b75cab
	assert(sp != NULL);
roentgen b75cab
	if( sp->state != ZSTATE_INIT_ENCODE )
roentgen b75cab
            tif->tif_setupencode( tif );
roentgen b75cab
roentgen b75cab
	sp->stream.next_out = tif->tif_rawdata;
roentgen b75cab
	assert(sizeof(sp->stream.avail_out)==4);  /* if this assert gets raised,
roentgen b75cab
	    we need to simplify this code to reflect a ZLib that is likely updated
roentgen b75cab
	    to deal with 8byte memory sizes, though this code will respond
roentgen b75cab
	    apropriately even before we simplify it */
roentgen b75cab
	sp->stream.avail_out = tif->tif_rawdatasize;
roentgen b75cab
	if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize)
roentgen b75cab
	{
roentgen b75cab
		TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size");
roentgen b75cab
		return (0);
roentgen b75cab
	}
roentgen b75cab
	return (deflateReset(&sp->stream) == Z_OK);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * Encode a chunk of pixels.
roentgen b75cab
 */
roentgen b75cab
static int
roentgen b75cab
ZIPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
roentgen b75cab
{
roentgen b75cab
	static const char module[] = "ZIPEncode";
roentgen b75cab
	ZIPState *sp = EncoderState(tif);
roentgen b75cab
roentgen b75cab
	assert(sp != NULL);
roentgen b75cab
	assert(sp->state == ZSTATE_INIT_ENCODE);
roentgen b75cab
roentgen b75cab
	(void) s;
roentgen b75cab
	sp->stream.next_in = bp;
roentgen b75cab
	assert(sizeof(sp->stream.avail_in)==4);  /* if this assert gets raised,
roentgen b75cab
	    we need to simplify this code to reflect a ZLib that is likely updated
roentgen b75cab
	    to deal with 8byte memory sizes, though this code will respond
roentgen b75cab
	    apropriately even before we simplify it */
roentgen b75cab
	sp->stream.avail_in = (uInt) cc;
roentgen b75cab
	if ((tmsize_t)sp->stream.avail_in != cc)
roentgen b75cab
	{
roentgen b75cab
		TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size");
roentgen b75cab
		return (0);
roentgen b75cab
	}
roentgen b75cab
	do {
roentgen b75cab
		if (deflate(&sp->stream, Z_NO_FLUSH) != Z_OK) {
roentgen b75cab
			TIFFErrorExt(tif->tif_clientdata, module, "Encoder error: %s",
roentgen b75cab
			    sp->stream.msg);
roentgen b75cab
			return (0);
roentgen b75cab
		}
roentgen b75cab
		if (sp->stream.avail_out == 0) {
roentgen b75cab
			tif->tif_rawcc = tif->tif_rawdatasize;
roentgen b75cab
			TIFFFlushData1(tif);
roentgen b75cab
			sp->stream.next_out = tif->tif_rawdata;
roentgen b75cab
			sp->stream.avail_out = (uInt) tif->tif_rawdatasize;  /* this is a safe typecast, as check is made already in ZIPPreEncode */
roentgen b75cab
		}
roentgen b75cab
	} while (sp->stream.avail_in > 0);
roentgen b75cab
	return (1);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * Finish off an encoded strip by flushing the last
roentgen b75cab
 * string and tacking on an End Of Information code.
roentgen b75cab
 */
roentgen b75cab
static int
roentgen b75cab
ZIPPostEncode(TIFF* tif)
roentgen b75cab
{
roentgen b75cab
	static const char module[] = "ZIPPostEncode";
roentgen b75cab
	ZIPState *sp = EncoderState(tif);
roentgen b75cab
	int state;
roentgen b75cab
roentgen b75cab
	sp->stream.avail_in = 0;
roentgen b75cab
	do {
roentgen b75cab
		state = deflate(&sp->stream, Z_FINISH);
roentgen b75cab
		switch (state) {
roentgen b75cab
		case Z_STREAM_END:
roentgen b75cab
		case Z_OK:
roentgen b75cab
			if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize)
roentgen b75cab
			{
roentgen b75cab
				tif->tif_rawcc =  tif->tif_rawdatasize - sp->stream.avail_out;
roentgen b75cab
				TIFFFlushData1(tif);
roentgen b75cab
				sp->stream.next_out = tif->tif_rawdata;
roentgen b75cab
				sp->stream.avail_out = (uInt) tif->tif_rawdatasize;  /* this is a safe typecast, as check is made already in ZIPPreEncode */
roentgen b75cab
			}
roentgen b75cab
			break;
roentgen b75cab
		default:
roentgen b75cab
			TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s",
roentgen b75cab
			    sp->stream.msg);
roentgen b75cab
			return (0);
roentgen b75cab
		}
roentgen b75cab
	} while (state != Z_STREAM_END);
roentgen b75cab
	return (1);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
static void
roentgen b75cab
ZIPCleanup(TIFF* tif)
roentgen b75cab
{
roentgen b75cab
	ZIPState* sp = ZState(tif);
roentgen b75cab
roentgen b75cab
	assert(sp != 0);
roentgen b75cab
roentgen b75cab
	(void)TIFFPredictorCleanup(tif);
roentgen b75cab
roentgen b75cab
	tif->tif_tagmethods.vgetfield = sp->vgetparent;
roentgen b75cab
	tif->tif_tagmethods.vsetfield = sp->vsetparent;
roentgen b75cab
roentgen b75cab
	if (sp->state & ZSTATE_INIT_ENCODE) {
roentgen b75cab
		deflateEnd(&sp->stream);
roentgen b75cab
		sp->state = 0;
roentgen b75cab
	} else if( sp->state & ZSTATE_INIT_DECODE) {
roentgen b75cab
		inflateEnd(&sp->stream);
roentgen b75cab
		sp->state = 0;
roentgen b75cab
	}
roentgen b75cab
	_TIFFfree(sp);
roentgen b75cab
	tif->tif_data = NULL;
roentgen b75cab
roentgen b75cab
	_TIFFSetDefaultCompressionState(tif);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
static int
roentgen b75cab
ZIPVSetField(TIFF* tif, uint32 tag, va_list ap)
roentgen b75cab
{
roentgen b75cab
	static const char module[] = "ZIPVSetField";
roentgen b75cab
	ZIPState* sp = ZState(tif);
roentgen b75cab
roentgen b75cab
	switch (tag) {
roentgen b75cab
	case TIFFTAG_ZIPQUALITY:
roentgen b75cab
		sp->zipquality = (int) va_arg(ap, int);
roentgen b75cab
		if ( sp->state&ZSTATE_INIT_ENCODE ) {
roentgen b75cab
			if (deflateParams(&sp->stream,
roentgen b75cab
			    sp->zipquality, Z_DEFAULT_STRATEGY) != Z_OK) {
roentgen b75cab
				TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s",
roentgen b75cab
				    sp->stream.msg);
roentgen b75cab
				return (0);
roentgen b75cab
			}
roentgen b75cab
		}
roentgen b75cab
		return (1);
roentgen b75cab
	default:
roentgen b75cab
		return (*sp->vsetparent)(tif, tag, ap);
roentgen b75cab
	}
roentgen b75cab
	/*NOTREACHED*/
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
static int
roentgen b75cab
ZIPVGetField(TIFF* tif, uint32 tag, va_list ap)
roentgen b75cab
{
roentgen b75cab
	ZIPState* sp = ZState(tif);
roentgen b75cab
roentgen b75cab
	switch (tag) {
roentgen b75cab
	case TIFFTAG_ZIPQUALITY:
roentgen b75cab
		*va_arg(ap, int*) = sp->zipquality;
roentgen b75cab
		break;
roentgen b75cab
	default:
roentgen b75cab
		return (*sp->vgetparent)(tif, tag, ap);
roentgen b75cab
	}
roentgen b75cab
	return (1);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
static const TIFFField zipFields[] = {
roentgen b75cab
    { TIFFTAG_ZIPQUALITY, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "", NULL },
roentgen b75cab
};
roentgen b75cab
roentgen b75cab
int
roentgen b75cab
TIFFInitZIP(TIFF* tif, int scheme)
roentgen b75cab
{
roentgen b75cab
	static const char module[] = "TIFFInitZIP";
roentgen b75cab
	ZIPState* sp;
roentgen b75cab
roentgen b75cab
	assert( (scheme == COMPRESSION_DEFLATE)
roentgen b75cab
		|| (scheme == COMPRESSION_ADOBE_DEFLATE));
roentgen b75cab
roentgen b75cab
	/*
roentgen b75cab
	 * Merge codec-specific tag information.
roentgen b75cab
	 */
roentgen b75cab
	if (!_TIFFMergeFields(tif, zipFields, TIFFArrayCount(zipFields))) {
roentgen b75cab
		TIFFErrorExt(tif->tif_clientdata, module,
roentgen b75cab
			     "Merging Deflate codec-specific tags failed");
roentgen b75cab
		return 0;
roentgen b75cab
	}
roentgen b75cab
roentgen b75cab
	/*
roentgen b75cab
	 * Allocate state block so tag methods have storage to record values.
roentgen b75cab
	 */
roentgen b75cab
	tif->tif_data = (uint8*) _TIFFmalloc(sizeof (ZIPState));
roentgen b75cab
	if (tif->tif_data == NULL)
roentgen b75cab
		goto bad;
roentgen b75cab
	sp = ZState(tif);
roentgen b75cab
	sp->stream.zalloc = NULL;
roentgen b75cab
	sp->stream.zfree = NULL;
roentgen b75cab
	sp->stream.opaque = NULL;
roentgen b75cab
	sp->stream.data_type = Z_BINARY;
roentgen b75cab
roentgen b75cab
	/*
roentgen b75cab
	 * Override parent get/set field methods.
roentgen b75cab
	 */
roentgen b75cab
	sp->vgetparent = tif->tif_tagmethods.vgetfield;
roentgen b75cab
	tif->tif_tagmethods.vgetfield = ZIPVGetField; /* hook for codec tags */
roentgen b75cab
	sp->vsetparent = tif->tif_tagmethods.vsetfield;
roentgen b75cab
	tif->tif_tagmethods.vsetfield = ZIPVSetField; /* hook for codec tags */
roentgen b75cab
roentgen b75cab
	/* Default values for codec-specific fields */
roentgen b75cab
	sp->zipquality = Z_DEFAULT_COMPRESSION;	/* default comp. level */
roentgen b75cab
	sp->state = 0;
roentgen b75cab
roentgen b75cab
	/*
roentgen b75cab
	 * Install codec methods.
roentgen b75cab
	 */
roentgen b75cab
	tif->tif_fixuptags = ZIPFixupTags; 
roentgen b75cab
	tif->tif_setupdecode = ZIPSetupDecode;
roentgen b75cab
	tif->tif_predecode = ZIPPreDecode;
roentgen b75cab
	tif->tif_decoderow = ZIPDecode;
roentgen b75cab
	tif->tif_decodestrip = ZIPDecode;
roentgen b75cab
	tif->tif_decodetile = ZIPDecode;  
roentgen b75cab
	tif->tif_setupencode = ZIPSetupEncode;
roentgen b75cab
	tif->tif_preencode = ZIPPreEncode;
roentgen b75cab
	tif->tif_postencode = ZIPPostEncode;
roentgen b75cab
	tif->tif_encoderow = ZIPEncode;
roentgen b75cab
	tif->tif_encodestrip = ZIPEncode;
roentgen b75cab
	tif->tif_encodetile = ZIPEncode;
roentgen b75cab
	tif->tif_cleanup = ZIPCleanup;
roentgen b75cab
	/*
roentgen b75cab
	 * Setup predictor setup.
roentgen b75cab
	 */
roentgen b75cab
	(void) TIFFPredictorInit(tif);
roentgen b75cab
	return (1);
roentgen b75cab
bad:
roentgen b75cab
	TIFFErrorExt(tif->tif_clientdata, module,
roentgen b75cab
		     "No space for ZIP state block");
roentgen b75cab
	return (0);
roentgen b75cab
}
roentgen b75cab
#endif /* ZIP_SUPORT */
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
 */