| 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-2014, 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 | #include "TypeDef.h" |
|---|
| 43 | |
|---|
| 44 | #include<stdio.h> |
|---|
| 45 | #include<iostream> |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | //! \ingroup TLibCommon |
|---|
| 49 | //! \{ |
|---|
| 50 | |
|---|
| 51 | // ==================================================================================================================== |
|---|
| 52 | // Macros |
|---|
| 53 | // ==================================================================================================================== |
|---|
| 54 | |
|---|
| 55 | #define MAX_CU_DEPTH 6 // log2(LCUSize) |
|---|
| 56 | #define MAX_CU_SIZE (1<<(MAX_CU_DEPTH)) // maximum allowable size of CU |
|---|
| 57 | #define MIN_PU_SIZE 4 |
|---|
| 58 | #define MAX_NUM_SPU_W (MAX_CU_SIZE/MIN_PU_SIZE) // maximum number of SPU in horizontal line |
|---|
| 59 | |
|---|
| 60 | // ==================================================================================================================== |
|---|
| 61 | // Initialize / destroy functions |
|---|
| 62 | // ==================================================================================================================== |
|---|
| 63 | |
|---|
| 64 | Void initROM(); |
|---|
| 65 | Void destroyROM(); |
|---|
| 66 | Void initSigLastScan(UInt* pBuffD, UInt* pBuffH, UInt* pBuffV, Int iWidth, Int iHeight); |
|---|
| 67 | // ==================================================================================================================== |
|---|
| 68 | // Data structure related table & variable |
|---|
| 69 | // ==================================================================================================================== |
|---|
| 70 | |
|---|
| 71 | // flexible conversion from relative to absolute index |
|---|
| 72 | extern UInt g_auiZscanToRaster[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
|---|
| 73 | extern UInt g_auiRasterToZscan[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
|---|
| 74 | |
|---|
| 75 | Void initZscanToRaster ( Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt*& rpuiCurrIdx ); |
|---|
| 76 | Void initRasterToZscan ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ); |
|---|
| 77 | |
|---|
| 78 | // conversion of partition index to picture pel position |
|---|
| 79 | extern UInt g_auiRasterToPelX[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
|---|
| 80 | extern UInt g_auiRasterToPelY[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
|---|
| 81 | |
|---|
| 82 | Void initRasterToPelXY ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ); |
|---|
| 83 | |
|---|
| 84 | // global variable (LCU width/height, max. CU depth) |
|---|
| 85 | extern UInt g_uiMaxCUWidth; |
|---|
| 86 | extern UInt g_uiMaxCUHeight; |
|---|
| 87 | extern UInt g_uiMaxCUDepth; |
|---|
| 88 | extern UInt g_uiAddCUDepth; |
|---|
| 89 | |
|---|
| 90 | #define MAX_TS_WIDTH 4 |
|---|
| 91 | #define MAX_TS_HEIGHT 4 |
|---|
| 92 | |
|---|
| 93 | extern UInt g_auiPUOffset[8]; |
|---|
| 94 | |
|---|
| 95 | #define QUANT_IQUANT_SHIFT 20 // Q(QP%6) * IQ(QP%6) = 2^20 |
|---|
| 96 | #define QUANT_SHIFT 14 // Q(4) = 2^14 |
|---|
| 97 | #define SCALE_BITS 15 // Inherited from TMuC, pressumably for fractional bit estimates in RDOQ |
|---|
| 98 | #define MAX_TR_DYNAMIC_RANGE 15 // Maximum transform dynamic range (excluding sign bit) |
|---|
| 99 | |
|---|
| 100 | #define SHIFT_INV_1ST 7 // Shift after first inverse transform stage |
|---|
| 101 | #define SHIFT_INV_2ND 12 // Shift after second inverse transform stage |
|---|
| 102 | |
|---|
| 103 | extern Int g_quantScales[6]; // Q(QP%6) |
|---|
| 104 | extern Int g_invQuantScales[6]; // IQ(QP%6) |
|---|
| 105 | extern const Short g_aiT4[4][4]; |
|---|
| 106 | extern const Short g_aiT8[8][8]; |
|---|
| 107 | extern const Short g_aiT16[16][16]; |
|---|
| 108 | extern const Short g_aiT32[32][32]; |
|---|
| 109 | |
|---|
| 110 | // ==================================================================================================================== |
|---|
| 111 | // Luma QP to Chroma QP mapping |
|---|
| 112 | // ==================================================================================================================== |
|---|
| 113 | |
|---|
| 114 | extern const UChar g_aucChromaScale [58]; |
|---|
| 115 | |
|---|
| 116 | // ==================================================================================================================== |
|---|
| 117 | // Scanning order & context mapping table |
|---|
| 118 | // ==================================================================================================================== |
|---|
| 119 | |
|---|
| 120 | extern UInt* g_auiSigLastScan[ 3 ][ MAX_CU_DEPTH ]; // raster index from scanning index (diag, hor, ver) |
|---|
| 121 | |
|---|
| 122 | extern const UInt g_uiGroupIdx[ 32 ]; |
|---|
| 123 | extern const UInt g_uiMinInGroup[ 10 ]; |
|---|
| 124 | |
|---|
| 125 | extern const UInt g_sigLastScan8x8[ 3 ][ 4 ]; //!< coefficient group scan order for 8x8 TUs |
|---|
| 126 | extern UInt g_sigLastScanCG32x32[ 64 ]; |
|---|
| 127 | |
|---|
| 128 | // ==================================================================================================================== |
|---|
| 129 | // ADI table |
|---|
| 130 | // ==================================================================================================================== |
|---|
| 131 | |
|---|
| 132 | extern const UChar g_aucIntraModeNumFast[ MAX_CU_DEPTH ]; |
|---|
| 133 | |
|---|
| 134 | // ==================================================================================================================== |
|---|
| 135 | // Bit-depth |
|---|
| 136 | // ==================================================================================================================== |
|---|
| 137 | |
|---|
| 138 | extern Int g_bitDepthY; |
|---|
| 139 | extern Int g_bitDepthC; |
|---|
| 140 | extern UInt g_uiPCMBitDepthLuma; |
|---|
| 141 | extern UInt g_uiPCMBitDepthChroma; |
|---|
| 142 | |
|---|
| 143 | // ==================================================================================================================== |
|---|
| 144 | // Texture type to integer mapping |
|---|
| 145 | // ==================================================================================================================== |
|---|
| 146 | |
|---|
| 147 | extern const UChar g_aucConvertTxtTypeToIdx[4]; |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | // ========================================== |
|---|
| 151 | // Mode-Dependent DST Matrices |
|---|
| 152 | extern const Short g_as_DST_MAT_4 [4][4]; |
|---|
| 153 | extern const UChar g_aucDCTDSTMode_Vert[NUM_INTRA_MODE]; |
|---|
| 154 | extern const UChar g_aucDCTDSTMode_Hor[NUM_INTRA_MODE]; |
|---|
| 155 | // ========================================== |
|---|
| 156 | |
|---|
| 157 | #if H_MV_HLS_PTL_LIMITS |
|---|
| 158 | class TComGeneralTierAndLevelLimits |
|---|
| 159 | { |
|---|
| 160 | public: |
|---|
| 161 | TComGeneralTierAndLevelLimits::TComGeneralTierAndLevelLimits |
|---|
| 162 | ( Int maxLumaPs, |
|---|
| 163 | Int maxCPBMainTier, |
|---|
| 164 | Int maxCPBHighTier, |
|---|
| 165 | Int maxSliceSegmentsPerPicture, |
|---|
| 166 | Int maxTileRows, |
|---|
| 167 | Int maxTileCols ) |
|---|
| 168 | : m_maxLumaPs ( maxLumaPs ), |
|---|
| 169 | m_maxCPBMainTier ( maxCPBMainTier ), |
|---|
| 170 | m_maxCPBHighTier ( maxCPBHighTier ), |
|---|
| 171 | m_maxSliceSegmentsPerPicture( maxSliceSegmentsPerPicture ), |
|---|
| 172 | m_maxTileRows ( maxTileRows ), |
|---|
| 173 | m_maxTileCols ( maxTileCols ); |
|---|
| 174 | {}; |
|---|
| 175 | |
|---|
| 176 | Int getMaxLumaPs ( ) { return m_maxLumaPs ; }; |
|---|
| 177 | Int getMaxCPBMainTier ( ) { return m_maxCPBMainTier ; }; |
|---|
| 178 | Int getMaxCPBHighTier ( ) { return m_maxCPBHighTier ; }; |
|---|
| 179 | Int getMaxSliceSegmentsPerPicture( ) { return m_maxSliceSegmentsPerPicture; }; |
|---|
| 180 | Int getMaxTileRows ( ) { return m_maxTileRows ; }; |
|---|
| 181 | Int getMaxTileCols ( ) { return m_maxTileCols ; }; |
|---|
| 182 | |
|---|
| 183 | private: |
|---|
| 184 | const Int m_maxLumaPs; |
|---|
| 185 | const Int m_maxCPBMainTier; |
|---|
| 186 | const Int m_maxCPBHighTier; |
|---|
| 187 | const Int m_maxSliceSegmentsPerPicture; |
|---|
| 188 | const Int m_maxTileRows; |
|---|
| 189 | const Int m_maxTileCols; |
|---|
| 190 | }; |
|---|
| 191 | |
|---|
| 192 | extern std::map< Level::Name, TComGeneralTierAndLevelLimits > g_generalTierAndLevelLimits; |
|---|
| 193 | |
|---|
| 194 | #endif |
|---|
| 195 | // ==================================================================================================================== |
|---|
| 196 | // Misc. |
|---|
| 197 | // ==================================================================================================================== |
|---|
| 198 | |
|---|
| 199 | extern Char g_aucConvertToBit [ MAX_CU_SIZE+1 ]; // from width to log2(width)-2 |
|---|
| 200 | |
|---|
| 201 | #ifndef ENC_DEC_TRACE |
|---|
| 202 | #define ENC_DEC_TRACE 0 |
|---|
| 203 | #endif |
|---|
| 204 | |
|---|
| 205 | #if ENC_DEC_TRACE |
|---|
| 206 | extern FILE* g_hTrace; |
|---|
| 207 | extern Bool g_bJustDoIt; |
|---|
| 208 | extern const Bool g_bEncDecTraceEnable; |
|---|
| 209 | extern const Bool g_bEncDecTraceDisable; |
|---|
| 210 | extern Bool g_HLSTraceEnable; |
|---|
| 211 | extern UInt64 g_nSymbolCounter; |
|---|
| 212 | |
|---|
| 213 | #define COUNTER_START 1 |
|---|
| 214 | #define COUNTER_END 0 //( UInt64(1) << 63 ) |
|---|
| 215 | |
|---|
| 216 | #define DTRACE_CABAC_F(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%f", x ); |
|---|
| 217 | #define DTRACE_CABAC_V(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%d", x ); |
|---|
| 218 | #define DTRACE_CABAC_VL(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%lld", x ); |
|---|
| 219 | #define DTRACE_CABAC_T(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%s", x ); |
|---|
| 220 | #define DTRACE_CABAC_X(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%x", x ); |
|---|
| 221 | #define DTRACE_CABAC_R( x,y ) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, x, y ); |
|---|
| 222 | #define DTRACE_CABAC_N if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "\n" ); |
|---|
| 223 | |
|---|
| 224 | #if H_MV_ENC_DEC_TRAC |
|---|
| 225 | extern Bool g_traceCU; |
|---|
| 226 | extern Bool g_tracePU; |
|---|
| 227 | extern Bool g_traceTU; |
|---|
| 228 | extern Bool g_disableHLSTrace; // USE g_HLSTraceEnable to toggle HLS trace. Not this one! |
|---|
| 229 | extern UInt64 g_stopAtCounter; // Counter to set breakpoint. |
|---|
| 230 | extern Bool g_traceCopyBack; // Output samples on copy back |
|---|
| 231 | extern Bool g_decTraceDispDer; // Trace derived disparity vectors (decoder only) |
|---|
| 232 | extern Bool g_decTraceMvFromMerge; // Trace motion vectors obtained from merge (decoder only) |
|---|
| 233 | extern Bool g_decTracePicOutput; // Trace output of pictures |
|---|
| 234 | extern Bool g_stopAtPos; // Stop at position |
|---|
| 235 | extern Bool g_outputPos; // Output position |
|---|
| 236 | |
|---|
| 237 | #define DTRACE_CU(x,y) writeToTraceFile( x,y, g_traceCU ); |
|---|
| 238 | #define DTRACE_PU(x,y) writeToTraceFile( x,y, g_tracePU ); |
|---|
| 239 | #define DTRACE_TU(x,y) writeToTraceFile( x,y, g_traceTU ); |
|---|
| 240 | #define DTRACE_CU_S(x) writeToTraceFile( x, g_traceCU ); |
|---|
| 241 | #define DTRACE_PU_S(x) writeToTraceFile( x, g_tracePU ); |
|---|
| 242 | #define DTRACE_TU_S(x) writeToTraceFile( x, g_traceTU ); |
|---|
| 243 | |
|---|
| 244 | Void writeToTraceFile( const Char* symbolName, Int val, Bool doIt ); |
|---|
| 245 | Void writeToTraceFile( const Char* symbolName, Bool doIt ); |
|---|
| 246 | Void stopAtPos ( Int poc, Int layerId, Int cuPelX, Int cuPelY, Int cuWidth, Int cuHeight ); |
|---|
| 247 | #endif |
|---|
| 248 | #else |
|---|
| 249 | |
|---|
| 250 | #define DTRACE_CABAC_F(x) |
|---|
| 251 | #define DTRACE_CABAC_V(x) |
|---|
| 252 | #define DTRACE_CABAC_VL(x) |
|---|
| 253 | #define DTRACE_CABAC_T(x) |
|---|
| 254 | #define DTRACE_CABAC_X(x) |
|---|
| 255 | #define DTRACE_CABAC_R( x,y ) |
|---|
| 256 | #define DTRACE_CABAC_N |
|---|
| 257 | |
|---|
| 258 | #if H_MV_ENC_DEC_TRAC |
|---|
| 259 | #define DTRACE_CU(x,y) |
|---|
| 260 | #define DTRACE_PU(x,y) |
|---|
| 261 | #define DTRACE_TU(x,y) |
|---|
| 262 | |
|---|
| 263 | #define DTRACE_CU_S(x) |
|---|
| 264 | #define DTRACE_PU_S(x) |
|---|
| 265 | #define DTRACE_TU_S(x) |
|---|
| 266 | |
|---|
| 267 | #endif |
|---|
| 268 | #endif |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | #define SCALING_LIST_NUM 6 ///< list number for quantization matrix |
|---|
| 272 | #define SCALING_LIST_NUM_32x32 2 ///< list number for quantization matrix 32x32 |
|---|
| 273 | #define SCALING_LIST_REM_NUM 6 ///< remainder of QP/6 |
|---|
| 274 | #define SCALING_LIST_START_VALUE 8 ///< start value for dpcm mode |
|---|
| 275 | #define MAX_MATRIX_COEF_NUM 64 ///< max coefficient number for quantization matrix |
|---|
| 276 | #define MAX_MATRIX_SIZE_NUM 8 ///< max size number for quantization matrix |
|---|
| 277 | #define SCALING_LIST_DC 16 ///< default DC value |
|---|
| 278 | enum ScalingListSize |
|---|
| 279 | { |
|---|
| 280 | SCALING_LIST_4x4 = 0, |
|---|
| 281 | SCALING_LIST_8x8, |
|---|
| 282 | SCALING_LIST_16x16, |
|---|
| 283 | SCALING_LIST_32x32, |
|---|
| 284 | SCALING_LIST_SIZE_NUM |
|---|
| 285 | }; |
|---|
| 286 | static const Char MatrixType[4][6][20] = |
|---|
| 287 | { |
|---|
| 288 | { |
|---|
| 289 | "INTRA4X4_LUMA", |
|---|
| 290 | "INTRA4X4_CHROMAU", |
|---|
| 291 | "INTRA4X4_CHROMAV", |
|---|
| 292 | "INTER4X4_LUMA", |
|---|
| 293 | "INTER4X4_CHROMAU", |
|---|
| 294 | "INTER4X4_CHROMAV" |
|---|
| 295 | }, |
|---|
| 296 | { |
|---|
| 297 | "INTRA8X8_LUMA", |
|---|
| 298 | "INTRA8X8_CHROMAU", |
|---|
| 299 | "INTRA8X8_CHROMAV", |
|---|
| 300 | "INTER8X8_LUMA", |
|---|
| 301 | "INTER8X8_CHROMAU", |
|---|
| 302 | "INTER8X8_CHROMAV" |
|---|
| 303 | }, |
|---|
| 304 | { |
|---|
| 305 | "INTRA16X16_LUMA", |
|---|
| 306 | "INTRA16X16_CHROMAU", |
|---|
| 307 | "INTRA16X16_CHROMAV", |
|---|
| 308 | "INTER16X16_LUMA", |
|---|
| 309 | "INTER16X16_CHROMAU", |
|---|
| 310 | "INTER16X16_CHROMAV" |
|---|
| 311 | }, |
|---|
| 312 | { |
|---|
| 313 | "INTRA32X32_LUMA", |
|---|
| 314 | "INTER32X32_LUMA", |
|---|
| 315 | }, |
|---|
| 316 | }; |
|---|
| 317 | static const Char MatrixType_DC[4][12][22] = |
|---|
| 318 | { |
|---|
| 319 | { |
|---|
| 320 | }, |
|---|
| 321 | { |
|---|
| 322 | }, |
|---|
| 323 | { |
|---|
| 324 | "INTRA16X16_LUMA_DC", |
|---|
| 325 | "INTRA16X16_CHROMAU_DC", |
|---|
| 326 | "INTRA16X16_CHROMAV_DC", |
|---|
| 327 | "INTER16X16_LUMA_DC", |
|---|
| 328 | "INTER16X16_CHROMAU_DC", |
|---|
| 329 | "INTER16X16_CHROMAV_DC" |
|---|
| 330 | }, |
|---|
| 331 | { |
|---|
| 332 | "INTRA32X32_LUMA_DC", |
|---|
| 333 | "INTER32X32_LUMA_DC", |
|---|
| 334 | }, |
|---|
| 335 | }; |
|---|
| 336 | extern Int g_quantIntraDefault8x8[64]; |
|---|
| 337 | extern Int g_quantIntraDefault16x16[256]; |
|---|
| 338 | extern Int g_quantIntraDefault32x32[1024]; |
|---|
| 339 | extern Int g_quantInterDefault8x8[64]; |
|---|
| 340 | extern Int g_quantInterDefault16x16[256]; |
|---|
| 341 | extern Int g_quantInterDefault32x32[1024]; |
|---|
| 342 | extern Int g_quantTSDefault4x4[16]; |
|---|
| 343 | extern UInt g_scalingListSize [SCALING_LIST_SIZE_NUM]; |
|---|
| 344 | extern UInt g_scalingListSizeX[SCALING_LIST_SIZE_NUM]; |
|---|
| 345 | extern UInt g_scalingListNum [SCALING_LIST_SIZE_NUM]; |
|---|
| 346 | extern Int g_eTTable[4]; |
|---|
| 347 | //! \} |
|---|
| 348 | |
|---|
| 349 | #endif //__TCOMROM__ |
|---|
| 350 | |
|---|