summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/libtiff/libtiff/tif_lzw.c
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@digia.com>2013-03-04 10:22:52 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-04-05 11:07:49 +0200
commit8b2b1b0f63d258ec5ea753cd44531731c0bdece8 (patch)
tree2c651bf7ba4d34ff8314d180eec11c7a7c3bbd52 /src/3rdparty/libtiff/libtiff/tif_lzw.c
parent7a10649ea7b8963d66c14a0391b7356fc7d9ce9d (diff)
Upgrading libtiff: Adding clean copy of libtiff 4.0.3
This commit removes the previous version of the bundled libtiff (3.9.2), as well as all local modifications to it. It adds an unmodified copy of the official libtiff source distribution, except that various extraneous files have been removed, as usual. The patches required to build it in Qt will follow in separate commit(s). Task-number: QTBUG-25409 Change-Id: If47e02c25ce1a2b3b47eff94a875e2abea0c7e1c Reviewed-by: aavit <eirik.aavitsland@digia.com>
Diffstat (limited to 'src/3rdparty/libtiff/libtiff/tif_lzw.c')
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_lzw.c359
1 files changed, 202 insertions, 157 deletions
diff --git a/src/3rdparty/libtiff/libtiff/tif_lzw.c b/src/3rdparty/libtiff/libtiff/tif_lzw.c
index bc4dac6..fd9c7a0 100644
--- a/src/3rdparty/libtiff/libtiff/tif_lzw.c
+++ b/src/3rdparty/libtiff/libtiff/tif_lzw.c
@@ -1,4 +1,4 @@
-/* $Id: tif_lzw.c,v 1.29.2.5 2009-06-22 04:57:31 fwarmerdam Exp $ */
+/* $Id: tif_lzw.c,v 1.45 2011-04-02 20:54:09 bfriesen Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
@@ -27,7 +27,7 @@
#include "tiffiop.h"
#ifdef LZW_SUPPORT
/*
- * TIFF Library.
+ * TIFF Library.
* Rev 5.0 Lempel-Ziv & Welch Compression Support
*
* This code is derived from the compress program whose code is
@@ -53,34 +53,34 @@
*
* Future revisions to the TIFF spec are expected to "clarify this issue".
*/
-#define LZW_COMPAT /* include backwards compatibility code */
+#define LZW_COMPAT /* include backwards compatibility code */
/*
* Each strip of data is supposed to be terminated by a CODE_EOI.
* If the following #define is included, the decoder will also
* check for end-of-strip w/o seeing this code. This makes the
* library more robust, but also slower.
*/
-#define LZW_CHECKEOS /* include checks for strips w/o EOI code */
+#define LZW_CHECKEOS /* include checks for strips w/o EOI code */
#define MAXCODE(n) ((1L<<(n))-1)
/*
* The TIFF spec specifies that encoded bit
* strings range from 9 to 12 bits.
*/
-#define BITS_MIN 9 /* start with 9 bits */
-#define BITS_MAX 12 /* max of 12 bit strings */
+#define BITS_MIN 9 /* start with 9 bits */
+#define BITS_MAX 12 /* max of 12 bit strings */
/* predefined codes */
-#define CODE_CLEAR 256 /* code to clear string table */
-#define CODE_EOI 257 /* end-of-information code */
-#define CODE_FIRST 258 /* first free code entry */
-#define CODE_MAX MAXCODE(BITS_MAX)
-#define HSIZE 9001L /* 91% occupancy */
-#define HSHIFT (13-8)
+#define CODE_CLEAR 256 /* code to clear string table */
+#define CODE_EOI 257 /* end-of-information code */
+#define CODE_FIRST 258 /* first free code entry */
+#define CODE_MAX MAXCODE(BITS_MAX)
+#define HSIZE 9001L /* 91% occupancy */
+#define HSHIFT (13-8)
#ifdef LZW_COMPAT
/* NB: +1024 is for compatibility with old files */
-#define CSIZE (MAXCODE(BITS_MAX)+1024L)
+#define CSIZE (MAXCODE(BITS_MAX)+1024L)
#else
-#define CSIZE (MAXCODE(BITS_MAX)+1L)
+#define CSIZE (MAXCODE(BITS_MAX)+1L)
#endif
/*
@@ -88,23 +88,23 @@
* compression/decompression. Note that the predictor
* state block must be first in this data structure.
*/
-typedef struct {
- TIFFPredictorState predict; /* predictor super class */
+typedef struct {
+ TIFFPredictorState predict; /* predictor super class */
- unsigned short nbits; /* # of bits/code */
- unsigned short maxcode; /* maximum code for lzw_nbits */
- unsigned short free_ent; /* next free entry in hash table */
- long nextdata; /* next bits of i/o */
- long nextbits; /* # of valid bits in lzw_nextdata */
+ unsigned short nbits; /* # of bits/code */
+ unsigned short maxcode; /* maximum code for lzw_nbits */
+ unsigned short free_ent; /* next free entry in hash table */
+ long nextdata; /* next bits of i/o */
+ long nextbits; /* # of valid bits in lzw_nextdata */
- int rw_mode; /* preserve rw_mode from init */
+ int rw_mode; /* preserve rw_mode from init */
} LZWBaseState;
-#define lzw_nbits base.nbits
-#define lzw_maxcode base.maxcode
-#define lzw_free_ent base.free_ent
-#define lzw_nextdata base.nextdata
-#define lzw_nextbits base.nextbits
+#define lzw_nbits base.nbits
+#define lzw_maxcode base.maxcode
+#define lzw_free_ent base.free_ent
+#define lzw_nextdata base.nextdata
+#define lzw_nextbits base.nextbits
/*
* Encoding-specific state.
@@ -125,44 +125,44 @@ typedef struct code_ent {
unsigned char firstchar; /* first token of string */
} code_t;
-typedef int (*decodeFunc)(TIFF*, tidata_t, tsize_t, tsample_t);
+typedef int (*decodeFunc)(TIFF*, uint8*, tmsize_t, uint16);
typedef struct {
LZWBaseState base;
/* Decoding specific data */
- long dec_nbitsmask; /* lzw_nbits 1 bits, right adjusted */
- long dec_restart; /* restart count */
+ long dec_nbitsmask; /* lzw_nbits 1 bits, right adjusted */
+ long dec_restart; /* restart count */
#ifdef LZW_CHECKEOS
- long dec_bitsleft; /* available bits in raw data */
+ uint64 dec_bitsleft; /* available bits in raw data */
#endif
decodeFunc dec_decode; /* regular or backwards compatible */
- code_t* dec_codep; /* current recognized code */
- code_t* dec_oldcodep; /* previously recognized code */
- code_t* dec_free_entp; /* next free entry */
- code_t* dec_maxcodep; /* max available entry */
- code_t* dec_codetab; /* kept separate for small machines */
+ code_t* dec_codep; /* current recognized code */
+ code_t* dec_oldcodep; /* previously recognized code */
+ code_t* dec_free_entp; /* next free entry */
+ code_t* dec_maxcodep; /* max available entry */
+ code_t* dec_codetab; /* kept separate for small machines */
/* Encoding specific data */
- int enc_oldcode; /* last code encountered */
- long enc_checkpoint; /* point at which to clear table */
+ int enc_oldcode; /* last code encountered */
+ long enc_checkpoint; /* point at which to clear table */
#define CHECK_GAP 10000 /* enc_ratio check interval */
- long enc_ratio; /* current compression ratio */
- long enc_incount; /* (input) data bytes encoded */
- long enc_outcount; /* encoded (output) bytes */
- tidata_t enc_rawlimit; /* bound on tif_rawdata buffer */
- hash_t* enc_hashtab; /* kept separate for small machines */
+ long enc_ratio; /* current compression ratio */
+ long enc_incount; /* (input) data bytes encoded */
+ long enc_outcount; /* encoded (output) bytes */
+ uint8* enc_rawlimit; /* bound on tif_rawdata buffer */
+ hash_t* enc_hashtab; /* kept separate for small machines */
} LZWCodecState;
-#define LZWState(tif) ((LZWBaseState*) (tif)->tif_data)
-#define DecoderState(tif) ((LZWCodecState*) LZWState(tif))
-#define EncoderState(tif) ((LZWCodecState*) LZWState(tif))
+#define LZWState(tif) ((LZWBaseState*) (tif)->tif_data)
+#define DecoderState(tif) ((LZWCodecState*) LZWState(tif))
+#define EncoderState(tif) ((LZWCodecState*) LZWState(tif))
-static int LZWDecode(TIFF*, tidata_t, tsize_t, tsample_t);
+static int LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s);
#ifdef LZW_COMPAT
-static int LZWDecodeCompat(TIFF*, tidata_t, tsize_t, tsample_t);
+static int LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s);
#endif
-static void cl_hash(LZWCodecState*);
+static void cl_hash(LZWCodecState*);
/*
* LZW Decoder.
@@ -174,8 +174,8 @@ static void cl_hash(LZWCodecState*);
* strip is suppose to be terminated with CODE_EOI.
*/
#define NextCode(_tif, _sp, _bp, _code, _get) { \
- if ((_sp)->dec_bitsleft < nbits) { \
- TIFFWarningExt(_tif->tif_clientdata, _tif->tif_name, \
+ if ((_sp)->dec_bitsleft < (uint64)nbits) { \
+ TIFFWarningExt(_tif->tif_clientdata, module, \
"LZWDecode: Strip %d not terminated with EOI code", \
_tif->tif_curstrip); \
_code = CODE_EOI; \
@@ -189,36 +189,43 @@ static void cl_hash(LZWCodecState*);
#endif
static int
+LZWFixupTags(TIFF* tif)
+{
+ (void) tif;
+ return (1);
+}
+
+static int
LZWSetupDecode(TIFF* tif)
{
+ static const char module[] = "LZWSetupDecode";
LZWCodecState* sp = DecoderState(tif);
- static const char module[] = " LZWSetupDecode";
int code;
- if( sp == NULL )
- {
- /*
- * Allocate state block so tag methods have storage to record
- * values.
- */
- tif->tif_data = (tidata_t) _TIFFmalloc(sizeof(LZWCodecState));
- if (tif->tif_data == NULL)
- {
- TIFFErrorExt(tif->tif_clientdata, "LZWPreDecode", "No space for LZW state block");
- return (0);
- }
-
- DecoderState(tif)->dec_codetab = NULL;
- DecoderState(tif)->dec_decode = NULL;
-
- /*
- * Setup predictor setup.
- */
- (void) TIFFPredictorInit(tif);
-
- sp = DecoderState(tif);
- }
-
+ if( sp == NULL )
+ {
+ /*
+ * Allocate state block so tag methods have storage to record
+ * values.
+ */
+ tif->tif_data = (uint8*) _TIFFmalloc(sizeof(LZWCodecState));
+ if (tif->tif_data == NULL)
+ {
+ TIFFErrorExt(tif->tif_clientdata, module, "No space for LZW state block");
+ return (0);
+ }
+
+ DecoderState(tif)->dec_codetab = NULL;
+ DecoderState(tif)->dec_decode = NULL;
+
+ /*
+ * Setup predictor setup.
+ */
+ (void) TIFFPredictorInit(tif);
+
+ sp = DecoderState(tif);
+ }
+
assert(sp != NULL);
if (sp->dec_codetab == NULL) {
@@ -231,13 +238,13 @@ LZWSetupDecode(TIFF* tif)
/*
* Pre-load the table.
*/
- code = 255;
- do {
- sp->dec_codetab[code].value = code;
- sp->dec_codetab[code].firstchar = code;
- sp->dec_codetab[code].length = 1;
- sp->dec_codetab[code].next = NULL;
- } while (code--);
+ code = 255;
+ do {
+ sp->dec_codetab[code].value = code;
+ sp->dec_codetab[code].firstchar = code;
+ sp->dec_codetab[code].length = 1;
+ sp->dec_codetab[code].next = NULL;
+ } while (code--);
/*
* Zero-out the unused entries
*/
@@ -251,13 +258,14 @@ LZWSetupDecode(TIFF* tif)
* Setup state for decoding a strip.
*/
static int
-LZWPreDecode(TIFF* tif, tsample_t s)
+LZWPreDecode(TIFF* tif, uint16 s)
{
+ static const char module[] = "LZWPreDecode";
LZWCodecState *sp = DecoderState(tif);
(void) s;
assert(sp != NULL);
- if( sp->dec_codetab == NULL )
+ if( sp->dec_codetab == NULL )
{
tif->tif_setupdecode( tif );
}
@@ -268,7 +276,7 @@ LZWPreDecode(TIFF* tif, tsample_t s)
if (tif->tif_rawdata[0] == 0 && (tif->tif_rawdata[1] & 0x1)) {
#ifdef LZW_COMPAT
if (!sp->dec_decode) {
- TIFFWarningExt(tif->tif_clientdata, tif->tif_name,
+ TIFFWarningExt(tif->tif_clientdata, module,
"Old-style LZW codes, convert file");
/*
* Override default decoding methods with
@@ -291,7 +299,7 @@ LZWPreDecode(TIFF* tif, tsample_t s)
sp->lzw_maxcode = MAXCODE(BITS_MIN);
#else /* !LZW_COMPAT */
if (!sp->dec_decode) {
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
+ TIFFErrorExt(tif->tif_clientdata, module,
"Old-style LZW codes not supported");
sp->dec_decode = LZWDecode;
}
@@ -308,7 +316,7 @@ LZWPreDecode(TIFF* tif, tsample_t s)
sp->dec_restart = 0;
sp->dec_nbitsmask = MAXCODE(BITS_MIN);
#ifdef LZW_CHECKEOS
- sp->dec_bitsleft = tif->tif_rawcc << 3;
+ sp->dec_bitsleft = ((uint64)tif->tif_rawcc) << 3;
#endif
sp->dec_free_entp = sp->dec_codetab + CODE_FIRST;
/*
@@ -339,16 +347,17 @@ LZWPreDecode(TIFF* tif, tsample_t s)
}
static void
-codeLoop(TIFF* tif)
+codeLoop(TIFF* tif, const char* module)
{
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
- "LZWDecode: Bogus encoding, loop in the code table; scanline %d",
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Bogus encoding, loop in the code table; scanline %d",
tif->tif_row);
}
static int
-LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
+LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
{
+ static const char module[] = "LZWDecode";
LZWCodecState *sp = DecoderState(tif);
char *op = (char*) op0;
long occ = (long) occ0;
@@ -362,6 +371,12 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
(void) s;
assert(sp != NULL);
assert(sp->dec_codetab != NULL);
+
+ /*
+ Fail if value does not fit in long.
+ */
+ if ((tmsize_t) occ != occ0)
+ return (0);
/*
* Restart interrupted output operation.
*/
@@ -428,7 +443,7 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
NextCode(tif, sp, bp, code, GetNextCode);
if (code == CODE_EOI)
break;
- if (code == CODE_CLEAR) {
+ if (code >= CODE_CLEAR) {
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"LZWDecode: Corrupted LZW table at scanline %d",
tif->tif_row);
@@ -441,22 +456,22 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
codep = sp->dec_codetab + code;
/*
- * Add the new entry to the code table.
- */
+ * Add the new entry to the code table.
+ */
if (free_entp < &sp->dec_codetab[0] ||
- free_entp >= &sp->dec_codetab[CSIZE]) {
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
- "LZWDecode: Corrupted LZW table at scanline %d",
- tif->tif_row);
+ free_entp >= &sp->dec_codetab[CSIZE]) {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Corrupted LZW table at scanline %d",
+ tif->tif_row);
return (0);
}
free_entp->next = oldcodep;
if (free_entp->next < &sp->dec_codetab[0] ||
- free_entp->next >= &sp->dec_codetab[CSIZE]) {
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
- "LZWDecode: Corrupted LZW table at scanline %d",
- tif->tif_row);
+ free_entp->next >= &sp->dec_codetab[CSIZE]) {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Corrupted LZW table at scanline %d",
+ tif->tif_row);
return (0);
}
free_entp->firstchar = free_entp->next->firstchar;
@@ -472,15 +487,15 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
oldcodep = codep;
if (code >= 256) {
/*
- * Code maps to a string, copy string
+ * Code maps to a string, copy string
* value to output (written in reverse).
- */
+ */
if(codep->length == 0) {
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
- "LZWDecode: Wrong length of decoded string: "
- "data probably corrupted at scanline %d",
- tif->tif_row);
- return (0);
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Wrong length of decoded string: "
+ "data probably corrupted at scanline %d",
+ tif->tif_row);
+ return (0);
}
if (codep->length > occ) {
/*
@@ -494,14 +509,14 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
codep = codep->next;
} while (codep && codep->length > occ);
if (codep) {
- sp->dec_restart = occ;
+ sp->dec_restart = (long)occ;
tp = op + occ;
do {
*--tp = codep->value;
codep = codep->next;
} while (--occ && codep);
if (codep)
- codeLoop(tif);
+ codeLoop(tif, module);
}
break;
}
@@ -515,15 +530,16 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
*tp = t;
} while (codep && tp > op);
if (codep) {
- codeLoop(tif);
+ codeLoop(tif, module);
break;
}
+ assert(occ >= len);
op += len, occ -= len;
} else
*op++ = (char)code, occ--;
}
- tif->tif_rawcp = (tidata_t) bp;
+ tif->tif_rawcp = (uint8*) bp;
sp->lzw_nbits = (unsigned short) nbits;
sp->lzw_nextdata = nextdata;
sp->lzw_nextbits = nextbits;
@@ -533,9 +549,15 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
sp->dec_maxcodep = maxcodep;
if (occ > 0) {
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
- "LZWDecode: Not enough data at scanline %d (short %ld bytes)",
- tif->tif_row, occ);
+#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Not enough data at scanline %d (short %I64d bytes)",
+ tif->tif_row, (unsigned __int64) occ);
+#else
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Not enough data at scanline %d (short %llu bytes)",
+ tif->tif_row, (unsigned long long) occ);
+#endif
return (0);
}
return (1);
@@ -558,8 +580,9 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
}
static int
-LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
+LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
{
+ static const char module[] = "LZWDecodeCompat";
LZWCodecState *sp = DecoderState(tif);
char *op = (char*) op0;
long occ = (long) occ0;
@@ -571,6 +594,13 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
(void) s;
assert(sp != NULL);
+
+ /*
+ Fail if value does not fit in long.
+ */
+ if ((tmsize_t) occ != occ0)
+ return (0);
+
/*
* Restart interrupted output operation.
*/
@@ -632,7 +662,7 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
NextCode(tif, sp, bp, code, GetNextCodeCompat);
if (code == CODE_EOI)
break;
- if (code == CODE_CLEAR) {
+ if (code >= CODE_CLEAR) {
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"LZWDecode: Corrupted LZW table at scanline %d",
tif->tif_row);
@@ -645,22 +675,20 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
codep = sp->dec_codetab + code;
/*
- * Add the new entry to the code table.
- */
+ * Add the new entry to the code table.
+ */
if (free_entp < &sp->dec_codetab[0] ||
- free_entp >= &sp->dec_codetab[CSIZE]) {
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
- "LZWDecodeCompat: Corrupted LZW table at scanline %d",
- tif->tif_row);
+ free_entp >= &sp->dec_codetab[CSIZE]) {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Corrupted LZW table at scanline %d", tif->tif_row);
return (0);
}
free_entp->next = oldcodep;
if (free_entp->next < &sp->dec_codetab[0] ||
- free_entp->next >= &sp->dec_codetab[CSIZE]) {
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
- "LZWDecodeCompat: Corrupted LZW table at scanline %d",
- tif->tif_row);
+ free_entp->next >= &sp->dec_codetab[CSIZE]) {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Corrupted LZW table at scanline %d", tif->tif_row);
return (0);
}
free_entp->firstchar = free_entp->next->firstchar;
@@ -675,17 +703,16 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
}
oldcodep = codep;
if (code >= 256) {
- char *op_orig = op;
/*
- * Code maps to a string, copy string
+ * Code maps to a string, copy string
* value to output (written in reverse).
- */
+ */
if(codep->length == 0) {
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
- "LZWDecodeCompat: Wrong length of decoded "
- "string: data probably corrupted at scanline %d",
- tif->tif_row);
- return (0);
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Wrong length of decoded "
+ "string: data probably corrupted at scanline %d",
+ tif->tif_row);
+ return (0);
}
if (codep->length > occ) {
/*
@@ -706,16 +733,17 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
} while (--occ);
break;
}
+ assert(occ >= codep->length);
op += codep->length, occ -= codep->length;
tp = op;
do {
*--tp = codep->value;
- } while( (codep = codep->next) != NULL && tp > op_orig);
+ } while( (codep = codep->next) != NULL );
} else
*op++ = code, occ--;
}
- tif->tif_rawcp = (tidata_t) bp;
+ tif->tif_rawcp = (uint8*) bp;
sp->lzw_nbits = nbits;
sp->lzw_nextdata = nextdata;
sp->lzw_nextbits = nextbits;
@@ -725,9 +753,15 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
sp->dec_maxcodep = maxcodep;
if (occ > 0) {
- TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
- "LZWDecodeCompat: Not enough data at scanline %d (short %ld bytes)",
- tif->tif_row, occ);
+#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Not enough data at scanline %d (short %I64d bytes)",
+ tif->tif_row, (unsigned __int64) occ);
+#else
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Not enough data at scanline %d (short %llu bytes)",
+ tif->tif_row, (unsigned long long) occ);
+#endif
return (0);
}
return (1);
@@ -741,13 +775,14 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
static int
LZWSetupEncode(TIFF* tif)
{
- LZWCodecState* sp = EncoderState(tif);
static const char module[] = "LZWSetupEncode";
+ LZWCodecState* sp = EncoderState(tif);
assert(sp != NULL);
sp->enc_hashtab = (hash_t*) _TIFFmalloc(HSIZE*sizeof (hash_t));
if (sp->enc_hashtab == NULL) {
- TIFFErrorExt(tif->tif_clientdata, module, "No space for LZW hash table");
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "No space for LZW hash table");
return (0);
}
return (1);
@@ -757,14 +792,14 @@ LZWSetupEncode(TIFF* tif)
* Reset encoding state at the start of a strip.
*/
static int
-LZWPreEncode(TIFF* tif, tsample_t s)
+LZWPreEncode(TIFF* tif, uint16 s)
{
LZWCodecState *sp = EncoderState(tif);
(void) s;
assert(sp != NULL);
-
- if( sp->enc_hashtab == NULL )
+
+ if( sp->enc_hashtab == NULL )
{
tif->tif_setupencode( tif );
}
@@ -822,7 +857,7 @@ LZWPreEncode(TIFF* tif, tsample_t s)
* for the decoder.
*/
static int
-LZWEncode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
+LZWEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
{
register LZWCodecState *sp = EncoderState(tif);
register long fcode;
@@ -833,7 +868,8 @@ LZWEncode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
long incount, outcount, checkpoint;
long nextdata, nextbits;
int free_ent, maxcode, nbits;
- tidata_t op, limit;
+ uint8* op;
+ uint8* limit;
(void) s;
if (sp == NULL)
@@ -912,7 +948,7 @@ LZWEncode(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s)
* are at least 4 bytes free--room for 2 codes.
*/
if (op > limit) {
- tif->tif_rawcc = (tsize_t)(op - tif->tif_rawdata);
+ tif->tif_rawcc = (tmsize_t)(op - tif->tif_rawdata);
TIFFFlushData1(tif);
op = tif->tif_rawdata;
}
@@ -990,14 +1026,14 @@ static int
LZWPostEncode(TIFF* tif)
{
register LZWCodecState *sp = EncoderState(tif);
- tidata_t op = tif->tif_rawcp;
+ uint8* op = tif->tif_rawcp;
long nextbits = sp->lzw_nextbits;
long nextdata = sp->lzw_nextdata;
long outcount = sp->enc_outcount;
int nbits = sp->lzw_nbits;
if (op > sp->enc_rawlimit) {
- tif->tif_rawcc = (tsize_t)(op - tif->tif_rawdata);
+ tif->tif_rawcc = (tmsize_t)(op - tif->tif_rawdata);
TIFFFlushData1(tif);
op = tif->tif_rawdata;
}
@@ -1008,7 +1044,7 @@ LZWPostEncode(TIFF* tif)
PutNextCode(op, CODE_EOI);
if (nextbits > 0)
*op++ = (unsigned char)(nextdata << (8-nextbits));
- tif->tif_rawcc = (tsize_t)(op - tif->tif_rawdata);
+ tif->tif_rawcc = (tmsize_t)(op - tif->tif_rawdata);
return (1);
}
@@ -1021,7 +1057,7 @@ cl_hash(LZWCodecState* sp)
register hash_t *hp = &sp->enc_hashtab[HSIZE-1];
register long i = HSIZE-8;
- do {
+ do {
i -= 8;
hp[-7].hash = -1;
hp[-6].hash = -1;
@@ -1033,7 +1069,7 @@ cl_hash(LZWCodecState* sp)
hp[ 0].hash = -1;
hp -= 8;
} while (i >= 0);
- for (i += 8; i > 0; i--, hp--)
+ for (i += 8; i > 0; i--, hp--)
hp->hash = -1;
}
@@ -1059,11 +1095,12 @@ LZWCleanup(TIFF* tif)
int
TIFFInitLZW(TIFF* tif, int scheme)
{
+ static const char module[] = "TIFFInitLZW";
assert(scheme == COMPRESSION_LZW);
/*
* Allocate state block so tag methods have storage to record values.
*/
- tif->tif_data = (tidata_t) _TIFFmalloc(sizeof (LZWCodecState));
+ tif->tif_data = (uint8*) _TIFFmalloc(sizeof (LZWCodecState));
if (tif->tif_data == NULL)
goto bad;
DecoderState(tif)->dec_codetab = NULL;
@@ -1074,6 +1111,7 @@ TIFFInitLZW(TIFF* tif, int scheme)
/*
* Install codec methods.
*/
+ tif->tif_fixuptags = LZWFixupTags;
tif->tif_setupdecode = LZWSetupDecode;
tif->tif_predecode = LZWPreDecode;
tif->tif_decoderow = LZWDecode;
@@ -1092,7 +1130,7 @@ TIFFInitLZW(TIFF* tif, int scheme)
(void) TIFFPredictorInit(tif);
return (1);
bad:
- TIFFErrorExt(tif->tif_clientdata, "TIFFInitLZW",
+ TIFFErrorExt(tif->tif_clientdata, module,
"No space for LZW state block");
return (0);
}
@@ -1120,3 +1158,10 @@ bad:
#endif /* LZW_SUPPORT */
/* vim: set ts=8 sts=8 sw=8 noet: */
+/*
+ * Local Variables:
+ * mode: c
+ * c-basic-offset: 8
+ * fill-column: 78
+ * End:
+ */