source: 3DVCSoftware/branches/HTM-12.2-dev1-Mediatek/source/Lib/TLibCommon/TComRom.cpp @ 1092

Last change on this file since 1092 was 1092, checked in by mediatek-htm, 10 years ago

Adding J0035 related changes, which reduces table size for the DMM wedgelet patterns. The corresponding changes are marked by macro MTK_DMM_SIM_J0035.

  • Property svn:eol-style set to native
File size: 30.5 KB
Line 
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.cpp
35    \brief    global variables & functions
36*/
37
38#include "TComRom.h"
39#include <memory.h>
40#include <stdlib.h>
41#include <stdio.h>
42// ====================================================================================================================
43// Initialize / destroy functions
44// ====================================================================================================================
45
46//! \ingroup TLibCommon
47//! \{
48
49// initialize ROM variables
50Void initROM()
51{
52  Int i, c;
53 
54  // g_aucConvertToBit[ x ]: log2(x/4), if x=4 -> 0, x=8 -> 1, x=16 -> 2, ...
55  ::memset( g_aucConvertToBit,   -1, sizeof( g_aucConvertToBit ) );
56  c=0;
57  for ( i=4; i<=MAX_CU_SIZE; i*=2 )
58  {
59    g_aucConvertToBit[ i ] = c;
60    c++;
61  }
62 
63  c=2;
64  for ( i=0; i<MAX_CU_DEPTH; i++ )
65  {
66    g_auiSigLastScan[0][i] = new UInt[ c*c ];
67    g_auiSigLastScan[1][i] = new UInt[ c*c ];
68    g_auiSigLastScan[2][i] = new UInt[ c*c ];
69    initSigLastScan( g_auiSigLastScan[0][i], g_auiSigLastScan[1][i], g_auiSigLastScan[2][i], c, c);
70
71    c <<= 1;
72  } 
73
74#if H_MV
75#if H_MV_HLS_PTL_LIMITS
76 g_generalTierAndLevelLimits[ Level::LEVEL1   ] = TComGeneralTierAndLevelLimits(    36864,     350,  INT_MIN,   16,   1,   1 );
77 g_generalTierAndLevelLimits[ Level::LEVEL2   ] = TComGeneralTierAndLevelLimits(   122880,    1500,  INT_MIN,   16,   1,   1 );
78 g_generalTierAndLevelLimits[ Level::LEVEL2_1 ] = TComGeneralTierAndLevelLimits(   245760,    3000,  INT_MIN,   20,   1,   1 );
79 g_generalTierAndLevelLimits[ Level::LEVEL3   ] = TComGeneralTierAndLevelLimits(   552960,    6000,  INT_MIN,   30,   2,   2 );
80 g_generalTierAndLevelLimits[ Level::LEVEL3_1 ] = TComGeneralTierAndLevelLimits(   983040,   10000,  INT_MIN,   40,   3,   3 );
81 g_generalTierAndLevelLimits[ Level::LEVEL4   ] = TComGeneralTierAndLevelLimits(  2228224,   12000,    30000,   75,   5,   5 );
82 g_generalTierAndLevelLimits[ Level::LEVEL4_1 ] = TComGeneralTierAndLevelLimits(  2228224,   20000,    50000,   75,   5,   5 );
83 g_generalTierAndLevelLimits[ Level::LEVEL5   ] = TComGeneralTierAndLevelLimits(  8912896,   25000,   100000,  200,  11,  10 );
84 g_generalTierAndLevelLimits[ Level::LEVEL5_1 ] = TComGeneralTierAndLevelLimits(  8912896,   40000,   160000,  200,  11,  10 );
85 g_generalTierAndLevelLimits[ Level::LEVEL5_2 ] = TComGeneralTierAndLevelLimits(  8912896,   60000,   240000,  200,  11,  10 );
86 g_generalTierAndLevelLimits[ Level::LEVEL6   ] = TComGeneralTierAndLevelLimits( 35651584,   60000,   240000,  600,  22,  20 );
87 g_generalTierAndLevelLimits[ Level::LEVEL6_1 ] = TComGeneralTierAndLevelLimits( 35651584,  120000,   480000,  600,  22,  20 );
88 g_generalTierAndLevelLimits[ Level::LEVEL6_2 ] = TComGeneralTierAndLevelLimits( 35651584,  240000,   800000,  600,  22,  20 );
89#endif
90#endif
91
92}
93
94Void destroyROM()
95{
96  for (Int i=0; i<MAX_CU_DEPTH; i++ )
97  {
98    delete[] g_auiSigLastScan[0][i];
99    delete[] g_auiSigLastScan[1][i];
100    delete[] g_auiSigLastScan[2][i];
101  }
102
103#if H_3D_DIM_DMM
104  if( !g_dmmWedgeLists.empty() ) 
105  {
106    for( UInt ui = 0; ui < g_dmmWedgeLists.size(); ui++ ) { g_dmmWedgeLists[ui].clear(); }
107    g_dmmWedgeLists.clear();
108  }
109  if( !g_dmmWedgeRefLists.empty() )
110  {
111    for( UInt ui = 0; ui < g_dmmWedgeRefLists.size(); ui++ ) { g_dmmWedgeRefLists[ui].clear(); }
112    g_dmmWedgeRefLists.clear();
113  }
114
115  if( !g_dmmWedgeNodeLists.empty() )
116  {
117    for( UInt ui = 0; ui < g_dmmWedgeNodeLists.size(); ui++ ) { g_dmmWedgeNodeLists[ui].clear(); }
118    g_dmmWedgeNodeLists.clear();
119  }
120#endif
121}
122
123// ====================================================================================================================
124// Data structure related table & variable
125// ====================================================================================================================
126
127UInt g_uiMaxCUWidth  = MAX_CU_SIZE;
128UInt g_uiMaxCUHeight = MAX_CU_SIZE;
129UInt g_uiMaxCUDepth  = MAX_CU_DEPTH;
130UInt g_uiAddCUDepth  = 0;
131UInt g_auiZscanToRaster [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, };
132UInt g_auiRasterToZscan [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, };
133UInt g_auiRasterToPelX  [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, };
134UInt g_auiRasterToPelY  [ MAX_NUM_SPU_W*MAX_NUM_SPU_W ] = { 0, };
135
136UInt g_auiPUOffset[8] = { 0, 8, 4, 4, 2, 10, 1, 5};
137
138Void initZscanToRaster ( Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt*& rpuiCurrIdx )
139{
140  Int iStride = 1 << ( iMaxDepth - 1 );
141 
142  if ( iDepth == iMaxDepth )
143  {
144    rpuiCurrIdx[0] = uiStartVal;
145    rpuiCurrIdx++;
146  }
147  else
148  {
149    Int iStep = iStride >> iDepth;
150    initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal,                     rpuiCurrIdx );
151    initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep,               rpuiCurrIdx );
152    initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep*iStride,       rpuiCurrIdx );
153    initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep*iStride+iStep, rpuiCurrIdx );
154  }
155}
156
157Void initRasterToZscan ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth )
158{
159  UInt  uiMinCUWidth  = uiMaxCUWidth  >> ( uiMaxDepth - 1 );
160  UInt  uiMinCUHeight = uiMaxCUHeight >> ( uiMaxDepth - 1 );
161 
162  UInt  uiNumPartInWidth  = (UInt)uiMaxCUWidth  / uiMinCUWidth;
163  UInt  uiNumPartInHeight = (UInt)uiMaxCUHeight / uiMinCUHeight;
164 
165  for ( UInt i = 0; i < uiNumPartInWidth*uiNumPartInHeight; i++ )
166  {
167    g_auiRasterToZscan[ g_auiZscanToRaster[i] ] = i;
168  }
169}
170
171Void initRasterToPelXY ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth )
172{
173  UInt    i;
174 
175  UInt* uiTempX = &g_auiRasterToPelX[0];
176  UInt* uiTempY = &g_auiRasterToPelY[0];
177 
178  UInt  uiMinCUWidth  = uiMaxCUWidth  >> ( uiMaxDepth - 1 );
179  UInt  uiMinCUHeight = uiMaxCUHeight >> ( uiMaxDepth - 1 );
180 
181  UInt  uiNumPartInWidth  = uiMaxCUWidth  / uiMinCUWidth;
182  UInt  uiNumPartInHeight = uiMaxCUHeight / uiMinCUHeight;
183 
184  uiTempX[0] = 0; uiTempX++;
185  for ( i = 1; i < uiNumPartInWidth; i++ )
186  {
187    uiTempX[0] = uiTempX[-1] + uiMinCUWidth; uiTempX++;
188  }
189  for ( i = 1; i < uiNumPartInHeight; i++ )
190  {
191    memcpy(uiTempX, uiTempX-uiNumPartInWidth, sizeof(UInt)*uiNumPartInWidth);
192    uiTempX += uiNumPartInWidth;
193  }
194 
195  for ( i = 1; i < uiNumPartInWidth*uiNumPartInHeight; i++ )
196  {
197    uiTempY[i] = ( i / uiNumPartInWidth ) * uiMinCUWidth;
198  }
199};
200
201
202Int g_quantScales[6] =
203{
204  26214,23302,20560,18396,16384,14564
205};   
206
207Int g_invQuantScales[6] =
208{
209  40,45,51,57,64,72
210};
211
212const Short g_aiT4[4][4] =
213{
214  { 64, 64, 64, 64},
215  { 83, 36,-36,-83},
216  { 64,-64,-64, 64},
217  { 36,-83, 83,-36}
218};
219
220const Short g_aiT8[8][8] =
221{
222  { 64, 64, 64, 64, 64, 64, 64, 64},
223  { 89, 75, 50, 18,-18,-50,-75,-89},
224  { 83, 36,-36,-83,-83,-36, 36, 83},
225  { 75,-18,-89,-50, 50, 89, 18,-75},
226  { 64,-64,-64, 64, 64,-64,-64, 64},
227  { 50,-89, 18, 75,-75,-18, 89,-50},
228  { 36,-83, 83,-36,-36, 83,-83, 36},
229  { 18,-50, 75,-89, 89,-75, 50,-18}
230};
231
232const Short g_aiT16[16][16] =
233{
234  { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64},
235  { 90, 87, 80, 70, 57, 43, 25,  9, -9,-25,-43,-57,-70,-80,-87,-90},
236  { 89, 75, 50, 18,-18,-50,-75,-89,-89,-75,-50,-18, 18, 50, 75, 89},
237  { 87, 57,  9,-43,-80,-90,-70,-25, 25, 70, 90, 80, 43, -9,-57,-87},
238  { 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83},
239  { 80,  9,-70,-87,-25, 57, 90, 43,-43,-90,-57, 25, 87, 70, -9,-80},
240  { 75,-18,-89,-50, 50, 89, 18,-75,-75, 18, 89, 50,-50,-89,-18, 75},
241  { 70,-43,-87,  9, 90, 25,-80,-57, 57, 80,-25,-90, -9, 87, 43,-70},
242  { 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64},
243  { 57,-80,-25, 90, -9,-87, 43, 70,-70,-43, 87,  9,-90, 25, 80,-57},
244  { 50,-89, 18, 75,-75,-18, 89,-50,-50, 89,-18,-75, 75, 18,-89, 50},
245  { 43,-90, 57, 25,-87, 70,  9,-80, 80, -9,-70, 87,-25,-57, 90,-43},
246  { 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36},
247  { 25,-70, 90,-80, 43,  9,-57, 87,-87, 57, -9,-43, 80,-90, 70,-25},
248  { 18,-50, 75,-89, 89,-75, 50,-18,-18, 50,-75, 89,-89, 75,-50, 18},
249  {  9,-25, 43,-57, 70,-80, 87,-90, 90,-87, 80,-70, 57,-43, 25, -9}
250};
251
252const Short g_aiT32[32][32] =
253{
254  { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64},
255  { 90, 90, 88, 85, 82, 78, 73, 67, 61, 54, 46, 38, 31, 22, 13,  4, -4,-13,-22,-31,-38,-46,-54,-61,-67,-73,-78,-82,-85,-88,-90,-90},
256  { 90, 87, 80, 70, 57, 43, 25,  9, -9,-25,-43,-57,-70,-80,-87,-90,-90,-87,-80,-70,-57,-43,-25, -9,  9, 25, 43, 57, 70, 80, 87, 90},
257  { 90, 82, 67, 46, 22, -4,-31,-54,-73,-85,-90,-88,-78,-61,-38,-13, 13, 38, 61, 78, 88, 90, 85, 73, 54, 31,  4,-22,-46,-67,-82,-90},
258  { 89, 75, 50, 18,-18,-50,-75,-89,-89,-75,-50,-18, 18, 50, 75, 89, 89, 75, 50, 18,-18,-50,-75,-89,-89,-75,-50,-18, 18, 50, 75, 89},
259  { 88, 67, 31,-13,-54,-82,-90,-78,-46, -4, 38, 73, 90, 85, 61, 22,-22,-61,-85,-90,-73,-38,  4, 46, 78, 90, 82, 54, 13,-31,-67,-88},
260  { 87, 57,  9,-43,-80,-90,-70,-25, 25, 70, 90, 80, 43, -9,-57,-87,-87,-57, -9, 43, 80, 90, 70, 25,-25,-70,-90,-80,-43,  9, 57, 87},
261  { 85, 46,-13,-67,-90,-73,-22, 38, 82, 88, 54, -4,-61,-90,-78,-31, 31, 78, 90, 61,  4,-54,-88,-82,-38, 22, 73, 90, 67, 13,-46,-85},
262  { 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83, 83, 36,-36,-83,-83,-36, 36, 83},
263  { 82, 22,-54,-90,-61, 13, 78, 85, 31,-46,-90,-67,  4, 73, 88, 38,-38,-88,-73, -4, 67, 90, 46,-31,-85,-78,-13, 61, 90, 54,-22,-82},
264  { 80,  9,-70,-87,-25, 57, 90, 43,-43,-90,-57, 25, 87, 70, -9,-80,-80, -9, 70, 87, 25,-57,-90,-43, 43, 90, 57,-25,-87,-70,  9, 80},
265  { 78, -4,-82,-73, 13, 85, 67,-22,-88,-61, 31, 90, 54,-38,-90,-46, 46, 90, 38,-54,-90,-31, 61, 88, 22,-67,-85,-13, 73, 82,  4,-78},
266  { 75,-18,-89,-50, 50, 89, 18,-75,-75, 18, 89, 50,-50,-89,-18, 75, 75,-18,-89,-50, 50, 89, 18,-75,-75, 18, 89, 50,-50,-89,-18, 75},
267  { 73,-31,-90,-22, 78, 67,-38,-90,-13, 82, 61,-46,-88, -4, 85, 54,-54,-85,  4, 88, 46,-61,-82, 13, 90, 38,-67,-78, 22, 90, 31,-73},
268  { 70,-43,-87,  9, 90, 25,-80,-57, 57, 80,-25,-90, -9, 87, 43,-70,-70, 43, 87, -9,-90,-25, 80, 57,-57,-80, 25, 90,  9,-87,-43, 70},
269  { 67,-54,-78, 38, 85,-22,-90,  4, 90, 13,-88,-31, 82, 46,-73,-61, 61, 73,-46,-82, 31, 88,-13,-90, -4, 90, 22,-85,-38, 78, 54,-67},
270  { 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64, 64,-64,-64, 64},
271  { 61,-73,-46, 82, 31,-88,-13, 90, -4,-90, 22, 85,-38,-78, 54, 67,-67,-54, 78, 38,-85,-22, 90,  4,-90, 13, 88,-31,-82, 46, 73,-61},
272  { 57,-80,-25, 90, -9,-87, 43, 70,-70,-43, 87,  9,-90, 25, 80,-57,-57, 80, 25,-90,  9, 87,-43,-70, 70, 43,-87, -9, 90,-25,-80, 57},
273  { 54,-85, -4, 88,-46,-61, 82, 13,-90, 38, 67,-78,-22, 90,-31,-73, 73, 31,-90, 22, 78,-67,-38, 90,-13,-82, 61, 46,-88,  4, 85,-54},
274  { 50,-89, 18, 75,-75,-18, 89,-50,-50, 89,-18,-75, 75, 18,-89, 50, 50,-89, 18, 75,-75,-18, 89,-50,-50, 89,-18,-75, 75, 18,-89, 50},
275  { 46,-90, 38, 54,-90, 31, 61,-88, 22, 67,-85, 13, 73,-82,  4, 78,-78, -4, 82,-73,-13, 85,-67,-22, 88,-61,-31, 90,-54,-38, 90,-46},
276  { 43,-90, 57, 25,-87, 70,  9,-80, 80, -9,-70, 87,-25,-57, 90,-43,-43, 90,-57,-25, 87,-70, -9, 80,-80,  9, 70,-87, 25, 57,-90, 43},
277  { 38,-88, 73, -4,-67, 90,-46,-31, 85,-78, 13, 61,-90, 54, 22,-82, 82,-22,-54, 90,-61,-13, 78,-85, 31, 46,-90, 67,  4,-73, 88,-38},
278  { 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36, 36,-83, 83,-36,-36, 83,-83, 36},
279  { 31,-78, 90,-61,  4, 54,-88, 82,-38,-22, 73,-90, 67,-13,-46, 85,-85, 46, 13,-67, 90,-73, 22, 38,-82, 88,-54, -4, 61,-90, 78,-31},
280  { 25,-70, 90,-80, 43,  9,-57, 87,-87, 57, -9,-43, 80,-90, 70,-25,-25, 70,-90, 80,-43, -9, 57,-87, 87,-57,  9, 43,-80, 90,-70, 25},
281  { 22,-61, 85,-90, 73,-38, -4, 46,-78, 90,-82, 54,-13,-31, 67,-88, 88,-67, 31, 13,-54, 82,-90, 78,-46,  4, 38,-73, 90,-85, 61,-22},
282  { 18,-50, 75,-89, 89,-75, 50,-18,-18, 50,-75, 89,-89, 75,-50, 18, 18,-50, 75,-89, 89,-75, 50,-18,-18, 50,-75, 89,-89, 75,-50, 18},
283  { 13,-38, 61,-78, 88,-90, 85,-73, 54,-31,  4, 22,-46, 67,-82, 90,-90, 82,-67, 46,-22, -4, 31,-54, 73,-85, 90,-88, 78,-61, 38,-13},
284  {  9,-25, 43,-57, 70,-80, 87,-90, 90,-87, 80,-70, 57,-43, 25, -9, -9, 25,-43, 57,-70, 80,-87, 90,-90, 87,-80, 70,-57, 43,-25,  9},
285  {  4,-13, 22,-31, 38,-46, 54,-61, 67,-73, 78,-82, 85,-88, 90,-90, 90,-90, 88,-85, 82,-78, 73,-67, 61,-54, 46,-38, 31,-22, 13, -4}
286};
287
288const UChar g_aucChromaScale[58]=
289{
290   0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,
291  17,18,19,20,21,22,23,24,25,26,27,28,29,29,30,31,32,
292  33,33,34,34,35,35,36,36,37,37,38,39,40,41,42,43,44,
293  45,46,47,48,49,50,51
294};
295
296
297// Mode-Dependent DCT/DST
298const Short g_as_DST_MAT_4 [4][4]=
299{
300  {29,   55,    74,   84},
301  {74,   74,    0 ,  -74},
302  {84,  -29,   -74,   55},
303  {55,  -84,    74,  -29},
304};
305
306
307// ====================================================================================================================
308// ADI
309// ====================================================================================================================
310
311#if FAST_UDI_USE_MPM
312const UChar g_aucIntraModeNumFast[MAX_CU_DEPTH] =
313{
314  3,  //   2x2
315  8,  //   4x4
316  8,  //   8x8
317  3,  //  16x16   
318  3,  //  32x32   
319  3   //  64x64   
320};
321#else // FAST_UDI_USE_MPM
322const UChar g_aucIntraModeNumFast[MAX_CU_DEPTH] =
323{
324  3,  //   2x2
325  9,  //   4x4
326  9,  //   8x8
327  4,  //  16x16   33
328  4,  //  32x32   33
329  5   //  64x64   33
330};
331#endif // FAST_UDI_USE_MPM
332
333// chroma
334
335const UChar g_aucConvertTxtTypeToIdx[4] = { 0, 1, 1, 2 };
336
337
338// ====================================================================================================================
339// Bit-depth
340// ====================================================================================================================
341
342Int  g_bitDepthY = 8;
343Int  g_bitDepthC = 8;
344
345UInt g_uiPCMBitDepthLuma     = 8;    // PCM bit-depth
346UInt g_uiPCMBitDepthChroma   = 8;    // PCM bit-depth
347
348#if H_3D_DIM_DMM
349// ====================================================================================================================
350// Depth coding modes
351// ====================================================================================================================
352const WedgeResolution g_dmmWedgeResolution[6] = 
353{
354  HALF_PEL,    //   4x4
355  HALF_PEL,    //   8x8
356  FULL_PEL,    //  16x16
357  FULL_PEL,    //  32x32
358  FULL_PEL,    //  64x64
359  FULL_PEL     // 128x128
360};
361
362const UChar g_dmm1TabIdxBits[6] =
363{ //2x2   4x4   8x8 16x16 32x32 64x64
364#if MTK_DMM_SIM_J0035
365     0,    7,   10,   9,    9,   13 };
366#else
367     0,    7,   10,   11,   11,   13 };
368#endif
369
370const UChar g_dmm3IntraTabIdxBits[6] =
371{ //2x2   4x4   8x8 16x16 32x32 64x64
372     0,    4,    7,    8,    8,    0 };
373
374Bool g_wedgePattern[32*32];
375
376extern std::vector< std::vector<TComWedgelet> >   g_dmmWedgeLists;
377extern std::vector< std::vector<TComWedgeRef> >   g_dmmWedgeRefLists;
378extern std::vector< std::vector<TComWedgeNode> >  g_dmmWedgeNodeLists;
379#endif
380
381// ====================================================================================================================
382// Misc.
383// ====================================================================================================================
384
385Char  g_aucConvertToBit  [ MAX_CU_SIZE+1 ];
386#if ENC_DEC_TRACE
387FILE*  g_hTrace = NULL;
388const Bool g_bEncDecTraceEnable  = true;
389const Bool g_bEncDecTraceDisable = false;
390Bool   g_HLSTraceEnable = true;
391Bool   g_bJustDoIt = false;
392UInt64 g_nSymbolCounter = 0;
393#if H_MV_ENC_DEC_TRAC
394Bool g_traceCU = false; 
395Bool g_tracePU = false; 
396Bool g_traceTU = false; 
397Bool g_disableHLSTrace = false; 
398UInt64 g_stopAtCounter       = 0; 
399Bool g_traceCopyBack         = false; 
400Bool g_decTraceDispDer       = false; 
401Bool g_decTraceMvFromMerge   = false; 
402Bool g_decTracePicOutput     = false; 
403Bool g_stopAtPos             = false; 
404Bool g_outputPos             = false; 
405#endif
406#endif
407// ====================================================================================================================
408// Scanning order & context model mapping
409// ====================================================================================================================
410
411// scanning order table
412UInt* g_auiSigLastScan[ 3 ][ MAX_CU_DEPTH ];
413
414const UInt g_sigLastScan8x8[ 3 ][ 4 ] =
415{
416  {0, 2, 1, 3},
417  {0, 1, 2, 3},
418  {0, 2, 1, 3}
419};
420UInt g_sigLastScanCG32x32[ 64 ];
421
422const UInt g_uiMinInGroup[ 10 ] = {0,1,2,3,4,6,8,12,16,24};
423const UInt g_uiGroupIdx[ 32 ]   = {0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9};
424
425Void initSigLastScan(UInt* pBuffD, UInt* pBuffH, UInt* pBuffV, Int iWidth, Int iHeight)
426{
427  const UInt  uiNumScanPos  = UInt( iWidth * iWidth );
428  UInt        uiNextScanPos = 0;
429
430  if( iWidth < 16 )
431  {
432  UInt* pBuffTemp = pBuffD;
433  if( iWidth == 8 )
434  {
435    pBuffTemp = g_sigLastScanCG32x32;
436  }
437  for( UInt uiScanLine = 0; uiNextScanPos < uiNumScanPos; uiScanLine++ )
438  {
439    Int    iPrimDim  = Int( uiScanLine );
440    Int    iScndDim  = 0;
441    while( iPrimDim >= iWidth )
442    {
443      iScndDim++;
444      iPrimDim--;
445    }
446    while( iPrimDim >= 0 && iScndDim < iWidth )
447    {
448      pBuffTemp[ uiNextScanPos ] = iPrimDim * iWidth + iScndDim ;
449      uiNextScanPos++;
450      iScndDim++;
451      iPrimDim--;
452    }
453  }
454  }
455  if( iWidth > 4 )
456  {
457    UInt uiNumBlkSide = iWidth >> 2;
458    UInt uiNumBlks    = uiNumBlkSide * uiNumBlkSide;
459    UInt log2Blk      = g_aucConvertToBit[ uiNumBlkSide ] + 1;
460
461    for( UInt uiBlk = 0; uiBlk < uiNumBlks; uiBlk++ )
462    {
463      uiNextScanPos   = 0;
464      UInt initBlkPos = g_auiSigLastScan[ SCAN_DIAG ][ log2Blk ][ uiBlk ];
465      if( iWidth == 32 )
466      {
467        initBlkPos = g_sigLastScanCG32x32[ uiBlk ];
468      }
469      UInt offsetY    = initBlkPos / uiNumBlkSide;
470      UInt offsetX    = initBlkPos - offsetY * uiNumBlkSide;
471      UInt offsetD    = 4 * ( offsetX + offsetY * iWidth );
472      UInt offsetScan = 16 * uiBlk;
473      for( UInt uiScanLine = 0; uiNextScanPos < 16; uiScanLine++ )
474      {
475        Int    iPrimDim  = Int( uiScanLine );
476        Int    iScndDim  = 0;
477        while( iPrimDim >= 4 )
478        {
479          iScndDim++;
480          iPrimDim--;
481        }
482        while( iPrimDim >= 0 && iScndDim < 4 )
483        {
484          pBuffD[ uiNextScanPos + offsetScan ] = iPrimDim * iWidth + iScndDim + offsetD;
485          uiNextScanPos++;
486          iScndDim++;
487          iPrimDim--;
488        }
489      }
490    }
491  }
492 
493  UInt uiCnt = 0;
494  if( iWidth > 2 )
495  {
496    UInt numBlkSide = iWidth >> 2;
497    for(Int blkY=0; blkY < numBlkSide; blkY++)
498    {
499      for(Int blkX=0; blkX < numBlkSide; blkX++)
500      {
501        UInt offset    = blkY * 4 * iWidth + blkX * 4;
502        for(Int y=0; y < 4; y++)
503        {
504          for(Int x=0; x < 4; x++)
505          {
506            pBuffH[uiCnt] = y*iWidth + x + offset;
507            uiCnt ++;
508          }
509        }
510      }
511    }
512
513    uiCnt = 0;
514    for(Int blkX=0; blkX < numBlkSide; blkX++)
515    {
516      for(Int blkY=0; blkY < numBlkSide; blkY++)
517      {
518        UInt offset    = blkY * 4 * iWidth + blkX * 4;
519        for(Int x=0; x < 4; x++)
520        {
521          for(Int y=0; y < 4; y++)
522          {
523            pBuffV[uiCnt] = y*iWidth + x + offset;
524            uiCnt ++;
525          }
526        }
527      }
528    }
529  }
530  else
531  {
532  for(Int iY=0; iY < iHeight; iY++)
533  {
534    for(Int iX=0; iX < iWidth; iX++)
535    {
536      pBuffH[uiCnt] = iY*iWidth + iX;
537      uiCnt ++;
538    }
539  }
540
541  uiCnt = 0;
542  for(Int iX=0; iX < iWidth; iX++)
543  {
544    for(Int iY=0; iY < iHeight; iY++)
545    {
546      pBuffV[uiCnt] = iY*iWidth + iX;
547      uiCnt ++;
548    }
549  }   
550  }
551}
552
553Int g_quantTSDefault4x4[16] =
554{
555  16,16,16,16,
556  16,16,16,16,
557  16,16,16,16,
558  16,16,16,16
559};
560
561Int g_quantIntraDefault8x8[64] =
562{
563  16,16,16,16,17,18,21,24,
564  16,16,16,16,17,19,22,25,
565  16,16,17,18,20,22,25,29,
566  16,16,18,21,24,27,31,36,
567  17,17,20,24,30,35,41,47,
568  18,19,22,27,35,44,54,65,
569  21,22,25,31,41,54,70,88,
570  24,25,29,36,47,65,88,115
571};
572
573Int g_quantInterDefault8x8[64] =
574{
575  16,16,16,16,17,18,20,24,
576  16,16,16,17,18,20,24,25,
577  16,16,17,18,20,24,25,28,
578  16,17,18,20,24,25,28,33,
579  17,18,20,24,25,28,33,41,
580  18,20,24,25,28,33,41,54,
581  20,24,25,28,33,41,54,71,
582  24,25,28,33,41,54,71,91
583};
584UInt g_scalingListSize   [4] = {16,64,256,1024}; 
585UInt g_scalingListSizeX  [4] = { 4, 8, 16,  32};
586UInt g_scalingListNum[SCALING_LIST_SIZE_NUM]={6,6,6,2};
587Int  g_eTTable[4] = {0,3,1,2};
588
589#if H_MV_ENC_DEC_TRAC
590#if ENC_DEC_TRACE
591Void stopAtPos( Int poc, Int layerId, Int cuPelX, Int cuPelY, Int cuWidth, Int cuHeight )
592{
593
594  if ( g_outputPos ) 
595  {
596    std::cout << "POC\t"        << poc
597              << "\tLayerId\t"  << layerId
598              << "\tCuPelX\t"   << cuPelX 
599              << "\tCuPelY\t"   << cuPelY
600              << "\tCuWidth\t"  << cuWidth
601              << "\tCuHeight\t" << cuHeight
602              << std::endl; 
603  }
604
605  Bool stopFlag = false; 
606  if ( g_stopAtPos && poc == 0 && layerId == 1 )
607  {
608    Bool stopAtCU = true; 
609    if ( stopAtCU )        // Stop at CU with specific size
610    {   
611      stopFlag = ( cuPelX  == 888 ) && ( cuPelY  == 248 ) && ( cuWidth == 8 ) && ( cuHeight == 8); 
612    }
613    else
614    {                     // Stop at specific position
615      Int xPos = 888; 
616      Int yPos = 248; 
617
618      Int cuPelXEnd = cuPelX + cuWidth  - 1; 
619      Int cuPelYEnd = cuPelY + cuHeight - 1; 
620
621      stopFlag = (cuPelX <= xPos ) && (cuPelXEnd >= xPos ) && (cuPelY <= yPos ) && (cuPelYEnd >= yPos ); 
622    }
623  }
624 
625  if ( stopFlag )
626  { // Set breakpoint here.
627    std::cout << "Stop position. Break point here." << std::endl; 
628  } 
629}
630
631Void writeToTraceFile( const Char* symbolName, Int val, Bool doIt )
632{
633  if ( ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) && doIt  ) 
634  {
635    if ( g_stopAtCounter == g_nSymbolCounter )
636    {
637      std::cout << "Break point here." << std::endl; 
638    }
639    fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
640    fprintf( g_hTrace, "%-50s       : %d\n", symbolName, val );     
641    fflush ( g_hTrace );
642    g_nSymbolCounter++; 
643  }
644}
645
646Void writeToTraceFile( const Char* symbolName, Bool doIt )
647{
648  if ( ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) && doIt  ) 
649  {
650    fprintf( g_hTrace, "%s", symbolName );   
651    fflush ( g_hTrace );
652    g_nSymbolCounter++; 
653  }
654}
655
656#endif
657#endif
658#if H_3D_DIM_DMM
659std::vector< std::vector<TComWedgelet>  > g_dmmWedgeLists;
660std::vector< std::vector<TComWedgeRef>  > g_dmmWedgeRefLists;
661std::vector< std::vector<TComWedgeNode> > g_dmmWedgeNodeLists;
662
663Void initWedgeLists( Bool initNodeList )
664{
665  if( !g_dmmWedgeLists.empty() ) return;
666
667  for( UInt ui = g_aucConvertToBit[DIM_MIN_SIZE]; ui < (g_aucConvertToBit[DIM_MAX_SIZE]); ui++ )
668  {
669    UInt uiWedgeBlockSize = ((UInt)DIM_MIN_SIZE)<<ui;
670    std::vector<TComWedgelet> acWedgeList;
671    std::vector<TComWedgeRef> acWedgeRefList;
672    createWedgeList( uiWedgeBlockSize, uiWedgeBlockSize, acWedgeList, acWedgeRefList, g_dmmWedgeResolution[ui] );
673    g_dmmWedgeLists.push_back( acWedgeList );
674    g_dmmWedgeRefLists.push_back( acWedgeRefList );
675
676    if( initNodeList )
677    {
678      // create WedgeNodeList
679      std::vector<TComWedgeNode> acWedgeNodeList;
680      for( UInt uiPos = 0; uiPos < acWedgeList.size(); uiPos++ )
681      {
682        if( acWedgeList[uiPos].getIsCoarse() )
683        {
684          TComWedgeNode cWedgeNode;
685          cWedgeNode.setPatternIdx( uiPos );
686
687          UInt uiRefPos = 0;
688          for( Int iOffS = -1; iOffS <= 1; iOffS++ )
689          {
690            for( Int iOffE = -1; iOffE <= 1; iOffE++ )
691            {
692              if( iOffS == 0 && iOffE == 0 ) { continue; }
693
694              Int iSx = (Int)acWedgeList[uiPos].getStartX();
695              Int iSy = (Int)acWedgeList[uiPos].getStartY();
696              Int iEx = (Int)acWedgeList[uiPos].getEndX();
697              Int iEy = (Int)acWedgeList[uiPos].getEndY();
698
699              switch( acWedgeList[uiPos].getOri() )
700              {
701              case( 0 ): { iSx += iOffS; iEy += iOffE; } break;
702              case( 1 ): { iSy += iOffS; iEx -= iOffE; } break;
703              case( 2 ): { iSx -= iOffS; iEy -= iOffE; } break;
704              case( 3 ): { iSy -= iOffS; iEx += iOffE; } break;
705              case( 4 ): { iSx += iOffS; iEx += iOffE; } break;
706              case( 5 ): { iSy += iOffS; iEy += iOffE; } break;
707              default: assert( 0 );
708              }
709
710              for( UInt k = 0; k < acWedgeRefList.size(); k++ )
711              {
712                if( iSx == (Int)acWedgeRefList[k].getStartX() && 
713                  iSy == (Int)acWedgeRefList[k].getStartY() && 
714                  iEx == (Int)acWedgeRefList[k].getEndX()   && 
715                  iEy == (Int)acWedgeRefList[k].getEndY()      )
716                {
717                  if( acWedgeRefList[k].getRefIdx() != cWedgeNode.getPatternIdx() )
718                  {
719                    Bool bNew = true;
720                    for( UInt m = 0; m < uiRefPos; m++ ) { if( acWedgeRefList[k].getRefIdx() == cWedgeNode.getRefineIdx( m ) ) { bNew = false; break; } }
721
722                    if( bNew ) 
723                    {
724                      cWedgeNode.setRefineIdx( acWedgeRefList[k].getRefIdx(), uiRefPos );
725                      uiRefPos++;
726                      break;
727                    }
728                  }
729                }
730              }
731            }
732          }
733          acWedgeNodeList.push_back( cWedgeNode );
734        }
735      }
736      g_dmmWedgeNodeLists.push_back( acWedgeNodeList );
737    }
738  }
739}
740
741Void createWedgeList( UInt uiWidth, UInt uiHeight, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList, WedgeResolution eWedgeRes )
742{
743  assert( uiWidth == uiHeight );
744
745  UChar    uhStartX = 0,    uhStartY = 0,    uhEndX = 0,    uhEndY = 0;
746  Int   iStepStartX = 0, iStepStartY = 0, iStepEndX = 0, iStepEndY = 0;
747
748  UInt uiBlockSize = 0;
749  switch( eWedgeRes )
750  {
751  case(   FULL_PEL ): { uiBlockSize =  uiWidth;     break; }
752  case(   HALF_PEL ): { uiBlockSize = (uiWidth<<1); break; }
753  }
754
755  TComWedgelet cTempWedgelet( uiWidth, uiHeight );
756  for( UInt uiOri = 0; uiOri < 6; uiOri++ )
757  {
758    // init the edge line parameters for each of the 6 wedgelet types
759    switch( uiOri )
760    {
761    case( 0 ): {  uhStartX = 0;               uhStartY = 0;               uhEndX = 0;               uhEndY = 0;               iStepStartX = +1; iStepStartY =  0; iStepEndX =  0; iStepEndY = +1; break; }
762    case( 1 ): {  uhStartX = (uiBlockSize-1); uhStartY = 0;               uhEndX = (uiBlockSize-1); uhEndY = 0;               iStepStartX =  0; iStepStartY = +1; iStepEndX = -1; iStepEndY =  0; break; }
763    case( 2 ): {  uhStartX = (uiBlockSize-1); uhStartY = (uiBlockSize-1); uhEndX = (uiBlockSize-1); uhEndY = (uiBlockSize-1); iStepStartX = -1; iStepStartY =  0; iStepEndX =  0; iStepEndY = -1; break; }
764    case( 3 ): {  uhStartX = 0;               uhStartY = (uiBlockSize-1); uhEndX = 0;               uhEndY = (uiBlockSize-1); iStepStartX =  0; iStepStartY = -1; iStepEndX = +1; iStepEndY =  0; break; }
765    case( 4 ): {  uhStartX = 0;               uhStartY = 0;               uhEndX = 0;               uhEndY = (uiBlockSize-1); iStepStartX = +1; iStepStartY =  0; iStepEndX = +1; iStepEndY =  0; break; }
766    case( 5 ): {  uhStartX = (uiBlockSize-1); uhStartY = 0;               uhEndX = 0;               uhEndY = 0;               iStepStartX =  0; iStepStartY = +1; iStepEndX =  0; iStepEndY = +1; break; }
767    }
768
769#if MTK_DMM_SIM_J0035
770    for( Int iK = 0; iK < uiBlockSize; iK += (uiWidth>=16 ?2:1))
771    {
772      for( Int iL = 0; iL < uiBlockSize; iL += ((uiWidth>=16 && uiOri<4)?2:1) )
773      {
774        cTempWedgelet.setWedgelet( uhStartX + (iK*iStepStartX) , uhStartY + (iK*iStepStartY), uhEndX + (iL*iStepEndX), uhEndY + (iL*iStepEndY), (UChar)uiOri, eWedgeRes, ((iL%2)==0 && (iK%2)==0) );
775        addWedgeletToList( cTempWedgelet, racWedgeList, racWedgeRefList );
776      }
777    }
778#else
779    for( Int iK = 0; iK < uiBlockSize; iK++ )
780    {
781      for( Int iL = 0; iL < uiBlockSize; iL++ )
782      {
783        cTempWedgelet.setWedgelet( uhStartX + (iK*iStepStartX) , uhStartY + (iK*iStepStartY), uhEndX + (iL*iStepEndX), uhEndY + (iL*iStepEndY), (UChar)uiOri, eWedgeRes, ((iL%2)==0 && (iK%2)==0) );
784        addWedgeletToList( cTempWedgelet, racWedgeList, racWedgeRefList );
785      }
786    }
787#endif
788  }
789
790
791}
792
793Void addWedgeletToList( TComWedgelet cWedgelet, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList )
794{
795  Bool bValid = cWedgelet.checkNotPlain();
796  if( bValid )
797  {
798    for( UInt uiPos = 0; uiPos < racWedgeList.size(); uiPos++ )
799    {
800      if( cWedgelet.checkIdentical( racWedgeList[uiPos].getPattern() ) )
801      {
802        TComWedgeRef cWedgeRef;
803        cWedgeRef.setWedgeRef( cWedgelet.getStartX(), cWedgelet.getStartY(), cWedgelet.getEndX(), cWedgelet.getEndY(), uiPos );
804        racWedgeRefList.push_back( cWedgeRef );
805        bValid = false;
806        return;
807      }
808    }
809  }
810  if( bValid )
811  {
812    for( UInt uiPos = 0; uiPos < racWedgeList.size(); uiPos++ )
813    {
814      if( cWedgelet.checkInvIdentical( racWedgeList[uiPos].getPattern() ) )
815      {
816        TComWedgeRef cWedgeRef;
817        cWedgeRef.setWedgeRef( cWedgelet.getStartX(), cWedgelet.getStartY(), cWedgelet.getEndX(), cWedgelet.getEndY(), uiPos );
818        racWedgeRefList.push_back( cWedgeRef );
819        bValid = false;
820        return;
821      }
822    }
823  }
824  if( bValid )
825  {
826    cWedgelet.findClosestAngle();
827    racWedgeList.push_back( cWedgelet );
828    TComWedgeRef cWedgeRef;
829    cWedgeRef.setWedgeRef( cWedgelet.getStartX(), cWedgelet.getStartY(), cWedgelet.getEndX(), cWedgelet.getEndY(), (UInt)(racWedgeList.size()-1) );
830    racWedgeRefList.push_back( cWedgeRef );
831  }
832}
833#endif //H_3D_DIM_DMM
834
835//! \}
Note: See TracBrowser for help on using the repository browser.