From 008ccfa4a9d5fe2616c289677ad8f6e58d1f0f49 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Wed, 27 Mar 2024 17:25:05 +0100 Subject: [PATCH 01/53] Reorganize bwc_field and bwc_data to split codec settings and data stream semantically into data structures `bwc_codec` and `bwc_stream`. Cleaning up by removal of redundant information like parameter linked list, file extension, and file pointer including associated functionality. Start constructing an API taking void pointers to the original data for compression. --- include/library/private/bitstream.h | 4 +- include/library/private/codestream.h | 15 +- include/library/private/constants.h | 8 +- include/library/private/dwt.h | 6 +- include/library/private/libbwc.h | 79 ++-- include/library/private/tier1.h | 6 +- include/library/private/tier2.h | 6 +- include/library/private/types.h | 60 +-- src/interfaces/fortran/bwc.F90 | 38 -- src/interfaces/python/bwc.py | 18 - src/library/bitstream.c | 8 +- src/library/codestream.c | 143 +++--- src/library/dwt.c | 18 +- src/library/libbwc.c | 663 ++++++++------------------- src/library/tier1.c | 14 +- src/library/tier2.c | 48 +- 16 files changed, 359 insertions(+), 775 deletions(-) diff --git a/include/library/private/bitstream.h b/include/library/private/bitstream.h index 6363775..3ec7a78 100755 --- a/include/library/private/bitstream.h +++ b/include/library/private/bitstream.h @@ -118,7 +118,7 @@ uchar get_bit (bitstream *const stream); //==========|==========================|======================|======|======|===================== uchar terminate_stream (bitstream *stream, - bwc_stream *const packed_stream); + bwc_span *const packed_stream); //==========|==========================|======================|======|======|===================== - void release_packed_stream (bwc_stream *const stream); + void release_packed_stream (bwc_span *const stream); #endif diff --git a/include/library/private/codestream.h b/include/library/private/codestream.h index 482b8eb..7b2c1f5 100755 --- a/include/library/private/codestream.h +++ b/include/library/private/codestream.h @@ -89,16 +89,17 @@ || | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] || || || \************************************************************************************************/ - uchar assemble_main_header (bwc_field *const field); + uchar assemble_main_header (bwc_codec *const field); //==========|==========================|======================|======|======|===================== - uchar codestream_write_aux (bwc_stream *const header, - bwc_stream *const aux); + uchar codestream_write_aux (bwc_span *const header, + bwc_span *const aux); //==========|==========================|======================|======|======|===================== - uchar codestream_write_com (bwc_stream *const header, - bwc_stream *const com); + uchar codestream_write_com (bwc_span *const header, + bwc_span *const com); //==========|==========================|======================|======|======|===================== - bwc_stream* assemble_codestream (bwc_field *const field); + bwc_span* assemble_codestream (bwc_codec *const field, + bwc_stream *const data); //==========|==========================|======================|======|======|===================== - bwc_field* parse_codestream (bwc_data *const data, + bwc_codec* parse_codestream (bwc_stream *const data, uint8 const layer); #endif \ No newline at end of file diff --git a/include/library/private/constants.h b/include/library/private/constants.h index c8af8d0..35bd7ef 100755 --- a/include/library/private/constants.h +++ b/include/library/private/constants.h @@ -114,8 +114,8 @@ \*----------------------------------------------------------------------------------------------*/ typedef enum { - bwc_type_half, - bwc_type_single, - bwc_type_double, - } bwc_type; + bwc_precision_half = 2, + bwc_precision_single = 4, + bwc_precision_double = 8, + } bwc_precision; #endif \ No newline at end of file diff --git a/include/library/private/dwt.h b/include/library/private/dwt.h index d9fa0eb..fa08858 100755 --- a/include/library/private/dwt.h +++ b/include/library/private/dwt.h @@ -157,13 +157,13 @@ \************************************************************************************************/ uchar initialize_gain_lut (); //==========|==========================|======================|======|=======|==================== - bwc_float get_dwt_energy_gain (bwc_field *const field, + bwc_float get_dwt_energy_gain (bwc_codec *const field, uchar const highband_flag, uint16 const level); //==========|==========================|======================|======|=======|==================== - uchar forward_wavelet_transform (bwc_field *const field, + uchar forward_wavelet_transform (bwc_codec *const field, bwc_parameter *const parameter); //==========|==========================|======================|======|=======|==================== - uchar inverse_wavelet_transform (bwc_field *const field, + uchar inverse_wavelet_transform (bwc_codec *const field, bwc_parameter *const parameter); #endif \ No newline at end of file diff --git a/include/library/private/libbwc.h b/include/library/private/libbwc.h index 8418632..fdeb409 100755 --- a/include/library/private/libbwc.h +++ b/include/library/private/libbwc.h @@ -64,92 +64,85 @@ || || \************************************************************************************************/ //==========|==========================|======================|======|=======|==================== - bwc_data* bwc_initialize_data (double *const field, + bwc_stream* bwc_initialize_data (void *const data, + bwc_precision const prec); + //==========|==========================|======================|======|=======|==================== + uchar bwc_set_com (bwc_stream *const data, + char const *const com, + uint16 const size); + //==========|==========================|======================|======|=======|==================== + uchar bwc_set_aux (bwc_stream *const data, + char const *const aux, + uint32 const size); + //==========|==========================|======================|======|=======|==================== + void bwc_free_data (bwc_stream *const data); + //==========|==========================|======================|======|=======|==================== + uchar create_field (bwc_codec *const field); + //==========|==========================|======================|======|=======|==================== + void bwc_kill_compression (bwc_codec *const field); + //==========|==========================|======================|======|=======|==================== + bwc_codec* bwc_initialize_field (bwc_precision const prec, uint64 const nX, uint64 const nY, uint64 const nZ, uint16 const nTS, - uint8 const nPar, - char *const file_extension); + uint8 const nPar); //==========|==========================|======================|======|=======|==================== - uchar bwc_set_com (bwc_data *const data, - char const *const com, - uint16 const size); + void bwc_set_error_resilience (bwc_codec *const field); //==========|==========================|======================|======|=======|==================== - uchar bwc_set_aux (bwc_data *const data, - char const *const aux, - uint32 const size); - //==========|==========================|======================|======|=======|==================== - void bwc_add_param (bwc_data *const data, - char *const name, - uint8 const precision); - //==========|==========================|======================|======|=======|==================== - void bwc_get_data (bwc_data *const data, - uchar *const buffer, - uint64 const size); - //==========|==========================|======================|======|=======|==================== - void bwc_free_data (bwc_data *const data); - //==========|==========================|======================|======|=======|==================== - uchar create_field (bwc_field *const field); - //==========|==========================|======================|======|=======|==================== - void bwc_kill_compression (bwc_field *const field); - //==========|==========================|======================|======|=======|==================== - bwc_field* bwc_initialize_field (bwc_data *const data); - //==========|==========================|======================|======|=======|==================== - void bwc_set_error_resilience (bwc_field *const field); - //==========|==========================|======================|======|=======|==================== - void set_quant_style (bwc_field *const field, + void set_quant_style (bwc_codec *const field, bwc_quant_st const quantization_style); //==========|==========================|======================|======|=======|==================== - void set_quant_step_size (bwc_field *const field, + void set_quant_step_size (bwc_codec *const field, double const delta); //==========|==========================|======================|======|=======|==================== - void set_progression (bwc_field *const field, + void set_progression (bwc_codec *const field, bwc_prog_ord const progression); //==========|==========================|======================|======|=======|==================== - void set_kernels (bwc_field *const field, + void set_kernels (bwc_codec *const field, bwc_dwt_filter const KernelX, bwc_dwt_filter const KernelY, bwc_dwt_filter const KernelZ, bwc_dwt_filter const KernelTS); //==========|==========================|======================|======|=======|==================== - void bwc_set_decomp (bwc_field *const field, + void bwc_set_decomp (bwc_codec *const field, uint8 const decompX, uint8 const decompY, uint8 const decompZ, uint8 const decompTS); //==========|==========================|======================|======|=======|==================== - void bwc_set_precincts (bwc_field *const field, + void bwc_set_precincts (bwc_codec *const field, uint8 const pX, uint8 const pY, uint8 const pZ, uint8 const pTS); //==========|==========================|======================|======|=======|==================== - void bwc_set_codeblocks (bwc_field *const field, + void bwc_set_codeblocks (bwc_codec *const field, uint8 const cbX, uint8 const cbY, uint8 const cbZ, uint8 const cbTS); //==========|==========================|======================|======|=======|==================== - void bwc_set_qm (bwc_field *const field, + void bwc_set_qm (bwc_codec *const field, uint8 const Qm); //==========|==========================|======================|======|=======|==================== - void bwc_set_tiles (bwc_field *const field, + void bwc_set_tiles (bwc_codec *const field, uint64 const tilesX, uint64 const tilesY, uint64 const tilesZ, uint64 const tilesTS, bwc_tile_instr const instr); //==========|==========================|======================|======|=======|==================== - uchar bwc_create_compression (bwc_field *const field, + uchar bwc_create_compression (bwc_codec *const codec, + bwc_stream *const data, char *const rate_control); //==========|==========================|======================|======|=======|==================== - uchar bwc_compress (bwc_field *const field, - bwc_data *const data); + uchar bwc_compress (bwc_codec *const field, + bwc_stream *const data); //==========|==========================|======================|======|=======|==================== - bwc_field* bwc_create_decompression (bwc_data *const data, + bwc_codec* bwc_create_decompression (bwc_stream *const data, uint8 const layer); //==========|==========================|======================|======|=======|==================== - uchar bwc_decompress (bwc_field *const field, - bwc_data *const data); + uchar bwc_decompress (bwc_codec *const field, + bwc_stream *const data); #endif \ No newline at end of file diff --git a/include/library/private/tier1.h b/include/library/private/tier1.h index 13f60eb..7f0e19c 100755 --- a/include/library/private/tier1.h +++ b/include/library/private/tier1.h @@ -16,7 +16,7 @@ || ------------ || || || || This file describes a set of functions that can be used to de-/encode bwc || -|| codeblocks described by the bwc_field structure according to the embedded block || +|| codeblocks described by the bwc_codec structure according to the embedded block || || coding paradigm described by the JPEG 2000 standard. For more information please || || refere to JPEG2000 by D. S. Taubman and M. W. Marcellin. || || || @@ -156,11 +156,11 @@ || | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] || || || \************************************************************************************************/ - uchar t1_encode (bwc_field *const field, + uchar t1_encode (bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const parameter); //==========|==========================|======================|======|=======|==================== - uchar t1_decode (bwc_field *const field, + uchar t1_decode (bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const parameter); diff --git a/include/library/private/tier2.h b/include/library/private/tier2.h index 3dc0bb2..074e49d 100755 --- a/include/library/private/tier2.h +++ b/include/library/private/tier2.h @@ -16,7 +16,7 @@ || ------------ || || || || This file describes a set of functions that can be used to de-/encode bwc || -|| codeblocks described by the bwc_field structure according to the embedded block || +|| codeblocks described by the bwc_codec structure according to the embedded block || || coding paradigm described by the JPEG 2000 standard. For more information please || || refere to JPEG2000 by D. S. Taubman and M. W. Marcellin. || || || @@ -76,10 +76,10 @@ || | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] || || || \************************************************************************************************/ - uchar t2_encode (bwc_field *const field, + uchar t2_encode (bwc_codec *const field, bwc_tile *const tile); //==========|==========================|======================|======|=======|==================== - uchar parse_packet (bwc_field *const field, + uchar parse_packet (bwc_codec *const field, bwc_tile *const tile, bwc_packet *const packet, uint64 const body_size); diff --git a/include/library/private/types.h b/include/library/private/types.h index 323101f..fcacd32 100755 --- a/include/library/private/types.h +++ b/include/library/private/types.h @@ -99,7 +99,7 @@ uchar *access; // Pointer used to parse packed stream. uchar *memory; // Memory handle for the packed stream. - } bwc_stream; + } bwc_span; /*----------------------------------------------------------------------------------------------*\ ! ! @@ -138,29 +138,6 @@ bwc_tagtree_node *nodes; // Pointer to the tagtree nodes. } bwc_tagtree; - - /*----------------------------------------------------------------------------------------------*\ - ! ! - ! DESCRIPTION: ! - ! ------------ ! - ! ! - ! This structure defines a linked list which stores the size, index, and bit pre- ! - ! cision The string name is used to store the parameter name supplied by the ! - ! function caller. ! - ! ! - \*----------------------------------------------------------------------------------------------*/ - typedef struct opt - { - char name[24]; // Parameter name. - uint8 id; // Parameter index. - - uint64 size; // Parameter size after sub-sampling. - uint8 precision; // Parameter precision. - - struct opt *next; // Next element in linked-list. - struct opt *root; // Linked-list root. - } bwc_cmd_opts_ll; - /*----------------------------------------------------------------------------------------------*\ ! ! ! DESCRIPTION: ! @@ -178,12 +155,8 @@ uint8 nPar; // Number of parameters. - uint8 precision; // Flag defining codec precision. - - uint8 codec_prec; // Encoder/decoder bit precision. - char f_ext[20]; // Uncompressed data set file extension. - - bwc_cmd_opts_ll *parameter; // Command options linked-list. + bwc_precision data_prec; // Data type of uncompressed field data. + bwc_precision codec_prec; // Encoder/decoder bit precision. } bwc_gl_inf; /*----------------------------------------------------------------------------------------------*\ @@ -197,14 +170,11 @@ \*----------------------------------------------------------------------------------------------*/ typedef struct { - bwc_gl_inf info; // Gloabal info structure. - FILE *fp; // File point to (un)compr. data-set. - struct codestream { - bwc_stream *data; // Data codestream block. - bwc_stream *aux; // Auxiliary info. codestream block. - bwc_stream *com; // Comment codestream block. + bwc_span *data; // Data codestream block. + bwc_span *aux; // Auxiliary info. codestream block. + bwc_span *com; // Comment codestream block. }codestream; struct field @@ -212,7 +182,7 @@ double *d; // Double precision numerical data-set. float *f; // Single precision numerical data-set. }field; - } bwc_data; + } bwc_stream; /*----------------------------------------------------------------------------------------------*\ ! ! @@ -420,8 +390,8 @@ \*----------------------------------------------------------------------------------------------*/ typedef struct { - bwc_stream header; // Packed stream header. - bwc_stream body; // Packed stream body. + bwc_span header; // Packed stream header. + bwc_span body; // Packed stream body. uint8 e; // Indicator for packet cb. contributions. uint32 size; // Codestream packet size. @@ -528,14 +498,9 @@ \*----------------------------------------------------------------------------------------------*/ typedef struct { - uint64 size; // Parameter size. - char *name; // Parameter name. - uint64 X0, Y0, Z0, TS0; // Tile parameter starting point. uint64 X1, Y1, Z1, TS1; // Tile parameter end point. - uint8 precision; // Tile parameter precision. - bwc_float parameter_min; // Min. value of tile parameter. bwc_float parameter_max; // Max. value of tile parameter. } bwc_param_inf; @@ -710,12 +675,9 @@ \*----------------------------------------------------------------------------------------------*/ typedef struct { - bwc_gl_inf *info; // Gloabal info structure + bwc_gl_inf info; // Global info structure bwc_gl_ctrl control; // Global control structure bwc_tile *tile; // Structure defining bwc tile. - - bwc_stream *aux; // Auxiliary info. codestream block. - bwc_stream *com; // Comment codestream block. - } bwc_field; + } bwc_codec; #endif \ No newline at end of file diff --git a/src/interfaces/fortran/bwc.F90 b/src/interfaces/fortran/bwc.F90 index b71e98a..aa413e9 100644 --- a/src/interfaces/fortran/bwc.F90 +++ b/src/interfaces/fortran/bwc.F90 @@ -107,42 +107,6 @@ module bwc CHARACTER(KIND=C_CHAR) :: file_extension(*) end function initialize_data_f !*============================================================================================*! - subroutine add_param_f(data, name, sample, dim, precision) & - BIND(C, NAME="bwc_add_param") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: data - - !*-----------------------*! - ! DEFINE INT VARIABLES: ! - !*-----------------------*! - INTEGER(KIND=C_INT16_T), VALUE :: sample - INTEGER(KIND=C_INT8_T), VALUE :: precision - INTEGER(KIND=C_SIGNED_CHAR), VALUE :: dim - - !*-----------------------*! - ! DEFINE CHAR VARIABLES: ! - !*-----------------------*! - CHARACTER(KIND=C_CHAR) :: name(*) - end subroutine add_param_f - !*============================================================================================*! - subroutine get_data_f(data, buffer, size) & - BIND(C, NAME="bwc_get_data") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: data - TYPE(C_PTR), VALUE :: buffer - - !*-----------------------*! - ! DEFINE INT VARIABLES: ! - !*-----------------------*! - INTEGER(KIND=C_INT64_T), Value :: size - end subroutine get_data_f - !*============================================================================================*! subroutine free_data_f(data) & BIND(C, NAME="bwc_free_data") IMPORT @@ -396,11 +360,9 @@ module bwc bwc_tile_numbof public :: bwc_initialize_data, & - bwc_get_data, & bwc_free_data public :: bwc_initialize_field, & - bwc_add_param, & bwc_kill_compression public :: bwc_set_error_resilience, & diff --git a/src/interfaces/python/bwc.py b/src/interfaces/python/bwc.py index e45984e..670ec90 100644 --- a/src/interfaces/python/bwc.py +++ b/src/interfaces/python/bwc.py @@ -102,24 +102,6 @@ def initialize_data(data, nX, nY, nZ, nTS, nPar, file_extension): ctypes.c_char_p] return ctypes.c_void_p(fun(data, nX, nY, nZ, nTS, nPar, file_extension.encode('utf-8'))) #==================================================================================================# -def get_data(data, buffer, size): - fun = libbwc.bwc_get_data - fun.restype = None - fun.argtypes = [ctypes.c_void_p, - ndpointer(ctypes.c_double, flags="C_CONTIGUOUS"), - ctypes.c_uint64] - fun(data, buffer, size) -#==================================================================================================# -def add_param(data, name, sample, dim, precision): - fun = libbwc.bwc_add_param - fun.restype = None - fun.argtypes = [ctypes.c_void_p, - ctypes.c_char_p, - ctypes.c_uint16, - ctypes.c_uint8, - ctypes.c_uint8] - fun(data, name.encode('utf-8'), sample, dim, precision) -#==================================================================================================# def kill_compression(field): fun = libbwc.bwc_kill_compression fun.restype = None diff --git a/src/library/bitstream.c b/src/library/bitstream.c index 1618c87..fee6777 100755 --- a/src/library/bitstream.c +++ b/src/library/bitstream.c @@ -896,7 +896,7 @@ flush_stream(bitstream *const stream) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -terminate_stream(bitstream *stream, bwc_stream *const packed_stream) +terminate_stream(bitstream *stream, bwc_span *const packed_stream) { /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -937,7 +937,7 @@ terminate_stream(bitstream *stream, bwc_stream *const packed_stream) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void release_packed_stream(bwc_stream *stream) ! +! FUNCTION NAME: void release_packed_stream(bwc_span *stream) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -949,7 +949,7 @@ terminate_stream(bitstream *stream, bwc_stream *const packed_stream) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! stream bwc_stream - Packed bitstream used to store parts of ! +! stream bwc_span - Packed bitstream used to store parts of ! ! the bwc codestream. ! ! ! ! RETURN VALUE: ! @@ -967,7 +967,7 @@ terminate_stream(bitstream *stream, bwc_stream *const packed_stream) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -release_packed_stream(bwc_stream *stream) +release_packed_stream(bwc_span *stream) { /*-----------------------*\ ! DEFINE ASSERTIONS: ! diff --git a/src/library/codestream.c b/src/library/codestream.c index 24af2f4..24955ad 100755 --- a/src/library/codestream.c +++ b/src/library/codestream.c @@ -104,7 +104,7 @@ can_read(bitstream *const stream, const uint64 length) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void codestream_write_header(bitstream *const stream, bwc_field *const field) ! +! FUNCTION NAME: void codestream_write_header(bitstream *const stream, bwc_codec *const field) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -116,7 +116,7 @@ can_read(bitstream *const stream, const uint64 length) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! stream bitstream* - Structure used to assemble a bwc bit- ! @@ -138,7 +138,8 @@ can_read(bitstream *const stream, const uint64 length) \*----------------------------------------------------------------------------------------------------------*/ static void codestream_write_header(bitstream *const stream, - bwc_field *const field) + bwc_codec *const field, + bwc_stream *const data) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -155,10 +156,8 @@ codestream_write_header(bitstream *const stream, \*-----------------------*/ bwc_gl_ctrl *control; bwc_gl_inf *info; - bwc_tile *tile; - bwc_parameter *parameter; - bwc_stream *aux; - bwc_stream *com; + bwc_span *aux; + bwc_span *com; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -171,17 +170,13 @@ codestream_write_header(bitstream *const stream, ! structure to temporary variables to make the code more ! ! readable. ! \*--------------------------------------------------------*/ - info = field->info; + info = &field->info; control = &field->control; - tile = &field->tile[0]; - - parameter = &tile->parameter[0]; - - aux = field->aux; - com = field->com; + aux = data->codestream.aux; + com = data->codestream.com; - Linf = 40 + info->nPar * 25; + Linf = 31; Lctr = 50 + control->nLayers * 4; Leoh = info->nPar * control->nTiles * 2 * PREC_BYTE; Lcss = control->codestreamSize; @@ -195,14 +190,8 @@ codestream_write_header(bitstream *const stream, 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) - { - emit_chunck(stream, (uchar*)parameter[p].info.name, 24); - emit_symbol(stream, parameter[p].info.precision, 1); - } + emit_symbol(stream, (uint8)info->data_prec, 1); + emit_symbol(stream, (uint8)info->codec_prec, 1); emit_symbol(stream, SGC, 2); emit_symbol(stream, Lctr, 2); @@ -288,7 +277,7 @@ codestream_write_header(bitstream *const stream, } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar sequence_packets(bwc_field *const field, bwc_field *const field) ! +! FUNCTION NAME: uchar sequence_packets(bwc_codec *const field, bwc_codec *const field) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -299,7 +288,7 @@ codestream_write_header(bitstream *const stream, ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -319,7 +308,7 @@ codestream_write_header(bitstream *const stream, ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -sequence_packets(bwc_field *const field, bwc_tile *const tile) +sequence_packets(bwc_codec *const field, bwc_tile *const tile) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -348,7 +337,7 @@ sequence_packets(bwc_field *const field, bwc_tile *const tile) ! code more readable. ! \*--------------------------------------------------------*/ control = &field->control; - info = field->info; + info = &field->info; packet_sequence = tile->packet_sequence; @@ -490,7 +479,7 @@ sequence_packets(bwc_field *const field, bwc_tile *const tile) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar sequence_packets(bwc_field *const field, bwc_field *const field) ! +! FUNCTION NAME: uchar sequence_packets(bwc_codec *const field, bwc_codec *const field) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -501,7 +490,7 @@ sequence_packets(bwc_field *const field, bwc_tile *const tile) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -521,7 +510,7 @@ sequence_packets(bwc_field *const field, bwc_tile *const tile) ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -assemble_tile(bwc_field *const field, bwc_tile *const tile, bitstream *const stream) +assemble_tile(bwc_codec *const field, bwc_tile *const tile, bitstream *const stream) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -613,8 +602,8 @@ assemble_tile(bwc_field *const field, bwc_tile *const tile, bitstream *const str ! - Patrick Vogler B87D120 V 0.1.0 function created ! ! ! \*----------------------------------------------------------------------------------------------------------*/ -bwc_field* -parse_main_header(bwc_data *const data,bitstream *const stream) +bwc_codec* +parse_main_header(bwc_stream *const data, bitstream *const stream) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -632,18 +621,17 @@ parse_main_header(bwc_data *const data,bitstream *const stream) uint16 nTS; uint8 index, l; uint8 nPar, p; - uint8 codec_prec, precision; + bwc_precision data_prec, codec_prec; /*-----------------------*\ ! DEFINE CHAR VARIABLES: ! \*-----------------------*/ - char* buffer_char; char status; /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - bwc_field *field; + bwc_codec *field; bwc_gl_ctrl *control; bwc_gl_inf *info; @@ -653,12 +641,6 @@ parse_main_header(bwc_data *const data,bitstream *const stream) 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; @@ -708,41 +690,24 @@ parse_main_header(bwc_data *const data,bitstream *const stream) 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); + nX = get_symbol(stream, 8); + nY = get_symbol(stream, 8); + nZ = get_symbol(stream, 8); + nTS = (uint16)get_symbol(stream, 2); + nPar = (uint8)get_symbol(stream, 1); + data_prec = (bwc_precision)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); + field = bwc_initialize_field(data_prec, nX, nY, nZ, nTS, nPar); 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; + info = &field->info; control = &field->control; + info->codec_prec = codec_prec = (bwc_precision)get_symbol(stream, 1); + control->codestreamSize = stream->Lmax; status |= CODESTREAM_SGI_READ; @@ -896,7 +861,7 @@ parse_main_header(bwc_data *const data,bitstream *const stream) break; } - data->codestream.aux = calloc(1, sizeof(bwc_stream)); + data->codestream.aux = calloc(1, sizeof(bwc_span)); if(!data->codestream.aux) { // memory allocation error @@ -934,7 +899,7 @@ parse_main_header(bwc_data *const data,bitstream *const stream) break; } - data->codestream.com = calloc(1, sizeof(bwc_stream)); + data->codestream.com = calloc(1, sizeof(bwc_span)); if(!data->codestream.com) { // memory allocation error @@ -974,7 +939,7 @@ parse_main_header(bwc_data *const data,bitstream *const stream) break; } - if(codec_prec == 8) + if(codec_prec == bwc_precision_double) { /*--------------------------------------------------------*\ ! Loop through all tile parameters and... ! @@ -995,7 +960,7 @@ parse_main_header(bwc_data *const data,bitstream *const stream) } } } - else if(codec_prec == 4) + else if(codec_prec == bwc_precision_single) { /*--------------------------------------------------------*\ ! Loop through all tile parameters and... ! @@ -1059,7 +1024,7 @@ parse_main_header(bwc_data *const data,bitstream *const stream) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar sequence_packets(bwc_field *const field, bwc_field *const field) ! +! FUNCTION NAME: uchar sequence_packets(bwc_codec *const field, bwc_codec *const field) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -1070,7 +1035,7 @@ parse_main_header(bwc_data *const data,bitstream *const stream) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -1090,7 +1055,7 @@ parse_main_header(bwc_data *const data,bitstream *const stream) ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -parse_tile(bwc_field *const field, bitstream *const stream) +parse_tile(bwc_codec *const field, bitstream *const stream) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1240,7 +1205,7 @@ parse_tile(bwc_field *const field, bitstream *const stream) ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -parse_body(bwc_field *const field, bitstream *const stream) +parse_body(bwc_codec *const field, bitstream *const stream) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1336,7 +1301,7 @@ parse_body(bwc_field *const field, bitstream *const stream) || || \************************************************************************************************************/ /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bwc_stream* assemble_codestream(bwc_field *const field) ! +! FUNCTION NAME: bwc_span* assemble_codestream(bwc_codec *const field) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -1347,14 +1312,14 @@ parse_body(bwc_field *const field, bitstream *const stream) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! RETURN VALUE: ! ! ------------- ! ! Type Description ! ! ---- ----------- ! -! bwc_stream* - Packed stream containing the compressed data set. ! +! bwc_span* - Packed stream containing the compressed data set. ! ! ! ! DEVELOPMENT HISTORY: ! ! -------------------- ! @@ -1364,8 +1329,8 @@ parse_body(bwc_field *const field, bitstream *const stream) ! 13.06.2019 Patrick Vogler B87D120 V 0.1.0 function created ! ! ! \*----------------------------------------------------------------------------------------------------------*/ -bwc_stream* -assemble_codestream(bwc_field *const field) +bwc_span* +assemble_codestream(bwc_codec *const field, bwc_stream *const data) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1378,7 +1343,7 @@ assemble_codestream(bwc_field *const field) bwc_gl_ctrl *control; bwc_tile *tile; bitstream *stream; - bwc_stream *packed_stream; + bwc_span *packed_stream; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -1424,7 +1389,7 @@ assemble_codestream(bwc_field *const field) ! bytes. ! \*--------------------------------------------------------*/ stream = init_stream(NULL, control->codestreamSize, 'c'); - codestream_write_header(stream, field); + codestream_write_header(stream, field, data); /*--------------------------------------------------------*\ ! Walk through the tile structure and assemble the packed ! @@ -1444,7 +1409,7 @@ assemble_codestream(bwc_field *const field) emit_symbol(stream, EOC, 2); - packed_stream = calloc(1, sizeof(bwc_stream)); + packed_stream = calloc(1, sizeof(bwc_span)); if(!packed_stream) { // memory allocation error @@ -1463,7 +1428,7 @@ assemble_codestream(bwc_field *const field) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar parse_codestream(bwc_field *const field, bitstream *const stream) ! +! FUNCTION NAME: uchar parse_codestream(bwc_codec *const field, bitstream *const stream) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -1474,7 +1439,7 @@ assemble_codestream(bwc_field *const field) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! stream bitstream* - Structure used to assemble a bwc bit- ! @@ -1494,13 +1459,13 @@ assemble_codestream(bwc_field *const field) ! 05.08.2019 Patrick Vogler B87D120 V 0.1.0 function created ! ! ! \*----------------------------------------------------------------------------------------------------------*/ -bwc_field* -parse_codestream(bwc_data *const data, uint8 const layer) +bwc_codec* +parse_codestream(bwc_stream *const data, uint8 const layer) { /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - bwc_field *field; + bwc_codec *field; bitstream *stream; /*-----------------------*\ diff --git a/src/library/dwt.c b/src/library/dwt.c index b22c7f2..1fc9136 100755 --- a/src/library/dwt.c +++ b/src/library/dwt.c @@ -1421,7 +1421,7 @@ initialize_gain_lut() } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bwc_float get_dwt_energy_gain(bwc_field *const field, uchar highband_flag, uint16 level) ! +! FUNCTION NAME: bwc_float get_dwt_energy_gain(bwc_codec *const field, uchar highband_flag, uint16 level) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -1434,7 +1434,7 @@ initialize_gain_lut() ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! highband_flag uchar - Defines the subband for which Gb is ! @@ -1459,7 +1459,7 @@ initialize_gain_lut() ! ! \*----------------------------------------------------------------------------------------------------------*/ bwc_float -get_dwt_energy_gain(bwc_field *const field, uchar highband_flag, uint16 level) +get_dwt_energy_gain(bwc_codec *const field, uchar highband_flag, uint16 level) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1576,7 +1576,7 @@ get_dwt_energy_gain(bwc_field *const field, uchar highband_flag, uint16 level) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar forward_discrete_wavelet_transform(bwc_field *const field, ! +! FUNCTION NAME: uchar forward_discrete_wavelet_transform(bwc_codec *const field, ! ! -------------- bwc_parameter *const parameter) ! ! ! ! DESCRIPTION: ! @@ -1594,7 +1594,7 @@ get_dwt_energy_gain(bwc_field *const field, uchar highband_flag, uint16 level) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! parameter bwc_parameter* - Structure defining a bwc parameter. ! @@ -1614,7 +1614,7 @@ get_dwt_energy_gain(bwc_field *const field, uchar highband_flag, uint16 level) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -forward_wavelet_transform(bwc_field *const field, bwc_parameter *const parameter) +forward_wavelet_transform(bwc_codec *const field, bwc_parameter *const parameter) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -2117,7 +2117,7 @@ forward_wavelet_transform(bwc_field *const field, bwc_parameter *const parameter } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar inverse_discrete_wavelet_transform(bwc_field *const field, ! +! FUNCTION NAME: uchar inverse_discrete_wavelet_transform(bwc_codec *const field, ! ! -------------- bwc_parameter *const parameter) ! ! ! ! DESCRIPTION: ! @@ -2135,7 +2135,7 @@ forward_wavelet_transform(bwc_field *const field, bwc_parameter *const parameter ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! parameter bwc_parameter* - Structure defining a bwc parameter. ! @@ -2155,7 +2155,7 @@ forward_wavelet_transform(bwc_field *const field, bwc_parameter *const parameter ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -inverse_wavelet_transform(bwc_field *const field, bwc_parameter *const parameter) +inverse_wavelet_transform(bwc_codec *const field, bwc_parameter *const parameter) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! diff --git a/src/library/libbwc.c b/src/library/libbwc.c index 7917322..83d7c9b 100755 --- a/src/library/libbwc.c +++ b/src/library/libbwc.c @@ -145,7 +145,7 @@ #endif /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uint8 initialize_precinct(bwc_field *const field, bwc_precinct *precinct, ! +! FUNCTION NAME: uint8 initialize_precinct(bwc_codec *const field, bwc_precinct *precinct, ! ! -------------- const uint32 dX, const uint32 dY, ! ! const uint32 dZ, const uint32 dTS) ! ! ! @@ -157,7 +157,7 @@ ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! precinct bwc_precinct* - Structure defining a bwc precinct. ! @@ -180,7 +180,7 @@ ! ! \*----------------------------------------------------------------------------------------------------------*/ static uint8 -initialize_precinct(bwc_field *const field, bwc_precinct *precinct, const uint32 dX, const uint32 dY, +initialize_precinct(bwc_codec *const field, bwc_precinct *precinct, const uint32 dX, const uint32 dY, const uint32 dZ, const uint32 dTS) { /*-----------------------*\ @@ -386,7 +386,7 @@ static uint8 subband_gain(const uint8 highband_flag) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar initialize_subband(bwc_field *const field, bwc_parameter *const parameter, ! +! FUNCTION NAME: uchar initialize_subband(bwc_codec *const field, bwc_parameter *const parameter, ! ! -------------- bwc_resolution *const resolution, ! ! bwc_subband *const subband, ! ! int32 resolution_level, ! @@ -403,7 +403,7 @@ static uint8 subband_gain(const uint8 highband_flag) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! parameter bwc_parameter* - Structure defining a bwc tile parameter.! @@ -433,7 +433,7 @@ static uint8 subband_gain(const uint8 highband_flag) ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -initialize_subband(bwc_field *const field, bwc_parameter *const parameter, bwc_resolution *const resolution, +initialize_subband(bwc_codec *const field, bwc_parameter *const parameter, bwc_resolution *const resolution, bwc_subband *const subband, int32 resolution_level, int16 highband_flag) @@ -684,7 +684,7 @@ initialize_subband(bwc_field *const field, bwc_parameter *const parameter, bwc_r /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void fill_buffer(bwc_field *const field, bwc_tile *const tile, ! +! FUNCTION NAME: void fill_buffer(bwc_codec *const field, bwc_tile *const tile, ! ! ------------ bwc_parameter *const parameter, ! ! bwc_sample *const working_buffer, ! ! double *const data, ! @@ -701,7 +701,7 @@ initialize_subband(bwc_field *const field, bwc_parameter *const parameter, bwc_r ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -732,9 +732,9 @@ initialize_subband(bwc_field *const field, bwc_parameter *const parameter, bwc_r ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -fill_buffer(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const parameter, +fill_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const parameter, bwc_sample *const working_buffer, - bwc_data *const data, + bwc_stream *const data, uint16 param_id) { /*-----------------------*\ @@ -760,7 +760,6 @@ fill_buffer(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const p bwc_tile_inf *tile_info; bwc_param_ctrl *param_control; bwc_param_inf *param_info; - bwc_cmd_opts_ll *param; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -776,7 +775,7 @@ fill_buffer(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const p ! structures to temporary variables to make the code more ! ! readable. ! \*--------------------------------------------------------*/ - info = field->info; + info = &field->info; tile_info = &tile->info; @@ -787,17 +786,7 @@ fill_buffer(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const p ! Calculate the offset of the current parameter in the da- ! ! ta array. ! \*--------------------------------------------------------*/ - param_offset = 0; - param = data->info.parameter->root; - - while(param != NULL && param->id < param_id) - { - if(param->precision == param_info->precision) - { - param_offset += param->size; - } - param = param -> next; - } + param_offset = info->nX * info->nY * info->nZ * info->nTS * param_id; /*--------------------------------------------------------*\ ! Associate the working buffer with the data pointer in ! @@ -824,7 +813,7 @@ fill_buffer(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const p ! Check if the parameter is single or double precision and ! ! handle the field accordingly. ! \*--------------------------------------------------------*/ - if(param_info->precision == 8) + if(info->data_prec == bwc_precision_double) { /*--------------------------------------------------------*\ ! Safe the field pointer to a temporary variable to make ! @@ -937,7 +926,7 @@ fill_buffer(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const p } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void fill_buffer(bwc_field *const field, bwc_tile *const tile, ! +! FUNCTION NAME: void fill_buffer(bwc_codec *const field, bwc_tile *const tile, ! ! ------------ bwc_parameter *const parameter, ! ! bwc_sample *const working_buffer, ! ! double *const data, ! @@ -953,7 +942,7 @@ fill_buffer(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const p ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -984,9 +973,9 @@ fill_buffer(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const p ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -flush_buffer(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const parameter, +flush_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const parameter, bwc_sample *const working_buffer, - bwc_data *const data, + bwc_stream *const data, uint16 param_id) { /*-----------------------*\ @@ -1010,7 +999,6 @@ flush_buffer(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const bwc_sample *src; bwc_gl_inf *info; bwc_param_inf *param_info; - bwc_cmd_opts_ll *param; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -1026,7 +1014,7 @@ flush_buffer(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const ! structures to temporary variables to make the code more ! ! readable. ! \*--------------------------------------------------------*/ - info = field->info; + info = &field->info; param_info = ¶meter->info; @@ -1038,17 +1026,7 @@ flush_buffer(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const ! Calculate the offset of the current parameter in the da- ! ! ta array. ! \*--------------------------------------------------------*/ - param_offset = 0; - param = data->info.parameter->root; - - while(param != NULL && param->id < param_id) - { - if(param->precision == param_info->precision) - { - param_offset += param->size; - } - param = param -> next; - } + param_offset = info->nX * info->nY * info->nZ * info->nTS * param_id; /*--------------------------------------------------------*\ ! Calculate the width, height, depth and dt of the current ! @@ -1063,7 +1041,7 @@ flush_buffer(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const ! Check if the parameter is single or double precision and ! ! handle the field accordingly. ! \*--------------------------------------------------------*/ - if(param_info->precision == 8) + if(info->data_prec == bwc_precision_double) { /*--------------------------------------------------------*\ ! Safe the field pointer to a temporary variable to make ! @@ -1150,7 +1128,7 @@ flush_buffer(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void buff_normalize(bwc_field *const field, bwc_parameter *const parameter) ! +! FUNCTION NAME: void buff_normalize(bwc_codec *const field, bwc_parameter *const parameter) ! ! ! ! ! ! DESCRIPTION: ! @@ -1187,7 +1165,7 @@ flush_buffer(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -normalize_param(bwc_field *const field, bwc_parameter *const parameter) +normalize_param(bwc_codec *const field, bwc_parameter *const parameter) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1275,7 +1253,7 @@ normalize_param(bwc_field *const field, bwc_parameter *const parameter) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void denormalize_param(bwc_field *const field, bwc_parameter *const parameter) ! +! FUNCTION NAME: void denormalize_param(bwc_codec *const field, bwc_parameter *const parameter) ! ! ! ! ! ! DESCRIPTION: ! @@ -1312,7 +1290,7 @@ normalize_param(bwc_field *const field, bwc_parameter *const parameter) ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -denormalize_param(bwc_field *const field, bwc_parameter *const parameter) +denormalize_param(bwc_codec *const field, bwc_parameter *const parameter) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1404,31 +1382,30 @@ denormalize_param(bwc_field *const field, bwc_parameter *const parameter) || || \************************************************************************************************************/ /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bwc_field *bwc_initialize_data(...) ! +! FUNCTION NAME: bwc_codec *bwc_initialize_data(...) ! ! -------------- ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function initializes the bwc_data structure with all necessary parameters. ! +! This function initializes the bwc_stream structure with all necessary parameters. ! ! ! ! PARAMETERS: ! ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! +! prec bwc_precision - Input data precision ! +! ! ! nX ,nY, nZ unsigned int(64 bit) - Number of spatial Datapoints ! ! ! ! nTS unsigned int(16 bit) - Number of Timesteps. ! ! ! ! nPar unsigned int(8 bit) - Number of Parameters ! ! ! -! file_extension char* - File extension associated ! -! with the numerical dataset. ! -! ! ! RETURN VALUE: ! ! ------------- ! ! Type Description ! ! ---- ----------- ! -! bwc_data* - Structure used to store a numerical ! +! bwc_stream* - Structure used to store a numerical ! ! dataset/compressed bitstream. ! ! ! ! DEVELOPMENT HISTORY: ! @@ -1439,16 +1416,15 @@ denormalize_param(bwc_field *const field, bwc_parameter *const parameter) ! 09.06.2021 Patrick Vogler B87D120 V 0.1.0 function created ! ! ! \*----------------------------------------------------------------------------------------------------------*/ -bwc_data* -bwc_initialize_data(double* field, uint64 const nX, uint64 const nY, uint64 const nZ, uint16 const nTS, uint8 const nPar, char *file_extension) +bwc_stream* +bwc_initialize_data(void *const data, bwc_precision const prec) { /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - bwc_gl_inf *info; - bwc_data *file; + bwc_stream *file; - file = calloc(1, sizeof(bwc_data)); + file = calloc(1, sizeof(bwc_stream)); if(!file) { // memory allocation error @@ -1456,137 +1432,18 @@ bwc_initialize_data(double* field, uint64 const nX, uint64 const nY, uint64 cons return NULL; } - info = &file->info; - - info->nX = nX; - info->nY = nY; - info->nZ = nZ; - info->nTS = nTS; - info->nPar = nPar; - memcpy(&info->f_ext, file_extension, sizeof(char) * 19); - - file->field.d = field; + if (prec == bwc_precision_double) + { + file->field.d = (double *)data; + } + else if (prec == bwc_precision_single) + { + file->field.f = (float *)data; + } return file; } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_add_param(bwc_data* data, char *name, uint16 sample, uchar dim, uint8 precision) ! -! -------------- ! -! ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function initializes and adds new parameters to the parameter linked list. The linked ! -! list stores the parameter name, its precision, sampling factor and the dimension for which ! -! the sampling is active. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! name char* - Name of parameter(id). ! -! ! -! sample unsigned int(16 bit) - Sampling factor for parameter(id). ! -! ! -! dim unsigned char - Dimension(s) for which the sampling ! -! factor is active. ! -! ! -! precision unsigned int(8 bit) - Bit precision of the parameter. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 19.10.2017 Patrick Vogler B87D120 V 0.1.0 function created ! -! 03.12.2019 Patrick Vogler B87E7E4 V 0.1.0 redefined the function for the ! -! bwc_data structure. ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ -void -bwc_add_param(bwc_data* data, char *name, uint8 precision) -{ - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - bwc_gl_inf *info; - - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(data); - - /*--------------------------------------------------------*\ - ! Save the global info structure to a temporary variable ! - ! to make the code more readable. ! - \*--------------------------------------------------------*/ - info = &data->info; - - /*--------------------------------------------------------*\ - ! Check if the specified parameter name has the proper ! - ! length. ! - \*--------------------------------------------------------*/ - if((strlen(name) > 24) && name) - { - fprintf(stderr, "o==========================================================o\n"\ - "| WARNING: Invalid parameter name: %-24s|\n"\ - "| |\n"\ - "| Parameter names cannot exceed 24 characters. |\n"\ - "| |\n"\ - "o==========================================================o\n",name); - } - - /*--------------------------------------------------------*\ - ! Check if the parameter structure has already been allo- ! - ! cated. ! - \*--------------------------------------------------------*/ - if(info->parameter == NULL) - { - /*--------------------------------------------------------*\ - ! If the bwc_add_param function is called for the first ! - ! time, allocate the parameter structure and save the root ! - ! node address. ! - \*--------------------------------------------------------*/ - info->parameter = calloc(1, sizeof(bwc_cmd_opts_ll)); - info->parameter->root = info->parameter; - } - else - { - /*--------------------------------------------------------*\ - ! If a new parameter is added, allocate the nex linked ! - ! list node, save the root node address in its structure ! - ! and set the linked list access pointer to the new node. ! - \*--------------------------------------------------------*/ - info->parameter->next = calloc(1, sizeof(bwc_cmd_opts_ll)); - info->parameter->next->root = info->parameter->root; - info->parameter->next->id = info->parameter->id + 1; - info->parameter = info->parameter->next; - } - - /*--------------------------------------------------------*\ - ! Save the name of the new parameter its precision in the ! - ! structure of the new node. ! - \*--------------------------------------------------------*/ - strcpy(info->parameter->name, name ? name : "undefined"); - info->parameter->precision = precision ? precision : PREC_BYTE; - - /*--------------------------------------------------------*\ - ! Evaluate the parameter size the information in the ! - ! linked list. ! - \*--------------------------------------------------------*/ - info->parameter->size = (info->nX * info->nY * info->nZ * info->nTS); -} - /*----------------------------------------------------------------------------------------------------------*\ ! FUNCTION NAME: ! ! -------------- ! @@ -1597,7 +1454,7 @@ bwc_add_param(bwc_data* data, char *name, uint8 precision) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -bwc_set_com(bwc_data *const data, char const *const com, uint16 size) +bwc_set_com(bwc_stream *const data, char const *const com, uint16 size) { /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -1635,7 +1492,7 @@ bwc_set_com(bwc_data *const data, char const *const com, uint16 size) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -bwc_set_aux(bwc_data *const data, char const *const aux, uint32 size) +bwc_set_aux(bwc_stream *const data, char const *const aux, uint32 size) { /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -1664,60 +1521,7 @@ bwc_set_aux(bwc_data *const data, char const *const aux, uint32 size) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bwc_field *bwc_initialize_data(...) ! -! -------------- ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function is used to copy the numerical dataset stored in the bwc_data ! -! structure to a user supplied memory block. A size argument is necessary ! -! to verify that the memory block has the correct size. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! data bwc_data* - Structure used to store a numerical ! -! dataset/compressed bitstream. ! -! ! -! buffer unsigned char* - Memory block supplied by ! -! the function caller. ! -! ! -! data bwc_data* - Size of memory block. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 09.06.2021 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ -void -bwc_get_data(bwc_data* data, uchar* buffer, uint64 size) -{ - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - - if(size != (uint64)(data->info.nX * data->info.nY * data->info.nZ * data->info.nTS * data->info.nPar)) - { - fprintf(stderr, "Incorrect buffer size\n"); - } - else - { - memcpy(buffer, data->field.d, size * sizeof(double)); - } -} - -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_free_data(bwc_data* file) ! +! FUNCTION NAME: void bwc_free_data(bwc_stream* file) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -1731,7 +1535,7 @@ bwc_get_data(bwc_data* data, uchar* buffer, uint64 size) ! ! ! Variable Type Description ! ! -------- ---- ----------- ! -! file bwc_data - Defines a structure used to store all ! +! file bwc_stream - Defines a structure used to store all ! ! the relevant parameters and the data ! ! field of a numerical dataset or com- ! ! pressed codestream. ! @@ -1753,57 +1557,33 @@ bwc_get_data(bwc_data* data, uchar* buffer, uint64 size) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_free_data(bwc_data* data) +bwc_free_data(bwc_stream* data) { - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - bwc_cmd_opts_ll *param, *temp; - if(data) { - if(data->info.parameter) + if(data->codestream.data) { - param = data->info.parameter->root; - - while(param != NULL) - { - temp = param; - param = param -> next; - free(temp); - } + release_packed_stream(data->codestream.data); } - - if(data) + if(data->codestream.aux) { - if(data->codestream.data) - { - release_packed_stream(data->codestream.data); - } - if(data->codestream.aux) - { - release_packed_stream(data->codestream.aux); - } - if(data->codestream.com) - { - release_packed_stream(data->codestream.com); - } - if(data->fp) - { - fclose(data->fp); - } - free(data->codestream.data); - free(data->codestream.aux); - free(data->codestream.com); - free(data->field.d); - free(data->field.f); - free(data); + release_packed_stream(data->codestream.aux); } + if(data->codestream.com) + { + release_packed_stream(data->codestream.com); + } + free(data->codestream.data); + free(data->codestream.aux); + free(data->codestream.com); + free(data->field.d); + free(data->field.f); + free(data); } } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar create_field(bwc_field *const field) ! +! FUNCTION NAME: uchar create_field(bwc_codec *const field) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -1815,7 +1595,7 @@ bwc_free_data(bwc_data* data) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! RETURN VALUE: ! @@ -1833,7 +1613,7 @@ bwc_free_data(bwc_data* data) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -create_field(bwc_field *const field) +create_field(bwc_codec *const field) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1856,7 +1636,6 @@ create_field(bwc_field *const field) \*-----------------------*/ bwc_gl_ctrl *control; bwc_gl_inf *info; - bwc_cmd_opts_ll *param; bwc_parameter *parameter; bwc_param_ctrl *param_control; bwc_param_inf *param_info; @@ -1878,7 +1657,7 @@ create_field(bwc_field *const field) ! variables to make the code more readable. ! \*--------------------------------------------------------*/ control = &field->control; - info = field->info; + info = &field->info; /*--------------------------------------------------------*\ ! Calculate the number of tiles in all spatial and tempo- ! @@ -1965,23 +1744,8 @@ create_field(bwc_field *const field) return 1; } - /*--------------------------------------------------------*\ - ! Initialize the parameter information linked listed. ! - \*--------------------------------------------------------*/ - param = info->parameter->root; - for(j = 0; j < info->nPar; ++j) { - /*--------------------------------------------------------*\ - ! Check if there is a node in the parameter information ! - ! linked list corresponding to the current paramter. ! - \*--------------------------------------------------------*/ - if(!param && (param->id == j)) - { - fprintf(stderr, MEMERROR); - return 1; - } - /*--------------------------------------------------------*\ ! Save the parameter and its info and control structure to ! ! temporary variables to make the code more readable. ! @@ -1990,13 +1754,6 @@ create_field(bwc_field *const field) param_control = ¶meter->control; param_info = ¶meter->info; - /*--------------------------------------------------------*\ - ! Save the corresponding parameter name and its sampling ! - ! factors and precision in the info and control structures.! - \*--------------------------------------------------------*/ - param_info->name = param->name; - param_info->precision = param->precision; - /*--------------------------------------------------------*\ ! Initialize the number of codeblocks for the current ! ! parameter. ! @@ -2199,12 +1956,6 @@ create_field(bwc_field *const field) } } } - - /*--------------------------------------------------------*\ - ! Advance the parameter information linked listed to the ! - ! next node. ! - \*--------------------------------------------------------*/ - param = param->next; } /*--------------------------------------------------------*\ @@ -2236,7 +1987,7 @@ create_field(bwc_field *const field) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void kill_compression(bwc_field *const field) ! +! FUNCTION NAME: void kill_compression(bwc_codec *const field) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -2251,7 +2002,7 @@ create_field(bwc_field *const field) ! ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! RETURN VALUE: ! @@ -2269,7 +2020,7 @@ create_field(bwc_field *const field) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_kill_compression(bwc_field *const field) +bwc_kill_compression(bwc_codec *const field) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -2292,7 +2043,7 @@ bwc_kill_compression(bwc_field *const field) ! variables to make the code more readable. ! \*--------------------------------------------------------*/ control = &field->control; - info = field->info; + info = &field->info; if(field->tile) { @@ -2356,12 +2107,12 @@ bwc_kill_compression(bwc_field *const field) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bwc_field *bwc_initialize_field(bwc_data *const data) ! +! FUNCTION NAME: bwc_codec *bwc_initialize_field(bwc_stream *const data) ! ! -------------- ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function initializes the bwc_field structure with all necessary standard parameters ! +! This function initializes the bwc_codec structure with all necessary standard parameters ! ! to (de)compress a floating point array with nX * nY * nZ grid points, nTS timesteps and ! ! nPar parameters. ! ! ! @@ -2376,7 +2127,7 @@ bwc_kill_compression(bwc_field *const field) ! ------------- ! ! Type Description ! ! ---- ----------- ! -! bwc_field* Defines the (de)compression data structure. ! +! bwc_codec* Defines the (de)compression data structure. ! ! ! ! DEVELOPMENT HISTORY: ! ! -------------------- ! @@ -2386,8 +2137,8 @@ bwc_kill_compression(bwc_field *const field) ! 14.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! ! ! \*----------------------------------------------------------------------------------------------------------*/ -bwc_field* -bwc_initialize_field(bwc_data *const data) +bwc_codec* +bwc_initialize_field(bwc_precision const prec, uint64 const nX, uint64 const nY, uint64 const nZ, uint16 const nTS, uint8 const nPar) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -2409,7 +2160,7 @@ bwc_initialize_field(bwc_data *const data) /*--------------------------------------------------------*\ ! Allocate the root compression data structure. ! \*--------------------------------------------------------*/ - bwc_field *field = calloc(1, sizeof(bwc_field)); + bwc_codec *field = calloc(1, sizeof(bwc_codec)); if(!field) { // memory allocation error @@ -2423,7 +2174,23 @@ bwc_initialize_field(bwc_data *const data) ! variables to make the code more readable. ! \*--------------------------------------------------------*/ control = &field->control; - info = field->info = &data->info; + info = &field->info; + + info->nX = nX; + info->nY = nY; + info->nZ = nZ; + info->nTS = nTS; + info->nPar = nPar; + info->data_prec = prec; + + /*--------------------------------------------------------*\ + ! Save the codec precision in the info structure. ! + \*--------------------------------------------------------*/ +#if PREC_BYTE == 8 + info->codec_prec = bwc_precision_double; +#elif PREC_BYTE == 4 + info->codec_prec = bwc_precision_single; +#endif /*--------------------------------------------------------*\ ! Set all tile sizes to their maximum allowable value. The ! @@ -2479,11 +2246,6 @@ bwc_initialize_field(bwc_data *const data) control->bitrate = 0; control->guard_bits = 2; - /*--------------------------------------------------------*\ - ! Save the codec precision in the info structure. ! - \*--------------------------------------------------------*/ - info->precision = PREC_BYTE; - /*--------------------------------------------------------*\ ! Calculate the possible decomposition levels for all ! ! spatial and temporal dimensions. ! @@ -2553,19 +2315,19 @@ bwc_initialize_field(bwc_data *const data) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_error_resilience(bwc_field *const field) ! +! FUNCTION NAME: void bwc_set_error_resilience(bwc_codec *const field) ! ! -------------- ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function sets the error resilience marker in the bwc_field structure if an error ! +! This function sets the error resilience marker in the bwc_codec structure if an error ! ! resilient compression approach is to be employed. ! ! ! ! PARAMETERS: ! ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! RETURN VALUE: ! @@ -2583,7 +2345,7 @@ bwc_initialize_field(bwc_data *const data) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_set_error_resilience(bwc_field *const field) +bwc_set_error_resilience(bwc_codec *const field) { /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -2602,7 +2364,7 @@ bwc_set_error_resilience(bwc_field *const field) control = &field->control; /*--------------------------------------------------------*\ - ! Amend the codeblock style in the bwc_field structure ! + ! Amend the codeblock style in the bwc_codec structure ! ! according to the specified value. ! \*--------------------------------------------------------*/ control->error_resilience ^= 0x01; @@ -2615,19 +2377,19 @@ bwc_set_error_resilience(bwc_field *const field) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_quant_style(bwc_field *const field, bwc_quant_st quantization_style) ! +! FUNCTION NAME: void bwc_set_quant_style(bwc_codec *const field, bwc_quant_st quantization_style) ! ! -------------- ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function amends the quantization style in the bwc_field structure according to the ! +! This function amends the quantization style in the bwc_codec structure according to the ! ! specified value. ! ! ! ! PARAMETERS: ! ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! quantization_style bwc_quant_st - Quantization style used during compres- ! @@ -2648,7 +2410,7 @@ bwc_set_error_resilience(bwc_field *const field) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -set_quant_style(bwc_field *const field, bwc_quant_st quantization_style) +set_quant_style(bwc_codec *const field, bwc_quant_st quantization_style) { /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -2668,7 +2430,7 @@ set_quant_style(bwc_field *const field, bwc_quant_st quantization_style) control = &field->control; /*--------------------------------------------------------*\ - ! Amend the quantization style in the bwc_field structure ! + ! Amend the quantization style in the bwc_codec structure ! ! according to the specified value. ! \*--------------------------------------------------------*/ control->quantization_style = quantization_style; @@ -2681,19 +2443,19 @@ set_quant_style(bwc_field *const field, bwc_quant_st quantization_style) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_quant_step_size(bwc_field *const field, double delta) ! +! FUNCTION NAME: void bwc_set_quant_step_size(bwc_codec *const field, double delta) ! ! -------------- ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function amends the quantization step size in the bwc_field structure according to ! +! This function amends the quantization step size in the bwc_codec structure according to ! ! the specified value. ! ! ! ! PARAMETERS: ! ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! delta double - Quantization step size used during ! @@ -2714,7 +2476,7 @@ set_quant_style(bwc_field *const field, bwc_quant_st quantization_style) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -set_quant_step_size(bwc_field *const field, double delta) +set_quant_step_size(bwc_codec *const field, double delta) { /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -2785,19 +2547,19 @@ set_quant_step_size(bwc_field *const field, double delta) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_progression(bwc_field *const field, bwc_prog_ord progression) ! +! FUNCTION NAME: void bwc_set_progression(bwc_codec *const field, bwc_prog_ord progression) ! ! -------------- ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function amends the progression order in the bwc_field structure according to the ! +! This function amends the progression order in the bwc_codec structure according to the ! ! specified value. ! ! ! ! PARAMETERS: ! ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! progression bwc_prog_ord - Progression orders employed during com- ! @@ -2819,7 +2581,7 @@ set_quant_step_size(bwc_field *const field, double delta) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -set_progression(bwc_field *const field, bwc_prog_ord progression) +set_progression(bwc_codec *const field, bwc_prog_ord progression) { /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -2841,7 +2603,7 @@ set_progression(bwc_field *const field, bwc_prog_ord progression) control = &field->control; /*--------------------------------------------------------*\ - ! Amend the progression order in the bwc_field structure ! + ! Amend the progression order in the bwc_codec structure ! ! according to the specified value. ! \*--------------------------------------------------------*/ control->progression = progression; @@ -2854,21 +2616,21 @@ set_progression(bwc_field *const field, bwc_prog_ord progression) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_kernels(bwc_field *const field, bwc_dwt_filter KernelX, ! +! FUNCTION NAME: void bwc_set_kernels(bwc_codec *const field, bwc_dwt_filter KernelX, ! ! -------------- bwc_dwt_filter KernelY, ! ! bwc_dwt_filter KernelZ, ! ! bwc_dwt_filter KernelTS) ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function amends the wavelet kernels in the bwc_field structure according to the ! +! This function amends the wavelet kernels in the bwc_codec structure according to the ! ! specified values. ! ! ! ! PARAMETERS: ! ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! KernelX, KernelY, KernelZ bwc_dwt_filter - Wavelet kernels used for spatial ! @@ -2892,7 +2654,7 @@ set_progression(bwc_field *const field, bwc_prog_ord progression) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -set_kernels(bwc_field *const field, bwc_dwt_filter KernelX, bwc_dwt_filter KernelY, +set_kernels(bwc_codec *const field, bwc_dwt_filter KernelX, bwc_dwt_filter KernelY, bwc_dwt_filter KernelZ, bwc_dwt_filter KernelTS) { /*-----------------------*\ @@ -2912,7 +2674,7 @@ set_kernels(bwc_field *const field, bwc_dwt_filter KernelX, bwc_dwt_filter Kerne control = &field->control; /*--------------------------------------------------------*\ - ! Amend the wavelet kernels in the bwc_field structure ac- ! + ! Amend the wavelet kernels in the bwc_codec structure ac- ! ! cording to the specified values. For all unspecified ! ! (NULL) values the corresponding wavelet kernel is set to ! ! bwc_dwt_9_7/bwc_dwt_haar. ! @@ -2930,19 +2692,19 @@ set_kernels(bwc_field *const field, bwc_dwt_filter KernelX, bwc_dwt_filter Kerne } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_decomp(bwc_field *const field, uint8 decompX, uint8 decompY, ! +! FUNCTION NAME: void bwc_set_decomp(bwc_codec *const field, uint8 decompX, uint8 decompY, ! ! -------------- uint8 decompZ, uint8 decompTS) ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function amends the decomposition levels in the bwc_field structure according to the ! +! This function amends the decomposition levels in the bwc_codec structure according to the ! ! specified values. ! ! ! ! PARAMETERS: ! ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! decompX, decompY, decompZ unsigned int(8 bit) - Number of spatial wavelet decomposition ! @@ -2966,7 +2728,7 @@ set_kernels(bwc_field *const field, bwc_dwt_filter KernelX, bwc_dwt_filter Kerne ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_set_decomp(bwc_field *const field, uint8 decompX, uint8 decompY, uint8 decompZ, uint8 decompTS) +bwc_set_decomp(bwc_codec *const field, uint8 decompX, uint8 decompY, uint8 decompZ, uint8 decompTS) { /*-----------------------*\ ! DEFINE FLOAT VARIABLES: ! @@ -2994,7 +2756,7 @@ bwc_set_decomp(bwc_field *const field, uint8 decompX, uint8 decompY, uint8 decom ! variables to make the code more readable. ! \*--------------------------------------------------------*/ control = &field->control; - info = field->info; + info = &field->info; /*--------------------------------------------------------*\ ! Calculate the possible decomposition levels for all ! @@ -3098,19 +2860,19 @@ bwc_set_decomp(bwc_field *const field, uint8 decompX, uint8 decompY, uint8 decom } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_precincts(bwc_field *const field, uint8 pX, uint8 pY, uint8 pZ, uint8 pTS) ! +! FUNCTION NAME: void bwc_set_precincts(bwc_codec *const field, uint8 pX, uint8 pY, uint8 pZ, uint8 pTS) ! ! -------------- ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function amends the precinct size in the bwc_field structure according to the ! +! This function amends the precinct size in the bwc_codec structure according to the ! ! specified values. ! ! ! ! PARAMETERS: ! ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! px, py, pz, pTS unsigned int(8 bit) - Spatial and temporal precinct dimensions! @@ -3131,7 +2893,7 @@ bwc_set_decomp(bwc_field *const field, uint8 decompX, uint8 decompY, uint8 decom ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_set_precincts(bwc_field *const field, uint8 pX, uint8 pY, uint8 pZ, uint8 pTS) +bwc_set_precincts(bwc_codec *const field, uint8 pX, uint8 pY, uint8 pZ, uint8 pTS) { /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -3149,7 +2911,7 @@ bwc_set_precincts(bwc_field *const field, uint8 pX, uint8 pY, uint8 pZ, uint8 pT ! variables to make the code more readable. ! \*--------------------------------------------------------*/ control = &field->control; - info = field->info; + info = &field->info; /*--------------------------------------------------------*\ ! Check if the precinct sizes are specified for a valid ! @@ -3199,19 +2961,19 @@ bwc_set_precincts(bwc_field *const field, uint8 pX, uint8 pY, uint8 pZ, uint8 pT } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_codeblocks(bwc_field *const field, uint8 cbX, uint8 cbY, ! +! FUNCTION NAME: void bwc_set_codeblocks(bwc_codec *const field, uint8 cbX, uint8 cbY, ! ! -------------- uint8 cbZ, uint8 cbTS) ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function amends the codeblock size in the bwc_field structure according to the ! +! This function amends the codeblock size in the bwc_codec structure according to the ! ! specified values. ! ! ! ! PARAMETERS: ! ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! cbx, cby, cbz, cbTS unsigned int(8 bit) - Spatial and temporal codeblock dimen- ! @@ -3232,7 +2994,7 @@ bwc_set_precincts(bwc_field *const field, uint8 pX, uint8 pY, uint8 pZ, uint8 pT ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_set_codeblocks(bwc_field *const field, uint8 cbX, uint8 cbY, uint8 cbZ, uint8 cbTS) +bwc_set_codeblocks(bwc_codec *const field, uint8 cbX, uint8 cbY, uint8 cbZ, uint8 cbTS) { /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -3250,7 +3012,7 @@ bwc_set_codeblocks(bwc_field *const field, uint8 cbX, uint8 cbY, uint8 cbZ, uint ! variables to make the code more readable. ! \*--------------------------------------------------------*/ control = &field->control; - info = field->info; + info = &field->info; /*--------------------------------------------------------*\ ! Check if the codeblock sizes are specified for a valid ! @@ -3300,19 +3062,19 @@ bwc_set_codeblocks(bwc_field *const field, uint8 cbX, uint8 cbY, uint8 cbZ, uint } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_qm(bwc_field *const field, uint8 Qm) ! +! FUNCTION NAME: void bwc_set_qm(bwc_codec *const field, uint8 Qm) ! ! -------------- ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function amends the Q number formate range in the bwc_field structure according to the ! +! This function amends the Q number formate range in the bwc_codec structure according to the ! ! specified value. ! ! ! ! PARAMETERS: ! ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! Qm unsigned int(8 bit) - Q number formate range (m). ! @@ -3332,7 +3094,7 @@ bwc_set_codeblocks(bwc_field *const field, uint8 cbX, uint8 cbY, uint8 cbZ, uint ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_set_qm(bwc_field *const field, uint8 Qm) +bwc_set_qm(bwc_codec *const field, uint8 Qm) { /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -3352,7 +3114,7 @@ bwc_set_qm(bwc_field *const field, uint8 Qm) /*--------------------------------------------------------*\ ! Check if the Q number formate range is valid and amend ! - ! the bwc_field structure accordingly. ! + ! the bwc_codec structure accordingly. ! \*--------------------------------------------------------*/ if((int8)(PREC_BIT - Qm) < 2) { @@ -3381,12 +3143,12 @@ bwc_set_qm(bwc_field *const field, uint8 Qm) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_tiles(bwc_field *const field, uint32 tilesX, uint32 tilesY, uint32 tilesZ, ! +! FUNCTION NAME: void bwc_set_tiles(bwc_codec *const field, uint32 tilesX, uint32 tilesY, uint32 tilesZ, ! ! -------------- uint32 tilesTS, uchar instr) ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function amends the tileSize and num_Tiles values in the bwc_field structure according ! +! This function amends the tileSize and num_Tiles values in the bwc_codec structure according ! ! to the specified values. The NUMBEROF and SIZEOF constants can be used to either specify ! ! the tile sizes or the number of tiles in each spatial and temporal directions. ! ! ! @@ -3394,7 +3156,7 @@ bwc_set_qm(bwc_field *const field, uint8 Qm) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tilesX, tilesY, tilesZ unsigned int(32 bit) - Variables defining the size of ! @@ -3421,7 +3183,7 @@ bwc_set_qm(bwc_field *const field, uint8 Qm) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_set_tiles(bwc_field *const field, uint64 tilesX, uint64 tilesY, uint64 tilesZ, uint16 tilesTS, bwc_tile_instr instr) +bwc_set_tiles(bwc_codec *const field, uint64 tilesX, uint64 tilesY, uint64 tilesZ, uint16 tilesTS, bwc_tile_instr instr) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -3446,7 +3208,7 @@ bwc_set_tiles(bwc_field *const field, uint64 tilesX, uint64 tilesY, uint64 tiles ! variables to make the code more readable. ! \*--------------------------------------------------------*/ control = &field->control; - info = field->info; + info = &field->info; /*--------------------------------------------------------*\ ! Check if the size of one tile or the overall number of ! @@ -3609,7 +3371,7 @@ bwc_set_tiles(bwc_field *const field, uint64 tilesX, uint64 tilesY, uint64 tiles } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_create_compression(bwc_field *field, char *rate_control) ! +! FUNCTION NAME: void bwc_create_compression(bwc_codec *field, char *rate_control) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -3625,7 +3387,7 @@ bwc_set_tiles(bwc_field *const field, uint64 tilesX, uint64 tilesY, uint64 tiles ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! rate_control char* - Variable defining the bitrate. ! @@ -3646,7 +3408,7 @@ bwc_set_tiles(bwc_field *const field, uint64 tilesX, uint64 tilesY, uint64 tiles ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -bwc_create_compression(bwc_field *field, char *rate_control) +bwc_create_compression(bwc_codec *codec, bwc_stream *stream, char *rate_control) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -3673,14 +3435,14 @@ bwc_create_compression(bwc_field *field, char *rate_control) /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); /*--------------------------------------------------------*\ ! Save the global control structure to a temporary varia- ! ! ble to make the code more readable. ! \*--------------------------------------------------------*/ - info = field->info; - control = &field->control; + info = &codec->info; + control = &codec->control; /*--------------------------------------------------------*\ ! Allocate the array used to hold the quality layer bit- ! @@ -3767,10 +3529,10 @@ bwc_create_compression(bwc_field *field, char *rate_control) control->bitrate = realloc(control->bitrate, control->nLayers * sizeof(float)); /*--------------------------------------------------------*\ - ! Create the field structure used to compress a floating ! + ! Create the codec structure used to compress a floating ! ! point array defined by the bwc_initialize function. ! \*--------------------------------------------------------*/ - if(create_field(field)) + if(create_field(codec)) { return 1; } @@ -3778,17 +3540,17 @@ bwc_create_compression(bwc_field *field, char *rate_control) /*--------------------------------------------------------*\ ! Evaluate the size of the main header. ! \*--------------------------------------------------------*/ - /*control->headerSize = 108 + info->nPar * (25 + control->nTiles * 2 * PREC_BYTE) - + control->nLayers * 4; + control->headerSize = 99 + info->nPar * control->nTiles * 2 * PREC_BYTE + + control->nLayers * 4; - if(field->aux != NULL) + if(stream->codestream.aux != NULL) { - control->headerSize += 6 + field->aux->size; + control->headerSize += 6 + stream->codestream.aux->size; } - if(field->com != NULL) + if(stream->codestream.com != NULL) { - control->headerSize += 6 + field->com->size; + control->headerSize += 6 + stream->codestream.com->size; } if(control->headerSize >= 0xFFFFFFFF) @@ -3803,13 +3565,13 @@ bwc_create_compression(bwc_field *field, char *rate_control) "o==========================================================o\n"); return 1; - }*/ + } return 0; } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar bwc_compress(bwc_field *const field, bwc_float *const data) ! +! FUNCTION NAME: uchar bwc_compress(bwc_codec *const field, bwc_float *const data) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -3820,7 +3582,7 @@ bwc_create_compression(bwc_field *field, char *rate_control) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! RETURN VALUE: ! @@ -3838,7 +3600,7 @@ bwc_create_compression(bwc_field *field, char *rate_control) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -bwc_compress(bwc_field *const field, bwc_data *const data) +bwc_compress(bwc_codec *const field, bwc_stream *const data) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -3902,39 +3664,7 @@ bwc_compress(bwc_field *const field, bwc_data *const data) ! variables to make the code more readable. ! \*--------------------------------------------------------*/ control = &field->control; - info = field->info; - - /*--------------------------------------------------------*\ - ! Evaluate the size of the main header. ! - \*--------------------------------------------------------*/ - control->headerSize = 108 + info->nPar * (25 + control->nTiles * 2 * PREC_BYTE) - + control->nLayers * 4; - - if(data->codestream.aux != NULL) - { - field->aux = data->codestream.aux; - control->headerSize += 6 + field->aux->size; - } - - if(data->codestream.com != NULL) - { - field->com = data->codestream.com; - control->headerSize += 6 + field->com->size; - } - - if(control->headerSize >= 0xFFFFFFFF) - { - fprintf(stderr,"o==========================================================o\n"\ - "| ERROR: Main header exceeds maximum size limit |\n"\ - "| |\n"\ - "| Appending the auxiliary information to the main |\n"\ - "| header would exceed its maximum size limit of |\n"\ - "| 4294967295 bytes. |\n"\ - "| |\n"\ - "o==========================================================o\n"); - - return 1; - } + info = &field->info; /*--------------------------------------------------------*\ ! Evaluate the working buffer size and allocate it accord- ! @@ -4107,7 +3837,7 @@ bwc_compress(bwc_field *const field, bwc_data *const data) start = (double)clock(); #endif #endif - data->codestream.data = assemble_codestream(field); + data->codestream.data = assemble_codestream(field, data); if(!data->codestream.data) { free(working_buffer); @@ -4138,7 +3868,7 @@ bwc_compress(bwc_field *const field, bwc_data *const data) ttl = ((double)clock() - ttl)/CLOCKS_PER_SEC; #endif - nfs = (uint64)(info->nX * info->nY * info->nZ * info->nTS * info->nPar * info->precision); + nfs = (uint64)(info->nX * info->nY * info->nZ * info->nTS * info->nPar * info->data_prec); css = (uint64)data->codestream.data->size; @@ -4165,7 +3895,7 @@ bwc_compress(bwc_field *const field, bwc_data *const data) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar bwc_create_compression(bwc_field *field_ptr, char *rate_control, uchar instr) ! +! FUNCTION NAME: uchar bwc_create_compression(bwc_codec *field_ptr, char *rate_control, uchar instr) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -4177,7 +3907,7 @@ bwc_compress(bwc_field *const field, bwc_data *const data) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! rate_control (opt) char* - Variable defining the bitrate/accuracy. ! @@ -4199,13 +3929,13 @@ bwc_compress(bwc_field *const field, bwc_data *const data) ! 15.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! ! ! \*----------------------------------------------------------------------------------------------------------*/ -bwc_field * -bwc_create_decompression(bwc_data *const data, uint8 layer) +bwc_codec * +bwc_create_decompression(bwc_stream *const data, uint8 layer) { /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - bwc_field *field; + bwc_codec *field; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -4229,7 +3959,7 @@ bwc_create_decompression(bwc_data *const data, uint8 layer) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar bwc_create_compression(bwc_field *field, float rate_control, uchar instr) ! +! FUNCTION NAME: uchar bwc_create_compression(bwc_codec *field, float rate_control, uchar instr) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -4244,7 +3974,7 @@ bwc_create_decompression(bwc_data *const data, uint8 layer) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! rate_control float - Variable defining the bitrate/accuracy. ! @@ -4267,13 +3997,13 @@ bwc_create_decompression(bwc_data *const data, uint8 layer) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -bwc_decompress(bwc_field *const field, bwc_data *const data) +bwc_decompress(bwc_codec *const field, bwc_stream *const data) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! \*-----------------------*/ uint64 buff_size; - uint64 single_size, double_size; + uint64 data_size; uint64 i; uint16 p; @@ -4300,7 +4030,6 @@ bwc_decompress(bwc_field *const field, bwc_data *const data) bwc_tile *tile; bwc_parameter *parameter; bwc_sample *working_buffer; - bwc_cmd_opts_ll *param; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -4324,40 +4053,30 @@ bwc_decompress(bwc_field *const field, bwc_data *const data) ! variables to make the code more readable. ! \*--------------------------------------------------------*/ control = &field->control; - info = field->info; + info = &field->info; - /*--------------------------------------------------------*\ - ! Calculate the field size after subsampling and allocate ! - ! the field memory blocks. ! - \*--------------------------------------------------------*/ - if(data->info.parameter) + data_size = info->nX * info->nY * info->nZ * info->nTS * info->nPar; + if(info->data_prec == bwc_precision_double) { - param = data->info.parameter->root; - double_size = - single_size = 0; - - while(param != NULL) - { - if(param->precision == 8) - { - double_size += param->size; - } - else if (param->precision == 4) - { - single_size += param->size; - } - - param = param -> next; - } + data->field.d = calloc(data_size, sizeof(double)); + data->field.f = calloc(0, sizeof(float)); + if(!data->field.d) + { + // memory allocation error + fprintf(stderr, MEMERROR); + return 1; + } } - - data->field.d = calloc(double_size, sizeof(double)); - data->field.f = calloc(single_size, sizeof(float)); - if(!data->field.d || !data->field.f) + else if (info->data_prec == bwc_precision_single) { - // memory allocation error - fprintf(stderr, MEMERROR); - return 1; + data->field.d = calloc(0, sizeof(double)); + data->field.f = calloc(data_size, sizeof(float)); + if(!data->field.f) + { + // memory allocation error + fprintf(stderr, MEMERROR); + return 1; + } } /*--------------------------------------------------------*\ @@ -4528,4 +4247,4 @@ bwc_decompress(bwc_field *const field, bwc_data *const data) return 0; -} \ No newline at end of file +} diff --git a/src/library/tier1.c b/src/library/tier1.c index 60abda2..79a09e8 100755 --- a/src/library/tier1.c +++ b/src/library/tier1.c @@ -16,7 +16,7 @@ || ------------ || || || || This file describes a set of functions that can be used to de-/encode bwc || -|| codeblocks described by the bwc_field structure according to the embedded block || +|| codeblocks described by the bwc_codec structure according to the embedded block || || coding paradigm described by the JPEG 2000 standard. For more information please || || refere to JPEG2000 by D. S. Taubman and M. W. Marcellin. || || || @@ -2274,7 +2274,7 @@ compute_convex_hull(bwc_encoded_cblk *const encoded_codeblock, double *const mse } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bwc_encoded_cblk* encode_codeblock(bwc_field *const field, bwc_cblk_access *const access, ! +! FUNCTION NAME: bwc_encoded_cblk* encode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, ! ! -------------- bwc_coder_stripe *const codeblock, ! ! const uint64 width, ! ! const uint64 height, ! @@ -2307,7 +2307,7 @@ compute_convex_hull(bwc_encoded_cblk *const encoded_codeblock, double *const mse ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -encode_codeblock(bwc_field *const field, bwc_cblk_access *const access, +encode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, bwc_coder_stripe *const codeblock, const uint64 width, const uint64 height, @@ -2595,7 +2595,7 @@ encode_codeblock(bwc_field *const field, bwc_cblk_access *const access, } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bwc_encoded_cblk* encode_codeblock(bwc_field *const field, bwc_cblk_access *const access, ! +! FUNCTION NAME: bwc_encoded_cblk* encode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, ! ! bwc_coder_stripe *const codeblock, ! ! const uint64 width, ! ! const uint64 height, ! @@ -2628,7 +2628,7 @@ encode_codeblock(bwc_field *const field, bwc_cblk_access *const access, ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -decode_codeblock(bwc_field *const field, bwc_cblk_access *const access, +decode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, bwc_coder_stripe *const codeblock, const uint64 width, const uint64 height, @@ -2828,7 +2828,7 @@ decode_codeblock(bwc_field *const field, bwc_cblk_access *const access, ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -t1_encode(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const parameter) +t1_encode(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const parameter) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -3131,7 +3131,7 @@ t1_encode(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const par ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -t1_decode(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const parameter) +t1_decode(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const parameter) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! diff --git a/src/library/tier2.c b/src/library/tier2.c index 96ac025..5c3a08a 100755 --- a/src/library/tier2.c +++ b/src/library/tier2.c @@ -16,7 +16,7 @@ || ------------ || || || || This file describes a set of functions that can be used to de-/encode bwc || -|| codeblocks described by the bwc_field structure according to the embedded block || +|| codeblocks described by the bwc_codec structure according to the embedded block || || coding paradigm described by the JPEG 2000 standard. For more information please || || refere to JPEG2000 by D. S. Taubman and M. W. Marcellin. || || || @@ -312,7 +312,7 @@ encode_length(bitstream *const header, bwc_codeblock *const codeblock, } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void create_quality_layers(bwc_field *const field, bwc_tile *const tile) ! +! FUNCTION NAME: void create_quality_layers(bwc_codec *const field, bwc_tile *const tile) ! ! -------------- ! ! ! ! ! @@ -385,7 +385,7 @@ decode_length(bitstream *const header, bwc_codeblock *const codeblock, int8 cons } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: int64 create_packet(bwc_field *const field, bwc_tile *const tile, ! +! FUNCTION NAME: int64 create_packet(bwc_codec *const field, bwc_tile *const tile, ! ! -------------- bwc_resolution *const resolution, ! ! uint32 const prec_idx, ! ! int8 const q_layer, ! @@ -403,7 +403,7 @@ decode_length(bitstream *const header, bwc_codeblock *const codeblock, int8 cons ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -435,7 +435,7 @@ decode_length(bitstream *const header, bwc_codeblock *const codeblock, int8 cons ! ! \*----------------------------------------------------------------------------------------------------------*/ static int32 -create_packet(bwc_field *const field, bwc_tile *const tile, +create_packet(bwc_codec *const field, bwc_tile *const tile, bwc_resolution *const resolution, uint32 const prec_idx, int16 const q_layer, @@ -498,7 +498,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_stream)); + packet->body.memory = calloc(packet->body.size, sizeof(bwc_span)); if(!packet->body.memory) { // memory allocation error @@ -706,7 +706,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile, } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar create_packets(bwc_field *const field, bwc_tile *const tile) ! +! FUNCTION NAME: uchar create_packets(bwc_codec *const field, bwc_tile *const tile) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -723,7 +723,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile, ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -743,7 +743,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile, ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -create_packets(bwc_field *const field, bwc_tile *const tile) +create_packets(bwc_codec *const field, bwc_tile *const tile) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -772,7 +772,7 @@ create_packets(bwc_field *const field, bwc_tile *const tile) ! variables to make the code more readable. ! \*--------------------------------------------------------*/ control = &field->control; - info = field->info; + info = &field->info; /*--------------------------------------------------------*\ ! Iterate overall quality layers for every precinct in all ! @@ -845,7 +845,7 @@ create_packets(bwc_field *const field, bwc_tile *const tile) /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: int64 create_quality_layer(bwc_field *const field, bwc_tile *const tile, ! +! FUNCTION NAME: int64 create_quality_layer(bwc_codec *const field, bwc_tile *const tile, ! ! -------------- uint16 const threshold, ! ! int16 const q_layer, ! ! uchar const est) ! @@ -860,7 +860,7 @@ create_packets(bwc_field *const field, bwc_tile *const tile) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -888,7 +888,7 @@ create_packets(bwc_field *const field, bwc_tile *const tile) ! ! \*----------------------------------------------------------------------------------------------------------*/ static int64 -create_quality_layer(bwc_field *const field, bwc_tile *const tile, +create_quality_layer(bwc_codec *const field, bwc_tile *const tile, uint16 const threshold, int16 const q_layer, uchar const est) @@ -924,7 +924,7 @@ create_quality_layer(bwc_field *const field, bwc_tile *const tile, ! variables to make the code more readable. ! \*--------------------------------------------------------*/ control = &field->control; - info = field->info; + info = &field->info; for(j = 0, estimated_ql_size = 0; j < info->nPar; ++j) { @@ -1075,7 +1075,7 @@ create_quality_layer(bwc_field *const field, bwc_tile *const tile, /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void create_quality_layers(bwc_field *const field, bwc_tile *const tile) ! +! FUNCTION NAME: void create_quality_layers(bwc_codec *const field, bwc_tile *const tile) ! ! -------------- ! ! ! ! ! @@ -1087,7 +1087,7 @@ create_quality_layer(bwc_field *const field, bwc_tile *const tile, ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -1107,7 +1107,7 @@ create_quality_layer(bwc_field *const field, bwc_tile *const tile, ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -create_quality_layers(bwc_field *const field, bwc_tile *const tile) +create_quality_layers(bwc_codec *const field, bwc_tile *const tile) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1139,7 +1139,7 @@ create_quality_layers(bwc_field *const field, bwc_tile *const tile) ! temporary variables to make the code more readable. ! \*--------------------------------------------------------*/ control = &field->control; - info = field->info; + info = &field->info; tile_control = &tile->control; tile_info = &tile->info; @@ -1255,7 +1255,7 @@ create_quality_layers(bwc_field *const field, bwc_tile *const tile) || || \************************************************************************************************************/ /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar t2_encode(bwc_field *const field, bwc_tile *const tile) ! +! FUNCTION NAME: uchar t2_encode(bwc_codec *const field, bwc_tile *const tile) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -1269,7 +1269,7 @@ create_quality_layers(bwc_field *const field, bwc_tile *const tile) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -1289,7 +1289,7 @@ create_quality_layers(bwc_field *const field, bwc_tile *const tile) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -t2_encode(bwc_field *const field, bwc_tile *const tile) +t2_encode(bwc_codec *const field, bwc_tile *const tile) { /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -1319,7 +1319,7 @@ t2_encode(bwc_field *const field, bwc_tile *const tile) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar parse_packet(bwc_field *const field, bwc_tile *const tile, ! +! FUNCTION NAME: uchar parse_packet(bwc_codec *const field, bwc_tile *const tile, ! ! -------------- bwc_packet *const packet, ! ! uint64 const body_size) ! ! ! @@ -1332,7 +1332,7 @@ t2_encode(bwc_field *const field, bwc_tile *const tile) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! +! field bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -1356,7 +1356,7 @@ t2_encode(bwc_field *const field, bwc_tile *const tile) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -parse_packet(bwc_field *const field, bwc_tile *const tile, +parse_packet(bwc_codec *const field, bwc_tile *const tile, bwc_packet *const packet, uint64 const body_size) { -- 2.45.2 From ad3a1ad06149c2cb39e9ea2f1ba3df8879bd6cf0 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Fri, 28 Jun 2024 16:37:19 +0200 Subject: [PATCH 02/53] Symmetrize API for compression and decompression to follow - allocate codec - initialize stream (using input data/codestream and output buffer from user) - create (de-)compression - run (de-)compression --- include/library/private/codestream.h | 7 +- include/library/private/constants.h | 6 + include/library/private/libbwc.h | 37 ++-- include/library/private/types.h | 11 +- src/library/bitstream.c | 5 + src/library/codestream.c | 133 ++++++------ src/library/libbwc.c | 294 +++++++++++++++------------ 7 files changed, 275 insertions(+), 218 deletions(-) diff --git a/include/library/private/codestream.h b/include/library/private/codestream.h index 7b2c1f5..6165760 100755 --- a/include/library/private/codestream.h +++ b/include/library/private/codestream.h @@ -97,9 +97,10 @@ uchar codestream_write_com (bwc_span *const header, bwc_span *const com); //==========|==========================|======================|======|======|===================== - bwc_span* assemble_codestream (bwc_codec *const field, - bwc_stream *const data); + bwc_span* assemble_codestream (bwc_codec *const codec, + bwc_stream *const stream); //==========|==========================|======================|======|======|===================== - bwc_codec* parse_codestream (bwc_stream *const data, + bwc_codec* parse_codestream (bwc_codec *const codec, + bwc_stream *const stream, uint8 const layer); #endif \ No newline at end of file diff --git a/include/library/private/constants.h b/include/library/private/constants.h index 35bd7ef..1251b4e 100755 --- a/include/library/private/constants.h +++ b/include/library/private/constants.h @@ -118,4 +118,10 @@ bwc_precision_single = 4, bwc_precision_double = 8, } bwc_precision; + + typedef enum + { + comp, + decomp, + } bwc_mode; #endif \ No newline at end of file diff --git a/include/library/private/libbwc.h b/include/library/private/libbwc.h index fdeb409..7becb04 100755 --- a/include/library/private/libbwc.h +++ b/include/library/private/libbwc.h @@ -64,29 +64,41 @@ || || \************************************************************************************************/ //==========|==========================|======================|======|=======|==================== - bwc_stream* bwc_initialize_data (void *const data, - bwc_precision const prec); + bwc_stream* bwc_init_stream (void *const inpbuf, + void *const outbuf, + bwc_mode const mode); //==========|==========================|======================|======|=======|==================== - uchar bwc_set_com (bwc_stream *const data, + uchar bwc_set_com (bwc_stream *const stream, char const *const com, uint16 const size); //==========|==========================|======================|======|=======|==================== - uchar bwc_set_aux (bwc_stream *const data, + uchar bwc_set_aux (bwc_stream *const stream, char const *const aux, uint32 const size); //==========|==========================|======================|======|=======|==================== + // TODO: remove void bwc_free_data (bwc_stream *const data); //==========|==========================|======================|======|=======|==================== - uchar create_field (bwc_codec *const field); + uchar create_field (bwc_codec *const codec); //==========|==========================|======================|======|=======|==================== - void bwc_kill_compression (bwc_codec *const field); - //==========|==========================|======================|======|=======|==================== - bwc_codec* bwc_initialize_field (bwc_precision const prec, + bwc_codec* configure_codec (bwc_codec *const codec, uint64 const nX, uint64 const nY, uint64 const nZ, uint16 const nTS, - uint8 const nPar); + uint8 const nPar, + bwc_precision const prec); + //==========|==========================|======================|======|=======|==================== + bwc_codec* bwc_alloc_coder (uint64 const nX, + uint64 const nY, + uint64 const nZ, + uint16 const nTS, + uint8 const nPar, + bwc_precision const prec); + //==========|==========================|======================|======|=======|==================== + bwc_codec* bwc_alloc_decoder (); + //==========|==========================|======================|======|=======|==================== + void bwc_free_codec (bwc_codec *const codec); //==========|==========================|======================|======|=======|==================== void bwc_set_error_resilience (bwc_codec *const field); //==========|==========================|======================|======|=======|==================== @@ -140,9 +152,10 @@ uchar bwc_compress (bwc_codec *const field, bwc_stream *const data); //==========|==========================|======================|======|=======|==================== - bwc_codec* bwc_create_decompression (bwc_stream *const data, + uchar bwc_create_decompression (bwc_codec *const codec, + bwc_stream *const stream, uint8 const layer); //==========|==========================|======================|======|=======|==================== - uchar bwc_decompress (bwc_codec *const field, - bwc_stream *const data); + uchar bwc_decompress (bwc_codec *const codec, + bwc_stream *const stream); #endif \ No newline at end of file diff --git a/include/library/private/types.h b/include/library/private/types.h index fcacd32..3dc8bf3 100755 --- a/include/library/private/types.h +++ b/include/library/private/types.h @@ -177,11 +177,10 @@ bwc_span *com; // Comment codestream block. }codestream; - struct field - { - double *d; // Double precision numerical data-set. - float *f; // Single precision numerical data-set. - }field; + void *inp; // User managed buffer for input + void *out; // User managed buffer for output + + bwc_mode mode; // Flag to signal (de-)compression } bwc_stream; /*----------------------------------------------------------------------------------------------*\ @@ -679,5 +678,7 @@ bwc_gl_ctrl control; // Global control structure bwc_tile *tile; // Structure defining bwc tile. + + bwc_mode mode; // Flag to signal (de-)compression } bwc_codec; #endif \ No newline at end of file diff --git a/src/library/bitstream.c b/src/library/bitstream.c index fee6777..c36cde0 100755 --- a/src/library/bitstream.c +++ b/src/library/bitstream.c @@ -168,6 +168,8 @@ init_stream(uchar* memory, uint32 size, char instr) return NULL; } + // TODO: Here is a problem. Memory might be allocated here or coming from outside. + // Violates RAII. Can lead to problem in terminate_stream. /*--------------------------------------------------------*\ ! Evaluate if a valid memory handle has been passed by the ! ! function caller. ! @@ -903,6 +905,9 @@ terminate_stream(bitstream *stream, bwc_span *const packed_stream) \*-----------------------*/ assert(stream); + // TODO: this seems dangerous because the bitstream is generated from provided (non-owning) pointer or allocated (owning). + // If the former is the case a user might get reallocations on his/her pointer. + // This risk is eminent now as bwc_stream data.out is now a user provided buffer pointer. if(packed_stream) { if(stream->error) diff --git a/src/library/codestream.c b/src/library/codestream.c index 24955ad..309e6ff 100755 --- a/src/library/codestream.c +++ b/src/library/codestream.c @@ -603,7 +603,7 @@ assemble_tile(bwc_codec *const field, bwc_tile *const tile, bitstream *const str ! ! \*----------------------------------------------------------------------------------------------------------*/ bwc_codec* -parse_main_header(bwc_stream *const data, bitstream *const stream) +parse_main_header(bwc_codec *const codec, bwc_stream *const data, bitstream *const stream) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -631,16 +631,23 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - bwc_codec *field; bwc_gl_ctrl *control; bwc_gl_inf *info; /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ + assert(codec); assert(data); assert(stream); + /*--------------------------------------------------------*\ + ! Save the global control and info structure to temporary ! + ! variables to make the code more readable. ! + \*--------------------------------------------------------*/ + info = &codec->info; + control = &codec->control; + status = CODESTREAM_OK; index = 0; @@ -690,23 +697,22 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) break; } - nX = get_symbol(stream, 8); - nY = get_symbol(stream, 8); - nZ = get_symbol(stream, 8); - nTS = (uint16)get_symbol(stream, 2); - nPar = (uint8)get_symbol(stream, 1); - data_prec = (bwc_precision)get_symbol(stream, 1); + nX = get_symbol(stream, 8); + nY = get_symbol(stream, 8); + nZ = get_symbol(stream, 8); + nTS = (uint16)get_symbol(stream, 2); + nPar = (uint8)get_symbol(stream, 1); + data_prec = (bwc_precision)get_symbol(stream, 1); + codec_prec = (bwc_precision)get_symbol(stream, 1); - field = bwc_initialize_field(data_prec, nX, nY, nZ, nTS, nPar); - if(!field) + info->codec_prec = codec_prec; + + configure_codec(codec, nX, nY, nZ, nTS, nPar, data_prec); + if(!codec) { status |= CODESTREAM_ERROR; break; } - info = &field->info; - control = &field->control; - - info->codec_prec = codec_prec = (bwc_precision)get_symbol(stream, 1); control->codestreamSize = stream->Lmax; @@ -720,7 +726,7 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) { // Invalid Codestream fprintf(stderr, CSERROR); - bwc_kill_compression(field); + bwc_free_codec(codec); status |= CODESTREAM_ERROR; break; } @@ -731,7 +737,7 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) { // Invalid Codestream fprintf(stderr, CSERROR); - bwc_kill_compression(field); + bwc_free_codec(codec); status |= CODESTREAM_ERROR; break; } @@ -742,14 +748,14 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) buff_long = get_symbol(stream, 1); if(CSsgc & (0x01 << 0)) { - bwc_set_error_resilience(field); + bwc_set_error_resilience(codec); } buff_long = get_symbol(stream, 1); if(CSsgc & (0x01 << 1)) { - set_quant_style(field, (bwc_quant_st)buff_long); + set_quant_style(codec, (bwc_quant_st)buff_long); } buff_long = get_symbol(stream, 1); @@ -765,41 +771,41 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) buff_long = get_symbol(stream, 1); if(CSsgc & (0x01 << 3)) { - set_progression(field, (uint8)buff_long); + set_progression(codec, (uint8)buff_long); } buff_long = get_symbol(stream, 1); if(CSsgc & (0x01 << 4)) { - set_kernels(field, (uint8)(0x03 & (buff_long >> 6)), (uint8)(0x03 & (buff_long >> 4)), + set_kernels(codec, (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)), + bwc_set_decomp(codec, (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)), + bwc_set_precincts(codec, (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)), + bwc_set_codeblocks(codec, (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); + bwc_set_qm(codec, (uint8)buff_long); } buffX = get_symbol(stream, 8); @@ -808,7 +814,7 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) buffTS = get_symbol(stream, 2); if(CSsgc & (0x01 << 9)) { - bwc_set_tiles(field, buffX, buffY, buffZ, (uint16)buffTS, bwc_tile_sizeof); + bwc_set_tiles(codec, buffX, buffY, buffZ, (uint16)buffTS, bwc_tile_sizeof); } control->nLayers = get_symbol(stream, 1); @@ -817,7 +823,7 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) { // memory allocation error fprintf(stderr, MEMERROR); - bwc_kill_compression(field); + bwc_free_codec(codec); status|= CODESTREAM_ERROR; break; } @@ -828,10 +834,10 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) control->bitrate[l] = *(float *)&bitrate; } - create_field(field); - if(!field) + create_field(codec); + if(!codec) { - bwc_kill_compression(field); + bwc_free_codec(codec); status |= CODESTREAM_ERROR; break; } @@ -846,7 +852,7 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) { // Invalid Codestream fprintf(stderr, CSERROR); - bwc_kill_compression(field); + bwc_free_codec(codec); status |= CODESTREAM_ERROR; break; } @@ -856,7 +862,7 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) { // Invalid Codestream fprintf(stderr, CSERROR); - bwc_kill_compression(field); + bwc_free_codec(codec); status |= CODESTREAM_ERROR; break; } @@ -866,7 +872,7 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) { // memory allocation error fprintf(stderr, MEMERROR); - bwc_kill_compression(field); + bwc_free_codec(codec); status |= CODESTREAM_ERROR; break; } @@ -884,7 +890,7 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) { // Invalid Codestream fprintf(stderr, CSERROR); - bwc_kill_compression(field); + bwc_free_codec(codec); status |= CODESTREAM_ERROR; break; } @@ -894,7 +900,7 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) { // Invalid Codestream fprintf(stderr, CSERROR); - bwc_kill_compression(field); + bwc_free_codec(codec); status |= CODESTREAM_ERROR; break; } @@ -904,7 +910,7 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) { // memory allocation error fprintf(stderr, MEMERROR); - bwc_kill_compression(field); + bwc_free_codec(codec); status |= CODESTREAM_ERROR; break; } @@ -924,7 +930,7 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) { // Invalid Codestream fprintf(stderr, CSERROR); - bwc_kill_compression(field); + bwc_free_codec(codec); status |= CODESTREAM_ERROR; break; } @@ -934,7 +940,7 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) { // Invalid Codestream fprintf(stderr, CSERROR); - bwc_kill_compression(field); + bwc_free_codec(codec); status |= CODESTREAM_ERROR; break; } @@ -953,10 +959,10 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) ! header stream. ! \*--------------------------------------------------------*/ buff_long = get_symbol(stream, sizeof(double)); - field->tile[t].parameter[p].info.parameter_min = (bwc_float)*(double*)&buff_long; + codec->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; + codec->tile[t].parameter[p].info.parameter_max = (bwc_float)*(double*)&buff_long; } } } @@ -974,20 +980,20 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) ! header stream. ! \*--------------------------------------------------------*/ buff = get_symbol(stream, sizeof(float)); - field->tile[t].parameter[p].info.parameter_min = (bwc_float)*(float*)&buff; + codec->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; + codec->tile[t].parameter[p].info.parameter_max = (bwc_float)*(float*)&buff; } } } - return field; + return codec; } else { // Invalid Codestream fprintf(stderr, CSERROR); - bwc_kill_compression(field); + bwc_free_codec(codec); status |= CODESTREAM_ERROR; } break; @@ -999,7 +1005,7 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) { // Invalid Codestream fprintf(stderr, CSERROR); - bwc_kill_compression(field); + bwc_free_codec(codec); status |= CODESTREAM_ERROR; break; } @@ -1009,7 +1015,7 @@ parse_main_header(bwc_stream *const data, bitstream *const stream) { // Invalid Codestream fprintf(stderr, CSERROR); - bwc_kill_compression(field); + bwc_free_codec(codec); status |= CODESTREAM_ERROR; break; } @@ -1272,7 +1278,7 @@ parse_body(bwc_codec *const field, bitstream *const stream) { // Invalid Codestream fprintf(stderr, CSERROR); - bwc_kill_compression(field); + bwc_free_codec(field); status |= CODESTREAM_ERROR; break; } @@ -1282,7 +1288,7 @@ parse_body(bwc_codec *const field, bitstream *const stream) { // Invalid Codestream fprintf(stderr, CSERROR); - bwc_kill_compression(field); + bwc_free_codec(field); status |= CODESTREAM_ERROR; break; } @@ -1343,12 +1349,13 @@ assemble_codestream(bwc_codec *const field, bwc_stream *const data) bwc_gl_ctrl *control; bwc_tile *tile; bitstream *stream; - bwc_span *packed_stream; + bwc_span *packed_stream; /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ assert(field); + assert(data); /*--------------------------------------------------------*\ ! Save the global control and info structure to temporary ! @@ -1388,7 +1395,7 @@ assemble_codestream(bwc_codec *const field, bwc_stream *const data) ! Initialize the final codestream and emit the header ! ! bytes. ! \*--------------------------------------------------------*/ - stream = init_stream(NULL, control->codestreamSize, 'c'); + stream = init_stream(data->out, control->codestreamSize, 'c'); codestream_write_header(stream, field, data); /*--------------------------------------------------------*\ @@ -1460,31 +1467,31 @@ assemble_codestream(bwc_codec *const field, bwc_stream *const data) ! ! \*----------------------------------------------------------------------------------------------------------*/ bwc_codec* -parse_codestream(bwc_stream *const data, uint8 const layer) +parse_codestream(bwc_codec *const codec, bwc_stream *const data, uint8 const layer) { /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - bwc_codec *field; bitstream *stream; /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ assert(data); + assert(codec); /*--------------------------------------------------------*\ ! Initialize a bitstream used to parse the packed code- ! ! stream. ! \*--------------------------------------------------------*/ - stream = init_stream(data->codestream.data->memory, 10, 'd'); + stream = init_stream(data->inp, 10, 'd'); /*--------------------------------------------------------*\ - ! Parse the main header and set up the field structure for ! + ! Parse the main header and set up the codec structure for ! ! the current decompression run. ! \*--------------------------------------------------------*/ - field = parse_main_header(data, stream); - if(!field) + parse_main_header(codec, data, stream); + if(!codec) { return NULL; } @@ -1493,36 +1500,36 @@ parse_codestream(bwc_stream *const data, uint8 const layer) ! Initialize the useLayer option to decompress the entire ! ! codestream. ! \*--------------------------------------------------------*/ - field->control.useLayer = field->control.nLayers - 1; + codec->control.useLayer = codec->control.nLayers - 1; /*--------------------------------------------------------*\ ! Check if the layer index supplied by the function caller ! ! is valid. ! \*--------------------------------------------------------*/ - if(layer < field->control.nLayers && layer > 0) + if(layer < codec->control.nLayers && layer > 0) { /*--------------------------------------------------------*\ ! Amend the use layer variable in the global control struc-! ! ture. ! \*--------------------------------------------------------*/ - field->control.useLayer = layer; + codec->control.useLayer = layer; } /*--------------------------------------------------------*\ ! Parse the rest of the compressed codestream and load the ! - ! body into the field structure. ! + ! body into the codec structure. ! \*--------------------------------------------------------*/ - if(parse_body(field, stream)) + if(parse_body(codec, stream)) { - bwc_kill_compression(field); + bwc_free_codec(codec); return NULL; } /*--------------------------------------------------------*\ ! Free the bitstream used to parse the codestream and re- ! - ! turn the field structure to the function caller. ! + ! turn the codec structure to the function caller. ! \*--------------------------------------------------------*/ free(stream); - return field; + return codec; } \ No newline at end of file diff --git a/src/library/libbwc.c b/src/library/libbwc.c index 83d7c9b..5f7a6a1 100755 --- a/src/library/libbwc.c +++ b/src/library/libbwc.c @@ -819,7 +819,7 @@ fill_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const p ! Safe the field pointer to a temporary variable to make ! ! the code more readable. ! \*--------------------------------------------------------*/ - tmp_d = data->field.d; + tmp_d = (double *)data->inp; /*--------------------------------------------------------*\ ! Walk through the tile parameter working buffer. ! @@ -867,7 +867,7 @@ fill_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const p ! Safe the field pointer to a temporary variable to make ! ! the code more readable. ! \*--------------------------------------------------------*/ - tmp_f = data->field.f; + tmp_f = (float *)data->inp; /*--------------------------------------------------------*\ ! Walk through the tile parameter working buffer. ! @@ -1047,7 +1047,7 @@ flush_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const ! Safe the field pointer to a temporary variable to make ! ! the code more readable. ! \*--------------------------------------------------------*/ - tmp_d = data->field.d; + tmp_d = (double *)data->out; /*--------------------------------------------------------*\ ! Walk through the tile parameter working buffer. ! @@ -1089,7 +1089,7 @@ flush_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const ! Safe the field pointer to a temporary variable to make ! ! the code more readable. ! \*--------------------------------------------------------*/ - tmp_f = data->field.f; + tmp_f = (float *)data->out; /*--------------------------------------------------------*\ ! Walk through the tile parameter working buffer. ! @@ -1375,6 +1375,45 @@ denormalize_param(bwc_codec *const field, bwc_parameter *const parameter) } } +/*----------------------------------------------------------------------------------------------------------*\ +! ! +! DESCRIPTION: ! +! ------------ ! +! This function allocates an instance of type bwc_codec and stores the codec precision. ! +! ! +! RETURN VALUE: ! +! ------------- ! +! Type Description ! +! ---- ----------- ! +! bwc_codec* Defines the (de)compression data structure. ! +! ! +\*----------------------------------------------------------------------------------------------------------*/ +bwc_codec* +alloc_codec() +{ + /*--------------------------------------------------------*\ + ! Allocate the root compression data structure. ! + \*--------------------------------------------------------*/ + bwc_codec *codec = calloc(1, sizeof(bwc_codec)); + if(!codec) + { + // memory allocation error + fprintf(stderr, MEMERROR); + return NULL; + } + + /*--------------------------------------------------------*\ + ! Save the codec precision in the info structure. ! + \*--------------------------------------------------------*/ +#if PREC_BYTE == 8 + codec->info.codec_prec = bwc_precision_double; +#elif PREC_BYTE == 4 + codec->info.codec_prec = bwc_precision_single; +#endif + + return codec; +} + /************************************************************************************************************\ || ___ _ _ ___ _ _ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ || || |__] | | |__] | | | |___ | | |\ | | | | | | |\ | [__ || @@ -1382,7 +1421,7 @@ denormalize_param(bwc_codec *const field, bwc_parameter *const parameter) || || \************************************************************************************************************/ /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bwc_codec *bwc_initialize_data(...) ! +! FUNCTION NAME: bwc_codec *bwc_init_stream(...) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -1417,31 +1456,26 @@ denormalize_param(bwc_codec *const field, bwc_parameter *const parameter) ! ! \*----------------------------------------------------------------------------------------------------------*/ bwc_stream* -bwc_initialize_data(void *const data, bwc_precision const prec) +bwc_init_stream(void *const inpbuf, void *const outbuf, bwc_mode const mode) { /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - bwc_stream *file; + bwc_stream *stream; - file = calloc(1, sizeof(bwc_stream)); - if(!file) + stream = calloc(1, sizeof(bwc_stream)); + if(!stream) { // memory allocation error fprintf(stderr, MEMERROR); return NULL; } - if (prec == bwc_precision_double) - { - file->field.d = (double *)data; - } - else if (prec == bwc_precision_single) - { - file->field.f = (float *)data; - } + stream->inp = inpbuf; + stream->out = outbuf; + stream->mode = mode; - return file; + return stream; } /*----------------------------------------------------------------------------------------------------------*\ @@ -1576,8 +1610,6 @@ bwc_free_data(bwc_stream* data) free(data->codestream.data); free(data->codestream.aux); free(data->codestream.com); - free(data->field.d); - free(data->field.f); free(data); } } @@ -2020,7 +2052,7 @@ create_field(bwc_codec *const field) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_kill_compression(bwc_codec *const field) +bwc_free_codec(bwc_codec *const codec) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -2036,109 +2068,94 @@ bwc_kill_compression(bwc_codec *const field) bwc_gl_ctrl *control; bwc_gl_inf *info; - if(field) + if(codec) { /*--------------------------------------------------------*\ ! Save the global control and info structure to temporary ! ! variables to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; - info = &field->info; + control = &codec->control; + info = &codec->info; - if(field->tile) + if(codec->tile) { for(i = 0; i < control->nTiles; ++i) { - if(field->tile[i].parameter) + if(codec->tile[i].parameter) { for(j = 0; j < info->nPar; ++j) { - if(field->tile[i].parameter[j].resolution) + if(codec->tile[i].parameter[j].resolution) { for(r = 0; r < control->nDecomp + 1; ++r) { - if(field->tile[i].parameter[j].resolution[r].subband) + if(codec->tile[i].parameter[j].resolution[r].subband) { - for(l = 0; l < field->tile[i].parameter[j].resolution[r].control.number_of_subbands; ++l) + for(l = 0; l < codec->tile[i].parameter[j].resolution[r].control.number_of_subbands; ++l) { - if(field->tile[i].parameter[j].resolution[r].subband[l].precinct) + if(codec->tile[i].parameter[j].resolution[r].subband[l].precinct) { - for(k = 0; k < field->tile[i].parameter[j].resolution[r].control.number_of_precincts; ++k) + for(k = 0; k < codec->tile[i].parameter[j].resolution[r].control.number_of_precincts; ++k) { - if(field->tile[i].parameter[j].resolution[r].subband[l].precinct[k].codeblock) + if(codec->tile[i].parameter[j].resolution[r].subband[l].precinct[k].codeblock) { - for(c = 0; c < field->tile[i].parameter[j].resolution[r].subband[l].precinct[k].control.number_of_codeblocks; ++c) + for(c = 0; c < codec->tile[i].parameter[j].resolution[r].subband[l].precinct[k].control.number_of_codeblocks; ++c) { - if(field->tile[i].parameter[j].resolution[r].subband[l].precinct[k].codeblock[c].encoded_block) + if(codec->tile[i].parameter[j].resolution[r].subband[l].precinct[k].codeblock[c].encoded_block) { - free(field->tile[i].parameter[j].resolution[r].subband[l].precinct[k].codeblock[c].encoded_block->data); + free(codec->tile[i].parameter[j].resolution[r].subband[l].precinct[k].codeblock[c].encoded_block->data); } - free(field->tile[i].parameter[j].resolution[r].subband[l].precinct[k].codeblock[c].control.memory); - free(field->tile[i].parameter[j].resolution[r].subband[l].precinct[k].codeblock[c].encoded_block); + free(codec->tile[i].parameter[j].resolution[r].subband[l].precinct[k].codeblock[c].control.memory); + free(codec->tile[i].parameter[j].resolution[r].subband[l].precinct[k].codeblock[c].encoded_block); } } - if(field->tile[i].parameter[j].resolution[r].subband[l].precinct[k].control.number_of_codeblocks) + if(codec->tile[i].parameter[j].resolution[r].subband[l].precinct[k].control.number_of_codeblocks) { - kill_tagtree(field->tile[i].parameter[j].resolution[r].subband[l].precinct[k].control.tag_inclusion); - kill_tagtree(field->tile[i].parameter[j].resolution[r].subband[l].precinct[k].control.tag_msbs); + kill_tagtree(codec->tile[i].parameter[j].resolution[r].subband[l].precinct[k].control.tag_inclusion); + kill_tagtree(codec->tile[i].parameter[j].resolution[r].subband[l].precinct[k].control.tag_msbs); } - free(field->tile[i].parameter[j].resolution[r].subband[l].precinct[k].codeblock); + free(codec->tile[i].parameter[j].resolution[r].subband[l].precinct[k].codeblock); } } - free(field->tile[i].parameter[j].resolution[r].subband[l].precinct); + free(codec->tile[i].parameter[j].resolution[r].subband[l].precinct); } } - free(field->tile[i].parameter[j].resolution[r].subband); - free(field->tile[i].parameter[j].resolution[r].packet); + free(codec->tile[i].parameter[j].resolution[r].subband); + free(codec->tile[i].parameter[j].resolution[r].packet); } } - free(field->tile[i].parameter[j].resolution); - free(field->tile[i].parameter[j].access); + free(codec->tile[i].parameter[j].resolution); + free(codec->tile[i].parameter[j].access); } } - free(field->tile[i].packet_sequence); - free(field->tile[i].parameter); + free(codec->tile[i].packet_sequence); + free(codec->tile[i].parameter); } } free(control->bitrate); - free(field->tile); - free(field); + free(codec->tile); + free(codec); } } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bwc_codec *bwc_initialize_field(bwc_stream *const data) ! -! -------------- ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function initializes the bwc_codec structure with all necessary standard parameters ! -! to (de)compress a floating point array with nX * nY * nZ grid points, nTS timesteps and ! +! This function configures the bwc_codec structure with all necessary standard parameters ! +! to compress a floating point array with nX * nY * nZ grid points, nTS timesteps and ! ! nPar parameters. ! ! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! nX ,nY, nZ unsigned int(64 bit) - Structure used to store a numerical ! -! dataset/compressed bitstream. ! -! ! ! RETURN VALUE: ! ! ------------- ! ! Type Description ! ! ---- ----------- ! ! bwc_codec* Defines the (de)compression data structure. ! ! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 14.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! \*----------------------------------------------------------------------------------------------------------*/ bwc_codec* -bwc_initialize_field(bwc_precision const prec, uint64 const nX, uint64 const nY, uint64 const nZ, uint16 const nTS, uint8 const nPar) +configure_codec(bwc_codec *const codec, uint64 const nX, uint64 const nY, uint64 const nZ, + uint16 const nTS, uint8 const nPar, bwc_precision const prec) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -2157,24 +2174,12 @@ bwc_initialize_field(bwc_precision const prec, uint64 const nX, uint64 const nY, bwc_gl_ctrl *control; bwc_gl_inf *info; - /*--------------------------------------------------------*\ - ! Allocate the root compression data structure. ! - \*--------------------------------------------------------*/ - bwc_codec *field = calloc(1, sizeof(bwc_codec)); - if(!field) - { - // memory allocation error - fprintf(stderr, MEMERROR); - bwc_kill_compression(field); - return NULL; - } - /*--------------------------------------------------------*\ ! Save the global control and info structure to temporary ! ! variables to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; - info = &field->info; + control = &codec->control; + info = &codec->info; info->nX = nX; info->nY = nY; @@ -2183,15 +2188,6 @@ bwc_initialize_field(bwc_precision const prec, uint64 const nX, uint64 const nY, info->nPar = nPar; info->data_prec = prec; - /*--------------------------------------------------------*\ - ! Save the codec precision in the info structure. ! - \*--------------------------------------------------------*/ -#if PREC_BYTE == 8 - info->codec_prec = bwc_precision_double; -#elif PREC_BYTE == 4 - info->codec_prec = bwc_precision_single; -#endif - /*--------------------------------------------------------*\ ! Set all tile sizes to their maximum allowable value. The ! ! value for the number of tiles is set to 1. ! @@ -2277,7 +2273,7 @@ bwc_initialize_field(bwc_precision const prec, uint64 const nX, uint64 const nY, \*--------------------------------------------------------*/ if(initialize_gain_lut()) { - bwc_kill_compression(field); + bwc_free_codec(codec); return NULL; } @@ -2287,7 +2283,7 @@ bwc_initialize_field(bwc_precision const prec, uint64 const nX, uint64 const nY, ! tion (10.19) (epsilon = 6, mu = 16) from JPEG2000 by ! ! by David S. Taubman and Michael W. Marcellin (p.437). ! \*--------------------------------------------------------*/ - delta = (bwc_float)(1/(pow(2, 2 + PREC_BIT) * sqrt(get_dwt_energy_gain(field, 0, control->nDecomp)))); + delta = (bwc_float)(1/(pow(2, 2 + PREC_BIT) * sqrt(get_dwt_energy_gain(codec, 0, control->nDecomp)))); for(control->qt_exponent = 0; delta < 1; ++control->qt_exponent, delta *= 2); control->qt_mantissa = (uint16)floor(0.5f + ((delta - 1.0f) * (1 << 16))); @@ -2311,7 +2307,63 @@ bwc_initialize_field(bwc_precision const prec, uint64 const nX, uint64 const nY, } } - return field; + return codec; +} + +/*----------------------------------------------------------------------------------------------------------*\ +! ! +! DESCRIPTION: ! +! ------------ ! +! This function initializes the bwc_codec structure with all necessary standard parameters ! +! to (de)compress a floating point array with nX * nY * nZ grid points, nTS timesteps and ! +! nPar parameters. ! +! ! +! RETURN VALUE: ! +! ------------- ! +! Type Description ! +! ---- ----------- ! +! bwc_codec* Defines the (de)compression data structure. ! +! ! +\*----------------------------------------------------------------------------------------------------------*/ +bwc_codec* +bwc_alloc_coder(uint64 const nX, uint64 const nY, uint64 const nZ, uint16 const nTS, + uint8 const nPar, bwc_precision const prec) +{ + /*--------------------------------------------------------*\ + ! Allocate and configure the compression data structure. ! + \*--------------------------------------------------------*/ + bwc_codec *codec = alloc_codec(); + codec = configure_codec(codec, nX, nY, nZ, nTS, nPar, prec); + codec->mode = comp; + + return codec; +} + +/*----------------------------------------------------------------------------------------------------------*\ +! ! +! DESCRIPTION: ! +! ------------ ! +! This function initializes the bwc_codec structure with all necessary standard parameters ! +! to (de)compress a floating point array with nX * nY * nZ grid points, nTS timesteps and ! +! nPar parameters. ! +! ! +! RETURN VALUE: ! +! ------------- ! +! Type Description ! +! ---- ----------- ! +! bwc_codec* Defines the (de)compression data structure. ! +! ! +\*----------------------------------------------------------------------------------------------------------*/ +bwc_codec* +bwc_alloc_decoder() +{ + /*--------------------------------------------------------*\ + ! Allocate the root compression data structure. ! + \*--------------------------------------------------------*/ + bwc_codec *codec = alloc_codec(); + codec->mode = decomp; + + return codec; } /*----------------------------------------------------------------------------------------------------------*\ @@ -2818,7 +2870,7 @@ bwc_set_decomp(bwc_codec *const field, uint8 decompX, uint8 decompY, uint8 decom \*--------------------------------------------------------*/ if(initialize_gain_lut()) { - bwc_kill_compression(field); + bwc_free_codec(field); return; } @@ -3436,6 +3488,7 @@ bwc_create_compression(bwc_codec *codec, bwc_stream *stream, char *rate_control) ! DEFINE ASSERTIONS: ! \*-----------------------*/ assert(codec); + assert(stream); /*--------------------------------------------------------*\ ! Save the global control structure to a temporary varia- ! @@ -3929,33 +3982,29 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) ! 15.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! ! ! \*----------------------------------------------------------------------------------------------------------*/ -bwc_codec * -bwc_create_decompression(bwc_stream *const data, uint8 layer) +uchar +bwc_create_decompression(bwc_codec *const decoder, bwc_stream *const stream, uint8 layer) { - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - bwc_codec *field; - /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(data); + assert(decoder); + assert(stream); /*--------------------------------------------------------*\ - ! Parse the codestream and setup the field codestream. ! + ! Parse the stream and setup the decoder. ! \*--------------------------------------------------------*/ - field = parse_codestream(data, layer); - if(!field) + parse_codestream(decoder, stream, layer); + if(!decoder) { - return NULL; + return 1; } /*--------------------------------------------------------*\ - ! If successful, return the field structure to the func- ! + ! If successful, return the decoder structure to the func- ! ! tion caller. ! \*--------------------------------------------------------*/ - return field; + return 0; } /*----------------------------------------------------------------------------------------------------------*\ @@ -4003,7 +4052,6 @@ bwc_decompress(bwc_codec *const field, bwc_stream *const data) ! DEFINE INT VARIABLES: ! \*-----------------------*/ uint64 buff_size; - uint64 data_size; uint64 i; uint16 p; @@ -4055,30 +4103,6 @@ bwc_decompress(bwc_codec *const field, bwc_stream *const data) control = &field->control; info = &field->info; - data_size = info->nX * info->nY * info->nZ * info->nTS * info->nPar; - if(info->data_prec == bwc_precision_double) - { - data->field.d = calloc(data_size, sizeof(double)); - data->field.f = calloc(0, sizeof(float)); - if(!data->field.d) - { - // memory allocation error - fprintf(stderr, MEMERROR); - return 1; - } - } - else if (info->data_prec == bwc_precision_single) - { - data->field.d = calloc(0, sizeof(double)); - data->field.f = calloc(data_size, sizeof(float)); - if(!data->field.f) - { - // memory allocation error - fprintf(stderr, MEMERROR); - return 1; - } - } - /*--------------------------------------------------------*\ ! Evaluate the working buffer size and allocate it accord- ! ! ingly. ! -- 2.45.2 From 0673dafb64edd3f9563c2e87bf77dff856fd56a5 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Mon, 1 Jul 2024 11:01:44 +0200 Subject: [PATCH 03/53] rename init_stream(...) -> init_bitstream(...). init_bitstream without allocation. emit_symbol and emit_chunck without reallocation. --- include/library/private/bitstream.h | 2 +- src/library/bitstream.c | 142 +++++++--------------------- src/library/codestream.c | 6 +- src/library/tier2.c | 12 ++- 4 files changed, 49 insertions(+), 113 deletions(-) diff --git a/include/library/private/bitstream.h b/include/library/private/bitstream.h index 3ec7a78..42f6763 100755 --- a/include/library/private/bitstream.h +++ b/include/library/private/bitstream.h @@ -92,7 +92,7 @@ \************************************************************************************************/ uint64 bytes_used (bitstream const *const stream); //==========|==========================|======================|======|======|===================== - bitstream* init_stream (uchar *const memory, + bitstream* init_bitstream (uchar *const memory, uint32 const size, char const instr); //==========|==========================|======================|======|======|===================== diff --git a/src/library/bitstream.c b/src/library/bitstream.c index c36cde0..b023bdd 100755 --- a/src/library/bitstream.c +++ b/src/library/bitstream.c @@ -107,8 +107,6 @@ bytes_used(bitstream const *const stream) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bitstream* bwc_init_stream(uchar* memory, uint32 size, char instr) ! -! -------------- ! ! ! ! DESCRIPTION: ! ! ------------ ! @@ -145,7 +143,7 @@ bytes_used(bitstream const *const stream) ! ! \*----------------------------------------------------------------------------------------------------------*/ bitstream* -init_stream(uchar* memory, uint32 size, char instr) +init_bitstream(uchar* memory, uint32 size, char instr) { /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -155,6 +153,7 @@ init_stream(uchar* memory, uint32 size, char instr) /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ + assert(memory); assert(instr == 'c' || instr == 'd'); /*--------------------------------------------------------*\ @@ -168,39 +167,11 @@ init_stream(uchar* memory, uint32 size, char instr) return NULL; } - // TODO: Here is a problem. Memory might be allocated here or coming from outside. - // Violates RAII. Can lead to problem in terminate_stream. - /*--------------------------------------------------------*\ - ! 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->memory = memory; stream->t = (instr == 'c') ? 8 : 0; stream->Lmax = size; stream->size_incr = (uint64)(size / 2); @@ -249,11 +220,6 @@ init_stream(uchar* memory, uint32 size, char instr) void emit_chunck(bitstream *const stream, const uchar* chunck, const uint64 size) { - /*-----------------------*\ - ! DEFINE INT VARIABLES: ! - \*-----------------------*/ - uint64 Lreq; - /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ @@ -261,54 +227,30 @@ emit_chunck(bitstream *const stream, const uchar* chunck, const uint64 size) assert(chunck); /*--------------------------------------------------------*\ - ! Evaluate the memory block size if the current chunck of ! - ! data is written to the stream. ! + ! Check if an error was encountered in a previous writing ! + ! operation ! \*--------------------------------------------------------*/ - 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(!stream->error) { /*--------------------------------------------------------*\ - ! If the stream is not large enough, check if this is due ! - ! to an error encountered in a previous writing operation ! + ! Check if the enough memory has been allocated for the ! + ! stream to store the additional symbol. ! \*--------------------------------------------------------*/ - if(!stream->error) + if((bytes_used(stream) + size) > 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; - } - } - else - { - /*--------------------------------------------------------*\ - ! Exit to function caller if error flag has been set. ! - \*--------------------------------------------------------*/ + // 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. ! @@ -372,44 +314,30 @@ emit_symbol(bitstream *const stream, const uint64 symbol, const uint8 size) assert(stream); /*--------------------------------------------------------*\ - ! Check if the enough memory has been allocated for the ! - ! stream to store the additional symbol. ! + ! Check if an error was encountered in a previous writing ! + ! operation ! \*--------------------------------------------------------*/ - if((bytes_used(stream) + size) > 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 ! + ! Check if the enough memory has been allocated for the ! + ! stream to store the additional symbol. ! \*--------------------------------------------------------*/ - if(!stream->error) + if((bytes_used(stream) + size) > stream->Lmax) { - /*--------------------------------------------------------*\ - ! 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); - - /*--------------------------------------------------------*\ - ! 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. ! - \*--------------------------------------------------------*/ + // 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 ! diff --git a/src/library/codestream.c b/src/library/codestream.c index 309e6ff..a8afd0e 100755 --- a/src/library/codestream.c +++ b/src/library/codestream.c @@ -1395,7 +1395,7 @@ assemble_codestream(bwc_codec *const field, bwc_stream *const data) ! Initialize the final codestream and emit the header ! ! bytes. ! \*--------------------------------------------------------*/ - stream = init_stream(data->out, control->codestreamSize, 'c'); + stream = init_bitstream(data->out, control->codestreamSize, 'c'); codestream_write_header(stream, field, data); /*--------------------------------------------------------*\ @@ -1414,7 +1414,7 @@ assemble_codestream(bwc_codec *const field, bwc_stream *const data) assemble_tile(field, tile, stream); } - emit_symbol(stream, EOC, 2); + emit_symbol(&(*stream), EOC, 2); packed_stream = calloc(1, sizeof(bwc_span)); if(!packed_stream) @@ -1484,7 +1484,7 @@ parse_codestream(bwc_codec *const codec, bwc_stream *const data, uint8 const lay ! Initialize a bitstream used to parse the packed code- ! ! stream. ! \*--------------------------------------------------------*/ - stream = init_stream(data->inp, 10, 'd'); + stream = init_bitstream(data->inp, 10, 'd'); /*--------------------------------------------------------*\ ! Parse the main header and set up the codec structure for ! diff --git a/src/library/tier2.c b/src/library/tier2.c index 5c3a08a..e784c8d 100755 --- a/src/library/tier2.c +++ b/src/library/tier2.c @@ -450,6 +450,7 @@ create_packet(bwc_codec *const field, bwc_tile *const tile, int16 *cp_contr; int16 delta_z; int8 m; + uchar *memory; /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -482,7 +483,14 @@ create_packet(bwc_codec *const field, bwc_tile *const tile, ! Initialize the stream that is used to assemble the pack- ! ! et header. ! \*--------------------------------------------------------*/ - header = init_stream(NULL, PACKET_HEADER_SIZE, 'c'); + memory = calloc(PACKET_HEADER_SIZE, sizeof(uchar)); + if(!memory) + { + // memory allocation error + fprintf(stderr, MEMERROR); + return -1; + } + header = init_bitstream(memory, PACKET_HEADER_SIZE, 'c'); if(!header) { // memory allocation error @@ -1392,7 +1400,7 @@ parse_packet(bwc_codec *const field, bwc_tile *const tile, ! Initialize the stream that is used to parse the packet ! ! codestream. ! \*--------------------------------------------------------*/ - header = init_stream(packet->header.memory, body_size, 'd'); + header = init_bitstream(packet->header.memory, body_size, 'd'); if(!header) { // memory allocation error -- 2.45.2 From 1c41147b73bf70ddff222d78b771346f34d0ce93 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Tue, 2 Jul 2024 17:58:41 +0200 Subject: [PATCH 04/53] resolved terminate_stream into shrink_to_fit and transfer_to_span. transferal of stream to span not required in assemble_codestream anymore. assemble_codestream and bwc_compress return the size of the compressed data. user provided buffer is used. --- include/library/private/bitstream.h | 6 +- include/library/private/codestream.h | 2 +- include/library/private/libbwc.h | 2 +- src/library/bitstream.c | 94 ++++++++++++++-------------- src/library/codestream.c | 26 +++----- src/library/libbwc.c | 21 ++++--- src/library/tier2.c | 7 ++- 7 files changed, 76 insertions(+), 82 deletions(-) diff --git a/include/library/private/bitstream.h b/include/library/private/bitstream.h index 42f6763..1e8aacc 100755 --- a/include/library/private/bitstream.h +++ b/include/library/private/bitstream.h @@ -117,8 +117,10 @@ //==========|==========================|======================|======|======|===================== uchar get_bit (bitstream *const stream); //==========|==========================|======================|======|======|===================== - uchar terminate_stream (bitstream *stream, - bwc_span *const packed_stream); + uchar shrink_to_fit (bitstream *const stream); + //==========|==========================|======================|======|======|===================== + uchar transfer_to_span (bitstream *const stream, + bwc_span *const span); //==========|==========================|======================|======|======|===================== void release_packed_stream (bwc_span *const stream); #endif diff --git a/include/library/private/codestream.h b/include/library/private/codestream.h index 6165760..e7f54fc 100755 --- a/include/library/private/codestream.h +++ b/include/library/private/codestream.h @@ -97,7 +97,7 @@ uchar codestream_write_com (bwc_span *const header, bwc_span *const com); //==========|==========================|======================|======|======|===================== - bwc_span* assemble_codestream (bwc_codec *const codec, + size_t assemble_codestream (bwc_codec *const codec, bwc_stream *const stream); //==========|==========================|======================|======|======|===================== bwc_codec* parse_codestream (bwc_codec *const codec, diff --git a/include/library/private/libbwc.h b/include/library/private/libbwc.h index 7becb04..7c65f6d 100755 --- a/include/library/private/libbwc.h +++ b/include/library/private/libbwc.h @@ -149,7 +149,7 @@ bwc_stream *const data, char *const rate_control); //==========|==========================|======================|======|=======|==================== - uchar bwc_compress (bwc_codec *const field, + size_t bwc_compress (bwc_codec *const field, bwc_stream *const data); //==========|==========================|======================|======|=======|==================== uchar bwc_create_decompression (bwc_codec *const codec, diff --git a/src/library/bitstream.c b/src/library/bitstream.c index b023bdd..2780b65 100755 --- a/src/library/bitstream.c +++ b/src/library/bitstream.c @@ -798,74 +798,74 @@ flush_stream(bitstream *const stream) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void *test(void) ! -! -------------- ! -! ! ! DESCRIPTION: ! ! ------------ ! -! DESCRIPTION NEEDED ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! - - - ! +! Shrinks the bitstream memory to the actually filled range. ! ! ! ! RETURN VALUE: ! ! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! - Patrick Vogler B87D120 V 0.1.0 function created ! +! Returns 0 if successfull and 1 if memory could not be resized. ! ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -terminate_stream(bitstream *stream, bwc_span *const packed_stream) +shrink_to_fit(bitstream *const stream) { /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ assert(stream); - // TODO: this seems dangerous because the bitstream is generated from provided (non-owning) pointer or allocated (owning). - // If the former is the case a user might get reallocations on his/her pointer. - // This risk is eminent now as bwc_stream data.out is now a user provided buffer pointer. - if(packed_stream) + if(stream->error) { - 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; } - 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; - } - } + } + return 0; +} - packed_stream->memory = stream->memory; - packed_stream->access = stream->memory; - packed_stream->size = stream->L; - packed_stream->position = 0; - } - else +/*----------------------------------------------------------------------------------------------------------*\ +! DESCRIPTION: ! +! ------------ ! +! Swap memory pointer and size to span. Invalidates stream pointers. ! +! ! +! RETURN VALUE: ! +! ------------- ! +! Returns 0 if successfull and 1 if stream had previous memory error. ! +! ! +\*----------------------------------------------------------------------------------------------------------*/ +uchar +transfer_to_span(bitstream *const stream, bwc_span *const span) +{ + /*-----------------------*\ + ! DEFINE ASSERTIONS: ! + \*-----------------------*/ + assert(stream); + assert(span); + + if(stream->error) { - free(stream->memory); + return 1; } - - free(stream); + + span->memory = stream->memory; + span->access = stream->memory; + span->size = stream->L; + span->position = 0; + + stream->memory = NULL; + stream->L = 0; + return 0; } diff --git a/src/library/codestream.c b/src/library/codestream.c index a8afd0e..48255fa 100755 --- a/src/library/codestream.c +++ b/src/library/codestream.c @@ -1335,12 +1335,13 @@ parse_body(bwc_codec *const field, bitstream *const stream) ! 13.06.2019 Patrick Vogler B87D120 V 0.1.0 function created ! ! ! \*----------------------------------------------------------------------------------------------------------*/ -bwc_span* +size_t assemble_codestream(bwc_codec *const field, bwc_stream *const data) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! \*-----------------------*/ + size_t compressed_size; uint64 i; /*-----------------------*\ @@ -1349,7 +1350,6 @@ assemble_codestream(bwc_codec *const field, bwc_stream *const data) bwc_gl_ctrl *control; bwc_tile *tile; bitstream *stream; - bwc_span *packed_stream; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -1385,7 +1385,7 @@ assemble_codestream(bwc_codec *const field, bwc_stream *const data) \*--------------------------------------------------------*/ if(sequence_packets(field, tile)) { - return NULL; + return 0; } control->codestreamSize += tile->control.header_size + tile->control.body_size; @@ -1414,24 +1414,12 @@ assemble_codestream(bwc_codec *const field, bwc_stream *const data) assemble_tile(field, tile, stream); } - emit_symbol(&(*stream), EOC, 2); + emit_symbol(stream, EOC, 2); - packed_stream = calloc(1, sizeof(bwc_span)); - if(!packed_stream) - { - // memory allocation error - fprintf(stderr, MEMERROR); - return NULL; - } + compressed_size = stream->L; + free(stream); - if(terminate_stream(stream, packed_stream)) - { - return NULL; - } - else - { - return packed_stream; - } + return compressed_size; } /*----------------------------------------------------------------------------------------------------------*\ diff --git a/src/library/libbwc.c b/src/library/libbwc.c index 5f7a6a1..239655c 100755 --- a/src/library/libbwc.c +++ b/src/library/libbwc.c @@ -3652,12 +3652,13 @@ bwc_create_compression(bwc_codec *codec, bwc_stream *stream, char *rate_control) ! 15.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! ! ! \*----------------------------------------------------------------------------------------------------------*/ -uchar +size_t bwc_compress(bwc_codec *const field, bwc_stream *const data) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! \*-----------------------*/ + size_t compressed_size = 0; uint64 buff_size = 0; uint64 i; uint16 p; @@ -3731,7 +3732,7 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) { // memory allocation error fprintf(stderr, MEMERROR); - return 1; + return 0; } /*--------------------------------------------------------*\ @@ -3812,7 +3813,7 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) if(forward_wavelet_transform(field, parameter)) { free(working_buffer); - return 1; + return 0; } #ifdef BWC_PROFILE #if defined (_OPENMP) @@ -3837,7 +3838,7 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) if(t1_encode(field, tile, parameter)) { free(working_buffer); - return 1; + return 0; } #ifdef BWC_PROFILE #if defined (_OPENMP) @@ -3868,7 +3869,7 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) if(t2_encode(field, tile)) { free(working_buffer); - return 1; + return 0; } #ifdef BWC_PROFILE #if defined (_OPENMP) @@ -3890,11 +3891,11 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) start = (double)clock(); #endif #endif - data->codestream.data = assemble_codestream(field, data); - if(!data->codestream.data) + compressed_size = assemble_codestream(field, data); + if(compressed_size == 0) { free(working_buffer); - return 1; + return 0; } #ifdef BWC_PROFILE #if defined (_OPENMP) @@ -3922,7 +3923,7 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) #endif nfs = (uint64)(info->nX * info->nY * info->nZ * info->nTS * info->nPar * info->data_prec); - css = (uint64)data->codestream.data->size; + css = (uint64)compressed_size; cpr = (double)nfs/css; @@ -3944,7 +3945,7 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) /*--------------------------------------------------------*\ ! Return to the function caller. ! \*--------------------------------------------------------*/ - return 0; + return compressed_size; } /*----------------------------------------------------------------------------------------------------------*\ diff --git a/src/library/tier2.c b/src/library/tier2.c index e784c8d..c492162 100755 --- a/src/library/tier2.c +++ b/src/library/tier2.c @@ -652,7 +652,8 @@ create_packet(bwc_codec *const field, bwc_tile *const tile, } k = header->L; - terminate_stream(header, NULL); + free(header->memory); + free(header); return k; } /*--------------------------------------------------------*\ @@ -663,11 +664,13 @@ create_packet(bwc_codec *const field, bwc_tile *const tile, \*--------------------------------------------------------*/ else { - if(terminate_stream(header, &packet->header)) + if(shrink_to_fit(header)) { // memory allocation error return -1; } + transfer_to_span(header, &packet->header); + free(header); packet->size = packet->body.size + packet->header.size; -- 2.45.2 From 3242165d9097f39037bda0e29d67cea8aca59d2a Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Tue, 2 Jul 2024 18:07:19 +0200 Subject: [PATCH 05/53] remove unused bwc_span bwc_stream.codestream.data --- include/library/private/types.h | 1 - src/library/libbwc.c | 5 ----- 2 files changed, 6 deletions(-) diff --git a/include/library/private/types.h b/include/library/private/types.h index 3dc8bf3..0320a8e 100755 --- a/include/library/private/types.h +++ b/include/library/private/types.h @@ -172,7 +172,6 @@ { struct codestream { - bwc_span *data; // Data codestream block. bwc_span *aux; // Auxiliary info. codestream block. bwc_span *com; // Comment codestream block. }codestream; diff --git a/src/library/libbwc.c b/src/library/libbwc.c index 239655c..bbbda4e 100755 --- a/src/library/libbwc.c +++ b/src/library/libbwc.c @@ -1595,10 +1595,6 @@ bwc_free_data(bwc_stream* data) { if(data) { - if(data->codestream.data) - { - release_packed_stream(data->codestream.data); - } if(data->codestream.aux) { release_packed_stream(data->codestream.aux); @@ -1607,7 +1603,6 @@ bwc_free_data(bwc_stream* data) { release_packed_stream(data->codestream.com); } - free(data->codestream.data); free(data->codestream.aux); free(data->codestream.com); free(data); -- 2.45.2 From e970a0d892085006e313aaa266394f1fb4c2a518 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Wed, 28 Aug 2024 12:00:14 +0200 Subject: [PATCH 06/53] uint64 for number of time steps parameter --- include/library/private/libbwc.h | 6 +++--- src/interfaces/python/bwc.py | 2 +- src/library/codestream.c | 6 +++--- src/library/libbwc.c | 23 +++++++++++------------ 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/include/library/private/libbwc.h b/include/library/private/libbwc.h index 7c65f6d..e84218b 100755 --- a/include/library/private/libbwc.h +++ b/include/library/private/libbwc.h @@ -85,14 +85,14 @@ uint64 const nX, uint64 const nY, uint64 const nZ, - uint16 const nTS, + uint64 const nTS, uint8 const nPar, bwc_precision const prec); //==========|==========================|======================|======|=======|==================== bwc_codec* bwc_alloc_coder (uint64 const nX, uint64 const nY, uint64 const nZ, - uint16 const nTS, + uint64 const nTS, uint8 const nPar, bwc_precision const prec); //==========|==========================|======================|======|=======|==================== @@ -158,4 +158,4 @@ //==========|==========================|======================|======|=======|==================== uchar bwc_decompress (bwc_codec *const codec, bwc_stream *const stream); -#endif \ No newline at end of file +#endif diff --git a/src/interfaces/python/bwc.py b/src/interfaces/python/bwc.py index 670ec90..5c22e93 100644 --- a/src/interfaces/python/bwc.py +++ b/src/interfaces/python/bwc.py @@ -97,7 +97,7 @@ def initialize_data(data, nX, nY, nZ, nTS, nPar, file_extension): ctypes.c_uint64, ctypes.c_uint64, ctypes.c_uint64, - ctypes.c_uint16, + ctypes.c_uint64, ctypes.c_uint8, ctypes.c_char_p] return ctypes.c_void_p(fun(data, nX, nY, nZ, nTS, nPar, file_extension.encode('utf-8'))) diff --git a/src/library/codestream.c b/src/library/codestream.c index 48255fa..185d03c 100755 --- a/src/library/codestream.c +++ b/src/library/codestream.c @@ -188,7 +188,7 @@ codestream_write_header(bitstream *const stream, 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->nTS, 8); emit_symbol(stream, info->nPar, 1); emit_symbol(stream, (uint8)info->data_prec, 1); emit_symbol(stream, (uint8)info->codec_prec, 1); @@ -700,7 +700,7 @@ parse_main_header(bwc_codec *const codec, bwc_stream *const data, bitstream *con nX = get_symbol(stream, 8); nY = get_symbol(stream, 8); nZ = get_symbol(stream, 8); - nTS = (uint16)get_symbol(stream, 2); + nTS = get_symbol(stream, 8); nPar = (uint8)get_symbol(stream, 1); data_prec = (bwc_precision)get_symbol(stream, 1); codec_prec = (bwc_precision)get_symbol(stream, 1); @@ -1520,4 +1520,4 @@ parse_codestream(bwc_codec *const codec, bwc_stream *const data, uint8 const lay free(stream); return codec; -} \ No newline at end of file +} diff --git a/src/library/libbwc.c b/src/library/libbwc.c index bbbda4e..c545b59 100755 --- a/src/library/libbwc.c +++ b/src/library/libbwc.c @@ -1742,11 +1742,11 @@ create_field(bwc_codec *const field) tile_info->X0 = (uint64)MAX(0, x * control->tileSizeX); tile_info->Y0 = (uint64)MAX(0, y * control->tileSizeY); tile_info->Z0 = (uint64)MAX(0, z * control->tileSizeZ); - tile_info->TS0 = (uint16)MAX(0, t * control->tileSizeTS); + tile_info->TS0 = (uint64)MAX(0, t * control->tileSizeTS); tile_info->X1 = (uint64)MIN(info->nX , (x + 1) * control->tileSizeX); tile_info->Y1 = (uint64)MIN(info->nY , (y + 1) * control->tileSizeY); tile_info->Z1 = (uint64)MIN(info->nZ , (z + 1) * control->tileSizeZ); - tile_info->TS1 = (uint16)MIN(info->nTS, (t + 1) * control->tileSizeTS); + tile_info->TS1 = (uint64)MIN(info->nTS, (t + 1) * control->tileSizeTS); /*--------------------------------------------------------*\ ! Initialize the tile header size. ! @@ -2150,7 +2150,7 @@ bwc_free_codec(bwc_codec *const codec) \*----------------------------------------------------------------------------------------------------------*/ bwc_codec* configure_codec(bwc_codec *const codec, uint64 const nX, uint64 const nY, uint64 const nZ, - uint16 const nTS, uint8 const nPar, bwc_precision const prec) + uint64 const nTS, uint8 const nPar, bwc_precision const prec) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -2321,7 +2321,7 @@ configure_codec(bwc_codec *const codec, uint64 const nX, uint64 const nY, uint64 ! ! \*----------------------------------------------------------------------------------------------------------*/ bwc_codec* -bwc_alloc_coder(uint64 const nX, uint64 const nY, uint64 const nZ, uint16 const nTS, +bwc_alloc_coder(uint64 const nX, uint64 const nY, uint64 const nZ, uint64 const nTS, uint8 const nPar, bwc_precision const prec) { /*--------------------------------------------------------*\ @@ -3230,13 +3230,12 @@ bwc_set_qm(bwc_codec *const field, uint8 Qm) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_set_tiles(bwc_codec *const field, uint64 tilesX, uint64 tilesY, uint64 tilesZ, uint16 tilesTS, bwc_tile_instr instr) +bwc_set_tiles(bwc_codec *const field, uint64 tilesX, uint64 tilesY, uint64 tilesZ, uint64 tilesTS, bwc_tile_instr instr) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! \*-----------------------*/ - uint64 num_tiles_X, num_tiles_Y, num_tiles_Z; - uint16 num_tiles_TS; + uint64 num_tiles_X, num_tiles_Y, num_tiles_Z, num_tiles_TS; /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -3304,7 +3303,7 @@ bwc_set_tiles(bwc_codec *const field, uint64 tilesX, uint64 tilesY, uint64 tiles num_tiles_X = (uint64)ceil(((float)info->nX / control->tileSizeX)); num_tiles_Y = (uint64)ceil(((float)info->nY / control->tileSizeY)); num_tiles_Z = (uint64)ceil(((float)info->nZ / control->tileSizeZ)); - num_tiles_TS = (uint16)ceil(((float)info->nTS/ control->tileSizeTS)); + num_tiles_TS = (uint64)ceil(((float)info->nTS/ control->tileSizeTS)); control->nTiles = num_tiles_X * num_tiles_Y * num_tiles_Z * num_tiles_TS; /*--------------------------------------------------------*\ @@ -3366,7 +3365,7 @@ bwc_set_tiles(bwc_codec *const field, uint64 tilesX, uint64 tilesY, uint64 tiles control->tileSizeX = (info->nX >> 1) ? (tilesX ? (uint64)ceil(((float)info->nX / tilesX)) : info->nX) : info->nX; control->tileSizeY = (info->nY >> 1) ? (tilesY ? (uint64)ceil(((float)info->nY / tilesY)) : info->nY) : info->nY; control->tileSizeZ = (info->nZ >> 1) ? (tilesZ ? (uint64)ceil(((float)info->nZ / tilesZ)) : info->nZ) : info->nZ; - control->tileSizeTS = (info->nTS >> 1) ? (tilesTS ? (uint16)ceil(((float)info->nTS/ tilesTS)) : info->nTS) : info->nTS; + control->tileSizeTS = (info->nTS >> 1) ? (tilesTS ? (uint64)ceil(((float)info->nTS/ tilesTS)) : info->nTS) : info->nTS; /*--------------------------------------------------------*\ ! Check if the tile sizes have valid values. ! @@ -3406,7 +3405,7 @@ bwc_set_tiles(bwc_codec *const field, uint64 tilesX, uint64 tilesY, uint64 tiles num_tiles_X = (uint64)ceil(((float)info->nX / control->tileSizeX)); num_tiles_Y = (uint64)ceil(((float)info->nY / control->tileSizeY)); num_tiles_Z = (uint64)ceil(((float)info->nZ / control->tileSizeZ)); - num_tiles_TS = (uint16)ceil(((float)info->nTS/ control->tileSizeTS)); + num_tiles_TS = (uint64)ceil(((float)info->nTS/ control->tileSizeTS)); control->nTiles = num_tiles_X * num_tiles_Y * num_tiles_Z * num_tiles_TS; } @@ -3588,8 +3587,8 @@ bwc_create_compression(bwc_codec *codec, bwc_stream *stream, char *rate_control) /*--------------------------------------------------------*\ ! Evaluate the size of the main header. ! \*--------------------------------------------------------*/ - control->headerSize = 99 + info->nPar * control->nTiles * 2 * PREC_BYTE - + control->nLayers * 4; + control->headerSize = 105 + info->nPar * control->nTiles * 2 * PREC_BYTE + + control->nLayers * 4; if(stream->codestream.aux != NULL) { -- 2.45.2 From 366827ca4a30b62eb10e0ae94384d6f040efeb74 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Wed, 18 Sep 2024 14:41:29 +0200 Subject: [PATCH 07/53] align integer precision for all dimensions, adaptations in fourth dimension --- src/library/codestream.c | 9 ++++----- src/library/dwt.c | 40 ++++++++++++++-------------------------- src/library/libbwc.c | 28 +++++++++++++--------------- src/library/tier1.c | 40 +++++++++++++++------------------------- 4 files changed, 46 insertions(+), 71 deletions(-) diff --git a/src/library/codestream.c b/src/library/codestream.c index 185d03c..a1468ec 100755 --- a/src/library/codestream.c +++ b/src/library/codestream.c @@ -228,7 +228,7 @@ codestream_write_header(bitstream *const stream, emit_symbol(stream, control->tileSizeX, 8); emit_symbol(stream, control->tileSizeY, 8); emit_symbol(stream, control->tileSizeZ, 8); - emit_symbol(stream, control->tileSizeTS, 2); + emit_symbol(stream, control->tileSizeTS, 8); emit_symbol(stream, control->nLayers, 1); @@ -609,7 +609,7 @@ parse_main_header(bwc_codec *const codec, bwc_stream *const data, bitstream *con ! DEFINE INT VARIABLES: ! \*-----------------------*/ uint64 buff_long, buffX, buffY, buffZ, buffTS; - uint64 nX, nY, nZ; + uint64 nX, nY, nZ, nTS; uint32 buff; uint32 bitrate; uint32 Lsax; @@ -618,7 +618,6 @@ parse_main_header(bwc_codec *const codec, bwc_stream *const data, bitstream *con uint16 CSsgc; uint16 Linf, Lctr, Lcom, Leoh, Lunk; uint16 marker; - uint16 nTS; uint8 index, l; uint8 nPar, p; bwc_precision data_prec, codec_prec; @@ -811,10 +810,10 @@ parse_main_header(bwc_codec *const codec, bwc_stream *const data, bitstream *con buffX = get_symbol(stream, 8); buffY = get_symbol(stream, 8); buffZ = get_symbol(stream, 8); - buffTS = get_symbol(stream, 2); + buffTS = get_symbol(stream, 8); if(CSsgc & (0x01 << 9)) { - bwc_set_tiles(codec, buffX, buffY, buffZ, (uint16)buffTS, bwc_tile_sizeof); + bwc_set_tiles(codec, buffX, buffY, buffZ, buffTS, bwc_tile_sizeof); } control->nLayers = get_symbol(stream, 1); diff --git a/src/library/dwt.c b/src/library/dwt.c index 1fc9136..65615ee 100755 --- a/src/library/dwt.c +++ b/src/library/dwt.c @@ -1619,23 +1619,17 @@ forward_wavelet_transform(bwc_codec *const field, bwc_parameter *const parameter /*-----------------------*\ ! DEFINE INT VARIABLES: ! \*-----------------------*/ - uint64 incr_X, incr_Y, incr_Z; - uint64 rX0, rY0, rZ0; - uint64 rX1, rY1, rZ1; - uint64 width, height, depth; - uint64 x, y, z; + uint64 incr_X, incr_Y, incr_Z, incr_TS; + uint64 rX0, rY0, rZ0, rTS0; + uint64 rX1, rY1, rZ1, rTS1; + uint64 width, height, depth, dt; + uint64 x, y, z, t; int64 nThreads; int16 i; uint32 buff_size; - uint16 incr_TS; - uint16 rTS0; - uint16 rTS1; - uint16 dt; - uint16 t; - uint8 id; uint8 filter_tapsX, filter_tapsY, filter_tapsZ; uint8 filter_tapsTS; @@ -1777,8 +1771,8 @@ forward_wavelet_transform(bwc_codec *const field, bwc_parameter *const parameter rY1 = (uint64)parameter->resolution[control->nDecomp - level].info.Y1; rZ0 = (uint64)parameter->resolution[control->nDecomp - level].info.Z0; rZ1 = (uint64)parameter->resolution[control->nDecomp - level].info.Z1; - rTS0 = (uint16)parameter->resolution[control->nDecomp - level].info.TS0; - rTS1 = (uint16)parameter->resolution[control->nDecomp - level].info.TS1; + rTS0 = (uint64)parameter->resolution[control->nDecomp - level].info.TS0; + rTS1 = (uint64)parameter->resolution[control->nDecomp - level].info.TS1; if(level < control->decompX && (rX1 - rX0) > 1) { @@ -2160,23 +2154,17 @@ inverse_wavelet_transform(bwc_codec *const field, bwc_parameter *const parameter /*-----------------------*\ ! DEFINE INT VARIABLES: ! \*-----------------------*/ - uint64 incr_X, incr_Y, incr_Z; - uint64 rX0, rY0, rZ0; - uint64 rX1, rY1, rZ1; - uint64 width, height, depth; - uint64 x, y, z; + uint64 incr_X, incr_Y, incr_Z, incr_TS; + uint64 rX0, rY0, rZ0, rTS0; + uint64 rX1, rY1, rZ1, rTS1; + uint64 width, height, depth, dt; + uint64 x, y, z, t; int64 nThreads; int64 i; uint32 buff_size; - uint16 incr_TS; - uint16 rTS0; - uint16 rTS1; - uint16 dt; - uint16 t; - uint8 id; uint8 filter_tapsX, filter_tapsY, filter_tapsZ; uint8 filter_tapsTS; @@ -2318,8 +2306,8 @@ inverse_wavelet_transform(bwc_codec *const field, bwc_parameter *const parameter rY1 = (uint64)parameter->resolution[control->nDecomp - level].info.Y1; rZ0 = (uint64)parameter->resolution[control->nDecomp - level].info.Z0; rZ1 = (uint64)parameter->resolution[control->nDecomp - level].info.Z1; - rTS0 = (uint16)parameter->resolution[control->nDecomp - level].info.TS0; - rTS1 = (uint16)parameter->resolution[control->nDecomp - level].info.TS1; + rTS0 = (uint64)parameter->resolution[control->nDecomp - level].info.TS0; + rTS1 = (uint64)parameter->resolution[control->nDecomp - level].info.TS1; if(level < control->decompTS && (rTS1 - rTS0) > 1) { diff --git a/src/library/libbwc.c b/src/library/libbwc.c index c545b59..00f754f 100755 --- a/src/library/libbwc.c +++ b/src/library/libbwc.c @@ -314,11 +314,11 @@ initialize_precinct(bwc_codec *const field, bwc_precinct *precinct, const uint32 cblk_info->X0 = dX + (uint32)MAX(prec_info->X0 , cbSizeX * (cb_X + (uint32)floor((float)prec_info->X0 / cbSizeX ))); cblk_info->Y0 = dY + (uint32)MAX(prec_info->Y0 , cbSizeY * (cb_Y + (uint32)floor((float)prec_info->Y0 / cbSizeY ))); cblk_info->Z0 = dZ + (uint32)MAX(prec_info->Z0 , cbSizeZ * (cb_Z + (uint32)floor((float)prec_info->Z0 / cbSizeZ ))); - cblk_info->TS0 = dTS + (uint16)MAX(prec_info->TS0, cbSizeTS * (cb_TS + (uint32)floor((float)prec_info->TS0/ cbSizeTS))); + cblk_info->TS0 = dTS + (uint32)MAX(prec_info->TS0, cbSizeTS * (cb_TS + (uint32)floor((float)prec_info->TS0/ cbSizeTS))); cblk_info->X1 = dX + (uint32)MIN(prec_info->X1 , cbSizeX * (cb_X + (uint32)floor((float)prec_info->X0 / cbSizeX ) + 1)); cblk_info->Y1 = dY + (uint32)MIN(prec_info->Y1 , cbSizeY * (cb_Y + (uint32)floor((float)prec_info->Y0 / cbSizeY ) + 1)); cblk_info->Z1 = dZ + (uint32)MIN(prec_info->Z1 , cbSizeZ * (cb_Z + (uint32)floor((float)prec_info->Z0 / cbSizeZ ) + 1)); - cblk_info->TS1 = dTS + (uint16)MIN(prec_info->TS1, cbSizeTS * (cb_TS + (uint32)floor((float)prec_info->TS0/ cbSizeTS) + 1)); + cblk_info->TS1 = dTS + (uint32)MIN(prec_info->TS1, cbSizeTS * (cb_TS + (uint32)floor((float)prec_info->TS0/ cbSizeTS) + 1)); } } } @@ -506,11 +506,11 @@ initialize_subband(bwc_codec *const field, bwc_parameter *const parameter, bwc_r subb_info->X0 = (uint64)ceil( ((float)param_info->X0 / (1 << level_X)) - 0.5 * ((highband_flag & DIM_X) >> 0)); subb_info->Y0 = (uint64)ceil( ((float)param_info->Y0 / (1 << level_Y)) - 0.5 * ((highband_flag & DIM_Y) >> 1)); subb_info->Z0 = (uint64)ceil( ((float)param_info->Z0 / (1 << level_Z)) - 0.5 * ((highband_flag & DIM_Z) >> 2)); - subb_info->TS0 = (uint16)ceil( ((float)param_info->TS0 / (1 << level_TS)) - 0.5 * ((highband_flag & DIM_TS) >> 3)); + subb_info->TS0 = (uint64)ceil( ((float)param_info->TS0 / (1 << level_TS)) - 0.5 * ((highband_flag & DIM_TS) >> 3)); subb_info->X1 = (uint64)ceil( ((float)param_info->X1 / (1 << level_X)) - 0.5 * ((highband_flag & DIM_X) >> 0)); subb_info->Y1 = (uint64)ceil( ((float)param_info->Y1 / (1 << level_Y)) - 0.5 * ((highband_flag & DIM_Y) >> 1)); subb_info->Z1 = (uint64)ceil( ((float)param_info->Z1 / (1 << level_Z)) - 0.5 * ((highband_flag & DIM_Z) >> 2)); - subb_info->TS1 = (uint16)ceil( ((float)param_info->TS1 / (1 << level_TS)) - 0.5 * ((highband_flag & DIM_TS) >> 3)); + subb_info->TS1 = (uint64)ceil( ((float)param_info->TS1 / (1 << level_TS)) - 0.5 * ((highband_flag & DIM_TS) >> 3)); /*--------------------------------------------------------*\ ! Evaluate the dynamic range (Rb) of the current subband. ! @@ -632,11 +632,11 @@ initialize_subband(bwc_codec *const field, bwc_parameter *const parameter, bwc_r prec_info->X0 = (uint32)MAX(res_info->X0 , pSizeX * (p_X + (uint32)floor(res_info->X0 / pSizeX))); prec_info->Y0 = (uint32)MAX(res_info->Y0 , pSizeY * (p_Y + (uint32)floor(res_info->Y0 / pSizeY))); prec_info->Z0 = (uint32)MAX(res_info->Z0 , pSizeZ * (p_Z + (uint32)floor(res_info->Z0 / pSizeZ))); - prec_info->TS0 = (uint16)MAX(res_info->TS0, pSizeTS * (p_TS + (uint32)floor(res_info->TS0/ pSizeTS))); + prec_info->TS0 = (uint32)MAX(res_info->TS0, pSizeTS * (p_TS + (uint32)floor(res_info->TS0/ pSizeTS))); prec_info->X1 = (uint32)MIN(res_info->X1 , pSizeX * (p_X + (uint32)floor(res_info->X0 / pSizeX) + 1)); prec_info->Y1 = (uint32)MIN(res_info->Y1 , pSizeY * (p_Y + (uint32)floor(res_info->Y0 / pSizeY) + 1)); prec_info->Z1 = (uint32)MIN(res_info->Z1 , pSizeZ * (p_Z + (uint32)floor(res_info->Z0 / pSizeZ) + 1)); - prec_info->TS1 = (uint16)MIN(res_info->TS1, pSizeTS * (p_TS + (uint32)floor(res_info->TS0/ pSizeTS)+ 1)); + prec_info->TS1 = (uint32)MIN(res_info->TS1, pSizeTS * (p_TS + (uint32)floor(res_info->TS0/ pSizeTS)+ 1)); if((control->nDecomp - control->decompX) < resolution_level) { @@ -658,8 +658,8 @@ initialize_subband(bwc_codec *const field, bwc_parameter *const parameter, bwc_r if((control->nDecomp - control->decompTS) < resolution_level) { - prec_info->TS0 = (uint16) ceil(((float)prec_info->TS0 / 2) - 0.5 * ((highband_flag & DIM_TS) >> 3)); - prec_info->TS1 = (uint16) ceil(((float)prec_info->TS1 / 2) - 0.5 * ((highband_flag & DIM_TS) >> 3)); + prec_info->TS0 = (uint32) ceil(((float)prec_info->TS0 / 2) - 0.5 * ((highband_flag & DIM_TS) >> 3)); + prec_info->TS1 = (uint32) ceil(((float)prec_info->TS1 / 2) - 0.5 * ((highband_flag & DIM_TS) >> 3)); } /*--------------------------------------------------------*\ @@ -742,8 +742,7 @@ fill_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const p \*-----------------------*/ uint64 width, height, depth, dt; uint64 param_offset; - uint64 x, y, z; - uint16 t; + uint64 x, y, z, t; /*-----------------------*\ ! DEFINE FLOAT VARIABLES: ! @@ -984,8 +983,7 @@ flush_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const uint64 width, height, depth, dt; uint64 nX, nY, nZ; uint64 param_offset; - uint64 x, y, z; - uint16 t; + uint64 x, y, z, t; /*-----------------------*\ ! DEFINE FLOAT VARIABLES: ! @@ -1837,11 +1835,11 @@ create_field(bwc_codec *const field) res_info->X0 = (uint64)ceil((float)param_info->X0 / (1 << MIN(control->nDecomp -r, control->decompX))); res_info->Y0 = (uint64)ceil((float)param_info->Y0 / (1 << MIN(control->nDecomp -r, control->decompY))); res_info->Z0 = (uint64)ceil((float)param_info->Z0 / (1 << MIN(control->nDecomp -r, control->decompZ))); - res_info->TS0 = (uint16)ceil((float)param_info->TS0/ (1 << MIN(control->nDecomp -r, control->decompTS))); + res_info->TS0 = (uint64)ceil((float)param_info->TS0/ (1 << MIN(control->nDecomp -r, control->decompTS))); res_info->X1 = (uint64)ceil((float)param_info->X1 / (1 << MIN(control->nDecomp -r, control->decompX))); res_info->Y1 = (uint64)ceil((float)param_info->Y1 / (1 << MIN(control->nDecomp -r, control->decompY))); res_info->Z1 = (uint64)ceil((float)param_info->Z1 / (1 << MIN(control->nDecomp -r, control->decompZ))); - res_info->TS1 = (uint16)ceil((float)param_info->TS1/ (1 << MIN(control->nDecomp -r, control->decompTS))); + res_info->TS1 = (uint64)ceil((float)param_info->TS1/ (1 << MIN(control->nDecomp -r, control->decompTS))); /*--------------------------------------------------------*\ ! Calculate the number of precincts to cover tile t in pa- ! @@ -3587,7 +3585,7 @@ bwc_create_compression(bwc_codec *codec, bwc_stream *stream, char *rate_control) /*--------------------------------------------------------*\ ! Evaluate the size of the main header. ! \*--------------------------------------------------------*/ - control->headerSize = 105 + info->nPar * control->nTiles * 2 * PREC_BYTE + control->headerSize = 111 + info->nPar * control->nTiles * 2 * PREC_BYTE + control->nLayers * 4; if(stream->codestream.aux != NULL) diff --git a/src/library/tier1.c b/src/library/tier1.c index 79a09e8..318b3e5 100755 --- a/src/library/tier1.c +++ b/src/library/tier1.c @@ -398,9 +398,8 @@ cblkreset_inv(bwc_coder_stripe *const cblk, const uint64 width, const uint64 hei uint64 i; uint64 limit; uint64 cblk_stripe; - uint64 x, y, z; + uint64 x, y, z, t; int64 idx_u, idx_r, idx_d, idx_l; - uint16 t; uint8 s; /*-----------------------*\ @@ -533,15 +532,12 @@ cblkcopy_forward(bwc_coder_stripe *const destination, bwc_sample *const source, \*-----------------------*/ bwc_raw buff, sign_mask; uint64 bit_mask, limit; - uint64 cblk_width, cblk_height, cblk_depth, cblk_stripe; + uint64 cblk_width, cblk_height, cblk_depth, cblk_dt, cblk_stripe; uint64 incrX, incrY, incrZ; - uint64 i, x, y, z; - uint64 X0, Y0, Z0; - uint64 X1, Y1, Z1; + uint64 i, x, y, z, t; + uint64 X0, Y0, Z0, TS0; + uint64 X1, Y1, Z1, TS1; int64 idx_u, idx_r, idx_d, idx_l; - uint16 TS0, TS1; - uint16 cblk_dt; - uint16 t; uint8 b, Kmax, s; /*-----------------------*\ @@ -775,15 +771,12 @@ cblkcopy_inverse(bwc_coder_stripe *const source, bwc_sample *const destinat /*-----------------------*\ ! DEFINE INT VARIABLES: ! \*-----------------------*/ - uint64 cblk_width, cblk_height, cblk_depth, cblk_stripe; + uint64 cblk_width, cblk_height, cblk_depth, cblk_dt, cblk_stripe; uint64 bit_shift, buff, limit; uint64 incrX, incrY, incrZ; - uint64 i, x, y, z; - uint64 X0, Y0, Z0; - uint64 X1, Y1, Z1; - uint16 TS0, TS1; - uint16 cblk_dt; - uint16 t; + uint64 i, x, y, z, t; + uint64 X0, Y0, Z0, TS0; + uint64 X1, Y1, Z1, TS1; uint8 bitplane; uint8 codingpass; uint8 s; @@ -2279,7 +2272,7 @@ compute_convex_hull(bwc_encoded_cblk *const encoded_codeblock, double *const mse ! const uint64 width, ! ! const uint64 height, ! ! const uint64 depth, ! -! const uint16 dt) ! +! const uint64 dt) ! ! ! ! ! ! DESCRIPTION: ! @@ -2312,7 +2305,7 @@ encode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, const uint64 width, const uint64 height, const uint64 depth, - const uint16 dt) + const uint64 dt) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -2600,7 +2593,7 @@ encode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, ! const uint64 width, ! ! const uint64 height, ! ! const uint64 depth, ! -! const uint16 dt) ! +! const uint64 dt) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -2633,7 +2626,7 @@ decode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, const uint64 width, const uint64 height, const uint64 depth, - const uint16 dt) + const uint64 dt) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -2834,14 +2827,13 @@ t1_encode(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const par ! DEFINE INT VARIABLES: ! \*-----------------------*/ uint64 c; - uint64 cbSizeX, cbSizeY, cbSizeZ; + uint64 cbSizeX, cbSizeY, cbSizeZ, cbSizeTS; uint64 width, height, depth; int64 buff_size; int64 i, j; int64 nThreads; - uint16 cbSizeTS; uint16 slope_max, slope_min; int16 z; @@ -3137,15 +3129,13 @@ t1_decode(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const par ! DEFINE INT VARIABLES: ! \*-----------------------*/ uint64 c; - uint64 cbSizeX, cbSizeY, cbSizeZ; + uint64 cbSizeX, cbSizeY, cbSizeZ, cbSizeTS; uint64 width, height, depth; int64 buff_size; int64 i, j; int64 nThreads; - uint16 cbSizeTS; - /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ -- 2.45.2 From 68fcedc9ffd5b823efeab9eba7551f77c7b475c7 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Wed, 9 Oct 2024 11:49:22 +0200 Subject: [PATCH 08/53] rename field->codec for bwc_codec variables --- include/library/private/codestream.h | 2 +- include/library/private/dwt.h | 6 +- include/library/private/libbwc.h | 24 +-- include/library/private/tier1.h | 4 +- include/library/private/tier2.h | 4 +- src/library/codestream.c | 100 +++++---- src/library/dwt.c | 32 +-- src/library/libbwc.c | 291 +++++++++++++-------------- src/library/tier1.c | 32 +-- src/library/tier2.c | 90 ++++----- 10 files changed, 283 insertions(+), 302 deletions(-) diff --git a/include/library/private/codestream.h b/include/library/private/codestream.h index e7f54fc..0445b59 100755 --- a/include/library/private/codestream.h +++ b/include/library/private/codestream.h @@ -89,7 +89,7 @@ || | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] || || || \************************************************************************************************/ - uchar assemble_main_header (bwc_codec *const field); + uchar assemble_main_header (bwc_codec *const codec); //==========|==========================|======================|======|======|===================== uchar codestream_write_aux (bwc_span *const header, bwc_span *const aux); diff --git a/include/library/private/dwt.h b/include/library/private/dwt.h index fa08858..1b17a6f 100755 --- a/include/library/private/dwt.h +++ b/include/library/private/dwt.h @@ -157,13 +157,13 @@ \************************************************************************************************/ uchar initialize_gain_lut (); //==========|==========================|======================|======|=======|==================== - bwc_float get_dwt_energy_gain (bwc_codec *const field, + bwc_float get_dwt_energy_gain (bwc_codec *const codec, uchar const highband_flag, uint16 const level); //==========|==========================|======================|======|=======|==================== - uchar forward_wavelet_transform (bwc_codec *const field, + uchar forward_wavelet_transform (bwc_codec *const codec, bwc_parameter *const parameter); //==========|==========================|======================|======|=======|==================== - uchar inverse_wavelet_transform (bwc_codec *const field, + uchar inverse_wavelet_transform (bwc_codec *const codec, bwc_parameter *const parameter); #endif \ No newline at end of file diff --git a/include/library/private/libbwc.h b/include/library/private/libbwc.h index e84218b..c2b003d 100755 --- a/include/library/private/libbwc.h +++ b/include/library/private/libbwc.h @@ -79,7 +79,7 @@ // TODO: remove void bwc_free_data (bwc_stream *const data); //==========|==========================|======================|======|=======|==================== - uchar create_field (bwc_codec *const codec); + uchar create_codec (bwc_codec *const codec); //==========|==========================|======================|======|=======|==================== bwc_codec* configure_codec (bwc_codec *const codec, uint64 const nX, @@ -100,45 +100,45 @@ //==========|==========================|======================|======|=======|==================== void bwc_free_codec (bwc_codec *const codec); //==========|==========================|======================|======|=======|==================== - void bwc_set_error_resilience (bwc_codec *const field); + void bwc_set_error_resilience (bwc_codec *const codec); //==========|==========================|======================|======|=======|==================== - void set_quant_style (bwc_codec *const field, + void set_quant_style (bwc_codec *const codec, bwc_quant_st const quantization_style); //==========|==========================|======================|======|=======|==================== - void set_quant_step_size (bwc_codec *const field, + void set_quant_step_size (bwc_codec *const codec, double const delta); //==========|==========================|======================|======|=======|==================== - void set_progression (bwc_codec *const field, + void set_progression (bwc_codec *const codec, bwc_prog_ord const progression); //==========|==========================|======================|======|=======|==================== - void set_kernels (bwc_codec *const field, + void set_kernels (bwc_codec *const codec, bwc_dwt_filter const KernelX, bwc_dwt_filter const KernelY, bwc_dwt_filter const KernelZ, bwc_dwt_filter const KernelTS); //==========|==========================|======================|======|=======|==================== - void bwc_set_decomp (bwc_codec *const field, + void bwc_set_decomp (bwc_codec *const codec, uint8 const decompX, uint8 const decompY, uint8 const decompZ, uint8 const decompTS); //==========|==========================|======================|======|=======|==================== - void bwc_set_precincts (bwc_codec *const field, + void bwc_set_precincts (bwc_codec *const codec, uint8 const pX, uint8 const pY, uint8 const pZ, uint8 const pTS); //==========|==========================|======================|======|=======|==================== - void bwc_set_codeblocks (bwc_codec *const field, + void bwc_set_codeblocks (bwc_codec *const codec, uint8 const cbX, uint8 const cbY, uint8 const cbZ, uint8 const cbTS); //==========|==========================|======================|======|=======|==================== - void bwc_set_qm (bwc_codec *const field, + void bwc_set_qm (bwc_codec *const codec, uint8 const Qm); //==========|==========================|======================|======|=======|==================== - void bwc_set_tiles (bwc_codec *const field, + void bwc_set_tiles (bwc_codec *const codec, uint64 const tilesX, uint64 const tilesY, uint64 const tilesZ, @@ -149,7 +149,7 @@ bwc_stream *const data, char *const rate_control); //==========|==========================|======================|======|=======|==================== - size_t bwc_compress (bwc_codec *const field, + size_t bwc_compress (bwc_codec *const codec, bwc_stream *const data); //==========|==========================|======================|======|=======|==================== uchar bwc_create_decompression (bwc_codec *const codec, diff --git a/include/library/private/tier1.h b/include/library/private/tier1.h index 7f0e19c..14546cc 100755 --- a/include/library/private/tier1.h +++ b/include/library/private/tier1.h @@ -156,11 +156,11 @@ || | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] || || || \************************************************************************************************/ - uchar t1_encode (bwc_codec *const field, + uchar t1_encode (bwc_codec *const codec, bwc_tile *const tile, bwc_parameter *const parameter); //==========|==========================|======================|======|=======|==================== - uchar t1_decode (bwc_codec *const field, + uchar t1_decode (bwc_codec *const codec, bwc_tile *const tile, bwc_parameter *const parameter); diff --git a/include/library/private/tier2.h b/include/library/private/tier2.h index 074e49d..d55cb65 100755 --- a/include/library/private/tier2.h +++ b/include/library/private/tier2.h @@ -76,10 +76,10 @@ || | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] || || || \************************************************************************************************/ - uchar t2_encode (bwc_codec *const field, + uchar t2_encode (bwc_codec *const codec, bwc_tile *const tile); //==========|==========================|======================|======|=======|==================== - uchar parse_packet (bwc_codec *const field, + uchar parse_packet (bwc_codec *const codec, bwc_tile *const tile, bwc_packet *const packet, uint64 const body_size); diff --git a/src/library/codestream.c b/src/library/codestream.c index a1468ec..3c0d8d3 100755 --- a/src/library/codestream.c +++ b/src/library/codestream.c @@ -104,7 +104,7 @@ can_read(bitstream *const stream, const uint64 length) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void codestream_write_header(bitstream *const stream, bwc_codec *const field) ! +! FUNCTION NAME: void codestream_write_header(bitstream *const stream, bwc_codec *const codec) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -116,7 +116,7 @@ can_read(bitstream *const stream, const uint64 length) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! stream bitstream* - Structure used to assemble a bwc bit- ! @@ -138,7 +138,7 @@ can_read(bitstream *const stream, const uint64 length) \*----------------------------------------------------------------------------------------------------------*/ static void codestream_write_header(bitstream *const stream, - bwc_codec *const field, + bwc_codec *const codec, bwc_stream *const data) { /*-----------------------*\ @@ -163,15 +163,15 @@ codestream_write_header(bitstream *const stream, ! DEFINE ASSERTIONS: ! \*-----------------------*/ assert(stream); - assert(field); + assert(codec); /*--------------------------------------------------------*\ ! Save the global as well as the subband control and info ! ! structure to temporary variables to make the code more ! ! readable. ! \*--------------------------------------------------------*/ - info = &field->info; - control = &field->control; + info = &codec->info; + control = &codec->control; aux = data->codestream.aux; com = data->codestream.com; @@ -263,21 +263,21 @@ codestream_write_header(bitstream *const stream, for(p = 0; p < info->nPar; ++p) { - emit_symbol(stream, *(uint64 *)&field->tile[t]. + emit_symbol(stream, *(uint64 *)&codec->tile[t]. parameter[p].info. parameter_min, PREC_BYTE); - emit_symbol(stream, *(uint64 *)&field->tile[t]. + emit_symbol(stream, *(uint64 *)&codec->tile[t]. parameter[p].info. parameter_max, PREC_BYTE); - field->tile[t].parameter[p].info.parameter_max = -FLT_MAX; - field->tile[t].parameter[p].info.parameter_min = FLT_MAX; + codec->tile[t].parameter[p].info.parameter_max = -FLT_MAX; + codec->tile[t].parameter[p].info.parameter_min = FLT_MAX; } } } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar sequence_packets(bwc_codec *const field, bwc_codec *const field) ! +! FUNCTION NAME: uchar sequence_packets(bwc_codec *const codec, bwc_tile *const tile) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -288,7 +288,7 @@ codestream_write_header(bitstream *const stream, ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -308,7 +308,7 @@ codestream_write_header(bitstream *const stream, ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -sequence_packets(bwc_codec *const field, bwc_tile *const tile) +sequence_packets(bwc_codec *const codec, bwc_tile *const tile) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -336,8 +336,8 @@ sequence_packets(bwc_codec *const field, bwc_tile *const tile) ! sequence structure to temporary variables to make the ! ! code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; - info = &field->info; + control = &codec->control; + info = &codec->info; packet_sequence = tile->packet_sequence; @@ -479,7 +479,7 @@ sequence_packets(bwc_codec *const field, bwc_tile *const tile) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar sequence_packets(bwc_codec *const field, bwc_codec *const field) ! +! FUNCTION NAME: ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -490,16 +490,11 @@ sequence_packets(bwc_codec *const field, bwc_tile *const tile) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! tile bwc_tile* - Structure defining a bwc tile. ! ! ! ! RETURN VALUE: ! ! ------------- ! ! Type Description ! ! ---- ----------- ! -! uchar - Returns an unsigned char for error handling. ! ! ! ! DEVELOPMENT HISTORY: ! ! -------------------- ! @@ -510,7 +505,7 @@ sequence_packets(bwc_codec *const field, bwc_tile *const tile) ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -assemble_tile(bwc_codec *const field, bwc_tile *const tile, bitstream *const stream) +assemble_tile(bwc_codec *const codec, bwc_tile *const tile, bitstream *const stream) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -526,7 +521,7 @@ assemble_tile(bwc_codec *const field, bwc_tile *const tile, bitstream *const str /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(tile); assert(stream); @@ -535,7 +530,7 @@ assemble_tile(bwc_codec *const field, bwc_tile *const tile, bitstream *const str ! sequence structure to temporary variables to make the ! ! code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; emit_symbol(stream, SOT, 2); emit_symbol(stream, 14, 2); @@ -833,7 +828,7 @@ parse_main_header(bwc_codec *const codec, bwc_stream *const data, bitstream *con control->bitrate[l] = *(float *)&bitrate; } - create_field(codec); + create_codec(codec); if(!codec) { bwc_free_codec(codec); @@ -1029,7 +1024,7 @@ parse_main_header(bwc_codec *const codec, bwc_stream *const data, bitstream *con } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar sequence_packets(bwc_codec *const field, bwc_codec *const field) ! +! FUNCTION NAME: ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -1040,16 +1035,11 @@ parse_main_header(bwc_codec *const codec, bwc_stream *const data, bitstream *con ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! tile bwc_tile* - Structure defining a bwc tile. ! ! ! ! RETURN VALUE: ! ! ------------- ! ! Type Description ! ! ---- ----------- ! -! uchar - Returns an unsigned char for error handling. ! ! ! ! DEVELOPMENT HISTORY: ! ! -------------------- ! @@ -1060,7 +1050,7 @@ parse_main_header(bwc_codec *const codec, bwc_stream *const data, bitstream *con ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -parse_tile(bwc_codec *const field, bitstream *const stream) +parse_tile(bwc_codec *const codec, bitstream *const stream) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1080,7 +1070,7 @@ parse_tile(bwc_codec *const field, bitstream *const stream) /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(stream); /*--------------------------------------------------------*\ @@ -1088,7 +1078,7 @@ parse_tile(bwc_codec *const field, bitstream *const stream) ! sequence structure to temporary variables to make the ! ! code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; if(!can_read(stream, 2)) { @@ -1114,7 +1104,7 @@ parse_tile(bwc_codec *const field, bitstream *const stream) return 1; } - tile = &field->tile[buf]; + tile = &codec->tile[buf]; tile->control.body_size = body_size = (uint64)get_symbol(stream, 8); @@ -1130,7 +1120,7 @@ parse_tile(bwc_codec *const field, bitstream *const stream) ! Sequence the packets according to the user specified op- ! ! tion. ! \*--------------------------------------------------------*/ - if(sequence_packets(field, tile)) + if(sequence_packets(codec, tile)) { return 1; } @@ -1168,7 +1158,7 @@ parse_tile(bwc_codec *const field, bitstream *const stream) packet->header.memory = get_access(stream); - if(parse_packet(field, tile, packet, body_size)) + if(parse_packet(codec, tile, packet, body_size)) { return 1; } @@ -1210,7 +1200,7 @@ parse_tile(bwc_codec *const field, bitstream *const stream) ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -parse_body(bwc_codec *const field, bitstream *const stream) +parse_body(bwc_codec *const codec, bitstream *const stream) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1226,7 +1216,7 @@ parse_body(bwc_codec *const field, bitstream *const stream) /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); status = CODESTREAM_OK; @@ -1244,7 +1234,7 @@ parse_body(bwc_codec *const field, bitstream *const stream) { case SOT: { - if(parse_tile(field, stream)) + if(parse_tile(codec, stream)) { status |= CODESTREAM_ERROR; } @@ -1277,7 +1267,7 @@ parse_body(bwc_codec *const field, bitstream *const stream) { // Invalid Codestream fprintf(stderr, CSERROR); - bwc_free_codec(field); + bwc_free_codec(codec); status |= CODESTREAM_ERROR; break; } @@ -1287,7 +1277,7 @@ parse_body(bwc_codec *const field, bitstream *const stream) { // Invalid Codestream fprintf(stderr, CSERROR); - bwc_free_codec(field); + bwc_free_codec(codec); status |= CODESTREAM_ERROR; break; } @@ -1306,7 +1296,7 @@ parse_body(bwc_codec *const field, bitstream *const stream) || || \************************************************************************************************************/ /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bwc_span* assemble_codestream(bwc_codec *const field) ! +! FUNCTION NAME: bwc_span* assemble_codestream(bwc_codec *const codec, bwc_stream *const data) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -1317,14 +1307,14 @@ parse_body(bwc_codec *const field, bitstream *const stream) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! RETURN VALUE: ! ! ------------- ! ! Type Description ! ! ---- ----------- ! -! bwc_span* - Packed stream containing the compressed data set. ! +! bwc_span* - Packed stream containing the compressed data set. ! ! ! ! DEVELOPMENT HISTORY: ! ! -------------------- ! @@ -1335,7 +1325,7 @@ parse_body(bwc_codec *const field, bitstream *const stream) ! ! \*----------------------------------------------------------------------------------------------------------*/ size_t -assemble_codestream(bwc_codec *const field, bwc_stream *const data) +assemble_codestream(bwc_codec *const codec, bwc_stream *const data) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1353,7 +1343,7 @@ assemble_codestream(bwc_codec *const field, bwc_stream *const data) /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(data); /*--------------------------------------------------------*\ @@ -1362,7 +1352,7 @@ assemble_codestream(bwc_codec *const field, bwc_stream *const data) ! the final codestream size with the number of header ! ! bytes. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; control->codestreamSize = control->headerSize + 2; @@ -1376,13 +1366,13 @@ assemble_codestream(bwc_codec *const field, bwc_stream *const data) ! Save the tile structure in a temporary variable to make ! ! the code more readable. ! \*--------------------------------------------------------*/ - tile = &field->tile[i]; + tile = &codec->tile[i]; /*--------------------------------------------------------*\ ! Sequence the packets according to the user specified op- ! ! tion and iterate the size of the codestream. ! \*--------------------------------------------------------*/ - if(sequence_packets(field, tile)) + if(sequence_packets(codec, tile)) { return 0; } @@ -1395,7 +1385,7 @@ assemble_codestream(bwc_codec *const field, bwc_stream *const data) ! bytes. ! \*--------------------------------------------------------*/ stream = init_bitstream(data->out, control->codestreamSize, 'c'); - codestream_write_header(stream, field, data); + codestream_write_header(stream, codec, data); /*--------------------------------------------------------*\ ! Walk through the tile structure and assemble the packed ! @@ -1408,9 +1398,9 @@ assemble_codestream(bwc_codec *const field, bwc_stream *const data) ! Save the tile structure in a temporary variable to make ! ! the code more readable. ! \*--------------------------------------------------------*/ - tile = &field->tile[i]; + tile = &codec->tile[i]; - assemble_tile(field, tile, stream); + assemble_tile(codec, tile, stream); } emit_symbol(stream, EOC, 2); @@ -1422,7 +1412,7 @@ assemble_codestream(bwc_codec *const field, bwc_stream *const data) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar parse_codestream(bwc_codec *const field, bitstream *const stream) ! +! FUNCTION NAME: uchar parse_codestream(bwc_codec *const codec, bitstream *const stream) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -1433,7 +1423,7 @@ assemble_codestream(bwc_codec *const field, bwc_stream *const data) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! stream bitstream* - Structure used to assemble a bwc bit- ! diff --git a/src/library/dwt.c b/src/library/dwt.c index 65615ee..c280e0d 100755 --- a/src/library/dwt.c +++ b/src/library/dwt.c @@ -1421,7 +1421,7 @@ initialize_gain_lut() } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bwc_float get_dwt_energy_gain(bwc_codec *const field, uchar highband_flag, uint16 level) ! +! FUNCTION NAME: bwc_float get_dwt_energy_gain(bwc_codec *const codec, uchar highband_flag, uint16 level) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -1434,7 +1434,7 @@ initialize_gain_lut() ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! highband_flag uchar - Defines the subband for which Gb is ! @@ -1459,7 +1459,7 @@ initialize_gain_lut() ! ! \*----------------------------------------------------------------------------------------------------------*/ bwc_float -get_dwt_energy_gain(bwc_codec *const field, uchar highband_flag, uint16 level) +get_dwt_energy_gain(bwc_codec *const codec, uchar highband_flag, uint16 level) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1480,15 +1480,15 @@ get_dwt_energy_gain(bwc_codec *const field, uchar highband_flag, uint16 level) /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); - assert(level <= field->control.nDecomp + 1); + assert(codec); + assert(level <= codec->control.nDecomp + 1); assert(highband_flag <= DIM_ALL); /*--------------------------------------------------------*\ ! Save the global control structure to a temporary varia- ! ! ble to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; /*--------------------------------------------------------*\ ! Evaluate the number of decompositions in each temporal & ! @@ -1576,7 +1576,7 @@ get_dwt_energy_gain(bwc_codec *const field, uchar highband_flag, uint16 level) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar forward_discrete_wavelet_transform(bwc_codec *const field, ! +! FUNCTION NAME: uchar forward_discrete_wavelet_transform(bwc_codec *const codec, ! ! -------------- bwc_parameter *const parameter) ! ! ! ! DESCRIPTION: ! @@ -1594,7 +1594,7 @@ get_dwt_energy_gain(bwc_codec *const field, uchar highband_flag, uint16 level) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! parameter bwc_parameter* - Structure defining a bwc parameter. ! @@ -1614,7 +1614,7 @@ get_dwt_energy_gain(bwc_codec *const field, uchar highband_flag, uint16 level) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -forward_wavelet_transform(bwc_codec *const field, bwc_parameter *const parameter) +forward_wavelet_transform(bwc_codec *const codec, bwc_parameter *const parameter) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1646,7 +1646,7 @@ forward_wavelet_transform(bwc_codec *const field, bwc_parameter *const parameter /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(parameter); /*-----------------------*\ @@ -1664,7 +1664,7 @@ forward_wavelet_transform(bwc_codec *const field, bwc_parameter *const parameter ! Save the global control and parameter info structure to ! ! temporary variables to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; param_info = ¶meter->info; /*--------------------------------------------------------*\ @@ -2111,7 +2111,7 @@ forward_wavelet_transform(bwc_codec *const field, bwc_parameter *const parameter } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar inverse_discrete_wavelet_transform(bwc_codec *const field, ! +! FUNCTION NAME: uchar inverse_discrete_wavelet_transform(bwc_codec *const codec, ! ! -------------- bwc_parameter *const parameter) ! ! ! ! DESCRIPTION: ! @@ -2129,7 +2129,7 @@ forward_wavelet_transform(bwc_codec *const field, bwc_parameter *const parameter ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! parameter bwc_parameter* - Structure defining a bwc parameter. ! @@ -2149,7 +2149,7 @@ forward_wavelet_transform(bwc_codec *const field, bwc_parameter *const parameter ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -inverse_wavelet_transform(bwc_codec *const field, bwc_parameter *const parameter) +inverse_wavelet_transform(bwc_codec *const codec, bwc_parameter *const parameter) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -2181,7 +2181,7 @@ inverse_wavelet_transform(bwc_codec *const field, bwc_parameter *const parameter /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(parameter); /*-----------------------*\ @@ -2199,7 +2199,7 @@ inverse_wavelet_transform(bwc_codec *const field, bwc_parameter *const parameter ! Save the global control and parameter info structure to ! ! temporary variables to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; param_info = ¶meter->info; /*--------------------------------------------------------*\ diff --git a/src/library/libbwc.c b/src/library/libbwc.c index 00f754f..42b09cc 100755 --- a/src/library/libbwc.c +++ b/src/library/libbwc.c @@ -145,7 +145,7 @@ #endif /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uint8 initialize_precinct(bwc_codec *const field, bwc_precinct *precinct, ! +! FUNCTION NAME: uint8 initialize_precinct(bwc_codec *const codec, bwc_precinct *precinct, ! ! -------------- const uint32 dX, const uint32 dY, ! ! const uint32 dZ, const uint32 dTS) ! ! ! @@ -157,7 +157,7 @@ ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! precinct bwc_precinct* - Structure defining a bwc precinct. ! @@ -180,7 +180,7 @@ ! ! \*----------------------------------------------------------------------------------------------------------*/ static uint8 -initialize_precinct(bwc_codec *const field, bwc_precinct *precinct, const uint32 dX, const uint32 dY, +initialize_precinct(bwc_codec *const codec, bwc_precinct *precinct, const uint32 dX, const uint32 dY, const uint32 dZ, const uint32 dTS) { /*-----------------------*\ @@ -202,7 +202,7 @@ initialize_precinct(bwc_codec *const field, bwc_precinct *precinct, const uint32 /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(precinct); /*--------------------------------------------------------*\ @@ -210,7 +210,7 @@ initialize_precinct(bwc_codec *const field, bwc_precinct *precinct, const uint32 ! and info structure to temporary variables to make the ! ! code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; prec_control = &precinct->control; prec_info = &precinct->info; @@ -386,7 +386,7 @@ static uint8 subband_gain(const uint8 highband_flag) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar initialize_subband(bwc_codec *const field, bwc_parameter *const parameter, ! +! FUNCTION NAME: uchar initialize_subband(bwc_codec *const codec, bwc_parameter *const parameter, ! ! -------------- bwc_resolution *const resolution, ! ! bwc_subband *const subband, ! ! int32 resolution_level, ! @@ -403,7 +403,7 @@ static uint8 subband_gain(const uint8 highband_flag) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! parameter bwc_parameter* - Structure defining a bwc tile parameter.! @@ -433,7 +433,7 @@ static uint8 subband_gain(const uint8 highband_flag) ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -initialize_subband(bwc_codec *const field, bwc_parameter *const parameter, bwc_resolution *const resolution, +initialize_subband(bwc_codec *const codec, bwc_parameter *const parameter, bwc_resolution *const resolution, bwc_subband *const subband, int32 resolution_level, int16 highband_flag) @@ -464,10 +464,10 @@ initialize_subband(bwc_codec *const field, bwc_parameter *const parameter, bwc_r /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(resolution); assert(subband); - assert(resolution_level <= field->control.nDecomp + 1); + assert(resolution_level <= codec->control.nDecomp + 1); assert(highband_flag <= DIM_ALL); /*--------------------------------------------------------*\ @@ -475,7 +475,7 @@ initialize_subband(bwc_codec *const field, bwc_parameter *const parameter, bwc_r ! trol and info structures to temporary variables to make ! ! the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; param_control = ¶meter->control; param_info = ¶meter->info; @@ -523,7 +523,7 @@ initialize_subband(bwc_codec *const field, bwc_parameter *const parameter, bwc_r ! band. ! \*--------------------------------------------------------*/ subb_control->highband_flag = highband_flag; - subb_info->dwt_gain = get_dwt_energy_gain(field, highband_flag, decomp_level); + subb_info->dwt_gain = get_dwt_energy_gain(codec, highband_flag, decomp_level); /*--------------------------------------------------------*\ ! Evaluate the quantization exponent, mantissa, step size ! @@ -666,7 +666,7 @@ initialize_subband(bwc_codec *const field, bwc_parameter *const parameter, bwc_r ! Initialize the precinct structure according to the speci-! ! fied compression parameters. ! \*--------------------------------------------------------*/ - initialize_precinct(field, &subband->precinct[p], (uint32)sb_sX - subb_info->X0, (uint32)sb_sY - subb_info->Y0, + initialize_precinct(codec, &subband->precinct[p], (uint32)sb_sX - subb_info->X0, (uint32)sb_sY - subb_info->Y0, (uint32)sb_sZ - subb_info->Z0, (uint32)sb_sTS - subb_info->TS0); /*--------------------------------------------------------*\ @@ -684,7 +684,7 @@ initialize_subband(bwc_codec *const field, bwc_parameter *const parameter, bwc_r /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void fill_buffer(bwc_codec *const field, bwc_tile *const tile, ! +! FUNCTION NAME: void fill_buffer(bwc_codec *const codec, bwc_tile *const tile, ! ! ------------ bwc_parameter *const parameter, ! ! bwc_sample *const working_buffer, ! ! double *const data, ! @@ -701,7 +701,7 @@ initialize_subband(bwc_codec *const field, bwc_parameter *const parameter, bwc_r ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -732,7 +732,7 @@ initialize_subband(bwc_codec *const field, bwc_parameter *const parameter, bwc_r ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -fill_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const parameter, +fill_buffer(bwc_codec *const codec, bwc_tile *const tile, bwc_parameter *const parameter, bwc_sample *const working_buffer, bwc_stream *const data, uint16 param_id) @@ -763,7 +763,7 @@ fill_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const p /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(tile); assert(parameter); assert(working_buffer); @@ -774,7 +774,7 @@ fill_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const p ! structures to temporary variables to make the code more ! ! readable. ! \*--------------------------------------------------------*/ - info = &field->info; + info = &codec->info; tile_info = &tile->info; @@ -925,7 +925,7 @@ fill_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const p } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void fill_buffer(bwc_codec *const field, bwc_tile *const tile, ! +! FUNCTION NAME: void fill_buffer(bwc_codec *const codec, bwc_tile *const tile, ! ! ------------ bwc_parameter *const parameter, ! ! bwc_sample *const working_buffer, ! ! double *const data, ! @@ -941,7 +941,7 @@ fill_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const p ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -972,7 +972,7 @@ fill_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const p ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -flush_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const parameter, +flush_buffer(bwc_codec *const codec, bwc_tile *const tile, bwc_parameter *const parameter, bwc_sample *const working_buffer, bwc_stream *const data, uint16 param_id) @@ -1001,7 +1001,7 @@ flush_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(tile); assert(parameter); assert(working_buffer); @@ -1012,7 +1012,7 @@ flush_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const ! structures to temporary variables to make the code more ! ! readable. ! \*--------------------------------------------------------*/ - info = &field->info; + info = &codec->info; param_info = ¶meter->info; @@ -1126,7 +1126,7 @@ flush_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void buff_normalize(bwc_codec *const field, bwc_parameter *const parameter) ! +! FUNCTION NAME: void normalize_param(bwc_codec *const codec, bwc_parameter *const parameter) ! ! ! ! ! ! DESCRIPTION: ! @@ -1143,10 +1143,10 @@ flush_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! parameter bwc_parameter* - Structure defining a bwc parameter. ! +! codec bwc_codec* - Structure defining the compression/ ! +! decompression stage. ! ! ! -! working_buffer bwc_sample* - Working buffer used to store flow field ! -! data for a specific tile parameter. ! +! parameter bwc_parameter* - Structure defining a bwc parameter. ! ! ! ! RETURN VALUE: ! ! ------------- ! @@ -1163,7 +1163,7 @@ flush_buffer(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -normalize_param(bwc_codec *const field, bwc_parameter *const parameter) +normalize_param(bwc_codec *const codec, bwc_parameter *const parameter) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1196,7 +1196,7 @@ normalize_param(bwc_codec *const field, bwc_parameter *const parameter) ! info structures to temporary variables to make the code ! ! more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; param_control = ¶meter->control; param_info = ¶meter->info; @@ -1251,7 +1251,7 @@ normalize_param(bwc_codec *const field, bwc_parameter *const parameter) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void denormalize_param(bwc_codec *const field, bwc_parameter *const parameter) ! +! FUNCTION NAME: void denormalize_param(bwc_codec *const codec, bwc_parameter *const parameter) ! ! ! ! ! ! DESCRIPTION: ! @@ -1268,10 +1268,10 @@ normalize_param(bwc_codec *const field, bwc_parameter *const parameter) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! parameter bwc_parameter* - Structure defining a bwc parameter. ! +! codec bwc_codec* - Structure defining the compression/ ! +! decompression stage. ! ! ! -! working_buffer bwc_sample* - Working buffer used to store flow field ! -! data for a specific tile parameter. ! +! parameter bwc_parameter* - Structure defining a bwc parameter. ! ! ! ! RETURN VALUE: ! ! ------------- ! @@ -1288,7 +1288,7 @@ normalize_param(bwc_codec *const field, bwc_parameter *const parameter) ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -denormalize_param(bwc_codec *const field, bwc_parameter *const parameter) +denormalize_param(bwc_codec *const codec, bwc_parameter *const parameter) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1320,7 +1320,7 @@ denormalize_param(bwc_codec *const field, bwc_parameter *const parameter) ! tures to temporary variables to make the code more ! ! readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; param_info = ¶meter->info; @@ -1608,19 +1608,19 @@ bwc_free_data(bwc_stream* data) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar create_field(bwc_codec *const field) ! +! FUNCTION NAME: uchar create_codec(bwc_codec *const codec) ! ! -------------- ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function creates the field structure used to (de)compress a floating point array de- ! +! This function creates the codec structure used to (de)compress a floating point array de- ! ! fined by the bwc_initialize function. ! ! ! ! PARAMETERS: ! ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! RETURN VALUE: ! @@ -1638,7 +1638,7 @@ bwc_free_data(bwc_stream* data) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -create_field(bwc_codec *const field) +create_codec(bwc_codec *const codec) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1675,14 +1675,14 @@ create_field(bwc_codec *const field) /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); /*--------------------------------------------------------*\ ! Save the global control and info structure to temporary ! ! variables to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; - info = &field->info; + control = &codec->control; + info = &codec->info; /*--------------------------------------------------------*\ ! Calculate the number of tiles in all spatial and tempo- ! @@ -1694,8 +1694,8 @@ create_field(bwc_codec *const field) num_tiles_Z = (int)ceil(((float)info->nZ / control->tileSizeZ)); num_tiles_TS = (int)ceil(((float)info->nTS/ control->tileSizeTS)); - field->tile = calloc(control->nTiles, sizeof(bwc_tile)); - if(!field->tile) + codec->tile = calloc(control->nTiles, sizeof(bwc_tile)); + if(!codec->tile) { // memory allocation error fprintf(stderr, MEMERROR); @@ -1725,7 +1725,7 @@ create_field(bwc_codec *const field) ! Save the tile and its info and control structure to tem- ! ! porary variables to make the code more readable. ! \*--------------------------------------------------------*/ - tile = &field->tile[i]; + tile = &codec->tile[i]; tile_control = &tile->control; tile_info = &tile->info; @@ -1936,7 +1936,7 @@ create_field(bwc_codec *const field) { if(r == 0 || ((l & highband_flag) == l && l != 0)) { - if(initialize_subband(field, parameter, resolution, &resolution->subband[m], r, l)) + if(initialize_subband(codec, parameter, resolution, &resolution->subband[m], r, l)) { return 1; } @@ -2012,12 +2012,12 @@ create_field(bwc_codec *const field) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void kill_compression(bwc_codec *const field) ! +! FUNCTION NAME: void bwc_free_compression(bwc_codec *const codec) ! ! -------------- ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function deallocates the compression field structure used to define and control the ! +! This function deallocates the compression codec structure used to define and control the ! ! bwc codec and can be called if an error occurs during the (de-)compression stage or once ! ! the codec has finished. The deallocation will be carried out down to the structure levels ! ! that have been allocated. ! @@ -2027,7 +2027,7 @@ create_field(bwc_codec *const field) ! ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! RETURN VALUE: ! @@ -2360,7 +2360,7 @@ bwc_alloc_decoder() } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_error_resilience(bwc_codec *const field) ! +! FUNCTION NAME: void bwc_set_error_resilience(bwc_codec *const codec) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -2372,7 +2372,7 @@ bwc_alloc_decoder() ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! RETURN VALUE: ! @@ -2390,7 +2390,7 @@ bwc_alloc_decoder() ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_set_error_resilience(bwc_codec *const field) +bwc_set_error_resilience(bwc_codec *const codec) { /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -2400,13 +2400,13 @@ bwc_set_error_resilience(bwc_codec *const field) /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); /*--------------------------------------------------------*\ ! Save the global control structure to a temporary varia- ! ! ble to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; /*--------------------------------------------------------*\ ! Amend the codeblock style in the bwc_codec structure ! @@ -2422,7 +2422,7 @@ bwc_set_error_resilience(bwc_codec *const field) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_quant_style(bwc_codec *const field, bwc_quant_st quantization_style) ! +! FUNCTION NAME: void bwc_set_quant_style(bwc_codec *const codec, bwc_quant_st quantization_style) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -2434,7 +2434,7 @@ bwc_set_error_resilience(bwc_codec *const field) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! quantization_style bwc_quant_st - Quantization style used during compres- ! @@ -2455,7 +2455,7 @@ bwc_set_error_resilience(bwc_codec *const field) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -set_quant_style(bwc_codec *const field, bwc_quant_st quantization_style) +set_quant_style(bwc_codec *const codec, bwc_quant_st quantization_style) { /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -2465,14 +2465,14 @@ set_quant_style(bwc_codec *const field, bwc_quant_st quantization_style) /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert((quantization_style == bwc_qt_derived) || (quantization_style == bwc_qt_none)); /*--------------------------------------------------------*\ ! Save the global control structure to a temporary varia- ! ! ble to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; /*--------------------------------------------------------*\ ! Amend the quantization style in the bwc_codec structure ! @@ -2488,7 +2488,7 @@ set_quant_style(bwc_codec *const field, bwc_quant_st quantization_style) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_quant_step_size(bwc_codec *const field, double delta) ! +! FUNCTION NAME: void bwc_set_quant_step_size(bwc_codec *const codec, double delta) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -2500,7 +2500,7 @@ set_quant_style(bwc_codec *const field, bwc_quant_st quantization_style) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! delta double - Quantization step size used during ! @@ -2521,7 +2521,7 @@ set_quant_style(bwc_codec *const field, bwc_quant_st quantization_style) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -set_quant_step_size(bwc_codec *const field, double delta) +set_quant_step_size(bwc_codec *const codec, double delta) { /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -2531,13 +2531,13 @@ set_quant_step_size(bwc_codec *const field, double delta) /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); /*--------------------------------------------------------*\ ! Save the global control structure to a temporary varia- ! ! ble to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; /*--------------------------------------------------------*\ ! Check if the quantization step size lies within the ac- ! @@ -2592,7 +2592,7 @@ set_quant_step_size(bwc_codec *const field, double delta) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_progression(bwc_codec *const field, bwc_prog_ord progression) ! +! FUNCTION NAME: void set_progression(bwc_codec *const codec, bwc_prog_ord progression) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -2604,7 +2604,7 @@ set_quant_step_size(bwc_codec *const field, double delta) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! progression bwc_prog_ord - Progression orders employed during com- ! @@ -2626,7 +2626,7 @@ set_quant_step_size(bwc_codec *const field, double delta) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -set_progression(bwc_codec *const field, bwc_prog_ord progression) +set_progression(bwc_codec *const codec, bwc_prog_ord progression) { /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -2636,7 +2636,7 @@ set_progression(bwc_codec *const field, bwc_prog_ord progression) /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert((progression == bwc_prog_CPRL) || (progression == bwc_prog_LRCP) || (progression == bwc_prog_PCRL) || (progression == bwc_prog_RLCP) || (progression == bwc_prog_RPCL)); @@ -2645,7 +2645,7 @@ set_progression(bwc_codec *const field, bwc_prog_ord progression) ! Save the global control structure to a temporary varia- ! ! ble to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; /*--------------------------------------------------------*\ ! Amend the progression order in the bwc_codec structure ! @@ -2661,7 +2661,7 @@ set_progression(bwc_codec *const field, bwc_prog_ord progression) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_kernels(bwc_codec *const field, bwc_dwt_filter KernelX, ! +! FUNCTION NAME: void set_kernels(bwc_codec *const codec, bwc_dwt_filter KernelX, ! ! -------------- bwc_dwt_filter KernelY, ! ! bwc_dwt_filter KernelZ, ! ! bwc_dwt_filter KernelTS) ! @@ -2675,7 +2675,7 @@ set_progression(bwc_codec *const field, bwc_prog_ord progression) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! KernelX, KernelY, KernelZ bwc_dwt_filter - Wavelet kernels used for spatial ! @@ -2699,7 +2699,7 @@ set_progression(bwc_codec *const field, bwc_prog_ord progression) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -set_kernels(bwc_codec *const field, bwc_dwt_filter KernelX, bwc_dwt_filter KernelY, +set_kernels(bwc_codec *const codec, bwc_dwt_filter KernelX, bwc_dwt_filter KernelY, bwc_dwt_filter KernelZ, bwc_dwt_filter KernelTS) { /*-----------------------*\ @@ -2710,13 +2710,13 @@ set_kernels(bwc_codec *const field, bwc_dwt_filter KernelX, bwc_dwt_filter Kerne /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); /*--------------------------------------------------------*\ ! Save the global control structure to a temporary varia- ! ! ble to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; /*--------------------------------------------------------*\ ! Amend the wavelet kernels in the bwc_codec structure ac- ! @@ -2737,7 +2737,7 @@ set_kernels(bwc_codec *const field, bwc_dwt_filter KernelX, bwc_dwt_filter Kerne } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_decomp(bwc_codec *const field, uint8 decompX, uint8 decompY, ! +! FUNCTION NAME: void bwc_set_decomp(bwc_codec *const codec, uint8 decompX, uint8 decompY, ! ! -------------- uint8 decompZ, uint8 decompTS) ! ! ! ! DESCRIPTION: ! @@ -2749,7 +2749,7 @@ set_kernels(bwc_codec *const field, bwc_dwt_filter KernelX, bwc_dwt_filter Kerne ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! decompX, decompY, decompZ unsigned int(8 bit) - Number of spatial wavelet decomposition ! @@ -2773,7 +2773,7 @@ set_kernels(bwc_codec *const field, bwc_dwt_filter KernelX, bwc_dwt_filter Kerne ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_set_decomp(bwc_codec *const field, uint8 decompX, uint8 decompY, uint8 decompZ, uint8 decompTS) +bwc_set_decomp(bwc_codec *const codec, uint8 decompX, uint8 decompY, uint8 decompZ, uint8 decompTS) { /*-----------------------*\ ! DEFINE FLOAT VARIABLES: ! @@ -2794,14 +2794,14 @@ bwc_set_decomp(bwc_codec *const field, uint8 decompX, uint8 decompY, uint8 decom /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); /*--------------------------------------------------------*\ ! Save the global control and info structure to temporary ! ! variables to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; - info = &field->info; + control = &codec->control; + info = &codec->info; /*--------------------------------------------------------*\ ! Calculate the possible decomposition levels for all ! @@ -2863,7 +2863,7 @@ bwc_set_decomp(bwc_codec *const field, uint8 decompX, uint8 decompY, uint8 decom \*--------------------------------------------------------*/ if(initialize_gain_lut()) { - bwc_free_codec(field); + bwc_free_codec(codec); return; } @@ -2873,7 +2873,7 @@ bwc_set_decomp(bwc_codec *const field, uint8 decompX, uint8 decompY, uint8 decom ! tion (10.19) (epsilon = 6, mu = 16) from JPEG2000 by ! ! by David S. Taubman and Michael W. Marcellin (p.437). ! \*--------------------------------------------------------*/ - delta = 1/(pow(2, 2 + PREC_BIT) * sqrt(get_dwt_energy_gain(field, 0, control->nDecomp))); + delta = 1/(pow(2, 2 + PREC_BIT) * sqrt(get_dwt_energy_gain(codec, 0, control->nDecomp))); for(control->qt_exponent = 0; delta < 1; ++control->qt_exponent, delta *= 2); control->qt_mantissa = (uint16)floor(0.5f + ((delta - 1.0f) * (1 << 16))); @@ -2905,7 +2905,7 @@ bwc_set_decomp(bwc_codec *const field, uint8 decompX, uint8 decompY, uint8 decom } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_precincts(bwc_codec *const field, uint8 pX, uint8 pY, uint8 pZ, uint8 pTS) ! +! FUNCTION NAME: void bwc_set_precincts(bwc_codec *const codec, uint8 pX, uint8 pY, uint8 pZ, uint8 pTS) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -2917,7 +2917,7 @@ bwc_set_decomp(bwc_codec *const field, uint8 decompX, uint8 decompY, uint8 decom ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! px, py, pz, pTS unsigned int(8 bit) - Spatial and temporal precinct dimensions! @@ -2938,7 +2938,7 @@ bwc_set_decomp(bwc_codec *const field, uint8 decompX, uint8 decompY, uint8 decom ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_set_precincts(bwc_codec *const field, uint8 pX, uint8 pY, uint8 pZ, uint8 pTS) +bwc_set_precincts(bwc_codec *const codec, uint8 pX, uint8 pY, uint8 pZ, uint8 pTS) { /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -2949,14 +2949,14 @@ bwc_set_precincts(bwc_codec *const field, uint8 pX, uint8 pY, uint8 pZ, uint8 pT /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); /*--------------------------------------------------------*\ ! Save the global control and info structure to temporary ! ! variables to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; - info = &field->info; + control = &codec->control; + info = &codec->info; /*--------------------------------------------------------*\ ! Check if the precinct sizes are specified for a valid ! @@ -3006,7 +3006,7 @@ bwc_set_precincts(bwc_codec *const field, uint8 pX, uint8 pY, uint8 pZ, uint8 pT } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_codeblocks(bwc_codec *const field, uint8 cbX, uint8 cbY, ! +! FUNCTION NAME: void bwc_set_codeblocks(bwc_codec *const codec, uint8 cbX, uint8 cbY, ! ! -------------- uint8 cbZ, uint8 cbTS) ! ! ! ! DESCRIPTION: ! @@ -3018,7 +3018,7 @@ bwc_set_precincts(bwc_codec *const field, uint8 pX, uint8 pY, uint8 pZ, uint8 pT ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! cbx, cby, cbz, cbTS unsigned int(8 bit) - Spatial and temporal codeblock dimen- ! @@ -3039,7 +3039,7 @@ bwc_set_precincts(bwc_codec *const field, uint8 pX, uint8 pY, uint8 pZ, uint8 pT ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_set_codeblocks(bwc_codec *const field, uint8 cbX, uint8 cbY, uint8 cbZ, uint8 cbTS) +bwc_set_codeblocks(bwc_codec *const codec, uint8 cbX, uint8 cbY, uint8 cbZ, uint8 cbTS) { /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -3050,14 +3050,14 @@ bwc_set_codeblocks(bwc_codec *const field, uint8 cbX, uint8 cbY, uint8 cbZ, uint /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); /*--------------------------------------------------------*\ ! Save the global control and info structure to temporary ! ! variables to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; - info = &field->info; + control = &codec->control; + info = &codec->info; /*--------------------------------------------------------*\ ! Check if the codeblock sizes are specified for a valid ! @@ -3107,7 +3107,7 @@ bwc_set_codeblocks(bwc_codec *const field, uint8 cbX, uint8 cbY, uint8 cbZ, uint } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_qm(bwc_codec *const field, uint8 Qm) ! +! FUNCTION NAME: void bwc_set_qm(bwc_codec *const codec, uint8 Qm) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -3119,7 +3119,7 @@ bwc_set_codeblocks(bwc_codec *const field, uint8 cbX, uint8 cbY, uint8 cbZ, uint ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! Qm unsigned int(8 bit) - Q number formate range (m). ! @@ -3139,7 +3139,7 @@ bwc_set_codeblocks(bwc_codec *const field, uint8 cbX, uint8 cbY, uint8 cbZ, uint ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_set_qm(bwc_codec *const field, uint8 Qm) +bwc_set_qm(bwc_codec *const codec, uint8 Qm) { /*-----------------------*\ ! DEFINE STRUCTS: ! @@ -3149,13 +3149,13 @@ bwc_set_qm(bwc_codec *const field, uint8 Qm) /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); /*--------------------------------------------------------*\ ! Save the global control structure to a temporary varia- ! ! ble to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; /*--------------------------------------------------------*\ ! Check if the Q number formate range is valid and amend ! @@ -3188,7 +3188,7 @@ bwc_set_qm(bwc_codec *const field, uint8 Qm) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_tiles(bwc_codec *const field, uint32 tilesX, uint32 tilesY, uint32 tilesZ, ! +! FUNCTION NAME: void bwc_set_tiles(bwc_codec *const codec, uint32 tilesX, uint32 tilesY, uint32 tilesZ, ! ! -------------- uint32 tilesTS, uchar instr) ! ! ! ! DESCRIPTION: ! @@ -3201,7 +3201,7 @@ bwc_set_qm(bwc_codec *const field, uint8 Qm) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tilesX, tilesY, tilesZ unsigned int(32 bit) - Variables defining the size of ! @@ -3228,7 +3228,7 @@ bwc_set_qm(bwc_codec *const field, uint8 Qm) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -bwc_set_tiles(bwc_codec *const field, uint64 tilesX, uint64 tilesY, uint64 tilesZ, uint64 tilesTS, bwc_tile_instr instr) +bwc_set_tiles(bwc_codec *const codec, uint64 tilesX, uint64 tilesY, uint64 tilesZ, uint64 tilesTS, bwc_tile_instr instr) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -3244,15 +3244,15 @@ bwc_set_tiles(bwc_codec *const field, uint64 tilesX, uint64 tilesY, uint64 tiles /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(instr == bwc_tile_sizeof || instr == bwc_tile_numbof); /*--------------------------------------------------------*\ ! Save the global control and info structure to temporary ! ! variables to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; - info = &field->info; + control = &codec->control; + info = &codec->info; /*--------------------------------------------------------*\ ! Check if the size of one tile or the overall number of ! @@ -3415,12 +3415,12 @@ bwc_set_tiles(bwc_codec *const field, uint64 tilesX, uint64 tilesY, uint64 tiles } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_create_compression(bwc_codec *field, char *rate_control) ! +! FUNCTION NAME: void bwc_create_compression(bwc_codec *codec, char *rate_control) ! ! -------------- ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function creates the field structure used to compress a floating point array defined ! +! This function creates the codec structure used to compress a floating point array defined ! ! by the bwc_initialize function. For a compression run, the rate_control and instr arguments ! ! need to be passed to the function to properly set up the lossy compression stage. Here, the ! ! instr parameter defines whether rate control is defined by a BITRATE - a floating point val-! @@ -3431,7 +3431,7 @@ bwc_set_tiles(bwc_codec *const field, uint64 tilesX, uint64 tilesY, uint64 tiles ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! rate_control char* - Variable defining the bitrate. ! @@ -3577,7 +3577,7 @@ bwc_create_compression(bwc_codec *codec, bwc_stream *stream, char *rate_control) ! Create the codec structure used to compress a floating ! ! point array defined by the bwc_initialize function. ! \*--------------------------------------------------------*/ - if(create_field(codec)) + if(create_codec(codec)) { return 1; } @@ -3616,7 +3616,7 @@ bwc_create_compression(bwc_codec *codec, bwc_stream *stream, char *rate_control) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar bwc_compress(bwc_codec *const field, bwc_float *const data) ! +! FUNCTION NAME: uchar bwc_compress(bwc_codec *const codec, bwc_float *const data) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -3627,7 +3627,7 @@ bwc_create_compression(bwc_codec *codec, bwc_stream *stream, char *rate_control) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! RETURN VALUE: ! @@ -3645,7 +3645,7 @@ bwc_create_compression(bwc_codec *codec, bwc_stream *stream, char *rate_control) ! ! \*----------------------------------------------------------------------------------------------------------*/ size_t -bwc_compress(bwc_codec *const field, bwc_stream *const data) +bwc_compress(bwc_codec *const codec, bwc_stream *const data) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -3691,7 +3691,7 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(data); /*--------------------------------------------------------*\ @@ -3709,8 +3709,8 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) ! Save the global control and info structure to temporary ! ! variables to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; - info = &field->info; + control = &codec->control; + info = &codec->info; /*--------------------------------------------------------*\ ! Evaluate the working buffer size and allocate it accord- ! @@ -3737,7 +3737,7 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) ! Save the tile structure in a temporary variable to make ! ! the code more readable. ! \*--------------------------------------------------------*/ - tile = &field->tile[i]; + tile = &codec->tile[i]; for(p = 0; p < info->nPar; ++p) { @@ -3758,7 +3758,7 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) start = (double)clock(); #endif #endif - fill_buffer(field, tile, parameter, working_buffer, data, p); + fill_buffer(codec, tile, parameter, working_buffer, data, p); #ifdef BWC_PROFILE #if defined (_OPENMP) end = omp_get_wtime(); @@ -3781,7 +3781,7 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) start = (double)clock(); #endif #endif - normalize_param(field, parameter); + normalize_param(codec, parameter); #ifdef BWC_PROFILE #if defined (_OPENMP) end = omp_get_wtime(); @@ -3802,7 +3802,7 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) start = (double)clock(); #endif #endif - if(forward_wavelet_transform(field, parameter)) + if(forward_wavelet_transform(codec, parameter)) { free(working_buffer); return 0; @@ -3827,7 +3827,7 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) start = (double)clock(); #endif #endif - if(t1_encode(field, tile, parameter)) + if(t1_encode(codec, tile, parameter)) { free(working_buffer); return 0; @@ -3858,7 +3858,7 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) start = (double)clock(); #endif #endif - if(t2_encode(field, tile)) + if(t2_encode(codec, tile)) { free(working_buffer); return 0; @@ -3883,7 +3883,7 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) start = (double)clock(); #endif #endif - compressed_size = assemble_codestream(field, data); + compressed_size = assemble_codestream(codec, data); if(compressed_size == 0) { free(working_buffer); @@ -3941,19 +3941,20 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar bwc_create_compression(bwc_codec *field_ptr, char *rate_control, uchar instr) ! -! -------------- ! +! FUNCTION NAME: uchar bwc_create_compression(bwc_codec *const codec, bwc_stream *const stream, ! +! -------------- uint8 layer) ! +! ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function parses the supplied bwc codestream and sets up the field structure used to ! +! This function parses the supplied bwc codestream and sets up the codec structure used to ! ! decompress the numerical dataset. ! ! ! ! PARAMETERS: ! ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! rate_control (opt) char* - Variable defining the bitrate/accuracy. ! @@ -3976,37 +3977,33 @@ bwc_compress(bwc_codec *const field, bwc_stream *const data) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -bwc_create_decompression(bwc_codec *const decoder, bwc_stream *const stream, uint8 layer) +bwc_create_decompression(bwc_codec *const codec, bwc_stream *const stream, uint8 layer) { /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(decoder); + assert(codec); assert(stream); /*--------------------------------------------------------*\ - ! Parse the stream and setup the decoder. ! + ! Parse the stream and setup the codec. ! \*--------------------------------------------------------*/ - parse_codestream(decoder, stream, layer); - if(!decoder) + parse_codestream(codec, stream, layer); + if(!codec) { return 1; } - /*--------------------------------------------------------*\ - ! If successful, return the decoder structure to the func- ! - ! tion caller. ! - \*--------------------------------------------------------*/ return 0; } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar bwc_create_compression(bwc_codec *field, float rate_control, uchar instr) ! +! FUNCTION NAME: uchar bwc_create_compression(bwc_codec *codec, float rate_control, uchar instr) ! ! -------------- ! ! ! ! DESCRIPTION: ! ! ------------ ! -! This function creates the field structure used to compress a floating point array defined ! +! This function creates the codec structure used to compress a floating point array defined ! ! by the bwc_initialize function at a prescribed bitrate or accuracy. In this context, the ! ! bitrate is a floating point value defining the average number of bits per datapoint and ! ! the accuracy is an integer value defining the exponent of the maximum allowable error ! @@ -4016,7 +4013,7 @@ bwc_create_decompression(bwc_codec *const decoder, bwc_stream *const stream, uin ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! rate_control float - Variable defining the bitrate/accuracy. ! @@ -4039,7 +4036,7 @@ bwc_create_decompression(bwc_codec *const decoder, bwc_stream *const stream, uin ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -bwc_decompress(bwc_codec *const field, bwc_stream *const data) +bwc_decompress(bwc_codec *const codec, bwc_stream *const data) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -4075,7 +4072,7 @@ bwc_decompress(bwc_codec *const field, bwc_stream *const data) /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(data); /*--------------------------------------------------------*\ @@ -4093,8 +4090,8 @@ bwc_decompress(bwc_codec *const field, bwc_stream *const data) ! Save the global control and info structure to temporary ! ! variables to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; - info = &field->info; + control = &codec->control; + info = &codec->info; /*--------------------------------------------------------*\ ! Evaluate the working buffer size and allocate it accord- ! @@ -4121,7 +4118,7 @@ bwc_decompress(bwc_codec *const field, bwc_stream *const data) ! Save the tile structure in a temporary variable to make ! ! the code more readable. ! \*--------------------------------------------------------*/ - tile = &field->tile[i]; + tile = &codec->tile[i]; for(p = 0; p < info->nPar; ++p) { @@ -4147,7 +4144,7 @@ bwc_decompress(bwc_codec *const field, bwc_stream *const data) start = (double)clock(); #endif #endif - if(t1_decode(field, tile, parameter)) + if(t1_decode(codec, tile, parameter)) { free(working_buffer); return 1; @@ -4172,7 +4169,7 @@ bwc_decompress(bwc_codec *const field, bwc_stream *const data) start = (double)clock(); #endif #endif - if(inverse_wavelet_transform(field, parameter)) + if(inverse_wavelet_transform(codec, parameter)) { free(working_buffer); return 1; @@ -4198,7 +4195,7 @@ bwc_decompress(bwc_codec *const field, bwc_stream *const data) start = (double)clock(); #endif #endif - denormalize_param(field, parameter); + denormalize_param(codec, parameter); #ifdef BWC_PROFILE #if defined (_OPENMP) end = omp_get_wtime(); @@ -4221,7 +4218,7 @@ bwc_decompress(bwc_codec *const field, bwc_stream *const data) start = (double)clock(); #endif #endif - flush_buffer(field, tile, parameter, working_buffer, data, p); + flush_buffer(codec, tile, parameter, working_buffer, data, p); #ifdef BWC_PROFILE #if defined (_OPENMP) end = omp_get_wtime(); diff --git a/src/library/tier1.c b/src/library/tier1.c index 318b3e5..1bc59fc 100755 --- a/src/library/tier1.c +++ b/src/library/tier1.c @@ -2267,7 +2267,7 @@ compute_convex_hull(bwc_encoded_cblk *const encoded_codeblock, double *const mse } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bwc_encoded_cblk* encode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, ! +! FUNCTION NAME: void encode_codeblock(bwc_codec *const codec, bwc_cblk_access *const access, ! ! -------------- bwc_coder_stripe *const codeblock, ! ! const uint64 width, ! ! const uint64 height, ! @@ -2300,7 +2300,7 @@ compute_convex_hull(bwc_encoded_cblk *const encoded_codeblock, double *const mse ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -encode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, +encode_codeblock(bwc_codec *const codec, bwc_cblk_access *const access, bwc_coder_stripe *const codeblock, const uint64 width, const uint64 height, @@ -2333,7 +2333,7 @@ encode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(access); assert(codeblock); assert(access->subband->control.highband_flag <= 15); @@ -2352,7 +2352,7 @@ encode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, ! info and encoded block structure to temporary variables ! ! to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; subb_ctrl = &access->subband->control; subb_inf = &access->subband->info; @@ -2588,7 +2588,7 @@ encode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bwc_encoded_cblk* encode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, ! +! FUNCTION NAME: void decode_codeblock(bwc_codec *const codec, bwc_cblk_access *const access, ! ! bwc_coder_stripe *const codeblock, ! ! const uint64 width, ! ! const uint64 height, ! @@ -2621,7 +2621,7 @@ encode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, ! ! \*----------------------------------------------------------------------------------------------------------*/ static void -decode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, +decode_codeblock(bwc_codec *const codec, bwc_cblk_access *const access, bwc_coder_stripe *const codeblock, const uint64 width, const uint64 height, @@ -2645,7 +2645,7 @@ decode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(access); assert(codeblock); assert(access->subband->control.highband_flag <= 15); @@ -2664,7 +2664,7 @@ decode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, ! structure to temporary variables to make the code more ! ! readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; subb_ctrl = &access->subband->control; @@ -2821,7 +2821,7 @@ decode_codeblock(bwc_codec *const field, bwc_cblk_access *const access, ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -t1_encode(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const parameter) +t1_encode(bwc_codec *const codec, bwc_tile *const tile, bwc_parameter *const parameter) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -2849,7 +2849,7 @@ t1_encode(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const par /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(tile); assert(parameter); @@ -2857,7 +2857,7 @@ t1_encode(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const par ! Save the global control structure to a temporary varia- ! ! ble to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; /*--------------------------------------------------------*\ ! Save the minimum and maximum slope values for the cur- ! @@ -3032,7 +3032,7 @@ t1_encode(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const par ! truncation points (L) and possible slope values (S) in ! ! the bwc_encoded_cblk structure. ! \*--------------------------------------------------------*/ - encode_codeblock(field, ¶meter->access[c], working_buffer, + encode_codeblock(codec, ¶meter->access[c], working_buffer, cbSizeX, cbSizeY, cbSizeZ, cbSizeTS); @@ -3123,7 +3123,7 @@ t1_encode(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const par ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -t1_decode(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const parameter) +t1_decode(bwc_codec *const codec, bwc_tile *const tile, bwc_parameter *const parameter) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -3149,7 +3149,7 @@ t1_decode(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const par /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(tile); assert(parameter); @@ -3157,7 +3157,7 @@ t1_decode(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const par ! Save the global control structure to a temporary varia- ! ! ble to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; + control = &codec->control; /*--------------------------------------------------------*\ ! Evaluate the width, height and depth of the current ! @@ -3322,7 +3322,7 @@ t1_decode(bwc_codec *const field, bwc_tile *const tile, bwc_parameter *const par if(codeblock->encoded_block->Z > 0) { - decode_codeblock(field, ¶meter->access[c], working_buffer, + decode_codeblock(codec, ¶meter->access[c], working_buffer, cbSizeX, cbSizeY, cbSizeZ, cbSizeTS); } diff --git a/src/library/tier2.c b/src/library/tier2.c index c492162..7aa0c9d 100755 --- a/src/library/tier2.c +++ b/src/library/tier2.c @@ -312,7 +312,7 @@ encode_length(bitstream *const header, bwc_codeblock *const codeblock, } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void create_quality_layers(bwc_codec *const field, bwc_tile *const tile) ! +! FUNCTION NAME: ! ! -------------- ! ! ! ! ! @@ -385,11 +385,10 @@ decode_length(bitstream *const header, bwc_codeblock *const codeblock, int8 cons } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: int64 create_packet(bwc_codec *const field, bwc_tile *const tile, ! -! -------------- bwc_resolution *const resolution, ! -! uint32 const prec_idx, ! -! int8 const q_layer, ! -! uchar const est) ! +! FUNCTION NAME: int64 create_packet(bwc_tile *const tile, bwc_resolution *const resolution, ! +! -------------- uint32 const prec_idx, ! +! int8 const q_layer, ! +! uchar const est) ! ! ! ! DESCRIPTION: ! ! ------------ ! @@ -403,9 +402,6 @@ decode_length(bitstream *const header, bwc_codeblock *const codeblock, int8 cons ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! ! tile bwc_tile* - Structure defining a bwc tile. ! ! ! ! resolution bwc_resolution* - Structure defining a bwc resolution ! @@ -435,11 +431,10 @@ decode_length(bitstream *const header, bwc_codeblock *const codeblock, int8 cons ! ! \*----------------------------------------------------------------------------------------------------------*/ static int32 -create_packet(bwc_codec *const field, bwc_tile *const tile, - bwc_resolution *const resolution, - uint32 const prec_idx, - int16 const q_layer, - uchar const est) +create_packet(bwc_tile *const tile, bwc_resolution *const resolution, + uint32 const prec_idx, + int16 const q_layer, + uchar const est) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -463,7 +458,6 @@ create_packet(bwc_codec *const field, bwc_tile *const tile, /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); assert(tile); assert(resolution); @@ -717,7 +711,7 @@ create_packet(bwc_codec *const field, bwc_tile *const tile, } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar create_packets(bwc_codec *const field, bwc_tile *const tile) ! +! FUNCTION NAME: uchar create_packets(bwc_codec *const codec, bwc_tile *const tile) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -734,7 +728,7 @@ create_packet(bwc_codec *const field, bwc_tile *const tile, ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -754,7 +748,7 @@ create_packet(bwc_codec *const field, bwc_tile *const tile, ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -create_packets(bwc_codec *const field, bwc_tile *const tile) +create_packets(bwc_codec *const codec, bwc_tile *const tile) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -775,15 +769,15 @@ create_packets(bwc_codec *const field, bwc_tile *const tile) /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(tile); /*--------------------------------------------------------*\ ! Save the global control and info structure to temporary ! ! variables to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; - info = &field->info; + control = &codec->control; + info = &codec->info; /*--------------------------------------------------------*\ ! Iterate overall quality layers for every precinct in all ! @@ -810,7 +804,7 @@ create_packets(bwc_codec *const field, bwc_tile *const tile) { for(l = 0; l < control->nLayers; ++l) { - if(create_packet(field, tile, resolution, p, l, 0) < 0) + if(create_packet(tile, resolution, p, l, 0) < 0) { // memory allocation error return 1; @@ -856,7 +850,7 @@ create_packets(bwc_codec *const field, bwc_tile *const tile) /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: int64 create_quality_layer(bwc_codec *const field, bwc_tile *const tile, ! +! FUNCTION NAME: int64 create_quality_layer(bwc_codec *const codec, bwc_tile *const tile, ! ! -------------- uint16 const threshold, ! ! int16 const q_layer, ! ! uchar const est) ! @@ -871,7 +865,7 @@ create_packets(bwc_codec *const field, bwc_tile *const tile) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -899,7 +893,7 @@ create_packets(bwc_codec *const field, bwc_tile *const tile) ! ! \*----------------------------------------------------------------------------------------------------------*/ static int64 -create_quality_layer(bwc_codec *const field, bwc_tile *const tile, +create_quality_layer(bwc_codec *const codec, bwc_tile *const tile, uint16 const threshold, int16 const q_layer, uchar const est) @@ -927,15 +921,15 @@ create_quality_layer(bwc_codec *const field, bwc_tile *const tile, /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(tile); /*--------------------------------------------------------*\ ! Save the global control and info structure to temporary ! ! variables to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; - info = &field->info; + control = &codec->control; + info = &codec->info; for(j = 0, estimated_ql_size = 0; j < info->nPar; ++j) { @@ -1067,7 +1061,7 @@ create_quality_layer(bwc_codec *const field, bwc_tile *const tile, for(p = 0; p < resolution->control.number_of_precincts; ++p) { - estimated_ph_size = create_packet(field, tile, resolution, p, q_layer, est + 1); + estimated_ph_size = create_packet(tile, resolution, p, q_layer, est + 1); if(estimated_ph_size < 0) { @@ -1086,7 +1080,7 @@ create_quality_layer(bwc_codec *const field, bwc_tile *const tile, /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void create_quality_layers(bwc_codec *const field, bwc_tile *const tile) ! +! FUNCTION NAME: void create_quality_layers(bwc_codec *const codec, bwc_tile *const tile) ! ! -------------- ! ! ! ! ! @@ -1098,7 +1092,7 @@ create_quality_layer(bwc_codec *const field, bwc_tile *const tile, ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -1118,7 +1112,7 @@ create_quality_layer(bwc_codec *const field, bwc_tile *const tile, ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -create_quality_layers(bwc_codec *const field, bwc_tile *const tile) +create_quality_layers(bwc_codec *const codec, bwc_tile *const tile) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1142,15 +1136,15 @@ create_quality_layers(bwc_codec *const field, bwc_tile *const tile) /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(tile); /*--------------------------------------------------------*\ ! Save the global and tile control and info structure to ! ! temporary variables to make the code more readable. ! \*--------------------------------------------------------*/ - control = &field->control; - info = &field->info; + control = &codec->control; + info = &codec->info; tile_control = &tile->control; tile_info = &tile->info; @@ -1200,7 +1194,7 @@ create_quality_layers(bwc_codec *const field, bwc_tile *const tile) { slope = (slope_max + slope_min) >> 1; - estimated_ql_size = create_quality_layer(field, tile, slope, l, 1); + estimated_ql_size = create_quality_layer(codec, tile, slope, l, 1); if(estimated_ql_size >= 0) { @@ -1245,7 +1239,7 @@ create_quality_layers(bwc_codec *const field, bwc_tile *const tile) slope = 0; } - estimated_ql_size = create_quality_layer(field, tile, slope, l, 0); + estimated_ql_size = create_quality_layer(codec, tile, slope, l, 0); if(estimated_ql_size >= 0) { @@ -1266,7 +1260,7 @@ create_quality_layers(bwc_codec *const field, bwc_tile *const tile) || || \************************************************************************************************************/ /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar t2_encode(bwc_codec *const field, bwc_tile *const tile) ! +! FUNCTION NAME: uchar t2_encode(bwc_codec *const codec, bwc_tile *const tile) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -1280,7 +1274,7 @@ create_quality_layers(bwc_codec *const field, bwc_tile *const tile) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -1300,19 +1294,19 @@ create_quality_layers(bwc_codec *const field, bwc_tile *const tile) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -t2_encode(bwc_codec *const field, bwc_tile *const tile) +t2_encode(bwc_codec *const codec, bwc_tile *const tile) { /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(tile); /*--------------------------------------------------------*\ ! Create the quality layers according to the bitrate val- ! ! ues provided by the user. ! \*--------------------------------------------------------*/ - if(create_quality_layers(field, tile)) + if(create_quality_layers(codec, tile)) { return 1; } @@ -1321,7 +1315,7 @@ t2_encode(bwc_codec *const field, bwc_tile *const tile) ! Create the data packets according to the quality layers ! ! evaluated in the previous step. ! \*--------------------------------------------------------*/ - if(create_packets(field, tile)) + if(create_packets(codec, tile)) { return 1; } @@ -1330,7 +1324,7 @@ t2_encode(bwc_codec *const field, bwc_tile *const tile) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar parse_packet(bwc_codec *const field, bwc_tile *const tile, ! +! FUNCTION NAME: uchar parse_packet(bwc_codec *const codec, bwc_tile *const tile, ! ! -------------- bwc_packet *const packet, ! ! uint64 const body_size) ! ! ! @@ -1343,7 +1337,7 @@ t2_encode(bwc_codec *const field, bwc_tile *const tile) ! ----------- ! ! Variable Type Description ! ! -------- ---- ----------- ! -! field bwc_codec* - Structure defining the compression/ ! +! codec bwc_codec* - Structure defining the compression/ ! ! decompression stage. ! ! ! ! tile bwc_tile* - Structure defining a bwc tile. ! @@ -1367,7 +1361,7 @@ t2_encode(bwc_codec *const field, bwc_tile *const tile) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -parse_packet(bwc_codec *const field, bwc_tile *const tile, +parse_packet(bwc_codec *const codec, bwc_tile *const tile, bwc_packet *const packet, uint64 const body_size) { @@ -1393,7 +1387,7 @@ parse_packet(bwc_codec *const field, bwc_tile *const tile, /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(field); + assert(codec); assert(tile); assert(packet); @@ -1583,7 +1577,7 @@ parse_packet(bwc_codec *const field, bwc_tile *const tile, ! If the error resilience mode is active for the current ! ! codestream... ! \*--------------------------------------------------------*/ - if(field->control.error_resilience) + if(codec->control.error_resilience) { /*--------------------------------------------------------*\ ! check if the next symbol corresponds to the end of pack- ! -- 2.45.2 From 4baaaddf5fdaf66cd5988f5e4da02803fc4530c0 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Wed, 9 Oct 2024 20:40:00 +0200 Subject: [PATCH 09/53] remove bwc_free_data --- include/library/private/libbwc.h | 3 -- src/library/libbwc.c | 55 -------------------------------- 2 files changed, 58 deletions(-) diff --git a/include/library/private/libbwc.h b/include/library/private/libbwc.h index c2b003d..5d67736 100755 --- a/include/library/private/libbwc.h +++ b/include/library/private/libbwc.h @@ -76,9 +76,6 @@ char const *const aux, uint32 const size); //==========|==========================|======================|======|=======|==================== - // TODO: remove - void bwc_free_data (bwc_stream *const data); - //==========|==========================|======================|======|=======|==================== uchar create_codec (bwc_codec *const codec); //==========|==========================|======================|======|=======|==================== bwc_codec* configure_codec (bwc_codec *const codec, diff --git a/src/library/libbwc.c b/src/library/libbwc.c index 42b09cc..bf01f88 100755 --- a/src/library/libbwc.c +++ b/src/library/libbwc.c @@ -1552,61 +1552,6 @@ bwc_set_aux(bwc_stream *const data, char const *const aux, uint32 size) return 0; } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_free_data(bwc_stream* file) ! -! -------------- ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function deallocates the data structure used to store an numerical dataset/compressed ! -! and can be called if an error occurs or once the data is no longer needed is to be closed. ! -! The deallocation will be carried out down to the structure levels that have been allocated. ! -! ! -! PARAMETERS: ! -! ----------- ! -! ! -! Variable Type Description ! -! -------- ---- ----------- ! -! file bwc_stream - Defines a structure used to store all ! -! the relevant parameters and the data ! -! field of a numerical dataset or com- ! -! pressed codestream. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! ! -! Variable Type Description ! -! -------- ---- ----------- ! -! - - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 20.06.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! 04.12.2019 Patrick Vogler B87E7E4 V 0.1.0 -! ! -\*----------------------------------------------------------------------------------------------------------*/ -void -bwc_free_data(bwc_stream* data) -{ - if(data) - { - if(data->codestream.aux) - { - release_packed_stream(data->codestream.aux); - } - if(data->codestream.com) - { - release_packed_stream(data->codestream.com); - } - free(data->codestream.aux); - free(data->codestream.com); - free(data); - } -} - /*----------------------------------------------------------------------------------------------------------*\ ! FUNCTION NAME: uchar create_codec(bwc_codec *const codec) ! ! -------------- ! -- 2.45.2 From 06b96ae5af7894a34f93ff08607e4860387b8830 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Wed, 9 Oct 2024 20:40:31 +0200 Subject: [PATCH 10/53] adjust python API --- src/interfaces/python/bwc.py | 88 ++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/src/interfaces/python/bwc.py b/src/interfaces/python/bwc.py index 5c22e93..c3e7189 100644 --- a/src/interfaces/python/bwc.py +++ b/src/interfaces/python/bwc.py @@ -84,37 +84,37 @@ const = _const() #| | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] |# #| |# #**************************************************************************************************# -def free_data(data): - fun = libbwc.bwc_free_data - fun.restype = None - fun.argtypes = [ctypes.c_void_p] - fun(data) -#==================================================================================================# -def initialize_data(data, nX, nY, nZ, nTS, nPar, file_extension): - fun = libbwc.bwc_initialize_data +def init_stream(inpbuf, outbuf, mode): + fun = libbwc.bwc_init_stream fun.restype = ctypes.c_void_p fun.argtypes = [ndpointer(ctypes.c_double, flags="C_CONTIGUOUS"), - ctypes.c_uint64, - ctypes.c_uint64, + ndpointer(ctypes.c_double, flags="C_CONTIGUOUS"), + ctypes.c_char_p] + return ctypes.c_void_p(fun(inpbuf, outbuf, mode.encode('utf-8'))) +#==================================================================================================# +def alloc_coder(nX, nY, nZ, nTS, nPar, prec): + fun = libbwc.bwc_alloc_coder + fun.restype = ctypes.c_void_p + fun.argtypes = [ctypes.c_uint64, ctypes.c_uint64, ctypes.c_uint64, ctypes.c_uint8, ctypes.c_char_p] - return ctypes.c_void_p(fun(data, nX, nY, nZ, nTS, nPar, file_extension.encode('utf-8'))) + return ctypes.c_void_p(fun(nX, nY, nZ, nTS, nPar, prec.encode('utf-8'))) #==================================================================================================# -def kill_compression(field): - fun = libbwc.bwc_kill_compression +def alloc_decoder(): + fun = libbwc.bwc_alloc_decoder + fun.restype = ctypes.c_void_p + fun.argtypes = [] + return ctypes.c_void_p(fun()) +#==================================================================================================# +def free_codec(codec): + fun = libbwc.bwc_free_codec fun.restype = None fun.argtypes = [ctypes.c_void_p] - fun(field) + fun(codec) #==================================================================================================# -def initialize_field(data): - fun = libbwc.bwc_initialize_field - fun.restype = ctypes.c_void_p - fun.argtypes = [ctypes.c_void_p] - return ctypes.c_void_p(fun(data)) -#==================================================================================================# -def set_codeblocks(field, cbX, cbY, cbZ, cbTS): +def set_codeblocks(codec, cbX, cbY, cbZ, cbTS): fun = libbwc.bwc_set_codeblocks fun.restype = None fun.argtypes = [ctypes.c_void_p, @@ -122,9 +122,9 @@ def set_codeblocks(field, cbX, cbY, cbZ, cbTS): ctypes.c_uint8, ctypes.c_uint8, ctypes.c_uint8] - fun(field, cbX, cbY, cbZ, cbTS) + fun(codec, cbX, cbY, cbZ, cbTS) #==================================================================================================# -def set_decomp(field, decompX, decompY, decompZ, decompTS): +def set_decomp(codec, decompX, decompY, decompZ, decompTS): fun = libbwc.bwc_set_decomp fun.restype = None fun.argtypes = [ctypes.c_void_p, @@ -132,16 +132,16 @@ def set_decomp(field, decompX, decompY, decompZ, decompTS): ctypes.c_uint8, ctypes.c_uint8, ctypes.c_uint8] - fun(field, decompX, decompY, decompZ, decompTS) + fun(codec, decompX, decompY, decompZ, decompTS) #==================================================================================================# -def set_qm(field, Qm): +def set_qm(codec, Qm): fun = libbwc.bwc_set_qm fun.restype = None fun.argtypes = [ctypes.c_void_p, - ctypes.c_int8] - fun(field, Qm) + ctypes.c_uint8] + fun(codec, Qm) #==================================================================================================# -def set_tiles(field, tilesX, tilesY, tilesZ, tilesTS, instr): +def set_tiles(codec, tilesX, tilesY, tilesZ, tilesTS, instr): fun = libbwc.bwc_set_tiles fun.restype = None fun.argtypes = [ctypes.c_void_p, @@ -150,9 +150,9 @@ def set_tiles(field, tilesX, tilesY, tilesZ, tilesTS, instr): ctypes.c_uint64, ctypes.c_uint64, ctypes.c_char_p] - fun(field, tilesX, tilesY, tilesZ, tilesTS, instr.encode('utf-8')) + fun(codec, tilesX, tilesY, tilesZ, tilesTS, instr.encode('utf-8')) #==================================================================================================# -def set_precincts(field, pX, pY, pZ, pTS): +def set_precincts(codec, pX, pY, pZ, pTS): fun = libbwc.bwc_set_precincts fun.restype = None fun.argtypes = [ctypes.c_void_p, @@ -160,32 +160,34 @@ def set_precincts(field, pX, pY, pZ, pTS): ctypes.c_uint8, ctypes.c_uint8, ctypes.c_uint8] - fun(field, pX, pY, pZ, pTS) + fun(codec, pX, pY, pZ, pTS) #==================================================================================================# -def create_compression(field, rate_control): +def create_compression(codec, stream, rate_control): fun = libbwc.bwc_create_compression - fun.restype = None + fun.restype = ctypes.c_uchar fun.argtypes = [ctypes.c_void_p, + ctypes.c_void_p, ctypes.c_char_p] - fun(field, rate_control.encode('utf-8')) + return ctypes.c_uchar(fun(codec, stream, rate_control.encode('utf-8'))) #==================================================================================================# -def compress(field, data): +def compress(codec, stream): fun = libbwc.bwc_compress - fun.restype = None + fun.restype = ctypes.c_size_t fun.argtypes = [ctypes.c_void_p, ctypes.c_void_p] - fun(field, data) + return ctypes.c_size_t(fun(codec, stream)) #==================================================================================================# -def create_decompression(field, data): +def create_decompression(codec, stream, layer): fun = libbwc.bwc_create_decompression - fun.restype = ctypes.c_void_p + fun.restype = ctypes.c_uchar fun.argtypes = [ctypes.c_void_p, + ctypes.c_void_p, ctypes.c_uint8] - return ctypes.c_void_p(fun(field, data)) + return ctypes.c_uchar(fun(codec, stream, layer)) #==================================================================================================# -def decompress(field, data): +def decompress(codec, stream): fun = libbwc.bwc_decompress - fun.restype = None + fun.restype = ctypes.c_uchar fun.argtypes = [ctypes.c_void_p, ctypes.c_void_p] - fun(field, data) \ No newline at end of file + return ctypes.c_uchar(fun(codec, stream)) \ No newline at end of file -- 2.45.2 From d8e2e58862641ff5a98192b29422f748eacbef70 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Wed, 9 Oct 2024 21:20:00 +0200 Subject: [PATCH 11/53] adjust Fortran API --- src/interfaces/fortran/bwc.F90 | 356 ++++++++++----------------------- 1 file changed, 103 insertions(+), 253 deletions(-) diff --git a/src/interfaces/fortran/bwc.F90 b/src/interfaces/fortran/bwc.F90 index aa413e9..dae5ec8 100644 --- a/src/interfaces/fortran/bwc.F90 +++ b/src/interfaces/fortran/bwc.F90 @@ -48,10 +48,10 @@ module bwc !| | | \| |___ |___ |__| |__/ |___ |! !| |! !************************************************************************************************! - use, intrinsic :: iso_c_binding, only: C_PTR, C_INT64_T, C_INT32_T, C_INT16_T, C_INT8_T, & - C_INT, C_DOUBLE, C_CHAR, C_SIGNED_CHAR - IMPLICIT NONE - PRIVATE + use, intrinsic :: iso_c_binding, only: c_ptr, c_int64_t, c_int32_t, c_int16_t, c_int8_t, & + c_int, c_double, c_char, c_signed_char + implicit none + private !************************************************************************************************! !| ____ ____ _ _ ____ ___ ____ _ _ ___ ____ |! @@ -59,25 +59,25 @@ module bwc !| |___ |__| | \| ___] | | | | \| | ___] |! !| |! !************************************************************************************************! - ENUM, BIND(C) + enum, bind(c) enumerator :: bwc_dwt_9_7 = 0, & bwc_dwt_5_3 = 1, & bwc_dwt_haar = 2 - END ENUM + end enum !*==============================================================================================*! - ENUM, BIND(C) - enumerator :: bwc_prog_LRCP = 0 - END ENUM + enum, bind(c) + enumerator :: bwc_prog_lrcp = 0 + end enum !*==============================================================================================*! - ENUM, BIND(C) + enum, bind(c) enumerator :: bwc_qt_none = 0, & bwc_qt_derived = 1 - END ENUM + end enum !*==============================================================================================*! - ENUM, BIND(C) + enum, bind(c) enumerator :: bwc_tile_sizeof = 0, & bwc_tile_numbof = 1 - END ENUM + end enum !************************************************************************************************! !| ___ _ _ ___ _ _ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ |! @@ -86,258 +86,113 @@ module bwc !| |! !************************************************************************************************! interface - function initialize_data_f(field, nX, nY, nZ, nTS, nPar, file_extension) result(data) & - BIND(C, NAME="bwc_initialize_data") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: field - TYPE(C_PTR) :: data - - !*-----------------------*! - ! DEFINE INT VARIABLES: ! - !*-----------------------*! - INTEGER(KIND=C_INT16_T), VALUE :: nX, nY, nZ - INTEGER(KIND=C_INT8_T), VALUE :: nTS, nPar - - !*-----------------------*! - ! DEFINE CHAR VARIABLES: ! - !*-----------------------*! - CHARACTER(KIND=C_CHAR) :: file_extension(*) - end function initialize_data_f + function init_stream_f(inpbuf, outbuf, mode) result(stream) & + bind(c, name="bwc_init_stream") + import + type(c_ptr) :: stream + type(c_ptr), value :: inpbuf + type(c_ptr), value :: outbuf + integer(kind=c_int), value :: mode + end function init_stream_f !*============================================================================================*! - subroutine free_data_f(data) & - BIND(C, NAME="bwc_free_data") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: data - end subroutine free_data_f + function alloc_coder_f(nx, ny, nz, nts, npar, prec) result(codec) & + bind(c, name="bwc_alloc_coder") + import + type(c_ptr) :: codec + integer(kind=c_int64_t), value :: nx, ny, nz, nts + integer(kind=c_int8_t), value :: npar + integer(kind=c_int), value :: prec + end function alloc_coder_f !*============================================================================================*! - subroutine kill_compression_f(field) & - BIND(C, NAME="bwc_kill_compression") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: field - end subroutine kill_compression_f + function alloc_decoder_f() result(codec) & + bind(c, name="bwc_alloc_decoder") + import + type(c_ptr) :: codec + end function alloc_decoder_f !*============================================================================================*! - function initialize_field_f(data) result(field) & - BIND(C, NAME="bwc_initialize_field") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: data - TYPE(C_PTR) :: field - end function initialize_field_f + subroutine free_codec_f(codec) & + bind(c, name="bwc_free_codec") + import + type(c_ptr), value :: codec + end subroutine free_codec_f !*============================================================================================*! - subroutine set_error_resilience_f(field) & - BIND(C, NAME="bwc_set_error_resilience") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: field + subroutine set_error_resilience_f(codec) & + bind(c, name="bwc_set_error_resilience") + import + type(c_ptr), value :: codec end subroutine set_error_resilience_f !*============================================================================================*! - subroutine set_quantization_style_f(field, quantization_style) & - BIND(C, NAME="bwc_set_quantization_style") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: field - - !*-----------------------*! - ! DEFINE INT VARIABLES: ! - !*-----------------------*! - INTEGER(KIND=C_INT), VALUE :: quantization_style - end subroutine set_quantization_style_f - !*============================================================================================*! - subroutine set_quantization_step_size_f(field, delta) & - BIND(C, NAME="bwc_set_quantization_step_size") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: field - - !*-----------------------*! - ! DEFINE FLOAT VARIABLES: ! - !*-----------------------*! - REAL(KIND=C_DOUBLE), VALUE :: delta - end subroutine set_quantization_step_size_f - !*============================================================================================*! - subroutine set_progression_f(field, progression) & - BIND(C, NAME="bwc_set_progression") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: field - - !*-----------------------*! - ! DEFINE INT VARIABLES: ! - !*-----------------------*! - INTEGER(KIND=C_INT), VALUE :: progression - end subroutine set_progression_f - !*============================================================================================*! - subroutine set_kernels_f(field, KernelX, KernelY, KernelZ, KernelTS) & - BIND(C, NAME="bwc_set_kernels") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: field - - !*-----------------------*! - ! DEFINE INT VARIABLES: ! - !*-----------------------*! - INTEGER(KIND=C_INT), VALUE :: KernelX, KernelY - INTEGER(KIND=C_INT), VALUE :: KernelZ, KernelTS - end subroutine set_kernels_f - !*============================================================================================*! - subroutine set_decomp_f(field, decompX, decompY, decompZ, decompTS) & - BIND(C, NAME="bwc_set_decomp") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: field - - !*-----------------------*! - ! DEFINE INT VARIABLES: ! - !*-----------------------*! - INTEGER(KIND=C_INT8_T), VALUE :: decompX, decompY - INTEGER(KIND=C_INT8_T), VALUE :: decompZ, decompTS + subroutine set_decomp_f(codec, decompx, decompy, decompz, decompts) & + bind(c, name="bwc_set_decomp") + import + type(c_ptr), value :: codec + integer(kind=c_int8_t), value :: decompx, decompy + integer(kind=c_int8_t), value :: decompz, decompts end subroutine set_decomp_f !*============================================================================================*! - subroutine set_precincts_f(field, pX, pY, pZ, pTS) & - BIND(C, NAME="bwc_set_precincts") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: field - - !*-----------------------*! - ! DEFINE INT VARIABLES: ! - !*-----------------------*! - INTEGER(KIND=C_INT8_T), VALUE :: pX, pY - INTEGER(KIND=C_INT8_T), VALUE :: pZ, pTS + subroutine set_precincts_f(codec, px, py, pz, pts) & + bind(c, name="bwc_set_precincts") + import + type(c_ptr), value :: codec + integer(kind=c_int8_t), value :: px, py + integer(kind=c_int8_t), value :: pz, pts end subroutine set_precincts_f !*============================================================================================*! - subroutine set_codeblocks_f(field, cbX, cbY, cbZ, cbTS) & - BIND(C, NAME="bwc_set_codeblocks") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: field - - !*-----------------------*! - ! DEFINE INT VARIABLES: ! - !*-----------------------*! - INTEGER(KIND=C_INT8_T), VALUE :: cbX, cbY - INTEGER(KIND=C_INT8_T), VALUE :: cbZ, cbTS + subroutine set_codeblocks_f(codec, cbx, cby, cbz, cbts) & + bind(c, name="bwc_set_codeblocks") + import + type(c_ptr), value :: codec + integer(kind=c_int8_t), value :: cbx, cby + integer(kind=c_int8_t), value :: cbz, cbts end subroutine set_codeblocks_f !*============================================================================================*! - subroutine set_qm_f(field, Qm) & - BIND(C, NAME="bwc_set_qm") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: field - - !*-----------------------*! - ! DEFINE INT VARIABLES: ! - !*-----------------------*! - INTEGER(KIND=C_INT8_T), VALUE :: Qm + subroutine set_qm_f(codec, qm) & + bind(c, name="bwc_set_qm") + import + type(c_ptr), value :: codec + integer(kind=c_int8_t), value :: qm end subroutine set_qm_f !*============================================================================================*! - subroutine set_tiles_f(field, tilesX, tilesY, tilesZ, tilesTS, instr) & - BIND(C, NAME="bwc_set_tiles") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: field - - !*-----------------------*! - ! DEFINE INT VARIABLES: ! - !*-----------------------*! - INTEGER(KIND=C_INT64_T), VALUE :: tilesX, tilesY, tilesZ - INTEGER(KIND=C_INT16_T), VALUE :: tilesTS - INTEGER(KIND=C_INT), VALUE :: instr + subroutine set_tiles_f(codec, tilesx, tilesy, tilesz, tilests, instr) & + bind(c, name="bwc_set_tiles") + import + type(c_ptr), value :: codec + integer(kind=c_int64_t), value :: tilesx, tilesy, tilesz, tilests + integer(kind=c_int), value :: instr end subroutine set_tiles_f !*============================================================================================*! - function create_compression_f(field, rate_control) result(error_flag) & - BIND(C, NAME="bwc_create_compression") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: field - - !*-----------------------*! - ! DEFINE INT VARIABLES: ! - !*-----------------------*! - INTEGER(KIND=C_INT8_T) :: error_flag - - !*-----------------------*! - ! DEFINE CHAR VARIABLES: ! - !*-----------------------*! - CHARACTER(KIND=C_CHAR) :: rate_control(*) + function create_compression_f(codec, stream, rate_control) result(error_flag) & + bind(c, name="bwc_create_compression") + import + integer(kind=c_int8_t) :: error_flag + type(c_ptr), value :: codec + type(c_ptr), value :: stream + character(kind=c_char) :: rate_control(*) end function create_compression_f !*============================================================================================*! - function compress_f(field, data) result(error_flag) & - BIND(C, NAME="bwc_compress") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: field - TYPE(C_PTR), VALUE :: data - - !*-----------------------*! - ! DEFINE INT VARIABLES: ! - !*-----------------------*! - INTEGER(KIND=C_INT8_T) :: error_flag + function compress_f(codec, stream) result(error_flag) & + bind(c, name="bwc_compress") + import + integer(kind=c_int8_t) :: error_flag + type(c_ptr), value :: codec + type(c_ptr), value :: stream end function compress_f !*============================================================================================*! - function create_decompression_f(data, layer) result(field) & - BIND(C, NAME="bwc_create_decompression") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR) :: field - TYPE(C_PTR), VALUE :: data - - !*-----------------------*! - ! DEFINE INT VARIABLES: ! - !*-----------------------*! - INTEGER(KIND=C_INT8_T), VALUE :: layer + function create_decompression_f(codec, stream, layer) result(error_flag) & + bind(c, name="bwc_create_decompression") + import + integer(kind=c_int8_t) :: error_flag + type(c_ptr), value :: codec + type(c_ptr), value :: stream + integer(kind=c_int8_t), value :: layer end function create_decompression_f !*============================================================================================*! - function decompress_f(field, data) result(error_flag) & - BIND(C, NAME="bwc_decompress") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: field - TYPE(C_PTR), VALUE :: data - - !*-----------------------*! - ! DEFINE INT VARIABLES: ! - !*-----------------------*! - INTEGER(KIND=C_INT8_T) :: error_flag + function decompress_f(codec, stream) result(error_flag) & + bind(c, name="bwc_decompress") + import + integer(kind=c_int8_t) :: error_flag + type(c_ptr), value :: codec + type(c_ptr), value :: stream end function decompress_f end interface @@ -359,22 +214,17 @@ module bwc public :: bwc_tile_sizeof, & bwc_tile_numbof - public :: bwc_initialize_data, & - bwc_free_data - - public :: bwc_initialize_field, & - bwc_kill_compression + public :: bwc_init_stream, & + bwc_alloc_coder, & + bwc_alloc_decoder, & + bwc_free_codec public :: bwc_set_error_resilience, & - bwc_set_quantization_style, & - bwc_set_quantization_step_size, & - bwc_set_progression, & - bwc_set_kernels, & bwc_set_decomp, & bwc_set_precincts, & bwc_set_codeblocks, & bwc_set_qm, & - bwc_set_tiles, + bwc_set_tiles public :: bwc_create_compression, & bwc_compress, & -- 2.45.2 From fc922d435427cc4d560d600d1df4c2cf22eaa9d7 Mon Sep 17 00:00:00 2001 From: Patrick Vogler Date: Tue, 15 Oct 2024 11:08:35 +0200 Subject: [PATCH 12/53] New Command Line Tool Framework --- src/tools/bwccmdl.c | 3651 +++++++------------------------------------ 1 file changed, 589 insertions(+), 3062 deletions(-) diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index 0749c24..f59e5b4 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -1,3143 +1,670 @@ -/*====================================================================================================================*\ -|| || -|| /$$$$$$$ /$$ /$$ /$$ /$$ || -|| | $$__ $$|__/ | $$ /$ | $$| $$ || -|| | $$ \ $$ /$$ /$$$$$$ | $$ /$$$| $$| $$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ || -|| | $$$$$$$ | $$ /$$__ $$ | $$/$$ $$ $$| $$__ $$ /$$__ $$ /$$__ $$ /$$__ $$ || -|| | $$__ $$| $$| $$ \ $$ | $$$$_ $$$$| $$ \ $$| $$ \ $$| $$ \ $$| $$ \ $$ || -|| | $$ \ $$| $$| $$ | $$ | $$$/ \ $$$| $$ | $$| $$ | $$| $$ | $$| $$ | $$ || -|| | $$$$$$$/| $$| $$$$$$$ | $$/ \ $$| $$ | $$| $$$$$$/| $$$$$$/| $$$$$$$/ || -|| |_______/ |__/ \____ $$ |__/ \__/|__/ |__/ \______/ \______/ | $$____/ || -|| /$$ \ $$ | $$ || -|| | $$$$$$/ | $$ || -|| \______/ |__/ || -|| || -|| DESCRIPTION: || -|| ------------ || -|| This is a simple command line tool that uses the Big Whoop library to (de)com- || -|| press a 2- to 4-dimensional IEEE 754 floating point array. For further infor- || -|| mation use the --help (-h) argument in the command-line or consult the appro- || -|| priate README file. || -|| || -|| FILE REFERENCES: || -|| ---------------- || -|| || -|| Name I/O Description || -|| ---- --- ----------- || -|| - input - input - Input file that corresponds to || -|| an uncompressed dataset, for a || -|| compression run, or a com- || -|| pressed bitstream, for a decom- || -|| pression run. || -|| || -|| - output - Output - Output file that the com- || -|| pressed bitstream, for a com- || -|| pression run, or reconstructed || -|| dataset, for a decompression || -|| run, is written to. || -|| || -|| FUNCTIONS: || -|| ---------- || -|| || -|| PRIVATE: PUBLIC: || -|| -------- ------- || -|| - get_digit_sep - main || -|| - get_size || -|| - get_dimension || -|| - get_prog_ord || -|| - get_quant_style || -|| || -|| DEVELOPMENT HISTORY: || -|| -------------------- || -|| || -|| Date Author Change Id Release Description Of Change || -|| ---- ------ --------- ------- --------------------- || -|| 13.10.2017 Patrick Vogler B87D120 V 0.1.0 source file created || -|| 26.11.2020 Patrick Vogler B87E7E4 V 0.1.0 Command line tool refac- || -|| tored. || -|| || -|| || -|| ------------------------------------------------------------------------------------------------------ || -|| || -|| Copyright (c) 2023, High Performance Computing Center - University of Stuttgart || -|| || -|| Redistribution and use in source and binary forms, with or without modification, are permitted || -|| provided that the following conditions are met: || -|| || -|| (1) Redistributions of source code must retain the above copyright notice, this list of || -|| conditions and the following disclaimer. || -|| || -|| (2) Redistributions in binary form must reproduce the above copyright notice, this list || -|| of conditions and the following disclaimer in the documentation and/or other materials || -|| provided with the distribution. || -|| || -|| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED || -|| WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A || -|| PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR || -|| ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT || -|| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS || -|| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR || -|| TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF || -|| ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. || -|| || -\*====================================================================================================================*/ -/**********************************************************************************************************************\ -|| _ _ _ ____ _ _ _ ___ ____ || -|| | |\ | | | | | | \ |___ || -|| | | \| |___ |___ |__| |__/ |___ || -|| || -\**********************************************************************************************************************/ +/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*\ +|| || +|| /$$$$$$$ /$$ /$$ /$$ /$$ || +|| | $$__ $$|__/ | $$ /$ | $$| $$ || +|| | $$ \ $$ /$$ /$$$$$$ | $$ /$$$| $$| $$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ || +|| | $$$$$$$ | $$ /$$__ $$ | $$/$$ $$ $$| $$__ $$ /$$__ $$ /$$__ $$ /$$__ $$ || +|| | $$__ $$| $$| $$ \ $$ | $$$$_ $$$$| $$ \ $$| $$ \ $$| $$ \ $$| $$ \ $$ || +|| | $$ \ $$| $$| $$ | $$ | $$$/ \ $$$| $$ | $$| $$ | $$| $$ | $$| $$ | $$ || +|| | $$$$$$$/| $$| $$$$$$$ | $$/ \ $$| $$ | $$| $$$$$$/| $$$$$$/| $$$$$$$/ || +|| |_______/ |__/ \____ $$ |__/ \__/|__/ |__/ \______/ \______/ | $$____/ || +|| /$$ \ $$ | $$ || +|| | $$$$$$/ | $$ || +|| \______/ |__/ || +|| || +\* -------------------------------------------------------------------------------------------- */ +/** + * @file test.c + * + * This file defines a simple command line tool that uses the Big Whoop library to + * (de) compress a 2- to 4-dimensional IEEE 754 floating point array. For further + * information use the --help (-h) argument in the command-line or consult the + * appropriate README file. + * */ +/* -------------------------------------------------------------------------------------------- *\ +|| Copyright (c) 2023, High Performance Computing Center - University of Stuttgart || +|| || +|| Redistribution and use in source and binary forms, with or without modification, are || +|| permitted provided that the following conditions are met: || +|| || +|| (1) Redistributions of source code must retain the above copyright notice, this list of || +|| conditions and the following disclaimer. || +|| || +|| (2) Redistributions in binary form must reproduce the above copyright notice, this list || +|| of conditions and the following disclaimer in the documentation and/or other || +|| materials provided with the distribution. || +|| || +|| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS || +|| OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF || +|| MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE || +|| COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, || +|| EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF || +|| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) || +|| HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR || +|| TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, || +|| EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. || +|| || +\*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ +#include #include -#include -#include #include -#include -#include #include #include #include -#include -#include -#include -#include "bwccmdl.h" -#include "eas3.h" +/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*\ +|| _ _ ____ ____ ____ ____ ____ || +|| |\/| |__| | |__/ | | [__ || +|| | | | | |___ | \ |__| ___] || +|| || +\*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ +/// @cond DO_NOT_DOCUMENT +/*================================================================================================*/ +/** + * @details This macro defines a simple operation to remove a supplied deliminator from a string. + */ +/*===========================================================================|====================*/ +#define remove_deliminator(arg, end, delim) \ +{ \ + for(end = arg; *end; end++) \ + *end = (*end == delim ? ' ' : *end); \ +} +/// @endcond -/**********************************************************************************************************************\ -|| ____ _ ____ ___ ____ _ ____ ____ _ _ ____ ___ ____ _ _ ___ ____ || -|| | __ | | | |__] |__| | | | | |\ | [__ | |__| |\ | | [__ || -|| |__] |___ |__| |__] | | |___ |___ |__| | \| ___] | | | | \| | ___] || -|| || -\**********************************************************************************************************************/ -/*--------------------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This array defines the arguments supported by the bwc command line tool. Each ! -! argument follows the following structure: ! -! ! -! | flag | long name | short name | opt | type | example | description | ! -! ! -! The flag signals if the argument is active, while the opt and type string def- ! -! ine the argument type and wether it is optional. Finally, the example string ! -! is 24 characters long and highlights how the argument is to be used while the ! -! description should be no longer than 1024 and contain the argument description. ! -! Additionally, the description needs to be subdivided into blocks of 50 charac- ! -! ters for formating. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 09.07.2019 Patrick Vogler B87D120 V 0.1.0 Constant created. ! -! 03.05.2021 Patrick Vogler B87E7E4 V 0.1.0 Description updated. ! -! ! -\*--------------------------------------------------------------------------------------------------------------------*/ -static bwc_cmdl_args CMDL_ARGS[] = { -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "compress", "c", "arg", "str1", "-c", "Compress a numerical dataset."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "decompress", "d", "arg", "str1", "-d", "Decompress a BigWhoop file."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "analysis", "al", "arg", "lit", "-al", "Analyze the Peak Signal to Noise Ratio (PSNR) and " - "Mean Square Error (MSE) of a decompressed dataset."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "info", "if", "arg", "str1", "-if", "Display the header information of a BigWhoop file."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "help", "h", "arg", "lit", "-h", "Print this help message and exit."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "input", "i", "arg", "str1", "-i /path/to/input", "Valid path to a file that can be parsed/read by " - "this command line tool. For a full list of the " - "supported file extension see the bottom of this " - "message."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "output", "o", "arg", "str1", "-o /path/to/output", "Valid path and filename that defines the output of" - "the (de)compressed dataset. If not defined, the " - "[input] argument is used to generate the (de)com- " - "pressed output."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "reference", "rf", "arg", "str1", "-rf /path/to/output", "Valid path to a file that is used as a reference " - "for the [analysis] option."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "verbose", "v", "opt", "num1", "-v *", "Displays miscellaneous information. This option " - "accepts the value 0 (default) for compression sta-" - "tistics and 1 for the applied compression param. "}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "bitrate", "b", "opt", "numl", "-b *, *, *...", "Defines the quality layers present in the code- " - "stream as a function of the average bits per data " - "point. This option accepts real numbers in the " - "range of 0 < * < 64."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "codeblock_size", "cb", "opt", "num4", "-cb x=* y=* z=* ts=*", "Defines the codeblocks size for all dimensions and" - "timesteps. This option accepts natural numbers in " - "log2 format in the range of 1 <= * <= 10. The sum " - "of all values has to lie within the range of " - "4 < sum* < 20."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "compression_ratio", "cr", "opt", "num1", "-cr *", "Defines the ratio between the uncompresssed and " - "uncompressed file size. This option accepts all " - "positive real numbers."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "decomposition_levels", "dl", "opt", "num4", "-dl x=* y=* z=* ts=*", "Deefines the number of wavelet decompositions ap- " - "plied to all dimensions and timesteps. This option" - "accepts natural numbers in the range of 1 <= * <= " - "63."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "number_of_threads", "n", "opt", "num1", "-n *", "Defines the number of OpenMP threads used to (de) " - "compress the [input] file. This option accepts " - "natural numbers in the range of 1 <= * <= 255. "}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "layer", "l", "opt", "num1", "-l *", "Defines the quality layer used to generate the nu-" - "merical dataset from the bwc codestream. This op- " - "tion accepts natural numbers in the range of 0 < " - "* <= number_of_quality_layers."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{0, "wavelet_kernels", "k", "opt", "str4", "-k x=* y=* z=* ts=*", "Ddefines the wavelet kernels applied to all dimen-" - "sions and timesteps. This option accepts the " - "strings CDF, LeGall and Haar."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{0, "quantisation_step_size", "q", "opt", "num1", "-q *", "Defines the step size of the quantization applied " - "to the wavelet coefficients. This option accepts " - "real numbers in the range of 0 < * < 2."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "q_format_range", "qm", "opt", "num1", "-qm *", "Defines the Q format's number of fractional bits " - "used to transform the floating to a fixed point " - "format. This option accepts natural numbers in the" - "range of 1 <= * <= 62."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "error_resilience", "r", "opt", "lit", "-r", "The [error_resilience] option is used to place " - "special markers in the compressed bitstream that " - "help with error detection and limit error propaga-" - "tion."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "tile_size", "t", "opt", "num4", "-t x=* y=* z=* ts=*", "Defines the tile size for all dimensions and time-" - "steps of a tile. This option accepts natural num- " - "bers in the range of 16 <= * <= domain size."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{1, "precinct_size", "p", "opt", "num4", "-p x=* y=* z=* ts=*", "Defines the precinct size for all dimensions and " - "timesteps. This option accepts natural numbers in " - "log2 format in the range of 1 <= * <= 15."}, -//----|---------------------------|-----|---------|---------|---------------------------|--------------------------------------------------| -{0, "", "", "end", "", "", ""}}; +/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*\ +|| ____ ____ _ _ ____ ___ ____ _ _ ___ ____ || +|| | | | |\ | [__ | |__| |\ | | [__ || +|| |___ |__| | \| ___] | | | | \| | ___] || +|| || +\*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ +/*================================================================================================*/ +/** + * @details Character strings containing the cli version and bug report e-mail address. + */ +/*================================================================================================*/ +const char *argp_program_version = "bwc 0.1.0"; +const char *argp_program_bug_address = "hpcpvogl@hlrs.de"; -/**********************************************************************************************************************\ -|| ___ ____ _ _ _ ____ ___ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ || -|| |__] |__/ | | | |__| | |___ |___ | | |\ | | | | | | |\ | [__ || -|| | | \ | \/ | | | |___ | |__| | \| |___ | | |__| | \| ___] || -|| || -\**********************************************************************************************************************/ -/*----------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function converts the endianess of half, single or double precision values. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! value void* - Memory address of the parame- ! -! ter to be converted. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 30.04.2019 Patrick Vogler B87D120 V 0.1.0 function created ! -! 21.11.2019 Patrick Vogler B87E7E4 V 0.1.0 functionality expanded ! -! to 32 bit integers ! -! 21.11.2019 Patrick Vogler B87E7E4 V 0.1.0 functionality expanded ! -! to 16 bit integers ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ -static void -endian_conversion(void *value, - uint8_t const accuracy) +/*================================================================================================*/ +/** + * @details Docummentation string displayed at the start of the help section. + */ +/*================================================================================================*/ +static char doc[] = "\n"\ + "bwc is a simple command line tool that leverages the Big Whoop library to" + " (de)compress a 2- to 4-dimensional IEEE 754 " + "floating point array.\n"\ + "\n"\ + "Available use cases:\n"\ + "\n"\ + " Compression: bwc -c [INPUT] [OPTIONS]\n"\ + " Decompression: bwc -d [INPUT] [OPTIONS]\n"\ + " Analysis: bwc -a [INPUT] -r [REFERENCE]\n"\ + " Information: bwc -h [INPUT]\n"\ + "\n"\ + "Valid Option Values:\n"\ + "\n" + " String that defines: input = path/to/an/input/file.\n" + " String that defines: output = path/to/an/output/file.\n" + "\n" + " Single numerical value: num = *.\n" + " One or more numerical values seperated by commas:\n" + " narr = *,*,...\n" + "\n" + " Numerical values that can be specified globally or for\n" + " all spacial and temporal directions individually:\n" + " ndir = * or ndir = x/y/z/ts.\n"; + /*"\n" + " Single string.\n" + " One or more strings seperated by commas: sarr = *,*,...\n" + " Strings that can be specified globally or for all\n" + " spacial and temporal directions individually:\n" + " sdir = * or sdir = x/y/z/ts.\n"*/ + +//=================================================================================================| +/** + * @details Structure specifing the BigWhoop command line interface options supported by the argp + * parser. + */ +/*================================================================================================*/ +static struct argp_option options[] = { +//--------------------|-----|------------|--------------------|--------------------------------|---| +// long name | key | argument | argp flag | documentation | g | +//--------------------|-----|------------|--------------------|--------------------------------|---| +//====================|=====|============|====================|================================|===| +{0, 0, 0, 0, " [FILE OPTIONS]\n", 1}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"analysis", 'a', "", 0, "Analyze Peak Signal to Noise" + " Ratio (PSNR) and Mean Square" + " Error (MSE) between input and" + " reference file.\n", 1}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"comp", 'c', "", 0, "Compress a numerical dataset.", 1}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"decomp", 'd', "", 0, "Decompress a BigWhoop file.", 1}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"header", 'h', "", 0, "Display the header information" + " of a BigWhoop file.\n", 1}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"output", 'o', "", 0, "Defines output file.", 1}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"reference", 'r', "", 0, "Reference file used for PSNR" + " and MSE calculation.", 1}, +//====================|=====|============|====================|================================|===| +//--------------------|-----|------------|--------------------|--------------------------------|---| +// long name | key | argument | argp flag | documentation | g | +//--------------------|-----|------------|--------------------|--------------------------------|---| +//====================|=====|============|====================|================================|===| +{0, 0, 0, 0, " [LITERAL OPTIONS]\n", 2}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"erresilience", 'e', 0, 0, "Instrument bitstream to allow " + "for error resilient decoding of" + " compressed dataset.\n", 2}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"stream", 's', 0, OPTION_HIDDEN, "Stream data to and from " + "/.", 2}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"verbose", 'v', 0, 0, "Display compression statistics " + "and applied compression " + "parameters.", 2}, +//====================|=====|============|====================|================================|===| +//--------------------|-----|------------|--------------------|--------------------------------|---| +// long name | key | argument | argp flag | documentation | g | +//--------------------|-----|------------|--------------------|--------------------------------|---| +//====================|=====|============|====================|================================|===| +{0, 0, 0, 0, " [NUMERICAL OPTIONS]\n", 3}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"bitrate", 'b', "", 0, "Quality layers present in the " + "code-stream as a function of " + "the average bits per data-" + "point. Accepts real numbers in " + "the range of 0 < * < 64.\n", 3}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"codeblock", 'B', "", 0, "Codeblock size in log2 format. " + "Accepts natural numbers in the " + "range of 1 <= * <= 10 with the " + "sum having to lie in the range " + "of 4 < sum* < 20.\n", 3}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"decomplvl", 'D', "", 0, "Number of wavelet decomposi" + "tions applied to the data " + "arrays. Accepts natural numbers" + " in the range of 1 <= * <= 63." + "\n", 3}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"layer", 'l', "", OPTION_HIDDEN, "Quality layer used to recon" + "struct the numerical data set. " + "Accepts natural numbers in the " + "range of 0 < * <= number_of_" + "quality_layers.\n", 3}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"nthreads", 'n', "", 0, "Number of OpenMP threads used " + "to (de)compress the " + "file. Accepts natural numbers " + "in the range of 1 <= * <= 255." + "\n", 3}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"precinct", 'p', "", OPTION_HIDDEN, "Precinct size in log2 format. " + "Accepts natural numbers in the" + " range of 1 <= * <= 15.\n", 3}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"qstep", 'q', "", OPTION_HIDDEN, "Quantization step size applied " + "to the wavelet coefficients. " + "Accepts real numbers in the " + "range of 0 < * < 2.\n", 3}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"qformat", 'Q', "", 0, "Fractional bits of the Q number" + " format used in the floating-to" + "-fixed point transfomration. " + "Accepts natural numbers in the " + "range of 1 <= * <= 62.\n", 3}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"compratio", 'R', "", 0, "Target ratio between the uncom" + "presssed and compressed file " + "size. Accepts positive real " + "numbers.\n", 3}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"tile", 't', "", 0, "Size of tiles the dataset is " + "subdivided into. Accepts " + "natural numbers in the range " + "of 16 <= * <= domain size.", 3}, +//====================|=====|============|====================|================================|===| +//--------------------|-----|------------|--------------------|--------------------------------|---| +// long name | key | argument | argp flag | documentation | g | +//--------------------|-----|------------|--------------------|--------------------------------|---| +//====================|=====|============|====================|================================|===| +//{0, 0, 0, 0, " [NUMERICAL OPTIONS]\n", 4}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{"wkernels", 'k', "", OPTION_HIDDEN, "Wavelet kernels applied along " + "spatial and temporal aixs. " + "Accepts the strings CDF, LeGall" + " and Haar.", 4}, +//--------------------|-----|------------|--------------------|--------------------------------|---| +{0} +}; + +//=================================================================================================| +/** + * @details Constants used to signal the command_line interface mode. + */ +/*=====================================================|==========================================*/ +typedef enum { + cli_err, //!< Command-line interface error + cli_cmp, //!< Compression run + cli_dcp, //!< Decompression run + cli_anl, //!< Analyse distortion of reconstr. file + cli_hdr, //!< Display header information +} cli_mode; + +/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*\ +|| ___ ____ ____ ____ _ _ _ ____ ___ ___ _ _ ___ ____ ____ || +|| | \ |___ |__/ |__/ | | | |___ | \ | \_/ |__] |___ [__ || +|| |__/ |___ | \ | \ | \/ |___ |__/ | | | |___ ___] || +|| || +\*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ +/*================================================================================================*/ +/** + * @details Structure used to store the user supplied command-line options and arguments. + */ +/*===========================|=========================|==========================================*/ +typedef struct +{ + cli_mode mode; //!< Current state of the cli tool + + FILE *fpIn, *fpOut; //!< Pointer to input/output file + char* *in, *out; //!< Name of the input/output files + + float bitrate[10]; //!< Quality layers defined by bitrate. + + bwc_stream *stream; //!< Structure defining the BigWhoop I/O + bwc_codec *codec; //!< Structure defining the BigWhoop codec +} cli_arguments; + + +/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*\ +|| ___ ____ _ _ _ ____ ___ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ || +|| |__] |__/ | | | |__| | |___ |___ | | |\ | | | | | | |\ | [__ || +|| | | \ | \/ | | | |___ | |__| | \| |___ | | |__| | \| ___] || +|| || +\*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ +/*================================================================================================*/ +/** + * @details This function analyzes one option at a time and sets the corresponding value and + * passes arguments in the bwc_codec struct. + * + * @param[in] key Option's key corresponding to the field value in the arg_option struct. + * @param[in] arg Argument corresponding to the option key. + * @param[in,out] state Struct containing useful information about the current parsing state. + * + * @retval -1 Error + * @retval 0 OK + */ +/*================================================================================================*/ +static error_t +parse_opt(int key, + char *arg, + struct argp_state *state) +{ + /*-----------------------*\ + ! DEFINE INT VARIABLES: ! + \*-----------------------*/ + //uint64_t buff_LL; + //uint64_t multiplier; + + //uint16_t buffI; + + uint8_t i; + //uint8_t length, shift; + + + /*-----------------------*\ + ! DEFINE REAL VARIABLES: ! + \*-----------------------*/ + float bitrate; + + /*-----------------------*\ + ! DEFINE REAL VARIABLES: ! + \*-----------------------*/ + char *end; + + /*-----------------------*\ + ! DEFINE STRUCTS: ! + \*-----------------------*/ + cli_arguments *arguments; + bwc_codec *codec; + bwc_stream *stream; + /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - assert(value); - - switch(accuracy) - { - case 2: - { - uint16_t *tmp = (uint16_t*)value; - - *tmp = (uint16_t)( *tmp << 8) | - (uint16_t)( *tmp >> 8); - break; - } - - case 4: - { - uint32_t *tmp = (uint32_t*)value; - - *tmp = (uint32_t)((*tmp << 8) & 0xFF00FF00) | - (uint32_t)((*tmp >> 8) & 0x00FF00FF); - - *tmp = (uint32_t)( *tmp << 16) | - (uint32_t)( *tmp >> 16); - break; - } - - case 8: - { - uint64_t *tmp = (uint64_t*)value; - - *tmp = (uint64_t)((*tmp << 8) & 0xFF00FF00FF00FF00ULL) | - (uint64_t)((*tmp >> 8) & 0x00FF00FF00FF00FFULL); - - *tmp = (uint64_t)((*tmp << 16) & 0xFFFF0000FFFF0000ULL) | - (uint64_t)((*tmp >> 16) & 0x0000FFFF0000FFFFULL); - - *tmp = (uint64_t)( *tmp << 32) | - (uint64_t)( *tmp >> 32); - break; - } - default: - { - break; - } - } -} - -/*--------------------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function takes a command line argument, checks if it is hyphenated and, ! -! if true, returns a pointer to the first valid character in the string. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! str char* - String containing a command ! -! line argument. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! char* - Pointer to a hyphenated com- ! -! mand line argument. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 03.05.2021 Patrick Vogler B87D120 V 0.1.0 function created ! -! 04.05.2021 Patrick Vogler B87E7E4 V 0.1.0 clean up ! -! ! -\*--------------------------------------------------------------------------------------------------------------------*/ -static char* -get_opt(char* str) -{ - /*-----------------------*\ - ! DEFINE INT VARIABLES: ! - \*-----------------------*/ - size_t trim; - - trim = strspn(str, " "); - - if((trim < strlen(str)) && (str[trim] == '-')) - return &str[trim]; - else - return NULL; -} - -/*--------------------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function takes an integer value, generates a version with proper digital ! -! group separators and returns the string to the function caller. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! integer unsigned int(64 bit) - Integer value. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! char* - Character array containing the ! -! group seperated integer value. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 03.02.2020 Patrick Vogler B87D120 V 0.1.0 function created ! -! 04.05.2021 Patrick Vogler B87E7E4 V 0.1.0 clean up ! -! ! -\*--------------------------------------------------------------------------------------------------------------------*/ -static char* -get_digit_sep(uint64_t integer) -{ - /*-----------------------*\ - ! DEFINE INT VARIABLES: ! - \*-----------------------*/ - uint64_t multiplier; - uint16_t buffI; - uint8_t length, shift; - - /*-----------------------*\ - ! DEFINE CHAR VARIABLES: ! - \*-----------------------*/ - char buffC[7] = {0}; - char *str; + assert(state); /*--------------------------------------------------------*\ - ! Calculate the decimal power of the integer value, esti- ! - ! mate the length of the group seperated string and alloc- ! - ! cate the corresponding character array. ! + ! Save frequently used variables/structures to temporary ! + ! variables to make the code more readable. ! \*--------------------------------------------------------*/ - shift = (uint8_t)log10(integer); - length = (uint8_t)floor(shift/3.0f) + shift + 2; - - str = calloc(length, sizeof(char)); - if(str == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - return NULL; - } + arguments = state->input; + codec = arguments->codec; + stream = arguments->stream; /*--------------------------------------------------------*\ - ! Iterate over the integer value and assemble the group ! - ! serparated string. ! + ! Parse the cli arguments according to the supplied opt. ! \*--------------------------------------------------------*/ - do + switch(key) { - /*--------------------------------------------------------*\ - ! If the first digits do not form a group, decrement the ! - ! shift to the next group, extract the first digits from ! - ! the integer and write them to the string. ! - \*--------------------------------------------------------*/ - if(shift % 3 || shift == 0) + case 'c': { - shift -= (shift % 3); - multiplier = (uint64_t)pow(10, shift); - buffI = integer/multiplier; - integer -= (uint64_t)buffI * multiplier; - - sprintf(buffC, "%d", buffI); - strcat(str, buffC); - memset(buffC, '\0', 5); - } - /*--------------------------------------------------------*\ - ! If the next digits form a group, decrement the decimal ! - ! shift, extract digits from the integer and write them ! - ! to the string with the proper separator. ! - \*--------------------------------------------------------*/ - else - { - shift -= 3; - multiplier = (uint64_t)pow(10, shift); - buffI = integer/multiplier; - integer -= (uint64_t)buffI * multiplier; - if(strlen(str)) + arguments->mode = bwc_cmp; + printf("Compress\n"); + if(arg[0] == '-') { - sprintf(buffC, ".%03d", buffI); + argp_error(state, "No input specified\n"); } else { - sprintf(buffC, "%03d", buffI); + arguments->input = ; } - strcat(str, buffC); - memset(buffC, '\0', 5); - } - } while(shift); - return str; -} - -/*--------------------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function takes an integer value and generates a version with the appropri- ! -! ate byte unit in log2 format that is returned to the function caller. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! integer unsigned int(64 bit) - Integer value. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! char* - Character array containing ! -! the group seperated string. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 03.05.2019 Patrick Vogler B87D120 V 0.1.0 function created ! -! 04.05.2021 Patrick Vogler B87E7E4 V 0.1.0 clean up ! -! ! -\*--------------------------------------------------------------------------------------------------------------------*/ -static char* -get_size(uint64_t integer) -{ - /*-----------------------*\ - ! DEFINE INT VARIABLES: ! - \*-----------------------*/ - uint64_t multiplier; - uint8_t i; - - /*-----------------------*\ - ! DEFINE CHAR VARIABLES: ! - \*-----------------------*/ - char *sizes[] = { "EiB", "PiB", "TiB", "GiB", "MiB", "KiB", "B" }; - char *str; - - /*--------------------------------------------------------*\ - ! Set up the multiplier used to evaluate the digital unit ! - ! prefix and allocate the character array returned to the ! - ! function caller. ! - \*--------------------------------------------------------*/ - multiplier = 1024ULL * 1024ULL * 1024ULL * - 1024ULL * 1024ULL * 1024ULL; - - str = calloc(10, sizeof(char)); - if(str == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - return NULL; - } - - /*--------------------------------------------------------*\ - ! If larger than 0, iterate over the byte units until the ! - ! integer is within its range and populate the char. array ! - ! with the appropriate information. ! - \*--------------------------------------------------------*/ - if(integer > 0) - { - for(i = 0; i < 7; ++i, multiplier /= 1024) - { - if(integer < multiplier) - continue; - if(integer % multiplier == 0) - sprintf(str, "%" PRIu64 " %s", integer / multiplier, sizes[i]); - else - sprintf(str, "%.1f %s", floor((10.0 * integer) / multiplier) / 10.0, sizes[i]); break; } - } - else - { - strcpy(str, "0 B"); - } - return str; -} - - -/*--------------------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function is a variant of the DJB hash function that takes a string, con- ! -! verts it to uppercase and returns the appropriate hash. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! str char* - String used to generate a u- ! -! niquely identifiable hash. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! uint64_t - Uniquely identifiable hash. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 17.04.2019 Patrick Vogler B87D120 V 0.1.0 function created ! -! 04.05.2021 Patrick Vogler B87E7E4 V 0.1.0 clean up ! -! ! -\*--------------------------------------------------------------------------------------------------------------------*/ -static uint64_t -hash(char* str) -{ - /*-----------------------*\ - ! DEFINE INT VARIABLES: ! - \*-----------------------*/ - uint64_t hash; - uint8_t c; - - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(str); - - /*--------------------------------------------------------*\ - ! Initialize the hash with a magic number. ! - \*--------------------------------------------------------*/ - hash = 0x1505; - - /*--------------------------------------------------------*\ - ! Walk through all the characters in the string, convert ! - ! them to uppercase and use them to generate the hash. ! - \*--------------------------------------------------------*/ - while((c = *str++)) - { - if((c >= 97) && - (c <= 122)) + case 'd': { - c = c - 32; + arguments->mode = bwc_dcp; + printf("Decompress\n"); + break; } - - hash = (hash * 33) ^ c; - } - - /*--------------------------------------------------------*\ - ! Return the hash. ! - \*--------------------------------------------------------*/ - return hash; -} - -/*--------------------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function deallocates a util_arg_node linked list that is used to store ! -! the bwc command line arguments. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! args util_arg_node* - Arguments/options linked list ! -! for the bwc command-line tool. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 24.04.2019 Patrick Vogler B87D120 V 0.1.0 Function created ! -! 04.05.2021 Patrick Vogler B87E7E4 V 0.1.0 clean up ! -! ! -\*--------------------------------------------------------------------------------------------------------------------*/ -static void -bwc_kill_arg(bwc_cmdl_arg_node *args) -{ - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - bwc_cmdl_arg_node *temp; - - if(args != NULL) - { - /*--------------------------------------------------------*\ - ! Reset the arguments linked list to its root node. ! - \*--------------------------------------------------------*/ - args = args->root; - - /*--------------------------------------------------------*\ - ! Walk through the arguments linked list and deallocate ! - ! the lit_opt, num_ opt and util_arg_node structure. ! - \*--------------------------------------------------------*/ - while(args != NULL) + case 'a': { - temp = args; - args = args->next; - - free(temp->lit_opt); - free(temp->num_opt); - free(temp); + //arguments->analysis = arg; + break; } - } -} - -/*--------------------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function is used to parse the command-line arguments, check if they are ! -! valid arguments and options for the bwc command-line tool and save them in a ! -! linked list. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! argc int - Argument count ! -! ! -! argv char** - Argument vector ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! util_arg_node* - Arguments/options linked list ! -! for the bwc command-line tool. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 17.04.2019 Patrick Vogler B87D120 V 0.1.0 function created ! -! 04.05.2021 Patrick Vogler B87E7E4 V 0.1.0 clean up ! -! ! -\*--------------------------------------------------------------------------------------------------------------------*/ -static bwc_cmdl_arg_node* -parse_arguments(int argc, - char **argv) -{ - /*-----------------------*\ - ! DEFINE INT VARIABLES: ! - \*-----------------------*/ - uint64_t buf; - uint64_t *hash_list; - uint64_t *tmp; - - uint16_t l, lsiz; - - uint8_t i, j; - - /*-----------------------*\ - ! DEFINE CHAR VARIABLES: ! - \*-----------------------*/ - char *token, *ptr; - char *str; - - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - bwc_cmdl_arg_node *args; - - /*--------------------------------------------------------*\ - ! Allocate an integer array used to store the hash values ! - ! for all active command line arguments and options. ! - \*--------------------------------------------------------*/ - hash_list = calloc(40, sizeof(uint64_t)); - if(hash_list == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - return NULL; - } - - /*--------------------------------------------------------*\ - ! Loop through the command line argument list and store ! - ! the hash value of the long and short name for all active ! - ! command line arguments in the hash list. ! - \*--------------------------------------------------------*/ - for(l = 0, lsiz = 20; strcmp(CMDL_ARGS[l].arg_type, "end"); ++l) - { - if(l >= lsiz) + case 'h': { - lsiz *= 2; - hash_list = realloc(hash_list, lsiz * 2 * sizeof(uint64_t)); - if(hash_list == NULL) + //arguments->header = arg; + break; + } + case 'o': + { + //arguments->output = arg; + break; + } + case 'r': + { + //arguments->reference = arg; + break; + } + case 's': + { + //arguments->stream = 1; + break; + } + case 'v': + { + //arguments->stream = 1; + break; + } + case 'b': + { + remove_deliminator(arg, end, ','); + + for(bitrate = strtod(arg, &end), i = 0; arg != end && i < 10; + bitrate = strtod(arg, &end), i++) { - // memory allocation error - fprintf(stderr, MEMERROR); - return NULL; - } - } + arg = end; - hash_list[2 * l] = hash(CMDL_ARGS[l].arg_long); - hash_list[2 * l + 1] = hash(CMDL_ARGS[l].arg_short); - } - - /*--------------------------------------------------------*\ - ! Save the total number of active command line arguments, ! - ! reallocate the corresponding hash list and initialize ! - ! the arguments linked list. ! - \*--------------------------------------------------------*/ - lsiz = l; - tmp = realloc(hash_list, lsiz * 2 * sizeof(uint64_t)); - if(tmp == NULL) - { - // memory allocation error - free(hash_list); - fprintf(stderr, MEMERROR); - return NULL; - } - else - { - hash_list = tmp; - } - - args = calloc(1, sizeof(bwc_cmdl_arg_node)); - if(args == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - return NULL; - } - args->root = args; - - /*--------------------------------------------------------*\ - ! Walk through all the command-line arguments passed to ! - ! main. ! - \*--------------------------------------------------------*/ - for(i = 0; i < argc; ++i) - { - /*--------------------------------------------------------*\ - ! Check if the command-line argument is hyphenated, indi- ! - ! cating a bwc argument or option. If this is the case, ! - ! save a pointer to the argument in a temporary variable. ! - \*--------------------------------------------------------*/ - str = get_opt(argv[i]); - - if(str) - { - /*--------------------------------------------------------*\ - ! Generate a hash from the argument string. ! - \*--------------------------------------------------------*/ - buf = hash(++str); - - /*--------------------------------------------------------*\ - ! Check if the command-line argument is a valid bwc argu- ! - ! ment or option and if additional values are expected for ! - ! the current argument or option. The additional values ! - ! are handled according to the type of the current argu- ! - ! ment. ! - \*--------------------------------------------------------*/ - for(l = 0; l < lsiz; ++l) - { - if(buf == hash_list[2 * l] || buf == hash_list[2 * l + 1]) + if(bitrate > 0 && bitrate < 64 && errno != ERANGE) { - switch(hash(CMDL_ARGS[l].type)) - { - /*--------------------------------------------------------*\ - ! This type of argument/option requires no additional in- ! - ! formation and the parser can advance to the next hyphen- ! - ! ated command-line argument. ! - \*--------------------------------------------------------*/ - case 0x000000000B87DB14: - { - /*--------------------------------------------------------*\ - ! Store the hash identifier in the linked list node. ! - \*--------------------------------------------------------*/ - args->hash = hash_list[2 * l]; - break; - } - - /*--------------------------------------------------------*\ - ! This type of argument/option accepts a single string ! - ! that is passed to the parser as a non-hyphenated ! - ! command-line argument. ! - \*--------------------------------------------------------*/ - case 0x000000017C8A3F41: - { - /*--------------------------------------------------------*\ - ! Store the hash identifier in the linked list node. ! - \*--------------------------------------------------------*/ - args->hash = hash_list[2 * l]; - - /*--------------------------------------------------------*\ - ! Check that the next command-line argument is non-hypenat-! - ! ed. If true, allocate the lit_opt character array and ! - ! store the arguments memory handle. ! - \*--------------------------------------------------------*/ - if(((i + 1) < argc) && (get_opt(argv[i + 1]) == NULL)) - { - args->lit_opt = calloc(args->count + 1, sizeof(char*)); - if(args->lit_opt == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - bwc_kill_arg(args); - free(hash_list); - return NULL; - } - args->lit_opt[args->count++] = argv[i + 1]; - } - break; - } - - /*--------------------------------------------------------*\ - ! This type of argument/option accepts four additional ! - ! strings that are passed to parser as a non-hyphenated ! - ! command-line arguments. ! - \*--------------------------------------------------------*/ - case 0x000000017C8A3F44: - { - /*--------------------------------------------------------*\ - ! Store the hash identifier in the linked list node. ! - \*--------------------------------------------------------*/ - args->hash = hash_list[2 * l]; - - /*--------------------------------------------------------*\ - ! Loop through the next four command-line arguments, check ! - ! that they are non-hyphenated and, if true, store their ! - ! memory handle in the list node. ! - \*--------------------------------------------------------*/ - for(j = i + 1; j < argc && (get_opt(argv[j]) == NULL); ++j) - { - /*--------------------------------------------------------*\ - ! Allocate the lit_opt array for 4 character strings. ! - \*--------------------------------------------------------*/ - if(args->lit_opt == NULL) - { - args->lit_opt = calloc(4, sizeof(char*)); - if(args->lit_opt == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - bwc_kill_arg(args); - free(hash_list); - return NULL; - } - args->count = 0x04; - } - - /*--------------------------------------------------------*\ - ! Save the memory handle for the next argument in a tempo- ! - ! rary variable and tokenize the string according to the ! - ! specified delimiters. ! - \*--------------------------------------------------------*/ - str = argv[j]; - token = strtok_r(str, ":=\t, ", &ptr); - - /*--------------------------------------------------------*\ - ! Check if a valid token has been generated for the first ! - ! spatial direction. If true, save the memory handle, set ! - ! the dimension flag and generate the next token. ! - \*--------------------------------------------------------*/ - if(token && ((strchr(token, 'x') != NULL) || - (strchr(token, 'X') != NULL))) - { - token = strtok_r(NULL, ":=\t, ", &ptr); - args->lit_opt[0] = token; - args->dim |= 0x01; - token = strtok_r(NULL, ":=\t, ", &ptr); - } - - /*--------------------------------------------------------*\ - ! Check if a valid token has been generated for the second ! - ! spatial direction. If true, save the memory handle, set ! - ! the dimension flag and generate the next token. ! - \*--------------------------------------------------------*/ - if(token && ((strchr(token, 'y') != NULL) || - (strchr(token, 'Y') != NULL))) - { - token = strtok_r(NULL, ":=\t, ", &ptr); - args->lit_opt[1] = token; - args->dim |= 0x02; - token = strtok_r(NULL, ":=\t, ", &ptr); - } - - /*--------------------------------------------------------*\ - ! Check if a valid token has been generated for the third ! - ! spatial direction. If true, save the memory handle, set ! - ! the dimension flag and generate the next token. ! - \*--------------------------------------------------------*/ - if(token && ((strchr(token, 'z') != NULL) || - (strchr(token, 'Z') != NULL))) - { - token = strtok_r(NULL, ":=\t, ", &ptr); - args->lit_opt[2] = token; - args->dim |= 0x04; - token = strtok_r(NULL, ":=\t, ", &ptr); - } - - /*--------------------------------------------------------*\ - ! Check if a valid token has been generated for the first ! - ! temporal direction. If true, save the memory handle, set ! - ! the dimension flag and generate the next token. ! - \*--------------------------------------------------------*/ - if(token && ((strchr(token, 't') != NULL) || - (strchr(token, 'T') != NULL))) - { - token = strtok_r(NULL, ":=\t, ", &ptr); - args->lit_opt[3] = token; - args->dim |= 0x08; - token = strtok_r(NULL, ":=\t, ", &ptr); - } - } - break; - } - - /*--------------------------------------------------------*\ - ! This type of argument/option accepts a single numerical ! - ! value that is passed to parser as a non-hyphenated com- ! - ! mand-line argument. ! - \*--------------------------------------------------------*/ - case 0x000000017C82A8C2: - { - /*--------------------------------------------------------*\ - ! Store the hash identifier in the linked list node. ! - \*--------------------------------------------------------*/ - args->hash = hash_list[2 * l]; - - /*--------------------------------------------------------*\ - ! Check that the next command-line argument is non-hypenat-! - ! ed and a valid floating point value. If true, allocate ! - ! the num_opt array and store the real value in it. ! - \*--------------------------------------------------------*/ - if(((i + 1) < argc) && (get_opt(argv[i + 1]) == NULL)) - { - str = argv[i + 1]; - - if(strtof(str, NULL) > 0.0f) - { - args->num_opt = calloc(args->count + 1, sizeof(double)); - if(args->num_opt == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - bwc_kill_arg(args); - free(hash_list); - return NULL; - } - args->num_opt[args->count++] = strtof(str, NULL); - } - } - break; - } - - /*--------------------------------------------------------*\ - ! This type of argument/option accepts four additional nu- ! - ! merical values that are passed to parser as a non-hyphen-! - ! ated command-line arguments. ! - \*--------------------------------------------------------*/ - case 0x000000017C82A8C7: - { - /*--------------------------------------------------------*\ - ! Store the hash identifier in the linked list node. ! - \*--------------------------------------------------------*/ - args->hash = hash_list[2 * l]; - - /*--------------------------------------------------------*\ - ! Loop through the next four command-line arguments, check ! - ! that they are non-hyphenated and, if true, store their ! - ! numerical values handle in the list node. ! - \*--------------------------------------------------------*/ - for(j = i + 1; j < argc && (get_opt(argv[j]) == NULL); ++j) - { - /*--------------------------------------------------------*\ - ! Allocate the num_opt array for 4 real values. ! - \*--------------------------------------------------------*/ - if(args->num_opt == NULL) - { - args->num_opt = calloc(4, sizeof(double)); - if(args->num_opt == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - bwc_kill_arg(args); - free(hash_list); - return NULL; - } - args->count = 0x04; - } - - /*--------------------------------------------------------*\ - ! Save the memory handle for the next argument in a tempo- ! - ! rary variable and tokenize the string according to the ! - ! specified delimiters. ! - \*--------------------------------------------------------*/ - str = argv[j]; - token = strtok_r(str, ":=\t, ", &ptr); - - /*--------------------------------------------------------*\ - ! Check if a valid token has been generated for the first ! - ! spatial direction. If true, save the numerical value, ! - ! set the dimension flag and generate the next token. ! - \*--------------------------------------------------------*/ - if(token && ((strchr(token, 'x') != NULL) || - (strchr(token, 'X') != NULL))) - { - token = strtok_r(NULL, ":=\t, ", &ptr); - if(token != NULL) - { - args->num_opt[0] = strtof(token, NULL); - args->dim |= 0x01; - } - token = strtok_r(NULL, ":=\t, ", &ptr); - } - - /*--------------------------------------------------------*\ - ! Check if a valid token has been generated for the second ! - ! spatial direction. If true, save the numerical value, ! - ! set the dimension flag and generate the next token. ! - \*--------------------------------------------------------*/ - if(token && ((strchr(token, 'y') != NULL) || - (strchr(token, 'Y') != NULL))) - { - token = strtok_r(NULL, ":=\t, ", &ptr); - if(token != NULL) - { - args->num_opt[1] = strtof(token, NULL); - args->dim |= 0x02; - } - token = strtok_r(NULL, ":=\t, ", &ptr); - } - - /*--------------------------------------------------------*\ - ! Check if a valid token has been generated for the third ! - ! spatial direction. If true, save the numerical value, ! - ! set the dimension flag and generate the next token. ! - \*--------------------------------------------------------*/ - if(token && ((strchr(token, 'z') != NULL) || - (strchr(token, 'Z') != NULL))) - { - token = strtok_r(NULL, ":=\t, ", &ptr); - if(token != NULL) - { - args->num_opt[2] = strtof(token, NULL); - args->dim |= 0x04; - } - token = strtok_r(NULL, ":=\t, ", &ptr); - } - - /*--------------------------------------------------------*\ - ! Check if a valid token has been generated for the first ! - ! temporal direction. If true, save the numerical value, ! - ! set the dimension flag and generate the next token. ! - \*--------------------------------------------------------*/ - if(token && ((strchr(token, 't') != NULL) || - (strchr(token, 'T') != NULL))) - { - token = strtok_r(NULL, ":=\t, ", &ptr); - if(token != NULL) - { - args->num_opt[3] = strtof(token, NULL); - args->dim |= 0x08; - } - token = strtok_r(NULL, ":=\t, ", &ptr); - } - } - break; - } - - /*--------------------------------------------------------*\ - ! This type of argument/option accepts one ore more numeri-! - ! cal values that are passed to parser as a non-hyphenated ! - ! command-line arguments. ! - \*--------------------------------------------------------*/ - case 0x000000017C82A8BF: - { - /*--------------------------------------------------------*\ - ! Store the hash identifier in the linked list node. ! - \*--------------------------------------------------------*/ - args->hash = hash_list[2 * l]; - - /*--------------------------------------------------------*\ - ! Loop through the next command-line arguments that are ! - ! non-hyphenated and store their numerical values handle ! - ! in the list node. ! - \*--------------------------------------------------------*/ - for(j = i + 1; j < argc && (get_opt(argv[j]) == NULL); ++j) - { - /*--------------------------------------------------------*\ - ! Save the memory handle for the next argument in a tempo- ! - ! rary variable and tokenize the string according to the ! - ! specified delimiters. ! - \*--------------------------------------------------------*/ - str = argv[j]; - token = strtok_r(str, ", ", &ptr); - - /*--------------------------------------------------------*\ - ! Check if a valid token has been generated. If true, re- ! - ! size the num_opt array, save the numerical value, and ! - ! generate the next token. ! - \*--------------------------------------------------------*/ - for(; (token != NULL); token = strtok_r(NULL, ", ", &ptr)) - { - if(token != NULL) - { - if(strtof(token, NULL) > 0.0f) - { - args->num_opt = realloc(args->num_opt, (args->count + 1) * sizeof(double)); - if(args->num_opt == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - bwc_kill_arg(args); - free(hash_list); - return NULL; - } - args->num_opt[args->count++] = strtof(token, NULL); - } - } - } - } - break; - } - - default: - { - continue; - } - } - /*--------------------------------------------------------*\ - ! Allocate and initialize the next linked list node. ! - \*--------------------------------------------------------*/ - args->next = calloc(1, sizeof(bwc_cmdl_arg_node)); - if(args->next == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - bwc_kill_arg(args); - free(hash_list); - return NULL; - } - args->next->root = args->root; - args = args->next; + arguments->bitrate[i] = (float) bitrate; + } + else + { + argp_error(state, "The specified bitrate (%f) is " + "out of the supported range.\n", bitrate); + + arguments->mode = cli_err; + errno = 0; + break; } } + break; } - } - /*--------------------------------------------------------*\ - ! Free the command line argument hash list and return the ! - ! linked list to the function caller. ! - \*--------------------------------------------------------*/ - free(hash_list); - return args; -} - -/*--------------------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function is used to parse the util_arg_node linked list and, if it is pre- ! -! sent in linked list, return the memory handle to the bwc argument/option short- ! -! /long-name supplied by the function. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! args util_arg_node* - Arguments/options linked list ! -! for the bwc command-line tool. ! -! ! -! str char* - Long-/short-name of a bwc com- ! -! mand-line argument or option. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! util_arg_nodes* - Memory handle bwc argument ! -! linked list node. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 24.04.2019 Patrick Vogler B87D120 V 0.1.0 function created ! -! 04.05.2021 Patrick Vogler B87E7E4 V 0.1.0 clean up ! -! ! -\*--------------------------------------------------------------------------------------------------------------------*/ -static bwc_cmdl_arg_node* -retrieve_arg(bwc_cmdl_arg_node *const args, - char* name) -{ - /*-----------------------*\ - ! DEFINE INT VARIABLES: ! - \*-----------------------*/ - uint64_t arg_hash; - - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - bwc_cmdl_arg_node *temp; - - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(args); - assert(name); - - /*--------------------------------------------------------*\ - ! Generate a hash from the argument/option name and save ! - ! the root node memory address in a temporary variable. ! - \*--------------------------------------------------------*/ - arg_hash = hash(name); - temp = args->root; - - /*--------------------------------------------------------*\ - ! Advance through the linked list until the argument/op- ! - ! tion, corresponding to the supplied name, has been found ! - ! or the end of the list has been reached. ! - \*--------------------------------------------------------*/ - while(temp->hash != arg_hash && temp->next != NULL) - temp = temp->next; - - /*--------------------------------------------------------*\ - ! If found, return the memory handle to the argument/op- ! - ! option to the function caller. ! - \*--------------------------------------------------------*/ - if((temp->next != NULL) && (temp->hash == arg_hash)) - return temp; - else - return NULL; -} - -/*--------------------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function prints the help page to the standard output. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! - - - ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 14.05.2019 Patrick Vogler B87D120 V 0.1.0 function created ! -! 03.05.2021 Patrick Vogler B87E7E4 V 0.1.0 clean up ! -! ! -\*--------------------------------------------------------------------------------------------------------------------*/ -static void -print_help(void) -{ - /*-----------------------*\ - ! DEFINE INT VARIABLES: ! - \*-----------------------*/ - uint16_t i; - - /*-----------------------*\ - ! DEFINE CHAR VARIABLES: ! - \*-----------------------*/ - char *buf; - - /*--------------------------------------------------------*\ - ! Write the head of the help message to the standard out- ! - ! put. ! - \*--------------------------------------------------------*/ - printf("Usage: bwc [arguments] [file] [options] (De)compress a specified [file] using [options]. \n"\ - " \n"\ - "e.g.: bwc -c -i [input] -o [output] [options] Compress an [input] file with the specified [op- \n"\ - " tions] and save the compressed bitstream in the \n"\ - " [output] file. \n"\ - " \n"\ - "e.g.: bwc -c [input] [options] Compress an [input] file with the specified [op- \n"\ - " tions] and save the compressed bitstream. \n"\ - " \n"\ - "e.g.: bwc -d -i [input] -o [output] [options] Decompress an [input] file with the specified [op-\n"\ - " tions] and save the decompressed bitstream in the \n"\ - " [output] file. \n"\ - " \n"\ - "e.g.: bwc -d [input] [options] Decompress an [input] file with the specified [op-\n"\ - " tions] and save the decompressed bitstream. \n"\ - " \n"\ - "e.g.: bwc -al -i [input] -ref [reference] Evaluate the Peak-Signal-to-Noise-Ratio of the \n"\ - " [input] file with regards to the [reference] file \n"\ - " and print the result to the standard output. \n"\ - " \n"\ - "e.g.: bwc -if -i [input] Print the header information of the compressed \n"\ - " [input] file to the standard output. \n"\ - " \n"\ - " \n"\ - "Arguments: \n"\ - " \n"\ - " [Type] [Usage] [Description] \n"\ - " \n"); - - /*--------------------------------------------------------*\ - ! Loop through the command line arguments list and write ! - ! the short and long name, usage example and description ! - ! for all mandatory (arg) command line arguments to stdout.! - \*--------------------------------------------------------*/ - for(i = 0; strcmp(CMDL_ARGS[i].arg_type, "end"); ++i) - { - if(strcmp(CMDL_ARGS[i].arg_type, "arg") == 0 && CMDL_ARGS[i].active) + case 'B': { - printf(" -%s,\t", CMDL_ARGS[i].arg_short); - printf("--%-24s", CMDL_ARGS[i].arg_long); - printf("%-24s", CMDL_ARGS[i].usage); - printf("%.50s\n", CMDL_ARGS[i].definition); + // remove_deliminator(arg, end, '/'); - for(buf = CMDL_ARGS[i].definition + 50; strcmp(buf, ""); buf += 50) - { - printf("%58s%.50s\n", "", buf); - } + // for(buff_LL = strtoll(arg, &end, 10), i = 0; arg != end && i < 4; + // buff_LL = strtoll(arg, &end, 10), i++) + // { + // arg = end; + // if (errno == ERANGE) + // { + // printf("range error, got "); + // errno = 0; + // } - printf("\n"); + // if(buff_LL > 1 && buff_LL < 10) + // { + // arguments->codeblock[i] = (uint8_t) buff_LL; + // } + // else + // { + // argp_error(state, "The specified codeblock size (%ld) " + // "is out of the supported range.\n", buff_LL); + // } + // } + + // if(i == 1) + // { + // arguments->codeblock[1] = + // arguments->codeblock[2] = + // arguments->codeblock[3] = arguments->codeblock[0]; + // } + // else if(i != 4) + // { + // argp_error(state, "The codeblock argument expects either a " + // "single global or 4 dirctional values\n"); + // } + + // if(((arguments->codeblock[0] + arguments->codeblock[1] + + // arguments->codeblock[2] + arguments->codeblock[3]) < 4) || + // ((arguments->codeblock[0] + arguments->codeblock[1] + + // arguments->codeblock[2] + arguments->codeblock[3]) > 20)) + // { + // argp_error(state, "The sum of the specified codeblock sizes " + // "is outside of the supported range\n"); + // } + break; } - } - - /*--------------------------------------------------------*\ - ! Write the head of the optional arguments list to the ! - ! standard output. ! - \*--------------------------------------------------------*/ - printf("Options: \n"\ - " \n"\ - " [Type] [Usage] [Description] \n"\ - " \n"); - - /*--------------------------------------------------------*\ - ! Loop through the command line arguments list and write ! - ! the short and long name, usage example and description ! - ! for all optional (arg) command line arguments to stdout. ! - \*--------------------------------------------------------*/ - for(i = 0; strcmp(CMDL_ARGS[i].arg_type, "end"); ++i) - { - if(strcmp(CMDL_ARGS[i].arg_type, "opt") == 0 && CMDL_ARGS[i].active) + case 'R': { - printf(" -%s,\t", CMDL_ARGS[i].arg_short); - printf("--%-24s", CMDL_ARGS[i].arg_long); - printf("%-24s", CMDL_ARGS[i].usage); - printf("%.50s\n", CMDL_ARGS[i].definition); - - for(buf = CMDL_ARGS[i].definition+50; strcmp(buf, ""); buf += 50) - { - printf("%58s%.50s\n", "", buf); - } - - printf("\n"); + // arguments->compratio = (uint8_t)strtoll(arg, &end, 10); + // printf("%d\n", arguments->compratio); + break; } - } -} - -/*--------------------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function prints the header information of a compressed dataset to the ! -! standard output. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! args util_arg_node* - Arguments/options linked list ! -! for the bwc command-line tool. ! -! ! -! name char* - Long-/short-name of a bwc com- ! -! mand-line argument or option. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 12.09.2019 Patrick Vogler B87D120 V 0.1.0 function created ! -! 17.05.2021 Patrick Vogler B87E7E4 V 0.1.0 clean up ! -! ! -\*--------------------------------------------------------------------------------------------------------------------*/ -static void -output_info(bwc_cmdl_arg_node *const args, - char* name) -{ - /*-----------------------*\ - ! DEFINE INT VARIABLES: ! - \*-----------------------*/ - uint64_t data_points; - - uint64_t Ld; - uint32_t Ls; - uint16_t Lh; - - uint32_t t; - uint8_t l, p; - - uint16_t marker; - uint8_t index; - - /*-----------------------*\ - ! DEFINE FLOAT VARIABLES: ! - \*-----------------------*/ - bwc_float minVal, maxVal; - - /*-----------------------*\ - ! DEFINE CHAR VARIABLES: ! - \*-----------------------*/ - char *buff; - uchar status; - - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - bwc_field *field; - bwc_data *data; - - bwc_gl_ctrl *control; - bwc_gl_inf *info; - - bwc_param_inf *param_info; - - bwc_cmdl_arg_node *temp; - - struct stat buf; - - /*-----------------------*\ - ! DEFINE FILE POINTER: ! - \*-----------------------*/ - FILE *fp; - - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(args); - - /*--------------------------------------------------------*\ - ! Retrieve the file argument from the linked list and con- ! - ! firm that only one file has been specified and that it ! - ! is a regular file. If true, open the file for reading. ! - \*--------------------------------------------------------*/ - temp = retrieve_arg(args, name); - if((temp == NULL) || - (temp->lit_opt == NULL) || - (temp->lit_opt[0] == NULL)) - { - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: File |\n"\ - "| |\n"\ - "| No File has been specified. |\n"\ - "| |\n"\ - "o##########################################################o\n"); - return; - } - - if(temp->count > 1) - { - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: File |\n"\ - "| |\n"\ - "| More than one file has been specified. |\n"\ - "| |\n"\ - "o##########################################################o\n"); - return; - } - - stat(temp->lit_opt[0], &buf); - if(!S_ISREG(buf.st_mode)) - { - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: file |\n"\ - "| |\n"\ - "| The specified input is not a regular file. |\n"\ - "| |\n"\ - "o##########################################################o\n"); - return; - } - - fp = fopen(temp->lit_opt[0], "rb"); - if(fp == NULL) - { - // error opening file - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: Could not open or read %-25s|\n"\ - "o##########################################################o\n", temp->lit_opt[0]); - return; - } - - /*--------------------------------------------------------*\ - ! Initialize the codestream status and reading index var- ! - ! iables and parse the codestream to evaluate the size of ! - ! the main header. ! - \*--------------------------------------------------------*/ - status = CODESTREAM_OK; - index = 0; - - while(status == 0) - { - Ld = fread(&marker, sizeof(uint16_t), 1, fp); - endian_conversion(&marker, 2); - if((Ld != 1) || (marker < 0xFF00)) + case 'D': { - // Invalid Codestream - fprintf(stderr, CSTERROR); - fclose(fp); - return; - } +/* remove_deliminator(arg, end, '/'); - switch(marker) - { - case SOC: + for(buff_LL = strtoll(arg, &end, 10), i = 0; arg != end && i < 4; + buff_LL = strtoll(arg, &end, 10), i++) { - break; - } - - case COM: - case SGC: - case SGI: - default: - { - if(fread(&Lh, sizeof(uint16_t), 1, fp) != 1) + arg = end; + if (errno == ERANGE) { - // Invalid Codestream - fprintf(stderr, CSTERROR); - fclose(fp); - return; + printf("range error, got "); + errno = 0; } - endian_conversion(&Lh, 2); - fseek(fp, Lh - 2, SEEK_CUR); - - break; - } - - case SAX: - { - if(fread(&Ls, sizeof(uint32_t), 1, fp) != 1) + if(buff_LL >= 1 && buff_LL <= 63) { - // Invalid Codestream - fprintf(stderr, CSTERROR); - fclose(fp); - return; + arguments->codeblock[i] = (uint8_t) buff_LL; } - - endian_conversion(&Ls, 4); - fseek(fp, Ls - 4, SEEK_CUR); - - break; - } - - case EOH: - { - if(fread(&Lh, sizeof(uint16_t), 1, fp) != 1) + else { - // Invalid Codestream - fprintf(stderr, CSTERROR); - fclose(fp); - return; + argp_error(state, "The specified codeblock size (%ld) " + "is out of the supported range.\n", buff_LL); } - - endian_conversion(&Lh, 2); - fseek(fp, Lh - 2, SEEK_CUR); - - status |= CODESTREAM_READ; - break; } - } - index++; - } - /*--------------------------------------------------------*\ - ! Determine the size of the main header present in the bwc ! - ! codestream and allocate the data structure, packed code- ! - ! stream sub-structure and its memory block. ! - \*--------------------------------------------------------*/ - Ld = ftell(fp); - fseek(fp, 0L, SEEK_SET); - - data = calloc(1, sizeof(bwc_data)); - if(data == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - fclose(fp); - return; - } - - data->codestream.data = calloc(1, sizeof(bwc_stream)); - if(data->codestream.data == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - bwc_free_data(data); - fclose(fp); - return; - } - - data->codestream.data->memory = calloc(Ld, sizeof(uchar)); - if(data->codestream.data->memory == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - bwc_free_data(data); - fclose(fp); - return; - } - - /*--------------------------------------------------------*\ - ! Read the main header from the packed codestream of the ! - ! user specified bcw file and set up the data structure. ! - \*--------------------------------------------------------*/ - if(fread(data->codestream.data->memory, sizeof(uchar), Ld, fp) != Ld) - { - // invalid read - fprintf(stderr, RDERROR); - bwc_free_data(data); - fclose(fp); - return; - } - - data->codestream.data->access = data->codestream.data->memory; - data->codestream.data->size = Ld; - data->codestream.data->position = 0; - - /*--------------------------------------------------------*\ - ! Initialize the bitstream, parse the main header and set ! - ! up the field structure for the current dataset. ! - \*--------------------------------------------------------*/ - field = bwc_create_decompression(data, 0); - if(field == NULL) - { - bwc_free_data(data); - fclose(fp); - return; - } - control = &field->control; - info = field->info; - - /*--------------------------------------------------------*\ - ! Write the help message to the standard output. ! - \*--------------------------------------------------------*/ - printf("/================================================================================\\\n"\ - "| |\n"\ - "| .:-------------: .:-------------: |\n"\ - "| .+++++++++++++++= :+++++++++++++++- |\n"\ - "| :+++. -++= -++= |\n"\ - "| :+++. -++= -++= |\n"\ - "| -++++++++++++++= -++= -++= |\n"\ - "| .=++---------=++= -++= -++= |\n"\ - "| :+++ :++= -++= -++= |\n"\ - "| .+++=--------=+++---=+++---=+++------------: |\n"\ - "| -=++++++++++++++++++++++++++++++++++++++++- |\n"\ - "| |\n"\ - "|------------------------------ General Information -----------------------------|\n"\ - "| |\n"); - - /*--------------------------------------------------------*\ - ! Print the original file size and format. ! - \*--------------------------------------------------------*/ - 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"\ - "|%80s|\n", buff, info->f_ext, " "); - - free(buff); - - /*--------------------------------------------------------*\ - ! Print the file size and compression ratio. ! - \*--------------------------------------------------------*/ - 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"\ - "|%80s|\n", buff, ((double)data_points * 8.0f/Ld), " "); - - free(buff); - - /*--------------------------------------------------------*\ - ! Print the number of datapoints. ! - \*--------------------------------------------------------*/ - buff = get_digit_sep(data_points); - printf("| Number of Datapoints: %42s |\n"\ - "|%80s|\n", buff, " "); - free(buff); - - buff = get_digit_sep(info->nX); - printf("| -1st Dim.: %42s |\n", buff); - free(buff); - - buff = get_digit_sep(info->nY); - printf("| -2nd Dim.: %42s |\n", buff); - free(buff); - - buff = get_digit_sep(info->nZ); - printf("| -3nd Dim.: %42s |\n", buff); - free(buff); - - buff = get_digit_sep(info->nTS); - printf("| -Time Steps: %42s |\n"\ - "| -No. Params: %42d |\n"\ - "|%80s|\n", buff, info->nPar, " "); - free(buff); - - /*--------------------------------------------------------*\ - ! Print the numerical Datapoints. ! - \*--------------------------------------------------------*/ - printf("|----------------------------- Numerical Parameters -----------------------------|\n"\ - "| |\n"); - - for(p = 0; p < info->nPar; ++p) - { - param_info = &field->tile[0].parameter[p].info; - - minVal = param_info->parameter_min; - maxVal = param_info->parameter_max; - - for(t = 0; t <= control->nTiles; ++t) - { - minVal = MIN(minVal, param_info->parameter_min); - maxVal = MIN(maxVal, param_info->parameter_max); - } - - buff = param_info->name + strlen(param_info->name) - 1; - 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", param_info->name, - minVal, - maxVal); - } - printf("|%80s|\n"," "); - /*--------------------------------------------------------*\ - ! Print the quality layers. ! - \*--------------------------------------------------------*/ - printf("|-------------------------------- Quality Layers --------------------------------|\n"\ - "| |\n"); - - for(l = 0; l < control->nLayers; ++l) - { - buff = get_size(data_points * control->bitrate[l]); - - printf("| |\n"\ - "| Quality Layer Nr. %d: %40.2f Bpd |\n"\ - "| %44s |\n", l + 1, control->bitrate[l], buff); - free(buff); - } - - printf("| |\n"\ - "\\--------------------------------------------------------------------------------/\n"); - - /*--------------------------------------------------------*\ - ! Free the field structure. ! - \*--------------------------------------------------------*/ - bwc_kill_compression(field); - bwc_free_data(data); -} - -/*--------------------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function opens a bwc file, checks it for its validity and loads its con- ! -! tent into a properly set up bwc_data structure. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! filename char* - Name of the bwc file that is ! -! to be opened and read. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! bwc_data* - Structure containing a code- ! -! stream/numerical dataset. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 20.06.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! 17.05.2021 Patrick Vogler B87E7E4 V 0.1.0 clean up ! -! ! -\*--------------------------------------------------------------------------------------------------------------------*/ -static bwc_data* -read_bwc(char *const filename) -{ - /*-----------------------*\ - ! DEFINE INT VARIABLES: ! - \*-----------------------*/ - uint64_t Lfield; - uint16_t root; - - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - bwc_data *file; - - /*-----------------------*\ - ! DEFINE FILE POINTER: ! - \*-----------------------*/ - FILE *fp; - - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(filename); - - /*--------------------------------------------------------*\ - ! Open the specified file for reading and, if succesful, ! - ! determine the size of the codestream. If the file could ! - ! not be opened, print an error message to stderr and exit.! - \*--------------------------------------------------------*/ - fp = fopen(filename, "rb"); - if(fp != NULL) - { - root = ftell(fp); - fseek(fp, 0L, SEEK_END); - Lfield = ftell(fp) - root; - fseek(fp, root, SEEK_SET); - } - else - { - // error opening file - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: Could not open or read %-25s|\n"\ - "o##########################################################o\n", filename); - return NULL; - } - - /*--------------------------------------------------------*\ - ! Allocate the data and packed codestream structure as ! - ! well as the memory block that will hold the codestream. ! - \*--------------------------------------------------------*/ - file = calloc(1, sizeof(bwc_data)); - if(file == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - fclose(fp); - return NULL; - } - - file->codestream.data = calloc(1, sizeof(bwc_stream)); - if(file->codestream.data == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - bwc_free_data(file); - fclose(fp); - return NULL; - } - - file->codestream.data->memory = calloc(Lfield, sizeof(uchar)); - if(file->codestream.data->memory == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - bwc_free_data(file); - fclose(fp); - return NULL; - } - - /*--------------------------------------------------------*\ - ! Read the compressed bitstream from the file and, if suc- ! - ! essfull, properly set up the packed codestream and re- ! - ! turn the bwc_data structre to the function caller. ! - \*--------------------------------------------------------*/ - if(fread(file->codestream.data->memory, sizeof(uchar), Lfield, fp) != Lfield) - { - // invalid read - fprintf(stderr, RDERROR); - bwc_free_data(file); - fclose(fp); - return NULL; - } - - file->codestream.data->access = file->codestream.data->memory; - file->codestream.data->size = Lfield; - file->codestream.data->position = 0; - - fclose(fp); - return file; -} - -/*--------------------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function opens a bwc file, checks it for its validity and writes the code- ! -! stream, provided by the function caller, to the file. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! filename char* - Name of the bwc file that is ! -! to be created. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! unsigned char - Returns an unsigned char for ! -! error handling. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 20.06.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! 17.05.2021 Patrick Vogler B87E7E4 V 0.1.0 clean up ! -! ! -\*--------------------------------------------------------------------------------------------------------------------*/ -static uchar -write_bwc(bwc_data *const data, - char *const filename) -{ - /*-----------------------*\ - ! DEFINE FILE POINTER: ! - \*-----------------------*/ - FILE *fp; - - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(data); - assert(filename); - - /*--------------------------------------------------------*\ - ! Open the specified file for writing If the file could ! - ! not be opened, print an error message to stderr and exit.! - \*--------------------------------------------------------*/ - fp = fopen(filename, "wb"); - if(fp == NULL) - { - // error opening file - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: Could not open %-33s|\n"\ - "o##########################################################o\n", filename); - return EXIT_FAILURE; - } - - /*--------------------------------------------------------*\ - ! Write the compressed codestream to file and, if success- ! - ! ful, close the file ptr and return to the fun. caller. ! - \*--------------------------------------------------------*/ - if(fwrite(data->codestream.data->memory, sizeof(uchar), data->codestream.data->size, fp) != - data->codestream.data->size) - { - // error opening file - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: Could not write to %-29s|\n"\ - "o##########################################################o\n", filename); - fclose(fp); - return EXIT_FAILURE; - } - - fclose(fp); - return EXIT_SUCCESS; -} - -/*--------------------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function is a wrapper that is used to invoke the appropriate read func- ! -! tion according to the file extension of the user supplied filename. The data- ! -! set is stored in the bwc_data structure and passed onto the function caller. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! args util_arg_node* - Arguments/options linked list ! -! for the bwc command-line tool. ! -! ! -! str char* - Long-/short-name of a bwc com- ! -! mand-line argument or option. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! bwc_data* - Structure containing a code- ! -! stream/numerical dataset. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 14.05.2019 Patrick Vogler B87D120 V 0.1.0 function created ! -! 03.05.2021 Patrick Vogler B87E7E4 V 0.1.0 clean up ! -! ! -\*--------------------------------------------------------------------------------------------------------------------*/ -static bwc_data* -read_file(bwc_cmdl_arg_node *const args, - char* name) -{ - /*-----------------------*\ - ! DEFINE CHAR VARIABLES: ! - \*-----------------------*/ - char *str; - - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - bwc_cmdl_arg_node *temp; - bwc_data *file; - struct stat buf; - - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(args); - assert(name); - - /*--------------------------------------------------------*\ - ! Retrieve the file argument from the linked list and con- ! - ! firm that only one file has been specified and that it ! - ! is a regular file. ! - \*--------------------------------------------------------*/ - temp = retrieve_arg(args, name); - if((temp == NULL) || - (temp->lit_opt == NULL) || - (temp->lit_opt[0] == NULL)) - { - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: File |\n"\ - "| |\n"\ - "| No File has been specified. |\n"\ - "| |\n"\ - "o##########################################################o\n"); - return NULL; - } - - if(temp->count > 1) - { - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: File |\n"\ - "| |\n"\ - "| More than one file has been specified. |\n"\ - "| |\n"\ - "o##########################################################o\n"); - return NULL; - } - - stat(temp->lit_opt[0], &buf); - if(!S_ISREG(buf.st_mode)) - { - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: file |\n"\ - "| |\n"\ - "| The specified input is not a regular file. |\n"\ - "| |\n"\ - "o##########################################################o\n"); - return NULL; - } - - /*--------------------------------------------------------*\ - ! Extract the file extension from the input string and use ! - ! it to invoke the appropriate read function. ! - \*--------------------------------------------------------*/ - str = strrchr(temp->lit_opt[0], '.'); - switch(hash(str)) - { - case 0x000000017C4DC25C: - { - file = read_eas3(temp->lit_opt[0]); - if(file == NULL) + if(i == 1) { - return NULL; + arguments->codeblock[1] = + arguments->codeblock[2] = + arguments->codeblock[3] = arguments->codeblock[0]; } - - return file; - } - - case 0x000000017C4DAF1D: - { - file = read_bwc(temp->lit_opt[0]); - if(file == NULL) + else if(i != 4) { - return NULL; - } - - return file; + argp_error(state, "The codeblock argument expects either a " + "single global or 4 directional values\n"); + }*/ + break; } + case 'n': + { + // buff_LL = strtoll(arg, &end, 10); + // if((buff_LL < 1) || (buff_LL > 255)) + // { + // argp_error(state, "The number of OpenMP threads specified" + // "is out of the supported range.\n"); + // } + // else + // { + // arguments->nthreads = (uint8_t)buff_LL; + // } + break; + } + case 'l': + { + printf("l\n"); + break; + } + case 'k': + { + printf("k\n"); + break; + } + case 'q': + { + printf("q\n"); + break; + } + case 'Q': + { + printf("Q\n"); + break; + } + case 'e': + { + printf("e\n"); + break; + } + case 't': + { + printf("t\n"); + break; + } + case 'p': + { + printf("p\n"); + break; + } + + case ARGP_KEY_NO_ARGS: + { + argp_usage (state); + break; + } + + case ARGP_KEY_ARG: + + // Too many arguments. + if(state->arg_num > 1) + argp_usage(state); + break; + + case ARGP_KEY_END: + /*if(!((arguments->analysis != NULL) && (arguments->comp == NULL) + && (arguments->decomp == NULL) + && (arguments->header == NULL) + && (arguments->output == NULL) + && (arguments->reference != NULL)) && + !((arguments->comp != NULL) && (arguments->analysis == NULL) + && (arguments->decomp == NULL) + && (arguments->header == NULL) + && (arguments->reference == NULL)) && + !((arguments->decomp != NULL) && (arguments->analysis == NULL) + && (arguments->comp == NULL) + && (arguments->header == NULL) + && (arguments->reference == NULL)) && + !((arguments->header != NULL) && (arguments->analysis == NULL) + && (arguments->comp == NULL) + && (arguments->decomp == NULL) + && (arguments->output == NULL) + && (arguments->reference == NULL))) + { + argp_error(state, "The User supplied options do not fit the " + "supported use cases.\n"); + }*/ + break; default: - { - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: File |\n"\ - "| |\n"\ - "| The format of the specified file is currently |\n"\ - "| not supported. |\n"\ - "| |\n"\ - "o##########################################################o\n"); - return NULL; - } + return ARGP_ERR_UNKNOWN; } -} - -/*--------------------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function is a wrapper that is used to invoke the appropriate write func- ! -! tion according to the file extension supplied by the user or codestream. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! args util_arg_node* - Arguments/options linked list ! -! for the bwc command-line tool. ! -! ! -! str char* - Long-/short-name of a bwc com- ! -! mand-line argument or option. ! -! ! -! data bwc_data* - Structure containing a code- ! -! stream/numerical dataset. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! unsigned char - Returns an unsigned char for ! -! error handling. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 14.05.2019 Patrick Vogler B87D120 V 0.1.0 function created ! -! 17.05.2021 Patrick Vogler B87E7E4 V 0.1.0 clean up ! -! ! -\*--------------------------------------------------------------------------------------------------------------------*/ -static uchar -write_file(bwc_cmdl_arg_node *const args, - bwc_data *const data, - char* name) -{ - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - uint64_t ext_hash; - uint16_t new_len; - - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - bwc_cmdl_arg_node *temp; - - /*-----------------------*\ - ! DEFINE CHAR VARIABLES: ! - \*-----------------------*/ - char *str; - - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(data); - assert(args); - assert(name); - - /*--------------------------------------------------------*\ - ! Retrieve the file argument from the linked list and con- ! - ! firm that only one file has been specified. ! - \*--------------------------------------------------------*/ - temp = retrieve_arg(args, name); - if((temp == NULL) || - (temp->lit_opt == NULL) || - (temp->lit_opt[0] == NULL)) - { - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: File |\n"\ - "| |\n"\ - "| No File has been specified. |\n"\ - "| |\n"\ - "o##########################################################o\n"); - return EXIT_FAILURE; - } - - if(temp->count > 1) - { - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: File |\n"\ - "| |\n"\ - "| More than one file has been specified. |\n"\ - "| |\n"\ - "o##########################################################o\n"); - return EXIT_FAILURE; - } - - /*--------------------------------------------------------*\ - ! If the output is a packed codestream, replace the user ! - ! supplied with the propper '.bwc' file extension to en- ! - ! sure uniformity. ! - \*--------------------------------------------------------*/ - if((retrieve_arg(args, "compress") != NULL) && (data->codestream.data != NULL)) - { - /*--------------------------------------------------------*\ - ! Extract the filename in the output argument, remove its ! - ! file extension and calculate the new string length with ! - ! the '.bwc' extension. ! - \*--------------------------------------------------------*/ - str = strrchr(temp->lit_opt[0], '.'); - str[1] = '\0'; - - new_len = (strlen(temp->lit_opt[0]) + 4) * sizeof(char); - - /*--------------------------------------------------------*\ - ! Resize the filename string in the output argument and ! - ! ammend the new file extension. ! - \*--------------------------------------------------------*/ - str = calloc(new_len, sizeof(char)); - if(str == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - return EXIT_FAILURE; - } - sprintf(str, "%s%s", temp->lit_opt[0],"bwc"); - - /*--------------------------------------------------------*\ - ! Write the codestream to the filesystem. ! - \*--------------------------------------------------------*/ - if(write_bwc(data, str) == EXIT_FAILURE) - { - free(str); - return EXIT_FAILURE; - } - } - /*--------------------------------------------------------*\ - ! If the output is a numerical dataset, generate the ap- ! - ! propriate filename and write the information to file. ! - \*--------------------------------------------------------*/ - else if((retrieve_arg(args, "decompress") != NULL) && ((data->field.d != NULL) || - (data->field.f != NULL))) - { - /*--------------------------------------------------------*\ - ! If no output file has been specified, assemble the file- ! - ! name using the input name and file extension assoc. with ! - ! the codestream. Generate the ext. hash accordingly. ! - \*--------------------------------------------------------*/ - if(strcmp(name, "decompress") == 0) - { - ext_hash = hash(data->info.f_ext); - str = strrchr(temp->lit_opt[0], '.'); - str[0] = '\0'; - - new_len = (strlen(temp->lit_opt[0]) + - strlen(data->info.f_ext) + 7) * sizeof(char); - - str = calloc(new_len, sizeof(char)); - if(str == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - return EXIT_FAILURE; - } - sprintf(str, "%s%s%s", temp->lit_opt[0], "_d.", data->info.f_ext); - } - /*--------------------------------------------------------*\ - ! If an output file has been specified, extract the file ! - ! extension, evaluate the corresponding hash and check ! - ! that the codestream supports the file format. ! - \*--------------------------------------------------------*/ - else - { - ext_hash = hash(strrchr(temp->lit_opt[0], '.') + 1); - if(ext_hash != hash(data->info.f_ext)) - { - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: Incompatible File Format |\n"\ - "| |\n"\ - "| The format of the specified file is incom- |\n"\ - "| patible with the information stored in the |\n"\ - "| codestream. |\n"\ - "| |\n"\ - "o##########################################################o\n"); - return EXIT_FAILURE; - } - - str = calloc(strlen(temp->lit_opt[0]) + 1, sizeof(char)); - if(str == NULL) - { - // memory allocation error - fprintf(stderr, MEMERROR); - return EXIT_FAILURE; - } - strcpy(str, temp->lit_opt[0]); - } - - /*--------------------------------------------------------*\ - ! Use the extension hash to invoke the appropriate write ! - ! function. ! - \*--------------------------------------------------------*/ - switch (ext_hash) - { - case 0X0000000000B87A592: - { - if(write_eas3(data, str) == EXIT_FAILURE) - { - free(str); - return EXIT_FAILURE; - } - break; - } - - default: - { - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: File |\n"\ - "| |\n"\ - "| The format of the specified file is currently |\n"\ - "| not supported. |\n"\ - "| |\n"\ - "o##########################################################o\n"); - free(str); - return EXIT_FAILURE; - } - } - } - /*--------------------------------------------------------*\ - ! If no apporprite in- or output argument has been speci- ! - ! fied return an error handle to the function caller. ! - \*--------------------------------------------------------*/ - else - { - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: Data |\n"\ - "| |\n"\ - "| Output can not be generated because no valid |\n"\ - "| data has been specified. |\n"\ - "| |\n"\ - "o##########################################################o\n"); - return EXIT_FAILURE; - } - - free(str); return EXIT_SUCCESS; } -/*--------------------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! | | ! -! This function calculates the Peak-Signal-to-Noise-Ratio of a compressed file ! -! in relation to the original reference file. The mean square error and peak ! -! signal to noise ratio are written to the standard output. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! args util_arg_node* - Arguments/options linked list ! -! for the bwc command-line tool. ! -! ! -! name char* - Long-/short-name of a bwc com- ! -! mand-line argument or option. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! unsigned char - Returns an unsigned char for ! -! error handling. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 12.09.2019 Patrick Vogler B87D120 V 0.1.0 function created ! -! 17.05.2021 Patrick Vogler B87E7E4 V 0.1.0 clean up ! -! ! -\*--------------------------------------------------------------------------------------------------------------------*/ -static uchar -output_analysis(bwc_cmdl_arg_node *const args) +// initialize the argp struct. Which will be used to parse and use the args. +static struct argp argp = {options, parse_opt, 0, doc}; + +/*================================================================================================*/ +/** + * @details This function provides the command-line interface for the BigWhoop compression + * library. + * + * @param[in] argc Number of strings pointed to by argv + * @param[in] argv Array of arguments + * + * @retval -1 Error + * @retval 0 OK + */ +/*================================================================================================*/ +int main(int argc, char *argv[]) { - /*-----------------------*\ - ! DEFINE INT VARIABLES: ! - \*-----------------------*/ - uint64_t size; - uint64_t i; - - uint8_t p; - - /*-----------------------*\ - ! DEFINE FLOAT VARIABLES: ! - \*-----------------------*/ - double MSE, PSNR; - double peakVal; - double sum; - - double *dOrig, *dRef; - float *fOrig, *fRef; - - bwc_float minVal, maxVal; - + int i = 0; /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - bwc_data *file, *ref; - - bwc_cmd_opts_ll *param; + cli_arguments arguments = {0}; /*--------------------------------------------------------*\ - ! Load the input and reference files into the appropriate ! - ! file structures. ! + ! Initialize the arguments structure. ! \*--------------------------------------------------------*/ - file = read_file(args, "input"); - if(file == NULL) + arguments.stream = calloc(1, sizeof(bwc_stream)); + arguments.codec = calloc(1, sizeof(bwc_codec)); + if((arguments.stream == NULL) || + (arguments.codec == NULL)) + { + // memory allocation error + fprintf(stderr, MEMERROR); + return EXIT_FAILURE; + } + + /*--------------------------------------------------------*\ + ! Parse the cli arguments. ! + \*--------------------------------------------------------*/ + argp_parse(&argp, argc, argv, 0, 0, &arguments); + if(arguments.mode == cli_err) { return EXIT_FAILURE; } - ref = read_file(args, "reference"); - if(ref == NULL) - { - bwc_free_data(file); - return EXIT_FAILURE; - } + for(i = 0; i < 10; ++i) + printf("bitrate %d:\t%f\n",i,arguments.bitrate[i]); - dOrig = file->field.d; - dRef = ref->field.d; - fOrig = file->field.f; - fRef = ref->field.f; - if(file->info.nX == ref->info.nX && - file->info.nY == ref->info.nY && - file->info.nZ == ref->info.nZ && - file->info.nTS == ref->info.nTS && - file->info.nPar == ref->info.nPar) - { - size = (uint64_t)ref->info.nX * ref->info.nY * - ref->info.nZ * ref->info.nTS; - - peakVal = -1.7976931348623157e+308; - PSNR = - MSE = 0; - - if(ref->info.parameter) - { - param = ref->info.parameter->root; - p = 0; - while(param != NULL) - { - minVal = 1.7976931348623157e+308; - maxVal = -1.7976931348623157e+308; - - if(param->precision == 8) - { - for(i = 0; i < size; ++i) - { - minVal = MIN(minVal, (double)dRef[i + p * size]); - maxVal = MAX(maxVal, (double)dRef[i + p * size]); - - sum = ((double)dRef[i + p * size] - (double)dOrig[i + p * size]); - - MSE += sum * sum; - } - } - else if(param->precision == 4) - { - for(i = 0; i < size; ++i) - { - minVal = MIN(minVal, (double)fRef[i + p * size]); - maxVal = MAX(maxVal, (double)fRef[i + p * size]); - - sum = ((double)fRef[i + p * size] - (double)fOrig[i + p * size]); - - MSE += sum * sum; - } - } - peakVal = MAX(peakVal, maxVal - minVal); - param = param -> next; - p++; - } - } - - MSE /= (double)size * ref->info.nPar; - PSNR = 20 * log10(peakVal/(2 * sqrt(MSE))); - - printf("==============================================================\n"); - printf(" Mean Square Error: %*.2f\n", 22, MSE); - printf(" Peak Signal-to-Noise Ratio: %*.2f\n", 22, PSNR); - printf("==============================================================\n"); - - } - /*--------------------------------------------------------*\ - ! Load the input and reference files into the appropriate ! - ! file structures. ! - \*--------------------------------------------------------*/ - bwc_free_data(file); - bwc_free_data(ref); - - return EXIT_SUCCESS; + //printf("ARG1: %s", arguments.args[0]); + //printf("\nVERBOSE: %s", arguments.verbose? "yes" : "no"); + //printf("\nOption1: %s", arguments.option1); + //printf("\n"); } - -/**********************************************************************************************************************\ -|| ___ _ _ ___ _ _ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ || -|| |__] | | |__] | | | |___ | | |\ | | | | | | |\ | [__ || -|| | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] || -|| || -\**********************************************************************************************************************/ -/*--------------------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function provides a command-line interface for the BigWhoop compression ! -! library. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! argc int - Number of strings pointed to ! -! by argv. ! -! ! -! argv char** - Array of arguments. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! int - Return value signaling a normal ! -! or abnormal process exit. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 17.04.2019 Patrick Vogler B87D120 V 0.1.0 function created ! -! 15.05.2021 Patrick Vogler B880CA2 V 0.1.0 Clean up. ! -! ! -\*--------------------------------------------------------------------------------------------------------------------*/ -int -main(int argc, - char *argv[]) -{ - /*-----------------------*\ - ! DEFINE INT VARIABLES: ! - \*-----------------------*/ - uint64_t i; - uint8_t error_handle; - - /*-----------------------*\ - ! DEFINE CHAR VARIABLES: ! - \*-----------------------*/ - char buff[200]; - char rate[10]; - - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - bwc_field *field = NULL; - bwc_data *file = NULL; - - bwc_gl_ctrl *control; - - //bwc_dwt_filter filter[4]; - bwc_cmdl_arg_node *args, *temp; - - /*--------------------------------------------------------*\ - ! Initialize the field and args structures for proper er- ! - ! ror handling, as well as the error handle itself. ! - \*--------------------------------------------------------*/ - field = NULL; - args = NULL; - - error_handle = EXIT_SUCCESS; - - /*--------------------------------------------------------*\ - ! Assemble the arg. linked list using the command-line ar- ! - ! guments passed by the function caller. ! - \*--------------------------------------------------------*/ - args = parse_arguments(argc, argv); - if(args == NULL) - { - error_handle = EXIT_FAILURE; - print_help(); - goto OUT; - } - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - if(retrieve_arg(args, "compress") != NULL) - { - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - if(retrieve_arg(args, "input")) - file = read_file(args, "input"); - else - file = read_file(args, "compress"); - - if(file == NULL) - { - error_handle = EXIT_FAILURE; - goto OUT; - } - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - /*--------------------------------------------------------*\ - ! Save frequently used variables/structures to temporary ! - ! variables to make the code more readable. ! - \*--------------------------------------------------------*/ - field = bwc_initialize_field(file); - if(field == NULL) - { - error_handle = EXIT_FAILURE; - goto OUT; - } - control = &field->control; - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - temp = retrieve_arg(args, "q_format_range"); - if((temp != NULL) && (temp->count == 1)) - { - bwc_set_qm(field, (uint8_t)temp->num_opt[0]); - } - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - // temp = retrieve_arg(args, "wavelet_kernels"); - // if((temp != NULL) && (temp->count == 4) && (temp->dim != 0x00)) - // { - // for(i = 0; i < temp->count; ++i) - // { - // switch(hash(temp->lit_opt[i])) - // { - // case 0x000000000B87CF64: - // { - // filter[i] = bwc_dwt_9_7; - // break; - // } - // case 0x00000652AB15772A: - // { - // filter[i] = bwc_dwt_5_3; - // break; - // } - // case 0x000000017C858EFF: - // { - // filter[i] = bwc_dwt_5_3; - // break; - // } - // default: - // { - // filter[i] = bwc_dwt_9_7; - // break; - // } - // } - // } - // bwc_set_kernels(field, filter[0], filter[1], - // filter[2], filter[3]); - // } - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - temp = retrieve_arg(args, "decomposition_levels"); - if((temp != NULL) && (temp->count == 4) && (temp->dim != 0x00)) - { - bwc_set_decomp(field, (uint8_t)temp->num_opt[0], (uint8_t)temp->num_opt[1], - (uint8_t)temp->num_opt[2], (uint8_t)temp->num_opt[3]); - } - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - temp = retrieve_arg(args, "tile_size"); - if((temp != NULL) && (temp->count == 4) && (temp->dim != 0x00)) - { - bwc_set_tiles(field, (uint64_t)temp->num_opt[0], (uint64_t)temp->num_opt[1], - (uint64_t)temp->num_opt[2], (uint64_t)temp->num_opt[3], bwc_tile_sizeof); - } - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - temp = retrieve_arg(args, "precinct_size"); - if((temp != NULL) && (temp->count == 4) && (temp->dim != 0x00)) - { - bwc_set_precincts(field, (uint8_t)temp->num_opt[0], (uint8_t)temp->num_opt[1], - (uint8_t)temp->num_opt[2], (uint8_t)temp->num_opt[3]); - } - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - temp = retrieve_arg(args, "codeblock_size"); - if((temp != NULL) && (temp->count == 4) && (temp->dim != 0x00)) - { - bwc_set_codeblocks(field, (uint8_t)temp->num_opt[0], (uint8_t)temp->num_opt[1], - (uint8_t)temp->num_opt[2], (uint8_t)temp->num_opt[3]); - } - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - // temp = retrieve_arg(args, "quantisation_style"); - // if((temp != NULL) && (temp->count == 1)) - // { - // if(strcmp(temp->lit_opt[0], "NONE")) - // bwc_set_quant_style(field, bwc_qt_none); - // else - // bwc_set_quant_style(field, bwc_qt_derived); - // } - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - // temp = retrieve_arg(args, "quantisation_step_size"); - // if((temp != NULL) && (temp->count == 1)) - // { - // bwc_set_quant_step_size(field, temp->num_opt[0]); - // } - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - memset(buff, 0, 200 * sizeof(char)); - - temp = retrieve_arg(args, "bitrate"); - if((temp != NULL) && (temp->count > 0)) - { - for(i = 0; i < temp->count && strlen(buff) < 192; ++i) - { - sprintf(rate, "%05.3f,", temp->num_opt[i]); - strcat(buff, rate); - } - buff[strlen(buff) - 1] = '0'; - } - - temp = retrieve_arg(args, "compression_ratio"); - if((temp != NULL) && (temp->count == 1)) - { - sprintf(buff, "%05.3f", ((double)PREC_BIT + 1.0f)/temp->num_opt[0]); - } - - if(strlen(buff) == 0) - { - sprintf(buff, "-"); - } - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - #if defined (_OPENMP) - temp = retrieve_arg(args, "number_of_threads"); - if((temp != NULL) && (temp->count == 1)) - { - omp_set_num_threads((uint8_t)temp->num_opt[0]); - } - #endif - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - if(retrieve_arg(args, "error_resilience")) - { - bwc_set_error_resilience(field); - } - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - if(bwc_create_compression(field, buff)) - { - error_handle = EXIT_FAILURE; - goto OUT; - } - - if(bwc_compress(field, file)) - { - error_handle = EXIT_FAILURE; - goto OUT; - } - - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - if(retrieve_arg(args, "output")) - { - if(write_file(args, file, "output")) - { - error_handle = EXIT_FAILURE; - goto OUT; - } - } - else - { - if(write_file(args, file, "compress")) - { - error_handle = EXIT_FAILURE; - goto OUT; - } - } - temp = retrieve_arg(args, "verbose"); - if(temp != NULL) - { - /*--------------------------------------------------------*\ - ! Calculate the original field size, compression ratio and ! - ! bits per datapoint and print the miscellaneous compres- ! - ! sion information to the standard output. ! - \*--------------------------------------------------------*/ - if((temp->count == 1) && (temp->num_opt[0] > 1) && (control->CSsgc != 0)) - { - printf("==============================================================\n"); - printf(" \n"\ - " .:-------------: .:-------------: \n"\ - " .+++++++++++++++= :+++++++++++++++- \n"\ - " :+++. -++= -++= \n"\ - " :+++. -++= -++= \n"\ - " -++++++++++++++= -++= -++= \n"\ - " .=++---------=++= -++= -++= \n"\ - " :+++ :++= -++= -++= \n"\ - " .+++=--------=+++---=+++---=+++------------: \n"\ - " -=++++++++++++++++++++++++++++++++++++++++- \n"\ - " \n"); - printf("----------------- Compression Parameters -----------------\n\n"); - if((control->CSsgc &0x200) != 0) - { - printf(" Number of Tiles: %27ld\n", control->nTiles); - printf(" - Samples in 1.D: %27ld\n", control->tileSizeX); - printf(" - Samples in 2.D: %27ld\n", control->tileSizeY); - printf(" - Samples in 3.D: %27ld\n", control->tileSizeZ); - printf(" - Timesteps: %27ld\n", control->tileSizeTS); - printf(" ..........................................................\n"); - printf("\n"); - } - - if((control->CSsgc &0xE0) != 0) - { - printf(" 1.D | 2.D | 3.D | TS\n"); - if((control->CSsgc &0x20) != 0) - { - printf(" Decomposition Levels: %2d | %2d | %2d | %2d\n", control->decompX - , control->decompY - , control->decompZ - , control->decompTS); - } - if((control->CSsgc &0x40) != 0) - { - printf(" Precincts [log2]: %2d | %2d | %2d | %2d\n", control->precSizeX - , control->precSizeY - , control->precSizeZ - , control->precSizeTS); - - } - if((control->CSsgc &0x80) != 0) - { - printf(" Codeblocks [log2]: %2d | %2d | %2d | %2d\n", control->cbX - , control->cbY - , control->cbZ - , control->cbTS); - } - printf(" ..........................................................\n"); - printf("\n"); - } - - if((control->CSsgc &0x101) != 0) - { - if((control->CSsgc &0x100) != 0) - printf(" Q Number Format: %27d\n", control->Qm); - if((control->CSsgc &0x1) != 0) - printf(" Error Resilience: %27s\n", ((control->error_resilience > 0) ? "True" : "False")); - - printf(" ..........................................................\n"); - printf("\n"); - } - - for(i = 0; i < control->nLayers; ++i) - { - printf(" Quality Layer Nr. %2ld: %23.2f bpd\n", i + 1, control->bitrate[i]/8.0f); - } - - printf("\n"); - printf("---------------- Compression Performance -----------------\n\n"); - } - else - { - printf("==============================================================\n"); - } - } - } - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - else if(retrieve_arg(args, "decompress") != NULL) - { - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - if(retrieve_arg(args, "input")) - file = read_file(args, "input"); - else - file = read_file(args, "decompress"); - - if(file == NULL) - { - error_handle = EXIT_FAILURE; - goto OUT; - } - - if(file->codestream.data == NULL) - { - fprintf(stderr, "o##########################################################o\n"\ - "| ERROR: File |\n"\ - "| |\n"\ - "| Input file does not contain a packed code- |\n"\ - "| stream. |\n"\ - "| |\n"\ - "o##########################################################o\n"); - - error_handle = EXIT_FAILURE; - goto OUT; - } - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - temp = retrieve_arg(args, "layer"); - if((temp != NULL) && (temp->count == 1)) - field = bwc_create_decompression(file, (uint8_t)temp->num_opt[0]); - else - field = bwc_create_decompression(file, 0); - - if(field == NULL) - { - error_handle = EXIT_FAILURE; - goto OUT; - } - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - #if defined (_OPENMP) - temp = retrieve_arg(args, "number_of_threads"); - if((temp != NULL) && (temp->count == 1)) - { - omp_set_num_threads((uint8_t)temp->num_opt[0]); - } - #endif - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - if(bwc_decompress(field, file)) - { - error_handle = EXIT_FAILURE; - goto OUT; - } - - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - if(retrieve_arg(args, "output")) - { - if(write_file(args, file, "output")) - { - error_handle = EXIT_FAILURE; - goto OUT; - } - } - else - { - if(write_file(args, file, "decompress")) - { - error_handle = EXIT_FAILURE; - goto OUT; - } - } - } - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - else if(retrieve_arg(args, "info") != NULL) - { - if(retrieve_arg(args, "input")) - output_info(args, "input"); - else - output_info(args, "info"); - } - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - else if(retrieve_arg(args, "analysis") != NULL) - { - if(output_analysis(args) == EXIT_FAILURE) - { - error_handle = EXIT_FAILURE; - goto OUT; - } - } - /*--------------------------------------------------------*\ - ! ! - \*--------------------------------------------------------*/ - else - { - print_help(); - goto OUT; - } - -OUT: - if(field != NULL) - { - bwc_kill_compression(field); - } - - if(file != NULL) - { - bwc_free_data(file); - } - - if(args != NULL) - { - bwc_kill_arg(args); - } - - fclose(stdin); - fclose(stdout); - fclose(stderr); - - return error_handle; -} \ No newline at end of file -- 2.45.2 From 60b5c6c80af06403fc636e4ad435a5fa09a6d744 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Tue, 15 Oct 2024 17:53:29 +0200 Subject: [PATCH 13/53] new eas3_data struct and mods in bitstream eas3_std_params --- include/interfaces/reader/eas3.h | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/include/interfaces/reader/eas3.h b/include/interfaces/reader/eas3.h index 9fe0d20..e75dfa2 100644 --- a/include/interfaces/reader/eas3.h +++ b/include/interfaces/reader/eas3.h @@ -199,15 +199,22 @@ \*----------------------------------------------------------------------------------------------*/ typedef struct { + //TODO: remove uchar error; // Error flag used during streaming. + uint64 size; + uint64 position; + //TODO: remove uint64 L; // Number of bytes written to/from stream. + //TODO: remove uint64 Lmax; // Size of packed stream. uint64 size_incr; // Size incrmnt used for stream assembly. + //TODO: remove uint8 T; // Byte buffer. int8 t; // Byte buffer counter. + uchar *access; // Pointer used to parse packed stream. uchar *memory; // Memory handle for packed stream chunck. } bitstream; @@ -303,7 +310,7 @@ { uint64_t file_type; uint64_t accuracy; - uint64_t nzs; + uint64_t nts; uint64_t npar; uint64_t ndim1; uint64_t ndim2; @@ -324,6 +331,27 @@ uint64_t udef_int_size; uint64_t udef_real_size; } eas3_std_params; + + /*----------------------------------------------------------------------------------------------*\ + ! ! + ! DESCRIPTION: ! + ! ------------ ! + ! ! + ! This structure is used to read eas3 stuff. ! + ! ! + \*----------------------------------------------------------------------------------------------*/ + typedef struct + { + eas3_std_params params; + + struct field + { + double *d; + float *f; + } field; + + bitstream *aux; + } eas3_data; /************************************************************************************************************\ || ___ _ _ ___ _ _ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ || -- 2.45.2 From ae7d48c4588ac56f302f6db13ab905b45129e6d4 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Tue, 15 Oct 2024 17:58:21 +0200 Subject: [PATCH 14/53] adjusted terminate_stream to shallow copy between two bitstreams --- src/interfaces/reader/eas3.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 2631bd9..973b778 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -461,7 +461,7 @@ get_chunck(bitstream *const stream, const uint64 size) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -terminate_stream(bitstream *stream, bwc_stream *const packed_stream) +terminate_stream(bitstream *stream, bitstream *const packed_stream) { /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -491,6 +491,7 @@ terminate_stream(bitstream *stream, bwc_stream *const packed_stream) packed_stream->access = stream->memory; packed_stream->size = stream->L; packed_stream->position = 0; + packed_stream->L = stream->L; } else { -- 2.45.2 From b48525b8e4f5940c00f5f20d805b9422ac6269a2 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Wed, 16 Oct 2024 10:19:30 +0200 Subject: [PATCH 15/53] add eas3_param_names linked list and functionality to extend eas3_add_param_name also add eas3_free_data --- include/interfaces/reader/eas3.h | 18 +++++++ src/interfaces/reader/eas3.c | 82 ++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/include/interfaces/reader/eas3.h b/include/interfaces/reader/eas3.h index e75dfa2..650d20f 100644 --- a/include/interfaces/reader/eas3.h +++ b/include/interfaces/reader/eas3.h @@ -332,6 +332,23 @@ uint64_t udef_real_size; } eas3_std_params; + /*----------------------------------------------------------------------------------------------*\ + ! ! + ! DESCRIPTION: ! + ! ------------ ! + ! ! + ! This structure is used to store field names eas3 file. ! + ! ! + \*----------------------------------------------------------------------------------------------*/ + typedef struct name + { + char name[24]; // Parameter name. + uint8 id; // Parameter index. + + struct name *next; // Next element in linked-list. + struct name *root; // Linked-list root. + } eas3_param_names; + /*----------------------------------------------------------------------------------------------*\ ! ! ! DESCRIPTION: ! @@ -342,6 +359,7 @@ \*----------------------------------------------------------------------------------------------*/ typedef struct { + eas3_param_names *param_names; eas3_std_params params; struct field diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 973b778..7752580 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -586,6 +586,88 @@ endian_conversion(void *value, } } +/*----------------------------------------------------------------------------------------------------------*\ +! ! +! DESCRIPTION: ! +! ------------ ! +! This function deallocates the data structure used to store an numerical dataset ! +! and can be called if an error occurs or once the data is no longer needed is to be closed. ! +! The deallocation will be carried out down to the structure levels that have been allocated. ! +! ! +\*----------------------------------------------------------------------------------------------------------*/ +void +eas3_free_data(eas3_data* data) +{ + if(data) + { + if(data->aux) + { + free(data->aux->memory); + data->aux->access = NULL; + data->aux->position = 0; + data->aux->size = 0; + // TODO: remove + data->aux->L = 0; + } + free(data->aux); + free(data); + } +} + +void +eas3_add_param_name(eas3_data *const data, char *name) +{ + eas3_param_names *param_names; + assert(data); + param_names = &data->param_names; + /*--------------------------------------------------------*\ + ! Check if the specified parameter name has the proper ! + ! length. ! + \*--------------------------------------------------------*/ + if((strlen(name) > 24) && name) + { + fprintf(stderr, "o==========================================================o\n"\ + "| WARNING: Invalid parameter name: %-24s|\n"\ + "| |\n"\ + "| Parameter names cannot exceed 24 characters. |\n"\ + "| |\n"\ + "o==========================================================o\n",name); + } + + /*--------------------------------------------------------*\ + ! Check if the parameter structure has already been allo- ! + ! cated. ! + \*--------------------------------------------------------*/ + if(data->param_names == NULL) + { + /*--------------------------------------------------------*\ + ! If eas3_add_param_name function is called for the first ! + ! time, allocate the parameter structure and save the root ! + ! node address. ! + \*--------------------------------------------------------*/ + data->param_names = calloc(1, sizeof(eas3_param_names)); + data->param_names->root = data->param_names; + } + else + { + /*--------------------------------------------------------*\ + ! If a new parameter is added, allocate the nex linked ! + ! list node, save the root node address in its structure ! + ! and set the linked list access pointer to the new node. ! + \*--------------------------------------------------------*/ + data->param_names->next = calloc(1, sizeof(eas3_param_names)); + data->param_names->next->root = data->param_names->root; + data->param_names->next->id = data->param_names->id + 1; + data->param_names = data->param_names->next; + } + + /*--------------------------------------------------------*\ + ! Save the name of the new parameter its precision in the ! + ! structure of the new node. ! + \*--------------------------------------------------------*/ + strcpy(data->param_names->name, name ? name : "undefined"); +} + /*----------------------------------------------------------------------------------------------------------*\ ! FUNCTION NAME: uchar read_eas3_header(bwc_data *const data) ! ! -------------- ! -- 2.45.2 From 00f9e720e93034996cafb8d8ca756bd4d2be1d0b Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Wed, 16 Oct 2024 10:31:15 +0200 Subject: [PATCH 16/53] adjust read_eas3_header --- src/interfaces/reader/eas3.c | 115 ++++++++++++++--------------------- 1 file changed, 44 insertions(+), 71 deletions(-) diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 7752580..c804852 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -703,7 +703,7 @@ eas3_add_param_name(eas3_data *const data, char *name) ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -read_eas3_header(bwc_data *const data) +read_eas3_header(FILE *const fp, eas3_data *const data) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -723,12 +723,7 @@ read_eas3_header(bwc_data *const data) \*-----------------------*/ bwc_gl_inf *info; bitstream *aux; - eas3_std_params params; - - /*-----------------------*\ - ! DEFINE FILE POINTER: ! - \*-----------------------*/ - FILE *fp; + eas3_std_params *params; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -736,11 +731,10 @@ read_eas3_header(bwc_data *const data) assert(data); /*--------------------------------------------------------*\ - ! Save the file pointer and data info structure in tempo- ! - ! rary variables to make the code more readable. ! + ! Save the eas3_std_params structure in temporary ! + ! variables to make the code more readable. ! \*--------------------------------------------------------*/ - fp = data->fp; - info = &data->info; + params = &data->params; /*--------------------------------------------------------*\ ! Allocate the character buffer used to store chunks of ! @@ -784,8 +778,8 @@ read_eas3_header(bwc_data *const data) /*--------------------------------------------------------*\ ! Allocate the auxiliary information packed stream. ! \*--------------------------------------------------------*/ - data->codestream.aux = calloc(1, sizeof(bwc_stream)); - if(!data->codestream.aux) + data->aux = calloc(1, sizeof(bitstream)); + if(!data->aux) { // memory allocation error fprintf(stderr, MEMERROR); @@ -813,7 +807,7 @@ read_eas3_header(bwc_data *const data) ! present the eas3 standard parameters. The information ! ! is stored in the eas3_std_params structure. ! \*--------------------------------------------------------*/ - if(fread(¶ms, sizeof(uint64), 22, fp) != 22) + if(fread(params, sizeof(uint64), 22, fp) != 22) { // invalid read fprintf(stderr, RDERROR); @@ -824,7 +818,7 @@ read_eas3_header(bwc_data *const data) /*--------------------------------------------------------*\ ! Check if the specified file is of the EAS3 type. ! \*--------------------------------------------------------*/ - if(params.file_type == EAS2_TYPE) + if(params->file_type == EAS2_TYPE) { // invalid file format fprintf(stderr, "o##########################################################o\n"\ @@ -834,50 +828,29 @@ read_eas3_header(bwc_data *const data) return 1; } - /*--------------------------------------------------------*\ - ! Emit a file format hash to the aux stream to identify it ! - ! as a eas3 auxiliary information block. This hash can be ! - ! used to properly handle decompression into an eas3 file ! - ! or conversion to other file formats. ! - \*--------------------------------------------------------*/ - // emit_symbol(aux, hash("eas3"), 8); - /*--------------------------------------------------------*\ ! Emit the standard parameters to the auxiliary informa- ! ! tion information memory block. ! \*--------------------------------------------------------*/ - emit_chunck(aux, (uchar*)¶ms, 176); + emit_chunck(aux, (uchar*)params, 176); /*--------------------------------------------------------*\ ! Convert the parameters required for the bwc compression ! ! stage to little endian and store them in the file info ! ! structure. ! \*--------------------------------------------------------*/ - endian_conversion(¶ms.nzs, 8); - info->nTS = (uint16)params.nzs; + endian_conversion(params->nts, 8); - endian_conversion(¶ms.npar, 8); - info->nPar = (uint8)params.npar; + endian_conversion(params->npar, 8); - endian_conversion(¶ms.ndim1, 8); - info->nX = (uint64)params.ndim1; + endian_conversion(params->ndim1, 8); - endian_conversion(¶ms.ndim2, 8); - info->nY = (uint64)params.ndim2; + endian_conversion(params->ndim2, 8); - endian_conversion(¶ms.ndim3, 8); - info->nZ = (uint64)params.ndim3; + endian_conversion(params->ndim3, 8); - endian_conversion(¶ms.accuracy, 8); - if(params.accuracy == 1) - { - precision = 4; - } - else if(params.accuracy == 2) - { - precision = 8; - } - else + endian_conversion(params->accuracy, 8); + if(params->accuracy != 1 && params->accuracy != 2) { fprintf(stderr, "o##########################################################o\n"\ "| ERROR: The accuracy of the specified dataset is not sup- |\n"\ @@ -890,20 +863,20 @@ read_eas3_header(bwc_data *const data) ! Convert the size parameters, used to load the rest of the! ! header, to little endian. ! \*--------------------------------------------------------*/ - endian_conversion(¶ms.size_time, 8); - endian_conversion(¶ms.size_parameter, 8); - endian_conversion(¶ms.size_dim1, 8); - endian_conversion(¶ms.size_dim2, 8); - endian_conversion(¶ms.size_dim3, 8); - endian_conversion(¶ms.udef_char_size, 8); - endian_conversion(¶ms.udef_int_size, 8); - endian_conversion(¶ms.udef_real_size, 8); + endian_conversion(params->size_time, 8); + endian_conversion(params->size_parameter, 8); + endian_conversion(params->size_dim1, 8); + endian_conversion(params->size_dim2, 8); + endian_conversion(params->size_dim3, 8); + endian_conversion(params->udef_char_size, 8); + endian_conversion(params->udef_int_size, 8); + endian_conversion(params->udef_real_size, 8); /*--------------------------------------------------------*\ ! Allocate the time step array. If successful, read the ! ! timesteps from the file stream. ! \*--------------------------------------------------------*/ - buffer_char = realloc(buffer_char, info->nTS * sizeof(uint64)); + buffer_char = realloc(buffer_char, params->nts * sizeof(uint64)); if(!buffer_char) { // memory allocation error @@ -911,7 +884,7 @@ read_eas3_header(bwc_data *const data) return 1; } - if(fread(buffer_char, sizeof(uint64), info->nTS, fp) != info->nTS) + if(fread(buffer_char, sizeof(uint64), params->nts, fp) != params->nts) { // invalid read fprintf(stderr, RDERROR); @@ -923,19 +896,19 @@ read_eas3_header(bwc_data *const data) ! Emit the time step array to the auxiliary information ! ! memory block. ! \*--------------------------------------------------------*/ - emit_chunck(aux, buffer_char, info->nTS * sizeof(uint64)); + emit_chunck(aux, buffer_char, params->nts * sizeof(uint64)); /*--------------------------------------------------------*\ ! Check if any attributes have been specified in the eas3 ! ! file. ! \*--------------------------------------------------------*/ - if(params.attribute_mode == EAS3_ALL_ATTR) + if(params->attribute_mode == EAS3_ALL_ATTR) { /*--------------------------------------------------------*\ ! Allocate the buffer character array. If successful, read ! ! the timestep attributes from the file stream. ! \*--------------------------------------------------------*/ - buffer_char = realloc(buffer_char, info->nTS * ATTRLEN * sizeof(char)); + buffer_char = realloc(buffer_char, params->nts * ATTRLEN * sizeof(char)); if(!buffer_char) { // memory allocation error @@ -944,7 +917,7 @@ read_eas3_header(bwc_data *const data) return 1; } - if(fread(buffer_char, sizeof(char), info->nTS * ATTRLEN, fp) != (info->nTS * ATTRLEN)) + if(fread(buffer_char, sizeof(char), params->nts * ATTRLEN, fp) != (params->nts * ATTRLEN)) { // invalid read fprintf(stderr, RDERROR); @@ -956,9 +929,9 @@ read_eas3_header(bwc_data *const data) ! Emit the timestep attribute array to the auxiliary infor-! ! mation memory block. ! \*--------------------------------------------------------*/ - emit_chunck(aux, buffer_char, info->nTS * ATTRLEN * sizeof(char)); + emit_chunck(aux, buffer_char, params->nts * ATTRLEN * sizeof(char)); - for(i = 0; i < info->nPar; ++i) + for(i = 0; i < params->npar; ++i) { /*--------------------------------------------------------*\ ! Read the parameter name from the file stream and add all ! @@ -973,7 +946,7 @@ read_eas3_header(bwc_data *const data) return 1; } - bwc_add_param(data, param_name, precision); + eas3_add_param_name(data, param_name); /*--------------------------------------------------------*\ ! Read the parameter name from the file stream and add all ! @@ -989,15 +962,15 @@ read_eas3_header(bwc_data *const data) ! the eas3 file header. ! \*--------------------------------------------------------*/ Lread = 0; - Lread += (params.attribute_mode == EAS3_ALL_ATTR) ? 3 * ATTRLEN : 0; - Lread += (params.gmode_time > EAS3_NO_G) ? params.size_time * sizeof(uint64) : 0; - Lread += (params.gmode_param > EAS3_NO_G) ? params.size_parameter * sizeof(uint64) : 0; - Lread += (params.gmode_dim1 > EAS3_NO_G) ? params.size_dim1 * sizeof(uint64) : 0; - Lread += (params.gmode_dim2 > EAS3_NO_G) ? params.size_dim2 * sizeof(uint64) : 0; - Lread += (params.gmode_dim3 > EAS3_NO_G) ? params.size_dim3 * sizeof(uint64) : 0; - Lread += (params.udef_param == EAS3_ALL_UDEF) ? params.udef_char_size * sizeof(char) * UDEFLEN + - params.udef_int_size * sizeof(uint64) + - params.udef_real_size * sizeof(double) : 0; + Lread += (params->attribute_mode == EAS3_ALL_ATTR) ? 3 * ATTRLEN : 0; + Lread += (params->gmode_time > EAS3_NO_G) ? params->size_time * sizeof(uint64) : 0; + Lread += (params->gmode_param > EAS3_NO_G) ? params->size_parameter * sizeof(uint64) : 0; + Lread += (params->gmode_dim1 > EAS3_NO_G) ? params->size_dim1 * sizeof(uint64) : 0; + Lread += (params->gmode_dim2 > EAS3_NO_G) ? params->size_dim2 * sizeof(uint64) : 0; + Lread += (params->gmode_dim3 > EAS3_NO_G) ? params->size_dim3 * sizeof(uint64) : 0; + Lread += (params->udef_param == EAS3_ALL_UDEF) ? params->udef_char_size * sizeof(char) * UDEFLEN + + params->udef_int_size * sizeof(uint64) + + params->udef_real_size * sizeof(double) : 0; /*--------------------------------------------------------*\ ! Reallocate the buffer character array to allow for the ! @@ -1039,7 +1012,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(terminate_stream(aux, data->codestream.aux)) + if(terminate_stream(aux, data->aux)) { // memory allocation error fprintf(stderr, MEMERROR); -- 2.45.2 From 379e10d5a2a639ba2ff5ba00f3dde2773c81081b Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Wed, 16 Oct 2024 10:34:25 +0200 Subject: [PATCH 17/53] adjust write_eas3_header --- src/interfaces/reader/eas3.c | 37 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index c804852..9bbffa5 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -1057,7 +1057,7 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! ! \*----------------------------------------------------------------------------------------------------------*/ static uchar -write_eas3_header(bwc_data *const data) +write_eas3_header(FILE *const fp, eas3_data *const data) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -1075,25 +1075,13 @@ write_eas3_header(bwc_data *const data) bwc_gl_inf *info; bitstream *aux; eas3_std_params *params; - bwc_cmd_opts_ll *param; + eas3_param_names *param_names; - /*-----------------------*\ - ! DEFINE FILE POINTER: ! - \*-----------------------*/ - FILE *fp; - /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ assert(data); - /*--------------------------------------------------------*\ - ! Save the file pointer and data info structure in tempo- ! - ! rary variables to make the code more readable. ! - \*--------------------------------------------------------*/ - fp = data->fp; - info = &data->info; - /*--------------------------------------------------------*\ ! Write the valid EAS3 identifier to the specified file. ! \*--------------------------------------------------------*/ @@ -1107,8 +1095,7 @@ write_eas3_header(bwc_data *const data) /*--------------------------------------------------------*\ ! Initialize the auxiliary information stream. ! \*--------------------------------------------------------*/ - aux = init_stream(data->codestream.aux->memory, - data->codestream.aux->size, 'd'); + aux = init_stream(data->aux->memory, data->aux->size, 'd'); /*--------------------------------------------------------*\ ! Get the standard parameters from the auxiliary informa- ! @@ -1142,7 +1129,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 = get_chunck(aux, info->nTS * sizeof(uint64)); + buffer_char = get_chunck(aux, data->params.nts * sizeof(uint64)); if(!buffer_char) { // memory allocation error @@ -1151,7 +1138,7 @@ write_eas3_header(bwc_data *const data) return 1; } - if(fwrite(buffer_char, sizeof(uint64), info->nTS, fp) != info->nTS) + if(fwrite(buffer_char, sizeof(uint64), data->params.nts, fp) != data->params.nts) { // invalid read fprintf(stderr, WRTERROR); @@ -1171,7 +1158,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 = get_chunck(aux, info->nTS * ATTRLEN); + buffer_char = get_chunck(aux, data->params.nts * ATTRLEN); if(!buffer_char) { // memory allocation error @@ -1180,7 +1167,7 @@ write_eas3_header(bwc_data *const data) return 1; } - if(fwrite(buffer_char, sizeof(uchar), info->nTS * ATTRLEN, fp) != (info->nTS * ATTRLEN)) + if(fwrite(buffer_char, sizeof(uchar), data->params.nts * ATTRLEN, fp) != (data->params.nts * ATTRLEN)) { // invalid read fprintf(stderr, WRTERROR); @@ -1192,17 +1179,17 @@ write_eas3_header(bwc_data *const data) /*--------------------------------------------------------*\ ! Loop through the parameter array and... ! \*--------------------------------------------------------*/ - if(data->info.parameter) + if(data->param_names) { - param = data->info.parameter->root; + param_names = data->param_names->root; - while(param != NULL) + while(param_names != NULL) { /*--------------------------------------------------------*\ ! ... write the parameter name from the info structure to ! ! the file stream. ! \*--------------------------------------------------------*/ - if(fwrite(param->name, sizeof(char), ATTRLEN, fp) != ATTRLEN) + if(fwrite(param_names->name, sizeof(char), ATTRLEN, fp) != ATTRLEN) { // invalid read fprintf(stderr, WRTERROR); @@ -1210,7 +1197,7 @@ write_eas3_header(bwc_data *const data) return 1; } - param = param -> next; + param_names = param_names->next; } } } -- 2.45.2 From 858808a46ccb50ea961c700605d55d9ec60bfa79 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Wed, 16 Oct 2024 11:11:34 +0200 Subject: [PATCH 18/53] adjust read_eas3 --- include/interfaces/reader/eas3.h | 2 +- src/interfaces/reader/eas3.c | 59 +++++++++++++++----------------- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/include/interfaces/reader/eas3.h b/include/interfaces/reader/eas3.h index 650d20f..b1bc4d8 100644 --- a/include/interfaces/reader/eas3.h +++ b/include/interfaces/reader/eas3.h @@ -388,7 +388,7 @@ ! structure. ! ! ! \*----------------------------------------------------------------------------------------------------------*/ - bwc_data* + eas3_data* read_eas3(char *const filename); /*----------------------------------------------------------------------------------------------------------*\ diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 9bbffa5..9fa436b 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -1290,7 +1290,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data) ! 20.06.2018 Patrick Vogler B87D120 V 0.1.0 function created ! ! ! \*----------------------------------------------------------------------------------------------------------*/ -bwc_data* +eas3_data* read_eas3(char *const filename) { /*-----------------------*\ @@ -1299,16 +1299,17 @@ read_eas3(char *const filename) uint64 Lfield; uint64 i; uint32 root; + FILE *fp; /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - bwc_data *data; + eas3_data *data; /*--------------------------------------------------------*\ ! Allocate the data structure. ! \*--------------------------------------------------------*/ - data = calloc(1, sizeof(bwc_data)); + data = calloc(1, sizeof(eas3_data)); if(!data) { // memory allocation error @@ -1316,23 +1317,17 @@ read_eas3(char *const filename) return NULL; } - /*--------------------------------------------------------*\ - ! Set the file identifier used to select the appropriate ! - ! write operation during decompression. ! - \*--------------------------------------------------------*/ - strncpy(data->info.f_ext, "eas", 4); - /*--------------------------------------------------------*\ ! Open the specified file for reading. If the file doesn't ! ! exist, exit the bwc command-line tool. ! \*--------------------------------------------------------*/ - if((data->fp = fopen(filename, "rb")) == NULL) + if((fp = fopen(filename, "rb")) == NULL) { // error opening file fprintf(stderr, "o##########################################################o\n"\ "| ERROR: Could not open or read %-25s|\n"\ "o##########################################################o\n", filename); - bwc_free_data(data); + fclose(fp); return NULL; } @@ -1340,10 +1335,10 @@ read_eas3(char *const filename) ! Parse the eas3 header and store the information in the ! ! data structure. ! \*--------------------------------------------------------*/ - if(read_eas3_header(data)) + if(read_eas3_header(fp, data)) { //error reading eas3 header - bwc_free_data(data); + eas3_free_data(data); } /*--------------------------------------------------------*\ @@ -1351,19 +1346,19 @@ read_eas3(char *const filename) ! file and store the information in the bwc_gl_data struc- ! ! ture. ! \*--------------------------------------------------------*/ - root = ftell(data->fp); - fseek(data->fp, 0L, SEEK_END); - Lfield = (ftell(data->fp) - root) / sizeof(double); - fseek(data->fp, root, SEEK_SET); + root = ftell(fp); + fseek(fp, 0L, SEEK_END); + Lfield = (ftell(fp) - root) / sizeof(double); + fseek(fp, root, SEEK_SET); /*--------------------------------------------------------*\ ! Check if the file_size coincide with the specified dimen-! ! sions, timesteps number of parameters or bitdepth speci- ! ! fied in the eas3 file header. ! \*--------------------------------------------------------*/ - if(Lfield != data->info.nX * data->info.nY * - data->info.nZ * data->info.nTS * - data->info.nPar) + if(Lfield != data->params.ndim1 * data->params.ndim2 * + data->params.ndim3 * data->params.nts * + data->params.npar) { // error in file size fprintf(stderr, "o##########################################################o\n"\ @@ -1372,11 +1367,11 @@ read_eas3(char *const filename) "| and number of parameters specified in the file |\n"\ "| header. |\n"\ "o##########################################################o\n"); - bwc_free_data(data); + eas3_free_data(data); return NULL; } - if(data->info.parameter->precision == 4) + if(data->params.accuracy == 1) { /*--------------------------------------------------------*\ ! Allocate the real field that will hold the numerical ! @@ -1384,22 +1379,22 @@ read_eas3(char *const filename) \*--------------------------------------------------------*/ data->field.d = NULL; data->field.f = calloc(Lfield, sizeof(float)); - if(!data->field.d) + if(!data->field.f) { // memory allocation error fprintf(stderr, MEMERROR); - bwc_free_data(data); + eas3_free_data(data); return NULL; } /*--------------------------------------------------------*\ ! Read the flow field data from the specified eas3 file. ! \*--------------------------------------------------------*/ - if(fread(data->field.f, sizeof(float), Lfield, data->fp) != Lfield) + if(fread(data->field.f, sizeof(float), Lfield, fp) != Lfield) { // invalid read fprintf(stderr, RDERROR); - bwc_free_data(data); + eas3_free_data(data); return NULL; } @@ -1412,7 +1407,7 @@ read_eas3(char *const filename) endian_conversion(&data->field.f[i], 4); } } - else if(data->info.parameter->precision == 8) + else if(data->params.accuracy == 2) { /*--------------------------------------------------------*\ ! Allocate the real field that will hold the numerical ! @@ -1424,18 +1419,18 @@ read_eas3(char *const filename) { // memory allocation error fprintf(stderr, MEMERROR); - bwc_free_data(data); + eas3_free_data(data); return NULL; } /*--------------------------------------------------------*\ ! Read the flow field data from the specified eas3 file. ! \*--------------------------------------------------------*/ - if(fread(data->field.d, sizeof(double), Lfield, data->fp) != Lfield) + if(fread(data->field.d, sizeof(double), Lfield, fp) != Lfield) { // invalid read fprintf(stderr, RDERROR); - bwc_free_data(data); + eas3_free_data(data); return NULL; } @@ -1453,8 +1448,8 @@ read_eas3(char *const filename) ! Close the file pointer and return the bwc_data structure ! ! to the function caller. ! \*--------------------------------------------------------*/ - fclose(data->fp); - data->fp = NULL; + fclose(fp); + fp = NULL; return data; } -- 2.45.2 From 62c9bc1a21ed575e9966869542c22091a7054ac7 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Wed, 16 Oct 2024 11:14:36 +0200 Subject: [PATCH 19/53] adjust write_eas3 --- include/interfaces/reader/eas3.h | 2 +- src/interfaces/reader/eas3.c | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/interfaces/reader/eas3.h b/include/interfaces/reader/eas3.h index b1bc4d8..758e542 100644 --- a/include/interfaces/reader/eas3.h +++ b/include/interfaces/reader/eas3.h @@ -402,5 +402,5 @@ ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar - write_eas3(bwc_data *const file, char *const filename); + write_eas3(eas3_data *const file, char *const filename); #endif \ No newline at end of file diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 9fa436b..ee2574b 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -1488,13 +1488,14 @@ read_eas3(char *const filename) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -write_eas3(bwc_data *const data, char *const filename) +write_eas3(eas3_data *const data, char *const filename) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! \*-----------------------*/ uint64 Lfield; uint64 i; + FILE *fp; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -1506,7 +1507,7 @@ write_eas3(bwc_data *const data, char *const filename) ! exist, discard its content. If the file cannot be creat- ! ! ed, exit the bwc command-line tool. ! \*--------------------------------------------------------*/ - if((data->fp = fopen(filename, "wb")) == NULL) + if((fp = fopen(filename, "wb")) == NULL) { // error opening file fprintf(stderr, "o##########################################################o\n"\ @@ -1518,7 +1519,7 @@ write_eas3(bwc_data *const data, char *const filename) /*--------------------------------------------------------*\ ! Write the eas3 header to the specified file. ! \*--------------------------------------------------------*/ - if(write_eas3_header(data)) + if(write_eas3_header(fp, data)) { //error reading eas3 header return 1; @@ -1528,10 +1529,10 @@ write_eas3(bwc_data *const data, char *const filename) ! Calculate the size of the data field used for the endian ! ! conversion and write operations. ! \*--------------------------------------------------------*/ - Lfield = data->info.nX * data->info.nY * - data->info.nZ * data->info.nTS * data->info.nPar; + Lfield = data->params.ndim1 * data->params.ndim2 * + data->params.ndim3 * data->params.nts * data->params.npar; - if(data->info.parameter->precision == 4) + if(data->params.accuracy == 1) { /*--------------------------------------------------------*\ ! Convert the flow field data from big endian to endian. ! @@ -1544,14 +1545,14 @@ write_eas3(bwc_data *const data, char *const filename) /*--------------------------------------------------------*\ ! Write the flow field data to the specified eas3 file. ! \*--------------------------------------------------------*/ - if(fwrite(data->field.f, sizeof(float), Lfield, data->fp) != Lfield) + if(fwrite(data->field.f, sizeof(float), Lfield, fp) != Lfield) { // invalid read fprintf(stderr, WRTERROR); return 1; } } - else if(data->info.parameter->precision == 8) + else if(data->params.accuracy == 2) { /*--------------------------------------------------------*\ ! Convert the flow field data from big endian to endian. ! @@ -1564,7 +1565,7 @@ write_eas3(bwc_data *const data, char *const filename) /*--------------------------------------------------------*\ ! Write the flow field data to the specified eas3 file. ! \*--------------------------------------------------------*/ - if(fwrite(data->field.d, sizeof(double), Lfield, data->fp) != Lfield) + if(fwrite(data->field.d, sizeof(double), Lfield, fp) != Lfield) { // invalid read fprintf(stderr, WRTERROR); @@ -1575,7 +1576,7 @@ write_eas3(bwc_data *const data, char *const filename) /*--------------------------------------------------------*\ ! Close the file pointer and return to the function caller.! \*--------------------------------------------------------*/ - fclose(data->fp); - data->fp = NULL; + fclose(fp); + fp = NULL; return 0; } \ No newline at end of file -- 2.45.2 From 46358b4c1fabccfd0ecf9612a1feb640df96b6eb Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Thu, 17 Oct 2024 14:30:53 +0200 Subject: [PATCH 20/53] rename functions and bitstream stuff to avoid redefinitions --- include/interfaces/reader/eas3.h | 4 +-- src/interfaces/reader/eas3.c | 52 ++++++++++++++++---------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/include/interfaces/reader/eas3.h b/include/interfaces/reader/eas3.h index 758e542..a346f0e 100644 --- a/include/interfaces/reader/eas3.h +++ b/include/interfaces/reader/eas3.h @@ -216,7 +216,7 @@ uchar *access; // Pointer used to parse packed stream. uchar *memory; // Memory handle for packed stream chunck. - } bitstream; + } span; /*----------------------------------------------------------------------------------------------------------*\ ! STRUCT NAME: eas3_header ! @@ -368,7 +368,7 @@ float *f; } field; - bitstream *aux; + span *aux; } eas3_data; /************************************************************************************************************\ diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index ee2574b..4b12431 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -85,7 +85,7 @@ || || \************************************************************************************************************/ /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uint32 bytes_used(bitstream *const stream) ! +! FUNCTION NAME: uint32 eas3_bytes_used(bitstream *const stream) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -115,7 +115,7 @@ ! ! \*----------------------------------------------------------------------------------------------------------*/ uint64 -bytes_used(bitstream const *const stream) +eas3_bytes_used(span const *const stream) { if(stream->T == 0xFF) { @@ -128,7 +128,7 @@ bytes_used(bitstream const *const stream) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bitstream* bwc_init_stream(uchar* memory, uint32 size, char instr) ! +! FUNCTION NAME: span* bwc_init_stream(uchar* memory, uint32 size, char instr) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -165,13 +165,13 @@ bytes_used(bitstream const *const stream) ! 19.06.2019 Patrick Vogler B87D120 V 0.1.0 function created ! ! ! \*----------------------------------------------------------------------------------------------------------*/ -bitstream* -init_stream(uchar* memory, uint32 size, char instr) +span* +eas3_init_stream(uchar* memory, uint32 size, char instr) { /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - bitstream *stream; + span *stream; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -181,7 +181,7 @@ init_stream(uchar* memory, uint32 size, char instr) /*--------------------------------------------------------*\ ! Allocate the bwc stream structure. ! \*--------------------------------------------------------*/ - stream = calloc(1, sizeof(bitstream)); + stream = calloc(1, sizeof(span)); if(!stream) { // memory allocation error @@ -231,7 +231,7 @@ init_stream(uchar* memory, uint32 size, char instr) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_emit_chunck(bitstream *const stream, const uchar* string, const uint64 length) ! +! FUNCTION NAME: void eas3_emit_chunck(bitstream *const stream, const uchar* string, const uint64 length) ! ! -------------- ! ! ! ! DESCRIPTION: ! @@ -266,7 +266,7 @@ init_stream(uchar* memory, uint32 size, char instr) ! ! \*----------------------------------------------------------------------------------------------------------*/ void -emit_chunck(bitstream *const stream, const uchar* chunck, const uint64 size) +eas3_emit_chunck(span *const stream, const uchar* chunck, const uint64 size) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -283,7 +283,7 @@ emit_chunck(bitstream *const stream, const uchar* chunck, const uint64 size) ! Evaluate the memory block size if the current chunck of ! ! data is written to the stream. ! \*--------------------------------------------------------*/ - Lreq = (bytes_used(stream) + size); + Lreq = (eas3_bytes_used(stream) + size); /*--------------------------------------------------------*\ ! Check if the enough memory has been allocated for the ! @@ -373,7 +373,7 @@ emit_chunck(bitstream *const stream, const uchar* chunck, const uint64 size) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar* -get_chunck(bitstream *const stream, const uint64 size) +eas3_get_chunck(span *const stream, const uint64 size) { /*-----------------------*\ ! DEFINE CHAR VARIABLES: ! @@ -390,7 +390,7 @@ get_chunck(bitstream *const stream, const uint64 size) ! does not exceed the number of bytes still present in its ! ! memory block. ! \*--------------------------------------------------------*/ - if(bytes_used(stream) + size <= stream->Lmax) + if(eas3_bytes_used(stream) + size <= stream->Lmax) { /*--------------------------------------------------------*\ ! Allocate a temporary array used to store the bytes that ! @@ -461,7 +461,7 @@ get_chunck(bitstream *const stream, const uint64 size) ! ! \*----------------------------------------------------------------------------------------------------------*/ uchar -terminate_stream(bitstream *stream, bitstream *const packed_stream) +eas3_terminate_stream(span *stream, span *const packed_stream) { /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -722,7 +722,7 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! DEFINE STRUCTS: ! \*-----------------------*/ bwc_gl_inf *info; - bitstream *aux; + span *aux; eas3_std_params *params; /*-----------------------*\ @@ -778,7 +778,7 @@ read_eas3_header(FILE *const fp, eas3_data *const data) /*--------------------------------------------------------*\ ! Allocate the auxiliary information packed stream. ! \*--------------------------------------------------------*/ - data->aux = calloc(1, sizeof(bitstream)); + data->aux = calloc(1, sizeof(span)); if(!data->aux) { // memory allocation error @@ -793,7 +793,7 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! block has been chosen arbitrarily and should be large ! ! enough to prevent excessive reallocation. ! \*--------------------------------------------------------*/ - aux = init_stream(NULL, AUX_SIZE, 'c'); + aux = eas3_init_stream(NULL, AUX_SIZE, 'c'); if(!aux) { // memory allocation error @@ -896,7 +896,7 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Emit the time step array to the auxiliary information ! ! memory block. ! \*--------------------------------------------------------*/ - emit_chunck(aux, buffer_char, params->nts * sizeof(uint64)); + eas3_emit_chunck(aux, buffer_char, params->nts * sizeof(uint64)); /*--------------------------------------------------------*\ ! Check if any attributes have been specified in the eas3 ! @@ -929,7 +929,7 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Emit the timestep attribute array to the auxiliary infor-! ! mation memory block. ! \*--------------------------------------------------------*/ - emit_chunck(aux, buffer_char, params->nts * ATTRLEN * sizeof(char)); + eas3_emit_chunck(aux, buffer_char, params->nts * ATTRLEN * sizeof(char)); for(i = 0; i < params->npar; ++i) { @@ -1000,7 +1000,7 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Emit the remaining header information the the auxiliary ! ! information stream. ! \*--------------------------------------------------------*/ - emit_chunck(aux, buffer_char, Lread); + eas3_emit_chunck(aux, buffer_char, Lread); /*--------------------------------------------------------*\ ! Free the buffer character array. ! @@ -1012,7 +1012,7 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! ful, the address to the aux memory block stored is ! ! stored in the file structure alongside its size. ! \*--------------------------------------------------------*/ - if(terminate_stream(aux, data->aux)) + if(eas3_terminate_stream(aux, data->aux)) { // memory allocation error fprintf(stderr, MEMERROR); @@ -1073,7 +1073,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data) ! DEFINE STRUCTS: ! \*-----------------------*/ bwc_gl_inf *info; - bitstream *aux; + span *aux; eas3_std_params *params; eas3_param_names *param_names; @@ -1095,13 +1095,13 @@ write_eas3_header(FILE *const fp, eas3_data *const data) /*--------------------------------------------------------*\ ! Initialize the auxiliary information stream. ! \*--------------------------------------------------------*/ - aux = init_stream(data->aux->memory, data->aux->size, 'd'); + aux = eas3_init_stream(data->aux->memory, data->aux->size, 'd'); /*--------------------------------------------------------*\ ! Get the standard parameters from the auxiliary informa- ! ! memory block and write them to the file stream. ! \*--------------------------------------------------------*/ - params = (eas3_std_params*)get_chunck(aux, 176); + params = (eas3_std_params*)eas3_get_chunck(aux, 176); if(fwrite(params, sizeof(uint64), 22, fp) != 22) { @@ -1129,7 +1129,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data) ! the timestep array from the auxiliary information block ! ! and write it to the file stream. ! \*--------------------------------------------------------*/ - buffer_char = get_chunck(aux, data->params.nts * sizeof(uint64)); + buffer_char = eas3_get_chunck(aux, data->params.nts * sizeof(uint64)); if(!buffer_char) { // memory allocation error @@ -1158,7 +1158,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data) ! the timestep attribute array from the auxiliary informa- ! ! tion block and write it to the file stream. ! \*--------------------------------------------------------*/ - buffer_char = get_chunck(aux, data->params.nts * ATTRLEN); + buffer_char = eas3_get_chunck(aux, data->params.nts * ATTRLEN); if(!buffer_char) { // memory allocation error @@ -1222,7 +1222,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data) ! the remaining eas header bytes from the auxiliary infor- ! ! mation block and write it to the file stream. ! \*--------------------------------------------------------*/ - buffer_char = get_chunck(aux, Lwrite); + buffer_char = eas3_get_chunck(aux, Lwrite); if(!buffer_char) { // memory allocation error -- 2.45.2 From e101bd2404b36ac18a5569ae61335ff908745779 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Thu, 17 Oct 2024 14:32:50 +0200 Subject: [PATCH 21/53] correct usage of params and param_names --- src/interfaces/reader/eas3.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 4b12431..80c8882 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -619,7 +619,7 @@ eas3_add_param_name(eas3_data *const data, char *name) { eas3_param_names *param_names; assert(data); - param_names = &data->param_names; + param_names = data->param_names; /*--------------------------------------------------------*\ ! Check if the specified parameter name has the proper ! ! length. ! @@ -832,24 +832,24 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Emit the standard parameters to the auxiliary informa- ! ! tion information memory block. ! \*--------------------------------------------------------*/ - emit_chunck(aux, (uchar*)params, 176); + eas3_emit_chunck(aux, (uchar*)params, 176); /*--------------------------------------------------------*\ ! Convert the parameters required for the bwc compression ! ! stage to little endian and store them in the file info ! ! structure. ! \*--------------------------------------------------------*/ - endian_conversion(params->nts, 8); + endian_conversion(¶ms->nts, 8); - endian_conversion(params->npar, 8); + endian_conversion(¶ms->npar, 8); - endian_conversion(params->ndim1, 8); + endian_conversion(¶ms->ndim1, 8); - endian_conversion(params->ndim2, 8); + endian_conversion(¶ms->ndim2, 8); - endian_conversion(params->ndim3, 8); + endian_conversion(¶ms->ndim3, 8); - endian_conversion(params->accuracy, 8); + endian_conversion(¶ms->accuracy, 8); if(params->accuracy != 1 && params->accuracy != 2) { fprintf(stderr, "o##########################################################o\n"\ @@ -863,14 +863,14 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Convert the size parameters, used to load the rest of the! ! header, to little endian. ! \*--------------------------------------------------------*/ - endian_conversion(params->size_time, 8); - endian_conversion(params->size_parameter, 8); - endian_conversion(params->size_dim1, 8); - endian_conversion(params->size_dim2, 8); - endian_conversion(params->size_dim3, 8); - endian_conversion(params->udef_char_size, 8); - endian_conversion(params->udef_int_size, 8); - endian_conversion(params->udef_real_size, 8); + endian_conversion(¶ms->size_time, 8); + endian_conversion(¶ms->size_parameter, 8); + endian_conversion(¶ms->size_dim1, 8); + endian_conversion(¶ms->size_dim2, 8); + endian_conversion(¶ms->size_dim3, 8); + endian_conversion(¶ms->udef_char_size, 8); + endian_conversion(¶ms->udef_int_size, 8); + endian_conversion(¶ms->udef_real_size, 8); /*--------------------------------------------------------*\ ! Allocate the time step array. If successful, read the ! -- 2.45.2 From 49a9cf3d63bb1a5ef1ab770d3f84ae9a3f5346e3 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Thu, 17 Oct 2024 14:33:35 +0200 Subject: [PATCH 22/53] don't close on null file pointer --- src/interfaces/reader/eas3.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 80c8882..28cf397 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -1327,7 +1327,6 @@ read_eas3(char *const filename) fprintf(stderr, "o##########################################################o\n"\ "| ERROR: Could not open or read %-25s|\n"\ "o##########################################################o\n", filename); - fclose(fp); return NULL; } -- 2.45.2 From 43dc27014b8cb39307c2924d4ab06f17c6b1a7a0 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Thu, 17 Oct 2024 15:16:19 +0200 Subject: [PATCH 23/53] initial test compression with new api; working eas3 reader --- src/tools/bwccmdl.c | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index f59e5b4..a9c9a69 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -52,6 +52,10 @@ #include #include +#include "eas3.h" +#include "bwc.h" +#include "bwccmdl.h" + /*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*\ || _ _ ____ ____ ____ ____ ____ || || |\/| |__| | |__/ | | [__ || @@ -631,11 +635,65 @@ static struct argp argp = {options, parse_opt, 0, doc}; int main(int argc, char *argv[]) { int i = 0; + int size = 0; /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ cli_arguments arguments = {0}; + eas3_data *data; + uchar *input; + uchar *output; + + data = read_eas3("TGV_125.eas"); + + printf("I read eas3. No guarantees. Check validity. Compression will start now ...\n"); + + size = data->params.ndim1 * data->params.ndim2 * + data->params.ndim3 * data->params.nts * + data->params.npar; + + bwc_precision precision; + if (data->params.accuracy == 1) + { + precision = bwc_precision_single; + input = (uchar*)data->field.f; + output = calloc(size, sizeof(float)); + } + else if (data->params.accuracy == 2) + { + precision = bwc_precision_double; + input = (uchar*)data->field.d; + output = calloc(size, sizeof(double)); + } + + bwc_mode mode = comp; + bwc_stream* stream = bwc_init_stream(input, output, comp); + bwc_codec* coder = bwc_alloc_coder(data->params.ndim1, + data->params.ndim2, + data->params.ndim3, + data->params.nts, + data->params.npar, + precision); + // TODO: implement setters for codeblocks, decomposition etc. + //bwc_set_qm(coder, 32); + char rate[10]; // TODO: replace with cmdl argument + sprintf(rate, "%05.3f", 4.0); + rate[strlen(rate)-1] = '0'; + printf("rate %s \n", rate); + + bwc_create_compression(coder, stream, rate); + bwc_compress(coder, stream); + bwc_free_codec(coder); + + // TODO: implement I/O of bwc file + // TODO: bwc_header_info + + //write_eas3(data, "output2.eas"); + + eas3_free_data(data); + free(output); + /*--------------------------------------------------------*\ ! Initialize the arguments structure. ! \*--------------------------------------------------------*/ -- 2.45.2 From e0bc0d883934e3ba816ddeef8bc8ee60f430e09a Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Thu, 17 Oct 2024 15:20:31 +0200 Subject: [PATCH 24/53] comments; todo implement --- src/tools/bwccmdl.c | 54 +++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index a9c9a69..d5ff025 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -303,13 +303,12 @@ typedef struct * * @retval -1 Error * @retval 0 OK - */ -/*================================================================================================*/ static error_t parse_opt(int key, char *arg, struct argp_state *state) { + */ /*-----------------------*\ ! DEFINE INT VARIABLES: ! \*-----------------------*/ @@ -317,44 +316,56 @@ parse_opt(int key, //uint64_t multiplier; //uint16_t buffI; - +/* uint8_t i; //uint8_t length, shift; + */ /*-----------------------*\ ! DEFINE REAL VARIABLES: ! \*-----------------------*/ + /* float bitrate; + */ /*-----------------------*\ ! DEFINE REAL VARIABLES: ! \*-----------------------*/ + /* char *end; + */ /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ + /* cli_arguments *arguments; bwc_codec *codec; bwc_stream *stream; + */ /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ + /* assert(state); + */ /*--------------------------------------------------------*\ ! Save frequently used variables/structures to temporary ! ! variables to make the code more readable. ! \*--------------------------------------------------------*/ + /* arguments = state->input; codec = arguments->codec; stream = arguments->stream; + */ /*--------------------------------------------------------*\ ! Parse the cli arguments according to the supplied opt. ! \*--------------------------------------------------------*/ + /* switch(key) { case 'c': @@ -487,6 +498,7 @@ parse_opt(int key, } case 'D': { + */ /* remove_deliminator(arg, end, '/'); for(buff_LL = strtoll(arg, &end, 10), i = 0; arg != end && i < 4; @@ -521,6 +533,7 @@ parse_opt(int key, argp_error(state, "The codeblock argument expects either a " "single global or 4 directional values\n"); }*/ + /* break; } case 'n': @@ -587,6 +600,7 @@ parse_opt(int key, break; case ARGP_KEY_END: + */ /*if(!((arguments->analysis != NULL) && (arguments->comp == NULL) && (arguments->decomp == NULL) && (arguments->header == NULL) @@ -609,6 +623,7 @@ parse_opt(int key, argp_error(state, "The User supplied options do not fit the " "supported use cases.\n"); }*/ + /* break; default: @@ -616,9 +631,10 @@ parse_opt(int key, } return EXIT_SUCCESS; } +*/ // initialize the argp struct. Which will be used to parse and use the args. -static struct argp argp = {options, parse_opt, 0, doc}; +//static struct argp argp = {options, parse_opt, 0, doc}; /*================================================================================================*/ /** @@ -697,27 +713,27 @@ int main(int argc, char *argv[]) /*--------------------------------------------------------*\ ! Initialize the arguments structure. ! \*--------------------------------------------------------*/ - arguments.stream = calloc(1, sizeof(bwc_stream)); - arguments.codec = calloc(1, sizeof(bwc_codec)); - if((arguments.stream == NULL) || - (arguments.codec == NULL)) - { + //arguments.stream = calloc(1, sizeof(bwc_stream)); + //arguments.codec = calloc(1, sizeof(bwc_codec)); + //if((arguments.stream == NULL) || + //(arguments.codec == NULL)) + //{ // memory allocation error - fprintf(stderr, MEMERROR); - return EXIT_FAILURE; - } + //fprintf(stderr, MEMERROR); + //return EXIT_FAILURE; + //} /*--------------------------------------------------------*\ ! Parse the cli arguments. ! \*--------------------------------------------------------*/ - argp_parse(&argp, argc, argv, 0, 0, &arguments); - if(arguments.mode == cli_err) - { - return EXIT_FAILURE; - } + //argp_parse(&argp, argc, argv, 0, 0, &arguments); + //if(arguments.mode == cli_err) + //{ + //return EXIT_FAILURE; + //} - for(i = 0; i < 10; ++i) - printf("bitrate %d:\t%f\n",i,arguments.bitrate[i]); + //for(i = 0; i < 10; ++i) + //printf("bitrate %d:\t%f\n",i,arguments.bitrate[i]); -- 2.45.2 From 31ed09982e25d7acdae349799023da68ee085f1d Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Thu, 17 Oct 2024 19:18:44 +0200 Subject: [PATCH 25/53] manual aux buffer --- include/interfaces/reader/eas3.h | 4 ++ src/interfaces/reader/eas3.c | 82 ++++++++++++++++---------------- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/include/interfaces/reader/eas3.h b/include/interfaces/reader/eas3.h index a346f0e..b2efca4 100644 --- a/include/interfaces/reader/eas3.h +++ b/include/interfaces/reader/eas3.h @@ -369,6 +369,10 @@ } field; span *aux; + + uchar *uchar_aux; + uint32 aux_pos; + uint32 aux_len; } eas3_data; /************************************************************************************************************\ diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 28cf397..65e6db7 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -231,40 +231,28 @@ eas3_init_stream(uchar* memory, uint32 size, char instr) } /*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void eas3_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 ! +! This macro is used to write an additional chunck of size length to the auxilliary ! +! information. ! ! ! \*----------------------------------------------------------------------------------------------------------*/ + +#define aux_push_back(aux, aux_pos, aux_len, chunck, chunck_len) \ +{ \ + if (aux_pos + chunck_len > aux_len) \ + { \ + while(aux_pos + chunck_len > aux_len) \ + { \ + aux_len += aux_len / 2; \ + } \ + aux = realloc(aux, aux_len); \ + } \ + memcpy(aux + aux_pos, chunck, chunck_len); \ + aux_pos += chunck_len; \ +} + void eas3_emit_chunck(span *const stream, const uchar* chunck, const uint64 size) { @@ -793,8 +781,10 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! block has been chosen arbitrarily and should be large ! ! enough to prevent excessive reallocation. ! \*--------------------------------------------------------*/ - aux = eas3_init_stream(NULL, AUX_SIZE, 'c'); - if(!aux) + data->uchar_aux = calloc(AUX_SIZE, sizeof(uchar)); + data->aux_pos = 0; + data->aux_len = AUX_SIZE; + if(!data->uchar_aux) { // memory allocation error fprintf(stderr, MEMERROR); @@ -832,7 +822,8 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Emit the standard parameters to the auxiliary informa- ! ! tion information memory block. ! \*--------------------------------------------------------*/ - eas3_emit_chunck(aux, (uchar*)params, 176); + aux_push_back(data->uchar_aux, data->aux_pos, data->aux_len, + (uchar*)params, 176); /*--------------------------------------------------------*\ ! Convert the parameters required for the bwc compression ! @@ -896,7 +887,8 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Emit the time step array to the auxiliary information ! ! memory block. ! \*--------------------------------------------------------*/ - eas3_emit_chunck(aux, buffer_char, params->nts * sizeof(uint64)); + aux_push_back(data->uchar_aux, data->aux_pos, data->aux_len, buffer_char, + params->nts * sizeof(uint64)); /*--------------------------------------------------------*\ ! Check if any attributes have been specified in the eas3 ! @@ -929,7 +921,8 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Emit the timestep attribute array to the auxiliary infor-! ! mation memory block. ! \*--------------------------------------------------------*/ - eas3_emit_chunck(aux, buffer_char, params->nts * ATTRLEN * sizeof(char)); + aux_push_back(data->uchar_aux, data->aux_pos, data->aux_len, buffer_char, + params->nts * ATTRLEN * sizeof(char)); for(i = 0; i < params->npar; ++i) { @@ -1000,7 +993,8 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Emit the remaining header information the the auxiliary ! ! information stream. ! \*--------------------------------------------------------*/ - eas3_emit_chunck(aux, buffer_char, Lread); + aux_push_back(data->uchar_aux, data->aux_pos, data->aux_len, + buffer_char, Lread); /*--------------------------------------------------------*\ ! Free the buffer character array. ! @@ -1012,12 +1006,18 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! ful, the address to the aux memory block stored is ! ! stored in the file structure alongside its size. ! \*--------------------------------------------------------*/ - if(eas3_terminate_stream(aux, data->aux)) - { - // memory allocation error - fprintf(stderr, MEMERROR); - return 1; - } + if(data->aux_pos != data->aux_len) + { + data->aux_len = data->aux_pos; + data->uchar_aux = realloc(data->uchar_aux, data->aux_len); + if(!data->uchar_aux) + { + // memory allocation error + fprintf(stderr, MEMERROR); + data->aux_len = 0; + return 1; + } + } return 0; } -- 2.45.2 From df2ad56f14088dfb14af46e8854cfeac82e0e4ee Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Fri, 18 Oct 2024 08:22:53 +0200 Subject: [PATCH 26/53] remove eas3_emit_chunck and eas3_terminate_stream --- src/interfaces/reader/eas3.c | 146 ----------------------------------- 1 file changed, 146 deletions(-) diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 65e6db7..6ef18d1 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -253,82 +253,6 @@ eas3_init_stream(uchar* memory, uint32 size, char instr) aux_pos += chunck_len; \ } -void -eas3_emit_chunck(span *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 = (eas3_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) ! ! -------------- ! @@ -420,76 +344,6 @@ eas3_get_chunck(span *const stream, const uint64 size) } } -/*----------------------------------------------------------------------------------------------------------*\ -! 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 -eas3_terminate_stream(span *stream, span *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; - packed_stream->L = stream->L; - } - else - { - free(stream->memory); - } - - free(stream); - return 0; -} - /*----------------------------------------------------------------------------------------------------------*\ ! ! ! DESCRIPTION: ! -- 2.45.2 From 58ab32e393e738062f56f04984233ba5a914ee79 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Fri, 18 Oct 2024 10:55:00 +0200 Subject: [PATCH 27/53] implement aux_dequeue, test, and remove aux span --- include/interfaces/reader/eas3.h | 3 +- src/interfaces/reader/eas3.c | 68 ++++++++++++++++++++------------ src/tools/bwccmdl.c | 4 +- 3 files changed, 46 insertions(+), 29 deletions(-) diff --git a/include/interfaces/reader/eas3.h b/include/interfaces/reader/eas3.h index b2efca4..9bb344d 100644 --- a/include/interfaces/reader/eas3.h +++ b/include/interfaces/reader/eas3.h @@ -368,8 +368,7 @@ float *f; } field; - span *aux; - + // TODO: implement aux as queue uchar *uchar_aux; uint32 aux_pos; uint32 aux_len; diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 6ef18d1..19e6558 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -253,6 +253,16 @@ eas3_init_stream(uchar* memory, uint32 size, char instr) aux_pos += chunck_len; \ } +#define aux_dequeue(aux, aux_pos, aux_len, chunck, chunck_len) \ +{ \ + if(aux_pos + chunck_len <= aux_len) { \ + memcpy(chunck, aux + aux_pos, chunck_len); \ + aux_pos += chunck_len; \ + } else { \ + fprintf(stderr, MEMERROR); \ + } \ +} + /*----------------------------------------------------------------------------------------------------------*\ ! FUNCTION NAME: void *test(void) ! ! -------------- ! @@ -442,16 +452,16 @@ eas3_free_data(eas3_data* data) { if(data) { - if(data->aux) - { - free(data->aux->memory); - data->aux->access = NULL; - data->aux->position = 0; - data->aux->size = 0; + //if(data->aux) + //{ + //free(data->aux->memory); + //data->aux->access = NULL; + //data->aux->position = 0; + //data->aux->size = 0; // TODO: remove - data->aux->L = 0; - } - free(data->aux); + //data->aux->L = 0; + //} + //free(data->aux); free(data); } } @@ -617,18 +627,6 @@ read_eas3_header(FILE *const fp, eas3_data *const data) return 1; } - /*--------------------------------------------------------*\ - ! Allocate the auxiliary information packed stream. ! - \*--------------------------------------------------------*/ - data->aux = calloc(1, sizeof(span)); - if(!data->aux) - { - // memory allocation error - fprintf(stderr, MEMERROR); - free(buffer_char); - return 1; - } - /*--------------------------------------------------------*\ ! Initialize the stream for the auxiliary information mem- ! ! ory block. The initial size of the auxiliary memory ! @@ -949,13 +947,25 @@ write_eas3_header(FILE *const fp, eas3_data *const data) /*--------------------------------------------------------*\ ! Initialize the auxiliary information stream. ! \*--------------------------------------------------------*/ - aux = eas3_init_stream(data->aux->memory, data->aux->size, 'd'); + aux = eas3_init_stream(data->uchar_aux, data->aux_len, 'd'); + + // Rewind aux + data->aux_pos = 0; /*--------------------------------------------------------*\ ! Get the standard parameters from the auxiliary informa- ! ! memory block and write them to the file stream. ! \*--------------------------------------------------------*/ - params = (eas3_std_params*)eas3_get_chunck(aux, 176); + params = calloc(1, sizeof(eas3_std_params)); + if(!params) + { + // memory allocation error + fprintf(stderr, MEMERROR); + free(params); + return 1; + } + aux_dequeue(data->uchar_aux, data->aux_pos, data->aux_len, + params, sizeof(eas3_std_params)); if(fwrite(params, sizeof(uint64), 22, fp) != 22) { @@ -983,7 +993,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data) ! the timestep array from the auxiliary information block ! ! and write it to the file stream. ! \*--------------------------------------------------------*/ - buffer_char = eas3_get_chunck(aux, data->params.nts * sizeof(uint64)); + buffer_char = calloc(data->params.nts * sizeof(uint64), sizeof(uchar)); if(!buffer_char) { // memory allocation error @@ -991,6 +1001,8 @@ write_eas3_header(FILE *const fp, eas3_data *const data) free(buffer_char); return 1; } + aux_dequeue(data->uchar_aux, data->aux_pos, data->aux_len, + buffer_char, data->params.nts * sizeof(uint64)); if(fwrite(buffer_char, sizeof(uint64), data->params.nts, fp) != data->params.nts) { @@ -1012,7 +1024,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data) ! the timestep attribute array from the auxiliary informa- ! ! tion block and write it to the file stream. ! \*--------------------------------------------------------*/ - buffer_char = eas3_get_chunck(aux, data->params.nts * ATTRLEN); + buffer_char = calloc(data->params.nts * ATTRLEN, sizeof(uchar)); if(!buffer_char) { // memory allocation error @@ -1020,6 +1032,8 @@ write_eas3_header(FILE *const fp, eas3_data *const data) free(buffer_char); return 1; } + aux_dequeue(data->uchar_aux, data->aux_pos, data->aux_len, + buffer_char, data->params.nts * ATTRLEN); if(fwrite(buffer_char, sizeof(uchar), data->params.nts * ATTRLEN, fp) != (data->params.nts * ATTRLEN)) { @@ -1076,7 +1090,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data) ! the remaining eas header bytes from the auxiliary infor- ! ! mation block and write it to the file stream. ! \*--------------------------------------------------------*/ - buffer_char = eas3_get_chunck(aux, Lwrite); + buffer_char = calloc(Lwrite, sizeof(uchar)); if(!buffer_char) { // memory allocation error @@ -1084,6 +1098,8 @@ write_eas3_header(FILE *const fp, eas3_data *const data) free(buffer_char); return 1; } + aux_dequeue(data->uchar_aux, data->aux_pos, data->aux_len, + buffer_char, Lwrite); if(fwrite(buffer_char, sizeof(uchar), Lwrite, fp) != Lwrite) { diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index d5ff025..8b29197 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -705,7 +705,9 @@ int main(int argc, char *argv[]) // TODO: implement I/O of bwc file // TODO: bwc_header_info - //write_eas3(data, "output2.eas"); + write_eas3(data, "output.eas"); + data = read_eas3("output.eas"); + write_eas3(data, "output2.eas"); eas3_free_data(data); free(output); -- 2.45.2 From 1175e8b71f48d024925f3c8a7a8f114277dbb607 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Fri, 18 Oct 2024 10:56:00 +0200 Subject: [PATCH 28/53] remove eas3_get_chunck --- src/interfaces/reader/eas3.c | 91 ------------------------------------ 1 file changed, 91 deletions(-) diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 19e6558..4cdbc34 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -263,97 +263,6 @@ eas3_init_stream(uchar* memory, uint32 size, char instr) } \ } -/*----------------------------------------------------------------------------------------------------------*\ -! 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* -eas3_get_chunck(span *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(eas3_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; - } -} - /*----------------------------------------------------------------------------------------------------------*\ ! ! ! DESCRIPTION: ! -- 2.45.2 From b8a1df1c116045fb372d4599c0f94945565daf6e Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Fri, 18 Oct 2024 10:59:09 +0200 Subject: [PATCH 29/53] rename aux_push_back to aux_enqueue --- src/interfaces/reader/eas3.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 4cdbc34..6457293 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -239,7 +239,7 @@ eas3_init_stream(uchar* memory, uint32 size, char instr) ! ! \*----------------------------------------------------------------------------------------------------------*/ -#define aux_push_back(aux, aux_pos, aux_len, chunck, chunck_len) \ +#define aux_enqueue(aux, aux_pos, aux_len, chunck, chunck_len) \ { \ if (aux_pos + chunck_len > aux_len) \ { \ @@ -583,8 +583,8 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Emit the standard parameters to the auxiliary informa- ! ! tion information memory block. ! \*--------------------------------------------------------*/ - aux_push_back(data->uchar_aux, data->aux_pos, data->aux_len, - (uchar*)params, 176); + aux_enqueue(data->uchar_aux, data->aux_pos, data->aux_len, + (uchar*)params, 176); /*--------------------------------------------------------*\ ! Convert the parameters required for the bwc compression ! @@ -648,8 +648,8 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Emit the time step array to the auxiliary information ! ! memory block. ! \*--------------------------------------------------------*/ - aux_push_back(data->uchar_aux, data->aux_pos, data->aux_len, buffer_char, - params->nts * sizeof(uint64)); + aux_enqueue(data->uchar_aux, data->aux_pos, data->aux_len, buffer_char, + params->nts * sizeof(uint64)); /*--------------------------------------------------------*\ ! Check if any attributes have been specified in the eas3 ! @@ -682,8 +682,8 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Emit the timestep attribute array to the auxiliary infor-! ! mation memory block. ! \*--------------------------------------------------------*/ - aux_push_back(data->uchar_aux, data->aux_pos, data->aux_len, buffer_char, - params->nts * ATTRLEN * sizeof(char)); + aux_enqueue(data->uchar_aux, data->aux_pos, data->aux_len, buffer_char, + params->nts * ATTRLEN * sizeof(char)); for(i = 0; i < params->npar; ++i) { @@ -754,8 +754,8 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Emit the remaining header information the the auxiliary ! ! information stream. ! \*--------------------------------------------------------*/ - aux_push_back(data->uchar_aux, data->aux_pos, data->aux_len, - buffer_char, Lread); + aux_enqueue(data->uchar_aux, data->aux_pos, data->aux_len, + buffer_char, Lread); /*--------------------------------------------------------*\ ! Free the buffer character array. ! -- 2.45.2 From a5d67f8470d7eebe5f414ee8ae6045c64c714853 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Fri, 18 Oct 2024 11:06:52 +0200 Subject: [PATCH 30/53] remove span, eas3_bytes_used, eas3_init_stream --- include/interfaces/reader/eas3.h | 37 -------- src/interfaces/reader/eas3.c | 157 +------------------------------ 2 files changed, 1 insertion(+), 193 deletions(-) diff --git a/include/interfaces/reader/eas3.h b/include/interfaces/reader/eas3.h index 9bb344d..5f8c256 100644 --- a/include/interfaces/reader/eas3.h +++ b/include/interfaces/reader/eas3.h @@ -181,43 +181,6 @@ #define AUX_SIZE 0x8000 - /************************************************************************************************************\ - || ___ _ _ ___ ____ ____ || - || | \_/ |__] |___ [__ || - || | | | |___ ___] || - || || - \************************************************************************************************************/ - /*----------------------------------------------------------------------------------------------*\ - ! ! - ! 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 - { - //TODO: remove - uchar error; // Error flag used during streaming. - - uint64 size; - uint64 position; - //TODO: remove - uint64 L; // Number of bytes written to/from stream. - //TODO: remove - uint64 Lmax; // Size of packed stream. - uint64 size_incr; // Size incrmnt used for stream assembly. - - //TODO: remove - uint8 T; // Byte buffer. - int8 t; // Byte buffer counter. - - uchar *access; // Pointer used to parse packed stream. - uchar *memory; // Memory handle for packed stream chunck. - } span; - /*----------------------------------------------------------------------------------------------------------*\ ! STRUCT NAME: eas3_header ! ! ----------- ! diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 6457293..19abf27 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -84,151 +84,6 @@ || | | \ | \/ | | | |___ | |__| | \| |___ | | |__| | \| ___] || || || \************************************************************************************************************/ -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uint32 eas3_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 -eas3_bytes_used(span const *const stream) -{ - if(stream->T == 0xFF) - { - return stream->L + 1; - } - else - { - return stream->L; - } -} - -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: span* 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 ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ -span* -eas3_init_stream(uchar* memory, uint32 size, char instr) -{ - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - span *stream; - - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(instr == 'c' || instr == 'd'); - - /*--------------------------------------------------------*\ - ! Allocate the bwc stream structure. ! - \*--------------------------------------------------------*/ - stream = calloc(1, sizeof(span)); - 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; -} /*----------------------------------------------------------------------------------------------------------*\ ! ! @@ -238,7 +93,6 @@ eas3_init_stream(uchar* memory, uint32 size, char instr) ! information. ! ! ! \*----------------------------------------------------------------------------------------------------------*/ - #define aux_enqueue(aux, aux_pos, aux_len, chunck, chunck_len) \ { \ if (aux_pos + chunck_len > aux_len) \ @@ -483,7 +337,6 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! DEFINE STRUCTS: ! \*-----------------------*/ bwc_gl_inf *info; - span *aux; eas3_std_params *params; /*-----------------------*\ @@ -834,7 +687,6 @@ write_eas3_header(FILE *const fp, eas3_data *const data) ! DEFINE STRUCTS: ! \*-----------------------*/ bwc_gl_inf *info; - span *aux; eas3_std_params *params; eas3_param_names *param_names; @@ -853,11 +705,6 @@ write_eas3_header(FILE *const fp, eas3_data *const data) return 1; } - /*--------------------------------------------------------*\ - ! Initialize the auxiliary information stream. ! - \*--------------------------------------------------------*/ - aux = eas3_init_stream(data->uchar_aux, data->aux_len, 'd'); - // Rewind aux data->aux_pos = 0; @@ -1020,10 +867,8 @@ write_eas3_header(FILE *const fp, eas3_data *const data) free(buffer_char); /*--------------------------------------------------------*\ - ! Free the auxiliary information memory block stream and ! - ! params structure. ! + ! Free the params structure. ! \*--------------------------------------------------------*/ - free(aux); free(params); return 0; -- 2.45.2 From 26c00bd4e395ee18d4cee54a7f65f24e1c4248b2 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Fri, 18 Oct 2024 11:23:12 +0200 Subject: [PATCH 31/53] refactor aux buffer and macros --- include/interfaces/reader/eas3.h | 10 ++-- src/interfaces/reader/eas3.c | 84 +++++++++++++++----------------- 2 files changed, 45 insertions(+), 49 deletions(-) diff --git a/include/interfaces/reader/eas3.h b/include/interfaces/reader/eas3.h index 5f8c256..00686f9 100644 --- a/include/interfaces/reader/eas3.h +++ b/include/interfaces/reader/eas3.h @@ -332,9 +332,13 @@ } field; // TODO: implement aux as queue - uchar *uchar_aux; - uint32 aux_pos; - uint32 aux_len; + struct aux + { + uchar *ptr; + uint32 pos; + uint32 len; + } aux; + } eas3_data; /************************************************************************************************************\ diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 19abf27..baacce0 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -93,28 +93,28 @@ ! information. ! ! ! \*----------------------------------------------------------------------------------------------------------*/ -#define aux_enqueue(aux, aux_pos, aux_len, chunck, chunck_len) \ -{ \ - if (aux_pos + chunck_len > aux_len) \ - { \ - while(aux_pos + chunck_len > aux_len) \ - { \ - aux_len += aux_len / 2; \ - } \ - aux = realloc(aux, aux_len); \ - } \ - memcpy(aux + aux_pos, chunck, chunck_len); \ - aux_pos += chunck_len; \ +#define aux_enqueue(aux, chunck, chunck_len) \ +{ \ + if (aux.pos + chunck_len > aux.len) \ + { \ + while(aux.pos + chunck_len > aux.len) \ + { \ + aux.len += aux.len / 2; \ + } \ + aux.ptr = realloc(aux.ptr, aux.len); \ + } \ + memcpy(aux.ptr + aux.pos, chunck, chunck_len); \ + aux.pos += chunck_len; \ } -#define aux_dequeue(aux, aux_pos, aux_len, chunck, chunck_len) \ -{ \ - if(aux_pos + chunck_len <= aux_len) { \ - memcpy(chunck, aux + aux_pos, chunck_len); \ - aux_pos += chunck_len; \ - } else { \ - fprintf(stderr, MEMERROR); \ - } \ +#define aux_dequeue(aux, chunck, chunck_len) \ +{ \ + if(aux.pos + chunck_len <= aux.len) { \ + memcpy(chunck, aux.ptr + aux.pos, chunck_len); \ + aux.pos += chunck_len; \ + } else { \ + fprintf(stderr, MEMERROR); \ + } \ } /*----------------------------------------------------------------------------------------------------------*\ @@ -395,10 +395,10 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! block has been chosen arbitrarily and should be large ! ! enough to prevent excessive reallocation. ! \*--------------------------------------------------------*/ - data->uchar_aux = calloc(AUX_SIZE, sizeof(uchar)); - data->aux_pos = 0; - data->aux_len = AUX_SIZE; - if(!data->uchar_aux) + data->aux.ptr = calloc(AUX_SIZE, sizeof(uchar)); + data->aux.pos = 0; + data->aux.len = AUX_SIZE; + if(!data->aux.ptr) { // memory allocation error fprintf(stderr, MEMERROR); @@ -436,8 +436,7 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Emit the standard parameters to the auxiliary informa- ! ! tion information memory block. ! \*--------------------------------------------------------*/ - aux_enqueue(data->uchar_aux, data->aux_pos, data->aux_len, - (uchar*)params, 176); + aux_enqueue(data->aux, (uchar*)params, 176); /*--------------------------------------------------------*\ ! Convert the parameters required for the bwc compression ! @@ -501,8 +500,7 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Emit the time step array to the auxiliary information ! ! memory block. ! \*--------------------------------------------------------*/ - aux_enqueue(data->uchar_aux, data->aux_pos, data->aux_len, buffer_char, - params->nts * sizeof(uint64)); + aux_enqueue(data->aux, buffer_char, params->nts * sizeof(uint64)); /*--------------------------------------------------------*\ ! Check if any attributes have been specified in the eas3 ! @@ -535,8 +533,7 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Emit the timestep attribute array to the auxiliary infor-! ! mation memory block. ! \*--------------------------------------------------------*/ - aux_enqueue(data->uchar_aux, data->aux_pos, data->aux_len, buffer_char, - params->nts * ATTRLEN * sizeof(char)); + aux_enqueue(data->aux, buffer_char, params->nts * ATTRLEN * sizeof(char)); for(i = 0; i < params->npar; ++i) { @@ -607,8 +604,7 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! Emit the remaining header information the the auxiliary ! ! information stream. ! \*--------------------------------------------------------*/ - aux_enqueue(data->uchar_aux, data->aux_pos, data->aux_len, - buffer_char, Lread); + aux_enqueue(data->aux, buffer_char, Lread); /*--------------------------------------------------------*\ ! Free the buffer character array. ! @@ -620,15 +616,15 @@ read_eas3_header(FILE *const fp, eas3_data *const data) ! ful, the address to the aux memory block stored is ! ! stored in the file structure alongside its size. ! \*--------------------------------------------------------*/ - if(data->aux_pos != data->aux_len) + if(data->aux.pos != data->aux.len) { - data->aux_len = data->aux_pos; - data->uchar_aux = realloc(data->uchar_aux, data->aux_len); - if(!data->uchar_aux) + data->aux.len = data->aux.pos; + data->aux.ptr = realloc(data->aux.ptr, data->aux.len); + if(!data->aux.ptr) { // memory allocation error fprintf(stderr, MEMERROR); - data->aux_len = 0; + data->aux.len = 0; return 1; } } @@ -706,7 +702,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data) } // Rewind aux - data->aux_pos = 0; + data->aux.pos = 0; /*--------------------------------------------------------*\ ! Get the standard parameters from the auxiliary informa- ! @@ -720,8 +716,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data) free(params); return 1; } - aux_dequeue(data->uchar_aux, data->aux_pos, data->aux_len, - params, sizeof(eas3_std_params)); + aux_dequeue(data->aux, params, sizeof(eas3_std_params)); if(fwrite(params, sizeof(uint64), 22, fp) != 22) { @@ -757,8 +752,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data) free(buffer_char); return 1; } - aux_dequeue(data->uchar_aux, data->aux_pos, data->aux_len, - buffer_char, data->params.nts * sizeof(uint64)); + aux_dequeue(data->aux, buffer_char, data->params.nts * sizeof(uint64)); if(fwrite(buffer_char, sizeof(uint64), data->params.nts, fp) != data->params.nts) { @@ -788,8 +782,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data) free(buffer_char); return 1; } - aux_dequeue(data->uchar_aux, data->aux_pos, data->aux_len, - buffer_char, data->params.nts * ATTRLEN); + aux_dequeue(data->aux, buffer_char, data->params.nts * ATTRLEN); if(fwrite(buffer_char, sizeof(uchar), data->params.nts * ATTRLEN, fp) != (data->params.nts * ATTRLEN)) { @@ -854,8 +847,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data) free(buffer_char); return 1; } - aux_dequeue(data->uchar_aux, data->aux_pos, data->aux_len, - buffer_char, Lwrite); + aux_dequeue(data->aux, buffer_char, Lwrite); if(fwrite(buffer_char, sizeof(uchar), Lwrite, fp) != Lwrite) { -- 2.45.2 From 6d5dc06446eeabea8cbc6edf66682d299f5148cb Mon Sep 17 00:00:00 2001 From: Patrick Vogler Date: Mon, 28 Oct 2024 11:04:18 +0100 Subject: [PATCH 32/53] Modified eas3 interface to decouple it from the command line tool. --- include/interfaces/reader/eas3.h | 12 +++++++++ src/interfaces/reader/eas3.c | 44 +++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/include/interfaces/reader/eas3.h b/include/interfaces/reader/eas3.h index 00686f9..c7d647b 100644 --- a/include/interfaces/reader/eas3.h +++ b/include/interfaces/reader/eas3.h @@ -347,6 +347,18 @@ || | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] || || || \************************************************************************************************************/ + /*----------------------------------------------------------------------------------------------------------*\ + ! ! + ! DESCRIPTION: ! + ! ------------ ! + ! This function deallocates the data structure used to store an numerical dataset ! + ! and can be called if an error occurs or once the data is no longer needed is to be closed. ! + ! The deallocation will be carried out down to the structure levels that have been allocated. ! + ! ! + \*----------------------------------------------------------------------------------------------------------*/ + void + eas3_free_data(eas3_data* data); + /*----------------------------------------------------------------------------------------------------------*\ ! FUNCTION NAME: bwc_data* read_eas3(const char* const filename) ! ! -------------- ! diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index baacce0..7581118 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -76,7 +76,25 @@ #include #include "eas3.h" -#include "bwccmdl.h" + + +/************************************************************************************************************\ +|| _ _ ____ ____ ____ ____ ____ || +|| |\/| |__| | |__/ | | [__ || +|| | | | | |___ | \ |__| ___] || +|| || +\************************************************************************************************************/ +#define MEMERROR "o##########################################################o\n"\ + "| ERROR: Out of memory |\n"\ + "o##########################################################o\n" + +#define RDERROR "o##########################################################o\n"\ + "| ERROR: Invalid Number of Bytes Read from File. |\n"\ + "o##########################################################o\n" + +#define WRTERROR "o##########################################################o\n"\ + "| ERROR: Invalid Number of Bytes Written to File. |\n"\ + "o##########################################################o\n" /************************************************************************************************************\ || ___ ____ _ _ _ ____ ___ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ || @@ -213,18 +231,20 @@ endian_conversion(void *value, void eas3_free_data(eas3_data* data) { - if(data) + if(data != NULL) { - //if(data->aux) - //{ - //free(data->aux->memory); - //data->aux->access = NULL; - //data->aux->position = 0; - //data->aux->size = 0; - // TODO: remove - //data->aux->L = 0; - //} - //free(data->aux); + if (data->param_names != NULL) + free(data->param_names); + + if (data->field.d != NULL) + free(data->field.d); + + if (data->field.f != NULL) + free(data->field.f); + + if(data->aux.ptr != NULL) + free(data->aux.ptr); + free(data); } } -- 2.45.2 From 90645bcf1b10a1554a7b812782f6c2cf9d87536c Mon Sep 17 00:00:00 2001 From: Patrick Vogler Date: Mon, 28 Oct 2024 11:05:34 +0100 Subject: [PATCH 33/53] Implemented the arg_parse function for bwccmdl and added preliminary mode setting functionality for main. --- include/tools/bwccmdl.h | 350 ------------ src/tools/bwccmdl.c | 1127 ++++++++++++++++++++++++++++----------- 2 files changed, 821 insertions(+), 656 deletions(-) delete mode 100644 include/tools/bwccmdl.h diff --git a/include/tools/bwccmdl.h b/include/tools/bwccmdl.h deleted file mode 100644 index be53e0b..0000000 --- a/include/tools/bwccmdl.h +++ /dev/null @@ -1,350 +0,0 @@ -/*====================================================================================================================*\ -|| || -|| /$$$$$$$ /$$ /$$ /$$ /$$ || -|| | $$__ $$|__/ | $$ /$ | $$| $$ || -|| | $$ \ $$ /$$ /$$$$$$ | $$ /$$$| $$| $$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ || -|| | $$$$$$$ | $$ /$$__ $$ | $$/$$ $$ $$| $$__ $$ /$$__ $$ /$$__ $$ /$$__ $$ || -|| | $$__ $$| $$| $$ \ $$ | $$$$_ $$$$| $$ \ $$| $$ \ $$| $$ \ $$| $$ \ $$ || -|| | $$ \ $$| $$| $$ | $$ | $$$/ \ $$$| $$ | $$| $$ | $$| $$ | $$| $$ | $$ || -|| | $$$$$$$/| $$| $$$$$$$ | $$/ \ $$| $$ | $$| $$$$$$/| $$$$$$/| $$$$$$$/ || -|| |_______/ |__/ \____ $$ |__/ \__/|__/ |__/ \______/ \______/ | $$____/ || -|| /$$ \ $$ | $$ || -|| | $$$$$$/ | $$ || -|| \______/ |__/ || -|| || -|| DESCRIPTION: || -|| ------------ || -|| This is a simple command line tool that uses the Big Whoop library to (de)com- || -|| press a 2- to 4-dimensional IEEE 754 floating point array. For further infor- || -|| mation use the --help (-h) argument in the command-line or consult the appro- || -|| priate README file. || -|| || -|| STRUCTS: || -|| -------- || -|| DESCRIPTION NEEDED. || -|| || -|| DEVELOPMENT HISTORY: || -|| -------------------- || -|| || -|| Date Author Change Id Release Description || -|| ---- ------ --------- ------- ----------- || -|| 13.10.2017 Patrick Vogler B87D120 V 0.1.0 source file created || -|| 26.11.2020 Patrick Vogler B87E7E4 V 0.1.0 Command line tool refac- || -|| tored. || -|| || -|| || -|| ------------------------------------------------------------------------------------------------------ || -|| || -|| Copyright (c) 2023, High Performance Computing Center - University of Stuttgart || -|| || -|| Redistribution and use in source and binary forms, with or without modification, are permitted || -|| provided that the following conditions are met: || -|| || -|| (1) Redistributions of source code must retain the above copyright notice, this list of || -|| conditions and the following disclaimer. || -|| || -|| (2) Redistributions in binary form must reproduce the above copyright notice, this list || -|| of conditions and the following disclaimer in the documentation and/or other materials || -|| provided with the distribution. || -|| || -|| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED || -|| WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A || -|| PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR || -|| ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT || -|| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS || -|| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR || -|| TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF || -|| ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. || -|| || -\*====================================================================================================================*/ -#ifndef BWC_CMDL_H -#define BWC_CMDL_H - - /********************************************************************************************************************\ - || _ _ _ ____ _ _ _ ___ ____ || - || | |\ | | | | | | \ |___ || - || | | \| |___ |___ |__| |__/ |___ || - || || - \********************************************************************************************************************/ - #include - - /********************************************************************************************************************\ - || _ _ ____ ____ ____ ____ ____ || - || |\/| |__| | |__/ | | [__ || - || | | | | |___ | \ |__| ___] || - || || - \********************************************************************************************************************/ - /*------------------------------------------------------------------------------------------------------------------*\ - ! DESCRIPTION: ! - ! ------------ ! - ! ! - ! These macros define minimum and maximum operators as well as an operator used ! - ! to evaluate the size of an array. ! - ! ! - ! MACROS: ! - ! ------- ! - ! Name Description ! - ! ---- ----------- ! - ! MAX(x, y) - Returns the maximum value of ! - ! two values. ! - ! ! - ! MIN(x, y) - Returns the minimum value of ! - ! two values. ! - ! ! - ! GET_LEN(x) - Returns the size of an array. ! - ! ! - ! DEVELOPMENT HISTORY: ! - ! -------------------- ! - ! ! - ! Date Author Change Id Release Description ! - ! ---- ------ --------- ------- ----------- ! - ! 21.03.2018 Patrick Vogler B87D120 V 0.1.0 macros created ! - ! 16.09.2019 Patrick Vogler B87E7E4 V 0.1.0 Added GET_LEN(X) macro. ! - ! ! - \*------------------------------------------------------------------------------------------------------------------*/ - #define MAX(x, y) (((x) < (y))?(y):(x)) - #define MIN(x, y) (((x) > (y))?(y):(x)) - - /*------------------------------------------------------------------------------------------------------------------*\ - ! DESCRIPTION: ! - ! ------------ ! - ! ! - ! These Constants define codestream markers used to create the embedded code- ! - ! stream. ! - ! ! - ! MACROS: ! - ! ------- ! - ! Name Description ! - ! ---- ----------- ! - ! SOC - Start of code-stream ! - ! SGI - Global data-set information ! - ! SGC - Global control parameters ! - ! SGR - Global register containing tile ! - ! bitstream size information ! - ! SAX - Auxiliary data-set information ! - ! TLM - Packet lengths: main header ! - ! PLM - Packet lengths: tile-part ! - ! PPM - Quantization default ! - ! COM - Comment ! - ! EOH - End of header ! - ! PLT - Packed packet headers: main header ! - ! PPT - Packed packet headers: tile-part ! - ! SOT - Start of tile ! - ! SOP - Start of packet ! - ! EPH - End of packet header ! - ! SOD - Start of data ! - ! EOC - End of code-stream ! - ! ! - ! DEVELOPMENT HISTORY: ! - ! -------------------- ! - ! ! - ! Date Author Change Id Release Description ! - ! ---- ------ --------- ------- ----------- ! - ! 01.12.2017 Patrick Vogler B87D120 V 0.1.0 macros created ! - ! ! - \*------------------------------------------------------------------------------------------------------------------*/ - #define SOC 0xFF50 - #define SGI 0xFF51 - #define SGC 0xFF52 - #define SAX 0xFF53 - #define TLM 0xFF54 - #define PLM 0xFF55 - #define PPM 0xFF56 - #define COM 0xFF57 - #define EOH 0xFF58 - #define PLT 0xFF60 - #define PPT 0xFF61 - #define SOT 0xFF90 - #define SOP 0xFF91 - #define EPH 0xFF92 - #define SOD 0xFF93 - #define EOC 0xFFFF - - /*------------------------------------------------------------------------------------------------------------------*\ - ! DESCRIPTION: ! - ! ------------ ! - ! ! - ! These macros define flags used for codestream parsing. ! - ! ! - ! MACROS: ! - ! ------- ! - ! Name Description ! - ! ---- ----------- ! - ! CODESTREAM_OK - No errors detected in Codestream ! - ! ! - ! CODESTREAM_READ - Codestream has been fully read. ! - ! ! - ! DEVELOPMENT HISTORY: ! - ! -------------------- ! - ! ! - ! Date Author Change Id Release Description ! - ! ---- ------ --------- ------- ----------- ! - ! 01.08.2019 Patrick Vogler B87D120 V 0.1.0 macros created ! - ! ! - \*------------------------------------------------------------------------------------------------------------------*/ - #define CODESTREAM_OK 0x00 - #define CODESTREAM_READ 0x80 - - /*------------------------------------------------------------------------------------------------------------------*\ - ! DESCRIPTION: ! - ! ------------ ! - ! ! - ! These Constants define common error messages used throughout the bwc library. ! - ! ! - ! MACROS: ! - ! ------- ! - ! Name Description ! - ! ---- ----------- ! - ! CSTERROR - Codestream parser has encoun- ! - ! tered invalid marker. ! - ! ! - ! MEMERROR - Allocation has returned a NULL ! - ! pointer due to limited memory. ! - ! ! - ! RDERROR - Invalid number of bytes read ! - ! from file. ! - ! ! - ! WRTERROR - Invalid number of bytes writ- ! - ! ten to file. ! - ! ! - ! DEVELOPMENT HISTORY: ! - ! -------------------- ! - ! ! - ! Date Author Change Id Release Description ! - ! ---- ------ --------- ------- ----------- ! - ! 01.12.2017 Patrick Vogler B87D120 V 0.1.0 macros created ! - ! ! - \*------------------------------------------------------------------------------------------------------------------*/ - #define CSTERROR "o##########################################################o\n"\ - "| ERROR: Invalid Codestream |\n"\ - "o##########################################################o\n" - - #define MEMERROR "o##########################################################o\n"\ - "| ERROR: Out of Memory |\n"\ - "o##########################################################o\n" - - #define RDERROR "o##########################################################o\n"\ - "| ERROR: Invalid Number of Bytes Read from File. |\n"\ - "o##########################################################o\n" - - #define WRTERROR "o##########################################################o\n"\ - "| ERROR: Invalid Number of Bytes Written to File. |\n"\ - "o##########################################################o\n" - - #define GET_DIM(x) (sizeof(x)/sizeof(*(x))) - /********************************************************************************************************************\ - || ___ ____ ____ ____ _ _ _ ____ ___ ___ _ _ ___ ____ ____ || - || | \ |___ |__/ |__/ | | | |___ | \ | \_/ |__] |___ [__ || - || |__/ |___ | \ | \ | \/ |___ |__/ | | | |___ ___] || - || || - \********************************************************************************************************************/ - /*------------------------------------------------------------------------------------------------------------------*\ - ! DESCRIPTION: ! - ! ------------ ! - ! ! - ! This structure defines the attributes of a single argument supported by the bwc ! - ! command line tool. ! - ! ! - ! PARAMETERS: ! - ! ----------- ! - ! Name Type Description ! - ! ---- ---- ----------- ! - ! active char - Flag indicating if the argu- ! - ! ment is active. ! - ! ! - ! arg_long char - Long form of the argument name. ! - ! ! - ! arg_short char - Short form of the argument ! - ! name. ! - ! ! - ! arg_type char - Flag signaling if the argument ! - ! is optional. ! - ! ! - ! type char - Flag signaling the argument ! - ! type. ! - ! ! - ! usage char - A string of 24 characters de- ! - ! scribing the argument usage. ! - ! ! - ! definition char - A string of 1024 characters ! - ! containing the argument de- ! - ! scription. ! - ! ! - ! DEVELOPMENT HISTORY: ! - ! -------------------- ! - ! ! - ! Date Author Change Id Release Description ! - ! ---- ------ --------- ------- ----------- ! - ! 14.02.2019 Patrick Vogler B87D120 V 0.1.0 struct created ! - ! 26.11.2020 Patrick Vogler B87E7E4 V 0.1.0 clean up ! - ! ! - \*------------------------------------------------------------------------------------------------------------------*/ - typedef struct - { - char active; - char arg_long[25]; - char arg_short[3]; - char arg_type[4]; - char type[5]; - char usage[25]; - char definition[1024]; - } bwc_cmdl_args; - - /*------------------------------------------------------------------------------------------------------------------*\ - ! DESCRIPTION: ! - ! ------------ ! - ! This structure describes a linked list which stores all the arguments and their ! - ! attributes supplied to the command line tool by the user. ! - ! ! - ! PARAMETERS: ! - ! ----------- ! - ! Name Type Description ! - ! ---- ---- ----------- ! - ! hash unsigned int(64 bit) - Uniquely identifiable hash that ! - ! corresponds to the arg/opt name. ! - ! ! - ! count unsigned int(8 bit) - Counter that signifies the num- ! - ! ber of modifier values stored ! - ! in the linked list node. ! - ! ! - ! dim unsigned int(8 bit) - Dimension(s) for which the mod- ! - ! ifiers have been defined ! - ! ! - ! active char - Flag indicating if the arg/opt ! - ! is active. ! - ! ! - ! num_opt double* - Array of numerical modifier ! - ! values. ! - ! ! - ! lit_opt char** - Character array of literal mod- ! - ! ifier values. ! - ! ! - ! DEPENDENCIES: ! - ! ------------- ! - ! Name TYPE ! - ! ---- ---- ! - ! next opt* ! - ! ! - ! root opt* ! - ! ! - ! DEVELOPMENT HISTORY: ! - ! -------------------- ! - ! ! - ! Date Author Change Id Release Description ! - ! ---- ------ --------- ------- ----------- ! - ! 26.04.2019 Patrick Vogler B87D120 V 0.1.0 struct created ! - ! 26.11.2020 Patrick Vogler B87E7E4 V 0.1.0 clean up ! - ! ! - \*------------------------------------------------------------------------------------------------------------------*/ - typedef struct arg - { - uint64_t hash; - uint8_t count; - uint8_t dim; - char active; - double *num_opt; - char **lit_opt; - struct arg *next; - struct arg *root; - } bwc_cmdl_arg_node; -#endif \ No newline at end of file diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index 8b29197..cbc5815 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -14,7 +14,7 @@ || || \* -------------------------------------------------------------------------------------------- */ /** - * @file test.c + * @file bwccmdl.c * * This file defines a simple command line tool that uses the Big Whoop library to * (de) compress a 2- to 4-dimensional IEEE 754 floating point array. For further @@ -48,13 +48,13 @@ #include #include #include +#include #include #include #include #include "eas3.h" #include "bwc.h" -#include "bwccmdl.h" /*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*\ || _ _ ____ ____ ____ ____ ____ || @@ -63,6 +63,44 @@ || || \*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ /// @cond DO_NOT_DOCUMENT +/*================================================================================================*/ +/** + * @details These macros define common error messages used throughout the BigWhoop cli. + */ +/*================================================================================================*/ +#define MEMERROR "o##########################################################o\n"\ + "| ERROR: Out of memory |\n"\ + "o##########################################################o\n" + +#define RDERROR "o##########################################################o\n"\ + "| ERROR: Invalid Number of Bytes Read from File. |\n"\ + "o##########################################################o\n" + +#define WRTERROR "o##########################################################o\n"\ + "| ERROR: Invalid Number of Bytes Written to File. |\n"\ + "o##########################################################o\n" + +/*================================================================================================*/ +/** + * @details These macros are used to set and probe the cli_arguments optSet variable + */ +/*================================================================================================*/ +#define BITRT 0x8000 +#define CBLKS 0x4000 +#define CMPRT 0x2000 +#define DCLVL 0x1000 +#define DWTKL 0x0800 +#define FLOUT 0x0400 +#define FLREF 0x0200 +#define OMPTH 0x0100 +#define PRORD 0x0080 +#define PRECS 0x0040 +#define QFRMT 0x0020 +#define QTSIZ 0x0010 +#define QTSTL 0x0008 +#define TILES 0x0004 +#define USQLY 0x0002 + /*================================================================================================*/ /** * @details This macro defines a simple operation to remove a supplied deliminator from a string. @@ -81,6 +119,24 @@ || |___ |__| | \| ___] | | | | \| | ___] || || || \*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ +/*================================================================================================*/ +/** + * @details String containing the header used for the cli output. + */ +/*================================================================================================*/ +static char bwc_header[] = "==============================================================\n"\ + " \n"\ + " .:-------------: .:-------------: \n"\ + " .+++++++++++++++= :+++++++++++++++- \n"\ + " :+++. -++= -++= \n"\ + " :+++. -++= -++= \n"\ + " -++++++++++++++= -++= -++= \n"\ + " .=++---------=++= -++= -++= \n"\ + " :+++ :++= -++= -++= \n"\ + " .+++=--------=+++---=+++---=+++------------: \n"\ + " -=++++++++++++++++++++++++++++++++++++++++- \n"\ + " \n"; + /*================================================================================================*/ /** * @details Character strings containing the cli version and bug report e-mail address. @@ -101,10 +157,10 @@ static char doc[] = "\n"\ "\n"\ "Available use cases:\n"\ "\n"\ - " Compression: bwc -c [INPUT] [OPTIONS]\n"\ - " Decompression: bwc -d [INPUT] [OPTIONS]\n"\ - " Analysis: bwc -a [INPUT] -r [REFERENCE]\n"\ - " Information: bwc -h [INPUT]\n"\ + " Compression: bwc -C [INPUT] [OPTIONS]\n"\ + " Decompression: bwc -D [INPUT] [OPTIONS]\n"\ + " Analysis: bwc -A [INPUT] -R [REFERENCE]\n"\ + " Information: bwc -H [INPUT]\n"\ "\n"\ "Valid Option Values:\n"\ "\n" @@ -117,13 +173,13 @@ static char doc[] = "\n"\ "\n" " Numerical values that can be specified globally or for\n" " all spacial and temporal directions individually:\n" - " ndir = * or ndir = x/y/z/ts.\n"; + " ndir = * or ndir = x,y,z,ts.\n"; /*"\n" " Single string.\n" " One or more strings seperated by commas: sarr = *,*,...\n" " Strings that can be specified globally or for all\n" " spacial and temporal directions individually:\n" - " sdir = * or sdir = x/y/z/ts.\n"*/ + " sdir = * or sdir = x,y,z,ts.\n"*/ //=================================================================================================| /** @@ -138,21 +194,21 @@ static struct argp_option options[] = { //====================|=====|============|====================|================================|===| {0, 0, 0, 0, " [FILE OPTIONS]\n", 1}, //--------------------|-----|------------|--------------------|--------------------------------|---| -{"analysis", 'a', "", 0, "Analyze Peak Signal to Noise" +{"analysis", 'A', "", 0, "Analyze Peak Signal to Noise" " Ratio (PSNR) and Mean Square" " Error (MSE) between input and" " reference file.\n", 1}, //--------------------|-----|------------|--------------------|--------------------------------|---| -{"comp", 'c', "", 0, "Compress a numerical dataset.", 1}, +{"comp", 'C', "", 0, "Compress a numerical dataset.", 1}, //--------------------|-----|------------|--------------------|--------------------------------|---| -{"decomp", 'd', "", 0, "Decompress a BigWhoop file.", 1}, +{"decomp", 'D', "", 0, "Decompress a BigWhoop file.", 1}, //--------------------|-----|------------|--------------------|--------------------------------|---| -{"header", 'h', "", 0, "Display the header information" +{"header", 'H', "", 0, "Display the header information" " of a BigWhoop file.\n", 1}, //--------------------|-----|------------|--------------------|--------------------------------|---| -{"output", 'o', "", 0, "Defines output file.", 1}, +{"output", 'O', "", 0, "Defines output file.", 1}, //--------------------|-----|------------|--------------------|--------------------------------|---| -{"reference", 'r', "", 0, "Reference file used for PSNR" +{"reference", 'R', "", 0, "Reference file used for PSNR" " and MSE calculation.", 1}, //====================|=====|============|====================|================================|===| //--------------------|-----|------------|--------------------|--------------------------------|---| @@ -165,9 +221,6 @@ static struct argp_option options[] = { "for error resilient decoding of" " compressed dataset.\n", 2}, //--------------------|-----|------------|--------------------|--------------------------------|---| -{"stream", 's', 0, OPTION_HIDDEN, "Stream data to and from " - "/.", 2}, -//--------------------|-----|------------|--------------------|--------------------------------|---| {"verbose", 'v', 0, 0, "Display compression statistics " "and applied compression " "parameters.", 2}, @@ -184,13 +237,13 @@ static struct argp_option options[] = { "point. Accepts real numbers in " "the range of 0 < * < 64.\n", 3}, //--------------------|-----|------------|--------------------|--------------------------------|---| -{"codeblock", 'B', "", 0, "Codeblock size in log2 format. " +{"codeblock", 'c', "", 0, "Codeblock size in log2 format. " "Accepts natural numbers in the " "range of 1 <= * <= 10 with the " "sum having to lie in the range " "of 4 < sum* < 20.\n", 3}, //--------------------|-----|------------|--------------------|--------------------------------|---| -{"decomplvl", 'D', "", 0, "Number of wavelet decomposi" +{"decomplvl", 'd', "", 0, "Number of wavelet decomposi" "tions applied to the data " "arrays. Accepts natural numbers" " in the range of 1 <= * <= 63." @@ -217,13 +270,13 @@ static struct argp_option options[] = { "Accepts real numbers in the " "range of 0 < * < 2.\n", 3}, //--------------------|-----|------------|--------------------|--------------------------------|---| -{"qformat", 'Q', "", 0, "Fractional bits of the Q number" +{"qformat", 'm', "", 0, "Fractional bits of the Q number" " format used in the floating-to" "-fixed point transfomration. " "Accepts natural numbers in the " "range of 1 <= * <= 62.\n", 3}, //--------------------|-----|------------|--------------------|--------------------------------|---| -{"compratio", 'R', "", 0, "Target ratio between the uncom" +{"compratio", 'r', "", 0, "Target ratio between the uncom" "presssed and compressed file " "size. Accepts positive real " "numbers.\n", 3}, @@ -254,11 +307,11 @@ static struct argp_option options[] = { /*=====================================================|==========================================*/ typedef enum { - cli_err, //!< Command-line interface error + cli_ini, //!< Undefined command line mode cli_cmp, //!< Compression run cli_dcp, //!< Decompression run cli_anl, //!< Analyse distortion of reconstr. file - cli_hdr, //!< Display header information + cli_inf, //!< Display BWC Header Information } cli_mode; /*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*\ @@ -274,15 +327,33 @@ typedef enum /*===========================|=========================|==========================================*/ typedef struct { + char *args[2]; cli_mode mode; //!< Current state of the cli tool + uint16_t optSet; //!< Flag signaling witch opt has been set - FILE *fpIn, *fpOut; //!< Pointer to input/output file - char* *in, *out; //!< Name of the input/output files + char *in, *out, *ref; //!< Name of the in/out/ref file - float bitrate[10]; //!< Quality layers defined by bitrate. + bool erresilience; //!< Flag signalling error resilience + bool verbose; //!< Flag signalling verbose output - bwc_stream *stream; //!< Structure defining the BigWhoop I/O - bwc_codec *codec; //!< Structure defining the BigWhoop codec + uint64_t tileSize[4]; //!< Spatial/Temporal tile size + uint8_t precSize[4]; //!< Spatial/Temporal precinct size + uint8_t cblkSize[4]; //!< Spatial/Temporal codeblock size + + bwc_dwt_filter dwtKernel[4]; //!< Spatial/Temporal wavelet kernels + + double rate[10]; //!< Quality layers defining rate ctrl. + uint8_t decompLevel[4]; //!< N.o. Spatial/temporal dwt decompo. + + double qt_step_size; //!< Global qunatization step size + uint8_t Qm; //!< Q number format range (m) + + uint8_t useLayer; //!< Quality layer used for decompression + + uint64_t nThreads; //!< Number of OpenMP threads + + //bwc_quant_st quantization_style; //!< Quantization style + //bwc_prog_ord progression; //!< Packet progression order } cli_arguments; @@ -294,8 +365,48 @@ typedef struct \*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ /*================================================================================================*/ /** - * @details This function analyzes one option at a time and sets the corresponding value and - * passes arguments in the bwc_codec struct. + * @details This function takes the argument string, removes the supplied deliminators and + * verifies that the values are valid. If decimal is set to true the decimal point + * in a floating point value will be ignored. + * + * @param[in] arg Argument corresponding to the option key. + * @param[in] delim Character used to deliminate between values. + * @param[in] dec Bool signaling if string contains floating point values. + * + * @retval -1 Error + * @retval 0 OK + */ +/*================================================================================================*/ +static error_t +verify_opt(char *arg, char deliminator, bool decimal) +{ + /*-----------------------*\ + ! DEFINE CHAR VARIABLES: ! + \*-----------------------*/ + char *parse; + + remove_deliminator(arg, parse, deliminator); + + for(parse = arg; *parse; parse++) + { + if (decimal == true) + { + if (!isdigit(*parse) && *parse != ' ' && *parse != '.') + return EXIT_FAILURE; + } + else + { + if (!isdigit(*parse) && *parse != ' ') + return EXIT_FAILURE; + } + } + return EXIT_SUCCESS; +} + +/*================================================================================================*/ +/** + * @details This function analyzes one option at a time and sets the corresponding value in + * the cli arguments struct. * * @param[in] key Option's key corresponding to the field value in the arg_option struct. * @param[in] arg Argument corresponding to the option key. @@ -303,338 +414,646 @@ typedef struct * * @retval -1 Error * @retval 0 OK + */ +/*================================================================================================*/ static error_t parse_opt(int key, char *arg, struct argp_state *state) { - */ /*-----------------------*\ ! DEFINE INT VARIABLES: ! \*-----------------------*/ - //uint64_t buff_LL; - //uint64_t multiplier; - - //uint16_t buffI; -/* + int64_t buff; uint8_t i; - //uint8_t length, shift; - */ /*-----------------------*\ ! DEFINE REAL VARIABLES: ! \*-----------------------*/ - /* + double compRatio; + double qt_step_size; float bitrate; - */ + /*-----------------------*\ - ! DEFINE REAL VARIABLES: ! + ! DEFINE CHAR VARIABLES: ! \*-----------------------*/ - /* char *end; - */ + char *token, *ptr; /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - /* cli_arguments *arguments; bwc_codec *codec; bwc_stream *stream; - */ /*-----------------------*\ ! DEFINE ASSERTIONS: ! \*-----------------------*/ - /* assert(state); - */ - /*--------------------------------------------------------*\ - ! Save frequently used variables/structures to temporary ! - ! variables to make the code more readable. ! - \*--------------------------------------------------------*/ - /* + /* Save frequently used variables/structures to * + * temporary variables. */ arguments = state->input; - codec = arguments->codec; - stream = arguments->stream; - */ - /*--------------------------------------------------------*\ - ! Parse the cli arguments according to the supplied opt. ! - \*--------------------------------------------------------*/ - /* + /* Parse the cli arguments. */ switch(key) { - case 'c': + /* Ingest compression argument. */ + case 'C': { - arguments->mode = bwc_cmp; - printf("Compress\n"); - if(arg[0] == '-') + if (arguments->mode != cli_ini) { - argp_error(state, "No input specified\n"); + argp_error(state, "Arguments define multiple use cases.\n"); + } + else if ((arg == NULL) || (arg[0] == '-')) + { + argp_error(state, "file names that start with an '-'" + " are not supported.\n"); } else { - arguments->input = ; + arguments->mode = cli_cmp; + arguments->in = arg; } break; } - case 'd': + + /* Ingest decompression argument. */ + case 'D': { - arguments->mode = bwc_dcp; - printf("Decompress\n"); + if (arguments->mode != cli_ini) + { + argp_error(state, "Arguments define multiple use cases.\n"); + } + else if ((arg == NULL) || (arg[0] == '-')) + { + argp_error(state, "file names that start with an '-'" + " are not supported.\n"); + } + else + { + arguments->mode = cli_dcp; + arguments->in = arg; + } break; } - case 'a': + + /* Ingest analysis argument. */ + case 'A': { - //arguments->analysis = arg; + if (arguments->mode != cli_ini) + { + argp_error(state, "Arguments define multiple use cases.\n"); + } + else if ((arg == NULL) || (arg[0] == '-')) + { + argp_error(state, "file names that start with an '-'" + " are not supported.\n"); + } + else + { + arguments->mode = cli_anl; + arguments->in = arg; + } + break; } - case 'h': + + /* Ingest header info argument. */ + case 'H': { - //arguments->header = arg; + if (arguments->mode != cli_ini) + { + argp_error(state, "Arguments define multiple use cases.\n"); + } + else if ((arg == NULL) || (arg[0] == '-')) + { + argp_error(state, "file names that start with an '-'" + " are not supported.\n"); + } + else + { + arguments->mode = cli_inf; + arguments->in = arg; + } + break; } - case 'o': + + /* Ingest output argument. */ + case 'O': { - //arguments->output = arg; + if (arguments->optSet & FLOUT) + { + argp_error(state, "The output file can only be defined once.\n"); + } + + if ((arg == NULL) || (arg[0] == '-')) + { + argp_error(state, "file names that start with an '-'" + " are not supported.\n"); + } + else + { + arguments->out = arg; + arguments->optSet |= FLOUT; + } break; } - case 'r': + + /* Ingest reference argument. */ + case 'R': { - //arguments->reference = arg; - break; - } - case 's': - { - //arguments->stream = 1; + if (arguments->optSet & FLREF) + { + argp_error(state, "The reference file can only be defined once.\n"); + } + + if ((arg == NULL) || (arg[0] == '-')) + { + argp_error(state, "file names that start with an '-'" + " are not supported.\n"); + } + else + { + arguments->ref = arg; + arguments->optSet |= FLREF; + } break; } + + /* Ingest verbose argument. */ case 'v': { - //arguments->stream = 1; + arguments->verbose = true; break; } + + /* Ingest bit rates. */ case 'b': { - remove_deliminator(arg, end, ','); + if (arguments->optSet & BITRT) + { + argp_error(state, "The bitrate can only be defined once.\n"); + } + else if (arguments->optSet & CMPRT) + { + argp_error(state, "The size reduction requires to be specified " + "either by a bit rate or a compression ratio, " + "never both.\n"); + } + + if (verify_opt(arg, ',', true) == EXIT_FAILURE) + { + argp_error(state, "Invalid delimitnator in the bitrate option\n"); + } for(bitrate = strtod(arg, &end), i = 0; arg != end && i < 10; bitrate = strtod(arg, &end), i++) { arg = end; - if(bitrate > 0 && bitrate < 64 && errno != ERANGE) + if (bitrate > 0 && bitrate <= 64 && errno != ERANGE) { - arguments->bitrate[i] = (float) bitrate; + arguments->rate[i] = (double) bitrate; } else { + errno = 0; argp_error(state, "The specified bitrate (%f) is " "out of the supported range.\n", bitrate); - - arguments->mode = cli_err; + } + } + + arguments->optSet |= BITRT; + break; + } + + /* Ingest codeblock size. */ + case 'c': + { + if (arguments->optSet & CBLKS) + { + argp_error(state, "The codeblock size can only be defined once.\n"); + } + + if (verify_opt(arg, ',', false) == EXIT_FAILURE) + { + argp_error(state, "Invalid delimitnator in the codeblock" + " size option.\n"); + } + + for(buff = strtoll(arg, &end, 10), i = 0; arg != end && i < 4; + buff = strtoll(arg, &end, 10), i++) + { + arg = end; + + if (buff >= 0 && buff <= 10 && errno != ERANGE) + { + arguments->cblkSize[i] = (uint8_t) buff; + } + else + { errno = 0; + argp_error(state, "The specified codeblock size (%ld) " + "is out of the supported range.\n", buff); break; } } - break; - } - case 'B': - { - // remove_deliminator(arg, end, '/'); - // for(buff_LL = strtoll(arg, &end, 10), i = 0; arg != end && i < 4; - // buff_LL = strtoll(arg, &end, 10), i++) - // { - // arg = end; - // if (errno == ERANGE) - // { - // printf("range error, got "); - // errno = 0; - // } - - // if(buff_LL > 1 && buff_LL < 10) - // { - // arguments->codeblock[i] = (uint8_t) buff_LL; - // } - // else - // { - // argp_error(state, "The specified codeblock size (%ld) " - // "is out of the supported range.\n", buff_LL); - // } - // } - - // if(i == 1) - // { - // arguments->codeblock[1] = - // arguments->codeblock[2] = - // arguments->codeblock[3] = arguments->codeblock[0]; - // } - // else if(i != 4) - // { - // argp_error(state, "The codeblock argument expects either a " - // "single global or 4 dirctional values\n"); - // } - - // if(((arguments->codeblock[0] + arguments->codeblock[1] + - // arguments->codeblock[2] + arguments->codeblock[3]) < 4) || - // ((arguments->codeblock[0] + arguments->codeblock[1] + - // arguments->codeblock[2] + arguments->codeblock[3]) > 20)) - // { - // argp_error(state, "The sum of the specified codeblock sizes " - // "is outside of the supported range\n"); - // } - break; - } - case 'R': - { - // arguments->compratio = (uint8_t)strtoll(arg, &end, 10); - // printf("%d\n", arguments->compratio); - break; - } - case 'D': - { - */ -/* remove_deliminator(arg, end, '/'); - - for(buff_LL = strtoll(arg, &end, 10), i = 0; arg != end && i < 4; - buff_LL = strtoll(arg, &end, 10), i++) + if (i == 1) { - arg = end; - if (errno == ERANGE) - { - printf("range error, got "); - errno = 0; - } - - if(buff_LL >= 1 && buff_LL <= 63) - { - arguments->codeblock[i] = (uint8_t) buff_LL; - } - else - { - argp_error(state, "The specified codeblock size (%ld) " - "is out of the supported range.\n", buff_LL); - } + arguments->cblkSize[1] = + arguments->cblkSize[2] = + arguments->cblkSize[3] = arguments->cblkSize[0]; } - - if(i == 1) - { - arguments->codeblock[1] = - arguments->codeblock[2] = - arguments->codeblock[3] = arguments->codeblock[0]; - } - else if(i != 4) + else if (i != 4) { argp_error(state, "The codeblock argument expects either a " "single global or 4 directional values\n"); - }*/ - /* + } + + arguments->optSet |= CBLKS; break; } + + /* Ingest compression ratio. */ + case 'r': + { + if (arguments->optSet & CMPRT) + { + argp_error(state, "The compression ratio can only be defined once.\n"); + } + else if (arguments->optSet & BITRT) + { + argp_error(state, "The size reduction requires to be specified " + "either by a bit rate or a compression ratio, " + "never both.\n"); + } + + if (verify_opt(arg, ',', true) == EXIT_FAILURE) + { + argp_error(state, "Invalid delimitnator in the compression" + " ratio option \n"); + } + + for(compRatio = strtod(arg, &end), i = 0; arg != end && i < 10; + compRatio = strtod(arg, &end), i++) + { + arg = end; + + if (compRatio > 0 && compRatio < 65536 && errno != ERANGE) + { + arguments->rate[i] = (double) compRatio; + } + else + { + errno = 0; + argp_error(state, "The specified bitrate (%d) is " + "out of the supported range.\n", compRatio); + } + } + + arguments->optSet |= CMPRT; + break; + } + + /* Ingest decomposition level. */ + case 'd': + { + if (arguments->optSet & DCLVL) + { + argp_error(state, "The compression ratio can only be defined once.\n"); + } + + if (verify_opt(arg, ',', false) == EXIT_FAILURE) + { + argp_error(state, "Invalid delimitnator in the decomposition" + " level option.\n"); + } + + for(buff = strtoll(arg, &end, 10), i = 0; arg != end && i < 4; + buff = strtoll(arg, &end, 10), i++) + { + arg = end; + + if (buff > 0 && buff <= 63 && errno != ERANGE) + { + arguments->decompLevel[i] = (uint8_t) buff; + } + else + { + errno = 0; + argp_error(state, "The specified decomposition level (%ld) " + "is out of the supported range.\n", buff); + break; + } + } + + if (i == 1) + { + arguments->decompLevel[1] = + arguments->decompLevel[2] = + arguments->decompLevel[3] = arguments->decompLevel[0]; + } + else if (i != 4) + { + argp_error(state, "The decomposition level argument expects either a " + "single global or 4 directional values\n"); + } + + arguments->optSet |= DCLVL; + break; + } + + /* Ingest number of OpenMP threads. */ case 'n': { - // buff_LL = strtoll(arg, &end, 10); - // if((buff_LL < 1) || (buff_LL > 255)) - // { - // argp_error(state, "The number of OpenMP threads specified" - // "is out of the supported range.\n"); - // } - // else - // { - // arguments->nthreads = (uint8_t)buff_LL; - // } + if (arguments->optSet & OMPTH) + { + argp_error(state, "The number of OpenMP threads can only be " + "defined once.\n"); + } + + buff = strtoll(arg, &end, 10); + + if (errno == ERANGE) + { + errno = 0; + argp_error(state, "The specified number of OpenMP threads (%ld) " + "is out of the supported range.\n", buff); + } + else + { + arguments->nThreads = (uint64_t) buff; + } + + arguments->optSet |= OMPTH; break; } + + /* Ingest quality layer to be used for decompression. */ case 'l': { - printf("l\n"); + if (arguments->optSet & USQLY) + { + argp_error(state, "The quality layer used for decompression" + " can only be defined once.\n"); + } + + buff = strtoll(arg, &end, 10); + + if (buff > 0 && buff <= 255 && errno != ERANGE) + { + errno = 0; + argp_error(state, "The specified quality layer (%ld) " + "is out of the supported range.\n", buff); + } + else + { + arguments->useLayer = (uint8_t) buff; + } + + arguments->optSet |= USQLY; break; } + + /* Ingest wavelet kernels. */ case 'k': { - printf("k\n"); + if (arguments->optSet & DWTKL) + { + argp_error(state, "The wavelet kernels can only be defined once.\n"); + } + + for(token = strtok_r(arg, ",", &ptr), i = 0; + token != NULL, i < 4; + token = strtok_r(NULL, ",", &ptr), i++) + { + if (strcasecmp(token, "leGall") == 0) + arguments->dwtKernel[i] = bwc_dwt_5_3; + else if (strcasecmp(token, "CDF") == 0) + arguments->dwtKernel[i] = bwc_dwt_9_7; + else if (strcasecmp(token, "Haar") == 0) + arguments->dwtKernel[i] = bwc_dwt_haar; + else + argp_error(state, "Waveket kernel %s is unknown " + "to the library.\n", token); + } + + if (i == 1) + { + arguments->dwtKernel[1] = + arguments->dwtKernel[2] = + arguments->dwtKernel[3] = arguments->dwtKernel[0]; + } + else if (i != 4) + { + argp_error(state, "The wavelet kernel argument expects either a " + "single global or 4 directional values\n"); + } + + arguments->optSet |= DWTKL; break; } + + /* Ingest quantization step size. */ case 'q': { - printf("q\n"); + if (arguments->optSet & QTSIZ) + { + argp_error(state, "The quantization step size can only be " + "defined once.\n"); + } + + qt_step_size = strtod(arg, &end); + + if (qt_step_size > 0 && qt_step_size < 2 && errno != ERANGE) + { + arguments->qt_step_size = (double) qt_step_size; + } + else + { + errno = 0; + argp_error(state, "The specified quantization step size (%f) is " + "out of the supported range.\n", qt_step_size); + } + + arguments->optSet |= QTSIZ; break; } - case 'Q': + + /* Ingest Q number format range. */ + case 'm': { - printf("Q\n"); + if (arguments->optSet & QFRMT) + { + argp_error(state, "The Q format range can only be defined once.\n"); + } + + buff = strtoll(arg, &end, 10); + if (buff > 0 && buff < 63 && errno != ERANGE) + { + arguments->Qm = (uint8_t) buff; + } + else + { + errno = 0; + argp_error(state, "The specified Q number format range (%ld) " + "is out of the supported range.\n", buff); + } + + arguments->optSet |= QFRMT; break; } + + /* Ingest error resilience setting. */ case 'e': { - printf("e\n"); + arguments->erresilience = true; break; } + + /* Ingest tile size. */ case 't': { - printf("t\n"); + if (arguments->optSet & TILES) + { + argp_error(state, "The tile size can only be defined once.\n"); + } + + if (verify_opt(arg, ',', false) == EXIT_FAILURE) + { + argp_error(state, "Invalid delimitnator in the tile" + " size option.\n"); + } + + for(buff = strtoll(arg, &end, 10), i = 0; arg != end && i < 4; + buff = strtoll(arg, &end, 10), i++) + { + arg = end; + + if (buff >= 16 && errno != ERANGE) + { + arguments->tileSize[i] = (uint64_t) buff; + } + else + { + errno = 0; + argp_error(state, "The specified tile size (%ld) " + "is out of the supported range.\n", buff); + break; + } + } + + if (i == 1) + { + arguments->tileSize[1] = + arguments->tileSize[2] = + arguments->tileSize[3] = arguments->tileSize[0]; + } + else if (i != 4) + { + argp_error(state, "The tile argument expects either a " + "single global or 4 directional values\n"); + } + + arguments->optSet |= TILES; break; } + + /* Ingest precinct size. */ case 'p': { - printf("p\n"); + if (arguments->optSet & PRECS) + { + argp_error(state, "The precinct size can only be defined once.\n"); + } + + if (verify_opt(arg, ',', false) == EXIT_FAILURE) + { + argp_error(state, "Invalid delimitnator in the precinct" + " size option.\n"); + } + + for(buff = strtoll(arg, &end, 10), i = 0; arg != end && i < 4; + buff = strtoll(arg, &end, 10), i++) + { + arg = end; + + if (buff >= 0 && buff <= 15 && errno != ERANGE) + { + arguments->precSize[i] = (uint8_t) buff; + } + else + { + errno = 0; + argp_error(state, "The specified precinct size (%ld) " + "is out of the supported range.\n", buff); + break; + } + } + + if (i == 1) + { + arguments->precSize[1] = + arguments->precSize[2] = + arguments->precSize[3] = arguments->precSize[0]; + } + else if (i != 4) + { + argp_error(state, "The precinct argument expects either a " + "single global or 4 directional values\n"); + } + + arguments->optSet |= PRECS; break; } - case ARGP_KEY_NO_ARGS: - { - argp_usage (state); - break; - } - - case ARGP_KEY_ARG: - - // Too many arguments. - if(state->arg_num > 1) - argp_usage(state); - break; - + /* Check if the user supplied options fit the supported * + * use case. */ case ARGP_KEY_END: - */ - /*if(!((arguments->analysis != NULL) && (arguments->comp == NULL) - && (arguments->decomp == NULL) - && (arguments->header == NULL) - && (arguments->output == NULL) - && (arguments->reference != NULL)) && - !((arguments->comp != NULL) && (arguments->analysis == NULL) - && (arguments->decomp == NULL) - && (arguments->header == NULL) - && (arguments->reference == NULL)) && - !((arguments->decomp != NULL) && (arguments->analysis == NULL) - && (arguments->comp == NULL) - && (arguments->header == NULL) - && (arguments->reference == NULL)) && - !((arguments->header != NULL) && (arguments->analysis == NULL) - && (arguments->comp == NULL) - && (arguments->decomp == NULL) - && (arguments->output == NULL) - && (arguments->reference == NULL))) + { + if (((arguments->mode == cli_cmp || + arguments->mode == cli_dcp) && (arguments->in == NULL || arguments->ref != NULL)) || + (arguments->mode == cli_inf && (arguments->in == NULL || arguments->ref != NULL + || arguments->out != NULL)) || + (arguments->mode == cli_anl && (arguments->in == NULL || arguments->ref == NULL + || arguments->out != NULL))) { argp_error(state, "The User supplied options do not fit the " "supported use cases.\n"); - }*/ - /* + } + else if (arguments->mode == cli_ini) + { + argp_usage(state); + } break; + } + /* Output standard usage message if no arg is defined. */ + case ARGP_KEY_NO_ARGS: + { + if (arguments->mode == cli_ini) + argp_usage (state); + } + + /* Return error if key is unknown. */ default: - return ARGP_ERR_UNKNOWN; + return ARGP_ERR_UNKNOWN; } return EXIT_SUCCESS; } -*/ -// initialize the argp struct. Which will be used to parse and use the args. -//static struct argp argp = {options, parse_opt, 0, doc}; +/*================================================================================================*/ +/** + * @details Initialize the argp struct. used to parse the command line arguments + */ +/*================================================================================================*/ +static struct argp argp = {options, parse_opt, 0, doc}; /*================================================================================================*/ /** @@ -650,97 +1069,193 @@ parse_opt(int key, /*================================================================================================*/ int main(int argc, char *argv[]) { - int i = 0; - int size = 0; + /*-----------------------*\ + ! DEFINE INT VARIABLES: ! + \*-----------------------*/ + uint64_t size = 0; + uint8_t i; + uint8_t error_handle; + + + /*-----------------------*\ + ! DEFINE REAL VARIABLES: ! + \*-----------------------*/ + double rtype; + + /*-----------------------*\ + ! DEFINE CHAR VARIABLES: ! + \*-----------------------*/ + char rate[200] = {0}; + + unsigned char *input; + unsigned char *output; + + /*-----------------------*\ + ! DEFINE DER. VARIABLES: ! + \*-----------------------*/ + bwc_precision precision; + bwc_stream *stream; + bwc_codec *coder; + /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - cli_arguments arguments = {0}; + eas3_data *data; + cli_arguments arguments = {0}; - eas3_data *data; - uchar *input; - uchar *output; + /* Parse the command line arguments and invoke the appro- * + * priate bwccmdl mode. */ + if (argp_parse(&argp, argc, argv, 0, 0, &arguments) == EXIT_FAILURE) + { + error_handle = EXIT_FAILURE; + goto OUT; + } - data = read_eas3("TGV_125.eas"); + /* Compress the user supplied data set. */ + if (arguments.mode == cli_cmp) + { + // TODO: Define a universal data structure and implement a reader + // that ingests different file formats + if ((data = read_eas3(arguments.in)) == NULL) + { + error_handle = EXIT_FAILURE; + goto OUT; + } - printf("I read eas3. No guarantees. Check validity. Compression will start now ...\n"); - - size = data->params.ndim1 * data->params.ndim2 * - data->params.ndim3 * data->params.nts * - data->params.npar; + /* Evaluate the input and output buffer size and initial- * + * ize the BigWhoop data and coder structs. */ + size = data->params.ndim1 * data->params.ndim2 * + data->params.ndim3 * data->params.nts * + data->params.npar; - bwc_precision precision; - if (data->params.accuracy == 1) - { - precision = bwc_precision_single; - input = (uchar*)data->field.f; - output = calloc(size, sizeof(float)); - } - else if (data->params.accuracy == 2) - { - precision = bwc_precision_double; - input = (uchar*)data->field.d; - output = calloc(size, sizeof(double)); - } + if (data->params.accuracy == 1) + { + precision = bwc_precision_single; + input = (unsigned char*)data->field.f; + output = calloc(size, sizeof(float)); + } + else if (data->params.accuracy == 2) + { + precision = bwc_precision_double; + input = (unsigned char*)data->field.d; + output = calloc(size, sizeof(double)); + } - bwc_mode mode = comp; - bwc_stream* stream = bwc_init_stream(input, output, comp); - bwc_codec* coder = bwc_alloc_coder(data->params.ndim1, - data->params.ndim2, - data->params.ndim3, - data->params.nts, - data->params.npar, - precision); - // TODO: implement setters for codeblocks, decomposition etc. - //bwc_set_qm(coder, 32); - char rate[10]; // TODO: replace with cmdl argument - sprintf(rate, "%05.3f", 4.0); - rate[strlen(rate)-1] = '0'; - printf("rate %s \n", rate); + stream = bwc_init_stream(input, output, comp); + coder = bwc_alloc_coder(data->params.ndim1, + data->params.ndim2, + data->params.ndim3, + data->params.nts, + data->params.npar, + precision); - bwc_create_compression(coder, stream, rate); - bwc_compress(coder, stream); - bwc_free_codec(coder); + /* Apply the user supplied compression options using the * + * appropriate setter functions. */ + if((arguments.optSet & QFRMT) != 0) + bwc_set_qm(coder, arguments.Qm); - // TODO: implement I/O of bwc file - // TODO: bwc_header_info + /*if((arguments.optSet & DWTKL) != 0) + { + bwc_set_kernels(coder, arguments.dwtKernel[0], + arguments.dwtKernel[1], + arguments.dwtKernel[2], + arguments.dwtKernel[3]); + }*/ - write_eas3(data, "output.eas"); - data = read_eas3("output.eas"); - write_eas3(data, "output2.eas"); + if((arguments.optSet & DCLVL) != 0) + { + bwc_set_decomp(coder, arguments.decompLevel[0], + arguments.decompLevel[1], + arguments.decompLevel[2], + arguments.decompLevel[3]); + } - eas3_free_data(data); - free(output); - - /*--------------------------------------------------------*\ - ! Initialize the arguments structure. ! - \*--------------------------------------------------------*/ - //arguments.stream = calloc(1, sizeof(bwc_stream)); - //arguments.codec = calloc(1, sizeof(bwc_codec)); - //if((arguments.stream == NULL) || - //(arguments.codec == NULL)) - //{ - // memory allocation error - //fprintf(stderr, MEMERROR); - //return EXIT_FAILURE; - //} + if((arguments.optSet & TILES) != 0) + { + bwc_set_tiles(coder, arguments.tileSize[0], + arguments.tileSize[1], + arguments.tileSize[2], + arguments.tileSize[3], bwc_tile_sizeof); + } - /*--------------------------------------------------------*\ - ! Parse the cli arguments. ! - \*--------------------------------------------------------*/ - //argp_parse(&argp, argc, argv, 0, 0, &arguments); - //if(arguments.mode == cli_err) - //{ - //return EXIT_FAILURE; - //} + if((arguments.optSet & PRECS) != 0) + { + bwc_set_precincts(coder, arguments.precSize[0], + arguments.precSize[1], + arguments.precSize[2], + arguments.precSize[3]); + } - //for(i = 0; i < 10; ++i) - //printf("bitrate %d:\t%f\n",i,arguments.bitrate[i]); + if((arguments.optSet & CBLKS) != 0) + { + bwc_set_codeblocks(coder, arguments.cblkSize[0], + arguments.cblkSize[1], + arguments.cblkSize[2], + arguments.cblkSize[3]); + } + /* Initialize the rate control string according to the * + * specified bit rate/compression ratio. */ + if((arguments.optSet & BITRT) != 0) + { + rtype = 1.0; + } + else if((arguments.optSet & CMPRT) != 0) + { + rtype = 64.0; + } + else + { + rtype = 1.0; + arguments.rate[0] = 64; + } + for(i = 0; i < 10 && strlen(rate) < 192; ++i) + { + if(arguments.rate[i] > 0) + sprintf(rate + strlen(rate), "%05.3f,", arguments.rate[i]/rtype); + } + rate[strlen(rate) - 1] = '0'; - //printf("ARG1: %s", arguments.args[0]); - //printf("\nVERBOSE: %s", arguments.verbose? "yes" : "no"); - //printf("\nOption1: %s", arguments.option1); - //printf("\n"); + /* Initialize the rate control string according to the * + * specified bit rate/compression ratio. */ + if (bwc_create_compression(coder, stream, rate) == EXIT_FAILURE) + { + error_handle = EXIT_FAILURE; + goto OUT; + } + + bwc_compress(coder, stream); + } + else if (arguments.mode == cli_dcp) + { + printf("Decompression\n"); + } + else if (arguments.mode == cli_anl) + { + printf("Analysis\n"); + } + else if (arguments.mode == cli_inf) + { + printf("Header Info\n"); + } + else + { + return EXIT_FAILURE; + } + +OUT: + if (coder != NULL) + bwc_free_codec(coder); + + if (data != NULL) + eas3_free_data(data); + + if (stream !=NULL) + free(stream); + + if (output != NULL) + free(output); + + return error_handle; } -- 2.45.2 From d9799506264244fba818ef57600bd466c464240e Mon Sep 17 00:00:00 2001 From: Patrick Vogler Date: Tue, 29 Oct 2024 19:01:33 +0100 Subject: [PATCH 34/53] Implemented the compression path with verbose output and support for all options available to the user. --- src/tools/bwccmdl.c | 266 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 240 insertions(+), 26 deletions(-) diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index cbc5815..4a5ee0d 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -48,6 +48,8 @@ #include #include #include +#include +#include #include #include #include @@ -72,12 +74,20 @@ "| ERROR: Out of memory |\n"\ "o##########################################################o\n" +#define TYPERROR "o##########################################################o\n"\ + "| ERROR: Invalid file type. |\n"\ + "o##########################################################o\n" + +#define FOUERROR "o##########################################################o\n"\ + "| ERROR: Could not open specified output file. |\n"\ + "o##########################################################o\n" + #define RDERROR "o##########################################################o\n"\ - "| ERROR: Invalid Number of Bytes Read from File. |\n"\ + "| ERROR: Invalid number of bytes read from file. |\n"\ "o##########################################################o\n" #define WRTERROR "o##########################################################o\n"\ - "| ERROR: Invalid Number of Bytes Written to File. |\n"\ + "| ERROR: Invalid number of bytes written to file. |\n"\ "o##########################################################o\n" /*================================================================================================*/ @@ -427,7 +437,6 @@ parse_opt(int key, int64_t buff; uint8_t i; - /*-----------------------*\ ! DEFINE REAL VARIABLES: ! \*-----------------------*/ @@ -435,7 +444,6 @@ parse_opt(int key, double qt_step_size; float bitrate; - /*-----------------------*\ ! DEFINE CHAR VARIABLES: ! \*-----------------------*/ @@ -1069,6 +1077,11 @@ static struct argp argp = {options, parse_opt, 0, doc}; /*================================================================================================*/ int main(int argc, char *argv[]) { + /*-----------------------*\ + ! DEFINE BOOL VARIABLES: ! + \*-----------------------*/ + bool delim = false; + /*-----------------------*\ ! DEFINE INT VARIABLES: ! \*-----------------------*/ @@ -1076,20 +1089,29 @@ int main(int argc, char *argv[]) uint8_t i; uint8_t error_handle; - /*-----------------------*\ ! DEFINE REAL VARIABLES: ! \*-----------------------*/ - double rtype; + double rtype, exp; /*-----------------------*\ ! DEFINE CHAR VARIABLES: ! \*-----------------------*/ char rate[200] = {0}; + char cli_buffer[1024] = {0}; + char cli_verbose[4096] = {0}; + + char *cli_output; + char *buffer; unsigned char *input; unsigned char *output; + /*-----------------------*\ + ! DEFINE FILE POINTER: ! + \*-----------------------*/ + FILE *fp; + /*-----------------------*\ ! DEFINE DER. VARIABLES: ! \*-----------------------*/ @@ -1111,9 +1133,18 @@ int main(int argc, char *argv[]) goto OUT; } + /* Set the number of OpenMP threads. */ + #if defined (_OPENMP) + if (arguments.optSet & OMPTH) + omp_set_num_threads((int)arguments.nThreads); + #endif + /* Compress the user supplied data set. */ if (arguments.mode == cli_cmp) { + + /* Ingest the bwccmdl input and set the appropriate cli_ * + * verbose message if the option is set. */ // TODO: Define a universal data structure and implement a reader // that ingests different file formats if ((data = read_eas3(arguments.in)) == NULL) @@ -1121,11 +1152,47 @@ int main(int argc, char *argv[]) error_handle = EXIT_FAILURE; goto OUT; } + if (arguments.verbose == true) + { + strcat(cli_verbose, bwc_header); + strcat(cli_verbose, "--------------------------- I/O --------------------------\n\n"); + + sprintf(cli_buffer," Input: %s \n", arguments.in); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + } + + /* Evaluate the appropriate output file. */ + if ((arguments.optSet & FLOUT) == 0) + arguments.out = arguments.in; + + printf("%s \n", arguments.out); + if ((buffer = strrchr(arguments.out, '.')) == NULL) + { + error_handle = EXIT_FAILURE; + printf(TYPERROR); + goto OUT; + } + cli_output = calloc(strlen(arguments.out) - strlen(buffer) + 1, sizeof(char)); + if (cli_output == NULL) + { + error_handle = EXIT_FAILURE; + printf(MEMERROR); + goto OUT; + } + sprintf(cli_output, "%.*s.bwc", (int)(strlen(arguments.out) - strlen(buffer)), arguments.out); + + if (arguments.verbose == true) + { + sprintf(cli_buffer," Output: %s \n", cli_output); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + } /* Evaluate the input and output buffer size and initial- * * ize the BigWhoop data and coder structs. */ size = data->params.ndim1 * data->params.ndim2 * - data->params.ndim3 * data->params.nts * + data->params.ndim3 * data->params.nts * data->params.npar; if (data->params.accuracy == 1) @@ -1151,10 +1218,39 @@ int main(int argc, char *argv[]) /* Apply the user supplied compression options using the * * appropriate setter functions. */ - if((arguments.optSet & QFRMT) != 0) - bwc_set_qm(coder, arguments.Qm); + if (arguments.verbose == true) + { + strcat(cli_verbose, "\n"); + strcat(cli_verbose, "----------------- Compression Parameters -----------------\n"); + strcat(cli_verbose, "\n"); + } - /*if((arguments.optSet & DWTKL) != 0) + if ((arguments.optSet & TILES) != 0) + { + bwc_set_tiles(coder, arguments.tileSize[0], + arguments.tileSize[1], + arguments.tileSize[2], + arguments.tileSize[3], bwc_tile_sizeof); + + if (arguments.verbose == true) + { + strcat(cli_verbose," Tile Size: \n"); + sprintf(cli_buffer," - Samples in 1.D: %27ld\n"\ + " - Samples in 2.D: %27ld\n"\ + " - Samples in 3.D: %27ld\n"\ + " - Samples in 4.D: %27ld\n", arguments.tileSize[0], + arguments.tileSize[1], + arguments.tileSize[2], + arguments.tileSize[3]); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + delim = true; + } + } + + // TODO: Implement the kernel setter as a global function + // and define the proper verbose output layout. + /*if ((arguments.optSet & DWTKL) != 0) { bwc_set_kernels(coder, arguments.dwtKernel[0], arguments.dwtKernel[1], @@ -1162,61 +1258,160 @@ int main(int argc, char *argv[]) arguments.dwtKernel[3]); }*/ - if((arguments.optSet & DCLVL) != 0) + if ((arguments.verbose == true) && + ((arguments.optSet & (DCLVL | PRECS | CBLKS)) != 0)) + { + if (delim == true) + { + strcat(cli_verbose, " __________________________________________________________\n"); + strcat(cli_verbose, "\n"); + } + strcat(cli_verbose, " 1.D | 2.D | 3.D | 4.D\n"); + delim = true; + } + + if ((arguments.optSet & DCLVL) != 0) { bwc_set_decomp(coder, arguments.decompLevel[0], arguments.decompLevel[1], arguments.decompLevel[2], arguments.decompLevel[3]); + + if (arguments.verbose == true) + { + sprintf(cli_buffer, " Decomposition Levels: %18d |%4d |%4d |%4d\n", + arguments.decompLevel[0], + arguments.decompLevel[1], + arguments.decompLevel[2], + arguments.decompLevel[3]); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + } } - if((arguments.optSet & TILES) != 0) - { - bwc_set_tiles(coder, arguments.tileSize[0], - arguments.tileSize[1], - arguments.tileSize[2], - arguments.tileSize[3], bwc_tile_sizeof); - } - - if((arguments.optSet & PRECS) != 0) + if ((arguments.optSet & PRECS) != 0) { bwc_set_precincts(coder, arguments.precSize[0], arguments.precSize[1], arguments.precSize[2], arguments.precSize[3]); + + if (arguments.verbose == true) + { + sprintf(cli_buffer, " Precincts [log2]: %18d |%4d |%4d |%4d\n", + arguments.precSize[0], + arguments.precSize[1], + arguments.precSize[2], + arguments.precSize[3]); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + } } - if((arguments.optSet & CBLKS) != 0) + if ((arguments.optSet & CBLKS) != 0) { bwc_set_codeblocks(coder, arguments.cblkSize[0], arguments.cblkSize[1], arguments.cblkSize[2], arguments.cblkSize[3]); + + if (arguments.verbose == true) + { + sprintf(cli_buffer, " Codeblocks [log2]: %18d |%4d |%4d |%4d\n", + arguments.cblkSize[0], + arguments.cblkSize[1], + arguments.cblkSize[2], + arguments.cblkSize[3]); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + } + } + + if ((arguments.verbose == true) && + (delim == true) && + (((arguments.optSet & QFRMT) != 0) || arguments.erresilience == true)) + { + + strcat(cli_verbose, " __________________________________________________________\n"); + strcat(cli_verbose, "\n"); + } + + if ((arguments.optSet & QFRMT) != 0) + { + bwc_set_qm(coder, arguments.Qm); + + if (arguments.verbose == true) + { + sprintf(cli_buffer, " Q Number Format: %27d\n", arguments.Qm); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + delim = true; + } + } + + if (arguments.erresilience == true) + { + bwc_set_error_resilience(coder); + + if (arguments.verbose == true) + { + sprintf(cli_buffer, " Error Resilience: %27s\n", "true"); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + delim = true; + } } /* Initialize the rate control string according to the * * specified bit rate/compression ratio. */ - if((arguments.optSet & BITRT) != 0) + if ((arguments.verbose == true) && + (delim == true)) + { + + strcat(cli_verbose, " __________________________________________________________\n"); + strcat(cli_verbose, "\n"); + } + + if ((arguments.optSet & BITRT) != 0) { rtype = 1.0; + exp = 1.0; } - else if((arguments.optSet & CMPRT) != 0) + else if ((arguments.optSet & CMPRT) != 0) { rtype = 64.0; + exp = -1.0; } else { rtype = 1.0; + exp = 1.0; arguments.rate[0] = 64; } for(i = 0; i < 10 && strlen(rate) < 192; ++i) { - if(arguments.rate[i] > 0) - sprintf(rate + strlen(rate), "%05.3f,", arguments.rate[i]/rtype); + if (arguments.rate[i] > 0) + { + sprintf(rate + strlen(rate), "%05.3f,", pow(arguments.rate[i]/rtype, exp)); + + if (arguments.verbose == true) + { + sprintf(cli_buffer, " Quality Layer Nr. %d: %33.2f bpd\n", i, + pow(arguments.rate[i]/rtype, exp)); + strcat(cli_verbose, cli_buffer); + } + } } rate[strlen(rate) - 1] = '0'; + if (arguments.verbose == true) + { + memset(cli_buffer, '0', sizeof(char) * 1024); + strcat(cli_verbose, "\n==============================================================\n"); + printf("%s", cli_verbose); + } + /* Initialize the rate control string according to the * * specified bit rate/compression ratio. */ if (bwc_create_compression(coder, stream, rate) == EXIT_FAILURE) @@ -1225,7 +1420,23 @@ int main(int argc, char *argv[]) goto OUT; } - bwc_compress(coder, stream); + size = bwc_compress(coder, stream); + + /* Write the codestream to the speicifed file. */ + fp = fopen(cli_output, "wb"); + if (fp == NULL) + { + error_handle = EXIT_FAILURE; + printf(FOUERROR); + goto OUT; + } + + if (fwrite(stream->out, sizeof(uchar), size, fp) != size) + { + error_handle = EXIT_FAILURE; + printf(WRTERROR); + goto OUT; + } } else if (arguments.mode == cli_dcp) { @@ -1257,5 +1468,8 @@ OUT: if (output != NULL) free(output); + if (cli_output != NULL) + free(cli_output); + return error_handle; } -- 2.45.2 From 6716a2b1d47b49be3b214b3ec88fdb3f6e2fe03c Mon Sep 17 00:00:00 2001 From: Patrick Vogler Date: Tue, 29 Oct 2024 19:03:11 +0100 Subject: [PATCH 35/53] Updated the WARNING messages to fit the layout of the verbose command line tool output. --- src/library/libbwc.c | 159 ++++++++++++++++++++----------------------- 1 file changed, 75 insertions(+), 84 deletions(-) diff --git a/src/library/libbwc.c b/src/library/libbwc.c index bf01f88..d6ede6f 100755 --- a/src/library/libbwc.c +++ b/src/library/libbwc.c @@ -2490,15 +2490,14 @@ set_quant_step_size(bwc_codec *const codec, double delta) \*--------------------------------------------------------*/ if((delta <= 0) || (delta >= 2)) { - fprintf(stderr, "o==========================================================o\n"\ - "| WARNING: Invalid quantization step size |\n"\ - "| |\n"\ - "| The quantization step size does not lie within |\n"\ - "| the acceptable range of: |\n"\ - "| |\n"\ - "| 0 < step size < 2 |\n"\ - "| |\n"\ - "o==========================================================o\n"); + fprintf(stderr, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"\ + " WARNING: Invalid quantization step size \n"\ + " \n"\ + " The quantization step size does not lie within \n"\ + " the acceptable range of: \n"\ + " \n"\ + " 0 < step size < 2 \n"\ + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); return; } @@ -2782,14 +2781,13 @@ bwc_set_decomp(bwc_codec *const codec, uint8 decompX, uint8 decompY, uint8 decom if((control->decompX > 63) || (control->decompY > 63) || (control->decompZ > 63) || (control->decompTS > 31)) { - fprintf(stderr, "o==========================================================o\n"\ - "| WARNING: Invalid decomposition level value |\n"\ - "| |\n"\ - "| The maximum acceptable decomposition level is |\n"\ - "| 63 for all spatial and 31 for the temporal |\n"\ - "| dimensions. |\n"\ - "| |\n"\ - "o==========================================================o\n"); + fprintf(stderr, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"\ + " WARNING: Invalid decomposition level value \n"\ + " \n"\ + " The maximum acceptable decomposition level is \n"\ + " 63 for all spatial and 31 for the temporal \n"\ + " dimensions. \n"\ + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); /*--------------------------------------------------------*\ ! Reset the decomposition levels to their standard values. ! @@ -2924,13 +2922,12 @@ bwc_set_precincts(bwc_codec *const codec, uint8 pX, uint8 pY, uint8 pZ, uint8 pT ((control->precSizeTS < 1) && (info->nTS >> 1)) || (control->precSizeX > 15) || (control->precSizeY > 15) || (control->precSizeZ > 15) || (control->precSizeTS > 15)) { - fprintf(stderr, "o==========================================================o\n"\ - "| WARNING: Invalid precinct size |\n"\ - "| |\n"\ - "| The maximum acceptable precinct size is 2^15, |\n"\ - "| the smallest valid precinct size is 2^1. |\n"\ - "| |\n"\ - "o==========================================================o\n"); + fprintf(stderr, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"\ + " WARNING: Invalid precinct size \n"\ + " \n"\ + " The maximum acceptable precinct size is 2^15, \n"\ + " the smallest valid precinct size is 2^1. \n"\ + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); /*--------------------------------------------------------*\ ! Reset the codeblock sizes to their standard values. ! @@ -3023,15 +3020,14 @@ bwc_set_codeblocks(bwc_codec *const codec, uint8 cbX, uint8 cbY, uint8 cbZ, uint ((control->cbX + control->cbY + control->cbZ + control->cbTS) < 4) || ((control->cbX + control->cbY + control->cbZ + control->cbTS) > 20)) { - fprintf(stderr, "o==========================================================o\n"\ - "| WARNING: Invalid codeblock size |\n"\ - "| |\n"\ - "| The maximum acceptable codeblock size is 2^20 |\n"\ - "| with a maximum allowable number of datapoints |\n"\ - "| in each dimension of 2^10. The smallest valid |\n"\ - "| codeblock size is 2^4. |\n"\ - "| |\n"\ - "o==========================================================o\n"); + fprintf(stderr, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"\ + " WARNING: Invalid codeblock size \n"\ + " \n"\ + " The maximum acceptable codeblock size is 2^20 \n"\ + " with a maximum allowable number of datapoints \n"\ + " in each dimension of 2^10. The smallest valid \n"\ + " codeblock size is 2^4. \n"\ + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); /*--------------------------------------------------------*\ ! Reset the codeblock sizes to their standard values. ! @@ -3106,19 +3102,18 @@ bwc_set_qm(bwc_codec *const codec, uint8 Qm) ! Check if the Q number formate range is valid and amend ! ! the bwc_codec structure accordingly. ! \*--------------------------------------------------------*/ - if((int8)(PREC_BIT - Qm) < 2) + if((int8)(PREC_BIT - Qm) < 1) { - fprintf(stderr, "o==========================================================o\n"\ - "| WARNING: Invalid Q number formate range |\n"\ - "| |\n"\ - "| The specified Q number formate range is larger |\n"); + fprintf(stderr, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"\ + " WARNING: Invalid Q number formate range \n"\ + " \n"\ + " The specified Q number formate range is larger \n"); #ifdef BWC_SINGLE_PRECISION - fprintf(stderr, "| than the permitted 30 bits. |\n"); + fprintf(stderr, " than the permitted 30 bits. \n"); #else - fprintf(stderr, "| than the permitted 62 bits. |\n"); + fprintf(stderr, " than the permitted 62 bits. \n"); #endif - fprintf(stderr, "| |\n"\ - "o==========================================================o\n"); + fprintf(stderr, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); } else { @@ -3213,17 +3208,16 @@ bwc_set_tiles(bwc_codec *const codec, uint64 tilesX, uint64 tilesY, uint64 tiles (control->tileSizeZ < 16 && control->tileSizeZ > info->nZ)|| (control->tileSizeTS < 16 && control->tileSizeTS > info->nTS)) { - fprintf(stderr,"o==========================================================o\n"\ - "| WARNING: Invalid Tile Dimensions |\n"\ - "| |\n"\ - "| One or more of the specified tile dimensions |\n"\ - "| has a value that falls outside of its valid |\n"\ - "| range. Please verify that all tile dimension |\n"\ - "| are within the range of: |\n"\ - "| |\n"\ - "| 16 ≤ Tile_Size_Xi ≤ Grid_Points_Xi |\n"\ - "| |\n"\ - "o==========================================================o\n"); + fprintf(stderr,">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"\ + " WARNING: Invalid Tile Dimensions \n"\ + " \n"\ + " One or more of the specified tile dimensions \n"\ + " has a value that falls outside of its valid \n"\ + " range. Please verify that all tile dimension \n"\ + " are within the range of: \n"\ + " \n"\ + " 16 ≤ Tile_Size_Xi ≤ Grid_Points_Xi \n"\ + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); return; } @@ -3255,16 +3249,15 @@ bwc_set_tiles(bwc_codec *const codec, uint64 tilesX, uint64 tilesY, uint64 tiles \*--------------------------------------------------------*/ if(((double)num_tiles_X * num_tiles_Y * num_tiles_Z * num_tiles_TS) > 0xFFFFFFFFFFFFFFFF) { - fprintf(stderr,"o==========================================================o\n"\ - "| WARNING: Invalid Tile Dimensions |\n"\ - "| |\n"\ - "| The number of tiles exceeds its maxmum allowa- |\n"\ - "| ble value. Please adjust all tile dimension so |\n"\ - "| that the number of tiles falls within the range |\n"\ - "| of: |\n"\ - "| Number_of_Tiles < 2^64 |\n"\ - "| |\n"\ - "o==========================================================o\n"); + fprintf(stderr,">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"\ + " WARNING: Invalid Tile Dimensions \n"\ + " \n"\ + " The number of tiles exceeds its maxmum allowa- \n"\ + " ble value. Please adjust all tile dimension so \n"\ + " that the number of tiles falls within the range \n"\ + " of: \n"\ + " Number_of_Tiles < 2^64 \n"\ + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); /*--------------------------------------------------------*\ ! Reset the tile sizes to their standard values. ! @@ -3285,15 +3278,14 @@ bwc_set_tiles(bwc_codec *const codec, uint64 tilesX, uint64 tilesY, uint64 tiles \*--------------------------------------------------------*/ if(((double)tilesX * tilesY * tilesZ * tilesTS) > 0xFFFFFFFFFFFFFFFF) { - fprintf(stderr,"o==========================================================o\n"\ - "| WARNING: Invalid Number Of Tiles |\n"\ - "| |\n"\ - "| The number of tiles exceeds its maxmum allowa- |\n"\ - "| ble value of: |\n"\ - "| |\n"\ - "| Number_of_Tiles < 2^64 |\n"\ - "| |\n"\ - "o==========================================================o\n"); + fprintf(stderr,">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"\ + " WARNING: Invalid Number Of Tiles \n"\ + " \n"\ + " The number of tiles exceeds its maxmum allowa- \n"\ + " ble value of: \n"\ + " \n"\ + " Number_of_Tiles < 2^64 \n"\ + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); return; } @@ -3318,18 +3310,17 @@ bwc_set_tiles(bwc_codec *const codec, uint64 tilesX, uint64 tilesY, uint64 tiles (control->tileSizeZ < 16 && control->tileSizeZ > info->nZ)|| (control->tileSizeTS < 16 && control->tileSizeTS > info->nTS)) { - fprintf(stderr,"o==========================================================o\n"\ - "| WARNING: Invalid Number Of Tiles |\n"\ - "| |\n"\ - "| One or more of the tile dimensions has a value |\n"\ - "| that falls outside of its valid range. Please |\n"\ - "| verify that the number of tiles for all dimen- |\n"\ - "| sions are set so that the corresponding tile |\n"\ - "| sizes fall within the range of: |\n"\ - "| |\n"\ - "| 16 ≤ Tile_Size_Xi ≤ Grid_Points_Xi |\n"\ - "| |\n"\ - "o==========================================================o\n"); + fprintf(stderr,">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"\ + " WARNING: Invalid Number Of Tiles \n"\ + " \n"\ + " One or more of the tile dimensions has a value \n"\ + " that falls outside of its valid range. Please \n"\ + " verify that the number of tiles for all dimen- \n"\ + " sions are set so that the corresponding tile \n"\ + " sizes fall within the range of: \n"\ + " \n"\ + " 16 ≤ Tile_Size_Xi ≤ Grid_Points_Xi \n"\ + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); /*--------------------------------------------------------*\ ! Reset the tile sizes to their standard values. ! -- 2.45.2 From f81807e1e35b269f26d03e7b5cd91a67045f5a14 Mon Sep 17 00:00:00 2001 From: Patrick Vogler Date: Wed, 30 Oct 2024 12:38:56 +0100 Subject: [PATCH 36/53] Fixed some memory leak issues. --- src/interfaces/reader/eas3.c | 41 +++++++++++++++++++++++------------- src/tools/bwccmdl.c | 32 +++++++++++++++------------- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 7581118..b5a3554 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -231,22 +231,36 @@ endian_conversion(void *value, void eas3_free_data(eas3_data* data) { - if(data != NULL) - { - if (data->param_names != NULL) - free(data->param_names); + /*-----------------------*\ + ! DEFINE STRUCTS: ! + \*-----------------------*/ + eas3_param_names *param, *temp; + + if(data != NULL) + { + if (data->param_names != NULL) + { + param = data->param_names->root; + + while(param != NULL) + { + temp = param; + param = param -> next; + free(temp); + } + } - if (data->field.d != NULL) - free(data->field.d); + if (data->field.d != NULL) + free(data->field.d); - if (data->field.f != NULL) - free(data->field.f); + if (data->field.f != NULL) + free(data->field.f); - if(data->aux.ptr != NULL) - free(data->aux.ptr); + if(data->aux.ptr != NULL) + free(data->aux.ptr); - free(data); - } + free(data); + } } void @@ -345,7 +359,6 @@ read_eas3_header(FILE *const fp, eas3_data *const data) \*-----------------------*/ uint64 Lread; uint64 i; - uint8 precision; /*-----------------------*\ ! DEFINE CHAR VARIABLES: ! @@ -356,7 +369,6 @@ read_eas3_header(FILE *const fp, eas3_data *const data) /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - bwc_gl_inf *info; eas3_std_params *params; /*-----------------------*\ @@ -702,7 +714,6 @@ write_eas3_header(FILE *const fp, eas3_data *const data) /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - bwc_gl_inf *info; eas3_std_params *params; eas3_param_names *param_names; diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index 4a5ee0d..db9f10e 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -454,8 +454,6 @@ parse_opt(int key, ! DEFINE STRUCTS: ! \*-----------------------*/ cli_arguments *arguments; - bwc_codec *codec; - bwc_stream *stream; /*-----------------------*\ ! DEFINE ASSERTIONS: ! @@ -720,7 +718,7 @@ parse_opt(int key, else { errno = 0; - argp_error(state, "The specified bitrate (%d) is " + argp_error(state, "The specified compression ratio (%f) is " "out of the supported range.\n", compRatio); } } @@ -838,7 +836,7 @@ parse_opt(int key, } for(token = strtok_r(arg, ",", &ptr), i = 0; - token != NULL, i < 4; + token != NULL && i < 4; token = strtok_r(NULL, ",", &ptr), i++) { if (strcasecmp(token, "leGall") == 0) @@ -1047,6 +1045,7 @@ parse_opt(int key, { if (arguments->mode == cli_ini) argp_usage (state); + break; } /* Return error if key is unknown. */ @@ -1061,7 +1060,7 @@ parse_opt(int key, * @details Initialize the argp struct. used to parse the command line arguments */ /*================================================================================================*/ -static struct argp argp = {options, parse_opt, 0, doc}; +static struct argp argp = {options, parse_opt, 0, doc, 0, 0, 0}; /*================================================================================================*/ /** @@ -1087,7 +1086,7 @@ int main(int argc, char *argv[]) \*-----------------------*/ uint64_t size = 0; uint8_t i; - uint8_t error_handle; + uint8_t error_handle = EXIT_SUCCESS; /*-----------------------*\ ! DEFINE REAL VARIABLES: ! @@ -1101,28 +1100,28 @@ int main(int argc, char *argv[]) char cli_buffer[1024] = {0}; char cli_verbose[4096] = {0}; - char *cli_output; - char *buffer; + char *cli_output = NULL; + char *buffer = NULL; - unsigned char *input; - unsigned char *output; + unsigned char *input = NULL; + unsigned char *output = NULL; /*-----------------------*\ ! DEFINE FILE POINTER: ! \*-----------------------*/ - FILE *fp; + FILE *fp = NULL; /*-----------------------*\ ! DEFINE DER. VARIABLES: ! \*-----------------------*/ bwc_precision precision; - bwc_stream *stream; - bwc_codec *coder; + bwc_stream *stream = NULL; + bwc_codec *coder = NULL; /*-----------------------*\ ! DEFINE STRUCTS: ! \*-----------------------*/ - eas3_data *data; + eas3_data *data = NULL; cli_arguments arguments = {0}; /* Parse the command line arguments and invoke the appro- * @@ -1173,7 +1172,7 @@ int main(int argc, char *argv[]) printf(TYPERROR); goto OUT; } - cli_output = calloc(strlen(arguments.out) - strlen(buffer) + 1, sizeof(char)); + cli_output = calloc(strlen(arguments.out) - strlen(buffer) + 5, sizeof(char)); if (cli_output == NULL) { error_handle = EXIT_FAILURE; @@ -1471,5 +1470,8 @@ OUT: if (cli_output != NULL) free(cli_output); + if (fp != NULL) + fclose(fp); + return error_handle; } -- 2.45.2 From 92a646b5e09aad0272417e5bdbca8d6fb9fb911f Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Thu, 31 Oct 2024 14:31:34 +0100 Subject: [PATCH 37/53] refactor and typos --- src/interfaces/reader/eas3.c | 4 ++-- src/tools/bwccmdl.c | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index b5a3554..868f1bf 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -223,8 +223,8 @@ endian_conversion(void *value, ! ! ! DESCRIPTION: ! ! ------------ ! -! This function deallocates the data structure used to store an numerical dataset ! -! and can be called if an error occurs or once the data is no longer needed is to be closed. ! +! This function deallocates the data structure used to store a numerical dataset ! +! and can be called if an error occurs or once the data is no longer needed. ! ! The deallocation will be carried out down to the structure levels that have been allocated. ! ! ! \*----------------------------------------------------------------------------------------------------------*/ diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index db9f10e..8df4e9c 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -153,7 +153,7 @@ static char bwc_header[] = "==================================================== */ /*================================================================================================*/ const char *argp_program_version = "bwc 0.1.0"; -const char *argp_program_bug_address = "hpcpvogl@hlrs.de"; +const char *argp_program_bug_address = "patrick.vogler@hlrs.de"; /*================================================================================================*/ /** @@ -614,7 +614,7 @@ parse_opt(int key, if (verify_opt(arg, ',', true) == EXIT_FAILURE) { - argp_error(state, "Invalid delimitnator in the bitrate option\n"); + argp_error(state, "Invalid deliminator in the bitrate option\n"); } for(bitrate = strtod(arg, &end), i = 0; arg != end && i < 10; @@ -648,7 +648,7 @@ parse_opt(int key, if (verify_opt(arg, ',', false) == EXIT_FAILURE) { - argp_error(state, "Invalid delimitnator in the codeblock" + argp_error(state, "Invalid deliminator in the codeblock" " size option.\n"); } @@ -702,7 +702,7 @@ parse_opt(int key, if (verify_opt(arg, ',', true) == EXIT_FAILURE) { - argp_error(state, "Invalid delimitnator in the compression" + argp_error(state, "Invalid deliminator in the compression" " ratio option \n"); } @@ -737,7 +737,7 @@ parse_opt(int key, if (verify_opt(arg, ',', false) == EXIT_FAILURE) { - argp_error(state, "Invalid delimitnator in the decomposition" + argp_error(state, "Invalid deliminator in the decomposition" " level option.\n"); } @@ -933,7 +933,7 @@ parse_opt(int key, if (verify_opt(arg, ',', false) == EXIT_FAILURE) { - argp_error(state, "Invalid delimitnator in the tile" + argp_error(state, "Invalid deliminator in the tile" " size option.\n"); } @@ -981,7 +981,7 @@ parse_opt(int key, if (verify_opt(arg, ',', false) == EXIT_FAILURE) { - argp_error(state, "Invalid delimitnator in the precinct" + argp_error(state, "Invalid deliminator in the precinct" " size option.\n"); } @@ -1189,7 +1189,7 @@ int main(int argc, char *argv[]) } /* Evaluate the input and output buffer size and initial- * - * ize the BigWhoop data and coder structs. */ + * size the BigWhoop data and coder structs. */ size = data->params.ndim1 * data->params.ndim2 * data->params.ndim3 * data->params.nts * data->params.npar; -- 2.45.2 From 12f937ecac54703f20d9e51ecbb38955a61cd6b9 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Mon, 4 Nov 2024 13:57:33 +0100 Subject: [PATCH 38/53] open and close header with new header structure --- include/library/private/codestream.h | 4 ++ include/library/private/libbwc.h | 4 ++ include/library/private/types.h | 13 ++++ src/library/codestream.c | 2 +- src/library/libbwc.c | 92 ++++++++++++++++++++++++++++ src/tools/bwccmdl.c | 26 ++++---- 6 files changed, 127 insertions(+), 14 deletions(-) diff --git a/include/library/private/codestream.h b/include/library/private/codestream.h index 0445b59..2e022aa 100755 --- a/include/library/private/codestream.h +++ b/include/library/private/codestream.h @@ -100,6 +100,10 @@ size_t assemble_codestream (bwc_codec *const codec, bwc_stream *const stream); //==========|==========================|======================|======|======|===================== + bwc_codec* parse_main_header (bwc_codec *const codec, + bwc_stream *const data, + bitstream *const stream); + //==========|==========================|======================|======|======|===================== bwc_codec* parse_codestream (bwc_codec *const codec, bwc_stream *const stream, uint8 const layer); diff --git a/include/library/private/libbwc.h b/include/library/private/libbwc.h index 5d67736..1afab38 100755 --- a/include/library/private/libbwc.h +++ b/include/library/private/libbwc.h @@ -142,6 +142,10 @@ uint64 const tilesTS, bwc_tile_instr const instr); //==========|==========================|======================|======|=======|==================== + bwc_header* bwc_open_header (void *const inpbuf); + //==========|==========================|======================|======|=======|==================== + void bwc_close_header (bwc_header *const header); + //==========|==========================|======================|======|=======|==================== uchar bwc_create_compression (bwc_codec *const codec, bwc_stream *const data, char *const rate_control); diff --git a/include/library/private/types.h b/include/library/private/types.h index 0320a8e..bba676d 100755 --- a/include/library/private/types.h +++ b/include/library/private/types.h @@ -659,6 +659,19 @@ bwc_prog_ord progression; // Packet progression order. } bwc_gl_ctrl; +/*================================================================================================*/ +/** + * @details Structure that is used to probe header information from a compressed data set. + */ +/*================================================================================================*/ + typedef struct + { + bwc_gl_inf info; // Global info structure + bwc_gl_ctrl control; // Global control structure + bwc_span aux; // Auxiliary info. codestream block. + bwc_span com; // Comment codestream block. + } bwc_header; + /*----------------------------------------------------------------------------------------------*\ ! ! ! DESCRIPTION: ! diff --git a/src/library/codestream.c b/src/library/codestream.c index 3c0d8d3..aec991c 100755 --- a/src/library/codestream.c +++ b/src/library/codestream.c @@ -912,7 +912,7 @@ parse_main_header(bwc_codec *const codec, bwc_stream *const data, bitstream *con data->codestream.com->memory = get_chunck(stream, Lcom - 2); data->codestream.com->size = Lcom -2; - status |= CODESTREAM_ERROR; + status |= CODESTREAM_COM_READ; break; } diff --git a/src/library/libbwc.c b/src/library/libbwc.c index d6ede6f..0beb985 100755 --- a/src/library/libbwc.c +++ b/src/library/libbwc.c @@ -3350,6 +3350,98 @@ bwc_set_tiles(bwc_codec *const codec, uint64 tilesX, uint64 tilesY, uint64 tiles control->CSsgc |= (0x01 << 9); } +/*================================================================================================*/ +/** + * @details This function opens the header of a compressed data set and parses it into an + * instance of type bwc_header. + * + * @param[in] inpbuf Pointer to compressed data set. + * + * @retval bwc_header* + */ +/*================================================================================================*/ +bwc_header* bwc_open_header(void *const inpbuf) +{ + /*-----------------------*\ + ! DEFINE STRUCTS: ! + \*-----------------------*/ + bwc_codec* codec; + bwc_stream* data; + bitstream* stream; + bwc_header* header; + + /*--------------------------------------------------------*\ + ! Initialize a codec, stream, and bitstream for parsing. ! + \*--------------------------------------------------------*/ + data = bwc_init_stream(inpbuf, NULL, decomp); + codec = bwc_alloc_decoder(); + stream = init_bitstream(data->inp, 10, 'd'); + + /*--------------------------------------------------------*\ + ! Parse the main header into the codec structure. ! + \*--------------------------------------------------------*/ + parse_main_header(codec, data, stream); + if(!codec) + { + return NULL; + } + + /*--------------------------------------------------------*\ + ! Allocate header and copy info and control structures. ! + \*--------------------------------------------------------*/ + header = calloc(1, sizeof(bwc_header)); + header->info = codec->info; + header->control = codec->control; + + /*--------------------------------------------------------*\ + ! Shallow copy aux data to span. ! + \*--------------------------------------------------------*/ + if (data->codestream.aux) + { + header->aux.memory = data->codestream.aux->memory; + header->aux.size = data->codestream.aux->size; + } + + /*--------------------------------------------------------*\ + ! Shallow copy com data to span. ! + \*--------------------------------------------------------*/ + if (data->codestream.com) + { + header->com.memory = data->codestream.com->memory; + header->com.size = data->codestream.com->size; + } + + free(stream); + free(data); + free(codec); + + return header; +} + +/*================================================================================================*/ +/** + * @details This function closes the header information in the bwc_header pointer. + * + * @param[in] header Instance of type bwc_header. + */ +/*================================================================================================*/ +void bwc_close_header(bwc_header *const header) +{ + if (header) + { + if (header->aux.memory) + { + free(header->aux.memory); + } + if (header->com.memory) + { + free(header->com.memory); + } + free(header); + } +} + + /*----------------------------------------------------------------------------------------------------------*\ ! FUNCTION NAME: void bwc_create_compression(bwc_codec *codec, char *rate_control) ! ! -------------- ! diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index 8df4e9c..8ec216f 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -134,18 +134,18 @@ * @details String containing the header used for the cli output. */ /*================================================================================================*/ -static char bwc_header[] = "==============================================================\n"\ - " \n"\ - " .:-------------: .:-------------: \n"\ - " .+++++++++++++++= :+++++++++++++++- \n"\ - " :+++. -++= -++= \n"\ - " :+++. -++= -++= \n"\ - " -++++++++++++++= -++= -++= \n"\ - " .=++---------=++= -++= -++= \n"\ - " :+++ :++= -++= -++= \n"\ - " .+++=--------=+++---=+++---=+++------------: \n"\ - " -=++++++++++++++++++++++++++++++++++++++++- \n"\ - " \n"; +static char bwc_header_art[] = "==============================================================\n"\ + " \n"\ + " .:-------------: .:-------------: \n"\ + " .+++++++++++++++= :+++++++++++++++- \n"\ + " :+++. -++= -++= \n"\ + " :+++. -++= -++= \n"\ + " -++++++++++++++= -++= -++= \n"\ + " .=++---------=++= -++= -++= \n"\ + " :+++ :++= -++= -++= \n"\ + " .+++=--------=+++---=+++---=+++------------: \n"\ + " -=++++++++++++++++++++++++++++++++++++++++- \n"\ + " \n"; /*================================================================================================*/ /** @@ -1153,7 +1153,7 @@ int main(int argc, char *argv[]) } if (arguments.verbose == true) { - strcat(cli_verbose, bwc_header); + strcat(cli_verbose, bwc_header_art); strcat(cli_verbose, "--------------------------- I/O --------------------------\n\n"); sprintf(cli_buffer," Input: %s \n", arguments.in); -- 2.45.2 From d631f693c966e5b1693f59dbacceee4d2a11bee1 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Mon, 4 Nov 2024 15:45:14 +0100 Subject: [PATCH 39/53] initial decompression workflow in cmdl tool --- src/tools/bwccmdl.c | 119 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 2 deletions(-) diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index 8ec216f..d408b3f 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -78,6 +78,10 @@ "| ERROR: Invalid file type. |\n"\ "o##########################################################o\n" +#define FINERROR "o##########################################################o\n"\ + "| ERROR: Could not open specified input file. |\n"\ + "o##########################################################o\n" + #define FOUERROR "o##########################################################o\n"\ "| ERROR: Could not open specified output file. |\n"\ "o##########################################################o\n" @@ -1085,6 +1089,7 @@ int main(int argc, char *argv[]) ! DEFINE INT VARIABLES: ! \*-----------------------*/ uint64_t size = 0; + uint64_t root, Lfield; uint8_t i; uint8_t error_handle = EXIT_SUCCESS; @@ -1115,6 +1120,7 @@ int main(int argc, char *argv[]) ! DEFINE DER. VARIABLES: ! \*-----------------------*/ bwc_precision precision; + bwc_header *header; bwc_stream *stream = NULL; bwc_codec *coder = NULL; @@ -1165,7 +1171,6 @@ int main(int argc, char *argv[]) if ((arguments.optSet & FLOUT) == 0) arguments.out = arguments.in; - printf("%s \n", arguments.out); if ((buffer = strrchr(arguments.out, '.')) == NULL) { error_handle = EXIT_FAILURE; @@ -1439,7 +1444,117 @@ int main(int argc, char *argv[]) } else if (arguments.mode == cli_dcp) { - printf("Decompression\n"); + if ((fp = fopen(arguments.in, "r")) == NULL) + { + error_handle = EXIT_FAILURE; + printf(FINERROR); + goto OUT; + } + + root = ftell(fp); + fseek(fp, 0L, SEEK_END); + Lfield = ftell(fp) - root; + fseek(fp, root, SEEK_SET); + + if (arguments.verbose == true) + { + strcat(cli_verbose, bwc_header_art); + strcat(cli_verbose, "--------------------------- I/O --------------------------\n\n"); + + sprintf(cli_buffer," Input: %s \n", arguments.in); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + } + + /* Evaluate the appropriate output file. */ + if ((arguments.optSet & FLOUT) == 0) + arguments.out = arguments.in; + + if ((buffer = strrchr(arguments.out, '.')) == NULL) + { + error_handle = EXIT_FAILURE; + printf(TYPERROR); + goto OUT; + } + cli_output = calloc(strlen(arguments.out) - strlen(buffer) + 5, sizeof(char)); + if (cli_output == NULL) + { + error_handle = EXIT_FAILURE; + printf(MEMERROR); + goto OUT; + } + sprintf(cli_output, "%.*s.eas", (int)(strlen(arguments.out) - strlen(buffer)), arguments.out); + + if (arguments.verbose == true) + { + sprintf(cli_buffer," Output: %s \n", cli_output); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + } + + if ((arguments.verbose == true) && + (delim == true)) + { + + strcat(cli_verbose, " __________________________________________________________\n"); + strcat(cli_verbose, "\n"); + } + + if (arguments.verbose == true) + { + memset(cli_buffer, '0', sizeof(char) * 1024); + strcat(cli_verbose, "\n==============================================================\n"); + printf("%s", cli_verbose); + } + + /* Read the codestream from the specified file. */ + input = calloc(Lfield, sizeof(uchar)); + if (fread(input, sizeof(uchar), Lfield, fp) != Lfield) + { + error_handle = EXIT_FAILURE; + printf(RDERROR); + goto OUT; + } + + header = bwc_open_header(input); + + size = header->info.nX * header->info.nY * header->info.nZ * + header->info.nTS * header->info.nPar; + + if(header->info.data_prec == bwc_precision_double) + { + output = calloc(size, sizeof(double)); + } + else if(header->info.data_prec == bwc_precision_single) + { + output = calloc(size, sizeof(float)); + } + + bwc_close_header(header); + + stream = bwc_init_stream(input, output, comp); + coder = bwc_alloc_decoder(); + + //if (arguments.verbose == true) + //{ + //memset(cli_buffer, '0', sizeof(char) * 1024); + //strcat(cli_verbose, "\n==============================================================\n"); + //printf("%s", cli_verbose); + //} + + /* Initialize the rate control string according to the * + * specified bit rate/compression ratio. */ + if (bwc_create_decompression(coder, stream, 0) == EXIT_FAILURE) + { + error_handle = EXIT_FAILURE; + goto OUT; + } + + size = bwc_decompress(coder, stream); + + //write_eas3(output, cli_output); + + goto OUT; } else if (arguments.mode == cli_anl) { -- 2.45.2 From d1bfb5236afc49ac33ffde2495774688590b465e Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Tue, 5 Nov 2024 11:07:24 +0100 Subject: [PATCH 40/53] fill eas3_data form bwc_stream and bwc_codec --- src/tools/bwccmdl.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index d408b3f..cf7a4cc 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -1550,9 +1550,32 @@ int main(int argc, char *argv[]) goto OUT; } - size = bwc_decompress(coder, stream); + bwc_decompress(coder, stream); - //write_eas3(output, cli_output); + size = coder->info.nX * coder->info.nY * coder->info.nZ * + coder->info.nTS * coder->info.nPar; + + data->params.ndim1 = coder->info.nX; + data->params.ndim2 = coder->info.nY; + data->params.ndim3 = coder->info.nZ; + data->params.nts = coder->info.nTS; + data->params.npar = coder->info.nPar; + if (coder->info.data_prec == bwc_precision_single) + { + data->params.accuracy = 1; + data->field.d = NULL; + data->field.f = calloc(size, sizeof(float)); + memcpy(data->field.f, stream->out, size); + } + else if (coder->info.data_prec == bwc_precision_double) + { + data->params.accuracy = 2; + data->field.f = NULL; + data->field.d = calloc(size, sizeof(double)); + memcpy(data->field.d, stream->out, size); + } + + //write_eas3(data, cli_output); goto OUT; } -- 2.45.2 From 9167ec48f3062a62e9266ee7d5a1d603264db427 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Tue, 5 Nov 2024 11:09:13 +0100 Subject: [PATCH 41/53] doxygen in types.h --- include/library/private/types.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/include/library/private/types.h b/include/library/private/types.h index bba676d..06b49b6 100755 --- a/include/library/private/types.h +++ b/include/library/private/types.h @@ -672,18 +672,12 @@ bwc_span com; // Comment codestream block. } bwc_header; - /*----------------------------------------------------------------------------------------------*\ - ! ! - ! DESCRIPTION: ! - ! ------------ ! - ! ! - ! This structure holds all the necessary parameters defining and controling a bwc ! - ! (de-)compression run. ! - ! ! - ! The meter structure is used to store measurements, including important time ! - ! measurements, for a particular compression run. ! - ! ! - \*----------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Structure holding all the necessary parameters defining and controlling a bwc + * (de-)compression run. + */ +/*================================================================================================*/ typedef struct { bwc_gl_inf info; // Global info structure -- 2.45.2 From 55ad00d6c5fdb33d17008dc3484e2b5be9d81cd1 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Tue, 5 Nov 2024 11:10:00 +0100 Subject: [PATCH 42/53] fill eas3 auxiliary information in cmdl tool compression --- src/tools/bwccmdl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index cf7a4cc..38de588 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -1416,6 +1416,8 @@ int main(int argc, char *argv[]) printf("%s", cli_verbose); } + bwc_set_aux(stream, (char*)data->aux.ptr, data->aux.len); + /* Initialize the rate control string according to the * * specified bit rate/compression ratio. */ if (bwc_create_compression(coder, stream, rate) == EXIT_FAILURE) -- 2.45.2 From 5d5aafae37bb456ccaaf78897eb78003fdac5d48 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Tue, 5 Nov 2024 11:12:12 +0100 Subject: [PATCH 43/53] bug fixes in bwc_set_aux and bwc_set_com, both missing allocation of bwc_span --- src/library/libbwc.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/library/libbwc.c b/src/library/libbwc.c index 0beb985..b886f64 100755 --- a/src/library/libbwc.c +++ b/src/library/libbwc.c @@ -1498,8 +1498,9 @@ bwc_set_com(bwc_stream *const data, char const *const com, uint16 size) ! Save the global info structure to a temporary variable ! ! to make the code more readable. ! \*--------------------------------------------------------*/ + data->codestream.com = calloc(1, sizeof(bwc_span)); data->codestream.com->memory = calloc(size, sizeof(char)); - if(!data->codestream.com->memory) + if(!data->codestream.com->memory) { // memory allocation error fprintf(stderr, MEMERROR); @@ -1536,18 +1537,19 @@ bwc_set_aux(bwc_stream *const data, char const *const aux, uint32 size) ! Save the global info structure to a temporary variable ! ! to make the code more readable. ! \*--------------------------------------------------------*/ - data->codestream.com->memory = calloc(size, sizeof(char)); - if(!data->codestream.com->memory) + data->codestream.aux = calloc(1, sizeof(bwc_span)); + data->codestream.aux->memory = calloc(size, sizeof(char)); + if(!data->codestream.aux->memory) { // memory allocation error fprintf(stderr, MEMERROR); return 1; } - memcpy(data->codestream.com->memory, aux, size * sizeof(char)); - data->codestream.com->access = data->codestream.com->memory; - data->codestream.com->size = size; - data->codestream.com->position = 0; + memcpy(data->codestream.aux->memory, aux, size * sizeof(char)); + data->codestream.aux->access = data->codestream.aux->memory; + data->codestream.aux->size = size; + data->codestream.aux->position = 0; return 0; } -- 2.45.2 From d13354078bcac21d933f70328cedc09caa03ec7f Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Tue, 5 Nov 2024 18:43:45 +0100 Subject: [PATCH 44/53] enqueue parameter names in auxiliary information --- src/interfaces/reader/eas3.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 868f1bf..8b817ba 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -582,13 +582,9 @@ read_eas3_header(FILE *const fp, eas3_data *const data) return 1; } + aux_enqueue(data->aux, param_name, ATTRLEN * sizeof(char)); eas3_add_param_name(data, param_name); - /*--------------------------------------------------------*\ - ! Read the parameter name from the file stream and add all ! - ! the necessary parameter information to the paramter ! - ! linked list. | - \*--------------------------------------------------------*/ memset(param_name, 0, ATTRLEN + 1); } } -- 2.45.2 From d4acd85c37eac35c6ee1eb1ad46b339202bc4e97 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Tue, 5 Nov 2024 18:45:40 +0100 Subject: [PATCH 45/53] bwc_to_eas3 and writing decompressed data, tested output can be parsed to compress again --- include/interfaces/reader/eas3.h | 3 + src/interfaces/reader/eas3.c | 120 +++++++++++++++++++++++++++++++ src/tools/bwccmdl.c | 27 +------ 3 files changed, 126 insertions(+), 24 deletions(-) diff --git a/include/interfaces/reader/eas3.h b/include/interfaces/reader/eas3.h index c7d647b..266d91c 100644 --- a/include/interfaces/reader/eas3.h +++ b/include/interfaces/reader/eas3.h @@ -359,6 +359,9 @@ void eas3_free_data(eas3_data* data); + uchar + bwc_to_eas3(bwc_stream *const stream, eas3_data *const data); + /*----------------------------------------------------------------------------------------------------------*\ ! FUNCTION NAME: bwc_data* read_eas3(const char* const filename) ! ! -------------- ! diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 8b817ba..8bc999e 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -317,6 +317,118 @@ eas3_add_param_name(eas3_data *const data, char *name) strcpy(data->param_names->name, name ? name : "undefined"); } +/*================================================================================================*/ +/** + * @details Parses the uncompressed output from bwc_stream into the eas3_data. + * + * @param[in] stream Pointer to uncompressed data set. + * @param[inout] data Pointer to eas3_data structure to be filled. + * + * @retval uchar + */ +/*================================================================================================*/ +uchar +bwc_to_eas3(bwc_stream *const stream, eas3_data *const data) +{ + /*-----------------------*\ + ! DEFINE INT VARIABLES: ! + \*-----------------------*/ + uint64 Lread; + uint64 size; + uint64 i; + + /*-----------------------*\ + ! DEFINE CHAR VARIABLES: ! + \*-----------------------*/ + uchar *buffer_char; + char param_name[ATTRLEN + 1] = {}; + + /*-----------------------*\ + ! DEFINE STRUCTS: ! + \*-----------------------*/ + eas3_std_params *params; + + params = &data->params; + + data->aux.ptr = calloc(stream->codestream.aux->size, sizeof(uchar)); + data->aux.pos = 0; + data->aux.len = stream->codestream.aux->size; + if(!data->aux.ptr) + { + // memory allocation error + fprintf(stderr, MEMERROR); + free(data->aux.ptr); + return 1; + } + memcpy(data->aux.ptr, stream->codestream.aux->memory, + stream->codestream.aux->size); + + aux_dequeue(data->aux, (uchar*)params, 176); + + endian_conversion(¶ms->nts, 8); + endian_conversion(¶ms->npar, 8); + endian_conversion(¶ms->ndim1, 8); + endian_conversion(¶ms->ndim2, 8); + endian_conversion(¶ms->ndim3, 8); + endian_conversion(¶ms->accuracy, 8); + if(params->accuracy != 1 && params->accuracy != 2) + { + fprintf(stderr, "o##########################################################o\n"\ + "| ERROR: The accuracy of the specified dataset is not sup- |\n"\ + "| ported by the compression algorithm. |\n"\ + "o##########################################################o\n"); + return 1; + } + + buffer_char = calloc(params->nts, sizeof(uint64)); + if(!buffer_char) + { + // memory allocation error + fprintf(stderr, MEMERROR); + free(buffer_char); + return 1; + } + aux_dequeue(data->aux, buffer_char, params->nts * sizeof(uint64)); + + if(params->attribute_mode == EAS3_ALL_ATTR) + { + buffer_char = realloc(buffer_char, params->nts * ATTRLEN * sizeof(char)); + if(!buffer_char) + { + // memory allocation error + fprintf(stderr, MEMERROR); + free(buffer_char); + return 1; + } + aux_dequeue(data->aux, buffer_char, params->nts * ATTRLEN * sizeof(char)); + + for(i = 0; i < params->npar; ++i) + { + aux_dequeue(data->aux, param_name, ATTRLEN * sizeof(char)); + eas3_add_param_name(data, param_name); + memset(param_name, 0, ATTRLEN + 1); + } + } + + size = params->ndim1 * params->ndim2 * params->ndim3 * + params->nts * params->npar; + + if(params->accuracy == 1) + { + data->field.d = NULL; + data->field.f = calloc(size, sizeof(float)); + memcpy(data->field.f, stream->out, size); + } + else if(params->accuracy == 2) + { + data->field.f = NULL; + data->field.d = calloc(size, sizeof(double)); + memcpy(data->field.d, stream->out, size); + } + + return 0; +} + /*----------------------------------------------------------------------------------------------------------*\ ! FUNCTION NAME: uchar read_eas3_header(bwc_data *const data) ! ! -------------- ! @@ -756,7 +868,13 @@ write_eas3_header(FILE *const fp, eas3_data *const data) ! Convert the size parameters, used to write the rest of ! ! the header, to little endian. ! \*--------------------------------------------------------*/ + endian_conversion(¶ms->file_type, 8); endian_conversion(¶ms->accuracy, 8); + endian_conversion(¶ms->nts, 8); + endian_conversion(¶ms->npar, 8); + endian_conversion(¶ms->ndim1, 8); + endian_conversion(¶ms->ndim2, 8); + endian_conversion(¶ms->ndim3, 8); endian_conversion(¶ms->size_time, 8); endian_conversion(¶ms->size_parameter, 8); endian_conversion(¶ms->size_dim1, 8); @@ -766,6 +884,8 @@ write_eas3_header(FILE *const fp, eas3_data *const data) endian_conversion(¶ms->udef_int_size, 8); endian_conversion(¶ms->udef_real_size, 8); + data->params = *params; + /*--------------------------------------------------------*\ ! Allocate the buffer character array. If successful, get ! ! the timestep array from the auxiliary information block ! diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index 38de588..2651b2c 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -1554,30 +1554,9 @@ int main(int argc, char *argv[]) bwc_decompress(coder, stream); - size = coder->info.nX * coder->info.nY * coder->info.nZ * - coder->info.nTS * coder->info.nPar; - - data->params.ndim1 = coder->info.nX; - data->params.ndim2 = coder->info.nY; - data->params.ndim3 = coder->info.nZ; - data->params.nts = coder->info.nTS; - data->params.npar = coder->info.nPar; - if (coder->info.data_prec == bwc_precision_single) - { - data->params.accuracy = 1; - data->field.d = NULL; - data->field.f = calloc(size, sizeof(float)); - memcpy(data->field.f, stream->out, size); - } - else if (coder->info.data_prec == bwc_precision_double) - { - data->params.accuracy = 2; - data->field.f = NULL; - data->field.d = calloc(size, sizeof(double)); - memcpy(data->field.d, stream->out, size); - } - - //write_eas3(data, cli_output); + data = calloc(1, sizeof(eas3_data)); + bwc_to_eas3(stream, data); + write_eas3(data, cli_output); goto OUT; } -- 2.45.2 From 1a087c1c857bf518a44b5a08192593280cce0d08 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Wed, 6 Nov 2024 15:42:56 +0100 Subject: [PATCH 46/53] Update docstrings in eas3.c --- src/interfaces/reader/eas3.c | 260 ++++++++++------------------------- 1 file changed, 75 insertions(+), 185 deletions(-) diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index 8bc999e..f3e2985 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -102,15 +102,11 @@ || | | \ | \/ | | | |___ | |__| | \| |___ | | |__| | \| ___] || || || \************************************************************************************************************/ - -/*----------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This macro is used to write an additional chunck of size length to the auxilliary ! -! information. ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Enqueues a chunck of size length to the auxilliary information. + */ +/*================================================================================================*/ #define aux_enqueue(aux, chunck, chunck_len) \ { \ if (aux.pos + chunck_len > aux.len) \ @@ -125,6 +121,11 @@ aux.pos += chunck_len; \ } +/*================================================================================================*/ +/** + * @details Dequeues a chunck of size length from the auxilliary information. + */ +/*================================================================================================*/ #define aux_dequeue(aux, chunck, chunck_len) \ { \ if(aux.pos + chunck_len <= aux.len) { \ @@ -135,37 +136,14 @@ } \ } -/*----------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function converts the endianess of half, single or double precision values. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! value void* - Memory address of the parame- ! -! ter to be converted. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description ! -! ---- ------ --------- ------- ----------- ! -! 30.04.2019 Patrick Vogler B87D120 V 0.1.0 function created ! -! 21.11.2019 Patrick Vogler B87E7E4 V 0.1.0 functionality expanded ! -! to 32 bit integers ! -! 21.11.2019 Patrick Vogler B87E7E4 V 0.1.0 functionality expanded ! -! to 16 bit integers ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Converts the endianess of half, single, or double precision values. + * + * @param[inout] value Pointer to the parameter to be converted. + * @param[in] accuracy Precision/accuracy of the pointed parameter. + */ +/*================================================================================================*/ static void endian_conversion(void *value, uint8_t const accuracy) @@ -219,15 +197,13 @@ endian_conversion(void *value, } } -/*----------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function deallocates the data structure used to store a numerical dataset ! -! and can be called if an error occurs or once the data is no longer needed. ! -! The deallocation will be carried out down to the structure levels that have been allocated. ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Deallocates the provided eas3_data structure including all contained data. + * + * @param[in] data Pointer to eas3_data structure to be filled. + */ +/*================================================================================================*/ void eas3_free_data(eas3_data* data) { @@ -263,6 +239,14 @@ eas3_free_data(eas3_data* data) } } +/*================================================================================================*/ +/** + * @details Adds a parameter name to the linked list inside the eas3_data structure. + * + * @param[in] data Pointer to eas3_data structure to be filled. + * @param[in] name Name to be added to the linked list. + */ +/*================================================================================================*/ void eas3_add_param_name(eas3_data *const data, char *name) { @@ -429,40 +413,17 @@ bwc_to_eas3(bwc_stream *const stream, eas3_data *const data) return 0; } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar read_eas3_header(bwc_data *const data) ! -! -------------- ! -! ! -! 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. ! -! ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! filename char* - Defines the filename of the eas3 file ! -! that is to be opened and read. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! file - Defines a structure used to store all ! -! the relevant parameters and the data ! -! field of an eas3 file. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 20.06.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Reads the header from an open eas3 file pointer parsing the header information into + * the eas3_data structure argument. + * + * @param[in] fp Readily opened file pointer. + * @param[inout] data Structure to store eas3 data. + * + * @retval uchar + */ +/*================================================================================================*/ static uchar read_eas3_header(FILE *const fp, eas3_data *const data) { @@ -772,40 +733,17 @@ read_eas3_header(FILE *const fp, eas3_data *const data) return 0; } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar read_eas3_header(bwc_data *const data) ! -! -------------- ! -! ! -! 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. ! -! ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! filename char* - Defines the filename of the eas3 file ! -! that is to be opened and read. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! file - Defines a structure used to store all ! -! the relevant parameters and the data ! -! field of an eas3 file. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 20.06.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Writes the header information from the eas3_data structure into the open eas3 + * file pointer. + * + * @param[in] fp Readily opened file pointer. + * @param[inout] data Structure to store eas3 data. + * + * @retval uchar + */ +/*================================================================================================*/ static uchar write_eas3_header(FILE *const fp, eas3_data *const data) { @@ -1019,40 +957,16 @@ write_eas3_header(FILE *const fp, eas3_data *const data) || | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] || || || \************************************************************************************************************/ -/*----------------------------------------------------------------------------------------------------------*\ -! 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. ! -! ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! filename char* - Defines the filename of the eas3 file ! -! that is to be opened and read. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! file - Defines a structure used to store all ! -! the relevant parameters and the data ! -! field of an eas3 file. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 20.06.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Opens an eas3 file and checks it for its validity. Then, it reads header and flow + * field data and returns a filled instance of the eas3_data structure. + * + * @param[in] filename Name of the eas3 file. + * + * @retval eas3_data* + */ +/*================================================================================================*/ eas3_data* read_eas3(char *const filename) { @@ -1215,40 +1129,16 @@ read_eas3(char *const filename) return data; } -/*----------------------------------------------------------------------------------------------------------*\ -! 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. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! filename char* - Defines the filename of the eas3 file ! -! that is to be opened and read. ! -! ! -! file bwc_data* - Defines a structure used to store all ! -! the relevant parameters and the data ! -! field of an eas3 file. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! uchar - Returns an unsigned char for error handling. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 20.06.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Opens an eas3 file and writes the content from the provided eas3_data structure. + * + * @param[in] data Data to be written into the eas3 file. + * @param[in] filename Name of the eas3 file. + * + * @retval uchar + */ +/*================================================================================================*/ uchar write_eas3(eas3_data *const data, char *const filename) { -- 2.45.2 From acf703f6502efa1ef869068af0380a1c0cdc59b1 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Wed, 6 Nov 2024 17:23:09 +0100 Subject: [PATCH 47/53] refactor/clean up in cmdl tool --- src/tools/bwccmdl.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index 2651b2c..20a1ce9 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -1219,6 +1219,7 @@ int main(int argc, char *argv[]) data->params.nts, data->params.npar, precision); + bwc_set_aux(stream, (char*)data->aux.ptr, data->aux.len); /* Apply the user supplied compression options using the * * appropriate setter functions. */ @@ -1416,8 +1417,6 @@ int main(int argc, char *argv[]) printf("%s", cli_verbose); } - bwc_set_aux(stream, (char*)data->aux.ptr, data->aux.len); - /* Initialize the rate control string according to the * * specified bit rate/compression ratio. */ if (bwc_create_compression(coder, stream, rate) == EXIT_FAILURE) @@ -1494,14 +1493,6 @@ int main(int argc, char *argv[]) memset(cli_buffer, '0', sizeof(char) * 1024); } - if ((arguments.verbose == true) && - (delim == true)) - { - - strcat(cli_verbose, " __________________________________________________________\n"); - strcat(cli_verbose, "\n"); - } - if (arguments.verbose == true) { memset(cli_buffer, '0', sizeof(char) * 1024); @@ -1509,7 +1500,7 @@ int main(int argc, char *argv[]) printf("%s", cli_verbose); } - /* Read the codestream from the specified file. */ + /* Read the compressed data from the input file. */ input = calloc(Lfield, sizeof(uchar)); if (fread(input, sizeof(uchar), Lfield, fp) != Lfield) { @@ -1518,11 +1509,10 @@ int main(int argc, char *argv[]) goto OUT; } + /* Retrieve header information and allocate output buffer. */ header = bwc_open_header(input); - size = header->info.nX * header->info.nY * header->info.nZ * header->info.nTS * header->info.nPar; - if(header->info.data_prec == bwc_precision_double) { output = calloc(size, sizeof(double)); @@ -1531,29 +1521,20 @@ int main(int argc, char *argv[]) { output = calloc(size, sizeof(float)); } - bwc_close_header(header); + /* Initialize and run the decompression. */ stream = bwc_init_stream(input, output, comp); coder = bwc_alloc_decoder(); - - //if (arguments.verbose == true) - //{ - //memset(cli_buffer, '0', sizeof(char) * 1024); - //strcat(cli_verbose, "\n==============================================================\n"); - //printf("%s", cli_verbose); - //} - - /* Initialize the rate control string according to the * - * specified bit rate/compression ratio. */ if (bwc_create_decompression(coder, stream, 0) == EXIT_FAILURE) { error_handle = EXIT_FAILURE; goto OUT; } - bwc_decompress(coder, stream); + /* Parse decompressed data into eas3 data structure * + * and write to the output file. */ data = calloc(1, sizeof(eas3_data)); bwc_to_eas3(stream, data); write_eas3(data, cli_output); -- 2.45.2 From 6176fea67667d79931cdd4f0ea1908321626284d Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Thu, 7 Nov 2024 10:32:38 +0100 Subject: [PATCH 48/53] header info mode --- src/tools/bwccmdl.c | 115 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index 20a1ce9..c85ce50 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -1547,7 +1547,120 @@ int main(int argc, char *argv[]) } else if (arguments.mode == cli_inf) { - printf("Header Info\n"); + strcat(cli_verbose, bwc_header_art); + strcat(cli_verbose, "--------------------------- I/O --------------------------\n\n"); + sprintf(cli_buffer," Input: %s \n", arguments.in); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + + if ((fp = fopen(arguments.in, "r")) == NULL) + { + error_handle = EXIT_FAILURE; + printf(FINERROR); + goto OUT; + } + + root = ftell(fp); + fseek(fp, 0L, SEEK_END); + Lfield = ftell(fp) - root; + fseek(fp, root, SEEK_SET); + + /* Read the compressed data from the input file. */ + input = calloc(Lfield, sizeof(uchar)); + if (fread(input, sizeof(uchar), Lfield, fp) != Lfield) + { + error_handle = EXIT_FAILURE; + printf(RDERROR); + goto OUT; + } + + /* Retrieve header information and allocate output buffer. */ + header = bwc_open_header(input); + size = header->info.nX * header->info.nY * header->info.nZ * + header->info.nTS * header->info.nPar; + if(header->info.data_prec == bwc_precision_double) + { + output = calloc(size, sizeof(double)); + } + else if(header->info.data_prec == bwc_precision_single) + { + output = calloc(size, sizeof(float)); + } + bwc_close_header(header); + + strcat(cli_verbose, "\n"); + strcat(cli_verbose, "----------------- Compression Parameters -----------------\n"); + strcat(cli_verbose, "\n"); + + strcat(cli_verbose," Tile Size: \n"); + sprintf(cli_buffer," - Samples in 1.D: %27ld\n"\ + " - Samples in 2.D: %27ld\n"\ + " - Samples in 3.D: %27ld\n"\ + " - Samples in 4.D: %27ld\n", header->control.tileSizeX, + header->control.tileSizeY, + header->control.tileSizeZ, + header->control.tileSizeTS); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + + strcat(cli_verbose, " __________________________________________________________\n"); + strcat(cli_verbose, "\n"); + strcat(cli_verbose, " 1.D | 2.D | 3.D | 4.D\n"); + sprintf(cli_buffer, " Decomposition Levels: %18d |%4d |%4d |%4d\n", + header->control.decompX, + header->control.decompY, + header->control.decompZ, + header->control.decompTS); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + + sprintf(cli_buffer, " Precincts [log2]: %18d |%4d |%4d |%4d\n", + header->control.precSizeX, + header->control.precSizeY, + header->control.precSizeZ, + header->control.precSizeTS); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + + sprintf(cli_buffer, " Codeblocks [log2]: %18d |%4d |%4d |%4d\n", + header->control.cbX, + header->control.cbY, + header->control.cbZ, + header->control.cbTS); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + + strcat(cli_verbose, " __________________________________________________________\n"); + strcat(cli_verbose, "\n"); + + sprintf(cli_buffer, " Q Number Format: %27d\n", header->control.Qm); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + + if (header->control.error_resilience) + { + sprintf(cli_buffer, " Error Resilience: %27s\n", "true"); + } + else + { + sprintf(cli_buffer, " Error Resilience: %27s\n", "false"); + } + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + + strcat(cli_verbose, " __________________________________________________________\n"); + strcat(cli_verbose, "\n"); + + for(i = 0; i < header->control.nLayers; ++i) + { + sprintf(cli_buffer, " Quality Layer Nr. %d: %33.2f bpd\n", i, + header->control.bitrate[i]); + strcat(cli_verbose, cli_buffer); + } + + memset(cli_buffer, '0', sizeof(char) * 1024); + strcat(cli_verbose, "\n==============================================================\n"); + printf("%s", cli_verbose); } else { -- 2.45.2 From 742fb3bc786e5ae295d94afaa998d833f416b71d Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Thu, 7 Nov 2024 13:41:38 +0100 Subject: [PATCH 49/53] mse and psnr analysis --- src/tools/bwccmdl.c | 173 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 172 insertions(+), 1 deletion(-) diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index c85ce50..85b139c 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -115,6 +115,14 @@ #define TILES 0x0004 #define USQLY 0x0002 +/*================================================================================================*/ +/** + * @details Macros to determine the minimum or maximum of two values. + */ +/*===========================================================================|====================*/ +#define MAX(x, y) (((x) < (y))?(y):(x)) // Returns maximum between two values +#define MIN(x, y) (((x) > (y))?(y):(x)) // Returns minimum between two values + /*================================================================================================*/ /** * @details This macro defines a simple operation to remove a supplied deliminator from a string. @@ -1059,6 +1067,105 @@ parse_opt(int key, return EXIT_SUCCESS; } +static uchar +output_analysis(eas3_data *const ref_data, eas3_data *const org_data) +{ + /*-----------------------*\ + ! DEFINE INT VARIABLES: ! + \*-----------------------*/ + uint64_t size; + uint64_t i; + + uint8_t p; + + /*-----------------------*\ + ! DEFINE FLOAT VARIABLES: ! + \*-----------------------*/ + double MSE, PSNR; + double peakVal; + double sum; + + double *dOrig, *dRef; + float *fOrig, *fRef; + + bwc_float minVal, maxVal; + + /*-----------------------*\ + ! DEFINE STRUCTS: ! + \*-----------------------*/ + eas3_param_names *param_name; + + dOrig = org_data->field.d; + dRef = ref_data->field.d; + + fOrig = org_data->field.f; + fRef = ref_data->field.f; + + if(org_data->params.ndim1 == ref_data->params.ndim1 && + org_data->params.ndim2 == ref_data->params.ndim2 && + org_data->params.ndim3 == ref_data->params.ndim3 && + org_data->params.nts == ref_data->params.nts && + org_data->params.npar == ref_data->params.npar) + { + size = (uint64_t)ref_data->params.ndim1 * ref_data->params.ndim2 * + ref_data->params.ndim3 * ref_data->params.nts; + + peakVal = -1.7976931348623157e+308; + PSNR = + MSE = 0; + + if(ref_data->param_names) + { + param_name = ref_data->param_names->root; + p = 0; + while(param_name != NULL) + { + minVal = 1.7976931348623157e+308; + maxVal = -1.7976931348623157e+308; + + if(ref_data->params.accuracy == 2) + { + for(i = 0; i < size; ++i) + { + minVal = MIN(minVal, (double)dRef[i + p * size]); + maxVal = MAX(maxVal, (double)dRef[i + p * size]); + + sum = ((double)dRef[i + p * size] - (double)dOrig[i + p * size]); + + MSE += sum * sum; + } + } + else if(ref_data->params.accuracy == 1) + { + for(i = 0; i < size; ++i) + { + minVal = MIN(minVal, (double)fRef[i + p * size]); + maxVal = MAX(maxVal, (double)fRef[i + p * size]); + + sum = ((double)fRef[i + p * size] - (double)fOrig[i + p * size]); + + MSE += sum * sum; + } + } + peakVal = MAX(peakVal, maxVal - minVal); + param_name = param_name->next; + p++; + } + } + + MSE /= (double)size * ref_data->params.npar; + PSNR = 20 * log10(peakVal/(2 * sqrt(MSE))); + + printf("==============================================================\n"); + printf(" Mean Square Error: %*.2e\n", 22, MSE); + printf(" Peak Signal-to-Noise Ratio: %*.2f\n", 22, PSNR); + printf("==============================================================\n"); + + } + + return EXIT_SUCCESS; +} + /*================================================================================================*/ /** * @details Initialize the argp struct. used to parse the command line arguments @@ -1128,6 +1235,7 @@ int main(int argc, char *argv[]) ! DEFINE STRUCTS: ! \*-----------------------*/ eas3_data *data = NULL; + eas3_data *ref_data = NULL; cli_arguments arguments = {0}; /* Parse the command line arguments and invoke the appro- * @@ -1543,7 +1651,67 @@ int main(int argc, char *argv[]) } else if (arguments.mode == cli_anl) { - printf("Analysis\n"); + /* Ingest the reference data input. */ + if ((ref_data = read_eas3(arguments.ref)) == NULL) + { + error_handle = EXIT_FAILURE; + goto OUT; + } + + /* Ingest the compressed data input. */ + if ((fp = fopen(arguments.in, "r")) == NULL) + { + error_handle = EXIT_FAILURE; + printf(FINERROR); + goto OUT; + } + + root = ftell(fp); + fseek(fp, 0L, SEEK_END); + Lfield = ftell(fp) - root; + fseek(fp, root, SEEK_SET); + + /* Read the compressed data from the input file. */ + input = calloc(Lfield, sizeof(uchar)); + if (fread(input, sizeof(uchar), Lfield, fp) != Lfield) + { + error_handle = EXIT_FAILURE; + printf(RDERROR); + goto OUT; + } + + /* Retrieve header information and allocate output buffer. */ + header = bwc_open_header(input); + size = header->info.nX * header->info.nY * header->info.nZ * + header->info.nTS * header->info.nPar; + if(header->info.data_prec == bwc_precision_double) + { + output = calloc(size, sizeof(double)); + } + else if(header->info.data_prec == bwc_precision_single) + { + output = calloc(size, sizeof(float)); + } + bwc_close_header(header); + + /* Initialize and run the decompression. */ + stream = bwc_init_stream(input, output, comp); + coder = bwc_alloc_decoder(); + if (bwc_create_decompression(coder, stream, 0) == EXIT_FAILURE) + { + error_handle = EXIT_FAILURE; + goto OUT; + } + bwc_decompress(coder, stream); + + /* Parse decompressed data into eas3 data structure * + * and write to the output file. */ + data = calloc(1, sizeof(eas3_data)); + bwc_to_eas3(stream, data); + + output_analysis(ref_data, data); + + goto OUT; } else if (arguments.mode == cli_inf) { @@ -1674,6 +1842,9 @@ OUT: if (data != NULL) eas3_free_data(data); + if (ref_data != NULL) + eas3_free_data(ref_data); + if (stream !=NULL) free(stream); -- 2.45.2 From 64eeda9072d85e236fde950f59ee765dae9a8abf Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Thu, 7 Nov 2024 13:42:16 +0100 Subject: [PATCH 50/53] bug fix; wrong size in memcpy --- src/interfaces/reader/eas3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interfaces/reader/eas3.c b/src/interfaces/reader/eas3.c index f3e2985..4ab8203 100644 --- a/src/interfaces/reader/eas3.c +++ b/src/interfaces/reader/eas3.c @@ -401,13 +401,13 @@ bwc_to_eas3(bwc_stream *const stream, eas3_data *const data) { data->field.d = NULL; data->field.f = calloc(size, sizeof(float)); - memcpy(data->field.f, stream->out, size); + memcpy(data->field.f, stream->out, size*sizeof(float)); } else if(params->accuracy == 2) { data->field.f = NULL; data->field.d = calloc(size, sizeof(double)); - memcpy(data->field.d, stream->out, size); + memcpy(data->field.d, stream->out, size*sizeof(double)); } return 0; -- 2.45.2 From a84768bbec408dea09442487589b41b1eb09b2ce Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Thu, 7 Nov 2024 16:26:20 +0100 Subject: [PATCH 51/53] refactor; print (verbose) header, I/O, and control parameters --- src/tools/bwccmdl.c | 405 +++++++++++++++++--------------------------- 1 file changed, 154 insertions(+), 251 deletions(-) diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index 85b139c..a5bd7b2 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -1067,6 +1067,121 @@ parse_opt(int key, return EXIT_SUCCESS; } +void +printheaderIO(char const *input, char const *output, char const *reference) +{ + /*-----------------------*\ + ! DEFINE CHAR VARIABLES: ! + \*-----------------------*/ + char cli_buffer[1024] = {0}; + char cli_verbose[4096] = {0}; + + strcat(cli_verbose, bwc_header_art); + strcat(cli_verbose, "--------------------------- I/O --------------------------\n\n"); + + sprintf(cli_buffer," Input: %s \n", input); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + + sprintf(cli_buffer," Output: %s \n", output); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + + sprintf(cli_buffer," Reference: %s \n", reference); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + printf("%s", cli_verbose); +} + +void +printctrl(bwc_gl_ctrl *const control) +{ + /*-----------------------*\ + ! DEFINE INT VARIABLES: ! + \*-----------------------*/ + uint8_t i; + + /*-----------------------*\ + ! DEFINE CHAR VARIABLES: ! + \*-----------------------*/ + char cli_buffer[1024] = {0}; + char cli_verbose[4096] = {0}; + + strcat(cli_verbose, "\n"); + strcat(cli_verbose, "----------------- Compression Parameters -----------------\n"); + strcat(cli_verbose, "\n"); + + strcat(cli_verbose," Tile Size: \n"); + sprintf(cli_buffer," - Samples in 1.D: %27ld\n"\ + " - Samples in 2.D: %27ld\n"\ + " - Samples in 3.D: %27ld\n"\ + " - Samples in 4.D: %27ld\n", control->tileSizeX, + control->tileSizeY, + control->tileSizeZ, + control->tileSizeTS); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + + strcat(cli_verbose, " __________________________________________________________\n"); + strcat(cli_verbose, "\n"); + strcat(cli_verbose, " 1.D | 2.D | 3.D | 4.D\n"); + sprintf(cli_buffer, " Decomposition Levels: %18d |%4d |%4d |%4d\n", + control->decompX, + control->decompY, + control->decompZ, + control->decompTS); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + + sprintf(cli_buffer, " Precincts [log2]: %18d |%4d |%4d |%4d\n", + control->precSizeX, + control->precSizeY, + control->precSizeZ, + control->precSizeTS); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + + sprintf(cli_buffer, " Codeblocks [log2]: %18d |%4d |%4d |%4d\n", + control->cbX, + control->cbY, + control->cbZ, + control->cbTS); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + + strcat(cli_verbose, " __________________________________________________________\n"); + strcat(cli_verbose, "\n"); + + sprintf(cli_buffer, " Q Number Format: %27d\n", control->Qm); + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + + if (control->error_resilience) + { + sprintf(cli_buffer, " Error Resilience: %27s\n", "true"); + } + else + { + sprintf(cli_buffer, " Error Resilience: %27s\n", "false"); + } + strcat(cli_verbose, cli_buffer); + memset(cli_buffer, '0', sizeof(char) * 1024); + + strcat(cli_verbose, " __________________________________________________________\n"); + strcat(cli_verbose, "\n"); + + for(i = 0; i < control->nLayers; ++i) + { + sprintf(cli_buffer, " Quality Layer Nr. %d: %33.2f bpd\n", i, + control->bitrate[i]); + strcat(cli_verbose, cli_buffer); + } + + memset(cli_buffer, '0', sizeof(char) * 1024); + strcat(cli_verbose, "\n==============================================================\n"); + printf("%s", cli_verbose); +} + static uchar output_analysis(eas3_data *const ref_data, eas3_data *const org_data) { @@ -1209,8 +1324,6 @@ int main(int argc, char *argv[]) ! DEFINE CHAR VARIABLES: ! \*-----------------------*/ char rate[200] = {0}; - char cli_buffer[1024] = {0}; - char cli_verbose[4096] = {0}; char *cli_output = NULL; char *buffer = NULL; @@ -1255,30 +1368,9 @@ int main(int argc, char *argv[]) /* Compress the user supplied data set. */ if (arguments.mode == cli_cmp) { - - /* Ingest the bwccmdl input and set the appropriate cli_ * - * verbose message if the option is set. */ - // TODO: Define a universal data structure and implement a reader - // that ingests different file formats - if ((data = read_eas3(arguments.in)) == NULL) - { - error_handle = EXIT_FAILURE; - goto OUT; - } - if (arguments.verbose == true) - { - strcat(cli_verbose, bwc_header_art); - strcat(cli_verbose, "--------------------------- I/O --------------------------\n\n"); - - sprintf(cli_buffer," Input: %s \n", arguments.in); - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); - } - /* Evaluate the appropriate output file. */ if ((arguments.optSet & FLOUT) == 0) arguments.out = arguments.in; - if ((buffer = strrchr(arguments.out, '.')) == NULL) { error_handle = EXIT_FAILURE; @@ -1296,9 +1388,15 @@ int main(int argc, char *argv[]) if (arguments.verbose == true) { - sprintf(cli_buffer," Output: %s \n", cli_output); - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); + printheaderIO(arguments.in, cli_output, arguments.ref); + } + + // TODO: Define a universal data structure and implement a reader + // that ingests different file formats + if ((data = read_eas3(arguments.in)) == NULL) + { + error_handle = EXIT_FAILURE; + goto OUT; } /* Evaluate the input and output buffer size and initial- * @@ -1329,15 +1427,6 @@ int main(int argc, char *argv[]) precision); bwc_set_aux(stream, (char*)data->aux.ptr, data->aux.len); - /* Apply the user supplied compression options using the * - * appropriate setter functions. */ - if (arguments.verbose == true) - { - strcat(cli_verbose, "\n"); - strcat(cli_verbose, "----------------- Compression Parameters -----------------\n"); - strcat(cli_verbose, "\n"); - } - if ((arguments.optSet & TILES) != 0) { bwc_set_tiles(coder, arguments.tileSize[0], @@ -1345,20 +1434,6 @@ int main(int argc, char *argv[]) arguments.tileSize[2], arguments.tileSize[3], bwc_tile_sizeof); - if (arguments.verbose == true) - { - strcat(cli_verbose," Tile Size: \n"); - sprintf(cli_buffer," - Samples in 1.D: %27ld\n"\ - " - Samples in 2.D: %27ld\n"\ - " - Samples in 3.D: %27ld\n"\ - " - Samples in 4.D: %27ld\n", arguments.tileSize[0], - arguments.tileSize[1], - arguments.tileSize[2], - arguments.tileSize[3]); - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); - delim = true; - } } // TODO: Implement the kernel setter as a global function @@ -1371,35 +1446,12 @@ int main(int argc, char *argv[]) arguments.dwtKernel[3]); }*/ - if ((arguments.verbose == true) && - ((arguments.optSet & (DCLVL | PRECS | CBLKS)) != 0)) - { - if (delim == true) - { - strcat(cli_verbose, " __________________________________________________________\n"); - strcat(cli_verbose, "\n"); - } - strcat(cli_verbose, " 1.D | 2.D | 3.D | 4.D\n"); - delim = true; - } - if ((arguments.optSet & DCLVL) != 0) { bwc_set_decomp(coder, arguments.decompLevel[0], arguments.decompLevel[1], arguments.decompLevel[2], arguments.decompLevel[3]); - - if (arguments.verbose == true) - { - sprintf(cli_buffer, " Decomposition Levels: %18d |%4d |%4d |%4d\n", - arguments.decompLevel[0], - arguments.decompLevel[1], - arguments.decompLevel[2], - arguments.decompLevel[3]); - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); - } } if ((arguments.optSet & PRECS) != 0) @@ -1408,17 +1460,6 @@ int main(int argc, char *argv[]) arguments.precSize[1], arguments.precSize[2], arguments.precSize[3]); - - if (arguments.verbose == true) - { - sprintf(cli_buffer, " Precincts [log2]: %18d |%4d |%4d |%4d\n", - arguments.precSize[0], - arguments.precSize[1], - arguments.precSize[2], - arguments.precSize[3]); - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); - } } if ((arguments.optSet & CBLKS) != 0) @@ -1427,64 +1468,21 @@ int main(int argc, char *argv[]) arguments.cblkSize[1], arguments.cblkSize[2], arguments.cblkSize[3]); - - if (arguments.verbose == true) - { - sprintf(cli_buffer, " Codeblocks [log2]: %18d |%4d |%4d |%4d\n", - arguments.cblkSize[0], - arguments.cblkSize[1], - arguments.cblkSize[2], - arguments.cblkSize[3]); - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); - } - } - - if ((arguments.verbose == true) && - (delim == true) && - (((arguments.optSet & QFRMT) != 0) || arguments.erresilience == true)) - { - - strcat(cli_verbose, " __________________________________________________________\n"); - strcat(cli_verbose, "\n"); } if ((arguments.optSet & QFRMT) != 0) { bwc_set_qm(coder, arguments.Qm); - - if (arguments.verbose == true) - { - sprintf(cli_buffer, " Q Number Format: %27d\n", arguments.Qm); - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); - delim = true; - } } if (arguments.erresilience == true) { bwc_set_error_resilience(coder); - if (arguments.verbose == true) - { - sprintf(cli_buffer, " Error Resilience: %27s\n", "true"); - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); - delim = true; - } } /* Initialize the rate control string according to the * * specified bit rate/compression ratio. */ - if ((arguments.verbose == true) && - (delim == true)) - { - - strcat(cli_verbose, " __________________________________________________________\n"); - strcat(cli_verbose, "\n"); - } - if ((arguments.optSet & BITRT) != 0) { rtype = 1.0; @@ -1507,32 +1505,21 @@ int main(int argc, char *argv[]) if (arguments.rate[i] > 0) { sprintf(rate + strlen(rate), "%05.3f,", pow(arguments.rate[i]/rtype, exp)); - - if (arguments.verbose == true) - { - sprintf(cli_buffer, " Quality Layer Nr. %d: %33.2f bpd\n", i, - pow(arguments.rate[i]/rtype, exp)); - strcat(cli_verbose, cli_buffer); - } } } rate[strlen(rate) - 1] = '0'; - if (arguments.verbose == true) - { - memset(cli_buffer, '0', sizeof(char) * 1024); - strcat(cli_verbose, "\n==============================================================\n"); - printf("%s", cli_verbose); - } - - /* Initialize the rate control string according to the * - * specified bit rate/compression ratio. */ if (bwc_create_compression(coder, stream, rate) == EXIT_FAILURE) { error_handle = EXIT_FAILURE; goto OUT; } + if(arguments.verbose == true) + { + printctrl(&coder->control); + } + size = bwc_compress(coder, stream); /* Write the codestream to the speicifed file. */ @@ -1553,32 +1540,9 @@ int main(int argc, char *argv[]) } else if (arguments.mode == cli_dcp) { - if ((fp = fopen(arguments.in, "r")) == NULL) - { - error_handle = EXIT_FAILURE; - printf(FINERROR); - goto OUT; - } - - root = ftell(fp); - fseek(fp, 0L, SEEK_END); - Lfield = ftell(fp) - root; - fseek(fp, root, SEEK_SET); - - if (arguments.verbose == true) - { - strcat(cli_verbose, bwc_header_art); - strcat(cli_verbose, "--------------------------- I/O --------------------------\n\n"); - - sprintf(cli_buffer," Input: %s \n", arguments.in); - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); - } - /* Evaluate the appropriate output file. */ if ((arguments.optSet & FLOUT) == 0) arguments.out = arguments.in; - if ((buffer = strrchr(arguments.out, '.')) == NULL) { error_handle = EXIT_FAILURE; @@ -1596,18 +1560,21 @@ int main(int argc, char *argv[]) if (arguments.verbose == true) { - sprintf(cli_buffer," Output: %s \n", cli_output); - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); + printheaderIO(arguments.in, cli_output, arguments.ref); } - if (arguments.verbose == true) + if ((fp = fopen(arguments.in, "r")) == NULL) { - memset(cli_buffer, '0', sizeof(char) * 1024); - strcat(cli_verbose, "\n==============================================================\n"); - printf("%s", cli_verbose); + error_handle = EXIT_FAILURE; + printf(FINERROR); + goto OUT; } + root = ftell(fp); + fseek(fp, 0L, SEEK_END); + Lfield = ftell(fp) - root; + fseek(fp, root, SEEK_SET); + /* Read the compressed data from the input file. */ input = calloc(Lfield, sizeof(uchar)); if (fread(input, sizeof(uchar), Lfield, fp) != Lfield) @@ -1631,6 +1598,8 @@ int main(int argc, char *argv[]) } bwc_close_header(header); + printctrl(&header->control); + /* Initialize and run the decompression. */ stream = bwc_init_stream(input, output, comp); coder = bwc_alloc_decoder(); @@ -1651,6 +1620,11 @@ int main(int argc, char *argv[]) } else if (arguments.mode == cli_anl) { + if (arguments.verbose == true) + { + printheaderIO(arguments.in, cli_output, arguments.ref); + } + /* Ingest the reference data input. */ if ((ref_data = read_eas3(arguments.ref)) == NULL) { @@ -1694,6 +1668,11 @@ int main(int argc, char *argv[]) } bwc_close_header(header); + if(arguments.verbose == true) + { + printctrl(&header->control); + } + /* Initialize and run the decompression. */ stream = bwc_init_stream(input, output, comp); coder = bwc_alloc_decoder(); @@ -1715,11 +1694,7 @@ int main(int argc, char *argv[]) } else if (arguments.mode == cli_inf) { - strcat(cli_verbose, bwc_header_art); - strcat(cli_verbose, "--------------------------- I/O --------------------------\n\n"); - sprintf(cli_buffer," Input: %s \n", arguments.in); - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); + printheaderIO(arguments.in, cli_output, arguments.ref); if ((fp = fopen(arguments.in, "r")) == NULL) { @@ -1742,7 +1717,7 @@ int main(int argc, char *argv[]) goto OUT; } - /* Retrieve header information and allocate output buffer. */ + /* Retrieve header information. */ header = bwc_open_header(input); size = header->info.nX * header->info.nY * header->info.nZ * header->info.nTS * header->info.nPar; @@ -1756,79 +1731,7 @@ int main(int argc, char *argv[]) } bwc_close_header(header); - strcat(cli_verbose, "\n"); - strcat(cli_verbose, "----------------- Compression Parameters -----------------\n"); - strcat(cli_verbose, "\n"); - - strcat(cli_verbose," Tile Size: \n"); - sprintf(cli_buffer," - Samples in 1.D: %27ld\n"\ - " - Samples in 2.D: %27ld\n"\ - " - Samples in 3.D: %27ld\n"\ - " - Samples in 4.D: %27ld\n", header->control.tileSizeX, - header->control.tileSizeY, - header->control.tileSizeZ, - header->control.tileSizeTS); - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); - - strcat(cli_verbose, " __________________________________________________________\n"); - strcat(cli_verbose, "\n"); - strcat(cli_verbose, " 1.D | 2.D | 3.D | 4.D\n"); - sprintf(cli_buffer, " Decomposition Levels: %18d |%4d |%4d |%4d\n", - header->control.decompX, - header->control.decompY, - header->control.decompZ, - header->control.decompTS); - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); - - sprintf(cli_buffer, " Precincts [log2]: %18d |%4d |%4d |%4d\n", - header->control.precSizeX, - header->control.precSizeY, - header->control.precSizeZ, - header->control.precSizeTS); - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); - - sprintf(cli_buffer, " Codeblocks [log2]: %18d |%4d |%4d |%4d\n", - header->control.cbX, - header->control.cbY, - header->control.cbZ, - header->control.cbTS); - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); - - strcat(cli_verbose, " __________________________________________________________\n"); - strcat(cli_verbose, "\n"); - - sprintf(cli_buffer, " Q Number Format: %27d\n", header->control.Qm); - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); - - if (header->control.error_resilience) - { - sprintf(cli_buffer, " Error Resilience: %27s\n", "true"); - } - else - { - sprintf(cli_buffer, " Error Resilience: %27s\n", "false"); - } - strcat(cli_verbose, cli_buffer); - memset(cli_buffer, '0', sizeof(char) * 1024); - - strcat(cli_verbose, " __________________________________________________________\n"); - strcat(cli_verbose, "\n"); - - for(i = 0; i < header->control.nLayers; ++i) - { - sprintf(cli_buffer, " Quality Layer Nr. %d: %33.2f bpd\n", i, - header->control.bitrate[i]); - strcat(cli_verbose, cli_buffer); - } - - memset(cli_buffer, '0', sizeof(char) * 1024); - strcat(cli_verbose, "\n==============================================================\n"); - printf("%s", cli_verbose); + printctrl(&header->control); } else { -- 2.45.2 From 3353fd77955f88c1ad423ac12e5d56f07ee4aeb0 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Thu, 7 Nov 2024 16:26:52 +0100 Subject: [PATCH 52/53] refactor; uchar -> unsigned char --- src/tools/bwccmdl.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index a5bd7b2..b6a8d2b 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -1182,7 +1182,7 @@ printctrl(bwc_gl_ctrl *const control) printf("%s", cli_verbose); } -static uchar +static unsigned char output_analysis(eas3_data *const ref_data, eas3_data *const org_data) { /*-----------------------*\ @@ -1531,7 +1531,7 @@ int main(int argc, char *argv[]) goto OUT; } - if (fwrite(stream->out, sizeof(uchar), size, fp) != size) + if (fwrite(stream->out, sizeof(unsigned char), size, fp) != size) { error_handle = EXIT_FAILURE; printf(WRTERROR); @@ -1576,8 +1576,8 @@ int main(int argc, char *argv[]) fseek(fp, root, SEEK_SET); /* Read the compressed data from the input file. */ - input = calloc(Lfield, sizeof(uchar)); - if (fread(input, sizeof(uchar), Lfield, fp) != Lfield) + input = calloc(Lfield, sizeof(unsigned char)); + if (fread(input, sizeof(unsigned char), Lfield, fp) != Lfield) { error_handle = EXIT_FAILURE; printf(RDERROR); @@ -1646,8 +1646,8 @@ int main(int argc, char *argv[]) fseek(fp, root, SEEK_SET); /* Read the compressed data from the input file. */ - input = calloc(Lfield, sizeof(uchar)); - if (fread(input, sizeof(uchar), Lfield, fp) != Lfield) + input = calloc(Lfield, sizeof(unsigned char)); + if (fread(input, sizeof(unsigned char), Lfield, fp) != Lfield) { error_handle = EXIT_FAILURE; printf(RDERROR); @@ -1709,8 +1709,8 @@ int main(int argc, char *argv[]) fseek(fp, root, SEEK_SET); /* Read the compressed data from the input file. */ - input = calloc(Lfield, sizeof(uchar)); - if (fread(input, sizeof(uchar), Lfield, fp) != Lfield) + input = calloc(Lfield, sizeof(unsigned char)); + if (fread(input, sizeof(unsigned char), Lfield, fp) != Lfield) { error_handle = EXIT_FAILURE; printf(RDERROR); -- 2.45.2 From d49754381b1d35cddbbc521aff7db13b31014be4 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Fri, 8 Nov 2024 11:03:59 +0100 Subject: [PATCH 53/53] Docstring in libbwc.c and bits of renaming. --- src/library/libbwc.c | 1307 +++++++++++------------------------------- 1 file changed, 341 insertions(+), 966 deletions(-) diff --git a/src/library/libbwc.c b/src/library/libbwc.c index b886f64..1d66076 100755 --- a/src/library/libbwc.c +++ b/src/library/libbwc.c @@ -78,23 +78,17 @@ || | | \ | \/ | | | |___ | |__| | \| |___ | | |__| | \| ___] || || || \************************************************************************************************************/ -/*----------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function takes an integer value and generates a version with the appropri- ! -! ate byte unit in log2 format that is returned to the function caller. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 03.05.2019 Patrick Vogler B87D120 V 0.1.0 function created ! -! 04.05.2021 Patrick Vogler B87E7E4 V 0.1.0 clean up ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ #ifdef BWC_PROFILE +/*================================================================================================*/ +/** + * @details Takes an integer value and generates a version with the appropriate byte unit in + * log2 format as return value string. + * + * @param[in] integer Integer value of bytes. + * + * @retval const char* + */ +/*================================================================================================*/ const char* get_size(uint64_t integer) { @@ -144,41 +138,20 @@ } #endif -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uint8 initialize_precinct(bwc_codec *const codec, bwc_precinct *precinct, ! -! -------------- const uint32 dX, const uint32 dY, ! -! const uint32 dZ, const uint32 dTS) ! -! ! -! ! -! DESCRIPTION: ! -! ------------ ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! precinct bwc_precinct* - Structure defining a bwc precinct. ! -! ! -! dX, dY, dZ, dTS unsigned int(32 bit) - Defines the offset of the codeblock ! -! with regards to the current subband. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! unsigned int (8 bit) - Subband gain factor in log2 factor. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 24.05.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Initializes the precinct layout. + * + * @param[in] codec Structure defining the (de)compression codec. + * @param[inout] precinct Structure defining the precinct. + * @param[in] dX Codeblock offset with regard to the current subband in the 1st dimension. + * @param[in] dY Codeblock offset with regard to the current subband in the 2nd dimension. + * @param[in] dZ Codeblock offset with regard to the current subband in the 3rd dimension. + * @param[in] dTS Codeblock offset with regard to the current subband in the 4th dimension. + * + * @retval uint8_t + */ +/*================================================================================================*/ static uint8 initialize_precinct(bwc_codec *const codec, bwc_precinct *precinct, const uint32 dX, const uint32 dY, const uint32 dZ, const uint32 dTS) @@ -327,38 +300,17 @@ initialize_precinct(bwc_codec *const codec, bwc_precinct *precinct, const uint32 return 0; } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uint8 subband_gain(const uint8 highband_flag) ! -! -------------- ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function calculates the gain for a specific subband in log2 format according to the ! -! number of applied 1-D wavelet transforms. The subband gain is calculated by evaluating the ! -! hamming weight of the highband flag. (see https://en.wikipedia.org/wiki/Hamming_weight) ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! highband_flag unsigned in (8 bit) - Flag defining the number and types of ! -! 1-D wavelet of transforms applied to ! -! the subband. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! unsigned int (8 bit) - Subband gain factor in log2 factor. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 15.05.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Calculates the gain for a specific subband in log2 format according to the number of + * applied 1-D wavelet transforms. The subband gain is calculated by evaluating the + * hamming weight of the highband flag. (see https://en.wikipedia.org/wiki/Hamming_weight) + * + * @param[in] highband_flag Number and types of transforms applied to the subband. + * + * @retval uint8_t Subband gain factor in log2 factor. + */ +/*================================================================================================*/ static uint8 subband_gain(const uint8 highband_flag) { /*-----------------------*\ @@ -385,53 +337,20 @@ static uint8 subband_gain(const uint8 highband_flag) return (temp + (temp >> 4)) & 0x0F; } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar initialize_subband(bwc_codec *const codec, bwc_parameter *const parameter, ! -! -------------- bwc_resolution *const resolution, ! -! bwc_subband *const subband, ! -! int32 resolution_level, ! -! int16 highband_flag) ! -! ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function initializes the bwc_subband structure with all necessary standard parameters ! -! to (de)compress a floating point array with nX * nY * nZ grid points, nTS timesteps and ! -! nPar parameters. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! parameter bwc_parameter* - Structure defining a bwc tile parameter.! -! ! -! resolution bwc_resolution* - Structure defining a bwc resolution ! -! level. ! -! ! -! subband bwc_subband* - Structure defining a bwc subband. ! -! ! -! resolution_level signed int(32 bit) - Defines the current resolution level. ! -! ! -! highband_flag signed int(16 bit) - Defines the type of highband the cur- ! -! rent subband represents. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! uchar - Returns an unsigned char for error handling. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 12.12.2017 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Initializes the bwc_subband structure. + * + * @param[in] codec Structure defining the (de)compression codec. + * @param[in] parameter Data of given parameter/field. + * @param[in] resolution Structure defining the resolution level. + * @param[in] subband Structure defining te subband. + * @param[in] resolution_level Current resolution level index. + * @param[in] highband_flag Type of highband that the current subband represents. + * + * @retval unsigned char + */ +/*================================================================================================*/ static uchar initialize_subband(bwc_codec *const codec, bwc_parameter *const parameter, bwc_resolution *const resolution, bwc_subband *const subband, @@ -682,55 +601,18 @@ initialize_subband(bwc_codec *const codec, bwc_parameter *const parameter, bwc_r return 0; } - -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void fill_buffer(bwc_codec *const codec, bwc_tile *const tile, ! -! ------------ bwc_parameter *const parameter, ! -! bwc_sample *const working_buffer, ! -! double *const data, ! -! uint64 param_size, ! -! uint16 param_id) ! -! ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function is used to fill the working buffer with the appropriate flow field data for ! -! the specified tile parameter. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! tile bwc_tile* - Structure defining a bwc tile. ! -! ! -! parameter bwc_parameter* - Structure defining a bwc parameter. ! -! ! -! working_buffer bwc_sample* - Working buffer used to store flow field ! -! data for a specific tile parameter. ! -! ! -! param_size uint64 - Specifies the byte size of one tile ! -! parameter. ! -! ! -! parameter uint16 - Specifies the parameter index for the ! -! current tile parameter. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 22.06.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Fills the working buffer with the flow field data before compression. + * + * @param[in] codec Structure defining the (de)compression codec. + * @param[in] tile Structure defining a bwc tile. + * @param[in] parameter Data of given parameter/field. + * @param[inout] working_buffer Buffer which stores the flow field for compression. + * @param[in] data Instance of bwc_stream type with the flow field data. + * @param[in] param_id Parameter index for the current tile parameter. + */ +/*================================================================================================*/ static void fill_buffer(bwc_codec *const codec, bwc_tile *const tile, bwc_parameter *const parameter, bwc_sample *const working_buffer, @@ -924,53 +806,18 @@ fill_buffer(bwc_codec *const codec, bwc_tile *const tile, bwc_parameter *const p param_control->beta = 2.0f/(param_info->parameter_max - param_info->parameter_min); } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void fill_buffer(bwc_codec *const codec, bwc_tile *const tile, ! -! ------------ bwc_parameter *const parameter, ! -! bwc_sample *const working_buffer, ! -! double *const data, ! -! uint64 param_size, ! -! uint16 param_id) ! -! ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function is used to flush the working buffer to the flow field data memory block. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! tile bwc_tile* - Structure defining a bwc tile. ! -! ! -! parameter bwc_parameter* - Structure defining a bwc parameter. ! -! ! -! working_buffer bwc_sample* - Working buffer used to store flow field ! -! data for a specific tile parameter. ! -! ! -! param_size uint64 - Specifies the byte size of one tile ! -! parameter. ! -! ! -! parameter uint16 - Specifies the parameter index for the ! -! current tile parameter. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 22.06.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Flushes the working buffer to the flow field data memory block after decompression. + * + * @param[in] codec Structure defining the (de)compression codec. + * @param[in] tile Structure defining a bwc tile. + * @param[in] parameter Data of given parameter/field. + * @param[in] working_buffer Buffer which stores the flow field during decompression. + * @param[inout] data Instance of bwc_stream type that the flow field data is flushed to. + * @param[in] param_id Parameter index for the current tile parameter. + */ +/*================================================================================================*/ static void flush_buffer(bwc_codec *const codec, bwc_tile *const tile, bwc_parameter *const parameter, bwc_sample *const working_buffer, @@ -1125,43 +972,18 @@ flush_buffer(bwc_codec *const codec, bwc_tile *const tile, bwc_parameter *const } } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void normalize_param(bwc_codec *const codec, bwc_parameter *const parameter) ! -! ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function is used to normalize the values v[i] of the current tile parameter to the ! -! range of [-1, 1) and scale them to a desired dynamic range: ! -! ! -! q[i] = [(v[i] - α)/β] * 2^Qm. ! -! ! -! Here, α and β define the normalization constants and Qm represents the dynamic range of ! -! the Q number format. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! parameter bwc_parameter* - Structure defining a bwc parameter. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 24.10.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Used to normalize the values v[i] of the current tile parameter to the range of [-1, 1) + * and scale them to a desired dynamic range: + * q[i] = [(v[i] - α)/β] * 2^Qm. + * Here, α and β define the normalization constants and Qm represents the dynamic range + * of the Q number format. + * + * @param[inout] codec Structure defining the (de)compression codec. + * @param[in] parameter Data of given parameter/field. + */ +/*================================================================================================*/ static void normalize_param(bwc_codec *const codec, bwc_parameter *const parameter) { @@ -1250,43 +1072,18 @@ normalize_param(bwc_codec *const codec, bwc_parameter *const parameter) } } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void denormalize_param(bwc_codec *const codec, bwc_parameter *const parameter) ! -! ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function is used to scale the decompressed values to their original dynamic range and ! -! denormalize the flow field values. ! -! ! -! q[i] = [(v[i]/2^Qm) * β] + α. ! -! ! -! Here, α and β define the normalization constants and Qm represents the dynamic range of ! -! the Q number format. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! parameter bwc_parameter* - Structure defining a bwc parameter. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 24.10.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Used to scale the decompressed values to their original dynamic range and denormalize + * the flow field values. + * q[i] = [(v[i]/2^Qm) * β] + α. + * Here, α and β define the normalization constants and Qm represents the dynamic range + * of the Q number format. + * + * @param[inout] codec Structure defining the (de)compression codec. + * @param[in] parameter Data of given parameter/field. + */ +/*================================================================================================*/ static void denormalize_param(bwc_codec *const codec, bwc_parameter *const parameter) { @@ -1373,19 +1170,13 @@ denormalize_param(bwc_codec *const codec, bwc_parameter *const parameter) } } -/*----------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function allocates an instance of type bwc_codec and stores the codec precision. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! bwc_codec* Defines the (de)compression data structure. ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Allocates an instance of type bwc_codec with the compile-time codec precision. + * + * @retval bwc_stream* + */ +/*================================================================================================*/ bwc_codec* alloc_codec() { @@ -1418,41 +1209,17 @@ alloc_codec() || | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] || || || \************************************************************************************************************/ -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: bwc_codec *bwc_init_stream(...) ! -! -------------- ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function initializes the bwc_stream structure with all necessary parameters. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! prec bwc_precision - Input data precision ! -! ! -! nX ,nY, nZ unsigned int(64 bit) - Number of spatial Datapoints ! -! ! -! nTS unsigned int(16 bit) - Number of Timesteps. ! -! ! -! nPar unsigned int(8 bit) - Number of Parameters ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! bwc_stream* - Structure used to store a numerical ! -! dataset/compressed bitstream. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 09.06.2021 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Allocates and assigns user-owned pointers for (de)compression input and output. + * + * @param[in] inpbuf Input data. Can be compressed or original flow field data. + * @param[in] outbuf Output pointer which must have enough space for given output. + * @param[in] mode Decides the mode to be input for compression or decompression (comp | decomp). + * + * @retval bwc_stream* + */ +/*================================================================================================*/ bwc_stream* bwc_init_stream(void *const inpbuf, void *const outbuf, bwc_mode const mode) { @@ -1476,15 +1243,18 @@ bwc_init_stream(void *const inpbuf, void *const outbuf, bwc_mode const mode) return stream; } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: ! -! -------------- ! -! ! -! ! -! DESCRIPTION: ! -! ------------ ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Amends a user-defined comment in the bwc_codec structure. Can be used to comment the + * compressed data with user-defined information that helps data interpretation. + * + * @param[inout] codec Structure defining the compression coder. + * @param[in] com Commentary string. + * @param[in] size Size of commentary string. + * + * @retval unsigned char + */ +/*================================================================================================*/ uchar bwc_set_com(bwc_stream *const data, char const *const com, uint16 size) { @@ -1515,15 +1285,18 @@ bwc_set_com(bwc_stream *const data, char const *const com, uint16 size) return 0; } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: ! -! -------------- ! -! ! -! ! -! DESCRIPTION: ! -! ------------ ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Amends the auxiliary information in the bwc_codec structure. Can be used to store and + * retrieve file format specific metadata. + * + * @param[inout] codec Structure defining the compression coder. + * @param[in] aux Auxiliary information string. + * @param[in] size Size of auxiliary information string. + * + * @retval unsigned char + */ +/*================================================================================================*/ uchar bwc_set_aux(bwc_stream *const data, char const *const aux, uint32 size) { @@ -1554,36 +1327,15 @@ bwc_set_aux(bwc_stream *const data, char const *const aux, uint32 size) return 0; } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar create_codec(bwc_codec *const codec) ! -! -------------- ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function creates the codec structure used to (de)compress a floating point array de- ! -! fined by the bwc_initialize function. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! unsigned char - Returns an unsigned char for error handling. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 15.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Creates intrinsics like tile and subband structure in a valid codec instance. + * + * @param[inout] codec Structure defining the compression coder. + * + * @retval unsigned char + */ +/*================================================================================================*/ uchar create_codec(bwc_codec *const codec) { @@ -1958,39 +1710,13 @@ create_codec(bwc_codec *const codec) return 0; } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_free_compression(bwc_codec *const codec) ! -! -------------- ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function deallocates the compression codec structure used to define and control the ! -! bwc codec and can be called if an error occurs during the (de-)compression stage or once ! -! the codec has finished. The deallocation will be carried out down to the structure levels ! -! that have been allocated. ! -! ! -! PARAMETERS: ! -! ----------- ! -! ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 19.10.2017 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Deallocates the (de)compression codec structure and contained resources. + * + * @param[inout] codec Structure defining the compression coder. + */ +/*================================================================================================*/ void bwc_free_codec(bwc_codec *const codec) { @@ -2078,21 +1804,21 @@ bwc_free_codec(bwc_codec *const codec) } } -/*----------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function configures the bwc_codec structure with all necessary standard parameters ! -! to compress a floating point array with nX * nY * nZ grid points, nTS timesteps and ! -! nPar parameters. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! bwc_codec* Defines the (de)compression data structure. ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Configures the bwc_codec structure for compression with given dimensions and precision. + * + * @param[inout] codec Structure defining the compression coder. + * @param[in] nX Field data size in first dimension. + * @param[in] nY Field data size in two dimension. + * @param[in] nZ Field data size in three dimension. + * @param[in] nTS Field data size in fourth dimension. + * @param[in] nPar Number of parameters. + * @param[in] prec Data precision. + * + * @retval bwc_codec* + */ +/*================================================================================================*/ bwc_codec* configure_codec(bwc_codec *const codec, uint64 const nX, uint64 const nY, uint64 const nZ, uint64 const nTS, uint8 const nPar, bwc_precision const prec) @@ -2250,21 +1976,20 @@ configure_codec(bwc_codec *const codec, uint64 const nX, uint64 const nY, uint64 return codec; } -/*----------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function initializes the bwc_codec structure with all necessary standard parameters ! -! to (de)compress a floating point array with nX * nY * nZ grid points, nTS timesteps and ! -! nPar parameters. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! bwc_codec* Defines the (de)compression data structure. ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Allocates the bwc_codec structure for compression with given dimensions and precision. + * + * @param[in] nX Field data size in first dimension. + * @param[in] nY Field data size in two dimension. + * @param[in] nZ Field data size in three dimension. + * @param[in] nTS Field data size in fourth dimension. + * @param[in] nPar Number of parameters. + * @param[in] prec Data precision. + * + * @retval bwc_codec* + */ +/*================================================================================================*/ bwc_codec* bwc_alloc_coder(uint64 const nX, uint64 const nY, uint64 const nZ, uint64 const nTS, uint8 const nPar, bwc_precision const prec) @@ -2279,21 +2004,13 @@ bwc_alloc_coder(uint64 const nX, uint64 const nY, uint64 const nZ, uint64 const return codec; } -/*----------------------------------------------------------------------------------------------------------*\ -! ! -! DESCRIPTION: ! -! ------------ ! -! This function initializes the bwc_codec structure with all necessary standard parameters ! -! to (de)compress a floating point array with nX * nY * nZ grid points, nTS timesteps and ! -! nPar parameters. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! bwc_codec* Defines the (de)compression data structure. ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Allocates the bwc_codec structure for decompression. + * + * @retval bwc_codec* + */ +/*================================================================================================*/ bwc_codec* bwc_alloc_decoder() { @@ -2306,36 +2023,13 @@ bwc_alloc_decoder() return codec; } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_error_resilience(bwc_codec *const codec) ! -! -------------- ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function sets the error resilience marker in the bwc_codec structure if an error ! -! resilient compression approach is to be employed. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 13.06.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Turns on the error resilience marker in the bwc_codec structure. + * + * @param[inout] codec Structure defining the compression coder. + */ +/*================================================================================================*/ void bwc_set_error_resilience(bwc_codec *const codec) { @@ -2368,39 +2062,14 @@ bwc_set_error_resilience(bwc_codec *const codec) control->CSsgc ^= (0x01 << 0); } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_quant_style(bwc_codec *const codec, bwc_quant_st quantization_style) ! -! -------------- ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function amends the quantization style in the bwc_codec structure according to the ! -! specified value. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! quantization_style bwc_quant_st - Quantization style used during compres- ! -! sion. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 15.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Amends the quantization style in the bwc_codec structure. + * + * @param[inout] codec Structure defining the compression coder. + * @param[in] quantization_sytle Quantization style employed during compression. + */ +/*================================================================================================*/ void set_quant_style(bwc_codec *const codec, bwc_quant_st quantization_style) { @@ -2434,39 +2103,14 @@ set_quant_style(bwc_codec *const codec, bwc_quant_st quantization_style) control->CSsgc |= (0x01 << 1); } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_quant_step_size(bwc_codec *const codec, double delta) ! -! -------------- ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function amends the quantization step size in the bwc_codec structure according to ! -! the specified value. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! delta double - Quantization step size used during ! -! compression. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 16.04.2019 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Amends the quantization step size in the bwc_codec structure. + * + * @param[inout] codec Structure defining the compression coder. + * @param[in] delta Quantization step size employed during compression. + */ +/*================================================================================================*/ void set_quant_step_size(bwc_codec *const codec, double delta) { @@ -2537,40 +2181,14 @@ set_quant_step_size(bwc_codec *const codec, double delta) control->CSsgc |= (0x01 << 2); } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void set_progression(bwc_codec *const codec, bwc_prog_ord progression) ! -! -------------- ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function amends the progression order in the bwc_codec structure according to the ! -! specified value. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! progression bwc_prog_ord - Progression orders employed during com- ! -! pression (CPRL, LRCP, PCRL, RLCP, ! -! RPCL). ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 15.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Amends the progression order in the bwc_codec structure. + * + * @param[inout] codec Structure defining the compression coder. + * @param[in] progression Progression orders employed during compression. + */ +/*================================================================================================*/ void set_progression(bwc_codec *const codec, bwc_prog_ord progression) { @@ -2606,44 +2224,17 @@ set_progression(bwc_codec *const codec, bwc_prog_ord progression) control->CSsgc |= (0x01 << 3); } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void set_kernels(bwc_codec *const codec, bwc_dwt_filter KernelX, ! -! -------------- bwc_dwt_filter KernelY, ! -! bwc_dwt_filter KernelZ, ! -! bwc_dwt_filter KernelTS) ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function amends the wavelet kernels in the bwc_codec structure according to the ! -! specified values. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! KernelX, KernelY, KernelZ bwc_dwt_filter - Wavelet kernels used for spatial ! -! decomposition. ! -! ! -! KernelT bwc_dwt_filter - Wavelet kernel used for temporal ! -! decomposition. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 15.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Amends the wavelet kernels in the bwc_codec structure. + * + * @param[inout] codec Structure defining the compression coder. + * @param[in] KernelX Wavelet kernel used in first dimemsion in log2 exponent format. + * @param[in] KernelY Wavelet kernel used in first dimemsion in log2 exponent format. + * @param[in] KernelZ Wavelet kernel used in third dimemsion in log2 exponent format. + * @param[in] KernelTS Wavelet kernel used in fourth dimemsion in log2 exponent format. + */ +/*================================================================================================*/ void set_kernels(bwc_codec *const codec, bwc_dwt_filter KernelX, bwc_dwt_filter KernelY, bwc_dwt_filter KernelZ, bwc_dwt_filter KernelTS) @@ -2682,42 +2273,17 @@ set_kernels(bwc_codec *const codec, bwc_dwt_filter KernelX, bwc_dwt_filter Kerne control->CSsgc |= (0x01 << 4); } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_decomp(bwc_codec *const codec, uint8 decompX, uint8 decompY, ! -! -------------- uint8 decompZ, uint8 decompTS) ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function amends the decomposition levels in the bwc_codec structure according to the ! -! specified values. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! decompX, decompY, decompZ unsigned int(8 bit) - Number of spatial wavelet decomposition ! -! levels used during compression. ! -! ! -! decompTS unsigned int(8 bit) - Number of temporal wavelet decomposi- ! -! tion level used during compression. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 14.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Amends the decomposition levels in the bwc_codec structure. + * + * @param[inout] codec Structure defining the compression coder. + * @param[in] decompX Number of wavelet decomposition levels in first dimemsion in log2 exponent format. + * @param[in] decompY Number of wavelet decomposition levels in first dimemsion in log2 exponent format. + * @param[in] decompZ Number of wavelet decomposition levels in third dimemsion in log2 exponent format. + * @param[in] decompTS Number of wavelet decomposition levels in fourth dimemsion in log2 exponent format. + */ +/*================================================================================================*/ void bwc_set_decomp(bwc_codec *const codec, uint8 decompX, uint8 decompY, uint8 decompZ, uint8 decompTS) { @@ -2849,39 +2415,17 @@ bwc_set_decomp(bwc_codec *const codec, uint8 decompX, uint8 decompY, uint8 decom control->CSsgc |= (0x01 << 5); } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_precincts(bwc_codec *const codec, uint8 pX, uint8 pY, uint8 pZ, uint8 pTS) ! -! -------------- ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function amends the precinct size in the bwc_codec structure according to the ! -! specified values. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! px, py, pz, pTS unsigned int(8 bit) - Spatial and temporal precinct dimensions! -! in log2 exponent format. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 15.05.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Amends the precinct size in the bwc_codec structure. + * + * @param[inout] codec Structure defining the compression coder. + * @param[in] pX Precinct size in first dimemsion in log2 exponent format. + * @param[in] pY Precinct size in first dimemsion in log2 exponent format. + * @param[in] pZ Precinct size in third dimemsion in log2 exponent format. + * @param[in] pTS Precinct size in fourth dimemsion in log2 exponent format. + */ +/*================================================================================================*/ void bwc_set_precincts(bwc_codec *const codec, uint8 pX, uint8 pY, uint8 pZ, uint8 pTS) { @@ -2949,39 +2493,17 @@ bwc_set_precincts(bwc_codec *const codec, uint8 pX, uint8 pY, uint8 pZ, uint8 pT control->CSsgc |= (0x01 << 6); } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_codeblocks(bwc_codec *const codec, uint8 cbX, uint8 cbY, ! -! -------------- uint8 cbZ, uint8 cbTS) ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function amends the codeblock size in the bwc_codec structure according to the ! -! specified values. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! cbx, cby, cbz, cbTS unsigned int(8 bit) - Spatial and temporal codeblock dimen- ! -! sions in log2 exponent format. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 14.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Amends the codeblock size in the bwc_codec structure. + * + * @param[inout] codec Structure defining the compression coder. + * @param[in] cbX Codeblock size in first dimemsion in log2 exponent format. + * @param[in] cbY Codeblock size in first dimemsion in log2 exponent format. + * @param[in] cbZ Codeblock size in third dimemsion in log2 exponent format. + * @param[in] cbTS Codeblock size in fourth dimemsion in log2 exponent format. + */ +/*================================================================================================*/ void bwc_set_codeblocks(bwc_codec *const codec, uint8 cbX, uint8 cbY, uint8 cbZ, uint8 cbTS) { @@ -3049,38 +2571,14 @@ bwc_set_codeblocks(bwc_codec *const codec, uint8 cbX, uint8 cbY, uint8 cbZ, uint control->CSsgc |= (0x01 << 7); } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_qm(bwc_codec *const codec, uint8 Qm) ! -! -------------- ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function amends the Q number formate range in the bwc_codec structure according to the ! -! specified value. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! Qm unsigned int(8 bit) - Q number formate range (m). ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 14.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Amends the Q number formate range in the bwc_codec structure. + * + * @param[inout] codec Structure defining the compression coder. + * @param[in] Qm Q number formate range (m). + */ +/*================================================================================================*/ void bwc_set_qm(bwc_codec *const codec, uint8 Qm) { @@ -3129,46 +2627,18 @@ bwc_set_qm(bwc_codec *const codec, uint8 Qm) } } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_tiles(bwc_codec *const codec, uint32 tilesX, uint32 tilesY, uint32 tilesZ, ! -! -------------- uint32 tilesTS, uchar instr) ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function amends the tileSize and num_Tiles values in the bwc_codec structure according ! -! to the specified values. The NUMBEROF and SIZEOF constants can be used to either specify ! -! the tile sizes or the number of tiles in each spatial and temporal directions. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! tilesX, tilesY, tilesZ unsigned int(32 bit) - Variables defining the size of ! -! a spatial tile. ! -! ! -! tilesTS unsigned int(32 bit) - Variables defining the size of ! -! a temporal tile. ! -! ! -! instr bwc_tile_instr - Constants used to instruct the ! -! bwc_set_tiles function. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 14.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Amends the tileSize and num_Tiles values in the bwc_codec structure. + * + * @param[inout] codec Structure defining the compression coder. + * @param[in] tilesX Spatial tile size/number in first dimension. + * @param[in] tilesY Spatial tile size/number in second dimension. + * @param[in] tilesZ Spatial tile size/number in third dimension. + * @param[in] tilesTS Spatial tile size/number in fourth dimension. + * @param[in] instr Instructs interpretation of parameters as 'size' or 'number'. + */ +/*================================================================================================*/ void bwc_set_tiles(bwc_codec *const codec, uint64 tilesX, uint64 tilesY, uint64 tilesZ, uint64 tilesTS, bwc_tile_instr instr) { @@ -3354,7 +2824,7 @@ bwc_set_tiles(bwc_codec *const codec, uint64 tilesX, uint64 tilesY, uint64 tiles /*================================================================================================*/ /** - * @details This function opens the header of a compressed data set and parses it into an + * @details Opens the header of a compressed data set and parses it into an * instance of type bwc_header. * * @param[in] inpbuf Pointer to compressed data set. @@ -3422,7 +2892,7 @@ bwc_header* bwc_open_header(void *const inpbuf) /*================================================================================================*/ /** - * @details This function closes the header information in the bwc_header pointer. + * @details Closes the header information in the bwc_header pointer. * * @param[in] header Instance of type bwc_header. */ @@ -3443,44 +2913,18 @@ void bwc_close_header(bwc_header *const header) } } - -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_create_compression(bwc_codec *codec, char *rate_control) ! -! -------------- ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function creates the codec structure used to compress a floating point array defined ! -! by the bwc_initialize function. For a compression run, the rate_control and instr arguments ! -! need to be passed to the function to properly set up the lossy compression stage. Here, the ! -! instr parameter defines whether rate control is defined by a BITRATE - a floating point val-! -! ue defining the average number of bits per datapoint - and ACCURACY - an integer value de- ! -! fining the exponent of the maximum allowable error (i.e. 15 for err = 1e-15). ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! rate_control char* - Variable defining the bitrate. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 15.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! 05.12.2019 Patrick vogler B87E7E4 V 0.1.0 streamlined function arguments ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Creates the codec structure used to compress floating point data in a previously + * initialized instance of the bwc_stream structure. + * + * @param[inout] codec Pointer to the returned codec structure. + * @param[in] stream Stream data structure containing the relevant floating point data. + * @param[in] rate_control The bitrates of several quality layers as string variable. + * + * @retval uchar + */ +/*================================================================================================*/ uchar bwc_create_compression(bwc_codec *codec, bwc_stream *stream, char *rate_control) { @@ -3645,37 +3089,19 @@ bwc_create_compression(bwc_codec *codec, bwc_stream *stream, char *rate_control) return 0; } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar bwc_compress(bwc_codec *const codec, bwc_float *const data) ! -! -------------- ! -! ! -! DESCRIPTION: ! -! ------------ ! -! Description needed. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! uchar - Returns an unsigned char for error handling. ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 15.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Compress the data of a readily initialized bwc_stream structure using the coder + * defined by the codec variable. + * + * @param[inout] codec Pointer to the returned codec structure. + * @param[in] stream Stream data structure containing the relevant floating point data. + * + * @retval size_t + */ +/*================================================================================================*/ size_t -bwc_compress(bwc_codec *const codec, bwc_stream *const data) +bwc_compress(bwc_codec *const codec, bwc_stream *const stream) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -3722,7 +3148,7 @@ bwc_compress(bwc_codec *const codec, bwc_stream *const data) ! DEFINE ASSERTIONS: ! \*-----------------------*/ assert(codec); - assert(data); + assert(stream); /*--------------------------------------------------------*\ ! Initialize the compression time measurement. ! @@ -3788,7 +3214,7 @@ bwc_compress(bwc_codec *const codec, bwc_stream *const data) start = (double)clock(); #endif #endif - fill_buffer(codec, tile, parameter, working_buffer, data, p); + fill_buffer(codec, tile, parameter, working_buffer, stream, p); #ifdef BWC_PROFILE #if defined (_OPENMP) end = omp_get_wtime(); @@ -3913,7 +3339,7 @@ bwc_compress(bwc_codec *const codec, bwc_stream *const data) start = (double)clock(); #endif #endif - compressed_size = assemble_codestream(codec, data); + compressed_size = assemble_codestream(codec, stream); if(compressed_size == 0) { free(working_buffer); @@ -3970,42 +3396,18 @@ bwc_compress(bwc_codec *const codec, bwc_stream *const data) return compressed_size; } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar bwc_create_compression(bwc_codec *const codec, bwc_stream *const stream, ! -! -------------- uint8 layer) ! -! ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function parses the supplied bwc codestream and sets up the codec structure used to ! -! decompress the numerical dataset. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! rate_control (opt) char* - Variable defining the bitrate/accuracy. ! -! ! -! instr (opt) bwc_rate_instr - Constants used to instruct the rate ! -! control information. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 15.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Creates the codec structure used to decompress floating point data in a previously + * initialized instance of the bwc_stream structure. + * + * @param[inout] codec Pointer to the returned codec structure. + * @param[in] stream Stream data structure containing the relevant floating point data. + * @param[in] layer Number of quality layers. + * + * @retval uchar + */ +/*================================================================================================*/ uchar bwc_create_decompression(bwc_codec *const codec, bwc_stream *const stream, uint8 layer) { @@ -4027,46 +3429,19 @@ bwc_create_decompression(bwc_codec *const codec, bwc_stream *const stream, uint8 return 0; } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: uchar bwc_create_compression(bwc_codec *codec, float rate_control, uchar instr) ! -! -------------- ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function creates the codec structure used to compress a floating point array defined ! -! by the bwc_initialize function at a prescribed bitrate or accuracy. In this context, the ! -! bitrate is a floating point value defining the average number of bits per datapoint and ! -! the accuracy is an integer value defining the exponent of the maximum allowable error ! -! (i.e. 15 for err = 1e-15). ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! codec bwc_codec* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! rate_control float - Variable defining the bitrate/accuracy. ! -! ! -! instr unsigned char - Constants used to instruct the rate ! -! control information. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 15.03.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ +/*================================================================================================*/ +/** + * @details Decompress the data of a readily initialized bwc_stream structure using the coder + * defined by the codec variable. + * + * @param[inout] codec Pointer to the returned codec structure. + * @param[in] stream Stream data structure containing the relevant floating point data. + * + * @retval uchar + */ +/*================================================================================================*/ uchar -bwc_decompress(bwc_codec *const codec, bwc_stream *const data) +bwc_decompress(bwc_codec *const codec, bwc_stream *const stream) { /*-----------------------*\ ! DEFINE INT VARIABLES: ! @@ -4103,7 +3478,7 @@ bwc_decompress(bwc_codec *const codec, bwc_stream *const data) ! DEFINE ASSERTIONS: ! \*-----------------------*/ assert(codec); - assert(data); + assert(stream); /*--------------------------------------------------------*\ ! Initialize the decompression time measurement. ! @@ -4248,7 +3623,7 @@ bwc_decompress(bwc_codec *const codec, bwc_stream *const data) start = (double)clock(); #endif #endif - flush_buffer(codec, tile, parameter, working_buffer, data, p); + flush_buffer(codec, tile, parameter, working_buffer, stream, p); #ifdef BWC_PROFILE #if defined (_OPENMP) end = omp_get_wtime(); -- 2.45.2