source: 3DVCSoftware/branches/HTM-15.1-MV-draft-4/source/Lib/TLibCommon/TComRom.cpp @ 1389

Last change on this file since 1389 was 1325, checked in by tech, 10 years ago

Removed 3D-HEVC.

  • Property svn:eol-style set to native
File size: 32.9 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/** \file     TComRom.cpp
34    \brief    global variables & functions
35*/
36#include "TComRom.h"
37#include <memory.h>
38#include <stdlib.h>
39#include <stdio.h>
40#include <iomanip>
41#include <assert.h>
42#include "TComDataCU.h"
43#include "Debug.h"
44// ====================================================================================================================
45// Initialize / destroy functions
46// ====================================================================================================================
47//! \ingroup TLibCommon
48//! \{
49const Char* nalUnitTypeToString(NalUnitType type)
50{
51  switch (type)
52  {
53  case NAL_UNIT_CODED_SLICE_TRAIL_R:    return "TRAIL_R";
54  case NAL_UNIT_CODED_SLICE_TRAIL_N:    return "TRAIL_N";
55  case NAL_UNIT_CODED_SLICE_TSA_R:      return "TSA_R";
56  case NAL_UNIT_CODED_SLICE_TSA_N:      return "TSA_N";
57  case NAL_UNIT_CODED_SLICE_STSA_R:     return "STSA_R";
58  case NAL_UNIT_CODED_SLICE_STSA_N:     return "STSA_N";
59  case NAL_UNIT_CODED_SLICE_BLA_W_LP:   return "BLA_W_LP";
60  case NAL_UNIT_CODED_SLICE_BLA_W_RADL: return "BLA_W_RADL";
61  case NAL_UNIT_CODED_SLICE_BLA_N_LP:   return "BLA_N_LP";
62  case NAL_UNIT_CODED_SLICE_IDR_W_RADL: return "IDR_W_RADL";
63  case NAL_UNIT_CODED_SLICE_IDR_N_LP:   return "IDR_N_LP";
64  case NAL_UNIT_CODED_SLICE_CRA:        return "CRA";
65  case NAL_UNIT_CODED_SLICE_RADL_R:     return "RADL_R";
66  case NAL_UNIT_CODED_SLICE_RADL_N:     return "RADL_N";
67  case NAL_UNIT_CODED_SLICE_RASL_R:     return "RASL_R";
68  case NAL_UNIT_CODED_SLICE_RASL_N:     return "RASL_N";
69  case NAL_UNIT_VPS:                    return "VPS";
70  case NAL_UNIT_SPS:                    return "SPS";
71  case NAL_UNIT_PPS:                    return "PPS";
72  case NAL_UNIT_ACCESS_UNIT_DELIMITER:  return "AUD";
73  case NAL_UNIT_EOS:                    return "EOS";
74  case NAL_UNIT_EOB:                    return "EOB";
75  case NAL_UNIT_FILLER_DATA:            return "FILLER";
76  case NAL_UNIT_PREFIX_SEI:             return "Prefix SEI";
77  case NAL_UNIT_SUFFIX_SEI:             return "Suffix SEI";
78  default:                              return "UNK";
79  }
80}
81class ScanGenerator
82{
83private:
84  UInt m_line, m_column;
85  const UInt m_blockWidth, m_blockHeight;
86  const UInt m_stride;
87  const COEFF_SCAN_TYPE m_scanType;
88public:
89  ScanGenerator(UInt blockWidth, UInt blockHeight, UInt stride, COEFF_SCAN_TYPE scanType)
90    : m_line(0), m_column(0), m_blockWidth(blockWidth), m_blockHeight(blockHeight), m_stride(stride), m_scanType(scanType)
91  { }
92  UInt GetCurrentX() const { return m_column; }
93  UInt GetCurrentY() const { return m_line; }
94  UInt GetNextIndex(UInt blockOffsetX, UInt blockOffsetY)
95  {
96    Int rtn=((m_line + blockOffsetY) * m_stride) + m_column + blockOffsetX;
97    //advance line and column to the next position
98    switch (m_scanType)
99    {
100      //------------------------------------------------
101      case SCAN_DIAG:
102        {
103          if ((m_column == (m_blockWidth - 1)) || (m_line == 0)) //if we reach the end of a rank, go diagonally down to the next one
104          {
105            m_line   += m_column + 1;
106            m_column  = 0;
107            if (m_line >= m_blockHeight) //if that takes us outside the block, adjust so that we are back on the bottom row
108            {
109              m_column += m_line - (m_blockHeight - 1);
110              m_line    = m_blockHeight - 1;
111            }
112          }
113          else
114          {
115            m_column++;
116            m_line--;
117          }
118        }
119        break;
120      //------------------------------------------------
121      case SCAN_HOR:
122        {
123          if (m_column == (m_blockWidth - 1))
124          {
125            m_line++;
126            m_column = 0;
127          }
128          else
129          {
130            m_column++;
131          }
132        }
133        break;
134      //------------------------------------------------
135      case SCAN_VER:
136        {
137          if (m_line == (m_blockHeight - 1))
138          {
139            m_column++;
140            m_line = 0;
141          }
142          else
143          {
144            m_line++;
145          }
146        }
147        break;
148      //------------------------------------------------
149      default:
150        {
151          std::cerr << "ERROR: Unknown scan type \"" << m_scanType << "\"in ScanGenerator::GetNextIndex" << std::endl;
152          exit(1);
153        }
154        break;
155    }
156    return rtn;
157  }
158};
159// initialize ROM variables
160Void initROM()
161{
162  Int i, c;
163  // g_aucConvertToBit[ x ]: log2(x/4), if x=4 -> 0, x=8 -> 1, x=16 -> 2, ...
164  ::memset( g_aucConvertToBit,   -1, sizeof( g_aucConvertToBit ) );
165  c=0;
166  for ( i=4; i<=MAX_CU_SIZE; i*=2 )
167  {
168    g_aucConvertToBit[ i ] = c;
169    c++;
170  }
171  // initialise scan orders
172  for(UInt log2BlockHeight = 0; log2BlockHeight < MAX_CU_DEPTH; log2BlockHeight++)
173  {
174    for(UInt log2BlockWidth = 0; log2BlockWidth < MAX_CU_DEPTH; log2BlockWidth++)
175    {
176      const UInt blockWidth  = 1 << log2BlockWidth;
177      const UInt blockHeight = 1 << log2BlockHeight;
178      const UInt totalValues = blockWidth * blockHeight;
179      //--------------------------------------------------------------------------------------------------
180      //non-grouped scan orders
181      for (UInt scanTypeIndex = 0; scanTypeIndex < SCAN_NUMBER_OF_TYPES; scanTypeIndex++)
182      {
183        const COEFF_SCAN_TYPE scanType = COEFF_SCAN_TYPE(scanTypeIndex);
184        g_scanOrder[SCAN_UNGROUPED][scanType][log2BlockWidth][log2BlockHeight] = new UInt[totalValues];
185        ScanGenerator fullBlockScan(blockWidth, blockHeight, blockWidth, scanType);
186        for (UInt scanPosition = 0; scanPosition < totalValues; scanPosition++)
187        {
188          g_scanOrder[SCAN_UNGROUPED][scanType][log2BlockWidth][log2BlockHeight][scanPosition] = fullBlockScan.GetNextIndex(0, 0);
189        }
190      }
191      //--------------------------------------------------------------------------------------------------
192      //grouped scan orders
193      const UInt  groupWidth           = 1           << MLS_CG_LOG2_WIDTH;
194      const UInt  groupHeight          = 1           << MLS_CG_LOG2_HEIGHT;
195      const UInt  widthInGroups        = blockWidth  >> MLS_CG_LOG2_WIDTH;
196      const UInt  heightInGroups       = blockHeight >> MLS_CG_LOG2_HEIGHT;
197      const UInt  groupSize            = groupWidth    * groupHeight;
198      const UInt  totalGroups          = widthInGroups * heightInGroups;
199      for (UInt scanTypeIndex = 0; scanTypeIndex < SCAN_NUMBER_OF_TYPES; scanTypeIndex++)
200      {
201        const COEFF_SCAN_TYPE scanType = COEFF_SCAN_TYPE(scanTypeIndex);
202        g_scanOrder[SCAN_GROUPED_4x4][scanType][log2BlockWidth][log2BlockHeight] = new UInt[totalValues];
203        ScanGenerator fullBlockScan(widthInGroups, heightInGroups, groupWidth, scanType);
204        for (UInt groupIndex = 0; groupIndex < totalGroups; groupIndex++)
205        {
206          const UInt groupPositionY  = fullBlockScan.GetCurrentY();
207          const UInt groupPositionX  = fullBlockScan.GetCurrentX();
208          const UInt groupOffsetX    = groupPositionX * groupWidth;
209          const UInt groupOffsetY    = groupPositionY * groupHeight;
210          const UInt groupOffsetScan = groupIndex     * groupSize;
211          ScanGenerator groupScan(groupWidth, groupHeight, blockWidth, scanType);
212          for (UInt scanPosition = 0; scanPosition < groupSize; scanPosition++)
213          {
214            g_scanOrder[SCAN_GROUPED_4x4][scanType][log2BlockWidth][log2BlockHeight][groupOffsetScan + scanPosition] = groupScan.GetNextIndex(groupOffsetX, groupOffsetY);
215          }
216          fullBlockScan.GetNextIndex(0,0);
217        }
218      }
219      //--------------------------------------------------------------------------------------------------
220    }
221  }
222#if NH_MV
223#if H_MV_HLS_PTL_LIMITS
224 g_generalTierAndLevelLimits[ Level::LEVEL1   ] = TComGeneralTierAndLevelLimits(    36864,     350,  MIN_INT,   16,   1,   1 );
225 g_generalTierAndLevelLimits[ Level::LEVEL2   ] = TComGeneralTierAndLevelLimits(   122880,    1500,  MIN_INT,   16,   1,   1 );
226 g_generalTierAndLevelLimits[ Level::LEVEL2_1 ] = TComGeneralTierAndLevelLimits(   245760,    3000,  MIN_INT,   20,   1,   1 );
227 g_generalTierAndLevelLimits[ Level::LEVEL3   ] = TComGeneralTierAndLevelLimits(   552960,    6000,  MIN_INT,   30,   2,   2 );
228 g_generalTierAndLevelLimits[ Level::LEVEL3_1 ] = TComGeneralTierAndLevelLimits(   983040,   10000,  MIN_INT,   40,   3,   3 );
229 g_generalTierAndLevelLimits[ Level::LEVEL4   ] = TComGeneralTierAndLevelLimits(  2228224,   12000,    30000,   75,   5,   5 );
230 g_generalTierAndLevelLimits[ Level::LEVEL4_1 ] = TComGeneralTierAndLevelLimits(  2228224,   20000,    50000,   75,   5,   5 );
231 g_generalTierAndLevelLimits[ Level::LEVEL5   ] = TComGeneralTierAndLevelLimits(  8912896,   25000,   100000,  200,  11,  10 );
232 g_generalTierAndLevelLimits[ Level::LEVEL5_1 ] = TComGeneralTierAndLevelLimits(  8912896,   40000,   160000,  200,  11,  10 );
233 g_generalTierAndLevelLimits[ Level::LEVEL5_2 ] = TComGeneralTierAndLevelLimits(  8912896,   60000,   240000,  200,  11,  10 );
234 g_generalTierAndLevelLimits[ Level::LEVEL6   ] = TComGeneralTierAndLevelLimits( 35651584,   60000,   240000,  600,  22,  20 );
235 g_generalTierAndLevelLimits[ Level::LEVEL6_1 ] = TComGeneralTierAndLevelLimits( 35651584,  120000,   480000,  600,  22,  20 );
236 g_generalTierAndLevelLimits[ Level::LEVEL6_2 ] = TComGeneralTierAndLevelLimits( 35651584,  240000,   800000,  600,  22,  20 );
237#endif
238#endif
239}
240Void destroyROM()
241{
242  for(UInt groupTypeIndex = 0; groupTypeIndex < SCAN_NUMBER_OF_GROUP_TYPES; groupTypeIndex++)
243  {
244    for (UInt scanOrderIndex = 0; scanOrderIndex < SCAN_NUMBER_OF_TYPES; scanOrderIndex++)
245    {
246      for (UInt log2BlockWidth = 0; log2BlockWidth < MAX_CU_DEPTH; log2BlockWidth++)
247      {
248        for (UInt log2BlockHeight = 0; log2BlockHeight < MAX_CU_DEPTH; log2BlockHeight++)
249        {
250          delete [] g_scanOrder[groupTypeIndex][scanOrderIndex][log2BlockWidth][log2BlockHeight];
251        }
252      }
253    }
254  }
255}
256// ====================================================================================================================
257// Data structure related table & variable
258// ====================================================================================================================
259UInt g_auiZscanToRaster [ MAX_NUM_PART_IDXS_IN_CTU_WIDTH*MAX_NUM_PART_IDXS_IN_CTU_WIDTH ] = { 0, };
260UInt g_auiRasterToZscan [ MAX_NUM_PART_IDXS_IN_CTU_WIDTH*MAX_NUM_PART_IDXS_IN_CTU_WIDTH ] = { 0, };
261UInt g_auiRasterToPelX  [ MAX_NUM_PART_IDXS_IN_CTU_WIDTH*MAX_NUM_PART_IDXS_IN_CTU_WIDTH ] = { 0, };
262UInt g_auiRasterToPelY  [ MAX_NUM_PART_IDXS_IN_CTU_WIDTH*MAX_NUM_PART_IDXS_IN_CTU_WIDTH ] = { 0, };
263const UInt g_auiPUOffset[NUMBER_OF_PART_SIZES] = { 0, 8, 4, 4, 2, 10, 1, 5};
264Void initZscanToRaster ( Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt*& rpuiCurrIdx )
265{
266  Int iStride = 1 << ( iMaxDepth - 1 );
267  if ( iDepth == iMaxDepth )
268  {
269    rpuiCurrIdx[0] = uiStartVal;
270    rpuiCurrIdx++;
271  }
272  else
273  {
274    Int iStep = iStride >> iDepth;
275    initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal,                     rpuiCurrIdx );
276    initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep,               rpuiCurrIdx );
277    initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep*iStride,       rpuiCurrIdx );
278    initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep*iStride+iStep, rpuiCurrIdx );
279  }
280}
281Void initRasterToZscan ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth )
282{
283  UInt  uiMinCUWidth  = uiMaxCUWidth  >> ( uiMaxDepth - 1 );
284  UInt  uiMinCUHeight = uiMaxCUHeight >> ( uiMaxDepth - 1 );
285  UInt  uiNumPartInWidth  = (UInt)uiMaxCUWidth  / uiMinCUWidth;
286  UInt  uiNumPartInHeight = (UInt)uiMaxCUHeight / uiMinCUHeight;
287  for ( UInt i = 0; i < uiNumPartInWidth*uiNumPartInHeight; i++ )
288  {
289    g_auiRasterToZscan[ g_auiZscanToRaster[i] ] = i;
290  }
291}
292Void initRasterToPelXY ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth )
293{
294  UInt    i;
295  UInt* uiTempX = &g_auiRasterToPelX[0];
296  UInt* uiTempY = &g_auiRasterToPelY[0];
297  UInt  uiMinCUWidth  = uiMaxCUWidth  >> ( uiMaxDepth - 1 );
298  UInt  uiMinCUHeight = uiMaxCUHeight >> ( uiMaxDepth - 1 );
299  UInt  uiNumPartInWidth  = uiMaxCUWidth  / uiMinCUWidth;
300  UInt  uiNumPartInHeight = uiMaxCUHeight / uiMinCUHeight;
301  uiTempX[0] = 0; uiTempX++;
302  for ( i = 1; i < uiNumPartInWidth; i++ )
303  {
304    uiTempX[0] = uiTempX[-1] + uiMinCUWidth; uiTempX++;
305  }
306  for ( i = 1; i < uiNumPartInHeight; i++ )
307  {
308    memcpy(uiTempX, uiTempX-uiNumPartInWidth, sizeof(UInt)*uiNumPartInWidth);
309    uiTempX += uiNumPartInWidth;
310  }
311  for ( i = 1; i < uiNumPartInWidth*uiNumPartInHeight; i++ )
312  {
313    uiTempY[i] = ( i / uiNumPartInWidth ) * uiMinCUWidth;
314  }
315}
316const Int g_quantScales[SCALING_LIST_REM_NUM] =
317{
318  26214,23302,20560,18396,16384,14564
319};
320const Int g_invQuantScales[SCALING_LIST_REM_NUM] =
321{
322  40,45,51,57,64,72
323};
324//--------------------------------------------------------------------------------------------------
325//structures
326#define DEFINE_DST4x4_MATRIX(a,b,c,d) \
327{ \
328  {  a,  b,  c,  d }, \
329  {  c,  c,  0, -c }, \
330  {  d, -a, -c,  b }, \
331  {  b, -d,  c, -a }, \
332}
333#define DEFINE_DCT4x4_MATRIX(a,b,c) \
334{ \
335  { a,  a,  a,  a}, \
336  { b,  c, -c, -b}, \
337  { a, -a, -a,  a}, \
338  { c, -b,  b, -c}  \
339}
340#define DEFINE_DCT8x8_MATRIX(a,b,c,d,e,f,g) \
341{ \
342  { a,  a,  a,  a,  a,  a,  a,  a}, \
343  { d,  e,  f,  g, -g, -f, -e, -d}, \
344  { b,  c, -c, -b, -b, -c,  c,  b}, \
345  { e, -g, -d, -f,  f,  d,  g, -e}, \
346  { a, -a, -a,  a,  a, -a, -a,  a}, \
347  { f, -d,  g,  e, -e, -g,  d, -f}, \
348  { c, -b,  b, -c, -c,  b, -b,  c}, \
349  { g, -f,  e, -d,  d, -e,  f, -g}  \
350}
351#define DEFINE_DCT16x16_MATRIX(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) \
352{ \
353  { a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a}, \
354  { h,  i,  j,  k,  l,  m,  n,  o, -o, -n, -m, -l, -k, -j, -i, -h}, \
355  { d,  e,  f,  g, -g, -f, -e, -d, -d, -e, -f, -g,  g,  f,  e,  d}, \
356  { i,  l,  o, -m, -j, -h, -k, -n,  n,  k,  h,  j,  m, -o, -l, -i}, \
357  { b,  c, -c, -b, -b, -c,  c,  b,  b,  c, -c, -b, -b, -c,  c,  b}, \
358  { j,  o, -k, -i, -n,  l,  h,  m, -m, -h, -l,  n,  i,  k, -o, -j}, \
359  { e, -g, -d, -f,  f,  d,  g, -e, -e,  g,  d,  f, -f, -d, -g,  e}, \
360  { k, -m, -i,  o,  h,  n, -j, -l,  l,  j, -n, -h, -o,  i,  m, -k}, \
361  { a, -a, -a,  a,  a, -a, -a,  a,  a, -a, -a,  a,  a, -a, -a,  a}, \
362  { l, -j, -n,  h, -o, -i,  m,  k, -k, -m,  i,  o, -h,  n,  j, -l}, \
363  { f, -d,  g,  e, -e, -g,  d, -f, -f,  d, -g, -e,  e,  g, -d,  f}, \
364  { m, -h,  l,  n, -i,  k,  o, -j,  j, -o, -k,  i, -n, -l,  h, -m}, \
365  { c, -b,  b, -c, -c,  b, -b,  c,  c, -b,  b, -c, -c,  b, -b,  c}, \
366  { n, -k,  h, -j,  m,  o, -l,  i, -i,  l, -o, -m,  j, -h,  k, -n}, \
367  { g, -f,  e, -d,  d, -e,  f, -g, -g,  f, -e,  d, -d,  e, -f,  g}, \
368  { o, -n,  m, -l,  k, -j,  i, -h,  h, -i,  j, -k,  l, -m,  n, -o}  \
369}
370#define DEFINE_DCT32x32_MATRIX(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E) \
371{ \
372  { a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a,  a}, \
373  { p,  q,  r,  s,  t,  u,  v,  w,  x,  y,  z,  A,  B,  C,  D,  E, -E, -D, -C, -B, -A, -z, -y, -x, -w, -v, -u, -t, -s, -r, -q, -p}, \
374  { h,  i,  j,  k,  l,  m,  n,  o, -o, -n, -m, -l, -k, -j, -i, -h, -h, -i, -j, -k, -l, -m, -n, -o,  o,  n,  m,  l,  k,  j,  i,  h}, \
375  { q,  t,  w,  z,  C, -E, -B, -y, -v, -s, -p, -r, -u, -x, -A, -D,  D,  A,  x,  u,  r,  p,  s,  v,  y,  B,  E, -C, -z, -w, -t, -q}, \
376  { d,  e,  f,  g, -g, -f, -e, -d, -d, -e, -f, -g,  g,  f,  e,  d,  d,  e,  f,  g, -g, -f, -e, -d, -d, -e, -f, -g,  g,  f,  e,  d}, \
377  { r,  w,  B, -D, -y, -t, -p, -u, -z, -E,  A,  v,  q,  s,  x,  C, -C, -x, -s, -q, -v, -A,  E,  z,  u,  p,  t,  y,  D, -B, -w, -r}, \
378  { i,  l,  o, -m, -j, -h, -k, -n,  n,  k,  h,  j,  m, -o, -l, -i, -i, -l, -o,  m,  j,  h,  k,  n, -n, -k, -h, -j, -m,  o,  l,  i}, \
379  { s,  z, -D, -w, -p, -v, -C,  A,  t,  r,  y, -E, -x, -q, -u, -B,  B,  u,  q,  x,  E, -y, -r, -t, -A,  C,  v,  p,  w,  D, -z, -s}, \
380  { b,  c, -c, -b, -b, -c,  c,  b,  b,  c, -c, -b, -b, -c,  c,  b,  b,  c, -c, -b, -b, -c,  c,  b,  b,  c, -c, -b, -b, -c,  c,  b}, \
381  { t,  C, -y, -p, -x,  D,  u,  s,  B, -z, -q, -w,  E,  v,  r,  A, -A, -r, -v, -E,  w,  q,  z, -B, -s, -u, -D,  x,  p,  y, -C, -t}, \
382  { j,  o, -k, -i, -n,  l,  h,  m, -m, -h, -l,  n,  i,  k, -o, -j, -j, -o,  k,  i,  n, -l, -h, -m,  m,  h,  l, -n, -i, -k,  o,  j}, \
383  { u, -E, -t, -v,  D,  s,  w, -C, -r, -x,  B,  q,  y, -A, -p, -z,  z,  p,  A, -y, -q, -B,  x,  r,  C, -w, -s, -D,  v,  t,  E, -u}, \
384  { e, -g, -d, -f,  f,  d,  g, -e, -e,  g,  d,  f, -f, -d, -g,  e,  e, -g, -d, -f,  f,  d,  g, -e, -e,  g,  d,  f, -f, -d, -g,  e}, \
385  { v, -B, -p, -C,  u,  w, -A, -q, -D,  t,  x, -z, -r, -E,  s,  y, -y, -s,  E,  r,  z, -x, -t,  D,  q,  A, -w, -u,  C,  p,  B, -v}, \
386  { k, -m, -i,  o,  h,  n, -j, -l,  l,  j, -n, -h, -o,  i,  m, -k, -k,  m,  i, -o, -h, -n,  j,  l, -l, -j,  n,  h,  o, -i, -m,  k}, \
387  { w, -y, -u,  A,  s, -C, -q,  E,  p,  D, -r, -B,  t,  z, -v, -x,  x,  v, -z, -t,  B,  r, -D, -p, -E,  q,  C, -s, -A,  u,  y, -w}, \
388  { a, -a, -a,  a,  a, -a, -a,  a,  a, -a, -a,  a,  a, -a, -a,  a,  a, -a, -a,  a,  a, -a, -a,  a,  a, -a, -a,  a,  a, -a, -a,  a}, \
389  { x, -v, -z,  t,  B, -r, -D,  p, -E, -q,  C,  s, -A, -u,  y,  w, -w, -y,  u,  A, -s, -C,  q,  E, -p,  D,  r, -B, -t,  z,  v, -x}, \
390  { l, -j, -n,  h, -o, -i,  m,  k, -k, -m,  i,  o, -h,  n,  j, -l, -l,  j,  n, -h,  o,  i, -m, -k,  k,  m, -i, -o,  h, -n, -j,  l}, \
391  { y, -s, -E,  r, -z, -x,  t,  D, -q,  A,  w, -u, -C,  p, -B, -v,  v,  B, -p,  C,  u, -w, -A,  q, -D, -t,  x,  z, -r,  E,  s, -y}, \
392  { f, -d,  g,  e, -e, -g,  d, -f, -f,  d, -g, -e,  e,  g, -d,  f,  f, -d,  g,  e, -e, -g,  d, -f, -f,  d, -g, -e,  e,  g, -d,  f}, \
393  { z, -p,  A,  y, -q,  B,  x, -r,  C,  w, -s,  D,  v, -t,  E,  u, -u, -E,  t, -v, -D,  s, -w, -C,  r, -x, -B,  q, -y, -A,  p, -z}, \
394  { m, -h,  l,  n, -i,  k,  o, -j,  j, -o, -k,  i, -n, -l,  h, -m, -m,  h, -l, -n,  i, -k, -o,  j, -j,  o,  k, -i,  n,  l, -h,  m}, \
395  { A, -r,  v, -E, -w,  q, -z, -B,  s, -u,  D,  x, -p,  y,  C, -t,  t, -C, -y,  p, -x, -D,  u, -s,  B,  z, -q,  w,  E, -v,  r, -A}, \
396  { c, -b,  b, -c, -c,  b, -b,  c,  c, -b,  b, -c, -c,  b, -b,  c,  c, -b,  b, -c, -c,  b, -b,  c,  c, -b,  b, -c, -c,  b, -b,  c}, \
397  { B, -u,  q, -x,  E,  y, -r,  t, -A, -C,  v, -p,  w, -D, -z,  s, -s,  z,  D, -w,  p, -v,  C,  A, -t,  r, -y, -E,  x, -q,  u, -B}, \
398  { n, -k,  h, -j,  m,  o, -l,  i, -i,  l, -o, -m,  j, -h,  k, -n, -n,  k, -h,  j, -m, -o,  l, -i,  i, -l,  o,  m, -j,  h, -k,  n}, \
399  { C, -x,  s, -q,  v, -A, -E,  z, -u,  p, -t,  y, -D, -B,  w, -r,  r, -w,  B,  D, -y,  t, -p,  u, -z,  E,  A, -v,  q, -s,  x, -C}, \
400  { g, -f,  e, -d,  d, -e,  f, -g, -g,  f, -e,  d, -d,  e, -f,  g,  g, -f,  e, -d,  d, -e,  f, -g, -g,  f, -e,  d, -d,  e, -f,  g}, \
401  { D, -A,  x, -u,  r, -p,  s, -v,  y, -B,  E,  C, -z,  w, -t,  q, -q,  t, -w,  z, -C, -E,  B, -y,  v, -s,  p, -r,  u, -x,  A, -D}, \
402  { o, -n,  m, -l,  k, -j,  i, -h,  h, -i,  j, -k,  l, -m,  n, -o, -o,  n, -m,  l, -k,  j, -i,  h, -h,  i, -j,  k, -l,  m, -n,  o}, \
403  { E, -D,  C, -B,  A, -z,  y, -x,  w, -v,  u, -t,  s, -r,  q, -p,  p, -q,  r, -s,  t, -u,  v, -w,  x, -y,  z, -A,  B, -C,  D, -E}  \
404}
405//--------------------------------------------------------------------------------------------------
406//coefficients
407#if RExt__HIGH_PRECISION_FORWARD_TRANSFORM
408const TMatrixCoeff g_aiT4 [TRANSFORM_NUMBER_OF_DIRECTIONS][4][4]   =
409{
410  DEFINE_DCT4x4_MATRIX  (16384, 21266,  9224),
411  DEFINE_DCT4x4_MATRIX  (   64,    83,    36)
412};
413const TMatrixCoeff g_aiT8 [TRANSFORM_NUMBER_OF_DIRECTIONS][8][8]   =
414{
415  DEFINE_DCT8x8_MATRIX  (16384, 21266,  9224, 22813, 19244, 12769,  4563),
416  DEFINE_DCT8x8_MATRIX  (   64,    83,    36,    89,    75,    50,    18)
417};
418const TMatrixCoeff g_aiT16[TRANSFORM_NUMBER_OF_DIRECTIONS][16][16] =
419{
420  DEFINE_DCT16x16_MATRIX(16384, 21266,  9224, 22813, 19244, 12769,  4563, 23120, 22063, 20450, 17972, 14642, 11109,  6446,  2316),
421  DEFINE_DCT16x16_MATRIX(   64,    83,    36,    89,    75,    50,    18,    90,    87,    80,    70,    57,    43,    25,     9)
422};
423const TMatrixCoeff g_aiT32[TRANSFORM_NUMBER_OF_DIRECTIONS][32][32] =
424{
425  DEFINE_DCT32x32_MATRIX(16384, 21266,  9224, 22813, 19244, 12769,  4563, 23120, 22063, 20450, 17972, 14642, 11109,  6446,  2316, 23106, 22852, 22445, 21848, 20995, 19810, 18601, 17143, 15718, 13853, 11749,  9846,  7908,  5573,  3281,   946),
426  DEFINE_DCT32x32_MATRIX(   64,    83,    36,    89,    75,    50,    18,    90,    87,    80,    70,    57,    43,    25,     9,    90,    90,    88,    85,    82,    78,    73,    67,    61,    54,    46,    38,    31,    22,    13,     4)
427};
428const TMatrixCoeff g_as_DST_MAT_4[TRANSFORM_NUMBER_OF_DIRECTIONS][4][4] =
429{
430  DEFINE_DST4x4_MATRIX( 7424, 14081, 18893, 21505),
431  DEFINE_DST4x4_MATRIX(   29,    55,    74,    84)
432};
433#else
434const TMatrixCoeff g_aiT4 [TRANSFORM_NUMBER_OF_DIRECTIONS][4][4]   =
435{
436  DEFINE_DCT4x4_MATRIX  (   64,    83,    36),
437  DEFINE_DCT4x4_MATRIX  (   64,    83,    36)
438};
439const TMatrixCoeff g_aiT8 [TRANSFORM_NUMBER_OF_DIRECTIONS][8][8]   =
440{
441  DEFINE_DCT8x8_MATRIX  (   64,    83,    36,    89,    75,    50,    18),
442  DEFINE_DCT8x8_MATRIX  (   64,    83,    36,    89,    75,    50,    18)
443};
444const TMatrixCoeff g_aiT16[TRANSFORM_NUMBER_OF_DIRECTIONS][16][16] =
445{
446  DEFINE_DCT16x16_MATRIX(   64,    83,    36,    89,    75,    50,    18,    90,    87,    80,    70,    57,    43,    25,     9),
447  DEFINE_DCT16x16_MATRIX(   64,    83,    36,    89,    75,    50,    18,    90,    87,    80,    70,    57,    43,    25,     9)
448};
449const TMatrixCoeff g_aiT32[TRANSFORM_NUMBER_OF_DIRECTIONS][32][32] =
450{
451  DEFINE_DCT32x32_MATRIX(   64,    83,    36,    89,    75,    50,    18,    90,    87,    80,    70,    57,    43,    25,     9,    90,    90,    88,    85,    82,    78,    73,    67,    61,    54,    46,    38,    31,    22,    13,     4),
452  DEFINE_DCT32x32_MATRIX(   64,    83,    36,    89,    75,    50,    18,    90,    87,    80,    70,    57,    43,    25,     9,    90,    90,    88,    85,    82,    78,    73,    67,    61,    54,    46,    38,    31,    22,    13,     4)
453};
454const TMatrixCoeff g_as_DST_MAT_4[TRANSFORM_NUMBER_OF_DIRECTIONS][4][4] =
455{
456  DEFINE_DST4x4_MATRIX(   29,    55,    74,    84),
457  DEFINE_DST4x4_MATRIX(   29,    55,    74,    84)
458};
459#endif
460//--------------------------------------------------------------------------------------------------
461#undef DEFINE_DST4x4_MATRIX
462#undef DEFINE_DCT4x4_MATRIX
463#undef DEFINE_DCT8x8_MATRIX
464#undef DEFINE_DCT16x16_MATRIX
465#undef DEFINE_DCT32x32_MATRIX
466//--------------------------------------------------------------------------------------------------
467const UChar g_aucChromaScale[NUM_CHROMA_FORMAT][chromaQPMappingTableSize]=
468{
469  //0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57
470  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
471  { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,29,30,31,32,33,33,34,34,35,35,36,36,37,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51 },
472  { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,51,51,51,51,51,51 },
473  { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,51,51,51,51,51,51 }
474};
475// ====================================================================================================================
476// Intra prediction
477// ====================================================================================================================
478const UChar g_aucIntraModeNumFast_UseMPM[MAX_CU_DEPTH] =
479{
480  3,  //   2x2
481  8,  //   4x4
482  8,  //   8x8
483  3,  //  16x16
484  3,  //  32x32
485  3   //  64x64
486};
487const UChar g_aucIntraModeNumFast_NotUseMPM[MAX_CU_DEPTH] =
488{
489  3,  //   2x2
490  9,  //   4x4
491  9,  //   8x8
492  4,  //  16x16   33
493  4,  //  32x32   33
494  5   //  64x64   33
495};
496const UChar g_chroma422IntraAngleMappingTable[NUM_INTRA_MODE] =
497  //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, DM
498  { 0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20, 21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31, DM_CHROMA_IDX};
499// ====================================================================================================================
500// Misc.
501// ====================================================================================================================
502Char  g_aucConvertToBit  [ MAX_CU_SIZE+1 ];
503#if ENC_DEC_TRACE
504FILE*  g_hTrace = NULL; // Set to NULL to open up a file. Set to stdout to use the current output
505const Bool g_bEncDecTraceEnable  = true;
506const Bool g_bEncDecTraceDisable = false;
507Bool   g_HLSTraceEnable = false;
508Bool   g_bJustDoIt = false;
509UInt64 g_nSymbolCounter = 0;
510#if H_MV_ENC_DEC_TRAC
511Bool g_traceCU = false; 
512Bool g_tracePU = false; 
513Bool g_traceTU = false; 
514Bool g_disableNumbering = false; 
515Bool g_disableHLSTrace = false; 
516UInt64 g_stopAtCounter       = 4660; 
517Bool g_traceCopyBack         = false; 
518Bool g_decTraceDispDer       = false; 
519Bool g_decTraceMvFromMerge   = false; 
520Bool g_decTracePicOutput     = false; 
521Bool g_startStopTrace          = false; 
522Bool g_outputPos             = false;   
523Bool g_traceCameraParameters = false; 
524Bool g_encNumberOfWrittenBits     = false; 
525Bool g_traceEncFracBits        = false; 
526Bool g_traceIntraSearchCost    = false; 
527Bool g_traceRDCost             = false; 
528Bool g_traceSAOCost            = false; 
529Bool g_traceModeCheck          = false; 
530UInt g_indent                  = false; 
531Bool g_decNumBitsRead          = false; 
532Bool g_traceMotionInfoBeforUniPred = false; 
533Bool g_traceMergeCandListConst = false; 
534Bool g_traceBitsRead          = false; 
535Bool g_traceSubPBMotion       = false; 
536#endif
537#endif
538// ====================================================================================================================
539// Scanning order & context model mapping
540// ====================================================================================================================
541// scanning order table
542UInt* g_scanOrder[SCAN_NUMBER_OF_GROUP_TYPES][SCAN_NUMBER_OF_TYPES][ MAX_CU_DEPTH ][ MAX_CU_DEPTH ];
543const UInt ctxIndMap4x4[4*4] =
544{
545  0, 1, 4, 5,
546  2, 3, 4, 5,
547  6, 6, 8, 8,
548  7, 7, 8, 8
549};
550const UInt g_uiMinInGroup[ LAST_SIGNIFICANT_GROUPS ] = {0,1,2,3,4,6,8,12,16,24};
551const UInt g_uiGroupIdx[ MAX_TU_SIZE ]   = {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};
552const Char *MatrixType[SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM] =
553{
554  {
555    "INTRA4X4_LUMA",
556    "INTRA4X4_CHROMAU",
557    "INTRA4X4_CHROMAV",
558    "INTER4X4_LUMA",
559    "INTER4X4_CHROMAU",
560    "INTER4X4_CHROMAV"
561  },
562  {
563    "INTRA8X8_LUMA",
564    "INTRA8X8_CHROMAU",
565    "INTRA8X8_CHROMAV",
566    "INTER8X8_LUMA",
567    "INTER8X8_CHROMAU",
568    "INTER8X8_CHROMAV"
569  },
570  {
571    "INTRA16X16_LUMA",
572    "INTRA16X16_CHROMAU",
573    "INTRA16X16_CHROMAV",
574    "INTER16X16_LUMA",
575    "INTER16X16_CHROMAU",
576    "INTER16X16_CHROMAV"
577  },
578  {
579   "INTRA32X32_LUMA",
580   "INTRA32X32_CHROMAU_FROM16x16_CHROMAU",
581   "INTRA32X32_CHROMAV_FROM16x16_CHROMAV",
582   "INTER32X32_LUMA",
583   "INTER32X32_CHROMAU_FROM16x16_CHROMAU",
584   "INTER32X32_CHROMAV_FROM16x16_CHROMAV"
585  },
586};
587const Char *MatrixType_DC[SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM] =
588{
589  {
590  },
591  {
592  },
593  {
594    "INTRA16X16_LUMA_DC",
595    "INTRA16X16_CHROMAU_DC",
596    "INTRA16X16_CHROMAV_DC",
597    "INTER16X16_LUMA_DC",
598    "INTER16X16_CHROMAU_DC",
599    "INTER16X16_CHROMAV_DC"
600  },
601  {
602    "INTRA32X32_LUMA_DC",
603    "INTRA32X32_CHROMAU_DC_FROM16x16_CHROMAU",
604    "INTRA32X32_CHROMAV_DC_FROM16x16_CHROMAV",
605    "INTER32X32_LUMA_DC",
606    "INTER32X32_CHROMAU_DC_FROM16x16_CHROMAU",
607    "INTER32X32_CHROMAV_DC_FROM16x16_CHROMAV"
608  },
609};
610const Int g_quantTSDefault4x4[4*4] =
611{
612  16,16,16,16,
613  16,16,16,16,
614  16,16,16,16,
615  16,16,16,16
616};
617const Int g_quantIntraDefault8x8[8*8] =
618{
619  16,16,16,16,17,18,21,24,
620  16,16,16,16,17,19,22,25,
621  16,16,17,18,20,22,25,29,
622  16,16,18,21,24,27,31,36,
623  17,17,20,24,30,35,41,47,
624  18,19,22,27,35,44,54,65,
625  21,22,25,31,41,54,70,88,
626  24,25,29,36,47,65,88,115
627};
628const Int g_quantInterDefault8x8[8*8] =
629{
630  16,16,16,16,17,18,20,24,
631  16,16,16,17,18,20,24,25,
632  16,16,17,18,20,24,25,28,
633  16,17,18,20,24,25,28,33,
634  17,18,20,24,25,28,33,41,
635  18,20,24,25,28,33,41,54,
636  20,24,25,28,33,41,54,71,
637  24,25,28,33,41,54,71,91
638};
639const UInt g_scalingListSize   [SCALING_LIST_SIZE_NUM] = {16,64,256,1024};
640const UInt g_scalingListSizeX  [SCALING_LIST_SIZE_NUM] = { 4, 8, 16,  32};
641#if H_MV_ENC_DEC_TRAC
642#if ENC_DEC_TRACE
643Void tracePSHeader( const Char* psName, Int layerId )
644{ 
645  if ( !g_disableHLSTrace  ) 
646  {
647    fprintf( g_hTrace, "=========== ");   
648    fprintf( g_hTrace, "%s", psName );   
649    fprintf( g_hTrace, " Layer %d ===========", layerId );   
650    fprintf( g_hTrace, "\n" );   
651    fflush ( g_hTrace );   
652  }
653}
654Void stopAtPos( Int poc, Int layerId, Int cuPelX, Int cuPelY, Int cuWidth, Int cuHeight )
655{
656  if ( g_outputPos ) 
657  {
658    std::cout << "POC\t"        << poc
659              << "\tLayerId\t"  << layerId
660              << "\tCuPelX\t"   << cuPelX 
661              << "\tCuPelY\t"   << cuPelY
662              << "\tCuWidth\t"  << cuWidth
663              << "\tCuHeight\t" << cuHeight
664              << std::endl; 
665  }
666  Bool startTrace = false; 
667  if ( g_startStopTrace && poc == 0 && layerId == 0 )
668  {
669    startTrace = ( cuPelX  == 0 ) && ( cuPelY  == 0 ) && ( cuWidth == 64 ) && ( cuHeight == 64 ); 
670    }
671  if ( startTrace )
672  { 
673    g_outputPos              = true; 
674    g_traceEncFracBits       = false;   
675    g_traceIntraSearchCost   = false;     
676    g_encNumberOfWrittenBits = false;     
677    g_traceRDCost            = true; 
678    g_traceModeCheck         = true; 
679    g_traceCopyBack          = false; 
680    }
681  Bool stopTrace = false; 
682  if ( g_startStopTrace && poc == 0 && layerId == 0 )
683  {
684    stopTrace = ( cuPelX  == 128 ) && ( cuPelY  == 0 ) && ( cuWidth == 64 ) && ( cuHeight == 64 ); 
685  }
686  if ( stopTrace )
687  { 
688    g_outputPos              = false; 
689    g_traceModeCheck         = false; 
690    g_traceEncFracBits       = false; 
691    g_traceIntraSearchCost   = false;       
692    g_encNumberOfWrittenBits = false; 
693    g_traceRDCost            = false; 
694    g_traceCopyBack          = false;     
695  } 
696}
697Void writeToTraceFile( const Char* symbolName, Int val, Bool doIt )
698{
699  if ( ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) && doIt  ) 
700  {
701    incSymbolCounter(); 
702    if ( !g_disableNumbering )
703    { 
704      fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter );
705    }
706    fprintf( g_hTrace, "%-50s       : %d\n", symbolName, val );     
707    fflush ( g_hTrace );   
708  }
709}
710UInt64 incSymbolCounter( )
711{
712  g_nSymbolCounter++; 
713  if ( g_stopAtCounter == g_nSymbolCounter )
714  {
715    std::cout << "Break point here." << std::endl; 
716  } 
717  return g_nSymbolCounter; 
718}
719Void writeToTraceFile( const Char* symbolName, Bool doIt )
720{
721  if ( ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) && doIt  ) 
722  {
723    incSymbolCounter(); 
724    fprintf( g_hTrace, "%s", symbolName );   
725    fflush ( g_hTrace );   
726  }
727}
728Void printStr( std::string str )
729{
730  std::cout << str << std::endl; 
731}
732Void printStrIndent( Bool b, std::string strStr )
733{
734  if ( b )
735  { 
736    std::cout << std::string(g_indent, ' ');
737    printStr( strStr );
738  }
739}
740Void prinStrIncIndent( Bool b,  std::string strStr )
741{
742  if ( b )
743  {
744    printStrIndent( true,  strStr );
745    if (g_indent < 50)
746    {
747      g_indent++;
748    }
749  } 
750}
751Void decIndent( Bool b )
752{
753  if (b && g_indent > 0)
754  {
755    g_indent--; 
756  } 
757}
758#endif
759#endif
760//! \}
Note: See TracBrowser for help on using the repository browser.