Skip to content
Snippets Groups Projects
Commit d63effd9 authored by Dominik Loidolt's avatar Dominik Loidolt
Browse files

Add check in the cmp_cfg_icu_buffers function if the compressed data can fit...

Add check in the cmp_cfg_icu_buffers function if the compressed data can fit in a compression entity
fix some typos; disable 3 times smaller warning if cfg->icu_output_buf = NULL
parent 89aeee27
No related branches found
No related tags found
1 merge request!11decompression/compression for non-imagette data
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
struct cmp_cfg cmp_cfg_icu_create(enum cmp_data_type data_type, enum cmp_mode cmp_mode, struct cmp_cfg cmp_cfg_icu_create(enum cmp_data_type data_type, enum cmp_mode cmp_mode,
uint32_t model_value, uint32_t lossy_par); uint32_t model_value, uint32_t lossy_par);
size_t cmp_cfg_icu_buffers(struct cmp_cfg *cfg, void *data_to_compress, uint32_t cmp_cfg_icu_buffers(struct cmp_cfg *cfg, void *data_to_compress,
uint32_t data_samples, void *model_of_data, uint32_t data_samples, void *model_of_data,
void *updated_model, uint32_t *compressed_data, void *updated_model, uint32_t *compressed_data,
uint32_t compressed_data_len_samples); uint32_t compressed_data_len_samples);
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <cmp_data_types.h> #include <cmp_data_types.h>
#include <cmp_support.h> #include <cmp_support.h>
#include <cmp_icu.h> #include <cmp_icu.h>
#include <cmp_entity.h>
/* maximum used bits registry */ /* maximum used bits registry */
...@@ -118,11 +119,13 @@ struct cmp_cfg cmp_cfg_icu_create(enum cmp_data_type data_type, enum cmp_mode cm ...@@ -118,11 +119,13 @@ struct cmp_cfg cmp_cfg_icu_create(enum cmp_data_type data_type, enum cmp_mode cm
* parameters are invalid * parameters are invalid
*/ */
size_t cmp_cfg_icu_buffers(struct cmp_cfg *cfg, void *data_to_compress, uint32_t cmp_cfg_icu_buffers(struct cmp_cfg *cfg, void *data_to_compress,
uint32_t data_samples, void *model_of_data, uint32_t data_samples, void *model_of_data,
void *updated_model, uint32_t *compressed_data, void *updated_model, uint32_t *compressed_data,
uint32_t compressed_data_len_samples) uint32_t compressed_data_len_samples)
{ {
uint32_t data_size, hdr_size;
if (!cfg) { if (!cfg) {
debug_print("Error: pointer to the compression configuration structure is NULL.\n"); debug_print("Error: pointer to the compression configuration structure is NULL.\n");
return 0; return 0;
...@@ -138,7 +141,15 @@ size_t cmp_cfg_icu_buffers(struct cmp_cfg *cfg, void *data_to_compress, ...@@ -138,7 +141,15 @@ size_t cmp_cfg_icu_buffers(struct cmp_cfg *cfg, void *data_to_compress,
if (!cmp_cfg_icu_buffers_is_valid(cfg)) if (!cmp_cfg_icu_buffers_is_valid(cfg))
return 0; return 0;
return cmp_cal_size_of_data(compressed_data_len_samples, cfg->data_type); data_size = cmp_cal_size_of_data(compressed_data_len_samples, cfg->data_type);
hdr_size = cmp_ent_cal_hdr_size(cfg->data_type, cfg->cmp_mode == CMP_MODE_RAW);
if ((data_size + hdr_size) > CMP_ENTITY_MAX_SIZE) {
debug_print("Error: The buffer for the compressed data is too large to fit in a compression entity.\n");
return 0;
}
return data_size;
} }
...@@ -643,7 +654,7 @@ static int encode_value_multi(uint32_t data, uint32_t model, int stream_len, ...@@ -643,7 +654,7 @@ static int encode_value_multi(uint32_t data, uint32_t model, int stream_len,
/** /**
* @brief put the value unencoded with(setup->cmp_par_1 bits without any changes * @brief put the value unencoded with setup->cmp_par_1 bits without any changes
* in the bitstream * in the bitstream
* *
* @param value value to put unchanged in the bitstream * @param value value to put unchanged in the bitstream
...@@ -783,6 +794,7 @@ static int configure_encoder_setup(struct encoder_setupt *setup, ...@@ -783,6 +794,7 @@ static int configure_encoder_setup(struct encoder_setupt *setup,
setup->encode_method_f = &encode_value_none; setup->encode_method_f = &encode_value_none;
setup->max_data_bits = cmp_par; setup->max_data_bits = cmp_par;
break; break;
case CMP_MODE_RAW:
default: default:
return -1; return -1;
} }
...@@ -2340,7 +2352,7 @@ int icu_compress_data(const struct cmp_cfg *cfg) ...@@ -2340,7 +2352,7 @@ int icu_compress_data(const struct cmp_cfg *cfg)
memcpy(cfg->icu_output_buf, cfg->input_buf, cmp_size); memcpy(cfg->icu_output_buf, cfg->input_buf, cmp_size);
cmp_size *= CHAR_BIT; /* convert to bits */ cmp_size *= CHAR_BIT; /* convert to bits */
} else { } else {
if (cfg->samples < cfg->buffer_length/3) if (cfg->icu_output_buf && cfg->samples/3 > cfg->buffer_length)
debug_print("Warning: The size of the compressed_data buffer is 3 times smaller than the data_to_compress. This is probably unintended.\n"); debug_print("Warning: The size of the compressed_data buffer is 3 times smaller than the data_to_compress. This is probably unintended.\n");
switch (cfg->data_type) { switch (cfg->data_type) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment