Blame libtiff/tif_zip.c

Packit 7838c8
/* $Id: tif_zip.c,v 1.37 2017-05-10 15:21:16 erouault Exp $ */
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Copyright (c) 1995-1997 Sam Leffler
Packit 7838c8
 * Copyright (c) 1995-1997 Silicon Graphics, Inc.
Packit 7838c8
 *
Packit 7838c8
 * Permission to use, copy, modify, distribute, and sell this software and 
Packit 7838c8
 * its documentation for any purpose is hereby granted without fee, provided
Packit 7838c8
 * that (i) the above copyright notices and this permission notice appear in
Packit 7838c8
 * all copies of the software and related documentation, and (ii) the names of
Packit 7838c8
 * Sam Leffler and Silicon Graphics may not be used in any advertising or
Packit 7838c8
 * publicity relating to the software without the specific, prior written
Packit 7838c8
 * permission of Sam Leffler and Silicon Graphics.
Packit 7838c8
 * 
Packit 7838c8
 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
Packit 7838c8
 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
Packit 7838c8
 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
Packit 7838c8
 * 
Packit 7838c8
 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
Packit 7838c8
 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
Packit 7838c8
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
Packit 7838c8
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
Packit 7838c8
 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
Packit 7838c8
 * OF THIS SOFTWARE.
Packit 7838c8
 */
Packit 7838c8
Packit 7838c8
#include "tiffiop.h"
Packit 7838c8
#ifdef ZIP_SUPPORT
Packit 7838c8
/*
Packit 7838c8
 * TIFF Library.
Packit 7838c8
 *
Packit 7838c8
 * ZIP (aka Deflate) Compression Support
Packit 7838c8
 *
Packit 7838c8
 * This file is simply an interface to the zlib library written by
Packit 7838c8
 * Jean-loup Gailly and Mark Adler.  You must use version 1.0 or later
Packit 7838c8
 * of the library: this code assumes the 1.0 API and also depends on
Packit 7838c8
 * the ability to write the zlib header multiple times (one per strip)
Packit 7838c8
 * which was not possible with versions prior to 0.95.  Note also that
Packit 7838c8
 * older versions of this codec avoided this bug by suppressing the header
Packit 7838c8
 * entirely.  This means that files written with the old library cannot
Packit 7838c8
 * be read; they should be converted to a different compression scheme
Packit 7838c8
 * and then reconverted.
Packit 7838c8
 *
Packit 7838c8
 * The data format used by the zlib library is described in the files
Packit 7838c8
 * zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available in the
Packit 7838c8
 * directory ftp://ftp.uu.net/pub/archiving/zip/doc.  The library was
Packit 7838c8
 * last found at ftp://ftp.uu.net/pub/archiving/zip/zlib/zlib-0.99.tar.gz.
Packit 7838c8
 */
Packit 7838c8
#include "tif_predict.h"
Packit 7838c8
#include "zlib.h"
Packit 7838c8
Packit 7838c8
#include <stdio.h>
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Sigh, ZLIB_VERSION is defined as a string so there's no
Packit 7838c8
 * way to do a proper check here.  Instead we guess based
Packit 7838c8
 * on the presence of #defines that were added between the
Packit 7838c8
 * 0.95 and 1.0 distributions.
Packit 7838c8
 */
Packit 7838c8
#if !defined(Z_NO_COMPRESSION) || !defined(Z_DEFLATED)
Packit 7838c8
#error "Antiquated ZLIB software; you must use version 1.0 or later"
Packit 7838c8
#endif
Packit 7838c8
Packit 7838c8
#define SAFE_MSG(sp)   ((sp)->stream.msg == NULL ? "" : (sp)->stream.msg)
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * State block for each open TIFF
Packit 7838c8
 * file using ZIP compression/decompression.
Packit 7838c8
 */
Packit 7838c8
typedef struct {
Packit 7838c8
	TIFFPredictorState predict;
Packit 7838c8
        z_stream        stream;
Packit 7838c8
	int             zipquality;            /* compression level */
Packit 7838c8
	int             state;                 /* state flags */
Packit 7838c8
#define ZSTATE_INIT_DECODE 0x01
Packit 7838c8
#define ZSTATE_INIT_ENCODE 0x02
Packit 7838c8
Packit 7838c8
	TIFFVGetMethod  vgetparent;            /* super-class method */
Packit 7838c8
	TIFFVSetMethod  vsetparent;            /* super-class method */
Packit 7838c8
} ZIPState;
Packit 7838c8
Packit 7838c8
#define ZState(tif)             ((ZIPState*) (tif)->tif_data)
Packit 7838c8
#define DecoderState(tif)       ZState(tif)
Packit 7838c8
#define EncoderState(tif)       ZState(tif)
Packit 7838c8
Packit 7838c8
static int ZIPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s);
Packit 7838c8
static int ZIPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s);
Packit 7838c8
Packit 7838c8
static int
Packit 7838c8
ZIPFixupTags(TIFF* tif)
Packit 7838c8
{
Packit 7838c8
	(void) tif;
Packit 7838c8
	return (1);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
static int
Packit 7838c8
ZIPSetupDecode(TIFF* tif)
Packit 7838c8
{
Packit 7838c8
	static const char module[] = "ZIPSetupDecode";
Packit 7838c8
	ZIPState* sp = DecoderState(tif);
Packit 7838c8
Packit 7838c8
	assert(sp != NULL);
Packit 7838c8
        
Packit 7838c8
        /* if we were last encoding, terminate this mode */
Packit 7838c8
	if (sp->state & ZSTATE_INIT_ENCODE) {
Packit 7838c8
	    deflateEnd(&sp->stream);
Packit 7838c8
	    sp->state = 0;
Packit 7838c8
	}
Packit 7838c8
Packit 7838c8
	/* This function can possibly be called several times by */
Packit 7838c8
	/* PredictorSetupDecode() if this function succeeds but */
Packit 7838c8
	/* PredictorSetup() fails */
Packit 7838c8
	if ((sp->state & ZSTATE_INIT_DECODE) == 0 &&
Packit 7838c8
	    inflateInit(&sp->stream) != Z_OK) {
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module, "%s", SAFE_MSG(sp));
Packit 7838c8
		return (0);
Packit 7838c8
	} else {
Packit 7838c8
		sp->state |= ZSTATE_INIT_DECODE;
Packit 7838c8
		return (1);
Packit 7838c8
	}
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Setup state for decoding a strip.
Packit 7838c8
 */
Packit 7838c8
static int
Packit 7838c8
ZIPPreDecode(TIFF* tif, uint16 s)
Packit 7838c8
{
Packit 7838c8
	static const char module[] = "ZIPPreDecode";
Packit 7838c8
	ZIPState* sp = DecoderState(tif);
Packit 7838c8
Packit 7838c8
	(void) s;
Packit 7838c8
	assert(sp != NULL);
Packit 7838c8
Packit 7838c8
	if( (sp->state & ZSTATE_INIT_DECODE) == 0 )
Packit 7838c8
            tif->tif_setupdecode( tif );
Packit 7838c8
Packit 7838c8
	sp->stream.next_in = tif->tif_rawdata;
Packit 7838c8
	assert(sizeof(sp->stream.avail_in)==4);  /* if this assert gets raised,
Packit 7838c8
	    we need to simplify this code to reflect a ZLib that is likely updated
Packit 7838c8
	    to deal with 8byte memory sizes, though this code will respond
Packit 7838c8
	    appropriately even before we simplify it */
Packit 7838c8
	sp->stream.avail_in = (uInt) tif->tif_rawcc;
Packit 7838c8
	if ((tmsize_t)sp->stream.avail_in != tif->tif_rawcc)
Packit 7838c8
	{
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size");
Packit 7838c8
		return (0);
Packit 7838c8
	}
Packit 7838c8
	return (inflateReset(&sp->stream) == Z_OK);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
static int
Packit 7838c8
ZIPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
Packit 7838c8
{
Packit 7838c8
	static const char module[] = "ZIPDecode";
Packit 7838c8
	ZIPState* sp = DecoderState(tif);
Packit 7838c8
Packit 7838c8
	(void) s;
Packit 7838c8
	assert(sp != NULL);
Packit 7838c8
	assert(sp->state == ZSTATE_INIT_DECODE);
Packit 7838c8
Packit 7838c8
        sp->stream.next_in = tif->tif_rawcp;
Packit 7838c8
	sp->stream.avail_in = (uInt) tif->tif_rawcc;
Packit 7838c8
        
Packit 7838c8
	sp->stream.next_out = op;
Packit 7838c8
	assert(sizeof(sp->stream.avail_out)==4);  /* if this assert gets raised,
Packit 7838c8
	    we need to simplify this code to reflect a ZLib that is likely updated
Packit 7838c8
	    to deal with 8byte memory sizes, though this code will respond
Packit 7838c8
	    appropriately even before we simplify it */
Packit 7838c8
	sp->stream.avail_out = (uInt) occ;
Packit 7838c8
	if ((tmsize_t)sp->stream.avail_out != occ)
Packit 7838c8
	{
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size");
Packit 7838c8
		return (0);
Packit 7838c8
	}
Packit 7838c8
	do {
Packit 7838c8
		int state = inflate(&sp->stream, Z_PARTIAL_FLUSH);
Packit 7838c8
		if (state == Z_STREAM_END)
Packit 7838c8
			break;
Packit 7838c8
		if (state == Z_DATA_ERROR) {
Packit 7838c8
			TIFFErrorExt(tif->tif_clientdata, module,
Packit 7838c8
			    "Decoding error at scanline %lu, %s",
Packit 7838c8
			     (unsigned long) tif->tif_row, SAFE_MSG(sp));
Packit 7838c8
			if (inflateSync(&sp->stream) != Z_OK)
Packit 7838c8
				return (0);
Packit 7838c8
			continue;
Packit 7838c8
		}
Packit 7838c8
		if (state != Z_OK) {
Packit 7838c8
			TIFFErrorExt(tif->tif_clientdata, module, 
Packit 7838c8
				     "ZLib error: %s", SAFE_MSG(sp));
Packit 7838c8
			return (0);
Packit 7838c8
		}
Packit 7838c8
	} while (sp->stream.avail_out > 0);
Packit 7838c8
	if (sp->stream.avail_out != 0) {
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module,
Packit 7838c8
		    "Not enough data at scanline %lu (short " TIFF_UINT64_FORMAT " bytes)",
Packit 7838c8
		    (unsigned long) tif->tif_row, (TIFF_UINT64_T) sp->stream.avail_out);
Packit 7838c8
		return (0);
Packit 7838c8
	}
Packit 7838c8
Packit 7838c8
        tif->tif_rawcp = sp->stream.next_in;
Packit 7838c8
        tif->tif_rawcc = sp->stream.avail_in;
Packit 7838c8
Packit 7838c8
	return (1);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
static int
Packit 7838c8
ZIPSetupEncode(TIFF* tif)
Packit 7838c8
{
Packit 7838c8
	static const char module[] = "ZIPSetupEncode";
Packit 7838c8
	ZIPState* sp = EncoderState(tif);
Packit 7838c8
Packit 7838c8
	assert(sp != NULL);
Packit 7838c8
	if (sp->state & ZSTATE_INIT_DECODE) {
Packit 7838c8
		inflateEnd(&sp->stream);
Packit 7838c8
		sp->state = 0;
Packit 7838c8
	}
Packit 7838c8
Packit 7838c8
	if (deflateInit(&sp->stream, sp->zipquality) != Z_OK) {
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module, "%s", SAFE_MSG(sp));
Packit 7838c8
		return (0);
Packit 7838c8
	} else {
Packit 7838c8
		sp->state |= ZSTATE_INIT_ENCODE;
Packit 7838c8
		return (1);
Packit 7838c8
	}
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Reset encoding state at the start of a strip.
Packit 7838c8
 */
Packit 7838c8
static int
Packit 7838c8
ZIPPreEncode(TIFF* tif, uint16 s)
Packit 7838c8
{
Packit 7838c8
	static const char module[] = "ZIPPreEncode";
Packit 7838c8
	ZIPState *sp = EncoderState(tif);
Packit 7838c8
Packit 7838c8
	(void) s;
Packit 7838c8
	assert(sp != NULL);
Packit 7838c8
	if( sp->state != ZSTATE_INIT_ENCODE )
Packit 7838c8
            tif->tif_setupencode( tif );
Packit 7838c8
Packit 7838c8
	sp->stream.next_out = tif->tif_rawdata;
Packit 7838c8
	assert(sizeof(sp->stream.avail_out)==4);  /* if this assert gets raised,
Packit 7838c8
	    we need to simplify this code to reflect a ZLib that is likely updated
Packit 7838c8
	    to deal with 8byte memory sizes, though this code will respond
Packit 7838c8
	    appropriately even before we simplify it */
Packit 7838c8
	sp->stream.avail_out = (uInt)tif->tif_rawdatasize;
Packit 7838c8
	if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize)
Packit 7838c8
	{
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size");
Packit 7838c8
		return (0);
Packit 7838c8
	}
Packit 7838c8
	return (deflateReset(&sp->stream) == Z_OK);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Encode a chunk of pixels.
Packit 7838c8
 */
Packit 7838c8
static int
Packit 7838c8
ZIPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
Packit 7838c8
{
Packit 7838c8
	static const char module[] = "ZIPEncode";
Packit 7838c8
	ZIPState *sp = EncoderState(tif);
Packit 7838c8
Packit 7838c8
	assert(sp != NULL);
Packit 7838c8
	assert(sp->state == ZSTATE_INIT_ENCODE);
Packit 7838c8
Packit 7838c8
	(void) s;
Packit 7838c8
	sp->stream.next_in = bp;
Packit 7838c8
	assert(sizeof(sp->stream.avail_in)==4);  /* if this assert gets raised,
Packit 7838c8
	    we need to simplify this code to reflect a ZLib that is likely updated
Packit 7838c8
	    to deal with 8byte memory sizes, though this code will respond
Packit 7838c8
	    appropriately even before we simplify it */
Packit 7838c8
	sp->stream.avail_in = (uInt) cc;
Packit 7838c8
	if ((tmsize_t)sp->stream.avail_in != cc)
Packit 7838c8
	{
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size");
Packit 7838c8
		return (0);
Packit 7838c8
	}
Packit 7838c8
	do {
Packit 7838c8
		if (deflate(&sp->stream, Z_NO_FLUSH) != Z_OK) {
Packit 7838c8
			TIFFErrorExt(tif->tif_clientdata, module, 
Packit 7838c8
				     "Encoder error: %s",
Packit 7838c8
				     SAFE_MSG(sp));
Packit 7838c8
			return (0);
Packit 7838c8
		}
Packit 7838c8
		if (sp->stream.avail_out == 0) {
Packit 7838c8
			tif->tif_rawcc = tif->tif_rawdatasize;
Packit 7838c8
			TIFFFlushData1(tif);
Packit 7838c8
			sp->stream.next_out = tif->tif_rawdata;
Packit 7838c8
			sp->stream.avail_out = (uInt) tif->tif_rawdatasize;  /* this is a safe typecast, as check is made already in ZIPPreEncode */
Packit 7838c8
		}
Packit 7838c8
	} while (sp->stream.avail_in > 0);
Packit 7838c8
	return (1);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Finish off an encoded strip by flushing the last
Packit 7838c8
 * string and tacking on an End Of Information code.
Packit 7838c8
 */
Packit 7838c8
static int
Packit 7838c8
ZIPPostEncode(TIFF* tif)
Packit 7838c8
{
Packit 7838c8
	static const char module[] = "ZIPPostEncode";
Packit 7838c8
	ZIPState *sp = EncoderState(tif);
Packit 7838c8
	int state;
Packit 7838c8
Packit 7838c8
	sp->stream.avail_in = 0;
Packit 7838c8
	do {
Packit 7838c8
		state = deflate(&sp->stream, Z_FINISH);
Packit 7838c8
		switch (state) {
Packit 7838c8
		case Z_STREAM_END:
Packit 7838c8
		case Z_OK:
Packit 7838c8
			if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize)
Packit 7838c8
			{
Packit 7838c8
				tif->tif_rawcc =  tif->tif_rawdatasize - sp->stream.avail_out;
Packit 7838c8
				TIFFFlushData1(tif);
Packit 7838c8
				sp->stream.next_out = tif->tif_rawdata;
Packit 7838c8
				sp->stream.avail_out = (uInt) tif->tif_rawdatasize;  /* this is a safe typecast, as check is made already in ZIPPreEncode */
Packit 7838c8
			}
Packit 7838c8
			break;
Packit 7838c8
		default:
Packit 7838c8
			TIFFErrorExt(tif->tif_clientdata, module, 
Packit 7838c8
				     "ZLib error: %s", SAFE_MSG(sp));
Packit 7838c8
			return (0);
Packit 7838c8
		}
Packit 7838c8
	} while (state != Z_STREAM_END);
Packit 7838c8
	return (1);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
static void
Packit 7838c8
ZIPCleanup(TIFF* tif)
Packit 7838c8
{
Packit 7838c8
	ZIPState* sp = ZState(tif);
Packit 7838c8
Packit 7838c8
	assert(sp != 0);
Packit 7838c8
Packit 7838c8
	(void)TIFFPredictorCleanup(tif);
Packit 7838c8
Packit 7838c8
	tif->tif_tagmethods.vgetfield = sp->vgetparent;
Packit 7838c8
	tif->tif_tagmethods.vsetfield = sp->vsetparent;
Packit 7838c8
Packit 7838c8
	if (sp->state & ZSTATE_INIT_ENCODE) {
Packit 7838c8
		deflateEnd(&sp->stream);
Packit 7838c8
		sp->state = 0;
Packit 7838c8
	} else if( sp->state & ZSTATE_INIT_DECODE) {
Packit 7838c8
		inflateEnd(&sp->stream);
Packit 7838c8
		sp->state = 0;
Packit 7838c8
	}
Packit 7838c8
	_TIFFfree(sp);
Packit 7838c8
	tif->tif_data = NULL;
Packit 7838c8
Packit 7838c8
	_TIFFSetDefaultCompressionState(tif);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
static int
Packit 7838c8
ZIPVSetField(TIFF* tif, uint32 tag, va_list ap)
Packit 7838c8
{
Packit 7838c8
	static const char module[] = "ZIPVSetField";
Packit 7838c8
	ZIPState* sp = ZState(tif);
Packit 7838c8
Packit 7838c8
	switch (tag) {
Packit 7838c8
	case TIFFTAG_ZIPQUALITY:
Packit 7838c8
		sp->zipquality = (int) va_arg(ap, int);
Packit 7838c8
		if ( sp->state&ZSTATE_INIT_ENCODE ) {
Packit 7838c8
			if (deflateParams(&sp->stream,
Packit 7838c8
			    sp->zipquality, Z_DEFAULT_STRATEGY) != Z_OK) {
Packit 7838c8
				TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s",
Packit 7838c8
					     SAFE_MSG(sp));
Packit 7838c8
				return (0);
Packit 7838c8
			}
Packit 7838c8
		}
Packit 7838c8
		return (1);
Packit 7838c8
	default:
Packit 7838c8
		return (*sp->vsetparent)(tif, tag, ap);
Packit 7838c8
	}
Packit 7838c8
	/*NOTREACHED*/
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
static int
Packit 7838c8
ZIPVGetField(TIFF* tif, uint32 tag, va_list ap)
Packit 7838c8
{
Packit 7838c8
	ZIPState* sp = ZState(tif);
Packit 7838c8
Packit 7838c8
	switch (tag) {
Packit 7838c8
	case TIFFTAG_ZIPQUALITY:
Packit 7838c8
		*va_arg(ap, int*) = sp->zipquality;
Packit 7838c8
		break;
Packit 7838c8
	default:
Packit 7838c8
		return (*sp->vgetparent)(tif, tag, ap);
Packit 7838c8
	}
Packit 7838c8
	return (1);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
static const TIFFField zipFields[] = {
Packit 7838c8
    { TIFFTAG_ZIPQUALITY, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "", NULL },
Packit 7838c8
};
Packit 7838c8
Packit 7838c8
int
Packit 7838c8
TIFFInitZIP(TIFF* tif, int scheme)
Packit 7838c8
{
Packit 7838c8
	static const char module[] = "TIFFInitZIP";
Packit 7838c8
	ZIPState* sp;
Packit 7838c8
Packit 7838c8
	assert( (scheme == COMPRESSION_DEFLATE)
Packit 7838c8
		|| (scheme == COMPRESSION_ADOBE_DEFLATE));
Packit 7838c8
Packit 7838c8
	/*
Packit 7838c8
	 * Merge codec-specific tag information.
Packit 7838c8
	 */
Packit 7838c8
	if (!_TIFFMergeFields(tif, zipFields, TIFFArrayCount(zipFields))) {
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module,
Packit 7838c8
			     "Merging Deflate codec-specific tags failed");
Packit 7838c8
		return 0;
Packit 7838c8
	}
Packit 7838c8
Packit 7838c8
	/*
Packit 7838c8
	 * Allocate state block so tag methods have storage to record values.
Packit 7838c8
	 */
Packit 7838c8
	tif->tif_data = (uint8*) _TIFFmalloc(sizeof (ZIPState));
Packit 7838c8
	if (tif->tif_data == NULL)
Packit 7838c8
		goto bad;
Packit 7838c8
	sp = ZState(tif);
Packit 7838c8
	sp->stream.zalloc = NULL;
Packit 7838c8
	sp->stream.zfree = NULL;
Packit 7838c8
	sp->stream.opaque = NULL;
Packit 7838c8
	sp->stream.data_type = Z_BINARY;
Packit 7838c8
Packit 7838c8
	/*
Packit 7838c8
	 * Override parent get/set field methods.
Packit 7838c8
	 */
Packit 7838c8
	sp->vgetparent = tif->tif_tagmethods.vgetfield;
Packit 7838c8
	tif->tif_tagmethods.vgetfield = ZIPVGetField; /* hook for codec tags */
Packit 7838c8
	sp->vsetparent = tif->tif_tagmethods.vsetfield;
Packit 7838c8
	tif->tif_tagmethods.vsetfield = ZIPVSetField; /* hook for codec tags */
Packit 7838c8
Packit 7838c8
	/* Default values for codec-specific fields */
Packit 7838c8
	sp->zipquality = Z_DEFAULT_COMPRESSION;	/* default comp. level */
Packit 7838c8
	sp->state = 0;
Packit 7838c8
Packit 7838c8
	/*
Packit 7838c8
	 * Install codec methods.
Packit 7838c8
	 */
Packit 7838c8
	tif->tif_fixuptags = ZIPFixupTags; 
Packit 7838c8
	tif->tif_setupdecode = ZIPSetupDecode;
Packit 7838c8
	tif->tif_predecode = ZIPPreDecode;
Packit 7838c8
	tif->tif_decoderow = ZIPDecode;
Packit 7838c8
	tif->tif_decodestrip = ZIPDecode;
Packit 7838c8
	tif->tif_decodetile = ZIPDecode;  
Packit 7838c8
	tif->tif_setupencode = ZIPSetupEncode;
Packit 7838c8
	tif->tif_preencode = ZIPPreEncode;
Packit 7838c8
	tif->tif_postencode = ZIPPostEncode;
Packit 7838c8
	tif->tif_encoderow = ZIPEncode;
Packit 7838c8
	tif->tif_encodestrip = ZIPEncode;
Packit 7838c8
	tif->tif_encodetile = ZIPEncode;
Packit 7838c8
	tif->tif_cleanup = ZIPCleanup;
Packit 7838c8
	/*
Packit 7838c8
	 * Setup predictor setup.
Packit 7838c8
	 */
Packit 7838c8
	(void) TIFFPredictorInit(tif);
Packit 7838c8
	return (1);
Packit 7838c8
bad:
Packit 7838c8
	TIFFErrorExt(tif->tif_clientdata, module,
Packit 7838c8
		     "No space for ZIP state block");
Packit 7838c8
	return (0);
Packit 7838c8
}
Packit 7838c8
#endif /* ZIP_SUPPORT */
Packit 7838c8
Packit 7838c8
/* vim: set ts=8 sts=8 sw=8 noet: */
Packit 7838c8
/*
Packit 7838c8
 * Local Variables:
Packit 7838c8
 * mode: c
Packit 7838c8
 * c-basic-offset: 8
Packit 7838c8
 * fill-column: 78
Packit 7838c8
 * End:
Packit 7838c8
 */