LCOV - code coverage report
Current view: top level - lib_com - parameter_bitmaping_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 174 175 99.4 %
Date: 2025-05-03 01:55:50 Functions: 11 11 100.0 %

          Line data    Source code
       1             : #include <assert.h>
       2             : #include <stdint.h>
       3             : #include "options.h"
       4             : #include "stat_com.h"
       5             : #include "prot_fx.h"
       6             : #include "wmc_auto.h"
       7             : 
       8             : 
       9             : /** Put nBits long encoded value from *pStream into bitstream. Using the function EncodeValue for encoding. */
      10         436 : static Word16 PutIntoBitstream_fx(
      11             :     const Word16 **pStream,
      12             :     TEncodeValue EncodeValue,
      13             :     Word16 index,
      14             :     BSTR_ENC_HANDLE hBstr,
      15             :     const Word16 nBits )
      16             : {
      17             :     Word16 value;
      18             :     Word16 codedValue;
      19             : 
      20         436 :     move16();
      21         436 :     value = *( *pStream )++;
      22         436 :     codedValue = EncodeValue( value, index );
      23             : 
      24         436 :     push_next_indice( hBstr, codedValue, nBits );
      25             : 
      26         436 :     return value;
      27             : }
      28     1645947 : static Word16 PutIntoBitstream_ivas_fx(
      29             :     const Word16 **pStream,
      30             :     TEncodeValue EncodeValue,
      31             :     Word16 index,
      32             :     BSTR_ENC_HANDLE hBstr,
      33             :     const Word16 nBits )
      34             : {
      35             :     Word16 value;
      36             :     Word16 codedValue;
      37             : 
      38     1645947 :     move16();
      39     1645947 :     value = *( *pStream )++;
      40     1645947 :     codedValue = EncodeValue( value, index );
      41             : 
      42     1645947 :     push_next_indice( hBstr, codedValue, nBits );
      43             : 
      44     1645947 :     return value;
      45             : }
      46             : 
      47      933160 : static Word16 FixedWidthEncoding( Word16 value, Word16 index )
      48             : {
      49             :     (void) index; /* suppress compiler warnings */
      50             : 
      51      933160 :     return value;
      52             : }
      53             : 
      54             : 
      55             : /********************************/
      56             : /*      Interface functions     */
      57             : /********************************/
      58             : 
      59      222292 : void GetParameters(
      60             :     ParamsBitMap const *paramsBitMap,
      61             :     const Word16 nArrayLength,
      62             :     void const *pParameter,
      63             :     Word16 **pStream,
      64             :     Word16 *pnSize,
      65             :     Word16 *pnBits )
      66             : {
      67             :     Word16 index;
      68             :     Word16 iParam, nParams;
      69             :     Word16 value;
      70             :     void const *pSubStruct;
      71             : 
      72      222292 :     assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( pnBits != NULL ) );
      73             : 
      74      222292 :     nParams = paramsBitMap->nParams;
      75      562851 :     for ( index = 0; index < nArrayLength; index++ )
      76             :     {
      77      681118 :         for ( iParam = 0; iParam < nParams; iParam++ )
      78             :         {
      79      340559 :             ParamBitMap const *const param = &paramsBitMap->params[iParam];
      80             : 
      81             : #define WMC_TOOL_SKIP
      82      340559 :             pSubStruct = param->GetParamValue( pParameter, index, &value );
      83             : #undef WMC_TOOL_SKIP
      84             :             /* If a function for encoding/decoding value is defined than it should take care of 0 */
      85      340559 :             if ( param->fZeroAllowed || ( param->EncodeValue != NULL ) )
      86             :             {
      87      323323 :                 *( *pStream )++ = value;
      88             :             }
      89             :             else
      90             :             {
      91       17236 :                 *( *pStream )++ = value - 1;
      92             :             }
      93      340559 :             ++*pnSize;
      94             : #define WMC_TOOL_SKIP
      95      340559 :             *pnBits += ( param->nBits != 0 ) ? param->nBits : param->GetNumberOfBits( value, index );
      96             : #undef WMC_TOOL_SKIP
      97      340559 :             if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
      98             :             {
      99       60183 :                 GetParameters( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize, pnBits );
     100             :             }
     101             :         }
     102             :     }
     103             : 
     104      222292 :     return;
     105             : }
     106             : 
     107     1465300 : void GetParameters_fx(
     108             :     ParamsBitMap const *paramsBitMap,
     109             :     const Word16 nArrayLength, // Q0
     110             :     void const *pParameter,    // Q0
     111             :     Word16 **pStream,          // Q0
     112             :     Word16 *pnSize,            // Q0
     113             :     Word16 *pnBits )           // Q0
     114             : {
     115             :     Word16 index;
     116             :     Word16 iParam, nParams;
     117             :     Word16 value;
     118             :     void const *pSubStruct;
     119             : 
     120     1465300 :     assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( pnBits != NULL ) );
     121             : 
     122     1465300 :     nParams = paramsBitMap->nParams;
     123     1465300 :     move16();
     124     3342956 :     FOR( index = 0; index < nArrayLength; index++ )
     125             :     {
     126     3824158 :         FOR( iParam = 0; iParam < nParams; iParam++ )
     127             :         {
     128     1946502 :             ParamBitMap const *const param = &paramsBitMap->params[iParam];
     129             : 
     130             : #define WMC_TOOL_SKIP
     131     1946502 :             pSubStruct = param->GetParamValue( pParameter, index, &value );
     132             : #undef WMC_TOOL_SKIP
     133             :             /* If a function for encoding/decoding value is defined than it should take care of 0 */
     134     1946502 :             test();
     135     1946502 :             IF( param->fZeroAllowed || ( param->EncodeValue != NULL ) )
     136             :             {
     137     1877656 :                 *( *pStream )++ = value;
     138     1877656 :                 move16();
     139             :             }
     140             :             ELSE
     141             :             {
     142       68846 :                 *( *pStream )++ = sub( value, 1 );
     143       68846 :                 move16();
     144             :             }
     145     1946502 :             ++*pnSize;
     146             : #define WMC_TOOL_SKIP
     147     1946502 :             IF( ( param->nBits != 0 ) )
     148             :             {
     149     1377601 :                 *pnBits = add( *pnBits, param->nBits );
     150             :             }
     151             :             ELSE
     152             :             {
     153      568901 :                 *pnBits = add( *pnBits, param->GetNumberOfBits( value, index ) );
     154             :             }
     155     1946502 :             move16();
     156             : #undef WMC_TOOL_SKIP
     157             : 
     158     1946502 :             test();
     159     1946502 :             IF( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
     160             :             {
     161      225391 :                 GetParameters_fx( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize, pnBits );
     162             :             }
     163             :         }
     164             :     }
     165             : 
     166     1465300 :     return;
     167             : }
     168             : 
     169      264875 : void SetParameters(
     170             :     ParamsBitMap const *paramsBitMap,
     171             :     const Word16 nArrayLength,
     172             :     void *pParameter,
     173             :     const Word16 **pStream,
     174             :     Word16 *pnSize )
     175             : {
     176             :     Word16 index;
     177             :     Word16 iParam, nParams;
     178             :     Word16 value;
     179             :     void *pSubStruct;
     180             : 
     181      264875 :     assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) );
     182             : 
     183      264875 :     nParams = paramsBitMap->nParams;
     184     1020489 :     for ( index = 0; index < nArrayLength; index++ )
     185             :     {
     186     1574729 :         for ( iParam = 0; iParam < nParams; iParam++ )
     187             :         {
     188      819115 :             ParamBitMap const *const param = &paramsBitMap->params[iParam];
     189             :             /* If a function for encoding/decoding value is defined than it should take care of 0 */
     190             : 
     191      819115 :             value = *( *pStream )++ + ( param->fZeroAllowed || ( param->EncodeValue != NULL ) ? 0 : 1 );
     192             : #define WMC_TOOL_SKIP
     193      819115 :             pSubStruct = param->SetParamValue( pParameter, index, value );
     194             : #undef WMC_TOOL_SKIP
     195      819115 :             ++*pnSize;
     196      819115 :             if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
     197             :             {
     198      183492 :                 SetParameters( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize );
     199             :             }
     200             :         }
     201             :     }
     202             : 
     203      264875 :     return;
     204             : }
     205             : 
     206      721991 : void SetParameters_fx(
     207             :     ParamsBitMap const *paramsBitMap,
     208             :     const Word16 nArrayLength,
     209             :     void *pParameter,
     210             :     const Word16 **pStream,
     211             :     Word16 *pnSize )
     212             : {
     213             :     Word16 index;
     214             :     Word16 iParam, nParams;
     215             :     Word16 value;
     216             :     void *pSubStruct;
     217             :     void *pTmp;
     218      721991 :     assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) );
     219      721991 :     nParams = paramsBitMap->nParams;
     220             : 
     221     1443982 :     FOR( index = 0; index < nArrayLength; index++ )
     222             :     {
     223     1443982 :         FOR( iParam = 0; iParam < nParams; iParam++ )
     224             :         {
     225             :             ParamBitMap const *param;
     226             :             /* If a function for encoding/decoding value is defined than it should take care of 0 */
     227             : 
     228      721991 :             move16();
     229      721991 :             param = &paramsBitMap->params[iParam];
     230             : 
     231      721991 :             move16();
     232      721991 :             value = 1;
     233      721991 :             if ( s_or( param->fZeroAllowed != 0, param->EncodeValue != NULL ) )
     234             :             {
     235      721991 :                 move16();
     236      721991 :                 value = 0;
     237             :             }
     238      721991 :             value = add( value, *( *pStream )++ );
     239             : 
     240             : #define WMC_TOOL_SKIP
     241      721991 :             pSubStruct = param->SetParamValue( pParameter, index, value );
     242             : #undef WMC_TOOL_SKIP
     243      721991 :             move16();
     244      721991 :             *pnSize = add( *pnSize, 1 );
     245             : 
     246      721991 :             IF( s_and( param->pSubParamBitMap != NULL, value > 0 ) )
     247             :             {
     248       81009 :                 pTmp = pParameter;
     249       81009 :                 if ( pSubStruct != NULL )
     250        1288 :                     pTmp = pSubStruct;
     251       81009 :                 SetParameters( param->pSubParamBitMap, value, pTmp, pStream, pnSize );
     252             :             }
     253             :         }
     254             :     }
     255      721991 : }
     256             : 
     257             : 
     258         410 : void WriteToBitstream_fx(
     259             :     ParamsBitMap const *paramsBitMap,
     260             :     const Word16 nArrayLength,
     261             :     const Word16 **pStream,
     262             :     Word16 *pnSize,
     263             :     BSTR_ENC_HANDLE hBstr,
     264             :     Word16 *pnBits )
     265             : {
     266             :     Word16 index;
     267             :     Word16 iParam, nParams;
     268             : 
     269             : 
     270         410 :     assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( hBstr != NULL ) && ( pnBits != NULL ) );
     271         410 :     nParams = paramsBitMap->nParams;
     272             : 
     273         846 :     FOR( index = 0; index < nArrayLength; index++ )
     274             :     {
     275             : 
     276         872 :         FOR( iParam = 0; iParam < nParams; iParam++ )
     277             :         {
     278             :             ParamBitMap const *param;
     279             :             Word16 nBits;
     280             :             /* If a function for encoding/decoding value is defined than it should take care of 0 */
     281             :             Word16 fShiftValue;
     282             :             TEncodeValue EncodeValue;
     283             :             Word16 value;
     284             : 
     285         436 :             move16();
     286         436 :             param = &paramsBitMap->params[iParam];
     287             : 
     288         436 :             move16();
     289         436 :             nBits = param->nBits;
     290         436 :             IF( param->nBits == 0 )
     291             :             {
     292             : #define WMC_TOOL_SKIP
     293          34 :                 nBits = param->GetNumberOfBits( **pStream, index );
     294             : #undef WMC_TOOL_SKIP
     295             :             }
     296             : 
     297         436 :             test();
     298         436 :             test();
     299         436 :             fShiftValue = s_and( param->fZeroAllowed == 0, param->EncodeValue == NULL );
     300         436 :             move16();
     301         436 :             EncodeValue = param->EncodeValue;
     302         436 :             if ( param->EncodeValue == NULL )
     303             :             {
     304         402 :                 move16();
     305         402 :                 EncodeValue = &FixedWidthEncoding;
     306             :             }
     307         436 :             value = PutIntoBitstream_fx( pStream, EncodeValue, index, hBstr, nBits );
     308         436 :             if ( fShiftValue )
     309             :             {
     310           0 :                 value = add( value, 1 );
     311             :             }
     312             : 
     313         436 :             move16();
     314         436 :             *pnSize = add( *pnSize, 1 );
     315         436 :             move16();
     316         436 :             *pnBits = add( *pnBits, nBits );
     317             : 
     318         436 :             IF( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
     319             :             {
     320           8 :                 WriteToBitstream_fx( param->pSubParamBitMap, value, pStream, pnSize, hBstr, pnBits );
     321             :             }
     322             :         }
     323             :     }
     324         410 : }
     325     1060570 : void WriteToBitstream_ivas_fx(
     326             :     ParamsBitMap const *paramsBitMap,
     327             :     const Word16 nArrayLength,
     328             :     const Word16 **pStream,
     329             :     Word16 *pnSize,
     330             :     BSTR_ENC_HANDLE hBstr,
     331             :     Word16 *pnBits )
     332             : {
     333             :     Word16 index;
     334             :     Word16 iParam, nParams;
     335             : 
     336             : 
     337     1060570 :     assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( hBstr != NULL ) && ( pnBits != NULL ) );
     338     1060570 :     nParams = paramsBitMap->nParams;
     339     1060570 :     move16();
     340             : 
     341     2640097 :     FOR( index = 0; index < nArrayLength; index++ )
     342             :     {
     343             : 
     344     3225474 :         FOR( iParam = 0; iParam < nParams; iParam++ )
     345             :         {
     346             :             ParamBitMap const *param;
     347             :             Word16 nBits;
     348             :             /* If a function for encoding/decoding value is defined than it should take care of 0 */
     349             :             Word16 fShiftValue;
     350             :             TEncodeValue EncodeValue;
     351             :             Word16 value;
     352             : 
     353     1645947 :             move16();
     354     1645947 :             param = &paramsBitMap->params[iParam];
     355             : 
     356     1645947 :             move16();
     357     1645947 :             nBits = param->nBits;
     358     1645947 :             IF( param->nBits == 0 )
     359             :             {
     360             : #define WMC_TOOL_SKIP
     361      713189 :                 nBits = param->GetNumberOfBits( **pStream, index );
     362             : #undef WMC_TOOL_SKIP
     363             :             }
     364             : 
     365     1645947 :             fShiftValue = s_and( param->fZeroAllowed == 0, param->EncodeValue == NULL );
     366             : 
     367     1645947 :             EncodeValue = param->EncodeValue;
     368     1645947 :             if ( param->EncodeValue == NULL )
     369             :             {
     370      932758 :                 move16();
     371      932758 :                 EncodeValue = &FixedWidthEncoding;
     372             :             }
     373     1645947 :             value = PutIntoBitstream_ivas_fx( pStream, EncodeValue, index, hBstr, nBits );
     374     1645947 :             IF( fShiftValue )
     375             :             {
     376       83656 :                 value = add( value, 1 );
     377             :             }
     378             : 
     379     1645947 :             move16();
     380     1645947 :             *pnSize = add( *pnSize, 1 );
     381     1645947 :             move16();
     382     1645947 :             *pnBits = add( *pnBits, nBits );
     383             : 
     384     1645947 :             test();
     385     1645947 :             IF( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
     386             :             {
     387      277888 :                 WriteToBitstream_ivas_fx( param->pSubParamBitMap, value, pStream, pnSize, hBstr, pnBits );
     388             :             }
     389             :         }
     390             :     }
     391     1060570 : }
     392             : 
     393             : /** Get nBits long value from bitstream into *pStream. */
     394     1517518 : static Word16 GetFromBitstream(
     395             :     Decoder_State *st,
     396             :     TDecodeValue DecodeValue,
     397             :     UWord16 index,
     398             :     Word16 nFixedBits,
     399             :     Word16 **pStream )
     400             : {
     401     1517518 :     Word16 value = 0;
     402     1517518 :     move16();
     403     1517518 :     move16();
     404     1517518 :     value = 0;
     405     1517518 :     IF( DecodeValue != NULL )
     406             :     {
     407      658993 :         DecodeValue( st, index, &value );
     408             :     }
     409             :     ELSE
     410             :     {
     411             :         // value = get_next_indice_fx(st, nFixedBits);
     412      858525 :         value = get_next_indice_fx( st, nFixedBits );
     413             :     }
     414     1517518 :     move16();
     415     1517518 :     *( *pStream )++ = value;
     416             : 
     417     1517518 :     return value;
     418             : }
     419             : 
     420      976989 : void ReadFromBitstream_fx(
     421             :     ParamsBitMap const *paramsBitMap,
     422             :     const Word16 nArrayLength,
     423             :     Decoder_State *st,
     424             :     Word16 **pStream,
     425             :     Word16 *pnSize )
     426             : {
     427             :     Word16 index;
     428             :     Word16 iParam, nParams;
     429             :     Word16 fShiftValue;
     430             :     Word16 value;
     431             : 
     432      976989 :     assert( ( paramsBitMap != NULL ) && GT_16( nArrayLength, 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( st != NULL ) );
     433      976989 :     move16();
     434      976989 :     nParams = paramsBitMap->nParams;
     435     2433340 :     FOR( index = 0; index < nArrayLength; index++ )
     436             :     {
     437     2973869 :         FOR( iParam = 0; iParam < nParams; iParam++ )
     438             :         {
     439             :             ParamBitMap const *param;
     440             :             /* If a function for encoding/decoding value is defined than it should take care of 0 */
     441     1517518 :             move16();
     442     1517518 :             param = &paramsBitMap->params[iParam];
     443     1517518 :             test();
     444     1517518 :             test();
     445     1517518 :             fShiftValue = s_and( (Word16) param->fZeroAllowed == 0, param->EncodeValue == NULL );
     446     1517518 :             value = GetFromBitstream( st, param->DecodeValue, index, param->nBits, pStream );
     447     1517518 :             IF( fShiftValue )
     448             :             {
     449       77387 :                 move16();
     450       77387 :                 value = add( value, 1 );
     451             :             }
     452             : 
     453     1517518 :             test();
     454     1517518 :             IF( ( param->pSubParamBitMap != NULL ) && value > 0 )
     455             :             {
     456      257018 :                 ReadFromBitstream_fx( param->pSubParamBitMap, value, st, pStream, pnSize );
     457             :             }
     458             :         }
     459             :     }
     460      976989 :     move16();
     461      976989 :     *pnSize = add( *pnSize, i_mult( nParams, nArrayLength ) );
     462      976989 : }

Generated by: LCOV version 1.14