This block of code allows an application to perform losless compression and uncompression on arbitrary chunks of data.
It will:
- abstract away how the samples are compressed and uncompressed,
- provide an easy interface via which data of any length compressed and uncompressed,
The Compress module will use both EEPROM and FLASH to store bits of data. The newest samples are always stored in EEPROM; when the reserved space in EEPROM is full, all the data is moved to FLASH, and the EEPROM is reused. Writing samples always means appending them to the already written samples; it is not possible to edit the already written stream of bits. When reading back again, the user can control the starting read position using a sequence number. It is automatically deduced where the corresponding sample is written, whether it is compressed, and what needs to be done to be able to return the requested sample(s).
It is expected that each application that requires this module includes it and configures the diversity settings of the module according to its specific needs.
- Diversity
- This module supports diversity: settings to tweak the effectiveness of the compression. Check Diversity Settings for all diversity parameters.
- Memory Requirements
- The memory requirements are defined by the diversity settings. Check COMPRESS_WINDOW_BITS and COMPRESS_USE_INDEX.
- How to use the module
- To compress, simply call Compress_Encode. No preparation or initialization is necessary.
- To uncompress, call Compress_Decod. No preparation or initialization is necessary.
- Compress_Decode o Compress_Encode is an identity function.
- Example
uint8_t data[1234];
uint8_t compressed[1234];
uint8_t uncompressed[1234];
int uncompressedSize =
Compress_Decode(compressed, compressedSize, uncompressed, 1234);
|
int | Compress_Encode (const uint8_t *input, int inputLength, uint8_t *output, int outputLength) |
|
int | Compress_Decode (const uint8_t *input, int inputLength, uint8_t *output, int outputLength) |
|
◆ Compress_Encode()
int Compress_Encode |
( |
const uint8_t * |
input, |
|
|
int |
inputLength, |
|
|
uint8_t * |
output, |
|
|
int |
outputLength |
|
) |
| |
Compresses a contiguous array of bytes.
- Parameters
-
input | pointer to the array where all bytes to encode can be found. No alignment is enforced. |
inputLength | The number of bytes to encode, starting from input . |
output | pointer to the array where the encoded end result will be written to. No alignment is enforced. |
outputLength | Size in bytes of the available output array. |
- Returns
- Size in bytes of the used
output
bytes. An output size of 0
indicates an error: the output
buffer may or may not have been written to, but none of the bytes may be used for further processing.
- Note
- The output, when a valid size has been returned, cannot be split up and decoded in chunks; decoding is only possible when providing the full array with all the now-encoded bytes.
◆ Compress_Decode()
int Compress_Decode |
( |
const uint8_t * |
input, |
|
|
int |
inputLength, |
|
|
uint8_t * |
output, |
|
|
int |
outputLength |
|
) |
| |
Uncompresses a contiguous array of bytes.
- Parameters
-
input | pointer to the array where the encoded bytes to uncompress can be found. No alignment is enforced. |
inputLength | The number of bytes to decode, starting from input . This value must be equal to the returnvalue of a previous call to Compress_Encode. |
output | pointer to the array where the decoded bytes will be written to. No alignment is enforced. |
outputLength | Size in bytes of the available output array. |
- Returns
- Size in bytes of the used
output
bytes. An output size of 0
indicates an error: the output
buffer may or may not have been written to, but none of the bytes may be used for further processing.
- Note
- The output length, when a valid size has been returned, will be equal to the value of
inputLength
during a previous call to Compress_Encode.