summaryrefslogtreecommitdiffstats
path: root/generic/tkImgGIF.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkImgGIF.c')
-rw-r--r--generic/tkImgGIF.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/generic/tkImgGIF.c b/generic/tkImgGIF.c
index 409300c..e7f4582 100644
--- a/generic/tkImgGIF.c
+++ b/generic/tkImgGIF.c
@@ -963,9 +963,9 @@ ReadImage(
* Last pass reset the decoder, so the first code we see
* must be a singleton. Seed the stack with it, and set up
* the old/first code pointers for insertion into the
- * string table. We can't just roll this into the
- * clearCode test above, because at that point we have not
- * yet read the next code.
+ * codes table. We can't just roll this into the clearCode
+ * test above, because at that point we have not yet read
+ * the next code.
*/
*top++ = append[code];
@@ -976,11 +976,11 @@ ReadImage(
inCode = code;
- if (code == maxCode) {
+ if ((code == maxCode) && (maxCode < (1 << MAX_LWZ_BITS))) {
/*
* maxCode is always one bigger than our highest assigned
* code. If the code we see is equal to maxCode, then we
- * are about to add a new string to the table. ???
+ * are about to add a new entry to the codes table.
*/
*top++ = firstCode;
@@ -989,7 +989,7 @@ ReadImage(
while (code > clearCode) {
/*
- * Populate the stack by tracing the string in the string
+ * Populate the stack by tracing the code in the codes
* table from its tail to its head
*/
@@ -998,28 +998,24 @@ ReadImage(
}
firstCode = append[code];
- /*
- * If there's no more room in our string table, quit.
- * Otherwise, add a new string to the table
- */
-
- if (maxCode >= (1 << MAX_LWZ_BITS)) {
- return TCL_OK;
- }
-
- /*
- * Push the head of the string onto the stack.
- */
+ /*
+ * Push the head of the code onto the stack.
+ */
- *top++ = firstCode;
+ *top++ = firstCode;
- /*
- * Add a new string to the string table
- */
+ if (maxCode < (1 << MAX_LWZ_BITS)) {
+ /*
+ * If there's still room in our codes table, add a new entry.
+ * Otherwise don't, and keep using the current table.
+ * See DEFERRED CLEAR CODE IN LZW COMPRESSION in the GIF89a
+ * specification.
+ */
- prefix[maxCode] = oldCode;
- append[maxCode] = firstCode;
- maxCode++;
+ prefix[maxCode] = oldCode;
+ append[maxCode] = firstCode;
+ maxCode++;
+ }
/*
* maxCode tells us the maximum code value we can accept. If