diff --git a/lib/cmp_chunk.h b/lib/cmp_chunk.h index 114c95202440cc1c920ffd498148cea459bc8802..77df4e21f5fdb7399fb034c3ae565f394abe8580 100644 --- a/lib/cmp_chunk.h +++ b/lib/cmp_chunk.h @@ -164,8 +164,8 @@ void compress_chunk_init(uint64_t(return_timestamp)(void), uint32_t version_id); * fails (which can be tested with cmp_is_error()) */ -uint32_t compress_chunk(void *chunk, uint32_t chunk_size, - void *chunk_model, void *updated_chunk_model, +uint32_t compress_chunk(const void *chunk, uint32_t chunk_size, + const void *chunk_model, void *updated_chunk_model, uint32_t *dst, uint32_t dst_capacity, const struct cmp_par *cmp_par); diff --git a/lib/common/cmp_cal_up_model.h b/lib/common/cmp_cal_up_model.h index 3a4c3457590f9d06045d8fb299e425addd3ad942..1651153ebb18f7a3db515837f3479714a5c64bf8 100644 --- a/lib/common/cmp_cal_up_model.h +++ b/lib/common/cmp_cal_up_model.h @@ -13,7 +13,7 @@ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * - * @brief functions to calculate the update (new) model + * @brief functions to calculate the updated (new) model */ #ifndef CMP_CAL_UP_MODEL_H @@ -69,17 +69,17 @@ #define cmp_up_model(data, model, model_value, round) \ __extension__ \ ({ \ - __typeof__(data) __ret; \ + uint32_t __ret; \ switch (sizeof(data)) { \ case sizeof(uint8_t): \ case sizeof(uint16_t): \ - __ret = (__typeof__(__ret))cmp_up_model16(data, model, model_value, round); \ + __ret = cmp_up_model16(data, model, model_value, round); \ break; \ case sizeof(uint32_t): \ - __ret = (__typeof__(__ret))cmp_up_model32(data, model, model_value, round); \ + __ret = cmp_up_model32(data, model, model_value, round); \ break; \ } \ - __ret; \ + (__typeof__(data))__ret; \ }) diff --git a/lib/common/cmp_entity.c b/lib/common/cmp_entity.c index 644a7e911ed99feb176952e14e521b68eb9ecbca..f1819714e52c761bb75122d7e961c85784584c32 100644 --- a/lib/common/cmp_entity.c +++ b/lib/common/cmp_entity.c @@ -1619,75 +1619,6 @@ uint16_t cmp_ent_get_non_ima_cmp_par6(const struct cmp_entity *ent) } -/** - * @brief get the start address of the compressed data in the compression - * entity - * - * @param ent pointer to a compression entity - * - * @note this only works if the data_type in the compression entity is set - * - * @returns a pointer to buffer where the compressed data are located in entity - * on success, NULL on error - */ - -void *cmp_ent_get_data_buf(struct cmp_entity *ent) -{ - enum cmp_data_type data_type; - void *data_ptr; - - if (!ent) - return NULL; - - data_type = cmp_ent_get_data_type(ent); - - switch (data_type) { - case DATA_TYPE_IMAGETTE: - case DATA_TYPE_SAT_IMAGETTE: - case DATA_TYPE_F_CAM_IMAGETTE: - data_ptr = ent->ima.ima_cmp_dat; - break; - case DATA_TYPE_IMAGETTE_ADAPTIVE: - case DATA_TYPE_SAT_IMAGETTE_ADAPTIVE: - case DATA_TYPE_F_CAM_IMAGETTE_ADAPTIVE: - data_ptr = ent->ima.ap_ima_cmp_data; - break; - case DATA_TYPE_OFFSET: - case DATA_TYPE_BACKGROUND: - case DATA_TYPE_SMEARING: - case DATA_TYPE_S_FX: - case DATA_TYPE_S_FX_EFX: - case DATA_TYPE_S_FX_NCOB: - case DATA_TYPE_S_FX_EFX_NCOB_ECOB: - case DATA_TYPE_L_FX: - case DATA_TYPE_L_FX_EFX: - case DATA_TYPE_L_FX_NCOB: - case DATA_TYPE_L_FX_EFX_NCOB_ECOB: - case DATA_TYPE_F_FX: - case DATA_TYPE_F_FX_EFX: - case DATA_TYPE_F_FX_NCOB: - case DATA_TYPE_F_FX_EFX_NCOB_ECOB: - case DATA_TYPE_F_CAM_OFFSET: - case DATA_TYPE_F_CAM_BACKGROUND: - case DATA_TYPE_CHUNK: - data_ptr = ent->non_ima.cmp_data; - break; - case DATA_TYPE_UNKNOWN: - default: - /* default branch never reached; cmp_ent_get_data_type returns - * DATA_TYPE_UNKNOWN if data type is unknown */ - debug_print("Error: Compression data type not supported."); - return NULL; - } - - /* the uncompressed data do not have a specific entity header */ - if (cmp_ent_get_data_type_raw_bit(ent)) - return (uint8_t *)ent + GENERIC_HEADER_SIZE; - - return data_ptr; -} - - /** * @brief copy the data from a compression entity to a buffer * @@ -1758,6 +1689,47 @@ static uint32_t cmp_ent_get_hdr_size(const struct cmp_entity *ent) } +/** + * @brief get the start address of the compressed data in the compression + * entity + * + * @param ent pointer to a compression entity + * + * @note this only works if the data_type in the compression entity is set + * + * @returns a pointer to the location where the compressed data are located in entity + * on success, NULL on error + */ + +void *cmp_ent_get_data_buf(struct cmp_entity *ent) +{ + uint32_t hdr_size = cmp_ent_get_hdr_size(ent); + if (!hdr_size) + return NULL; + return (uint8_t *)ent + hdr_size; +} + + +/** + * @brief same as cmp_ent_get_data_buf but with const pointers + * + * @param ent const pointer to a compression entity + * + * @note this only works if the data_type in the compression entity is set + * + * @returns a const pointer to the location where the compressed data are located + * in entity on success, NULL on error + */ + +const void *cmp_ent_get_data_buf_const(const struct cmp_entity *ent) +{ + uint32_t hdr_size = cmp_ent_get_hdr_size(ent); + if (!hdr_size) + return NULL; + return (const uint8_t *)ent + hdr_size; +} + + /** * @brief get the size of the compressed data based on the set data product * type and compressed entity size in the compression entity diff --git a/lib/common/cmp_entity.h b/lib/common/cmp_entity.h index 8a839d9d49c953ab158eed9a0b7ebc154ff68f5e..049f0db2996bcc4c9c93d587df03f638eed06a01 100644 --- a/lib/common/cmp_entity.h +++ b/lib/common/cmp_entity.h @@ -75,7 +75,6 @@ struct imagette_header { union{ struct { uint8_t spare1; - uint8_t ima_cmp_dat[]; /**< compressed data for imagette specific header */ } __attribute__((packed)); struct { uint16_t ap1_spill_used; /**< Adaptive Spillover threshold used 1 */ @@ -84,7 +83,6 @@ struct imagette_header { uint8_t ap2_golomb_par_used; /**< Adaptive Golomb parameter used 2 */ uint8_t spare2; uint16_t spare3; - uint8_t ap_ima_cmp_data[]; /**< compressed data for adaptive imagette specific header */ } __attribute__((packed)); }; } __attribute__((packed)); @@ -110,7 +108,6 @@ struct non_imagette_header { uint32_t spill_6_used:24; /**< spillover threshold 6 used */ uint16_t cmp_par_6_used; /**< compression parameter 6 used */ uint16_t spare; - uint8_t cmp_data[]; } __attribute__((packed)); compile_time_assert(sizeof(struct non_imagette_header) == SPECIFIC_NON_IMAGETTE_HEADER_SIZE, NON_IMAGETTE_HEADER_T_SIZE_IS_NOT_CORRECT); @@ -292,6 +289,7 @@ uint16_t cmp_ent_get_non_ima_cmp_par6(const struct cmp_entity *ent); /* get function for the compressed data buffer in the entity */ void *cmp_ent_get_data_buf(struct cmp_entity *ent); +const void *cmp_ent_get_data_buf_const(const struct cmp_entity *ent); uint32_t cmp_ent_get_cmp_data_size(const struct cmp_entity *ent); int32_t cmp_ent_get_cmp_data(struct cmp_entity *ent, uint32_t *data_buf, uint32_t data_buf_size); diff --git a/lib/common/cmp_support.c b/lib/common/cmp_support.c index 1b2ccd1f49910988344b1794ac76f82270eaff2b..a4362e69c17362ba873b4ac802c7840fbf278948 100644 --- a/lib/common/cmp_support.c +++ b/lib/common/cmp_support.c @@ -414,7 +414,7 @@ int cmp_cfg_icu_buffers_is_invalid(const struct cmp_cfg *cfg) if (!cfg) return 1; - if (cfg->input_buf == NULL) { + if (cfg->src == NULL) { debug_print("Error: The data_to_compress buffer for the data to be compressed is NULL."); cfg_invalid++; } @@ -422,18 +422,18 @@ int cmp_cfg_icu_buffers_is_invalid(const struct cmp_cfg *cfg) if (cfg->samples == 0) debug_print("Warning: The samples parameter is 0. No data are compressed. This behavior may not be intended."); - if (cfg->icu_output_buf) { - if (cfg->buffer_length == 0 && cfg->samples != 0) { + if (cfg->dst) { + if (cfg->stream_size == 0 && cfg->samples != 0) { debug_print("Error: The buffer_length is set to 0. There is no space to store the compressed data."); cfg_invalid++; } - if (raw_mode_is_used(cfg->cmp_mode) && cfg->buffer_length < cfg->samples) { + if (raw_mode_is_used(cfg->cmp_mode) && cfg->stream_size < cfg->samples) { debug_print("Error: The compressed_data_len_samples is to small to hold the data form the data_to_compress."); cfg_invalid++; } - if (cfg->icu_output_buf == cfg->input_buf) { + if (cfg->dst == cfg->src) { debug_print("Error: The compressed_data buffer is the same as the data_to_compress buffer."); cfg_invalid++; } @@ -445,23 +445,23 @@ int cmp_cfg_icu_buffers_is_invalid(const struct cmp_cfg *cfg) cfg_invalid++; } - if (cfg->model_buf == cfg->input_buf) { + if (cfg->model_buf == cfg->src) { debug_print("Error: The model_of_data buffer is the same as the data_to_compress buffer."); cfg_invalid++; } - if (cfg->model_buf == cfg->icu_output_buf) { + if (cfg->model_buf == cfg->dst) { debug_print("Error: The model_of_data buffer is the same as the compressed_data buffer."); cfg_invalid++; } - if (cfg->icu_new_model_buf) { - if (cfg->icu_new_model_buf == cfg->input_buf) { + if (cfg->updated_model_buf) { + if (cfg->updated_model_buf == cfg->src) { debug_print("Error: The updated_model buffer is the same as the data_to_compress buffer."); cfg_invalid++; } - if (cfg->icu_new_model_buf == cfg->icu_output_buf) { + if (cfg->updated_model_buf == cfg->dst) { debug_print("Error: The compressed_data buffer is the same as the compressed_data buffer."); cfg_invalid++; } diff --git a/lib/common/cmp_support.h b/lib/common/cmp_support.h index 01553bdb39196a64a4aef7f336f379fef93dc38f..cc5232afcf7f413ad498686784b2227ed7c06173 100644 --- a/lib/common/cmp_support.h +++ b/lib/common/cmp_support.h @@ -143,28 +143,26 @@ enum cmp_mode { /** * @brief The cmp_cfg structure can contain the complete configuration for a SW - * compression + * (de)compression */ __extension__ struct cmp_cfg { - void *input_buf; /**< Pointer to the data to compress buffer */ - void *model_buf; /**< Pointer to the model buffer */ - void *icu_new_model_buf; /**< Pointer to the updated model buffer */ - uint32_t *icu_output_buf; /**< Pointer to the compressed data buffer */ - uint32_t samples; /**< Number of samples to compress, length of the data and model buffer - * (including the multi entity header by non-imagette data) - */ - uint32_t buffer_length; /**< Length of the compressed data buffer in number of samples */ - enum cmp_data_type data_type; /**< Compression Data Product Types */ - enum cmp_mode cmp_mode; /**< 0: raw mode - * 1: model mode with zero escape symbol mechanism - * 2: 1d differencing mode without input model with zero escape symbol mechanism - * 3: model mode with multi escape symbol mechanism - * 4: 1d differencing mode without input model multi escape symbol mechanism - */ - uint32_t model_value; /**< Model weighting parameter */ - uint32_t round; /**< lossy compression parameter */ + const void *src; /**< Pointer to the source data buffer (data to be compressed for compression; compressed data for decompression) */ + void *dst; /**< Pointer to the destination buffer (compressed data for compression; decompressed data for decompression) */ + const void *model_buf; /**< Pointer to the model buffer */ + void *updated_model_buf; /**< Pointer to the updated model buffer */ + uint32_t samples; /**< Number of samples in a collection, length of the data and model buffers */ + uint32_t stream_size; /**< Length of the compressed data buffer in number of samples */ + enum cmp_data_type data_type; /**< Compression Data Product Type */ + enum cmp_mode cmp_mode; /**< 0: raw mode + * 1: model mode with zero escape symbol mechanism + * 2: 1d differencing mode without input model with zero escape symbol mechanism + * 3: model mode with multi escape symbol mechanism + * 4: 1d differencing mode without input model multi escape symbol mechanism + */ + uint32_t model_value; /**< Model weighting parameter */ + uint32_t round; /**< lossy compression parameter */ union { uint32_t cmp_par_1; uint32_t cmp_par_imagette; /**< Golomb parameter for imagette data compression */ diff --git a/lib/decmp.h b/lib/decmp.h index f39cb37d4e46d6eb32a1f5e8e6d6966a0b9df4aa..3cdeb4c53c103b32f20aa9aa3b35e2871721d48f 100644 --- a/lib/decmp.h +++ b/lib/decmp.h @@ -22,11 +22,11 @@ #include "common/cmp_entity.h" #include "common/cmp_support.h" -int decompress_cmp_entiy(struct cmp_entity *ent, void *model_of_data, +int decompress_cmp_entiy(const struct cmp_entity *ent, const void *model_of_data, void *up_model_buf, void *decompressed_data); -int decompress_rdcu_data(uint32_t *compressed_data, const struct cmp_info *info, - uint16_t *model_of_data, uint16_t *up_model_buf, +int decompress_rdcu_data(const uint32_t *compressed_data, const struct cmp_info *info, + const uint16_t *model_of_data, uint16_t *up_model_buf, uint16_t *decompressed_data); #endif /* DECMP_H */ diff --git a/lib/decompress/decmp.c b/lib/decompress/decmp.c index b36879bd17f79eb0738b56909898b397597be8b8..37773b6776a57fcdf4d3044f77b4a28ee17da6e8 100644 --- a/lib/decompress/decmp.c +++ b/lib/decompress/decmp.c @@ -385,6 +385,22 @@ static void *get_collection_data(void *col) } +/** + * @brief return a pointer of the data of a collection + * + * @param col pointer to a collection header (can be NULL) + * + * @returns pointer to the collection data; NULL if col is NULL + */ + +static const void *get_collection_data_const(const void *col) +{ + if (col) + col = (const uint8_t *)col + COLLECTION_HDR_SIZE; + return col; +} + + /** * @brief decompress imagette data * @@ -402,21 +418,21 @@ static int decompress_imagette(const struct cmp_cfg *cfg, struct bit_decoder *de uint32_t max_data_bits; struct decoder_setup setup; uint16_t *data_buf; - uint16_t *model_buf; + const uint16_t *model_buf; uint16_t *up_model_buf; - uint16_t *next_model_p; + const uint16_t *next_model_p; uint16_t model; switch (decmp_type) { case RDCU_DECOMPRESSION: /* RDCU compresses the header like data */ - data_buf = cfg->input_buf; + data_buf = cfg->dst; model_buf = cfg->model_buf; - up_model_buf = cfg->icu_new_model_buf; + up_model_buf = cfg->updated_model_buf; break; case ICU_DECOMRESSION: - data_buf = get_collection_data(cfg->input_buf); - model_buf = get_collection_data(cfg->model_buf); - up_model_buf = get_collection_data(cfg->icu_new_model_buf); + data_buf = get_collection_data(cfg->dst); + model_buf = get_collection_data_const(cfg->model_buf); + up_model_buf = get_collection_data(cfg->updated_model_buf); break; } @@ -527,16 +543,16 @@ static int decompress_s_fx(const struct cmp_cfg *cfg, struct bit_decoder *dec) int err; uint32_t decoded_value; struct decoder_setup setup_exp_flags, setup_fx; - struct s_fx *data_buf = get_collection_data(cfg->input_buf); - struct s_fx *model_buf = get_collection_data(cfg->model_buf); + struct s_fx *data_buf = get_collection_data(cfg->dst); + const struct s_fx *model_buf = get_collection_data_const(cfg->model_buf); struct s_fx *up_model_buf; - struct s_fx *next_model_p; + const struct s_fx *next_model_p; struct s_fx model; if (model_mode_is_used(cfg->cmp_mode)) { model = model_buf[0]; next_model_p = &model_buf[1]; - up_model_buf = get_collection_data(cfg->icu_new_model_buf); + up_model_buf = get_collection_data(cfg->updated_model_buf); } else { memset(&model, 0, sizeof(model)); next_model_p = data_buf; @@ -590,14 +606,14 @@ static int decompress_s_fx_efx(const struct cmp_cfg *cfg, struct bit_decoder *de int err; uint32_t decoded_value; struct decoder_setup setup_exp_flags, setup_fx, setup_efx; - struct s_fx_efx *data_buf = get_collection_data(cfg->input_buf); - struct s_fx_efx *model_buf = get_collection_data(cfg->model_buf); + struct s_fx_efx *data_buf = get_collection_data(cfg->dst); + const struct s_fx_efx *model_buf = get_collection_data_const(cfg->model_buf); struct s_fx_efx *up_model_buf; - struct s_fx_efx *next_model_p; + const struct s_fx_efx *next_model_p; struct s_fx_efx model; if (model_mode_is_used(cfg->cmp_mode)) { - up_model_buf = get_collection_data(cfg->icu_new_model_buf); + up_model_buf = get_collection_data(cfg->updated_model_buf); model = model_buf[0]; next_model_p = &model_buf[1]; } else { @@ -662,14 +678,14 @@ static int decompress_s_fx_ncob(const struct cmp_cfg *cfg, struct bit_decoder *d int err; uint32_t decoded_value; struct decoder_setup setup_exp_flags, setup_fx, setup_ncob; - struct s_fx_ncob *data_buf = get_collection_data(cfg->input_buf); - struct s_fx_ncob *model_buf = get_collection_data(cfg->model_buf); + struct s_fx_ncob *data_buf = get_collection_data(cfg->dst); + const struct s_fx_ncob *model_buf = get_collection_data_const(cfg->model_buf); struct s_fx_ncob *up_model_buf; - struct s_fx_ncob *next_model_p; + const struct s_fx_ncob *next_model_p; struct s_fx_ncob model; if (model_mode_is_used(cfg->cmp_mode)) { - up_model_buf = get_collection_data(cfg->icu_new_model_buf); + up_model_buf = get_collection_data(cfg->updated_model_buf); model = model_buf[0]; next_model_p = &model_buf[1]; } else { @@ -741,14 +757,14 @@ static int decompress_s_fx_efx_ncob_ecob(const struct cmp_cfg *cfg, struct bit_d int err; uint32_t decoded_value; struct decoder_setup setup_exp_flags, setup_fx, setup_ncob, setup_efx, setup_ecob; - struct s_fx_efx_ncob_ecob *data_buf = get_collection_data(cfg->input_buf); - struct s_fx_efx_ncob_ecob *model_buf = get_collection_data(cfg->model_buf); + struct s_fx_efx_ncob_ecob *data_buf = get_collection_data(cfg->dst); + const struct s_fx_efx_ncob_ecob *model_buf = get_collection_data_const(cfg->model_buf); struct s_fx_efx_ncob_ecob *up_model_buf; - struct s_fx_efx_ncob_ecob *next_model_p; + const struct s_fx_efx_ncob_ecob *next_model_p; struct s_fx_efx_ncob_ecob model; if (model_mode_is_used(cfg->cmp_mode)) { - up_model_buf = get_collection_data(cfg->icu_new_model_buf); + up_model_buf = get_collection_data(cfg->updated_model_buf); model = model_buf[0]; next_model_p = &model_buf[1]; } else { @@ -845,14 +861,14 @@ static int decompress_l_fx(const struct cmp_cfg *cfg, struct bit_decoder *dec) int err; uint32_t decoded_value; struct decoder_setup setup_exp_flags, setup_fx, setup_fx_var; - struct l_fx *data_buf = get_collection_data(cfg->input_buf); - struct l_fx *model_buf = get_collection_data(cfg->model_buf); + struct l_fx *data_buf = get_collection_data(cfg->dst); + const struct l_fx *model_buf = get_collection_data_const(cfg->model_buf); struct l_fx *up_model_buf; - struct l_fx *next_model_p; + const struct l_fx *next_model_p; struct l_fx model; if (model_mode_is_used(cfg->cmp_mode)) { - up_model_buf = get_collection_data(cfg->icu_new_model_buf); + up_model_buf = get_collection_data(cfg->updated_model_buf); model = model_buf[0]; next_model_p = &model_buf[1]; } else { @@ -917,14 +933,14 @@ static int decompress_l_fx_efx(const struct cmp_cfg *cfg, struct bit_decoder *de int err; uint32_t decoded_value; struct decoder_setup setup_exp_flags, setup_fx, setup_efx, setup_fx_var; - struct l_fx_efx *data_buf = get_collection_data(cfg->input_buf); - struct l_fx_efx *model_buf = get_collection_data(cfg->model_buf); + struct l_fx_efx *data_buf = get_collection_data(cfg->dst); + const struct l_fx_efx *model_buf = get_collection_data_const(cfg->model_buf); struct l_fx_efx *up_model_buf; - struct l_fx_efx *next_model_p; + const struct l_fx_efx *next_model_p; struct l_fx_efx model; if (model_mode_is_used(cfg->cmp_mode)) { - up_model_buf = get_collection_data(cfg->icu_new_model_buf); + up_model_buf = get_collection_data(cfg->updated_model_buf); model = model_buf[0]; next_model_p = &model_buf[1]; } else { @@ -999,14 +1015,14 @@ static int decompress_l_fx_ncob(const struct cmp_cfg *cfg, struct bit_decoder *d uint32_t decoded_value; struct decoder_setup setup_exp_flags, setup_fx, setup_ncob, setup_fx_var, setup_cob_var; - struct l_fx_ncob *data_buf = get_collection_data(cfg->input_buf); - struct l_fx_ncob *model_buf = get_collection_data(cfg->model_buf); + struct l_fx_ncob *data_buf = get_collection_data(cfg->dst); + const struct l_fx_ncob *model_buf = get_collection_data_const(cfg->model_buf); struct l_fx_ncob *up_model_buf; - struct l_fx_ncob *next_model_p; + const struct l_fx_ncob *next_model_p; struct l_fx_ncob model; if (model_mode_is_used(cfg->cmp_mode)) { - up_model_buf = get_collection_data(cfg->icu_new_model_buf); + up_model_buf = get_collection_data(cfg->updated_model_buf); model = model_buf[0]; next_model_p = &model_buf[1]; } else { @@ -1104,14 +1120,14 @@ static int decompress_l_fx_efx_ncob_ecob(const struct cmp_cfg *cfg, struct bit_d uint32_t decoded_value; struct decoder_setup setup_exp_flags, setup_fx, setup_ncob, setup_efx, setup_ecob, setup_fx_var, setup_cob_var; - struct l_fx_efx_ncob_ecob *data_buf = get_collection_data(cfg->input_buf); - struct l_fx_efx_ncob_ecob *model_buf = get_collection_data(cfg->model_buf); + struct l_fx_efx_ncob_ecob *data_buf = get_collection_data(cfg->dst); + const struct l_fx_efx_ncob_ecob *model_buf = get_collection_data_const(cfg->model_buf); struct l_fx_efx_ncob_ecob *up_model_buf; - struct l_fx_efx_ncob_ecob *next_model_p; + const struct l_fx_efx_ncob_ecob *next_model_p; struct l_fx_efx_ncob_ecob model; if (model_mode_is_used(cfg->cmp_mode)) { - up_model_buf = get_collection_data(cfg->icu_new_model_buf); + up_model_buf = get_collection_data(cfg->updated_model_buf); model = model_buf[0]; next_model_p = &model_buf[1]; } else { @@ -1233,14 +1249,14 @@ static int decompress_offset(const struct cmp_cfg *cfg, struct bit_decoder *dec) int err; uint32_t decoded_value; struct decoder_setup setup_mean, setup_var; - struct offset *data_buf = get_collection_data(cfg->input_buf); - struct offset *model_buf = get_collection_data(cfg->model_buf); + struct offset *data_buf = get_collection_data(cfg->dst); + const struct offset *model_buf = get_collection_data_const(cfg->model_buf); struct offset *up_model_buf; - struct offset *next_model_p; + const struct offset *next_model_p; struct offset model; if (model_mode_is_used(cfg->cmp_mode)) { - up_model_buf = get_collection_data(cfg->icu_new_model_buf); + up_model_buf = get_collection_data(cfg->updated_model_buf); model = model_buf[0]; next_model_p = &model_buf[1]; } else { @@ -1313,14 +1329,14 @@ static int decompress_background(const struct cmp_cfg *cfg, struct bit_decoder * int err; uint32_t decoded_value; struct decoder_setup setup_mean, setup_var, setup_pix; - struct background *data_buf = get_collection_data(cfg->input_buf); - struct background *model_buf = get_collection_data(cfg->model_buf); + struct background *data_buf = get_collection_data(cfg->dst); + const struct background *model_buf = get_collection_data_const(cfg->model_buf); struct background *up_model_buf; - struct background *next_model_p; + const struct background *next_model_p; struct background model; if (model_mode_is_used(cfg->cmp_mode)) { - up_model_buf = get_collection_data(cfg->icu_new_model_buf); + up_model_buf = get_collection_data(cfg->updated_model_buf); model = model_buf[0]; next_model_p = &model_buf[1]; } else { @@ -1405,14 +1421,14 @@ static int decompress_smearing(const struct cmp_cfg *cfg, struct bit_decoder *de int err; uint32_t decoded_value; struct decoder_setup setup_mean, setup_var, setup_pix; - struct smearing *data_buf = get_collection_data(cfg->input_buf); - struct smearing *model_buf = get_collection_data(cfg->model_buf); + struct smearing *data_buf = get_collection_data(cfg->dst); + const struct smearing *model_buf = get_collection_data_const(cfg->model_buf); struct smearing *up_model_buf; - struct smearing *next_model_p; + const struct smearing *next_model_p; struct smearing model; if (model_mode_is_used(cfg->cmp_mode)) { - up_model_buf = get_collection_data(cfg->icu_new_model_buf); + up_model_buf = get_collection_data(cfg->updated_model_buf); model = model_buf[0]; next_model_p = &model_buf[1]; } else { @@ -1476,15 +1492,15 @@ static int decompress_smearing(const struct cmp_cfg *cfg, struct bit_decoder *de static int decompress_collection_hdr(const struct cmp_cfg *cfg) { - if (cfg->buffer_length < COLLECTION_HDR_SIZE) + if (cfg->stream_size < COLLECTION_HDR_SIZE) return -1; - if (cfg->icu_output_buf) { - if (cfg->input_buf) - memcpy(cfg->input_buf, cfg->icu_output_buf, COLLECTION_HDR_SIZE); + if (cfg->src) { + if (cfg->dst) + memcpy(cfg->dst, cfg->src, COLLECTION_HDR_SIZE); - if (model_mode_is_used(cfg->cmp_mode) && cfg->icu_new_model_buf) - memcpy(cfg->icu_new_model_buf, cfg->icu_output_buf, COLLECTION_HDR_SIZE); + if (model_mode_is_used(cfg->cmp_mode) && cfg->updated_model_buf) + memcpy(cfg->updated_model_buf, cfg->src, COLLECTION_HDR_SIZE); } return COLLECTION_HDR_SIZE; } @@ -1511,7 +1527,7 @@ static int decompressed_data_internal(const struct cmp_cfg *cfg, enum decmp_type if (!cfg) return -1; - if (!cfg->icu_output_buf) + if (!cfg->src) return -1; if (cmp_imagette_data_type_is_used(cfg->data_type)) { @@ -1535,24 +1551,24 @@ static int decompressed_data_internal(const struct cmp_cfg *cfg, enum decmp_type if (decmp_type == ICU_DECOMRESSION) data_size += COLLECTION_HDR_SIZE; /* data_size = cmp_cal_size_of_data(cfg->samples, cfg->data_type); */ - /* if (!cfg->input_buf || !data_size) */ + /* if (!cfg->dst || !data_size) */ /* return (int)data_size; */ if (cfg->cmp_mode == CMP_MODE_RAW) { /* if (data_size < cfg->buffer_length/CHAR_BIT) */ /* return -1; */ - if (cfg->input_buf) { + if (cfg->dst) { /* uint32_t s = cmp_col_get_size(cfg->icu_output_buf); */ /* assert(s==data_size); */ - memcpy(cfg->input_buf, cfg->icu_output_buf, data_size); + memcpy(cfg->dst, cfg->src, data_size); switch (decmp_type) { case ICU_DECOMRESSION: - if (be_to_cpu_chunk(cfg->input_buf, data_size)) + if (be_to_cpu_chunk(cfg->dst, data_size)) return -1; break; case RDCU_DECOMPRESSION: - if (be_to_cpu_data_type(cfg->input_buf, data_size, + if (be_to_cpu_data_type(cfg->dst, data_size, cfg->data_type)) return -1; break; @@ -1564,7 +1580,7 @@ static int decompressed_data_internal(const struct cmp_cfg *cfg, enum decmp_type struct bit_decoder dec; int hdr_size = 0; - if (!cfg->input_buf) + if (!cfg->dst) return (int)data_size; if (decmp_type == ICU_DECOMRESSION) { @@ -1573,8 +1589,8 @@ static int decompressed_data_internal(const struct cmp_cfg *cfg, enum decmp_type return -1; } - bit_init_decoder(&dec, (uint8_t *)cfg->icu_output_buf+hdr_size, - cfg->buffer_length-(uint32_t)hdr_size); + bit_init_decoder(&dec, (const uint8_t *)cfg->src+hdr_size, + cfg->stream_size-(uint32_t)hdr_size); switch (cfg->data_type) { case DATA_TYPE_IMAGETTE: @@ -1668,7 +1684,7 @@ static int decompressed_data_internal(const struct cmp_cfg *cfg, enum decmp_type * @returns 0 on success; otherwise error */ -static int cmp_ent_read_header(struct cmp_entity *ent, struct cmp_cfg *cfg) +static int cmp_ent_read_header(const struct cmp_entity *ent, struct cmp_cfg *cfg) { if (!cfg) return -1; @@ -1687,12 +1703,12 @@ static int cmp_ent_read_header(struct cmp_entity *ent, struct cmp_cfg *cfg) } cfg->model_value = cmp_ent_get_model_value(ent); cfg->round = cmp_ent_get_lossy_cmp_par(ent); - cfg->buffer_length = cmp_ent_get_cmp_data_size(ent); + cfg->stream_size = cmp_ent_get_cmp_data_size(ent); if (cfg->data_type == DATA_TYPE_CHUNK) { cfg->samples = 0; - if ((cfg->buffer_length < (COLLECTION_HDR_SIZE + CMP_COLLECTION_FILD_SIZE) && (cfg->cmp_mode != CMP_MODE_RAW)) || - (cfg->buffer_length < COLLECTION_HDR_SIZE && (cfg->cmp_mode == CMP_MODE_RAW))) { + if ((cfg->stream_size < (COLLECTION_HDR_SIZE + CMP_COLLECTION_FILD_SIZE) && (cfg->cmp_mode != CMP_MODE_RAW)) || + (cfg->stream_size < COLLECTION_HDR_SIZE && (cfg->cmp_mode == CMP_MODE_RAW))) { debug_print("Error: The compressed data size in the compression header is smaller than a collection header."); return -1; } @@ -1707,7 +1723,7 @@ static int cmp_ent_read_header(struct cmp_entity *ent, struct cmp_cfg *cfg) cfg->samples = org_size/sizeof(uint16_t); } - cfg->icu_output_buf = cmp_ent_get_data_buf(ent); + cfg->src = cmp_ent_get_data_buf_const(ent); if (cmp_ent_get_reserved(ent)) { debug_print("Error: The reserved field in the compressed header should be zero. Compressed data may be corrupted."); @@ -1784,7 +1800,7 @@ static int cmp_ent_read_header(struct cmp_entity *ent, struct cmp_cfg *cfg) * @return The size of the compressed collection data in bytes */ -static uint16_t get_cmp_collection_data_length(uint8_t *cmp_col) +static uint16_t get_cmp_collection_data_length(const uint8_t *cmp_col) { uint16_t cmp_data_size; /* If a non-raw mode is used to compress all collections, a @@ -1825,7 +1841,7 @@ static uint16_t get_cmp_collection_data_length(uint8_t *cmp_col) * @return The total size of the compressed collection in bytes */ -static uint32_t get_cmp_collection_size(uint8_t *cmp_col) +static uint32_t get_cmp_collection_size(const uint8_t *cmp_col) { return CMP_COLLECTION_FILD_SIZE + COLLECTION_HDR_SIZE + get_cmp_collection_data_length(cmp_col); @@ -1844,12 +1860,12 @@ static uint32_t get_cmp_collection_size(uint8_t *cmp_col) * on error */ -static int get_num_of_chunks(struct cmp_entity *ent) +static int get_num_of_chunks(const struct cmp_entity *ent) { - uint8_t *cmp_data_p = cmp_ent_get_data_buf(ent); + const uint8_t *cmp_data_p = cmp_ent_get_data_buf_const(ent); long cmp_data_size = cmp_ent_get_cmp_data_size(ent); int n = 0; - uint8_t *p = cmp_data_p; + const uint8_t *p = cmp_data_p; /* highest plausible address of compressed collection */ const uint8_t *limit_ptr = cmp_data_p + cmp_data_size - COLLECTION_HDR_SIZE; @@ -1881,22 +1897,23 @@ static int get_num_of_chunks(struct cmp_entity *ent) * decompressed data, or -1 on error. */ -static long parse_cmp_collection(uint8_t *cmp_col, int n, struct cmp_cfg *cfg, int *coll_uncompressed) +static long parse_cmp_collection(const uint8_t *cmp_col, int n, struct cmp_cfg *cfg, + int *coll_uncompressed) { int i; long decmp_pos = 0; /* position where to put the uncompressed result */ /* pointer to the collection header */ - struct collection_hdr *col_hdr = (struct collection_hdr *)(cmp_col + CMP_COLLECTION_FILD_SIZE); + const struct collection_hdr *col_hdr = + (const struct collection_hdr *)(cmp_col + CMP_COLLECTION_FILD_SIZE); uint32_t cmp_data_size; /* size of the compressed data in the collection (not including the header) */ uint16_t original_col_size; /* size of the decompressed collection data (not including the header) */ size_t sample_size; - void *void_poiter; /* used to suppress unaligned cast warning */ /* get to the collection we want to decompress */ for (i = 0; i < n; i++) { decmp_pos += cmp_col_get_size(col_hdr); cmp_col += get_cmp_collection_size(cmp_col); - col_hdr = (struct collection_hdr *)(cmp_col + CMP_COLLECTION_FILD_SIZE); + col_hdr = (const struct collection_hdr *)(cmp_col + CMP_COLLECTION_FILD_SIZE); } cmp_data_size = get_cmp_collection_data_length(cmp_col); @@ -1914,9 +1931,8 @@ static long parse_cmp_collection(uint8_t *cmp_col, int n, struct cmp_cfg *cfg, i else *coll_uncompressed = 0; - void_poiter = (void *)(col_hdr); /* unaligned cast -> reading compressed data as uint8_t * */ - cfg->icu_output_buf = void_poiter; - cfg->buffer_length = cmp_data_size + COLLECTION_HDR_SIZE; + cfg->src = col_hdr; + cfg->stream_size = cmp_data_size + COLLECTION_HDR_SIZE; cfg->data_type = convert_subservice_to_cmp_data_type(cmp_col_get_subservice(col_hdr)); sample_size = size_of_a_sample(cfg->data_type); @@ -1948,7 +1964,7 @@ static long parse_cmp_collection(uint8_t *cmp_col, int n, struct cmp_cfg *cfg, i * @returns the size of the decompressed data on success; returns negative on failure */ -int decompress_cmp_entiy(struct cmp_entity *ent, void *model_of_data, +int decompress_cmp_entiy(const struct cmp_entity *ent, const void *model_of_data, void *up_model_buf, void *decompressed_data) { struct cmp_cfg cfg; @@ -1974,7 +1990,7 @@ int decompress_cmp_entiy(struct cmp_entity *ent, void *model_of_data, uint32_t data_size = cfg.samples * sizeof(uint16_t); if (decompressed_data) { - memcpy(decompressed_data, cmp_ent_get_data_buf(ent), data_size); + memcpy(decompressed_data, cmp_ent_get_data_buf_const(ent), data_size); if (cmp_input_big_to_cpu_endianness(decompressed_data, data_size, cfg.data_type)) return -1; } @@ -1982,8 +1998,8 @@ int decompress_cmp_entiy(struct cmp_entity *ent, void *model_of_data, } cfg.model_buf = model_of_data; - cfg.icu_new_model_buf = up_model_buf; - cfg.input_buf = decompressed_data; + cfg.updated_model_buf = up_model_buf; + cfg.dst = decompressed_data; return decompressed_data_internal(&cfg, RDCU_DECOMPRESSION); } @@ -1992,14 +2008,14 @@ int decompress_cmp_entiy(struct cmp_entity *ent, void *model_of_data, if (cfg.cmp_mode == CMP_MODE_RAW) { if (decompressed_data) { - memcpy(decompressed_data, cfg.icu_output_buf, cfg.buffer_length); - cpu_to_be_chunk(decompressed_data, cfg.buffer_length); + memcpy(decompressed_data, cfg.src, cfg.stream_size); + cpu_to_be_chunk(decompressed_data, cfg.stream_size); } /* if (up_model_buf) { /1* TODO: if diff non model mode? *1/ */ /* memcpy(up_model_buf, cfg.icu_output_buf, cfg.buffer_length); */ /* cpu_to_be_chunk(up_model_buf, cfg.buffer_length); */ /* } */ - return (int)cfg.buffer_length; + return (int)cfg.stream_size; } n_chunks = get_num_of_chunks(ent); @@ -2010,23 +2026,23 @@ int decompress_cmp_entiy(struct cmp_entity *ent, void *model_of_data, int decmp_chunk_size; int col_uncompressed; struct cmp_cfg cmp_cpy = cfg; - long offset = parse_cmp_collection(cmp_ent_get_data_buf(ent), i, + long offset = parse_cmp_collection(cmp_ent_get_data_buf_const(ent), i, &cmp_cpy, &col_uncompressed); if (offset < 0) return -1; if (decompressed_data) - cmp_cpy.input_buf = (uint8_t *)decompressed_data + offset; + cmp_cpy.dst = (uint8_t *)decompressed_data + offset; if (model_of_data) - cmp_cpy.model_buf = (uint8_t *)model_of_data + offset; + cmp_cpy.model_buf = (const uint8_t *)model_of_data + offset; if (up_model_buf) - cmp_cpy.icu_new_model_buf = (uint8_t *)up_model_buf + offset; + cmp_cpy.updated_model_buf = (uint8_t *)up_model_buf + offset; if (col_uncompressed) { - if (cmp_cpy.icu_new_model_buf && model_mode_is_used(cmp_cpy.cmp_mode)) { - uint32_t s = cmp_cpy.buffer_length; - memcpy(cmp_cpy.icu_new_model_buf, cmp_cpy.icu_output_buf, s); - if (be_to_cpu_chunk(cmp_cpy.icu_new_model_buf, s)) + if (cmp_cpy.updated_model_buf && model_mode_is_used(cmp_cpy.cmp_mode)) { + uint32_t s = cmp_cpy.stream_size; + memcpy(cmp_cpy.updated_model_buf, cmp_cpy.src, s); + if (be_to_cpu_chunk(cmp_cpy.updated_model_buf, s)) return -1; } cmp_cpy.cmp_mode = CMP_MODE_RAW; @@ -2058,8 +2074,8 @@ int decompress_cmp_entiy(struct cmp_entity *ent, void *model_of_data, * @returns the size of the decompressed data on success; returns negative on failure */ -int decompress_rdcu_data(uint32_t *compressed_data, const struct cmp_info *info, - uint16_t *model_of_data, uint16_t *up_model_buf, +int decompress_rdcu_data(const uint32_t *compressed_data, const struct cmp_info *info, + const uint16_t *model_of_data, uint16_t *up_model_buf, uint16_t *decompressed_data) { @@ -2078,8 +2094,8 @@ int decompress_rdcu_data(uint32_t *compressed_data, const struct cmp_info *info, cfg.data_type = DATA_TYPE_IMAGETTE; cfg.model_buf = model_of_data; - cfg.icu_new_model_buf = up_model_buf; - cfg.input_buf = decompressed_data; + cfg.updated_model_buf = up_model_buf; + cfg.dst = decompressed_data; cfg.cmp_mode = info->cmp_mode_used; cfg.model_value = info->model_value_used; @@ -2087,8 +2103,8 @@ int decompress_rdcu_data(uint32_t *compressed_data, const struct cmp_info *info, cfg.spill_imagette = info->spill_used; cfg.cmp_par_imagette = info->golomb_par_used; cfg.samples = info->samples_used; - cfg.icu_output_buf = compressed_data; - cfg.buffer_length = (info->cmp_size+7)/8; + cfg.src = compressed_data; + cfg.stream_size = (info->cmp_size+7)/8; return decompressed_data_internal(&cfg, RDCU_DECOMPRESSION); } diff --git a/lib/icu_compress/cmp_icu.c b/lib/icu_compress/cmp_icu.c index bb8df0f5370716b2fa7376f130f2ac1d7ee40e66..3703ecd11211f3a3597c47b3a11b3e0448bfb1a6 100644 --- a/lib/icu_compress/cmp_icu.c +++ b/lib/icu_compress/cmp_icu.c @@ -80,7 +80,7 @@ struct encoder_setup { uint32_t (*encode_method_f)(uint32_t data, uint32_t model, uint32_t stream_len, const struct encoder_setup *setup); /**< pointer to the encoding function */ uint32_t *bitstream_adr; /**< start address of the compressed data bitstream */ - uint32_t max_stream_len; /**< maximum length of the bitstream/icu_output_buf in bits */ + uint32_t max_stream_len; /**< maximum length of the bitstream in bits */ uint32_t encoder_par1; /**< encoding parameter 1 */ uint32_t encoder_par2; /**< encoding parameter 2 */ uint32_t spillover_par; /**< outlier parameter */ @@ -437,18 +437,18 @@ static uint32_t encode_value(uint32_t data, uint32_t model, uint32_t stream_len, /** - * @brief calculate the maximum length of the bitstream/icu_output_buf in bits + * @brief calculate the maximum length of the bitstream in bits * @note we round down to the next 4-byte allied address because we access the * cmp_buffer in uint32_t words * - * @param buffer_length length of the icu_output_buf in bytes + * @param stream_size size of the bitstream in bytes * * @returns buffer size in bits */ -static uint32_t cmp_buffer_length_to_bits(uint32_t buffer_length) +static uint32_t cmp_stream_size_to_bits(uint32_t stream_size) { - return (buffer_length & ~0x3U) * 8; + return (stream_size & ~0x3U) * 8; } @@ -475,8 +475,8 @@ static void configure_encoder_setup(struct encoder_setup *setup, setup->encoder_par1 = cmp_par; setup->max_data_bits = max_data_bits; setup->lossy_par = lossy_par; - setup->bitstream_adr = cfg->icu_output_buf; - setup->max_stream_len = cmp_buffer_length_to_bits(cfg->buffer_length); + setup->bitstream_adr = cfg->dst; + setup->max_stream_len = cmp_stream_size_to_bits(cfg->stream_size); setup->encoder_par2 = ilog_2(cmp_par); setup->spillover_par = spillover; @@ -521,16 +521,16 @@ static uint32_t compress_imagette(const struct cmp_cfg *cfg, uint32_t stream_len struct encoder_setup setup; uint32_t max_data_bits; - uint16_t *data_buf = cfg->input_buf; - uint16_t *model_buf = cfg->model_buf; + const uint16_t *data_buf = cfg->src; + const uint16_t *model_buf = cfg->model_buf; uint16_t model = 0; - uint16_t *next_model_p = data_buf; + const uint16_t *next_model_p = data_buf; uint16_t *up_model_buf = NULL; if (model_mode_is_used(cfg->cmp_mode)) { model = get_unaligned(&model_buf[0]); next_model_p = &model_buf[1]; - up_model_buf = cfg->icu_new_model_buf; + up_model_buf = cfg->updated_model_buf; } switch (cfg->data_type) { @@ -586,17 +586,17 @@ static uint32_t compress_s_fx(const struct cmp_cfg *cfg, uint32_t stream_len) { size_t i; - struct s_fx *data_buf = cfg->input_buf; - struct s_fx *model_buf = cfg->model_buf; + const struct s_fx *data_buf = cfg->src; + const struct s_fx *model_buf = cfg->model_buf; struct s_fx *up_model_buf = NULL; - struct s_fx *next_model_p; + const struct s_fx *next_model_p; struct s_fx model; struct encoder_setup setup_exp_flag, setup_fx; if (model_mode_is_used(cfg->cmp_mode)) { model = model_buf[0]; next_model_p = &model_buf[1]; - up_model_buf = cfg->icu_new_model_buf; + up_model_buf = cfg->updated_model_buf; } else { memset(&model, 0, sizeof(model)); next_model_p = data_buf; @@ -647,17 +647,17 @@ static uint32_t compress_s_fx_efx(const struct cmp_cfg *cfg, uint32_t stream_len { size_t i; - struct s_fx_efx *data_buf = cfg->input_buf; - struct s_fx_efx *model_buf = cfg->model_buf; + const struct s_fx_efx *data_buf = cfg->src; + const struct s_fx_efx *model_buf = cfg->model_buf; struct s_fx_efx *up_model_buf = NULL; - struct s_fx_efx *next_model_p; + const struct s_fx_efx *next_model_p; struct s_fx_efx model; struct encoder_setup setup_exp_flag, setup_fx, setup_efx; if (model_mode_is_used(cfg->cmp_mode)) { model = model_buf[0]; next_model_p = &model_buf[1]; - up_model_buf = cfg->icu_new_model_buf; + up_model_buf = cfg->updated_model_buf; } else { memset(&model, 0, sizeof(model)); next_model_p = data_buf; @@ -716,17 +716,17 @@ static uint32_t compress_s_fx_ncob(const struct cmp_cfg *cfg, uint32_t stream_le { size_t i; - struct s_fx_ncob *data_buf = cfg->input_buf; - struct s_fx_ncob *model_buf = cfg->model_buf; + const struct s_fx_ncob *data_buf = cfg->src; + const struct s_fx_ncob *model_buf = cfg->model_buf; struct s_fx_ncob *up_model_buf = NULL; - struct s_fx_ncob *next_model_p; + const struct s_fx_ncob *next_model_p; struct s_fx_ncob model; struct encoder_setup setup_exp_flag, setup_fx, setup_ncob; if (model_mode_is_used(cfg->cmp_mode)) { model = model_buf[0]; next_model_p = &model_buf[1]; - up_model_buf = cfg->icu_new_model_buf; + up_model_buf = cfg->updated_model_buf; } else { memset(&model, 0, sizeof(model)); next_model_p = data_buf; @@ -791,10 +791,10 @@ static uint32_t compress_s_fx_efx_ncob_ecob(const struct cmp_cfg *cfg, uint32_t { size_t i; - struct s_fx_efx_ncob_ecob *data_buf = cfg->input_buf; - struct s_fx_efx_ncob_ecob *model_buf = cfg->model_buf; + const struct s_fx_efx_ncob_ecob *data_buf = cfg->src; + const struct s_fx_efx_ncob_ecob *model_buf = cfg->model_buf; struct s_fx_efx_ncob_ecob *up_model_buf = NULL; - struct s_fx_efx_ncob_ecob *next_model_p; + const struct s_fx_efx_ncob_ecob *next_model_p; struct s_fx_efx_ncob_ecob model; struct encoder_setup setup_exp_flag, setup_fx, setup_ncob, setup_efx, setup_ecob; @@ -802,7 +802,7 @@ static uint32_t compress_s_fx_efx_ncob_ecob(const struct cmp_cfg *cfg, uint32_t if (model_mode_is_used(cfg->cmp_mode)) { model = model_buf[0]; next_model_p = &model_buf[1]; - up_model_buf = cfg->icu_new_model_buf; + up_model_buf = cfg->updated_model_buf; } else { memset(&model, 0, sizeof(model)); next_model_p = data_buf; @@ -889,17 +889,17 @@ static uint32_t compress_l_fx(const struct cmp_cfg *cfg, uint32_t stream_len) { size_t i; - struct l_fx *data_buf = cfg->input_buf; - struct l_fx *model_buf = cfg->model_buf; + const struct l_fx *data_buf = cfg->src; + const struct l_fx *model_buf = cfg->model_buf; struct l_fx *up_model_buf = NULL; - struct l_fx *next_model_p; + const struct l_fx *next_model_p; struct l_fx model; struct encoder_setup setup_exp_flag, setup_fx, setup_fx_var; if (model_mode_is_used(cfg->cmp_mode)) { model = model_buf[0]; next_model_p = &model_buf[1]; - up_model_buf = cfg->icu_new_model_buf; + up_model_buf = cfg->updated_model_buf; } else { memset(&model, 0, sizeof(model)); next_model_p = data_buf; @@ -958,17 +958,17 @@ static uint32_t compress_l_fx_efx(const struct cmp_cfg *cfg, uint32_t stream_len { size_t i; - struct l_fx_efx *data_buf = cfg->input_buf; - struct l_fx_efx *model_buf = cfg->model_buf; + const struct l_fx_efx *data_buf = cfg->src; + const struct l_fx_efx *model_buf = cfg->model_buf; struct l_fx_efx *up_model_buf = NULL; - struct l_fx_efx *next_model_p; + const struct l_fx_efx *next_model_p; struct l_fx_efx model; struct encoder_setup setup_exp_flag, setup_fx, setup_efx, setup_fx_var; if (model_mode_is_used(cfg->cmp_mode)) { model = model_buf[0]; next_model_p = &model_buf[1]; - up_model_buf = cfg->icu_new_model_buf; + up_model_buf = cfg->updated_model_buf; } else { memset(&model, 0, sizeof(model)); next_model_p = data_buf; @@ -1035,10 +1035,10 @@ static uint32_t compress_l_fx_ncob(const struct cmp_cfg *cfg, uint32_t stream_le { size_t i; - struct l_fx_ncob *data_buf = cfg->input_buf; - struct l_fx_ncob *model_buf = cfg->model_buf; + const struct l_fx_ncob *data_buf = cfg->src; + const struct l_fx_ncob *model_buf = cfg->model_buf; struct l_fx_ncob *up_model_buf = NULL; - struct l_fx_ncob *next_model_p; + const struct l_fx_ncob *next_model_p; struct l_fx_ncob model; struct encoder_setup setup_exp_flag, setup_fx, setup_ncob, setup_fx_var, setup_cob_var; @@ -1046,7 +1046,7 @@ static uint32_t compress_l_fx_ncob(const struct cmp_cfg *cfg, uint32_t stream_le if (model_mode_is_used(cfg->cmp_mode)) { model = model_buf[0]; next_model_p = &model_buf[1]; - up_model_buf = cfg->icu_new_model_buf; + up_model_buf = cfg->updated_model_buf; } else { memset(&model, 0, sizeof(model)); next_model_p = data_buf; @@ -1134,10 +1134,10 @@ static uint32_t compress_l_fx_efx_ncob_ecob(const struct cmp_cfg *cfg, uint32_t { size_t i; - struct l_fx_efx_ncob_ecob *data_buf = cfg->input_buf; - struct l_fx_efx_ncob_ecob *model_buf = cfg->model_buf; + const struct l_fx_efx_ncob_ecob *data_buf = cfg->src; + const struct l_fx_efx_ncob_ecob *model_buf = cfg->model_buf; struct l_fx_efx_ncob_ecob *up_model_buf = NULL; - struct l_fx_efx_ncob_ecob *next_model_p; + const struct l_fx_efx_ncob_ecob *next_model_p; struct l_fx_efx_ncob_ecob model; struct encoder_setup setup_exp_flag, setup_fx, setup_ncob, setup_efx, setup_ecob, setup_fx_var, setup_cob_var; @@ -1145,7 +1145,7 @@ static uint32_t compress_l_fx_efx_ncob_ecob(const struct cmp_cfg *cfg, uint32_t if (model_mode_is_used(cfg->cmp_mode)) { model = model_buf[0]; next_model_p = &model_buf[1]; - up_model_buf = cfg->icu_new_model_buf; + up_model_buf = cfg->updated_model_buf; } else { memset(&model, 0, sizeof(model)); next_model_p = data_buf; @@ -1254,17 +1254,17 @@ static uint32_t compress_offset(const struct cmp_cfg *cfg, uint32_t stream_len) { size_t i; - struct offset *data_buf = cfg->input_buf; - struct offset *model_buf = cfg->model_buf; + const struct offset *data_buf = cfg->src; + const struct offset *model_buf = cfg->model_buf; struct offset *up_model_buf = NULL; - struct offset *next_model_p; + const struct offset *next_model_p; struct offset model; struct encoder_setup setup_mean, setup_var; if (model_mode_is_used(cfg->cmp_mode)) { model = model_buf[0]; next_model_p = &model_buf[1]; - up_model_buf = cfg->icu_new_model_buf; + up_model_buf = cfg->updated_model_buf; } else { memset(&model, 0, sizeof(model)); next_model_p = data_buf; @@ -1329,17 +1329,17 @@ static uint32_t compress_background(const struct cmp_cfg *cfg, uint32_t stream_l { size_t i; - struct background *data_buf = cfg->input_buf; - struct background *model_buf = cfg->model_buf; + const struct background *data_buf = cfg->src; + const struct background *model_buf = cfg->model_buf; struct background *up_model_buf = NULL; - struct background *next_model_p; + const struct background *next_model_p; struct background model; struct encoder_setup setup_mean, setup_var, setup_pix; if (model_mode_is_used(cfg->cmp_mode)) { model = model_buf[0]; next_model_p = &model_buf[1]; - up_model_buf = cfg->icu_new_model_buf; + up_model_buf = cfg->updated_model_buf; } else { memset(&model, 0, sizeof(model)); next_model_p = data_buf; @@ -1415,17 +1415,17 @@ static uint32_t compress_smearing(const struct cmp_cfg *cfg, uint32_t stream_len { size_t i; - struct smearing *data_buf = cfg->input_buf; - struct smearing *model_buf = cfg->model_buf; + const struct smearing *data_buf = cfg->src; + const struct smearing *model_buf = cfg->model_buf; struct smearing *up_model_buf = NULL; - struct smearing *next_model_p; + const struct smearing *next_model_p; struct smearing model; struct encoder_setup setup_mean, setup_var_mean, setup_pix; if (model_mode_is_used(cfg->cmp_mode)) { model = model_buf[0]; next_model_p = &model_buf[1]; - up_model_buf = cfg->icu_new_model_buf; + up_model_buf = cfg->updated_model_buf; } else { memset(&model, 0, sizeof(model)); next_model_p = data_buf; @@ -1514,20 +1514,20 @@ static uint32_t pad_bitstream(const struct cmp_cfg *cfg, uint32_t cmp_size) { unsigned int output_buf_len_bits, n_pad_bits; - if (!cfg->icu_output_buf) + if (!cfg->dst) return cmp_size; /* no padding in RAW mode; ALWAYS BIG-ENDIAN */ if (cfg->cmp_mode == CMP_MODE_RAW) return cmp_size; - /* maximum length of the bitstream/icu_output_buf in bits */ - output_buf_len_bits = cmp_buffer_length_to_bits(cfg->buffer_length); + /* maximum length of the bitstream in bits */ + output_buf_len_bits = cmp_stream_size_to_bits(cfg->stream_size); n_pad_bits = 32 - (cmp_size & 0x1FU); if (n_pad_bits < 32) { FORWARD_IF_ERROR(put_n_bits32(0, n_pad_bits, cmp_size, - cfg->icu_output_buf, output_buf_len_bits), ""); + cfg->dst, output_buf_len_bits), ""); } return cmp_size; @@ -1556,12 +1556,12 @@ static uint32_t compress_data_internal(const struct cmp_cfg *cfg, uint32_t strea RETURN_ERROR_IF(cfg == NULL, GENERIC, ""); RETURN_ERROR_IF(stream_len & 0x7, GENERIC, "The stream_len parameter must be a multiple of 8."); - if (raw_mode_is_used(cfg->cmp_mode) && cfg->icu_output_buf) { + if (raw_mode_is_used(cfg->cmp_mode) && cfg->dst) { uint32_t raw_stream_size = (stream_len >> 3) + cfg->samples * (uint32_t)size_of_a_sample(cfg->data_type); /* TODO: move this check to the memcpy */ - RETURN_ERROR_IF(raw_stream_size > cfg->buffer_length, SMALL_BUF_, ""); + RETURN_ERROR_IF(raw_stream_size > cfg->stream_size, SMALL_BUF_, ""); } if (cfg->samples == 0) /* nothing to compress we are done */ return stream_len; @@ -1572,10 +1572,10 @@ static uint32_t compress_data_internal(const struct cmp_cfg *cfg, uint32_t strea if (raw_mode_is_used(cfg->cmp_mode)) { uint32_t raw_size = cfg->samples * (uint32_t)size_of_a_sample(cfg->data_type); - if (cfg->icu_output_buf) { - uint8_t *p = (uint8_t *)cfg->icu_output_buf + (stream_len >> 3); + if (cfg->dst) { + uint8_t *p = (uint8_t *)cfg->dst + (stream_len >> 3); - memcpy(p, cfg->input_buf, raw_size); + memcpy(p, cfg->src, raw_size); RETURN_ERROR_IF(cpu_to_be_data_type(p, raw_size, cfg->data_type), GENERIC, ""); } bitsize += stream_len + raw_size*8; /* convert to bits */ @@ -1708,13 +1708,14 @@ static uint32_t set_cmp_col_size(uint8_t *cmp_col_size_field, uint32_t cmp_col_s * cmp_is_error()) */ -static uint32_t cmp_collection(uint8_t *col, uint8_t *model, uint8_t *updated_model, +static uint32_t cmp_collection(const uint8_t *col, + const uint8_t *model, uint8_t *updated_model, uint32_t *dst, uint32_t dst_capacity, struct cmp_cfg *cfg, uint32_t dst_size) { uint32_t dst_size_begin = dst_size; uint32_t dst_size_bits; - struct collection_hdr *col_hdr = (struct collection_hdr *)col; + const struct collection_hdr *col_hdr = (const struct collection_hdr *)col; uint16_t col_data_length = cmp_col_get_data_length(col_hdr); uint16_t sample_size; @@ -1746,12 +1747,12 @@ static uint32_t cmp_collection(uint8_t *col, uint8_t *model, uint8_t *updated_mo memcpy(updated_model, col, COLLECTION_HDR_SIZE); /* prepare the different buffers */ - cfg->icu_output_buf = dst; - cfg->input_buf = col + COLLECTION_HDR_SIZE; + cfg->dst = dst; + cfg->src = col + COLLECTION_HDR_SIZE; if (model) cfg->model_buf = model + COLLECTION_HDR_SIZE; if (updated_model) - cfg->icu_new_model_buf = updated_model + COLLECTION_HDR_SIZE; + cfg->updated_model_buf = updated_model + COLLECTION_HDR_SIZE; /* is enough capacity in the dst buffer to store the data uncompressed */ if ((!dst || dst_capacity >= dst_size + col_data_length) && @@ -1759,7 +1760,7 @@ static uint32_t cmp_collection(uint8_t *col, uint8_t *model, uint8_t *updated_mo /* we set the compressed buffer size to the data size -1 to provoke * a CMP_ERROR_SMALL_BUF_ error if the data are not compressible */ - cfg->buffer_length = dst_size + col_data_length - 1; + cfg->stream_size = dst_size + col_data_length - 1; dst_size_bits = compress_data_internal(cfg, dst_size<<3); if (cmp_get_error_code(dst_size_bits) == CMP_ERROR_SMALL_BUF_ || @@ -1768,16 +1769,16 @@ static uint32_t cmp_collection(uint8_t *col, uint8_t *model, uint8_t *updated_mo * put them uncompressed (raw) into the dst buffer */ enum cmp_mode cmp_mode_cpy = cfg->cmp_mode; - cfg->buffer_length = dst_size + col_data_length; + cfg->stream_size = dst_size + col_data_length; cfg->cmp_mode = CMP_MODE_RAW; dst_size_bits = compress_data_internal(cfg, dst_size<<3); cfg->cmp_mode = cmp_mode_cpy; /* updated model is in this case a copy of the data to compress */ - if (model_mode_is_used(cfg->cmp_mode) && cfg->icu_new_model_buf) - memcpy(cfg->icu_new_model_buf, cfg->input_buf, col_data_length); + if (model_mode_is_used(cfg->cmp_mode) && cfg->updated_model_buf) + memcpy(cfg->updated_model_buf, cfg->src, col_data_length); } } else { - cfg->buffer_length = dst_capacity; + cfg->stream_size = dst_capacity; dst_size_bits = compress_data_internal(cfg, dst_size<<3); } FORWARD_IF_ERROR(dst_size_bits, "compression failed"); @@ -2063,13 +2064,13 @@ void compress_chunk_init(uint64_t(return_timestamp)(void), uint32_t version_id) * fails (which can be tested with cmp_is_error()) */ -uint32_t compress_chunk(void *chunk, uint32_t chunk_size, - void *chunk_model, void *updated_chunk_model, +uint32_t compress_chunk(const void *chunk, uint32_t chunk_size, + const void *chunk_model, void *updated_chunk_model, uint32_t *dst, uint32_t dst_capacity, const struct cmp_par *cmp_par) { uint64_t start_timestamp = get_timestamp(); - struct collection_hdr *col = (struct collection_hdr *)chunk; + const struct collection_hdr *col = (const struct collection_hdr *)chunk; enum chunk_type chunk_type; struct cmp_cfg cfg; uint32_t cmp_size_byte; /* size of the compressed data in bytes */ @@ -2103,15 +2104,15 @@ uint32_t compress_chunk(void *chunk, uint32_t chunk_size, read_bytes <= chunk_size - COLLECTION_HDR_SIZE; read_bytes += cmp_col_get_size(col)) { - uint8_t *col_model = NULL; + const uint8_t *col_model = NULL; uint8_t *col_up_model = NULL; /* setup pointers for the next collection we want to compress */ - col = (struct collection_hdr *)((uint8_t *)chunk + read_bytes); + col = (const struct collection_hdr *)((const uint8_t *)chunk + read_bytes); if (chunk_model) - col_model = ((uint8_t *)chunk_model + read_bytes); + col_model = (const uint8_t *)chunk_model + read_bytes; if (updated_chunk_model) - col_up_model = ((uint8_t *)updated_chunk_model + read_bytes); + col_up_model = (uint8_t *)updated_chunk_model + read_bytes; RETURN_ERROR_IF(cmp_col_get_chunk_type(col) != chunk_type, CHUNK_SUBSERVICE_INCONSISTENT, ""); @@ -2119,7 +2120,7 @@ uint32_t compress_chunk(void *chunk, uint32_t chunk_size, if (read_bytes + cmp_col_get_size(col) > chunk_size) break; - cmp_size_byte = cmp_collection((uint8_t *)col, col_model, col_up_model, + cmp_size_byte = cmp_collection((const uint8_t *)col, col_model, col_up_model, dst, dst_capacity, &cfg, cmp_size_byte); FORWARD_IF_ERROR(cmp_size_byte, "error occurred when compressing the collection with offset %u", read_bytes); } @@ -2238,10 +2239,10 @@ int32_t compress_like_rdcu(const struct rdcu_cfg *rcfg, struct cmp_info *info) cfg.data_type = DATA_TYPE_IMAGETTE; - cfg.input_buf = rcfg->input_buf; + cfg.src = rcfg->input_buf; cfg.model_buf = rcfg->model_buf; cfg.samples = rcfg->samples; - cfg.buffer_length = (rcfg->buffer_length * sizeof(uint16_t)); + cfg.stream_size = (rcfg->buffer_length * sizeof(uint16_t)); cfg.cmp_mode = rcfg->cmp_mode; cfg.model_value = rcfg->model_value; cfg.round = rcfg->round; @@ -2279,8 +2280,8 @@ int32_t compress_like_rdcu(const struct rdcu_cfg *rcfg, struct cmp_info *info) cfg.cmp_par_imagette = rcfg->golomb_par; cfg.spill_imagette = rcfg->spill; - cfg.icu_new_model_buf = rcfg->icu_new_model_buf; - cfg.icu_output_buf = rcfg->icu_output_buf; + cfg.updated_model_buf = rcfg->icu_new_model_buf; + cfg.dst = rcfg->icu_output_buf; cmp_size_bit = compress_data_internal(&cfg, 0); diff --git a/programs/cmp_tool.c b/programs/cmp_tool.c index acb523968f24cdcfcfaf8acd0545df8cffbd6ea6..4cb5531a9625c1af060990947e56f5152921557b 100644 --- a/programs/cmp_tool.c +++ b/programs/cmp_tool.c @@ -46,13 +46,14 @@ static int guess_cmp_pars(struct rdcu_cfg *rcfg, const char *guess_cmp_mode, int guess_level); /* compress chunk data and write the results to files */ -static int compression_of_chunk(void *chunk, uint32_t size, void *model, struct cmp_par *chunk_par); +static int compression_of_chunk(const void *chunk, uint32_t size, void *model, + const struct cmp_par *chunk_par); /* compress the data and write the results to files */ static int compression_for_rdcu(struct rdcu_cfg *rcfg); /* decompress the data and write the results in file(s)*/ -static int decompression(struct cmp_entity *ent, uint16_t *input_model_buf); +static int decompression(const struct cmp_entity *ent, uint16_t *input_model_buf); /* create a default configuration for a compression data type */ enum cfg_default_opt {DIFF_CFG, MODEL_CFG}; @@ -649,7 +650,8 @@ static uint64_t return_timestamp(void) * @brief compress chunk data and write the results to files */ -static int compression_of_chunk(void *chunk, uint32_t size, void *model, struct cmp_par *chunk_par) +static int compression_of_chunk(const void *chunk, uint32_t size, void *model, + const struct cmp_par *chunk_par) { uint32_t bound = compress_chunk_cmp_size_bound(chunk, size); uint32_t *cmp_data; @@ -830,7 +832,7 @@ error_cleanup: * @brief decompress the data and write the results in file(s) */ -static int decompression(struct cmp_entity *ent, uint16_t *input_model_buf) +static int decompression(const struct cmp_entity *ent, uint16_t *input_model_buf) { int error; int decomp_size; diff --git a/test/bench/bench.c b/test/bench/bench.c index 35854fbe3e0d41dcfd49c37bed715a8e01eaf7b9..879370be020b3a74eee9315309d400a1b44e4406 100644 --- a/test/bench/bench.c +++ b/test/bench/bench.c @@ -170,8 +170,7 @@ static size_t local_compress_chunk(const void *src, size_t srcSize, const void * { struct cmp_par *par = (struct cmp_par *)payload; - /* FIXME: cast from 'const void *' to 'void *' drops const qualifier */ - return compress_chunk((void *)src, (uint32_t)srcSize, (void *)model, upmodel, + return compress_chunk(src, (uint32_t)srcSize, model, upmodel, dst, (uint32_t)dstSize, par); } @@ -295,11 +294,11 @@ static int bench_ref_data(void) data_set_name = "short cadence (1.4MB)"; /* reference data are stored compressed */ - decmp_size = decompress_cmp_entiy((void *)ref_short_cadence_1_cmp, + decmp_size = decompress_cmp_entiy((const void *)ref_short_cadence_1_cmp, NULL, NULL, model); CONTROL(decmp_size > 0); size = (size_t)decmp_size; - decmp_size = decompress_cmp_entiy((void *)ref_short_cadence_2_cmp, + decmp_size = decompress_cmp_entiy((const void *)ref_short_cadence_2_cmp, model, NULL, data); CONTROL(decmp_size == (int)size); diff --git a/test/cmp_data_types/test_cmp_data_types.c b/test/cmp_data_types/test_cmp_data_types.c index 94e2029f7c514ffeea09352bff6cc8a11110932e..0f43ed5f4634c47186dcd24e1991b74ea99ac4dc 100644 --- a/test/cmp_data_types/test_cmp_data_types.c +++ b/test/cmp_data_types/test_cmp_data_types.c @@ -46,12 +46,12 @@ void test_cmp_col_get_and_set(void) int err; size_t i; struct collection_hdr *col = malloc(sizeof(struct collection_hdr)); - uint8_t *u8_p = (uint8_t *)col; + const uint8_t *u8_p = (const uint8_t *)col; uint64_t timestamp; uint16_t configuration_id, collection_id, collection_length; uint8_t pkt_type, subservice, ccd_id, sequence_num; - TEST_ASSERT_TRUE(col); + TEST_ASSERT_NOT_NULL(col); memset(col, 0, sizeof(struct collection_hdr)); @@ -255,7 +255,7 @@ void test_cmp_input_big_to_cpu_endianness(void) struct offset entry[2]; } __attribute__((packed)) data = {0}; size_t i; - uint8_t *p_8 = (uint8_t *)&data; + const uint8_t *p_8 = (const uint8_t *)&data; data_type = DATA_TYPE_OFFSET; diff --git a/test/cmp_entity/test_cmp_entity.c b/test/cmp_entity/test_cmp_entity.c index 64d3a62eaa7470679d3b56fe6cf074838c66479e..4746d32e74454b3802a49e03f7c2c8142dc05dc4 100644 --- a/test/cmp_entity/test_cmp_entity.c +++ b/test/cmp_entity/test_cmp_entity.c @@ -98,7 +98,7 @@ void test_ent_version_id(void) struct cmp_entity ent = {0}; uint32_t version_id; uint32_t version_id_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; version_id = 0x12345678; error = cmp_ent_set_version_id(&ent, version_id); @@ -132,7 +132,7 @@ void test_ent_size(void) struct cmp_entity ent = {0}; uint32_t size; uint32_t size_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; size = 0x123456; error = cmp_ent_set_size(&ent, size); @@ -168,7 +168,7 @@ void test_ent_original_size(void) struct cmp_entity ent = {0}; uint32_t original_size; uint32_t original_size_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; original_size = 0x123456; error = cmp_ent_set_original_size(&ent, original_size); @@ -206,7 +206,7 @@ void test_ent_start_timestamp(void) uint64_t start_timestamp_read; uint32_t coarse_start_timestamp_read; uint16_t fine_start_timestamp_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; start_timestamp = 0x123456789ABCULL; error = cmp_ent_set_start_timestamp(&ent, start_timestamp); @@ -250,7 +250,7 @@ void test_ent_coarse_start_time(void) struct cmp_entity ent = {0}; uint32_t coarse_start_time; uint32_t coarse_start_time_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; coarse_start_time = 0x12345678; error = cmp_ent_set_coarse_start_time(&ent, coarse_start_time); @@ -284,7 +284,7 @@ void test_ent_fine_start_time(void) struct cmp_entity ent = {0}; uint16_t fine_start_time; uint16_t fine_start_time_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; fine_start_time = 0x1234; error = cmp_ent_set_fine_start_time(&ent, fine_start_time); @@ -318,7 +318,7 @@ void test_ent_end_timestamp(void) uint64_t end_timestamp_read; uint32_t coarse_end_timestamp_read; uint16_t fine_end_timestamp_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; end_timestamp = 0x123456789ABCULL; error = cmp_ent_set_end_timestamp(&ent, end_timestamp); @@ -362,7 +362,7 @@ void test_ent_coarse_end_time(void) struct cmp_entity ent = {0}; uint32_t coarse_end_time; uint32_t coarse_end_time_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; coarse_end_time = 0x12345678; error = cmp_ent_set_coarse_end_time(&ent, coarse_end_time); @@ -396,7 +396,7 @@ void test_ent_fine_end_time(void) struct cmp_entity ent = {0}; uint16_t fine_end_time; uint16_t fine_end_time_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; fine_end_time = 0x1234; error = cmp_ent_set_fine_end_time(&ent, fine_end_time); @@ -429,7 +429,7 @@ void test_cmp_ent_data_type(void) struct cmp_entity ent = {0}; enum cmp_data_type data_type, data_type_read; int raw_mode_flag, raw_mode_flag_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; /* test raw_mode */ raw_mode_flag = 1; @@ -486,7 +486,7 @@ void test_ent_cmp_mode(void) int error; struct cmp_entity ent = {0}; enum cmp_mode cmp_mode, cmp_mode_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; cmp_mode = (enum cmp_mode)0x12; error = cmp_ent_set_cmp_mode(&ent, cmp_mode); @@ -519,7 +519,7 @@ void test_ent_model_value(void) int error; struct cmp_entity ent = {0}; uint32_t model_value, model_value_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; model_value = 0x12; error = cmp_ent_set_model_value(&ent, model_value); @@ -552,7 +552,7 @@ void test_ent_model_id(void) int error; struct cmp_entity ent = {0}; uint32_t model_id, model_id_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; model_id = 0x1234; error = cmp_ent_set_model_id(&ent, model_id); @@ -586,7 +586,7 @@ void test_ent_model_counter(void) int error; struct cmp_entity ent = {0}; uint32_t model_counter, model_counter_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; model_counter = 0x12; error = cmp_ent_set_model_counter(&ent, model_counter); @@ -619,7 +619,7 @@ void test_ent_reserved(void) int error; struct cmp_entity ent = {0}; uint8_t reserved, reserved_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; reserved = 0x12; error = cmp_ent_set_reserved(&ent, reserved); @@ -649,7 +649,7 @@ void test_ent_lossy_cmp_par(void) int error; struct cmp_entity ent = {0}; uint32_t lossy_cmp_par, lossy_cmp_par_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; lossy_cmp_par = 0x1234; error = cmp_ent_set_lossy_cmp_par(&ent, lossy_cmp_par); @@ -683,7 +683,7 @@ void test_ent_ima_spill(void) int error; struct cmp_entity ent = {0}; uint32_t ima_spill, ima_spill_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; ima_spill = 0x1234; error = cmp_ent_set_ima_spill(&ent, ima_spill); @@ -717,7 +717,7 @@ void test_ent_ima_golomb_par(void) int error; struct cmp_entity ent = {0}; uint32_t ima_golomb_par, ima_golomb_par_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; ima_golomb_par = 0x12; error = cmp_ent_set_ima_golomb_par(&ent, ima_golomb_par); @@ -750,7 +750,7 @@ void test_ent_ima_ap1_spill(void) int error; struct cmp_entity ent = {0}; uint32_t ima_ap1_spill, ima_ap1_spill_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; ima_ap1_spill = 0x1234; error = cmp_ent_set_ima_ap1_spill(&ent, ima_ap1_spill); @@ -784,7 +784,7 @@ void test_ent_ima_ap1_golomb_par(void) int error; struct cmp_entity ent = {0}; uint32_t ima_ap1_golomb_par, ima_ap1_golomb_par_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; ima_ap1_golomb_par = 0x12; error = cmp_ent_set_ima_ap1_golomb_par(&ent, ima_ap1_golomb_par); @@ -817,7 +817,7 @@ void test_ent_ima_ap2_spill(void) int error; struct cmp_entity ent = {0}; uint32_t ima_ap2_spill, ima_ap2_spill_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; ima_ap2_spill = 0x1234; error = cmp_ent_set_ima_ap2_spill(&ent, ima_ap2_spill); @@ -851,7 +851,7 @@ void test_ent_ima_ap2_golomb_par(void) int error; struct cmp_entity ent = {0}; uint32_t ima_ap2_golomb_par, ima_ap2_golomb_par_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; ima_ap2_golomb_par = 0x12; error = cmp_ent_set_ima_ap2_golomb_par(&ent, ima_ap2_golomb_par); @@ -884,7 +884,7 @@ void test_ent_non_ima_spill1(void) int error; struct cmp_entity ent = {0}; uint32_t non_ima_spill1, non_ima_spill1_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; non_ima_spill1 = 0x123456; error = cmp_ent_set_non_ima_spill1(&ent, non_ima_spill1); @@ -919,7 +919,7 @@ void test_ent_non_ima_cmp_par1(void) int error; struct cmp_entity ent = {0}; uint32_t non_ima_cmp_par1, non_ima_cmp_par1_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; non_ima_cmp_par1 = 0x1234; error = cmp_ent_set_non_ima_cmp_par1(&ent, non_ima_cmp_par1); @@ -953,7 +953,7 @@ void test_ent_non_ima_spill2(void) int error; struct cmp_entity ent = {0}; uint32_t non_ima_spill2, non_ima_spill2_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; non_ima_spill2 = 0x123456; error = cmp_ent_set_non_ima_spill2(&ent, non_ima_spill2); @@ -988,7 +988,7 @@ void test_ent_non_ima_cmp_par2(void) int error; struct cmp_entity ent = {0}; uint32_t non_ima_cmp_par2, non_ima_cmp_par2_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; non_ima_cmp_par2 = 0x1234; error = cmp_ent_set_non_ima_cmp_par2(&ent, non_ima_cmp_par2); @@ -1022,7 +1022,7 @@ void test_ent_non_ima_spill3(void) int error; struct cmp_entity ent = {0}; uint32_t non_ima_spill3, non_ima_spill3_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; non_ima_spill3 = 0x123456; error = cmp_ent_set_non_ima_spill3(&ent, non_ima_spill3); @@ -1057,7 +1057,7 @@ void test_ent_non_ima_cmp_par3(void) int error; struct cmp_entity ent = {0}; uint32_t non_ima_cmp_par3, non_ima_cmp_par3_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; non_ima_cmp_par3 = 0x1234; error = cmp_ent_set_non_ima_cmp_par3(&ent, non_ima_cmp_par3); @@ -1091,7 +1091,7 @@ void test_ent_non_ima_spill4(void) int error; struct cmp_entity ent = {0}; uint32_t non_ima_spill4, non_ima_spill4_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; non_ima_spill4 = 0x123456; error = cmp_ent_set_non_ima_spill4(&ent, non_ima_spill4); @@ -1126,7 +1126,7 @@ void test_ent_non_ima_cmp_par4(void) int error; struct cmp_entity ent = {0}; uint32_t non_ima_cmp_par4, non_ima_cmp_par4_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; non_ima_cmp_par4 = 0x1234; error = cmp_ent_set_non_ima_cmp_par4(&ent, non_ima_cmp_par4); @@ -1160,7 +1160,7 @@ void test_ent_non_ima_spill5(void) int error; struct cmp_entity ent = {0}; uint32_t non_ima_spill5, non_ima_spill5_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; non_ima_spill5 = 0x123456; error = cmp_ent_set_non_ima_spill5(&ent, non_ima_spill5); @@ -1195,7 +1195,7 @@ void test_ent_non_ima_cmp_par5(void) int error; struct cmp_entity ent = {0}; uint32_t non_ima_cmp_par5, non_ima_cmp_par5_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; non_ima_cmp_par5 = 0x1234; error = cmp_ent_set_non_ima_cmp_par5(&ent, non_ima_cmp_par5); @@ -1229,7 +1229,7 @@ void test_ent_non_ima_spill6(void) int error; struct cmp_entity ent = {0}; uint32_t non_ima_spill6, non_ima_spill6_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; non_ima_spill6 = 0x123456; error = cmp_ent_set_non_ima_spill6(&ent, non_ima_spill6); @@ -1264,7 +1264,7 @@ void test_ent_non_ima_cmp_par6(void) int error; struct cmp_entity ent = {0}; uint32_t non_ima_cmp_par6, non_ima_cmp_par6_read; - uint8_t *entity_p = (uint8_t *)&ent; + const uint8_t *entity_p = (const uint8_t *)&ent; non_ima_cmp_par6 = 0x1234; error = cmp_ent_set_non_ima_cmp_par6(&ent, non_ima_cmp_par6); @@ -1296,7 +1296,7 @@ void test_cmp_ent_get_data_buf(void) { enum cmp_data_type data_type; struct cmp_entity ent = {0}; - char *adr; + const char *adr; uint32_t s, hdr_size; int error; diff --git a/test/cmp_icu/test_cmp_icu.c b/test/cmp_icu/test_cmp_icu.c index 1574976f2800bd62933409b960ca0afe44a5b250..2dfd9d426ea139d67e9f3ae413fd43dcc6983e17 100644 --- a/test/cmp_icu/test_cmp_icu.c +++ b/test/cmp_icu/test_cmp_icu.c @@ -1454,9 +1454,9 @@ void test_pad_bitstream(void) const int MAX_BIT_LEN = 96; memset(cmp_data, 0xFF, sizeof(cmp_data)); - cfg.icu_output_buf = cmp_data; + cfg.dst = cmp_data; cfg.data_type = DATA_TYPE_IMAGETTE; /* 16 bit samples */ - cfg.buffer_length = sizeof(cmp_data); /* 6 * 16 bit samples -> 3 * 32 bit */ + cfg.stream_size = sizeof(cmp_data); /* 6 * 16 bit samples -> 3 * 32 bit */ /* test negative cmp_size */ cmp_size = -1U; @@ -1479,7 +1479,7 @@ void test_pad_bitstream(void) cfg.cmp_mode = CMP_MODE_MODEL_MULTI; cmp_size = 0; /* set the first 32 bits zero no change should occur */ - cmp_size = put_n_bits32(0, 32, cmp_size, cfg.icu_output_buf, MAX_BIT_LEN); + cmp_size = put_n_bits32(0, 32, cmp_size, cfg.dst, MAX_BIT_LEN); cmp_size_return = pad_bitstream(&cfg, cmp_size); TEST_ASSERT_EQUAL_INT(cmp_size, cmp_size_return); TEST_ASSERT_EQUAL_INT(cmp_data[0], 0); @@ -1487,7 +1487,7 @@ void test_pad_bitstream(void) TEST_ASSERT_EQUAL_INT(cmp_data[2], 0xFFFFFFFF); /* set the first 33 bits zero; and checks the padding */ - cmp_size = put_n_bits32(0, 1, cmp_size, cfg.icu_output_buf, MAX_BIT_LEN); + cmp_size = put_n_bits32(0, 1, cmp_size, cfg.dst, MAX_BIT_LEN); cmp_size_return = pad_bitstream(&cfg, cmp_size); TEST_ASSERT_EQUAL_INT(cmp_size, cmp_size_return); TEST_ASSERT_EQUAL_INT(cmp_data[0], 0); @@ -1497,7 +1497,7 @@ void test_pad_bitstream(void) /* set the first 63 bits zero; and checks the padding */ cmp_data[1] = 0xFFFFFFFF; cmp_size = 32; - cmp_size = put_n_bits32(0, 31, cmp_size, cfg.icu_output_buf, MAX_BIT_LEN); + cmp_size = put_n_bits32(0, 31, cmp_size, cfg.dst, MAX_BIT_LEN); cmp_size_return = pad_bitstream(&cfg, cmp_size); TEST_ASSERT_EQUAL_INT(cmp_size, cmp_size_return); TEST_ASSERT_EQUAL_INT(cmp_data[0], 0); @@ -1506,9 +1506,9 @@ void test_pad_bitstream(void) /* error case the rest of the compressed data are to small for a 32 bit * access */ - cfg.buffer_length -= 1; + cfg.stream_size -= 1; cmp_size = 64; - cmp_size = put_n_bits32(0, 1, cmp_size, cfg.icu_output_buf, MAX_BIT_LEN); + cmp_size = put_n_bits32(0, 1, cmp_size, cfg.dst, MAX_BIT_LEN); cmp_size_return = pad_bitstream(&cfg, cmp_size); TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF_, cmp_get_error_code(cmp_size_return)); } diff --git a/test/decmp/test_decmp.c b/test/decmp/test_decmp.c index bb7bf1673ceedd65148e310b9b2abb4482c392fb..c8d379b3f9848fde1e1908f0f2d1a32713508bfd 100644 --- a/test/decmp/test_decmp.c +++ b/test/decmp/test_decmp.c @@ -1020,17 +1020,17 @@ void test_decompress_imagette_model(void) cfg.data_type = DATA_TYPE_IMAGETTE; cfg.cmp_mode = CMP_MODE_MODEL_MULTI; - cfg.input_buf = data; + cfg.dst = data; cfg.model_buf = model; - cfg.icu_new_model_buf = up_model; - cfg.icu_output_buf = cmp_data; - cfg.buffer_length = 4; + cfg.updated_model_buf = up_model; + cfg.src = cmp_data; + cfg.stream_size = 4; cfg.samples = 5; cfg.model_value = 16; cfg.cmp_par_imagette = 4; cfg.spill_imagette = 48; - bit_init_decoder(&dec, cfg.icu_output_buf, cfg.buffer_length); + bit_init_decoder(&dec, cfg.src, cfg.stream_size); err = decompress_imagette(&cfg, &dec, RDCU_DECOMPRESSION); TEST_ASSERT_FALSE(err); diff --git a/test/fuzz/fuzz_compression.c b/test/fuzz/fuzz_compression.c index e3a121853dbe4267b659acc98c0872bb5a047710..8be34ff2db2cddbc43ac90534e4b900556ce55c2 100644 --- a/test/fuzz/fuzz_compression.c +++ b/test/fuzz/fuzz_compression.c @@ -35,7 +35,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size) { struct cmp_par cmp_par; - struct cmp_par *cmp_par_ptr = NULL; + const struct cmp_par *cmp_par_ptr = NULL; const uint8_t *model = NULL; void *up_model; uint32_t *cmp_data; @@ -89,7 +89,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size) } - return_value = compress_chunk((void *)src, size, (void *)model, up_model, + return_value = compress_chunk(src, (uint32_t)size, model, up_model, cmp_data, cmp_data_capacity, cmp_par_ptr); switch (cmp_get_error_code(return_value)) { diff --git a/test/fuzz/fuzz_round_trip.c b/test/fuzz/fuzz_round_trip.c index 5fae042172b0556e7451d4827ffec6d397dea12b..b71948f0f898f3f0a63078828b9587848fedb6b0 100644 --- a/test/fuzz/fuzz_round_trip.c +++ b/test/fuzz/fuzz_round_trip.c @@ -77,7 +77,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size) use_decmp_buf = FUZZ_dataProducer_int32Range(producer, 0, 1); use_decmp_up_model = FUZZ_dataProducer_int32Range(producer, 0, 1); - return_value = chunk_round_trip(src, size, model, up_model, cmp_data, + return_value = chunk_round_trip(src, (uint32_t)size, model, up_model, cmp_data, cmp_data_capacity, cmp_par_ptr, use_decmp_buf, use_decmp_up_model); switch (cmp_get_error_code(return_value)) { diff --git a/test/test_common/chunk_round_trip.c b/test/test_common/chunk_round_trip.c index 4819ffdf9eeff80f2c9174d1fef68ebee1df1d43..b51bc48b3bfa59a55439f00b79d3b2ae1d9439ad 100644 --- a/test/test_common/chunk_round_trip.c +++ b/test/test_common/chunk_round_trip.c @@ -63,22 +63,24 @@ * @returns the return value of the compress_chunk() function */ -uint32_t chunk_round_trip(void *chunk, uint32_t chunk_size, - void *chunk_model, void *updated_chunk_model, +uint32_t chunk_round_trip(const void *chunk, uint32_t chunk_size, + const void *chunk_model, void *updated_chunk_model, uint32_t *dst, uint32_t dst_capacity, - struct cmp_par *cmp_par, + const struct cmp_par *cmp_par, int use_decmp_buf, int use_decmp_up_model) { uint32_t cmp_size; - void *model_cpy = NULL; + void *model_cpy_p = NULL; + const void *model_cpy = NULL; /* if in-place model update is used (up_model == model), the model * needed for decompression is destroyed; therefore we make a copy */ if (chunk_model) { if (updated_chunk_model == chunk_model) { - model_cpy = TEST_malloc(chunk_size); - memcpy(model_cpy, chunk_model, chunk_size); + model_cpy_p = TEST_malloc(chunk_size); + memcpy(model_cpy_p, chunk_model, chunk_size); + model_cpy = model_cpy_p; } else { model_cpy = chunk_model; } @@ -127,7 +129,7 @@ uint32_t chunk_round_trip(void *chunk, uint32_t chunk_size, } if (updated_chunk_model == chunk_model) - free(model_cpy); + free(model_cpy_p); return cmp_size; } diff --git a/test/test_common/chunk_round_trip.h b/test/test_common/chunk_round_trip.h index 96e9df807ce3b7f17675839c66cacf2f80072611..cc049d1142be9708f7f92a7349648d8213eb7451 100644 --- a/test/test_common/chunk_round_trip.h +++ b/test/test_common/chunk_round_trip.h @@ -23,11 +23,11 @@ #include "../../lib/cmp_chunk.h" -uint32_t chunk_round_trip(void *data, uint32_t data_size, - void *model, void *up_model, - uint32_t *cmp_data, uint32_t cmp_data_capacity, - struct cmp_par *cmp_par, int use_decmp_buf, int - use_decmp_up_model); +uint32_t chunk_round_trip(const void *chunk, uint32_t chunk_size, + const void *chunk_model, void *updated_chunk_model, + uint32_t *dst, uint32_t dst_capacity, + const struct cmp_par *cmp_par, int use_decmp_buf, + int use_decmp_up_model); #endif /* CHUNK_ROUND_TRIP_H */