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