From a630bec3eb1bed70c9b1a4628e87708f02ab4304 Mon Sep 17 00:00:00 2001
From: "Mirar (Pontus Hagland)" <pike@sort.mirar.org>
Date: Sun, 30 May 1999 22:11:15 +0200
Subject: [PATCH] (Image.GIF) added support for crippled lzw, some kind of rle

Rev: src/configure.in:1.294
Rev: src/modules/Image/encodings/gif_lzw.c:1.6
Rev: src/modules/Image/encodings/gif_lzw.h:1.7
---
 src/configure.in                      |  3 ++-
 src/modules/Image/encodings/gif_lzw.c | 39 ++++++++++++++++++++++-----
 src/modules/Image/encodings/gif_lzw.h |  6 ++++-
 3 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/src/configure.in b/src/configure.in
index d6ac27bbc0..486079734f 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -1,4 +1,4 @@
-AC_REVISION("$Id: configure.in,v 1.293 1999/05/29 15:20:51 grubba Exp $")
+AC_REVISION("$Id: configure.in,v 1.294 1999/05/30 20:11:12 mirar Exp $")
 AC_INIT(interpret.c)
 AC_CONFIG_HEADER(machine.h)
 
@@ -284,6 +284,7 @@ AC_ARG_WITH(threads,     [  --without-threads      no threads support],[],[with_
 AC_ARG_WITH(zlib,        [  --without-zlib         no gz compression support],[],[with_zlib=yes])
 AC_ARG_WITH(ssleay,      [  --without-ssleay       no support for the secure socket protocol],[],[with_ssleay=yes])
 AC_ARG_WITH(mysql,       [  --without-mysql        no support for the Mysql database],[],[with_mysql=yes])
+AC_ARG_WITH(gif-rle,     [  --with-gif-rle        use kind-of-rle packing instead of lzw],[],[])
 AC_ARG_WITH(dmalloc,     [  --with-dmalloc         enable memory-leak tests],[AC_DEFINE(DEBUG_MALLOC,10)],[])
 AC_ARG_WITH(checker,	 [  --with-checker         add extra memory checking overhead (Purify)])
 AC_ARG_WITH(profiling,   [  --with-profiling       add code used to profile pike code ],[AC_DEFINE(PROFILING)],[])
diff --git a/src/modules/Image/encodings/gif_lzw.c b/src/modules/Image/encodings/gif_lzw.c
index 13ffa22830..4cd1b40023 100644
--- a/src/modules/Image/encodings/gif_lzw.c
+++ b/src/modules/Image/encodings/gif_lzw.c
@@ -1,10 +1,11 @@
 /*
 **! module Image
 **! note
-**!	$Id: gif_lzw.c,v 1.5 1998/04/29 01:27:22 mirar Exp $
+**!	$Id: gif_lzw.c,v 1.6 1999/05/30 20:11:14 mirar Exp $
 */
 
 #include "global.h"
+#include "image_machine.h"
 #include "gif_lzw.h"
 
 #define DEFAULT_OUTBYTES 16384
@@ -84,19 +85,37 @@ static INLINE void lzw_add(struct gif_lzw *lzw,int c)
    if (lzw->current==LZWCNULL) /* no current, load */
    {
       lzw->current=c;
+#ifdef GIF_LZW_LZ
+      lzw->skipone=0;
+#endif
       return;
    }
 
-   lno=lzw->code[lzw->current].firstchild; /* check if we have this sequence */
-   while (lno!=LZWCNULL)
+#ifdef GIF_LZW_RLE
+   if (c==lzw->code[lzw->current].c)
    {
-      if (lzw->code[lno].c==c && lno!=lzw->codes-1 )
+#endif
+#ifdef GIF_LZW_LZ
+      if (!lzw->skipone)
       {
-	 lzw->current=lno;
-	 return;
+#endif
+	 /* check if we have this sequence */
+	 lno=lzw->code[lzw->current].firstchild; 
+	 while (lno!=LZWCNULL)
+	 {
+	    if (lzw->code[lno].c==c && lno!=lzw->codes-1 )
+	    {
+	       lzw->current=lno;
+	       return;
+	    }
+	    lno=lzw->code[lno].next;
+	 }
+#ifdef GIF_LZW_RLE
       }
-      lno=lzw->code[lno].next;
+#endif
+#ifdef GIF_LZW_LZ
    }
+#endif
 
    if (lzw->codes==4096)  /* needs more than 12 bits */
    {
@@ -113,6 +132,9 @@ static INLINE void lzw_add(struct gif_lzw *lzw,int c)
 
       lzw->codebits=lzw->bits+1;
       lzw->current=c;
+#ifdef GIF_LZW_LZ
+      lzw->skipone=0;
+#endif
       return;
    }
 
@@ -133,6 +155,9 @@ static INLINE void lzw_add(struct gif_lzw *lzw,int c)
       lzw->codebits++;
 
    lzw->current=c;
+#ifdef GIF_LZW_LZ
+   lzw->skipone=!lzw->skipone;
+#endif
 }
 
 void image_gif_lzw_init(struct gif_lzw *lzw,int bits)
diff --git a/src/modules/Image/encodings/gif_lzw.h b/src/modules/Image/encodings/gif_lzw.h
index 6cfc993613..aa46fabe34 100644
--- a/src/modules/Image/encodings/gif_lzw.h
+++ b/src/modules/Image/encodings/gif_lzw.h
@@ -1,7 +1,7 @@
 /*
 **! module Image
 **! note
-**!	$Id: gif_lzw.h,v 1.6 1998/05/02 01:24:25 mirar Exp $
+**!	$Id: gif_lzw.h,v 1.7 1999/05/30 20:11:15 mirar Exp $
 */
 
 typedef unsigned short lzwcode_t; /* no more than 12 bits used */
@@ -23,6 +23,10 @@ struct gif_lzw
 
    int earlychange;
    int reversebits;
+
+#ifdef GIF_LZW_LZ
+   int skipone; /* lz marker for skip next code */
+#endif
    
    unsigned long codes;
    unsigned long bits; /* initial encoding bits */
-- 
GitLab