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