source: 3DVCSoftware/branches/HTM-14.0-dev0/source/Lib/TLibCommon/TComRom.cpp @ 1187

Last change on this file since 1187 was 1187, checked in by tech, 9 years ago

Clean up Part 3.

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