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

now the adaptive compression size (ap1_cmp_size, ap2_cmp_size) is calculate...

now the adaptive compression size (ap1_cmp_size, ap2_cmp_size) is calculate when the --rdcu_par option is used
parent 7ee4798b
No related branches found
No related tags found
1 merge request!11decompression/compression for non-imagette data
...@@ -90,7 +90,7 @@ static const char *output_prefix = DEFAULT_OUTPUT_PREFIX; ...@@ -90,7 +90,7 @@ static const char *output_prefix = DEFAULT_OUTPUT_PREFIX;
/* if non zero additional RDCU parameters are included in the compression /* if non zero additional RDCU parameters are included in the compression
* configuration and decompression information files */ * configuration and decompression information files */
static int print_rdcu_cfg; static int add_rdcu_pars;
/* if non zero generate RDCU setup packets */ /* if non zero generate RDCU setup packets */
static int rdcu_pkt_mode; static int rdcu_pkt_mode;
...@@ -160,7 +160,7 @@ int main(int argc, char **argv) ...@@ -160,7 +160,7 @@ int main(int argc, char **argv)
NULL)) != -1) { NULL)) != -1) {
switch (opt) { switch (opt) {
case 'a': /* --rdcu_par */ case 'a': /* --rdcu_par */
print_rdcu_cfg = 1; add_rdcu_pars = 1;
break; break;
case 'c': case 'c':
cmp_operation = 1; cmp_operation = 1;
...@@ -271,7 +271,7 @@ int main(int argc, char **argv) ...@@ -271,7 +271,7 @@ int main(int argc, char **argv)
CMP_DEF_IMA_MODEL_GOLOMB_PAR, CMP_DEF_IMA_MODEL_SPILL_PAR, 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_AP1_GOLOMB_PAR, CMP_DEF_IMA_MODEL_AP1_SPILL_PAR,
CMP_DEF_IMA_MODEL_AP2_GOLOMB_PAR, CMP_DEF_IMA_MODEL_AP2_SPILL_PAR); CMP_DEF_IMA_MODEL_AP2_GOLOMB_PAR, CMP_DEF_IMA_MODEL_AP2_SPILL_PAR);
print_cfg(&cfg, print_rdcu_cfg); print_cfg(&cfg, add_rdcu_pars);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
...@@ -285,7 +285,7 @@ int main(int argc, char **argv) ...@@ -285,7 +285,7 @@ int main(int argc, char **argv)
CMP_DEF_IMA_DIFF_GOLOMB_PAR, CMP_DEF_IMA_DIFF_SPILL_PAR, 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_AP1_GOLOMB_PAR, CMP_DEF_IMA_DIFF_AP1_SPILL_PAR,
CMP_DEF_IMA_DIFF_AP2_GOLOMB_PAR, CMP_DEF_IMA_DIFF_AP2_SPILL_PAR); CMP_DEF_IMA_DIFF_AP2_GOLOMB_PAR, CMP_DEF_IMA_DIFF_AP2_SPILL_PAR);
print_cfg(&cfg, print_rdcu_cfg); print_cfg(&cfg, add_rdcu_pars);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
...@@ -369,7 +369,7 @@ int main(int argc, char **argv) ...@@ -369,7 +369,7 @@ int main(int argc, char **argv)
ent_size = cmp_ent_create(NULL, DATA_TYPE_IMAGETTE, info.cmp_mode_used == CMP_MODE_RAW, ent_size = cmp_ent_create(NULL, DATA_TYPE_IMAGETTE, info.cmp_mode_used == CMP_MODE_RAW,
cmp_size_byte); cmp_size_byte);
if (ent_size <= 0) if (!ent_size)
goto fail; goto fail;
decomp_entity = malloc(ent_size); decomp_entity = malloc(ent_size);
if (!decomp_entity) { if (!decomp_entity) {
...@@ -378,7 +378,7 @@ int main(int argc, char **argv) ...@@ -378,7 +378,7 @@ int main(int argc, char **argv)
} }
ent_size = cmp_ent_create(decomp_entity, DATA_TYPE_IMAGETTE, info.cmp_mode_used == CMP_MODE_RAW, ent_size = cmp_ent_create(decomp_entity, DATA_TYPE_IMAGETTE, info.cmp_mode_used == CMP_MODE_RAW,
cmp_size_byte); cmp_size_byte);
if (ent_size <= 0) if (!ent_size)
goto fail; goto fail;
if (info.cmp_mode_used == CMP_MODE_RAW) if (info.cmp_mode_used == CMP_MODE_RAW)
...@@ -531,7 +531,7 @@ static int guess_cmp_pars(struct cmp_cfg *cfg, const char *guess_cmp_mode, ...@@ -531,7 +531,7 @@ static int guess_cmp_pars(struct cmp_cfg *cfg, const char *guess_cmp_mode,
printf("Search for a good set of compression parameters (level: %d) ... ", guess_level); printf("Search for a good set of compression parameters (level: %d) ... ", guess_level);
if (!strcmp(guess_cmp_mode, "RDCU")) { if (!strcmp(guess_cmp_mode, "RDCU")) {
if (print_rdcu_cfg) if (add_rdcu_pars)
cfg->data_type = DATA_TYPE_IMAGETTE_ADAPTIVE; cfg->data_type = DATA_TYPE_IMAGETTE_ADAPTIVE;
else else
cfg->data_type = DATA_TYPE_IMAGETTE; cfg->data_type = DATA_TYPE_IMAGETTE;
...@@ -563,7 +563,7 @@ static int guess_cmp_pars(struct cmp_cfg *cfg, const char *guess_cmp_mode, ...@@ -563,7 +563,7 @@ static int guess_cmp_pars(struct cmp_cfg *cfg, const char *guess_cmp_mode,
printf("DONE\n"); printf("DONE\n");
printf("Write the guessed compression configuration to file %s.cfg ... ", output_prefix); printf("Write the guessed compression configuration to file %s.cfg ... ", output_prefix);
error = write_cfg(cfg, output_prefix, print_rdcu_cfg, verbose_en); error = write_cfg(cfg, output_prefix, add_rdcu_pars, verbose_en);
if (error) if (error)
return -1; return -1;
printf("DONE\n"); printf("DONE\n");
...@@ -624,10 +624,11 @@ static int gen_rdcu_write_pkts(struct cmp_cfg *cfg) ...@@ -624,10 +624,11 @@ static int gen_rdcu_write_pkts(struct cmp_cfg *cfg)
* @note set cmp_size, ap1_cmp_size, ap2_cmp_size will be set to 0 * @note set cmp_size, ap1_cmp_size, ap2_cmp_size will be set to 0
* *
* @returns 0 on success, error otherwise * @returns 0 on success, error otherwise
* TODO: set cmp_err in error case * 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, struct cmp_info *info) static int cmp_gernate_rdcu_info(const struct cmp_cfg *cfg, int cmp_size_bit,
struct cmp_info *info)
{ {
if (!cfg) if (!cfg)
return -1; return -1;
...@@ -649,21 +650,39 @@ static int cmp_gernate_rdcu_info(const struct cmp_cfg *cfg, int cmp_size_bit, st ...@@ -649,21 +650,39 @@ static int cmp_gernate_rdcu_info(const struct cmp_cfg *cfg, int cmp_size_bit, st
info->spill_used = cfg->spill; info->spill_used = cfg->spill;
info->golomb_par_used = cfg->golomb_par; info->golomb_par_used = cfg->golomb_par;
info->samples_used = cfg->samples; info->samples_used = cfg->samples;
info->cmp_size = 0;
info->ap1_cmp_size = 0;
info->ap2_cmp_size = 0;
info->rdcu_new_model_adr_used = cfg->rdcu_new_model_adr; info->rdcu_new_model_adr_used = cfg->rdcu_new_model_adr;
info->rdcu_cmp_adr_used = cfg->rdcu_buffer_adr; info->rdcu_cmp_adr_used = cfg->rdcu_buffer_adr;
if (cmp_size_bit == CMP_ERROR_SMALL_BUF) if (cmp_size_bit == CMP_ERROR_SMALL_BUF)
/* the icu_output_buf is to small to store the whole bitstream */ /* the icu_output_buf is to small to store the whole bitstream */
info->cmp_err |= 1UL << SMALL_BUFFER_ERR_BIT; /* set small buffer error */ info->cmp_err |= 1UL << SMALL_BUFFER_ERR_BIT; /* set small buffer error */
if (cmp_size_bit < 0) if (cmp_size_bit < 0) {
info->cmp_size = 0; info->cmp_size = 0;
else info->ap1_cmp_size = 0;
info->ap2_cmp_size = 0;
} else {
info->cmp_size = (uint32_t)cmp_size_bit; info->cmp_size = (uint32_t)cmp_size_bit;
}
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;
info->ap1_cmp_size = icu_compress_data(&cfg_cpy);
if ((int)info->ap1_cmp_size < 0)
info->ap1_cmp_size = 0;
cfg_cpy.golomb_par = cfg_cpy.ap2_golomb_par;
cfg_cpy.spill = cfg_cpy.ap2_spill;
info->ap2_cmp_size = icu_compress_data(&cfg_cpy);
if ((int)info->ap2_cmp_size < 0)
info->ap2_cmp_size = 0;
}
}
}
return 0; return 0;
} }
...@@ -711,15 +730,8 @@ static int compression(struct cmp_cfg *cfg, struct cmp_info *info) ...@@ -711,15 +730,8 @@ static int compression(struct cmp_cfg *cfg, struct cmp_info *info)
cfg->icu_output_buf = cmp_ent_get_data_buf(cmp_entity); cfg->icu_output_buf = cmp_ent_get_data_buf(cmp_entity);
cmp_size = icu_compress_data(cfg); cmp_size = icu_compress_data(cfg);
cmp_gernate_rdcu_info(cfg, cmp_size, info); if (cmp_size < 0)
if (cmp_size < 0 || info->cmp_err != 0) {
if (info->cmp_err)
printf("\nCompression error 0x%02X\n... ", info->cmp_err);
/* TODO: add a parse cmp error function */
/* if ((info->cmp_err >> SMALL_BUFFER_ERR_BIT) & 1U) */
/* fprintf(stderr, "%s: the buffer for the compressed data is too small. Try a larger buffer_length parameter.\n", PROGRAM_NAME); */
goto error_cleanup; goto error_cleanup;
}
if (model_id_str) { if (model_id_str) {
uint32_t red_val; uint32_t red_val;
...@@ -750,6 +762,8 @@ static int compression(struct cmp_cfg *cfg, struct cmp_info *info) ...@@ -750,6 +762,8 @@ static int compression(struct cmp_cfg *cfg, struct cmp_info *info)
data_to_write_to_file = cmp_entity; data_to_write_to_file = cmp_entity;
cmp_size_byte = cmp_ent_get_size(cmp_entity); cmp_size_byte = cmp_ent_get_size(cmp_entity);
} else { } else {
if (cmp_gernate_rdcu_info(cfg, cmp_size, info))
goto error_cleanup;
data_to_write_to_file = cmp_ent_get_data_buf(cmp_entity); data_to_write_to_file = cmp_ent_get_data_buf(cmp_entity);
if (cfg->cmp_mode == CMP_MODE_RAW) if (cfg->cmp_mode == CMP_MODE_RAW)
cmp_size_byte = info->cmp_size/CHAR_BIT; cmp_size_byte = info->cmp_size/CHAR_BIT;
...@@ -777,17 +791,17 @@ static int compression(struct cmp_cfg *cfg, struct cmp_info *info) ...@@ -777,17 +791,17 @@ static int compression(struct cmp_cfg *cfg, struct cmp_info *info)
if (!include_cmp_header) { if (!include_cmp_header) {
printf("Write decompression information to file %s.info ... ", printf("Write decompression information to file %s.info ... ",
output_prefix); output_prefix);
error = write_info(info, output_prefix, print_rdcu_cfg); error = write_info(info, output_prefix, add_rdcu_pars);
if (error) if (error)
goto error_cleanup; goto error_cleanup;
printf("DONE\n"); printf("DONE\n");
}
if (verbose_en) { if (verbose_en) {
printf("\n"); printf("\n");
print_cmp_info(info); print_cmp_info(info);
printf("\n"); printf("\n");
} }
}
free(cmp_entity); free(cmp_entity);
cfg->icu_output_buf = NULL; cfg->icu_output_buf = NULL;
......
...@@ -831,9 +831,7 @@ def test_small_buf_err(): ...@@ -831,9 +831,7 @@ def test_small_buf_err():
assert(stdout == CMP_START_STR_CMP + assert(stdout == CMP_START_STR_CMP +
"Importing configuration file %s ... DONE\n" % (cfg_file_name) + "Importing configuration file %s ... DONE\n" % (cfg_file_name) +
"Importing data file %s ... DONE\n" % (data_file_name) + "Importing data file %s ... DONE\n" % (data_file_name) +
"Compress data ... \n" "Compress data ... FAILED\n")
"Compression error 0x01\n"
"... FAILED\n")
# assert(stderr == "cmp_tool: the buffer for the compressed data is too small. Try a larger buffer_length parameter.\n") # assert(stderr == "cmp_tool: the buffer for the compressed data is too small. Try a larger buffer_length parameter.\n")
assert(stderr == "Error: The buffer for the compressed data is too small to hold the compressed data. Try a larger buffer_length parameter.\n") assert(stderr == "Error: The buffer for the compressed data is too small to hold the compressed data. Try a larger buffer_length parameter.\n")
assert(returncode == EXIT_FAILURE) assert(returncode == EXIT_FAILURE)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment