| iMatix home page | << | < | > | >> |
SFL Version 2.11 |
#include "sflcomp.h" word expand_bits ( const byte *src, byte *dst, word src_size)
Expands a block of data previously compressed using the compress bits() 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++]; if (cur_byte < 8) /* Single bit in position 0 to 7 */ dst [dst_size++] = 1 << cur_byte; else if (cur_byte < 128) /* String of 1 to 120 bytes */ { length = (word) cur_byte - 7; memcpy (dst + dst_size, src + src_scan, length); src_scan += length; dst_size += length; } else /* Run of 1 or more bytes */ { switch (cur_byte) { case 0x80: /* 381-2^16 binary zeroes */ length = src [src_scan++]; length += src [src_scan++] << 8; cur_byte = 0; break; case 0x81: length = src [src_scan++]; if (length == 0xFE) /* 4-255 non-zero bytes */ { length = src [src_scan++]; cur_byte = src [src_scan++]; } else if (length == 0xFF) /* Run of 256-2^15 non-zero bytes */ { length = src [src_scan++]; length += src [src_scan++] << 8; cur_byte = src [src_scan++]; } else { length += 127; cur_byte = 0; /* 127 to 380 zeroes */ } break; default: /* 1 to 126 zeroes */ length = (cur_byte - 1) & 127; cur_byte = 0; } memset (dst + dst_size, cur_byte, length); dst_size += length; } } return (dst_size); /* Return expanded data size */ }
| << | < | > | >> | Copyright © 1996-2000 iMatix Corporation |