<commit_before>/*!
 * \copy
 *     Copyright (c)  2013, Cisco Systems
 *     All rights reserved.
 *
 *     Redistribution and use in source and binary forms, with or without
 *     modification, are permitted provided that the following conditions
 *     are met:
 *
 *        * Redistributions of source code must retain the above copyright
 *          notice, this list of conditions and the following disclaimer.
 *
 *        * 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.
 *
 */

//wels_common_basis.h
#ifndef WELS_COMMON_BASIS_H__
#define WELS_COMMON_BASIS_H__

#include "typedefs.h"
#include "macros.h"

#include "wels_common_defs.h"

using namespace WelsCommon;

namespace WelsDec {

/*common use table*/
extern const uint8_t g_kuiScan8[24];
extern const uint8_t g_kuiLumaDcZigzagScan[16];
extern const uint8_t g_kuiChromaDcScan[4];
extern const uint8_t g_kMbNonZeroCountIdx[24];
extern const uint8_t g_kCacheNzcScanIdx[4*4+4+4+3];
extern const uint8_t g_kCache26ScanIdx[16];
extern const uint8_t g_kCache30ScanIdx[16];
extern const uint8_t g_kNonZeroScanIdxC[4];
/* Profile IDC */
typedef uint8_t		ProfileIdc;

/* Position Offset structure */
typedef struct TagPosOffset {
int32_t	iLeftOffset;
int32_t	iTopOffset;
int32_t	iRightOffset;
int32_t	iBottomOffset;
} SPosOffset;

/* MB Type & Sub-MB Type */
typedef int32_t MbType;
typedef int32_t SubMbType;

#define I16_LUMA_DC  1
#define I16_LUMA_AC  2
#define LUMA_DC_AC   3
#define CHROMA_DC    4
#define CHROMA_AC    5
#define LUMA_DC_AC_8  6
#define CHROMA_DC_U  7
#define CHROMA_DC_V  8
#define CHROMA_AC_U  9
#define CHROMA_AC_V  10
#define LUMA_DC_AC_INTRA 11
#define LUMA_DC_AC_INTER 12
#define CHROMA_DC_U_INTER  13
#define CHROMA_DC_V_INTER  14
#define CHROMA_AC_U_INTER  15
#define CHROMA_AC_V_INTER  16
#define LUMA_DC_AC_INTRA_8  17
#define LUMA_DC_AC_INTER_8  18

#define SHIFT_BUFFER(pBitsCache)	{	pBitsCache->pBuf+=2; pBitsCache->uiRemainBits += 16; pBitsCache->uiCache32Bit |= (((pBitsCache->pBuf[2] << 8) | pBitsCache->pBuf[3]) << (32 - pBitsCache->uiRemainBits));	}
#define POP_BUFFER(pBitsCache, iCount)	{ pBitsCache->uiCache32Bit <<= iCount;	pBitsCache->uiRemainBits -= iCount;	}

static const uint8_t g_kuiZigzagScan[16] = { //4*4block residual zig-zag scan order
    0,  1,  4,  8,
    5,  2,  3,  6,
    9, 12, 13, 10,
    7, 11, 14, 15,
};

static const uint8_t g_kuiZigzagScan8x8[64] = { //8x8 block residual zig-zag scan order
    0,  1,  8,  16, 9,  2,  3,  10,
    17, 24, 32, 25, 18, 11, 4,  5,
    12, 19, 26, 33, 40, 48, 41, 34,
    27, 20, 13, 6,  7,  14, 21, 28,
    35, 42, 49, 56, 57, 50, 43, 36,
    29, 22, 15, 23, 30, 37, 44, 51,
    58, 59, 52, 45, 38, 31, 39, 46,
    53, 60, 61, 54, 47, 55, 62, 63,
};

static const uint8_t g_kuiIdx2CtxSignificantCoeffFlag8x8[64] = {  // Table 9-43, Page 289
    0,  1,  2,  3,  4,  5,  5,  4,
    4,  3,  3,  4,  4,  4,  5,  5,
    4,  4,  4,  4,  3,  3,  6,  7,
    7,  7,  8,  9, 10,  9,  8,  7,
    7,  6, 11, 12, 13, 11,  6,  7,
    8,  9, 14, 10,  9,  8,  6, 11,
    12, 13, 11, 6,  9, 14, 10,  9,
    11, 12, 13, 11 ,14, 10, 12, 14,
};

static const uint8_t g_kuiIdx2CtxLastSignificantCoeffFlag8x8[64] = { // Table 9-43, Page 289
    0,  1,  1,  1,  1,  1,  1,  1,
    1,  1,  1,  1,  1,  1,  1,  1,
    2,  2,  2,  2,  2,  2,  2,  2,
    2,  2,  2,  2,  2,  2,  2,  2,
    3,  3,  3,  3,  3,  3,  3,  3,
    4,  4,  4,  4,  4,  4,  4,  4,
    5,  5,  5,  5,  6,  6,  6,  6,
    7,  7,  7,  7,  8,  8,  8,  8,
};

static inline void GetMbResProperty(int32_t * pMBproperty,int32_t* pResidualProperty,bool bCavlc)
{
 switch(*pResidualProperty)
  {
  case CHROMA_AC_U:
	  *pMBproperty = 1;
	  *pResidualProperty = bCavlc ? CHROMA_AC : CHROMA_AC_U;
	  break;
  case CHROMA_AC_V:
	  *pMBproperty = 2;
	  *pResidualProperty = bCavlc ? CHROMA_AC : CHROMA_AC_V;
	  break;
  case LUMA_DC_AC_INTRA:
	  *pMBproperty = 0;
	  *pResidualProperty = LUMA_DC_AC;
	  break;
  case CHROMA_DC_U:
      *pMBproperty = 1;
	  *pResidualProperty =  bCavlc ? CHROMA_DC : CHROMA_DC_U;
      break;
 case CHROMA_DC_V:
	  *pMBproperty = 2;
	  *pResidualProperty =  bCavlc ? CHROMA_DC : CHROMA_DC_V;
	  break;
  case I16_LUMA_AC:
	  *pMBproperty = 0;
	  break;
  case I16_LUMA_DC:
	  *pMBproperty = 0;
	  break;
  case LUMA_DC_AC_INTER:
	  *pMBproperty = 3;
      *pResidualProperty = LUMA_DC_AC;
	  break;
  case CHROMA_DC_U_INTER:
      *pMBproperty = 4;
	  *pResidualProperty =  bCavlc ? CHROMA_DC : CHROMA_DC_U;
      break;
  case CHROMA_DC_V_INTER:
	  *pMBproperty = 5;
	  *pResidualProperty =  bCavlc ? CHROMA_DC : CHROMA_DC_V;
	  break;
 case CHROMA_AC_U_INTER:
	  *pMBproperty = 4;
	  *pResidualProperty =  bCavlc ? CHROMA_AC : CHROMA_AC_U;
	  break;
 case CHROMA_AC_V_INTER:
	  *pMBproperty = 5;
	  *pResidualProperty =  bCavlc ? CHROMA_AC : CHROMA_AC_V;
	  break;
    // Reference to Table 7-2
 case LUMA_DC_AC_INTRA_8:
    *pMBproperty = 6;
    *pResidualProperty = LUMA_DC_AC_8;
    break;
 case LUMA_DC_AC_INTER_8:
    *pMBproperty = 7;
    *pResidualProperty = LUMA_DC_AC_8;
    break;
 }
  }

typedef struct TagI16PredInfo {
    int8_t iPredMode;<commit_msg>Run astyle on a newly added function<commit_after>/*!
 * \copy
 *     Copyright (c)  2013, Cisco Systems
 *     All rights reserved.
 *
 *     Redistribution and use in source and binary forms, with or without
 *     modification, are permitted provided that the following conditions
 *     are met:
 *
 *        * Redistributions of source code must retain the above copyright
 *          notice, this list of conditions and the following disclaimer.
 *
 *        * 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.
 *
 */

//wels_common_basis.h
#ifndef WELS_COMMON_BASIS_H__
#define WELS_COMMON_BASIS_H__

#include "typedefs.h"
#include "macros.h"

#include "wels_common_defs.h"

using namespace WelsCommon;

namespace WelsDec {

/*common use table*/
extern const uint8_t g_kuiScan8[24];
extern const uint8_t g_kuiLumaDcZigzagScan[16];
extern const uint8_t g_kuiChromaDcScan[4];
extern const uint8_t g_kMbNonZeroCountIdx[24];
extern const uint8_t g_kCacheNzcScanIdx[4*4+4+4+3];
extern const uint8_t g_kCache26ScanIdx[16];
extern const uint8_t g_kCache30ScanIdx[16];
extern const uint8_t g_kNonZeroScanIdxC[4];
/* Profile IDC */
typedef uint8_t		ProfileIdc;

/* Position Offset structure */
typedef struct TagPosOffset {
int32_t	iLeftOffset;
int32_t	iTopOffset;
int32_t	iRightOffset;
int32_t	iBottomOffset;
} SPosOffset;

/* MB Type & Sub-MB Type */
typedef int32_t MbType;
typedef int32_t SubMbType;

#define I16_LUMA_DC  1
#define I16_LUMA_AC  2
#define LUMA_DC_AC   3
#define CHROMA_DC    4
#define CHROMA_AC    5
#define LUMA_DC_AC_8  6
#define CHROMA_DC_U  7
#define CHROMA_DC_V  8
#define CHROMA_AC_U  9
#define CHROMA_AC_V  10
#define LUMA_DC_AC_INTRA 11
#define LUMA_DC_AC_INTER 12
#define CHROMA_DC_U_INTER  13
#define CHROMA_DC_V_INTER  14
#define CHROMA_AC_U_INTER  15
#define CHROMA_AC_V_INTER  16
#define LUMA_DC_AC_INTRA_8  17
#define LUMA_DC_AC_INTER_8  18

#define SHIFT_BUFFER(pBitsCache)	{	pBitsCache->pBuf+=2; pBitsCache->uiRemainBits += 16; pBitsCache->uiCache32Bit |= (((pBitsCache->pBuf[2] << 8) | pBitsCache->pBuf[3]) << (32 - pBitsCache->uiRemainBits));	}
#define POP_BUFFER(pBitsCache, iCount)	{ pBitsCache->uiCache32Bit <<= iCount;	pBitsCache->uiRemainBits -= iCount;	}

static const uint8_t g_kuiZigzagScan[16] = { //4*4block residual zig-zag scan order
    0,  1,  4,  8,
    5,  2,  3,  6,
    9, 12, 13, 10,
    7, 11, 14, 15,
};

static const uint8_t g_kuiZigzagScan8x8[64] = { //8x8 block residual zig-zag scan order
    0,  1,  8,  16, 9,  2,  3,  10,
    17, 24, 32, 25, 18, 11, 4,  5,
    12, 19, 26, 33, 40, 48, 41, 34,
    27, 20, 13, 6,  7,  14, 21, 28,
    35, 42, 49, 56, 57, 50, 43, 36,
    29, 22, 15, 23, 30, 37, 44, 51,
    58, 59, 52, 45, 38, 31, 39, 46,
    53, 60, 61, 54, 47, 55, 62, 63,
};

static const uint8_t g_kuiIdx2CtxSignificantCoeffFlag8x8[64] = {  // Table 9-43, Page 289
    0,  1,  2,  3,  4,  5,  5,  4,
    4,  3,  3,  4,  4,  4,  5,  5,
    4,  4,  4,  4,  3,  3,  6,  7,
    7,  7,  8,  9, 10,  9,  8,  7,
    7,  6, 11, 12, 13, 11,  6,  7,
    8,  9, 14, 10,  9,  8,  6, 11,
    12, 13, 11, 6,  9, 14, 10,  9,
    11, 12, 13, 11 ,14, 10, 12, 14,
};

static const uint8_t g_kuiIdx2CtxLastSignificantCoeffFlag8x8[64] = { // Table 9-43, Page 289
    0,  1,  1,  1,  1,  1,  1,  1,
    1,  1,  1,  1,  1,  1,  1,  1,
    2,  2,  2,  2,  2,  2,  2,  2,
    2,  2,  2,  2,  2,  2,  2,  2,
    3,  3,  3,  3,  3,  3,  3,  3,
    4,  4,  4,  4,  4,  4,  4,  4,
    5,  5,  5,  5,  6,  6,  6,  6,
    7,  7,  7,  7,  8,  8,  8,  8,
};

static inline void GetMbResProperty (int32_t* pMBproperty, int32_t* pResidualProperty, bool bCavlc) {
  switch (*pResidualProperty) {
  case CHROMA_AC_U:
    *pMBproperty = 1;
    *pResidualProperty = bCavlc ? CHROMA_AC : CHROMA_AC_U;
    break;
  case CHROMA_AC_V:
    *pMBproperty = 2;
    *pResidualProperty = bCavlc ? CHROMA_AC : CHROMA_AC_V;
    break;
  case LUMA_DC_AC_INTRA:
    *pMBproperty = 0;
    *pResidualProperty = LUMA_DC_AC;
    break;
  case CHROMA_DC_U:
    *pMBproperty = 1;
    *pResidualProperty =  bCavlc ? CHROMA_DC : CHROMA_DC_U;
    break;
  case CHROMA_DC_V:
    *pMBproperty = 2;
    *pResidualProperty =  bCavlc ? CHROMA_DC : CHROMA_DC_V;
    break;
  case I16_LUMA_AC:
    *pMBproperty = 0;
    break;
  case I16_LUMA_DC:
    *pMBproperty = 0;
    break;
  case LUMA_DC_AC_INTER:
    *pMBproperty = 3;
    *pResidualProperty = LUMA_DC_AC;
    break;
  case CHROMA_DC_U_INTER:
    *pMBproperty = 4;
    *pResidualProperty =  bCavlc ? CHROMA_DC : CHROMA_DC_U;
    break;
  case CHROMA_DC_V_INTER:
    *pMBproperty = 5;
    *pResidualProperty =  bCavlc ? CHROMA_DC : CHROMA_DC_V;
    break;
  case CHROMA_AC_U_INTER:
    *pMBproperty = 4;
    *pResidualProperty =  bCavlc ? CHROMA_AC : CHROMA_AC_U;
    break;
  case CHROMA_AC_V_INTER:
    *pMBproperty = 5;
    *pResidualProperty =  bCavlc ? CHROMA_AC : CHROMA_AC_V;
    break;
  // Reference to Table 7-2
  case LUMA_DC_AC_INTRA_8:
    *pMBproperty = 6;
    *pResidualProperty = LUMA_DC_AC_8;
    break;
  case LUMA_DC_AC_INTER_8:
    *pMBproperty = 7;
    *pResidualProperty = LUMA_DC_AC_8;
    break;
  }
}

typedef struct TagI16PredInfo {
    int8_t iPredMode;
{'fraction_non_alphanumeric': 0.10074869791666667, 'fraction_numerical': 0.07307942708333333, 'mean_word_length': 3.1321452589105583, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 42, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5888829', 'n_tokens_mistral': 5736, 'n_tokens_neox': 5063, 'n_words': 1441}