Preliminary split of libbwc.c in libbwc.c and codec.c. The new codec.c source file will contain all functions that create or modify the bwc_codec struct

This commit is contained in:
Patrick Vogler 2024-06-27 14:47:10 +02:00
parent 8b6a3ac561
commit bbbb6117a9
Signed by: Patrick Vogler
GPG key ID: 5536B08CE82E8509
2 changed files with 915 additions and 1132 deletions

915
src/library/codec.c Normal file
View file

@ -0,0 +1,915 @@
/*================================================================================================*\
|| ||
|| /$$$$$$$ /$$ /$$ /$$ /$$ ||
|| | $$__ $$|__/ | $$ /$ | $$| $$ ||
|| | $$ \ $$ /$$ /$$$$$$ | $$ /$$$| $$| $$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ ||
|| | $$$$$$$ | $$ /$$__ $$ | $$/$$ $$ $$| $$__ $$ /$$__ $$ /$$__ $$ /$$__ $$ ||
|| | $$__ $$| $$| $$ \ $$ | $$$$_ $$$$| $$ \ $$| $$ \ $$| $$ \ $$| $$ \ $$ ||
|| | $$ \ $$| $$| $$ | $$ | $$$/ \ $$$| $$ | $$| $$ | $$| $$ | $$| $$ | $$ ||
|| | $$$$$$$/| $$| $$$$$$$ | $$/ \ $$| $$ | $$| $$$$$$/| $$$$$$/| $$$$$$$/ ||
|| |_______/ |__/ \____ $$ |__/ \__/|__/ |__/ \______/ \______/ | $$____/ ||
|| /$$ \ $$ | $$ ||
|| | $$$$$$/ | $$ ||
|| \______/ |__/ ||
|| ||
|| DESCRIPTION: ||
|| ------------ ||
|| ||
|| DESCRIPTION NEEDED. ||
|| | | ||
|| ||
|| -------------------------------------------------------------------------------------------- ||
|| 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. ||
|| ||
\*================================================================================================*/
/**************************************************************************************************\
|| _ _ _ ____ _ _ _ ___ ____ ||
|| | |\ | | | | | | \ |___ ||
|| | | \| |___ |___ |__| |__/ |___ ||
|| ||
\**************************************************************************************************/
/**************************************************************************************************\
|| ___ ____ _ _ _ ____ ___ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ ||
|| |__] |__/ | | | |__| | |___ |___ | | |\ | | | | | | |\ | [__ ||
|| | | \ | \/ | | | |___ | |__| | \| |___ | | |__| | \| ___] ||
|| ||
\**************************************************************************************************/
/**************************************************************************************************\
|| ___ _ _ ___ _ _ ____ ____ _ _ _ _ ____ ___ _ ____ _ _ ____ ||
|| |__] | | |__] | | | |___ | | |\ | | | | | | |\ | [__ ||
|| | |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___] ||
|| ||
\**************************************************************************************************/
/*------------------------------------------------------------------------------------------------*\
! !
! DESCRIPTION: !
! ------------ !
! !
! DESCRIPTION NEEDED !
! | | !
! !
! RETURN: !
! ------- !
! !
! DESCRIPTION NEEDED !
! | | !
! !
\*------------------------------------------------------------------------------------------------*/
uchar
bwc_set_com(bwc_data *const data, char const *const com, uint16 size)
{
/*-----------------------*\
! DEFINE ASSERTIONS: !
\*-----------------------*/
assert(data);
assert(com);
/*--------------------------------------------------------*\
! 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)
{
// memory allocation error
fprintf(stderr, MEMERROR);
return 1;
}
memcpy(data->codestream.com->memory, com, size * sizeof(char));
data->codestream.com->access = data->codestream.com->memory;
data->codestream.com->size = size;
data->codestream.com->position = 0;
return 0;
}
/*------------------------------------------------------------------------------------------------*\
! !
! DESCRIPTION: !
! ------------ !
! !
! DESCRIPTION NEEDED !
! | | !
! !
! RETURN: !
! ------- !
! !
! DESCRIPTION NEEDED !
! | | !
! !
\*------------------------------------------------------------------------------------------------*/
uchar
bwc_set_aux(bwc_data *const data, char const *const aux, uint32 size)
{
/*-----------------------*\
! DEFINE ASSERTIONS: !
\*-----------------------*/
assert(data);
assert(aux);
/*--------------------------------------------------------*\
! 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)
{
// 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;
return 0;
}
/*------------------------------------------------------------------------------------------------*\
! !
! DESCRIPTION: !
! ------------ !
! !
! This function sets the error resilience marker in the bwc_field structure if an !
! error resilient compression approach is to be employed. !
! !
! RETURN: !
! ------- !
! !
! - !
! !
\*------------------------------------------------------------------------------------------------*/
void
bwc_set_error_resilience(bwc_field *const field)
{
/*-----------------------*\
! DEFINE ASSERTIONS: !
\*-----------------------*/
assert(field);
/*--------------------------------------------------------*\
! Set the error resilience flag in the bwc_field structure !
! and record the setting in the CSsgc variable. !
\*--------------------------------------------------------*/
field->control.resilience ^= 0x01;
field->control.CSsgc ^= (0x01 << 0);
}
/*------------------------------------------------------------------------------------------------*\
! !
! DESCRIPTION: !
! ------------ !
! !
! This function amends the quantization style in the bwc_field structure according !
! to the specified value. !
! !
! RETURN: !
! ------- !
! !
! - !
! !
\*------------------------------------------------------------------------------------------------*/
void
set_quant_style(bwc_field *const field,
bwc_quant_st const quantization_style)
{
/*-----------------------*\
! DEFINE ASSERTIONS: !
\*-----------------------*/
assert(field);
assert((quantization_style == bwc_qt_derived) ||
(quantization_style == bwc_qt_none));
/*--------------------------------------------------------*\
! Amend the quantization style in the bwc_field structure !
! and record the setting in the CSsgc variable. !
\*--------------------------------------------------------*/
field->control.quantization_style = quantization_style;
field->control.CSsgc |= (0x01 << 1);
}
/*------------------------------------------------------------------------------------------------*\
! !
! DESCRIPTION: !
! ------------ !
! !
! This function amends the quantization step size in the bwc_field structure !
! according to the specified value. !
! !
! RETURN: !
! ------- !
! !
! - !
! !
\*------------------------------------------------------------------------------------------------*/
void
set_quant_step_size(bwc_field *const field,
double delta)
{
/*-----------------------*\
! DEFINE STRUCTS: !
\*-----------------------*/
bwc_gl_ctrl *control;
/*-----------------------*\
! DEFINE ASSERTIONS: !
\*-----------------------*/
assert(field);
/*--------------------------------------------------------*\
! Save frequently used variables/structures to temporary !
! variables to make the code more readable. !
\*--------------------------------------------------------*/
control = &field->control;
/*--------------------------------------------------------*\
! Check if the quantization step size lies within the ac- !
! ceptable range. !
\*--------------------------------------------------------*/
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");
return;
}
/*--------------------------------------------------------*\
! Reevaluate the mantissa and exponent of the user defined !
! quantization step size. !
\*--------------------------------------------------------*/
for(control->qt_exponent = 0; delta < 1; ++control->qt_exponent, delta *= 2);
control->qt_mantissa = (uint16)floor(0.5f + ((delta - 1.0f) * (1 << 16)));
if(control->qt_exponent > PREC_BIT)
{
control->qt_exponent = PREC_BIT;
control->qt_mantissa = 0;
}
if(control->qt_mantissa >= 1 << 16)
{
if(control->qt_exponent == 0)
{
control->qt_exponent = 0;
control->qt_mantissa = (1 << 16) - 1;
}
else
{
control->qt_exponent--;
control->qt_mantissa = 0;
}
}
/*--------------------------------------------------------*\
! Record the setting of the quantization step size in the !
! CSsgc variable. !
\*--------------------------------------------------------*/
control->CSsgc |= (0x01 << 2);
}
/*------------------------------------------------------------------------------------------------*\
! !
! DESCRIPTION: !
! ------------ !
! !
! This function amends the progression order in the bwc_field structure according !
! to the specified value. !
! !
! RETURN: !
! ------- !
! !
! - !
! !
\*------------------------------------------------------------------------------------------------*/
void
set_progression(bwc_field *const field,
bwc_prog_ord const progression)
{
/*-----------------------*\
! DEFINE ASSERTIONS: !
\*-----------------------*/
assert(field);
assert((progression == bwc_prog_CPRL) || (progression == bwc_prog_LRCP) ||
(progression == bwc_prog_PCRL) || (progression == bwc_prog_RLCP) ||
(progression == bwc_prog_RPCL));
/*--------------------------------------------------------*\
! Set the progression order in the bwc_field structure and !
! record the setting in the CSsgc variable. !
\*--------------------------------------------------------*/
field->control.progression = progression;
field->control.CSsgc |= (0x01 << 3);
}
/*------------------------------------------------------------------------------------------------*\
! !
! DESCRIPTION: !
! ------------ !
! !
! This function amends the wavelet kernels in the bwc_field structure according !
! to the specified values. !
! !
! RETURN: !
! ------- !
! !
! - !
! !
\*------------------------------------------------------------------------------------------------*/
void
set_kernels(bwc_field *const field,
bwc_dwt_filter const KernelX,
bwc_dwt_filter const KernelY,
bwc_dwt_filter const KernelZ,
bwc_dwt_filter const KernelTS)
{
/*-----------------------*\
! DEFINE ASSERTIONS: !
\*-----------------------*/
assert(field);
/*--------------------------------------------------------*\
! Set the wavelet kernel in the bwc_field structure and !
! record the setting in the CSsgc variable. !
\*--------------------------------------------------------*/
field->control.KernelX = KernelX ? KernelX : bwc_dwt_9_7;
field->control.KernelY = KernelY ? KernelY : bwc_dwt_9_7;
field->control.KernelZ = KernelZ ? KernelZ : bwc_dwt_9_7;
field->control.KernelTS = KernelTS ? KernelTS : bwc_dwt_haar;
field->control.CSsgc |= (0x01 << 4);
}
/*------------------------------------------------------------------------------------------------*\
! !
! DESCRIPTION: !
! ------------ !
! !
! This function amends the decomposition levels in the bwc_field structure !
! according to the specified values. !
! !
! RETURN: !
! ------- !
! !
! - !
! !
\*------------------------------------------------------------------------------------------------*/
void
bwc_set_decomp(bwc_field *const field,
uint8 const decompX,
uint8 const decompY,
uint8 const decompZ,
uint8 const decompTS)
{
/*-----------------------*\
! DEFINE FLOAT VARIABLES: !
\*-----------------------*/
double delta;
/*-----------------------*\
! DEFINE CHAR VARIABLES: !
\*-----------------------*/
uint8 levelsX, levelsY, levelsZ, levelsTS;
/*-----------------------*\
! DEFINE STRUCTS: !
\*-----------------------*/
bwc_gl_ctrl *control;
bwc_gl_inf *info;
/*-----------------------*\
! DEFINE ASSERTIONS: !
\*-----------------------*/
assert(field);
/*--------------------------------------------------------*\
! Save frequently used variables/structures to temporary !
! variables to make the code more readable. !
\*--------------------------------------------------------*/
control = &field->control;
info = field->info;
/*--------------------------------------------------------*\
! Calculate the maximum posssible decorrelations and eval- !
! uate the number of decomposition levels accordingly. !
\*--------------------------------------------------------*/
levelsX = log(info->nX) /log(2);
levelsY = log(info->nY) /log(2);
levelsZ = log(info->nZ) /log(2);
levelsTS = log(info->nTS)/log(2);
control->decompX = (info->nX >> 1) ? ((decompX < levelsX) ? decompX : levelsX) : 0;
control->decompY = (info->nY >> 1) ? ((decompY < levelsY) ? decompY : levelsY) : 0;
control->decompZ = (info->nZ >> 1) ? ((decompZ < levelsZ) ? decompZ : levelsZ) : 0;
control->decompTS = (info->nTS >> 1) ? ((decompTS < levelsTS) ? decompTS : levelsTS) : 0;
control->nDecomp = MAX(control->decompX,
MAX(control->decompY,
MAX(control->decompZ, control->decompTS)));
/*--------------------------------------------------------*\
! Check validity of decomp levels and, if necessary, reset !
! them to teir standard values. !
\*--------------------------------------------------------*/
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");
control->decompX = (info->nX >> 1) ? 4 : 0;
control->decompY = (info->nY >> 1) ? 4 : 0;
control->decompZ = (info->nZ >> 1) ? 4 : 0;
control->decompTS = (info->nTS >> 1) ? 4 : 0;
return;
}
/*--------------------------------------------------------*\
! Record the setting of the decomposition level variables !
! in the CSsgc variable. !
\*--------------------------------------------------------*/
control->CSsgc |= (0x01 << 5);
}
/*------------------------------------------------------------------------------------------------*\
! !
! DESCRIPTION: !
! ------------ !
! !
! This function amends the precinct size in the bwc_field structure according !
! to the specified values. !
! !
! RETURN: !
! ------- !
! !
! - !
! !
\*------------------------------------------------------------------------------------------------*/
void
bwc_set_precincts(bwc_field *const field,
uint8 const pX,
uint8 const pY,
uint8 const pZ,
uint8 const pTS)
{
/*-----------------------*\
! DEFINE STRUCTS: !
\*-----------------------*/
bwc_gl_ctrl *control;
bwc_gl_inf *info;
/*-----------------------*\
! DEFINE ASSERTIONS: !
\*-----------------------*/
assert(field);
/*--------------------------------------------------------*\
! Save frequently used variables/structures to temporary !
! variables to make the code more readable. !
\*--------------------------------------------------------*/
control = &field->control;
info = field->info;
/*--------------------------------------------------------*\
! Set the specified precinct values for all valid dimen- !
! sions taking the maximum allowable size into account. !
\*--------------------------------------------------------*/
control->precSizeX = (info->nX >> 1) ? (pX ? pX : 15) : 0;
control->precSizeY = (info->nY >> 1) ? (pY ? pY : 15) : 0;
control->precSizeZ = (info->nZ >> 1) ? (pZ ? pZ : 15) : 0;
control->precSizeTS = (info->nTS >> 1) ? (pTS ? pTS : 15) : 0;
/*--------------------------------------------------------*\
! Check validity of the precint size and reset them, if !
! necessary to teir standard values. !
\*--------------------------------------------------------*/
if(((control->precSizeX < 1) && (info->nX >> 1)) ||
((control->precSizeY < 1) && (info->nY >> 1)) ||
((control->precSizeZ < 1) && (info->nZ >> 1)) ||
((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");
control->precSizeX = (info->nX >> 1) ? 15 : 0;
control->precSizeY = (info->nY >> 1) ? 15 : 0;
control->precSizeZ = (info->nZ >> 1) ? 15 : 0;
control->precSizeTS = (info->nTS >> 1) ? 15 : 0;
return;
}
/*--------------------------------------------------------*\
! Record the setting of the precinct size variables in the !
! CSsgc variable. !
\*--------------------------------------------------------*/
control->CSsgc |= (0x01 << 6);
}
/*------------------------------------------------------------------------------------------------*\
! !
! DESCRIPTION: !
! ------------ !
! !
! This function amends the codeblock size in the bwc_field structure according !
! to the specified values. !
! !
! RETURN: !
! ------- !
! !
! - !
! !
\*------------------------------------------------------------------------------------------------*/
void
bwc_set_codeblocks(bwc_field *const field,
uint8 const cbX,
uint8 const cbY,
uint8 const cbZ,
uint8 const cbTS)
{
/*-----------------------*\
! DEFINE STRUCTS: !
\*-----------------------*/
bwc_gl_ctrl *control;
bwc_gl_inf *info;
/*-----------------------*\
! DEFINE ASSERTIONS: !
\*-----------------------*/
assert(field);
/*--------------------------------------------------------*\
! Save frequently used variables/structures to temporary !
! variables to make the code more readable. !
\*--------------------------------------------------------*/
control = &field->control;
info = field->info;
/*--------------------------------------------------------*\
! Set the specified codeblock values for all valid dimen- !
! sions taking the maximum allowable size into account. !
\*--------------------------------------------------------*/
control->cbX = (info->nX >> 1) ? (cbX ? cbX : 5) : 0;
control->cbY = (info->nY >> 1) ? (cbY ? cbY : 5) : 0;
control->cbZ = (info->nZ >> 1) ? (cbZ ? cbZ : 5) : 0;
control->cbTS = (info->nTS >> 1) ? (cbTS ? cbTS : 5) : 0;
/*--------------------------------------------------------*\
! Check validity of the codeblock size and reset them, if !
! necessary to teir standard values. !
\*--------------------------------------------------------*/
if((control->cbX > 10) || (control->cbY > 10) || (control->cbZ > 10) || (control->cbTS > 10)||
((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");
control->cbX = (info->nX >> 1) ? 5 : 0;
control->cbY = (info->nY >> 1) ? 5 : 0;
control->cbZ = (info->nZ >> 1) ? 5 : 0;
control->cbTS = (info->nTS >> 1) ? 5 : 0;
return;
}
/*--------------------------------------------------------*\
! Record the setting of the codeblock size variables in !
! the CSsgc variable. !
\*--------------------------------------------------------*/
control->CSsgc |= (0x01 << 7);
}
/*------------------------------------------------------------------------------------------------*\
! !
! DESCRIPTION: !
! ------------ !
! !
! This function amends the Q number formate range in the bwc_field structure !
! according to the specified value. !
! !
! RETURN: !
! ------- !
! !
! - !
! !
\*------------------------------------------------------------------------------------------------*/
void
bwc_set_qm(bwc_field *const field,
uint8 const Qm)
{
/*-----------------------*\
! DEFINE ASSERTIONS: !
\*-----------------------*/
assert(field);
/*--------------------------------------------------------*\
! Check validity of the specified Qm ammend its value and !
! the CSsgc flag accordingly. !
\*--------------------------------------------------------*/
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");
#ifdef BWC_SINGLE_PRECISION
fprintf(stderr, "| than the permitted 30 bits. |\n");
#else
fprintf(stderr, "| than the permitted 62 bits. |\n");
#endif
fprintf(stderr, "| |\n"\
"o==========================================================o\n");
}
else
{
control->Qm = Qm;
control->CSsgc |= (0x01 << 8);
}
}
/*----------------------------------------------------------------------------------------------------------*\
! FUNCTION NAME: void bwc_set_tiles(bwc_field *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 !
! 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 !
! -------- ---- ----------- !
! field bwc_field* - 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 !
! !
\*----------------------------------------------------------------------------------------------------------*/
void
bwc_set_tiles(bwc_field *const field, uint64 tilesX, uint64 tilesY, uint64 tilesZ, uint16 tilesTS, bwc_tile_instr instr)
{
/*-----------------------*\
! DEFINE INT VARIABLES: !
\*-----------------------*/
uint64 num_tiles_X, num_tiles_Y, num_tiles_Z;
uint16 num_tiles_TS;
/*-----------------------*\
! DEFINE STRUCTS: !
\*-----------------------*/
bwc_gl_ctrl *control;
bwc_gl_inf *info;
/*-----------------------*\
! DEFINE ASSERTIONS: !
\*-----------------------*/
assert(field);
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;
/*--------------------------------------------------------*\
! Check if the size of one tile or the overall number of !
! tiles are defined. !
\*--------------------------------------------------------*/
if(instr == bwc_tile_sizeof)
{
/*--------------------------------------------------------*\
! Check if the tile sizes have valid values. !
\*--------------------------------------------------------*/
if((control->tileSizeX < 16 && control->tileSizeX > info->nX)||
(control->tileSizeY < 16 && control->tileSizeY > info->nY)||
(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");
return;
}
/*--------------------------------------------------------*\
! Check if the tile dimensions are specified for a valid !
! spatial or temporal dimension. All invalid and unspeci- !
! fied (NULL) values are set to the maximum allowable tile !
! size. !
\*--------------------------------------------------------*/
control->tileSizeX = (info->nX >> 1) ? (tilesX ? tilesX : info->nX) : info->nX;
control->tileSizeY = (info->nY >> 1) ? (tilesY ? tilesY : info->nY) : info->nY;
control->tileSizeZ = (info->nZ >> 1) ? (tilesZ ? tilesZ : info->nZ) : info->nZ;
control->tileSizeTS = (info->nTS >> 1) ? (tilesTS ? tilesTS : info->nTS) : info->nTS;
/*--------------------------------------------------------*\
! Calculate the number of tiles in all spatial and tempo- !
! ral directions and the overall number of 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));
control->nTiles = num_tiles_X * num_tiles_Y * num_tiles_Z * num_tiles_TS;
/*--------------------------------------------------------*\
! Check if the number of tiles exceeds its maximum allowa- !
! ble value. !
\*--------------------------------------------------------*/
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");
/*--------------------------------------------------------*\
! Reset the tile sizes to their standard values. !
\*--------------------------------------------------------*/
control->tileSizeX = info->nX;
control->tileSizeY = info->nY;
control->tileSizeZ = info->nZ;
control->tileSizeTS = info->nTS;
return;
}
}
else if(bwc_tile_numbof)
{
/*--------------------------------------------------------*\
! Check if the number of tiles exceeds its maximum allowa- !
! ble value. !
\*--------------------------------------------------------*/
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");
return;
}
/*--------------------------------------------------------*\
! Check if the number of tiles are specified for a valid !
! spatial or temporal dimension. For all invalid and un- !
! specified (NULL) values the corresponding tile size is !
! set to its maximum allowable value. For all valid values !
! the tile sizes are calculated accordingly. !
\*--------------------------------------------------------*/
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;
/*--------------------------------------------------------*\
! Check if the tile sizes have valid values. !
\*--------------------------------------------------------*/
if((control->tileSizeX < 16 && control->tileSizeX > info->nX)||
(control->tileSizeY < 16 && control->tileSizeY > info->nY)||
(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");
/*--------------------------------------------------------*\
! Reset the tile sizes to their standard values. !
\*--------------------------------------------------------*/
control->tileSizeX = info->nX;
control->tileSizeY = info->nY;
control->tileSizeZ = info->nZ;
control->tileSizeTS = info->nTS;
return;
}
/*--------------------------------------------------------*\
! Reevaluate the number of tiles in all spatial and tempo- !
! ral directions and the overall number of 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));
control->nTiles = num_tiles_X * num_tiles_Y * num_tiles_Z * num_tiles_TS;
}
/*--------------------------------------------------------*\
! Record the setting of the tile size variables in the !
! CSsgc variable. !
\*--------------------------------------------------------*/
control->CSsgc |= (0x01 << 9);
}

File diff suppressed because it is too large Load diff