Loading...
Searching...
No Matches
compress.h File Reference

LZSS based compression HAL API. More...

#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  CompressConfigHeatshrink
 Configuration for heatshrink compression. More...
 

Typedefs

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.
 

Enumerations

enum  CompressType { CompressTypeHeatshrink = 0 }
 Supported compression types.
 

Functions

CompressIconcompress_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.
 
Compresscompress_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.
 
CompressStreamDecodercompress_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.
 

Variables

const CompressConfigHeatshrink compress_config_heatshrink_default
 Default configuration for heatshrink compression.
 

Detailed Description

LZSS based compression HAL API.

Typedef Documentation

◆ CompressIoCallback

typedef int32_t(* CompressIoCallback) (void *context, uint8_t *buffer, size_t size)

I/O callback for streamed compression/decompression.

Parameters
contextuser context
bufferbuffer to read/write
sizesize of buffer
Returns
number of bytes read/written, 0 on end of stream, negative on error

Function Documentation

◆ compress_alloc()

Compress * compress_alloc ( CompressType type,
const void * config )

Allocate encoder and decoder.

Parameters
typeCompression type
[in]configConfiguration 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
compressCompress instance
data_inpointer to input data
data_in_sizesize of input data
data_outmaximum size of output data
[in]data_out_sizeThe data out size
data_res_sizepointer to result output data size
Note
Expects compressed stream with a header, as produced by compress_encode.
Returns
true on success

◆ compress_decode_streamed()

bool compress_decode_streamed ( Compress * compress,
CompressIoCallback read_cb,
void * read_context,
CompressIoCallback write_cb,
void * write_context )

Decompress streamed data.

Parameters
compressCompress instance
read_cbread callback
read_contextread callback context
write_cbwrite callback
write_contextwrite 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
compressCompress instance
data_inpointer to input data
data_in_sizesize of input data
data_outmaximum size of output data
[in]data_out_sizeThe data out size
data_res_sizepointer 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
compressCompress instance

◆ compress_icon_alloc()

CompressIcon * compress_icon_alloc ( size_t decode_buf_size)

Initialize icon compressor.

Parameters
[in]decode_buf_sizeThe 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
instanceThe Compress Icon instance
icon_datapointer to icon data.
[in]outputpointer 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()

void compress_icon_free ( CompressIcon * instance)

Free icon compressor.

Parameters
instanceThe Compress Icon instance

◆ compress_stream_decoder_alloc()

CompressStreamDecoder * compress_stream_decoder_alloc ( CompressType type,
const void * config,
CompressIoCallback read_cb,
void * read_context )

Allocate stream decoder.

Parameters
typeCompression type
[in]configConfiguration for compression, specific to type
read_cbThe read callback for input (compressed) data
read_contextThe read context
Returns
CompressStreamDecoder instance

◆ compress_stream_decoder_free()

void compress_stream_decoder_free ( CompressStreamDecoder * instance)

Free stream decoder.

Parameters
instanceThe 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
instanceThe CompressStreamDecoder instance
data_outThe data out
[in]data_out_sizeThe data out size
Returns
true on success

◆ compress_stream_decoder_rewind()

bool compress_stream_decoder_rewind ( CompressStreamDecoder * instance)

Reset stream decoder to the beginning.

Warning
Read callback must be repositioned by caller separately
Parameters
instanceThe CompressStreamDecoder instance
Returns
true on success

◆ compress_stream_decoder_seek()

bool compress_stream_decoder_seek ( CompressStreamDecoder * instance,
size_t position )

Seek to position in uncompressed data stream.

Parameters
instanceThe CompressStreamDecoder instance
[in]positionThe position
Returns
true on success
Warning
Backward seeking is not supported

◆ compress_stream_decoder_tell()

size_t compress_stream_decoder_tell ( CompressStreamDecoder * instance)

Get current position in uncompressed data stream.

Parameters
instanceThe CompressStreamDecoder instance
Returns
current position

Variable Documentation

◆ compress_config_heatshrink_default

const CompressConfigHeatshrink compress_config_heatshrink_default
extern

Default configuration for heatshrink compression.

Used for image assets.