Skip to content
View in the app

A better way to browse. Learn more.

ResHax

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Help us keep the site running.

LZW Implementation

Featured Replies

  • Author
  • Localization

Ekey, posted Mon Nov 02, 2015 12:12 pm (9212)


There is a realization of LZW algorithm is similar to the code below?

Code:
int LZWEncode(unsigned char* pScrBuffer, unsigned char* pDstBuffer) - It should return the compressed size
int LZWDecode(unsigned char* pScrBuffer, unsigned char* pDstBuffer) - It should return the decompressed size


I see only by file stream realizations. Like

Code:
void LZWEncode(FILE *fin, FILE *fout)
void LZWDecode(FILE *fin, FILE *fout)
  • Author
  • Localization

aluigi, posted Mon Nov 02, 2015 1:15 pm (9215)


Have you already checked quickbms?
I have seen many LZW* in various games and implemented lot of them so it's highly possible that it's already there.
And if it's there, there is also the source code for performing the memory->memory decompression.
  • Author
  • Localization

Ekey, posted Mon Nov 02, 2015 2:36 pm (9219)


Yeah, I already checked QuickBMS source's. Correct algorithm is clzw for The Binding of Isaac compressed data, but it also works like FileIn, FileOut

Code:
   lzw_dec_init(ctx, fout);
   while (len = lzw_readbuf(fin, buf, sizeof(buf)))
   {
      int ret = lzw_decode(ctx, buf, len);
      if (ret != len)
      {
         fprintf(stderr, "Error %d\n", ctx);
         break;
      }
   }
  • Author
  • Localization

aluigi, posted Mon Nov 02, 2015 4:59 pm (9222)


100% memory2memory or quickbms doesn't use it :D
From src/perform.c:
Code:
            lzw_dec_t  *clzw_ctx;
            clzw_ctx = calloc(1, sizeof(lzw_dec_t));
            if(!clzw_ctx) STD_ERR(QUICKBMS_ERROR_MEMORY);
            clzw_outsz = 0;
            lzw_dec_init(clzw_ctx, out);
            lzw_decode(clzw_ctx, in, zsize);
            size = clzw_outsz;
            FREE(clzw_ctx);
  • Author
  • Localization

Ekey, posted Mon Nov 02, 2015 5:33 pm (9230)


Here is my attempt to do something like this

Code:
int LZWDecode(unsigned char* pScrBuffer, unsigned char* pDstBuffer)


But in the output buffer I see incorrect data.

QuickBMS result with 1024 bytes is:

Code:

   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   Code:

   
  • Author
  • Localization

aluigi, posted Mon Nov 02, 2015 5:47 pm (9232)


Why don't have you used lzw-dec.c in your code?
Your implementation of clzw is a bit different than the library.
  • Author
  • Localization

Ekey, posted Mon Nov 02, 2015 6:05 pm (9236)


I do not see the difference, because give identical good results in 1024 bytes: QuickBMS library (lzw-dec.c) and (Google Code lzw.c)
  • Author
  • Localization

Ekey, posted Mon Nov 02, 2015 6:32 pm (9238)


Ok seems found problem

After part
Code:
        strlen = lzw_get_str(ctx, nc, buff, sizeof(buff));
        c = buff[sizeof(buff) - strlen];
        memcpy(pDstBuffer, buff (sizeof(buff) - strlen), strlen);


Add

Code:
       for(int i = 0; i < strlen; i  )
           pDstBuffer ;


Decompressed size:

Code:
return isize * 2   1; //  1 mean first byte which is copied
  • Author
  • Localization

Ekey, posted Mon Nov 02, 2015 8:47 pm (9242)


Well, the problem is still there, not all blocks can be decompressed, god damn! QuickBMS also give invalid dump :(

Chunk 1: Offset at 0xE > ZSize is 602 - Valid dump
Chunk 2: Offset at 0x26C > ZSize is 436 - Invalid dump
  • Author
  • Localization

aluigi, posted Mon Nov 02, 2015 10:06 pm (9245)


I tried also to concatenate chunk1 and chunk2 but it fails too.
Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.