|
| iMatix home page | << | < | > | >> |
SFLVersion 2.11 |
#include "sflcomp.h"
word
expand_nulls (
const byte *src,
byte *dst,
word src_size)
Expands a block of data previously compressed using the compress nulls() 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 expanded data.
{
word
dst_size, /* Size of expanded data */
src_scan, /* Scan through source data */
length; /* Size of the run or string */
byte
cur_byte; /* Next byte to process */
src_scan = 0;
dst_size = 0;
while (src_scan < src_size)
{
cur_byte = src [src_scan++];
/* 1 to 127 is uncompressed string of 1 to 127 bytes */
if (cur_byte > 0 && cur_byte < 128)
{
length = (word) cur_byte;
memcpy (dst + dst_size, src + src_scan, length);
src_scan += length;
dst_size += length;
}
else /* Run of 2 or more bytes */
{
switch (cur_byte)
{
case 0x00: /* Run of non-zero bytes */
length = src [src_scan++];
if (length == 0) /* Stored as double-byte */
{
length = src [src_scan++];
length += src [src_scan++] << 8;
}
cur_byte = src [src_scan++];
break;
case 0x80: /* 256-2^16 zeroes */
length = src [src_scan++];
length += src [src_scan++] << 8;
cur_byte = 0;
break;
case 0x81: /* 128 to 255 zeroes */
length = src [src_scan++];
cur_byte = 0;
break;
default: /* 2 to 127 zeroes */
length = cur_byte & 127;
cur_byte = 0;
}
memset (dst + dst_size, cur_byte, length);
dst_size += length;
}
}
return (dst_size); /* Return expanded data size */
}
| | << | < | > | >> |
|