HEVC Test Model (HM)  HM-16.18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TComRom.cpp
Go to the documentation of this file.
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-2017, 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 
38 #include "TComRom.h"
39 #include <memory.h>
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <iomanip>
43 #include <assert.h>
44 #include "TComDataCU.h"
45 #include "Debug.h"
46 // ====================================================================================================================
47 // Initialize / destroy functions
48 // ====================================================================================================================
49 
52 
54 {
55  switch (type)
56  {
57  case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R";
58  case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N";
59  case NAL_UNIT_CODED_SLICE_TSA_R: return "TSA_R";
60  case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N";
61  case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R";
62  case NAL_UNIT_CODED_SLICE_STSA_N: return "STSA_N";
63  case NAL_UNIT_CODED_SLICE_BLA_W_LP: return "BLA_W_LP";
64  case NAL_UNIT_CODED_SLICE_BLA_W_RADL: return "BLA_W_RADL";
65  case NAL_UNIT_CODED_SLICE_BLA_N_LP: return "BLA_N_LP";
66  case NAL_UNIT_CODED_SLICE_IDR_W_RADL: return "IDR_W_RADL";
67  case NAL_UNIT_CODED_SLICE_IDR_N_LP: return "IDR_N_LP";
68  case NAL_UNIT_CODED_SLICE_CRA: return "CRA";
69  case NAL_UNIT_CODED_SLICE_RADL_R: return "RADL_R";
70  case NAL_UNIT_CODED_SLICE_RADL_N: return "RADL_N";
71  case NAL_UNIT_CODED_SLICE_RASL_R: return "RASL_R";
72  case NAL_UNIT_CODED_SLICE_RASL_N: return "RASL_N";
73  case NAL_UNIT_VPS: return "VPS";
74  case NAL_UNIT_SPS: return "SPS";
75  case NAL_UNIT_PPS: return "PPS";
76  case NAL_UNIT_ACCESS_UNIT_DELIMITER: return "AUD";
77  case NAL_UNIT_EOS: return "EOS";
78  case NAL_UNIT_EOB: return "EOB";
79  case NAL_UNIT_FILLER_DATA: return "FILLER";
80  case NAL_UNIT_PREFIX_SEI: return "Prefix SEI";
81  case NAL_UNIT_SUFFIX_SEI: return "Suffix SEI";
82  default: return "UNK";
83  }
84 }
85 
87 {
88 private:
91  const UInt m_stride;
93 
94 public:
95  ScanGenerator(UInt blockWidth, UInt blockHeight, UInt stride, COEFF_SCAN_TYPE scanType)
96  : m_line(0), m_column(0), m_blockWidth(blockWidth), m_blockHeight(blockHeight), m_stride(stride), m_scanType(scanType)
97  { }
98 
99  UInt GetCurrentX() const { return m_column; }
100  UInt GetCurrentY() const { return m_line; }
101 
102  UInt GetNextIndex(UInt blockOffsetX, UInt blockOffsetY)
103  {
104  Int rtn=((m_line + blockOffsetY) * m_stride) + m_column + blockOffsetX;
105 
106  //advance line and column to the next position
107  switch (m_scanType)
108  {
109  //------------------------------------------------
110 
111  case SCAN_DIAG:
112  {
113  if ((m_column == (m_blockWidth - 1)) || (m_line == 0)) //if we reach the end of a rank, go diagonally down to the next one
114  {
115  m_line += m_column + 1;
116  m_column = 0;
117 
118  if (m_line >= m_blockHeight) //if that takes us outside the block, adjust so that we are back on the bottom row
119  {
120  m_column += m_line - (m_blockHeight - 1);
121  m_line = m_blockHeight - 1;
122  }
123  }
124  else
125  {
126  m_column++;
127  m_line--;
128  }
129  }
130  break;
131 
132  //------------------------------------------------
133 
134  case SCAN_HOR:
135  {
136  if (m_column == (m_blockWidth - 1))
137  {
138  m_line++;
139  m_column = 0;
140  }
141  else
142  {
143  m_column++;
144  }
145  }
146  break;
147 
148  //------------------------------------------------
149 
150  case SCAN_VER:
151  {
152  if (m_line == (m_blockHeight - 1))
153  {
154  m_column++;
155  m_line = 0;
156  }
157  else
158  {
159  m_line++;
160  }
161  }
162  break;
163 
164  //------------------------------------------------
165 
166  default:
167  {
168  std::cerr << "ERROR: Unknown scan type \"" << m_scanType << "\"in ScanGenerator::GetNextIndex" << std::endl;
169  exit(1);
170  }
171  break;
172  }
173 
174  return rtn;
175  }
176 };
177 
178 // initialize ROM variables
180 {
181  Int i, c;
182 
183  // g_aucConvertToBit[ x ]: log2(x/4), if x=4 -> 0, x=8 -> 1, x=16 -> 2, ...
184  ::memset( g_aucConvertToBit, -1, sizeof( g_aucConvertToBit ) );
185  c=0;
186  for ( i=4; i<=MAX_CU_SIZE; i*=2 )
187  {
188  g_aucConvertToBit[ i ] = c;
189  c++;
190  }
191 
192  // initialise scan orders
193  for(UInt log2BlockHeight = 0; log2BlockHeight < MAX_CU_DEPTH; log2BlockHeight++)
194  {
195  for(UInt log2BlockWidth = 0; log2BlockWidth < MAX_CU_DEPTH; log2BlockWidth++)
196  {
197  const UInt blockWidth = 1 << log2BlockWidth;
198  const UInt blockHeight = 1 << log2BlockHeight;
199  const UInt totalValues = blockWidth * blockHeight;
200 
201  //--------------------------------------------------------------------------------------------------
202 
203  //non-grouped scan orders
204 
205  for (UInt scanTypeIndex = 0; scanTypeIndex < SCAN_NUMBER_OF_TYPES; scanTypeIndex++)
206  {
207  const COEFF_SCAN_TYPE scanType = COEFF_SCAN_TYPE(scanTypeIndex);
208 
209  g_scanOrder[SCAN_UNGROUPED][scanType][log2BlockWidth][log2BlockHeight] = new UInt[totalValues];
210 
211  ScanGenerator fullBlockScan(blockWidth, blockHeight, blockWidth, scanType);
212 
213  for (UInt scanPosition = 0; scanPosition < totalValues; scanPosition++)
214  {
215  g_scanOrder[SCAN_UNGROUPED][scanType][log2BlockWidth][log2BlockHeight][scanPosition] = fullBlockScan.GetNextIndex(0, 0);
216  }
217  }
218 
219  //--------------------------------------------------------------------------------------------------
220 
221  //grouped scan orders
222 
223  const UInt groupWidth = 1 << MLS_CG_LOG2_WIDTH;
224  const UInt groupHeight = 1 << MLS_CG_LOG2_HEIGHT;
225  const UInt widthInGroups = blockWidth >> MLS_CG_LOG2_WIDTH;
226  const UInt heightInGroups = blockHeight >> MLS_CG_LOG2_HEIGHT;
227 
228  const UInt groupSize = groupWidth * groupHeight;
229  const UInt totalGroups = widthInGroups * heightInGroups;
230 
231  for (UInt scanTypeIndex = 0; scanTypeIndex < SCAN_NUMBER_OF_TYPES; scanTypeIndex++)
232  {
233  const COEFF_SCAN_TYPE scanType = COEFF_SCAN_TYPE(scanTypeIndex);
234 
235  g_scanOrder[SCAN_GROUPED_4x4][scanType][log2BlockWidth][log2BlockHeight] = new UInt[totalValues];
236 
237  ScanGenerator fullBlockScan(widthInGroups, heightInGroups, groupWidth, scanType);
238 
239  for (UInt groupIndex = 0; groupIndex < totalGroups; groupIndex++)
240  {
241  const UInt groupPositionY = fullBlockScan.GetCurrentY();
242  const UInt groupPositionX = fullBlockScan.GetCurrentX();
243  const UInt groupOffsetX = groupPositionX * groupWidth;
244  const UInt groupOffsetY = groupPositionY * groupHeight;
245  const UInt groupOffsetScan = groupIndex * groupSize;
246 
247  ScanGenerator groupScan(groupWidth, groupHeight, blockWidth, scanType);
248 
249  for (UInt scanPosition = 0; scanPosition < groupSize; scanPosition++)
250  {
251  g_scanOrder[SCAN_GROUPED_4x4][scanType][log2BlockWidth][log2BlockHeight][groupOffsetScan + scanPosition] = groupScan.GetNextIndex(groupOffsetX, groupOffsetY);
252  }
253 
254  fullBlockScan.GetNextIndex(0,0);
255  }
256  }
257 
258  //--------------------------------------------------------------------------------------------------
259  }
260  }
261 }
262 
264 {
265  for(UInt groupTypeIndex = 0; groupTypeIndex < SCAN_NUMBER_OF_GROUP_TYPES; groupTypeIndex++)
266  {
267  for (UInt scanOrderIndex = 0; scanOrderIndex < SCAN_NUMBER_OF_TYPES; scanOrderIndex++)
268  {
269  for (UInt log2BlockWidth = 0; log2BlockWidth < MAX_CU_DEPTH; log2BlockWidth++)
270  {
271  for (UInt log2BlockHeight = 0; log2BlockHeight < MAX_CU_DEPTH; log2BlockHeight++)
272  {
273  delete [] g_scanOrder[groupTypeIndex][scanOrderIndex][log2BlockWidth][log2BlockHeight];
274  }
275  }
276  }
277  }
278 }
279 
280 // ====================================================================================================================
281 // Data structure related table & variable
282 // ====================================================================================================================
283 
288 
289 const UInt g_auiPUOffset[NUMBER_OF_PART_SIZES] = { 0, 8, 4, 4, 2, 10, 1, 5};
290 
291 Void initZscanToRaster ( Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt*& rpuiCurrIdx )
292 {
293  Int iStride = 1 << ( iMaxDepth - 1 );
294 
295  if ( iDepth == iMaxDepth )
296  {
297  rpuiCurrIdx[0] = uiStartVal;
298  rpuiCurrIdx++;
299  }
300  else
301  {
302  Int iStep = iStride >> iDepth;
303  initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal, rpuiCurrIdx );
304  initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep, rpuiCurrIdx );
305  initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep*iStride, rpuiCurrIdx );
306  initZscanToRaster( iMaxDepth, iDepth+1, uiStartVal+iStep*iStride+iStep, rpuiCurrIdx );
307  }
308 }
309 
310 Void initRasterToZscan ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth )
311 {
312  UInt uiMinCUWidth = uiMaxCUWidth >> ( uiMaxDepth - 1 );
313  UInt uiMinCUHeight = uiMaxCUHeight >> ( uiMaxDepth - 1 );
314 
315  UInt uiNumPartInWidth = (UInt)uiMaxCUWidth / uiMinCUWidth;
316  UInt uiNumPartInHeight = (UInt)uiMaxCUHeight / uiMinCUHeight;
317 
318  for ( UInt i = 0; i < uiNumPartInWidth*uiNumPartInHeight; i++ )
319  {
321  }
322 }
323 
324 Void initRasterToPelXY ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth )
325 {
326  UInt i;
327 
328  UInt* uiTempX = &g_auiRasterToPelX[0];
329  UInt* uiTempY = &g_auiRasterToPelY[0];
330 
331  UInt uiMinCUWidth = uiMaxCUWidth >> ( uiMaxDepth - 1 );
332  UInt uiMinCUHeight = uiMaxCUHeight >> ( uiMaxDepth - 1 );
333 
334  UInt uiNumPartInWidth = uiMaxCUWidth / uiMinCUWidth;
335  UInt uiNumPartInHeight = uiMaxCUHeight / uiMinCUHeight;
336 
337  uiTempX[0] = 0; uiTempX++;
338  for ( i = 1; i < uiNumPartInWidth; i++ )
339  {
340  uiTempX[0] = uiTempX[-1] + uiMinCUWidth; uiTempX++;
341  }
342  for ( i = 1; i < uiNumPartInHeight; i++ )
343  {
344  memcpy(uiTempX, uiTempX-uiNumPartInWidth, sizeof(UInt)*uiNumPartInWidth);
345  uiTempX += uiNumPartInWidth;
346  }
347 
348  for ( i = 1; i < uiNumPartInWidth*uiNumPartInHeight; i++ )
349  {
350  uiTempY[i] = ( i / uiNumPartInWidth ) * uiMinCUWidth;
351  }
352 }
353 
355 {
356  26214,23302,20560,18396,16384,14564
357 };
358 
360 {
361  40,45,51,57,64,72
362 };
363 
364 //--------------------------------------------------------------------------------------------------
365 
366 //structures
367 
368 #define DEFINE_DST4x4_MATRIX(a,b,c,d) \
369 { \
370  { a, b, c, d }, \
371  { c, c, 0, -c }, \
372  { d, -a, -c, b }, \
373  { b, -d, c, -a }, \
374 }
375 
376 #define DEFINE_DCT4x4_MATRIX(a,b,c) \
377 { \
378  { a, a, a, a}, \
379  { b, c, -c, -b}, \
380  { a, -a, -a, a}, \
381  { c, -b, b, -c} \
382 }
383 
384 #define DEFINE_DCT8x8_MATRIX(a,b,c,d,e,f,g) \
385 { \
386  { a, a, a, a, a, a, a, a}, \
387  { d, e, f, g, -g, -f, -e, -d}, \
388  { b, c, -c, -b, -b, -c, c, b}, \
389  { e, -g, -d, -f, f, d, g, -e}, \
390  { a, -a, -a, a, a, -a, -a, a}, \
391  { f, -d, g, e, -e, -g, d, -f}, \
392  { c, -b, b, -c, -c, b, -b, c}, \
393  { g, -f, e, -d, d, -e, f, -g} \
394 }
395 
396 #define DEFINE_DCT16x16_MATRIX(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) \
397 { \
398  { a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a}, \
399  { h, i, j, k, l, m, n, o, -o, -n, -m, -l, -k, -j, -i, -h}, \
400  { d, e, f, g, -g, -f, -e, -d, -d, -e, -f, -g, g, f, e, d}, \
401  { i, l, o, -m, -j, -h, -k, -n, n, k, h, j, m, -o, -l, -i}, \
402  { b, c, -c, -b, -b, -c, c, b, b, c, -c, -b, -b, -c, c, b}, \
403  { j, o, -k, -i, -n, l, h, m, -m, -h, -l, n, i, k, -o, -j}, \
404  { e, -g, -d, -f, f, d, g, -e, -e, g, d, f, -f, -d, -g, e}, \
405  { k, -m, -i, o, h, n, -j, -l, l, j, -n, -h, -o, i, m, -k}, \
406  { a, -a, -a, a, a, -a, -a, a, a, -a, -a, a, a, -a, -a, a}, \
407  { l, -j, -n, h, -o, -i, m, k, -k, -m, i, o, -h, n, j, -l}, \
408  { f, -d, g, e, -e, -g, d, -f, -f, d, -g, -e, e, g, -d, f}, \
409  { m, -h, l, n, -i, k, o, -j, j, -o, -k, i, -n, -l, h, -m}, \
410  { c, -b, b, -c, -c, b, -b, c, c, -b, b, -c, -c, b, -b, c}, \
411  { n, -k, h, -j, m, o, -l, i, -i, l, -o, -m, j, -h, k, -n}, \
412  { g, -f, e, -d, d, -e, f, -g, -g, f, -e, d, -d, e, -f, g}, \
413  { o, -n, m, -l, k, -j, i, -h, h, -i, j, -k, l, -m, n, -o} \
414 }
415 
416 #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) \
417 { \
418  { 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}, \
419  { 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}, \
420  { 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}, \
421  { 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}, \
422  { 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}, \
423  { 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}, \
424  { 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}, \
425  { 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}, \
426  { 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}, \
427  { 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}, \
428  { 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}, \
429  { 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}, \
430  { 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}, \
431  { 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}, \
432  { 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}, \
433  { 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}, \
434  { 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}, \
435  { 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}, \
436  { 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}, \
437  { 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}, \
438  { 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}, \
439  { 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}, \
440  { 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}, \
441  { 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}, \
442  { 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}, \
443  { 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}, \
444  { 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}, \
445  { 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}, \
446  { 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}, \
447  { 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}, \
448  { 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}, \
449  { 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} \
450 }
451 
452 //--------------------------------------------------------------------------------------------------
453 
454 //coefficients
455 
456 #if RExt__HIGH_PRECISION_FORWARD_TRANSFORM
458 {
459  DEFINE_DCT4x4_MATRIX (16384, 21266, 9224),
460  DEFINE_DCT4x4_MATRIX ( 64, 83, 36)
461 };
462 
464 {
465  DEFINE_DCT8x8_MATRIX (16384, 21266, 9224, 22813, 19244, 12769, 4563),
466  DEFINE_DCT8x8_MATRIX ( 64, 83, 36, 89, 75, 50, 18)
467 };
468 
470 {
471  DEFINE_DCT16x16_MATRIX(16384, 21266, 9224, 22813, 19244, 12769, 4563, 23120, 22063, 20450, 17972, 14642, 11109, 6446, 2316),
472  DEFINE_DCT16x16_MATRIX( 64, 83, 36, 89, 75, 50, 18, 90, 87, 80, 70, 57, 43, 25, 9)
473 };
474 
476 {
477  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),
478  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)
479 };
480 
482 {
483  DEFINE_DST4x4_MATRIX( 7424, 14081, 18893, 21505),
484  DEFINE_DST4x4_MATRIX( 29, 55, 74, 84)
485 };
486 
487 #else
488 
490 {
491  DEFINE_DCT4x4_MATRIX ( 64, 83, 36),
492  DEFINE_DCT4x4_MATRIX ( 64, 83, 36)
493 };
494 
496 {
497  DEFINE_DCT8x8_MATRIX ( 64, 83, 36, 89, 75, 50, 18),
498  DEFINE_DCT8x8_MATRIX ( 64, 83, 36, 89, 75, 50, 18)
499 };
500 
502 {
503  DEFINE_DCT16x16_MATRIX( 64, 83, 36, 89, 75, 50, 18, 90, 87, 80, 70, 57, 43, 25, 9),
504  DEFINE_DCT16x16_MATRIX( 64, 83, 36, 89, 75, 50, 18, 90, 87, 80, 70, 57, 43, 25, 9)
505 };
506 
508 {
509  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),
510  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)
511 };
512 
514 {
515  DEFINE_DST4x4_MATRIX( 29, 55, 74, 84),
516  DEFINE_DST4x4_MATRIX( 29, 55, 74, 84)
517 };
518 #endif
519 
520 
521 //--------------------------------------------------------------------------------------------------
522 
523 #undef DEFINE_DST4x4_MATRIX
524 #undef DEFINE_DCT4x4_MATRIX
525 #undef DEFINE_DCT8x8_MATRIX
526 #undef DEFINE_DCT16x16_MATRIX
527 #undef DEFINE_DCT32x32_MATRIX
528 
529 //--------------------------------------------------------------------------------------------------
530 
531 
533 {
534  //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
535  { 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 },
536  { 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 },
537  { 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 },
538  { 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 }
539 };
540 
541 // ====================================================================================================================
542 // Intra prediction
543 // ====================================================================================================================
544 
546 {
547  3, // 2x2
548  8, // 4x4
549  8, // 8x8
550  3, // 16x16
551  3, // 32x32
552  3 // 64x64
553 };
555 {
556  3, // 2x2
557  9, // 4x4
558  9, // 8x8
559  4, // 16x16 33
560  4, // 32x32 33
561  5 // 64x64 33
562 };
563 
565  //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
566  { 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};
567 
568 // ====================================================================================================================
569 // Misc.
570 // ====================================================================================================================
571 
573 
574 #if ENC_DEC_TRACE
575 FILE* g_hTrace = NULL; // Set to NULL to open up a file. Set to stdout to use the current output
576 const Bool g_bEncDecTraceEnable = true;
577 const Bool g_bEncDecTraceDisable = false;
578 Bool g_HLSTraceEnable = true;
579 Bool g_bJustDoIt = false;
580 UInt64 g_nSymbolCounter = 0;
581 #endif
582 // ====================================================================================================================
583 // Scanning order & context model mapping
584 // ====================================================================================================================
585 
586 // scanning order table
588 
589 const UInt ctxIndMap4x4[4*4] =
590 {
591  0, 1, 4, 5,
592  2, 3, 4, 5,
593  6, 6, 8, 8,
594  7, 7, 8, 8
595 };
596 
597 const UInt g_uiMinInGroup[ LAST_SIGNIFICANT_GROUPS ] = {0,1,2,3,4,6,8,12,16,24};
598 const 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};
599 
601 {
602  {
603  "INTRA4X4_LUMA",
604  "INTRA4X4_CHROMAU",
605  "INTRA4X4_CHROMAV",
606  "INTER4X4_LUMA",
607  "INTER4X4_CHROMAU",
608  "INTER4X4_CHROMAV"
609  },
610  {
611  "INTRA8X8_LUMA",
612  "INTRA8X8_CHROMAU",
613  "INTRA8X8_CHROMAV",
614  "INTER8X8_LUMA",
615  "INTER8X8_CHROMAU",
616  "INTER8X8_CHROMAV"
617  },
618  {
619  "INTRA16X16_LUMA",
620  "INTRA16X16_CHROMAU",
621  "INTRA16X16_CHROMAV",
622  "INTER16X16_LUMA",
623  "INTER16X16_CHROMAU",
624  "INTER16X16_CHROMAV"
625  },
626  {
627  "INTRA32X32_LUMA",
628  "INTRA32X32_CHROMAU_FROM16x16_CHROMAU",
629  "INTRA32X32_CHROMAV_FROM16x16_CHROMAV",
630  "INTER32X32_LUMA",
631  "INTER32X32_CHROMAU_FROM16x16_CHROMAU",
632  "INTER32X32_CHROMAV_FROM16x16_CHROMAV"
633  },
634 };
635 
637 {
638  {
639  },
640  {
641  },
642  {
643  "INTRA16X16_LUMA_DC",
644  "INTRA16X16_CHROMAU_DC",
645  "INTRA16X16_CHROMAV_DC",
646  "INTER16X16_LUMA_DC",
647  "INTER16X16_CHROMAU_DC",
648  "INTER16X16_CHROMAV_DC"
649  },
650  {
651  "INTRA32X32_LUMA_DC",
652  "INTRA32X32_CHROMAU_DC_FROM16x16_CHROMAU",
653  "INTRA32X32_CHROMAV_DC_FROM16x16_CHROMAV",
654  "INTER32X32_LUMA_DC",
655  "INTER32X32_CHROMAU_DC_FROM16x16_CHROMAU",
656  "INTER32X32_CHROMAV_DC_FROM16x16_CHROMAV"
657  },
658 };
659 
661 {
662  16,16,16,16,
663  16,16,16,16,
664  16,16,16,16,
665  16,16,16,16
666 };
667 
669 {
670  16,16,16,16,17,18,21,24,
671  16,16,16,16,17,19,22,25,
672  16,16,17,18,20,22,25,29,
673  16,16,18,21,24,27,31,36,
674  17,17,20,24,30,35,41,47,
675  18,19,22,27,35,44,54,65,
676  21,22,25,31,41,54,70,88,
677  24,25,29,36,47,65,88,115
678 };
679 
681 {
682  16,16,16,16,17,18,20,24,
683  16,16,16,17,18,20,24,25,
684  16,16,17,18,20,24,25,28,
685  16,17,18,20,24,25,28,33,
686  17,18,20,24,25,28,33,41,
687  18,20,24,25,28,33,41,54,
688  20,24,25,28,33,41,54,71,
689  24,25,28,33,41,54,71,91
690 };
691 
692 const UInt g_scalingListSize [SCALING_LIST_SIZE_NUM] = {16,64,256,1024};
694 
SChar g_aucConvertToBit[MAX_CU_SIZE+1]
Definition: TComRom.cpp:572
const Int g_quantScales[SCALING_LIST_REM_NUM]
Definition: TComRom.cpp:354
const Int g_quantTSDefault4x4[4 *4]
Definition: TComRom.cpp:660
static const Int SCALING_LIST_REM_NUM
Definition: CommonDef.h:226
UInt GetNextIndex(UInt blockOffsetX, UInt blockOffsetY)
Definition: TComRom.cpp:102
static const Int SCALING_LIST_NUM
list number for quantization matrix
Definition: CommonDef.h:232
Void initROM()
Definition: TComRom.cpp:179
const TMatrixCoeff g_aiT16[TRANSFORM_NUMBER_OF_DIRECTIONS][16][16]
Definition: TComRom.cpp:501
void Void
Definition: TypeDef.h:203
const TChar * nalUnitTypeToString(NalUnitType type)
Definition: TComRom.cpp:53
static const Int MAX_CU_DEPTH
log2(CTUSize)
Definition: CommonDef.h:220
static const Int DM_CHROMA_IDX
chroma mode index for derived from luma intra mode
Definition: CommonDef.h:188
static const Int MAX_TU_SIZE
Definition: CommonDef.h:224
const TMatrixCoeff g_aiT4[TRANSFORM_NUMBER_OF_DIRECTIONS][4][4]
Definition: TComRom.cpp:489
global variables &amp; functions (header)
#define NULL
Definition: CommonDef.h:107
const Int g_quantInterDefault8x8[8 *8]
Definition: TComRom.cpp:680
unsigned int UInt
Definition: TypeDef.h:212
const UInt m_blockWidth
Definition: TComRom.cpp:90
#define DEFINE_DST4x4_MATRIX(a, b, c, d)
Definition: TComRom.cpp:368
#define DEFINE_DCT4x4_MATRIX(a, b, c)
Definition: TComRom.cpp:376
char TChar
Definition: TypeDef.h:206
horizontal first scan
Definition: TypeDef.h:476
Short TMatrixCoeff
transform matrix coefficient
Definition: TypeDef.h:251
const UInt g_auiPUOffset[NUMBER_OF_PART_SIZES]
Definition: TComRom.cpp:289
const UInt m_stride
Definition: TComRom.cpp:91
UInt m_column
Definition: TComRom.cpp:89
const UInt m_blockHeight
Definition: TComRom.cpp:90
signed char SChar
Definition: TypeDef.h:207
UInt GetCurrentX() const
Definition: TComRom.cpp:99
static const Int MLS_CG_LOG2_WIDTH
Definition: CommonDef.h:169
bool Bool
Definition: TypeDef.h:204
Void initRasterToPelXY(UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth)
Definition: TComRom.cpp:324
const TChar * MatrixType[SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]
Definition: TComRom.cpp:600
ScanGenerator(UInt blockWidth, UInt blockHeight, UInt stride, COEFF_SCAN_TYPE scanType)
Definition: TComRom.cpp:95
up-right diagonal scan
Definition: TypeDef.h:475
Void initRasterToZscan(UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth)
Definition: TComRom.cpp:310
UInt * g_scanOrder[SCAN_NUMBER_OF_GROUP_TYPES][SCAN_NUMBER_OF_TYPES][MAX_CU_DEPTH][MAX_CU_DEPTH]
Definition: TComRom.cpp:587
const UChar g_aucIntraModeNumFast_UseMPM[MAX_CU_DEPTH]
Definition: TComRom.cpp:545
const Int g_invQuantScales[SCALING_LIST_REM_NUM]
Definition: TComRom.cpp:359
unsigned char UChar
Definition: TypeDef.h:208
COEFF_SCAN_TYPE
coefficient scanning type used in ACS
Definition: TypeDef.h:473
const UInt g_scalingListSize[SCALING_LIST_SIZE_NUM]
Definition: TComRom.cpp:692
UInt g_auiZscanToRaster[MAX_NUM_PART_IDXS_IN_CTU_WIDTH *MAX_NUM_PART_IDXS_IN_CTU_WIDTH]
Definition: TComRom.cpp:284
UInt g_auiRasterToZscan[MAX_NUM_PART_IDXS_IN_CTU_WIDTH *MAX_NUM_PART_IDXS_IN_CTU_WIDTH]
Definition: TComRom.cpp:285
#define DEFINE_DCT8x8_MATRIX(a, b, c, d, e, f, g)
Definition: TComRom.cpp:384
const TMatrixCoeff g_aiT32[TRANSFORM_NUMBER_OF_DIRECTIONS][32][32]
Definition: TComRom.cpp:507
static const Int NUM_INTRA_MODE
Definition: CommonDef.h:182
const UInt g_uiMinInGroup[LAST_SIGNIFICANT_GROUPS]
Definition: TComRom.cpp:597
const TMatrixCoeff g_aiT8[TRANSFORM_NUMBER_OF_DIRECTIONS][8][8]
Definition: TComRom.cpp:495
unsigned long long UInt64
Definition: TypeDef.h:233
#define DEFINE_DCT16x16_MATRIX(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
Definition: TComRom.cpp:396
const COEFF_SCAN_TYPE m_scanType
Definition: TComRom.cpp:92
const UChar g_chroma422IntraAngleMappingTable[NUM_INTRA_MODE]
Definition: TComRom.cpp:564
const UInt g_uiGroupIdx[MAX_TU_SIZE]
Definition: TComRom.cpp:598
const UInt ctxIndMap4x4[4 *4]
Definition: TComRom.cpp:589
static const Int MAX_CU_SIZE
= 1&lt;&lt;(MAX_CU_DEPTH)
Definition: CommonDef.h:221
const TMatrixCoeff g_as_DST_MAT_4[TRANSFORM_NUMBER_OF_DIRECTIONS][4][4]
Definition: TComRom.cpp:513
Void initZscanToRaster(Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt *&rpuiCurrIdx)
Definition: TComRom.cpp:291
const UInt g_scalingListSizeX[SCALING_LIST_SIZE_NUM]
Definition: TComRom.cpp:693
static const Int chromaQPMappingTableSize
Definition: TComRom.h:94
static const Int MLS_CG_LOG2_HEIGHT
Definition: CommonDef.h:170
int Int
Definition: TypeDef.h:211
static const Int MAX_NUM_PART_IDXS_IN_CTU_WIDTH
maximum number of partition indices across the width of a CTU (or height of a CTU) ...
Definition: CommonDef.h:225
NalUnitType
Definition: TypeDef.h:664
const TChar * MatrixType_DC[SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]
Definition: TComRom.cpp:636
const UChar g_aucChromaScale[NUM_CHROMA_FORMAT][chromaQPMappingTableSize]
Definition: TComRom.cpp:532
UInt g_auiRasterToPelX[MAX_NUM_PART_IDXS_IN_CTU_WIDTH *MAX_NUM_PART_IDXS_IN_CTU_WIDTH]
Definition: TComRom.cpp:286
CU data structure (header)
UInt GetCurrentY() const
Definition: TComRom.cpp:100
vertical first scan
Definition: TypeDef.h:477
#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)
Definition: TComRom.cpp:416
Defines types and objects for environment-variable-based debugging and feature control.
Void destroyROM()
Definition: TComRom.cpp:263
UInt g_auiRasterToPelY[MAX_NUM_PART_IDXS_IN_CTU_WIDTH *MAX_NUM_PART_IDXS_IN_CTU_WIDTH]
Definition: TComRom.cpp:287
const Int g_quantIntraDefault8x8[8 *8]
Definition: TComRom.cpp:668
static const Int LAST_SIGNIFICANT_GROUPS
Definition: CommonDef.h:242
const UChar g_aucIntraModeNumFast_NotUseMPM[MAX_CU_DEPTH]
Definition: TComRom.cpp:554