diff --git a/examples/example_cmp_rdcu.c b/examples/example_cmp_rdcu.c index 93c76dfa469604502d9cf8ff41b1f72d86b62f6c..69b385f50afd6fb023c6f0b395cf5a69dba28a0c 100644 --- a/examples/example_cmp_rdcu.c +++ b/examples/example_cmp_rdcu.c @@ -52,12 +52,11 @@ int demo_rdcu_compression(void) int cnt = 0; /* declare configuration, status and information structure */ - struct cmp_cfg example_cfg; + struct rdcu_cfg example_rcfg; struct cmp_status example_status; struct cmp_info example_info; /* declare data buffers with some example data */ - enum cmp_data_type example_data_type = DATA_TYPE_IMAGETTE_ADAPTIVE; uint16_t data[DATA_SAMPLES] = {42, 23, 1, 13, 20, 1000}; uint16_t model[DATA_SAMPLES] = {0, 22, 3, 42, 23, 16}; @@ -66,20 +65,19 @@ int demo_rdcu_compression(void) rdcu_rmap_init(MAX_PAYLOAD_SIZE, rmap_tx, rmap_rx); /* set up compressor configuration */ - example_cfg = rdcu_cfg_create(example_data_type, CMP_DEF_IMA_MODEL_CMP_MODE, - CMP_DEF_IMA_MODEL_MODEL_VALUE, CMP_DEF_IMA_MODEL_LOSSY_PAR); - if (example_cfg.data_type == DATA_TYPE_UNKNOWN) { + if(rdcu_cfg_create(&example_rcfg, CMP_DEF_IMA_MODEL_CMP_MODE, + CMP_DEF_IMA_MODEL_MODEL_VALUE, CMP_DEF_IMA_MODEL_LOSSY_PAR)) { printf("Error occurred during rdcu_cfg_create()\n"); return -1; } - if (rdcu_cfg_buffers(&example_cfg, data, DATA_SAMPLES, model, CMP_DEF_IMA_MODEL_RDCU_DATA_ADR, + if (rdcu_cfg_buffers(&example_rcfg, data, DATA_SAMPLES, model, CMP_DEF_IMA_MODEL_RDCU_DATA_ADR, CMP_DEF_IMA_MODEL_RDCU_MODEL_ADR, CMP_DEF_IMA_MODEL_RDCU_UP_MODEL_ADR, CMP_DEF_IMA_MODEL_RDCU_BUFFER_ADR, CMP_BUF_LEN_SAMPLES)) { printf("Error occurred during rdcu_cfg_buffers()\n"); return -1; } - if (rdcu_cfg_imagette(&example_cfg, + if (rdcu_cfg_imagette(&example_rcfg, CMP_DEF_IMA_MODEL_GOLOMB_PAR, CMP_DEF_IMA_MODEL_SPILL_PAR, CMP_DEF_IMA_MODEL_AP1_GOLOMB_PAR, CMP_DEF_IMA_MODEL_AP1_SPILL_PAR, CMP_DEF_IMA_MODEL_AP2_GOLOMB_PAR, CMP_DEF_IMA_MODEL_AP2_SPILL_PAR)) { @@ -88,7 +86,7 @@ int demo_rdcu_compression(void) } /* start HW compression */ - if (rdcu_compress_data(&example_cfg)) { + if (rdcu_compress_data(&example_rcfg)) { printf("Error occurred during rdcu_compress_data()\n"); return -1; } @@ -140,16 +138,16 @@ int demo_rdcu_compression(void) } /* build a compression entity and put compressed data from the RDCU into it and print */ - if (1) { + { struct cmp_entity *cmp_ent; void *cmp_ent_data; size_t cmp_ent_size; uint32_t i, s; /* get the size of the compression entity */ - cmp_ent_size = cmp_ent_build(NULL, CMP_ASW_VERSION_ID, - START_TIME, END_TIME, MODEL_ID, MODEL_COUNTER, - &example_cfg, (int)example_info.cmp_size); + cmp_ent_size = cmp_ent_create(NULL, DATA_TYPE_IMAGETTE_ADAPTIVE, + example_info.cmp_mode_used == CMP_MODE_RAW, + cmp_bit_to_byte(example_info.cmp_size)); if (!cmp_ent_size) { printf("Error occurred during cmp_ent_build()\n"); return -1; @@ -163,14 +161,39 @@ int demo_rdcu_compression(void) } /* now let us build the compression entity */ - cmp_ent_size = cmp_ent_build(cmp_ent, CMP_ASW_VERSION_ID, - START_TIME, END_TIME, MODEL_ID, MODEL_COUNTER, - &example_cfg, (int)example_info.cmp_size); + cmp_ent_size = cmp_ent_create(cmp_ent, DATA_TYPE_IMAGETTE_ADAPTIVE, + example_info.cmp_mode_used == CMP_MODE_RAW, + cmp_bit_to_byte(example_info.cmp_size)); if (!cmp_ent_size) { printf("Error occurred during cmp_ent_build()\n"); return -1; } + if (cmp_ent_set_version_id(cmp_ent, CMP_ASW_VERSION_ID)) { + printf("Error occurred during cmp_ent_set_version_id()\n"); + return -1; + } + if (cmp_ent_set_start_timestamp(cmp_ent, START_TIME)) { + printf("Error occurred during cmp_ent_set_start_timestamp()\n"); + return -1; + } + if (cmp_ent_set_end_timestamp(cmp_ent, END_TIME)) { + printf("Error occurred during cmp_ent_set_end_timestamp()\n"); + return -1; + } + if (cmp_ent_set_model_id(cmp_ent, MODEL_ID)) { + printf("Error occurred during cmp_ent_set_model_id()\n"); + return -1; + } + if (cmp_ent_set_model_counter(cmp_ent, MODEL_COUNTER)) { + printf("Error occurred during cmp_ent_set_model_counter()\n"); + return -1; + } + if (cmp_ent_write_rdcu_cmp_pars(cmp_ent, &example_info, &example_rcfg)) { + printf("Error occurred during cmp_ent_write_rdcu_cmp_pars()\n"); + return -1; + } + /* get the address to store the compressed data in the * compression entity */ cmp_ent_data = cmp_ent_get_data_buf(cmp_ent); diff --git a/lib/cmp_icu.h b/lib/cmp_icu.h index 1dedf3ebda3cb13d2b7082fc7a7b7d34457dabac..2c431e7732eb80f2e49a43e362e37019b449db2a 100644 --- a/lib/cmp_icu.h +++ b/lib/cmp_icu.h @@ -23,6 +23,7 @@ #include "common/cmp_support.h" #define CMP_PAR_UNUSED 0 +int32_t compress_like_rdcu(const struct rdcu_cfg *rcfg, struct cmp_info *info); /* create and setup a compression configuration */ struct cmp_cfg cmp_cfg_icu_create(enum cmp_data_type data_type, enum cmp_mode cmp_mode, diff --git a/lib/cmp_rdcu.h b/lib/cmp_rdcu.h index 0f4fe20549fb0afb089ad36e810d2d8a37e546e8..dc94d29fc48597ea8c7ec053a69c057015b0c572 100644 --- a/lib/cmp_rdcu.h +++ b/lib/cmp_rdcu.h @@ -39,7 +39,7 @@ #define INVALID_ADDRESS_ERR_BIT 9 /* The bus master has received the “invalid address” status */ -int rdcu_compress_data(const struct cmp_cfg *cfg); +int rdcu_compress_data(const struct rdcu_cfg *rcfg); int rdcu_read_cmp_status(struct cmp_status *status); diff --git a/lib/common/cmp_entity.c b/lib/common/cmp_entity.c index afece91b260287c95dcd85b8a47eb06329a04e78..0b4f634cd21b50072dbd18b2e1d3882f98c8d46e 100644 --- a/lib/common/cmp_entity.c +++ b/lib/common/cmp_entity.c @@ -1930,14 +1930,15 @@ int cmp_ent_write_cmp_pars(struct cmp_entity *ent, const struct cmp_cfg *cfg, * * @param ent pointer to a compression entity * @param info pointer to a decompression information structure - * @param cfg pointer to a compression configuration structure for adaptive - * compression parameters (can be NULL if non adaptive data_type is used) + * @param rcfg pointer to a RDCU compression configuration structure for + * adaptive compression parameters (can be NULL if non adaptive data_type + * is used) * * @returns 0 on success, negative on error */ int cmp_ent_write_rdcu_cmp_pars(struct cmp_entity *ent, const struct cmp_info *info, - const struct cmp_cfg *cfg) + const struct rdcu_cfg *rcfg) { uint32_t ent_cmp_data_size; enum cmp_data_type data_type; @@ -1996,17 +1997,17 @@ int cmp_ent_write_rdcu_cmp_pars(struct cmp_entity *ent, const struct cmp_info *i * if an adaptive imagette compression data type is ent in the entity */ if (cmp_ap_imagette_data_type_is_used(data_type)) { - if (!cfg) { + if (!rcfg) { debug_print("Error: Need the compression configuration to get the adaptive parameters."); return -1; } - if (cmp_ent_set_ima_ap1_spill(ent, cfg->ap1_spill)) + if (cmp_ent_set_ima_ap1_spill(ent, rcfg->ap1_spill)) return -1; - if (cmp_ent_set_ima_ap1_golomb_par(ent, cfg->ap1_golomb_par)) + if (cmp_ent_set_ima_ap1_golomb_par(ent, rcfg->ap1_golomb_par)) return -1; - if (cmp_ent_set_ima_ap2_spill(ent, cfg->ap2_spill)) + if (cmp_ent_set_ima_ap2_spill(ent, rcfg->ap2_spill)) return -1; - if (cmp_ent_set_ima_ap2_golomb_par(ent, cfg->ap2_golomb_par)) + if (cmp_ent_set_ima_ap2_golomb_par(ent, rcfg->ap2_golomb_par)) return -1; } diff --git a/lib/common/cmp_entity.h b/lib/common/cmp_entity.h index 33c0edbfd8b3673c23f864231620fa3c944759c7..e60c097001a7d5e3d1c1eb218dcfbcf56c622683 100644 --- a/lib/common/cmp_entity.h +++ b/lib/common/cmp_entity.h @@ -172,7 +172,7 @@ int cmp_ent_write_cmp_pars(struct cmp_entity *ent, const struct cmp_cfg *cfg, * compression entity header */ int cmp_ent_write_rdcu_cmp_pars(struct cmp_entity *ent, const struct cmp_info *info, - const struct cmp_cfg *cfg); + const struct rdcu_cfg *rcfg); /* set functions for generic compression entity header */ diff --git a/lib/common/cmp_support.h b/lib/common/cmp_support.h index 38ee7e295e0e4aa3108fb07e0c0d9878ff8c68cf..bc9c98e4c2858600f80814069e2a1754e1fdc620 100644 --- a/lib/common/cmp_support.h +++ b/lib/common/cmp_support.h @@ -149,10 +149,8 @@ enum cmp_mode { /** - * @brief The cmp_cfg structure can contain the complete configuration of the HW as - * well as the SW compressor. - * @note the icu_output_buf will not be used for HW compression - * @note the rdcu_***_adr parameters are ignored for SW compression + * @brief The cmp_cfg structure can contain the complete configuration for a SW + * compression */ __extension__ @@ -165,10 +163,6 @@ struct cmp_cfg { * (including the multi entity header by non-imagette data) */ uint32_t buffer_length; /**< Length of the compressed data buffer in number of samples */ - uint32_t rdcu_data_adr; /**< RDCU data to compress start address, the first data address in the RDCU SRAM; HW only */ - uint32_t rdcu_model_adr; /**< RDCU model start address, the first model address in the RDCU SRAM */ - uint32_t rdcu_new_model_adr;/**< RDCU updated model start address, the address in the RDCU SRAM where the updated model is stored */ - uint32_t rdcu_buffer_adr; /**< RDCU compressed data start address, the first output data address in the RDCU SRAM */ 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 @@ -232,13 +226,13 @@ struct cmp_cfg { union { uint32_t cmp_par_5; - uint32_t cmp_par_ecob; /**< Compression parameter for executed center of brightness compression */ + uint32_t cmp_par_ecob; /**< Compression parameter for extended center of brightness compression */ uint32_t cmp_par_background_variance; /**< Compression parameter for auxiliary science variance compression */ uint32_t cmp_par_smearing_variance; /**< Compression parameter for auxiliary science variance compression */ }; union { uint32_t spill_par_5; - uint32_t spill_ecob; /**< Spillover threshold parameter for executed center of brightness compression */ + uint32_t spill_ecob; /**< Spillover threshold parameter for extended center of brightness compression */ uint32_t spill_background_variance; /**< Spillover threshold parameter for auxiliary science variance compression */ uint32_t spill_smearing_variance; /**< Spillover threshold parameter for auxiliary science variance compression */ }; @@ -255,7 +249,35 @@ struct cmp_cfg { uint32_t spill_background_pixels_error; /**< Spillover threshold parameter for auxiliary science outlier pixels number compression */ uint32_t spill_smearing_pixels_error; /**< Spillover threshold parameter for auxiliary science outlier pixels number compression */ }; - const struct cmp_max_used_bits *max_used_bits; /**< the maximum length of the different data products types in bits */ + const struct cmp_max_used_bits *max_used_bits; /**< the maximum length of the different data product types in bits */ +}; + + +/** + * @brief RDCU configuration structure, can contain the information of the + * RDCU configuration registers + */ + +struct rdcu_cfg { + uint16_t *input_buf; /**< Pointer to the data to compress buffer */ + uint16_t *model_buf; /**< Pointer to the model buffer */ + uint16_t *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 16-bit samples to compress, length of the data and model buffer */ + uint32_t buffer_length; /**< Length of the compressed data buffer in number of samples */ + uint32_t rdcu_data_adr; /**< RDCU data to compress start address, the first data address in the RDCU SRAM; HW only */ + uint32_t rdcu_model_adr; /**< RDCU model start address, the first model address in the RDCU SRAM; HW only */ + uint32_t rdcu_new_model_adr; /**< RDCU updated model start address, the address in the RDCU SRAM where the updated model is stored; HW only */ + uint32_t rdcu_buffer_adr; /**< RDCU compressed data start address, the first output data address in the RDCU SRAM; HW only */ + enum cmp_mode cmp_mode; /**< compression mode */ + uint32_t model_value; /**< Model weighting parameter */ + uint32_t round; /**< lossy compression parameter */ + uint32_t golomb_par; /**< Golomb parameter for imagette data compression */ + uint32_t spill; /**< Spillover threshold parameter for imagette data compression */ + uint32_t ap1_golomb_par; /**< Adaptive 2 spillover threshold for imagette data; HW only */ + uint32_t ap1_spill; /**< Adaptive 2 Golomb parameter; HW only */ + uint32_t ap2_golomb_par; /**< Adaptive 2 spillover threshold for imagette data; HW only */ + uint32_t ap2_spill; /**< Adaptive 2 Golomb parameter; HW only */ }; diff --git a/lib/icu_compress/cmp_icu.c b/lib/icu_compress/cmp_icu.c index ef2fd3347f17f6764a19b537caa6fb8144857335..7b437d7df20675d117161b98dde7ebe8ba623f3d 100644 --- a/lib/icu_compress/cmp_icu.c +++ b/lib/icu_compress/cmp_icu.c @@ -2819,3 +2819,92 @@ uint32_t compress_chunk_set_model_id_and_counter(void *dst, uint32_t dst_size, return dst_size; } + + +/** + * @brief compress data the same way as the RDCU HW compressor + * + * @param rcfg pointer to a RDCU compression configuration (created with the + * rdcu_cfg_create() function, set up with the rdcu_cfg_buffers() + * and rdcu_cfg_imagette() functions) + * @param info pointer to a compression information structure contains the + * metadata of a compression (can be NULL) + * + * @returns the bit length of the bitstream on success; negative on error, + * CMP_ERROR_SMALL_BUF (-2) if the compressed data buffer is too small to + * hold the whole compressed data + * + * @warning only the small buffer error in the info.cmp_err field is implemented + */ + +int32_t compress_like_rdcu(const struct rdcu_cfg *rcfg, struct cmp_info *info) +{ + struct cmp_cfg cfg = {0}; + uint32_t cmp_size_bit; + + if (info) + memset(info, 0, sizeof(*info)); + + if (!rcfg) + return (int32_t)compress_data_internal(NULL, 0); + + cfg.data_type = DATA_TYPE_IMAGETTE; + cfg.max_used_bits = &MAX_USED_BITS_SAFE; + + cfg.input_buf = rcfg->input_buf; + cfg.model_buf = rcfg->model_buf; + cfg.samples = rcfg->samples; + cfg.buffer_length = (rcfg->buffer_length * sizeof(uint16_t)); + cfg.cmp_mode = rcfg->cmp_mode; + cfg.model_value = rcfg->model_value; + cfg.round = rcfg->round; + + if (info) { + info->cmp_err = 0; + info->cmp_mode_used = (uint8_t)rcfg->cmp_mode; + info->model_value_used = (uint8_t)rcfg->model_value; + info->round_used = (uint8_t)rcfg->round; + info->spill_used = rcfg->spill; + info->golomb_par_used = rcfg->golomb_par; + info->samples_used = rcfg->samples; + info->rdcu_new_model_adr_used = rcfg->rdcu_new_model_adr; + info->rdcu_cmp_adr_used = rcfg->rdcu_buffer_adr; + + if (rcfg->ap1_golomb_par && rcfg->ap1_golomb_par) { + uint32_t ap1_cmp_size, ap2_cmp_size; + + cfg.cmp_par_imagette = rcfg->ap1_golomb_par; + cfg.spill_imagette = rcfg->ap1_spill; + ap1_cmp_size = compress_data_internal(&cfg, 0); + if (cmp_is_error(ap1_cmp_size) || ap1_cmp_size > INT32_MAX) + ap1_cmp_size = 0; + + cfg.cmp_par_imagette = rcfg->ap2_golomb_par; + cfg.spill_imagette = rcfg->ap2_spill; + ap2_cmp_size = compress_data_internal(&cfg, 0); + if (cmp_is_error(ap2_cmp_size) || ap2_cmp_size > INT32_MAX) + ap2_cmp_size = 0; + + info->ap1_cmp_size = ap1_cmp_size; + info->ap2_cmp_size = ap2_cmp_size; + } + } + + 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; + + cmp_size_bit = compress_data_internal(&cfg, 0); + + if (info) { + if (cmp_get_error_code(cmp_size_bit) == CMP_ERROR_SMALL_BUF_) + info->cmp_err |= 1UL << 0;/* SMALL_BUFFER_ERR_BIT;*/ /* set small buffer error */ + if (cmp_is_error(cmp_size_bit)) + info->cmp_size = 0; + else + info->cmp_size = cmp_size_bit; + } + + return (int32_t)cmp_size_bit; +} diff --git a/lib/rdcu_compress/cmp_rdcu.c b/lib/rdcu_compress/cmp_rdcu.c index ec99dc7817ba63d027069e9da18ddb7a9588445f..9635570f45741b3f72efa9ae3acb374010d73ced 100644 --- a/lib/rdcu_compress/cmp_rdcu.c +++ b/lib/rdcu_compress/cmp_rdcu.c @@ -104,15 +104,15 @@ int rdcu_interrupt_compression(void) /** * @brief set up RDCU compression register * - * @param cfg pointer to a compression configuration contains all parameters - * required for compression + * @param rcfg pointer to a compression configuration contains all parameters + * required for a RDCU compression * * @returns 0 on success, error otherwise */ -static int rdcu_set_compression_register(const struct cmp_cfg *cfg) +static int rdcu_set_compression_register(const struct rdcu_cfg *rcfg) { - if (rdcu_cmp_cfg_is_invalid(cfg)) + if (rdcu_cmp_cfg_is_invalid(rcfg)) return -1; #if 1 /* @@ -130,39 +130,39 @@ static int rdcu_set_compression_register(const struct cmp_cfg *cfg) /* first, set compression parameters in local mirror registers */ - if (rdcu_set_compression_mode(cfg->cmp_mode)) + if (rdcu_set_compression_mode(rcfg->cmp_mode)) return -1; - if (rdcu_set_golomb_param(cfg->golomb_par)) + if (rdcu_set_golomb_param(rcfg->golomb_par)) return -1; - if (rdcu_set_spillover_threshold(cfg->spill)) + if (rdcu_set_spillover_threshold(rcfg->spill)) return -1; - if (rdcu_set_weighting_param(cfg->model_value)) + if (rdcu_set_weighting_param(rcfg->model_value)) return -1; - if (rdcu_set_noise_bits_rounded(cfg->round)) + if (rdcu_set_noise_bits_rounded(rcfg->round)) return -1; - if (rdcu_set_adaptive_1_golomb_param(cfg->ap1_golomb_par)) + if (rdcu_set_adaptive_1_golomb_param(rcfg->ap1_golomb_par)) return -1; - if (rdcu_set_adaptive_1_spillover_threshold(cfg->ap1_spill)) + if (rdcu_set_adaptive_1_spillover_threshold(rcfg->ap1_spill)) return -1; - if (rdcu_set_adaptive_2_golomb_param(cfg->ap2_golomb_par)) + if (rdcu_set_adaptive_2_golomb_param(rcfg->ap2_golomb_par)) return -1; - if (rdcu_set_adaptive_2_spillover_threshold(cfg->ap2_spill)) + if (rdcu_set_adaptive_2_spillover_threshold(rcfg->ap2_spill)) return -1; - if (rdcu_set_data_start_addr(cfg->rdcu_data_adr)) + if (rdcu_set_data_start_addr(rcfg->rdcu_data_adr)) return -1; - if (rdcu_set_model_start_addr(cfg->rdcu_model_adr)) + if (rdcu_set_model_start_addr(rcfg->rdcu_model_adr)) return -1; - if (rdcu_set_num_samples(cfg->samples)) + if (rdcu_set_num_samples(rcfg->samples)) return -1; - if (rdcu_set_new_model_start_addr(cfg->rdcu_new_model_adr)) + if (rdcu_set_new_model_start_addr(rcfg->rdcu_new_model_adr)) return -1; - if (rdcu_set_compr_data_buf_start_addr(cfg->rdcu_buffer_adr)) + if (rdcu_set_compr_data_buf_start_addr(rcfg->rdcu_buffer_adr)) return -1; - if (rdcu_set_compr_data_buf_len(cfg->buffer_length)) + if (rdcu_set_compr_data_buf_len(rcfg->buffer_length)) return -1; /* now sync the configuration registers to the RDCU... */ @@ -229,38 +229,38 @@ int rdcu_start_compression(void) /** * @brief set up RDCU SRAM for compression * - * @param cfg pointer to a compression configuration + * @param rcfg pointer to a RDCU compression configuration * * @returns 0 on success, error otherwise */ -static int rdcu_transfer_sram(const struct cmp_cfg *cfg) +static int rdcu_transfer_sram(const struct rdcu_cfg *rcfg) { - if (cfg->input_buf != NULL) { + if (rcfg->input_buf != NULL) { /* round up needed size must be a multiple of 4 bytes */ - uint32_t size = (cfg->samples * 2 + 3) & ~3U; + uint32_t size = (rcfg->samples * 2 + 3) & ~3U; /* now set the data in the local mirror... */ - if (rdcu_write_sram_16(cfg->input_buf, cfg->rdcu_data_adr, cfg->samples * 2) < 0) { + if (rdcu_write_sram_16(rcfg->input_buf, rcfg->rdcu_data_adr, rcfg->samples * 2) < 0) { debug_print("Error: The data to be compressed cannot be transferred to the SRAM of the RDCU."); return -1; } - if (rdcu_sync_mirror_to_sram(cfg->rdcu_data_adr, size, rdcu_get_data_mtu())) { + if (rdcu_sync_mirror_to_sram(rcfg->rdcu_data_adr, size, rdcu_get_data_mtu())) { debug_print("Error: The data to be compressed cannot be transferred to the SRAM of the RDCU."); return -1; } } /*...and the model when needed */ - if (cfg->model_buf != NULL) { + if (rcfg->model_buf != NULL) { /* set model only when model mode is used */ - if (model_mode_is_used(cfg->cmp_mode)) { + if (model_mode_is_used(rcfg->cmp_mode)) { /* round up needed size must be a multiple of 4 bytes */ - uint32_t size = (cfg->samples * 2 + 3) & ~3U; + uint32_t size = (rcfg->samples * 2 + 3) & ~3U; /* set the model in the local mirror... */ - if (rdcu_write_sram_16(cfg->model_buf, cfg->rdcu_model_adr, cfg->samples * 2) < 0) { + if (rdcu_write_sram_16(rcfg->model_buf, rcfg->rdcu_model_adr, rcfg->samples * 2) < 0) { debug_print("Error: The model buffer cannot be transferred to the SRAM of the RDCU."); return -1; } - if (rdcu_sync_mirror_to_sram(cfg->rdcu_model_adr, size, rdcu_get_data_mtu())) { + if (rdcu_sync_mirror_to_sram(rcfg->rdcu_model_adr, size, rdcu_get_data_mtu())) { debug_print("Error: The model buffer cannot be transferred to the SRAM of the RDCU."); return -1; } @@ -277,23 +277,23 @@ static int rdcu_transfer_sram(const struct cmp_cfg *cfg) /** * @brief compressing data with the help of the RDCU hardware compressor * - * @param cfg configuration contains all parameters required for compression + * @param rcfg RDCU configuration contains all parameters required for compression * * @note Before the rdcu_compress function can be used, an initialisation of * the RMAP library is required. This is achieved with the functions * rdcu_ctrl_init() and rdcu_rmap_init(). - * @note The validity of the cfg structure is checked before the compression is + * @note The validity of the rcfg structure is checked before the compression is * started. * * @returns 0 on success, error otherwise */ -int rdcu_compress_data(const struct cmp_cfg *cfg) +int rdcu_compress_data(const struct rdcu_cfg *rcfg) { - if (rdcu_set_compression_register(cfg)) + if (rdcu_set_compression_register(rcfg)) return -1; - if (rdcu_transfer_sram(cfg)) + if (rdcu_transfer_sram(rcfg)) return -1; if (rdcu_start_compression()) @@ -498,19 +498,19 @@ void rdcu_disable_interrput_signal(void) /** * @brief inject a SRAM edac multi bit error into the RDCU SRAM * - * @param cfg configuration to inject error + * @param rcfg configuration to inject error * @param addr SRAM address to inject edac error */ -int rdcu_inject_edac_error(const struct cmp_cfg *cfg, uint32_t addr) +int rdcu_inject_edac_error(const struct rdcu_cfg *rcfg, uint32_t addr) { uint32_t sub_chip_die_addr; uint8_t buf[4] = {0}; - if (rdcu_set_compression_register(cfg)) + if (rdcu_set_compression_register(rcfg)) return -1; - if (rdcu_transfer_sram(cfg)) + if (rdcu_transfer_sram(rcfg)) return -1; /* disable edac */ @@ -597,7 +597,7 @@ int rdcu_inject_edac_error(const struct cmp_cfg *cfg, uint32_t addr) debug_print("Error: sub_chip_die_addr unexpected!"); return -1; } - if (1 == rdcu_edac_get_bypass_status()) { + if (rdcu_edac_get_bypass_status() == 1) { debug_print("Error: bypass status unexpected!"); return -1; } @@ -610,58 +610,57 @@ int rdcu_inject_edac_error(const struct cmp_cfg *cfg, uint32_t addr) * @brief compressing data with the help of the RDCU hardware compressor; read * data from the last compression before starting compression * - * @param cfg configuration contains all parameters required for compression + * @param rcfg configuration contains all parameters required for compression * @param last_info compression information of last compression run * * @note when using the 1d-differencing mode or the raw mode (cmp_mode = 0,2,4), * the model parameters (model_value, model_buf, rdcu_model_adr) are ignored * @note the overlapping of the different rdcu buffers is not checked - * @note the validity of the cfg structure is checked before the compression is + * @note the validity of the rcfg structure is checked before the compression is * started * * @returns 0 on success, error otherwise */ -int rdcu_compress_data_parallel(const struct cmp_cfg *cfg, +int rdcu_compress_data_parallel(const struct rdcu_cfg *rcfg, const struct cmp_info *last_info) { uint32_t samples_4byte; - if (!cfg) + if (!rcfg) return -1; if (!last_info) - return rdcu_compress_data(cfg); + return rdcu_compress_data(rcfg); if (last_info->cmp_err) return -1; - rdcu_set_compression_register(cfg); + rdcu_set_compression_register(rcfg); /* round up needed size must be a multiple of 4 bytes */ - samples_4byte = (cfg->samples * IMA_SAM2BYT + 3) & ~3U; + samples_4byte = (rcfg->samples * IMA_SAM2BYT + 3) & ~3U; - if (cfg->input_buf != NULL) { + if (rcfg->input_buf != NULL) { uint32_t cmp_size_4byte; /* now set the data in the local mirror... */ - if (rdcu_write_sram_16(cfg->input_buf, cfg->rdcu_data_adr, - cfg->samples * IMA_SAM2BYT) < 0) + if (rdcu_write_sram_16(rcfg->input_buf, rcfg->rdcu_data_adr, + rcfg->samples * IMA_SAM2BYT) < 0) return -1; /* calculate the need bytes for the bitstream */ cmp_size_4byte = cmp_bit_to_4byte(last_info->cmp_size); - /* parallel read compressed data and write input data from sram - * to mirror */ + /* parallel read compressed data and write input data from sram to mirror */ if (rdcu_sync_sram_mirror_parallel(last_info->rdcu_cmp_adr_used, - cmp_size_4byte, cfg->rdcu_data_adr, samples_4byte, + cmp_size_4byte, rcfg->rdcu_data_adr, samples_4byte, rdcu_get_data_mtu())) return -1; /* wait for it */ rdcu_syncing(); - if (cfg->icu_output_buf) { - if (rdcu_read_sram(cfg->icu_output_buf, + if (rcfg->icu_output_buf) { + if (rdcu_read_sram(rcfg->icu_output_buf, last_info->rdcu_cmp_adr_used, cmp_size_4byte)) return -1; @@ -671,46 +670,46 @@ int rdcu_compress_data_parallel(const struct cmp_cfg *cfg, } /* read model and write model in parallel */ - if (cfg->model_buf && model_mode_is_used(cfg->cmp_mode) && model_mode_is_used(last_info->cmp_mode_used)) { - if (cfg->rdcu_model_adr == last_info->rdcu_new_model_adr_used && - cfg->samples == last_info->samples_used) { + if (rcfg->model_buf && model_mode_is_used(rcfg->cmp_mode) && model_mode_is_used(last_info->cmp_mode_used)) { + if (rcfg->rdcu_model_adr == last_info->rdcu_new_model_adr_used && + rcfg->samples == last_info->samples_used) { debug_print("The last updated model buffer and the current model buffer overlap exactly in the SRAM of the RDCU. Skip model transfer."); } else { uint32_t new_model_size_4byte; /* set the model in the local mirror... */ - if (rdcu_write_sram_16(cfg->model_buf, cfg->rdcu_model_adr, - cfg->samples * IMA_SAM2BYT) < 0) + if (rdcu_write_sram_16(rcfg->model_buf, rcfg->rdcu_model_adr, + rcfg->samples * IMA_SAM2BYT) < 0) return -1; new_model_size_4byte = last_info->samples_used * IMA_SAM2BYT; if (rdcu_sync_sram_mirror_parallel(last_info->rdcu_new_model_adr_used, (new_model_size_4byte+3) & ~0x3U, - cfg->rdcu_model_adr, + rcfg->rdcu_model_adr, samples_4byte, rdcu_get_data_mtu())) return -1; /* wait for it */ rdcu_syncing(); - if (cfg->icu_new_model_buf) { - if (rdcu_read_sram(cfg->icu_new_model_buf, + if (rcfg->icu_new_model_buf) { + if (rdcu_read_sram(rcfg->icu_new_model_buf, last_info->rdcu_new_model_adr_used, new_model_size_4byte) < 0) return -1; } } /* write model */ - } else if (cfg->model_buf && model_mode_is_used(cfg->cmp_mode)) { + } else if (rcfg->model_buf && model_mode_is_used(rcfg->cmp_mode)) { /* set the model in the local mirror... */ - if (rdcu_write_sram_16(cfg->model_buf, cfg->rdcu_model_adr, - cfg->samples * IMA_SAM2BYT) < 0) + if (rdcu_write_sram_16(rcfg->model_buf, rcfg->rdcu_model_adr, + rcfg->samples * IMA_SAM2BYT) < 0) return -1; - if (rdcu_sync_mirror_to_sram(cfg->rdcu_model_adr, samples_4byte, + if (rdcu_sync_mirror_to_sram(rcfg->rdcu_model_adr, samples_4byte, rdcu_get_data_mtu())) return -1; /* read model */ } else if (model_mode_is_used(last_info->cmp_mode_used)) { - if (rdcu_read_model(last_info, cfg->icu_new_model_buf) < 0) + if (rdcu_read_model(last_info, rcfg->icu_new_model_buf) < 0) return -1; } diff --git a/lib/rdcu_compress/cmp_rdcu_cfg.c b/lib/rdcu_compress/cmp_rdcu_cfg.c index 5093e7c1a2e8970369b36451ae42708efe53a6d4..69935250219a41a4ebb1af741d898cf5acb6fa5e 100644 --- a/lib/rdcu_compress/cmp_rdcu_cfg.c +++ b/lib/rdcu_compress/cmp_rdcu_cfg.c @@ -23,39 +23,79 @@ #include "../common/cmp_debug.h" #include "../common/cmp_support.h" +#include "../common/leon_inttypes.h" +#include "../common/compiler.h" #include "rdcu_cmd.h" #include "cmp_rdcu_cfg.h" +/** + * @brief check if the compression mode, model value and the lossy rounding + * parameters are invalid for an RDCU compression + * + * @param rcfg pointer to a RDCU compression configuration containing the + * compression mode, model value and the rounding parameters + * + * @returns 0 if the compression mode, model value and the lossy rounding + * parameters are valid for an RDCU compression, non-zero if parameters are + * invalid + */ + +static int rdcu_cfg_gen_pars_are_invalid(const struct rdcu_cfg *rcfg) +{ + int rcfg_invalid = 0; + + if (!rcfg) + return 1; + + if (!rdcu_supported_cmp_mode_is_used(rcfg->cmp_mode)) { + debug_print("Error: selected cmp_mode: %i is not supported for a RDCU compression.", rcfg->cmp_mode); + rcfg_invalid++; + } + + if (rcfg->model_value > MAX_MODEL_VALUE) { + debug_print("Error: selected model_value: %" PRIu32 " is invalid. The largest supported value is: %u.", + rcfg->model_value, MAX_MODEL_VALUE); + rcfg_invalid++; + } + + if (rcfg->round > MAX_RDCU_ROUND) { + debug_print("Error: selected lossy parameter: %" PRIu32 " is not supported for a RDCU compression. The largest supported value is: %" PRIu32 ".", + rcfg->round, MAX_RDCU_ROUND); + rcfg_invalid++; + } + +#ifdef SKIP_CMP_PAR_CHECK + return 0; +#endif + return rcfg_invalid; +} + + /** * @brief create an RDCU compression configuration * - * @param data_type compression data product type + * @param rcfg pointer to an RDCU compression configuration to be created * @param cmp_mode compression mode * @param model_value model weighting parameter (only needed for model compression mode) - * @param lossy_par lossy rounding parameter (use CMP_LOSSLESS for lossless compression) + * @param round lossy rounding parameter (use CMP_LOSSLESS for lossless compression) * - * @returns a compression configuration containing the chosen parameters; - * on error the data_type record is set to DATA_TYPE_UNKNOWN + * @returns 0 if parameters are valid, non-zero if parameters are invalid */ -struct cmp_cfg rdcu_cfg_create(enum cmp_data_type data_type, enum cmp_mode cmp_mode, - uint32_t model_value, uint32_t lossy_par) +int rdcu_cfg_create(struct rdcu_cfg *rcfg, enum cmp_mode cmp_mode, + uint32_t model_value, uint32_t round) { - struct cmp_cfg cfg; - - memset(&cfg, 0, sizeof(cfg)); + if (!rcfg) + return 1; - cfg.data_type = data_type; - cfg.cmp_mode = cmp_mode; - cfg.model_value = model_value; - cfg.round = lossy_par; - cfg.max_used_bits = &MAX_USED_BITS_SAFE; + memset(rcfg, 0, sizeof(*rcfg)); - if (cmp_cfg_gen_par_is_invalid(&cfg, RDCU_CHECK)) - cfg.data_type = DATA_TYPE_UNKNOWN; + rcfg->cmp_mode = cmp_mode; + rcfg->model_value = model_value; + rcfg->round = round; - return cfg; + return rdcu_cfg_gen_pars_are_invalid(rcfg); } @@ -109,125 +149,125 @@ static int buffers_overlap(uint32_t start_a, uint32_t end_a, uint32_t start_b, /** * @brief check if RDCU buffer settings are invalid * - * @param cfg a pointer to a compression configuration + * @param rcfg a pointer to a RDCU compression configuration * - * @returns 0 if buffers configuration is valid, otherwise the configuration is - * invalid + * @returns 0 if the buffer configuration is valid, otherwise the configuration + * is invalid */ -static int rdcu_cfg_buffers_is_invalid(const struct cmp_cfg *cfg) +static int rdcu_cfg_buffers_is_invalid(const struct rdcu_cfg *rcfg) { - int cfg_invalid = 0; + int rcfg_invalid = 0; - if (cfg->cmp_mode == CMP_MODE_RAW) { - if (cfg->buffer_length < cfg->samples) { + if (rcfg->cmp_mode == CMP_MODE_RAW) { + if (rcfg->buffer_length < rcfg->samples) { debug_print("rdcu_buffer_length is smaller than the samples parameter. There is not enough space to copy the data in RAW mode."); - cfg_invalid++; + rcfg_invalid++; } } - if (cfg->rdcu_data_adr & 0x3) { + if (rcfg->rdcu_data_adr & 0x3) { debug_print("Error: The RDCU data to compress start address is not 4-Byte aligned."); - cfg_invalid++; + rcfg_invalid++; } - if (cfg->rdcu_buffer_adr & 0x3) { + if (rcfg->rdcu_buffer_adr & 0x3) { debug_print("Error: The RDCU compressed data start address is not 4-Byte aligned."); - cfg_invalid++; + rcfg_invalid++; } - if (outside_sram_range(cfg->rdcu_data_adr, cfg->samples * IMA_SAM2BYT)) { + if (outside_sram_range(rcfg->rdcu_data_adr, rcfg->samples * IMA_SAM2BYT)) { debug_print("Error: The RDCU data to compress buffer is outside the RDCU SRAM address space."); - cfg_invalid++; + rcfg_invalid++; } - if (outside_sram_range(cfg->rdcu_buffer_adr, cfg->buffer_length * IMA_SAM2BYT)) { + if (outside_sram_range(rcfg->rdcu_buffer_adr, rcfg->buffer_length * IMA_SAM2BYT)) { debug_print("Error: The RDCU compressed data buffer is outside the RDCU SRAM address space."); - cfg_invalid++; + rcfg_invalid++; } - if (buffers_overlap(cfg->rdcu_data_adr, - cfg->rdcu_data_adr + cfg->samples * IMA_SAM2BYT, - cfg->rdcu_buffer_adr, - cfg->rdcu_buffer_adr + cfg->buffer_length * IMA_SAM2BYT)) { + if (buffers_overlap(rcfg->rdcu_data_adr, + rcfg->rdcu_data_adr + rcfg->samples * IMA_SAM2BYT, + rcfg->rdcu_buffer_adr, + rcfg->rdcu_buffer_adr + rcfg->buffer_length * IMA_SAM2BYT)) { debug_print("Error: The RDCU data to compress buffer and the RDCU compressed data buffer are overlapping."); - cfg_invalid++; + rcfg_invalid++; } - if (model_mode_is_used(cfg->cmp_mode)) { - if (cfg->model_buf && cfg->model_buf == cfg->input_buf) { + if (model_mode_is_used(rcfg->cmp_mode)) { + if (rcfg->model_buf && rcfg->model_buf == rcfg->input_buf) { debug_print("Error: The model buffer (model_buf) and the data to be compressed (input_buf) are equal."); - cfg_invalid++; + rcfg_invalid++; } - if (cfg->rdcu_model_adr & 0x3) { + if (rcfg->rdcu_model_adr & 0x3) { debug_print("Error: The RDCU model start address is not 4-Byte aligned."); - cfg_invalid++; + rcfg_invalid++; } - if (outside_sram_range(cfg->rdcu_model_adr, cfg->samples * IMA_SAM2BYT)) { + if (outside_sram_range(rcfg->rdcu_model_adr, rcfg->samples * IMA_SAM2BYT)) { debug_print("Error: The RDCU model buffer is outside the RDCU SRAM address space."); - cfg_invalid++; + rcfg_invalid++; } if (buffers_overlap( - cfg->rdcu_model_adr, - cfg->rdcu_model_adr + cfg->samples * IMA_SAM2BYT, - cfg->rdcu_data_adr, - cfg->rdcu_data_adr + cfg->samples * IMA_SAM2BYT)) { + rcfg->rdcu_model_adr, + rcfg->rdcu_model_adr + rcfg->samples * IMA_SAM2BYT, + rcfg->rdcu_data_adr, + rcfg->rdcu_data_adr + rcfg->samples * IMA_SAM2BYT)) { debug_print("Error: The model buffer and the data to compress buffer are overlapping."); - cfg_invalid++; + rcfg_invalid++; } if (buffers_overlap( - cfg->rdcu_model_adr, - cfg->rdcu_model_adr + cfg->samples * IMA_SAM2BYT, - cfg->rdcu_buffer_adr, - cfg->rdcu_buffer_adr + cfg->buffer_length * IMA_SAM2BYT) + rcfg->rdcu_model_adr, + rcfg->rdcu_model_adr + rcfg->samples * IMA_SAM2BYT, + rcfg->rdcu_buffer_adr, + rcfg->rdcu_buffer_adr + rcfg->buffer_length * IMA_SAM2BYT) ) { debug_print("Error: The model buffer and the compressed data buffer are overlapping."); - cfg_invalid++; + rcfg_invalid++; } - if (cfg->rdcu_model_adr != cfg->rdcu_new_model_adr) { - if (cfg->rdcu_new_model_adr & 0x3) { + if (rcfg->rdcu_model_adr != rcfg->rdcu_new_model_adr) { + if (rcfg->rdcu_new_model_adr & 0x3) { debug_print("Error: The RDCU updated model start address (rdcu_new_model_adr) is not 4-Byte aligned."); - cfg_invalid++; + rcfg_invalid++; } - if (outside_sram_range(cfg->rdcu_new_model_adr, - cfg->samples * IMA_SAM2BYT)) { + if (outside_sram_range(rcfg->rdcu_new_model_adr, + rcfg->samples * IMA_SAM2BYT)) { debug_print("Error: The RDCU updated model buffer is outside the RDCU SRAM address space."); - cfg_invalid++; + rcfg_invalid++; } if (buffers_overlap( - cfg->rdcu_new_model_adr, - cfg->rdcu_new_model_adr + cfg->samples * IMA_SAM2BYT, - cfg->rdcu_data_adr, - cfg->rdcu_data_adr + cfg->samples * IMA_SAM2BYT) + rcfg->rdcu_new_model_adr, + rcfg->rdcu_new_model_adr + rcfg->samples * IMA_SAM2BYT, + rcfg->rdcu_data_adr, + rcfg->rdcu_data_adr + rcfg->samples * IMA_SAM2BYT) ) { debug_print("Error: The updated model buffer and the data to compress buffer are overlapping."); - cfg_invalid++; + rcfg_invalid++; } if (buffers_overlap( - cfg->rdcu_new_model_adr, - cfg->rdcu_new_model_adr + cfg->samples * IMA_SAM2BYT, - cfg->rdcu_buffer_adr, - cfg->rdcu_buffer_adr + cfg->buffer_length * IMA_SAM2BYT) + rcfg->rdcu_new_model_adr, + rcfg->rdcu_new_model_adr + rcfg->samples * IMA_SAM2BYT, + rcfg->rdcu_buffer_adr, + rcfg->rdcu_buffer_adr + rcfg->buffer_length * IMA_SAM2BYT) ) { debug_print("Error: The updated model buffer and the compressed data buffer are overlapping."); - cfg_invalid++; + rcfg_invalid++; } if (buffers_overlap( - cfg->rdcu_new_model_adr, - cfg->rdcu_new_model_adr + cfg->samples * IMA_SAM2BYT, - cfg->rdcu_model_adr, - cfg->rdcu_model_adr + cfg->samples * IMA_SAM2BYT) + rcfg->rdcu_new_model_adr, + rcfg->rdcu_new_model_adr + rcfg->samples * IMA_SAM2BYT, + rcfg->rdcu_model_adr, + rcfg->rdcu_model_adr + rcfg->samples * IMA_SAM2BYT) ) { debug_print("Error: The updated model buffer and the model buffer are overlapping."); - cfg_invalid++; + rcfg_invalid++; } } } @@ -235,15 +275,15 @@ static int rdcu_cfg_buffers_is_invalid(const struct cmp_cfg *cfg) #ifdef SKIP_CMP_PAR_CHECK return 0; #endif - return cfg_invalid; + return rcfg_invalid; } /** * @brief setup of the different data buffers for an RDCU compression * - * @param cfg pointer to a compression configuration (created - * with the rdcu_cfg_create() function) + * @param rcfg pointer to a RDCU compression configuration + * (created with the rdcu_cfg_create() function) * @param data_to_compress pointer to the data to be compressed (if NULL no * data transfer to the RDCU) * @param data_samples length of the data to be compressed (plus the @@ -263,35 +303,101 @@ static int rdcu_cfg_buffers_is_invalid(const struct cmp_cfg *cfg) * @returns 0 if parameters are valid, non-zero if parameters are invalid */ -int rdcu_cfg_buffers(struct cmp_cfg *cfg, uint16_t *data_to_compress, +int rdcu_cfg_buffers(struct rdcu_cfg *rcfg, uint16_t *data_to_compress, uint32_t data_samples, uint16_t *model_of_data, uint32_t rdcu_data_adr, uint32_t rdcu_model_adr, uint32_t rdcu_new_model_adr, uint32_t rdcu_buffer_adr, uint32_t rdcu_buffer_lenght) { - if (!cfg) { + if (!rcfg) { debug_print("Error: pointer to the compression configuration structure is NULL."); return -1; } - cfg->input_buf = data_to_compress; - cfg->samples = data_samples; - cfg->model_buf = model_of_data; - cfg->rdcu_data_adr = rdcu_data_adr; - cfg->rdcu_model_adr = rdcu_model_adr; - cfg->rdcu_new_model_adr = rdcu_new_model_adr; - cfg->rdcu_buffer_adr = rdcu_buffer_adr; - cfg->buffer_length = rdcu_buffer_lenght; + rcfg->input_buf = data_to_compress; + rcfg->samples = data_samples; + rcfg->model_buf = model_of_data; + rcfg->rdcu_data_adr = rdcu_data_adr; + rcfg->rdcu_model_adr = rdcu_model_adr; + rcfg->rdcu_new_model_adr = rdcu_new_model_adr; + rcfg->rdcu_buffer_adr = rdcu_buffer_adr; + rcfg->buffer_length = rdcu_buffer_lenght; + + return rdcu_cfg_buffers_is_invalid(rcfg); +} + + +/** + * @brief check if the combination of the Golomb and spill parameters is invalid + * + * @param golomb_par Golomb parameter + * @param spill spillover threshold parameter + * @param par_name string describing the use of the compression par. for + * debug messages (can be NULL) + * + * @returns 0 if the parameter combination is valid, otherwise the combination is invalid + */ + +static int rdcu_cfg_golomb_spill_are_invalid(uint32_t golomb_par, uint32_t spill, + const char *par_name MAYBE_UNUSED) +{ + int rcfg_invalid = 0; + + if (golomb_par < MIN_IMA_GOLOMB_PAR || golomb_par > MAX_IMA_GOLOMB_PAR) { + debug_print("Error: The selected %s compression parameter: %" PRIu32 " is not supported in the selected compression mode. The compression parameter has to be between [%" PRIu32 ", %" PRIu32 "] in this mode.", + par_name, golomb_par, MIN_IMA_GOLOMB_PAR, MAX_IMA_GOLOMB_PAR); + rcfg_invalid++; + } + if (spill < MIN_IMA_SPILL) { + debug_print("Error: The selected %s spillover threshold value: %" PRIu32 " is too small. The smallest possible spillover value is: %" PRIu32 ".", + par_name, spill, MIN_IMA_SPILL); + rcfg_invalid++; + } + if (spill > cmp_ima_max_spill(golomb_par)) { + debug_print("Error: The selected %s spillover threshold value: %" PRIu32 " is too large for the selected %s compression parameter: %" PRIu32 ". The largest possible spillover value in the selected compression mode is: %" PRIu32 ".", + par_name, spill, par_name, golomb_par, cmp_ima_max_spill(golomb_par)); + rcfg_invalid++; + } + - return rdcu_cfg_buffers_is_invalid(cfg); +#ifdef SKIP_CMP_PAR_CHECK + return 0; +#endif + return rcfg_invalid; +} + + +/** + * @brief check if the all Golomb and spill parameters pairs are invalid + * + * @param rcfg pointer to a RDCU compressor configuration + * + * @returns 0 if the parameters are valid, otherwise invalid + */ + +static int rdcu_cfg_imagette_is_invalid(const struct rdcu_cfg *rcfg) +{ + int rcfg_invalid = 0; + + if (!rcfg) + return 1; + + rcfg_invalid += rdcu_cfg_golomb_spill_are_invalid(rcfg->golomb_par, rcfg->spill, + "imagette"); + rcfg_invalid += rdcu_cfg_golomb_spill_are_invalid(rcfg->ap1_golomb_par, rcfg->ap1_spill, + "adaptive 1 imagette"); + rcfg_invalid += rdcu_cfg_golomb_spill_are_invalid(rcfg->ap2_golomb_par, rcfg->ap2_spill, + "adaptive 2 imagette"); + + return rcfg_invalid; } /** * @brief set up the configuration parameters for an RDCU imagette compression * - * @param cfg pointer to a compression configuration (created - * with the rdcu_cfg_create() function) + * @param rcfg pointer to a RDCU compression configuration + * (created with the rdcu_cfg_create() function) * @param golomb_par imagette compression parameter * @param spillover_par imagette spillover threshold parameter * @param ap1_golomb_par adaptive 1 imagette compression parameter @@ -302,24 +408,24 @@ int rdcu_cfg_buffers(struct cmp_cfg *cfg, uint16_t *data_to_compress, * @returns 0 if parameters are valid, non-zero if parameters are invalid */ -int rdcu_cfg_imagette(struct cmp_cfg *cfg, +int rdcu_cfg_imagette(struct rdcu_cfg *rcfg, uint32_t golomb_par, uint32_t spillover_par, uint32_t ap1_golomb_par, uint32_t ap1_spillover_par, uint32_t ap2_golomb_par, uint32_t ap2_spillover_par) { - if (!cfg) { + if (!rcfg) { debug_print("Error: pointer to the compression configuration structure is NULL."); return -1; } - cfg->golomb_par = golomb_par; - cfg->spill = spillover_par; - cfg->ap1_golomb_par = ap1_golomb_par; - cfg->ap1_spill = ap1_spillover_par; - cfg->ap2_golomb_par = ap2_golomb_par; - cfg->ap2_spill = ap2_spillover_par; + rcfg->golomb_par = golomb_par; + rcfg->spill = spillover_par; + rcfg->ap1_golomb_par = ap1_golomb_par; + rcfg->ap1_spill = ap1_spillover_par; + rcfg->ap2_golomb_par = ap2_golomb_par; + rcfg->ap2_spill = ap2_spillover_par; - return cmp_cfg_imagette_is_invalid(cfg, RDCU_CHECK); + return rdcu_cfg_imagette_is_invalid(rcfg); } @@ -327,26 +433,29 @@ int rdcu_cfg_imagette(struct cmp_cfg *cfg, * @brief set up the default configuration parameters for an RDCU imagette * compression based on the set compression mode * + * @param rcfg pointer to a RDCU compression configuration (created with the + * rdcu_cfg_create() function) + * * @returns 0 if parameters are valid, non-zero if parameters are invalid */ -int rdcu_cfg_imagette_default(struct cmp_cfg *cfg) +int rdcu_cfg_imagette_default(struct rdcu_cfg *rcfg) { - if (!cfg) { + if (!rcfg) { debug_print("Error: pointer to the compression configuration structure is NULL."); return -1; } - if (model_mode_is_used(cfg->cmp_mode)) { - return rdcu_cfg_imagette(cfg, CMP_DEF_IMA_MODEL_GOLOMB_PAR, + if (model_mode_is_used(rcfg->cmp_mode)) { + return rdcu_cfg_imagette(rcfg, CMP_DEF_IMA_MODEL_GOLOMB_PAR, CMP_DEF_IMA_MODEL_SPILL_PAR, CMP_DEF_IMA_MODEL_AP1_GOLOMB_PAR, CMP_DEF_IMA_MODEL_AP1_SPILL_PAR, CMP_DEF_IMA_MODEL_AP2_GOLOMB_PAR, CMP_DEF_IMA_MODEL_AP2_SPILL_PAR); } else { - return rdcu_cfg_imagette(cfg, CMP_DEF_IMA_DIFF_GOLOMB_PAR, + return rdcu_cfg_imagette(rcfg, CMP_DEF_IMA_DIFF_GOLOMB_PAR, CMP_DEF_IMA_DIFF_SPILL_PAR, CMP_DEF_IMA_DIFF_AP1_GOLOMB_PAR, CMP_DEF_IMA_DIFF_AP1_SPILL_PAR, @@ -360,46 +469,46 @@ int rdcu_cfg_imagette_default(struct cmp_cfg *cfg) * @brief check if the compressor configuration is invalid for an RDCU compression, * see the user manual for more information (PLATO-UVIE-PL-UM-0001). * - * @param cfg pointer to a compression configuration contains all parameters - * required for compression + * @param rcfg pointer to a RDCU compression configuration contains all + * parameters required for compression * * @returns 0 if parameters are valid, non-zero if parameters are invalid */ -int rdcu_cmp_cfg_is_invalid(const struct cmp_cfg *cfg) +int rdcu_cmp_cfg_is_invalid(const struct rdcu_cfg *rcfg) { - int cfg_invalid = 0; + int rcfg_invalid = 0; - if (!cfg) { + if (!rcfg) { debug_print("Error: pointer to the compression configuration structure is NULL."); return -1; } - if (!cfg->input_buf) + if (!rcfg->input_buf) debug_print("Warning: The data to compress buffer is set to NULL. No data will be transferred to the rdcu_data_adr in the RDCU SRAM."); - if (model_mode_is_used(cfg->cmp_mode)) { - if (!cfg->model_buf) + if (model_mode_is_used(rcfg->cmp_mode)) { + if (!rcfg->model_buf) debug_print("Warning: The model buffer is set to NULL. No model data will be transferred to the rdcu_model_adr in the RDCU SRAM."); } - if (cfg->samples == 0) + if (rcfg->samples == 0) debug_print("Warning: The samples parameter is set to 0. No data will be compressed."); - if (cfg->icu_new_model_buf) + if (rcfg->icu_new_model_buf) debug_print("Warning: ICU updated model buffer is set. This buffer is not used for an RDCU compression."); - if (cfg->icu_output_buf) + if (rcfg->icu_output_buf) debug_print("Warning: ICU compressed data buffer is set. This buffer is not used for an RDCU compression."); - if (cfg->buffer_length == 0) { + if (rcfg->buffer_length == 0) { debug_print("Error: The buffer_length is set to 0. There is no place to store the compressed data."); - cfg_invalid++; + rcfg_invalid++; } - cfg_invalid += cmp_cfg_gen_par_is_invalid(cfg, RDCU_CHECK); - cfg_invalid += rdcu_cfg_buffers_is_invalid(cfg); - cfg_invalid += cmp_cfg_imagette_is_invalid(cfg, RDCU_CHECK); + rcfg_invalid += rdcu_cfg_gen_pars_are_invalid(rcfg); + rcfg_invalid += rdcu_cfg_buffers_is_invalid(rcfg); + rcfg_invalid += rdcu_cfg_imagette_is_invalid(rcfg); - return cfg_invalid; + return rcfg_invalid; } diff --git a/lib/rdcu_compress/cmp_rdcu_cfg.h b/lib/rdcu_compress/cmp_rdcu_cfg.h index 46a597662cb89729e7ea3252d9f8f839b4b1c433..e754b4d993f8fea26bc5888589a508018c43d516 100644 --- a/lib/rdcu_compress/cmp_rdcu_cfg.h +++ b/lib/rdcu_compress/cmp_rdcu_cfg.h @@ -22,21 +22,21 @@ #include "../common/cmp_support.h" -struct cmp_cfg rdcu_cfg_create(enum cmp_data_type data_type, enum cmp_mode cmp_mode, - uint32_t model_value, uint32_t lossy_par); +int rdcu_cfg_create(struct rdcu_cfg *rcfg, enum cmp_mode cmp_mode, + uint32_t model_value, uint32_t round); -int rdcu_cfg_buffers(struct cmp_cfg *cfg, uint16_t *data_to_compress, +int rdcu_cfg_buffers(struct rdcu_cfg *rcfg, uint16_t *data_to_compress, uint32_t data_samples, uint16_t *model_of_data, uint32_t rdcu_data_adr, uint32_t rdcu_model_adr, uint32_t rdcu_new_model_adr, uint32_t rdcu_buffer_adr, uint32_t rdcu_buffer_lenght); -int rdcu_cfg_imagette(struct cmp_cfg *cfg, +int rdcu_cfg_imagette(struct rdcu_cfg *rcfg, uint32_t golomb_par, uint32_t spillover_par, uint32_t ap1_golomb_par, uint32_t ap1_spillover_par, uint32_t ap2_golomb_par, uint32_t ap2_spillover_par); -int rdcu_cfg_imagette_default(struct cmp_cfg *cfg); +int rdcu_cfg_imagette_default(struct rdcu_cfg *rcfg); -int rdcu_cmp_cfg_is_invalid(const struct cmp_cfg *cfg); +int rdcu_cmp_cfg_is_invalid(const struct rdcu_cfg *rcfg); #endif /* CMP_RDCU_CFG_H */ diff --git a/lib/rdcu_compress/cmp_rdcu_testing.h b/lib/rdcu_compress/cmp_rdcu_testing.h index 56f24094dc11da394f4911d65574f62e33463e27..644a06bc969b4953eb9736f6334a9288dbbfd3cd 100644 --- a/lib/rdcu_compress/cmp_rdcu_testing.h +++ b/lib/rdcu_compress/cmp_rdcu_testing.h @@ -23,8 +23,8 @@ #include "../common/cmp_support.h" int rdcu_start_compression(void); -int rdcu_inject_edac_error(const struct cmp_cfg *cfg, uint32_t addr); -int rdcu_compress_data_parallel(const struct cmp_cfg *cfg, +int rdcu_inject_edac_error(const struct rdcu_cfg *rcfg, uint32_t addr); +int rdcu_compress_data_parallel(const struct rdcu_cfg *rcfg, const struct cmp_info *last_info); #endif /* CMP_RDCU_TESTING_H */ diff --git a/programs/cmp_guess.c b/programs/cmp_guess.c index 10956e7ed09ebabb202d998a89c08c6a38296958..65aa81f7d1f24079c98303d85edc5d858e63b4d0 100644 --- a/programs/cmp_guess.c +++ b/programs/cmp_guess.c @@ -112,13 +112,13 @@ uint32_t cmp_rdcu_get_good_spill(unsigned int golomb_par, enum cmp_mode cmp_mode /** * @brief guess a good configuration with pre_cal_method * - * @param cfg compression configuration structure + * @param rcfg RDCU compression configuration structure * * @returns the size in bits of the compressed data of the guessed * configuration; 0 on error */ -static uint32_t pre_cal_method(struct cmp_cfg *cfg) +static uint32_t pre_cal_method(struct rdcu_cfg *rcfg) { uint32_t g; int cmp_size, cmp_size_best = INT_MAX; @@ -126,11 +126,11 @@ static uint32_t pre_cal_method(struct cmp_cfg *cfg) uint32_t spill_best = 0; for (g = MIN_IMA_GOLOMB_PAR; g < MAX_IMA_GOLOMB_PAR; g++) { - uint32_t s = cmp_rdcu_get_good_spill(g, cfg->cmp_mode); + uint32_t s = cmp_rdcu_get_good_spill(g, rcfg->cmp_mode); - cfg->golomb_par = g; - cfg->spill = s; - cmp_size = icu_compress_data(cfg); + rcfg->golomb_par = g; + rcfg->spill = s; + cmp_size = compress_like_rdcu(rcfg, NULL); if (cmp_size <= 0) { return 0; } else if (cmp_size < cmp_size_best) { @@ -139,8 +139,8 @@ static uint32_t pre_cal_method(struct cmp_cfg *cfg) spill_best = s; } } - cfg->golomb_par = golomb_par_best; - cfg->spill = spill_best; + rcfg->golomb_par = golomb_par_best; + rcfg->spill = spill_best; return (uint32_t)cmp_size_best; } @@ -149,13 +149,13 @@ static uint32_t pre_cal_method(struct cmp_cfg *cfg) /** * @brief guess a good configuration with brute force method * - * @param cfg compression configuration structure + * @param rcfg RDCU compression configuration structure * * @returns the size in bits of the compressed data of the guessed * configuration; 0 on error */ -static uint32_t brute_force(struct cmp_cfg *cfg) +static uint32_t brute_force(struct rdcu_cfg *rcfg) { uint32_t g, s; uint32_t n_cal_steps = 0, last = 0; @@ -166,18 +166,18 @@ static uint32_t brute_force(struct cmp_cfg *cfg) uint32_t percent; /* short cut for zero escape mechanism */ - if (zero_escape_mech_is_used(cfg->cmp_mode)) - return pre_cal_method(cfg); + if (zero_escape_mech_is_used(rcfg->cmp_mode)) + return pre_cal_method(rcfg); printf("0%%... "); fflush(stdout); for (g = MIN_IMA_GOLOMB_PAR; g < MAX_IMA_GOLOMB_PAR; g++) { for (s = MIN_IMA_SPILL; s < cmp_ima_max_spill(g); s++) { - cfg->golomb_par = g; - cfg->spill = s; + rcfg->golomb_par = g; + rcfg->spill = s; - cmp_size = icu_compress_data(cfg); + cmp_size = compress_like_rdcu(rcfg, NULL); if (cmp_size <= 0) { return 0; } else if (cmp_size < cmp_size_best) { @@ -196,8 +196,8 @@ static uint32_t brute_force(struct cmp_cfg *cfg) } } printf("100%% "); - cfg->golomb_par = golomb_par_best; - cfg->spill = spill_best; + rcfg->golomb_par = golomb_par_best; + rcfg->spill = spill_best; return (uint32_t)cmp_size_best; } @@ -206,90 +206,84 @@ static uint32_t brute_force(struct cmp_cfg *cfg) /** * @brief guessed rdcu specific adaptive parameters * - * @param cfg compression configuration structure + * @param rcfg RDCU compression configuration structure * @note internal use only */ -static void add_rdcu_pars_internal(struct cmp_cfg *cfg) +static void add_rdcu_pars_internal(struct rdcu_cfg *rcfg) { - if (cfg->golomb_par == MIN_IMA_GOLOMB_PAR) { - cfg->ap1_golomb_par = cfg->golomb_par + 1; - cfg->ap2_golomb_par = cfg->golomb_par + 2; + if (rcfg->golomb_par == MIN_IMA_GOLOMB_PAR) { + rcfg->ap1_golomb_par = rcfg->golomb_par + 1; + rcfg->ap2_golomb_par = rcfg->golomb_par + 2; - } else if (cfg->golomb_par == MAX_IMA_GOLOMB_PAR) { - cfg->ap1_golomb_par = cfg->golomb_par - 2; - cfg->ap2_golomb_par = cfg->golomb_par - 1; + } else if (rcfg->golomb_par == MAX_IMA_GOLOMB_PAR) { + rcfg->ap1_golomb_par = rcfg->golomb_par - 2; + rcfg->ap2_golomb_par = rcfg->golomb_par - 1; } else { - cfg->ap1_golomb_par = cfg->golomb_par - 1; - cfg->ap2_golomb_par = cfg->golomb_par + 1; + rcfg->ap1_golomb_par = rcfg->golomb_par - 1; + rcfg->ap2_golomb_par = rcfg->golomb_par + 1; } - cfg->ap1_spill = cmp_rdcu_get_good_spill(cfg->ap1_golomb_par, cfg->cmp_mode); - cfg->ap2_spill = cmp_rdcu_get_good_spill(cfg->ap2_golomb_par, cfg->cmp_mode); + rcfg->ap1_spill = cmp_rdcu_get_good_spill(rcfg->ap1_golomb_par, rcfg->cmp_mode); + rcfg->ap2_spill = cmp_rdcu_get_good_spill(rcfg->ap2_golomb_par, rcfg->cmp_mode); - if (model_mode_is_used(cfg->cmp_mode)) { - cfg->rdcu_data_adr = CMP_DEF_IMA_MODEL_RDCU_DATA_ADR; - cfg->rdcu_model_adr = CMP_DEF_IMA_MODEL_RDCU_MODEL_ADR; - cfg->rdcu_new_model_adr = CMP_DEF_IMA_MODEL_RDCU_UP_MODEL_ADR; - cfg->rdcu_buffer_adr = CMP_DEF_IMA_MODEL_RDCU_BUFFER_ADR; + if (model_mode_is_used(rcfg->cmp_mode)) { + rcfg->rdcu_data_adr = CMP_DEF_IMA_MODEL_RDCU_DATA_ADR; + rcfg->rdcu_model_adr = CMP_DEF_IMA_MODEL_RDCU_MODEL_ADR; + rcfg->rdcu_new_model_adr = CMP_DEF_IMA_MODEL_RDCU_UP_MODEL_ADR; + rcfg->rdcu_buffer_adr = CMP_DEF_IMA_MODEL_RDCU_BUFFER_ADR; } else { - cfg->rdcu_data_adr = CMP_DEF_IMA_DIFF_RDCU_DATA_ADR; - cfg->rdcu_model_adr = CMP_DEF_IMA_DIFF_RDCU_MODEL_ADR; - cfg->rdcu_new_model_adr = CMP_DEF_IMA_DIFF_RDCU_UP_MODEL_ADR; - cfg->rdcu_buffer_adr = CMP_DEF_IMA_DIFF_RDCU_BUFFER_ADR; + rcfg->rdcu_data_adr = CMP_DEF_IMA_DIFF_RDCU_DATA_ADR; + rcfg->rdcu_model_adr = CMP_DEF_IMA_DIFF_RDCU_MODEL_ADR; + rcfg->rdcu_new_model_adr = CMP_DEF_IMA_DIFF_RDCU_UP_MODEL_ADR; + rcfg->rdcu_buffer_adr = CMP_DEF_IMA_DIFF_RDCU_BUFFER_ADR; } } /** * @brief guess a good compression configuration - * @details use the referenced in the cfg struct (samples, input_buf, model_buf + * @details use the referenced in the rcfg struct (samples, input_buf, model_buf * (optional)) and the cmp_mode to find a good set of compression parameters - * @note compression parameters in the cfg struct (golomb_par, spill, model_value, + * @note compression parameters in the rcfg struct (golomb_par, spill, model_value, * ap1_.., ap2_.., buffer_length, ...) are overwritten by this function * - * @param cfg compression configuration structure - * @param level guess_level 1 -> fast; 2 -> default; 3 -> slow(brute force) + * @param rcfg RDCU compression configuration structure + * @param level guess_level 1 -> fast; 2 -> default; 3 -> slow(brute force) * * @returns the size in bits of the compressed data of the guessed * configuration; 0 on error */ -uint32_t cmp_guess(struct cmp_cfg *cfg, int level) +uint32_t cmp_guess(struct rdcu_cfg *rcfg, int level) { - size_t size; - struct cmp_cfg work_cfg; + struct rdcu_cfg work_rcfg; uint32_t cmp_size = 0; - if (!cfg) + if (!rcfg) return 0; - if (!cfg->input_buf) + if (!rcfg->input_buf) return 0; - if (model_mode_is_used(cfg->cmp_mode)) - if (!cfg->model_buf) + if (model_mode_is_used(rcfg->cmp_mode)) + if (!rcfg->model_buf) return 0; - if (!rdcu_supported_cmp_mode_is_used(cfg->cmp_mode)) { + if (!rdcu_supported_cmp_mode_is_used(rcfg->cmp_mode)) { printf("This compression mode is not implied yet.\n"); return 0; } /* make a working copy of the input data (and model) because the * following function works inplace */ - work_cfg = *cfg; - work_cfg.icu_new_model_buf = NULL; - work_cfg.icu_output_buf = NULL; - work_cfg.buffer_length = 0; - work_cfg.data_type = DATA_TYPE_IMAGETTE; /* TODO: adapt to others data types */ - - size = cmp_cal_size_of_data(cfg->samples, cfg->data_type); - if (size == 0) - goto error; - - if (model_mode_is_used(cfg->cmp_mode)) { - work_cfg.icu_new_model_buf = malloc(size); - if (!work_cfg.icu_new_model_buf) { + work_rcfg = *rcfg; + work_rcfg.icu_new_model_buf = NULL; + work_rcfg.icu_output_buf = NULL; + work_rcfg.buffer_length = 0; + + if (model_mode_is_used(rcfg->cmp_mode)) { + work_rcfg.icu_new_model_buf = malloc(rcfg->samples * sizeof(uint16_t)); + if (!work_rcfg.icu_new_model_buf) { printf("malloc() failed!\n"); goto error; } @@ -298,13 +292,13 @@ uint32_t cmp_guess(struct cmp_cfg *cfg, int level) /* find the best parameters */ switch (level) { case 3: - cmp_size = brute_force(&work_cfg); + cmp_size = brute_force(&work_rcfg); break; case 1: printf("guess level 1 not implied yet use guess level 2\n"); /* fall through */ case 2: - cmp_size = pre_cal_method(&work_cfg); + cmp_size = pre_cal_method(&work_rcfg); break; default: fprintf(stderr, "cmp_tool: guess level not supported!\n"); @@ -314,23 +308,23 @@ uint32_t cmp_guess(struct cmp_cfg *cfg, int level) if (!cmp_size) goto error; - free(work_cfg.icu_new_model_buf); + free(work_rcfg.icu_new_model_buf); - cfg->golomb_par = work_cfg.golomb_par; - cfg->spill = work_cfg.spill; + rcfg->golomb_par = work_rcfg.golomb_par; + rcfg->spill = work_rcfg.spill; - cfg->model_value = cmp_guess_model_value(num_model_updates); + rcfg->model_value = cmp_guess_model_value(num_model_updates); - if (rdcu_supported_data_type_is_used(cfg->data_type)) - add_rdcu_pars_internal(cfg); + /* if (rdcu_support_data_type_is_used(rcfg->data_type)) */ + add_rdcu_pars_internal(rcfg); /* TODO: check that for non-imagette data */ - cfg->buffer_length = ((cmp_size + 32)&~0x1FU)/(size_of_a_sample(cfg->data_type)*8); + rcfg->buffer_length = ((cmp_size + 32)&~0x1FU)/(size_of_a_sample(DATA_TYPE_IMAGETTE)*8); return cmp_size; error: - free(work_cfg.icu_new_model_buf); + free(work_rcfg.icu_new_model_buf); return 0; } diff --git a/programs/cmp_guess.h b/programs/cmp_guess.h index efca334022833735b6c65c4bf96506184474dc17..3de2cb6271200f63c6f32064ab18d40dd311109b 100644 --- a/programs/cmp_guess.h +++ b/programs/cmp_guess.h @@ -33,7 +33,7 @@ /* how often the model is updated before it is reset default value */ #define CMP_GUESS_N_MODEL_UPDATE_DEF 8 -uint32_t cmp_guess(struct cmp_cfg *cfg, int level); +uint32_t cmp_guess(struct rdcu_cfg *rcfg, int level); void cmp_guess_set_model_updates(int n_model_updates); uint32_t cmp_rdcu_get_good_spill(unsigned int golomb_par, enum cmp_mode cmp_mode); diff --git a/programs/cmp_io.c b/programs/cmp_io.c index 66ea2964486a13e2ced72025abb0c7a741220ba6..9678fb6c031fe89608f62f7c38145ff30cbac62a 100644 --- a/programs/cmp_io.c +++ b/programs/cmp_io.c @@ -158,7 +158,7 @@ static FILE *open_file(const char *dirname, const char *filename) * * @param data the data to write a file * @param data_size size of the data in bytes - * @param data_type compression data type of the data + * @param cmp_type RDCU or chunk compression? * @param output_prefix file name without file extension * @param name_extension extension (with leading point character) * @param flags CMP_IO_VERBOSE_EXTRA print verbose output if set @@ -167,7 +167,7 @@ static FILE *open_file(const char *dirname, const char *filename) * @returns 0 on success, error otherwise */ -int write_input_data_to_file(const void *data, uint32_t data_size, enum cmp_data_type data_type, +int write_input_data_to_file(const void *data, uint32_t data_size, enum cmp_type cmp_type, const char *output_prefix, const char *name_extension, int flags) { uint8_t *tmp_buf; @@ -185,10 +185,18 @@ int write_input_data_to_file(const void *data, uint32_t data_size, enum cmp_data memcpy(tmp_buf, data, data_size); - if (data_type == DATA_TYPE_CHUNK) + switch (cmp_type) { + case CMP_TYPE_CHUNK: return_value = cpu_to_be_chunk(tmp_buf, data_size); - else - return_value = cmp_input_big_to_cpu_endianness(tmp_buf, data_size, data_type); + break; + case CMP_TYPE_RDCU: + return_value = be_to_cpu_data_type(tmp_buf, data_size, DATA_TYPE_IMAGETTE); + break; + case CMP_TYPE_ERROR: + default: + return_value = -1; + break; + } if (!return_value) return_value = write_data_to_file(tmp_buf, data_size, output_prefix, @@ -370,7 +378,7 @@ static int sram_addr_to_int(const char *addr) * @brief Interprets an uint32_t integer value in a byte string * * @param dep_str description string of the read in value - * @param val_str value string contain the value to convert in uint32_t + * @param val_str value string contains the value to convert in uint32_t * @param red_val address for storing the converted result * * @returns 0 on success, error otherwise @@ -529,23 +537,26 @@ int cmp_mode_parse(const char *cmp_mode_str, enum cmp_mode *cmp_mode) * @note internal use only! * * @param fp FILE pointer - * @param cfg compression configuration structure holding the read in + * @param rcfg RDCU compression configuration structure holding the read in * configuration * @param par chunk compression parameters structure holding the read in * chunk configuration * - * @returns 0 on success, error otherwise + * @returns CMP_TYPE_CHUNK if a chunk configuration is detected (stored in par), + * CMP_TYPE_RDCU if an RDCU configuration is detected (stored in cfg) or + * CMP_TYPE_ERROR on error */ -static int parse_cfg(FILE *fp, struct cmp_cfg *cfg, struct cmp_par *par) +static enum cmp_type parse_cfg(FILE *fp, struct rdcu_cfg *rcfg, struct cmp_par *par) { -#define chunk_parse_uint32_parmter(parmter) \ - if (!strcmp(token1, #parmter)) { \ - if (atoui32(token1, token2, &par->parmter)) \ - return -1; \ - cfg->data_type = DATA_TYPE_CHUNK; \ +#define chunk_parse_uint32_parameter(parameter) \ + if (!strcmp(token1, #parameter)) { \ + if (atoui32(token1, token2, &par->parameter)) \ + return CMP_TYPE_ERROR; \ + cmp_type = CMP_TYPE_CHUNK; \ continue; \ } + enum cmp_type cmp_type = CMP_TYPE_RDCU; char *token1, *token2; char line[MAX_CONFIG_LINE]; enum {CMP_MODE, SAMPLES, BUFFER_LENGTH, LAST_ITEM}; @@ -553,9 +564,9 @@ static int parse_cfg(FILE *fp, struct cmp_cfg *cfg, struct cmp_par *par) if (!fp) abort(); - if (!cfg) + if (!rcfg) abort(); - if(!par) + if (!par) abort(); while (fgets(line, sizeof(line), fp) != NULL) { @@ -565,7 +576,7 @@ static int parse_cfg(FILE *fp, struct cmp_cfg *cfg, struct cmp_par *par) if (!strchr(line, '\n')) { /* detect a to long line */ fprintf(stderr, "%s: Error read in line to long. Maximal line length is %d characters.\n", PROGRAM_NAME, MAX_CONFIG_LINE-1); - return -1; + return CMP_TYPE_ERROR; } remove_comments(line); @@ -579,58 +590,52 @@ static int parse_cfg(FILE *fp, struct cmp_cfg *cfg, struct cmp_par *par) continue; - if (!strcmp(token1, "data_type")) { - cfg->data_type = string2data_type(token2); - if (cfg->data_type == DATA_TYPE_UNKNOWN) - return -1; - continue; - } if (!strcmp(token1, "cmp_mode")) { must_read_items[CMP_MODE] = 1; - if (cmp_mode_parse(token2, &cfg->cmp_mode)) - return -1; - par->cmp_mode = cfg->cmp_mode; + if (cmp_mode_parse(token2, &rcfg->cmp_mode)) + return CMP_TYPE_ERROR; + par->cmp_mode = rcfg->cmp_mode; continue; } if (!strcmp(token1, "golomb_par")) { - if (atoui32(token1, token2, &cfg->golomb_par)) - return -1; + if (atoui32(token1, token2, &rcfg->golomb_par)) + return CMP_TYPE_ERROR; continue; } if (!strcmp(token1, "spill")) { - if (atoui32(token1, token2, &cfg->spill)) - return -1; + if (atoui32(token1, token2, &rcfg->spill)) + return CMP_TYPE_ERROR; continue; } if (!strcmp(token1, "model_value")) { - if (atoui32(token1, token2, &cfg->model_value)) - return -1; - par->model_value = cfg->model_value; + if (atoui32(token1, token2, &rcfg->model_value)) + return CMP_TYPE_ERROR; + par->model_value = rcfg->model_value; continue; } if (!strcmp(token1, "round")) { - if (atoui32(token1, token2, &cfg->round)) - return -1; + if (atoui32(token1, token2, &rcfg->round)) + return CMP_TYPE_ERROR; continue; } if (!strcmp(token1, "ap1_golomb_par")) { - if (atoui32(token1, token2, &cfg->ap1_golomb_par)) - return -1; + if (atoui32(token1, token2, &rcfg->ap1_golomb_par)) + return CMP_TYPE_ERROR; continue; } if (!strcmp(token1, "ap1_spill")) { - if (atoui32(token1, token2, &cfg->ap1_spill)) - return -1; + if (atoui32(token1, token2, &rcfg->ap1_spill)) + return CMP_TYPE_ERROR; continue; } if (!strcmp(token1, "ap2_golomb_par")) { - if (atoui32(token1, token2, &cfg->ap2_golomb_par)) - return -1; + if (atoui32(token1, token2, &rcfg->ap2_golomb_par)) + return CMP_TYPE_ERROR; continue; } if (!strcmp(token1, "ap2_spill")) { - if (atoui32(token1, token2, &cfg->ap2_spill)) - return -1; + if (atoui32(token1, token2, &rcfg->ap2_spill)) + return CMP_TYPE_ERROR; continue; } @@ -640,9 +645,9 @@ static int parse_cfg(FILE *fp, struct cmp_cfg *cfg, struct cmp_par *par) if (i < 0) { printf("%s: Error read in rdcu_data_adr_par\n", PROGRAM_NAME); - return -1; + return CMP_TYPE_ERROR; } - cfg->rdcu_data_adr = (uint32_t)i; + rcfg->rdcu_data_adr = (uint32_t)i; continue; } if (!strcmp(token1, "rdcu_model_adr")) { @@ -651,9 +656,9 @@ static int parse_cfg(FILE *fp, struct cmp_cfg *cfg, struct cmp_par *par) if (i < 0) { printf("%s: Error read in rdcu_model_adr_par\n", PROGRAM_NAME); - return -1; + return CMP_TYPE_ERROR; } - cfg->rdcu_model_adr = (uint32_t)i; + rcfg->rdcu_model_adr = (uint32_t)i; continue; } if (!strcmp(token1, "rdcu_new_model_adr")) { @@ -662,14 +667,14 @@ static int parse_cfg(FILE *fp, struct cmp_cfg *cfg, struct cmp_par *par) if (i < 0) { printf("%s: Error read in rdcu_new_model_adr_par\n", PROGRAM_NAME); - return -1; + return CMP_TYPE_ERROR; } - cfg->rdcu_new_model_adr = (uint32_t)i; + rcfg->rdcu_new_model_adr = (uint32_t)i; continue; } if (!strcmp(token1, "samples")) { - if (atoui32(token1, token2, &cfg->samples)) - return -1; + if (atoui32(token1, token2, &rcfg->samples)) + return CMP_TYPE_ERROR; must_read_items[SAMPLES] = 1; continue; } @@ -679,72 +684,72 @@ static int parse_cfg(FILE *fp, struct cmp_cfg *cfg, struct cmp_par *par) if (i < 0) { printf("%s: Error read in rdcu_buffer_adr_par\n", PROGRAM_NAME); - return -1; + return CMP_TYPE_ERROR; } - cfg->rdcu_buffer_adr = (uint32_t)i; + rcfg->rdcu_buffer_adr = (uint32_t)i; continue; } if (!strcmp(token1, "buffer_length")) { - if (atoui32(token1, token2, &cfg->buffer_length)) - return -1; + if (atoui32(token1, token2, &rcfg->buffer_length)) + return CMP_TYPE_ERROR; must_read_items[BUFFER_LENGTH] = 1; continue; } - /* chunk_parse_uint32_parmter(model_value); */ - chunk_parse_uint32_parmter(lossy_par); - - chunk_parse_uint32_parmter(nc_imagette); - - chunk_parse_uint32_parmter(s_exp_flags); - chunk_parse_uint32_parmter(s_fx); - chunk_parse_uint32_parmter(s_ncob); - chunk_parse_uint32_parmter(s_efx); - chunk_parse_uint32_parmter(s_ecob); - - chunk_parse_uint32_parmter(l_exp_flags); - chunk_parse_uint32_parmter(l_fx); - chunk_parse_uint32_parmter(l_ncob); - chunk_parse_uint32_parmter(l_efx); - chunk_parse_uint32_parmter(l_ecob); - chunk_parse_uint32_parmter(l_fx_cob_variance); - - chunk_parse_uint32_parmter(saturated_imagette); - - chunk_parse_uint32_parmter(nc_offset_mean); - chunk_parse_uint32_parmter(nc_offset_variance); - chunk_parse_uint32_parmter(nc_background_mean); - chunk_parse_uint32_parmter(nc_background_variance); - chunk_parse_uint32_parmter(nc_background_outlier_pixels); - - chunk_parse_uint32_parmter(smearing_mean); - chunk_parse_uint32_parmter(smearing_variance_mean); - chunk_parse_uint32_parmter(smearing_outlier_pixels); - - chunk_parse_uint32_parmter(fc_imagette); - chunk_parse_uint32_parmter(fc_offset_mean); - chunk_parse_uint32_parmter(fc_offset_variance); - chunk_parse_uint32_parmter(fc_background_mean); - chunk_parse_uint32_parmter(fc_background_variance); - chunk_parse_uint32_parmter(fc_background_outlier_pixels); + /* chunk_parse_uint32_parameter(model_value); */ + chunk_parse_uint32_parameter(lossy_par); + + chunk_parse_uint32_parameter(nc_imagette); + + chunk_parse_uint32_parameter(s_exp_flags); + chunk_parse_uint32_parameter(s_fx); + chunk_parse_uint32_parameter(s_ncob); + chunk_parse_uint32_parameter(s_efx); + chunk_parse_uint32_parameter(s_ecob); + + chunk_parse_uint32_parameter(l_exp_flags); + chunk_parse_uint32_parameter(l_fx); + chunk_parse_uint32_parameter(l_ncob); + chunk_parse_uint32_parameter(l_efx); + chunk_parse_uint32_parameter(l_ecob); + chunk_parse_uint32_parameter(l_fx_cob_variance); + + chunk_parse_uint32_parameter(saturated_imagette); + + chunk_parse_uint32_parameter(nc_offset_mean); + chunk_parse_uint32_parameter(nc_offset_variance); + chunk_parse_uint32_parameter(nc_background_mean); + chunk_parse_uint32_parameter(nc_background_variance); + chunk_parse_uint32_parameter(nc_background_outlier_pixels); + + chunk_parse_uint32_parameter(smearing_mean); + chunk_parse_uint32_parameter(smearing_variance_mean); + chunk_parse_uint32_parameter(smearing_outlier_pixels); + + chunk_parse_uint32_parameter(fc_imagette); + chunk_parse_uint32_parameter(fc_offset_mean); + chunk_parse_uint32_parameter(fc_offset_variance); + chunk_parse_uint32_parameter(fc_background_mean); + chunk_parse_uint32_parameter(fc_background_variance); + chunk_parse_uint32_parameter(fc_background_outlier_pixels); } - if (cfg->data_type != DATA_TYPE_CHUNK) { - if (raw_mode_is_used(cfg->cmp_mode)) + if (cmp_type == CMP_TYPE_RDCU) { + if (raw_mode_is_used(rcfg->cmp_mode)) if (must_read_items[CMP_MODE] == 1 && must_read_items[BUFFER_LENGTH] == 1) - return 0; + return cmp_type; for (j = 0; j < LAST_ITEM; j++) { if (must_read_items[j] < 1) { fprintf(stderr, "%s: Some parameters are missing. Check if the following parameters: cmp_mode, golomb_par, spill, samples and buffer_length are all set in the configuration file.\n", PROGRAM_NAME); - return -1; + return CMP_TYPE_ERROR; } } } - return 0; + return cmp_type; } @@ -752,25 +757,27 @@ static int parse_cfg(FILE *fp, struct cmp_cfg *cfg, struct cmp_par *par) * @brief reading a compressor configuration file * * @param file_name file containing the compression configuration file - * @param cfg compression configuration structure holding the read in + * @param rcfg RDCU compression configuration structure holding the read in * configuration * @param par chunk compression parameters structure holding the read * in chunk configuration * @param verbose_en print verbose output if not zero * - * @returns 0 on success, error otherwise + * @returns CMP_TYPE_CHUNK if a chunk configuration is detected (stored in par), + * CMP_TYPE_RDCU if an RDCU configuration is detected (stored in cfg) or + * CMP_TYPE_ERROR on error */ -int cmp_cfg_read(const char *file_name, struct cmp_cfg *cfg, struct cmp_par *par, - int verbose_en) +enum cmp_type cmp_cfg_read(const char *file_name, struct rdcu_cfg *rcfg, + struct cmp_par *par, int verbose_en) { - int err; + enum cmp_type cmp_type; FILE *fp; if (!file_name) abort(); - if (!cfg) + if (!rcfg) abort(); if (strstr(file_name, ".info")) { @@ -786,18 +793,16 @@ int cmp_cfg_read(const char *file_name, struct cmp_cfg *cfg, struct cmp_par *par return -1; } - err = parse_cfg(fp, cfg, par); + cmp_type = parse_cfg(fp, rcfg, par); fclose(fp); - if (err) - return err; - if (verbose_en) { + if (verbose_en && cmp_type == CMP_TYPE_RDCU) { printf("\n\n"); - cmp_cfg_print(cfg); + cmp_cfg_print(rcfg, 1); printf("\n"); } - return 0; + return cmp_type; } @@ -1378,7 +1383,7 @@ fail: * @brief reads hex-encoded data from a file into a buffer * * @param file_name data/model file name - * @param data_type compression data type used for the data + * @param cmp_type RDCU or chunk compression? * @param buf buffer to write the file content (can be NULL) * @param buf_size size in bytes of the buffer * @param flags CMP_IO_VERBOSE_EXTRA print verbose output if set @@ -1387,11 +1392,10 @@ fail: * @returns the size in bytes to store the file content; negative on error */ -ssize_t read_file_data(const char *file_name, enum cmp_data_type data_type, +ssize_t read_file_data(const char *file_name, enum cmp_type cmp_type, void *buf, uint32_t buf_size, int flags) { ssize_t size; - int32_t samples; int err; size = read_file8(file_name, (uint8_t *)buf, buf_size, flags); @@ -1401,22 +1405,20 @@ ssize_t read_file_data(const char *file_name, enum cmp_data_type data_type, if (size < 0) return size; - if (data_type != DATA_TYPE_CHUNK) { - samples = cmp_input_size_to_samples((uint32_t)size, data_type); - if (samples < 0) { - fprintf(stderr, "%s: %s: Error: The data are not correct formatted for the used compression data type.\n", - PROGRAM_NAME, file_name); - return -1; - } - - err = cmp_input_big_to_cpu_endianness(buf, (uint32_t)size, data_type); - if (err) - return -1; - } else { + switch (cmp_type) { + case CMP_TYPE_RDCU: + err = be_to_cpu_data_type(buf, (uint32_t)size, DATA_TYPE_IMAGETTE); + break; + case CMP_TYPE_CHUNK: err = be_to_cpu_chunk(buf, (uint32_t)size); - if (err) - return -1; + break; + case CMP_TYPE_ERROR: + default: + err = -1; } + + if (err) + return -1; return size; } @@ -1524,29 +1526,27 @@ uint32_t cmp_tool_gen_version_id(const char *version) * @note internal use only! * * @param fp FILE pointer - * @param cfg pointer to a configuration to print + * @param rcfg pointer to a RDCU configuration to print + * @param add_ap_pars if non-zero write the adaptive RDCU parameter in the + * file */ -static void write_cfg_internal(FILE *fp, const struct cmp_cfg *cfg) +static void write_cfg_internal(FILE *fp, const struct rdcu_cfg *rcfg, + int add_ap_pars) { if (!fp) return; - if (!cfg) { + if (!rcfg) { fprintf(fp, "Pointer to the compressor configuration is NULL.\n"); return; } fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# Selected compression data type\n"); fprintf(fp, "\n"); - fprintf(fp, "data_type = %s\n", data_type2string(cfg->data_type)); + fprintf(fp, "# RDCU compression configuration\n"); fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); - - if (cmp_data_type_is_invalid(cfg->data_type)) - return; - fprintf(fp, "# Selected compression mode\n"); fprintf(fp, "# 0: raw mode\n"); fprintf(fp, "# 1: model mode with zero escape symbol mechanism\n"); @@ -1554,205 +1554,82 @@ static void write_cfg_internal(FILE *fp, const struct cmp_cfg *cfg) fprintf(fp, "# 3: model mode with multi escape symbol mechanism\n"); fprintf(fp, "# 4: 1d differencing mode without input model multi escape symbol mechanism\n"); fprintf(fp, "\n"); - fprintf(fp, "cmp_mode = %d\n", cfg->cmp_mode); + fprintf(fp, "cmp_mode = %d\n", rcfg->cmp_mode); fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); fprintf(fp, "# Number of samples to compress, length of the data and model buffer\n"); fprintf(fp, "\n"); - fprintf(fp, "samples = %" PRIu32 "\n", cfg->samples); + fprintf(fp, "samples = %" PRIu32 "\n", rcfg->samples); fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); fprintf(fp, "# Length of the compressed data buffer in number of samples\n"); fprintf(fp, "\n"); - fprintf(fp, "buffer_length = %" PRIu32 "\n", cfg->buffer_length); + fprintf(fp, "buffer_length = %" PRIu32 "\n", rcfg->buffer_length); fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); fprintf(fp, "# Model weighting parameter\n"); fprintf(fp, "\n"); - fprintf(fp, "model_value = %" PRIu32 "\n", cfg->model_value); + fprintf(fp, "model_value = %" PRIu32 "\n", rcfg->model_value); fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); fprintf(fp, "# Number of noise bits to be rounded\n"); fprintf(fp, "\n"); - fprintf(fp, "round = %" PRIu32 "\n", cfg->round); + fprintf(fp, "round = %" PRIu32 "\n", rcfg->round); fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); + fprintf(fp, "# Golomb parameter for dictionary selection\n"); + fprintf(fp, "\n"); + fprintf(fp, "golomb_par = %" PRIu32 "\n", rcfg->golomb_par); + fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# Data Type Specific Compression Parameters\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); + fprintf(fp, "# Spillover threshold for encoding outliers\n"); + fprintf(fp, "\n"); + fprintf(fp, "spill = %" PRIu32 "\n", rcfg->spill); + fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); - if (cmp_imagette_data_type_is_used(cfg->data_type)) { - fprintf(fp, "# Golomb parameter for dictionary selection\n"); + if (add_ap_pars) { + fprintf(fp, "# Adaptive 1 Golomb parameter\n"); fprintf(fp, "\n"); - fprintf(fp, "golomb_par = %" PRIu32 "\n", cfg->golomb_par); + fprintf(fp, "ap1_golomb_par = %" PRIu32 "\n", rcfg->ap1_golomb_par); fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# Spillover threshold for encoding outliers\n"); + fprintf(fp, "# Adaptive 1 spillover threshold\n"); fprintf(fp, "\n"); - fprintf(fp, "spill = %" PRIu32 "\n", cfg->spill); + fprintf(fp, "ap1_spill = %" PRIu32 "\n", rcfg->ap1_spill); fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); - } - - if (cmp_ap_imagette_data_type_is_used(cfg->data_type)) { + fprintf(fp, "# Adaptive 2 Golomb parameter\n"); fprintf(fp, "\n"); - fprintf(fp, "# Adaptive 1 Golomb parameter; HW only\n"); - fprintf(fp, "\n"); - fprintf(fp, "ap1_golomb_par = %" PRIu32 "\n", cfg->ap1_golomb_par); + fprintf(fp, "ap2_golomb_par = %" PRIu32 "\n", rcfg->ap2_golomb_par); fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# Adaptive 1 spillover threshold; HW only\n"); + fprintf(fp, "# Adaptive 2 spillover threshold\n"); fprintf(fp, "\n"); - fprintf(fp, "ap1_spill = %" PRIu32 "\n", cfg->ap1_spill); + fprintf(fp, "ap2_spill = %" PRIu32 "\n", rcfg->ap2_spill); fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# Adaptive 2 Golomb parameter; HW only\n"); + fprintf(fp, "# RDCU data to compress start address, the first data address in the RDCU SRAM\n"); fprintf(fp, "\n"); - fprintf(fp, "ap2_golomb_par = %" PRIu32 "\n", cfg->ap2_golomb_par); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# Adaptive 2 spillover threshold; HW only\n"); - fprintf(fp, "\n"); - fprintf(fp, "ap2_spill = %" PRIu32 "\n", cfg->ap2_spill); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# RDCU data to compress start address, the first data address in the RDCU SRAM; HW only\n"); - fprintf(fp, "\n"); - fprintf(fp, "rdcu_data_adr = 0x%06"PRIX32"\n", cfg->rdcu_data_adr); + fprintf(fp, "rdcu_data_adr = 0x%06"PRIX32"\n", rcfg->rdcu_data_adr); fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); fprintf(fp, "# RDCU model start address, the first model address in the RDCU SRAM\n"); fprintf(fp, "\n"); - fprintf(fp, "rdcu_model_adr = 0x%06"PRIX32"\n", cfg->rdcu_model_adr); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# RDCU updated model start address, the address in the RDCU SRAM where the updated model is stored\n"); - fprintf(fp, "\n"); - fprintf(fp, "rdcu_new_model_adr = 0x%06"PRIX32"\n", cfg->rdcu_new_model_adr); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# RDCU compressed data start address, the first output data address in the RDCU SRAM\n"); - fprintf(fp, "\n"); - fprintf(fp, "rdcu_buffer_adr = 0x%06"PRIX32"\n", cfg->rdcu_buffer_adr); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - } -#if 0 - if (cmp_aux_data_type_is_used(cfg->data_type)) { - fprintf(fp, "# mean compression parameter\n"); - fprintf(fp, "\n"); - fprintf(fp, "cmp_par_mean = %" PRIu32 "\n", cfg->cmp_par_mean); + fprintf(fp, "rdcu_model_adr = 0x%06"PRIX32"\n", rcfg->rdcu_model_adr); fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# mean spillover threshold parameter\n"); + fprintf(fp, "# RDCU updated model start address, the first address in the RDCU SRAM where the\n"); + fprintf(fp, "# updated model is stored\n"); fprintf(fp, "\n"); - fprintf(fp, "spill_mean = %" PRIu32 "\n", cfg->spill_mean); + fprintf(fp, "rdcu_new_model_adr = 0x%06"PRIX32"\n", rcfg->rdcu_new_model_adr); fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# variance compression parameter\n"); + fprintf(fp, "# RDCU compressed data start address, the first output data address in the SRAM\n"); fprintf(fp, "\n"); - fprintf(fp, "cmp_par_variance = %" PRIu32 "\n", cfg->cmp_par_variance); + fprintf(fp, "rdcu_buffer_adr = 0x%06"PRIX32"\n", rcfg->rdcu_buffer_adr); fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# variance spillover threshold parameter\n"); - fprintf(fp, "\n"); - fprintf(fp, "spill_variance = %" PRIu32 "\n", cfg->spill_variance); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - if (cfg->data_type != DATA_TYPE_OFFSET && - cfg->data_type != DATA_TYPE_F_CAM_OFFSET) { - fprintf(fp, "# outlier pixels number compression parameter\n"); - fprintf(fp, "\n"); - fprintf(fp, "cmp_par_pixels_error = %" PRIu32 "\n", cfg->cmp_par_pixels_error); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# outlier pixels number spillover threshold parameter\n"); - fprintf(fp, "\n"); - fprintf(fp, "spill_pixels_error = %" PRIu32 "\n", cfg->spill_pixels_error); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - } - } -#endif - - if (cmp_fx_cob_data_type_is_used(cfg->data_type)) { - struct fx_cob_par needed_pars; - - cmp_cfg_fx_cob_get_need_pars(cfg->data_type, &needed_pars); - - if (needed_pars.exp_flags) { - fprintf(fp, "# exposure flags compression parameter\n"); - fprintf(fp, "\n"); - fprintf(fp, "cmp_par_exp_flags = %" PRIu32 "\n", cfg->cmp_par_exp_flags); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# exposure flags spillover threshold parameter\n"); - fprintf(fp, "\n"); - fprintf(fp, "spill_exp_flags = %" PRIu32 "\n", cfg->spill_exp_flags); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - } - if (needed_pars.fx) { - fprintf(fp, "# normal light flux compression parameter\n"); - fprintf(fp, "\n"); - fprintf(fp, "cmp_par_fx = %" PRIu32 "\n", cfg->cmp_par_fx); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# normal light flux spillover threshold parameter\n"); - fprintf(fp, "\n"); - fprintf(fp, "spill_fx = %" PRIu32 "\n", cfg->spill_fx); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - } - if (needed_pars.ncob) { - fprintf(fp, "# normal center of brightness compression parameter\n"); - fprintf(fp, "\n"); - fprintf(fp, "cmp_par_ncob = %" PRIu32 "\n", cfg->cmp_par_ncob); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# normal center of brightness spillover threshold parameter\n"); - fprintf(fp, "\n"); - fprintf(fp, "spill_nocb = %" PRIu32 "\n", cfg->spill_ncob); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - } - if (needed_pars.efx) { - fprintf(fp, "# extended light flux compression parameter\n"); - fprintf(fp, "\n"); - fprintf(fp, "cmp_par_efx = %" PRIu32 "\n", cfg->cmp_par_efx); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# extended light flux spillover threshold parameter\n"); - fprintf(fp, "\n"); - fprintf(fp, "spill_efx = %" PRIu32 "\n", cfg->spill_efx); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - } - if (needed_pars.ecob) { - fprintf(fp, "# extended center of brightness compression parameter\n"); - fprintf(fp, "\n"); - fprintf(fp, "cmp_par_ecob = %" PRIu32 "\n", cfg->cmp_par_ecob); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# extended center of brightness spillover threshold parameter\n"); - fprintf(fp, "\n"); - fprintf(fp, "spill_ecob = %" PRIu32 "\n", cfg->spill_ecob); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - } - if (needed_pars.fx_cob_variance) { - fprintf(fp, "# flux/COB variance compression parameter\n"); - fprintf(fp, "\n"); - fprintf(fp, "cmp_par_fx_cob_variance = %" PRIu32 "\n", cfg->cmp_par_fx_cob_variance); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - fprintf(fp, "# flux/COB variance spillover threshold parameter\n"); - fprintf(fp, "\n"); - fprintf(fp, "spill_fx_cob_variance = %" PRIu32 "\n", cfg->spill_fx_cob_variance); - fprintf(fp, "\n"); - fprintf(fp, "#-------------------------------------------------------------------------------\n"); - } } } @@ -1760,26 +1637,29 @@ static void write_cfg_internal(FILE *fp, const struct cmp_cfg *cfg) /** * @brief prints config struct * - * @param cfg configuration to print + * @param rcfg pointer to a RDCU configuration to print + * @param add_ap_pars if non-zero write the adaptive RDCU parameter in the file */ -void cmp_cfg_print(const struct cmp_cfg *cfg) +void cmp_cfg_print(const struct rdcu_cfg *rcfg, int add_ap_pars) { - write_cfg_internal(stdout, cfg); + write_cfg_internal(stdout, rcfg, add_ap_pars); } /** * @brief write compression configuration to a file * - * @param cfg configuration to print + * @param rcfg pointer to a RDCU configuration to print * @param output_prefix prefix of the written file (.cfg is added to the prefix) * @param verbose print verbose output if not zero + * @param add_ap_pars if non-zero write the adaptive RDCU parameter in the file * * @returns 0 on success, error otherwise */ -int cmp_cfg_fo_file(const struct cmp_cfg *cfg, const char *output_prefix, int verbose) +int cmp_cfg_fo_file(const struct rdcu_cfg *rcfg, const char *output_prefix, + int verbose, int add_ap_pars) { FILE *fp = open_file(output_prefix, ".cfg"); @@ -1789,12 +1669,12 @@ int cmp_cfg_fo_file(const struct cmp_cfg *cfg, const char *output_prefix, int ve return -1; } - write_cfg_internal(fp, cfg); + write_cfg_internal(fp, rcfg, add_ap_pars); fclose(fp); if (verbose) - cmp_cfg_print(cfg); + cmp_cfg_print(rcfg, add_ap_pars); return 0; } @@ -1803,16 +1683,17 @@ int cmp_cfg_fo_file(const struct cmp_cfg *cfg, const char *output_prefix, int ve /** * @brief write a decompression information structure to a file * - * @param info compressor information contains information of an executed - * compression - * @param output_prefix prefix of the written file (.info is added to the prefix) - * @param rdcu_cfg - if non-zero write additional RDCU parameter in the file + * @param info compressor information contains information of an + * executed compression + * @param output_prefix prefix of the written file (.info is added to the prefix) + * @param add_ap_pars if non-zero write the additional RDCU parameter in the + * file * * @returns 0 on success, error otherwise */ int cmp_info_to_file(const struct cmp_info *info, const char *output_prefix, - int rdcu_cfg) + int add_ap_pars) { FILE *fp = open_file(output_prefix, ".info"); @@ -1866,7 +1747,7 @@ int cmp_info_to_file(const struct cmp_info *info, const char *output_prefix, fprintf(fp, "\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); - if (rdcu_cfg) { + if (add_ap_pars) { fprintf(fp, "#-------------------------------------------------------------------------------\n"); fprintf(fp, "# Hardware Compressor Settings (not need for SW compression)\n"); fprintf(fp, "#-------------------------------------------------------------------------------\n"); diff --git a/programs/cmp_io.h b/programs/cmp_io.h index c1f4e86f80d9f12e47c0662d7e97ab3fa0cea575..34dcff034aa00a8476206c2540dd770a16c2a2a3 100644 --- a/programs/cmp_io.h +++ b/programs/cmp_io.h @@ -38,13 +38,22 @@ #define CMP_IO_VERBOSE 0x2 #define CMP_IO_VERBOSE_EXTRA 0x4 + +enum cmp_type { + CMP_TYPE_RDCU, + CMP_TYPE_CHUNK, + CMP_TYPE_ERROR = -1 +}; + + void print_help(const char *program_name); -int cmp_cfg_read(const char *file_name, struct cmp_cfg *cfg, struct cmp_par *par, int verbose_en); +enum cmp_type cmp_cfg_read(const char *file_name, struct rdcu_cfg *rcfg, + struct cmp_par *par, int verbose_en); int cmp_info_read(const char *file_name, struct cmp_info *info, int verbose_en); ssize_t read_file8(const char *file_name, uint8_t *buf, uint32_t buf_size, int flags); -ssize_t read_file_data(const char *file_name, enum cmp_data_type data_type, +ssize_t read_file_data(const char *file_name, enum cmp_type cmp_type, void *buf, uint32_t buf_size, int flags); ssize_t read_file_cmp_entity(const char *file_name, struct cmp_entity *ent, uint32_t ent_size, int flags); @@ -53,11 +62,13 @@ uint32_t cmp_tool_gen_version_id(const char *version); int write_data_to_file(const void *buf, uint32_t buf_size, const char *output_prefix, const char *name_extension, int flags); -int write_input_data_to_file(const void *data, uint32_t data_size, enum cmp_data_type data_type, +int write_input_data_to_file(const void *data, uint32_t data_size, enum cmp_type cmp_type, const char *output_prefix, const char *name_extension, int flags); -int cmp_info_to_file(const struct cmp_info *info, const char *output_prefix, int rdcu_cfg); -int cmp_cfg_fo_file(const struct cmp_cfg *cfg, const char *output_prefix, int verbose); -void cmp_cfg_print(const struct cmp_cfg *cfg); +int cmp_cfg_fo_file(const struct rdcu_cfg *rcfg, const char *output_prefix, + int verbose, int add_ap_pars); +int cmp_info_to_file(const struct cmp_info *info, const char *output_prefix, + int add_ap_pars); +void cmp_cfg_print(const struct rdcu_cfg *rcfg, int add_ap_pars); int atoui32(const char *dep_str, const char *val_str, uint32_t *red_val); int cmp_mode_parse(const char *cmp_mode_str, enum cmp_mode *cmp_mode); diff --git a/programs/cmp_tool.c b/programs/cmp_tool.c index 1d7aee352bf1aec9169810c97d6c303adff7ddd2..5043fd292873e3e67c82eb38c29e9ad308df8fdb 100644 --- a/programs/cmp_tool.c +++ b/programs/cmp_tool.c @@ -41,26 +41,22 @@ #define DEFAULT_MODEL_ID 53264 /* random default id */ -/* parse a data_type option argument */ -static enum cmp_data_type parse_data_type(const char *data_type_str); - /* find a good set of compression parameters for a given dataset */ -static int guess_cmp_pars(struct cmp_cfg *cfg, const char *guess_cmp_mode, +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); /* compress the data and write the results to files */ -static int compression(struct cmp_cfg *cfg, struct cmp_info *info); +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); /* create a default configuration for a compression data type */ enum cfg_default_opt {DIFF_CFG, MODEL_CFG}; -static int cmp_cfg_create_default(struct cmp_cfg *cfg, enum cmp_data_type data_type, - enum cfg_default_opt mode); +static void cmp_cfg_create_default(struct rdcu_cfg *rcfg, enum cfg_default_opt mode); /* @@ -158,12 +154,10 @@ int main(int argc, char **argv) /* size of the data to be compressed and the model of it */ uint32_t input_size = 0; - struct cmp_info info = {0}; /* decompression information struct */ - struct cmp_cfg cfg = {0}; /* compressor configuration struct */ + struct cmp_info info = {0}; /* RDCU decompression information struct */ + struct rdcu_cfg rcfg = {0}; /* RDCU compressor configuration struct */ struct cmp_par chunk_par = {0}; /* compressor parameters for chunk compression */ - - cfg.data_type = DATA_TYPE_IMAGETTE; /* use imagette as default data type */ - cfg.max_used_bits = &MAX_USED_BITS_SAFE; /* define max_used_bits default */ + enum cmp_type cmp_type; /* show help if no arguments are provided */ if (argc < 2) { @@ -200,9 +194,6 @@ int main(int argc, char **argv) break; case 'n': /* --model_cfg */ print_model_cfg = 1; - cfg.data_type = parse_data_type(optarg); - if (cfg.data_type == DATA_TYPE_UNKNOWN) - exit(EXIT_FAILURE); break; case 'o': output_prefix = optarg; @@ -218,9 +209,6 @@ int main(int argc, char **argv) break; case DIFF_CFG_OPTION: print_diff_cfg = 1; - cfg.data_type = parse_data_type(optarg); - if (cfg.data_type == DATA_TYPE_UNKNOWN) - exit(EXIT_FAILURE); break; case GUESS_OPTION: guess_operation = 1; @@ -298,19 +286,17 @@ int main(int argc, char **argv) } #endif - if (print_model_cfg == 1) { - if (add_rdcu_pars) - cfg.data_type = DATA_TYPE_IMAGETTE_ADAPTIVE; - cmp_cfg_create_default(&cfg, cfg.data_type, MODEL_CFG); - cmp_cfg_print(&cfg); - exit(EXIT_SUCCESS); - } - - if (print_diff_cfg == 1) { - if (add_rdcu_pars) - cfg.data_type = DATA_TYPE_IMAGETTE_ADAPTIVE; - cmp_cfg_create_default(&cfg, cfg.data_type, DIFF_CFG); - cmp_cfg_print(&cfg); + if (print_model_cfg || print_diff_cfg) { + if (print_model_cfg && print_diff_cfg) { + fprintf(stderr, "%s: Cannot use -n, --model_cfg and -diff_cfg together.\n", + PROGRAM_NAME); + exit(EXIT_FAILURE); + } + if (print_model_cfg) + cmp_cfg_create_default(&rcfg, MODEL_CFG); + else + cmp_cfg_create_default(&rcfg, DIFF_CFG); + cmp_cfg_print(&rcfg, add_rdcu_pars); exit(EXIT_SUCCESS); } @@ -347,45 +333,41 @@ int main(int argc, char **argv) if (cmp_operation) { printf("## Starting the compression ##\n"); printf("Importing configuration file %s ... ", cfg_file_name); - error = cmp_cfg_read(cfg_file_name, &cfg, &chunk_par, io_flags & CMP_IO_VERBOSE); - if (error) + cmp_type = cmp_cfg_read(cfg_file_name, &rcfg, &chunk_par, io_flags & CMP_IO_VERBOSE); + if (cmp_type == CMP_TYPE_ERROR) goto fail; printf("DONE\n"); } else { printf("## Search for a good set of compression parameters ##\n"); + cmp_type = CMP_TYPE_RDCU; /* guess_cmp_pars only works for RDCU like compression */ } printf("Importing data file %s ... ", data_file_name); - /* count the samples in the data file when samples == 0 */ - if (cfg.data_type != DATA_TYPE_CHUNK) { - if (cfg.samples == 0) { - int32_t samples; - - size = read_file_data(data_file_name, cfg.data_type, NULL, 0, io_flags); - if (size <= 0 || size > INT32_MAX) /* empty file is treated as an error */ - goto fail; - samples = cmp_input_size_to_samples((uint32_t)size, cfg.data_type); - if (samples < 0) + if (cmp_type == CMP_TYPE_RDCU) { + if (rcfg.samples == 0) { + /* count the samples in the data file when samples == 0 */ + size = read_file_data(data_file_name, cmp_type, NULL, 0, io_flags); + if (size <= 0 || size > INT32_MAX || (size_t)size % sizeof(uint16_t)) /* empty file is treated as an error */ goto fail; - cfg.samples = (uint32_t)samples; - printf("\nNo samples parameter set. Use samples = %u.\n... ", cfg.samples); + rcfg.samples = (uint32_t)((size_t)size/sizeof(uint16_t)); + printf("\nNo samples parameter set. Use samples = %u.\n... ", rcfg.samples); } - input_size = cmp_cal_size_of_data(cfg.samples, cfg.data_type); + input_size = rcfg.samples * sizeof(uint16_t); } else { - size = read_file_data(data_file_name, cfg.data_type, NULL, 0, io_flags); + size = read_file_data(data_file_name, cmp_type, NULL, 0, io_flags); if (size <= 0 || size > INT32_MAX) /* empty file is treated as an error */ goto fail; input_size = (uint32_t)size; } - cfg.input_buf = malloc(input_size); - if (!cfg.input_buf) { + rcfg.input_buf = malloc(input_size); + if (!rcfg.input_buf) { fprintf(stderr, "%s: Error allocating memory for input data buffer.\n", PROGRAM_NAME); goto fail; } - size = read_file_data(data_file_name, cfg.data_type, cfg.input_buf, + size = read_file_data(data_file_name, cmp_type, rcfg.input_buf, input_size, io_flags); if (size < 0) goto fail; @@ -454,22 +436,27 @@ int main(int argc, char **argv) cmp_ent_print(decomp_entity); printf("\n"); } + } + if (cmp_ent_get_data_type(decomp_entity) == DATA_TYPE_CHUNK) + cmp_type = CMP_TYPE_CHUNK; + else + cmp_type = CMP_TYPE_RDCU; + printf("DONE\n"); } if (model_file_name && !guess_operation && - ((cmp_operation && !model_mode_is_used(cfg.cmp_mode)) || + ((cmp_operation && !model_mode_is_used(rcfg.cmp_mode)) || (!cmp_operation && !model_mode_is_used(cmp_ent_get_cmp_mode(decomp_entity))))) printf("Warring: Model file (-m option) specified but no model is used.\n"); /* read in model */ - if ((cmp_operation && model_mode_is_used(cfg.cmp_mode)) || + if ((cmp_operation && model_mode_is_used(rcfg.cmp_mode)) || (!cmp_operation && model_mode_is_used(cmp_ent_get_cmp_mode(decomp_entity))) || (guess_operation && model_file_name)) { ssize_t size; uint32_t model_size; - enum cmp_data_type data_type; printf("Importing model file %s ... ", model_file_name ? model_file_name : ""); if (!model_file_name) { @@ -477,13 +464,11 @@ int main(int argc, char **argv) goto fail; } - if (cmp_operation || guess_operation) { - data_type = cfg.data_type; + if (cmp_operation || guess_operation) model_size = input_size; - } else { - data_type = cmp_ent_get_data_type(decomp_entity); + else model_size = cmp_ent_get_original_size(decomp_entity); - } + input_model_buf = malloc(model_size); if (!input_model_buf) { @@ -491,58 +476,51 @@ int main(int argc, char **argv) goto fail; } - size = read_file_data(model_file_name, data_type, input_model_buf, + size = read_file_data(model_file_name, cmp_type, input_model_buf, model_size, io_flags); if (size < 0) goto fail; printf("DONE\n"); - cfg.model_buf = input_model_buf; - cfg.icu_new_model_buf = input_model_buf; /* in-place model update */ + rcfg.model_buf = input_model_buf; + rcfg.icu_new_model_buf = input_model_buf; /* in-place model update */ } if (guess_operation) { - error = guess_cmp_pars(&cfg, guess_cmp_mode, guess_level); - if (error) - goto fail; + error = guess_cmp_pars(&rcfg, guess_cmp_mode, guess_level); } else if (cmp_operation) { - if (cfg.data_type == DATA_TYPE_CHUNK) - error = compression_of_chunk(cfg.input_buf, input_size, + if (cmp_type == CMP_TYPE_CHUNK) + error = compression_of_chunk(rcfg.input_buf, input_size, input_model_buf, &chunk_par); else - error = compression(&cfg, &info); - if (error) - goto fail; + error = compression_for_rdcu(&rcfg); } else { error = decompression(decomp_entity, input_model_buf); - if (error) - goto fail; } + if (error) + goto fail; /* write our the updated model for compressed or decompression */ if (!guess_operation && - ((cmp_operation && model_mode_is_used(cfg.cmp_mode)) || + ((cmp_operation && model_mode_is_used(rcfg.cmp_mode)) || (!cmp_operation && model_mode_is_used(cmp_ent_get_cmp_mode(decomp_entity))))) { - enum cmp_data_type data_type = DATA_TYPE_UNKNOWN; uint32_t model_size; printf("Write updated model to file %s_upmodel.dat ... ", output_prefix); - if (cmp_operation) { - data_type = cfg.data_type; + if (cmp_operation) model_size = input_size; - } else { - data_type = cmp_ent_get_data_type(decomp_entity); + else model_size = cmp_ent_get_original_size(decomp_entity); - } - error = write_input_data_to_file(input_model_buf, model_size, data_type, + + error = write_input_data_to_file(input_model_buf, model_size, cmp_type, output_prefix, "_upmodel.dat", io_flags); if (error) goto fail; printf("DONE\n"); } - free(cfg.input_buf); + free(rcfg.input_buf); free(decomp_entity); free(input_model_buf); @@ -551,7 +529,7 @@ int main(int argc, char **argv) fail: printf("FAILED\n"); - free(cfg.input_buf); + free(rcfg.input_buf); free(decomp_entity); free(input_model_buf); @@ -559,76 +537,58 @@ fail: } -/** - * @brief parse a data_type option argument - */ - -static enum cmp_data_type parse_data_type(const char *data_type_str) -{ - /* default data type if no optional argument is used */ - enum cmp_data_type data_type = DATA_TYPE_IMAGETTE; - - if (data_type_str) { - data_type = string2data_type(optarg); - if (data_type == DATA_TYPE_UNKNOWN) - printf("Do not recognize %s compression data type.\n", - data_type_str); - } - return data_type; -} - - /** * @brief find a good set of compression parameters for a given dataset */ -static int guess_cmp_pars(struct cmp_cfg *cfg, const char *guess_cmp_mode, +static int guess_cmp_pars(struct rdcu_cfg *rcfg, const char *guess_cmp_mode, int guess_level) { int error; uint32_t cmp_size_bit; double cr; + enum cmp_data_type data_type; printf("Search for a good set of compression parameters (level: %d) ... ", guess_level); if (!strcmp(guess_cmp_mode, "RDCU")) { if (add_rdcu_pars) - cfg->data_type = DATA_TYPE_IMAGETTE_ADAPTIVE; + data_type = DATA_TYPE_IMAGETTE_ADAPTIVE; else - cfg->data_type = DATA_TYPE_IMAGETTE; - if (cfg->model_buf) - cfg->cmp_mode = CMP_GUESS_DEF_MODE_MODEL; + data_type = DATA_TYPE_IMAGETTE; + if (rcfg->model_buf) + rcfg->cmp_mode = CMP_GUESS_DEF_MODE_MODEL; else - cfg->cmp_mode = CMP_GUESS_DEF_MODE_DIFF; + rcfg->cmp_mode = CMP_GUESS_DEF_MODE_DIFF; } else { - cfg->data_type = DATA_TYPE_IMAGETTE; /* TODO*/ - error = cmp_mode_parse(guess_cmp_mode, &cfg->cmp_mode); + data_type = DATA_TYPE_IMAGETTE; + error = cmp_mode_parse(guess_cmp_mode, &rcfg->cmp_mode); if (error) { fprintf(stderr, "%s: Error: unknown compression mode: %s\n", PROGRAM_NAME, guess_cmp_mode); return -1; } } - if (model_mode_is_used(cfg->cmp_mode) && !cfg->model_buf) { + if (model_mode_is_used(rcfg->cmp_mode) && !rcfg->model_buf) { fprintf(stderr, "%s: Error: model mode needs model data (-m option)\n", PROGRAM_NAME); return -1; } - cmp_size_bit = cmp_guess(cfg, guess_level); + cmp_size_bit = cmp_guess(rcfg, guess_level); if (!cmp_size_bit) return -1; if (include_cmp_header) cmp_size_bit = CHAR_BIT * (cmp_bit_to_byte(cmp_size_bit) + - cmp_ent_cal_hdr_size(cfg->data_type, cfg->cmp_mode == CMP_MODE_RAW)); + cmp_ent_cal_hdr_size(data_type, rcfg->cmp_mode == CMP_MODE_RAW)); printf("DONE\n"); printf("Write the guessed compression configuration to file %s.cfg ... ", output_prefix); - error = cmp_cfg_fo_file(cfg, output_prefix, io_flags & CMP_IO_VERBOSE); + error = cmp_cfg_fo_file(rcfg, output_prefix, io_flags & CMP_IO_VERBOSE, add_rdcu_pars); if (error) return -1; printf("DONE\n"); - cr = (8.0 * cmp_cal_size_of_data(cfg->samples, cfg->data_type))/cmp_size_bit; + cr = (8.0 * cmp_cal_size_of_data(rcfg->samples, data_type))/cmp_size_bit; printf("Guessed parameters can compress the data with a CR of %.2f.\n", cr); return 0; @@ -639,7 +599,7 @@ static int guess_cmp_pars(struct cmp_cfg *cfg, const char *guess_cmp_mode, * @brief generate packets to setup an RDCU compression */ -static int gen_rdcu_write_pkts(const struct cmp_cfg *cfg) +static int gen_rdcu_write_pkts(const struct rdcu_cfg *rcfg) { int error; @@ -661,13 +621,13 @@ static int gen_rdcu_write_pkts(const struct cmp_cfg *cfg) return -1; } - error = gen_rdcu_parallel_pkts(cfg, &last_info); + error = gen_rdcu_parallel_pkts(rcfg, &last_info); if (error) return -1; } /* generation of packets for non-parallel read/write RDCU setup */ - error = gen_write_rdcu_pkts(cfg); + error = gen_write_rdcu_pkts(rcfg); if (error) return -1; @@ -675,63 +635,6 @@ static int gen_rdcu_write_pkts(const struct cmp_cfg *cfg) } -/** - * @brief generate the compression information used based on the compression - * configuration, to emulate the RDCU behaviour - * - * @param cfg compression configuration struct - * @param cmp_size_bit length of the bitstream in bits - * @param ap1_cmp_size_bit length of the adaptive 1 bitstream in bits - * @param ap2_cmp_size_bit length of the adaptive 2 bitstream in bits - * @param info compressor information struct to set the used compression - * parameters (can be NULL) - * - * @returns 0 on success, error otherwise - * TODO: set cmp_mode_err, set model_value_err, etc, in error case - */ - -static int cmp_gernate_rdcu_info(const struct cmp_cfg *cfg, int cmp_size_bit, - int ap1_cmp_size_bit, int ap2_cmp_size_bit, - struct cmp_info *info) -{ - if (!cfg) - return -1; - - if (cfg->cmp_mode > UINT8_MAX) - return -1; - - if (cfg->round > UINT8_MAX) - return -1; - - if (cfg->model_value > UINT8_MAX) - return -1; - - if (info) { - info->cmp_err = 0; - info->cmp_mode_used = (uint8_t)cfg->cmp_mode; - info->model_value_used = (uint8_t)cfg->model_value; - info->round_used = (uint8_t)cfg->round; - info->spill_used = cfg->spill; - info->golomb_par_used = cfg->golomb_par; - info->samples_used = cfg->samples; - info->rdcu_new_model_adr_used = cfg->rdcu_new_model_adr; - info->rdcu_cmp_adr_used = cfg->rdcu_buffer_adr; - info->ap1_cmp_size = (uint32_t)ap1_cmp_size_bit; - info->ap2_cmp_size = (uint32_t)ap2_cmp_size_bit; - - if (cmp_size_bit == CMP_ERROR_SMALL_BUF) - /* the icu_output_buf is to small to store the whole bitstream */ - info->cmp_err |= 1UL << SMALL_BUFFER_ERR_BIT; /* set small buffer error */ - if (cmp_size_bit < 0) - info->cmp_size = 0; - else - info->cmp_size = (uint32_t)cmp_size_bit; - - } - return 0; -} - - /** * return a current PLATO timestamp */ @@ -799,90 +702,81 @@ cmp_chunk_fail: * @brief compress the data and write the results to files */ -static int compression(struct cmp_cfg *cfg, struct cmp_info *info) +static int compression_for_rdcu(struct rdcu_cfg *rcfg) { - int cmp_size, error; - int ap1_cmp_size = 0, ap2_cmp_size = 0; + uint64_t start_time = cmp_ent_create_timestamp(NULL); + enum cmp_data_type data_type = add_rdcu_pars ? + DATA_TYPE_IMAGETTE_ADAPTIVE : DATA_TYPE_IMAGETTE; + int32_t cmp_size; + int error; uint32_t cmp_size_byte, out_buf_size; size_t s; - uint64_t start_time = cmp_ent_create_timestamp(NULL); struct cmp_entity *cmp_entity = NULL; void *data_to_write_to_file; + struct cmp_info info; - if (cfg->buffer_length == 0) { - cfg->buffer_length = (cfg->samples+1) * BUFFER_LENGTH_DEF_FAKTOR; /* +1 to prevent malloc(0)*/ + if (rcfg->buffer_length == 0) { + rcfg->buffer_length = (rcfg->samples+1) * BUFFER_LENGTH_DEF_FAKTOR; /* +1 to prevent malloc(0)*/ printf("No buffer_length parameter set. Use buffer_length = %u as compression buffer size.\n", - cfg->buffer_length); + rcfg->buffer_length); } if (rdcu_pkt_mode) { - void *tmp = cfg->icu_new_model_buf; + void *tmp = rcfg->icu_new_model_buf; - cfg->icu_new_model_buf = NULL; + rcfg->icu_new_model_buf = NULL; printf("Generate compression setup packets ...\n"); - error = gen_rdcu_write_pkts(cfg); + error = gen_rdcu_write_pkts(rcfg); if (error) goto error_cleanup; printf("... DONE\n"); - cfg->icu_new_model_buf = tmp; - } - if (add_rdcu_pars) { - struct cmp_cfg cfg_cpy = *cfg; - - cfg_cpy.icu_output_buf = NULL; - cfg_cpy.icu_new_model_buf = NULL; - - cfg_cpy.golomb_par = cfg_cpy.ap1_golomb_par; - cfg_cpy.spill = cfg_cpy.ap1_spill; - ap1_cmp_size = icu_compress_data(&cfg_cpy); - if (ap1_cmp_size < 0) - ap1_cmp_size = 0; - - cfg_cpy.golomb_par = cfg_cpy.ap2_golomb_par; - cfg_cpy.spill = cfg_cpy.ap2_spill; - ap2_cmp_size = icu_compress_data(&cfg_cpy); - if (ap2_cmp_size < 0) - ap2_cmp_size = 0; + rcfg->icu_new_model_buf = tmp; } printf("Compress data ... "); - - out_buf_size = cmp_cal_size_of_data(cfg->buffer_length, cfg->data_type); + out_buf_size = rcfg->buffer_length * sizeof(uint16_t); cmp_entity = calloc(1, out_buf_size + sizeof(struct cmp_entity)); if (cmp_entity == NULL) { fprintf(stderr, "%s: Error allocating memory for output buffer.\n", PROGRAM_NAME); goto error_cleanup; } - s = cmp_ent_create(cmp_entity, cfg->data_type, cfg->cmp_mode == CMP_MODE_RAW, out_buf_size); + s = cmp_ent_create(cmp_entity, data_type, rcfg->cmp_mode == CMP_MODE_RAW, out_buf_size); if (!s) { fprintf(stderr, "%s: error occurred while creating the compression entity header.\n", PROGRAM_NAME); goto error_cleanup; } - cfg->icu_output_buf = cmp_ent_get_data_buf(cmp_entity); + rcfg->icu_output_buf = cmp_ent_get_data_buf(cmp_entity); - cmp_size = icu_compress_data(cfg); + cmp_size = compress_like_rdcu(rcfg, &info); if (cmp_size < 0) { if (cmp_size == CMP_ERROR_SMALL_BUF) fprintf(stderr, "Error: The buffer for the compressed data is too small to hold the compressed data. Try a larger buffer_length parameter.\n"); goto error_cleanup; } - if (!model_counter && model_mode_is_used(cfg->cmp_mode)) + if (!model_counter && model_mode_is_used(rcfg->cmp_mode)) model_counter++; - s = cmp_ent_build(cmp_entity, cmp_tool_gen_version_id(CMP_TOOL_VERSION), - start_time, cmp_ent_create_timestamp(NULL), (uint16_t)model_id, - (uint8_t)model_counter, cfg, cmp_size); + s = cmp_ent_create(cmp_entity, data_type, rcfg->cmp_mode == CMP_MODE_RAW, cmp_bit_to_byte((unsigned int)cmp_size)); if (!s) { fprintf(stderr, "%s: error occurred while creating the compression entity header.\n", PROGRAM_NAME); goto error_cleanup; } + error = cmp_ent_set_version_id(cmp_entity, cmp_tool_gen_version_id(CMP_TOOL_VERSION)); + error |= cmp_ent_set_start_timestamp(cmp_entity, start_time); + error |= cmp_ent_set_end_timestamp(cmp_entity, cmp_ent_create_timestamp(NULL)); + error |= cmp_ent_set_model_id(cmp_entity, model_id); + error |= cmp_ent_set_model_counter(cmp_entity, model_counter); + error |= cmp_ent_write_rdcu_cmp_pars(cmp_entity, &info, rcfg); + if (error) { + fprintf(stderr, "%s: error occurred while creating the compression entity header.\n", PROGRAM_NAME); + goto error_cleanup; + } + if (include_cmp_header) { data_to_write_to_file = cmp_entity; cmp_size_byte = cmp_ent_get_size(cmp_entity); } else { - if (cmp_gernate_rdcu_info(cfg, cmp_size, ap1_cmp_size, ap2_cmp_size, info)) - goto error_cleanup; data_to_write_to_file = cmp_ent_get_data_buf(cmp_entity); cmp_size_byte = cmp_ent_get_cmp_data_size(cmp_entity); } @@ -891,7 +785,7 @@ static int compression(struct cmp_cfg *cfg, struct cmp_info *info) if (rdcu_pkt_mode) { printf("Generate the read results packets ... "); - error = gen_read_rdcu_pkts(info); + error = gen_read_rdcu_pkts(&info); if (error) goto error_cleanup; printf("DONE\n"); @@ -907,26 +801,26 @@ static int compression(struct cmp_cfg *cfg, struct cmp_info *info) if (!include_cmp_header) { printf("Write decompression information to file %s.info ... ", output_prefix); - error = cmp_info_to_file(info, output_prefix, add_rdcu_pars); + error = cmp_info_to_file(&info, output_prefix, add_rdcu_pars); if (error) goto error_cleanup; printf("DONE\n"); if (io_flags & CMP_IO_VERBOSE) { printf("\n"); - print_cmp_info(info); + print_cmp_info(&info); printf("\n"); } } free(cmp_entity); - cfg->icu_output_buf = NULL; + rcfg->icu_output_buf = NULL; return 0; error_cleanup: free(cmp_entity); - cfg->icu_output_buf = NULL; + rcfg->icu_output_buf = NULL; return -1; } @@ -941,6 +835,7 @@ static int decompression(struct cmp_entity *ent, uint16_t *input_model_buf) int error; int decomp_size; uint16_t *decomp_output; + enum cmp_type cmp_type; printf("Decompress data ... "); @@ -969,7 +864,11 @@ static int decompression(struct cmp_entity *ent, uint16_t *input_model_buf) printf("Write decompressed data to file %s.dat ... ", output_prefix); - error = write_input_data_to_file(decomp_output, (uint32_t)decomp_size, cmp_ent_get_data_type(ent), + if (cmp_ent_get_data_type(ent) == DATA_TYPE_CHUNK) + cmp_type = CMP_TYPE_CHUNK; + else + cmp_type = CMP_TYPE_RDCU; + error = write_input_data_to_file(decomp_output, (uint32_t)decomp_size, cmp_type, output_prefix, ".dat", io_flags); free(decomp_output); @@ -986,42 +885,28 @@ static int decompression(struct cmp_entity *ent, uint16_t *input_model_buf) * @brief create a default configuration for a compression data type */ -static int cmp_cfg_create_default(struct cmp_cfg *cfg, enum cmp_data_type data_type, - enum cfg_default_opt mode) +static void cmp_cfg_create_default(struct rdcu_cfg *rcfg, enum cfg_default_opt mode) { - if (cmp_data_type_is_invalid(data_type)) - return -1; - - if (!cfg) /* nothing to do */ - return 0; - - if (cmp_imagette_data_type_is_used(data_type)) { - switch (mode) { - case MODEL_CFG: - *cfg = rdcu_cfg_create(data_type, CMP_DEF_IMA_MODEL_CMP_MODE, - CMP_DEF_IMA_MODEL_MODEL_VALUE, CMP_DEF_IMA_MODEL_LOSSY_PAR); - rdcu_cfg_buffers(cfg, NULL, 0, NULL, CMP_DEF_IMA_MODEL_RDCU_DATA_ADR, - CMP_DEF_IMA_MODEL_RDCU_MODEL_ADR, CMP_DEF_IMA_MODEL_RDCU_UP_MODEL_ADR, - CMP_DEF_IMA_MODEL_RDCU_BUFFER_ADR, 0); - rdcu_cfg_imagette(cfg, - CMP_DEF_IMA_MODEL_GOLOMB_PAR, CMP_DEF_IMA_MODEL_SPILL_PAR, - CMP_DEF_IMA_MODEL_AP1_GOLOMB_PAR, CMP_DEF_IMA_MODEL_AP1_SPILL_PAR, - CMP_DEF_IMA_MODEL_AP2_GOLOMB_PAR, CMP_DEF_IMA_MODEL_AP2_SPILL_PAR); - break; - case DIFF_CFG: - *cfg = rdcu_cfg_create(data_type, CMP_DEF_IMA_DIFF_CMP_MODE, - CMP_DEF_IMA_DIFF_MODEL_VALUE, CMP_DEF_IMA_DIFF_LOSSY_PAR); - rdcu_cfg_buffers(cfg, NULL, 0, NULL, CMP_DEF_IMA_DIFF_RDCU_DATA_ADR, - CMP_DEF_IMA_DIFF_RDCU_MODEL_ADR, CMP_DEF_IMA_DIFF_RDCU_UP_MODEL_ADR, - CMP_DEF_IMA_DIFF_RDCU_BUFFER_ADR, 0); - rdcu_cfg_imagette(cfg, - CMP_DEF_IMA_DIFF_GOLOMB_PAR, CMP_DEF_IMA_DIFF_SPILL_PAR, - CMP_DEF_IMA_DIFF_AP1_GOLOMB_PAR, CMP_DEF_IMA_DIFF_AP1_SPILL_PAR, - CMP_DEF_IMA_DIFF_AP2_GOLOMB_PAR, CMP_DEF_IMA_DIFF_AP2_SPILL_PAR); - break; - } + if (!rcfg) /* nothing to do */ + return; + + switch (mode) { + case MODEL_CFG: + rdcu_cfg_create(rcfg, CMP_DEF_IMA_MODEL_CMP_MODE, CMP_DEF_IMA_MODEL_MODEL_VALUE, + CMP_DEF_IMA_MODEL_LOSSY_PAR); + rdcu_cfg_buffers(rcfg, NULL, 0, NULL, CMP_DEF_IMA_MODEL_RDCU_DATA_ADR, + CMP_DEF_IMA_MODEL_RDCU_MODEL_ADR, CMP_DEF_IMA_MODEL_RDCU_UP_MODEL_ADR, + CMP_DEF_IMA_MODEL_RDCU_BUFFER_ADR, 0); + rdcu_cfg_imagette_default(rcfg); + break; + case DIFF_CFG: + rdcu_cfg_create(rcfg, CMP_DEF_IMA_DIFF_CMP_MODE, + CMP_DEF_IMA_DIFF_MODEL_VALUE, + CMP_DEF_IMA_DIFF_LOSSY_PAR); + rdcu_cfg_buffers(rcfg, NULL, 0, NULL, CMP_DEF_IMA_DIFF_RDCU_DATA_ADR, + CMP_DEF_IMA_DIFF_RDCU_MODEL_ADR, CMP_DEF_IMA_DIFF_RDCU_UP_MODEL_ADR, + CMP_DEF_IMA_DIFF_RDCU_BUFFER_ADR, 0); + rdcu_cfg_imagette_default(rcfg); + break; } - /* TODO: implement other data types */ - /* TODO: implement error checks */ - return 0; } diff --git a/programs/rdcu_pkt_to_file.c b/programs/rdcu_pkt_to_file.c index 2ae6a9fa50a4536cb40d2c74614afc0ae62ed038..cfa7ff82d384110df63f19914f1bfe1810e8b128 100644 --- a/programs/rdcu_pkt_to_file.c +++ b/programs/rdcu_pkt_to_file.c @@ -326,17 +326,17 @@ int init_rmap_pkt_to_file(void) * @note the configuration of the ICU_ADDR, RDCU_ADDR, MTU settings are in the * .rdcu_pkt_mode_cfg file * - * @param cfg compressor configuration contains all parameters required for - * compression + * @param rcfg RDCU compressor configuration contains all parameters required + * for compression * * @returns 0 on success, error otherwise */ -int gen_write_rdcu_pkts(const struct cmp_cfg *cfg) +int gen_write_rdcu_pkts(const struct rdcu_cfg *rcfg) { struct stat st = { 0 }; - if (!cfg) + if (!rcfg) return -1; /* creating TC_DIR directory if that directory does not exist */ @@ -352,7 +352,7 @@ int gen_write_rdcu_pkts(const struct cmp_cfg *cfg) } set_tc_folder_dir(TC_DIR "/compress_data"); - if (rdcu_compress_data(cfg)) + if (rdcu_compress_data(rcfg)) return -1; return 0; @@ -441,20 +441,20 @@ int gen_read_rdcu_pkts(const struct cmp_info *info) * @note the configuration of the ICU_ADDR, RDCU_ADDR, MTU settings are in the * .rdcu_pkt_mode_cfg file * - * @param cfg compressor configuration contains all parameters required for - * compression + * @param rcfg RDCU compressor configuration contains all parameters + * required for compression * @param last_info compression information from the last executed * compression * * @returns 0 on success, error otherwise */ -int gen_rdcu_parallel_pkts(const struct cmp_cfg *cfg, +int gen_rdcu_parallel_pkts(const struct rdcu_cfg *rcfg, const struct cmp_info *last_info) { struct stat st = { 0 }; - if (!cfg) + if (!rcfg) return -1; /* creating TC_DIR directory if that directory does not exist */ @@ -470,7 +470,7 @@ int gen_rdcu_parallel_pkts(const struct cmp_cfg *cfg, } set_tc_folder_dir(TC_DIR "/compress_data_parallel"); - if (rdcu_compress_data_parallel(cfg, last_info)) + if (rdcu_compress_data_parallel(rcfg, last_info)) return -1; return 0; diff --git a/programs/rdcu_pkt_to_file.h b/programs/rdcu_pkt_to_file.h index d185e59a2179e933e38dbec1d061e320b183d5ca..7f6b771fa689843570450d3c1ad7738fcfc93867 100644 --- a/programs/rdcu_pkt_to_file.h +++ b/programs/rdcu_pkt_to_file.h @@ -37,9 +37,9 @@ int init_rmap_pkt_to_file(void); void set_tc_folder_dir(const char *dir_name); -int gen_write_rdcu_pkts(const struct cmp_cfg *cfg); +int gen_write_rdcu_pkts(const struct rdcu_cfg *rcfg); int gen_read_rdcu_pkts(const struct cmp_info *info); -int gen_rdcu_parallel_pkts(const struct cmp_cfg *cfg, +int gen_rdcu_parallel_pkts(const struct rdcu_cfg *rcfg, const struct cmp_info *last_info); #endif /* RDCU_PKT_TO_FILE_H */ diff --git a/test/cmp_decmp/test_cmp_decmp.c b/test/cmp_decmp/test_cmp_decmp.c index 0a9d21ce9c1b4be9a2f726e6c19484a921fbcf90..65205567df2af7c7ae8b16aa2acd3930b2b0fbb4 100644 --- a/test/cmp_decmp/test_cmp_decmp.c +++ b/test/cmp_decmp/test_cmp_decmp.c @@ -31,6 +31,7 @@ #include <cmp_chunk.h> #include <decmp.h> #include <cmp_data_types.h> +#include <cmp_rdcu_cfg.h> #include <leon_inttypes.h> #include <byteorder.h> #include <cmp_error.h> @@ -812,10 +813,10 @@ void test_random_round_trip_like_rdcu_compression(void) void test_random_compression_decompress_rdcu_data(void) { - struct cmp_cfg cfg; + struct rdcu_cfg rcfg; struct cmp_info info = {0}; - uint32_t cmp_buffer_size; - int s, i, cmp_size_bits; + int error, s, i; + int32_t cmp_size_bits; void *compressed_data; uint16_t *decompressed_data; enum {N_SAMPLES = 5}; @@ -824,27 +825,17 @@ void test_random_compression_decompress_rdcu_data(void) CMP_BUFFER_FAKTOR = 2 /* compression data buffer size / data to compress buffer size */ }; - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_RAW, 8, CMP_LOSSLESS); - TEST_ASSERT_NOT_EQUAL_INT(cfg.data_type, DATA_TYPE_UNKNOWN); + compressed_data = malloc(sizeof(uint16_t)*N_SAMPLES*CMP_BUFFER_FAKTOR); + error = rdcu_cfg_create(&rcfg, CMP_MODE_RAW, 8, CMP_LOSSLESS); + TEST_ASSERT_FALSE(error); - cmp_buffer_size = cmp_cfg_icu_buffers(&cfg, data, N_SAMPLES, NULL, NULL, - NULL, N_SAMPLES*CMP_BUFFER_FAKTOR); - compressed_data = malloc(cmp_buffer_size); - cmp_buffer_size = cmp_cfg_icu_buffers(&cfg, data, N_SAMPLES, NULL, NULL, - compressed_data, N_SAMPLES*CMP_BUFFER_FAKTOR); - TEST_ASSERT_EQUAL_INT(cmp_buffer_size, cmp_cal_size_of_data(CMP_BUFFER_FAKTOR*N_SAMPLES, DATA_TYPE_IMAGETTE)); + rcfg.input_buf = data; + rcfg.samples = N_SAMPLES; + rcfg.icu_output_buf = compressed_data; + rcfg.buffer_length = CMP_BUFFER_FAKTOR*N_SAMPLES; - cmp_size_bits = icu_compress_data(&cfg); + cmp_size_bits = compress_like_rdcu(&rcfg, &info); TEST_ASSERT(cmp_size_bits > 0); - info.cmp_size = (uint32_t)cmp_size_bits; - info.cmp_mode_used = (uint8_t)cfg.cmp_mode; - info.model_value_used = (uint8_t)cfg.model_value; - info.round_used = (uint8_t)cfg.round; - info.spill_used = cfg.spill; - info.golomb_par_used = cfg.golomb_par; - info.samples_used = cfg.samples; - info.rdcu_new_model_adr_used = cfg.rdcu_new_model_adr; - info.rdcu_cmp_adr_used = cfg.rdcu_buffer_adr; s = decompress_rdcu_data(compressed_data, &info, NULL, NULL, NULL); TEST_ASSERT_EQUAL(sizeof(data), s); diff --git a/test/cmp_entity/test_cmp_entity.c b/test/cmp_entity/test_cmp_entity.c index 2c1274d0082b34a88138d06e5b4763cf23abaaaf..cd2384cdb8a04740f9329432fa07fb3dff9b0548 100644 --- a/test/cmp_entity/test_cmp_entity.c +++ b/test/cmp_entity/test_cmp_entity.c @@ -1436,7 +1436,7 @@ void test_cmp_ent_write_rdcu_cmp_pars(void) uint32_t size; struct cmp_entity *ent; struct cmp_info info; - struct cmp_cfg cfg; + struct rdcu_cfg rcfg; info.cmp_mode_used = CMP_MODE_DIFF_ZERO; info.spill_used = 42; @@ -1498,10 +1498,10 @@ void test_cmp_ent_write_rdcu_cmp_pars(void) /* adaptive configuration */ info.cmp_mode_used = CMP_MODE_MODEL_MULTI; - cfg.ap1_golomb_par = 0xFF; - cfg.ap1_spill = 1; - cfg.ap2_golomb_par = 0x32; - cfg.ap2_spill = 201; + rcfg.ap1_golomb_par = 0xFF; + rcfg.ap1_spill = 1; + rcfg.ap2_golomb_par = 0x32; + rcfg.ap2_spill = 201; /* create a adaptive imagette compression entity */ size = cmp_ent_create(NULL, DATA_TYPE_IMAGETTE_ADAPTIVE, info.cmp_mode_used == CMP_MODE_RAW, 12); @@ -1510,7 +1510,7 @@ void test_cmp_ent_write_rdcu_cmp_pars(void) size = cmp_ent_create(ent, DATA_TYPE_IMAGETTE_ADAPTIVE, info.cmp_mode_used == CMP_MODE_RAW, 12); TEST_ASSERT_NOT_EQUAL_INT(0, size); - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_FALSE(error); TEST_ASSERT_EQUAL_INT(DATA_TYPE_IMAGETTE_ADAPTIVE, cmp_ent_get_data_type(ent)); @@ -1525,20 +1525,20 @@ void test_cmp_ent_write_rdcu_cmp_pars(void) TEST_ASSERT_EQUAL_INT(info.spill_used, cmp_ent_get_ima_spill(ent)); TEST_ASSERT_EQUAL_INT(info.golomb_par_used, cmp_ent_get_ima_golomb_par(ent)); - TEST_ASSERT_EQUAL_INT(cfg.ap1_spill, cmp_ent_get_ima_ap1_spill(ent)); - TEST_ASSERT_EQUAL_INT(cfg.ap1_golomb_par, cmp_ent_get_ima_ap1_golomb_par(ent)); - TEST_ASSERT_EQUAL_INT(cfg.ap2_spill, cmp_ent_get_ima_ap2_spill(ent)); - TEST_ASSERT_EQUAL_INT(cfg.ap2_golomb_par, cmp_ent_get_ima_ap2_golomb_par(ent)); + TEST_ASSERT_EQUAL_INT(rcfg.ap1_spill, cmp_ent_get_ima_ap1_spill(ent)); + TEST_ASSERT_EQUAL_INT(rcfg.ap1_golomb_par, cmp_ent_get_ima_ap1_golomb_par(ent)); + TEST_ASSERT_EQUAL_INT(rcfg.ap2_spill, cmp_ent_get_ima_ap2_spill(ent)); + TEST_ASSERT_EQUAL_INT(rcfg.ap2_golomb_par, cmp_ent_get_ima_ap2_golomb_par(ent)); /** error cases **/ /* ent = NULL */ - error = cmp_ent_write_rdcu_cmp_pars(NULL, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(NULL, &info, &rcfg); TEST_ASSERT_TRUE(error); /* info = NULL */ - error = cmp_ent_write_rdcu_cmp_pars(ent, NULL, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, NULL, &rcfg); TEST_ASSERT_TRUE(error); /* cfg = NULL and adaptive data type */ @@ -1547,35 +1547,35 @@ void test_cmp_ent_write_rdcu_cmp_pars(void) /* compressed data are to big for the compression entity */ info.cmp_size = 12*8 + 1; - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_TRUE(error); info.cmp_size = 1; /* wrong data_type */ cmp_ent_set_data_type(ent, DATA_TYPE_S_FX, 0); - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_TRUE(error); cmp_ent_set_data_type(ent, DATA_TYPE_F_CAM_IMAGETTE_ADAPTIVE, 0); /* this should work */ - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_FALSE(error); /* original_size to high */ info.samples_used = 0x800000; - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_TRUE(error); info.samples_used = 0x7FFFFF; /* this should work */ - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_FALSE(error); /* cmp_mode to high */ info.cmp_mode_used = 0x100; - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_TRUE(error); info.cmp_mode_used = 0xFF; /* this should work */ - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_FALSE(error); TEST_ASSERT_EQUAL_INT(1, sizeof(info.model_value_used)); @@ -1602,79 +1602,79 @@ void test_cmp_ent_write_rdcu_cmp_pars(void) /* spill to high */ info.spill_used = 0x10000; - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_TRUE(error); info.spill_used = 0xFFFF; /* this should work */ - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_FALSE(error); /* golomb_par to high */ info.golomb_par_used = 0x100; - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_TRUE(error); info.golomb_par_used = 0xFF; /* this should work */ - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_FALSE(error); /* adaptive 1 spill to high */ - cfg.ap1_spill = 0x10000; - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + rcfg.ap1_spill = 0x10000; + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_TRUE(error); - cfg.ap1_spill = 0xFFFF; + rcfg.ap1_spill = 0xFFFF; /* this should work */ - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_FALSE(error); /* adaptive 1 golomb_par to high */ - cfg.ap1_golomb_par = 0x100; - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + rcfg.ap1_golomb_par = 0x100; + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_TRUE(error); - cfg.ap1_golomb_par = 0xFF; + rcfg.ap1_golomb_par = 0xFF; /* this should work */ - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_FALSE(error); /* adaptive 2 spill to high */ - cfg.ap2_spill = 0x10000; - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + rcfg.ap2_spill = 0x10000; + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_TRUE(error); - cfg.ap2_spill = 0xFFFF; + rcfg.ap2_spill = 0xFFFF; /* this should work */ - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_FALSE(error); /* adaptive 2 golomb_par to high */ - cfg.ap2_golomb_par = 0x100; - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + rcfg.ap2_golomb_par = 0x100; + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_TRUE(error); - cfg.ap2_golomb_par = 0xFF; + rcfg.ap2_golomb_par = 0xFF; /* this should work */ - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_FALSE(error); /* The entity's raw data bit is not set, but the configuration contains raw data */ info.cmp_mode_used = CMP_MODE_RAW; - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_TRUE(error); info.cmp_mode_used = CMP_MODE_MODEL_MULTI; /* this should work */ - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_FALSE(error); /* The entity's raw data bit is set, but the configuration contains no raw data */ cmp_ent_set_data_type(ent, DATA_TYPE_IMAGETTE_ADAPTIVE, 1); /* set raw bit */ - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_TRUE(error); cmp_ent_set_data_type(ent, DATA_TYPE_F_CAM_IMAGETTE_ADAPTIVE, 0); /* this should work */ - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_FALSE(error); /* compression error set */ info.cmp_err = 1; - error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &cfg); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, &rcfg); TEST_ASSERT_TRUE(error); info.cmp_err = 0; diff --git a/test/cmp_icu/test_cmp_icu.c b/test/cmp_icu/test_cmp_icu.c index e4734e45386ae5243a397c261e9fa61e2cd4adc3..d0f8fbb29c3945c639ec9c22b81fe94683f14363 100644 --- a/test/cmp_icu/test_cmp_icu.c +++ b/test/cmp_icu/test_cmp_icu.c @@ -33,6 +33,7 @@ #include <cmp_icu.h> #include <cmp_data_types.h> +#include <cmp_rdcu_cfg.h> #include "../../lib/icu_compress/cmp_icu.c" /* this is a hack to test static functions */ diff --git a/test/cmp_rdcu_cfg/test_cmp_rdcu_cfg.c b/test/cmp_rdcu_cfg/test_cmp_rdcu_cfg.c index 89ab07d35dba5536586b756c2bc94fc600a100ba..0c77be782a52914b6ba2f55f8031159d914ea064 100644 --- a/test/cmp_rdcu_cfg/test_cmp_rdcu_cfg.c +++ b/test/cmp_rdcu_cfg/test_cmp_rdcu_cfg.c @@ -29,110 +29,68 @@ void test_rdcu_cfg_create(void) { - struct cmp_cfg cfg; - enum cmp_data_type data_type; + struct rdcu_cfg rcfg; enum cmp_mode cmp_mode; uint32_t model_value, lossy_par; - - /* wrong data type tests */ - data_type = DATA_TYPE_UNKNOWN; /* not valid data type */ - cmp_mode = CMP_MODE_RAW; - model_value = 0; - lossy_par = CMP_LOSSLESS; - cfg = rdcu_cfg_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL(DATA_TYPE_UNKNOWN, cfg.data_type); - - /* data_type not supported by RDCU */ - data_type = DATA_TYPE_OFFSET; - cfg = rdcu_cfg_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL(DATA_TYPE_UNKNOWN, cfg.data_type); - - data_type = -1U; /* not valid data type */ - cfg = rdcu_cfg_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL(DATA_TYPE_UNKNOWN, cfg.data_type); - - /*now it should work */ - data_type = DATA_TYPE_F_CAM_IMAGETTE_ADAPTIVE; - cfg = rdcu_cfg_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL(data_type, cfg.data_type); - TEST_ASSERT_EQUAL(cmp_mode, cfg.cmp_mode); - TEST_ASSERT_EQUAL(model_value, cfg.model_value); - TEST_ASSERT_EQUAL(lossy_par, cfg.round); + int error; /* wrong compression mode tests */ cmp_mode = (enum cmp_mode)(CMP_MODE_DIFF_MULTI+1); /* not a RDCU compression mode */ - cfg = rdcu_cfg_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL(DATA_TYPE_UNKNOWN, cfg.data_type); + model_value = 0; + lossy_par = CMP_LOSSLESS; + error = rdcu_cfg_create(&rcfg, cmp_mode, model_value, lossy_par); + TEST_ASSERT_TRUE(error); cmp_mode = (enum cmp_mode)-1U; - cfg = rdcu_cfg_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL(DATA_TYPE_UNKNOWN, cfg.data_type); + error = rdcu_cfg_create(&rcfg, cmp_mode, model_value, lossy_par); + TEST_ASSERT_TRUE(error); /* this should work */ - cmp_mode = (enum cmp_mode)4; - cfg = rdcu_cfg_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL(data_type, cfg.data_type); - TEST_ASSERT_EQUAL(cmp_mode, cfg.cmp_mode); - TEST_ASSERT_EQUAL(model_value, cfg.model_value); - TEST_ASSERT_EQUAL(lossy_par, cfg.round); + cmp_mode = CMP_MODE_DIFF_MULTI; + error = rdcu_cfg_create(&rcfg, cmp_mode, model_value, lossy_par); + TEST_ASSERT_FALSE(error); + TEST_ASSERT_EQUAL(cmp_mode, rcfg.cmp_mode); + TEST_ASSERT_EQUAL(model_value, rcfg.model_value); + TEST_ASSERT_EQUAL(lossy_par, rcfg.round); /* wrong model_value tests */ cmp_mode = CMP_MODE_DIFF_ZERO; model_value = MAX_MODEL_VALUE + 1; - cfg = rdcu_cfg_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL(DATA_TYPE_UNKNOWN, cfg.data_type); + error = rdcu_cfg_create(&rcfg, cmp_mode, model_value, lossy_par); + TEST_ASSERT_TRUE(error); cmp_mode = CMP_MODE_RAW; model_value = -1U; - cfg = rdcu_cfg_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL(DATA_TYPE_UNKNOWN, cfg.data_type); + error = rdcu_cfg_create(&rcfg, cmp_mode, model_value, lossy_par); + TEST_ASSERT_TRUE(error); /* this should work */ model_value = MAX_MODEL_VALUE; - cfg = rdcu_cfg_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL(data_type, cfg.data_type); - TEST_ASSERT_EQUAL(cmp_mode, cfg.cmp_mode); - TEST_ASSERT_EQUAL(model_value, cfg.model_value); - TEST_ASSERT_EQUAL(lossy_par, cfg.round); + error = rdcu_cfg_create(&rcfg, cmp_mode, model_value, lossy_par); + TEST_ASSERT_FALSE(error); + TEST_ASSERT_EQUAL(cmp_mode, rcfg.cmp_mode); + TEST_ASSERT_EQUAL(model_value, rcfg.model_value); + TEST_ASSERT_EQUAL(lossy_par, rcfg.round); /* wrong lossy_par tests */ lossy_par = MAX_RDCU_ROUND + 1; - cfg = rdcu_cfg_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL(DATA_TYPE_UNKNOWN, cfg.data_type); + error = rdcu_cfg_create(&rcfg, cmp_mode, model_value, lossy_par); + TEST_ASSERT_TRUE(error); lossy_par = -1U; - cfg = rdcu_cfg_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL(DATA_TYPE_UNKNOWN, cfg.data_type); + error = rdcu_cfg_create(&rcfg, cmp_mode, model_value, lossy_par); + TEST_ASSERT_TRUE(error); /* this should work */ lossy_par = MAX_RDCU_ROUND; - cfg = rdcu_cfg_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL(data_type, cfg.data_type); - TEST_ASSERT_EQUAL(cmp_mode, cfg.cmp_mode); - TEST_ASSERT_EQUAL(model_value, cfg.model_value); - TEST_ASSERT_EQUAL(lossy_par, cfg.round); - - - /* wrong data type test */ - for (data_type = 0; data_type <= DATA_TYPE_F_CAM_BACKGROUND; data_type++) { - cfg = rdcu_cfg_create(data_type, CMP_MODE_DIFF_MULTI, MAX_MODEL_VALUE, CMP_LOSSLESS); - if (data_type == DATA_TYPE_IMAGETTE || - data_type == DATA_TYPE_IMAGETTE_ADAPTIVE || - data_type == DATA_TYPE_SAT_IMAGETTE || - data_type == DATA_TYPE_SAT_IMAGETTE_ADAPTIVE || - data_type == DATA_TYPE_F_CAM_IMAGETTE || - data_type == DATA_TYPE_F_CAM_IMAGETTE_ADAPTIVE) { - TEST_ASSERT_EQUAL(data_type, cfg.data_type); - TEST_ASSERT_EQUAL(CMP_MODE_DIFF_MULTI, cfg.cmp_mode); - TEST_ASSERT_EQUAL(MAX_MODEL_VALUE, cfg.model_value); - TEST_ASSERT_EQUAL(CMP_LOSSLESS, cfg.round); - } else { - TEST_ASSERT_EQUAL(DATA_TYPE_UNKNOWN, cfg.data_type); - } - } + error = rdcu_cfg_create(&rcfg, cmp_mode, model_value, lossy_par); + TEST_ASSERT_FALSE(error); + TEST_ASSERT_EQUAL(cmp_mode, rcfg.cmp_mode); + TEST_ASSERT_EQUAL(model_value, rcfg.model_value); + TEST_ASSERT_EQUAL(lossy_par, rcfg.round); } @@ -143,7 +101,7 @@ void test_rdcu_cfg_create(void) void test_rdcu_cfg_buffers_raw_diff(void) { int error; - struct cmp_cfg cfg; + struct rdcu_cfg rcfg; uint16_t data_to_compress[4] = {0x23, 0x42, 0xFF, 0x32}; uint32_t data_samples = 4; uint32_t rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr; @@ -151,29 +109,30 @@ void test_rdcu_cfg_buffers_raw_diff(void) /* test a RAW mode buffer configuration */ - cfg = rdcu_cfg_create(DATA_TYPE_IMAGETTE_ADAPTIVE, CMP_MODE_RAW, + error = rdcu_cfg_create(&rcfg, CMP_MODE_RAW, MAX_MODEL_VALUE, CMP_LOSSLESS); + TEST_ASSERT_FALSE(error); rdcu_model_adr = 0x0; rdcu_new_model_adr = 0x0; rdcu_data_adr = 0x0; rdcu_buffer_adr = 0x8; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, NULL, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, NULL, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL(data_to_compress, cfg.input_buf); - TEST_ASSERT_EQUAL(data_samples, cfg.samples); - TEST_ASSERT_EQUAL(NULL, cfg.model_buf); - TEST_ASSERT_EQUAL(rdcu_data_adr, cfg.rdcu_data_adr); - TEST_ASSERT_EQUAL(rdcu_model_adr, cfg.rdcu_model_adr); - TEST_ASSERT_EQUAL(rdcu_new_model_adr, cfg.rdcu_new_model_adr); - TEST_ASSERT_EQUAL(rdcu_buffer_adr, cfg.rdcu_buffer_adr); - TEST_ASSERT_EQUAL(rdcu_buffer_lenght, cfg.buffer_length); + TEST_ASSERT_EQUAL(data_to_compress, rcfg.input_buf); + TEST_ASSERT_EQUAL(data_samples, rcfg.samples); + TEST_ASSERT_EQUAL(NULL, rcfg.model_buf); + TEST_ASSERT_EQUAL(rdcu_data_adr, rcfg.rdcu_data_adr); + TEST_ASSERT_EQUAL(rdcu_model_adr, rcfg.rdcu_model_adr); + TEST_ASSERT_EQUAL(rdcu_new_model_adr, rcfg.rdcu_new_model_adr); + TEST_ASSERT_EQUAL(rdcu_buffer_adr, rcfg.rdcu_buffer_adr); + TEST_ASSERT_EQUAL(rdcu_buffer_lenght, rcfg.buffer_length); /* set input buffer to NULL */ - error = rdcu_cfg_buffers(&cfg, NULL, data_samples, NULL, + error = rdcu_cfg_buffers(&rcfg, NULL, data_samples, NULL, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_FALSE(error); @@ -182,7 +141,7 @@ void test_rdcu_cfg_buffers_raw_diff(void) rdcu_data_adr = 0x0; rdcu_buffer_adr = 0x8; rdcu_buffer_lenght = 3; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, NULL, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, NULL, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -191,18 +150,19 @@ void test_rdcu_cfg_buffers_raw_diff(void) rdcu_data_adr = 0x0; rdcu_buffer_adr = 0x4; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, NULL, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, NULL, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); /* get a diff config */ - cfg = rdcu_cfg_create(DATA_TYPE_IMAGETTE, CMP_MODE_DIFF_MULTI, - MAX_MODEL_VALUE, CMP_LOSSLESS); + error = rdcu_cfg_create(&rcfg, CMP_MODE_DIFF_MULTI, + MAX_MODEL_VALUE, CMP_LOSSLESS); + TEST_ASSERT_FALSE(error); rdcu_data_adr = 0x4; rdcu_buffer_adr = 0x0; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, NULL, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, NULL, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -211,7 +171,7 @@ void test_rdcu_cfg_buffers_raw_diff(void) rdcu_data_adr = RDCU_SRAM_END & ~0x3UL; rdcu_buffer_adr = 0x8; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, NULL, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, NULL, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -219,7 +179,7 @@ void test_rdcu_cfg_buffers_raw_diff(void) rdcu_data_adr = 0x0; rdcu_buffer_adr = 0x8; rdcu_buffer_lenght = RDCU_SRAM_SIZE; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, NULL, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, NULL, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -227,7 +187,7 @@ void test_rdcu_cfg_buffers_raw_diff(void) rdcu_data_adr = 0xFFFFFFFC; rdcu_buffer_adr = 0x8; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, NULL, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, NULL, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -235,7 +195,7 @@ void test_rdcu_cfg_buffers_raw_diff(void) rdcu_data_adr = 0x0; rdcu_buffer_adr = 0x8; rdcu_buffer_lenght = UINT32_MAX; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, NULL, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, NULL, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -244,7 +204,7 @@ void test_rdcu_cfg_buffers_raw_diff(void) rdcu_data_adr = 0x2; rdcu_buffer_adr = 0x10; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, NULL, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, NULL, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -252,7 +212,7 @@ void test_rdcu_cfg_buffers_raw_diff(void) rdcu_data_adr = 0x0; rdcu_buffer_adr = 0x9; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, NULL, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, NULL, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -272,7 +232,7 @@ void test_rdcu_cfg_buffers_raw_diff(void) void test_rdcu_cfg_buffers_model(void) { int error; - struct cmp_cfg cfg; + struct rdcu_cfg rcfg; uint16_t data_to_compress[4] = {0x23, 0x42, 0xFF, 0x32}; uint16_t model_of_data[4] = {0xFF, 0x12, 0x34, 0xAB}; uint32_t data_samples = 4; @@ -281,36 +241,36 @@ void test_rdcu_cfg_buffers_model(void) /* test a RAW mode buffer configuration */ - cfg = rdcu_cfg_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_MULTI, - MAX_MODEL_VALUE, CMP_LOSSLESS); + error = rdcu_cfg_create(&rcfg, CMP_MODE_MODEL_MULTI, MAX_MODEL_VALUE, + CMP_LOSSLESS); rdcu_data_adr = 0x0; rdcu_model_adr = 0x8; rdcu_new_model_adr = 0x10; rdcu_buffer_adr = 0x18; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, model_of_data, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, model_of_data, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL(data_to_compress, cfg.input_buf); - TEST_ASSERT_EQUAL(data_samples, cfg.samples); - TEST_ASSERT_EQUAL(model_of_data, cfg.model_buf); - TEST_ASSERT_EQUAL(rdcu_data_adr, cfg.rdcu_data_adr); - TEST_ASSERT_EQUAL(rdcu_model_adr, cfg.rdcu_model_adr); - TEST_ASSERT_EQUAL(rdcu_new_model_adr, cfg.rdcu_new_model_adr); - TEST_ASSERT_EQUAL(rdcu_buffer_adr, cfg.rdcu_buffer_adr); - TEST_ASSERT_EQUAL(rdcu_buffer_lenght, cfg.buffer_length); + TEST_ASSERT_EQUAL(data_to_compress, rcfg.input_buf); + TEST_ASSERT_EQUAL(data_samples, rcfg.samples); + TEST_ASSERT_EQUAL(model_of_data, rcfg.model_buf); + TEST_ASSERT_EQUAL(rdcu_data_adr, rcfg.rdcu_data_adr); + TEST_ASSERT_EQUAL(rdcu_model_adr, rcfg.rdcu_model_adr); + TEST_ASSERT_EQUAL(rdcu_new_model_adr, rcfg.rdcu_new_model_adr); + TEST_ASSERT_EQUAL(rdcu_buffer_adr, rcfg.rdcu_buffer_adr); + TEST_ASSERT_EQUAL(rdcu_buffer_lenght, rcfg.buffer_length); /* data and model buffers are NULL */ rdcu_new_model_adr = rdcu_model_adr; - error = rdcu_cfg_buffers(&cfg, NULL, data_samples, NULL, + error = rdcu_cfg_buffers(&rcfg, NULL, data_samples, NULL, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_FALSE(error); /* error: data and model buffer are the same */ - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, data_to_compress, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, data_to_compress, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -321,7 +281,7 @@ void test_rdcu_cfg_buffers_model(void) rdcu_new_model_adr = rdcu_model_adr; rdcu_buffer_adr = 0x14; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, model_of_data, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, model_of_data, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -332,7 +292,7 @@ void test_rdcu_cfg_buffers_model(void) rdcu_new_model_adr = rdcu_model_adr; rdcu_buffer_adr = 0x10; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, model_of_data, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, model_of_data, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -343,7 +303,7 @@ void test_rdcu_cfg_buffers_model(void) rdcu_new_model_adr = rdcu_model_adr; rdcu_buffer_adr = 0x10; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, model_of_data, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, model_of_data, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -354,7 +314,7 @@ void test_rdcu_cfg_buffers_model(void) rdcu_new_model_adr = rdcu_model_adr; rdcu_buffer_adr = 0x10; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, model_of_data, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, model_of_data, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -367,7 +327,7 @@ void test_rdcu_cfg_buffers_model(void) rdcu_new_model_adr = 0x11; /* not 4 byte aligned */ rdcu_buffer_adr = 0x1C; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, model_of_data, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, model_of_data, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -378,7 +338,7 @@ void test_rdcu_cfg_buffers_model(void) rdcu_new_model_adr = 0xFFFFFFFC; /* not in SRAM range */ rdcu_buffer_adr = 0x18; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, model_of_data, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, model_of_data, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -389,7 +349,7 @@ void test_rdcu_cfg_buffers_model(void) rdcu_new_model_adr = 0xC; /* overlaps with data buffer */ rdcu_buffer_adr = 0x18; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, model_of_data, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, model_of_data, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -400,7 +360,7 @@ void test_rdcu_cfg_buffers_model(void) rdcu_new_model_adr = 0x14; /* overlaps with compressed data buffer */ rdcu_buffer_adr = 0x18; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, model_of_data, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, model_of_data, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -411,7 +371,7 @@ void test_rdcu_cfg_buffers_model(void) rdcu_new_model_adr = 0xC; /* overlaps with model buffer */ rdcu_buffer_adr = 0x18; rdcu_buffer_lenght = 4; - error = rdcu_cfg_buffers(&cfg, data_to_compress, data_samples, model_of_data, + error = rdcu_cfg_buffers(&rcfg, data_to_compress, data_samples, model_of_data, rdcu_data_adr, rdcu_model_adr, rdcu_new_model_adr, rdcu_buffer_adr, rdcu_buffer_lenght); TEST_ASSERT_EQUAL(1, error); @@ -426,11 +386,14 @@ void test_rdcu_cfg_buffers_model(void) void test_rdcu_cfg_imagette(void) { int error; - struct cmp_cfg cfg = rdcu_cfg_create(DATA_TYPE_IMAGETTE, CMP_MODE_RAW, - 10, CMP_LOSSLESS); + struct rdcu_cfg rcfg; uint32_t golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par; + error = rdcu_cfg_create(&rcfg, CMP_MODE_RAW, 10, + CMP_LOSSLESS); + TEST_ASSERT_FALSE(error); + golomb_par = MIN_IMA_GOLOMB_PAR; spillover_par = MIN_IMA_SPILL; ap1_golomb_par = MIN_IMA_GOLOMB_PAR; @@ -438,117 +401,117 @@ void test_rdcu_cfg_imagette(void) ap2_golomb_par = MIN_IMA_GOLOMB_PAR; ap2_spillover_par = MIN_IMA_SPILL; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL(golomb_par, cfg.golomb_par); - TEST_ASSERT_EQUAL(spillover_par, cfg.spill); - TEST_ASSERT_EQUAL(ap1_golomb_par, cfg.ap1_golomb_par); - TEST_ASSERT_EQUAL(ap1_spillover_par, cfg.ap1_spill); - TEST_ASSERT_EQUAL(ap2_golomb_par, cfg.ap2_golomb_par); - TEST_ASSERT_EQUAL(ap2_spillover_par, cfg.ap2_spill); + TEST_ASSERT_EQUAL(golomb_par, rcfg.golomb_par); + TEST_ASSERT_EQUAL(spillover_par, rcfg.spill); + TEST_ASSERT_EQUAL(ap1_golomb_par, rcfg.ap1_golomb_par); + TEST_ASSERT_EQUAL(ap1_spillover_par, rcfg.ap1_spill); + TEST_ASSERT_EQUAL(ap2_golomb_par, rcfg.ap2_golomb_par); + TEST_ASSERT_EQUAL(ap2_spillover_par, rcfg.ap2_spill); /* wrong golomb_par */ golomb_par = MIN_IMA_GOLOMB_PAR - 1; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_TRUE(error); golomb_par = MAX_IMA_GOLOMB_PAR + 1; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_TRUE(error); /* this should work */ golomb_par = MAX_IMA_GOLOMB_PAR; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL(golomb_par, cfg.golomb_par); - TEST_ASSERT_EQUAL(spillover_par, cfg.spill); - TEST_ASSERT_EQUAL(ap1_golomb_par, cfg.ap1_golomb_par); - TEST_ASSERT_EQUAL(ap1_spillover_par, cfg.ap1_spill); - TEST_ASSERT_EQUAL(ap2_golomb_par, cfg.ap2_golomb_par); - TEST_ASSERT_EQUAL(ap2_spillover_par, cfg.ap2_spill); + TEST_ASSERT_EQUAL(golomb_par, rcfg.golomb_par); + TEST_ASSERT_EQUAL(spillover_par, rcfg.spill); + TEST_ASSERT_EQUAL(ap1_golomb_par, rcfg.ap1_golomb_par); + TEST_ASSERT_EQUAL(ap1_spillover_par, rcfg.ap1_spill); + TEST_ASSERT_EQUAL(ap2_golomb_par, rcfg.ap2_golomb_par); + TEST_ASSERT_EQUAL(ap2_spillover_par, rcfg.ap2_spill); /* wrong ap1_golomb_par */ ap1_golomb_par = MIN_IMA_GOLOMB_PAR - 1; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_TRUE(error); ap1_golomb_par = MAX_IMA_GOLOMB_PAR + 1; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_TRUE(error); /* this should work */ ap1_golomb_par = MAX_IMA_GOLOMB_PAR; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL(golomb_par, cfg.golomb_par); - TEST_ASSERT_EQUAL(spillover_par, cfg.spill); - TEST_ASSERT_EQUAL(ap1_golomb_par, cfg.ap1_golomb_par); - TEST_ASSERT_EQUAL(ap1_spillover_par, cfg.ap1_spill); - TEST_ASSERT_EQUAL(ap2_golomb_par, cfg.ap2_golomb_par); - TEST_ASSERT_EQUAL(ap2_spillover_par, cfg.ap2_spill); + TEST_ASSERT_EQUAL(golomb_par, rcfg.golomb_par); + TEST_ASSERT_EQUAL(spillover_par, rcfg.spill); + TEST_ASSERT_EQUAL(ap1_golomb_par, rcfg.ap1_golomb_par); + TEST_ASSERT_EQUAL(ap1_spillover_par, rcfg.ap1_spill); + TEST_ASSERT_EQUAL(ap2_golomb_par, rcfg.ap2_golomb_par); + TEST_ASSERT_EQUAL(ap2_spillover_par, rcfg.ap2_spill); /* wrong ap2_golomb_par */ - cfg.cmp_mode = CMP_MODE_DIFF_ZERO; + rcfg.cmp_mode = CMP_MODE_DIFF_ZERO; ap2_golomb_par = MIN_IMA_GOLOMB_PAR - 1; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_TRUE(error); ap2_golomb_par = MAX_IMA_GOLOMB_PAR + 1; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_TRUE(error); /* this should work */ ap2_golomb_par = MAX_IMA_GOLOMB_PAR; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL(golomb_par, cfg.golomb_par); - TEST_ASSERT_EQUAL(spillover_par, cfg.spill); - TEST_ASSERT_EQUAL(ap1_golomb_par, cfg.ap1_golomb_par); - TEST_ASSERT_EQUAL(ap1_spillover_par, cfg.ap1_spill); - TEST_ASSERT_EQUAL(ap2_golomb_par, cfg.ap2_golomb_par); - TEST_ASSERT_EQUAL(ap2_spillover_par, cfg.ap2_spill); + TEST_ASSERT_EQUAL(golomb_par, rcfg.golomb_par); + TEST_ASSERT_EQUAL(spillover_par, rcfg.spill); + TEST_ASSERT_EQUAL(ap1_golomb_par, rcfg.ap1_golomb_par); + TEST_ASSERT_EQUAL(ap1_spillover_par, rcfg.ap1_spill); + TEST_ASSERT_EQUAL(ap2_golomb_par, rcfg.ap2_golomb_par); + TEST_ASSERT_EQUAL(ap2_spillover_par, rcfg.ap2_spill); /* wrong spillover_par */ golomb_par = MIN_IMA_GOLOMB_PAR; spillover_par = cmp_ima_max_spill(golomb_par)+1; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_EQUAL(1, error); golomb_par = MAX_IMA_GOLOMB_PAR; spillover_par = cmp_ima_max_spill(golomb_par)+1; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_EQUAL(1, error); golomb_par = MIN_IMA_GOLOMB_PAR; spillover_par = MIN_IMA_SPILL - 1; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_EQUAL(1, error); @@ -556,35 +519,35 @@ void test_rdcu_cfg_imagette(void) /* this should work */ golomb_par = MAX_IMA_GOLOMB_PAR; spillover_par = cmp_ima_max_spill(golomb_par); - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL(golomb_par, cfg.golomb_par); - TEST_ASSERT_EQUAL(spillover_par, cfg.spill); - TEST_ASSERT_EQUAL(ap1_golomb_par, cfg.ap1_golomb_par); - TEST_ASSERT_EQUAL(ap1_spillover_par, cfg.ap1_spill); - TEST_ASSERT_EQUAL(ap2_golomb_par, cfg.ap2_golomb_par); - TEST_ASSERT_EQUAL(ap2_spillover_par, cfg.ap2_spill); + TEST_ASSERT_EQUAL(golomb_par, rcfg.golomb_par); + TEST_ASSERT_EQUAL(spillover_par, rcfg.spill); + TEST_ASSERT_EQUAL(ap1_golomb_par, rcfg.ap1_golomb_par); + TEST_ASSERT_EQUAL(ap1_spillover_par, rcfg.ap1_spill); + TEST_ASSERT_EQUAL(ap2_golomb_par, rcfg.ap2_golomb_par); + TEST_ASSERT_EQUAL(ap2_spillover_par, rcfg.ap2_spill); /* wrong ap1_spillover_par */ ap1_golomb_par = MIN_IMA_GOLOMB_PAR; ap1_spillover_par = cmp_ima_max_spill(golomb_par)+1; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_EQUAL(1, error); ap1_golomb_par = MAX_IMA_GOLOMB_PAR; ap1_spillover_par = cmp_ima_max_spill(golomb_par)+1; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_EQUAL(1, error); ap1_golomb_par = MIN_IMA_GOLOMB_PAR; ap1_spillover_par = MIN_IMA_SPILL - 1; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_EQUAL(1, error); @@ -592,35 +555,35 @@ void test_rdcu_cfg_imagette(void) /* this should work */ ap1_golomb_par = MAX_IMA_GOLOMB_PAR; ap1_spillover_par = cmp_ima_max_spill(golomb_par); - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL(golomb_par, cfg.golomb_par); - TEST_ASSERT_EQUAL(spillover_par, cfg.spill); - TEST_ASSERT_EQUAL(ap1_golomb_par, cfg.ap1_golomb_par); - TEST_ASSERT_EQUAL(ap1_spillover_par, cfg.ap1_spill); - TEST_ASSERT_EQUAL(ap2_golomb_par, cfg.ap2_golomb_par); - TEST_ASSERT_EQUAL(ap2_spillover_par, cfg.ap2_spill); + TEST_ASSERT_EQUAL(golomb_par, rcfg.golomb_par); + TEST_ASSERT_EQUAL(spillover_par, rcfg.spill); + TEST_ASSERT_EQUAL(ap1_golomb_par, rcfg.ap1_golomb_par); + TEST_ASSERT_EQUAL(ap1_spillover_par, rcfg.ap1_spill); + TEST_ASSERT_EQUAL(ap2_golomb_par, rcfg.ap2_golomb_par); + TEST_ASSERT_EQUAL(ap2_spillover_par, rcfg.ap2_spill); /* wrong ap2_spillover_par */ ap2_golomb_par = MIN_IMA_GOLOMB_PAR; ap2_spillover_par = cmp_ima_max_spill(golomb_par)+1; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_EQUAL(1, error); ap2_golomb_par = MAX_IMA_GOLOMB_PAR; ap2_spillover_par = cmp_ima_max_spill(golomb_par)+1; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_EQUAL(1, error); ap2_golomb_par = MIN_IMA_GOLOMB_PAR; ap2_spillover_par = MIN_IMA_SPILL - 1; - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_EQUAL(1, error); @@ -628,16 +591,16 @@ void test_rdcu_cfg_imagette(void) /* this should work */ ap2_golomb_par = MAX_IMA_GOLOMB_PAR; ap2_spillover_par = cmp_ima_max_spill(golomb_par); - error = rdcu_cfg_imagette(&cfg, golomb_par, spillover_par, + error = rdcu_cfg_imagette(&rcfg, golomb_par, spillover_par, ap1_golomb_par, ap1_spillover_par, ap2_golomb_par, ap2_spillover_par); TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL(golomb_par, cfg.golomb_par); - TEST_ASSERT_EQUAL(spillover_par, cfg.spill); - TEST_ASSERT_EQUAL(ap1_golomb_par, cfg.ap1_golomb_par); - TEST_ASSERT_EQUAL(ap1_spillover_par, cfg.ap1_spill); - TEST_ASSERT_EQUAL(ap2_golomb_par, cfg.ap2_golomb_par); - TEST_ASSERT_EQUAL(ap2_spillover_par, cfg.ap2_spill); + TEST_ASSERT_EQUAL(golomb_par, rcfg.golomb_par); + TEST_ASSERT_EQUAL(spillover_par, rcfg.spill); + TEST_ASSERT_EQUAL(ap1_golomb_par, rcfg.ap1_golomb_par); + TEST_ASSERT_EQUAL(ap1_spillover_par, rcfg.ap1_spill); + TEST_ASSERT_EQUAL(ap2_golomb_par, rcfg.ap2_golomb_par); + TEST_ASSERT_EQUAL(ap2_spillover_par, rcfg.ap2_spill); /* cfg = NULL test */ error = rdcu_cfg_imagette(NULL, golomb_par, spillover_par, @@ -653,35 +616,35 @@ void test_rdcu_cfg_imagette(void) void test_rdcu_cfg_imagette_default(void) { int error; - struct cmp_cfg cfg; + struct rdcu_cfg rcfg; /* 1d configuration */ - cfg = rdcu_cfg_create(DATA_TYPE_IMAGETTE, CMP_MODE_DIFF_ZERO, 0, CMP_LOSSLESS); - TEST_ASSERT_NOT_EQUAL(DATA_TYPE_UNKNOWN, cfg.data_type); + error = rdcu_cfg_create(&rcfg, CMP_MODE_DIFF_ZERO, 0, CMP_LOSSLESS); + TEST_ASSERT_FALSE(error); - error = rdcu_cfg_imagette_default(&cfg); + error = rdcu_cfg_imagette_default(&rcfg); TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL(CMP_DEF_IMA_DIFF_GOLOMB_PAR, cfg.golomb_par); - TEST_ASSERT_EQUAL(CMP_DEF_IMA_DIFF_SPILL_PAR, cfg.spill); - TEST_ASSERT_EQUAL(CMP_DEF_IMA_DIFF_AP1_GOLOMB_PAR, cfg.ap1_golomb_par); - TEST_ASSERT_EQUAL(CMP_DEF_IMA_DIFF_AP1_SPILL_PAR, cfg.ap1_spill); - TEST_ASSERT_EQUAL(CMP_DEF_IMA_DIFF_AP2_GOLOMB_PAR, cfg.ap2_golomb_par); - TEST_ASSERT_EQUAL(CMP_DEF_IMA_DIFF_AP2_SPILL_PAR, cfg.ap2_spill); + TEST_ASSERT_EQUAL(CMP_DEF_IMA_DIFF_GOLOMB_PAR, rcfg.golomb_par); + TEST_ASSERT_EQUAL(CMP_DEF_IMA_DIFF_SPILL_PAR, rcfg.spill); + TEST_ASSERT_EQUAL(CMP_DEF_IMA_DIFF_AP1_GOLOMB_PAR, rcfg.ap1_golomb_par); + TEST_ASSERT_EQUAL(CMP_DEF_IMA_DIFF_AP1_SPILL_PAR, rcfg.ap1_spill); + TEST_ASSERT_EQUAL(CMP_DEF_IMA_DIFF_AP2_GOLOMB_PAR, rcfg.ap2_golomb_par); + TEST_ASSERT_EQUAL(CMP_DEF_IMA_DIFF_AP2_SPILL_PAR, rcfg.ap2_spill); /* 1d configuration */ - cfg = rdcu_cfg_create(DATA_TYPE_IMAGETTE_ADAPTIVE, CMP_MODE_MODEL_MULTI, 0, CMP_LOSSLESS); - TEST_ASSERT_NOT_EQUAL(DATA_TYPE_UNKNOWN, cfg.data_type); + error = rdcu_cfg_create(&rcfg, CMP_MODE_MODEL_MULTI, 0, CMP_LOSSLESS); + TEST_ASSERT_FALSE(error); - error = rdcu_cfg_imagette_default(&cfg); + error = rdcu_cfg_imagette_default(&rcfg); TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL(CMP_DEF_IMA_MODEL_GOLOMB_PAR, cfg.golomb_par); - TEST_ASSERT_EQUAL(CMP_DEF_IMA_MODEL_SPILL_PAR, cfg.spill); - TEST_ASSERT_EQUAL(CMP_DEF_IMA_MODEL_AP1_GOLOMB_PAR, cfg.ap1_golomb_par); - TEST_ASSERT_EQUAL(CMP_DEF_IMA_MODEL_AP1_SPILL_PAR, cfg.ap1_spill); - TEST_ASSERT_EQUAL(CMP_DEF_IMA_MODEL_AP2_GOLOMB_PAR, cfg.ap2_golomb_par); - TEST_ASSERT_EQUAL(CMP_DEF_IMA_MODEL_AP2_SPILL_PAR, cfg.ap2_spill); + TEST_ASSERT_EQUAL(CMP_DEF_IMA_MODEL_GOLOMB_PAR, rcfg.golomb_par); + TEST_ASSERT_EQUAL(CMP_DEF_IMA_MODEL_SPILL_PAR, rcfg.spill); + TEST_ASSERT_EQUAL(CMP_DEF_IMA_MODEL_AP1_GOLOMB_PAR, rcfg.ap1_golomb_par); + TEST_ASSERT_EQUAL(CMP_DEF_IMA_MODEL_AP1_SPILL_PAR, rcfg.ap1_spill); + TEST_ASSERT_EQUAL(CMP_DEF_IMA_MODEL_AP2_GOLOMB_PAR, rcfg.ap2_golomb_par); + TEST_ASSERT_EQUAL(CMP_DEF_IMA_MODEL_AP2_SPILL_PAR, rcfg.ap2_spill); /* error case */ error = rdcu_cfg_imagette_default(NULL); @@ -696,55 +659,61 @@ void test_rdcu_cfg_imagette_default(void) void test_rdcu_cmp_cfg_is_invalid(void) { int error; - struct cmp_cfg cfg; + struct rdcu_cfg rcfg; uint16_t data[1] = {1}; uint16_t model[1] = {2}; /* diff test */ - cfg = rdcu_cfg_create(DATA_TYPE_IMAGETTE, CMP_DEF_IMA_DIFF_CMP_MODE, - CMP_DEF_IMA_DIFF_MODEL_VALUE, CMP_DEF_IMA_DIFF_LOSSY_PAR); - error = rdcu_cfg_buffers(&cfg, data, 1, NULL, CMP_DEF_IMA_DIFF_RDCU_DATA_ADR, + error = rdcu_cfg_create(&rcfg, CMP_DEF_IMA_DIFF_CMP_MODE, + CMP_DEF_IMA_DIFF_MODEL_VALUE, + CMP_DEF_IMA_DIFF_LOSSY_PAR); + TEST_ASSERT_FALSE(error); + error = rdcu_cfg_buffers(&rcfg, data, 1, NULL, CMP_DEF_IMA_DIFF_RDCU_DATA_ADR, CMP_DEF_IMA_DIFF_RDCU_MODEL_ADR, CMP_DEF_IMA_DIFF_RDCU_UP_MODEL_ADR, CMP_DEF_IMA_DIFF_RDCU_BUFFER_ADR, 1); TEST_ASSERT_FALSE(error); - error = rdcu_cfg_imagette(&cfg, + error = rdcu_cfg_imagette(&rcfg, CMP_DEF_IMA_DIFF_GOLOMB_PAR, CMP_DEF_IMA_DIFF_SPILL_PAR, CMP_DEF_IMA_DIFF_AP1_GOLOMB_PAR, CMP_DEF_IMA_DIFF_AP1_SPILL_PAR, CMP_DEF_IMA_DIFF_AP2_GOLOMB_PAR, CMP_DEF_IMA_DIFF_AP2_SPILL_PAR); TEST_ASSERT_FALSE(error); - error = rdcu_cmp_cfg_is_invalid(&cfg); + error = rdcu_cmp_cfg_is_invalid(&rcfg); TEST_ASSERT_FALSE(error); /* model test */ - cfg = rdcu_cfg_create(DATA_TYPE_IMAGETTE, CMP_DEF_IMA_MODEL_CMP_MODE, - CMP_DEF_IMA_MODEL_MODEL_VALUE, CMP_DEF_IMA_MODEL_LOSSY_PAR); - error = rdcu_cfg_buffers(&cfg, data, 1, model, CMP_DEF_IMA_MODEL_RDCU_DATA_ADR, + error = rdcu_cfg_create(&rcfg, CMP_DEF_IMA_MODEL_CMP_MODE, + CMP_DEF_IMA_MODEL_MODEL_VALUE, + CMP_DEF_IMA_MODEL_LOSSY_PAR); + TEST_ASSERT_FALSE(error); + error = rdcu_cfg_buffers(&rcfg, data, 1, model, CMP_DEF_IMA_MODEL_RDCU_DATA_ADR, CMP_DEF_IMA_MODEL_RDCU_MODEL_ADR, CMP_DEF_IMA_MODEL_RDCU_UP_MODEL_ADR, CMP_DEF_IMA_MODEL_RDCU_BUFFER_ADR, 1); TEST_ASSERT_FALSE(error); - error = rdcu_cfg_imagette(&cfg, + error = rdcu_cfg_imagette(&rcfg, CMP_DEF_IMA_MODEL_GOLOMB_PAR, CMP_DEF_IMA_MODEL_SPILL_PAR, CMP_DEF_IMA_MODEL_AP1_GOLOMB_PAR, CMP_DEF_IMA_MODEL_AP1_SPILL_PAR, CMP_DEF_IMA_MODEL_AP2_GOLOMB_PAR, CMP_DEF_IMA_MODEL_AP2_SPILL_PAR); TEST_ASSERT_FALSE(error); - error = rdcu_cmp_cfg_is_invalid(&cfg); + error = rdcu_cmp_cfg_is_invalid(&rcfg); TEST_ASSERT_FALSE(error); /* test warnings */ - cfg = rdcu_cfg_create(DATA_TYPE_IMAGETTE, CMP_DEF_IMA_MODEL_CMP_MODE, - CMP_DEF_IMA_MODEL_MODEL_VALUE, CMP_DEF_IMA_MODEL_LOSSY_PAR); - error = rdcu_cfg_buffers(&cfg, NULL, 0, NULL, CMP_DEF_IMA_MODEL_RDCU_DATA_ADR, + error = rdcu_cfg_create(&rcfg, CMP_DEF_IMA_MODEL_CMP_MODE, + CMP_DEF_IMA_MODEL_MODEL_VALUE, + CMP_DEF_IMA_MODEL_LOSSY_PAR); + TEST_ASSERT_FALSE(error); + error = rdcu_cfg_buffers(&rcfg, NULL, 0, NULL, CMP_DEF_IMA_MODEL_RDCU_DATA_ADR, CMP_DEF_IMA_MODEL_RDCU_MODEL_ADR, CMP_DEF_IMA_MODEL_RDCU_UP_MODEL_ADR, CMP_DEF_IMA_MODEL_RDCU_BUFFER_ADR, 1); TEST_ASSERT_FALSE(error); - error = rdcu_cfg_imagette(&cfg, + error = rdcu_cfg_imagette(&rcfg, CMP_DEF_IMA_MODEL_GOLOMB_PAR, CMP_DEF_IMA_MODEL_SPILL_PAR, CMP_DEF_IMA_MODEL_AP1_GOLOMB_PAR, CMP_DEF_IMA_MODEL_AP1_SPILL_PAR, CMP_DEF_IMA_MODEL_AP2_GOLOMB_PAR, CMP_DEF_IMA_MODEL_AP2_SPILL_PAR); TEST_ASSERT_FALSE(error); - cfg.icu_new_model_buf = data; - cfg.icu_output_buf = (void *)model; - error = rdcu_cmp_cfg_is_invalid(&cfg); + rcfg.icu_new_model_buf = data; + rcfg.icu_output_buf = (void *)model; + error = rdcu_cmp_cfg_is_invalid(&rcfg); TEST_ASSERT_FALSE(error); /* error: cfg is NULL */ @@ -752,63 +721,70 @@ void test_rdcu_cmp_cfg_is_invalid(void) TEST_ASSERT_TRUE(error); /* error: buffer length = 0 */ - cfg = rdcu_cfg_create(DATA_TYPE_IMAGETTE, CMP_DEF_IMA_MODEL_CMP_MODE, - CMP_DEF_IMA_MODEL_MODEL_VALUE, CMP_DEF_IMA_MODEL_LOSSY_PAR); - error = rdcu_cfg_buffers(&cfg, data, 1, model, CMP_DEF_IMA_MODEL_RDCU_DATA_ADR, + error = rdcu_cfg_create(&rcfg, CMP_DEF_IMA_MODEL_CMP_MODE, + CMP_DEF_IMA_MODEL_MODEL_VALUE, + CMP_DEF_IMA_MODEL_LOSSY_PAR); + TEST_ASSERT_FALSE(error); + error = rdcu_cfg_buffers(&rcfg, data, 1, model, CMP_DEF_IMA_MODEL_RDCU_DATA_ADR, CMP_DEF_IMA_MODEL_RDCU_MODEL_ADR, CMP_DEF_IMA_MODEL_RDCU_UP_MODEL_ADR, CMP_DEF_IMA_MODEL_RDCU_BUFFER_ADR, 0); TEST_ASSERT_FALSE(error); - error = rdcu_cfg_imagette(&cfg, + error = rdcu_cfg_imagette(&rcfg, CMP_DEF_IMA_MODEL_GOLOMB_PAR, CMP_DEF_IMA_MODEL_SPILL_PAR, CMP_DEF_IMA_MODEL_AP1_GOLOMB_PAR, CMP_DEF_IMA_MODEL_AP1_SPILL_PAR, CMP_DEF_IMA_MODEL_AP2_GOLOMB_PAR, CMP_DEF_IMA_MODEL_AP2_SPILL_PAR); TEST_ASSERT_FALSE(error); - error = rdcu_cmp_cfg_is_invalid(&cfg); + error = rdcu_cmp_cfg_is_invalid(&rcfg); TEST_ASSERT_TRUE(error); /* error: wrong gen par */ - cfg = rdcu_cfg_create(DATA_TYPE_IMAGETTE, CMP_DEF_IMA_DIFF_CMP_MODE, - MAX_MODEL_VALUE+1, CMP_DEF_IMA_DIFF_LOSSY_PAR); - cfg.data_type = DATA_TYPE_IMAGETTE; - error = rdcu_cfg_buffers(&cfg, data, 1, NULL, CMP_DEF_IMA_DIFF_RDCU_DATA_ADR, + error = rdcu_cfg_create(&rcfg, CMP_DEF_IMA_DIFF_CMP_MODE, + MAX_MODEL_VALUE+1, CMP_DEF_IMA_DIFF_LOSSY_PAR); + TEST_ASSERT_TRUE(error); + rcfg.model_value = 32; + error = rdcu_cfg_buffers(&rcfg, data, 1, NULL, CMP_DEF_IMA_DIFF_RDCU_DATA_ADR, CMP_DEF_IMA_DIFF_RDCU_MODEL_ADR, CMP_DEF_IMA_DIFF_RDCU_UP_MODEL_ADR, CMP_DEF_IMA_DIFF_RDCU_BUFFER_ADR, 1); TEST_ASSERT_FALSE(error); - error = rdcu_cfg_imagette(&cfg, + error = rdcu_cfg_imagette(&rcfg, CMP_DEF_IMA_DIFF_GOLOMB_PAR, CMP_DEF_IMA_DIFF_SPILL_PAR, CMP_DEF_IMA_DIFF_AP1_GOLOMB_PAR, CMP_DEF_IMA_DIFF_AP1_SPILL_PAR, CMP_DEF_IMA_DIFF_AP2_GOLOMB_PAR, CMP_DEF_IMA_DIFF_AP2_SPILL_PAR); TEST_ASSERT_FALSE(error); - error = rdcu_cmp_cfg_is_invalid(&cfg); + error = rdcu_cmp_cfg_is_invalid(&rcfg); TEST_ASSERT_TRUE(error); /* error: wrong buffers config */ - cfg = rdcu_cfg_create(DATA_TYPE_IMAGETTE, CMP_DEF_IMA_DIFF_CMP_MODE, - CMP_DEF_IMA_DIFF_MODEL_VALUE, CMP_DEF_IMA_DIFF_LOSSY_PAR); - error = rdcu_cfg_buffers(&cfg, data, 1, NULL, RDCU_SRAM_END+4, + error = rdcu_cfg_create(&rcfg, CMP_DEF_IMA_DIFF_CMP_MODE, + CMP_DEF_IMA_DIFF_MODEL_VALUE, + CMP_DEF_IMA_DIFF_LOSSY_PAR); + TEST_ASSERT_FALSE(error); + error = rdcu_cfg_buffers(&rcfg, data, 1, NULL, RDCU_SRAM_END+4, CMP_DEF_IMA_DIFF_RDCU_MODEL_ADR, CMP_DEF_IMA_DIFF_RDCU_UP_MODEL_ADR, CMP_DEF_IMA_DIFF_RDCU_BUFFER_ADR, 1); TEST_ASSERT_TRUE(error); - error = rdcu_cfg_imagette(&cfg, + error = rdcu_cfg_imagette(&rcfg, CMP_DEF_IMA_DIFF_GOLOMB_PAR, CMP_DEF_IMA_DIFF_SPILL_PAR, CMP_DEF_IMA_DIFF_AP1_GOLOMB_PAR, CMP_DEF_IMA_DIFF_AP1_SPILL_PAR, CMP_DEF_IMA_DIFF_AP2_GOLOMB_PAR, CMP_DEF_IMA_DIFF_AP2_SPILL_PAR); TEST_ASSERT_FALSE(error); - error = rdcu_cmp_cfg_is_invalid(&cfg); + error = rdcu_cmp_cfg_is_invalid(&rcfg); TEST_ASSERT_TRUE(error); /* error: wrong compression parameter test */ - cfg = rdcu_cfg_create(DATA_TYPE_IMAGETTE, CMP_DEF_IMA_DIFF_CMP_MODE, - CMP_DEF_IMA_DIFF_MODEL_VALUE, CMP_DEF_IMA_DIFF_LOSSY_PAR); - error = rdcu_cfg_buffers(&cfg, data, 1, NULL, CMP_DEF_IMA_DIFF_RDCU_DATA_ADR, + error = rdcu_cfg_create(&rcfg, CMP_DEF_IMA_DIFF_CMP_MODE, + CMP_DEF_IMA_DIFF_MODEL_VALUE, + CMP_DEF_IMA_DIFF_LOSSY_PAR); + TEST_ASSERT_FALSE(error); + error = rdcu_cfg_buffers(&rcfg, data, 1, NULL, CMP_DEF_IMA_DIFF_RDCU_DATA_ADR, CMP_DEF_IMA_DIFF_RDCU_MODEL_ADR, CMP_DEF_IMA_DIFF_RDCU_UP_MODEL_ADR, CMP_DEF_IMA_DIFF_RDCU_BUFFER_ADR, 1); TEST_ASSERT_FALSE(error); - error = rdcu_cfg_imagette(&cfg, + error = rdcu_cfg_imagette(&rcfg, MAX_IMA_GOLOMB_PAR+1, CMP_DEF_IMA_DIFF_SPILL_PAR, CMP_DEF_IMA_DIFF_AP1_GOLOMB_PAR, CMP_DEF_IMA_DIFF_AP1_SPILL_PAR, CMP_DEF_IMA_DIFF_AP2_GOLOMB_PAR, CMP_DEF_IMA_DIFF_AP2_SPILL_PAR); TEST_ASSERT_TRUE(error); - error = rdcu_cmp_cfg_is_invalid(&cfg); + error = rdcu_cmp_cfg_is_invalid(&rcfg); TEST_ASSERT_TRUE(error); } diff --git a/test/decmp/test_decmp.c b/test/decmp/test_decmp.c index 39765d89faee393a07d3ef4033245d5d9b726463..a3637844d856147345f32bb5e297ecfcb8c1fcd5 100644 --- a/test/decmp/test_decmp.c +++ b/test/decmp/test_decmp.c @@ -947,86 +947,42 @@ void test_re_map_to_pos(void) /** - * returns the needed size of the compression entry header plus the max size of the - * compressed data if ent == NULL if ent is set the size of the compression - * entry (entity header + compressed data) + * @test decompress_cmp_entiy */ -size_t icu_compress_data_entity(struct cmp_entity *ent, const struct cmp_cfg *cfg) -{ - uint32_t s; - struct cmp_cfg cfg_cpy; - int cmp_size_bits; - - if (!cfg) - return 0; - - if (cfg->icu_output_buf) - debug_print("Warning the set buffer for the compressed data is ignored! The compressed data are write to the compression entry."); - - s = cmp_cal_size_of_data(cfg->buffer_length, cfg->data_type); - if (!s) - return 0; - /* we round down to the next 4-byte allied address because we access the - * cmp_buffer in uint32_t words - */ - if (cfg->cmp_mode != CMP_MODE_RAW) - s &= ~0x3U; - - s = cmp_ent_create(ent, cfg->data_type, cfg->cmp_mode == CMP_MODE_RAW, s); - - if (!ent || !s) - return s; - - cfg_cpy = *cfg; - cfg_cpy.icu_output_buf = cmp_ent_get_data_buf(ent); - if (!cfg_cpy.icu_output_buf) - return 0; - cmp_size_bits = icu_compress_data(&cfg_cpy); - if (cmp_size_bits < 0) - return 0; - - /* XXX overwrite the size of the compression entity with the size of the actual - * size of the compressed data; not all allocated memory is normally used - */ - s = cmp_ent_create(ent, cfg->data_type, cfg->cmp_mode == CMP_MODE_RAW, - cmp_bit_to_byte((unsigned int)cmp_size_bits)); - - if (cmp_ent_write_cmp_pars(ent, cfg, cmp_size_bits)) - return 0; - - return s; -} - - -void test_cmp_decmp_n_imagette_raw(void) +void test_cmp_decmp_rdcu_raw(void) { int cmp_size, decmp_size; size_t s, i; - struct cmp_cfg cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_RAW, 0, CMP_LOSSLESS); + struct rdcu_cfg rcfg = {0}; + struct cmp_info info; uint16_t data[] = {0, 1, 2, 0x42, (uint16_t)INT16_MIN, INT16_MAX, UINT16_MAX}; uint32_t *compressed_data; uint16_t *decompressed_data; struct cmp_entity *ent; - s = cmp_cfg_icu_buffers(&cfg, data, ARRAY_SIZE(data), NULL, NULL, - NULL, ARRAY_SIZE(data)); - TEST_ASSERT_TRUE(s); - compressed_data = malloc(s); + rcfg.cmp_mode = CMP_MODE_RAW; + rcfg.input_buf = data; + rcfg.samples = ARRAY_SIZE(data); + rcfg.buffer_length = ARRAY_SIZE(data); + + compressed_data = malloc(sizeof(data)); TEST_ASSERT_TRUE(compressed_data); - s = cmp_cfg_icu_buffers(&cfg, data, ARRAY_SIZE(data), NULL, NULL, - compressed_data, ARRAY_SIZE(data)); - TEST_ASSERT_TRUE(s); + rcfg.icu_output_buf = compressed_data; - cmp_size = icu_compress_data(&cfg); + cmp_size = compress_like_rdcu(&rcfg, &info); TEST_ASSERT_EQUAL_INT(sizeof(data)*CHAR_BIT, cmp_size); - s = cmp_ent_build(NULL, 0, 0, 0, 0, 0, &cfg, cmp_size); + s = cmp_ent_create(NULL, DATA_TYPE_IMAGETTE , rcfg.cmp_mode == CMP_MODE_RAW, + cmp_bit_to_byte((unsigned int)cmp_size)); TEST_ASSERT_TRUE(s); ent = malloc(s); TEST_ASSERT_TRUE(ent); - s = cmp_ent_build(ent, 0, 0, 0, 0, 0, &cfg, cmp_size); + s = cmp_ent_create(ent, DATA_TYPE_IMAGETTE , rcfg.cmp_mode == CMP_MODE_RAW, + cmp_bit_to_byte((unsigned int)cmp_size)); TEST_ASSERT_TRUE(s); + TEST_ASSERT_FALSE(cmp_ent_write_rdcu_cmp_pars(ent, &info, NULL)); + memcpy(cmp_ent_get_data_buf(ent), compressed_data, ((unsigned int)cmp_size+7)/8); decmp_size = decompress_cmp_entiy(ent, NULL, NULL, NULL); @@ -1046,6 +1002,10 @@ void test_cmp_decmp_n_imagette_raw(void) } +/** + * @test decompress_imagette + */ + void test_decompress_imagette_model(void) { uint16_t data[5] = {0};