Removed the streaming functions from the public header to clean up the API.

This commit is contained in:
Patrick Vogler 2024-02-22 16:25:52 +01:00
parent 8850d525f2
commit eae976b9ba
Signed by: Patrick Vogler
GPG key ID: 5536B08CE82E8509
15 changed files with 1966 additions and 1536 deletions

View file

@ -187,6 +187,30 @@
|| | | | |___ ___] || || | | | |___ ___] ||
|| || || ||
\************************************************************************************************************/ \************************************************************************************************************/
/*----------------------------------------------------------------------------------------------*\
! !
! DESCRIPTION: !
! ------------ !
! !
! This structure is used to read/assemble a packed codestream during coding. The !
! byte buffer is flushed to the packed stream as soon as the a single byte has !
! been assembled. !
! !
\*----------------------------------------------------------------------------------------------*/
typedef struct
{
uchar error; // Error flag used during streaming.
uint64 L; // Number of bytes written to/from stream.
uint64 Lmax; // Size of packed stream.
uint64 size_incr; // Size incrmnt used for stream assembly.
uint8 T; // Byte buffer.
int8 t; // Byte buffer counter.
uchar *memory; // Memory handle for packed stream chunck.
} bitstream;
/*----------------------------------------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------------------------------------*\
! STRUCT NAME: eas3_header ! ! STRUCT NAME: eas3_header !
! ----------- ! ! ----------- !

View file

@ -54,41 +54,71 @@
\************************************************************************************************/ \************************************************************************************************/
#include "types.h" #include "types.h"
/************************************************************************************************\
|| ___ ____ ____ ____ _ _ _ ____ ___ ___ _ _ ___ ____ ____ ||
|| | \ |___ |__/ |__/ | | | |___ | \ | \_/ |__] |___ [__ ||
|| |__/ |___ | \ | \ | \/ |___ |__/ | | | |___ ___] ||
|| ||
\************************************************************************************************/
/*----------------------------------------------------------------------------------------------*\
! !
! DESCRIPTION: !
! ------------ !
! !
! This structure is used to read/assemble a packed codestream during coding. The !
! byte buffer is flushed to the packed stream as soon as the a single byte has !
! been assembled. !
! !
\*----------------------------------------------------------------------------------------------*/
typedef struct
{
uchar error; // Error flag used during streaming.
uint64 L; // Number of bytes written to/from stream.
uint64 Lmax; // Size of packed stream.
uint64 size_incr; // Size incrmnt used for stream assembly.
uint8 T; // Byte buffer.
int8 t; // Byte buffer counter.
uchar *memory; // Memory handle for packed stream chunck.
} bitstream;
/************************************************************************************************\ /************************************************************************************************\
|| ___ _ _ ___ _ _ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ || || ___ _ _ ___ _ _ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ ||
|| |__] | | |__] | | | |___ | | |\ | | | | | | |\ | [__ || || |__] | | |__] | | | |___ | | |\ | | | | | | |\ | [__ ||
|| | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] || || | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] ||
|| || || ||
\************************************************************************************************/ \************************************************************************************************/
uint64 bytes_used (bwc_stream const *const stream); uint64 bytes_used (bitstream const *const stream);
//==========|==========================|======================|======|======|===================== //==========|==========================|======================|======|======|=====================
bwc_stream* bwc_init_stream (uchar *const memory, bitstream* init_stream (uchar *const memory,
uint32 const size, uint32 const size,
char const instr); char const instr);
//==========|==========================|======================|======|======|===================== //==========|==========================|======================|======|======|=====================
void bwc_emit_chunck (bwc_stream *const stream, void emit_chunck (bitstream *const stream,
uchar const *const chunck, uchar const *const chunck,
uint64 const size); uint64 const size);
//==========|==========================|======================|======|======|===================== //==========|==========================|======================|======|======|=====================
void bwc_emit_symbol (bwc_stream *const stream, void emit_symbol (bitstream *const stream,
uint64 const symbol, uint64 const symbol,
uint8 const size); uint8 const size);
//==========|==========================|======================|======|======|===================== //==========|==========================|======================|======|======|=====================
void bwc_emit_bit (bwc_stream *const stream, void emit_bit (bitstream *const stream,
uint64 const bit); uint64 const bit);
//==========|==========================|======================|======|======|===================== //==========|==========================|======================|======|======|=====================
void flush_stream (bwc_stream *const stream); void flush_stream (bitstream *const stream);
//==========|==========================|======================|======|======|===================== //==========|==========================|======================|======|======|=====================
uchar* bwc_get_chunck (bwc_stream *const stream, uchar* get_chunck (bitstream *const stream,
uint64 const length); uint64 const length);
//==========|==========================|======================|======|======|===================== //==========|==========================|======================|======|======|=====================
uint64 bwc_get_symbol (bwc_stream *const stream, uint64 get_symbol (bitstream *const stream,
uint8 const length); uint8 const length);
//==========|==========================|======================|======|======|===================== //==========|==========================|======================|======|======|=====================
uchar bwc_get_bit (bwc_stream *const stream); uchar get_bit (bitstream *const stream);
//==========|==========================|======================|======|======|===================== //==========|==========================|======================|======|======|=====================
uchar bwc_terminate_stream (bwc_stream *stream, uchar terminate_stream (bitstream *stream,
bwc_packed_stream *const packed_stream); bwc_stream *const packed_stream);
//==========|==========================|======================|======|======|===================== //==========|==========================|======================|======|======|=====================
void release_packed_stream (bwc_packed_stream *const stream); void release_packed_stream (bwc_stream *const stream);
#endif #endif

View file

@ -54,6 +54,7 @@
|| || || ||
\************************************************************************************************/ \************************************************************************************************/
#include "types.h" #include "types.h"
#include "bitstream.h"
/************************************************************************************************\ /************************************************************************************************\
|| _ _ ____ ____ ____ ____ ____ || || _ _ ____ ____ ____ ____ ____ ||
@ -67,7 +68,7 @@
! ------------ ! ! ------------ !
! ! ! !
! These macros define stream manipulation operations to rewind, forward, inquire ! ! These macros define stream manipulation operations to rewind, forward, inquire !
! the availability and get access to the current memory position of a bwc_stream. ! ! the availability and get access to the current memory position of a bitstrean. !
! ! ! !
\*----------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------*/
#define rewind_stream(stream, delta) \ #define rewind_stream(stream, delta) \
@ -90,17 +91,13 @@
\************************************************************************************************/ \************************************************************************************************/
uchar assemble_main_header (bwc_field *const field); uchar assemble_main_header (bwc_field *const field);
//==========|==========================|======================|======|======|===================== //==========|==========================|======================|======|======|=====================
bwc_field* bwc_parse_main_header (bwc_data *const data, uchar codestream_write_aux (bwc_stream *const header,
bwc_stream *const stream); bwc_stream *const aux);
//==========|==========================|======================|======|======|===================== //==========|==========================|======================|======|======|=====================
uchar codestream_write_aux (bwc_packed_stream *const header, uchar codestream_write_com (bwc_stream *const header,
bwc_packed_stream *const aux); bwc_stream *const com);
//==========|==========================|======================|======|======|===================== //==========|==========================|======================|======|======|=====================
uchar codestream_write_com (bwc_packed_stream *const header, bwc_stream* assemble_codestream (bwc_field *const field);
bwc_packed_stream *const com);
//==========|==========================|======================|======|======|=====================
bwc_packed_stream* assemble_codestream (bwc_field *const field);
//==========|==========================|======================|======|======|===================== //==========|==========================|======================|======|======|=====================
bwc_field* parse_codestream (bwc_data *const data, bwc_field* parse_codestream (bwc_data *const data,
uint8 const layer); uint8 const layer);

View file

@ -59,6 +59,7 @@
|| || || ||
\************************************************************************************************/ \************************************************************************************************/
#include "types.h" #include "types.h"
#include "bitstream.h"
/************************************************************************************************\ /************************************************************************************************\
|| ___ _ _ ___ _ _ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ || || ___ _ _ ___ _ _ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ ||
@ -83,13 +84,13 @@
uint16 const value); uint16 const value);
//==========|==========================|======================|======|=======|==================== //==========|==========================|======================|======|=======|====================
void encode_tagtree (bwc_tagtree *const tagtree, void encode_tagtree (bwc_tagtree *const tagtree,
bwc_stream *const stream, bitstream *const stream,
uint32 const threshold, uint32 const threshold,
uint32 const leaf_index, uint32 const leaf_index,
uchar const estimate); uchar const estimate);
//==========|==========================|======================|======|=======|==================== //==========|==========================|======================|======|=======|====================
uchar decode_tagtree (bwc_tagtree *const tagtree, uchar decode_tagtree (bwc_tagtree *const tagtree,
bwc_stream *const stream, bitstream *const stream,
uint32 const threshold, uint32 const threshold,
uint32 const leaf_index); uint32 const leaf_index);
#endif #endif

View file

@ -54,7 +54,6 @@
\************************************************************************************************/ \************************************************************************************************/
#include "types.h" #include "types.h"
/************************************************************************************************\ /************************************************************************************************\
|| _ _ ____ ____ ____ ____ ____ || || _ _ ____ ____ ____ ____ ____ ||
|| |\/| |__| | |__/ | | [__ || || |\/| |__| | |__/ | | [__ ||

View file

@ -99,33 +99,8 @@
uchar *access; // Pointer used to parse packed stream. uchar *access; // Pointer used to parse packed stream.
uchar *memory; // Memory handle for the packed stream. uchar *memory; // Memory handle for the packed stream.
} bwc_packed_stream;
/*----------------------------------------------------------------------------------------------*\
! !
! DESCRIPTION: !
! ------------ !
! !
! This structure is used to read/assemble a packed codestream during coding. The !
! byte buffer is flushed to the packed stream as soon as the a single byte has !
! been assembled. !
! !
\*----------------------------------------------------------------------------------------------*/
typedef struct
{
uchar error; // Error flag used during streaming.
uint64 L; // Number of bytes written to/from stream.
uint64 Lmax; // Size of packed stream.
uint64 size_incr; // Size incrmnt used for stream assembly.
uint8 T; // Byte buffer.
int8 t; // Byte buffer counter.
uchar *memory; // Memory handle for packed stream chunck.
} bwc_stream; } bwc_stream;
/*----------------------------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------------------------*\
! ! ! !
! DESCRIPTION: ! ! DESCRIPTION: !
@ -227,9 +202,9 @@
struct codestream struct codestream
{ {
bwc_packed_stream *data; // Data codestream block. bwc_stream *data; // Data codestream block.
bwc_packed_stream *aux; // Auxiliary info. codestream block. bwc_stream *aux; // Auxiliary info. codestream block.
bwc_packed_stream *com; // Comment codestream block. bwc_stream *com; // Comment codestream block.
}codestream; }codestream;
struct field struct field
@ -445,8 +420,8 @@
\*----------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------*/
typedef struct typedef struct
{ {
bwc_packed_stream header; // Packed stream header. bwc_stream header; // Packed stream header.
bwc_packed_stream body; // Packed stream body. bwc_stream body; // Packed stream body.
uint8 e; // Indicator for packet cb. contributions. uint8 e; // Indicator for packet cb. contributions.
uint32 size; // Codestream packet size. uint32 size; // Codestream packet size.
@ -714,7 +689,7 @@
uint8 guard_bits; // Number of guard bits during quant. uint8 guard_bits; // Number of guard bits during quant.
bwc_packed_stream header; // Main codestream header. bwc_stream header; // Main codestream header.
bwc_quant_st quantization_style; // Quantization style. bwc_quant_st quantization_style; // Quantization style.
bwc_prog_ord progression; // Packet progression order. bwc_prog_ord progression; // Packet progression order.

View file

@ -84,6 +84,423 @@
|| | | \ | \/ | | | |___ | |__| | \| |___ | | |__| | \| ___] || || | | \ | \/ | | | |___ | |__| | \| |___ | | |__| | \| ___] ||
|| || || ||
\************************************************************************************************************/ \************************************************************************************************************/
/*----------------------------------------------------------------------------------------------------------*\
! FUNCTION NAME: uint32 bytes_used(bitstream *const stream) !
! -------------- !
! !
! DESCRIPTION: !
! ------------ !
! This function is used to evaluate the number of bytes that have already been !
! written to the allocated bitstream memory block. !
! !
! PARAMETERS: !
! ----------- !
! Variable Type Description !
! -------- ---- ----------- !
! stream bitstream* - Structure that !
! !
! RETURN VALUE: !
! ------------- !
! Type Description !
! ---- ----------- !
! unsigned int(32 bit) - Number of bites that have been written to the !
! bitstream. !
! !
! DEVELOPMENT HISTORY: !
! -------------------- !
! !
! Date Author Change Id Release Description Of Change !
! ---- ------ --------- ------- --------------------- !
! 13.05.2019 Patrick Vogler B87D120 V 0.1.0 function created !
! !
\*----------------------------------------------------------------------------------------------------------*/
uint64
bytes_used(bitstream const *const stream)
{
if(stream->T == 0xFF)
{
return stream->L + 1;
}
else
{
return stream->L;
}
}
/*----------------------------------------------------------------------------------------------------------*\
! FUNCTION NAME: bitstream* bwc_init_stream(uchar* memory, uint32 size, char instr) !
! -------------- !
! !
! DESCRIPTION: !
! ------------ !
! This function is used to initialize a bwc bitstream. For encoding, a null pointer !
! is passed as a memory handle and the function will allocate a memory block with the !
! specified stream size. For decoding, a valid memory handle, passed by the function !
! caller, will be stored in the bitstream structure. The byte buffer counter t, !
! stream size Lmax and size increment are initialized with their appropriate values. !
! !
! PARAMETERS: !
! ----------- !
! Variable Type Description !
! -------- ---- ----------- !
! size unsigned int(32 bit) - Initial size of the bwc stream. !
! !
! memory unsigned char - Memory handle for the bwc stream memory !
! block. !
! !
! instr char - Constant used to instruct the field !
! initialization. !
! !
! RETURN VALUE: !
! ------------- !
! Type Description !
! ---- ----------- !
! bitstream* - Memory handle for the initialized bwc stream. !
! !
! DEVELOPMENT HISTORY: !
! -------------------- !
! !
! Date Author Change Id Release Description Of Change !
! ---- ------ --------- ------- --------------------- !
! 19.06.2019 Patrick Vogler B87D120 V 0.1.0 function created !
! !
\*----------------------------------------------------------------------------------------------------------*/
bitstream*
init_stream(uchar* memory, uint32 size, char instr)
{
/*-----------------------*\
! DEFINE STRUCTS: !
\*-----------------------*/
bitstream *stream;
/*-----------------------*\
! DEFINE ASSERTIONS: !
\*-----------------------*/
assert(instr == 'c' || instr == 'd');
/*--------------------------------------------------------*\
! Allocate the bwc stream structure. !
\*--------------------------------------------------------*/
stream = calloc(1, sizeof(bitstream));
if(!stream)
{
// memory allocation error
fprintf(stderr, MEMERROR);
return NULL;
}
/*--------------------------------------------------------*\
! Evaluate if a valid memory handle has been passed by the !
! function caller. !
\*--------------------------------------------------------*/
if(!memory)
{
/*--------------------------------------------------------*\
! If no valid memory handle has been passed, allocate a !
! memory block with the specifiec stream size. !
\*--------------------------------------------------------*/
stream->memory = calloc(size, sizeof(uchar));
if(!stream->memory)
{
// memory allocation error
fprintf(stderr, MEMERROR);
return NULL;
}
}
else
{
/*--------------------------------------------------------*\
! If a valid memory handle has been passed for decoding, !
! save the memory handle in the bwc stream structure. !
\*--------------------------------------------------------*/
stream->memory = memory;
}
/*--------------------------------------------------------*\
! Initialize the byte buffer counter, stream size and size !
! increment for the current stream. !
\*--------------------------------------------------------*/
stream->t = (instr == 'c') ? 8 : 0;
stream->Lmax = size;
stream->size_incr = (uint64)(size / 2);
/*--------------------------------------------------------*\
! Return the stream memory handle. !
\*--------------------------------------------------------*/
return stream;
}
/*----------------------------------------------------------------------------------------------------------*\
! FUNCTION NAME: void bwc_emit_chunck(bitstream *const stream, const uchar* string, const uint64 length) !
! -------------- !
! !
! DESCRIPTION: !
! ------------ !
! This function is used to write an additional chunck of size length to a bwc bitstream. !
! !
! !
! PARAMETERS: !
! ----------- !
! Variable Type Description !
! -------- ---- ----------- !
! stream bitstream* - Structure used to assemble a bwc bit- !
! bitstream. !
! !
! chunck unsigned char* - Memory handle for a data block that is !
! to be written to the bwc bitstream. !
! !
! size unsigned int(64 bit) - Size of the data block. !
! !
! RETURN VALUE: !
! ------------- !
! Type Description !
! ---- ----------- !
! - - !
! !
! DEVELOPMENT HISTORY: !
! -------------------- !
! !
! Date Author Change Id Release Description Of Change !
! ---- ------ --------- ------- --------------------- !
! 22.06.2019 Patrick Vogler B87D120 V 0.1.0 function created !
! !
\*----------------------------------------------------------------------------------------------------------*/
void
emit_chunck(bitstream *const stream, const uchar* chunck, const uint64 size)
{
/*-----------------------*\
! DEFINE INT VARIABLES: !
\*-----------------------*/
uint64 Lreq;
/*-----------------------*\
! DEFINE ASSERTIONS: !
\*-----------------------*/
assert(stream);
assert(chunck);
/*--------------------------------------------------------*\
! Evaluate the memory block size if the current chunck of !
! data is written to the stream. !
\*--------------------------------------------------------*/
Lreq = (bytes_used(stream) + size);
/*--------------------------------------------------------*\
! Check if the enough memory has been allocated for the !
! stream to store the additional data chunck. !
\*--------------------------------------------------------*/
if(Lreq > stream->Lmax)
{
/*--------------------------------------------------------*\
! If the stream is not large enough, check if this is due !
! to an error encountered in a previous writing operation !
\*--------------------------------------------------------*/
if(!stream->error)
{
/*--------------------------------------------------------*\
! If the error flag is not set, increase the stream size !
! until it is large enough to store the additional data !
! chunck. !
\*--------------------------------------------------------*/
while(Lreq > stream->Lmax)
{
stream->Lmax += stream->size_incr + size;
stream->size_incr = (uint64)(stream->Lmax / 2);
}
/*--------------------------------------------------------*\
! Reallocate the stream data block. !
\*--------------------------------------------------------*/
stream->memory = realloc(stream->memory, stream->Lmax);
if(!stream->memory)
{
// memory allocation error
stream->error |= 1;
stream->Lmax = 0;
return;
}
}
else
{
/*--------------------------------------------------------*\
! Exit to function caller if error flag has been set. !
\*--------------------------------------------------------*/
return;
}
}
/*--------------------------------------------------------*\
! Copy the additional data to the stream memory block. !
\*--------------------------------------------------------*/
memcpy(stream->memory + stream->L, chunck, size);
/*--------------------------------------------------------*\
! Increment the number of bytes written to the stream with !
! the size of the newly added data chunck. !
\*--------------------------------------------------------*/
stream->L += size;
}
/*----------------------------------------------------------------------------------------------------------*\
! FUNCTION NAME: void *test(void) !
! -------------- !
! !
! DESCRIPTION: !
! ------------ !
! DESCRIPTION NEEDED !
! !
! PARAMETERS: !
! ----------- !
! Variable Type Description !
! -------- ---- ----------- !
! stream bitstream* - Structure used to assemble a bwc bit- !
! bitstream. !
! !
! size unsigned int(64 bit) - Size of the data block. !
! !
! RETURN VALUE: !
! ------------- !
! Type Description !
! ---- ----------- !
! uchar* - Data chunck requested by the function caller. !
! !
! DEVELOPMENT HISTORY: !
! -------------------- !
! !
! Date Author Change Id Release Description Of Change !
! ---- ------ --------- ------- --------------------- !
! 22.06.2019 Patrick Vogler B87D120 V 0.1.0 function created !
! !
\*----------------------------------------------------------------------------------------------------------*/
uchar*
get_chunck(bitstream *const stream, const uint64 size)
{
/*-----------------------*\
! DEFINE CHAR VARIABLES: !
\*-----------------------*/
uchar *tmp;
/*-----------------------*\
! DEFINE ASSERTIONS: !
\*-----------------------*/
assert(stream);
/*--------------------------------------------------------*\
! Check if the number of bytes to be read from the stream !
! does not exceed the number of bytes still present in its !
! memory block. !
\*--------------------------------------------------------*/
if(bytes_used(stream) + size <= stream->Lmax)
{
/*--------------------------------------------------------*\
! Allocate a temporary array used to store the bytes that !
! are extracted from the stream. !
\*--------------------------------------------------------*/
tmp = calloc(size, sizeof(uchar));
if(!tmp)
{
// memory allocation error
fprintf(stderr, MEMERROR);
return NULL;
}
/*--------------------------------------------------------*\
! Copy the bytes requested from the function caller from !
! the stream to the temporary data block. !
\*--------------------------------------------------------*/
memcpy(tmp, stream->memory + stream->L, size);
/*--------------------------------------------------------*\
! Increment the number of bytes read from the bitstream. !
\*--------------------------------------------------------*/
stream->L += size;
/*--------------------------------------------------------*\
! Return the temporary data block to the function caller. !
\*--------------------------------------------------------*/
return tmp;
}
else
{
/*--------------------------------------------------------*\
! If the requested block size exceeds the information left !
! in the bitstream, set the bitstream error flag and !
! return a NULL pointer. !
\*--------------------------------------------------------*/
stream->error |= 1;
return NULL;
}
}
/*----------------------------------------------------------------------------------------------------------*\
! FUNCTION NAME: void *test(void) !
! -------------- !
! !
! DESCRIPTION: !
! ------------ !
! DESCRIPTION NEEDED !
! !
! PARAMETERS: !
! ----------- !
! Variable Type Description !
! -------- ---- ----------- !
! - - - !
! !
! RETURN VALUE: !
! ------------- !
! Type Description !
! ---- ----------- !
! - - !
! !
! DEVELOPMENT HISTORY: !
! -------------------- !
! !
! Date Author Change Id Release Description Of Change !
! ---- ------ --------- ------- --------------------- !
! - Patrick Vogler B87D120 V 0.1.0 function created !
! !
\*----------------------------------------------------------------------------------------------------------*/
uchar
terminate_stream(bitstream *stream, bwc_stream *const packed_stream)
{
/*-----------------------*\
! DEFINE ASSERTIONS: !
\*-----------------------*/
assert(stream);
if(packed_stream)
{
if(stream->error)
{
return 1;
}
else if(stream->L != stream->Lmax)
{
stream->Lmax = stream->L;
stream->memory = realloc(stream->memory, stream->Lmax);
if(!stream->memory)
{
// memory allocation error
fprintf(stderr, MEMERROR);
stream->Lmax = 0;
return 1;
}
}
packed_stream->memory = stream->memory;
packed_stream->access = stream->memory;
packed_stream->size = stream->L;
packed_stream->position = 0;
}
else
{
free(stream->memory);
}
free(stream);
return 0;
}
/*----------------------------------------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------------------------------------*\
! ! ! !
! DESCRIPTION: ! ! DESCRIPTION: !
@ -222,7 +639,7 @@ read_eas3_header(bwc_data *const data)
! DEFINE STRUCTS: ! ! DEFINE STRUCTS: !
\*-----------------------*/ \*-----------------------*/
bwc_gl_inf *info; bwc_gl_inf *info;
bwc_stream *aux; bitstream *aux;
eas3_std_params params; eas3_std_params params;
/*-----------------------*\ /*-----------------------*\
@ -284,7 +701,7 @@ read_eas3_header(bwc_data *const data)
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Allocate the auxiliary information packed stream. ! ! Allocate the auxiliary information packed stream. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
data->codestream.aux = calloc(1, sizeof(bwc_packed_stream)); data->codestream.aux = calloc(1, sizeof(bwc_stream));
if(!data->codestream.aux) if(!data->codestream.aux)
{ {
// memory allocation error // memory allocation error
@ -299,7 +716,7 @@ read_eas3_header(bwc_data *const data)
! block has been chosen arbitrarily and should be large ! ! block has been chosen arbitrarily and should be large !
! enough to prevent excessive reallocation. ! ! enough to prevent excessive reallocation. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
aux = bwc_init_stream(NULL, AUX_SIZE, 'c'); aux = init_stream(NULL, AUX_SIZE, 'c');
if(!aux) if(!aux)
{ {
// memory allocation error // memory allocation error
@ -346,7 +763,7 @@ read_eas3_header(bwc_data *const data)
! Emit the standard parameters to the auxiliary informa- ! ! Emit the standard parameters to the auxiliary informa- !
! tion information memory block. ! ! tion information memory block. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
bwc_emit_chunck(aux, (uchar*)&params, 176); emit_chunck(aux, (uchar*)&params, 176);
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Convert the parameters required for the bwc compression ! ! Convert the parameters required for the bwc compression !
@ -423,7 +840,7 @@ read_eas3_header(bwc_data *const data)
! Emit the time step array to the auxiliary information ! ! Emit the time step array to the auxiliary information !
! memory block. ! ! memory block. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
bwc_emit_chunck(aux, buffer_char, info->nTS * sizeof(uint64)); emit_chunck(aux, buffer_char, info->nTS * sizeof(uint64));
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Check if any attributes have been specified in the eas3 ! ! Check if any attributes have been specified in the eas3 !
@ -456,7 +873,7 @@ read_eas3_header(bwc_data *const data)
! Emit the timestep attribute array to the auxiliary infor-! ! Emit the timestep attribute array to the auxiliary infor-!
! mation memory block. ! ! mation memory block. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
bwc_emit_chunck(aux, buffer_char, info->nTS * ATTRLEN * sizeof(char)); emit_chunck(aux, buffer_char, info->nTS * ATTRLEN * sizeof(char));
for(i = 0; i < info->nPar; ++i) for(i = 0; i < info->nPar; ++i)
{ {
@ -527,7 +944,7 @@ read_eas3_header(bwc_data *const data)
! Emit the remaining header information the the auxiliary ! ! Emit the remaining header information the the auxiliary !
! information stream. ! ! information stream. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
bwc_emit_chunck(aux, buffer_char, Lread); emit_chunck(aux, buffer_char, Lread);
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Free the buffer character array. ! ! Free the buffer character array. !
@ -539,7 +956,7 @@ read_eas3_header(bwc_data *const data)
! ful, the address to the aux memory block stored is ! ! ful, the address to the aux memory block stored is !
! stored in the file structure alongside its size. ! ! stored in the file structure alongside its size. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
if(bwc_terminate_stream(aux, data->codestream.aux)) if(terminate_stream(aux, data->codestream.aux))
{ {
// memory allocation error // memory allocation error
fprintf(stderr, MEMERROR); fprintf(stderr, MEMERROR);
@ -600,7 +1017,7 @@ write_eas3_header(bwc_data *const data)
! DEFINE STRUCTS: ! ! DEFINE STRUCTS: !
\*-----------------------*/ \*-----------------------*/
bwc_gl_inf *info; bwc_gl_inf *info;
bwc_stream *aux; bitstream *aux;
eas3_std_params *params; eas3_std_params *params;
bwc_cmd_opts_ll *param; bwc_cmd_opts_ll *param;
@ -634,14 +1051,14 @@ write_eas3_header(bwc_data *const data)
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Initialize the auxiliary information stream. ! ! Initialize the auxiliary information stream. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
aux = bwc_init_stream(data->codestream.aux->memory, aux = init_stream(data->codestream.aux->memory,
data->codestream.aux->size, 'd'); data->codestream.aux->size, 'd');
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Get the standard parameters from the auxiliary informa- ! ! Get the standard parameters from the auxiliary informa- !
! memory block and write them to the file stream. ! ! memory block and write them to the file stream. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
params = (eas3_std_params*)bwc_get_chunck(aux, 176); params = (eas3_std_params*)get_chunck(aux, 176);
if(fwrite(params, sizeof(uint64), 22, fp) != 22) if(fwrite(params, sizeof(uint64), 22, fp) != 22)
{ {
@ -669,7 +1086,7 @@ write_eas3_header(bwc_data *const data)
! the timestep array from the auxiliary information block ! ! the timestep array from the auxiliary information block !
! and write it to the file stream. ! ! and write it to the file stream. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
buffer_char = bwc_get_chunck(aux, info->nTS * sizeof(uint64)); buffer_char = get_chunck(aux, info->nTS * sizeof(uint64));
if(!buffer_char) if(!buffer_char)
{ {
// memory allocation error // memory allocation error
@ -698,7 +1115,7 @@ write_eas3_header(bwc_data *const data)
! the timestep attribute array from the auxiliary informa- ! ! the timestep attribute array from the auxiliary informa- !
! tion block and write it to the file stream. ! ! tion block and write it to the file stream. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
buffer_char = bwc_get_chunck(aux, info->nTS * ATTRLEN); buffer_char = get_chunck(aux, info->nTS * ATTRLEN);
if(!buffer_char) if(!buffer_char)
{ {
// memory allocation error // memory allocation error
@ -762,7 +1179,7 @@ write_eas3_header(bwc_data *const data)
! the remaining eas header bytes from the auxiliary infor- ! ! the remaining eas header bytes from the auxiliary infor- !
! mation block and write it to the file stream. ! ! mation block and write it to the file stream. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
buffer_char = bwc_get_chunck(aux, Lwrite); buffer_char = get_chunck(aux, Lwrite);
if(!buffer_char) if(!buffer_char)
{ {
// memory allocation error // memory allocation error

View file

@ -64,7 +64,7 @@
|| || || ||
\************************************************************************************************************/ \************************************************************************************************************/
/*----------------------------------------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------------------------------------*\
! FUNCTION NAME: uint32 bytes_used(bwc_stream *const stream) ! ! FUNCTION NAME: uint32 bytes_used(bitstream *const stream) !
! -------------- ! ! -------------- !
! ! ! !
! DESCRIPTION: ! ! DESCRIPTION: !
@ -76,7 +76,7 @@
! ----------- ! ! ----------- !
! Variable Type Description ! ! Variable Type Description !
! -------- ---- ----------- ! ! -------- ---- ----------- !
! stream bwc_stream* - Structure that ! ! stream bitstream* - Structure that !
! ! ! !
! RETURN VALUE: ! ! RETURN VALUE: !
! ------------- ! ! ------------- !
@ -94,7 +94,7 @@
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
uint64 uint64
bytes_used(bwc_stream const *const stream) bytes_used(bitstream const *const stream)
{ {
if(stream->T == 0xFF) if(stream->T == 0xFF)
{ {
@ -107,7 +107,7 @@ bytes_used(bwc_stream const *const stream)
} }
/*----------------------------------------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------------------------------------*\
! FUNCTION NAME: bwc_stream* bwc_init_stream(uchar* memory, uint32 size, char instr) ! ! FUNCTION NAME: bitstream* bwc_init_stream(uchar* memory, uint32 size, char instr) !
! -------------- ! ! -------------- !
! ! ! !
! DESCRIPTION: ! ! DESCRIPTION: !
@ -115,7 +115,7 @@ bytes_used(bwc_stream const *const stream)
! This function is used to initialize a bwc bitstream. For encoding, a null pointer ! ! 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 ! ! 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 ! ! specified stream size. For decoding, a valid memory handle, passed by the function !
! caller, will be stored in the bwc_stream structure. The byte buffer counter t, ! ! caller, will be stored in the bitstream structure. The byte buffer counter t, !
! stream size Lmax and size increment are initialized with their appropriate values. ! ! stream size Lmax and size increment are initialized with their appropriate values. !
! ! ! !
! PARAMETERS: ! ! PARAMETERS: !
@ -134,7 +134,7 @@ bytes_used(bwc_stream const *const stream)
! ------------- ! ! ------------- !
! Type Description ! ! Type Description !
! ---- ----------- ! ! ---- ----------- !
! bwc_stream* - Memory handle for the initialized bwc stream. ! ! bitstream* - Memory handle for the initialized bwc stream. !
! ! ! !
! DEVELOPMENT HISTORY: ! ! DEVELOPMENT HISTORY: !
! -------------------- ! ! -------------------- !
@ -144,13 +144,13 @@ bytes_used(bwc_stream const *const stream)
! 19.06.2019 Patrick Vogler B87D120 V 0.1.0 function created ! ! 19.06.2019 Patrick Vogler B87D120 V 0.1.0 function created !
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
bwc_stream* bitstream*
bwc_init_stream(uchar* memory, uint32 size, char instr) init_stream(uchar* memory, uint32 size, char instr)
{ {
/*-----------------------*\ /*-----------------------*\
! DEFINE STRUCTS: ! ! DEFINE STRUCTS: !
\*-----------------------*/ \*-----------------------*/
bwc_stream *stream; bitstream *stream;
/*-----------------------*\ /*-----------------------*\
! DEFINE ASSERTIONS: ! ! DEFINE ASSERTIONS: !
@ -160,7 +160,7 @@ bwc_init_stream(uchar* memory, uint32 size, char instr)
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Allocate the bwc stream structure. ! ! Allocate the bwc stream structure. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
stream = calloc(1, sizeof(bwc_stream)); stream = calloc(1, sizeof(bitstream));
if(!stream) if(!stream)
{ {
// memory allocation error // memory allocation error
@ -210,7 +210,7 @@ bwc_init_stream(uchar* memory, uint32 size, char instr)
} }
/*----------------------------------------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------------------------------------*\
! FUNCTION NAME: void bwc_emit_chunck(bwc_stream *const stream, const uchar* string, const uint64 length) ! ! FUNCTION NAME: void bwc_emit_chunck(bitstream *const stream, const uchar* string, const uint64 length) !
! -------------- ! ! -------------- !
! ! ! !
! DESCRIPTION: ! ! DESCRIPTION: !
@ -222,7 +222,7 @@ bwc_init_stream(uchar* memory, uint32 size, char instr)
! ----------- ! ! ----------- !
! Variable Type Description ! ! Variable Type Description !
! -------- ---- ----------- ! ! -------- ---- ----------- !
! stream bwc_stream* - Structure used to assemble a bwc bit- ! ! stream bitstream* - Structure used to assemble a bwc bit- !
! bitstream. ! ! bitstream. !
! ! ! !
! chunck unsigned char* - Memory handle for a data block that is ! ! chunck unsigned char* - Memory handle for a data block that is !
@ -245,7 +245,7 @@ bwc_init_stream(uchar* memory, uint32 size, char instr)
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
void void
bwc_emit_chunck(bwc_stream *const stream, const uchar* chunck, const uint64 size) emit_chunck(bitstream *const stream, const uchar* chunck, const uint64 size)
{ {
/*-----------------------*\ /*-----------------------*\
! DEFINE INT VARIABLES: ! ! DEFINE INT VARIABLES: !
@ -332,7 +332,7 @@ bwc_emit_chunck(bwc_stream *const stream, const uchar* chunck, const uint64 size
! ----------- ! ! ----------- !
! Variable Type Description ! ! Variable Type Description !
! -------- ---- ----------- ! ! -------- ---- ----------- !
! stream bwc_stream* - Structure used to assemble a bwc bit- ! ! stream bitstream* - Structure used to assemble a bwc bit- !
! bitstream. ! ! bitstream. !
! ! ! !
! symbol unsigned int(64 bit) - Symbol that is to be written to the bwc ! ! symbol unsigned int(64 bit) - Symbol that is to be written to the bwc !
@ -356,7 +356,7 @@ bwc_emit_chunck(bwc_stream *const stream, const uchar* chunck, const uint64 size
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
void void
bwc_emit_symbol(bwc_stream *const stream, const uint64 symbol, const uint8 size) emit_symbol(bitstream *const stream, const uint64 symbol, const uint8 size)
{ {
/*-----------------------*\ /*-----------------------*\
! DEFINE INT VARIABLES: ! ! DEFINE INT VARIABLES: !
@ -422,7 +422,7 @@ bwc_emit_symbol(bwc_stream *const stream, const uint64 symbol, const uint8 size)
} }
/*----------------------------------------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------------------------------------*\
! FUNCTION NAME: void bwc_emit_bit(bwc_stream *const stream, const uint64 bit) ! ! FUNCTION NAME: void bwc_emit_bit(bitstream *const stream, const uint64 bit) !
! -------------- ! ! -------------- !
! ! ! !
! DESCRIPTION: ! ! DESCRIPTION: !
@ -433,7 +433,7 @@ bwc_emit_symbol(bwc_stream *const stream, const uint64 symbol, const uint8 size)
! ----------- ! ! ----------- !
! Variable Type Description ! ! Variable Type Description !
! -------- ---- ----------- ! ! -------- ---- ----------- !
! stream bwc_stream* - Structure used to assemble a bwc bit- ! ! stream bitstream* - Structure used to assemble a bwc bit- !
! bitstream. ! ! bitstream. !
! ! ! !
! bit unsigned int(64 bit) - Bit that is to be written to the bwc ! ! bit unsigned int(64 bit) - Bit that is to be written to the bwc !
@ -454,7 +454,7 @@ bwc_emit_symbol(bwc_stream *const stream, const uint64 symbol, const uint8 size)
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
void void
bwc_emit_bit(bwc_stream *const stream, const uint64 bit) emit_bit(bitstream *const stream, const uint64 bit)
{ {
/*-----------------------*\ /*-----------------------*\
! DEFINE ASSERTIONS: ! ! DEFINE ASSERTIONS: !
@ -561,7 +561,7 @@ bwc_emit_bit(bwc_stream *const stream, const uint64 bit)
! ----------- ! ! ----------- !
! Variable Type Description ! ! Variable Type Description !
! -------- ---- ----------- ! ! -------- ---- ----------- !
! stream bwc_stream* - Structure used to assemble a bwc bit- ! ! stream bitstream* - Structure used to assemble a bwc bit- !
! bitstream. ! ! bitstream. !
! ! ! !
! size unsigned int(64 bit) - Size of the data block. ! ! size unsigned int(64 bit) - Size of the data block. !
@ -581,7 +581,7 @@ bwc_emit_bit(bwc_stream *const stream, const uint64 bit)
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
uchar* uchar*
bwc_get_chunck(bwc_stream *const stream, const uint64 size) get_chunck(bitstream *const stream, const uint64 size)
{ {
/*-----------------------*\ /*-----------------------*\
! DEFINE CHAR VARIABLES: ! ! DEFINE CHAR VARIABLES: !
@ -652,7 +652,7 @@ bwc_get_chunck(bwc_stream *const stream, const uint64 size)
! ----------- ! ! ----------- !
! Variable Type Description ! ! Variable Type Description !
! -------- ---- ----------- ! ! -------- ---- ----------- !
! stream bwc_stream* - Structure used to assemble a bwc bit- ! ! stream bitstream* - Structure used to assemble a bwc bit- !
! bitstream. ! ! bitstream. !
! ! ! !
! size unsigned int(8 bit) - Number of significant bytes in the ! ! size unsigned int(8 bit) - Number of significant bytes in the !
@ -673,7 +673,7 @@ bwc_get_chunck(bwc_stream *const stream, const uint64 size)
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
uint64 uint64
bwc_get_symbol(bwc_stream *const stream, const uint8 size) get_symbol(bitstream *const stream, const uint8 size)
{ {
/*-----------------------*\ /*-----------------------*\
! DEFINE INT VARIABLES: ! ! DEFINE INT VARIABLES: !
@ -751,7 +751,7 @@ bwc_get_symbol(bwc_stream *const stream, const uint8 size)
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
uchar uchar
bwc_get_bit(bwc_stream *const stream) get_bit(bitstream *const stream)
{ {
/*-----------------------*\ /*-----------------------*\
! DEFINE ASSERTIONS: ! ! DEFINE ASSERTIONS: !
@ -807,7 +807,7 @@ bwc_get_bit(bwc_stream *const stream)
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
void void
flush_stream(bwc_stream *const stream) flush_stream(bitstream *const stream)
{ {
/*-----------------------*\ /*-----------------------*\
! DEFINE ASSERTIONS: ! ! DEFINE ASSERTIONS: !
@ -896,7 +896,7 @@ flush_stream(bwc_stream *const stream)
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
uchar uchar
bwc_terminate_stream(bwc_stream *stream, bwc_packed_stream *const packed_stream) terminate_stream(bitstream *stream, bwc_stream *const packed_stream)
{ {
/*-----------------------*\ /*-----------------------*\
! DEFINE ASSERTIONS: ! ! DEFINE ASSERTIONS: !
@ -937,7 +937,7 @@ bwc_terminate_stream(bwc_stream *stream, bwc_packed_stream *const packed_stream)
} }
/*----------------------------------------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------------------------------------*\
! FUNCTION NAME: void release_packed_stream(bwc_packed_stream *stream) ! ! FUNCTION NAME: void release_packed_stream(bwc_stream *stream) !
! -------------- ! ! -------------- !
! ! ! !
! DESCRIPTION: ! ! DESCRIPTION: !
@ -949,7 +949,7 @@ bwc_terminate_stream(bwc_stream *stream, bwc_packed_stream *const packed_stream)
! ----------- ! ! ----------- !
! Variable Type Description ! ! Variable Type Description !
! -------- ---- ----------- ! ! -------- ---- ----------- !
! stream bwc_packed_stream - Packed bitstream used to store parts of ! ! stream bwc_stream - Packed bitstream used to store parts of !
! the bwc codestream. ! ! the bwc codestream. !
! ! ! !
! RETURN VALUE: ! ! RETURN VALUE: !
@ -967,7 +967,7 @@ bwc_terminate_stream(bwc_stream *stream, bwc_packed_stream *const packed_stream)
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
void void
release_packed_stream(bwc_packed_stream *stream) release_packed_stream(bwc_stream *stream)
{ {
/*-----------------------*\ /*-----------------------*\
! DEFINE ASSERTIONS: ! ! DEFINE ASSERTIONS: !

File diff suppressed because it is too large Load diff

View file

@ -612,7 +612,7 @@ initialize_subband(bwc_field *const field, bwc_parameter *const parameter, bwc_r
} }
/*----------------------------------------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------------------------------------*\
! FUNCTION NAME: void bwc_header_append_aux(bwc_field *const field, bwc_packed_stream *const aux) ! ! FUNCTION NAME: void bwc_header_append_aux(bwc_field *const field, bwc_stream *const aux) !
! -------------- ! ! -------------- !
! ! ! !
! DESCRIPTION: ! ! DESCRIPTION: !
@ -647,7 +647,7 @@ initialize_subband(bwc_field *const field, bwc_parameter *const parameter, bwc_r
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
static uchar static uchar
header_append_aux(bwc_field *const field, bwc_packed_stream *const aux) header_append_aux(bwc_field *const field, bwc_stream *const aux)
{ {
/*-----------------------*\ /*-----------------------*\
! DEFINE STRUCTS: ! ! DEFINE STRUCTS: !
@ -714,7 +714,7 @@ header_append_aux(bwc_field *const field, bwc_packed_stream *const aux)
} }
/*----------------------------------------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------------------------------------*\
! FUNCTION NAME: void bwc_header_append_com(bwc_field *const field, bwc_packed_stream *const com) ! ! FUNCTION NAME: void bwc_header_append_com(bwc_field *const field, bwc_stream *const com) !
! -------------- ! ! -------------- !
! ! ! !
! DESCRIPTION: ! ! DESCRIPTION: !
@ -749,7 +749,7 @@ header_append_aux(bwc_field *const field, bwc_packed_stream *const aux)
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
static uchar static uchar
header_append_com(bwc_field *const field, bwc_packed_stream *const com) header_append_com(bwc_field *const field, bwc_stream *const com)
{ {
/*-----------------------*\ /*-----------------------*\
! DEFINE STRUCTS: ! ! DEFINE STRUCTS: !

View file

@ -419,7 +419,7 @@ initialize_tagtree(const uint64 leafsX, const uint64 leafsY, const uint64 leafsZ
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
void void
encode_tagtree(bwc_tagtree *const tagtree, bwc_stream *const stream, const uint32 threshold, const uint32 leaf_index, const uchar estimate) encode_tagtree(bwc_tagtree *const tagtree, bitstream *const stream, const uint32 threshold, const uint32 leaf_index, const uchar estimate)
{ {
/*-----------------------*\ /*-----------------------*\
! DEFINE INT VARIABLES: ! ! DEFINE INT VARIABLES: !
@ -461,11 +461,11 @@ encode_tagtree(bwc_tagtree *const tagtree, bwc_stream *const stream, const uint3
threshold_tmp++; threshold_tmp++;
if(node->value >= threshold_tmp) if(node->value >= threshold_tmp)
{ {
bwc_emit_bit(stream, 0); emit_bit(stream, 0);
} }
else else
{ {
bwc_emit_bit(stream, 1); emit_bit(stream, 1);
} }
} }
@ -512,7 +512,7 @@ encode_tagtree(bwc_tagtree *const tagtree, bwc_stream *const stream, const uint3
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
uchar uchar
decode_tagtree(bwc_tagtree *const tagtree, bwc_stream *const stream, const uint32 threshold, const uint32 leaf_index) decode_tagtree(bwc_tagtree *const tagtree, bitstream *const stream, const uint32 threshold, const uint32 leaf_index)
{ {
/*-----------------------*\ /*-----------------------*\
! DEFINE INT VARIABLES: ! ! DEFINE INT VARIABLES: !
@ -556,7 +556,7 @@ decode_tagtree(bwc_tagtree *const tagtree, bwc_stream *const stream, const uint3
while((node->value == node->threshold) && (node->threshold < threshold)) while((node->value == node->threshold) && (node->threshold < threshold))
{ {
node->threshold++; node->threshold++;
if(!bwc_get_bit(stream)) if(!get_bit(stream))
{ {
node->value++; node->value++;
} }

View file

@ -99,71 +99,71 @@
{ \ { \
if(delta_z == 1) \ if(delta_z == 1) \
{ \ { \
bwc_emit_bit(stream, 0); \ emit_bit(stream, 0); \
} \ } \
else if(delta_z == 2) \ else if(delta_z == 2) \
{ \ { \
bwc_emit_bit(stream, 1); \ emit_bit(stream, 1); \
bwc_emit_bit(stream, 0); \ emit_bit(stream, 0); \
} \ } \
else if(delta_z < 6) \ else if(delta_z < 6) \
{ \ { \
delta_z -= 3; \ delta_z -= 3; \
bwc_emit_bit(stream, 1); \ emit_bit(stream, 1); \
bwc_emit_bit(stream, 1); \ emit_bit(stream, 1); \
bwc_emit_bit(stream, 0x02 & delta_z); \ emit_bit(stream, 0x02 & delta_z); \
bwc_emit_bit(stream, 0x01 & delta_z); \ emit_bit(stream, 0x01 & delta_z); \
} \ } \
else if(delta_z < 37) \ else if(delta_z < 37) \
{ \ { \
delta_z -= 6; \ delta_z -= 6; \
bwc_emit_bit(stream, 1); \ emit_bit(stream, 1); \
bwc_emit_bit(stream, 1); \ emit_bit(stream, 1); \
bwc_emit_bit(stream, 1); \ emit_bit(stream, 1); \
bwc_emit_bit(stream, 1); \ emit_bit(stream, 1); \
bwc_emit_bit(stream, 0x10 & delta_z); \ emit_bit(stream, 0x10 & delta_z); \
bwc_emit_bit(stream, 0x08 & delta_z); \ emit_bit(stream, 0x08 & delta_z); \
bwc_emit_bit(stream, 0x04 & delta_z); \ emit_bit(stream, 0x04 & delta_z); \
bwc_emit_bit(stream, 0x02 & delta_z); \ emit_bit(stream, 0x02 & delta_z); \
bwc_emit_bit(stream, 0x01 & delta_z); \ emit_bit(stream, 0x01 & delta_z); \
} \ } \
else if(delta_z < 293) \ else if(delta_z < 293) \
{ \ { \
delta_z -= 37; \ delta_z -= 37; \
bwc_emit_bit(stream, 1); \ emit_bit(stream, 1); \
bwc_emit_bit(stream, 1); \ emit_bit(stream, 1); \
bwc_emit_bit(stream, 1); \ emit_bit(stream, 1); \
bwc_emit_bit(stream, 1); \ emit_bit(stream, 1); \
bwc_emit_bit(stream, 1); \ emit_bit(stream, 1); \
bwc_emit_bit(stream, 1); \ emit_bit(stream, 1); \
bwc_emit_bit(stream, 1); \ emit_bit(stream, 1); \
bwc_emit_bit(stream, 1); \ emit_bit(stream, 1); \
bwc_emit_bit(stream, 1); \ emit_bit(stream, 1); \
bwc_emit_bit(stream, 0x080 & delta_z); \ emit_bit(stream, 0x080 & delta_z); \
bwc_emit_bit(stream, 0x040 & delta_z); \ emit_bit(stream, 0x040 & delta_z); \
bwc_emit_bit(stream, 0x020 & delta_z); \ emit_bit(stream, 0x020 & delta_z); \
bwc_emit_bit(stream, 0x010 & delta_z); \ emit_bit(stream, 0x010 & delta_z); \
bwc_emit_bit(stream, 0x008 & delta_z); \ emit_bit(stream, 0x008 & delta_z); \
bwc_emit_bit(stream, 0x004 & delta_z); \ emit_bit(stream, 0x004 & delta_z); \
bwc_emit_bit(stream, 0x002 & delta_z); \ emit_bit(stream, 0x002 & delta_z); \
bwc_emit_bit(stream, 0x001 & delta_z); \ emit_bit(stream, 0x001 & delta_z); \
} \ } \
} }
#define decode_delta_z(stream, delta_z) \ #define decode_delta_z(stream, delta_z) \
{ \ { \
if(!bwc_get_bit(stream)) \ if(!get_bit(stream)) \
{ \ { \
delta_z = 1; \ delta_z = 1; \
} \ } \
else if(!bwc_get_bit(stream)) \ else if(!get_bit(stream)) \
{ \ { \
delta_z = 2; \ delta_z = 2; \
} \ } \
else \ else \
{ \ { \
delta_z = (bwc_get_bit(stream) << 1) | \ delta_z = (get_bit(stream) << 1) | \
bwc_get_bit(stream); \ get_bit(stream); \
\ \
if(delta_z < 3) \ if(delta_z < 3) \
{ \ { \
@ -171,11 +171,11 @@
} \ } \
else \ else \
{ \ { \
delta_z = (bwc_get_bit(stream) << 4) | \ delta_z = (get_bit(stream) << 4) | \
(bwc_get_bit(stream) << 3) | \ (get_bit(stream) << 3) | \
(bwc_get_bit(stream) << 2) | \ (get_bit(stream) << 2) | \
(bwc_get_bit(stream) << 1) | \ (get_bit(stream) << 1) | \
bwc_get_bit(stream); \ get_bit(stream); \
\ \
if(delta_z < 31) \ if(delta_z < 31) \
{ \ { \
@ -183,14 +183,14 @@
} \ } \
else \ else \
{ \ { \
delta_z = (bwc_get_bit(stream) << 7) | \ delta_z = (get_bit(stream) << 7) | \
(bwc_get_bit(stream) << 6) | \ (get_bit(stream) << 6) | \
(bwc_get_bit(stream) << 5) | \ (get_bit(stream) << 5) | \
(bwc_get_bit(stream) << 4) | \ (get_bit(stream) << 4) | \
(bwc_get_bit(stream) << 3) | \ (get_bit(stream) << 3) | \
(bwc_get_bit(stream) << 2) | \ (get_bit(stream) << 2) | \
(bwc_get_bit(stream) << 1) | \ (get_bit(stream) << 1) | \
bwc_get_bit(stream); \ get_bit(stream); \
\ \
delta_z += 37; \ delta_z += 37; \
} \ } \
@ -205,7 +205,7 @@
|| || || ||
\************************************************************************************************************/ \************************************************************************************************************/
/*----------------------------------------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------------------------------------*\
! FUNCTION NAME: void encode_length(bwc_stream *const header, bwc_codeblock *const codeblock, ! ! FUNCTION NAME: void encode_length(bitstream *const header, bwc_codeblock *const codeblock, !
! -------------- int8 const quality_layer, ! ! -------------- int8 const quality_layer, !
! uchar const estimate) ! ! uchar const estimate) !
! ! ! !
@ -236,7 +236,7 @@
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
static void static void
encode_length(bwc_stream *const header, bwc_codeblock *const codeblock, encode_length(bitstream *const header, bwc_codeblock *const codeblock,
int8 const quality_layer, int8 const quality_layer,
uchar const estimate) uchar const estimate)
{ {
@ -284,17 +284,17 @@ encode_length(bwc_stream *const header, bwc_codeblock *const codeblock,
while(beta < max_beta) while(beta < max_beta)
{ {
bwc_emit_bit(header, 1); emit_bit(header, 1);
beta++; beta++;
} }
bwc_emit_bit(header, 0); emit_bit(header, 0);
L_bits = 1 << (beta + cp_bits - 1); L_bits = 1 << (beta + cp_bits - 1);
while(L_bits > 0) while(L_bits > 0)
{ {
bwc_emit_bit(header, L & L_bits); emit_bit(header, L & L_bits);
L_bits >>= 1; L_bits >>= 1;
} }
@ -339,7 +339,7 @@ encode_length(bwc_stream *const header, bwc_codeblock *const codeblock,
! ! ! !
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
static void static void
decode_length(bwc_stream *const header, bwc_codeblock *const codeblock, int8 const quality_layer) decode_length(bitstream *const header, bwc_codeblock *const codeblock, int8 const quality_layer)
{ {
/*-----------------------*\ /*-----------------------*\
! DEFINE INT VARIABLES: ! ! DEFINE INT VARIABLES: !
@ -363,7 +363,7 @@ decode_length(bwc_stream *const header, bwc_codeblock *const codeblock, int8 con
cblk_ctrl = &codeblock->control; cblk_ctrl = &codeblock->control;
cp_contr = cblk_ctrl->cp_contr; cp_contr = cblk_ctrl->cp_contr;
while(bwc_get_bit(header)) while(get_bit(header))
{ {
cblk_ctrl->beta++; cblk_ctrl->beta++;
} }
@ -376,7 +376,7 @@ decode_length(bwc_stream *const header, bwc_codeblock *const codeblock, int8 con
for(i = 0; L_bits > 0; --L_bits) for(i = 0; L_bits > 0; --L_bits)
{ {
i <<= 1; i <<= 1;
i |= bwc_get_bit(header); i |= get_bit(header);
} }
codeblock->encoded_block->L[z_curr] = ((z_prev >= 0) ? codeblock->encoded_block->L[z_prev] : 0) + i; codeblock->encoded_block->L[z_curr] = ((z_prev >= 0) ? codeblock->encoded_block->L[z_prev] : 0) + i;
@ -455,7 +455,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile,
bwc_packet *packet; bwc_packet *packet;
bwc_precinct *precinct; bwc_precinct *precinct;
bwc_codeblock *codeblock; bwc_codeblock *codeblock;
bwc_stream *header; bitstream *header;
/*-----------------------*\ /*-----------------------*\
! DEFINE ASSERTIONS: ! ! DEFINE ASSERTIONS: !
@ -480,7 +480,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile,
! Initialize the stream that is used to assemble the pack- ! ! Initialize the stream that is used to assemble the pack- !
! et header. ! ! et header. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
header = bwc_init_stream(NULL, PACKET_HEADER_SIZE, 'c'); header = init_stream(NULL, PACKET_HEADER_SIZE, 'c');
if(!header) if(!header)
{ {
// memory allocation error // memory allocation error
@ -496,7 +496,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile,
if(!est) if(!est)
{ {
packet->body.access = packet->body.access =
packet->body.memory = calloc(packet->body.size, sizeof(bwc_packed_stream)); packet->body.memory = calloc(packet->body.size, sizeof(bwc_stream));
if(!packet->body.memory) if(!packet->body.memory)
{ {
// memory allocation error // memory allocation error
@ -509,7 +509,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile,
! Emit the contribution bit to the packet header that sig- ! ! Emit the contribution bit to the packet header that sig- !
! nals a non-empty packet body. ! ! nals a non-empty packet body. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
bwc_emit_bit(header, 1); emit_bit(header, 1);
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Iterate over all codeblocks in all subbands to assemble ! ! Iterate over all codeblocks in all subbands to assemble !
@ -571,7 +571,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile,
! If a contribution has already been made, transmit a flag ! ! If a contribution has already been made, transmit a flag !
! to signal if new coding passes are to be contributed. ! ! to signal if new coding passes are to be contributed. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
bwc_emit_bit(header, delta_z); emit_bit(header, delta_z);
} }
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
@ -642,7 +642,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile,
} }
k = header->L; k = header->L;
bwc_terminate_stream(header, NULL); terminate_stream(header, NULL);
return k; return k;
} }
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
@ -653,7 +653,7 @@ create_packet(bwc_field *const field, bwc_tile *const tile,
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
else else
{ {
if(bwc_terminate_stream(header, &packet->header)) if(terminate_stream(header, &packet->header))
{ {
// memory allocation error // memory allocation error
return -1; return -1;
@ -1375,7 +1375,7 @@ parse_packet(bwc_field *const field, bwc_tile *const tile,
bwc_precinct *precinct; bwc_precinct *precinct;
bwc_codeblock *codeblock; bwc_codeblock *codeblock;
bwc_encoded_cblk *encoded_block; bwc_encoded_cblk *encoded_block;
bwc_stream *header; bitstream *header;
/*-----------------------*\ /*-----------------------*\
! DEFINE ASSERTIONS: ! ! DEFINE ASSERTIONS: !
@ -1390,7 +1390,7 @@ parse_packet(bwc_field *const field, bwc_tile *const tile,
! Initialize the stream that is used to parse the packet ! ! Initialize the stream that is used to parse the packet !
! codestream. ! ! codestream. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
header = bwc_init_stream(packet->header.memory, body_size, 'd'); header = init_stream(packet->header.memory, body_size, 'd');
if(!header) if(!header)
{ {
// memory allocation error // memory allocation error
@ -1401,7 +1401,7 @@ parse_packet(bwc_field *const field, bwc_tile *const tile,
! Extract the codeblock contribution marker from the code- ! ! Extract the codeblock contribution marker from the code- !
! stream. ! ! stream. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
packet->e = bwc_get_bit(header); packet->e = get_bit(header);
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Check if the current packet has any codeblock contribu- ! ! Check if the current packet has any codeblock contribu- !
@ -1471,7 +1471,7 @@ parse_packet(bwc_field *const field, bwc_tile *const tile,
! flag from the codestream that signals if new coding pas- ! ! flag from the codestream that signals if new coding pas- !
! ses are available. ! ! ses are available. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
delta_z = bwc_get_bit(header); delta_z = get_bit(header);
} }

View file

@ -1508,7 +1508,6 @@ output_info(bwc_cmdl_arg_node *const args,
bwc_cmdl_arg_node *temp; bwc_cmdl_arg_node *temp;
bwc_stream *stream;
struct stat buf; struct stat buf;
/*-----------------------*\ /*-----------------------*\
@ -1672,7 +1671,7 @@ output_info(bwc_cmdl_arg_node *const args,
return; return;
} }
data->codestream.data = calloc(1, sizeof(bwc_packed_stream)); data->codestream.data = calloc(1, sizeof(bwc_stream));
if(data->codestream.data == NULL) if(data->codestream.data == NULL)
{ {
// memory allocation error // memory allocation error
@ -1713,33 +1712,16 @@ output_info(bwc_cmdl_arg_node *const args,
! Initialize the bitstream, parse the main header and set ! ! Initialize the bitstream, parse the main header and set !
! up the field structure for the current dataset. ! ! up the field structure for the current dataset. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
stream = calloc(1, sizeof(bwc_stream)); field = bwc_create_decompression(data, 0);
if(stream == NULL)
{
// memory allocation error
fprintf(stderr, MEMERROR);
return;
}
stream->memory = data->codestream.data->memory;
stream->t = 0;
stream->Lmax = data->codestream.data->size;
stream->size_incr = (uint64)(stream->Lmax / 2);
field = bwc_parse_main_header(data, stream);
if(field == NULL) if(field == NULL)
{ {
bwc_free_data(data); bwc_free_data(data);
free(stream);
fclose(fp); fclose(fp);
return; return;
} }
control = &field->control; control = &field->control;
info = field->info; info = field->info;
free(stream);
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Write the help message to the standard output. ! ! Write the help message to the standard output. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
@ -1755,16 +1737,15 @@ output_info(bwc_cmdl_arg_node *const args,
"| .+++=--------=+++---=+++---=+++------------: |\n"\ "| .+++=--------=+++---=+++---=+++------------: |\n"\
"| -=++++++++++++++++++++++++++++++++++++++++- |\n"\ "| -=++++++++++++++++++++++++++++++++++++++++- |\n"\
"| |\n"\ "| |\n"\
"|-------------------------------General Information------------------------------|\n"\ "|------------------------------ General Information -----------------------------|\n"\
"| |\n"); "| |\n");
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Print the original file size and format. ! ! Print the original file size and format. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
fseek(fp, 0L, SEEK_END); data_points = (uint64)info->nX * info->nY * info->nZ *
Ld = ftell(fp); info->nTS * info->nPar;
buff = get_size(Ld); buff = get_size(data_points * 8);
fclose(fp);
printf("| Original size: %42s |\n"\ printf("| Original size: %42s |\n"\
"| Original file format: %42s |\n"\ "| Original file format: %42s |\n"\
@ -1775,9 +1756,10 @@ output_info(bwc_cmdl_arg_node *const args,
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Print the file size and compression ratio. ! ! Print the file size and compression ratio. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
data_points = (uint64)info->nX * info->nY * info->nZ * fseek(fp, 0L, SEEK_END);
info->nTS * info->nPar; Ld = ftell(fp);
buff = get_size(data_points * 8); buff = get_size(Ld);
fclose(fp);
printf("| Size on Disk: %42s |\n"\ printf("| Size on Disk: %42s |\n"\
"| Comp. Ratio: %42.2f |\n"\ "| Comp. Ratio: %42.2f |\n"\
@ -1814,7 +1796,7 @@ output_info(bwc_cmdl_arg_node *const args,
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
! Print the numerical Datapoints. ! ! Print the numerical Datapoints. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
printf("|------------------------------Numerical Parameters------------------------------|\n"\ printf("|----------------------------- Numerical Parameters -----------------------------|\n"\
"| |\n"); "| |\n");
for(p = 0; p < info->nPar; ++p) for(p = 0; p < info->nPar; ++p)
@ -1835,19 +1817,23 @@ output_info(bwc_cmdl_arg_node *const args,
while(buff > param_info->name && isspace((unsigned char)*buff)) buff--; while(buff > param_info->name && isspace((unsigned char)*buff)) buff--;
buff[1] = '\0'; buff[1] = '\0';
printf("| Name: %55s |\n"\ if(p != 0)
"| Minimum value: %55.2e |\n"\ {
"| Maximum value: %55.2e |\n"\ printf("| ........................................................................ |\n"
"| ........................................................................ |\n" "|%80s|\n"," ");
"|%80s|\n", param_info->name,
minVal,
maxVal, " ");
} }
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. ! ! Print the quality layers. !
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
printf("|---------------------------------Quality Layers---------------------------------|\n"\ printf("|-------------------------------- Quality Layers --------------------------------|\n"\
"| |\n"); "| |\n");
for(l = 0; l < control->nLayers; ++l) for(l = 0; l < control->nLayers; ++l)
@ -1959,7 +1945,7 @@ read_bwc(char *const filename)
return NULL; return NULL;
} }
file->codestream.data = calloc(1, sizeof(bwc_packed_stream)); file->codestream.data = calloc(1, sizeof(bwc_stream));
if(file->codestream.data == NULL) if(file->codestream.data == NULL)
{ {
// memory allocation error // memory allocation error