From d631f693c966e5b1693f59dbacceee4d2a11bee1 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Mon, 4 Nov 2024 15:45:14 +0100 Subject: [PATCH] initial decompression workflow in cmdl tool --- src/tools/bwccmdl.c | 119 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 2 deletions(-) diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index 8ec216f..d408b3f 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -78,6 +78,10 @@ "| ERROR: Invalid file type. |\n"\ "o##########################################################o\n" +#define FINERROR "o##########################################################o\n"\ + "| ERROR: Could not open specified input file. |\n"\ + "o##########################################################o\n" + #define FOUERROR "o##########################################################o\n"\ "| ERROR: Could not open specified output file. |\n"\ "o##########################################################o\n" @@ -1085,6 +1089,7 @@ int main(int argc, char *argv[]) ! DEFINE INT VARIABLES: ! \*-----------------------*/ uint64_t size = 0; + uint64_t root, Lfield; uint8_t i; uint8_t error_handle = EXIT_SUCCESS; @@ -1115,6 +1120,7 @@ int main(int argc, char *argv[]) ! DEFINE DER. VARIABLES: ! \*-----------------------*/ bwc_precision precision; + bwc_header *header; bwc_stream *stream = NULL; bwc_codec *coder = NULL; @@ -1165,7 +1171,6 @@ int main(int argc, char *argv[]) if ((arguments.optSet & FLOUT) == 0) arguments.out = arguments.in; - printf("%s \n", arguments.out); if ((buffer = strrchr(arguments.out, '.')) == NULL) { error_handle = EXIT_FAILURE; @@ -1439,7 +1444,117 @@ int main(int argc, char *argv[]) } else if (arguments.mode == cli_dcp) { - printf("Decompression\n"); + 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. */ + if ((arguments.optSet & FLOUT) == 0) + arguments.out = arguments.in; + + if ((buffer = strrchr(arguments.out, '.')) == NULL) + { + error_handle = EXIT_FAILURE; + printf(TYPERROR); + goto OUT; + } + cli_output = calloc(strlen(arguments.out) - strlen(buffer) + 5, sizeof(char)); + if (cli_output == NULL) + { + error_handle = EXIT_FAILURE; + printf(MEMERROR); + goto OUT; + } + sprintf(cli_output, "%.*s.eas", (int)(strlen(arguments.out) - strlen(buffer)), arguments.out); + + if (arguments.verbose == true) + { + sprintf(cli_buffer," Output: %s \n", cli_output); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + } + + if ((arguments.verbose == true) && + (delim == true)) + { + + strcat(cli_verbose, " __________________________________________________________\n"); + strcat(cli_verbose, "\n"); + } + + if (arguments.verbose == true) + { + memset(cli_buffer, '0', sizeof(char) * 1024); + strcat(cli_verbose, "\n==============================================================\n"); + printf("%s", cli_verbose); + } + + /* Read the codestream from the specified file. */ + input = calloc(Lfield, sizeof(uchar)); + if (fread(input, sizeof(uchar), Lfield, fp) != Lfield) + { + error_handle = EXIT_FAILURE; + printf(RDERROR); + goto OUT; + } + + header = bwc_open_header(input); + + size = header->info.nX * header->info.nY * header->info.nZ * + header->info.nTS * header->info.nPar; + + if(header->info.data_prec == bwc_precision_double) + { + output = calloc(size, sizeof(double)); + } + else if(header->info.data_prec == bwc_precision_single) + { + output = calloc(size, sizeof(float)); + } + + bwc_close_header(header); + + stream = bwc_init_stream(input, output, comp); + coder = bwc_alloc_decoder(); + + //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_decompression(coder, stream, 0) == EXIT_FAILURE) + { + error_handle = EXIT_FAILURE; + goto OUT; + } + + size = bwc_decompress(coder, stream); + + //write_eas3(output, cli_output); + + goto OUT; } else if (arguments.mode == cli_anl) {