From a6bc7b3e211d1d4e95cc875ea2192efef4ce145a Mon Sep 17 00:00:00 2001 From: Dominik Loidolt <dominik.loidolt@univie.ac.at> Date: Thu, 1 Sep 2022 14:02:50 +0200 Subject: [PATCH] fix a bug in the model update; add a test for this bug warn if -m option is used without model compression mode read in compression parameter for non-imagette compression --- cmp_tool.c | 8 +- lib/cmp_io.c | 143 +++++++++++++++------ test/cmp_tool/cmp_tool_integration_test.py | 6 +- 3 files changed, 112 insertions(+), 45 deletions(-) diff --git a/cmp_tool.c b/cmp_tool.c index 54e20ab..0cf72ef 100644 --- a/cmp_tool.c +++ b/cmp_tool.c @@ -424,6 +424,11 @@ int main(int argc, char **argv) printf("DONE\n"); } + if (model_file_name && !guess_operation && + ((cmp_operation && !model_mode_is_used(cfg.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)) || (!cmp_operation && model_mode_is_used(cmp_ent_get_cmp_mode(decomp_entity))) || @@ -459,6 +464,7 @@ int main(int argc, char **argv) printf("DONE\n"); cfg.model_buf = input_model_buf; + cfg.icu_new_model_buf = input_model_buf; /* in-place model update */ } if (guess_operation) { @@ -479,7 +485,7 @@ int main(int argc, char **argv) if (!guess_operation && ((cmp_operation && model_mode_is_used(cfg.cmp_mode)) || (!cmp_operation && model_mode_is_used(cmp_ent_get_cmp_mode(decomp_entity))))) { - enum cmp_data_type data_type = DATA_TYPE_UNKOWN; + enum cmp_data_type data_type = DATA_TYPE_UNKNOWN; uint32_t model_size; printf("Write updated model to file %s_upmodel.dat ... ", output_prefix); diff --git a/lib/cmp_io.c b/lib/cmp_io.c index 9e4eb3a..83c6906 100644 --- a/lib/cmp_io.c +++ b/lib/cmp_io.c @@ -61,7 +61,7 @@ static const struct { {DATA_TYPE_F_CAM_IMAGETTE_ADAPTIVE, "DATA_TYPE_F_CAM_IMAGETTE_ADAPTIVE"}, {DATA_TYPE_F_CAM_OFFSET, "DATA_TYPE_F_CAM_OFFSET"}, {DATA_TYPE_F_CAM_BACKGROUND, "DATA_TYPE_F_CAM_BACKGROUND"}, - {DATA_TYPE_UNKOWN, "DATA_TYPE_UNKOWN"} + {DATA_TYPE_UNKNOWN, "DATA_TYPE_UNKNOWN"} }; @@ -403,12 +403,12 @@ int atoui32(const char *dep_str, const char *val_str, uint32_t *red_val) * * @param data_type_str string containing the compression data type to parse * - * @returns data type on success, DATA_TYPE_UNKOWN on error + * @returns data type on success, DATA_TYPE_UNKNOWN on error */ enum cmp_data_type string2data_type(const char *data_type_str) { - enum cmp_data_type data_type = DATA_TYPE_UNKOWN; + enum cmp_data_type data_type = DATA_TYPE_UNKNOWN; if (data_type_str) { if (isalpha(data_type_str[0])) { /* check if mode is given as text */ @@ -426,7 +426,7 @@ enum cmp_data_type string2data_type(const char *data_type_str) if (!atoui32("Compression Data Type", data_type_str, &read_val)) { data_type = read_val; if (!cmp_data_type_valid(data_type)) - data_type = DATA_TYPE_UNKOWN; + data_type = DATA_TYPE_UNKNOWN; } } } @@ -439,13 +439,13 @@ enum cmp_data_type string2data_type(const char *data_type_str) * * @param data_type compression data type to convert in string * - * @returns data type on success, DATA_TYPE_UNKOWN on error + * @returns data type on success, DATA_TYPE_UNKNOWN on error */ const char *data_type2string(enum cmp_data_type data_type) { size_t j; - const char *string = "DATA_TYPE_UNKOWN"; + const char *string = "DATA_TYPE_UNKNOWN"; for (j = 0; j < sizeof(data_type_string_table) / sizeof(data_type_string_table[0]); j++) { if (data_type == data_type_string_table[j].data_type) { @@ -527,7 +527,7 @@ static int parse_cfg(FILE *fp, struct cmp_cfg *cfg) { char *token1, *token2; char line[MAX_CONFIG_LINE]; - enum {CMP_MODE, GOLOMB_PAR, SPILL, SAMPLES, BUFFER_LENGTH, LAST_ITEM}; + enum {CMP_MODE, SAMPLES, BUFFER_LENGTH, LAST_ITEM}; int j, must_read_items[LAST_ITEM] = {0}; if (!fp) @@ -559,53 +559,24 @@ static int parse_cfg(FILE *fp, struct cmp_cfg *cfg) if (!strcmp(token1, "data_type")) { cfg->data_type = string2data_type(token2); - if (cfg->data_type == DATA_TYPE_UNKOWN) + if (cfg->data_type == DATA_TYPE_UNKNOWN) return -1; continue; } if (!strcmp(token1, "cmp_mode")) { must_read_items[CMP_MODE] = 1; - if (isalpha(*token2)) { /* check if mode is given as text or val*/ - /* TODO: use conversion function for this: */ - if (!strcmp(token2, "MODE_RAW")) { - cfg->cmp_mode = 0; - continue; - } - if (!strcmp(token2, "MODE_MODEL_ZERO")) { - cfg->cmp_mode = 1; - continue; - } - if (!strcmp(token2, "MODE_DIFF_ZERO")) { - cfg->cmp_mode = 2; - continue; - } - if (!strcmp(token2, "MODE_MODEL_MULTI")) { - cfg->cmp_mode = 3; - continue; - } - if (!strcmp(token2, "MODE_DIFF_MULTI")) { - cfg->cmp_mode = 4; - continue; - } - fprintf(stderr, "%s: Error read in cmp_mode.\n", - PROGRAM_NAME); + if (cmp_mode_parse(token2, &cfg->cmp_mode)) return -1; - } else { - if (atoui32(token1, token2, &cfg->cmp_mode)) - return -1; - continue; - } + continue; } if (!strcmp(token1, "golomb_par")) { if (atoui32(token1, token2, &cfg->golomb_par)) return -1; - must_read_items[GOLOMB_PAR] = 1; continue; } if (!strcmp(token1, "spill")) { if (atoui32(token1, token2, &cfg->spill)) return -1; - must_read_items[SPILL] = 1; continue; } if (!strcmp(token1, "model_value")) { @@ -638,6 +609,96 @@ static int parse_cfg(FILE *fp, struct cmp_cfg *cfg) return -1; continue; } + if (!strcmp(token1, "cmp_par_exp_flags")) { + if (atoui32(token1, token2, &cfg->cmp_par_exp_flags)) + return -1; + continue; + } + if (!strcmp(token1, "spill_exp_flags")) { + if (atoui32(token1, token2, &cfg->spill_exp_flags)) + return -1; + continue; + } + if (!strcmp(token1, "cmp_par_fx")) { + if (atoui32(token1, token2, &cfg->cmp_par_fx)) + return -1; + continue; + } + if (!strcmp(token1, "spill_fx")) { + if (atoui32(token1, token2, &cfg->spill_fx)) + return -1; + continue; + } + if (!strcmp(token1, "cmp_par_ncob")) { + if (atoui32(token1, token2, &cfg->cmp_par_ncob)) + return -1; + continue; + } + if (!strcmp(token1, "spill_ncob")) { + if (atoui32(token1, token2, &cfg->spill_ncob)) + return -1; + continue; + } + if (!strcmp(token1, "cmp_par_efx")) { + if (atoui32(token1, token2, &cfg->cmp_par_efx)) + return -1; + continue; + } + if (!strcmp(token1, "spill_efx")) { + if (atoui32(token1, token2, &cfg->spill_efx)) + return -1; + continue; + } + if (!strcmp(token1, "cmp_par_ecob")) { + if (atoui32(token1, token2, &cfg->cmp_par_ecob)) + return -1; + continue; + } + if (!strcmp(token1, "spill_ecob")) { + if (atoui32(token1, token2, &cfg->spill_ecob)) + return -1; + continue; + } + if (!strcmp(token1, "cmp_par_fx_cob_variance")) { + if (atoui32(token1, token2, &cfg->cmp_par_fx_cob_variance)) + return -1; + continue; + } + if (!strcmp(token1, "spill_fx_cob_variance")) { + if (atoui32(token1, token2, &cfg->spill_fx_cob_variance)) + return -1; + continue; + } + if (!strcmp(token1, "cmp_par_mean")) { + if (atoui32(token1, token2, &cfg->cmp_par_mean)) + return -1; + continue; + } + if (!strcmp(token1, "spill_mean")) { + if (atoui32(token1, token2, &cfg->spill_mean)) + return -1; + continue; + } + if (!strcmp(token1, "cmp_par_variance")) { + if (atoui32(token1, token2, &cfg->cmp_par_variance)) + return -1; + continue; + } + if (!strcmp(token1, "spill_variance")) { + if (atoui32(token1, token2, &cfg->spill_variance)) + return -1; + continue; + } + if (!strcmp(token1, "cmp_par_pixels_error")) { + if (atoui32(token1, token2, &cfg->cmp_par_pixels_error)) + return -1; + continue; + } + if (!strcmp(token1, "spill_pixels_error")) { + if (atoui32(token1, token2, &cfg->spill_pixels_error)) + return -1; + continue; + } if (!strcmp(token1, "rdcu_data_adr")) { int i = sram_addr_to_int(token2); @@ -1384,7 +1445,7 @@ ssize_t read_file_cmp_entity(const char *file_name, struct cmp_entity *ent, if (ent) { enum cmp_data_type data_type = cmp_ent_get_data_type(ent); - if (data_type == DATA_TYPE_UNKOWN) { + if (data_type == DATA_TYPE_UNKNOWN) { fprintf(stderr, "%s: %s: Error: Compression data type is not supported.\n", PROGRAM_NAME, file_name); return -1; @@ -1501,7 +1562,7 @@ static void write_cfg_internal(FILE *fp, const struct cmp_cfg *cfg, int rdcu_cfg fprintf(fp, "#-------------------------------------------------------------------------------\n"); fprintf(fp, "# Selected compression data type\n"); fprintf(fp, "\n"); - fprintf(fp, "data_type = %u\n", cfg->data_type); + fprintf(fp, "data_type = %s\n", data_type2string(cfg->data_type)); fprintf(fp, "\n"); fprintf(fp, "# Selected compression mode\n"); fprintf(fp, "# 0: raw mode\n"); diff --git a/test/cmp_tool/cmp_tool_integration_test.py b/test/cmp_tool/cmp_tool_integration_test.py index aac8b0b..f08d53b 100755 --- a/test/cmp_tool/cmp_tool_integration_test.py +++ b/test/cmp_tool/cmp_tool_integration_test.py @@ -481,7 +481,7 @@ def test_model_compression(): assert(stderr == "") cfg = parse_key_value(stdout) cfg['cmp_mode'] = 'MODE_MODEL_MULTI' - cfg['model_value'] = '16' + cfg['model_value'] = '0' cfg["samples"] = '5' cfg["buffer_length"] = '2' for key, value in cfg.items(): @@ -566,8 +566,8 @@ def test_model_compression(): with open(output_prefix1+"_upmodel.dat", encoding='utf-8') as f1: with open(output_prefix2+"_upmodel.dat", encoding='utf-8') as f2: - assert(f1.read() == f2.read() == - '00 00 00 01 00 02 00 03 00 04 \n') + assert(f1.read() == f2.read() == data) # upmodel == data -> model_value = 0 + # '00 00 00 01 00 02 00 03 00 04 \n') # clean up finally: del_file(data_file_name) -- GitLab