|
| iMatix home page | << | < | > | >> |
SFLVersion 2.11 |
#include "sflcomp.h"
word
expand_block (
const byte *src,
byte *dst,
word src_size)
Expands a block of data previously compressed using the compress block() function. The compressed block is passed in src; the expanded result in dst. dst must be large enough to accomodate the largest possible decompressed block. Returns the size of the uncompressed data.
{
word SymbolAddress;
word ChunkSize;
word Counter;
word Command = 0;
word src_index = 1;
word dst_size = 0;
byte Bit = 0;
if (src [0] == FLAG_COPY)
{
for (dst_size = 1; dst_size < src_size; dst_size++)
dst [dst_size - 1] = src [dst_size];
return (src_size - 1);
}
while (src_index < src_size)
{
if (Bit == 0)
{
Command = src [src_index++] << 8;
Command += src [src_index++];
Bit = 16;
}
if (Command & 0x8000)
{
SymbolAddress = (word) (src [src_index++] << 4);
SymbolAddress += (word) (src [src_index] >> 4);
if (SymbolAddress)
{
ChunkSize = (word) (src [src_index++] & 0x0f) + 3;
SymbolAddress = dst_size - SymbolAddress;
for (Counter = 0; Counter < ChunkSize; Counter++)
dst [dst_size++] = dst [SymbolAddress++];
}
else
{
ChunkSize = (word) (src [src_index++] << 8);
ChunkSize += (word) (src [src_index++] + 16);
for (Counter = 0; Counter < ChunkSize; Counter++)
dst [dst_size++] = src [src_index];
src_index++;
}
}
else
dst [dst_size++] = src [src_index++];
Command <<= 1;
Bit--;
}
return (dst_size);
}
| | << | < | > | >> |
|