From 338bcfc322a1c4141cf1d9230c877d3bf078e289 Mon Sep 17 00:00:00 2001 From: driAn Date: Sun, 21 Sep 2008 16:07:28 +0000 Subject: [PATCH] compression test git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2724 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/lzwcompression.cpp | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/source/src/lzwcompression.cpp b/source/src/lzwcompression.cpp index 6bf9133e..1bfc0c52 100644 --- a/source/src/lzwcompression.cpp +++ b/source/src/lzwcompression.cpp @@ -41,22 +41,6 @@ struct lzwdirectory : vector { if(eidx<=255) return true; else return inrange(eidx-256); - - - /* - if(eidx<=255) - { - e.data = new uchar(eidx); - e.size = 1; - } - else - { - int i = idx-256; - if(dictionary.inrange(i)) e = dictionary[eidx-256]; - else return -1; - } - return e; - */ } }; @@ -221,7 +205,7 @@ struct lzwbuffer : bitbuf out.put(*w); conoutf("decompressing value %d %c (size %d)", *w, *w, fieldsize); - for(uint k = this->getuint(fieldsize); length(); k = this->getuint(fieldsize)) + for(uint k = this->getuint(fieldsize); !overread(); k = this->getuint(fieldsize)) { lzwentry e; if(dictionary.lzwentryexists(k)) @@ -245,10 +229,15 @@ struct lzwbuffer : bitbuf } else ASSERT(0); + // add to output out.put(*e.data); - conoutf("decompressing value %d %c (size %d)", *e.data, *e.data, fieldsize); + conoutf("decompressing value %d %c (size %d)", k, *e.data, fieldsize); - dictionary.add(e); + // new dictionary entry + lzwentry newentry = { new uchar[wsize+1], wsize+1 }; + memcpy(newentry.data, w, wsize); + newentry.data[wsize] = e.data[0]; + dictionary.add(newentry); // adjust bitfieldsize int supporteddictsize = (1<