/* * RLEunpack() * by Christian 'tokai' Rosentreter * * Description: unpacks RLEpacked data * * stream: UBYTE pointer to (linked) RLE packed data (use RLEpack to * create a RLE packed RAW file and convert it with bin2c into c * source. You find these tools on my homepage under: * http://www.christianrosentreter.com/releases/ ) * * streamsize: size (in bytes) of the RLE packed stream * * out: pointer to pre-allocated memory for storing the unpacked * data. Make sure you allocate enough memory (you need the exact * size of the unpacked data (simply check filesize before using * RLEpack ;) ) * * This function is freely (re)usable and distributable. * */ #include void RLEunpack(UBYTE *stream, ULONG streamsize, UBYTE *out) { ULONG i = 0, c; UBYTE b, f; while (i < streamsize) { b = stream[i++]; if (0xC0 == (b & 0xC0)) { f = b & 0x3F; b = stream[i++]; } else { f = 1; } for (c = 0; c < f; c++) { *out++ = b; } } }