Bienvenidos a Abandonsocios: El Portal de los Juegos Antiguos
0 Usuarios y 1 Visitante están viendo este tema.
uint8[4] signature = "LZSS" uint16 width uint16 height uint8[4] palette_signature = "CMAP" rgb[256] palette (in RGB format 24-bit for pixel) uint8[4] image_signature = "FORM" uint32 compressed_size uint8[compressed_size] compressed_image_data (indexes into palette)
#define N 4096 /* size of ring buffer - must be power of 2 */ #define F 18 /* upper limit for match_length */ #define THRESHOLD 2 /* encode string into position and length if match_length is greater than this */ int decompress_lzss( u_int8_t * dst, u_int32_t dstlen, u_int8_t * src, u_int32_t srclen) { /* ring buffer of size N, with extra F-1 bytes to aid string comparison */ u_int8_t text_buf[N + F - 1]; u_int8_t * dststart = dst; const u_int8_t * dstend = dst + dstlen; const u_int8_t * srcend = src + srclen; int i, j, k, r, c; unsigned int flags; dst = dststart; for (i = 0; i < N - F; i++) text_buf[i] = ' '; r = N - F; flags = 0; for ( ; ; ) { if (((flags >>= 1) & 0x100) == 0) { if (src < srcend) c = *src++; else break; flags = c | 0xFF00; /* uses higher byte cleverly */ } /* to count eight */ if (flags & 1) { if (src < srcend) c = *src++; else break; if (dst < dstend) *dst++ = c; else break; text_buf[r++] = c; r &= (N - 1); } else { if (src < srcend) i = *src++; else break; if (src < srcend) j = *src++; else break; i |= ((j & 0xF0) << 4); j = (j & 0x0F) + THRESHOLD; for (k = 0; k <= j; k++) { c = text_buf[(i + k) & (N - 1)]; if (dst < dstend) *dst++ = c; else break; text_buf[r++] = c; r &= (N - 1); } } } return (int)(dst - dststart); }