algorithm - C++ LZSS Compression -
can find compression algorithm decompression code. algorithms not forte , friend made code didn't put comments in , somehow lost compression code before leaving. haa.
static inline unsigned char getbit_le(unsigned char byte, unsigned int pos) { return !!(byte & (1 << pos)); } static inline unsigned char getbyte_le(unsigned char byte) { return byte; } static int lzss_decompress(byte *uncompr, dword uncomprlen, byte *compr, dword comprlen) { unsigned int act_uncomprlen = 0; unsigned int curbyte = 0; unsigned int ncurwindowbyte = 0xfee; unsigned char window[4096]; unsigned int win_size = 4096; memset(window, 0, win_size); while (1) { unsigned char bitmap; if (curbyte >= comprlen) break; bitmap = getbyte_le(compr[curbyte++]); (unsigned int curbit_bitmap = 0; curbit_bitmap < 8; curbit_bitmap++) { if (getbit_le(bitmap, curbit_bitmap)) { unsigned char data; if (curbyte >= comprlen) goto out; if (act_uncomprlen >= uncomprlen) goto out; data = ~getbyte_le(compr[curbyte++]); uncompr[act_uncomprlen++] = data; window[ncurwindowbyte++] = data; ncurwindowbyte &= win_size - 1; } else { unsigned int copy_bytes, win_offset; if (curbyte >= comprlen) goto out; win_offset = getbyte_le(compr[curbyte++]); if (curbyte >= comprlen) goto out; copy_bytes = getbyte_le(compr[curbyte++]); win_offset |= (copy_bytes >> 4) << 8; copy_bytes &= 0x0f; copy_bytes += 3; (unsigned int = 0; < copy_bytes; i++) { unsigned char data; if (act_uncomprlen >= uncomprlen) goto out; data = window[(win_offset + i) & (win_size - 1)]; uncompr[act_uncomprlen++] = data; window[ncurwindowbyte++] = data; ncurwindowbyte &= win_size - 1; } } } } out: return act_uncomprlen; }
Comments
Post a Comment