[5] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
| 4 | * granted under this license. |
---|
| 5 | * |
---|
| 6 | * Copyright (c) 2010-2011, ISO/IEC |
---|
| 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the ISO/IEC nor the names of its contributors may |
---|
| 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
[2] | 33 | |
---|
| 34 | |
---|
[5] | 35 | |
---|
[2] | 36 | /** \file TComRom.h |
---|
| 37 | \brief global variables & functions (header) |
---|
| 38 | */ |
---|
| 39 | |
---|
| 40 | #ifndef __TCOMROM__ |
---|
| 41 | #define __TCOMROM__ |
---|
| 42 | |
---|
| 43 | #include "CommonDef.h" |
---|
| 44 | |
---|
| 45 | #include<stdio.h> |
---|
| 46 | #include<iostream> |
---|
| 47 | |
---|
| 48 | |
---|
[5] | 49 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[2] | 50 | #include "TComWedgelet.h" |
---|
| 51 | #endif |
---|
| 52 | |
---|
| 53 | // ==================================================================================================================== |
---|
| 54 | // Macros |
---|
| 55 | // ==================================================================================================================== |
---|
| 56 | |
---|
| 57 | #define MAX_CU_DEPTH 7 // log2(LCUSize) |
---|
| 58 | #define MAX_CU_SIZE (1<<(MAX_CU_DEPTH)) // maximum allowable size of CU |
---|
| 59 | #define MIN_PU_SIZE 4 |
---|
| 60 | #define MAX_NUM_SPU_W (MAX_CU_SIZE/MIN_PU_SIZE) // maximum number of SPU in horizontal line |
---|
| 61 | |
---|
| 62 | // ==================================================================================================================== |
---|
| 63 | // Initialize / destroy functions |
---|
| 64 | // ==================================================================================================================== |
---|
| 65 | |
---|
| 66 | Void initROM(); |
---|
| 67 | Void destroyROM(); |
---|
| 68 | Void initFrameScanXY( UInt* pBuff, UInt* pBuffX, UInt* pBuffY, Int iWidth, Int iHeight ); |
---|
| 69 | #if QC_MDCS |
---|
| 70 | Void initSigLastScan(UInt* pBuffZ, UInt* pBuffH, UInt* pBuffV, Int iWidth, Int iHeight, Int iDepth); |
---|
| 71 | #endif //QC_MDCS |
---|
| 72 | |
---|
[5] | 73 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[2] | 74 | Void initWedgeLists(); |
---|
| 75 | Void createWedgeList( UInt uiWidth, UInt uiHeight, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList, WedgeResolution eWedgeRes ); |
---|
| 76 | #endif |
---|
| 77 | |
---|
| 78 | // ==================================================================================================================== |
---|
| 79 | // Data structure related table & variable |
---|
| 80 | // ==================================================================================================================== |
---|
| 81 | |
---|
| 82 | // flexible conversion from relative to absolute index |
---|
| 83 | extern UInt g_auiZscanToRaster[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
| 84 | extern UInt g_auiRasterToZscan[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
| 85 | |
---|
| 86 | Void initZscanToRaster ( Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt*& rpuiCurrIdx ); |
---|
| 87 | Void initRasterToZscan ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ); |
---|
| 88 | |
---|
| 89 | // conversion of partition index to picture pel position |
---|
| 90 | extern UInt g_auiRasterToPelX[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
| 91 | extern UInt g_auiRasterToPelY[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
| 92 | |
---|
| 93 | Void initRasterToPelXY ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ); |
---|
| 94 | #if MTK_SAO |
---|
| 95 | Int LevelRowCol2Idx(int level, int row, int col); |
---|
| 96 | void Idx2LevelRowCol(int idx, int *level, int *row, int *col); |
---|
| 97 | #endif |
---|
| 98 | |
---|
| 99 | // global variable (LCU width/height, max. CU depth) |
---|
| 100 | extern UInt g_uiMaxCUWidth; |
---|
| 101 | extern UInt g_uiMaxCUHeight; |
---|
| 102 | extern UInt g_uiMaxCUDepth; |
---|
| 103 | extern UInt g_uiAddCUDepth; |
---|
| 104 | |
---|
| 105 | extern UInt g_auiPUOffset[4]; |
---|
| 106 | |
---|
[5] | 107 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[2] | 108 | extern std::vector<std::vector<TComWedgelet> > g_aacWedgeLists; |
---|
| 109 | extern std::vector<std::vector<TComWedgeRef> > g_aacWedgeRefLists; |
---|
| 110 | #endif |
---|
| 111 | |
---|
| 112 | #if E243_CORE_TRANSFORMS |
---|
| 113 | #define QUANT_IQUANT_SHIFT 20 // Q(QP%6) * IQ(QP%6) = 2^20 |
---|
| 114 | #define QUANT_SHIFT 14 // Q(4) = 2^14 |
---|
| 115 | #define SCALE_BITS 15 // Inherited from TMuC, pressumably for fractional bit estimates in RDOQ |
---|
| 116 | #define MAX_TR_DYNAMIC_RANGE 15 // Maximum transform dynamic range (excluding sign bit) |
---|
| 117 | |
---|
| 118 | #define SHIFT_INV_1ST 7 // Shift after first inverse transform stage |
---|
| 119 | #define SHIFT_INV_2ND 12 // Shift after second inverse transform stage |
---|
| 120 | |
---|
| 121 | extern UInt g_auiQ[6]; // Q(QP%6) |
---|
| 122 | extern UInt g_auiIQ[6]; // IQ(QP%6) |
---|
| 123 | extern const short g_aiT4[4][4]; |
---|
| 124 | extern const short g_aiT8[8][8]; |
---|
| 125 | extern const short g_aiT16[16][16]; |
---|
| 126 | extern const short g_aiT32[32][32]; |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | #endif |
---|
| 131 | |
---|
| 132 | // ==================================================================================================================== |
---|
| 133 | // Quantization & DeQuantization |
---|
| 134 | // ==================================================================================================================== |
---|
| 135 | |
---|
| 136 | extern UInt g_aiQuantCoef4 [6]; |
---|
| 137 | extern Int g_aiDequantCoef4 [6]; |
---|
| 138 | extern UInt g_aiQuantCoef [6][16]; |
---|
| 139 | extern Int g_aiDequantCoef [6][16]; |
---|
| 140 | extern Int g_aiDequantCoef64 [6][64]; |
---|
| 141 | extern UInt g_aiQuantCoef64 [6][64]; |
---|
| 142 | extern UInt g_aiQuantCoef256 [6][256]; |
---|
| 143 | extern UInt g_aiDeQuantCoef256 [6][256]; |
---|
| 144 | extern UInt g_aiQuantCoef1024 [6][1024]; |
---|
| 145 | extern UInt g_aiDeQuantCoef1024 [6][1024]; |
---|
| 146 | extern UInt g_aiQuantCoef4096 [6]; |
---|
| 147 | extern UInt g_aiDeQuantCoef4096 [6]; |
---|
| 148 | |
---|
| 149 | // ==================================================================================================================== |
---|
| 150 | // Luma QP to Chroma QP mapping |
---|
| 151 | // ==================================================================================================================== |
---|
| 152 | |
---|
| 153 | extern const UChar g_aucChromaScale [52]; |
---|
| 154 | |
---|
| 155 | // ==================================================================================================================== |
---|
| 156 | // Scanning order & context mapping table |
---|
| 157 | // ==================================================================================================================== |
---|
| 158 | |
---|
| 159 | extern UInt* g_auiFrameScanXY[ MAX_CU_DEPTH ]; // raster index from scanning index |
---|
| 160 | extern UInt* g_auiFrameScanX [ MAX_CU_DEPTH ]; // raster index (x) from scanning index |
---|
| 161 | extern UInt* g_auiFrameScanY [ MAX_CU_DEPTH ]; // raster index (y) from scanning index |
---|
| 162 | extern UInt g_auiAntiScan8[64]; // 2D context mapping for coefficients |
---|
| 163 | #if QC_MDCS |
---|
| 164 | extern UInt* g_auiSigLastScan[3][ MAX_CU_DEPTH ]; // raster index from scanning index (zigzag, hor, ver) |
---|
| 165 | #endif //QC_MDCS |
---|
| 166 | #if PCP_SIGMAP_SIMPLE_LAST |
---|
| 167 | extern UInt g_uiCtxXYOffset[ MAX_CU_DEPTH ]; //!< context offset for last pos coding |
---|
| 168 | extern UInt g_uiCtxXY [ 31 ]; //!< context mapping for last pos coding |
---|
| 169 | #endif |
---|
| 170 | |
---|
| 171 | #if E253 |
---|
| 172 | extern const UInt g_auiGoRiceRange[4]; //!< maximum value coded with Rice codes |
---|
| 173 | extern const UInt g_auiGoRicePrefixLen[4]; //!< prefix length for each maximum value |
---|
| 174 | extern const UInt g_aauiGoRiceUpdate[4][16]; //!< parameter update rules for Rice codes |
---|
| 175 | #endif |
---|
| 176 | |
---|
| 177 | // ==================================================================================================================== |
---|
| 178 | // CAVLC table |
---|
| 179 | // ==================================================================================================================== |
---|
| 180 | |
---|
| 181 | extern const UChar g_aucCodeTable3[7][15]; |
---|
| 182 | extern const UChar g_aucLenTable3 [7][15]; |
---|
| 183 | extern const UChar g_aucCodeTableTZ4[3][4]; |
---|
| 184 | extern const UChar g_aucLenTableTZ4 [3][4]; |
---|
| 185 | extern const UChar g_aucCodeTableTZ16[15][16]; |
---|
| 186 | extern const UChar g_aucLenTableTZ16 [15][16]; |
---|
| 187 | extern const UChar g_aucCodeTableTO4[4][5]; |
---|
| 188 | extern const UChar g_aucLenTableTO4 [4][5]; |
---|
| 189 | extern const UChar g_aucACTab[6]; |
---|
| 190 | extern const UChar g_aucFrameBits[32]; |
---|
| 191 | |
---|
| 192 | #if !CAVLC_COEF_LRG_BLK |
---|
| 193 | extern const UInt g_auiLPTableE8[8][128]; |
---|
| 194 | extern const UInt g_auiLPTableD8[8][128]; |
---|
| 195 | #endif |
---|
| 196 | extern const UInt g_auiLPTableE4[3][32]; |
---|
| 197 | extern const UInt g_auiLPTableD4[3][32]; |
---|
| 198 | extern const UInt g_auiLastPosVlcIndex[10]; |
---|
| 199 | extern const UInt g_auiLastPosVlcNum[10][17]; |
---|
| 200 | #if RUNLEVEL_TABLE_CUT |
---|
| 201 | extern const UInt g_auiLumaRun8x8[28][29]; |
---|
| 202 | #else |
---|
| 203 | extern const UInt g_auiLumaRun8x8[29][2][64]; |
---|
| 204 | #endif |
---|
| 205 | |
---|
| 206 | #if LCEC_INTRA_MODE |
---|
| 207 | #if MTK_DCM_MPM |
---|
| 208 | extern const UInt g_auiIntraModeTableD17[2][16]; |
---|
| 209 | extern const UInt g_auiIntraModeTableE17[2][16]; |
---|
| 210 | extern const UInt g_auiIntraModeTableD34[2][33]; |
---|
| 211 | extern const UInt g_auiIntraModeTableE34[2][33]; |
---|
| 212 | #else |
---|
| 213 | extern const UInt g_auiIntraModeTableD17[16]; |
---|
| 214 | extern const UInt g_auiIntraModeTableE17[16]; |
---|
| 215 | extern const UInt g_auiIntraModeTableD34[33]; |
---|
| 216 | extern const UInt g_auiIntraModeTableE34[33]; |
---|
| 217 | #endif |
---|
| 218 | #endif |
---|
| 219 | |
---|
| 220 | #if QC_MOD_LCEC |
---|
| 221 | extern const UInt g_auiVlcTable8x8Inter[29]; |
---|
| 222 | extern const UInt g_auiVlcTable8x8Intra[29]; |
---|
| 223 | #else |
---|
| 224 | extern const UInt g_auiVlcTable8x8[28]; |
---|
| 225 | #endif |
---|
| 226 | #if RUNLEVEL_TABLE_CUT |
---|
| 227 | extern const UInt g_acstructLumaRun8x8[28][29]; |
---|
| 228 | #else |
---|
| 229 | extern const LastCoeffStruct g_acstructLumaRun8x8[29][127]; |
---|
| 230 | #endif |
---|
| 231 | |
---|
| 232 | #if CAVLC_COEF_LRG_BLK |
---|
| 233 | extern const UInt g_auiVlcTable16x16Intra[29]; |
---|
| 234 | extern const UInt g_auiVlcTable16x16Inter[29]; |
---|
| 235 | #endif |
---|
| 236 | |
---|
| 237 | #if LCEC_INTRA_MODE |
---|
| 238 | extern const UInt huff17_2[2][17]; |
---|
| 239 | extern const UInt lengthHuff17_2[2][17]; |
---|
| 240 | extern const UInt huff34_2[2][34]; |
---|
| 241 | extern const UInt lengthHuff34_2[2][34]; |
---|
| 242 | #endif |
---|
| 243 | |
---|
| 244 | #if QC_MOD_LCEC |
---|
| 245 | #if CAVLC_COEF_LRG_BLK |
---|
| 246 | extern const UInt *g_pLumaRunTr14x4[5]; |
---|
| 247 | extern const UInt *g_pLumaRunTr18x8[5]; |
---|
| 248 | #else |
---|
| 249 | extern const UInt g_auiLumaRunTr14x4[5][15]; |
---|
| 250 | extern const UInt g_auiLumaRunTr18x8[5][29]; |
---|
| 251 | #endif |
---|
| 252 | #endif |
---|
| 253 | #if CAVLC_RQT_CBP |
---|
| 254 | extern const UInt g_auiCBP_YUV_TableE[4][8]; |
---|
| 255 | extern const UInt g_auiCBP_YUV_TableD[4][8]; |
---|
| 256 | extern const UInt g_auiCBP_YS_TableE[2][4]; |
---|
| 257 | extern const UInt g_auiCBP_YS_TableD[2][4]; |
---|
| 258 | extern const UInt g_auiCBP_YCS_TableE[2][8]; |
---|
| 259 | extern const UInt g_auiCBP_YCS_TableD[2][8]; |
---|
| 260 | extern const UInt g_auiCBP_YCS_Table[2][8]; |
---|
| 261 | extern const UInt g_auiCBP_YCS_TableLen[2][8]; |
---|
| 262 | extern const UInt g_auiCBP_YC_TableE[2][4]; |
---|
| 263 | extern const UInt g_auiCBP_YC_TableD[2][4]; |
---|
| 264 | extern const UInt g_auiCBP_4Y_TableE[2][15]; |
---|
| 265 | extern const UInt g_auiCBP_4Y_TableD[2][15]; |
---|
| 266 | extern const UInt g_auiCBP_4Y_VlcNum[15]; |
---|
| 267 | #else |
---|
| 268 | extern const UInt g_auiCBPTableE[2][8]; |
---|
| 269 | extern const UInt g_auiCBPTableD[2][8]; |
---|
| 270 | extern const UInt g_auiBlkCBPTableE[2][15]; |
---|
| 271 | extern const UInt g_auiBlkCBPTableD[2][15]; |
---|
| 272 | extern const UInt g_auiBlkCbpVlcNum[15]; |
---|
| 273 | #endif// |
---|
| 274 | extern const UInt g_auiCbpVlcNum[2][8]; |
---|
| 275 | |
---|
| 276 | #if UNIFY_INTER_TABLE |
---|
| 277 | extern const UInt g_auiComMI1TableE[9]; |
---|
| 278 | extern const UInt g_auiComMI1TableD[9]; |
---|
| 279 | #else |
---|
| 280 | extern const UInt g_auiMI1TableE[8]; |
---|
| 281 | extern const UInt g_auiMI1TableD[8]; |
---|
| 282 | extern const UInt g_auiMI2TableE[15]; |
---|
| 283 | extern const UInt g_auiMI2TableD[15]; |
---|
| 284 | extern const UInt g_auiMITableVlcNum[15]; |
---|
| 285 | |
---|
| 286 | extern const UInt g_auiMI1TableENoL1[8]; |
---|
| 287 | extern const UInt g_auiMI1TableDNoL1[8]; |
---|
| 288 | extern const UInt g_auiMI2TableENoL1[15]; |
---|
| 289 | extern const UInt g_auiMI2TableDNoL1[15]; |
---|
| 290 | |
---|
| 291 | #if MS_LCEC_ONE_FRAME |
---|
| 292 | extern const UInt g_auiMI1TableEOnly1Ref[8]; |
---|
| 293 | extern const UInt g_auiMI1TableDOnly1Ref[8]; |
---|
| 294 | extern const UInt g_auiMI1TableEOnly1RefNoL1[8]; |
---|
| 295 | extern const UInt g_auiMI1TableDOnly1RefNoL1[8]; |
---|
| 296 | #endif |
---|
| 297 | #endif |
---|
| 298 | |
---|
| 299 | #if QC_LCEC_INTER_MODE |
---|
| 300 | extern const UInt g_auiInterModeTableE[4][7]; |
---|
| 301 | extern const UInt g_auiInterModeTableD[4][7]; |
---|
| 302 | #endif |
---|
| 303 | // ==================================================================================================================== |
---|
| 304 | // ADI table |
---|
| 305 | // ==================================================================================================================== |
---|
| 306 | |
---|
| 307 | extern const UChar g_aucIntraModeNumFast[7]; |
---|
| 308 | |
---|
| 309 | // ==================================================================================================================== |
---|
| 310 | // Angular Intra table |
---|
| 311 | // ==================================================================================================================== |
---|
| 312 | |
---|
| 313 | extern const UChar g_aucIntraModeNumAng[7]; |
---|
| 314 | extern const UChar g_aucIntraModeBitsAng[7]; |
---|
| 315 | extern const UChar g_aucAngModeMapping[4][34]; |
---|
| 316 | #if ADD_PLANAR_MODE |
---|
| 317 | extern const UChar g_aucAngIntraModeOrder[NUM_INTRA_MODE]; |
---|
| 318 | #else |
---|
| 319 | extern const UChar g_aucAngIntraModeOrder[34]; |
---|
| 320 | #endif |
---|
| 321 | |
---|
[5] | 322 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[2] | 323 | extern const UChar g_aucWedgeFullBitsListIdx[7]; |
---|
| 324 | extern const UChar g_aucIntraSizeIdxToWedgeSize[7]; |
---|
| 325 | extern const WedgeResolution g_aeWedgeResolutionList[5]; |
---|
| 326 | extern double g_dDeltaDCsQuantOffset; |
---|
| 327 | #endif |
---|
| 328 | |
---|
| 329 | // ==================================================================================================================== |
---|
| 330 | // Bit-depth |
---|
| 331 | // ==================================================================================================================== |
---|
| 332 | |
---|
| 333 | extern UInt g_uiBitDepth; |
---|
| 334 | extern UInt g_uiBitIncrement; |
---|
| 335 | extern UInt g_uiIBDI_MAX; |
---|
| 336 | extern UInt g_uiBASE_MAX; |
---|
| 337 | |
---|
| 338 | // ==================================================================================================================== |
---|
| 339 | // Texture type to integer mapping |
---|
| 340 | // ==================================================================================================================== |
---|
| 341 | |
---|
| 342 | extern const UChar g_aucConvertTxtTypeToIdx[4]; |
---|
| 343 | |
---|
| 344 | // ========================================== |
---|
| 345 | // Mode-Dependent DST Matrices |
---|
| 346 | #if INTRA_DST_TYPE_7 |
---|
| 347 | extern const short g_as_DST_MAT_4 [4][4]; |
---|
[5] | 348 | #if ADD_PLANAR_MODE |
---|
| 349 | #if HHI_DMM_WEDGE_INTRA && HHI_DMM_PRED_TEX |
---|
| 350 | extern const UChar g_aucDCTDSTMode_Vert[NUM_INTRA_MODE+8]; |
---|
| 351 | extern const UChar g_aucDCTDSTMode_Hor[NUM_INTRA_MODE+8]; |
---|
| 352 | #elif HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
| 353 | extern const UChar g_aucDCTDSTMode_Vert[NUM_INTRA_MODE+4]; |
---|
| 354 | extern const UChar g_aucDCTDSTMode_Hor[NUM_INTRA_MODE+4]; |
---|
| 355 | #else |
---|
[2] | 356 | extern const UChar g_aucDCTDSTMode_Vert[NUM_INTRA_MODE]; |
---|
| 357 | extern const UChar g_aucDCTDSTMode_Hor[NUM_INTRA_MODE]; |
---|
[5] | 358 | #endif |
---|
[2] | 359 | #else |
---|
[5] | 360 | #if HHI_DMM_WEDGE_INTRA && HHI_DMM_PRED_TEX |
---|
| 361 | extern const UChar g_aucDCTDSTMode_Vert[34+8]; |
---|
| 362 | extern const UChar g_aucDCTDSTMode_Hor[34+8]; |
---|
| 363 | #elif HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
| 364 | extern const UChar g_aucDCTDSTMode_Vert[34+4]; |
---|
| 365 | extern const UChar g_aucDCTDSTMode_Hor[34+4]; |
---|
| 366 | #else |
---|
[2] | 367 | extern const UChar g_aucDCTDSTMode_Vert[34]; |
---|
| 368 | extern const UChar g_aucDCTDSTMode_Hor[34]; |
---|
| 369 | #endif |
---|
| 370 | #endif |
---|
[5] | 371 | #endif |
---|
[2] | 372 | // ========================================== |
---|
| 373 | |
---|
| 374 | // ==================================================================================================================== |
---|
| 375 | // Misc. |
---|
| 376 | // ==================================================================================================================== |
---|
| 377 | |
---|
| 378 | #if QC_MOD_LCEC |
---|
| 379 | __inline UInt xRunLevelInd(Int lev, Int run, Int maxrun, UInt lrg1Pos) |
---|
| 380 | { |
---|
| 381 | UInt cn; |
---|
| 382 | |
---|
| 383 | if ( lrg1Pos > 0 ) |
---|
| 384 | { |
---|
| 385 | if ( lev == 0 ) |
---|
| 386 | { |
---|
| 387 | if ( run < lrg1Pos ) |
---|
| 388 | cn = run; |
---|
| 389 | else |
---|
| 390 | cn = (run << 1) - lrg1Pos + 1; |
---|
| 391 | } |
---|
| 392 | else |
---|
| 393 | { |
---|
| 394 | if ( run > (maxrun - (Int)lrg1Pos + 1) ) |
---|
| 395 | cn = maxrun + run + 2 ; |
---|
| 396 | else |
---|
| 397 | cn = lrg1Pos + (run << 1); |
---|
| 398 | } |
---|
| 399 | } |
---|
| 400 | else |
---|
| 401 | { |
---|
| 402 | cn = (run << 1); |
---|
| 403 | if ( lev == 0 && run <= maxrun ) |
---|
| 404 | { |
---|
| 405 | cn++; |
---|
| 406 | } |
---|
| 407 | } |
---|
| 408 | return(cn); |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | #if RUNLEVEL_TABLE_CUT |
---|
| 412 | /** Function for deriving codeword index in CAVLC run-level coding |
---|
| 413 | * \param lev a value indicating coefficient level greater than one or not |
---|
| 414 | * \param run length of run |
---|
| 415 | * \param maxrun maximum length of run for a given coefficient location |
---|
| 416 | * \returns the codeword index |
---|
| 417 | * This function derives codeword index in CAVLC run-level coding . |
---|
| 418 | */ |
---|
| 419 | __inline UInt xRunLevelIndInter(Int lev, Int run, Int maxrun) |
---|
| 420 | { |
---|
| 421 | UInt cn; |
---|
| 422 | |
---|
| 423 | if (maxrun < 28) |
---|
| 424 | { |
---|
| 425 | if (lev == 0) |
---|
| 426 | { |
---|
| 427 | cn = g_auiLumaRun8x8[maxrun][run]; |
---|
| 428 | } |
---|
| 429 | else |
---|
| 430 | { |
---|
| 431 | cn = maxrun + g_auiLumaRun8x8[maxrun][run] + 1; |
---|
| 432 | } |
---|
| 433 | } |
---|
| 434 | else |
---|
| 435 | { |
---|
| 436 | if (lev == 0) |
---|
| 437 | { |
---|
| 438 | cn = run; |
---|
| 439 | } |
---|
| 440 | else |
---|
| 441 | { |
---|
| 442 | cn = maxrun + run + 2; |
---|
| 443 | } |
---|
| 444 | } |
---|
| 445 | |
---|
| 446 | return(cn); |
---|
| 447 | } |
---|
| 448 | #endif |
---|
| 449 | #endif |
---|
| 450 | |
---|
| 451 | |
---|
| 452 | #if QC_MOD_LCEC_RDOQ |
---|
| 453 | __inline UInt xLeadingZeros(UInt uiCode) |
---|
| 454 | { |
---|
| 455 | UInt uiCount = 0; |
---|
| 456 | Int iDone = 0; |
---|
| 457 | |
---|
| 458 | if (uiCode) |
---|
| 459 | { |
---|
| 460 | while (!iDone) |
---|
| 461 | { |
---|
| 462 | uiCode >>= 1; |
---|
| 463 | if (!uiCode) iDone = 1; |
---|
| 464 | else uiCount++; |
---|
| 465 | } |
---|
| 466 | } |
---|
| 467 | return uiCount; |
---|
| 468 | } |
---|
| 469 | #endif |
---|
| 470 | |
---|
| 471 | extern Char g_aucConvertToBit [ MAX_CU_SIZE+1 ]; // from width to log2(width)-2 |
---|
| 472 | |
---|
| 473 | #if CAVLC_COEF_LRG_BLK |
---|
| 474 | /** Function for deriving codeword index in coding last significant position and level information. |
---|
| 475 | * \param lev a value indicating coefficient level greater than one or not |
---|
| 476 | * \param last_pos last significant coefficient position |
---|
| 477 | * \param N block size |
---|
| 478 | * \returns the codeword index |
---|
| 479 | * This function derives codeword index in coding last significant position and level information in CAVLC. |
---|
| 480 | */ |
---|
| 481 | __inline UInt xLastLevelInd(Int lev, Int last_pos, Int N) |
---|
| 482 | { |
---|
| 483 | UInt cx; |
---|
| 484 | UInt uiConvBit = g_aucConvertToBit[N]+2; |
---|
| 485 | |
---|
| 486 | if (lev==0) |
---|
| 487 | { |
---|
| 488 | cx = ((last_pos + (last_pos>>uiConvBit))>>uiConvBit)+last_pos; |
---|
| 489 | } |
---|
| 490 | else |
---|
| 491 | { |
---|
| 492 | if (last_pos<N) |
---|
| 493 | { |
---|
| 494 | cx = (last_pos+1)<<uiConvBit; |
---|
| 495 | } |
---|
| 496 | else |
---|
| 497 | { |
---|
| 498 | cx = (0x01<<(uiConvBit<<1)) + last_pos; |
---|
| 499 | } |
---|
| 500 | } |
---|
| 501 | return(cx); |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | __inline void xLastLevelIndInv(Int& lev, Int& last_pos, Int N, UInt cx) |
---|
| 505 | { |
---|
| 506 | UInt uiConvBit = g_aucConvertToBit[N]+2; |
---|
| 507 | Int N2 = 0x01<<(uiConvBit<<1); |
---|
| 508 | |
---|
| 509 | if(cx <= N2+N) |
---|
| 510 | { |
---|
| 511 | if(cx && (cx&(N-1))==0) |
---|
| 512 | { |
---|
| 513 | lev = 1; |
---|
| 514 | last_pos = (cx>>uiConvBit)-1; |
---|
| 515 | } |
---|
| 516 | else |
---|
| 517 | { |
---|
| 518 | lev = 0; |
---|
| 519 | last_pos = cx - (cx>>uiConvBit); |
---|
| 520 | } |
---|
| 521 | } |
---|
| 522 | else |
---|
| 523 | { |
---|
| 524 | lev = 1; |
---|
| 525 | last_pos = cx - N2; |
---|
| 526 | } |
---|
| 527 | } |
---|
| 528 | #endif |
---|
| 529 | |
---|
| 530 | |
---|
| 531 | #if CHROMA_CODEWORD_SWITCH |
---|
| 532 | extern const UChar ChromaMapping[2][5]; |
---|
| 533 | #endif |
---|
| 534 | |
---|
| 535 | #if ADD_PLANAR_MODE |
---|
| 536 | __inline Void mapPlanartoDC( UChar& curDir ) { curDir = (curDir == PLANAR_IDX) ? 2 : curDir; } |
---|
| 537 | __inline Void mapPlanartoDC( UInt& curDir ) { curDir = (curDir == PLANAR_IDX) ? 2 : curDir; } |
---|
| 538 | __inline Void mapPlanartoDC( Int& curDir ) { curDir = (curDir == PLANAR_IDX) ? 2 : curDir; } |
---|
| 539 | #endif |
---|
[5] | 540 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
[2] | 541 | __inline Void mapDMMtoDC( UChar& curDir ) { curDir = (curDir > MAX_MODE_ID_INTRA_DIR) ? 2 : curDir; } |
---|
| 542 | __inline Void mapDMMtoDC( UInt& curDir ) { curDir = (curDir > MAX_MODE_ID_INTRA_DIR) ? 2 : curDir; } |
---|
| 543 | __inline Void mapDMMtoDC( Int& curDir ) { curDir = (curDir > MAX_MODE_ID_INTRA_DIR) ? 2 : curDir; } |
---|
| 544 | #endif |
---|
| 545 | |
---|
| 546 | |
---|
| 547 | #define ENC_DEC_TRACE 0 |
---|
| 548 | |
---|
| 549 | |
---|
| 550 | #if ENC_DEC_TRACE |
---|
| 551 | extern FILE* g_hTrace; |
---|
| 552 | extern Bool g_bJustDoIt; |
---|
| 553 | extern const Bool g_bEncDecTraceEnable; |
---|
| 554 | extern const Bool g_bEncDecTraceDisable; |
---|
| 555 | extern UInt64 g_nSymbolCounter; |
---|
| 556 | |
---|
| 557 | #define COUNTER_START 1 |
---|
| 558 | #define COUNTER_END 0 //( UInt64(1) << 63 ) |
---|
| 559 | |
---|
| 560 | #define DTRACE_CABAC_F(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%f", x ); |
---|
| 561 | #define DTRACE_CABAC_V(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%d", x ); |
---|
| 562 | #define DTRACE_CABAC_T(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%s", x ); |
---|
| 563 | #define DTRACE_CABAC_X(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%x", x ); |
---|
| 564 | #define DTRACE_CABAC_R( x,y ) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, x, y ); |
---|
| 565 | #define DTRACE_CABAC_N if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "\n" ); |
---|
| 566 | |
---|
| 567 | #else |
---|
| 568 | |
---|
| 569 | #define DTRACE_CABAC_F(x) |
---|
| 570 | #define DTRACE_CABAC_V(x) |
---|
| 571 | #define DTRACE_CABAC_T(x) |
---|
| 572 | #define DTRACE_CABAC_X(x) |
---|
| 573 | #define DTRACE_CABAC_R( x,y ) |
---|
| 574 | #define DTRACE_CABAC_N |
---|
| 575 | |
---|
| 576 | #endif |
---|
| 577 | #if CAVLC_COUNTER_ADAPT |
---|
| 578 | /** Function for codeword adaptation |
---|
| 579 | * \param uiCodeIdx codeword index of the syntax element being coded |
---|
| 580 | * \param pucTableCounter pointer to counter array |
---|
| 581 | * \param rucTableCounterSum sum counter |
---|
| 582 | * \param puiTableD pointer to table mapping codeword index to syntax element value |
---|
| 583 | * \param puiTableE pointer to table mapping syntax element value to codeword index |
---|
| 584 | * \param uiCounterNum number of counters |
---|
| 585 | * \returns |
---|
| 586 | * This function performs codeword adaptation. |
---|
| 587 | */ |
---|
| 588 | __inline Void adaptCodeword( UInt uiCodeIdx, UChar * pucTableCounter, UChar & rucTableCounterSum, UInt * puiTableD, UInt * puiTableE, UInt uiCounterNum ) |
---|
| 589 | { |
---|
| 590 | Bool bSwapping = false; |
---|
| 591 | UInt uiCodeword = puiTableD [uiCodeIdx]; |
---|
| 592 | |
---|
| 593 | UInt uiPrevCodeIdx = (uiCodeIdx >= 1)? uiCodeIdx - 1 : 0; |
---|
| 594 | UInt uiPrevCodeword = puiTableD[uiPrevCodeIdx]; |
---|
| 595 | |
---|
| 596 | if ( uiCodeIdx < uiCounterNum ) |
---|
| 597 | { |
---|
| 598 | pucTableCounter [uiCodeIdx] ++; |
---|
| 599 | |
---|
| 600 | if (pucTableCounter[uiCodeIdx] >= pucTableCounter[uiPrevCodeIdx]) |
---|
| 601 | { |
---|
| 602 | bSwapping = true; |
---|
| 603 | UChar ucTempCounter = pucTableCounter[uiCodeIdx]; |
---|
| 604 | pucTableCounter[uiCodeIdx] = pucTableCounter[uiPrevCodeIdx]; |
---|
| 605 | pucTableCounter[uiPrevCodeIdx] = ucTempCounter; |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | if ( rucTableCounterSum >= 15 ) |
---|
| 609 | { |
---|
| 610 | rucTableCounterSum = 0; |
---|
| 611 | for (UInt uiIdx = 0; uiIdx < uiCounterNum; uiIdx++) |
---|
| 612 | { |
---|
| 613 | pucTableCounter[uiIdx] >>= 1; |
---|
| 614 | } |
---|
| 615 | } |
---|
| 616 | else |
---|
| 617 | { |
---|
| 618 | rucTableCounterSum ++; |
---|
| 619 | } |
---|
| 620 | } |
---|
| 621 | else |
---|
| 622 | { |
---|
| 623 | bSwapping = true; |
---|
| 624 | } |
---|
| 625 | |
---|
| 626 | if ( bSwapping ) |
---|
| 627 | { |
---|
| 628 | puiTableD[uiPrevCodeIdx] = uiCodeword; |
---|
| 629 | puiTableD[uiCodeIdx ] = uiPrevCodeword; |
---|
| 630 | |
---|
| 631 | if (puiTableE != NULL) |
---|
| 632 | { |
---|
| 633 | puiTableE[uiCodeword] = uiPrevCodeIdx; |
---|
| 634 | puiTableE[uiPrevCodeword] = uiCodeIdx; |
---|
| 635 | } |
---|
| 636 | } |
---|
| 637 | } |
---|
| 638 | #endif |
---|
| 639 | #endif //__TCOMROM__ |
---|
| 640 | |
---|