diff --git a/applications/debug/unit_tests/tests/compress/compress_test.c b/applications/debug/unit_tests/tests/compress/compress_test.c index 3e4b4d736..0f2bd7a03 100644 --- a/applications/debug/unit_tests/tests/compress/compress_test.c +++ b/applications/debug/unit_tests/tests/compress/compress_test.c @@ -182,9 +182,9 @@ static void compress_test_heatshrink_stream() { File* dest_file = storage_file_alloc(api); CompressConfigHeatshrink config = { - .base.input_buffer_sz = 128, .window_sz2 = 9, .lookahead_sz2 = 4, + .input_buffer_sz = 128, }; Compress* compress = compress_alloc(CompressTypeHeatshrink, &config); diff --git a/lib/toolbox/compress.c b/lib/toolbox/compress.c index 5736023c4..d37003bcb 100644 --- a/lib/toolbox/compress.c +++ b/lib/toolbox/compress.c @@ -17,9 +17,9 @@ #define COMPRESS_ICON_ENCODED_BUFF_SIZE (256u) const CompressConfigHeatshrink compress_config_heatshrink_default = { - .base.input_buffer_sz = COMPRESS_ICON_ENCODED_BUFF_SIZE, .window_sz2 = COMPRESS_EXP_BUFF_SIZE_LOG, .lookahead_sz2 = COMPRESS_LOOKAHEAD_BUFF_SIZE_LOG, + .input_buffer_sz = COMPRESS_ICON_ENCODED_BUFF_SIZE, }; /** Buffer size for input data */ @@ -377,7 +377,7 @@ bool compress_decode( if(!compress->decoder) { CompressConfigHeatshrink* hs_config = (CompressConfigHeatshrink*)compress->config; compress->decoder = heatshrink_decoder_alloc( - hs_config->base.input_buffer_sz, hs_config->window_sz2, hs_config->lookahead_sz2); + hs_config->input_buffer_sz, hs_config->window_sz2, hs_config->lookahead_sz2); } return compress_decode_internal( compress->decoder, data_in, data_in_size, data_out, data_out_size, data_res_size); @@ -392,13 +392,13 @@ bool compress_decode_streamed( CompressConfigHeatshrink* hs_config = (CompressConfigHeatshrink*)compress->config; if(!compress->decoder) { compress->decoder = heatshrink_decoder_alloc( - hs_config->base.input_buffer_sz, hs_config->window_sz2, hs_config->lookahead_sz2); + hs_config->input_buffer_sz, hs_config->window_sz2, hs_config->lookahead_sz2); } heatshrink_decoder_reset(compress->decoder); return compress_decode_stream_internal( compress->decoder, - hs_config->base.input_buffer_sz, + hs_config->input_buffer_sz, read_cb, read_context, write_cb, @@ -469,20 +469,20 @@ CompressStreamDecoder* compress_stream_decoder_alloc( furi_check(type < CompressTypeMAX); furi_check(config); - const CompressConfigBase* base_config = config; CompressStreamDecoder* instance = malloc(sizeof(CompressStreamDecoder)); instance->type = type; instance->stream_position = 0; - instance->decode_buffer_size = base_config->input_buffer_sz; instance->decode_buffer_position = 0; - instance->decode_buffer = malloc(base_config->input_buffer_sz); instance->read_cb = read_cb; instance->read_context = read_context; if(type == CompressTypeHeatshrink) { const CompressConfigHeatshrink* hs_config = config; + instance->decode_buffer_size = hs_config->input_buffer_sz; + instance->decode_buffer = malloc(hs_config->input_buffer_sz); + heatshrink_decoder* hs_decoder = heatshrink_decoder_alloc( - base_config->input_buffer_sz, hs_config->window_sz2, hs_config->lookahead_sz2); + hs_config->input_buffer_sz, hs_config->window_sz2, hs_config->lookahead_sz2); if(hs_decoder == NULL) { free(instance->decode_buffer); free(instance); @@ -492,6 +492,9 @@ CompressStreamDecoder* compress_stream_decoder_alloc( } else if(type == CompressTypeGzip) { const CompressConfigGzip* gz_config = config; + instance->decode_buffer_size = gz_config->input_buffer_sz; + instance->decode_buffer = malloc(gz_config->input_buffer_sz); + gzip_decoder* gz_decoder = malloc(sizeof(gzip_decoder) + gz_config->dict_sz); gz_decoder->sd = instance; gz_decoder->dict_sz = gz_config->dict_sz; diff --git a/lib/toolbox/compress.h b/lib/toolbox/compress.h index f9cca1fcf..c80167168 100644 --- a/lib/toolbox/compress.h +++ b/lib/toolbox/compress.h @@ -56,31 +56,22 @@ typedef enum { CompressTypeMAX, } CompressType; -/** Base configuration for all compression types */ -typedef struct { - uint16_t input_buffer_sz; -} CompressConfigBase; - /** Configuration for heatshrink compression */ typedef struct { - CompressConfigBase base; uint16_t window_sz2; uint16_t lookahead_sz2; + uint16_t input_buffer_sz; } CompressConfigHeatshrink; -_Static_assert(offsetof(CompressConfigHeatshrink, base) == 0, "Base must be first struct member"); - /** Default configuration for heatshrink compression. Used for image assets. */ extern const CompressConfigHeatshrink compress_config_heatshrink_default; /** Configuration for gzip compression */ typedef struct { - CompressConfigBase base; uint32_t dict_sz; + uint16_t input_buffer_sz; } CompressConfigGzip; -_Static_assert(offsetof(CompressConfigGzip, base) == 0, "Base must be first struct member"); - /** Allocate encoder and decoder * * @param type Compression type diff --git a/lib/toolbox/tar/tar_archive.c b/lib/toolbox/tar/tar_archive.c index b6e0ce807..a95e740a6 100644 --- a/lib/toolbox/tar/tar_archive.c +++ b/lib/toolbox/tar/tar_archive.c @@ -75,7 +75,6 @@ const struct mtar_ops filesystem_ops = { typedef struct { CompressType type; union { - CompressConfigBase base; // All other configs start with base CompressConfigHeatshrink heatshrink; CompressConfigGzip gzip; } config; @@ -191,7 +190,6 @@ bool tar_archive_open(TarArchive* archive, const char* path, TarOpenMode mode) { CompressedStream* compressed_stream = malloc(sizeof(CompressedStream)); compressed_stream->stream = stream; - compressed_stream->config.base.input_buffer_sz = FILE_BLOCK_SIZE; if(mode == TarOpenModeReadHeatshrink) { /* Read and validate stream header */ @@ -207,10 +205,12 @@ bool tar_archive_open(TarArchive* archive, const char* path, TarOpenMode mode) { compressed_stream->type = CompressTypeHeatshrink; compressed_stream->config.heatshrink.window_sz2 = header.window_sz2; compressed_stream->config.heatshrink.lookahead_sz2 = header.lookahead_sz2; + compressed_stream->config.heatshrink.input_buffer_sz = FILE_BLOCK_SIZE; } else if(mode == TarOpenModeReadGzip) { compressed_stream->type = CompressTypeGzip; compressed_stream->config.gzip.dict_sz = 32 * 1024; + compressed_stream->config.gzip.input_buffer_sz = FILE_BLOCK_SIZE; } compressed_stream->decoder = compress_stream_decoder_alloc(