LZSS based compression HAL API.
More...
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
Go to the source code of this file.
|
typedef struct CompressIcon | CompressIcon |
| Compress Icon control structure.
|
|
typedef struct Compress | Compress |
| Compress control structure.
|
|
typedef int32_t(* | CompressIoCallback) (void *context, uint8_t *buffer, size_t size) |
| I/O callback for streamed compression/decompression.
|
|
typedef struct CompressStreamDecoder | CompressStreamDecoder |
| CompressStreamDecoder control structure.
|
|
|
enum | CompressType { CompressTypeHeatshrink = 0
} |
| Supported compression types.
|
|
|
CompressIcon * | compress_icon_alloc (size_t decode_buf_size) |
| Initialize icon compressor.
|
|
void | compress_icon_free (CompressIcon *instance) |
| Free icon compressor.
|
|
void | compress_icon_decode (CompressIcon *instance, const uint8_t *icon_data, uint8_t **output) |
| Decompress icon.
|
|
Compress * | compress_alloc (CompressType type, const void *config) |
| Allocate encoder and decoder.
|
|
void | compress_free (Compress *compress) |
| Free encoder and decoder.
|
|
bool | compress_encode (Compress *compress, uint8_t *data_in, size_t data_in_size, uint8_t *data_out, size_t data_out_size, size_t *data_res_size) |
| Encode data.
|
|
bool | compress_decode (Compress *compress, uint8_t *data_in, size_t data_in_size, uint8_t *data_out, size_t data_out_size, size_t *data_res_size) |
| Decode data.
|
|
bool | compress_decode_streamed (Compress *compress, CompressIoCallback read_cb, void *read_context, CompressIoCallback write_cb, void *write_context) |
| Decompress streamed data.
|
|
CompressStreamDecoder * | compress_stream_decoder_alloc (CompressType type, const void *config, CompressIoCallback read_cb, void *read_context) |
| Allocate stream decoder.
|
|
void | compress_stream_decoder_free (CompressStreamDecoder *instance) |
| Free stream decoder.
|
|
bool | compress_stream_decoder_read (CompressStreamDecoder *instance, uint8_t *data_out, size_t data_out_size) |
| Read uncompressed data chunk from stream decoder.
|
|
bool | compress_stream_decoder_seek (CompressStreamDecoder *instance, size_t position) |
| Seek to position in uncompressed data stream.
|
|
size_t | compress_stream_decoder_tell (CompressStreamDecoder *instance) |
| Get current position in uncompressed data stream.
|
|
bool | compress_stream_decoder_rewind (CompressStreamDecoder *instance) |
| Reset stream decoder to the beginning.
|
|
LZSS based compression HAL API.
◆ CompressIoCallback
typedef int32_t(* CompressIoCallback) (void *context, uint8_t *buffer, size_t size) |
I/O callback for streamed compression/decompression.
- Parameters
-
context | user context |
buffer | buffer to read/write |
size | size of buffer |
- Returns
- number of bytes read/written, 0 on end of stream, negative on error
◆ compress_alloc()
Allocate encoder and decoder.
- Parameters
-
| type | Compression type |
[in] | config | Configuration for compression, specific to type |
- Returns
- Compress instance
◆ compress_decode()
bool compress_decode |
( |
Compress * | compress, |
|
|
uint8_t * | data_in, |
|
|
size_t | data_in_size, |
|
|
uint8_t * | data_out, |
|
|
size_t | data_out_size, |
|
|
size_t * | data_res_size ) |
Decode data.
- Parameters
-
| compress | Compress instance |
| data_in | pointer to input data |
| data_in_size | size of input data |
| data_out | maximum size of output data |
[in] | data_out_size | The data out size |
| data_res_size | pointer to result output data size |
- Note
- Expects compressed stream with a header, as produced by
compress_encode
.
- Returns
- true on success
◆ compress_decode_streamed()
Decompress streamed data.
- Parameters
-
compress | Compress instance |
read_cb | read callback |
read_context | read callback context |
write_cb | write callback |
write_context | write callback context |
- Note
- Does not expect a header, just compressed data stream.
- Returns
- true on success
◆ compress_encode()
bool compress_encode |
( |
Compress * | compress, |
|
|
uint8_t * | data_in, |
|
|
size_t | data_in_size, |
|
|
uint8_t * | data_out, |
|
|
size_t | data_out_size, |
|
|
size_t * | data_res_size ) |
Encode data.
- Parameters
-
| compress | Compress instance |
| data_in | pointer to input data |
| data_in_size | size of input data |
| data_out | maximum size of output data |
[in] | data_out_size | The data out size |
| data_res_size | pointer to result output data size |
- Note
- Prepends compressed stream with a header. If data is not compressible, it will be stored as is after the header.
- Returns
- true on success
◆ compress_free()
void compress_free |
( |
Compress * | compress | ) |
|
Free encoder and decoder.
- Parameters
-
compress | Compress instance |
◆ compress_icon_alloc()
CompressIcon * compress_icon_alloc |
( |
size_t | decode_buf_size | ) |
|
Initialize icon compressor.
- Parameters
-
[in] | decode_buf_size | The icon buffer size for decoding. Ensure that it's big enough for any icons that you are planning to decode with it. |
- Returns
- Compress Icon instance
◆ compress_icon_decode()
void compress_icon_decode |
( |
CompressIcon * | instance, |
|
|
const uint8_t * | icon_data, |
|
|
uint8_t ** | output ) |
Decompress icon.
- Warning
- output pointer set by this function is valid till next
compress_icon_decode
or compress_icon_free
call
- Parameters
-
| instance | The Compress Icon instance |
| icon_data | pointer to icon data. |
[in] | output | pointer to decoded buffer pointer. Data in buffer is valid till next call. If icon data was not compressed, pointer within icon_data is returned |
◆ compress_icon_free()
Free icon compressor.
- Parameters
-
instance | The Compress Icon instance |
◆ compress_stream_decoder_alloc()
Allocate stream decoder.
- Parameters
-
| type | Compression type |
[in] | config | Configuration for compression, specific to type |
| read_cb | The read callback for input (compressed) data |
| read_context | The read context |
- Returns
- CompressStreamDecoder instance
◆ compress_stream_decoder_free()
Free stream decoder.
- Parameters
-
instance | The CompressStreamDecoder instance |
◆ compress_stream_decoder_read()
bool compress_stream_decoder_read |
( |
CompressStreamDecoder * | instance, |
|
|
uint8_t * | data_out, |
|
|
size_t | data_out_size ) |
Read uncompressed data chunk from stream decoder.
- Parameters
-
| instance | The CompressStreamDecoder instance |
| data_out | The data out |
[in] | data_out_size | The data out size |
- Returns
- true on success
◆ compress_stream_decoder_rewind()
Reset stream decoder to the beginning.
- Warning
- Read callback must be repositioned by caller separately
- Parameters
-
instance | The CompressStreamDecoder instance |
- Returns
- true on success
◆ compress_stream_decoder_seek()
Seek to position in uncompressed data stream.
- Parameters
-
| instance | The CompressStreamDecoder instance |
[in] | position | The position |
- Returns
- true on success
- Warning
- Backward seeking is not supported
◆ compress_stream_decoder_tell()
Get current position in uncompressed data stream.
- Parameters
-
instance | The CompressStreamDecoder instance |
- Returns
- current position
◆ compress_config_heatshrink_default
Default configuration for heatshrink compression.
Used for image assets.