refactor; print (verbose) header, I/O, and control parameters

This commit is contained in:
Gregor Weiss 2024-11-07 16:26:20 +01:00
parent 64eeda9072
commit a84768bbec
Signed by: Gregor Weiss
GPG key ID: 61E170A8BBFE5756

View file

@ -1067,6 +1067,121 @@ parse_opt(int key,
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void
printheaderIO(char const *input, char const *output, char const *reference)
{
/*-----------------------*\
! DEFINE CHAR VARIABLES: !
\*-----------------------*/
char cli_buffer[1024] = {0};
char cli_verbose[4096] = {0};
strcat(cli_verbose, bwc_header_art);
strcat(cli_verbose, "--------------------------- I/O --------------------------\n\n");
sprintf(cli_buffer," Input: %s \n", input);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
sprintf(cli_buffer," Output: %s \n", output);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
sprintf(cli_buffer," Reference: %s \n", reference);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
printf("%s", cli_verbose);
}
void
printctrl(bwc_gl_ctrl *const control)
{
/*-----------------------*\
! DEFINE INT VARIABLES: !
\*-----------------------*/
uint8_t i;
/*-----------------------*\
! DEFINE CHAR VARIABLES: !
\*-----------------------*/
char cli_buffer[1024] = {0};
char cli_verbose[4096] = {0};
strcat(cli_verbose, "\n");
strcat(cli_verbose, "----------------- Compression Parameters -----------------\n");
strcat(cli_verbose, "\n");
strcat(cli_verbose," Tile Size: \n");
sprintf(cli_buffer," - Samples in 1.D: %27ld\n"\
" - Samples in 2.D: %27ld\n"\
" - Samples in 3.D: %27ld\n"\
" - Samples in 4.D: %27ld\n", control->tileSizeX,
control->tileSizeY,
control->tileSizeZ,
control->tileSizeTS);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
strcat(cli_verbose, " __________________________________________________________\n");
strcat(cli_verbose, "\n");
strcat(cli_verbose, " 1.D | 2.D | 3.D | 4.D\n");
sprintf(cli_buffer, " Decomposition Levels: %18d |%4d |%4d |%4d\n",
control->decompX,
control->decompY,
control->decompZ,
control->decompTS);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
sprintf(cli_buffer, " Precincts [log2]: %18d |%4d |%4d |%4d\n",
control->precSizeX,
control->precSizeY,
control->precSizeZ,
control->precSizeTS);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
sprintf(cli_buffer, " Codeblocks [log2]: %18d |%4d |%4d |%4d\n",
control->cbX,
control->cbY,
control->cbZ,
control->cbTS);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
strcat(cli_verbose, " __________________________________________________________\n");
strcat(cli_verbose, "\n");
sprintf(cli_buffer, " Q Number Format: %27d\n", control->Qm);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
if (control->error_resilience)
{
sprintf(cli_buffer, " Error Resilience: %27s\n", "true");
}
else
{
sprintf(cli_buffer, " Error Resilience: %27s\n", "false");
}
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
strcat(cli_verbose, " __________________________________________________________\n");
strcat(cli_verbose, "\n");
for(i = 0; i < control->nLayers; ++i)
{
sprintf(cli_buffer, " Quality Layer Nr. %d: %33.2f bpd\n", i,
control->bitrate[i]);
strcat(cli_verbose, cli_buffer);
}
memset(cli_buffer, '0', sizeof(char) * 1024);
strcat(cli_verbose, "\n==============================================================\n");
printf("%s", cli_verbose);
}
static uchar static uchar
output_analysis(eas3_data *const ref_data, eas3_data *const org_data) output_analysis(eas3_data *const ref_data, eas3_data *const org_data)
{ {
@ -1209,8 +1324,6 @@ int main(int argc, char *argv[])
! DEFINE CHAR VARIABLES: ! ! DEFINE CHAR VARIABLES: !
\*-----------------------*/ \*-----------------------*/
char rate[200] = {0}; char rate[200] = {0};
char cli_buffer[1024] = {0};
char cli_verbose[4096] = {0};
char *cli_output = NULL; char *cli_output = NULL;
char *buffer = NULL; char *buffer = NULL;
@ -1255,30 +1368,9 @@ int main(int argc, char *argv[])
/* Compress the user supplied data set. */ /* Compress the user supplied data set. */
if (arguments.mode == cli_cmp) if (arguments.mode == cli_cmp)
{ {
/* Ingest the bwccmdl input and set the appropriate cli_ *
* verbose message if the option is set. */
// TODO: Define a universal data structure and implement a reader
// that ingests different file formats
if ((data = read_eas3(arguments.in)) == NULL)
{
error_handle = EXIT_FAILURE;
goto OUT;
}
if (arguments.verbose == true)
{
strcat(cli_verbose, bwc_header_art);
strcat(cli_verbose, "--------------------------- I/O --------------------------\n\n");
sprintf(cli_buffer," Input: %s \n", arguments.in);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
}
/* Evaluate the appropriate output file. */ /* Evaluate the appropriate output file. */
if ((arguments.optSet & FLOUT) == 0) if ((arguments.optSet & FLOUT) == 0)
arguments.out = arguments.in; arguments.out = arguments.in;
if ((buffer = strrchr(arguments.out, '.')) == NULL) if ((buffer = strrchr(arguments.out, '.')) == NULL)
{ {
error_handle = EXIT_FAILURE; error_handle = EXIT_FAILURE;
@ -1296,9 +1388,15 @@ int main(int argc, char *argv[])
if (arguments.verbose == true) if (arguments.verbose == true)
{ {
sprintf(cli_buffer," Output: %s \n", cli_output); printheaderIO(arguments.in, cli_output, arguments.ref);
strcat(cli_verbose, cli_buffer); }
memset(cli_buffer, '0', sizeof(char) * 1024);
// TODO: Define a universal data structure and implement a reader
// that ingests different file formats
if ((data = read_eas3(arguments.in)) == NULL)
{
error_handle = EXIT_FAILURE;
goto OUT;
} }
/* Evaluate the input and output buffer size and initial- * /* Evaluate the input and output buffer size and initial- *
@ -1329,15 +1427,6 @@ int main(int argc, char *argv[])
precision); precision);
bwc_set_aux(stream, (char*)data->aux.ptr, data->aux.len); bwc_set_aux(stream, (char*)data->aux.ptr, data->aux.len);
/* Apply the user supplied compression options using the *
* appropriate setter functions. */
if (arguments.verbose == true)
{
strcat(cli_verbose, "\n");
strcat(cli_verbose, "----------------- Compression Parameters -----------------\n");
strcat(cli_verbose, "\n");
}
if ((arguments.optSet & TILES) != 0) if ((arguments.optSet & TILES) != 0)
{ {
bwc_set_tiles(coder, arguments.tileSize[0], bwc_set_tiles(coder, arguments.tileSize[0],
@ -1345,20 +1434,6 @@ int main(int argc, char *argv[])
arguments.tileSize[2], arguments.tileSize[2],
arguments.tileSize[3], bwc_tile_sizeof); arguments.tileSize[3], bwc_tile_sizeof);
if (arguments.verbose == true)
{
strcat(cli_verbose," Tile Size: \n");
sprintf(cli_buffer," - Samples in 1.D: %27ld\n"\
" - Samples in 2.D: %27ld\n"\
" - Samples in 3.D: %27ld\n"\
" - Samples in 4.D: %27ld\n", arguments.tileSize[0],
arguments.tileSize[1],
arguments.tileSize[2],
arguments.tileSize[3]);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
delim = true;
}
} }
// TODO: Implement the kernel setter as a global function // TODO: Implement the kernel setter as a global function
@ -1371,35 +1446,12 @@ int main(int argc, char *argv[])
arguments.dwtKernel[3]); arguments.dwtKernel[3]);
}*/ }*/
if ((arguments.verbose == true) &&
((arguments.optSet & (DCLVL | PRECS | CBLKS)) != 0))
{
if (delim == true)
{
strcat(cli_verbose, " __________________________________________________________\n");
strcat(cli_verbose, "\n");
}
strcat(cli_verbose, " 1.D | 2.D | 3.D | 4.D\n");
delim = true;
}
if ((arguments.optSet & DCLVL) != 0) if ((arguments.optSet & DCLVL) != 0)
{ {
bwc_set_decomp(coder, arguments.decompLevel[0], bwc_set_decomp(coder, arguments.decompLevel[0],
arguments.decompLevel[1], arguments.decompLevel[1],
arguments.decompLevel[2], arguments.decompLevel[2],
arguments.decompLevel[3]); arguments.decompLevel[3]);
if (arguments.verbose == true)
{
sprintf(cli_buffer, " Decomposition Levels: %18d |%4d |%4d |%4d\n",
arguments.decompLevel[0],
arguments.decompLevel[1],
arguments.decompLevel[2],
arguments.decompLevel[3]);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
}
} }
if ((arguments.optSet & PRECS) != 0) if ((arguments.optSet & PRECS) != 0)
@ -1408,17 +1460,6 @@ int main(int argc, char *argv[])
arguments.precSize[1], arguments.precSize[1],
arguments.precSize[2], arguments.precSize[2],
arguments.precSize[3]); arguments.precSize[3]);
if (arguments.verbose == true)
{
sprintf(cli_buffer, " Precincts [log2]: %18d |%4d |%4d |%4d\n",
arguments.precSize[0],
arguments.precSize[1],
arguments.precSize[2],
arguments.precSize[3]);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
}
} }
if ((arguments.optSet & CBLKS) != 0) if ((arguments.optSet & CBLKS) != 0)
@ -1427,64 +1468,21 @@ int main(int argc, char *argv[])
arguments.cblkSize[1], arguments.cblkSize[1],
arguments.cblkSize[2], arguments.cblkSize[2],
arguments.cblkSize[3]); arguments.cblkSize[3]);
if (arguments.verbose == true)
{
sprintf(cli_buffer, " Codeblocks [log2]: %18d |%4d |%4d |%4d\n",
arguments.cblkSize[0],
arguments.cblkSize[1],
arguments.cblkSize[2],
arguments.cblkSize[3]);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
}
}
if ((arguments.verbose == true) &&
(delim == true) &&
(((arguments.optSet & QFRMT) != 0) || arguments.erresilience == true))
{
strcat(cli_verbose, " __________________________________________________________\n");
strcat(cli_verbose, "\n");
} }
if ((arguments.optSet & QFRMT) != 0) if ((arguments.optSet & QFRMT) != 0)
{ {
bwc_set_qm(coder, arguments.Qm); bwc_set_qm(coder, arguments.Qm);
if (arguments.verbose == true)
{
sprintf(cli_buffer, " Q Number Format: %27d\n", arguments.Qm);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
delim = true;
}
} }
if (arguments.erresilience == true) if (arguments.erresilience == true)
{ {
bwc_set_error_resilience(coder); bwc_set_error_resilience(coder);
if (arguments.verbose == true)
{
sprintf(cli_buffer, " Error Resilience: %27s\n", "true");
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
delim = true;
}
} }
/* Initialize the rate control string according to the * /* Initialize the rate control string according to the *
* specified bit rate/compression ratio. */ * specified bit rate/compression ratio. */
if ((arguments.verbose == true) &&
(delim == true))
{
strcat(cli_verbose, " __________________________________________________________\n");
strcat(cli_verbose, "\n");
}
if ((arguments.optSet & BITRT) != 0) if ((arguments.optSet & BITRT) != 0)
{ {
rtype = 1.0; rtype = 1.0;
@ -1507,32 +1505,21 @@ int main(int argc, char *argv[])
if (arguments.rate[i] > 0) if (arguments.rate[i] > 0)
{ {
sprintf(rate + strlen(rate), "%05.3f,", pow(arguments.rate[i]/rtype, exp)); sprintf(rate + strlen(rate), "%05.3f,", pow(arguments.rate[i]/rtype, exp));
if (arguments.verbose == true)
{
sprintf(cli_buffer, " Quality Layer Nr. %d: %33.2f bpd\n", i,
pow(arguments.rate[i]/rtype, exp));
strcat(cli_verbose, cli_buffer);
}
} }
} }
rate[strlen(rate) - 1] = '0'; rate[strlen(rate) - 1] = '0';
if (arguments.verbose == true)
{
memset(cli_buffer, '0', sizeof(char) * 1024);
strcat(cli_verbose, "\n==============================================================\n");
printf("%s", cli_verbose);
}
/* Initialize the rate control string according to the *
* specified bit rate/compression ratio. */
if (bwc_create_compression(coder, stream, rate) == EXIT_FAILURE) if (bwc_create_compression(coder, stream, rate) == EXIT_FAILURE)
{ {
error_handle = EXIT_FAILURE; error_handle = EXIT_FAILURE;
goto OUT; goto OUT;
} }
if(arguments.verbose == true)
{
printctrl(&coder->control);
}
size = bwc_compress(coder, stream); size = bwc_compress(coder, stream);
/* Write the codestream to the speicifed file. */ /* Write the codestream to the speicifed file. */
@ -1553,32 +1540,9 @@ int main(int argc, char *argv[])
} }
else if (arguments.mode == cli_dcp) else if (arguments.mode == cli_dcp)
{ {
if ((fp = fopen(arguments.in, "r")) == NULL)
{
error_handle = EXIT_FAILURE;
printf(FINERROR);
goto OUT;
}
root = ftell(fp);
fseek(fp, 0L, SEEK_END);
Lfield = ftell(fp) - root;
fseek(fp, root, SEEK_SET);
if (arguments.verbose == true)
{
strcat(cli_verbose, bwc_header_art);
strcat(cli_verbose, "--------------------------- I/O --------------------------\n\n");
sprintf(cli_buffer," Input: %s \n", arguments.in);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
}
/* Evaluate the appropriate output file. */ /* Evaluate the appropriate output file. */
if ((arguments.optSet & FLOUT) == 0) if ((arguments.optSet & FLOUT) == 0)
arguments.out = arguments.in; arguments.out = arguments.in;
if ((buffer = strrchr(arguments.out, '.')) == NULL) if ((buffer = strrchr(arguments.out, '.')) == NULL)
{ {
error_handle = EXIT_FAILURE; error_handle = EXIT_FAILURE;
@ -1596,18 +1560,21 @@ int main(int argc, char *argv[])
if (arguments.verbose == true) if (arguments.verbose == true)
{ {
sprintf(cli_buffer," Output: %s \n", cli_output); printheaderIO(arguments.in, cli_output, arguments.ref);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
} }
if (arguments.verbose == true) if ((fp = fopen(arguments.in, "r")) == NULL)
{ {
memset(cli_buffer, '0', sizeof(char) * 1024); error_handle = EXIT_FAILURE;
strcat(cli_verbose, "\n==============================================================\n"); printf(FINERROR);
printf("%s", cli_verbose); goto OUT;
} }
root = ftell(fp);
fseek(fp, 0L, SEEK_END);
Lfield = ftell(fp) - root;
fseek(fp, root, SEEK_SET);
/* Read the compressed data from the input file. */ /* Read the compressed data from the input file. */
input = calloc(Lfield, sizeof(uchar)); input = calloc(Lfield, sizeof(uchar));
if (fread(input, sizeof(uchar), Lfield, fp) != Lfield) if (fread(input, sizeof(uchar), Lfield, fp) != Lfield)
@ -1631,6 +1598,8 @@ int main(int argc, char *argv[])
} }
bwc_close_header(header); bwc_close_header(header);
printctrl(&header->control);
/* Initialize and run the decompression. */ /* Initialize and run the decompression. */
stream = bwc_init_stream(input, output, comp); stream = bwc_init_stream(input, output, comp);
coder = bwc_alloc_decoder(); coder = bwc_alloc_decoder();
@ -1651,6 +1620,11 @@ int main(int argc, char *argv[])
} }
else if (arguments.mode == cli_anl) else if (arguments.mode == cli_anl)
{ {
if (arguments.verbose == true)
{
printheaderIO(arguments.in, cli_output, arguments.ref);
}
/* Ingest the reference data input. */ /* Ingest the reference data input. */
if ((ref_data = read_eas3(arguments.ref)) == NULL) if ((ref_data = read_eas3(arguments.ref)) == NULL)
{ {
@ -1694,6 +1668,11 @@ int main(int argc, char *argv[])
} }
bwc_close_header(header); bwc_close_header(header);
if(arguments.verbose == true)
{
printctrl(&header->control);
}
/* Initialize and run the decompression. */ /* Initialize and run the decompression. */
stream = bwc_init_stream(input, output, comp); stream = bwc_init_stream(input, output, comp);
coder = bwc_alloc_decoder(); coder = bwc_alloc_decoder();
@ -1715,11 +1694,7 @@ int main(int argc, char *argv[])
} }
else if (arguments.mode == cli_inf) else if (arguments.mode == cli_inf)
{ {
strcat(cli_verbose, bwc_header_art); printheaderIO(arguments.in, cli_output, arguments.ref);
strcat(cli_verbose, "--------------------------- I/O --------------------------\n\n");
sprintf(cli_buffer," Input: %s \n", arguments.in);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
if ((fp = fopen(arguments.in, "r")) == NULL) if ((fp = fopen(arguments.in, "r")) == NULL)
{ {
@ -1742,7 +1717,7 @@ int main(int argc, char *argv[])
goto OUT; goto OUT;
} }
/* Retrieve header information and allocate output buffer. */ /* Retrieve header information. */
header = bwc_open_header(input); header = bwc_open_header(input);
size = header->info.nX * header->info.nY * header->info.nZ * size = header->info.nX * header->info.nY * header->info.nZ *
header->info.nTS * header->info.nPar; header->info.nTS * header->info.nPar;
@ -1756,79 +1731,7 @@ int main(int argc, char *argv[])
} }
bwc_close_header(header); bwc_close_header(header);
strcat(cli_verbose, "\n"); printctrl(&header->control);
strcat(cli_verbose, "----------------- Compression Parameters -----------------\n");
strcat(cli_verbose, "\n");
strcat(cli_verbose," Tile Size: \n");
sprintf(cli_buffer," - Samples in 1.D: %27ld\n"\
" - Samples in 2.D: %27ld\n"\
" - Samples in 3.D: %27ld\n"\
" - Samples in 4.D: %27ld\n", header->control.tileSizeX,
header->control.tileSizeY,
header->control.tileSizeZ,
header->control.tileSizeTS);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
strcat(cli_verbose, " __________________________________________________________\n");
strcat(cli_verbose, "\n");
strcat(cli_verbose, " 1.D | 2.D | 3.D | 4.D\n");
sprintf(cli_buffer, " Decomposition Levels: %18d |%4d |%4d |%4d\n",
header->control.decompX,
header->control.decompY,
header->control.decompZ,
header->control.decompTS);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
sprintf(cli_buffer, " Precincts [log2]: %18d |%4d |%4d |%4d\n",
header->control.precSizeX,
header->control.precSizeY,
header->control.precSizeZ,
header->control.precSizeTS);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
sprintf(cli_buffer, " Codeblocks [log2]: %18d |%4d |%4d |%4d\n",
header->control.cbX,
header->control.cbY,
header->control.cbZ,
header->control.cbTS);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
strcat(cli_verbose, " __________________________________________________________\n");
strcat(cli_verbose, "\n");
sprintf(cli_buffer, " Q Number Format: %27d\n", header->control.Qm);
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
if (header->control.error_resilience)
{
sprintf(cli_buffer, " Error Resilience: %27s\n", "true");
}
else
{
sprintf(cli_buffer, " Error Resilience: %27s\n", "false");
}
strcat(cli_verbose, cli_buffer);
memset(cli_buffer, '0', sizeof(char) * 1024);
strcat(cli_verbose, " __________________________________________________________\n");
strcat(cli_verbose, "\n");
for(i = 0; i < header->control.nLayers; ++i)
{
sprintf(cli_buffer, " Quality Layer Nr. %d: %33.2f bpd\n", i,
header->control.bitrate[i]);
strcat(cli_verbose, cli_buffer);
}
memset(cli_buffer, '0', sizeof(char) * 1024);
strcat(cli_verbose, "\n==============================================================\n");
printf("%s", cli_verbose);
} }
else else
{ {