[324] | 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-2013, ITU/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 ITU/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 | */ |
---|
| 33 | |
---|
| 34 | /** \file TComRom.h |
---|
| 35 | \brief global variables & functions (header) |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #ifndef __TCOMROM__ |
---|
| 39 | #define __TCOMROM__ |
---|
| 40 | |
---|
| 41 | #include "CommonDef.h" |
---|
| 42 | |
---|
| 43 | #include<stdio.h> |
---|
| 44 | #include<iostream> |
---|
| 45 | |
---|
[459] | 46 | #if H_3D_DIM |
---|
| 47 | #include "TComWedgelet.h" |
---|
| 48 | #endif |
---|
| 49 | |
---|
[324] | 50 | //! \ingroup TLibCommon |
---|
| 51 | //! \{ |
---|
| 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 initSigLastScan(UInt* pBuffD, UInt* pBuffH, UInt* pBuffV, Int iWidth, Int iHeight); |
---|
| 69 | // ==================================================================================================================== |
---|
| 70 | // Data structure related table & variable |
---|
| 71 | // ==================================================================================================================== |
---|
| 72 | |
---|
| 73 | // flexible conversion from relative to absolute index |
---|
| 74 | extern UInt g_auiZscanToRaster[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
| 75 | extern UInt g_auiRasterToZscan[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
| 76 | |
---|
| 77 | Void initZscanToRaster ( Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt*& rpuiCurrIdx ); |
---|
| 78 | Void initRasterToZscan ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ); |
---|
| 79 | |
---|
| 80 | // conversion of partition index to picture pel position |
---|
| 81 | extern UInt g_auiRasterToPelX[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
| 82 | extern UInt g_auiRasterToPelY[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
| 83 | |
---|
| 84 | Void initRasterToPelXY ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ); |
---|
| 85 | |
---|
| 86 | // global variable (LCU width/height, max. CU depth) |
---|
| 87 | extern UInt g_uiMaxCUWidth; |
---|
| 88 | extern UInt g_uiMaxCUHeight; |
---|
| 89 | extern UInt g_uiMaxCUDepth; |
---|
| 90 | extern UInt g_uiAddCUDepth; |
---|
| 91 | |
---|
| 92 | #define MAX_TS_WIDTH 4 |
---|
| 93 | #define MAX_TS_HEIGHT 4 |
---|
| 94 | |
---|
| 95 | extern UInt g_auiPUOffset[8]; |
---|
| 96 | |
---|
| 97 | #define QUANT_IQUANT_SHIFT 20 // Q(QP%6) * IQ(QP%6) = 2^20 |
---|
| 98 | #define QUANT_SHIFT 14 // Q(4) = 2^14 |
---|
| 99 | #define SCALE_BITS 15 // Inherited from TMuC, pressumably for fractional bit estimates in RDOQ |
---|
| 100 | #define MAX_TR_DYNAMIC_RANGE 15 // Maximum transform dynamic range (excluding sign bit) |
---|
| 101 | |
---|
| 102 | #define SHIFT_INV_1ST 7 // Shift after first inverse transform stage |
---|
| 103 | #define SHIFT_INV_2ND 12 // Shift after second inverse transform stage |
---|
| 104 | |
---|
| 105 | extern Int g_quantScales[6]; // Q(QP%6) |
---|
| 106 | extern Int g_invQuantScales[6]; // IQ(QP%6) |
---|
| 107 | extern const Short g_aiT4[4][4]; |
---|
| 108 | extern const Short g_aiT8[8][8]; |
---|
| 109 | extern const Short g_aiT16[16][16]; |
---|
| 110 | extern const Short g_aiT32[32][32]; |
---|
| 111 | |
---|
| 112 | // ==================================================================================================================== |
---|
| 113 | // Luma QP to Chroma QP mapping |
---|
| 114 | // ==================================================================================================================== |
---|
| 115 | |
---|
| 116 | extern const UChar g_aucChromaScale [58]; |
---|
| 117 | |
---|
| 118 | // ==================================================================================================================== |
---|
| 119 | // Scanning order & context mapping table |
---|
| 120 | // ==================================================================================================================== |
---|
| 121 | |
---|
| 122 | extern UInt* g_auiSigLastScan[ 3 ][ MAX_CU_DEPTH ]; // raster index from scanning index (diag, hor, ver) |
---|
| 123 | |
---|
| 124 | extern const UInt g_uiGroupIdx[ 32 ]; |
---|
| 125 | extern const UInt g_uiMinInGroup[ 10 ]; |
---|
| 126 | |
---|
| 127 | extern const UInt g_auiGoRiceRange[5]; //!< maximum value coded with Rice codes |
---|
| 128 | extern const UInt g_auiGoRicePrefixLen[5]; //!< prefix length for each maximum value |
---|
| 129 | |
---|
| 130 | extern const UInt g_sigLastScan8x8[ 3 ][ 4 ]; //!< coefficient group scan order for 8x8 TUs |
---|
| 131 | extern UInt g_sigLastScanCG32x32[ 64 ]; |
---|
| 132 | |
---|
| 133 | // ==================================================================================================================== |
---|
| 134 | // ADI table |
---|
| 135 | // ==================================================================================================================== |
---|
| 136 | |
---|
| 137 | extern const UChar g_aucIntraModeNumFast[7]; |
---|
| 138 | |
---|
| 139 | // ==================================================================================================================== |
---|
| 140 | // Bit-depth |
---|
| 141 | // ==================================================================================================================== |
---|
| 142 | |
---|
| 143 | extern Int g_bitDepthY; |
---|
| 144 | extern Int g_bitDepthC; |
---|
| 145 | extern UInt g_uiPCMBitDepthLuma; |
---|
| 146 | extern UInt g_uiPCMBitDepthChroma; |
---|
| 147 | |
---|
| 148 | // ==================================================================================================================== |
---|
| 149 | // Texture type to integer mapping |
---|
| 150 | // ==================================================================================================================== |
---|
| 151 | |
---|
| 152 | extern const UChar g_aucConvertTxtTypeToIdx[4]; |
---|
| 153 | |
---|
[459] | 154 | #if H_3D_DIM |
---|
| 155 | // ==================================================================================================================== |
---|
| 156 | // Depth coding modes |
---|
| 157 | // ==================================================================================================================== |
---|
| 158 | __inline Void mapDepthModeToIntraDir( UInt& intraMode ) { if( isDimMode( intraMode ) ) intraMode = DC_IDX; } |
---|
| 159 | __inline Void mapDepthModeToIntraDir( Int& intraMode ) { if( isDimMode( intraMode ) ) intraMode = DC_IDX; } |
---|
| 160 | |
---|
| 161 | #if H_3D_DIM_DMM |
---|
| 162 | extern const WedgeResolution g_dmmWedgeResolution [6]; |
---|
| 163 | extern const UChar g_dmm1TabIdxBits [6]; |
---|
| 164 | extern const UChar g_dmm3IntraTabIdxBits[6]; |
---|
| 165 | |
---|
| 166 | extern std::vector< std::vector<TComWedgelet> > g_dmmWedgeLists; |
---|
| 167 | extern std::vector< std::vector<TComWedgeRef> > g_dmmWedgeRefLists; |
---|
| 168 | extern std::vector< std::vector<TComWedgeNode> > g_dmmWedgeNodeLists; |
---|
| 169 | extern std::vector< std::vector< std::vector<UInt> > > g_aauiWdgLstM3; |
---|
| 170 | |
---|
| 171 | Void initWedgeLists( Bool initRefinements = false ); |
---|
| 172 | Void createWedgeList( UInt uiWidth, UInt uiHeight, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList, WedgeResolution eWedgeRes ); |
---|
| 173 | Void addWedgeletToList( TComWedgelet cWedgelet, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList ); |
---|
| 174 | #endif |
---|
| 175 | #endif |
---|
| 176 | |
---|
[324] | 177 | // ========================================== |
---|
| 178 | // Mode-Dependent DST Matrices |
---|
| 179 | extern const Short g_as_DST_MAT_4 [4][4]; |
---|
| 180 | extern const UChar g_aucDCTDSTMode_Vert[NUM_INTRA_MODE]; |
---|
| 181 | extern const UChar g_aucDCTDSTMode_Hor[NUM_INTRA_MODE]; |
---|
| 182 | // ========================================== |
---|
| 183 | |
---|
| 184 | // ==================================================================================================================== |
---|
| 185 | // Misc. |
---|
| 186 | // ==================================================================================================================== |
---|
| 187 | |
---|
| 188 | extern Char g_aucConvertToBit [ MAX_CU_SIZE+1 ]; // from width to log2(width)-2 |
---|
| 189 | |
---|
| 190 | #ifndef ENC_DEC_TRACE |
---|
| 191 | # define ENC_DEC_TRACE 0 |
---|
| 192 | #endif |
---|
| 193 | |
---|
| 194 | #if ENC_DEC_TRACE |
---|
| 195 | extern FILE* g_hTrace; |
---|
| 196 | extern Bool g_bJustDoIt; |
---|
| 197 | extern const Bool g_bEncDecTraceEnable; |
---|
| 198 | extern const Bool g_bEncDecTraceDisable; |
---|
| 199 | extern Bool g_HLSTraceEnable; |
---|
| 200 | extern UInt64 g_nSymbolCounter; |
---|
| 201 | |
---|
| 202 | #define COUNTER_START 1 |
---|
| 203 | #define COUNTER_END 0 //( UInt64(1) << 63 ) |
---|
| 204 | |
---|
| 205 | #define DTRACE_CABAC_F(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%f", x ); |
---|
| 206 | #define DTRACE_CABAC_V(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%d", x ); |
---|
| 207 | #define DTRACE_CABAC_VL(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%lld", x ); |
---|
| 208 | #define DTRACE_CABAC_T(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%s", x ); |
---|
| 209 | #define DTRACE_CABAC_X(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%x", x ); |
---|
| 210 | #define DTRACE_CABAC_R( x,y ) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, x, y ); |
---|
| 211 | #define DTRACE_CABAC_N if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "\n" ); |
---|
| 212 | |
---|
| 213 | #else |
---|
| 214 | |
---|
| 215 | #define DTRACE_CABAC_F(x) |
---|
| 216 | #define DTRACE_CABAC_V(x) |
---|
| 217 | #define DTRACE_CABAC_VL(x) |
---|
| 218 | #define DTRACE_CABAC_T(x) |
---|
| 219 | #define DTRACE_CABAC_X(x) |
---|
| 220 | #define DTRACE_CABAC_R( x,y ) |
---|
| 221 | #define DTRACE_CABAC_N |
---|
| 222 | |
---|
| 223 | #endif |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | #define SCALING_LIST_NUM 6 ///< list number for quantization matrix |
---|
| 227 | #define SCALING_LIST_NUM_32x32 2 ///< list number for quantization matrix 32x32 |
---|
| 228 | #define SCALING_LIST_REM_NUM 6 ///< remainder of QP/6 |
---|
| 229 | #define SCALING_LIST_START_VALUE 8 ///< start value for dpcm mode |
---|
| 230 | #define MAX_MATRIX_COEF_NUM 64 ///< max coefficient number for quantization matrix |
---|
| 231 | #define MAX_MATRIX_SIZE_NUM 8 ///< max size number for quantization matrix |
---|
| 232 | #define SCALING_LIST_DC 16 ///< default DC value |
---|
| 233 | enum ScalingListSize |
---|
| 234 | { |
---|
| 235 | SCALING_LIST_4x4 = 0, |
---|
| 236 | SCALING_LIST_8x8, |
---|
| 237 | SCALING_LIST_16x16, |
---|
| 238 | SCALING_LIST_32x32, |
---|
| 239 | SCALING_LIST_SIZE_NUM |
---|
| 240 | }; |
---|
| 241 | static const Char MatrixType[4][6][20] = |
---|
| 242 | { |
---|
| 243 | { |
---|
| 244 | "INTRA4X4_LUMA", |
---|
| 245 | "INTRA4X4_CHROMAU", |
---|
| 246 | "INTRA4X4_CHROMAV", |
---|
| 247 | "INTER4X4_LUMA", |
---|
| 248 | "INTER4X4_CHROMAU", |
---|
| 249 | "INTER4X4_CHROMAV" |
---|
| 250 | }, |
---|
| 251 | { |
---|
| 252 | "INTRA8X8_LUMA", |
---|
| 253 | "INTRA8X8_CHROMAU", |
---|
| 254 | "INTRA8X8_CHROMAV", |
---|
| 255 | "INTER8X8_LUMA", |
---|
| 256 | "INTER8X8_CHROMAU", |
---|
| 257 | "INTER8X8_CHROMAV" |
---|
| 258 | }, |
---|
| 259 | { |
---|
| 260 | "INTRA16X16_LUMA", |
---|
| 261 | "INTRA16X16_CHROMAU", |
---|
| 262 | "INTRA16X16_CHROMAV", |
---|
| 263 | "INTER16X16_LUMA", |
---|
| 264 | "INTER16X16_CHROMAU", |
---|
| 265 | "INTER16X16_CHROMAV" |
---|
| 266 | }, |
---|
| 267 | { |
---|
| 268 | "INTRA32X32_LUMA", |
---|
| 269 | "INTER32X32_LUMA", |
---|
| 270 | }, |
---|
| 271 | }; |
---|
| 272 | static const Char MatrixType_DC[4][12][22] = |
---|
| 273 | { |
---|
| 274 | { |
---|
| 275 | }, |
---|
| 276 | { |
---|
| 277 | }, |
---|
| 278 | { |
---|
| 279 | "INTRA16X16_LUMA_DC", |
---|
| 280 | "INTRA16X16_CHROMAU_DC", |
---|
| 281 | "INTRA16X16_CHROMAV_DC", |
---|
| 282 | "INTER16X16_LUMA_DC", |
---|
| 283 | "INTER16X16_CHROMAU_DC", |
---|
| 284 | "INTER16X16_CHROMAV_DC" |
---|
| 285 | }, |
---|
| 286 | { |
---|
| 287 | "INTRA32X32_LUMA_DC", |
---|
| 288 | "INTER32X32_LUMA_DC", |
---|
| 289 | }, |
---|
| 290 | }; |
---|
| 291 | extern Int g_quantIntraDefault8x8[64]; |
---|
| 292 | extern Int g_quantIntraDefault16x16[256]; |
---|
| 293 | extern Int g_quantIntraDefault32x32[1024]; |
---|
| 294 | extern Int g_quantInterDefault8x8[64]; |
---|
| 295 | extern Int g_quantInterDefault16x16[256]; |
---|
| 296 | extern Int g_quantInterDefault32x32[1024]; |
---|
| 297 | extern Int g_quantTSDefault4x4[16]; |
---|
| 298 | extern UInt g_scalingListSize [SCALING_LIST_SIZE_NUM]; |
---|
| 299 | extern UInt g_scalingListSizeX[SCALING_LIST_SIZE_NUM]; |
---|
| 300 | extern UInt g_scalingListNum [SCALING_LIST_SIZE_NUM]; |
---|
| 301 | extern Int g_eTTable[4]; |
---|
| 302 | //! \} |
---|
| 303 | |
---|
| 304 | #endif //__TCOMROM__ |
---|
| 305 | |
---|