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-2012, 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 | |
---|
53 | #define MAX_CU_DEPTH 7 // log2(LCUSize) |
---|
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 | #if !REMOVE_ZIGZAG_SCAN |
---|
65 | Void initFrameScanXY( UInt* pBuff, UInt* pBuffX, UInt* pBuffY, Int iWidth, Int iHeight ); |
---|
66 | #endif |
---|
67 | Void initSigLastScan(UInt* pBuffZ, UInt* pBuffH, UInt* pBuffV, UInt* pBuffD, Int iWidth, Int iHeight, Int iDepth); |
---|
68 | Void initNonSquareSigLastScan(UInt* pBuffZ, UInt uiWidth, UInt uiHeight); |
---|
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 | extern UInt g_motionRefer[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
77 | |
---|
78 | Void initZscanToRaster ( Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt*& rpuiCurrIdx ); |
---|
79 | Void initRasterToZscan ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ); |
---|
80 | |
---|
81 | Void initMotionReferIdx ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ); |
---|
82 | |
---|
83 | // conversion of partition index to picture pel position |
---|
84 | extern UInt g_auiRasterToPelX[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
85 | extern UInt g_auiRasterToPelY[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ]; |
---|
86 | |
---|
87 | Void initRasterToPelXY ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth ); |
---|
88 | |
---|
89 | // global variable (LCU width/height, max. CU depth) |
---|
90 | extern UInt g_uiMaxCUWidth; |
---|
91 | extern UInt g_uiMaxCUHeight; |
---|
92 | extern UInt g_uiMaxCUDepth; |
---|
93 | extern UInt g_uiAddCUDepth; |
---|
94 | |
---|
95 | #define MAX_TS_WIDTH 4 |
---|
96 | #define MAX_TS_HEIGHT 4 |
---|
97 | |
---|
98 | extern UInt g_auiPUOffset[8]; |
---|
99 | |
---|
100 | #define QUANT_IQUANT_SHIFT 20 // Q(QP%6) * IQ(QP%6) = 2^20 |
---|
101 | #define QUANT_SHIFT 14 // Q(4) = 2^14 |
---|
102 | #define SCALE_BITS 15 // Inherited from TMuC, pressumably for fractional bit estimates in RDOQ |
---|
103 | #define MAX_TR_DYNAMIC_RANGE 15 // Maximum transform dynamic range (excluding sign bit) |
---|
104 | |
---|
105 | #define SHIFT_INV_1ST 7 // Shift after first inverse transform stage |
---|
106 | #define SHIFT_INV_2ND 12 // Shift after second inverse transform stage |
---|
107 | |
---|
108 | extern Int g_quantScales[6]; // Q(QP%6) |
---|
109 | extern Int g_invQuantScales[6]; // IQ(QP%6) |
---|
110 | extern const short g_aiT4[4][4]; |
---|
111 | extern const short g_aiT8[8][8]; |
---|
112 | extern const short g_aiT16[16][16]; |
---|
113 | extern const short g_aiT32[32][32]; |
---|
114 | |
---|
115 | // ==================================================================================================================== |
---|
116 | // Luma QP to Chroma QP mapping |
---|
117 | // ==================================================================================================================== |
---|
118 | |
---|
119 | #if CHROMA_QP_EXTENSION |
---|
120 | extern const UChar g_aucChromaScale [58]; |
---|
121 | #else |
---|
122 | extern const UChar g_aucChromaScale [52]; |
---|
123 | #endif |
---|
124 | |
---|
125 | // ==================================================================================================================== |
---|
126 | // Scanning order & context mapping table |
---|
127 | // ==================================================================================================================== |
---|
128 | |
---|
129 | #if !REMOVE_ZIGZAG_SCAN |
---|
130 | extern UInt* g_auiFrameScanXY[ MAX_CU_DEPTH ]; // raster index from scanning index |
---|
131 | extern UInt* g_auiFrameScanX [ MAX_CU_DEPTH ]; // raster index (x) from scanning index |
---|
132 | extern UInt* g_auiFrameScanY [ MAX_CU_DEPTH ]; // raster index (y) from scanning index |
---|
133 | #endif |
---|
134 | extern UInt* g_auiSigLastScan[4][ MAX_CU_DEPTH ]; // raster index from scanning index (zigzag, hor, ver, diag) |
---|
135 | #if !REMOVE_NSQT |
---|
136 | extern UInt *g_sigScanNSQT[ 4 ]; // scan for non-square partitions |
---|
137 | extern UInt g_sigCGScanNSQT[ 4 ][ 16 ]; // coarse-grain scan for non-square partitions |
---|
138 | #endif |
---|
139 | |
---|
140 | extern UInt* g_auiNonSquareSigLastScan[ 4 ]; // raster index from scanning index (zigzag) |
---|
141 | |
---|
142 | extern const UInt g_uiGroupIdx[ 32 ]; |
---|
143 | extern const UInt g_uiMinInGroup[ 10 ]; |
---|
144 | |
---|
145 | extern const UInt g_auiGoRiceRange[5]; //!< maximum value coded with Rice codes |
---|
146 | extern const UInt g_auiGoRicePrefixLen[5]; //!< prefix length for each maximum value |
---|
147 | |
---|
148 | extern const UInt g_sigLastScan8x8[ 4 ][ 4 ]; //!< coefficient group scan order for 8x8 TUs |
---|
149 | extern UInt g_sigLastScanCG32x32[ 64 ]; |
---|
150 | |
---|
151 | // ==================================================================================================================== |
---|
152 | // ADI table |
---|
153 | // ==================================================================================================================== |
---|
154 | |
---|
155 | extern const UChar g_aucIntraModeNumFast[7]; |
---|
156 | |
---|
157 | // ==================================================================================================================== |
---|
158 | // Angular Intra table |
---|
159 | // ==================================================================================================================== |
---|
160 | |
---|
161 | extern const UChar g_aucIntraModeNumAng[7]; |
---|
162 | extern const UChar g_aucIntraModeBitsAng[7]; |
---|
163 | extern const UChar g_aucAngIntraModeOrder[NUM_INTRA_MODE]; |
---|
164 | |
---|
165 | // ==================================================================================================================== |
---|
166 | // Bit-depth |
---|
167 | // ==================================================================================================================== |
---|
168 | |
---|
169 | extern UInt g_uiBitDepth; |
---|
170 | extern UInt g_uiBitIncrement; |
---|
171 | extern UInt g_uiIBDI_MAX; |
---|
172 | extern UInt g_uiBASE_MAX; |
---|
173 | extern UInt g_uiPCMBitDepthLuma; |
---|
174 | extern UInt g_uiPCMBitDepthChroma; |
---|
175 | |
---|
176 | // ==================================================================================================================== |
---|
177 | // Texture type to integer mapping |
---|
178 | // ==================================================================================================================== |
---|
179 | |
---|
180 | extern const UChar g_aucConvertTxtTypeToIdx[4]; |
---|
181 | |
---|
182 | // ========================================== |
---|
183 | // Mode-Dependent DST Matrices |
---|
184 | extern const short g_as_DST_MAT_4 [4][4]; |
---|
185 | extern const UChar g_aucDCTDSTMode_Vert[NUM_INTRA_MODE]; |
---|
186 | extern const UChar g_aucDCTDSTMode_Hor[NUM_INTRA_MODE]; |
---|
187 | // ========================================== |
---|
188 | |
---|
189 | // ==================================================================================================================== |
---|
190 | // Misc. |
---|
191 | // ==================================================================================================================== |
---|
192 | |
---|
193 | extern Char g_aucConvertToBit [ MAX_CU_SIZE+1 ]; // from width to log2(width)-2 |
---|
194 | |
---|
195 | #define ENC_DEC_TRACE 0 |
---|
196 | |
---|
197 | |
---|
198 | #if ENC_DEC_TRACE |
---|
199 | extern FILE* g_hTrace; |
---|
200 | extern Bool g_bJustDoIt; |
---|
201 | extern const Bool g_bEncDecTraceEnable; |
---|
202 | extern const Bool g_bEncDecTraceDisable; |
---|
203 | extern Bool g_HLSTraceEnable; |
---|
204 | extern UInt64 g_nSymbolCounter; |
---|
205 | |
---|
206 | #define COUNTER_START 1 |
---|
207 | #define COUNTER_END 0 //( UInt64(1) << 63 ) |
---|
208 | |
---|
209 | #define DTRACE_CABAC_F(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%f", x ); |
---|
210 | #define DTRACE_CABAC_V(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%d", x ); |
---|
211 | #define DTRACE_CABAC_VL(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%lld", x ); |
---|
212 | #define DTRACE_CABAC_T(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%s", x ); |
---|
213 | #define DTRACE_CABAC_X(x) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%x", x ); |
---|
214 | #define DTRACE_CABAC_R( x,y ) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, x, y ); |
---|
215 | #define DTRACE_CABAC_N if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "\n" ); |
---|
216 | |
---|
217 | #else |
---|
218 | |
---|
219 | #define DTRACE_CABAC_F(x) |
---|
220 | #define DTRACE_CABAC_V(x) |
---|
221 | #define DTRACE_CABAC_VL(x) |
---|
222 | #define DTRACE_CABAC_T(x) |
---|
223 | #define DTRACE_CABAC_X(x) |
---|
224 | #define DTRACE_CABAC_R( x,y ) |
---|
225 | #define DTRACE_CABAC_N |
---|
226 | |
---|
227 | #endif |
---|
228 | |
---|
229 | |
---|
230 | #define SCALING_LIST_NUM 6 ///< list number for quantization matrix |
---|
231 | #define SCALING_LIST_NUM_32x32 2 ///< list number for quantization matrix 32x32 |
---|
232 | #define SCALING_LIST_REM_NUM 6 ///< remainder of QP/6 |
---|
233 | #define SCALING_LIST_START_VALUE 8 ///< start value for dpcm mode |
---|
234 | #define MAX_MATRIX_COEF_NUM 64 ///< max coefficient number for quantization matrix |
---|
235 | #define MAX_MATRIX_SIZE_NUM 8 ///< max size number for quantization matrix |
---|
236 | #define SCALING_LIST_DC 16 ///< default DC value |
---|
237 | enum ScalingListDIR |
---|
238 | { |
---|
239 | SCALING_LIST_SQT = 0, |
---|
240 | SCALING_LIST_VER, |
---|
241 | SCALING_LIST_HOR, |
---|
242 | SCALING_LIST_DIR_NUM |
---|
243 | }; |
---|
244 | enum ScalingListSize |
---|
245 | { |
---|
246 | SCALING_LIST_4x4 = 0, |
---|
247 | SCALING_LIST_8x8, |
---|
248 | SCALING_LIST_16x16, |
---|
249 | SCALING_LIST_32x32, |
---|
250 | SCALING_LIST_SIZE_NUM |
---|
251 | }; |
---|
252 | static const char MatrixType[4][6][20] = |
---|
253 | { |
---|
254 | { |
---|
255 | "INTRA4X4_LUMA", |
---|
256 | "INTRA4X4_CHROMAU", |
---|
257 | "INTRA4X4_CHROMAV", |
---|
258 | "INTER4X4_LUMA", |
---|
259 | "INTER4X4_CHROMAU", |
---|
260 | "INTER4X4_CHROMAV" |
---|
261 | }, |
---|
262 | { |
---|
263 | "INTRA8X8_LUMA", |
---|
264 | "INTRA8X8_CHROMAU", |
---|
265 | "INTRA8X8_CHROMAV", |
---|
266 | "INTER8X8_LUMA", |
---|
267 | "INTER8X8_CHROMAU", |
---|
268 | "INTER8X8_CHROMAV" |
---|
269 | }, |
---|
270 | { |
---|
271 | "INTRA16X16_LUMA", |
---|
272 | "INTRA16X16_CHROMAU", |
---|
273 | "INTRA16X16_CHROMAV", |
---|
274 | "INTER16X16_LUMA", |
---|
275 | "INTER16X16_CHROMAU", |
---|
276 | "INTER16X16_CHROMAV" |
---|
277 | }, |
---|
278 | { |
---|
279 | "INTRA32X32_LUMA", |
---|
280 | "INTER32X32_LUMA", |
---|
281 | }, |
---|
282 | }; |
---|
283 | static const char MatrixType_DC[4][12][22] = |
---|
284 | { |
---|
285 | { |
---|
286 | }, |
---|
287 | { |
---|
288 | }, |
---|
289 | { |
---|
290 | "INTRA16X16_LUMA_DC", |
---|
291 | "INTRA16X16_CHROMAU_DC", |
---|
292 | "INTRA16X16_CHROMAV_DC", |
---|
293 | "INTER16X16_LUMA_DC", |
---|
294 | "INTER16X16_CHROMAU_DC", |
---|
295 | "INTER16X16_CHROMAV_DC" |
---|
296 | }, |
---|
297 | { |
---|
298 | "INTRA32X32_LUMA_DC", |
---|
299 | "INTER32X32_LUMA_DC", |
---|
300 | }, |
---|
301 | }; |
---|
302 | extern Int g_quantIntraDefault4x4[16]; |
---|
303 | extern Int g_quantIntraDefault8x8[64]; |
---|
304 | extern Int g_quantIntraDefault16x16[256]; |
---|
305 | extern Int g_quantIntraDefault32x32[1024]; |
---|
306 | extern Int g_quantInterDefault4x4[16]; |
---|
307 | extern Int g_quantInterDefault8x8[64]; |
---|
308 | extern Int g_quantInterDefault16x16[256]; |
---|
309 | extern Int g_quantInterDefault32x32[1024]; |
---|
310 | #if TS_FLAT_QUANTIZATION_MATRIX |
---|
311 | extern Int g_quantTSDefault4x4[16]; |
---|
312 | #endif |
---|
313 | extern UInt g_scalingListSize [SCALING_LIST_SIZE_NUM]; |
---|
314 | extern UInt g_scalingListSizeX[SCALING_LIST_SIZE_NUM]; |
---|
315 | extern UInt g_scalingListNum [SCALING_LIST_SIZE_NUM]; |
---|
316 | extern Int g_eTTable[4]; |
---|
317 | //! \} |
---|
318 | |
---|
319 | #endif //__TCOMROM__ |
---|
320 | |
---|