From eae976b9ba3b49e6c0cc89be4e5e35414f5ebea3 Mon Sep 17 00:00:00 2001 From: Patrick Vogler Date: Thu, 22 Feb 2024 16:25:52 +0100 Subject: [PATCH] Removed the streaming functions from the public header to clean up the API. --- Makefile | 6 +- include/interfaces/reader/eas3.h | 550 ++++----- include/library/private/bitstream.h | 56 +- include/library/private/codestream.h | 17 +- include/library/private/prim_types_double.h | 26 +- include/library/private/tagtree.h | 5 +- include/library/private/tier2.h | 1 - include/library/private/types.h | 37 +- src/interfaces/reader/eas3.c | 447 +++++++- src/library/bitstream.c | 988 ++++++++-------- src/library/codestream.c | 1147 ++++++++++--------- src/library/libbwc.c | 8 +- src/library/tagtree.c | 10 +- src/library/tier2.c | 142 +-- src/tools/bwccmdl.c | 62 +- 15 files changed, 1966 insertions(+), 1536 deletions(-) diff --git a/Makefile b/Makefile index 71dbbb7..4db8802 100755 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ #| DESCRIPTION: |# #| ------------ |# #| Defines a wrapper for the Big Whoop cmake & make tools. This Makefile creates the |# -#| build dir if it does not exist, switches to it and executes cmake and make. |# +#| build dir if it does not exist, switches to it and executes cmake and make. |# #| |# #| ---------------------------------------------------------------------------------------------------------------- |# #| |# @@ -78,12 +78,12 @@ BUILD_EAS3="False" BUILD_NETCDF="False" #*--------------------------------------------------------*# -# Define default target. # +# Define default target. # #*--------------------------------------------------------*# default: | build_bwc display #*--------------------------------------------------------*# -# Define helper target. # +# Define helper target. # #*--------------------------------------------------------*# help: diff --git a/include/interfaces/reader/eas3.h b/include/interfaces/reader/eas3.h index 702adde..9fe0d20 100644 --- a/include/interfaces/reader/eas3.h +++ b/include/interfaces/reader/eas3.h @@ -61,276 +61,300 @@ #ifndef EAS3_H #define EAS3_H - /************************************************************************************************************\ - || _ _ _ ____ _ _ _ ___ ____ || - || | |\ | | | | | | \ |___ || - || | | \| |___ |___ |__| |__/ |___ || - || || - \************************************************************************************************************/ - #include - #include - #include + /************************************************************************************************************\ + || _ _ _ ____ _ _ _ ___ ____ || + || | |\ | | | | | | \ |___ || + || | | \| |___ |___ |__| |__/ |___ || + || || + \************************************************************************************************************/ + #include + #include + #include - /************************************************************************************************************\ - || _ _ ____ ____ ____ ____ ____ || - || |\/| |__| | |__/ | | [__ || - || | | | | |___ | \ |__| ___] || - || || - \************************************************************************************************************/ - /*----------------------------------------------------------------------------------------------------------*\ - ! DESCRIPTION: ! - ! ------------ ! - ! ! - ! These macros are used to identify the spatial and temporal dimensions. ! - ! ! - ! MACROS: ! - ! ------- ! - ! Name Description ! - ! ---- ----------- ! - ! DIM_X, DIM_Y, DIM_Z - Spatial Dimensions ! - ! ! - ! DIM_TS - Temporal Dimension ! - ! ! - ! DIM_ALL - All Dimensions ! - ! ! - ! DEVELOPMENT HISTORY: ! - ! -------------------- ! - ! ! - ! Date Author Change Id Release Description ! - ! ---- ------ --------- ------- ----------- ! - ! 04.12.2017 Patrick Vogler B87D120 V 0.1.0 macros created ! - ! ! - \*----------------------------------------------------------------------------------------------------------*/ - #define DIM_X 1 - #define DIM_Y 2 - #define DIM_Z 4 - #define DIM_TS 8 - #define DIM_ALL 15 + /************************************************************************************************************\ + || _ _ ____ ____ ____ ____ ____ || + || |\/| |__| | |__/ | | [__ || + || | | | | |___ | \ |__| ___] || + || || + \************************************************************************************************************/ + /*----------------------------------------------------------------------------------------------------------*\ + ! DESCRIPTION: ! + ! ------------ ! + ! ! + ! These macros are used to identify the spatial and temporal dimensions. ! + ! ! + ! MACROS: ! + ! ------- ! + ! Name Description ! + ! ---- ----------- ! + ! DIM_X, DIM_Y, DIM_Z - Spatial Dimensions ! + ! ! + ! DIM_TS - Temporal Dimension ! + ! ! + ! DIM_ALL - All Dimensions ! + ! ! + ! DEVELOPMENT HISTORY: ! + ! -------------------- ! + ! ! + ! Date Author Change Id Release Description ! + ! ---- ------ --------- ------- ----------- ! + ! 04.12.2017 Patrick Vogler B87D120 V 0.1.0 macros created ! + ! ! + \*----------------------------------------------------------------------------------------------------------*/ + #define DIM_X 1 + #define DIM_Y 2 + #define DIM_Z 4 + #define DIM_TS 8 + #define DIM_ALL 15 - /*----------------------------------------------------------------------------------------------------------*\ - ! DESCRIPTION: ! - ! ------------ ! - ! ! - ! These macros are used to instruct the read_eas3_header function. ! - ! ! - ! Macros: ! - ! ------- ! - ! Macro Description ! - ! ----- ----------- ! - ! EAS3_NO_ATTR 1 - Specifies that no attributes are present in the bit- ! - ! stream. ! - ! ! - ! EAS3_ALL_ATTR 2 - Specifies that all attributes are present in the bit- ! - ! bitstream. ! - ! ! - ! ATTRLEN 10 - Defines the number of bytes used to define an attrib- ! - ! ute. ! - ! ! - ! UDEFLEN 20 - Defines the number of bytes used to define a user de- ! - ! fined data. ! - ! ! - ! EAS3_NO_G 1 - Specifies that no geometry data is present in the bit- ! - ! stream. ! - ! ! - ! EAS3_X0DX_G 2 - Specifies that a start value and step size are present ! - ! in the bitstream. ! - ! ! - ! EAS3_UDEF_G 3 - Specifies that ng = number of coordinate data is pres- ! - ! ent in the bitstream. ! - ! ! - ! EAS3_ALL_G 4 - Specifies that an element for every appropriate di- ! - ! mension is present in the bitstream. ! - ! ! - ! EAS3_FULL_G 5 - Specifies that an element for every dimension is pres- ! - ! ent in the bitstream. ! - ! ! - ! EAS3_NO_UDEF 1 - Specifies that no user defined data is present in the ! - ! bitstream. ! - ! ! - ! EAS3_ALL_UDEF 2 - Specifies that all user defined fields are present in ! - ! the bitstream. ! - ! ! - ! EAS3_INT_UDEF 3 - Specifies that an user defined integer field is pres- ! - ! ent in the bitstream. ! - ! ! - ! DEVELOPMENT HISTORY: ! - ! -------------------- ! - ! ! - ! Date Author Change Id Release Description Of Change ! - ! ---- ------ --------- ------- --------------------- ! - ! 20.06.2018 Patrick Vogler B87D120 V 0.1.0 Macros created ! - \*----------------------------------------------------------------------------------------------------------*/ - #define EAS3_NO_ATTR 0x100000000000000 - #define EAS3_ALL_ATTR 0x200000000000000 + /*----------------------------------------------------------------------------------------------------------*\ + ! DESCRIPTION: ! + ! ------------ ! + ! ! + ! These macros are used to instruct the read_eas3_header function. ! + ! ! + ! Macros: ! + ! ------- ! + ! Macro Description ! + ! ----- ----------- ! + ! EAS3_NO_ATTR 1 - Specifies that no attributes are present in the bit- ! + ! stream. ! + ! ! + ! EAS3_ALL_ATTR 2 - Specifies that all attributes are present in the bit- ! + ! bitstream. ! + ! ! + ! ATTRLEN 10 - Defines the number of bytes used to define an attrib- ! + ! ute. ! + ! ! + ! UDEFLEN 20 - Defines the number of bytes used to define a user de- ! + ! fined data. ! + ! ! + ! EAS3_NO_G 1 - Specifies that no geometry data is present in the bit- ! + ! stream. ! + ! ! + ! EAS3_X0DX_G 2 - Specifies that a start value and step size are present ! + ! in the bitstream. ! + ! ! + ! EAS3_UDEF_G 3 - Specifies that ng = number of coordinate data is pres- ! + ! ent in the bitstream. ! + ! ! + ! EAS3_ALL_G 4 - Specifies that an element for every appropriate di- ! + ! mension is present in the bitstream. ! + ! ! + ! EAS3_FULL_G 5 - Specifies that an element for every dimension is pres- ! + ! ent in the bitstream. ! + ! ! + ! EAS3_NO_UDEF 1 - Specifies that no user defined data is present in the ! + ! bitstream. ! + ! ! + ! EAS3_ALL_UDEF 2 - Specifies that all user defined fields are present in ! + ! the bitstream. ! + ! ! + ! EAS3_INT_UDEF 3 - Specifies that an user defined integer field is pres- ! + ! ent in the bitstream. ! + ! ! + ! DEVELOPMENT HISTORY: ! + ! -------------------- ! + ! ! + ! Date Author Change Id Release Description Of Change ! + ! ---- ------ --------- ------- --------------------- ! + ! 20.06.2018 Patrick Vogler B87D120 V 0.1.0 Macros created ! + \*----------------------------------------------------------------------------------------------------------*/ + #define EAS3_NO_ATTR 0x100000000000000 + #define EAS3_ALL_ATTR 0x200000000000000 - #define EAS2_TYPE 0x100000000000000 - #define EAS3_TYPE 0x200000000000000 + #define EAS2_TYPE 0x100000000000000 + #define EAS3_TYPE 0x200000000000000 - #define ATTRLEN 10 - #define UDEFLEN 20 + #define ATTRLEN 10 + #define UDEFLEN 20 - #define EAS3_NO_G 0x100000000000000 - #define EAS3_X0DX_G 0x200000000000000 - #define EAS3_UDEF_G 0x300000000000000 - #define EAS3_ALL_G 0x400000000000000 - #define EAS3_FULL_G 0x500000000000000 + #define EAS3_NO_G 0x100000000000000 + #define EAS3_X0DX_G 0x200000000000000 + #define EAS3_UDEF_G 0x300000000000000 + #define EAS3_ALL_G 0x400000000000000 + #define EAS3_FULL_G 0x500000000000000 - #define EAS3_NO_UDEF 0x100000000000000 - #define EAS3_ALL_UDEF 0x200000000000000 - #define EAS3_INT_UDEF 0x300000000000000 + #define EAS3_NO_UDEF 0x100000000000000 + #define EAS3_ALL_UDEF 0x200000000000000 + #define EAS3_INT_UDEF 0x300000000000000 - #define AUX_SIZE 0x8000 + #define AUX_SIZE 0x8000 - /************************************************************************************************************\ - || ___ _ _ ___ ____ ____ || - || | \_/ |__] |___ [__ || - || | | | |___ ___] || - || || - \************************************************************************************************************/ - /*----------------------------------------------------------------------------------------------------------*\ - ! STRUCT NAME: eas3_header ! - ! ----------- ! - ! ! - ! DESCRIPTION: ! - ! ------------ ! - ! This structure is used to store the eas3 header information. For a more thorough discussion ! - ! of the eas3 datatype see: ! - ! ! - ! https://wiki.iag.uni-stuttgart.de/eas3wiki/index.php/EAS3_File_Format/de ! - ! ! - ! PARAMETERS: ! - ! ----------- ! - ! Variable Type Description ! - ! -------- ---- ----------- ! - ! file_type unsigned int(64 bit) - Defines an identifier for the EAS type. ! - ! ! - ! accuracy unsigned int(64 bit) - Defines the accuracy of an eas3 file. ! - ! ! - ! nzs unsigned int(64 bit) - Variable defining the temporal size of ! - ! the uncompressed dataset. ! - ! ! - ! npar unsigned int(64 bit) - Defines the number of parameters in the ! - ! eas3 dataset. ! - ! ! - ! ndim1, -2, -3 unsigned int(64 bit) - Variables defining the spatial size of ! - ! the eas3 dataset. ! - ! ! - ! attribute_mode; unsigned int(64 bit) - Defines an identifier used to signal ! - ! the attribute mode of the eas3 file. ! - ! ! - ! gmode_time unsigned int(64 bit) - Defines the geometry mode for the temp- ! - ! oral dimension. ! - ! ! - ! gmode_param unsigned int(64 bit) - Defines the geometry mode for the para- ! - ! meters. ! - ! ! - ! gmode_dim1 unsigned int(64 bit) - Defines the geometry mode for the first ! - ! spatial dimension. ! - ! ! - ! gmode_dim2 unsigned int(64 bit) - Defines the geometry mode for the sec- ! - ! ond spatial dimension. ! - ! ! - ! gmode_dim3 unsigned int(64 bit) - Defines the geometry mode for the third ! - ! spatial dimension. ! - ! ! - ! size_time unsigned int(64 bit) - Defines the geometry array size for the ! - ! temporal dimension. ! - ! ! - ! size_parameter unsigned int(64 bit) - Defines the geometry array size for the ! - ! parameters. ! - ! ! - ! size_dim1 unsigned int(64 bit) - Defines the geometry array size for the ! - ! first spatial dimension. ! - ! ! - ! size_dim2 unsigned int(64 bit) - Defines the geometry array size for the ! - ! second spatial dimension. ! - ! ! - ! size_dim3 unsigned int(64 bit) - Defines the geometry array size for the ! - ! third spatial dimension. ! - ! ! - ! udef_param unsigned int(64 bit) - Defines a marker used to signal which ! - ! user defined parameters are present in ! - ! the eas3 file. ! - ! ! - ! udef_char_size unsigned int(64 bit) - Defines the size for the user defined ! - ! char array. ! - ! ! - ! udef_int_size unsigned int(64 bit) - Defines the size for the user defined ! - ! int array. ! - ! ! - ! udef_real_size unsigned int(64 bit) - Defines the size for the user defined ! - ! real array. ! - ! ! - ! DEPENDENCIES: ! - ! ------------- ! - ! Variable Type Description ! - ! -------- ---- ----------- ! - ! - - - ! - ! ! - ! DEVELOPMENT HISTORY: ! - ! -------------------- ! - ! ! - ! Date Author Change Id Release Description Of Change ! - ! ---- ------ --------- ------- --------------------- ! - ! 20.06.2018 Patrick Vogler B87D120 V 0.1.0 struct created ! - ! ! - \*----------------------------------------------------------------------------------------------------------*/ - typedef struct - { - uint64_t file_type; - uint64_t accuracy; - uint64_t nzs; - uint64_t npar; - uint64_t ndim1; - uint64_t ndim2; - uint64_t ndim3; - uint64_t attribute_mode; - uint64_t gmode_time; - uint64_t gmode_param; - uint64_t gmode_dim1; - uint64_t gmode_dim2; - uint64_t gmode_dim3; - uint64_t size_time; - uint64_t size_parameter; - uint64_t size_dim1; - uint64_t size_dim2; - uint64_t size_dim3; - uint64_t udef_param; - uint64_t udef_char_size; - uint64_t udef_int_size; - uint64_t udef_real_size; - } eas3_std_params; - - /************************************************************************************************************\ - || ___ _ _ ___ _ _ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ || - || |__] | | |__] | | | |___ | | |\ | | | | | | |\ | [__ || - || | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] || - || || - \************************************************************************************************************/ - /*----------------------------------------------------------------------------------------------------------*\ - ! FUNCTION NAME: bwc_data* read_eas3(const char* const filename) ! - ! -------------- ! - ! ! - ! DESCRIPTION: ! - ! ------------ ! - ! This function opens an eas3 file and checks it for its validity. Once the specified file ! - ! has been verified, its header and flow field data is read and stored in the bwc_data ! - ! structure. ! - ! ! - \*----------------------------------------------------------------------------------------------------------*/ - bwc_data* - read_eas3(char *const filename); + /************************************************************************************************************\ + || ___ _ _ ___ ____ ____ || + || | \_/ |__] |___ [__ || + || | | | |___ ___] || + || || + \************************************************************************************************************/ + /*----------------------------------------------------------------------------------------------*\ + ! ! + ! DESCRIPTION: ! + ! ------------ ! + ! ! + ! This structure is used to read/assemble a packed codestream during coding. The ! + ! byte buffer is flushed to the packed stream as soon as the a single byte has ! + ! been assembled. ! + ! ! + \*----------------------------------------------------------------------------------------------*/ + typedef struct + { + uchar error; // Error flag used during streaming. - /*----------------------------------------------------------------------------------------------------------*\ - ! FUNCTION NAME: uchar write_eas3(bwc_data *const file, char *const filename) ! - ! -------------- ! - ! ! - ! DESCRIPTION: ! - ! ------------ ! - ! This function creates a valid eas3 file from the information stored in the bwc_data ! - ! structure. ! - ! ! - \*----------------------------------------------------------------------------------------------------------*/ - uchar - write_eas3(bwc_data *const file, char *const filename); + uint64 L; // Number of bytes written to/from stream. + uint64 Lmax; // Size of packed stream. + uint64 size_incr; // Size incrmnt used for stream assembly. + + uint8 T; // Byte buffer. + int8 t; // Byte buffer counter. + + uchar *memory; // Memory handle for packed stream chunck. + } bitstream; + + /*----------------------------------------------------------------------------------------------------------*\ + ! STRUCT NAME: eas3_header ! + ! ----------- ! + ! ! + ! DESCRIPTION: ! + ! ------------ ! + ! This structure is used to store the eas3 header information. For a more thorough discussion ! + ! of the eas3 datatype see: ! + ! ! + ! https://wiki.iag.uni-stuttgart.de/eas3wiki/index.php/EAS3_File_Format/de ! + ! ! + ! PARAMETERS: ! + ! ----------- ! + ! Variable Type Description ! + ! -------- ---- ----------- ! + ! file_type unsigned int(64 bit) - Defines an identifier for the EAS type. ! + ! ! + ! accuracy unsigned int(64 bit) - Defines the accuracy of an eas3 file. ! + ! ! + ! nzs unsigned int(64 bit) - Variable defining the temporal size of ! + ! the uncompressed dataset. ! + ! ! + ! npar unsigned int(64 bit) - Defines the number of parameters in the ! + ! eas3 dataset. ! + ! ! + ! ndim1, -2, -3 unsigned int(64 bit) - Variables defining the spatial size of ! + ! the eas3 dataset. ! + ! ! + ! attribute_mode; unsigned int(64 bit) - Defines an identifier used to signal ! + ! the attribute mode of the eas3 file. ! + ! ! + ! gmode_time unsigned int(64 bit) - Defines the geometry mode for the temp- ! + ! oral dimension. ! + ! ! + ! gmode_param unsigned int(64 bit) - Defines the geometry mode for the para- ! + ! meters. ! + ! ! + ! gmode_dim1 unsigned int(64 bit) - Defines the geometry mode for the first ! + ! spatial dimension. ! + ! ! + ! gmode_dim2 unsigned int(64 bit) - Defines the geometry mode for the sec- ! + ! ond spatial dimension. ! + ! ! + ! gmode_dim3 unsigned int(64 bit) - Defines the geometry mode for the third ! + ! spatial dimension. ! + ! ! + ! size_time unsigned int(64 bit) - Defines the geometry array size for the ! + ! temporal dimension. ! + ! ! + ! size_parameter unsigned int(64 bit) - Defines the geometry array size for the ! + ! parameters. ! + ! ! + ! size_dim1 unsigned int(64 bit) - Defines the geometry array size for the ! + ! first spatial dimension. ! + ! ! + ! size_dim2 unsigned int(64 bit) - Defines the geometry array size for the ! + ! second spatial dimension. ! + ! ! + ! size_dim3 unsigned int(64 bit) - Defines the geometry array size for the ! + ! third spatial dimension. ! + ! ! + ! udef_param unsigned int(64 bit) - Defines a marker used to signal which ! + ! user defined parameters are present in ! + ! the eas3 file. ! + ! ! + ! udef_char_size unsigned int(64 bit) - Defines the size for the user defined ! + ! char array. ! + ! ! + ! udef_int_size unsigned int(64 bit) - Defines the size for the user defined ! + ! int array. ! + ! ! + ! udef_real_size unsigned int(64 bit) - Defines the size for the user defined ! + ! real array. ! + ! ! + ! DEPENDENCIES: ! + ! ------------- ! + ! Variable Type Description ! + ! -------- ---- ----------- ! + ! - - - ! + ! ! + ! DEVELOPMENT HISTORY: ! + ! -------------------- ! + ! ! + ! Date Author Change Id Release Description Of Change ! + ! ---- ------ --------- ------- --------------------- ! + ! 20.06.2018 Patrick Vogler B87D120 V 0.1.0 struct created ! + ! ! + \*----------------------------------------------------------------------------------------------------------*/ + typedef struct + { + uint64_t file_type; + uint64_t accuracy; + uint64_t nzs; + uint64_t npar; + uint64_t ndim1; + uint64_t ndim2; + uint64_t ndim3; + uint64_t attribute_mode; + uint64_t gmode_time; + uint64_t gmode_param; + uint64_t gmode_dim1; + uint64_t gmode_dim2; + uint64_t gmode_dim3; + uint64_t size_time; + uint64_t size_parameter; + uint64_t size_dim1; + uint64_t size_dim2; + uint64_t size_dim3; + uint64_t udef_param; + uint64_t udef_char_size; + uint64_t udef_int_size; + uint64_t udef_real_size; + } eas3_std_params; + + /************************************************************************************************************\ + || ___ _ _ ___ _ _ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ || + || |__] | | |__] | | | |___ | | |\ | | | | | | |\ | [__ || + || | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] || + || || + \************************************************************************************************************/ + /*----------------------------------------------------------------------------------------------------------*\ + ! FUNCTION NAME: bwc_data* read_eas3(const char* const filename) ! + ! -------------- ! + ! ! + ! DESCRIPTION: ! + ! ------------ ! + ! This function opens an eas3 file and checks it for its validity. Once the specified file ! + ! has been verified, its header and flow field data is read and stored in the bwc_data ! + ! structure. ! + ! ! + \*----------------------------------------------------------------------------------------------------------*/ + bwc_data* + read_eas3(char *const filename); + + /*----------------------------------------------------------------------------------------------------------*\ + ! FUNCTION NAME: uchar write_eas3(bwc_data *const file, char *const filename) ! + ! -------------- ! + ! ! + ! DESCRIPTION: ! + ! ------------ ! + ! This function creates a valid eas3 file from the information stored in the bwc_data ! + ! structure. ! + ! ! + \*----------------------------------------------------------------------------------------------------------*/ + uchar + write_eas3(bwc_data *const file, char *const filename); #endif \ No newline at end of file diff --git a/include/library/private/bitstream.h b/include/library/private/bitstream.h index f0c3239..6363775 100755 --- a/include/library/private/bitstream.h +++ b/include/library/private/bitstream.h @@ -54,41 +54,71 @@ \************************************************************************************************/ #include "types.h" + /************************************************************************************************\ + || ___ ____ ____ ____ _ _ _ ____ ___ ___ _ _ ___ ____ ____ || + || | \ |___ |__/ |__/ | | | |___ | \ | \_/ |__] |___ [__ || + || |__/ |___ | \ | \ | \/ |___ |__/ | | | |___ ___] || + || || + \************************************************************************************************/ + /*----------------------------------------------------------------------------------------------*\ + ! ! + ! DESCRIPTION: ! + ! ------------ ! + ! ! + ! This structure is used to read/assemble a packed codestream during coding. The ! + ! byte buffer is flushed to the packed stream as soon as the a single byte has ! + ! been assembled. ! + ! ! + \*----------------------------------------------------------------------------------------------*/ + typedef struct + { + uchar error; // Error flag used during streaming. + + uint64 L; // Number of bytes written to/from stream. + uint64 Lmax; // Size of packed stream. + uint64 size_incr; // Size incrmnt used for stream assembly. + + uint8 T; // Byte buffer. + int8 t; // Byte buffer counter. + + uchar *memory; // Memory handle for packed stream chunck. + } bitstream; + /************************************************************************************************\ || ___ _ _ ___ _ _ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ || || |__] | | |__] | | | |___ | | |\ | | | | | | |\ | [__ || || | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] || || || \************************************************************************************************/ - uint64 bytes_used (bwc_stream const *const stream); + uint64 bytes_used (bitstream const *const stream); //==========|==========================|======================|======|======|===================== - bwc_stream* bwc_init_stream (uchar *const memory, + bitstream* init_stream (uchar *const memory, uint32 const size, char const instr); //==========|==========================|======================|======|======|===================== - void bwc_emit_chunck (bwc_stream *const stream, + void emit_chunck (bitstream *const stream, uchar const *const chunck, uint64 const size); //==========|==========================|======================|======|======|===================== - void bwc_emit_symbol (bwc_stream *const stream, + void emit_symbol (bitstream *const stream, uint64 const symbol, uint8 const size); //==========|==========================|======================|======|======|===================== - void bwc_emit_bit (bwc_stream *const stream, + void emit_bit (bitstream *const stream, uint64 const bit); //==========|==========================|======================|======|======|===================== - void flush_stream (bwc_stream *const stream); + void flush_stream (bitstream *const stream); //==========|==========================|======================|======|======|===================== - uchar* bwc_get_chunck (bwc_stream *const stream, + uchar* get_chunck (bitstream *const stream, uint64 const length); //==========|==========================|======================|======|======|===================== - uint64 bwc_get_symbol (bwc_stream *const stream, + uint64 get_symbol (bitstream *const stream, uint8 const length); //==========|==========================|======================|======|======|===================== - uchar bwc_get_bit (bwc_stream *const stream); + uchar get_bit (bitstream *const stream); //==========|==========================|======================|======|======|===================== - uchar bwc_terminate_stream (bwc_stream *stream, - bwc_packed_stream *const packed_stream); + uchar terminate_stream (bitstream *stream, + bwc_stream *const packed_stream); //==========|==========================|======================|======|======|===================== - void release_packed_stream (bwc_packed_stream *const stream); -#endif \ No newline at end of file + void release_packed_stream (bwc_stream *const stream); +#endif diff --git a/include/library/private/codestream.h b/include/library/private/codestream.h index d13ebd6..482b8eb 100755 --- a/include/library/private/codestream.h +++ b/include/library/private/codestream.h @@ -54,6 +54,7 @@ || || \************************************************************************************************/ #include "types.h" + #include "bitstream.h" /************************************************************************************************\ || _ _ ____ ____ ____ ____ ____ || @@ -67,7 +68,7 @@ ! ------------ ! ! ! ! These macros define stream manipulation operations to rewind, forward, inquire ! - ! the availability and get access to the current memory position of a bwc_stream. ! + ! the availability and get access to the current memory position of a bitstrean. ! ! ! \*----------------------------------------------------------------------------------------------*/ #define rewind_stream(stream, delta) \ @@ -90,17 +91,13 @@ \************************************************************************************************/ uchar assemble_main_header (bwc_field *const field); //==========|==========================|======================|======|======|===================== - bwc_field* bwc_parse_main_header (bwc_data *const data, - bwc_stream *const stream); + uchar codestream_write_aux (bwc_stream *const header, + bwc_stream *const aux); //==========|==========================|======================|======|======|===================== - uchar codestream_write_aux (bwc_packed_stream *const header, - bwc_packed_stream *const aux); + uchar codestream_write_com (bwc_stream *const header, + bwc_stream *const com); //==========|==========================|======================|======|======|===================== - uchar codestream_write_com (bwc_packed_stream *const header, - bwc_packed_stream *const com); - //==========|==========================|======================|======|======|===================== - bwc_packed_stream* assemble_codestream (bwc_field *const field); - + bwc_stream* assemble_codestream (bwc_field *const field); //==========|==========================|======================|======|======|===================== bwc_field* parse_codestream (bwc_data *const data, uint8 const layer); diff --git a/include/library/private/prim_types_double.h b/include/library/private/prim_types_double.h index a5db7e5..4c8fc4b 100755 --- a/include/library/private/prim_types_double.h +++ b/include/library/private/prim_types_double.h @@ -58,21 +58,21 @@ || | | \ | | | | | | \/ |___ | | | |___ ___] || || || \************************************************************************************************/ - typedef unsigned char uchar; - typedef unsigned short ushort; - typedef unsigned int uint; + typedef unsigned char uchar; + typedef unsigned short ushort; + typedef unsigned int uint; - typedef int8_t int8; - typedef uint8_t uint8; - typedef int16_t int16; - typedef uint16_t uint16; - typedef int32_t int32; - typedef uint32_t uint32; - typedef int64_t int64; - typedef uint64_t uint64; + typedef int8_t int8; + typedef uint8_t uint8; + typedef int16_t int16; + typedef uint16_t uint16; + typedef int32_t int32; + typedef uint32_t uint32; + typedef int64_t int64; + typedef uint64_t uint64; - typedef double bwc_float; - typedef uint64 bwc_raw; + typedef double bwc_float; + typedef uint64 bwc_raw; /************************************************************************************************\ || _ _ ____ ____ ____ ____ ____ || diff --git a/include/library/private/tagtree.h b/include/library/private/tagtree.h index 721696a..7682cf4 100755 --- a/include/library/private/tagtree.h +++ b/include/library/private/tagtree.h @@ -59,6 +59,7 @@ || || \************************************************************************************************/ #include "types.h" + #include "bitstream.h" /************************************************************************************************\ || ___ _ _ ___ _ _ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ || @@ -83,13 +84,13 @@ uint16 const value); //==========|==========================|======================|======|=======|==================== void encode_tagtree (bwc_tagtree *const tagtree, - bwc_stream *const stream, + bitstream *const stream, uint32 const threshold, uint32 const leaf_index, uchar const estimate); //==========|==========================|======================|======|=======|==================== uchar decode_tagtree (bwc_tagtree *const tagtree, - bwc_stream *const stream, + bitstream *const stream, uint32 const threshold, uint32 const leaf_index); #endif \ No newline at end of file diff --git a/include/library/private/tier2.h b/include/library/private/tier2.h index cf135de..3dc0bb2 100755 --- a/include/library/private/tier2.h +++ b/include/library/private/tier2.h @@ -54,7 +54,6 @@ \************************************************************************************************/ #include "types.h" - /************************************************************************************************\ || _ _ ____ ____ ____ ____ ____ || || |\/| |__| | |__/ | | [__ || diff --git a/include/library/private/types.h b/include/library/private/types.h index 2af1a59..153be17 100755 --- a/include/library/private/types.h +++ b/include/library/private/types.h @@ -99,33 +99,8 @@ uchar *access; // Pointer used to parse packed stream. uchar *memory; // Memory handle for the packed stream. - } bwc_packed_stream; - - /*----------------------------------------------------------------------------------------------*\ - ! ! - ! DESCRIPTION: ! - ! ------------ ! - ! ! - ! This structure is used to read/assemble a packed codestream during coding. The ! - ! byte buffer is flushed to the packed stream as soon as the a single byte has ! - ! been assembled. ! - ! ! - \*----------------------------------------------------------------------------------------------*/ - typedef struct - { - uchar error; // Error flag used during streaming. - - uint64 L; // Number of bytes written to/from stream. - uint64 Lmax; // Size of packed stream. - uint64 size_incr; // Size incrmnt used for stream assembly. - - uint8 T; // Byte buffer. - int8 t; // Byte buffer counter. - - uchar *memory; // Memory handle for packed stream chunck. } bwc_stream; - /*----------------------------------------------------------------------------------------------*\ ! ! ! DESCRIPTION: ! @@ -227,9 +202,9 @@ struct codestream { - bwc_packed_stream *data; // Data codestream block. - bwc_packed_stream *aux; // Auxiliary info. codestream block. - bwc_packed_stream *com; // Comment codestream block. + bwc_stream *data; // Data codestream block. + bwc_stream *aux; // Auxiliary info. codestream block. + bwc_stream *com; // Comment codestream block. }codestream; struct field @@ -445,8 +420,8 @@ \*----------------------------------------------------------------------------------------------*/ typedef struct { - bwc_packed_stream header; // Packed stream header. - bwc_packed_stream body; // Packed stream body. + bwc_stream header; // Packed stream header. + bwc_stream body; // Packed stream body. uint8 e; // Indicator for packet cb. contributions. uint32 size; // Codestream packet size. @@ -714,7 +689,7 @@ uint8 guard_bits; // Number of guard bits during quant. - bwc_packed_stream header; // Main codestream header. + bwc_stream header; // Main codestream header. bwc_quant_st quantization_style; // Quantization style. bwc_prog_ord progression; // Packet progression order. diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 27237d0..c09fa90 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -84,6 +84,423 @@ || | | \ | \/ | | | |___ | |__| | \| |___ | | |__| | \| ___] || || || \************************************************************************************************************/ +/*----------------------------------------------------------------------------------------------------------*\ +! FUNCTION NAME: uint32 bytes_used(bitstream *const stream) ! +! -------------- ! +! ! +! DESCRIPTION: ! +! ------------ ! +! This function is used to evaluate the number of bytes that have already been ! +! written to the allocated bitstream memory block. ! +! ! +! PARAMETERS: ! +! ----------- ! +! Variable Type Description ! +! -------- ---- ----------- ! +! stream bitstream* - Structure that ! +! ! +! RETURN VALUE: ! +! ------------- ! +! Type Description ! +! ---- ----------- ! +! unsigned int(32 bit) - Number of bites that have been written to the ! +! bitstream. ! +! ! +! DEVELOPMENT HISTORY: ! +! -------------------- ! +! ! +! Date Author Change Id Release Description Of Change ! +! ---- ------ --------- ------- --------------------- ! +! 13.05.2019 Patrick Vogler B87D120 V 0.1.0 function created ! +! ! +\*----------------------------------------------------------------------------------------------------------*/ +uint64 +bytes_used(bitstream const *const stream) +{ + if(stream->T == 0xFF) + { + return stream->L + 1; + } + else + { + return stream->L; + } +} + +/*----------------------------------------------------------------------------------------------------------*\ +! FUNCTION NAME: bitstream* bwc_init_stream(uchar* memory, uint32 size, char instr) ! +! -------------- ! +! ! +! DESCRIPTION: ! +! ------------ ! +! This function is used to initialize a bwc bitstream. For encoding, a null pointer ! +! is passed as a memory handle and the function will allocate a memory block with the ! +! specified stream size. For decoding, a valid memory handle, passed by the function ! +! caller, will be stored in the bitstream structure. The byte buffer counter t, ! +! stream size Lmax and size increment are initialized with their appropriate values. ! +! ! +! PARAMETERS: ! +! ----------- ! +! Variable Type Description ! +! -------- ---- ----------- ! +! size unsigned int(32 bit) - Initial size of the bwc stream. ! +! ! +! memory unsigned char - Memory handle for the bwc stream memory ! +! block. ! +! ! +! instr char - Constant used to instruct the field ! +! initialization. ! +! ! +! RETURN VALUE: ! +! ------------- ! +! Type Description ! +! ---- ----------- ! +! bitstream* - Memory handle for the initialized bwc stream. ! +! ! +! DEVELOPMENT HISTORY: ! +! -------------------- ! +! ! +! Date Author Change Id Release Description Of Change ! +! ---- ------ --------- ------- --------------------- ! +! 19.06.2019 Patrick Vogler B87D120 V 0.1.0 function created ! +! ! +\*----------------------------------------------------------------------------------------------------------*/ +bitstream* +init_stream(uchar* memory, uint32 size, char instr) +{ + /*-----------------------*\ + ! DEFINE STRUCTS: ! + \*-----------------------*/ + bitstream *stream; + + /*-----------------------*\ + ! DEFINE ASSERTIONS: ! + \*-----------------------*/ + assert(instr == 'c' || instr == 'd'); + + /*--------------------------------------------------------*\ + ! Allocate the bwc stream structure. ! + \*--------------------------------------------------------*/ + stream = calloc(1, sizeof(bitstream)); + if(!stream) + { + // memory allocation error + fprintf(stderr, MEMERROR); + return NULL; + } + + /*--------------------------------------------------------*\ + ! Evaluate if a valid memory handle has been passed by the ! + ! function caller. ! + \*--------------------------------------------------------*/ + if(!memory) + { + /*--------------------------------------------------------*\ + ! If no valid memory handle has been passed, allocate a ! + ! memory block with the specifiec stream size. ! + \*--------------------------------------------------------*/ + stream->memory = calloc(size, sizeof(uchar)); + if(!stream->memory) + { + // memory allocation error + fprintf(stderr, MEMERROR); + return NULL; + } + } + else + { + /*--------------------------------------------------------*\ + ! If a valid memory handle has been passed for decoding, ! + ! save the memory handle in the bwc stream structure. ! + \*--------------------------------------------------------*/ + stream->memory = memory; + } + + /*--------------------------------------------------------*\ + ! Initialize the byte buffer counter, stream size and size ! + ! increment for the current stream. ! + \*--------------------------------------------------------*/ + stream->t = (instr == 'c') ? 8 : 0; + stream->Lmax = size; + stream->size_incr = (uint64)(size / 2); + + /*--------------------------------------------------------*\ + ! Return the stream memory handle. ! + \*--------------------------------------------------------*/ + return stream; +} + +/*----------------------------------------------------------------------------------------------------------*\ +! FUNCTION NAME: void bwc_emit_chunck(bitstream *const stream, const uchar* string, const uint64 length) ! +! -------------- ! +! ! +! DESCRIPTION: ! +! ------------ ! +! This function is used to write an additional chunck of size length to a bwc bitstream. ! +! ! +! ! +! PARAMETERS: ! +! ----------- ! +! Variable Type Description ! +! -------- ---- ----------- ! +! stream bitstream* - Structure used to assemble a bwc bit- ! +! bitstream. ! +! ! +! chunck unsigned char* - Memory handle for a data block that is ! +! to be written to the bwc bitstream. ! +! ! +! size unsigned int(64 bit) - Size of the data block. ! +! ! +! RETURN VALUE: ! +! ------------- ! +! Type Description ! +! ---- ----------- ! +! - - ! +! ! +! DEVELOPMENT HISTORY: ! +! -------------------- ! +! ! +! Date Author Change Id Release Description Of Change ! +! ---- ------ --------- ------- --------------------- ! +! 22.06.2019 Patrick Vogler B87D120 V 0.1.0 function created ! +! ! +\*----------------------------------------------------------------------------------------------------------*/ +void +emit_chunck(bitstream *const stream, const uchar* chunck, const uint64 size) +{ + /*-----------------------*\ + ! DEFINE INT VARIABLES: ! + \*-----------------------*/ + uint64 Lreq; + + /*-----------------------*\ + ! DEFINE ASSERTIONS: ! + \*-----------------------*/ + assert(stream); + assert(chunck); + + /*--------------------------------------------------------*\ + ! Evaluate the memory block size if the current chunck of ! + ! data is written to the stream. ! + \*--------------------------------------------------------*/ + Lreq = (bytes_used(stream) + size); + + /*--------------------------------------------------------*\ + ! Check if the enough memory has been allocated for the ! + ! stream to store the additional data chunck. ! + \*--------------------------------------------------------*/ + if(Lreq > stream->Lmax) + { + /*--------------------------------------------------------*\ + ! If the stream is not large enough, check if this is due ! + ! to an error encountered in a previous writing operation ! + \*--------------------------------------------------------*/ + if(!stream->error) + { + /*--------------------------------------------------------*\ + ! If the error flag is not set, increase the stream size ! + ! until it is large enough to store the additional data ! + ! chunck. ! + \*--------------------------------------------------------*/ + while(Lreq > stream->Lmax) + { + stream->Lmax += stream->size_incr + size; + stream->size_incr = (uint64)(stream->Lmax / 2); + } + + /*--------------------------------------------------------*\ + ! Reallocate the stream data block. ! + \*--------------------------------------------------------*/ + stream->memory = realloc(stream->memory, stream->Lmax); + if(!stream->memory) + { + // memory allocation error + stream->error |= 1; + stream->Lmax = 0; + return; + } + } + else + { + /*--------------------------------------------------------*\ + ! Exit to function caller if error flag has been set. ! + \*--------------------------------------------------------*/ + return; + } + } + + /*--------------------------------------------------------*\ + ! Copy the additional data to the stream memory block. ! + \*--------------------------------------------------------*/ + memcpy(stream->memory + stream->L, chunck, size); + + /*--------------------------------------------------------*\ + ! Increment the number of bytes written to the stream with ! + ! the size of the newly added data chunck. ! + \*--------------------------------------------------------*/ + stream->L += size; +} + +/*----------------------------------------------------------------------------------------------------------*\ +! FUNCTION NAME: void *test(void) ! +! -------------- ! +! ! +! DESCRIPTION: ! +! ------------ ! +! DESCRIPTION NEEDED ! +! ! +! PARAMETERS: ! +! ----------- ! +! Variable Type Description ! +! -------- ---- ----------- ! +! stream bitstream* - Structure used to assemble a bwc bit- ! +! bitstream. ! +! ! +! size unsigned int(64 bit) - Size of the data block. ! +! ! +! RETURN VALUE: ! +! ------------- ! +! Type Description ! +! ---- ----------- ! +! uchar* - Data chunck requested by the function caller. ! +! ! +! DEVELOPMENT HISTORY: ! +! -------------------- ! +! ! +! Date Author Change Id Release Description Of Change ! +! ---- ------ --------- ------- --------------------- ! +! 22.06.2019 Patrick Vogler B87D120 V 0.1.0 function created ! +! ! +\*----------------------------------------------------------------------------------------------------------*/ +uchar* +get_chunck(bitstream *const stream, const uint64 size) +{ + /*-----------------------*\ + ! DEFINE CHAR VARIABLES: ! + \*-----------------------*/ + uchar *tmp; + + /*-----------------------*\ + ! DEFINE ASSERTIONS: ! + \*-----------------------*/ + assert(stream); + + /*--------------------------------------------------------*\ + ! Check if the number of bytes to be read from the stream ! + ! does not exceed the number of bytes still present in its ! + ! memory block. ! + \*--------------------------------------------------------*/ + if(bytes_used(stream) + size <= stream->Lmax) + { + /*--------------------------------------------------------*\ + ! Allocate a temporary array used to store the bytes that ! + ! are extracted from the stream. ! + \*--------------------------------------------------------*/ + tmp = calloc(size, sizeof(uchar)); + if(!tmp) + { + // memory allocation error + fprintf(stderr, MEMERROR); + return NULL; + } + + /*--------------------------------------------------------*\ + ! Copy the bytes requested from the function caller from ! + ! the stream to the temporary data block. ! + \*--------------------------------------------------------*/ + memcpy(tmp, stream->memory + stream->L, size); + + /*--------------------------------------------------------*\ + ! Increment the number of bytes read from the bitstream. ! + \*--------------------------------------------------------*/ + stream->L += size; + + /*--------------------------------------------------------*\ + ! Return the temporary data block to the function caller. ! + \*--------------------------------------------------------*/ + return tmp; + } + else + { + /*--------------------------------------------------------*\ + ! If the requested block size exceeds the information left ! + ! in the bitstream, set the bitstream error flag and ! + ! return a NULL pointer. ! + \*--------------------------------------------------------*/ + stream->error |= 1; + return NULL; + } +} + +/*----------------------------------------------------------------------------------------------------------*\ +! FUNCTION NAME: void *test(void) ! +! -------------- ! +! ! +! DESCRIPTION: ! +! ------------ ! +! DESCRIPTION NEEDED ! +! ! +! PARAMETERS: ! +! ----------- ! +! Variable Type Description ! +! -------- ---- ----------- ! +! - - - ! +! ! +! RETURN VALUE: ! +! ------------- ! +! Type Description ! +! ---- ----------- ! +! - - ! +! ! +! DEVELOPMENT HISTORY: ! +! -------------------- ! +! ! +! Date Author Change Id Release Description Of Change ! +! ---- ------ --------- ------- --------------------- ! +! - Patrick Vogler B87D120 V 0.1.0 function created ! +! ! +\*----------------------------------------------------------------------------------------------------------*/ +uchar +terminate_stream(bitstream *stream, bwc_stream *const packed_stream) +{ + /*-----------------------*\ + ! DEFINE ASSERTIONS: ! + \*-----------------------*/ + assert(stream); + + if(packed_stream) + { + if(stream->error) + { + return 1; + } + else if(stream->L != stream->Lmax) + { + stream->Lmax = stream->L; + stream->memory = realloc(stream->memory, stream->Lmax); + if(!stream->memory) + { + // memory allocation error + fprintf(stderr, MEMERROR); + stream->Lmax = 0; + return 1; + } + } + + packed_stream->memory = stream->memory; + packed_stream->access = stream->memory; + packed_stream->size = stream->L; + packed_stream->position = 0; + } + else + { + free(stream->memory); + } + + free(stream); + return 0; +} + /*----------------------------------------------------------------------------------------------------------*\ ! ! ! DESCRIPTION: ! @@ -222,7 +639,7 @@ read_eas3_header(bwc_data *const data) ! DEFINE STRUCTS: ! \*-----------------------*/ bwc_gl_inf *info; - bwc_stream *aux; + bitstream *aux; eas3_std_params params; /*-----------------------*\ @@ -284,7 +701,7 @@ read_eas3_header(bwc_data *const data) /*--------------------------------------------------------*\ ! Allocate the auxiliary information packed stream. ! \*--------------------------------------------------------*/ - data->codestream.aux = calloc(1, sizeof(bwc_packed_stream)); + data->codestream.aux = calloc(1, sizeof(bwc_stream)); if(!data->codestream.aux) { // memory allocation error @@ -299,7 +716,7 @@ read_eas3_header(bwc_data *const data) ! block has been chosen arbitrarily and should be large ! ! enough to prevent excessive reallocation. ! \*--------------------------------------------------------*/ - aux = bwc_init_stream(NULL, AUX_SIZE, 'c'); + aux = init_stream(NULL, AUX_SIZE, 'c'); if(!aux) { // memory allocation error @@ -346,7 +763,7 @@ read_eas3_header(bwc_data *const data) ! Emit the standard parameters to the auxiliary informa- ! ! tion information memory block. ! \*--------------------------------------------------------*/ - bwc_emit_chunck(aux, (uchar*)¶ms, 176); + emit_chunck(aux, (uchar*)¶ms, 176); /*--------------------------------------------------------*\ ! Convert the parameters required for the bwc compression ! @@ -423,7 +840,7 @@ read_eas3_header(bwc_data *const data) ! Emit the time step array to the auxiliary information ! ! memory block. ! \*--------------------------------------------------------*/ - bwc_emit_chunck(aux, buffer_char, info->nTS * sizeof(uint64)); + emit_chunck(aux, buffer_char, info->nTS * sizeof(uint64)); /*--------------------------------------------------------*\ ! Check if any attributes have been specified in the eas3 ! @@ -456,7 +873,7 @@ read_eas3_header(bwc_data *const data) ! Emit the timestep attribute array to the auxiliary infor-! ! mation memory block. ! \*--------------------------------------------------------*/ - bwc_emit_chunck(aux, buffer_char, info->nTS * ATTRLEN * sizeof(char)); + emit_chunck(aux, buffer_char, info->nTS * ATTRLEN * sizeof(char)); for(i = 0; i < info->nPar; ++i) { @@ -527,7 +944,7 @@ read_eas3_header(bwc_data *const data) ! Emit the remaining header information the the auxiliary ! ! information stream. ! \*--------------------------------------------------------*/ - bwc_emit_chunck(aux, buffer_char, Lread); + emit_chunck(aux, buffer_char, Lread); /*--------------------------------------------------------*\ ! Free the buffer character array. ! @@ -539,7 +956,7 @@ read_eas3_header(bwc_data *const data) ! ful, the address to the aux memory block stored is ! ! stored in the file structure alongside its size. ! \*--------------------------------------------------------*/ - if(bwc_terminate_stream(aux, data->codestream.aux)) + if(terminate_stream(aux, data->codestream.aux)) { // memory allocation error fprintf(stderr, MEMERROR); @@ -600,7 +1017,7 @@ write_eas3_header(bwc_data *const data) ! DEFINE STRUCTS: ! \*-----------------------*/ bwc_gl_inf *info; - bwc_stream *aux; + bitstream *aux; eas3_std_params *params; bwc_cmd_opts_ll *param; @@ -634,14 +1051,14 @@ write_eas3_header(bwc_data *const data) /*--------------------------------------------------------*\ ! Initialize the auxiliary information stream. ! \*--------------------------------------------------------*/ - aux = bwc_init_stream(data->codestream.aux->memory, - data->codestream.aux->size, 'd'); + aux = init_stream(data->codestream.aux->memory, + data->codestream.aux->size, 'd'); /*--------------------------------------------------------*\ ! Get the standard parameters from the auxiliary informa- ! ! memory block and write them to the file stream. ! \*--------------------------------------------------------*/ - params = (eas3_std_params*)bwc_get_chunck(aux, 176); + params = (eas3_std_params*)get_chunck(aux, 176); if(fwrite(params, sizeof(uint64), 22, fp) != 22) { @@ -669,7 +1086,7 @@ write_eas3_header(bwc_data *const data) ! the timestep array from the auxiliary information block ! ! and write it to the file stream. ! \*--------------------------------------------------------*/ - buffer_char = bwc_get_chunck(aux, info->nTS * sizeof(uint64)); + buffer_char = get_chunck(aux, info->nTS * sizeof(uint64)); if(!buffer_char) { // memory allocation error @@ -698,7 +1115,7 @@ write_eas3_header(bwc_data *const data) ! the timestep attribute array from the auxiliary informa- ! ! tion block and write it to the file stream. ! \*--------------------------------------------------------*/ - buffer_char = bwc_get_chunck(aux, info->nTS * ATTRLEN); + buffer_char = get_chunck(aux, info->nTS * ATTRLEN); if(!buffer_char) { // memory allocation error @@ -762,7 +1179,7 @@ write_eas3_header(bwc_data *const data) ! the remaining eas header bytes from the auxiliary infor- ! ! mation block and write it to the file stream. ! \*--------------------------------------------------------*/ - buffer_char = bwc_get_chunck(aux, Lwrite); + buffer_char = get_chunck(aux, Lwrite); if(!buffer_char) { // memory allocation error diff --git a/src/library/bitstream.c b/src/library/bitstream.c index 962daa4..1618c87 100755 --- a/src/library/bitstream.c +++ b/src/library/bitstream.c @@ -64,7 +64,7 @@ || || \************************************************************************************************************/ /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uint32 bytes_used(bwc_stream *const stream) ! +! FUNCTION NAME: uint32 bytes_used(bitstream *const stream) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -76,7 +76,7 @@ ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! stream bwc_stream* - Structure that ! +! stream bitstream* - Structure that ! ! ! ! RETURN VALUE: ! ! ------------- ! @@ -94,20 +94,20 @@ ! ! \*----------------------------------------------------------------------------------------------------------*/ uint64 -bytes_used(bwc_stream const *const stream) +bytes_used(bitstream const *const stream) { - if(stream->T == 0xFF) - { - return stream->L + 1; - } - else - { - return stream->L; - } + if(stream->T == 0xFF) + { + return stream->L + 1; + } + else + { + return stream->L; + } } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bwc_stream* bwc_init_stream(uchar* memory, uint32 size, char instr) ! +! FUNCTION NAME: bitstream* bwc_init_stream(uchar* memory, uint32 size, char instr) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -115,7 +115,7 @@ bytes_used(bwc_stream const *const stream) ! This function is used to initialize a bwc bitstream. For encoding, a null pointer ! ! is passed as a memory handle and the function will allocate a memory block with the ! ! specified stream size. For decoding, a valid memory handle, passed by the function ! -! caller, will be stored in the bwc_stream structure. The byte buffer counter t, ! +! caller, will be stored in the bitstream structure. The byte buffer counter t, ! ! stream size Lmax and size increment are initialized with their appropriate values. ! ! ! ! PARAMETERS: ! @@ -134,7 +134,7 @@ bytes_used(bwc_stream const *const stream) ! ------------- ! ! Type Description ! ! ---- ----------- ! -! bwc_stream* - Memory handle for the initialized bwc stream. ! +! bitstream* - Memory handle for the initialized bwc stream. ! ! ! ! DEVELOPMENT HISTORY: ! ! -------------------- ! @@ -144,73 +144,73 @@ bytes_used(bwc_stream const *const stream) ! 19.06.2019 Patrick Vogler B87D120 V 0.1.0 function created ! ! ! \*----------------------------------------------------------------------------------------------------------*/ -bwc_stream* -bwc_init_stream(uchar* memory, uint32 size, char instr) +bitstream* +init_stream(uchar* memory, uint32 size, char instr) { - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - bwc_stream *stream; + /*-----------------------*\ + ! DEFINE STRUCTS: ! + \*-----------------------*/ + bitstream *stream; - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(instr == 'c' || instr == 'd'); + /*-----------------------*\ + ! DEFINE ASSERTIONS: ! + \*-----------------------*/ + assert(instr == 'c' || instr == 'd'); - /*--------------------------------------------------------*\ - ! Allocate the bwc stream structure. ! - \*--------------------------------------------------------*/ - stream = calloc(1, sizeof(bwc_stream)); - if(!stream) - { + /*--------------------------------------------------------*\ + ! Allocate the bwc stream structure. ! + \*--------------------------------------------------------*/ + stream = calloc(1, sizeof(bitstream)); + if(!stream) + { + // memory allocation error + fprintf(stderr, MEMERROR); + return NULL; + } + + /*--------------------------------------------------------*\ + ! Evaluate if a valid memory handle has been passed by the ! + ! function caller. ! + \*--------------------------------------------------------*/ + if(!memory) + { + /*--------------------------------------------------------*\ + ! If no valid memory handle has been passed, allocate a ! + ! memory block with the specifiec stream size. ! + \*--------------------------------------------------------*/ + stream->memory = calloc(size, sizeof(uchar)); + if(!stream->memory) + { // memory allocation error fprintf(stderr, MEMERROR); return NULL; - } + } + } + else + { + /*--------------------------------------------------------*\ + ! If a valid memory handle has been passed for decoding, ! + ! save the memory handle in the bwc stream structure. ! + \*--------------------------------------------------------*/ + stream->memory = memory; + } + + /*--------------------------------------------------------*\ + ! Initialize the byte buffer counter, stream size and size ! + ! increment for the current stream. ! + \*--------------------------------------------------------*/ + stream->t = (instr == 'c') ? 8 : 0; + stream->Lmax = size; + stream->size_incr = (uint64)(size / 2); - /*--------------------------------------------------------*\ - ! Evaluate if a valid memory handle has been passed by the ! - ! function caller. ! - \*--------------------------------------------------------*/ - if(!memory) - { - /*--------------------------------------------------------*\ - ! If no valid memory handle has been passed, allocate a ! - ! memory block with the specifiec stream size. ! - \*--------------------------------------------------------*/ - stream->memory = calloc(size, sizeof(uchar)); - if(!stream->memory) - { - // memory allocation error - fprintf(stderr, MEMERROR); - return NULL; - } - } - else - { - /*--------------------------------------------------------*\ - ! If a valid memory handle has been passed for decoding, ! - ! save the memory handle in the bwc stream structure. ! - \*--------------------------------------------------------*/ - stream->memory = memory; - } - - /*--------------------------------------------------------*\ - ! Initialize the byte buffer counter, stream size and size ! - ! increment for the current stream. ! - \*--------------------------------------------------------*/ - stream->t = (instr == 'c') ? 8 : 0; - stream->Lmax = size; - stream->size_incr = (uint64)(size / 2); - - /*--------------------------------------------------------*\ - ! Return the stream memory handle. ! - \*--------------------------------------------------------*/ - return stream; + /*--------------------------------------------------------*\ + ! Return the stream memory handle. ! + \*--------------------------------------------------------*/ + return stream; } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_emit_chunck(bwc_stream *const stream, const uchar* string, const uint64 length) ! +! FUNCTION NAME: void bwc_emit_chunck(bitstream *const stream, const uchar* string, const uint64 length) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -222,7 +222,7 @@ bwc_init_stream(uchar* memory, uint32 size, char instr) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! stream bwc_stream* - Structure used to assemble a bwc bit- ! +! stream bitstream* - Structure used to assemble a bwc bit- ! ! bitstream. ! ! ! ! chunck unsigned char* - Memory handle for a data block that is ! @@ -245,79 +245,79 @@ bwc_init_stream(uchar* memory, uint32 size, char instr) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_emit_chunck(bwc_stream *const stream, const uchar* chunck, const uint64 size) +emit_chunck(bitstream *const stream, const uchar* chunck, const uint64 size) { - /*-----------------------*\ - ! DEFINE INT VARIABLES: ! - \*-----------------------*/ - uint64 Lreq; + /*-----------------------*\ + ! DEFINE INT VARIABLES: ! + \*-----------------------*/ + uint64 Lreq; - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(stream); - assert(chunck); + /*-----------------------*\ + ! DEFINE ASSERTIONS: ! + \*-----------------------*/ + assert(stream); + assert(chunck); - /*--------------------------------------------------------*\ - ! Evaluate the memory block size if the current chunck of ! - ! data is written to the stream. ! - \*--------------------------------------------------------*/ - Lreq = (bytes_used(stream) + size); + /*--------------------------------------------------------*\ + ! Evaluate the memory block size if the current chunck of ! + ! data is written to the stream. ! + \*--------------------------------------------------------*/ + Lreq = (bytes_used(stream) + size); - /*--------------------------------------------------------*\ - ! Check if the enough memory has been allocated for the ! - ! stream to store the additional data chunck. ! - \*--------------------------------------------------------*/ - if(Lreq > stream->Lmax) - { + /*--------------------------------------------------------*\ + ! Check if the enough memory has been allocated for the ! + ! stream to store the additional data chunck. ! + \*--------------------------------------------------------*/ + if(Lreq > stream->Lmax) + { + /*--------------------------------------------------------*\ + ! If the stream is not large enough, check if this is due ! + ! to an error encountered in a previous writing operation ! + \*--------------------------------------------------------*/ + if(!stream->error) + { /*--------------------------------------------------------*\ - ! If the stream is not large enough, check if this is due ! - ! to an error encountered in a previous writing operation ! + ! If the error flag is not set, increase the stream size ! + ! until it is large enough to store the additional data ! + ! chunck. ! \*--------------------------------------------------------*/ - if(!stream->error) + while(Lreq > stream->Lmax) { - /*--------------------------------------------------------*\ - ! If the error flag is not set, increase the stream size ! - ! until it is large enough to store the additional data ! - ! chunck. ! - \*--------------------------------------------------------*/ - while(Lreq > stream->Lmax) - { - stream->Lmax += stream->size_incr + size; - stream->size_incr = (uint64)(stream->Lmax / 2); - } - - /*--------------------------------------------------------*\ - ! Reallocate the stream data block. ! - \*--------------------------------------------------------*/ - stream->memory = realloc(stream->memory, stream->Lmax); - if(!stream->memory) - { - // memory allocation error - stream->error |= 1; - stream->Lmax = 0; - return; - } + stream->Lmax += stream->size_incr + size; + stream->size_incr = (uint64)(stream->Lmax / 2); } - else + + /*--------------------------------------------------------*\ + ! Reallocate the stream data block. ! + \*--------------------------------------------------------*/ + stream->memory = realloc(stream->memory, stream->Lmax); + if(!stream->memory) { - /*--------------------------------------------------------*\ - ! Exit to function caller if error flag has been set. ! - \*--------------------------------------------------------*/ - return; + // memory allocation error + stream->error |= 1; + stream->Lmax = 0; + return; } - } + } + else + { + /*--------------------------------------------------------*\ + ! Exit to function caller if error flag has been set. ! + \*--------------------------------------------------------*/ + return; + } + } - /*--------------------------------------------------------*\ - ! Copy the additional data to the stream memory block. ! - \*--------------------------------------------------------*/ - memcpy(stream->memory + stream->L, chunck, size); + /*--------------------------------------------------------*\ + ! Copy the additional data to the stream memory block. ! + \*--------------------------------------------------------*/ + memcpy(stream->memory + stream->L, chunck, size); - /*--------------------------------------------------------*\ - ! Increment the number of bytes written to the stream with ! - ! the size of the newly added data chunck. ! - \*--------------------------------------------------------*/ - stream->L += size; + /*--------------------------------------------------------*\ + ! Increment the number of bytes written to the stream with ! + ! the size of the newly added data chunck. ! + \*--------------------------------------------------------*/ + stream->L += size; } /*----------------------------------------------------------------------------------------------------------*\ @@ -332,7 +332,7 @@ bwc_emit_chunck(bwc_stream *const stream, const uchar* chunck, const uint64 size ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! stream bwc_stream* - Structure used to assemble a bwc bit- ! +! stream bitstream* - Structure used to assemble a bwc bit- ! ! bitstream. ! ! ! ! symbol unsigned int(64 bit) - Symbol that is to be written to the bwc ! @@ -356,73 +356,73 @@ bwc_emit_chunck(bwc_stream *const stream, const uchar* chunck, const uint64 size ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_emit_symbol(bwc_stream *const stream, const uint64 symbol, const uint8 size) +emit_symbol(bitstream *const stream, const uint64 symbol, const uint8 size) { - /*-----------------------*\ - ! DEFINE INT VARIABLES: ! - \*-----------------------*/ - uint8 byte; - int8 i; + /*-----------------------*\ + ! DEFINE INT VARIABLES: ! + \*-----------------------*/ + uint8 byte; + int8 i; - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(stream); - - /*--------------------------------------------------------*\ - ! Check if the enough memory has been allocated for the ! - ! stream to store the additional symbol. ! - \*--------------------------------------------------------*/ - if((bytes_used(stream) + size) > stream->Lmax) - { + /*-----------------------*\ + ! DEFINE ASSERTIONS: ! + \*-----------------------*/ + assert(stream); + + /*--------------------------------------------------------*\ + ! Check if the enough memory has been allocated for the ! + ! stream to store the additional symbol. ! + \*--------------------------------------------------------*/ + if((bytes_used(stream) + size) > stream->Lmax) + { + /*--------------------------------------------------------*\ + ! If the stream is not large enough, check if this is due ! + ! to an error encountered in a previous writing operation ! + \*--------------------------------------------------------*/ + if(!stream->error) + { /*--------------------------------------------------------*\ - ! If the stream is not large enough, check if this is due ! - ! to an error encountered in a previous writing operation ! + ! If the error flag is not set, increment the stream size ! + ! to store the additional symbol. ! \*--------------------------------------------------------*/ - if(!stream->error) - { - /*--------------------------------------------------------*\ - ! If the error flag is not set, increment the stream size ! - ! to store the additional symbol. ! - \*--------------------------------------------------------*/ - stream->Lmax += stream->size_incr; - stream->size_incr = (uint64)(stream->Lmax / 2); + stream->Lmax += stream->size_incr; + stream->size_incr = (uint64)(stream->Lmax / 2); - /*--------------------------------------------------------*\ - ! Reallocate the stream data block. ! - \*--------------------------------------------------------*/ - stream->memory = realloc(stream->memory, stream->Lmax); - if(!stream->memory) - { - // memory allocation error - stream->error |= 1; - stream->Lmax = 0; - return; - } - } - else + /*--------------------------------------------------------*\ + ! Reallocate the stream data block. ! + \*--------------------------------------------------------*/ + stream->memory = realloc(stream->memory, stream->Lmax); + if(!stream->memory) { - /*--------------------------------------------------------*\ - ! Exit to function caller if error flag has been set. ! - \*--------------------------------------------------------*/ - return; + // memory allocation error + stream->error |= 1; + stream->Lmax = 0; + return; } - } + } + else + { + /*--------------------------------------------------------*\ + ! Exit to function caller if error flag has been set. ! + \*--------------------------------------------------------*/ + return; + } + } - /*--------------------------------------------------------*\ - ! Copy the additional symbol to the stream memory block ! - ! one byte at a time and Increment the number of bytes ! - ! written to the stream. ! - \*--------------------------------------------------------*/ - for(i = size; i --> 0;) - { - byte = (uint8)((symbol >> (8 * i)) & 0xFF); - stream->memory[stream->L++] = (uchar)byte; - } + /*--------------------------------------------------------*\ + ! Copy the additional symbol to the stream memory block ! + ! one byte at a time and Increment the number of bytes ! + ! written to the stream. ! + \*--------------------------------------------------------*/ + for(i = size; i --> 0;) + { + byte = (uint8)((symbol >> (8 * i)) & 0xFF); + stream->memory[stream->L++] = (uchar)byte; + } } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_emit_bit(bwc_stream *const stream, const uint64 bit) ! +! FUNCTION NAME: void bwc_emit_bit(bitstream *const stream, const uint64 bit) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -433,7 +433,7 @@ bwc_emit_symbol(bwc_stream *const stream, const uint64 symbol, const uint8 size) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! stream bwc_stream* - Structure used to assemble a bwc bit- ! +! stream bitstream* - Structure used to assemble a bwc bit- ! ! bitstream. ! ! ! ! bit unsigned int(64 bit) - Bit that is to be written to the bwc ! @@ -454,99 +454,99 @@ bwc_emit_symbol(bwc_stream *const stream, const uint64 symbol, const uint8 size) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_emit_bit(bwc_stream *const stream, const uint64 bit) +emit_bit(bitstream *const stream, const uint64 bit) { - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(stream); - - /*--------------------------------------------------------*\ - ! Decrement the bit buffer counter. ! - \*--------------------------------------------------------*/ - stream->t--; + /*-----------------------*\ + ! DEFINE ASSERTIONS: ! + \*-----------------------*/ + assert(stream); + + /*--------------------------------------------------------*\ + ! Decrement the bit buffer counter. ! + \*--------------------------------------------------------*/ + stream->t--; - /*--------------------------------------------------------*\ - ! If the bit is significant, store the information at the ! - ! appropriate position in the bit buffer. ! - \*--------------------------------------------------------*/ - if(bit) - { - stream->T |= (1 << stream->t); - } + /*--------------------------------------------------------*\ + ! If the bit is significant, store the information at the ! + ! appropriate position in the bit buffer. ! + \*--------------------------------------------------------*/ + if(bit) + { + stream->T |= (1 << stream->t); + } - /*--------------------------------------------------------*\ - ! Check the bit buffer counter to see if the bit buffer is ! - ! full. ! - \*--------------------------------------------------------*/ - if(!stream->t) - { + /*--------------------------------------------------------*\ + ! Check the bit buffer counter to see if the bit buffer is ! + ! full. ! + \*--------------------------------------------------------*/ + if(!stream->t) + { + /*--------------------------------------------------------*\ + ! Check if the enough memory has been allocated for the ! + ! stream to store the additional byte. ! + \*--------------------------------------------------------*/ + if(bytes_used(stream) + 1 > stream->Lmax) + { /*--------------------------------------------------------*\ - ! Check if the enough memory has been allocated for the ! - ! stream to store the additional byte. ! + ! If the stream is not large enough, check if this is due ! + ! to an error encountered in a previous writing operation ! \*--------------------------------------------------------*/ - if(bytes_used(stream) + 1 > stream->Lmax) + if(!stream->error) { - /*--------------------------------------------------------*\ - ! If the stream is not large enough, check if this is due ! - ! to an error encountered in a previous writing operation ! - \*--------------------------------------------------------*/ - if(!stream->error) - { - /*--------------------------------------------------------*\ - ! If the error flag is not set, increment the stream size ! - ! to store the additional byte. ! - \*--------------------------------------------------------*/ - stream->Lmax += stream->size_incr; - stream->size_incr = (uint64)(stream->Lmax / 2); + /*--------------------------------------------------------*\ + ! If the error flag is not set, increment the stream size ! + ! to store the additional byte. ! + \*--------------------------------------------------------*/ + stream->Lmax += stream->size_incr; + stream->size_incr = (uint64)(stream->Lmax / 2); - /*--------------------------------------------------------*\ - ! Reallocate the stream data block. ! - \*--------------------------------------------------------*/ - stream->memory = realloc(stream->memory, stream->Lmax); - if(!stream->memory) - { - // memory allocation error - stream->error |= 1; - stream->Lmax = 0; - return; - } - } - else - { - /*--------------------------------------------------------*\ - ! Exit to function caller if error flag has been set. ! - \*--------------------------------------------------------*/ - return; - } - } - - /*--------------------------------------------------------*\ - ! Copy the additional byte to the stream memory block and ! - ! increment the number of bytes written to the stream. ! - \*--------------------------------------------------------*/ - stream->memory[stream->L++] = (uchar)stream->T; - - /*--------------------------------------------------------*\ - ! Reset the byte buffer counter. If the current buffer has ! - ! a value of 255, limit the counter to 7 bits to ensure ! - ! that the range FFFF to FF80 is reserved for the code- ! - ! stream markers. ! - \*--------------------------------------------------------*/ - if(stream->T == 0xFF) - { - stream->t = 7; + /*--------------------------------------------------------*\ + ! Reallocate the stream data block. ! + \*--------------------------------------------------------*/ + stream->memory = realloc(stream->memory, stream->Lmax); + if(!stream->memory) + { + // memory allocation error + stream->error |= 1; + stream->Lmax = 0; + return; + } } else { - stream->t = 8; + /*--------------------------------------------------------*\ + ! Exit to function caller if error flag has been set. ! + \*--------------------------------------------------------*/ + return; } + } - /*--------------------------------------------------------*\ - ! Reset the byte buffer. ! - \*--------------------------------------------------------*/ - stream->T = 0; - } + /*--------------------------------------------------------*\ + ! Copy the additional byte to the stream memory block and ! + ! increment the number of bytes written to the stream. ! + \*--------------------------------------------------------*/ + stream->memory[stream->L++] = (uchar)stream->T; + + /*--------------------------------------------------------*\ + ! Reset the byte buffer counter. If the current buffer has ! + ! a value of 255, limit the counter to 7 bits to ensure ! + ! that the range FFFF to FF80 is reserved for the code- ! + ! stream markers. ! + \*--------------------------------------------------------*/ + if(stream->T == 0xFF) + { + stream->t = 7; + } + else + { + stream->t = 8; + } + + /*--------------------------------------------------------*\ + ! Reset the byte buffer. ! + \*--------------------------------------------------------*/ + stream->T = 0; + } } /*----------------------------------------------------------------------------------------------------------*\ @@ -561,7 +561,7 @@ bwc_emit_bit(bwc_stream *const stream, const uint64 bit) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! stream bwc_stream* - Structure used to assemble a bwc bit- ! +! stream bitstream* - Structure used to assemble a bwc bit- ! ! bitstream. ! ! ! ! size unsigned int(64 bit) - Size of the data block. ! @@ -581,63 +581,63 @@ bwc_emit_bit(bwc_stream *const stream, const uint64 bit) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar* -bwc_get_chunck(bwc_stream *const stream, const uint64 size) +get_chunck(bitstream *const stream, const uint64 size) { - /*-----------------------*\ - ! DEFINE CHAR VARIABLES: ! - \*-----------------------*/ - uchar *tmp; + /*-----------------------*\ + ! DEFINE CHAR VARIABLES: ! + \*-----------------------*/ + uchar *tmp; - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(stream); + /*-----------------------*\ + ! DEFINE ASSERTIONS: ! + \*-----------------------*/ + assert(stream); - /*--------------------------------------------------------*\ - ! Check if the number of bytes to be read from the stream ! - ! does not exceed the number of bytes still present in its ! - ! memory block. ! - \*--------------------------------------------------------*/ - if(bytes_used(stream) + size <= stream->Lmax) - { - /*--------------------------------------------------------*\ - ! Allocate a temporary array used to store the bytes that ! - ! are extracted from the stream. ! - \*--------------------------------------------------------*/ - tmp = calloc(size, sizeof(uchar)); - if(!tmp) - { - // memory allocation error - fprintf(stderr, MEMERROR); - return NULL; - } - - /*--------------------------------------------------------*\ - ! Copy the bytes requested from the function caller from ! - ! the stream to the temporary data block. ! - \*--------------------------------------------------------*/ - memcpy(tmp, stream->memory + stream->L, size); - - /*--------------------------------------------------------*\ - ! Increment the number of bytes read from the bitstream. ! - \*--------------------------------------------------------*/ - stream->L += size; - - /*--------------------------------------------------------*\ - ! Return the temporary data block to the function caller. ! - \*--------------------------------------------------------*/ - return tmp; - } - else - { - /*--------------------------------------------------------*\ - ! If the requested block size exceeds the information left ! - ! in the bitstream, set the bitstream error flag and ! - ! return a NULL pointer. ! - \*--------------------------------------------------------*/ - stream->error |= 1; + /*--------------------------------------------------------*\ + ! Check if the number of bytes to be read from the stream ! + ! does not exceed the number of bytes still present in its ! + ! memory block. ! + \*--------------------------------------------------------*/ + if(bytes_used(stream) + size <= stream->Lmax) + { + /*--------------------------------------------------------*\ + ! Allocate a temporary array used to store the bytes that ! + ! are extracted from the stream. ! + \*--------------------------------------------------------*/ + tmp = calloc(size, sizeof(uchar)); + if(!tmp) + { + // memory allocation error + fprintf(stderr, MEMERROR); return NULL; - } + } + + /*--------------------------------------------------------*\ + ! Copy the bytes requested from the function caller from ! + ! the stream to the temporary data block. ! + \*--------------------------------------------------------*/ + memcpy(tmp, stream->memory + stream->L, size); + + /*--------------------------------------------------------*\ + ! Increment the number of bytes read from the bitstream. ! + \*--------------------------------------------------------*/ + stream->L += size; + + /*--------------------------------------------------------*\ + ! Return the temporary data block to the function caller. ! + \*--------------------------------------------------------*/ + return tmp; + } + else + { + /*--------------------------------------------------------*\ + ! If the requested block size exceeds the information left ! + ! in the bitstream, set the bitstream error flag and ! + ! return a NULL pointer. ! + \*--------------------------------------------------------*/ + stream->error |= 1; + return NULL; + } } /*----------------------------------------------------------------------------------------------------------*\ @@ -652,7 +652,7 @@ bwc_get_chunck(bwc_stream *const stream, const uint64 size) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! stream bwc_stream* - Structure used to assemble a bwc bit- ! +! stream bitstream* - Structure used to assemble a bwc bit- ! ! bitstream. ! ! ! ! size unsigned int(8 bit) - Number of significant bytes in the ! @@ -673,53 +673,53 @@ bwc_get_chunck(bwc_stream *const stream, const uint64 size) ! ! \*----------------------------------------------------------------------------------------------------------*/ uint64 -bwc_get_symbol(bwc_stream *const stream, const uint8 size) +get_symbol(bitstream *const stream, const uint8 size) { - /*-----------------------*\ - ! DEFINE INT VARIABLES: ! - \*-----------------------*/ - uint64 symbol; - uint8 byte; - int8 i; + /*-----------------------*\ + ! DEFINE INT VARIABLES: ! + \*-----------------------*/ + uint64 symbol; + uint8 byte; + int8 i; - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(stream); - - /*--------------------------------------------------------*\ - ! Check if the number of bytes to be read from the stream ! - ! does not exceed the number of bytes still present in its ! - ! memory block. ! - \*--------------------------------------------------------*/ - if(bytes_used(stream) + size <= stream->Lmax) - { - /*--------------------------------------------------------*\ - ! Extract the requested information from the bitstream one ! - ! byte at a time. Adjust the number of bytes read from the ! - ! stream accordingly. ! - \*--------------------------------------------------------*/ - for(i = size, symbol = 0; i --> 0;) - { - byte = (uint8)stream->memory[stream->L++]; - symbol |= ((uint64)byte << (i * 8)); - } + /*-----------------------*\ + ! DEFINE ASSERTIONS: ! + \*-----------------------*/ + assert(stream); + + /*--------------------------------------------------------*\ + ! Check if the number of bytes to be read from the stream ! + ! does not exceed the number of bytes still present in its ! + ! memory block. ! + \*--------------------------------------------------------*/ + if(bytes_used(stream) + size <= stream->Lmax) + { + /*--------------------------------------------------------*\ + ! Extract the requested information from the bitstream one ! + ! byte at a time. Adjust the number of bytes read from the ! + ! stream accordingly. ! + \*--------------------------------------------------------*/ + for(i = size, symbol = 0; i --> 0;) + { + byte = (uint8)stream->memory[stream->L++]; + symbol |= ((uint64)byte << (i * 8)); + } - /*--------------------------------------------------------*\ - ! Return the symbol to the function caller. ! - \*--------------------------------------------------------*/ - return symbol; - } - else - { - /*--------------------------------------------------------*\ - ! If the requested block size exceeds the information left ! - ! in the bitstream, set the bitstream error flag and ! - ! return zero. ! - \*--------------------------------------------------------*/ - stream->error |= 1; - return 0; - } + /*--------------------------------------------------------*\ + ! Return the symbol to the function caller. ! + \*--------------------------------------------------------*/ + return symbol; + } + else + { + /*--------------------------------------------------------*\ + ! If the requested block size exceeds the information left ! + ! in the bitstream, set the bitstream error flag and ! + ! return zero. ! + \*--------------------------------------------------------*/ + stream->error |= 1; + return 0; + } } /*----------------------------------------------------------------------------------------------------------*\ @@ -751,31 +751,31 @@ bwc_get_symbol(bwc_stream *const stream, const uint8 size) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -bwc_get_bit(bwc_stream *const stream) +get_bit(bitstream *const stream) { - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(stream); + /*-----------------------*\ + ! DEFINE ASSERTIONS: ! + \*-----------------------*/ + assert(stream); - if(!stream->t) - { - if(stream->L == stream->Lmax) - { - return 1; - } - if(stream->T == 0xFF) - { - stream->t = 7; - } - else - { - stream->t = 8; - } - stream->T = (uint16)stream->memory[stream->L++]; - } - stream->t--; - return ((stream->T & (1 << stream->t)) >> stream->t); + if(!stream->t) + { + if(stream->L == stream->Lmax) + { + return 1; + } + if(stream->T == 0xFF) + { + stream->t = 7; + } + else + { + stream->t = 8; + } + stream->T = (uint16)stream->memory[stream->L++]; + } + stream->t--; + return ((stream->T & (1 << stream->t)) >> stream->t); } /*----------------------------------------------------------------------------------------------------------*\ @@ -807,64 +807,64 @@ bwc_get_bit(bwc_stream *const stream) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -flush_stream(bwc_stream *const stream) +flush_stream(bitstream *const stream) { - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(stream); + /*-----------------------*\ + ! DEFINE ASSERTIONS: ! + \*-----------------------*/ + assert(stream); - /*--------------------------------------------------------*\ - ! Check the if the bit buffer contains information. ! - \*--------------------------------------------------------*/ - if(stream->t != 8) - { + /*--------------------------------------------------------*\ + ! Check the if the bit buffer contains information. ! + \*--------------------------------------------------------*/ + if(stream->t != 8) + { + /*--------------------------------------------------------*\ + ! Check if the enough memory has been allocated for the ! + ! stream to store the additional byte. ! + \*--------------------------------------------------------*/ + if((bytes_used(stream) + 1) > stream->Lmax) + { /*--------------------------------------------------------*\ - ! Check if the enough memory has been allocated for the ! - ! stream to store the additional byte. ! + ! If the stream is not large enough, check if this is due ! + ! to an error encountered in a previous writing operation ! \*--------------------------------------------------------*/ - if((bytes_used(stream) + 1) > stream->Lmax) + if(!stream->error) { - /*--------------------------------------------------------*\ - ! If the stream is not large enough, check if this is due ! - ! to an error encountered in a previous writing operation ! - \*--------------------------------------------------------*/ - if(!stream->error) - { - /*--------------------------------------------------------*\ - ! If the error flag is not set, increment the stream size ! - ! to store the additional byte. ! - \*--------------------------------------------------------*/ - stream->Lmax += stream->size_incr; - stream->size_incr = (uint64)(stream->Lmax / 2); + /*--------------------------------------------------------*\ + ! If the error flag is not set, increment the stream size ! + ! to store the additional byte. ! + \*--------------------------------------------------------*/ + stream->Lmax += stream->size_incr; + stream->size_incr = (uint64)(stream->Lmax / 2); - /*--------------------------------------------------------*\ - ! Reallocate the stream data block. ! - \*--------------------------------------------------------*/ - stream->memory = realloc(stream->memory, stream->Lmax); - if(!stream->memory) - { - // memory allocation error - stream->error |= 1; - stream->Lmax = 0; - return; - } - } - else - { - /*--------------------------------------------------------*\ - ! Exit to function caller if error flag has been set. ! - \*--------------------------------------------------------*/ - return; - } + /*--------------------------------------------------------*\ + ! Reallocate the stream data block. ! + \*--------------------------------------------------------*/ + stream->memory = realloc(stream->memory, stream->Lmax); + if(!stream->memory) + { + // memory allocation error + stream->error |= 1; + stream->Lmax = 0; + return; + } } + else + { + /*--------------------------------------------------------*\ + ! Exit to function caller if error flag has been set. ! + \*--------------------------------------------------------*/ + return; + } + } - /*--------------------------------------------------------*\ - ! Copy the additional byte to the stream memory block and ! - ! increment the number of bytes written to the stream. ! - \*--------------------------------------------------------*/ - stream->memory[stream->L++] = (uchar)stream->T; - } + /*--------------------------------------------------------*\ + ! Copy the additional byte to the stream memory block and ! + ! increment the number of bytes written to the stream. ! + \*--------------------------------------------------------*/ + stream->memory[stream->L++] = (uchar)stream->T; + } } /*----------------------------------------------------------------------------------------------------------*\ @@ -896,48 +896,48 @@ flush_stream(bwc_stream *const stream) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -bwc_terminate_stream(bwc_stream *stream, bwc_packed_stream *const packed_stream) +terminate_stream(bitstream *stream, bwc_stream *const packed_stream) { - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(stream); + /*-----------------------*\ + ! DEFINE ASSERTIONS: ! + \*-----------------------*/ + assert(stream); - if(packed_stream) - { - if(stream->error) + if(packed_stream) + { + if(stream->error) + { + return 1; + } + else if(stream->L != stream->Lmax) + { + stream->Lmax = stream->L; + stream->memory = realloc(stream->memory, stream->Lmax); + if(!stream->memory) { - return 1; - } - else if(stream->L != stream->Lmax) - { - stream->Lmax = stream->L; - stream->memory = realloc(stream->memory, stream->Lmax); - if(!stream->memory) - { - // memory allocation error - fprintf(stderr, MEMERROR); - stream->Lmax = 0; - return 1; - } + // memory allocation error + fprintf(stderr, MEMERROR); + stream->Lmax = 0; + return 1; } + } - packed_stream->memory = stream->memory; - packed_stream->access = stream->memory; - packed_stream->size = stream->L; - packed_stream->position = 0; - } - else - { - free(stream->memory); - } - - free(stream); - return 0; + packed_stream->memory = stream->memory; + packed_stream->access = stream->memory; + packed_stream->size = stream->L; + packed_stream->position = 0; + } + else + { + free(stream->memory); + } + + free(stream); + return 0; } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void release_packed_stream(bwc_packed_stream *stream) ! +! FUNCTION NAME: void release_packed_stream(bwc_stream *stream) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -949,7 +949,7 @@ bwc_terminate_stream(bwc_stream *stream, bwc_packed_stream *const packed_stream) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! stream bwc_packed_stream - Packed bitstream used to store parts of ! +! stream bwc_stream - Packed bitstream used to store parts of ! ! the bwc codestream. ! ! ! ! RETURN VALUE: ! @@ -967,22 +967,22 @@ bwc_terminate_stream(bwc_stream *stream, bwc_packed_stream *const packed_stream) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -release_packed_stream(bwc_packed_stream *stream) +release_packed_stream(bwc_stream *stream) { - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(stream); + /*-----------------------*\ + ! DEFINE ASSERTIONS: ! + \*-----------------------*/ + assert(stream); - /*--------------------------------------------------------*\ - ! Free the data block of the packed bitstream. ! - \*--------------------------------------------------------*/ - free(stream->memory); + /*--------------------------------------------------------*\ + ! Free the data block of the packed bitstream. ! + \*--------------------------------------------------------*/ + free(stream->memory); - /*--------------------------------------------------------*\ - ! Reset all the packed stream parameters. ! - \*--------------------------------------------------------*/ - stream->access = NULL; - stream->position = 0; - stream->size = 0; + /*--------------------------------------------------------*\ + ! Reset all the packed stream parameters. ! + \*--------------------------------------------------------*/ + stream->access = NULL; + stream->position = 0; + stream->size = 0; } \ No newline at end of file diff --git a/src/library/codestream.c b/src/library/codestream.c index 55d6353..ca96310 100755 --- a/src/library/codestream.c +++ b/src/library/codestream.c @@ -56,6 +56,7 @@ #include #include "libbwc.h" +#include "bitstream.h" #include "codestream.h" #include "tier2.h" @@ -91,7 +92,7 @@ ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -can_read(bwc_stream *const stream, const uint64 length) +can_read(bitstream *const stream, const uint64 length) { /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -103,7 +104,7 @@ can_read(bwc_stream *const stream, const uint64 length) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void codestream_write_header(bwc_stream *const stream, bwc_field *const field) ! +! FUNCTION NAME: void codestream_write_header(bitstream *const stream, bwc_field *const field) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -118,7 +119,7 @@ can_read(bwc_stream *const stream, const uint64 length) ! field bwc_field* - Structure defining the compression/ ! ! decompression stage. ! ! ! -! stream bwc_stream* - Structure used to assemble a bwc bit- ! +! stream bitstream* - Structure used to assemble a bwc bit- ! ! bitstream. ! ! ! ! RETURN VALUE: ! @@ -136,7 +137,7 @@ can_read(bwc_stream *const stream, const uint64 length) ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -codestream_write_header(bwc_stream *const stream, bwc_field *const field) +codestream_write_header(bitstream *const stream, bwc_field *const field) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -175,14 +176,14 @@ codestream_write_header(bwc_stream *const stream, bwc_field *const field) ! Emit the portion of the main header already created by ! ! the bwc_create_compression function. ! \*--------------------------------------------------------*/ - bwc_emit_chunck(stream, control->header.memory, control->header.size); + emit_chunck(stream, control->header.memory, control->header.size); /*--------------------------------------------------------*\ ! Emit the end of header (EOH) marker and EOH marker seg- ! ! ment size Leoh. ! \*--------------------------------------------------------*/ - bwc_emit_symbol(stream, EOH, 2); - bwc_emit_symbol(stream, Leoh, 2); + emit_symbol(stream, EOH, 2); + emit_symbol(stream, Leoh, 2); /*--------------------------------------------------------*\ ! Loop through all tile parameters and... ! @@ -195,8 +196,8 @@ codestream_write_header(bwc_stream *const stream, bwc_field *const field) ! ...emit the maximum and minimum parameter value to the ! ! header stream. ! \*--------------------------------------------------------*/ - bwc_emit_symbol(stream, *(uint64 *)&field->tile[t].parameter[p].info.parameter_min, PREC_BYTE); - bwc_emit_symbol(stream, *(uint64 *)&field->tile[t].parameter[p].info.parameter_max, PREC_BYTE); + emit_symbol(stream, *(uint64 *)&field->tile[t].parameter[p].info.parameter_min, PREC_BYTE); + emit_symbol(stream, *(uint64 *)&field->tile[t].parameter[p].info.parameter_max, PREC_BYTE); /*--------------------------------------------------------*\ ! Reset the maximum and minimum parameter value in the ! @@ -442,7 +443,7 @@ sequence_packets(bwc_field *const field, bwc_tile *const tile) ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -assemble_tile(bwc_field *const field, bwc_tile *const tile, bwc_stream *const stream) +assemble_tile(bwc_field *const field, bwc_tile *const tile, bitstream *const stream) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -469,11 +470,11 @@ assemble_tile(bwc_field *const field, bwc_tile *const tile, bwc_stream *const st \*--------------------------------------------------------*/ control = &field->control; - bwc_emit_symbol(stream, SOT, 2); - bwc_emit_symbol(stream, 14, 2); - bwc_emit_symbol(stream, tile->info.tile_index, 4); - bwc_emit_symbol(stream, tile->control.body_size, 8); - bwc_emit_symbol(stream, SOD, 2); + emit_symbol(stream, SOT, 2); + emit_symbol(stream, 14, 2); + emit_symbol(stream, tile->info.tile_index, 4); + emit_symbol(stream, tile->control.body_size, 8); + emit_symbol(stream, SOD, 2); for(packet_index = 0; packet_index < tile->control.nPackets; ++packet_index) { @@ -481,18 +482,18 @@ assemble_tile(bwc_field *const field, bwc_tile *const tile, bwc_stream *const st if(control->error_resilience) { - bwc_emit_symbol(stream, SOP, 2); - bwc_emit_symbol(stream, 4, 2); - bwc_emit_symbol(stream, packet_index % 0x100000000, 4); + emit_symbol(stream, SOP, 2); + emit_symbol(stream, 4, 2); + emit_symbol(stream, packet_index % 0x100000000, 4); } if(packet->header.memory) { - bwc_emit_chunck(stream, packet->header.memory, packet->header.size); + emit_chunck(stream, packet->header.memory, packet->header.size); if(control->error_resilience) { - bwc_emit_symbol(stream, EPH, 2); + emit_symbol(stream, EPH, 2); } release_packed_stream(&packet->header); @@ -500,13 +501,482 @@ assemble_tile(bwc_field *const field, bwc_tile *const tile, bwc_stream *const st if(packet->body.memory) { - bwc_emit_chunck(stream, packet->body.memory, packet->body.size); + emit_chunck(stream, packet->body.memory, packet->body.size); release_packed_stream(&packet->body); } } } +/*----------------------------------------------------------------------------------------------------------*\ +! FUNCTION NAME: void *test(void) ! +! -------------- ! +! ! +! DESCRIPTION: ! +! ------------ ! +! DESCRIPTION NEEDED ! +! ! +! PARAMETERS: ! +! ----------- ! +! Variable Type Description ! +! -------- ---- ----------- ! +! - - - ! +! ! +! RETURN VALUE: ! +! ------------- ! +! Type Description ! +! ---- ----------- ! +! - - ! +! ! +! DEVELOPMENT HISTORY: ! +! -------------------- ! +! ! +! Date Author Change Id Release Description Of Change ! +! ---- ------ --------- ------- --------------------- ! +! - Patrick Vogler B87D120 V 0.1.0 function created ! +! ! +\*----------------------------------------------------------------------------------------------------------*/ +bwc_field* +parse_main_header(bwc_data *const data,bitstream *const stream) +{ + /*-----------------------*\ + ! DEFINE INT VARIABLES: ! + \*-----------------------*/ + uint64 buff_long, buffX, buffY, buffZ, buffTS; + uint64 nX, nY, nZ; + uint32 buff; + uint32 bitrate; + uint32 Lsax; + uint32 mantissa, exponent; + uint32 t; + uint16 CSsgc; + uint16 Linf, Lctr, Lcom, Leoh, Lunk; + uint16 marker; + uint16 nTS; + uint8 dim; + uint8 index, l; + uint8 samp; + uint8 nPar, p; + uint8 codec_prec, precision; + + /*-----------------------*\ + ! DEFINE CHAR VARIABLES: ! + \*-----------------------*/ + char* buffer_char; + char status; + + /*-----------------------*\ + ! DEFINE STRUCTS: ! + \*-----------------------*/ + bwc_field *field; + bwc_gl_ctrl *control; + bwc_gl_inf *info; + + /*-----------------------*\ + ! DEFINE ASSERTIONS: ! + \*-----------------------*/ + assert(data); + assert(stream); + + /*--------------------------------------------------------*\ + ! Save the data info structure to a temporary variable to ! + ! make the code more readable. ! + \*--------------------------------------------------------*/ + info = &data->info; + + status = CODESTREAM_OK; + index = 0; + + while(!(status & CODESTREAM_ERROR) && can_read(stream, 2)) + { + marker = (uint16)get_symbol(stream, 2); + if(marker < 0xFF00) + { + // Invalid Codestream + fprintf(stderr, CSERROR); + status |= CODESTREAM_ERROR; + } + + switch(marker) + { + case SOC: + { + if(index != 0) + { + // Invalid Codestream + fprintf(stderr, CSERROR); + status |= CODESTREAM_ERROR; + } + break; + } + + case SGI: + { + if(index != 1 && !can_read(stream, 2)) + { + // Invalid Codestream + fprintf(stderr, CSERROR); + status |= CODESTREAM_ERROR; + break; + } + + Linf = (uint16)get_symbol(stream, 2); + if(!can_read(stream, Linf - 2)) + { + // Invalid Codestream + fprintf(stderr, CSERROR); + status |= CODESTREAM_ERROR; + break; + } + + info->nX = nX = get_symbol(stream, 8); + info->nY = nY = get_symbol(stream, 8); + info->nZ = nZ = get_symbol(stream, 8); + info->nTS = nTS = (uint16)get_symbol(stream, 2); + info->nPar = nPar = (uint8)get_symbol(stream, 1); + info->precision = codec_prec = (uint8)get_symbol(stream, 1); + + buffer_char = (char*)get_chunck(stream, 10); + strncpy(info->f_ext, buffer_char, sizeof(buffer_char)/sizeof(*buffer_char)); + free(buffer_char); + + for(p = 0; p < nPar; ++p) + { + buffer_char = (char*)get_chunck(stream, 24); + precision = (uint8)get_symbol(stream, 1); + + bwc_add_param(data, buffer_char, precision); + + free(buffer_char); + } + + field = bwc_initialize_field(data); + if(!field) + { + status |= CODESTREAM_ERROR; + break; + } + + /*--------------------------------------------------------*\ + ! Save the global control and info structure to temporary ! + ! variables to make the code more readable. ! + \*--------------------------------------------------------*/ + info = field->info = &data->info; + control = &field->control; + + status |= CODESTREAM_SGI_READ; + break; + } + + case SGC: + { + if(index != 2 && !can_read(stream, 2)) + { + // Invalid Codestream + fprintf(stderr, CSERROR); + bwc_kill_compression(field); + status |= CODESTREAM_ERROR; + break; + } + + Lctr = (uint16)get_symbol(stream, 2); + + if(!can_read(stream, Lctr - 2)) + { + // Invalid Codestream + fprintf(stderr, CSERROR); + bwc_kill_compression(field); + status |= CODESTREAM_ERROR; + break; + } + + CSsgc = (uint16)get_symbol(stream, 2); + + + buff_long = get_symbol(stream, 1); + if(CSsgc & (0x01 << 0)) + { + bwc_set_error_resilience(field); + } + + buff_long = get_symbol(stream, 1); + + if(CSsgc & (0x01 << 1)) + { + bwc_set_quant_style(field, (bwc_quant_st)buff_long); + } + + buff_long = get_symbol(stream, 1); + + exponent = (uint32)get_symbol(stream, 1); + mantissa = (uint32)get_symbol(stream, 2); + if(CSsgc & (0x01 << 2)) + { + control->qt_exponent = exponent; + control->qt_mantissa = mantissa; + } + + buff_long = get_symbol(stream, 1); + if(CSsgc & (0x01 << 3)) + { + bwc_set_progression(field, (uint8)buff_long); + } + + buff_long = get_symbol(stream, 1); + if(CSsgc & (0x01 << 4)) + { + bwc_set_kernels(field, (uint8)(0x03 & (buff_long >> 6)), (uint8)(0x03 & (buff_long >> 4)), + (uint8)(0x03 & (buff_long >> 2)), (uint8)(0x03 & buff_long)); + } + + buff_long = get_symbol(stream, 4); + if(CSsgc & (0x01 << 5)) + { + bwc_set_decomp(field, (uint8)(0xFF & (buff_long >> 24)), (uint8)(0xFF & (buff_long >> 16)), + (uint8)(0xFF & (buff_long >> 8)), (uint8)(0xFF & buff_long)); + } + + buff_long = get_symbol(stream, 2); + if(CSsgc & (0x01 << 6)) + { + bwc_set_precincts(field, (uint8)(0x0F & (buff_long >> 8)), (uint8)(0x0F & (buff_long >> 12)), + (uint8)(0x0F & buff_long), (uint8)(0x0F & (buff_long >> 4))); + } + + buff_long = get_symbol(stream, 4); + if(CSsgc & (0x01 << 7)) + { + bwc_set_codeblocks(field, (uint8)(0xFF & (buff_long >> 24)), (uint8)(0xFF & (buff_long >> 16)), + (uint8)(0xFF & (buff_long >> 8)), (uint8)(0xFF & buff_long)); + } + + buff_long = get_symbol(stream, 1); + if(CSsgc & (0x01 << 8)) + { + bwc_set_qm(field, (uint8)buff_long); + } + + buffX = get_symbol(stream, 8); + buffY = get_symbol(stream, 8); + buffZ = get_symbol(stream, 8); + buffTS = get_symbol(stream, 2); + if(CSsgc & (0x01 << 9)) + { + bwc_set_tiles(field, buffX, buffY, buffZ, (uint16)buffTS, bwc_tile_sizeof); + } + + control->nLayers = get_symbol(stream, 1); + control->bitrate = calloc(control->nLayers, sizeof(float)); + if(!control->bitrate) + { + // memory allocation error + fprintf(stderr, MEMERROR); + bwc_kill_compression(field); + status|= CODESTREAM_ERROR; + break; + } + + for(l = 0; l < control->nLayers; ++l) + { + bitrate = (uint32)get_symbol(stream, 4); + control->bitrate[l] = *(float *)&bitrate; + } + + create_field(field); + if(!field) + { + bwc_kill_compression(field); + status |= CODESTREAM_ERROR; + break; + } + + status |= CODESTREAM_SGC_READ; + break; + } + + case SAX: + { + if(index <= 2 && !can_read(stream, 4)) + { + // Invalid Codestream + fprintf(stderr, CSERROR); + bwc_kill_compression(field); + status |= CODESTREAM_ERROR; + break; + } + + Lsax = (uint32)get_symbol(stream, 4); + if(!can_read(stream, Lsax - 4)) + { + // Invalid Codestream + fprintf(stderr, CSERROR); + bwc_kill_compression(field); + status |= CODESTREAM_ERROR; + break; + } + + data->codestream.aux = calloc(1, sizeof(bwc_stream)); + if(!data->codestream.aux) + { + // memory allocation error + fprintf(stderr, MEMERROR); + bwc_kill_compression(field); + status |= CODESTREAM_ERROR; + break; + } + + data->codestream.aux->memory = get_chunck(stream, Lsax - 4); + data->codestream.aux->size = Lsax - 4; + + status |= CODESTREAM_SAX_READ; + break; + } + + case COM: + { + if(index <= 2 && !can_read(stream, 2)) + { + // Invalid Codestream + fprintf(stderr, CSERROR); + bwc_kill_compression(field); + status |= CODESTREAM_ERROR; + break; + } + + Lcom = (uint16)get_symbol(stream, 2); + if(!can_read(stream, Lcom - 2)) + { + // Invalid Codestream + fprintf(stderr, CSERROR); + bwc_kill_compression(field); + status |= CODESTREAM_ERROR; + break; + } + + data->codestream.com = calloc(1, sizeof(bwc_stream)); + if(!data->codestream.com) + { + // memory allocation error + fprintf(stderr, MEMERROR); + bwc_kill_compression(field); + status |= CODESTREAM_ERROR; + break; + } + + data->codestream.com->memory = get_chunck(stream, Lcom - 2); + data->codestream.com->size = Lcom -2; + + status |= CODESTREAM_ERROR; + break; + } + + case EOH: + { + if((status & CODESTREAM_SGI_READ) && (status & CODESTREAM_SGC_READ)) + { + if(index <= 2 && !can_read(stream, 2)) + { + // Invalid Codestream + fprintf(stderr, CSERROR); + bwc_kill_compression(field); + status |= CODESTREAM_ERROR; + break; + } + + Leoh = (uint16)get_symbol(stream, 2); + if(!can_read(stream, Leoh - 2)) + { + // Invalid Codestream + fprintf(stderr, CSERROR); + bwc_kill_compression(field); + status |= CODESTREAM_ERROR; + break; + } + + if(codec_prec == 8) + { + /*--------------------------------------------------------*\ + ! Loop through all tile parameters and... ! + \*--------------------------------------------------------*/ + for(t = 0; t < control->nTiles; ++t) + { + for(p = 0; p < info->nPar; ++p) + { + /*--------------------------------------------------------*\ + ! ...get the maximum and minimum parameter value to the ! + ! header stream. ! + \*--------------------------------------------------------*/ + buff_long = get_symbol(stream, sizeof(double)); + field->tile[t].parameter[p].info.parameter_min = (bwc_float)*(double*)&buff_long; + + buff_long = get_symbol(stream, sizeof(double)); + field->tile[t].parameter[p].info.parameter_max = (bwc_float)*(double*)&buff_long; + } + } + } + else if(codec_prec == 4) + { + /*--------------------------------------------------------*\ + ! Loop through all tile parameters and... ! + \*--------------------------------------------------------*/ + for(t = 0; t < control->nTiles; ++t) + { + for(p = 0; p < info->nPar; ++p) + { + /*--------------------------------------------------------*\ + ! ...get the maximum and minimum parameter value to the ! + ! header stream. ! + \*--------------------------------------------------------*/ + buff = get_symbol(stream, sizeof(float)); + field->tile[t].parameter[p].info.parameter_min = (bwc_float)*(float*)&buff; + + buff = get_symbol(stream, sizeof(float)); + field->tile[t].parameter[p].info.parameter_max = (bwc_float)*(float*)&buff; + } + } + } + return field; + } + else + { + // Invalid Codestream + fprintf(stderr, CSERROR); + bwc_kill_compression(field); + status |= CODESTREAM_ERROR; + } + break; + } + + default: + { + if(!can_read(stream, 2)) + { + // Invalid Codestream + fprintf(stderr, CSERROR); + bwc_kill_compression(field); + status |= CODESTREAM_ERROR; + break; + } + + Lunk = (uint16)get_symbol(stream, 2); + if(!can_read(stream, Lcom - 2)) + { + // Invalid Codestream + fprintf(stderr, CSERROR); + bwc_kill_compression(field); + status |= CODESTREAM_ERROR; + break; + } + + stream->L += Lunk - 2; + break; + } + } + index++; + } + return NULL; +} + /*----------------------------------------------------------------------------------------------------------*\ ! FUNCTION NAME: uchar sequence_packets(bwc_field *const field, bwc_field *const field) ! ! -------------- ! @@ -539,7 +1009,7 @@ assemble_tile(bwc_field *const field, bwc_tile *const tile, bwc_stream *const st ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -parse_tile(bwc_field *const field, bwc_stream *const stream) +parse_tile(bwc_field *const field, bitstream *const stream) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -576,7 +1046,7 @@ parse_tile(bwc_field *const field, bwc_stream *const stream) return 1; } - L = (uint16)bwc_get_symbol(stream, 2); + L = (uint16)get_symbol(stream, 2); if(!can_read(stream, L - 2)) { @@ -585,7 +1055,7 @@ parse_tile(bwc_field *const field, bwc_stream *const stream) return 1; } - buf = (uint32)bwc_get_symbol(stream, 4); + buf = (uint32)get_symbol(stream, 4); if(buf >= control->nTiles) { // Invalid Codestream @@ -595,9 +1065,9 @@ parse_tile(bwc_field *const field, bwc_stream *const stream) tile = &field->tile[buf]; tile->control.body_size = - body_size = (uint64)bwc_get_symbol(stream, 8); + body_size = (uint64)get_symbol(stream, 8); - if(SOD != (uint16)bwc_get_symbol(stream, 2)) + if(SOD != (uint16)get_symbol(stream, 2)) { // Invalid Codestream fprintf(stderr, CSERROR); @@ -618,7 +1088,7 @@ parse_tile(bwc_field *const field, bwc_stream *const stream) while((body_size != 0) && can_read(stream, body_size) && packet_index < tile->control.nPackets) { - if(SOP == (uint16)bwc_get_symbol(stream, 2)) + if(SOP == (uint16)get_symbol(stream, 2)) { if(!can_read(stream, 6)) { @@ -627,14 +1097,14 @@ parse_tile(bwc_field *const field, bwc_stream *const stream) return 1; } - if(4 != (uint16)bwc_get_symbol(stream, 2)) + if(4 != (uint16)get_symbol(stream, 2)) { //Invalid Codestream fprintf(stderr, CSERROR); return 1; } - buf = (uint32)bwc_get_symbol(stream, 4); + buf = (uint32)get_symbol(stream, 4); body_size -= 8; } @@ -689,7 +1159,7 @@ parse_tile(bwc_field *const field, bwc_stream *const stream) ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -parse_body(bwc_field *const field, bwc_stream *const stream) +parse_body(bwc_field *const field, bitstream *const stream) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -711,7 +1181,7 @@ parse_body(bwc_field *const field, bwc_stream *const stream) while(!(status & CODESTREAM_ERROR) && can_read(stream, 2)) { - marker = (uint16)bwc_get_symbol(stream, 2); + marker = (uint16)get_symbol(stream, 2); if(marker < 0xFF00) { // Invalid Codestream @@ -761,7 +1231,7 @@ parse_body(bwc_field *const field, bwc_stream *const stream) break; } - Lunk = (uint16)bwc_get_symbol(stream, 2); + Lunk = (uint16)get_symbol(stream, 2); if(!can_read(stream, Lunk - 2)) { // Invalid Codestream @@ -829,7 +1299,7 @@ assemble_main_header(bwc_field *const field) bwc_gl_inf *info; bwc_tile *tile; bwc_parameter *parameter; - bwc_stream *stream; + bitstream *stream; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -853,75 +1323,75 @@ assemble_main_header(bwc_field *const field) size = 6 + Linf + Lctr; - stream = bwc_init_stream(NULL, size, 'c'); + stream = init_stream(NULL, size, 'c'); if(!stream) { // memory allocation error return 1; } - bwc_emit_symbol(stream, SOC, 2); - bwc_emit_symbol(stream, SGI, 2); - bwc_emit_symbol(stream, Linf, 2); - bwc_emit_symbol(stream, info->nX, 8); - bwc_emit_symbol(stream, info->nY, 8); - bwc_emit_symbol(stream, info->nZ, 8); - bwc_emit_symbol(stream, info->nTS, 2); - bwc_emit_symbol(stream, info->nPar, 1); - bwc_emit_symbol(stream, info->precision, 1); - bwc_emit_chunck(stream, (uchar*)info->f_ext, 10); + emit_symbol(stream, SOC, 2); + emit_symbol(stream, SGI, 2); + emit_symbol(stream, Linf, 2); + emit_symbol(stream, info->nX, 8); + emit_symbol(stream, info->nY, 8); + emit_symbol(stream, info->nZ, 8); + emit_symbol(stream, info->nTS, 2); + emit_symbol(stream, info->nPar, 1); + emit_symbol(stream, info->precision, 1); + emit_chunck(stream, (uchar*)info->f_ext, 10); for(p = 0; p < info->nPar; ++p) { - bwc_emit_chunck(stream, (uchar*)parameter[p].info.name, 24); - bwc_emit_symbol(stream, parameter[p].info.precision, 1); + emit_chunck(stream, (uchar*)parameter[p].info.name, 24); + emit_symbol(stream, parameter[p].info.precision, 1); } - bwc_emit_symbol(stream, SGC, 2); - bwc_emit_symbol(stream, Lctr, 2); + emit_symbol(stream, SGC, 2); + emit_symbol(stream, Lctr, 2); - bwc_emit_symbol(stream, control->CSsgc, 2); + emit_symbol(stream, control->CSsgc, 2); - bwc_emit_symbol(stream, control->error_resilience, 1); + emit_symbol(stream, control->error_resilience, 1); - bwc_emit_symbol(stream, control->quantization_style, 1); - bwc_emit_symbol(stream, control->guard_bits, 1); + emit_symbol(stream, control->quantization_style, 1); + emit_symbol(stream, control->guard_bits, 1); - bwc_emit_symbol(stream, control->qt_exponent, 1); - bwc_emit_symbol(stream, control->qt_mantissa, 2); + emit_symbol(stream, control->qt_exponent, 1); + emit_symbol(stream, control->qt_mantissa, 2); - bwc_emit_symbol(stream, control->progression, 1); - bwc_emit_symbol(stream, control->KernelX << 6 | control->KernelY << 4 | - control->KernelZ << 2 | control->KernelTS, 1); + emit_symbol(stream, control->progression, 1); + emit_symbol(stream, control->KernelX << 6 | control->KernelY << 4 | + control->KernelZ << 2 | control->KernelTS, 1); - bwc_emit_symbol(stream, control->decompX, 1); - bwc_emit_symbol(stream, control->decompY, 1); - bwc_emit_symbol(stream, control->decompZ, 1); - bwc_emit_symbol(stream, control->decompTS, 1); + emit_symbol(stream, control->decompX, 1); + emit_symbol(stream, control->decompY, 1); + emit_symbol(stream, control->decompZ, 1); + emit_symbol(stream, control->decompTS, 1); - bwc_emit_symbol(stream, control->precSizeY << 4 | control->precSizeX, 1); - bwc_emit_symbol(stream, control->precSizeTS << 4 | control->precSizeZ, 1); + emit_symbol(stream, control->precSizeY << 4 | control->precSizeX, 1); + emit_symbol(stream, control->precSizeTS << 4 | control->precSizeZ, 1); - bwc_emit_symbol(stream, control->cbX, 1); - bwc_emit_symbol(stream, control->cbY, 1); - bwc_emit_symbol(stream, control->cbZ, 1); - bwc_emit_symbol(stream, control->cbTS, 1); + emit_symbol(stream, control->cbX, 1); + emit_symbol(stream, control->cbY, 1); + emit_symbol(stream, control->cbZ, 1); + emit_symbol(stream, control->cbTS, 1); - bwc_emit_symbol(stream, control->Qm, 1); + emit_symbol(stream, control->Qm, 1); - bwc_emit_symbol(stream, control->tileSizeX, 8); - bwc_emit_symbol(stream, control->tileSizeY, 8); - bwc_emit_symbol(stream, control->tileSizeZ, 8); - bwc_emit_symbol(stream, control->tileSizeTS, 2); + emit_symbol(stream, control->tileSizeX, 8); + emit_symbol(stream, control->tileSizeY, 8); + emit_symbol(stream, control->tileSizeZ, 8); + emit_symbol(stream, control->tileSizeTS, 2); - bwc_emit_symbol(stream, control->nLayers, 1); + emit_symbol(stream, control->nLayers, 1); for(l = 0; l < control->nLayers; ++l) { - bwc_emit_symbol(stream, *(uint32 *)&control->bitrate[l], 4); + emit_symbol(stream, *(uint32 *)&control->bitrate[l], 4); } - if(bwc_terminate_stream(stream, &control->header)) + if(terminate_stream(stream, &control->header)) { // memory allocation error fprintf(stderr, MEMERROR); @@ -931,475 +1401,6 @@ assemble_main_header(bwc_field *const field) return 0; } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void *test(void) ! -! -------------- ! -! ! -! DESCRIPTION: ! -! ------------ ! -! DESCRIPTION NEEDED ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! - - - ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! - Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ -bwc_field* -bwc_parse_main_header(bwc_data *const data,bwc_stream *const stream) -{ - /*-----------------------*\ - ! DEFINE INT VARIABLES: ! - \*-----------------------*/ - uint64 buff_long, buffX, buffY, buffZ, buffTS; - uint64 nX, nY, nZ; - uint32 buff; - uint32 bitrate; - uint32 Lsax; - uint32 mantissa, exponent; - uint32 t; - uint16 CSsgc; - uint16 Linf, Lctr, Lcom, Leoh, Lunk; - uint16 marker; - uint16 nTS; - uint8 dim; - uint8 index, l; - uint8 samp; - uint8 nPar, p; - uint8 codec_prec, precision; - - /*-----------------------*\ - ! DEFINE CHAR VARIABLES: ! - \*-----------------------*/ - char* buffer_char; - char status; - - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - bwc_field *field; - bwc_gl_ctrl *control; - bwc_gl_inf *info; - - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(data); - assert(stream); - - /*--------------------------------------------------------*\ - ! Save the data info structure to a temporary variable to ! - ! make the code more readable. ! - \*--------------------------------------------------------*/ - info = &data->info; - - status = CODESTREAM_OK; - index = 0; - - while(!(status & CODESTREAM_ERROR) && can_read(stream, 2)) - { - marker = (uint16)bwc_get_symbol(stream, 2); - if(marker < 0xFF00) - { - // Invalid Codestream - fprintf(stderr, CSERROR); - status |= CODESTREAM_ERROR; - } - - switch(marker) - { - case SOC: - { - if(index != 0) - { - // Invalid Codestream - fprintf(stderr, CSERROR); - status |= CODESTREAM_ERROR; - } - break; - } - - case SGI: - { - if(index != 1 && !can_read(stream, 2)) - { - // Invalid Codestream - fprintf(stderr, CSERROR); - status |= CODESTREAM_ERROR; - break; - } - - Linf = (uint16)bwc_get_symbol(stream, 2); - if(!can_read(stream, Linf - 2)) - { - // Invalid Codestream - fprintf(stderr, CSERROR); - status |= CODESTREAM_ERROR; - break; - } - - info->nX = nX = bwc_get_symbol(stream, 8); - info->nY = nY = bwc_get_symbol(stream, 8); - info->nZ = nZ = bwc_get_symbol(stream, 8); - info->nTS = nTS = (uint16)bwc_get_symbol(stream, 2); - info->nPar = nPar = (uint8)bwc_get_symbol(stream, 1); - info->precision = codec_prec = (uint8)bwc_get_symbol(stream, 1); - - buffer_char = (char*)bwc_get_chunck(stream, 10); - strncpy(info->f_ext, buffer_char, sizeof(buffer_char)/sizeof(*buffer_char)); - free(buffer_char); - - for(p = 0; p < nPar; ++p) - { - buffer_char = (char*)bwc_get_chunck(stream, 24); - precision = (uint8)bwc_get_symbol(stream, 1); - - bwc_add_param(data, buffer_char, precision); - - free(buffer_char); - } - - field = bwc_initialize_field(data); - if(!field) - { - status |= CODESTREAM_ERROR; - break; - } - - /*--------------------------------------------------------*\ - ! Save the global control and info structure to temporary ! - ! variables to make the code more readable. ! - \*--------------------------------------------------------*/ - info = field->info = &data->info; - control = &field->control; - - status |= CODESTREAM_SGI_READ; - break; - } - - case SGC: - { - if(index != 2 && !can_read(stream, 2)) - { - // Invalid Codestream - fprintf(stderr, CSERROR); - bwc_kill_compression(field); - status |= CODESTREAM_ERROR; - break; - } - - Lctr = (uint16)bwc_get_symbol(stream, 2); - - if(!can_read(stream, Lctr - 2)) - { - // Invalid Codestream - fprintf(stderr, CSERROR); - bwc_kill_compression(field); - status |= CODESTREAM_ERROR; - break; - } - - CSsgc = (uint16)bwc_get_symbol(stream, 2); - - - buff_long = bwc_get_symbol(stream, 1); - if(CSsgc & (0x01 << 0)) - { - bwc_set_error_resilience(field); - } - - buff_long = bwc_get_symbol(stream, 1); - - if(CSsgc & (0x01 << 1)) - { - bwc_set_quant_style(field, (bwc_quant_st)buff_long); - } - - buff_long = bwc_get_symbol(stream, 1); - - exponent = (uint32)bwc_get_symbol(stream, 1); - mantissa = (uint32)bwc_get_symbol(stream, 2); - if(CSsgc & (0x01 << 2)) - { - control->qt_exponent = exponent; - control->qt_mantissa = mantissa; - } - - buff_long = bwc_get_symbol(stream, 1); - if(CSsgc & (0x01 << 3)) - { - bwc_set_progression(field, (uint8)buff_long); - } - - buff_long = bwc_get_symbol(stream, 1); - if(CSsgc & (0x01 << 4)) - { - bwc_set_kernels(field, (uint8)(0x03 & (buff_long >> 6)), (uint8)(0x03 & (buff_long >> 4)), - (uint8)(0x03 & (buff_long >> 2)), (uint8)(0x03 & buff_long)); - } - - buff_long = bwc_get_symbol(stream, 4); - if(CSsgc & (0x01 << 5)) - { - bwc_set_decomp(field, (uint8)(0xFF & (buff_long >> 24)), (uint8)(0xFF & (buff_long >> 16)), - (uint8)(0xFF & (buff_long >> 8)), (uint8)(0xFF & buff_long)); - } - - buff_long = bwc_get_symbol(stream, 2); - if(CSsgc & (0x01 << 6)) - { - bwc_set_precincts(field, (uint8)(0x0F & (buff_long >> 8)), (uint8)(0x0F & (buff_long >> 12)), - (uint8)(0x0F & buff_long), (uint8)(0x0F & (buff_long >> 4))); - } - - buff_long = bwc_get_symbol(stream, 4); - if(CSsgc & (0x01 << 7)) - { - bwc_set_codeblocks(field, (uint8)(0xFF & (buff_long >> 24)), (uint8)(0xFF & (buff_long >> 16)), - (uint8)(0xFF & (buff_long >> 8)), (uint8)(0xFF & buff_long)); - } - - buff_long = bwc_get_symbol(stream, 1); - if(CSsgc & (0x01 << 8)) - { - bwc_set_qm(field, (uint8)buff_long); - } - - buffX = bwc_get_symbol(stream, 8); - buffY = bwc_get_symbol(stream, 8); - buffZ = bwc_get_symbol(stream, 8); - buffTS = bwc_get_symbol(stream, 2); - if(CSsgc & (0x01 << 9)) - { - bwc_set_tiles(field, buffX, buffY, buffZ, (uint16)buffTS, bwc_tile_sizeof); - } - - control->nLayers = bwc_get_symbol(stream, 1); - control->bitrate = calloc(control->nLayers, sizeof(float)); - if(!control->bitrate) - { - // memory allocation error - fprintf(stderr, MEMERROR); - bwc_kill_compression(field); - status|= CODESTREAM_ERROR; - break; - } - - for(l = 0; l < control->nLayers; ++l) - { - bitrate = (uint32)bwc_get_symbol(stream, 4); - control->bitrate[l] = *(float *)&bitrate; - } - - create_field(field); - if(!field) - { - bwc_kill_compression(field); - status |= CODESTREAM_ERROR; - break; - } - - status |= CODESTREAM_SGC_READ; - break; - } - - case SAX: - { - if(index <= 2 && !can_read(stream, 4)) - { - // Invalid Codestream - fprintf(stderr, CSERROR); - bwc_kill_compression(field); - status |= CODESTREAM_ERROR; - break; - } - - Lsax = (uint32)bwc_get_symbol(stream, 4); - if(!can_read(stream, Lsax - 4)) - { - // Invalid Codestream - fprintf(stderr, CSERROR); - bwc_kill_compression(field); - status |= CODESTREAM_ERROR; - break; - } - - data->codestream.aux = calloc(1, sizeof(bwc_packed_stream)); - if(!data->codestream.aux) - { - // memory allocation error - fprintf(stderr, MEMERROR); - bwc_kill_compression(field); - status |= CODESTREAM_ERROR; - break; - } - - data->codestream.aux->memory = bwc_get_chunck(stream, Lsax - 4); - data->codestream.aux->size = Lsax - 4; - - status |= CODESTREAM_SAX_READ; - break; - } - - case COM: - { - if(index <= 2 && !can_read(stream, 2)) - { - // Invalid Codestream - fprintf(stderr, CSERROR); - bwc_kill_compression(field); - status |= CODESTREAM_ERROR; - break; - } - - Lcom = (uint16)bwc_get_symbol(stream, 2); - if(!can_read(stream, Lcom - 2)) - { - // Invalid Codestream - fprintf(stderr, CSERROR); - bwc_kill_compression(field); - status |= CODESTREAM_ERROR; - break; - } - - data->codestream.com = calloc(1, sizeof(bwc_packed_stream)); - if(!data->codestream.com) - { - // memory allocation error - fprintf(stderr, MEMERROR); - bwc_kill_compression(field); - status |= CODESTREAM_ERROR; - break; - } - - data->codestream.com->memory = bwc_get_chunck(stream, Lcom - 2); - data->codestream.com->size = Lcom -2; - - status |= CODESTREAM_ERROR; - break; - } - - case EOH: - { - if((status & CODESTREAM_SGI_READ) && (status & CODESTREAM_SGC_READ)) - { - if(index <= 2 && !can_read(stream, 2)) - { - // Invalid Codestream - fprintf(stderr, CSERROR); - bwc_kill_compression(field); - status |= CODESTREAM_ERROR; - break; - } - - Leoh = (uint16)bwc_get_symbol(stream, 2); - if(!can_read(stream, Leoh - 2)) - { - // Invalid Codestream - fprintf(stderr, CSERROR); - bwc_kill_compression(field); - status |= CODESTREAM_ERROR; - break; - } - - if(codec_prec == 8) - { - /*--------------------------------------------------------*\ - ! Loop through all tile parameters and... ! - \*--------------------------------------------------------*/ - for(t = 0; t < control->nTiles; ++t) - { - for(p = 0; p < info->nPar; ++p) - { - /*--------------------------------------------------------*\ - ! ...get the maximum and minimum parameter value to the ! - ! header stream. ! - \*--------------------------------------------------------*/ - buff_long = bwc_get_symbol(stream, sizeof(double)); - field->tile[t].parameter[p].info.parameter_min = (bwc_float)*(double*)&buff_long; - - buff_long = bwc_get_symbol(stream, sizeof(double)); - field->tile[t].parameter[p].info.parameter_max = (bwc_float)*(double*)&buff_long; - } - } - } - else if(codec_prec == 4) - { - /*--------------------------------------------------------*\ - ! Loop through all tile parameters and... ! - \*--------------------------------------------------------*/ - for(t = 0; t < control->nTiles; ++t) - { - for(p = 0; p < info->nPar; ++p) - { - /*--------------------------------------------------------*\ - ! ...get the maximum and minimum parameter value to the ! - ! header stream. ! - \*--------------------------------------------------------*/ - buff = bwc_get_symbol(stream, sizeof(float)); - field->tile[t].parameter[p].info.parameter_min = (bwc_float)*(float*)&buff; - - buff = bwc_get_symbol(stream, sizeof(float)); - field->tile[t].parameter[p].info.parameter_max = (bwc_float)*(float*)&buff; - } - } - } - return field; - } - else - { - // Invalid Codestream - fprintf(stderr, CSERROR); - bwc_kill_compression(field); - status |= CODESTREAM_ERROR; - } - break; - } - - default: - { - if(!can_read(stream, 2)) - { - // Invalid Codestream - fprintf(stderr, CSERROR); - bwc_kill_compression(field); - status |= CODESTREAM_ERROR; - break; - } - - Lunk = (uint16)bwc_get_symbol(stream, 2); - if(!can_read(stream, Lcom - 2)) - { - // Invalid Codestream - fprintf(stderr, CSERROR); - bwc_kill_compression(field); - status |= CODESTREAM_ERROR; - break; - } - - stream->L += Lunk - 2; - break; - } - } - index++; - } - return NULL; -} - /*----------------------------------------------------------------------------------------------------------*\ ! FUNCTION NAME: void *test(void) ! ! -------------- ! @@ -1429,7 +1430,7 @@ bwc_parse_main_header(bwc_data *const data,bwc_stream *const stream) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -codestream_write_aux(bwc_packed_stream *const header, bwc_packed_stream *const aux) +codestream_write_aux(bwc_stream *const header, bwc_stream *const aux) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1439,7 +1440,7 @@ codestream_write_aux(bwc_packed_stream *const header, bwc_packed_stream *const a /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - bwc_stream *stream; + bitstream *stream; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -1447,7 +1448,7 @@ codestream_write_aux(bwc_packed_stream *const header, bwc_packed_stream *const a assert(header); assert(aux); - stream = bwc_init_stream(header->memory, header->size, 'c'); + stream = init_stream(header->memory, header->size, 'c'); if(!stream) { // memory allocation error @@ -1466,11 +1467,11 @@ codestream_write_aux(bwc_packed_stream *const header, bwc_packed_stream *const a return 1; } - bwc_emit_symbol(stream, SAX, 2); - bwc_emit_symbol(stream, Laux, 4); - bwc_emit_chunck(stream, aux->memory, aux->size); + emit_symbol(stream, SAX, 2); + emit_symbol(stream, Laux, 4); + emit_chunck(stream, aux->memory, aux->size); - if(bwc_terminate_stream(stream, header)) + if(terminate_stream(stream, header)) { // memory allocation error return 1; @@ -1508,7 +1509,7 @@ codestream_write_aux(bwc_packed_stream *const header, bwc_packed_stream *const a ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -codestream_write_com(bwc_packed_stream *const header, bwc_packed_stream *const com) +codestream_write_com(bwc_stream *const header, bwc_stream *const com) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1518,7 +1519,7 @@ codestream_write_com(bwc_packed_stream *const header, bwc_packed_stream *const c /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - bwc_stream *stream; + bitstream *stream; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -1526,7 +1527,7 @@ codestream_write_com(bwc_packed_stream *const header, bwc_packed_stream *const c assert(header); assert(com); - stream = bwc_init_stream(header->memory, header->size, 'c'); + stream = init_stream(header->memory, header->size, 'c'); if(!stream) { // memory allocation error @@ -1545,11 +1546,11 @@ codestream_write_com(bwc_packed_stream *const header, bwc_packed_stream *const c return 1; } - bwc_emit_symbol(stream, COM, 2); - bwc_emit_symbol(stream, Lcom, 2); - bwc_emit_chunck(stream, com->memory, com->size); + emit_symbol(stream, COM, 2); + emit_symbol(stream, Lcom, 2); + emit_chunck(stream, com->memory, com->size); - if(bwc_terminate_stream(stream, header)) + if(terminate_stream(stream, header)) { // memory allocation error return 1; @@ -1559,7 +1560,7 @@ codestream_write_com(bwc_packed_stream *const header, bwc_packed_stream *const c } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bwc_packed_stream* assemble_codestream(bwc_field *const field) ! +! FUNCTION NAME: bwc_stream* assemble_codestream(bwc_field *const field) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -1577,7 +1578,7 @@ codestream_write_com(bwc_packed_stream *const header, bwc_packed_stream *const c ! ------------- ! ! Type Description ! ! ---- ----------- ! -! bwc_packed_stream* - Packed stream containing the compressed data set. ! +! bwc_stream* - Packed stream containing the compressed data set. ! ! ! ! DEVELOPMENT HISTORY: ! ! -------------------- ! @@ -1587,7 +1588,7 @@ codestream_write_com(bwc_packed_stream *const header, bwc_packed_stream *const c ! 13.06.2019 Patrick Vogler B87D120 V 0.1.0 function created ! ! ! \*----------------------------------------------------------------------------------------------------------*/ -bwc_packed_stream* +bwc_stream* assemble_codestream(bwc_field *const field) { /*-----------------------*\ @@ -1600,8 +1601,8 @@ assemble_codestream(bwc_field *const field) \*-----------------------*/ bwc_gl_ctrl *control; bwc_tile *tile; - bwc_stream *stream; - bwc_packed_stream *packed_stream; + bitstream *stream; + bwc_stream *packed_stream; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -1645,7 +1646,7 @@ assemble_codestream(bwc_field *const field) ! Initialize the final codestream and emit the header ! ! bytes. ! \*--------------------------------------------------------*/ - stream = bwc_init_stream(NULL, size, 'c'); + stream = init_stream(NULL, size, 'c'); codestream_write_header(stream, field); /*--------------------------------------------------------*\ @@ -1663,9 +1664,9 @@ assemble_codestream(bwc_field *const field) assemble_tile(field, tile, stream); } - bwc_emit_symbol(stream, EOC, 2); + emit_symbol(stream, EOC, 2); - packed_stream = calloc(1, sizeof(bwc_packed_stream)); + packed_stream = calloc(1, sizeof(bwc_stream)); if(!packed_stream) { // memory allocation error @@ -1673,7 +1674,7 @@ assemble_codestream(bwc_field *const field) return NULL; } - if(bwc_terminate_stream(stream, packed_stream)) + if(terminate_stream(stream, packed_stream)) { return NULL; } @@ -1684,7 +1685,7 @@ assemble_codestream(bwc_field *const field) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar parse_codestream(bwc_field *const field, bwc_stream *const stream) ! +! FUNCTION NAME: uchar parse_codestream(bwc_field *const field, bitstream *const stream) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -1698,7 +1699,7 @@ assemble_codestream(bwc_field *const field) ! field bwc_field* - Structure defining the compression/ ! ! decompression stage. ! ! ! -! stream bwc_stream* - Structure used to assemble a bwc bit- ! +! stream bitstream* - Structure used to assemble a bwc bit- ! ! bitstream. ! ! ! ! RETURN VALUE: ! @@ -1722,7 +1723,7 @@ parse_codestream(bwc_data *const data, uint8 const layer) ! DEFINE STRUCTS: ! \*-----------------------*/ bwc_field *field; - bwc_stream *stream; + bitstream *stream; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -1733,14 +1734,14 @@ parse_codestream(bwc_data *const data, uint8 const layer) ! Initialize a bitstream used to parse the packed code- ! ! stream. ! \*--------------------------------------------------------*/ - stream = bwc_init_stream(data->codestream.data->memory, - data->codestream.data->size, 'd'); + stream = init_stream(data->codestream.data->memory, + data->codestream.data->size, 'd'); /*--------------------------------------------------------*\ ! Parse the main header and set up the field structure for ! ! the current decompression run. ! \*--------------------------------------------------------*/ - field = bwc_parse_main_header(data, stream); + field = parse_main_header(data, stream); if(!field) { return NULL; diff --git a/src/library/libbwc.c b/src/library/libbwc.c index 2f6aa65..9970805 100755 --- a/src/library/libbwc.c +++ b/src/library/libbwc.c @@ -612,7 +612,7 @@ initialize_subband(bwc_field *const field, bwc_parameter *const parameter, bwc_r } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_header_append_aux(bwc_field *const field, bwc_packed_stream *const aux) ! +! FUNCTION NAME: void bwc_header_append_aux(bwc_field *const field, bwc_stream *const aux) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -647,7 +647,7 @@ initialize_subband(bwc_field *const field, bwc_parameter *const parameter, bwc_r ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -header_append_aux(bwc_field *const field, bwc_packed_stream *const aux) +header_append_aux(bwc_field *const field, bwc_stream *const aux) { /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -714,7 +714,7 @@ header_append_aux(bwc_field *const field, bwc_packed_stream *const aux) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_header_append_com(bwc_field *const field, bwc_packed_stream *const com) ! +! FUNCTION NAME: void bwc_header_append_com(bwc_field *const field, bwc_stream *const com) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -749,7 +749,7 @@ header_append_aux(bwc_field *const field, bwc_packed_stream *const aux) ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -header_append_com(bwc_field *const field, bwc_packed_stream *const com) +header_append_com(bwc_field *const field, bwc_stream *const com) { /*-----------------------*\ ! DEFINE STRUCTS: ! diff --git a/src/library/tagtree.c b/src/library/tagtree.c index 37743ad..9ba1554 100755 --- a/src/library/tagtree.c +++ b/src/library/tagtree.c @@ -419,7 +419,7 @@ initialize_tagtree(const uint64 leafsX, const uint64 leafsY, const uint64 leafsZ ! ! \*----------------------------------------------------------------------------------------------------------*/ void -encode_tagtree(bwc_tagtree *const tagtree, bwc_stream *const stream, const uint32 threshold, const uint32 leaf_index, const uchar estimate) +encode_tagtree(bwc_tagtree *const tagtree, bitstream *const stream, const uint32 threshold, const uint32 leaf_index, const uchar estimate) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -461,11 +461,11 @@ encode_tagtree(bwc_tagtree *const tagtree, bwc_stream *const stream, const uint3 threshold_tmp++; if(node->value >= threshold_tmp) { - bwc_emit_bit(stream, 0); + emit_bit(stream, 0); } else { - bwc_emit_bit(stream, 1); + emit_bit(stream, 1); } } @@ -512,7 +512,7 @@ encode_tagtree(bwc_tagtree *const tagtree, bwc_stream *const stream, const uint3 ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -decode_tagtree(bwc_tagtree *const tagtree, bwc_stream *const stream, const uint32 threshold, const uint32 leaf_index) +decode_tagtree(bwc_tagtree *const tagtree, bitstream *const stream, const uint32 threshold, const uint32 leaf_index) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -556,7 +556,7 @@ decode_tagtree(bwc_tagtree *const tagtree, bwc_stream *const stream, const uint3 while((node->value == node->threshold) && (node->threshold < threshold)) { node->threshold++; - if(!bwc_get_bit(stream)) + if(!get_bit(stream)) { node->value++; } diff --git a/src/library/tier2.c b/src/library/tier2.c index 560f8c8..138affd 100755 --- a/src/library/tier2.c +++ b/src/library/tier2.c @@ -99,71 +99,71 @@ { \ if(delta_z == 1) \ { \ - bwc_emit_bit(stream, 0); \ + emit_bit(stream, 0); \ } \ else if(delta_z == 2) \ { \ - bwc_emit_bit(stream, 1); \ - bwc_emit_bit(stream, 0); \ + emit_bit(stream, 1); \ + emit_bit(stream, 0); \ } \ else if(delta_z < 6) \ { \ delta_z -= 3; \ - bwc_emit_bit(stream, 1); \ - bwc_emit_bit(stream, 1); \ - bwc_emit_bit(stream, 0x02 & delta_z); \ - bwc_emit_bit(stream, 0x01 & delta_z); \ + emit_bit(stream, 1); \ + emit_bit(stream, 1); \ + emit_bit(stream, 0x02 & delta_z); \ + emit_bit(stream, 0x01 & delta_z); \ } \ else if(delta_z < 37) \ { \ delta_z -= 6; \ - bwc_emit_bit(stream, 1); \ - bwc_emit_bit(stream, 1); \ - bwc_emit_bit(stream, 1); \ - bwc_emit_bit(stream, 1); \ - bwc_emit_bit(stream, 0x10 & delta_z); \ - bwc_emit_bit(stream, 0x08 & delta_z); \ - bwc_emit_bit(stream, 0x04 & delta_z); \ - bwc_emit_bit(stream, 0x02 & delta_z); \ - bwc_emit_bit(stream, 0x01 & delta_z); \ + emit_bit(stream, 1); \ + emit_bit(stream, 1); \ + emit_bit(stream, 1); \ + emit_bit(stream, 1); \ + emit_bit(stream, 0x10 & delta_z); \ + emit_bit(stream, 0x08 & delta_z); \ + emit_bit(stream, 0x04 & delta_z); \ + emit_bit(stream, 0x02 & delta_z); \ + emit_bit(stream, 0x01 & delta_z); \ } \ else if(delta_z < 293) \ { \ delta_z -= 37; \ - bwc_emit_bit(stream, 1); \ - bwc_emit_bit(stream, 1); \ - bwc_emit_bit(stream, 1); \ - bwc_emit_bit(stream, 1); \ - bwc_emit_bit(stream, 1); \ - bwc_emit_bit(stream, 1); \ - bwc_emit_bit(stream, 1); \ - bwc_emit_bit(stream, 1); \ - bwc_emit_bit(stream, 1); \ - bwc_emit_bit(stream, 0x080 & delta_z); \ - bwc_emit_bit(stream, 0x040 & delta_z); \ - bwc_emit_bit(stream, 0x020 & delta_z); \ - bwc_emit_bit(stream, 0x010 & delta_z); \ - bwc_emit_bit(stream, 0x008 & delta_z); \ - bwc_emit_bit(stream, 0x004 & delta_z); \ - bwc_emit_bit(stream, 0x002 & delta_z); \ - bwc_emit_bit(stream, 0x001 & delta_z); \ + emit_bit(stream, 1); \ + emit_bit(stream, 1); \ + emit_bit(stream, 1); \ + emit_bit(stream, 1); \ + emit_bit(stream, 1); \ + emit_bit(stream, 1); \ + emit_bit(stream, 1); \ + emit_bit(stream, 1); \ + emit_bit(stream, 1); \ + emit_bit(stream, 0x080 & delta_z); \ + emit_bit(stream, 0x040 & delta_z); \ + emit_bit(stream, 0x020 & delta_z); \ + emit_bit(stream, 0x010 & delta_z); \ + emit_bit(stream, 0x008 & delta_z); \ + emit_bit(stream, 0x004 & delta_z); \ + emit_bit(stream, 0x002 & delta_z); \ + emit_bit(stream, 0x001 & delta_z); \ } \ } #define decode_delta_z(stream, delta_z) \ { \ - if(!bwc_get_bit(stream)) \ + if(!get_bit(stream)) \ { \ delta_z = 1; \ } \ - else if(!bwc_get_bit(stream)) \ + else if(!get_bit(stream)) \ { \ delta_z = 2; \ } \ else \ { \ - delta_z = (bwc_get_bit(stream) << 1) | \ - bwc_get_bit(stream); \ + delta_z = (get_bit(stream) << 1) | \ + get_bit(stream); \ \ if(delta_z < 3) \ { \ @@ -171,11 +171,11 @@ } \ else \ { \ - delta_z = (bwc_get_bit(stream) << 4) | \ - (bwc_get_bit(stream) << 3) | \ - (bwc_get_bit(stream) << 2) | \ - (bwc_get_bit(stream) << 1) | \ - bwc_get_bit(stream); \ + delta_z = (get_bit(stream) << 4) | \ + (get_bit(stream) << 3) | \ + (get_bit(stream) << 2) | \ + (get_bit(stream) << 1) | \ + get_bit(stream); \ \ if(delta_z < 31) \ { \ @@ -183,14 +183,14 @@ } \ else \ { \ - delta_z = (bwc_get_bit(stream) << 7) | \ - (bwc_get_bit(stream) << 6) | \ - (bwc_get_bit(stream) << 5) | \ - (bwc_get_bit(stream) << 4) | \ - (bwc_get_bit(stream) << 3) | \ - (bwc_get_bit(stream) << 2) | \ - (bwc_get_bit(stream) << 1) | \ - bwc_get_bit(stream); \ + delta_z = (get_bit(stream) << 7) | \ + (get_bit(stream) << 6) | \ + (get_bit(stream) << 5) | \ + (get_bit(stream) << 4) | \ + (get_bit(stream) << 3) | \ + (get_bit(stream) << 2) | \ + (get_bit(stream) << 1) | \ + get_bit(stream); \ \ delta_z += 37; \ } \ @@ -205,7 +205,7 @@ || || \************************************************************************************************************/ /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void encode_length(bwc_stream *const header, bwc_codeblock *const codeblock, ! +! FUNCTION NAME: void encode_length(bitstream *const header, bwc_codeblock *const codeblock, ! ! -------------- int8 const quality_layer, ! ! uchar const estimate) ! ! ! @@ -236,9 +236,9 @@ ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -encode_length(bwc_stream *const header, bwc_codeblock *const codeblock, - int8 const quality_layer, - uchar const estimate) +encode_length(bitstream *const header, bwc_codeblock *const codeblock, + int8 const quality_layer, + uchar const estimate) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -284,17 +284,17 @@ encode_length(bwc_stream *const header, bwc_codeblock *const codeblock, while(beta < max_beta) { - bwc_emit_bit(header, 1); + emit_bit(header, 1); beta++; } - bwc_emit_bit(header, 0); + emit_bit(header, 0); L_bits = 1 << (beta + cp_bits - 1); while(L_bits > 0) { - bwc_emit_bit(header, L & L_bits); + emit_bit(header, L & L_bits); L_bits >>= 1; } @@ -339,7 +339,7 @@ encode_length(bwc_stream *const header, bwc_codeblock *const codeblock, ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -decode_length(bwc_stream *const header, bwc_codeblock *const codeblock, int8 const quality_layer) +decode_length(bitstream *const header, bwc_codeblock *const codeblock, int8 const quality_layer) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -363,7 +363,7 @@ decode_length(bwc_stream *const header, bwc_codeblock *const codeblock, int8 con cblk_ctrl = &codeblock->control; cp_contr = cblk_ctrl->cp_contr; - while(bwc_get_bit(header)) + while(get_bit(header)) { cblk_ctrl->beta++; } @@ -376,7 +376,7 @@ decode_length(bwc_stream *const header, bwc_codeblock *const codeblock, int8 con for(i = 0; L_bits > 0; --L_bits) { i <<= 1; - i |= bwc_get_bit(header); + i |= get_bit(header); } codeblock->encoded_block->L[z_curr] = ((z_prev >= 0) ? codeblock->encoded_block->L[z_prev] : 0) + i; @@ -455,7 +455,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile, bwc_packet *packet; bwc_precinct *precinct; bwc_codeblock *codeblock; - bwc_stream *header; + bitstream *header; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -480,7 +480,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile, ! Initialize the stream that is used to assemble the pack- ! ! et header. ! \*--------------------------------------------------------*/ - header = bwc_init_stream(NULL, PACKET_HEADER_SIZE, 'c'); + header = init_stream(NULL, PACKET_HEADER_SIZE, 'c'); if(!header) { // memory allocation error @@ -496,7 +496,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile, if(!est) { packet->body.access = - packet->body.memory = calloc(packet->body.size, sizeof(bwc_packed_stream)); + packet->body.memory = calloc(packet->body.size, sizeof(bwc_stream)); if(!packet->body.memory) { // memory allocation error @@ -509,7 +509,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile, ! Emit the contribution bit to the packet header that sig- ! ! nals a non-empty packet body. ! \*--------------------------------------------------------*/ - bwc_emit_bit(header, 1); + emit_bit(header, 1); /*--------------------------------------------------------*\ ! Iterate over all codeblocks in all subbands to assemble ! @@ -571,7 +571,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile, ! If a contribution has already been made, transmit a flag ! ! to signal if new coding passes are to be contributed. ! \*--------------------------------------------------------*/ - bwc_emit_bit(header, delta_z); + emit_bit(header, delta_z); } /*--------------------------------------------------------*\ @@ -642,7 +642,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile, } k = header->L; - bwc_terminate_stream(header, NULL); + terminate_stream(header, NULL); return k; } /*--------------------------------------------------------*\ @@ -653,7 +653,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile, \*--------------------------------------------------------*/ else { - if(bwc_terminate_stream(header, &packet->header)) + if(terminate_stream(header, &packet->header)) { // memory allocation error return -1; @@ -1375,7 +1375,7 @@ parse_packet(bwc_field *const field, bwc_tile *const tile, bwc_precinct *precinct; bwc_codeblock *codeblock; bwc_encoded_cblk *encoded_block; - bwc_stream *header; + bitstream *header; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -1390,7 +1390,7 @@ parse_packet(bwc_field *const field, bwc_tile *const tile, ! Initialize the stream that is used to parse the packet ! ! codestream. ! \*--------------------------------------------------------*/ - header = bwc_init_stream(packet->header.memory, body_size, 'd'); + header = init_stream(packet->header.memory, body_size, 'd'); if(!header) { // memory allocation error @@ -1401,7 +1401,7 @@ parse_packet(bwc_field *const field, bwc_tile *const tile, ! Extract the codeblock contribution marker from the code- ! ! stream. ! \*--------------------------------------------------------*/ - packet->e = bwc_get_bit(header); + packet->e = get_bit(header); /*--------------------------------------------------------*\ ! Check if the current packet has any codeblock contribu- ! @@ -1471,7 +1471,7 @@ parse_packet(bwc_field *const field, bwc_tile *const tile, ! flag from the codestream that signals if new coding pas- ! ! ses are available. ! \*--------------------------------------------------------*/ - delta_z = bwc_get_bit(header); + delta_z = get_bit(header); } diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index 73f659b..672d973 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -1507,8 +1507,7 @@ output_info(bwc_cmdl_arg_node *const args, bwc_param_inf *param_info; bwc_cmdl_arg_node *temp; - - bwc_stream *stream; + struct stat buf; /*-----------------------*\ @@ -1672,7 +1671,7 @@ output_info(bwc_cmdl_arg_node *const args, return; } - data->codestream.data = calloc(1, sizeof(bwc_packed_stream)); + data->codestream.data = calloc(1, sizeof(bwc_stream)); if(data->codestream.data == NULL) { // memory allocation error @@ -1713,33 +1712,16 @@ output_info(bwc_cmdl_arg_node *const args, ! Initialize the bitstream, parse the main header and set ! ! up the field structure for the current dataset. ! \*--------------------------------------------------------*/ - stream = calloc(1, sizeof(bwc_stream)); - if(stream == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - return; - } - - stream->memory = data->codestream.data->memory; - - stream->t = 0; - stream->Lmax = data->codestream.data->size; - stream->size_incr = (uint64)(stream->Lmax / 2); - - field = bwc_parse_main_header(data, stream); + field = bwc_create_decompression(data, 0); if(field == NULL) { bwc_free_data(data); - free(stream); fclose(fp); return; } control = &field->control; info = field->info; - free(stream); - /*--------------------------------------------------------*\ ! Write the help message to the standard output. ! \*--------------------------------------------------------*/ @@ -1755,16 +1737,15 @@ output_info(bwc_cmdl_arg_node *const args, "| .+++=--------=+++---=+++---=+++------------: |\n"\ "| -=++++++++++++++++++++++++++++++++++++++++- |\n"\ "| |\n"\ - "|-------------------------------General Information------------------------------|\n"\ + "|------------------------------ General Information -----------------------------|\n"\ "| |\n"); /*--------------------------------------------------------*\ ! Print the original file size and format. ! \*--------------------------------------------------------*/ - fseek(fp, 0L, SEEK_END); - Ld = ftell(fp); - buff = get_size(Ld); - fclose(fp); + data_points = (uint64)info->nX * info->nY * info->nZ * + info->nTS * info->nPar; + buff = get_size(data_points * 8); printf("| Original size: %42s |\n"\ "| Original file format: %42s |\n"\ @@ -1775,9 +1756,10 @@ output_info(bwc_cmdl_arg_node *const args, /*--------------------------------------------------------*\ ! Print the file size and compression ratio. ! \*--------------------------------------------------------*/ - data_points = (uint64)info->nX * info->nY * info->nZ * - info->nTS * info->nPar; - buff = get_size(data_points * 8); + fseek(fp, 0L, SEEK_END); + Ld = ftell(fp); + buff = get_size(Ld); + fclose(fp); printf("| Size on Disk: %42s |\n"\ "| Comp. Ratio: %42.2f |\n"\ @@ -1814,7 +1796,7 @@ output_info(bwc_cmdl_arg_node *const args, /*--------------------------------------------------------*\ ! Print the numerical Datapoints. ! \*--------------------------------------------------------*/ - printf("|------------------------------Numerical Parameters------------------------------|\n"\ + printf("|----------------------------- Numerical Parameters -----------------------------|\n"\ "| |\n"); for(p = 0; p < info->nPar; ++p) @@ -1835,19 +1817,23 @@ output_info(bwc_cmdl_arg_node *const args, while(buff > param_info->name && isspace((unsigned char)*buff)) buff--; buff[1] = '\0'; + if(p != 0) + { + printf("| ........................................................................ |\n" + "|%80s|\n"," "); + } + printf("| Name: %55s |\n"\ "| Minimum value: %55.2e |\n"\ - "| Maximum value: %55.2e |\n"\ - "| ........................................................................ |\n" - "|%80s|\n", param_info->name, - minVal, - maxVal, " "); + "| Maximum value: %55.2e |\n", param_info->name, + minVal, + maxVal); } - + printf("|%80s|\n"," "); /*--------------------------------------------------------*\ ! Print the quality layers. ! \*--------------------------------------------------------*/ - printf("|---------------------------------Quality Layers---------------------------------|\n"\ + printf("|-------------------------------- Quality Layers --------------------------------|\n"\ "| |\n"); for(l = 0; l < control->nLayers; ++l) @@ -1959,7 +1945,7 @@ read_bwc(char *const filename) return NULL; } - file->codestream.data = calloc(1, sizeof(bwc_packed_stream)); + file->codestream.data = calloc(1, sizeof(bwc_stream)); if(file->codestream.data == NULL) { // memory allocation error