From 12f937ecac54703f20d9e51ecbb38955a61cd6b9 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Mon, 4 Nov 2024 13:57:33 +0100 Subject: [PATCH] open and close header with new header structure --- include/library/private/codestream.h | 4 ++ include/library/private/libbwc.h | 4 ++ include/library/private/types.h | 13 ++++ src/library/codestream.c | 2 +- src/library/libbwc.c | 92 ++++++++++++++++++++++++++++ src/tools/bwccmdl.c | 26 ++++---- 6 files changed, 127 insertions(+), 14 deletions(-) diff --git a/include/library/private/codestream.h b/include/library/private/codestream.h index 0445b59..2e022aa 100755 --- a/include/library/private/codestream.h +++ b/include/library/private/codestream.h @@ -100,6 +100,10 @@ size_t assemble_codestream (bwc_codec *const codec, bwc_stream *const stream); //==========|==========================|======================|======|======|===================== + bwc_codec* parse_main_header (bwc_codec *const codec, + bwc_stream *const data, + bitstream *const stream); + //==========|==========================|======================|======|======|===================== bwc_codec* parse_codestream (bwc_codec *const codec, bwc_stream *const stream, uint8 const layer); diff --git a/include/library/private/libbwc.h b/include/library/private/libbwc.h index 5d67736..1afab38 100755 --- a/include/library/private/libbwc.h +++ b/include/library/private/libbwc.h @@ -142,6 +142,10 @@ uint64 const tilesTS, bwc_tile_instr const instr); //==========|==========================|======================|======|=======|==================== + bwc_header* bwc_open_header (void *const inpbuf); + //==========|==========================|======================|======|=======|==================== + void bwc_close_header (bwc_header *const header); + //==========|==========================|======================|======|=======|==================== uchar bwc_create_compression (bwc_codec *const codec, bwc_stream *const data, char *const rate_control); diff --git a/include/library/private/types.h b/include/library/private/types.h index 0320a8e..bba676d 100755 --- a/include/library/private/types.h +++ b/include/library/private/types.h @@ -659,6 +659,19 @@ bwc_prog_ord progression; // Packet progression order. } bwc_gl_ctrl; +/*================================================================================================*/ +/** + * @details Structure that is used to probe header information from a compressed data set. + */ +/*================================================================================================*/ + typedef struct + { + bwc_gl_inf info; // Global info structure + bwc_gl_ctrl control; // Global control structure + bwc_span aux; // Auxiliary info. codestream block. + bwc_span com; // Comment codestream block. + } bwc_header; + /*----------------------------------------------------------------------------------------------*\ ! ! ! DESCRIPTION: ! diff --git a/src/library/codestream.c b/src/library/codestream.c index 3c0d8d3..aec991c 100755 --- a/src/library/codestream.c +++ b/src/library/codestream.c @@ -912,7 +912,7 @@ parse_main_header(bwc_codec *const codec, bwc_stream *const data, bitstream *con data->codestream.com->memory = get_chunck(stream, Lcom - 2); data->codestream.com->size = Lcom -2; - status |= CODESTREAM_ERROR; + status |= CODESTREAM_COM_READ; break; } diff --git a/src/library/libbwc.c b/src/library/libbwc.c index d6ede6f..0beb985 100755 --- a/src/library/libbwc.c +++ b/src/library/libbwc.c @@ -3350,6 +3350,98 @@ bwc_set_tiles(bwc_codec *const codec, uint64 tilesX, uint64 tilesY, uint64 tiles control->CSsgc |= (0x01 << 9); } +/*================================================================================================*/ +/** + * @details This function opens the header of a compressed data set and parses it into an + * instance of type bwc_header. + * + * @param[in] inpbuf Pointer to compressed data set. + * + * @retval bwc_header* + */ +/*================================================================================================*/ +bwc_header* bwc_open_header(void *const inpbuf) +{ + /*-----------------------*\ + ! DEFINE STRUCTS: ! + \*-----------------------*/ + bwc_codec* codec; + bwc_stream* data; + bitstream* stream; + bwc_header* header; + + /*--------------------------------------------------------*\ + ! Initialize a codec, stream, and bitstream for parsing. ! + \*--------------------------------------------------------*/ + data = bwc_init_stream(inpbuf, NULL, decomp); + codec = bwc_alloc_decoder(); + stream = init_bitstream(data->inp, 10, 'd'); + + /*--------------------------------------------------------*\ + ! Parse the main header into the codec structure. ! + \*--------------------------------------------------------*/ + parse_main_header(codec, data, stream); + if(!codec) + { + return NULL; + } + + /*--------------------------------------------------------*\ + ! Allocate header and copy info and control structures. ! + \*--------------------------------------------------------*/ + header = calloc(1, sizeof(bwc_header)); + header->info = codec->info; + header->control = codec->control; + + /*--------------------------------------------------------*\ + ! Shallow copy aux data to span. ! + \*--------------------------------------------------------*/ + if (data->codestream.aux) + { + header->aux.memory = data->codestream.aux->memory; + header->aux.size = data->codestream.aux->size; + } + + /*--------------------------------------------------------*\ + ! Shallow copy com data to span. ! + \*--------------------------------------------------------*/ + if (data->codestream.com) + { + header->com.memory = data->codestream.com->memory; + header->com.size = data->codestream.com->size; + } + + free(stream); + free(data); + free(codec); + + return header; +} + +/*================================================================================================*/ +/** + * @details This function closes the header information in the bwc_header pointer. + * + * @param[in] header Instance of type bwc_header. + */ +/*================================================================================================*/ +void bwc_close_header(bwc_header *const header) +{ + if (header) + { + if (header->aux.memory) + { + free(header->aux.memory); + } + if (header->com.memory) + { + free(header->com.memory); + } + free(header); + } +} + + /*----------------------------------------------------------------------------------------------------------*\ ! FUNCTION NAME: void bwc_create_compression(bwc_codec *codec, char *rate_control) ! ! -------------- ! diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index 8df4e9c..8ec216f 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -134,18 +134,18 @@ * @details String containing the header used for the cli output. */ /*================================================================================================*/ -static char bwc_header[] = "==============================================================\n"\ - " \n"\ - " .:-------------: .:-------------: \n"\ - " .+++++++++++++++= :+++++++++++++++- \n"\ - " :+++. -++= -++= \n"\ - " :+++. -++= -++= \n"\ - " -++++++++++++++= -++= -++= \n"\ - " .=++---------=++= -++= -++= \n"\ - " :+++ :++= -++= -++= \n"\ - " .+++=--------=+++---=+++---=+++------------: \n"\ - " -=++++++++++++++++++++++++++++++++++++++++- \n"\ - " \n"; +static char bwc_header_art[] = "==============================================================\n"\ + " \n"\ + " .:-------------: .:-------------: \n"\ + " .+++++++++++++++= :+++++++++++++++- \n"\ + " :+++. -++= -++= \n"\ + " :+++. -++= -++= \n"\ + " -++++++++++++++= -++= -++= \n"\ + " .=++---------=++= -++= -++= \n"\ + " :+++ :++= -++= -++= \n"\ + " .+++=--------=+++---=+++---=+++------------: \n"\ + " -=++++++++++++++++++++++++++++++++++++++++- \n"\ + " \n"; /*================================================================================================*/ /** @@ -1153,7 +1153,7 @@ int main(int argc, char *argv[]) } if (arguments.verbose == true) { - strcat(cli_verbose, bwc_header); + strcat(cli_verbose, bwc_header_art); strcat(cli_verbose, "--------------------------- I/O --------------------------\n\n"); sprintf(cli_buffer," Input: %s \n", arguments.in);