HEVC Test Model (HM)  HM-16.3
TComDataCU.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-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 
39 #include "TComDataCU.h"
40 #include "TComTU.h"
41 #include "TComPic.h"
42 
45 
46 #if ADAPTIVE_QP_SELECTION
48 #endif
49 
50 // ====================================================================================================================
51 // Constructor / destructor / create / destroy
52 // ====================================================================================================================
53 
55 {
56  m_pcPic = NULL;
57  m_pcSlice = NULL;
58  m_puhDepth = NULL;
59 
60  m_skipFlag = NULL;
61 
65  m_puhWidth = NULL;
66  m_puhHeight = NULL;
67  m_phQP = NULL;
71  for(UInt i=0; i<MAX_NUM_CHANNEL_TYPE; i++)
72  {
73  m_puhIntraDir[i] = NULL;
74  }
76  m_puhTrIdx = NULL;
77 
78  for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
79  {
80  m_puhCbf[comp] = NULL;
82  m_puhTransformSkip[comp] = NULL;
83  m_pcTrCoeff[comp] = NULL;
84 #if ADAPTIVE_QP_SELECTION
85  m_pcArlCoeff[comp] = NULL;
86 #endif
87  m_pcIPCMSample[comp] = NULL;
88  m_explicitRdpcmMode[comp] = NULL;
89  }
90 #if ADAPTIVE_QP_SELECTION
92 #endif
94 
97  m_pCtuAbove = NULL;
98  m_pCtuLeft = NULL;
99 
100  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
101  {
102  m_apcCUColocated[i] = NULL;
103  m_apiMVPIdx[i] = NULL;
104  m_apiMVPNum[i] = NULL;
105  }
106 
107  m_bDecSubCu = false;
108 }
109 
111 {
112 }
113 
114 Void TComDataCU::create( ChromaFormat chromaFormatIDC, UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize
116  , Bool bGlobalRMARLBuffer
117 #endif
118  )
119 {
120  m_bDecSubCu = bDecSubCu;
121 
122  m_pcPic = NULL;
123  m_pcSlice = NULL;
124  m_uiNumPartition = uiNumPartition;
125  m_unitSize = unitSize;
126 
127  if ( !bDecSubCu )
128  {
129  m_phQP = (Char* )xMalloc(Char, uiNumPartition);
130  m_puhDepth = (UChar* )xMalloc(UChar, uiNumPartition);
131  m_puhWidth = (UChar* )xMalloc(UChar, uiNumPartition);
132  m_puhHeight = (UChar* )xMalloc(UChar, uiNumPartition);
133 
134  m_ChromaQpAdj = new UChar[ uiNumPartition ];
135  m_skipFlag = new Bool[ uiNumPartition ];
136  m_pePartSize = new Char[ uiNumPartition ];
137  memset( m_pePartSize, NUMBER_OF_PART_SIZES,uiNumPartition * sizeof( *m_pePartSize ) );
138  m_pePredMode = new Char[ uiNumPartition ];
139  m_CUTransquantBypass = new Bool[ uiNumPartition ];
140 
141  m_pbMergeFlag = (Bool* )xMalloc(Bool, uiNumPartition);
142  m_puhMergeIndex = (UChar* )xMalloc(UChar, uiNumPartition);
143 
144  for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
145  {
146  m_puhIntraDir[ch] = (UChar* )xMalloc(UChar, uiNumPartition);
147  }
148  m_puhInterDir = (UChar* )xMalloc(UChar, uiNumPartition);
149 
150  m_puhTrIdx = (UChar* )xMalloc(UChar, uiNumPartition);
151 
152  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
153  {
154  const RefPicList rpl=RefPicList(i);
155  m_apiMVPIdx[rpl] = new Char[ uiNumPartition ];
156  m_apiMVPNum[rpl] = new Char[ uiNumPartition ];
157  memset( m_apiMVPIdx[rpl], -1,uiNumPartition * sizeof( Char ) );
158  }
159 
160  for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
161  {
162  const ComponentID compID = ComponentID(comp);
163  const UInt chromaShift = getComponentScaleX(compID, chromaFormatIDC) + getComponentScaleY(compID, chromaFormatIDC);
164  const UInt totalSize = (uiWidth * uiHeight) >> chromaShift;
165 
166  m_crossComponentPredictionAlpha[compID] = (Char* )xMalloc(Char, uiNumPartition);
167  m_puhTransformSkip[compID] = (UChar* )xMalloc(UChar, uiNumPartition);
168  m_explicitRdpcmMode[compID] = (UChar* )xMalloc(UChar, uiNumPartition);
169  m_puhCbf[compID] = (UChar* )xMalloc(UChar, uiNumPartition);
170  m_pcTrCoeff[compID] = (TCoeff*)xMalloc(TCoeff, totalSize);
171  memset( m_pcTrCoeff[compID], 0, (totalSize * sizeof( TCoeff )) );
172 
173 #if ADAPTIVE_QP_SELECTION
174  if( bGlobalRMARLBuffer )
175  {
176  if (m_pcGlbArlCoeff[compID] == NULL)
177  {
178  m_pcGlbArlCoeff[compID] = (TCoeff*)xMalloc(TCoeff, totalSize);
179  }
180 
181  m_pcArlCoeff[compID] = m_pcGlbArlCoeff[compID];
183  }
184  else
185  {
186  m_pcArlCoeff[compID] = (TCoeff*)xMalloc(TCoeff, totalSize);
187  }
188 #endif
189  m_pcIPCMSample[compID] = (Pel* )xMalloc(Pel , totalSize);
190  }
191 
192  m_pbIPCMFlag = (Bool* )xMalloc(Bool, uiNumPartition);
193 
194  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
195  {
196  m_acCUMvField[i].create( uiNumPartition );
197  }
198 
199  }
200  else
201  {
202  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
203  {
204  m_acCUMvField[i].setNumPartition(uiNumPartition );
205  }
206  }
207 
208  // create motion vector fields
209 
212  m_pCtuAbove = NULL;
213  m_pCtuLeft = NULL;
214 
215  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
216  {
217  m_apcCUColocated[i] = NULL;
218  }
219 }
220 
222 {
223  // encoder-side buffer free
224  if ( !m_bDecSubCu )
225  {
226  if ( m_phQP )
227  {
228  xFree(m_phQP);
229  m_phQP = NULL;
230  }
231  if ( m_puhDepth )
232  {
233  xFree(m_puhDepth);
234  m_puhDepth = NULL;
235  }
236  if ( m_puhWidth )
237  {
238  xFree(m_puhWidth);
239  m_puhWidth = NULL;
240  }
241  if ( m_puhHeight )
242  {
244  m_puhHeight = NULL;
245  }
246 
247  if ( m_skipFlag )
248  {
249  delete[] m_skipFlag;
250  m_skipFlag = NULL;
251  }
252 
253  if ( m_pePartSize )
254  {
255  delete[] m_pePartSize;
256  m_pePartSize = NULL;
257  }
258  if ( m_pePredMode )
259  {
260  delete[] m_pePredMode;
261  m_pePredMode = NULL;
262  }
263  if ( m_ChromaQpAdj )
264  {
265  delete[] m_ChromaQpAdj;
267  }
268  if ( m_CUTransquantBypass )
269  {
270  delete[] m_CUTransquantBypass;
272  }
273  if ( m_puhInterDir )
274  {
277  }
278  if ( m_pbMergeFlag )
279  {
282  }
283  if ( m_puhMergeIndex )
284  {
287  }
288 
289  for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
290  {
291  xFree(m_puhIntraDir[ch]);
292  m_puhIntraDir[ch] = NULL;
293  }
294 
295  if ( m_puhTrIdx )
296  {
297  xFree(m_puhTrIdx);
298  m_puhTrIdx = NULL;
299  }
300 
301  for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
302  {
304  {
307  }
308  if ( m_puhTransformSkip[comp] )
309  {
310  xFree(m_puhTransformSkip[comp]);
311  m_puhTransformSkip[comp] = NULL;
312  }
313  if ( m_puhCbf[comp] )
314  {
315  xFree(m_puhCbf[comp]);
316  m_puhCbf[comp] = NULL;
317  }
318  if ( m_pcTrCoeff[comp] )
319  {
320  xFree(m_pcTrCoeff[comp]);
321  m_pcTrCoeff[comp] = NULL;
322  }
323  if ( m_explicitRdpcmMode[comp] )
324  {
325  xFree(m_explicitRdpcmMode[comp]);
326  m_explicitRdpcmMode[comp] = NULL;
327  }
328 
329 #if ADAPTIVE_QP_SELECTION
331  {
332  if ( m_pcArlCoeff[comp] )
333  {
334  xFree(m_pcArlCoeff[comp]);
335  m_pcArlCoeff[comp] = NULL;
336  }
337  }
338 
339  if ( m_pcGlbArlCoeff[comp] )
340  {
341  xFree(m_pcGlbArlCoeff[comp]);
342  m_pcGlbArlCoeff[comp] = NULL;
343  }
344 #endif
345 
346  if ( m_pcIPCMSample[comp] )
347  {
348  xFree(m_pcIPCMSample[comp]);
349  m_pcIPCMSample[comp] = NULL;
350  }
351  }
352  if ( m_pbIPCMFlag )
353  {
355  m_pbIPCMFlag = NULL;
356  }
357 
358  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
359  {
360  const RefPicList rpl=RefPicList(i);
361  if ( m_apiMVPIdx[rpl] )
362  {
363  delete[] m_apiMVPIdx[rpl];
364  m_apiMVPIdx[rpl] = NULL;
365  }
366  if ( m_apiMVPNum[rpl] )
367  {
368  delete[] m_apiMVPNum[rpl];
369  m_apiMVPNum[rpl] = NULL;
370  }
371  }
372 
373  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
374  {
375  const RefPicList rpl=RefPicList(i);
376  m_acCUMvField[rpl].destroy();
377  }
378  }
379 
380  m_pcPic = NULL;
381  m_pcSlice = NULL;
382 
385  m_pCtuAbove = NULL;
386  m_pCtuLeft = NULL;
387 
388 
389  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
390  {
391  m_apcCUColocated[i] = NULL;
392  }
393 
394 }
395 
396 Bool TComDataCU::CUIsFromSameTile ( const TComDataCU *pCU /* Can be NULL */) const
397 {
398  return pCU!=NULL &&
399  pCU->getSlice() != NULL &&
401 }
402 
403 Bool TComDataCU::CUIsFromSameSliceAndTile ( const TComDataCU *pCU /* Can be NULL */) const
404 {
405  return pCU!=NULL &&
406  pCU->getSlice() != NULL &&
409  ;
410 }
411 
413 {
414  return CUIsFromSameSliceAndTile(pCU)
416 }
417 
419 {
420  TComPic* pcPic = getPic();
421  TComSlice * pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
422 
423  const UInt picWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
424  const UInt picHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
425  const UInt granularityWidth = g_uiMaxCUWidth;
426 
427  const UInt cuPosX = getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[absPartIdx] ];
428  const UInt cuPosY = getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[absPartIdx] ];
429 
430  return (((cuPosX+getWidth( absPartIdx))%granularityWidth==0||(cuPosX+getWidth( absPartIdx)==picWidth ))
431  && ((cuPosY+getHeight(absPartIdx))%granularityWidth==0||(cuPosY+getHeight(absPartIdx)==picHeight)));
432 }
433 
434 // ====================================================================================================================
435 // Public member functions
436 // ====================================================================================================================
437 
438 // --------------------------------------------------------------------------------------------------------------------
439 // Initialization
440 // --------------------------------------------------------------------------------------------------------------------
441 
448 Void TComDataCU::initCtu( TComPic* pcPic, UInt ctuRsAddr )
449 {
450 
451  m_pcPic = pcPic;
452  m_pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
453  m_ctuRsAddr = ctuRsAddr;
454  m_uiCUPelX = ( ctuRsAddr % pcPic->getFrameWidthInCtus() ) * g_uiMaxCUWidth;
455  m_uiCUPelY = ( ctuRsAddr / pcPic->getFrameWidthInCtus() ) * g_uiMaxCUHeight;
456  m_absZIdxInCtu = 0;
459  m_uiTotalBits = 0;
460  m_uiTotalBins = 0;
462 
463  memset( m_skipFlag , false, m_uiNumPartition * sizeof( *m_skipFlag ) );
464 
467  memset( m_CUTransquantBypass, false, m_uiNumPartition * sizeof( *m_CUTransquantBypass) );
468  memset( m_puhDepth , 0, m_uiNumPartition * sizeof( *m_puhDepth ) );
469  memset( m_puhTrIdx , 0, m_uiNumPartition * sizeof( *m_puhTrIdx ) );
470  memset( m_puhWidth , g_uiMaxCUWidth, m_uiNumPartition * sizeof( *m_puhWidth ) );
471  memset( m_puhHeight , g_uiMaxCUHeight, m_uiNumPartition * sizeof( *m_puhHeight ) );
472  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
473  {
474  const RefPicList rpl=RefPicList(i);
475  memset( m_apiMVPIdx[rpl] , -1, m_uiNumPartition * sizeof( *m_apiMVPIdx[rpl] ) );
476  memset( m_apiMVPNum[rpl] , -1, m_uiNumPartition * sizeof( *m_apiMVPNum[rpl] ) );
477  }
478  memset( m_phQP , getSlice()->getSliceQp(), m_uiNumPartition * sizeof( *m_phQP ) );
479  memset( m_ChromaQpAdj , 0, m_uiNumPartition * sizeof( *m_ChromaQpAdj ) );
480  for(UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
481  {
483  memset( m_puhTransformSkip[comp] , 0, m_uiNumPartition * sizeof( *m_puhTransformSkip[comp]) );
484  memset( m_puhCbf[comp] , 0, m_uiNumPartition * sizeof( *m_puhCbf[comp] ) );
486  }
487  memset( m_pbMergeFlag , false, m_uiNumPartition * sizeof( *m_pbMergeFlag ) );
488  memset( m_puhMergeIndex , 0, m_uiNumPartition * sizeof( *m_puhMergeIndex ) );
489  for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
490  {
491  memset( m_puhIntraDir[ch] , ((ch==0) ? DC_IDX : 0), m_uiNumPartition * sizeof( *(m_puhIntraDir[ch]) ) );
492  }
493  memset( m_puhInterDir , 0, m_uiNumPartition * sizeof( *m_puhInterDir ) );
494  memset( m_pbIPCMFlag , false, m_uiNumPartition * sizeof( *m_pbIPCMFlag ) );
495 
496  const UInt numCoeffY = g_uiMaxCUWidth*g_uiMaxCUHeight;
497  for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
498  {
499  const UInt componentShift = m_pcPic->getComponentScaleX(ComponentID(comp)) + m_pcPic->getComponentScaleY(ComponentID(comp));
500  memset( m_pcTrCoeff[comp], 0, sizeof(TCoeff)* numCoeffY>>componentShift );
501 #if ADAPTIVE_QP_SELECTION
502  memset( m_pcArlCoeff[comp], 0, sizeof(TCoeff)* numCoeffY>>componentShift );
503 #endif
504  }
505 
506  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
507  {
509  }
510 
511  // Setting neighbor CU
512  m_pCtuLeft = NULL;
513  m_pCtuAbove = NULL;
516 
517 
518  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
519  {
520  m_apcCUColocated[i] = NULL;
521  }
522 
523  UInt frameWidthInCtus = pcPic->getFrameWidthInCtus();
524  if ( m_ctuRsAddr % frameWidthInCtus )
525  {
526  m_pCtuLeft = pcPic->getCtu( m_ctuRsAddr - 1 );
527  }
528 
529  if ( m_ctuRsAddr / frameWidthInCtus )
530  {
531  m_pCtuAbove = pcPic->getCtu( m_ctuRsAddr - frameWidthInCtus );
532  }
533 
534  if ( m_pCtuLeft && m_pCtuAbove )
535  {
536  m_pCtuAboveLeft = pcPic->getCtu( m_ctuRsAddr - frameWidthInCtus - 1 );
537  }
538 
539  if ( m_pCtuAbove && ( (m_ctuRsAddr%frameWidthInCtus) < (frameWidthInCtus-1) ) )
540  {
541  m_pCtuAboveRight = pcPic->getCtu( m_ctuRsAddr - frameWidthInCtus + 1 );
542  }
543 
544  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
545  {
546  const RefPicList rpl=RefPicList(i);
547  if ( getSlice()->getNumRefIdx( rpl ) > 0 )
548  {
549  m_apcCUColocated[rpl] = getSlice()->getRefPic( rpl, 0)->getCtu( m_ctuRsAddr );
550  }
551  }
552 }
553 
554 
564 Void TComDataCU::initEstData( const UInt uiDepth, const Int qp, const Bool bTransquantBypass )
565 {
568  m_uiTotalBits = 0;
569  m_uiTotalBins = 0;
570 
571  UChar uhWidth = g_uiMaxCUWidth >> uiDepth;
572  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
573 
574  for (UInt ui = 0; ui < m_uiNumPartition; ui++)
575  {
576  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
577  {
578  const RefPicList rpl=RefPicList(i);
579  m_apiMVPIdx[rpl][ui] = -1;
580  m_apiMVPNum[rpl][ui] = -1;
581  }
582  m_puhDepth [ui] = uiDepth;
583  m_puhWidth [ui] = uhWidth;
584  m_puhHeight [ui] = uhHeight;
585  m_puhTrIdx [ui] = 0;
586  for(UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
587  {
588  m_crossComponentPredictionAlpha[comp][ui] = 0;
589  m_puhTransformSkip [comp][ui] = 0;
591  }
592  m_skipFlag[ui] = false;
595  m_CUTransquantBypass[ui] = bTransquantBypass;
596  m_pbIPCMFlag[ui] = 0;
597  m_phQP[ui] = qp;
598  m_ChromaQpAdj[ui] = 0;
599  m_pbMergeFlag[ui] = 0;
600  m_puhMergeIndex[ui] = 0;
601 
602  for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
603  {
604  m_puhIntraDir[ch][ui] = ((ch==0) ? DC_IDX : 0);
605  }
606 
607  m_puhInterDir[ui] = 0;
608  for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
609  {
610  m_puhCbf[comp][ui] = 0;
611  }
612  }
613 
614  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
615  {
617  }
618 
619  const UInt numCoeffY = uhWidth*uhHeight;
620 
621  for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
622  {
623  const ComponentID component = ComponentID(comp);
624  const UInt numCoeff = numCoeffY >> (getPic()->getComponentScaleX(component) + getPic()->getComponentScaleY(component));
625  memset( m_pcTrCoeff[comp], 0, numCoeff * sizeof( TCoeff ) );
626 #if ADAPTIVE_QP_SELECTION
627  memset( m_pcArlCoeff[comp], 0, numCoeff * sizeof( TCoeff ) );
628 #endif
629  memset( m_pcIPCMSample[comp], 0, numCoeff * sizeof( Pel) );
630  }
631 }
632 
633 
634 // initialize Sub partition
635 Void TComDataCU::initSubCU( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp )
636 {
637  assert( uiPartUnitIdx<4 );
638 
639  UInt uiPartOffset = ( pcCU->getTotalNumPart()>>2 )*uiPartUnitIdx;
640 
641  m_pcPic = pcCU->getPic();
643  m_ctuRsAddr = pcCU->getCtuRsAddr();
644  m_absZIdxInCtu = pcCU->getZorderIdxInCtu() + uiPartOffset;
645 
646  m_uiCUPelX = pcCU->getCUPelX() + ( g_uiMaxCUWidth>>uiDepth )*( uiPartUnitIdx & 1 );
647  m_uiCUPelY = pcCU->getCUPelY() + ( g_uiMaxCUHeight>>uiDepth )*( uiPartUnitIdx >> 1 );
648 
651  m_uiTotalBits = 0;
652  m_uiTotalBins = 0;
653  m_uiNumPartition = pcCU->getTotalNumPart() >> 2;
654 
655  Int iSizeInUchar = sizeof( UChar ) * m_uiNumPartition;
656  Int iSizeInBool = sizeof( Bool ) * m_uiNumPartition;
657  Int sizeInChar = sizeof( Char ) * m_uiNumPartition;
658 
659  memset( m_phQP, qp, sizeInChar );
660  memset( m_pbMergeFlag, 0, iSizeInBool );
661  memset( m_puhMergeIndex, 0, iSizeInUchar );
662  for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
663  {
664  memset( m_puhIntraDir[ch], ((ch==0) ? DC_IDX : 0), iSizeInUchar );
665  }
666 
667  memset( m_puhInterDir, 0, iSizeInUchar );
668  memset( m_puhTrIdx, 0, iSizeInUchar );
669 
670  for(UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
671  {
672  memset( m_crossComponentPredictionAlpha[comp], 0, iSizeInUchar );
673  memset( m_puhTransformSkip[comp], 0, iSizeInUchar );
674  memset( m_puhCbf[comp], 0, iSizeInUchar );
675  memset( m_explicitRdpcmMode[comp], NUMBER_OF_RDPCM_MODES, iSizeInUchar );
676  }
677 
678  memset( m_puhDepth, uiDepth, iSizeInUchar );
679 
680  UChar uhWidth = g_uiMaxCUWidth >> uiDepth;
681  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
682  memset( m_puhWidth, uhWidth, iSizeInUchar );
683  memset( m_puhHeight, uhHeight, iSizeInUchar );
684  memset( m_pbIPCMFlag, 0, iSizeInBool );
685  for (UInt ui = 0; ui < m_uiNumPartition; ui++)
686  {
687  m_skipFlag[ui] = false;
690  m_CUTransquantBypass[ui] = false;
691  m_ChromaQpAdj[ui] = 0;
692 
693  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
694  {
695  const RefPicList rpl=RefPicList(i);
696  m_apiMVPIdx[rpl][ui] = -1;
697  m_apiMVPNum[rpl][ui] = -1;
698  }
699  }
700 
701  const UInt numCoeffY = uhWidth*uhHeight;
702  for (UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
703  {
704  const UInt componentShift = m_pcPic->getComponentScaleX(ComponentID(ch)) + m_pcPic->getComponentScaleY(ComponentID(ch));
705  memset( m_pcTrCoeff[ch], 0, sizeof(TCoeff)*(numCoeffY>>componentShift) );
706 #if ADAPTIVE_QP_SELECTION
707  memset( m_pcArlCoeff[ch], 0, sizeof(TCoeff)*(numCoeffY>>componentShift) );
708 #endif
709  memset( m_pcIPCMSample[ch], 0, sizeof(Pel)* (numCoeffY>>componentShift) );
710  }
711 
712  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
713  {
715  }
716 
717  m_pCtuLeft = pcCU->getCtuLeft();
718  m_pCtuAbove = pcCU->getCtuAbove();
721 
722  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
723  {
725  }
726 }
727 
728 Void TComDataCU::setOutsideCUPart( UInt uiAbsPartIdx, UInt uiDepth )
729 {
730  UInt uiNumPartition = m_uiNumPartition >> (uiDepth << 1);
731  UInt uiSizeInUchar = sizeof( UChar ) * uiNumPartition;
732 
733  UChar uhWidth = g_uiMaxCUWidth >> uiDepth;
734  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
735  memset( m_puhDepth + uiAbsPartIdx, uiDepth, uiSizeInUchar );
736  memset( m_puhWidth + uiAbsPartIdx, uhWidth, uiSizeInUchar );
737  memset( m_puhHeight + uiAbsPartIdx, uhHeight, uiSizeInUchar );
738 }
739 
740 // --------------------------------------------------------------------------------------------------------------------
741 // Copy
742 // --------------------------------------------------------------------------------------------------------------------
743 
744 Void TComDataCU::copySubCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
745 {
746  UInt uiPart = uiAbsPartIdx;
747 
748  m_pcPic = pcCU->getPic();
749  m_pcSlice = pcCU->getSlice();
750  m_ctuRsAddr = pcCU->getCtuRsAddr();
751  m_absZIdxInCtu = uiAbsPartIdx;
752 
753  m_uiCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
754  m_uiCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
755 
756  m_skipFlag=pcCU->getSkipFlag() + uiPart;
757 
758  m_phQP=pcCU->getQP() + uiPart;
759  m_ChromaQpAdj = pcCU->getChromaQpAdj() + uiPart;
760  m_pePartSize = pcCU->getPartitionSize() + uiPart;
761  m_pePredMode=pcCU->getPredictionMode() + uiPart;
763 
764  m_pbMergeFlag = pcCU->getMergeFlag() + uiPart;
765  m_puhMergeIndex = pcCU->getMergeIndex() + uiPart;
766 
767  for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
768  {
769  m_puhIntraDir[ch] = pcCU->getIntraDir(ChannelType(ch)) + uiPart;
770  }
771 
772  m_puhInterDir = pcCU->getInterDir() + uiPart;
773  m_puhTrIdx = pcCU->getTransformIdx() + uiPart;
774 
775  for(UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
776  {
778  m_puhTransformSkip[comp] = pcCU->getTransformSkip(ComponentID(comp)) + uiPart;
779  m_puhCbf[comp] = pcCU->getCbf(ComponentID(comp)) + uiPart;
780  m_explicitRdpcmMode[comp] = pcCU->getExplicitRdpcmMode(ComponentID(comp)) + uiPart;
781  }
782 
783  m_puhDepth=pcCU->getDepth() + uiPart;
784  m_puhWidth=pcCU->getWidth() + uiPart;
785  m_puhHeight=pcCU->getHeight() + uiPart;
786 
787  m_pbIPCMFlag = pcCU->getIPCMFlag() + uiPart;
788 
791  m_pCtuAbove = pcCU->getCtuAbove();
792  m_pCtuLeft = pcCU->getCtuLeft();
793 
794  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
795  {
796  const RefPicList rpl=RefPicList(i);
797  m_apcCUColocated[rpl] = pcCU->getCUColocated(rpl);
798  m_apiMVPIdx[rpl]=pcCU->getMVPIdx(rpl) + uiPart;
799  m_apiMVPNum[rpl]=pcCU->getMVPNum(rpl) + uiPart;
800  }
801 
802  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
803  {
804  const RefPicList rpl=RefPicList(i);
805  m_acCUMvField[rpl].linkToWithOffset( pcCU->getCUMvField(rpl), uiPart );
806  }
807 
808  UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
809  UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
810 
811  UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*uiAbsPartIdx/pcCU->getPic()->getNumPartitionsInCtu();
812 
813  for (UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
814  {
815  const ComponentID component = ComponentID(ch);
816  const UInt componentShift = m_pcPic->getComponentScaleX(component) + m_pcPic->getComponentScaleY(component);
817  const UInt offset = uiCoffOffset >> componentShift;
818  m_pcTrCoeff[ch] = pcCU->getCoeff(component) + offset;
819 #if ADAPTIVE_QP_SELECTION
820  m_pcArlCoeff[ch] = pcCU->getArlCoeff(component) + offset;
821 #endif
822  m_pcIPCMSample[ch] = pcCU->getPCMSample(component) + offset;
823  }
824 }
825 
826 // Copy inter prediction info from the biggest CU
828 {
829  m_pcPic = pcCU->getPic();
830  m_pcSlice = pcCU->getSlice();
831  m_ctuRsAddr = pcCU->getCtuRsAddr();
832  m_absZIdxInCtu = uiAbsPartIdx;
833 
834  Int iRastPartIdx = g_auiZscanToRaster[uiAbsPartIdx];
835  m_uiCUPelX = pcCU->getCUPelX() + m_pcPic->getMinCUWidth ()*( iRastPartIdx % m_pcPic->getNumPartInCtuWidth() );
836  m_uiCUPelY = pcCU->getCUPelY() + m_pcPic->getMinCUHeight()*( iRastPartIdx / m_pcPic->getNumPartInCtuWidth() );
837 
840  m_pCtuAbove = pcCU->getCtuAbove();
841  m_pCtuLeft = pcCU->getCtuLeft();
842 
843  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
844  {
846  }
847 
848  m_skipFlag = pcCU->getSkipFlag () + uiAbsPartIdx;
849 
850  m_pePartSize = pcCU->getPartitionSize () + uiAbsPartIdx;
851  m_pePredMode = pcCU->getPredictionMode() + uiAbsPartIdx;
852  m_ChromaQpAdj = pcCU->getChromaQpAdj() + uiAbsPartIdx;
853  m_CUTransquantBypass = pcCU->getCUTransquantBypass() + uiAbsPartIdx;
854  m_puhInterDir = pcCU->getInterDir () + uiAbsPartIdx;
855 
856  m_puhDepth = pcCU->getDepth () + uiAbsPartIdx;
857  m_puhWidth = pcCU->getWidth () + uiAbsPartIdx;
858  m_puhHeight = pcCU->getHeight() + uiAbsPartIdx;
859 
860  m_pbMergeFlag = pcCU->getMergeFlag() + uiAbsPartIdx;
861  m_puhMergeIndex = pcCU->getMergeIndex() + uiAbsPartIdx;
862 
863  m_apiMVPIdx[eRefPicList] = pcCU->getMVPIdx(eRefPicList) + uiAbsPartIdx;
864  m_apiMVPNum[eRefPicList] = pcCU->getMVPNum(eRefPicList) + uiAbsPartIdx;
865 
866  m_acCUMvField[ eRefPicList ].linkToWithOffset( pcCU->getCUMvField(eRefPicList), uiAbsPartIdx );
867 }
868 
869 // Copy small CU to bigger CU.
870 // One of quarter parts overwritten by predicted sub part.
871 Void TComDataCU::copyPartFrom( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth )
872 {
873  assert( uiPartUnitIdx<4 );
874 
875  m_dTotalCost += pcCU->getTotalCost();
877  m_uiTotalBits += pcCU->getTotalBits();
878 
879  UInt uiOffset = pcCU->getTotalNumPart()*uiPartUnitIdx;
880  const UInt numValidComp=pcCU->getPic()->getNumberValidComponents();
881  const UInt numValidChan=pcCU->getPic()->getChromaFormat()==CHROMA_400 ? 1:2;
882 
883  UInt uiNumPartition = pcCU->getTotalNumPart();
884  Int iSizeInUchar = sizeof( UChar ) * uiNumPartition;
885  Int iSizeInBool = sizeof( Bool ) * uiNumPartition;
886 
887  Int sizeInChar = sizeof( Char ) * uiNumPartition;
888  memcpy( m_skipFlag + uiOffset, pcCU->getSkipFlag(), sizeof( *m_skipFlag ) * uiNumPartition );
889  memcpy( m_phQP + uiOffset, pcCU->getQP(), sizeInChar );
890  memcpy( m_pePartSize + uiOffset, pcCU->getPartitionSize(), sizeof( *m_pePartSize ) * uiNumPartition );
891  memcpy( m_pePredMode + uiOffset, pcCU->getPredictionMode(), sizeof( *m_pePredMode ) * uiNumPartition );
892  memcpy( m_ChromaQpAdj + uiOffset, pcCU->getChromaQpAdj(), sizeof( *m_ChromaQpAdj ) * uiNumPartition );
893  memcpy( m_CUTransquantBypass + uiOffset, pcCU->getCUTransquantBypass(), sizeof( *m_CUTransquantBypass ) * uiNumPartition );
894  memcpy( m_pbMergeFlag + uiOffset, pcCU->getMergeFlag(), iSizeInBool );
895  memcpy( m_puhMergeIndex + uiOffset, pcCU->getMergeIndex(), iSizeInUchar );
896 
897  for (UInt ch=0; ch<numValidChan; ch++)
898  {
899  memcpy( m_puhIntraDir[ch] + uiOffset, pcCU->getIntraDir(ChannelType(ch)), iSizeInUchar );
900  }
901 
902  memcpy( m_puhInterDir + uiOffset, pcCU->getInterDir(), iSizeInUchar );
903  memcpy( m_puhTrIdx + uiOffset, pcCU->getTransformIdx(), iSizeInUchar );
904 
905  for(UInt comp=0; comp<numValidComp; comp++)
906  {
907  memcpy( m_crossComponentPredictionAlpha[comp] + uiOffset, pcCU->getCrossComponentPredictionAlpha(ComponentID(comp)), iSizeInUchar );
908  memcpy( m_puhTransformSkip[comp] + uiOffset, pcCU->getTransformSkip(ComponentID(comp)) , iSizeInUchar );
909  memcpy( m_puhCbf[comp] + uiOffset, pcCU->getCbf(ComponentID(comp)) , iSizeInUchar );
910  memcpy( m_explicitRdpcmMode[comp] + uiOffset, pcCU->getExplicitRdpcmMode(ComponentID(comp)) , iSizeInUchar );
911  }
912 
913  memcpy( m_puhDepth + uiOffset, pcCU->getDepth(), iSizeInUchar );
914  memcpy( m_puhWidth + uiOffset, pcCU->getWidth(), iSizeInUchar );
915  memcpy( m_puhHeight + uiOffset, pcCU->getHeight(), iSizeInUchar );
916 
917  memcpy( m_pbIPCMFlag + uiOffset, pcCU->getIPCMFlag(), iSizeInBool );
918 
921  m_pCtuAbove = pcCU->getCtuAbove();
922  m_pCtuLeft = pcCU->getCtuLeft();
923 
924  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
925  {
926  const RefPicList rpl=RefPicList(i);
927  memcpy( m_apiMVPIdx[rpl] + uiOffset, pcCU->getMVPIdx(rpl), iSizeInUchar );
928  memcpy( m_apiMVPNum[rpl] + uiOffset, pcCU->getMVPNum(rpl), iSizeInUchar );
929  m_apcCUColocated[rpl] = pcCU->getCUColocated(rpl);
930  }
931 
932  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
933  {
934  const RefPicList rpl=RefPicList(i);
935  m_acCUMvField[rpl].copyFrom( pcCU->getCUMvField( rpl ), pcCU->getTotalNumPart(), uiOffset );
936  }
937 
938  const UInt numCoeffY = g_uiMaxCUWidth*g_uiMaxCUHeight >> (uiDepth<<1);
939  const UInt offsetY = uiPartUnitIdx*numCoeffY;
940  for (UInt ch=0; ch<numValidComp; ch++)
941  {
942  const ComponentID component = ComponentID(ch);
943  const UInt componentShift = m_pcPic->getComponentScaleX(component) + m_pcPic->getComponentScaleY(component);
944  const UInt offset = offsetY>>componentShift;
945  memcpy( m_pcTrCoeff [ch] + offset, pcCU->getCoeff(component), sizeof(TCoeff)*(numCoeffY>>componentShift) );
946 #if ADAPTIVE_QP_SELECTION
947  memcpy( m_pcArlCoeff[ch] + offset, pcCU->getArlCoeff(component), sizeof(TCoeff)*(numCoeffY>>componentShift) );
948 #endif
949  memcpy( m_pcIPCMSample[ch] + offset, pcCU->getPCMSample(component), sizeof(Pel)*(numCoeffY>>componentShift) );
950  }
951 
952  m_uiTotalBins += pcCU->getTotalBins();
953 }
954 
955 // Copy current predicted part to a CU in picture.
956 // It is used to predict for next part
958 {
959  TComDataCU* pCtu = m_pcPic->getCtu( m_ctuRsAddr );
960  const UInt numValidComp=pCtu->getPic()->getNumberValidComponents();
961  const UInt numValidChan=pCtu->getPic()->getChromaFormat()==CHROMA_400 ? 1:2;
962 
963  pCtu->getTotalCost() = m_dTotalCost;
965  pCtu->getTotalBits() = m_uiTotalBits;
966 
967  Int iSizeInUchar = sizeof( UChar ) * m_uiNumPartition;
968  Int iSizeInBool = sizeof( Bool ) * m_uiNumPartition;
969  Int sizeInChar = sizeof( Char ) * m_uiNumPartition;
970 
971  memcpy( pCtu->getSkipFlag() + m_absZIdxInCtu, m_skipFlag, sizeof( *m_skipFlag ) * m_uiNumPartition );
972 
973  memcpy( pCtu->getQP() + m_absZIdxInCtu, m_phQP, sizeInChar );
974 
975  memcpy( pCtu->getPartitionSize() + m_absZIdxInCtu, m_pePartSize, sizeof( *m_pePartSize ) * m_uiNumPartition );
976  memcpy( pCtu->getPredictionMode() + m_absZIdxInCtu, m_pePredMode, sizeof( *m_pePredMode ) * m_uiNumPartition );
977  memcpy( pCtu->getChromaQpAdj() + m_absZIdxInCtu, m_ChromaQpAdj, sizeof( *m_ChromaQpAdj ) * m_uiNumPartition );
978  memcpy( pCtu->getCUTransquantBypass()+ m_absZIdxInCtu, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * m_uiNumPartition );
979  memcpy( pCtu->getMergeFlag() + m_absZIdxInCtu, m_pbMergeFlag, iSizeInBool );
980  memcpy( pCtu->getMergeIndex() + m_absZIdxInCtu, m_puhMergeIndex, iSizeInUchar );
981  for (UInt ch=0; ch<numValidChan; ch++)
982  {
983  memcpy( pCtu->getIntraDir(ChannelType(ch)) + m_absZIdxInCtu, m_puhIntraDir[ch], iSizeInUchar);
984  }
985 
986  memcpy( pCtu->getInterDir() + m_absZIdxInCtu, m_puhInterDir, iSizeInUchar );
987  memcpy( pCtu->getTransformIdx() + m_absZIdxInCtu, m_puhTrIdx, iSizeInUchar );
988 
989  for(UInt comp=0; comp<numValidComp; comp++)
990  {
992  memcpy( pCtu->getTransformSkip(ComponentID(comp)) + m_absZIdxInCtu, m_puhTransformSkip[comp], iSizeInUchar );
993  memcpy( pCtu->getCbf(ComponentID(comp)) + m_absZIdxInCtu, m_puhCbf[comp], iSizeInUchar );
994  memcpy( pCtu->getExplicitRdpcmMode(ComponentID(comp)) + m_absZIdxInCtu, m_explicitRdpcmMode[comp], iSizeInUchar );
995  }
996 
997  memcpy( pCtu->getDepth() + m_absZIdxInCtu, m_puhDepth, iSizeInUchar );
998  memcpy( pCtu->getWidth() + m_absZIdxInCtu, m_puhWidth, iSizeInUchar );
999  memcpy( pCtu->getHeight() + m_absZIdxInCtu, m_puhHeight, iSizeInUchar );
1000 
1001  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
1002  {
1003  const RefPicList rpl=RefPicList(i);
1004  memcpy( pCtu->getMVPIdx(rpl) + m_absZIdxInCtu, m_apiMVPIdx[rpl], iSizeInUchar );
1005  memcpy( pCtu->getMVPNum(rpl) + m_absZIdxInCtu, m_apiMVPNum[rpl], iSizeInUchar );
1006  }
1007 
1008  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
1009  {
1010  const RefPicList rpl=RefPicList(i);
1011  m_acCUMvField[rpl].copyTo( pCtu->getCUMvField( rpl ), m_absZIdxInCtu );
1012  }
1013 
1014  memcpy( pCtu->getIPCMFlag() + m_absZIdxInCtu, m_pbIPCMFlag, iSizeInBool );
1015 
1016  const UInt numCoeffY = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>(uhDepth<<1);
1018  for (UInt comp=0; comp<numValidComp; comp++)
1019  {
1020  const ComponentID component = ComponentID(comp);
1021  const UInt componentShift = m_pcPic->getComponentScaleX(component) + m_pcPic->getComponentScaleY(component);
1022  memcpy( pCtu->getCoeff(component) + (offsetY>>componentShift), m_pcTrCoeff[component], sizeof(TCoeff)*(numCoeffY>>componentShift) );
1023 #if ADAPTIVE_QP_SELECTION
1024  memcpy( pCtu->getArlCoeff(component) + (offsetY>>componentShift), m_pcArlCoeff[component], sizeof(TCoeff)*(numCoeffY>>componentShift) );
1025 #endif
1026  memcpy( pCtu->getPCMSample(component) + (offsetY>>componentShift), m_pcIPCMSample[component], sizeof(Pel)*(numCoeffY>>componentShift) );
1027  }
1028 
1029  pCtu->getTotalBins() = m_uiTotalBins;
1030 }
1031 
1032 // --------------------------------------------------------------------------------------------------------------------
1033 // Other public functions
1034 // --------------------------------------------------------------------------------------------------------------------
1035 
1037  UInt uiCurrPartUnitIdx,
1038  Bool bEnforceSliceRestriction,
1039  Bool bEnforceTileRestriction )
1040 {
1041  UInt uiAbsPartIdx = g_auiZscanToRaster[uiCurrPartUnitIdx];
1042  UInt uiAbsZorderCUIdx = g_auiZscanToRaster[m_absZIdxInCtu];
1043  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
1044 
1045  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, numPartInCtuWidth ) )
1046  {
1047  uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
1048  if ( RasterAddress::isEqualCol( uiAbsPartIdx, uiAbsZorderCUIdx, numPartInCtuWidth ) )
1049  {
1050  return m_pcPic->getCtu( getCtuRsAddr() );
1051  }
1052  else
1053  {
1054  uiLPartUnitIdx -= m_absZIdxInCtu;
1055  return this;
1056  }
1057  }
1058 
1059  uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + numPartInCtuWidth - 1 ];
1060  if ( (bEnforceSliceRestriction && !CUIsFromSameSlice(m_pCtuLeft)) || (bEnforceTileRestriction && !CUIsFromSameTile(m_pCtuLeft)) )
1061  {
1062  return NULL;
1063  }
1064  return m_pCtuLeft;
1065 }
1066 
1067 
1069  UInt uiCurrPartUnitIdx,
1070  Bool bEnforceSliceRestriction,
1071  Bool planarAtCtuBoundary,
1072  Bool bEnforceTileRestriction )
1073 {
1074  UInt uiAbsPartIdx = g_auiZscanToRaster[uiCurrPartUnitIdx];
1075  UInt uiAbsZorderCUIdx = g_auiZscanToRaster[m_absZIdxInCtu];
1076  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
1077 
1078  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, numPartInCtuWidth ) )
1079  {
1080  uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - numPartInCtuWidth ];
1081  if ( RasterAddress::isEqualRow( uiAbsPartIdx, uiAbsZorderCUIdx, numPartInCtuWidth ) )
1082  {
1083  return m_pcPic->getCtu( getCtuRsAddr() );
1084  }
1085  else
1086  {
1087  uiAPartUnitIdx -= m_absZIdxInCtu;
1088  return this;
1089  }
1090  }
1091 
1092  if(planarAtCtuBoundary)
1093  {
1094  return NULL;
1095  }
1096 
1097  uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + m_pcPic->getNumPartitionsInCtu() - numPartInCtuWidth ];
1098 
1099  if ( (bEnforceSliceRestriction && !CUIsFromSameSlice(m_pCtuAbove)) || (bEnforceTileRestriction && !CUIsFromSameTile(m_pCtuAbove)) )
1100  {
1101  return NULL;
1102  }
1103  return m_pCtuAbove;
1104 }
1105 
1106 TComDataCU* TComDataCU::getPUAboveLeft( UInt& uiALPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1107 {
1108  UInt uiAbsPartIdx = g_auiZscanToRaster[uiCurrPartUnitIdx];
1109  UInt uiAbsZorderCUIdx = g_auiZscanToRaster[m_absZIdxInCtu];
1110  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
1111 
1112  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, numPartInCtuWidth ) )
1113  {
1114  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, numPartInCtuWidth ) )
1115  {
1116  uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - numPartInCtuWidth - 1 ];
1117  if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdx, uiAbsZorderCUIdx, numPartInCtuWidth ) )
1118  {
1119  return m_pcPic->getCtu( getCtuRsAddr() );
1120  }
1121  else
1122  {
1123  uiALPartUnitIdx -= m_absZIdxInCtu;
1124  return this;
1125  }
1126  }
1127  uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + getPic()->getNumPartitionsInCtu() - numPartInCtuWidth - 1 ];
1128  if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuAbove) )
1129  {
1130  return NULL;
1131  }
1132  return m_pCtuAbove;
1133  }
1134 
1135  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, numPartInCtuWidth ) )
1136  {
1137  uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
1138  if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuLeft) )
1139  {
1140  return NULL;
1141  }
1142  return m_pCtuLeft;
1143  }
1144 
1145  uiALPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartitionsInCtu() - 1 ];
1146  if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuAboveLeft) )
1147  {
1148  return NULL;
1149  }
1150  return m_pCtuAboveLeft;
1151 }
1152 
1153 TComDataCU* TComDataCU::getPUAboveRight( UInt& uiARPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1154 {
1155  UInt uiAbsPartIdxRT = g_auiZscanToRaster[uiCurrPartUnitIdx];
1156  UInt uiAbsZorderCUIdx = g_auiZscanToRaster[ m_absZIdxInCtu ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1;
1157  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
1158 
1160  {
1161  uiARPartUnitIdx = MAX_UINT;
1162  return NULL;
1163  }
1164 
1165  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, numPartInCtuWidth - 1, numPartInCtuWidth ) )
1166  {
1167  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, numPartInCtuWidth ) )
1168  {
1169  if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - numPartInCtuWidth + 1 ] )
1170  {
1171  uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - numPartInCtuWidth + 1 ];
1172  if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, numPartInCtuWidth ) )
1173  {
1174  return m_pcPic->getCtu( getCtuRsAddr() );
1175  }
1176  else
1177  {
1178  uiARPartUnitIdx -= m_absZIdxInCtu;
1179  return this;
1180  }
1181  }
1182  uiARPartUnitIdx = MAX_UINT;
1183  return NULL;
1184  }
1185  uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartitionsInCtu() - numPartInCtuWidth + 1 ];
1186 
1187  if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuAbove) )
1188  {
1189  return NULL;
1190  }
1191  return m_pCtuAbove;
1192  }
1193 
1194  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, numPartInCtuWidth ) )
1195  {
1196  uiARPartUnitIdx = MAX_UINT;
1197  return NULL;
1198  }
1199 
1200  uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartitionsInCtu() - numPartInCtuWidth ];
1201 
1202  if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuAboveRight) )
1203  {
1204  return NULL;
1205  }
1206  return m_pCtuAboveRight;
1207 }
1208 
1209 TComDataCU* TComDataCU::getPUBelowLeft( UInt& uiBLPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1210 {
1211  UInt uiAbsPartIdxLB = g_auiZscanToRaster[uiCurrPartUnitIdx];
1212  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
1213  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_absZIdxInCtu ] + (m_puhHeight[0] / m_pcPic->getMinCUHeight() - 1)*numPartInCtuWidth;
1214 
1216  {
1217  uiBLPartUnitIdx = MAX_UINT;
1218  return NULL;
1219  }
1220 
1221  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInCtuHeight() - 1, numPartInCtuWidth ) )
1222  {
1223  if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, numPartInCtuWidth ) )
1224  {
1225  if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + numPartInCtuWidth - 1 ] )
1226  {
1227  uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + numPartInCtuWidth - 1 ];
1228  if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, numPartInCtuWidth ) )
1229  {
1230  return m_pcPic->getCtu( getCtuRsAddr() );
1231  }
1232  else
1233  {
1234  uiBLPartUnitIdx -= m_absZIdxInCtu;
1235  return this;
1236  }
1237  }
1238  uiBLPartUnitIdx = MAX_UINT;
1239  return NULL;
1240  }
1241  uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + numPartInCtuWidth*2 - 1 ];
1242  if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuLeft) )
1243  {
1244  return NULL;
1245  }
1246  return m_pCtuLeft;
1247  }
1248 
1249  uiBLPartUnitIdx = MAX_UINT;
1250  return NULL;
1251 }
1252 
1253 TComDataCU* TComDataCU::getPUBelowLeftAdi(UInt& uiBLPartUnitIdx, UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction)
1254 {
1255  UInt uiAbsPartIdxLB = g_auiZscanToRaster[uiCurrPartUnitIdx];
1256  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
1257  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_absZIdxInCtu ] + ((m_puhHeight[0] / m_pcPic->getMinCUHeight()) - 1)*numPartInCtuWidth;
1258 
1259  if( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples())
1260  {
1261  uiBLPartUnitIdx = MAX_UINT;
1262  return NULL;
1263  }
1264 
1265  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInCtuHeight() - uiPartUnitOffset, numPartInCtuWidth ) )
1266  {
1267  if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, numPartInCtuWidth ) )
1268  {
1269  if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * numPartInCtuWidth - 1 ] )
1270  {
1271  uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * numPartInCtuWidth - 1 ];
1272  if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, numPartInCtuWidth ) )
1273  {
1274  return m_pcPic->getCtu( getCtuRsAddr() );
1275  }
1276  else
1277  {
1278  uiBLPartUnitIdx -= m_absZIdxInCtu;
1279  return this;
1280  }
1281  }
1282  uiBLPartUnitIdx = MAX_UINT;
1283  return NULL;
1284  }
1285  uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + (1+uiPartUnitOffset) * numPartInCtuWidth - 1 ];
1286  if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuLeft) )
1287  {
1288  return NULL;
1289  }
1290  return m_pCtuLeft;
1291  }
1292 
1293  uiBLPartUnitIdx = MAX_UINT;
1294  return NULL;
1295 }
1296 
1297 TComDataCU* TComDataCU::getPUAboveRightAdi(UInt& uiARPartUnitIdx, UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction)
1298 {
1299  UInt uiAbsPartIdxRT = g_auiZscanToRaster[uiCurrPartUnitIdx];
1300  UInt uiAbsZorderCUIdx = g_auiZscanToRaster[ m_absZIdxInCtu ] + (m_puhWidth[0] / m_pcPic->getMinCUWidth()) - 1;
1301  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
1302 
1303  if( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
1304  {
1305  uiARPartUnitIdx = MAX_UINT;
1306  return NULL;
1307  }
1308 
1309  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, numPartInCtuWidth - uiPartUnitOffset, numPartInCtuWidth ) )
1310  {
1311  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, numPartInCtuWidth ) )
1312  {
1313  if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - numPartInCtuWidth + uiPartUnitOffset ] )
1314  {
1315  uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - numPartInCtuWidth + uiPartUnitOffset ];
1316  if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, numPartInCtuWidth ) )
1317  {
1318  return m_pcPic->getCtu( getCtuRsAddr() );
1319  }
1320  else
1321  {
1322  uiARPartUnitIdx -= m_absZIdxInCtu;
1323  return this;
1324  }
1325  }
1326  uiARPartUnitIdx = MAX_UINT;
1327  return NULL;
1328  }
1329 
1330  uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartitionsInCtu() - numPartInCtuWidth + uiPartUnitOffset ];
1331  if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuAbove) )
1332  {
1333  return NULL;
1334  }
1335  return m_pCtuAbove;
1336  }
1337 
1338  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, numPartInCtuWidth ) )
1339  {
1340  uiARPartUnitIdx = MAX_UINT;
1341  return NULL;
1342  }
1343 
1344  uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartitionsInCtu() - numPartInCtuWidth + uiPartUnitOffset-1 ];
1345  if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuAboveRight) )
1346  {
1347  return NULL;
1348  }
1349  return m_pCtuAboveRight;
1350 }
1351 
1357 TComDataCU* TComDataCU::getQpMinCuLeft( UInt& uiLPartUnitIdx, UInt uiCurrAbsIdxInCtu )
1358 {
1359  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
1360  UInt absZorderQpMinCUIdx = (uiCurrAbsIdxInCtu>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth -getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
1361  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
1362 
1363  // check for left CTU boundary
1364  if ( RasterAddress::isZeroCol(absRorderQpMinCUIdx, numPartInCtuWidth) )
1365  {
1366  return NULL;
1367  }
1368 
1369  // get index of left-CU relative to top-left corner of current quantization group
1370  uiLPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - 1];
1371 
1372  // return pointer to current CTU
1373  return m_pcPic->getCtu( getCtuRsAddr() );
1374 }
1375 
1381 TComDataCU* TComDataCU::getQpMinCuAbove( UInt& uiAPartUnitIdx, UInt uiCurrAbsIdxInCtu )
1382 {
1383  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
1384  UInt absZorderQpMinCUIdx = (uiCurrAbsIdxInCtu>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
1385  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
1386 
1387  // check for top CTU boundary
1388  if ( RasterAddress::isZeroRow( absRorderQpMinCUIdx, numPartInCtuWidth) )
1389  {
1390  return NULL;
1391  }
1392 
1393  // get index of top-CU relative to top-left corner of current quantization group
1394  uiAPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - numPartInCtuWidth];
1395 
1396  // return pointer to current CTU
1397  return m_pcPic->getCtu( getCtuRsAddr() );
1398 }
1399 
1400 
1401 
1406 Char TComDataCU::getRefQP( UInt uiCurrAbsIdxInCtu )
1407 {
1408  UInt lPartIdx = MAX_UINT;
1409  UInt aPartIdx = MAX_UINT;
1410  TComDataCU* cULeft = getQpMinCuLeft ( lPartIdx, m_absZIdxInCtu + uiCurrAbsIdxInCtu );
1411  TComDataCU* cUAbove = getQpMinCuAbove( aPartIdx, m_absZIdxInCtu + uiCurrAbsIdxInCtu );
1412  return (((cULeft? cULeft->getQP( lPartIdx ): getLastCodedQP( uiCurrAbsIdxInCtu )) + (cUAbove? cUAbove->getQP( aPartIdx ): getLastCodedQP( uiCurrAbsIdxInCtu )) + 1) >> 1);
1413 }
1414 
1416 {
1417  Int iLastValidPartIdx = iAbsPartIdx-1;
1418  while ( iLastValidPartIdx >= 0
1419  && getPredictionMode( iLastValidPartIdx ) == NUMBER_OF_PREDICTION_MODES )
1420  {
1421  UInt uiDepth = getDepth( iLastValidPartIdx );
1422  iLastValidPartIdx -= m_uiNumPartition>>(uiDepth<<1);
1423  }
1424  return iLastValidPartIdx;
1425 }
1426 
1428 {
1429  UInt uiQUPartIdxMask = ~((1<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))-1);
1430  Int iLastValidPartIdx = getLastValidPartIdx( uiAbsPartIdx&uiQUPartIdxMask ); // A idx will be invalid if it is off the right or bottom edge of the picture.
1431  // If this CU is in the first CTU of the slice and there is no valid part before this one, use slice QP
1432  if ( getPic()->getPicSym()->getCtuTsToRsAddrMap(getSlice()->getSliceCurStartCtuTsAddr()) == getCtuRsAddr() && Int(getZorderIdxInCtu())+iLastValidPartIdx<0)
1433  {
1434  return getSlice()->getSliceQp();
1435  }
1436  else if ( iLastValidPartIdx >= 0 )
1437  {
1438  // If there is a valid part within the current Sub-CU, use it
1439  return getQP( iLastValidPartIdx );
1440  }
1441  else
1442  {
1443  if ( getZorderIdxInCtu() > 0 )
1444  {
1445  // If this wasn't the first sub-cu within the Ctu, explore the CTU itself.
1446  return getPic()->getCtu( getCtuRsAddr() )->getLastCodedQP( getZorderIdxInCtu() ); // TODO - remove this recursion
1447  }
1448  else if ( getPic()->getPicSym()->getCtuRsToTsAddrMap(getCtuRsAddr()) > 0
1449  && CUIsFromSameSliceTileAndWavefrontRow(getPic()->getCtu(getPic()->getPicSym()->getCtuTsToRsAddrMap(getPic()->getPicSym()->getCtuRsToTsAddrMap(getCtuRsAddr())-1))) )
1450  {
1451  // If this isn't the first Ctu (how can it be due to the first 'if'?), and the previous Ctu is from the same tile, examine the previous Ctu.
1452  return getPic()->getCtu( getPic()->getPicSym()->getCtuTsToRsAddrMap(getPic()->getPicSym()->getCtuRsToTsAddrMap(getCtuRsAddr())-1) )->getLastCodedQP( getPic()->getNumPartitionsInCtu() ); // TODO - remove this recursion
1453  }
1454  else
1455  {
1456  // No other options available - use the slice-level QP.
1457  return getSlice()->getSliceQp();
1458  }
1459  }
1460 }
1461 
1462 
1468 {
1469  return (getSlice()->getPPS()->getTransquantBypassEnableFlag() && getCUTransquantBypass (absPartIdx));
1470 }
1471 
1472 
1480 {
1481  uiModeList[0] = PLANAR_IDX;
1482  uiModeList[1] = VER_IDX;
1483  uiModeList[2] = HOR_IDX;
1484  uiModeList[3] = DC_IDX;
1485  uiModeList[4] = DM_CHROMA_IDX;
1486  assert(4<NUM_CHROMA_MODE);
1487 
1488  UInt uiLumaMode = getIntraDir( CHANNEL_TYPE_LUMA, uiAbsPartIdx );
1489 
1490  for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ )
1491  {
1492  if( uiLumaMode == uiModeList[i] )
1493  {
1494  uiModeList[i] = 34; // VER+8 mode
1495  break;
1496  }
1497  }
1498 }
1499 
1507 Void TComDataCU::getIntraDirPredictor( UInt uiAbsPartIdx, Int uiIntraDirPred[NUM_MOST_PROBABLE_MODES], const ComponentID compID, Int* piMode )
1508 {
1509  TComDataCU* pcCULeft, *pcCUAbove;
1510  UInt LeftPartIdx = MAX_UINT;
1511  UInt AbovePartIdx = MAX_UINT;
1512  Int iLeftIntraDir, iAboveIntraDir;
1513 
1514  const ChannelType chType = toChannelType(compID);
1515  const ChromaFormat chForm = getPic()->getChromaFormat();
1516  // Get intra direction of left PU
1517  pcCULeft = getPULeft( LeftPartIdx, m_absZIdxInCtu + uiAbsPartIdx );
1518 
1519  if (isChroma(compID))
1520  {
1521  LeftPartIdx = getChromasCorrespondingPULumaIdx(LeftPartIdx, chForm);
1522  }
1523  iLeftIntraDir = pcCULeft ? ( pcCULeft->isIntra( LeftPartIdx ) ? pcCULeft->getIntraDir( chType, LeftPartIdx ) : DC_IDX ) : DC_IDX;
1524 
1525  // Get intra direction of above PU
1526  pcCUAbove = getPUAbove( AbovePartIdx, m_absZIdxInCtu + uiAbsPartIdx, true, true );
1527 
1528  if (isChroma(compID))
1529  {
1530  AbovePartIdx = getChromasCorrespondingPULumaIdx(AbovePartIdx, chForm);
1531  }
1532  iAboveIntraDir = pcCUAbove ? ( pcCUAbove->isIntra( AbovePartIdx ) ? pcCUAbove->getIntraDir( chType, AbovePartIdx ) : DC_IDX ) : DC_IDX;
1533 
1534  if (isChroma(chType))
1535  {
1536  if (iLeftIntraDir == DM_CHROMA_IDX)
1537  {
1538  iLeftIntraDir = pcCULeft-> getIntraDir( CHANNEL_TYPE_LUMA, LeftPartIdx );
1539  }
1540  if (iAboveIntraDir == DM_CHROMA_IDX)
1541  {
1542  iAboveIntraDir = pcCUAbove->getIntraDir( CHANNEL_TYPE_LUMA, AbovePartIdx );
1543  }
1544  }
1545 
1546  assert (2<NUM_MOST_PROBABLE_MODES);
1547  if(iLeftIntraDir == iAboveIntraDir)
1548  {
1549  if( piMode )
1550  {
1551  *piMode = 1;
1552  }
1553 
1554  if (iLeftIntraDir > 1) // angular modes
1555  {
1556  uiIntraDirPred[0] = iLeftIntraDir;
1557  uiIntraDirPred[1] = ((iLeftIntraDir + 29) % 32) + 2;
1558  uiIntraDirPred[2] = ((iLeftIntraDir - 1 ) % 32) + 2;
1559  }
1560  else //non-angular
1561  {
1562  uiIntraDirPred[0] = PLANAR_IDX;
1563  uiIntraDirPred[1] = DC_IDX;
1564  uiIntraDirPred[2] = VER_IDX;
1565  }
1566  }
1567  else
1568  {
1569  if( piMode )
1570  {
1571  *piMode = 2;
1572  }
1573  uiIntraDirPred[0] = iLeftIntraDir;
1574  uiIntraDirPred[1] = iAboveIntraDir;
1575 
1576  if (iLeftIntraDir && iAboveIntraDir ) //both modes are non-planar
1577  {
1578  uiIntraDirPred[2] = PLANAR_IDX;
1579  }
1580  else
1581  {
1582  uiIntraDirPred[2] = (iLeftIntraDir+iAboveIntraDir)<2? VER_IDX : DC_IDX;
1583  }
1584  }
1585  for (UInt i=0; i<NUM_MOST_PROBABLE_MODES; i++)
1586  {
1587  assert(uiIntraDirPred[i] < 35);
1588  }
1589 }
1590 
1591 UInt TComDataCU::getCtxSplitFlag( UInt uiAbsPartIdx, UInt uiDepth )
1592 {
1593  TComDataCU* pcTempCU;
1594  UInt uiTempPartIdx;
1595  UInt uiCtx;
1596  // Get left split flag
1597  pcTempCU = getPULeft( uiTempPartIdx, m_absZIdxInCtu + uiAbsPartIdx );
1598  uiCtx = ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
1599 
1600  // Get above split flag
1601  pcTempCU = getPUAbove( uiTempPartIdx, m_absZIdxInCtu + uiAbsPartIdx );
1602  uiCtx += ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
1603 
1604  return uiCtx;
1605 }
1606 
1608 {
1609  const UInt transformDepth = rTu.GetTransformDepthRel();
1610 
1611  if (isChroma(chType))
1612  {
1613  return transformDepth;
1614  }
1615  else
1616  {
1617  const UInt uiCtx = ( transformDepth == 0 ? 1 : 0 );
1618  return uiCtx;
1619  }
1620 }
1621 
1623 {
1624  UInt log2CbSize = g_aucConvertToBit[getWidth( absPartIdx )] + 2;
1625  PartSize partSize = getPartitionSize( absPartIdx );
1626  UInt quadtreeTUMaxDepth = isIntra( absPartIdx ) ? m_pcSlice->getSPS()->getQuadtreeTUMaxDepthIntra() : m_pcSlice->getSPS()->getQuadtreeTUMaxDepthInter();
1627  Int intraSplitFlag = ( isIntra( absPartIdx ) && partSize == SIZE_NxN ) ? 1 : 0;
1628  Int interSplitFlag = ((quadtreeTUMaxDepth == 1) && isInter( absPartIdx ) && (partSize != SIZE_2Nx2N) );
1629 
1630  UInt log2MinTUSizeInCU = 0;
1631  if (log2CbSize < (m_pcSlice->getSPS()->getQuadtreeTULog2MinSize() + quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag) )
1632  {
1633  // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is < QuadtreeTULog2MinSize
1634  log2MinTUSizeInCU = m_pcSlice->getSPS()->getQuadtreeTULog2MinSize();
1635  }
1636  else
1637  {
1638  // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is still >= QuadtreeTULog2MinSize
1639  log2MinTUSizeInCU = log2CbSize - ( quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag); // stop when trafoDepth == hierarchy_depth = splitFlag
1640  if ( log2MinTUSizeInCU > m_pcSlice->getSPS()->getQuadtreeTULog2MaxSize())
1641  {
1642  // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is still > QuadtreeTULog2MaxSize
1643  log2MinTUSizeInCU = m_pcSlice->getSPS()->getQuadtreeTULog2MaxSize();
1644  }
1645  }
1646  return log2MinTUSizeInCU;
1647 }
1648 
1650 {
1651  TComDataCU* pcTempCU;
1652  UInt uiTempPartIdx;
1653  UInt uiCtx = 0;
1654 
1655  // Get BCBP of left PU
1656  pcTempCU = getPULeft( uiTempPartIdx, m_absZIdxInCtu + uiAbsPartIdx );
1657  uiCtx = ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
1658 
1659  // Get BCBP of above PU
1660  pcTempCU = getPUAbove( uiTempPartIdx, m_absZIdxInCtu + uiAbsPartIdx );
1661  uiCtx += ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
1662 
1663  return uiCtx;
1664 }
1665 
1667 {
1668  return getDepth( uiAbsPartIdx );
1669 }
1670 
1671 
1673 {
1674  const UInt numberValidComponents = getPic()->getNumberValidComponents();
1675  return getCbf( uiIdx, COMPONENT_Y, 0 )
1676  || ((numberValidComponents > COMPONENT_Cb) && getCbf( uiIdx, COMPONENT_Cb, 0 ))
1677  || ((numberValidComponents > COMPONENT_Cr) && getCbf( uiIdx, COMPONENT_Cr, 0 ));
1678 }
1679 
1680 Void TComDataCU::setCbfSubParts( const UInt uiCbf[MAX_NUM_COMPONENT], UInt uiAbsPartIdx, UInt uiDepth )
1681 {
1682  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
1683  for(UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
1684  {
1685  memset( m_puhCbf[comp] + uiAbsPartIdx, uiCbf[comp], sizeof( UChar ) * uiCurrPartNumb );
1686  }
1687 }
1688 
1689 Void TComDataCU::setCbfSubParts( UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiDepth )
1690 {
1691  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
1692  memset( m_puhCbf[compID] + uiAbsPartIdx, uiCbf, sizeof( UChar ) * uiCurrPartNumb );
1693 }
1694 
1702 Void TComDataCU::setCbfSubParts ( UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
1703 {
1704  setSubPart<UChar>( uiCbf, m_puhCbf[compID], uiAbsPartIdx, uiDepth, uiPartIdx );
1705 }
1706 
1707 Void TComDataCU::setCbfPartRange ( UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes )
1708 {
1709  memset((m_puhCbf[compID] + uiAbsPartIdx), uiCbf, (sizeof(UChar) * uiCoveredPartIdxes));
1710 }
1711 
1712 Void TComDataCU::bitwiseOrCbfPartRange( UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes )
1713 {
1714  const UInt stopAbsPartIdx = uiAbsPartIdx + uiCoveredPartIdxes;
1715 
1716  for (UInt subPartIdx = uiAbsPartIdx; subPartIdx < stopAbsPartIdx; subPartIdx++)
1717  {
1718  m_puhCbf[compID][subPartIdx] |= uiCbf;
1719  }
1720 }
1721 
1722 Void TComDataCU::setDepthSubParts( UInt uiDepth, UInt uiAbsPartIdx )
1723 {
1724  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
1725  memset( m_puhDepth + uiAbsPartIdx, uiDepth, sizeof(UChar)*uiCurrPartNumb );
1726 }
1727 
1729 {
1730  UInt uiPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
1731  return (((m_absZIdxInCtu + uiAbsPartIdx)% uiPartNumb) == 0);
1732 }
1733 
1734 Void TComDataCU::setPartSizeSubParts( PartSize eMode, UInt uiAbsPartIdx, UInt uiDepth )
1735 {
1736  assert( sizeof( *m_pePartSize) == 1 );
1737  memset( m_pePartSize + uiAbsPartIdx, eMode, m_pcPic->getNumPartitionsInCtu() >> ( 2 * uiDepth ) );
1738 }
1739 
1741 {
1742  memset( m_CUTransquantBypass + uiAbsPartIdx, flag, m_pcPic->getNumPartitionsInCtu() >> ( 2 * uiDepth ) );
1743 }
1744 
1746 {
1747  assert( sizeof( *m_skipFlag) == 1 );
1748  memset( m_skipFlag + absPartIdx, skip, m_pcPic->getNumPartitionsInCtu() >> ( 2 * depth ) );
1749 }
1750 
1751 Void TComDataCU::setPredModeSubParts( PredMode eMode, UInt uiAbsPartIdx, UInt uiDepth )
1752 {
1753  assert( sizeof( *m_pePredMode) == 1 );
1754  memset( m_pePredMode + uiAbsPartIdx, eMode, m_pcPic->getNumPartitionsInCtu() >> ( 2 * uiDepth ) );
1755 }
1756 
1758 {
1759  assert( sizeof(*m_ChromaQpAdj) == 1 );
1760  memset( m_ChromaQpAdj + absPartIdx, val, m_pcPic->getNumPartitionsInCtu() >> ( 2 * depth ) );
1761 }
1762 
1763 Void TComDataCU::setQPSubCUs( Int qp, UInt absPartIdx, UInt depth, Bool &foundNonZeroCbf )
1764 {
1765  UInt currPartNumb = m_pcPic->getNumPartitionsInCtu() >> (depth << 1);
1766  UInt currPartNumQ = currPartNumb >> 2;
1767  const UInt numValidComp = m_pcPic->getNumberValidComponents();
1768 
1769  if(!foundNonZeroCbf)
1770  {
1771  if(getDepth(absPartIdx) > depth)
1772  {
1773  for ( UInt partUnitIdx = 0; partUnitIdx < 4; partUnitIdx++ )
1774  {
1775  setQPSubCUs( qp, absPartIdx+partUnitIdx*currPartNumQ, depth+1, foundNonZeroCbf );
1776  }
1777  }
1778  else
1779  {
1780  if(getCbf( absPartIdx, COMPONENT_Y ) || (numValidComp>COMPONENT_Cb && getCbf( absPartIdx, COMPONENT_Cb )) || (numValidComp>COMPONENT_Cr && getCbf( absPartIdx, COMPONENT_Cr) ) )
1781  {
1782  foundNonZeroCbf = true;
1783  }
1784  else
1785  {
1786  setQPSubParts(qp, absPartIdx, depth);
1787  }
1788  }
1789  }
1790 }
1791 
1792 Void TComDataCU::setQPSubParts( Int qp, UInt uiAbsPartIdx, UInt uiDepth )
1793 {
1794  const UInt numPart = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
1795  memset(m_phQP+uiAbsPartIdx, qp, numPart);
1796 }
1797 
1798 Void TComDataCU::setIntraDirSubParts( const ChannelType channelType, const UInt dir, const UInt absPartIdx, const UInt depth )
1799 {
1800  UInt numPart = m_pcPic->getNumPartitionsInCtu() >> (depth << 1);
1801  memset( m_puhIntraDir[channelType] + absPartIdx, dir,sizeof(UChar)*numPart );
1802 }
1803 
1804 template<typename T>
1805 Void TComDataCU::setSubPart( T uiParameter, T* puhBaseCtu, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx )
1806 {
1807  assert( sizeof(T) == 1 ); // Using memset() works only for types of size 1
1808 
1809  UInt uiCurrPartNumQ = (m_pcPic->getNumPartitionsInCtu() >> (2 * uiCUDepth)) >> 2;
1810  switch ( m_pePartSize[ uiCUAddr ] )
1811  {
1812  case SIZE_2Nx2N:
1813  memset( puhBaseCtu + uiCUAddr, uiParameter, 4 * uiCurrPartNumQ );
1814  break;
1815  case SIZE_2NxN:
1816  memset( puhBaseCtu + uiCUAddr, uiParameter, 2 * uiCurrPartNumQ );
1817  break;
1818  case SIZE_Nx2N:
1819  memset( puhBaseCtu + uiCUAddr, uiParameter, uiCurrPartNumQ );
1820  memset( puhBaseCtu + uiCUAddr + 2 * uiCurrPartNumQ, uiParameter, uiCurrPartNumQ );
1821  break;
1822  case SIZE_NxN:
1823  memset( puhBaseCtu + uiCUAddr, uiParameter, uiCurrPartNumQ );
1824  break;
1825  case SIZE_2NxnU:
1826  if ( uiPUIdx == 0 )
1827  {
1828  memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );
1829  memset( puhBaseCtu + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );
1830  }
1831  else if ( uiPUIdx == 1 )
1832  {
1833  memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );
1834  memset( puhBaseCtu + uiCUAddr + uiCurrPartNumQ, uiParameter, ((uiCurrPartNumQ >> 1) + (uiCurrPartNumQ << 1)) );
1835  }
1836  else
1837  {
1838  assert(0);
1839  }
1840  break;
1841  case SIZE_2NxnD:
1842  if ( uiPUIdx == 0 )
1843  {
1844  memset( puhBaseCtu + uiCUAddr, uiParameter, ((uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1)) );
1845  memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );
1846  }
1847  else if ( uiPUIdx == 1 )
1848  {
1849  memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );
1850  memset( puhBaseCtu + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );
1851  }
1852  else
1853  {
1854  assert(0);
1855  }
1856  break;
1857  case SIZE_nLx2N:
1858  if ( uiPUIdx == 0 )
1859  {
1860  memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
1861  memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
1862  memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );
1863  memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
1864  }
1865  else if ( uiPUIdx == 1 )
1866  {
1867  memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
1868  memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );
1869  memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );
1870  memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );
1871  }
1872  else
1873  {
1874  assert(0);
1875  }
1876  break;
1877  case SIZE_nRx2N:
1878  if ( uiPUIdx == 0 )
1879  {
1880  memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );
1881  memset( puhBaseCtu + uiCUAddr + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
1882  memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );
1883  memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
1884  }
1885  else if ( uiPUIdx == 1 )
1886  {
1887  memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
1888  memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
1889  memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );
1890  memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
1891  }
1892  else
1893  {
1894  assert(0);
1895  }
1896  break;
1897  default:
1898  assert( 0 );
1899  break;
1900  }
1901 }
1902 
1903 Void TComDataCU::setMergeFlagSubParts ( Bool bMergeFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
1904 {
1905  setSubPart( bMergeFlag, m_pbMergeFlag, uiAbsPartIdx, uiDepth, uiPartIdx );
1906 }
1907 
1908 Void TComDataCU::setMergeIndexSubParts ( UInt uiMergeIndex, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
1909 {
1910  setSubPart<UChar>( uiMergeIndex, m_puhMergeIndex, uiAbsPartIdx, uiDepth, uiPartIdx );
1911 }
1912 
1913 Void TComDataCU::setInterDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
1914 {
1915  setSubPart<UChar>( uiDir, m_puhInterDir, uiAbsPartIdx, uiDepth, uiPartIdx );
1916 }
1917 
1918 Void TComDataCU::setMVPIdxSubParts( Int iMVPIdx, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
1919 {
1920  setSubPart<Char>( iMVPIdx, m_apiMVPIdx[eRefPicList], uiAbsPartIdx, uiDepth, uiPartIdx );
1921 }
1922 
1923 Void TComDataCU::setMVPNumSubParts( Int iMVPNum, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
1924 {
1925  setSubPart<Char>( iMVPNum, m_apiMVPNum[eRefPicList], uiAbsPartIdx, uiDepth, uiPartIdx );
1926 }
1927 
1928 
1929 Void TComDataCU::setTrIdxSubParts( UInt uiTrIdx, UInt uiAbsPartIdx, UInt uiDepth )
1930 {
1931  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
1932 
1933  memset( m_puhTrIdx + uiAbsPartIdx, uiTrIdx, sizeof(UChar)*uiCurrPartNumb );
1934 }
1935 
1936 Void TComDataCU::setTransformSkipSubParts( const UInt useTransformSkip[MAX_NUM_COMPONENT], UInt uiAbsPartIdx, UInt uiDepth )
1937 {
1938  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
1939 
1940  for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
1941  {
1942  memset( m_puhTransformSkip[i] + uiAbsPartIdx, useTransformSkip[i], sizeof( UChar ) * uiCurrPartNumb );
1943  }
1944 }
1945 
1946 Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkip, ComponentID compID, UInt uiAbsPartIdx, UInt uiDepth)
1947 {
1948  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
1949 
1950  memset( m_puhTransformSkip[compID] + uiAbsPartIdx, useTransformSkip, sizeof( UChar ) * uiCurrPartNumb );
1951 }
1952 
1953 Void TComDataCU::setTransformSkipPartRange ( UInt useTransformSkip, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes )
1954 {
1955  memset((m_puhTransformSkip[compID] + uiAbsPartIdx), useTransformSkip, (sizeof(UChar) * uiCoveredPartIdxes));
1956 }
1957 
1958 Void TComDataCU::setCrossComponentPredictionAlphaPartRange( Char alphaValue, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes )
1959 {
1960  memset((m_crossComponentPredictionAlpha[compID] + uiAbsPartIdx), alphaValue, (sizeof(Char) * uiCoveredPartIdxes));
1961 }
1962 
1963 Void TComDataCU::setExplicitRdpcmModePartRange ( UInt rdpcmMode, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes )
1964 {
1965  memset((m_explicitRdpcmMode[compID] + uiAbsPartIdx), rdpcmMode, (sizeof(UChar) * uiCoveredPartIdxes));
1966 }
1967 
1968 Void TComDataCU::setSizeSubParts( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, UInt uiDepth )
1969 {
1970  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
1971 
1972  memset( m_puhWidth + uiAbsPartIdx, uiWidth, sizeof(UChar)*uiCurrPartNumb );
1973  memset( m_puhHeight + uiAbsPartIdx, uiHeight, sizeof(UChar)*uiCurrPartNumb );
1974 }
1975 
1977 {
1978  UChar iNumPart = 0;
1979 
1980  switch ( m_pePartSize[uiAbsPartIdx] )
1981  {
1982  case SIZE_2Nx2N: iNumPart = 1; break;
1983  case SIZE_2NxN: iNumPart = 2; break;
1984  case SIZE_Nx2N: iNumPart = 2; break;
1985  case SIZE_NxN: iNumPart = 4; break;
1986  case SIZE_2NxnU: iNumPart = 2; break;
1987  case SIZE_2NxnD: iNumPart = 2; break;
1988  case SIZE_nLx2N: iNumPart = 2; break;
1989  case SIZE_nRx2N: iNumPart = 2; break;
1990  default: assert (0); break;
1991  }
1992 
1993  return iNumPart;
1994 }
1995 
1996 // This is for use by a leaf/sub CU object only, with no additional AbsPartIdx
1997 Void TComDataCU::getPartIndexAndSize( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight )
1998 {
1999  switch ( m_pePartSize[0] )
2000  {
2001  case SIZE_2NxN:
2002  riWidth = getWidth(0); riHeight = getHeight(0) >> 1; ruiPartAddr = ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2003  break;
2004  case SIZE_Nx2N:
2005  riWidth = getWidth(0) >> 1; riHeight = getHeight(0); ruiPartAddr = ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 2;
2006  break;
2007  case SIZE_NxN:
2008  riWidth = getWidth(0) >> 1; riHeight = getHeight(0) >> 1; ruiPartAddr = ( m_uiNumPartition >> 2 ) * uiPartIdx;
2009  break;
2010  case SIZE_2NxnU:
2011  riWidth = getWidth(0);
2012  riHeight = ( uiPartIdx == 0 ) ? getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
2013  ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : m_uiNumPartition >> 3;
2014  break;
2015  case SIZE_2NxnD:
2016  riWidth = getWidth(0);
2017  riHeight = ( uiPartIdx == 0 ) ? ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
2018  ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 3);
2019  break;
2020  case SIZE_nLx2N:
2021  riWidth = ( uiPartIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
2022  riHeight = getHeight(0);
2023  ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : m_uiNumPartition >> 4;
2024  break;
2025  case SIZE_nRx2N:
2026  riWidth = ( uiPartIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
2027  riHeight = getHeight(0);
2028  ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (m_uiNumPartition >> 2) + (m_uiNumPartition >> 4);
2029  break;
2030  default:
2031  assert ( m_pePartSize[0] == SIZE_2Nx2N );
2032  riWidth = getWidth(0); riHeight = getHeight(0); ruiPartAddr = 0;
2033  break;
2034  }
2035 }
2036 
2037 
2038 Void TComDataCU::getMvField ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList, TComMvField& rcMvField )
2039 {
2040  if ( pcCU == NULL ) // OUT OF BOUNDARY
2041  {
2042  TComMv cZeroMv;
2043  rcMvField.setMvField( cZeroMv, NOT_VALID );
2044  return;
2045  }
2046 
2047  TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefPicList );
2048  rcMvField.setMvField( pcCUMvField->getMv( uiAbsPartIdx ), pcCUMvField->getRefIdx( uiAbsPartIdx ) );
2049 }
2050 
2051 Void TComDataCU::deriveLeftRightTopIdxGeneral ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
2052 {
2053  ruiPartIdxLT = m_absZIdxInCtu + uiAbsPartIdx;
2054  UInt uiPUWidth = 0;
2055 
2056  switch ( m_pePartSize[uiAbsPartIdx] )
2057  {
2058  case SIZE_2Nx2N: uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
2059  case SIZE_2NxN: uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
2060  case SIZE_Nx2N: uiPUWidth = m_puhWidth[uiAbsPartIdx] >> 1; break;
2061  case SIZE_NxN: uiPUWidth = m_puhWidth[uiAbsPartIdx] >> 1; break;
2062  case SIZE_2NxnU: uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
2063  case SIZE_2NxnD: uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
2064  case SIZE_nLx2N:
2065  if ( uiPartIdx == 0 )
2066  {
2067  uiPUWidth = m_puhWidth[uiAbsPartIdx] >> 2;
2068  }
2069  else if ( uiPartIdx == 1 )
2070  {
2071  uiPUWidth = (m_puhWidth[uiAbsPartIdx] >> 1) + (m_puhWidth[uiAbsPartIdx] >> 2);
2072  }
2073  else
2074  {
2075  assert(0);
2076  }
2077  break;
2078  case SIZE_nRx2N:
2079  if ( uiPartIdx == 0 )
2080  {
2081  uiPUWidth = (m_puhWidth[uiAbsPartIdx] >> 1) + (m_puhWidth[uiAbsPartIdx] >> 2);
2082  }
2083  else if ( uiPartIdx == 1 )
2084  {
2085  uiPUWidth = m_puhWidth[uiAbsPartIdx] >> 2;
2086  }
2087  else
2088  {
2089  assert(0);
2090  }
2091  break;
2092  default:
2093  assert (0);
2094  break;
2095  }
2096 
2097  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + uiPUWidth / m_pcPic->getMinCUWidth() - 1 ];
2098 }
2099 
2100 Void TComDataCU::deriveLeftBottomIdxGeneral( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLB )
2101 {
2102  UInt uiPUHeight = 0;
2103  switch ( m_pePartSize[uiAbsPartIdx] )
2104  {
2105  case SIZE_2Nx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx]; break;
2106  case SIZE_2NxN: uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 1; break;
2107  case SIZE_Nx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx]; break;
2108  case SIZE_NxN: uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 1; break;
2109  case SIZE_2NxnU:
2110  if ( uiPartIdx == 0 )
2111  {
2112  uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;
2113  }
2114  else if ( uiPartIdx == 1 )
2115  {
2116  uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);
2117  }
2118  else
2119  {
2120  assert(0);
2121  }
2122  break;
2123  case SIZE_2NxnD:
2124  if ( uiPartIdx == 0 )
2125  {
2126  uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);
2127  }
2128  else if ( uiPartIdx == 1 )
2129  {
2130  uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;
2131  }
2132  else
2133  {
2134  assert(0);
2135  }
2136  break;
2137  case SIZE_nLx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx]; break;
2138  case SIZE_nRx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx]; break;
2139  default:
2140  assert (0);
2141  break;
2142  }
2143 
2144  ruiPartIdxLB = g_auiRasterToZscan [g_auiZscanToRaster[ m_absZIdxInCtu + uiAbsPartIdx ] + ((uiPUHeight / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInCtuWidth()];
2145 }
2146 
2147 Void TComDataCU::deriveLeftRightTopIdx ( UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
2148 {
2149  ruiPartIdxLT = m_absZIdxInCtu;
2150  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1 ];
2151 
2152  switch ( m_pePartSize[0] )
2153  {
2154  case SIZE_2Nx2N: break;
2155  case SIZE_2NxN:
2156  ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1; ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2157  break;
2158  case SIZE_Nx2N:
2159  ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 2; ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : m_uiNumPartition >> 2;
2160  break;
2161  case SIZE_NxN:
2162  ruiPartIdxLT += ( m_uiNumPartition >> 2 ) * uiPartIdx; ruiPartIdxRT += ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );
2163  break;
2164  case SIZE_2NxnU:
2165  ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 3;
2166  ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 3;
2167  break;
2168  case SIZE_2NxnD:
2169  ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 1 ) + ( m_uiNumPartition >> 3 );
2170  ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 1 ) + ( m_uiNumPartition >> 3 );
2171  break;
2172  case SIZE_nLx2N:
2173  ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 4;
2174  ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : ( m_uiNumPartition >> 2 ) + ( m_uiNumPartition >> 4 );
2175  break;
2176  case SIZE_nRx2N:
2177  ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 2 ) + ( m_uiNumPartition >> 4 );
2178  ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : m_uiNumPartition >> 4;
2179  break;
2180  default:
2181  assert (0);
2182  break;
2183  }
2184 
2185 }
2186 
2187 Void TComDataCU::deriveLeftBottomIdx( UInt uiPartIdx, UInt& ruiPartIdxLB )
2188 {
2190 
2191  switch ( m_pePartSize[0] )
2192  {
2193  case SIZE_2Nx2N:
2194  ruiPartIdxLB += m_uiNumPartition >> 1;
2195  break;
2196  case SIZE_2NxN:
2197  ruiPartIdxLB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2198  break;
2199  case SIZE_Nx2N:
2200  ruiPartIdxLB += ( uiPartIdx == 0 )? m_uiNumPartition >> 1 : (m_uiNumPartition >> 2)*3;
2201  break;
2202  case SIZE_NxN:
2203  ruiPartIdxLB += ( m_uiNumPartition >> 2 ) * uiPartIdx;
2204  break;
2205  case SIZE_2NxnU:
2206  ruiPartIdxLB += ( uiPartIdx == 0 ) ? -((Int)m_uiNumPartition >> 3) : m_uiNumPartition >> 1;
2207  break;
2208  case SIZE_2NxnD:
2209  ruiPartIdxLB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3): m_uiNumPartition >> 1;
2210  break;
2211  case SIZE_nLx2N:
2212  ruiPartIdxLB += ( uiPartIdx == 0 ) ? m_uiNumPartition >> 1 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 4);
2213  break;
2214  case SIZE_nRx2N:
2215  ruiPartIdxLB += ( uiPartIdx == 0 ) ? m_uiNumPartition >> 1 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 2) + (m_uiNumPartition >> 4);
2216  break;
2217  default:
2218  assert (0);
2219  break;
2220  }
2221 }
2222 
2227 Void TComDataCU::deriveRightBottomIdx( UInt uiPartIdx, UInt &ruiPartIdxRB )
2228 {
2230 
2231  switch ( m_pePartSize[0] )
2232  {
2233  case SIZE_2Nx2N:
2234  ruiPartIdxRB += m_uiNumPartition >> 1;
2235  break;
2236  case SIZE_2NxN:
2237  ruiPartIdxRB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2238  break;
2239  case SIZE_Nx2N:
2240  ruiPartIdxRB += ( uiPartIdx == 0 )? m_uiNumPartition >> 2 : (m_uiNumPartition >> 1);
2241  break;
2242  case SIZE_NxN:
2243  ruiPartIdxRB += ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );
2244  break;
2245  case SIZE_2NxnU:
2246  ruiPartIdxRB += ( uiPartIdx == 0 ) ? -((Int)m_uiNumPartition >> 3) : m_uiNumPartition >> 1;
2247  break;
2248  case SIZE_2NxnD:
2249  ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3): m_uiNumPartition >> 1;
2250  break;
2251  case SIZE_nLx2N:
2252  ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 3) + (m_uiNumPartition >> 4): m_uiNumPartition >> 1;
2253  break;
2254  case SIZE_nRx2N:
2255  ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3) + (m_uiNumPartition >> 4) : m_uiNumPartition >> 1;
2256  break;
2257  default:
2258  assert (0);
2259  break;
2260  }
2261 }
2262 
2263 Void TComDataCU::deriveLeftRightTopIdxAdi ( UInt& ruiPartIdxLT, UInt& ruiPartIdxRT, UInt uiPartOffset, UInt uiPartDepth )
2264 {
2265  UInt uiNumPartInWidth = (m_puhWidth[0]/m_pcPic->getMinCUWidth())>>uiPartDepth;
2266  ruiPartIdxLT = m_absZIdxInCtu + uiPartOffset;
2267  ruiPartIdxRT = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxLT ] + uiNumPartInWidth - 1 ];
2268 }
2269 
2270 Void TComDataCU::deriveLeftBottomIdxAdi( UInt& ruiPartIdxLB, UInt uiPartOffset, UInt uiPartDepth )
2271 {
2272  UInt uiAbsIdx;
2273  UInt uiMinCuWidth, uiWidthInMinCus;
2274 
2275  uiMinCuWidth = getPic()->getMinCUWidth();
2276  uiWidthInMinCus = (getWidth(0)/uiMinCuWidth)>>uiPartDepth;
2277  uiAbsIdx = getZorderIdxInCtu()+uiPartOffset+(m_uiNumPartition>>(uiPartDepth<<1))-1;
2278  uiAbsIdx = g_auiZscanToRaster[uiAbsIdx]-(uiWidthInMinCus-1);
2279  ruiPartIdxLB = g_auiRasterToZscan[uiAbsIdx];
2280 }
2281 
2282 Bool TComDataCU::hasEqualMotion( UInt uiAbsPartIdx, TComDataCU* pcCandCU, UInt uiCandAbsPartIdx )
2283 {
2284  if ( getInterDir( uiAbsPartIdx ) != pcCandCU->getInterDir( uiCandAbsPartIdx ) )
2285  {
2286  return false;
2287  }
2288 
2289  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
2290  {
2291  if ( getInterDir( uiAbsPartIdx ) & ( 1 << uiRefListIdx ) )
2292  {
2293  if ( getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiAbsPartIdx ) != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiCandAbsPartIdx ) ||
2294  getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiAbsPartIdx ) != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiCandAbsPartIdx ) )
2295  {
2296  return false;
2297  }
2298  }
2299  }
2300 
2301  return true;
2302 }
2303 
2305 Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int mrgCandIdx )
2306 {
2307  UInt uiAbsPartAddr = m_absZIdxInCtu + uiAbsPartIdx;
2308  Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
2309  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
2310  {
2311  abCandIsInter[ui] = false;
2312  pcMvFieldNeighbours[ ( ui << 1 ) ].setRefIdx(NOT_VALID);
2313  pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setRefIdx(NOT_VALID);
2314  }
2315  numValidMergeCand = getSlice()->getMaxNumMergeCand();
2316  // compute the location of the current PU
2317  Int xP, yP, nPSW, nPSH;
2318  this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
2319 
2320  Int iCount = 0;
2321 
2322  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
2323  PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
2324  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
2325  deriveLeftBottomIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
2326 
2327  //left
2328  UInt uiLeftPartIdx = 0;
2329  TComDataCU* pcCULeft = 0;
2330  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
2331 
2332  Bool isAvailableA1 = pcCULeft &&
2333  pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
2334  !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
2335  pcCULeft->isInter( uiLeftPartIdx ) ;
2336 
2337  if ( isAvailableA1 )
2338  {
2339  abCandIsInter[iCount] = true;
2340  // get Inter Dir
2341  puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
2342  // get Mv from Left
2343  pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2344  if ( getSlice()->isInterB() )
2345  {
2346  pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2347  }
2348  if ( mrgCandIdx == iCount )
2349  {
2350  return;
2351  }
2352  iCount ++;
2353  }
2354 
2355  // early termination
2356  if (iCount == getSlice()->getMaxNumMergeCand())
2357  {
2358  return;
2359  }
2360  // above
2361  UInt uiAbovePartIdx = 0;
2362  TComDataCU* pcCUAbove = 0;
2363  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
2364 
2365  Bool isAvailableB1 = pcCUAbove &&
2366  pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
2367  !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
2368  pcCUAbove->isInter( uiAbovePartIdx );
2369 
2370  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
2371  {
2372  abCandIsInter[iCount] = true;
2373  // get Inter Dir
2374  puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
2375  // get Mv from Left
2376  pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2377  if ( getSlice()->isInterB() )
2378  {
2379  pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2380  }
2381  if ( mrgCandIdx == iCount )
2382  {
2383  return;
2384  }
2385  iCount ++;
2386  }
2387  // early termination
2388  if (iCount == getSlice()->getMaxNumMergeCand())
2389  {
2390  return;
2391  }
2392 
2393  // above right
2394  UInt uiAboveRightPartIdx = 0;
2395  TComDataCU* pcCUAboveRight = 0;
2396  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
2397 
2398  Bool isAvailableB0 = pcCUAboveRight &&
2399  pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
2400  pcCUAboveRight->isInter( uiAboveRightPartIdx );
2401 
2402  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
2403  {
2404  abCandIsInter[iCount] = true;
2405  // get Inter Dir
2406  puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
2407  // get Mv from Left
2408  pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2409  if ( getSlice()->isInterB() )
2410  {
2411  pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2412  }
2413  if ( mrgCandIdx == iCount )
2414  {
2415  return;
2416  }
2417  iCount ++;
2418  }
2419  // early termination
2420  if (iCount == getSlice()->getMaxNumMergeCand())
2421  {
2422  return;
2423  }
2424 
2425  //left bottom
2426  UInt uiLeftBottomPartIdx = 0;
2427  TComDataCU* pcCULeftBottom = 0;
2428  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
2429 
2430  Bool isAvailableA0 = pcCULeftBottom &&
2431  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
2432  pcCULeftBottom->isInter( uiLeftBottomPartIdx ) ;
2433 
2434  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
2435  {
2436  abCandIsInter[iCount] = true;
2437  // get Inter Dir
2438  puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
2439  // get Mv from Left
2440  pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2441  if ( getSlice()->isInterB() )
2442  {
2443  pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2444  }
2445  if ( mrgCandIdx == iCount )
2446  {
2447  return;
2448  }
2449  iCount ++;
2450  }
2451  // early termination
2452  if (iCount == getSlice()->getMaxNumMergeCand())
2453  {
2454  return;
2455  }
2456 
2457  // above left
2458  if( iCount < 4 )
2459  {
2460  UInt uiAboveLeftPartIdx = 0;
2461  TComDataCU* pcCUAboveLeft = 0;
2462  pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
2463 
2464  Bool isAvailableB2 = pcCUAboveLeft &&
2465  pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
2466  pcCUAboveLeft->isInter( uiAboveLeftPartIdx );
2467 
2468  if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
2469  && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
2470  {
2471  abCandIsInter[iCount] = true;
2472  // get Inter Dir
2473  puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
2474  // get Mv from Left
2475  pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2476  if ( getSlice()->isInterB() )
2477  {
2478  pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2479  }
2480  if ( mrgCandIdx == iCount )
2481  {
2482  return;
2483  }
2484  iCount ++;
2485  }
2486  }
2487  // early termination
2488  if (iCount == getSlice()->getMaxNumMergeCand())
2489  {
2490  return;
2491  }
2492 
2493  if ( getSlice()->getEnableTMVPFlag() )
2494  {
2495  //>> MTK colocated-RightBottom
2496  UInt uiPartIdxRB;
2497 
2498  deriveRightBottomIdx( uiPUIdx, uiPartIdxRB );
2499 
2500  UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
2501  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
2502  const UInt numPartInCtuHeight = m_pcPic->getNumPartInCtuHeight();
2503 
2504  TComMv cColMv;
2505  Int iRefIdx;
2506  Int ctuRsAddr = -1;
2507 
2508  if ( ( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth () ) < m_pcSlice->getSPS()->getPicWidthInLumaSamples () ) // image boundary check
2510  {
2511  if ( ( uiAbsPartIdxTmp % numPartInCtuWidth < numPartInCtuWidth - 1 ) && // is not at the last column of CTU
2512  ( uiAbsPartIdxTmp / numPartInCtuWidth < numPartInCtuHeight - 1 ) ) // is not at the last row of CTU
2513  {
2514  uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + numPartInCtuWidth + 1 ];
2515  ctuRsAddr = getCtuRsAddr();
2516  }
2517  else if ( uiAbsPartIdxTmp % numPartInCtuWidth < numPartInCtuWidth - 1 ) // is not at the last column of CTU But is last row of CTU
2518  {
2519  uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + numPartInCtuWidth + 1) % m_pcPic->getNumPartitionsInCtu() ];
2520  }
2521  else if ( uiAbsPartIdxTmp / numPartInCtuWidth < numPartInCtuHeight - 1 ) // is not at the last row of CTU But is last column of CTU
2522  {
2523  uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
2524  ctuRsAddr = getCtuRsAddr() + 1;
2525  }
2526  else //is the right bottom corner of CTU
2527  {
2528  uiAbsPartAddr = 0;
2529  }
2530  }
2531 
2532  iRefIdx = 0;
2533 
2534  Bool bExistMV = false;
2535  UInt uiPartIdxCenter;
2536  Int dir = 0;
2537  UInt uiArrayAddr = iCount;
2538  xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
2539  bExistMV = ctuRsAddr >= 0 && xGetColMVP( REF_PIC_LIST_0, ctuRsAddr, uiAbsPartAddr, cColMv, iRefIdx );
2540  if( bExistMV == false )
2541  {
2542  bExistMV = xGetColMVP( REF_PIC_LIST_0, getCtuRsAddr(), uiPartIdxCenter, cColMv, iRefIdx );
2543  }
2544  if( bExistMV )
2545  {
2546  dir |= 1;
2547  pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
2548  }
2549 
2550  if ( getSlice()->isInterB() )
2551  {
2552  bExistMV = ctuRsAddr >= 0 && xGetColMVP( REF_PIC_LIST_1, ctuRsAddr, uiAbsPartAddr, cColMv, iRefIdx);
2553  if( bExistMV == false )
2554  {
2555  bExistMV = xGetColMVP( REF_PIC_LIST_1, getCtuRsAddr(), uiPartIdxCenter, cColMv, iRefIdx );
2556  }
2557  if( bExistMV )
2558  {
2559  dir |= 2;
2560  pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
2561  }
2562  }
2563 
2564  if (dir != 0)
2565  {
2566  puhInterDirNeighbours[uiArrayAddr] = dir;
2567  abCandIsInter[uiArrayAddr] = true;
2568 
2569  if ( mrgCandIdx == iCount )
2570  {
2571  return;
2572  }
2573  iCount++;
2574  }
2575  }
2576  // early termination
2577  if (iCount == getSlice()->getMaxNumMergeCand())
2578  {
2579  return;
2580  }
2581 
2582  UInt uiArrayAddr = iCount;
2583  UInt uiCutoff = uiArrayAddr;
2584 
2585  if ( getSlice()->isInterB() )
2586  {
2587  static const UInt NUM_PRIORITY_LIST=12;
2588  static const UInt uiPriorityList0[NUM_PRIORITY_LIST] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
2589  static const UInt uiPriorityList1[NUM_PRIORITY_LIST] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
2590 
2591  for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
2592  {
2593  assert(idx<NUM_PRIORITY_LIST);
2594  Int i = uiPriorityList0[idx];
2595  Int j = uiPriorityList1[idx];
2596  if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
2597  {
2598  abCandIsInter[uiArrayAddr] = true;
2599  puhInterDirNeighbours[uiArrayAddr] = 3;
2600 
2601  // get Mv from cand[i] and cand[j]
2602  pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
2603  pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
2604 
2605  Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
2606  Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
2607  if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
2608  {
2609  abCandIsInter[uiArrayAddr] = false;
2610  }
2611  else
2612  {
2613  uiArrayAddr++;
2614  }
2615  }
2616  }
2617  }
2618  // early termination
2619  if (uiArrayAddr == getSlice()->getMaxNumMergeCand())
2620  {
2621  return;
2622  }
2623 
2625 
2626  Int r = 0;
2627  Int refcnt = 0;
2628  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
2629  {
2630  abCandIsInter[uiArrayAddr] = true;
2631  puhInterDirNeighbours[uiArrayAddr] = 1;
2632  pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
2633 
2634  if ( getSlice()->isInterB() )
2635  {
2636  puhInterDirNeighbours[uiArrayAddr] = 3;
2637  pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
2638  }
2639  uiArrayAddr++;
2640 
2641  if ( refcnt == iNumRefIdx - 1 )
2642  {
2643  r = 0;
2644  }
2645  else
2646  {
2647  ++r;
2648  ++refcnt;
2649  }
2650  }
2651  numValidMergeCand = uiArrayAddr;
2652 }
2653 
2659 {
2660 
2661  UInt plevel = this->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() + 2;
2662  if ((xN>>plevel)!= (xP>>plevel))
2663  {
2664  return true;
2665  }
2666  if ((yN>>plevel)!= (yP>>plevel))
2667  {
2668  return true;
2669  }
2670  return false;
2671 }
2672 
2678 Void TComDataCU::getPartPosition( UInt partIdx, Int& xP, Int& yP, Int& nPSW, Int& nPSH)
2679 {
2680  UInt col = m_uiCUPelX;
2681  UInt row = m_uiCUPelY;
2682 
2683  switch ( m_pePartSize[0] )
2684  {
2685  case SIZE_2NxN:
2686  nPSW = getWidth(0);
2687  nPSH = getHeight(0) >> 1;
2688  xP = col;
2689  yP = (partIdx ==0)? row: row + nPSH;
2690  break;
2691  case SIZE_Nx2N:
2692  nPSW = getWidth(0) >> 1;
2693  nPSH = getHeight(0);
2694  xP = (partIdx ==0)? col: col + nPSW;
2695  yP = row;
2696  break;
2697  case SIZE_NxN:
2698  nPSW = getWidth(0) >> 1;
2699  nPSH = getHeight(0) >> 1;
2700  xP = col + (partIdx&0x1)*nPSW;
2701  yP = row + (partIdx>>1)*nPSH;
2702  break;
2703  case SIZE_2NxnU:
2704  nPSW = getWidth(0);
2705  nPSH = ( partIdx == 0 ) ? getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
2706  xP = col;
2707  yP = (partIdx ==0)? row: row + getHeight(0) - nPSH;
2708 
2709  break;
2710  case SIZE_2NxnD:
2711  nPSW = getWidth(0);
2712  nPSH = ( partIdx == 0 ) ? ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
2713  xP = col;
2714  yP = (partIdx ==0)? row: row + getHeight(0) - nPSH;
2715  break;
2716  case SIZE_nLx2N:
2717  nPSW = ( partIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
2718  nPSH = getHeight(0);
2719  xP = (partIdx ==0)? col: col + getWidth(0) - nPSW;
2720  yP = row;
2721  break;
2722  case SIZE_nRx2N:
2723  nPSW = ( partIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
2724  nPSH = getHeight(0);
2725  xP = (partIdx ==0)? col: col + getWidth(0) - nPSW;
2726  yP = row;
2727  break;
2728  default:
2729  assert ( m_pePartSize[0] == SIZE_2Nx2N );
2730  nPSW = getWidth(0);
2731  nPSH = getHeight(0);
2732  xP = col ;
2733  yP = row ;
2734 
2735  break;
2736  }
2737 }
2738 
2746 Void TComDataCU::fillMvpCand ( UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo* pInfo )
2747 {
2748  TComMv cMvPred;
2749  Bool bAddedSmvp = false;
2750 
2751  pInfo->iN = 0;
2752  if (iRefIdx < 0)
2753  {
2754  return;
2755  }
2756 
2757  //-- Get Spatial MV
2758  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
2759  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
2760  const UInt numPartInCtuHeight = m_pcPic->getNumPartInCtuHeight();
2761  Bool bAdded = false;
2762 
2763  deriveLeftRightTopIdx( uiPartIdx, uiPartIdxLT, uiPartIdxRT );
2764  deriveLeftBottomIdx( uiPartIdx, uiPartIdxLB );
2765 
2766  TComDataCU* tmpCU = NULL;
2767  UInt idx;
2768  tmpCU = getPUBelowLeft(idx, uiPartIdxLB);
2769  bAddedSmvp = (tmpCU != NULL) && (tmpCU->isInter(idx));
2770 
2771  if (!bAddedSmvp)
2772  {
2773  tmpCU = getPULeft(idx, uiPartIdxLB);
2774  bAddedSmvp = (tmpCU != NULL) && (tmpCU->isInter(idx));
2775  }
2776 
2777  // Left predictor search
2778  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
2779  if (!bAdded)
2780  {
2781  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
2782  }
2783 
2784  if(!bAdded)
2785  {
2786  bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
2787  if (!bAdded)
2788  {
2789  xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
2790  }
2791  }
2792 
2793  // Above predictor search
2794  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
2795 
2796  if (!bAdded)
2797  {
2798  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
2799  }
2800 
2801  if(!bAdded)
2802  {
2803  xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
2804  }
2805 
2806  if(!bAddedSmvp)
2807  {
2808  bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
2809  if (!bAdded)
2810  {
2811  bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
2812  }
2813 
2814  if(!bAdded)
2815  {
2816  xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
2817  }
2818  }
2819 
2820  if ( pInfo->iN == 2 )
2821  {
2822  if ( pInfo->m_acMvCand[ 0 ] == pInfo->m_acMvCand[ 1 ] )
2823  {
2824  pInfo->iN = 1;
2825  }
2826  }
2827 
2828  if ( getSlice()->getEnableTMVPFlag() )
2829  {
2830  // Get Temporal Motion Predictor
2831  Int iRefIdx_Col = iRefIdx;
2832  TComMv cColMv;
2833  UInt uiPartIdxRB;
2834  UInt uiAbsPartIdx;
2835  UInt uiAbsPartAddr;
2836 
2837  deriveRightBottomIdx( uiPartIdx, uiPartIdxRB );
2838  uiAbsPartAddr = m_absZIdxInCtu + uiPartAddr;
2839 
2840  //---- co-located RightBottom Temporal Predictor (H) ---//
2841  uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
2842  Int ctuRsAddr = -1;
2843  if ( ( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth () ) < m_pcSlice->getSPS()->getPicWidthInLumaSamples () ) // image boundary check
2845  {
2846  if ( ( uiAbsPartIdx % numPartInCtuWidth < numPartInCtuWidth - 1 ) && // is not at the last column of CTU
2847  ( uiAbsPartIdx / numPartInCtuWidth < numPartInCtuHeight - 1 ) ) // is not at the last row of CTU
2848  {
2849  uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + numPartInCtuWidth + 1 ];
2850  ctuRsAddr = getCtuRsAddr();
2851  }
2852  else if ( uiAbsPartIdx % numPartInCtuWidth < numPartInCtuWidth - 1 ) // is not at the last column of CTU But is last row of CTU
2853  {
2854  uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + numPartInCtuWidth + 1) % m_pcPic->getNumPartitionsInCtu() ];
2855  }
2856  else if ( uiAbsPartIdx / numPartInCtuWidth < numPartInCtuHeight - 1 ) // is not at the last row of CTU But is last column of CTU
2857  {
2858  uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + 1 ];
2859  ctuRsAddr = getCtuRsAddr() + 1;
2860  }
2861  else //is the right bottom corner of CTU
2862  {
2863  uiAbsPartAddr = 0;
2864  }
2865  }
2866  if ( ctuRsAddr >= 0 && xGetColMVP( eRefPicList, ctuRsAddr, uiAbsPartAddr, cColMv, iRefIdx_Col ) )
2867  {
2868  pInfo->m_acMvCand[pInfo->iN++] = cColMv;
2869  }
2870  else
2871  {
2872  UInt uiPartIdxCenter;
2873  xDeriveCenterIdx( uiPartIdx, uiPartIdxCenter );
2874  if (xGetColMVP( eRefPicList, getCtuRsAddr(), uiPartIdxCenter, cColMv, iRefIdx_Col ))
2875  {
2876  pInfo->m_acMvCand[pInfo->iN++] = cColMv;
2877  }
2878  }
2879  //---- co-located RightBottom Temporal Predictor ---//
2880  }
2881 
2882  if (pInfo->iN > AMVP_MAX_NUM_CANDS)
2883  {
2884  pInfo->iN = AMVP_MAX_NUM_CANDS;
2885  }
2886 
2887  while (pInfo->iN < AMVP_MAX_NUM_CANDS)
2888  {
2889  pInfo->m_acMvCand[pInfo->iN].set(0,0);
2890  pInfo->iN++;
2891  }
2892  return ;
2893 }
2894 
2895 
2897 {
2898  Int width = 0;
2899  Int height = 0;
2900  UInt partAddr;
2901 
2902  getPartIndexAndSize( puIdx, partAddr, width, height );
2903  if ( getWidth(0) == 8 && (width < 8 || height < 8) )
2904  {
2905  return true;
2906  }
2907  return false;
2908 }
2909 
2910 
2912 {
2913  Int iMvShift = 2;
2914  Int iOffset = 8;
2915  Int iHorMax = ( m_pcSlice->getSPS()->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
2916  Int iHorMin = ( -(Int)g_uiMaxCUWidth - iOffset - (Int)m_uiCUPelX + 1 ) << iMvShift;
2917 
2918  Int iVerMax = ( m_pcSlice->getSPS()->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
2919  Int iVerMin = ( -(Int)g_uiMaxCUHeight - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
2920 
2921  rcMv.setHor( min (iHorMax, max (iHorMin, rcMv.getHor())) );
2922  rcMv.setVer( min (iVerMax, max (iVerMin, rcMv.getVer())) );
2923 }
2924 
2925 
2927 {
2928  UInt uiShift = ( m_pePartSize[uiAbsPartIdx]==SIZE_NxN ? 1 : 0 );
2929 
2930  UChar uiWidth = m_puhWidth[uiAbsPartIdx]>>uiShift;
2931  UInt uiCnt = 0;
2932  while( uiWidth )
2933  {
2934  uiCnt++;
2935  uiWidth>>=1;
2936  }
2937  uiCnt-=2;
2938  return uiCnt > 6 ? 6 : uiCnt;
2939 }
2940 
2941 Void TComDataCU::clearCbf( UInt uiIdx, ComponentID compID, UInt uiNumParts )
2942 {
2943  memset( &m_puhCbf[compID][uiIdx], 0, sizeof(UChar)*uiNumParts);
2944 }
2945 
2952 Void TComDataCU::setIPCMFlagSubParts (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
2953 {
2954  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
2955 
2956  memset(m_pbIPCMFlag + uiAbsPartIdx, bIpcmFlag, sizeof(Bool)*uiCurrPartNumb );
2957 }
2958 
2964 {
2965  return ( getSkipFlag( uiPartIdx ) );
2966 }
2967 
2968 // ====================================================================================================================
2969 // Protected member functions
2970 // ====================================================================================================================
2971 
2972 Bool TComDataCU::xAddMVPCand( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
2973 {
2974  TComDataCU* pcTmpCU = NULL;
2975  UInt uiIdx;
2976  switch( eDir )
2977  {
2978  case MD_LEFT:
2979  {
2980  pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
2981  break;
2982  }
2983  case MD_ABOVE:
2984  {
2985  pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx);
2986  break;
2987  }
2988  case MD_ABOVE_RIGHT:
2989  {
2990  pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
2991  break;
2992  }
2993  case MD_BELOW_LEFT:
2994  {
2995  pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
2996  break;
2997  }
2998  case MD_ABOVE_LEFT:
2999  {
3000  pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
3001  break;
3002  }
3003  default:
3004  {
3005  break;
3006  }
3007  }
3008 
3009  if ( pcTmpCU == NULL )
3010  {
3011  return false;
3012  }
3013 
3014  if ( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC() == pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ))
3015  {
3016  TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
3017 
3018  pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
3019  return true;
3020  }
3021 
3022  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
3023  if( eRefPicList == REF_PIC_LIST_0 )
3024  {
3025  eRefPicList2nd = REF_PIC_LIST_1;
3026  }
3027  else if ( eRefPicList == REF_PIC_LIST_1)
3028  {
3029  eRefPicList2nd = REF_PIC_LIST_0;
3030  }
3031 
3032 
3033  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
3034  Int iNeibRefPOC;
3035 
3036 
3037  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0 )
3038  {
3039  iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
3040  if( iNeibRefPOC == iCurrRefPOC ) // Same Reference Frame But Diff List//
3041  {
3042  TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
3043  pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
3044  return true;
3045  }
3046  }
3047  return false;
3048 }
3049 
3058 Bool TComDataCU::xAddMVPCandOrder( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
3059 {
3060  TComDataCU* pcTmpCU = NULL;
3061  UInt uiIdx;
3062  switch( eDir )
3063  {
3064  case MD_LEFT:
3065  {
3066  pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
3067  break;
3068  }
3069  case MD_ABOVE:
3070  {
3071  pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx);
3072  break;
3073  }
3074  case MD_ABOVE_RIGHT:
3075  {
3076  pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
3077  break;
3078  }
3079  case MD_BELOW_LEFT:
3080  {
3081  pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
3082  break;
3083  }
3084  case MD_ABOVE_LEFT:
3085  {
3086  pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
3087  break;
3088  }
3089  default:
3090  {
3091  break;
3092  }
3093  }
3094 
3095  if ( pcTmpCU == NULL )
3096  {
3097  return false;
3098  }
3099 
3100  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
3101  if( eRefPicList == REF_PIC_LIST_0 )
3102  {
3103  eRefPicList2nd = REF_PIC_LIST_1;
3104  }
3105  else if ( eRefPicList == REF_PIC_LIST_1)
3106  {
3107  eRefPicList2nd = REF_PIC_LIST_0;
3108  }
3109 
3110  Int iCurrPOC = m_pcSlice->getPOC();
3111  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
3112  Int iNeibPOC = iCurrPOC;
3113  Int iNeibRefPOC;
3114  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getIsLongTerm();
3115  Bool bIsNeibRefLongTerm = false;
3116 
3117  //--------------- V1 (END) ------------------//
3118  if( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0)
3119  {
3120  iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) );
3121  TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
3122  TComMv rcMv;
3123 
3124  bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) )->getIsLongTerm();
3125  if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm )
3126  {
3127  if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
3128  {
3129  rcMv = cMvPred;
3130  }
3131  else
3132  {
3133  Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
3134  if ( iScale == 4096 )
3135  {
3136  rcMv = cMvPred;
3137  }
3138  else
3139  {
3140  rcMv = cMvPred.scaleMv( iScale );
3141  }
3142  }
3143 
3144  pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
3145  return true;
3146  }
3147  }
3148  //---------------------- V2(END) --------------------//
3149  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0)
3150  {
3151  iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
3152  TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
3153  TComMv rcMv;
3154 
3155  bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) )->getIsLongTerm();
3156  if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm )
3157  {
3158  if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
3159  {
3160  rcMv = cMvPred;
3161  }
3162  else
3163  {
3164  Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
3165  if ( iScale == 4096 )
3166  {
3167  rcMv = cMvPred;
3168  }
3169  else
3170  {
3171  rcMv = cMvPred.scaleMv( iScale );
3172  }
3173  }
3174 
3175  pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
3176  return true;
3177  }
3178  }
3179  //---------------------- V3(END) --------------------//
3180  return false;
3181 }
3182 
3183 Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int ctuRsAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx )
3184 {
3185  UInt uiAbsPartAddr = uiPartUnitIdx;
3186 
3187  RefPicList eColRefPicList;
3188  Int iColPOC, iColRefPOC, iCurrPOC, iCurrRefPOC, iScale;
3189  TComMv cColMv;
3190 
3191  // use coldir.
3192  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
3193  TComDataCU *pColCtu = pColPic->getCtu( ctuRsAddr );
3194  if(pColCtu->getPic()==0||pColCtu->getPartitionSize(uiPartUnitIdx)==NUMBER_OF_PART_SIZES)
3195  {
3196  return false;
3197  }
3198  iCurrPOC = m_pcSlice->getPOC();
3199  iColPOC = pColCtu->getSlice()->getPOC();
3200 
3201  if (!pColCtu->isInter(uiAbsPartAddr))
3202  {
3203  return false;
3204  }
3205 
3206  eColRefPicList = getSlice()->getCheckLDC() ? eRefPicList : RefPicList(getSlice()->getColFromL0Flag());
3207 
3208  Int iColRefIdx = pColCtu->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
3209 
3210  if (iColRefIdx < 0 )
3211  {
3212  eColRefPicList = RefPicList(1 - eColRefPicList);
3213  iColRefIdx = pColCtu->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
3214 
3215  if (iColRefIdx < 0 )
3216  {
3217  return false;
3218  }
3219  }
3220 
3221  // Scale the vector.
3222  iColRefPOC = pColCtu->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
3223  cColMv = pColCtu->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
3224 
3225  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
3226 
3227  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
3228  Bool bIsColRefLongTerm = pColCtu->getSlice()->getIsUsedAsLongTerm(eColRefPicList, iColRefIdx);
3229 
3230  if ( bIsCurrRefLongTerm != bIsColRefLongTerm )
3231  {
3232  return false;
3233  }
3234 
3235  if ( bIsCurrRefLongTerm || bIsColRefLongTerm )
3236  {
3237  rcMv = cColMv;
3238  }
3239  else
3240  {
3241  iScale = xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iColPOC, iColRefPOC);
3242  if ( iScale == 4096 )
3243  {
3244  rcMv = cColMv;
3245  }
3246  else
3247  {
3248  rcMv = cColMv.scaleMv( iScale );
3249  }
3250  }
3251 
3252  return true;
3253 }
3254 
3256 {
3257  return ( xGetComponentBits(cMvd.getHor()) + xGetComponentBits(cMvd.getVer()) );
3258 }
3259 
3261 {
3262  UInt uiLength = 1;
3263  UInt uiTemp = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1);
3264 
3265  assert ( uiTemp );
3266 
3267  while ( 1 != uiTemp )
3268  {
3269  uiTemp >>= 1;
3270  uiLength += 2;
3271  }
3272 
3273  return uiLength;
3274 }
3275 
3276 
3277 Int TComDataCU::xGetDistScaleFactor(Int iCurrPOC, Int iCurrRefPOC, Int iColPOC, Int iColRefPOC)
3278 {
3279  Int iDiffPocD = iColPOC - iColRefPOC;
3280  Int iDiffPocB = iCurrPOC - iCurrRefPOC;
3281 
3282  if( iDiffPocD == iDiffPocB )
3283  {
3284  return 4096;
3285  }
3286  else
3287  {
3288  Int iTDB = Clip3( -128, 127, iDiffPocB );
3289  Int iTDD = Clip3( -128, 127, iDiffPocD );
3290  Int iX = (0x4000 + abs(iTDD/2)) / iTDD;
3291  Int iScale = Clip3( -4096, 4095, (iTDB * iX + 32) >> 6 );
3292  return iScale;
3293  }
3294 }
3295 
3296 Void TComDataCU::xDeriveCenterIdx( UInt uiPartIdx, UInt& ruiPartIdxCenter )
3297 {
3298  UInt uiPartAddr;
3299  Int iPartWidth;
3300  Int iPartHeight;
3301  getPartIndexAndSize( uiPartIdx, uiPartAddr, iPartWidth, iPartHeight);
3302 
3303  ruiPartIdxCenter = m_absZIdxInCtu+uiPartAddr; // partition origin.
3304  ruiPartIdxCenter = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxCenter ]
3305  + ( iPartHeight/m_pcPic->getMinCUHeight() )/2*m_pcPic->getNumPartInCtuWidth()
3306  + ( iPartWidth/m_pcPic->getMinCUWidth() )/2];
3307 }
3308 
3310 {
3311  Int scaleFactor = 4 * AMVP_DECIMATION_FACTOR / m_unitSize;
3312  if (scaleFactor > 0)
3313  {
3314  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
3315  {
3316  m_acCUMvField[i].compress(m_pePredMode, scaleFactor);
3317  }
3318  }
3319 }
3320 
3321 UInt TComDataCU::getCoefScanIdx(const UInt uiAbsPartIdx, const UInt uiWidth, const UInt uiHeight, const ComponentID compID) const
3322 {
3323  //------------------------------------------------
3324 
3325  //this mechanism is available for intra only
3326 
3327  if (!isIntra(uiAbsPartIdx))
3328  {
3329  return SCAN_DIAG;
3330  }
3331 
3332  //------------------------------------------------
3333 
3334  //check that MDCS can be used for this TU
3335 
3336  const ChromaFormat format = getPic()->getChromaFormat();
3337 
3338  const UInt maximumWidth = MDCS_MAXIMUM_WIDTH >> getComponentScaleX(compID, format);
3339  const UInt maximumHeight = MDCS_MAXIMUM_HEIGHT >> getComponentScaleY(compID, format);
3340 
3341  if ((uiWidth > maximumWidth) || (uiHeight > maximumHeight))
3342  {
3343  return SCAN_DIAG;
3344  }
3345 
3346  //------------------------------------------------
3347 
3348  //otherwise, select the appropriate mode
3349 
3350  UInt uiDirMode = getIntraDir(toChannelType(compID), uiAbsPartIdx);
3351 
3352  if (uiDirMode==DM_CHROMA_IDX)
3353  {
3354  uiDirMode = getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, getPic()->getChromaFormat()));
3355  }
3356 
3357  if (isChroma(compID) && (format == CHROMA_422))
3358  {
3359  uiDirMode = g_chroma422IntraAngleMappingTable[uiDirMode];
3360  }
3361 
3362  //------------------
3363 
3364  if (abs((Int)uiDirMode - VER_IDX) <= MDCS_ANGLE_LIMIT)
3365  {
3366  return SCAN_HOR;
3367  }
3368  else if (abs((Int)uiDirMode - HOR_IDX) <= MDCS_ANGLE_LIMIT)
3369  {
3370  return SCAN_VER;
3371  }
3372  else
3373  {
3374  return SCAN_DIAG;
3375  }
3376 }
3377 
UInt g_uiMaxCUDepth
Definition: TComRom.cpp:253
Char * m_apiMVPIdx[NUM_REF_PIC_LIST_01]
array of motion vector predictor candidates
Definition: TComDataCU.h:139
TComDataCU * getPUAboveLeft(UInt &uiALPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction=true)
Char * getQP()
Definition: TComDataCU.h:255
MVP of above block.
Definition: TypeDef.h:492
UInt m_absZIdxInCtu
absolute address in a CTU. It's Z scan order
Definition: TComDataCU.h:80
Int getRefIdx(Int iIdx) const
Void setMVPNumSubParts(Int iMVPNum, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
UInt m_uiTotalBins
sum of partition bins
Definition: TComDataCU.h:151
UInt & getTotalBins()
Definition: TComDataCU.h:467
Void linkToWithOffset(TComCUMvField const *src, Int offset)
CU data structure class.
Definition: TComDataCU.h:64
TCoeff * getArlCoeff(ComponentID component)
Definition: TComDataCU.h:299
ChannelType
Definition: TypeDef.h:361
UChar getQtRootCbf(UInt uiIdx)
UChar * m_puhDepth
array of depths
Definition: TComDataCU.h:86
Int getHor() const
Definition: TComMv.h:88
Void setMergeFlagSubParts(Bool bMergeFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
picture class (symbol + YUV buffers)
Definition: TComPic.h:56
Char * m_pePartSize
array of partition sizes
Definition: TComDataCU.h:94
void Void
Definition: TypeDef.h:285
Void create(ChromaFormat chromaFormatIDC, UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize, Bool bGlobalRMARLBuffer=false)
Definition: TComDataCU.cpp:114
UChar * getExplicitRdpcmMode(ComponentID component)
Definition: TComDataCU.h:283
TComDataCU * getPUBelowLeft(UInt &uiBLPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction=true)
UInt getCtxSplitFlag(UInt uiAbsPartIdx, UInt uiDepth)
UInt g_auiRasterToPelX[((1<<(6))/4)*((1<<(6))/4)]
Definition: TComRom.cpp:257
UChar * getTransformIdx()
Definition: TComDataCU.h:274
#define NUM_CHROMA_MODE
Definition: TypeDef.h:184
#define NULL
Definition: CommonDef.h:100
TComMv const & getMv() const
Bool isSkipped(UInt uiPartIdx)
returns true, if the partiton is skipped
TComSlice * getSlice(Int i)
Definition: TComPic.h:103
class for motion vector with reference index
static Bool isEqualCol(Int addrA, Int addrB, Int numUnitsPerRow)
Definition: TComDataCU.h:489
static UInt getComponentScaleY(const ComponentID id, const ChromaFormat fmt)
UInt m_uiTotalBits
sum of partition bits
Definition: TComDataCU.h:150
char Char
Definition: TypeDef.h:291
MVP of above left block.
Definition: TypeDef.h:495
Char g_aucConvertToBit[(1<<(6))+1]
Definition: TComRom.cpp:558
unsigned int UInt
Definition: TypeDef.h:297
Bool * getSkipFlag()
Definition: TComDataCU.h:229
UInt getNumPartitionsInCtu() const
Definition: TComPic.h:119
TComDataCU * getPULeft(UInt &uiLPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction=true, Bool bEnforceTileRestriction=true)
#define MDCS_MAXIMUM_HEIGHT
(default 8) (measured in pixels) TUs with height greater than this can only use diagonal scan ...
Definition: TypeDef.h:191
static UInt getComponentScaleX(const ComponentID id, const ChromaFormat fmt)
TComPic * m_pcPic
picture class pointer
Definition: TComDataCU.h:72
TComDataCU * getCtuAboveLeft()
Definition: TComDataCU.h:397
Bool getIsLongTerm() const
Definition: TComPic.h:97
#define VER_IDX
Definition: TypeDef.h:181
Bool isFirstAbsZorderIdxInDepth(UInt uiAbsPartIdx, UInt uiDepth)
Short Pel
pixel type
Definition: TypeDef.h:692
static UInt getChromasCorrespondingPULumaIdx(const UInt lumaZOrderIdxInCtu, const ChromaFormat chFmt)
Bool CUIsFromSameTile(const TComDataCU *pCU) const
Definition: TComDataCU.cpp:396
Void initCtu(TComPic *pcPic, UInt ctuRsAddr)
Definition: TComDataCU.cpp:448
symmetric motion partition, 2Nx N
Definition: TypeDef.h:396
UInt getMinCUHeight() const
Definition: TComPicSym.h:131
TComDataCU * getCtuAboveRight()
Definition: TComDataCU.h:398
#define DC_IDX
Definition: TypeDef.h:183
UInt getIntraSizeIdx(UInt uiAbsPartIdx)
static Bool isEqualRowOrCol(Int addrA, Int addrB, Int numUnitsPerRow)
Definition: TComDataCU.h:513
Void initSubCU(TComDataCU *pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp)
Definition: TComDataCU.cpp:635
Char getLastCodedQP(UInt uiAbsPartIdx)
UChar getNumPartitions(const UInt uiAbsPartIdx=0)
UInt getMaxCUHeight() const
Definition: TComSlice.h:847
UChar * m_puhCbf[MAX_NUM_COMPONENT]
array of coded block flags (CBF)
Definition: TComDataCU.h:103
UInt GetTransformDepthRel() const
Definition: TComTU.h:108
Int getNumberValidComponents() const
Definition: TComPic.h:129
UChar * m_puhMergeIndex
array of merge candidate indices
Definition: TComDataCU.h:133
picture class (header)
Void copyPartFrom(TComDataCU *pcCU, UInt uiPartUnitIdx, UInt uiDepth)
Definition: TComDataCU.cpp:871
Void setOutsideCUPart(UInt uiAbsPartIdx, UInt uiDepth)
Definition: TComDataCU.cpp:728
UChar * getMergeIndex()
Definition: TComDataCU.h:326
UChar * getInterDir()
Definition: TComDataCU.h:346
Int getNumRefIdx(RefPicList e) const
Definition: TComSlice.h:1353
TComDataCU * getCUColocated(RefPicList eRefPicList)
Definition: TComDataCU.h:399
UInt getMinCUWidth() const
Definition: TComPic.h:122
UChar getCbf(UInt uiIdx, ComponentID eType)
Definition: TComDataCU.h:303
UInt getCtxQtCbf(TComTU &rTu, const ChannelType chType)
UChar * m_puhTrIdx
array of transform indices
Definition: TComDataCU.h:101
Void setIntraDirSubParts(const ChannelType channelType, const UInt uiDir, const UInt uiAbsPartIdx, const UInt uiDepth)
#define PLANAR_IDX
Definition: TypeDef.h:180
Void setHor(Short i)
Definition: TComMv.h:80
Bool isInterB() const
Definition: TComSlice.h:1405
UInt getZorderIdxInCtu() const
Definition: TComDataCU.h:209
Distortion & getTotalDistortion()
Definition: TComDataCU.h:473
Bool m_bDecSubCu
indicates decoder-mode
Definition: TComDataCU.h:147
static Bool lessThanCol(Int addr, Int val, Int numUnitsPerRow)
Definition: TComDataCU.h:546
TComDataCU * m_apcCUColocated[NUM_REF_PIC_LIST_01]
pointer of temporally colocated CU's for both directions
Definition: TComDataCU.h:122
Void setCrossComponentPredictionAlphaPartRange(Char alphaValue, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes)
Bool CUIsFromSameSlice(const TComDataCU *pCU) const
Definition: TComDataCU.h:400
TComDataCU * m_pCtuAboveRight
pointer of above-right CTU.
Definition: TComDataCU.h:119
Bool isInter(UInt uiPartIdx) const
Definition: TComDataCU.h:444
UInt getNumPartInCtuHeight() const
Definition: TComPic.h:118
Void getPartPosition(UInt partIdx, Int &xP, Int &yP, Int &nPSW, Int &nPSH)
Char * m_pePredMode
array of prediction modes
Definition: TComDataCU.h:95
horizontal first scan
Definition: TypeDef.h:524
#define AMVP_MAX_NUM_CANDS
max number of final candidates
Definition: CommonDef.h:183
Void setCbfPartRange(UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes)
Void setPartSizeSubParts(PartSize eMode, UInt uiAbsPartIdx, UInt uiDepth)
Void copyFrom(TComCUMvField const *pcCUMvFieldSrc, Int iNumPartSrc, Int iPartAddrDst)
class for motion information in one CU
static Bool isEqualRow(Int addrA, Int addrB, Int numUnitsPerRow)
Definition: TComDataCU.h:501
Void deriveLeftBottomIdx(UInt uiPartIdx, UInt &ruiPartIdxLB)
Void clearCbf(UInt uiIdx, ComponentID eType, UInt uiNumParts)
PartSize
supported partition shape
Definition: TypeDef.h:393
UInt getNumPartInCtuWidth() const
Definition: TComPic.h:117
Void setTransformSkipPartRange(UInt useTransformSkip, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes)
Char * m_phQP
array of QP values
Definition: TComDataCU.h:98
Bool CUIsFromSameSliceTileAndWavefrontRow(const TComDataCU *pCU) const
Definition: TComDataCU.cpp:412
UInt m_uiCUPelY
CU position in a pixel (Y)
Definition: TComDataCU.h:82
Bool * getIPCMFlag()
Definition: TComDataCU.h:350
UInt g_auiRasterToZscan[((1<<(6))/4)*((1<<(6))/4)]
Definition: TComRom.cpp:256
Double & getTotalCost()
Definition: TComDataCU.h:472
const UChar g_chroma422IntraAngleMappingTable[36]
Definition: TComRom.cpp:540
#define MAX_UINT
max. value of unsigned 32-bit integer
Definition: CommonDef.h:115
UChar * getIntraDir(const ChannelType channelType) const
Definition: TComDataCU.h:338
Void setMvField(TComMv const &cMv, Int iRefIdx)
TComDataCU * getPUAboveRightAdi(UInt &uiARPartUnitIdx, UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset=1, Bool bEnforceSliceRestriction=true)
UChar * m_puhInterDir
array of inter directions
Definition: TComDataCU.h:138
Void compress(Char *pePredMode, Int scale)
Int getMVPNum(RefPicList eRefPicList, UInt uiIdx)
Definition: TComDataCU.h:378
UInt xGetMvdBits(TComMv cMvd)
compute required bits to encode MVD (used in AMVP)
#define NOT_VALID
Definition: CommonDef.h:129
UInt getMaxNumMergeCand() const
Definition: TComSlice.h:1451
UInt getTileIdxMap(Int ctuRsAddr) const
Definition: TComPicSym.h:151
Int iN
number of motion vector predictor candidates
symmetric motion partition, 2Nx2N
Definition: TypeDef.h:395
Void copyToPic(UChar uiDepth)
Definition: TComDataCU.cpp:957
Bool xAddMVPCand(AMVPInfo *pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir)
add possible motion vector predictor candidates
static Bool lessThanRow(Int addr, Int val, Int numUnitsPerRow)
Definition: TComDataCU.h:558
virtual ~TComDataCU()
Definition: TComDataCU.cpp:110
bool Bool
Definition: TypeDef.h:286
Bool isIntra(UInt uiPartIdx) const
Definition: TComDataCU.h:443
Void setDepthSubParts(UInt uiDepth, UInt uiAbsPartIdx)
Void setQPSubCUs(Int qp, UInt absPartIdx, UInt depth, Bool &foundNonZeroCbf)
Int getLastValidPartIdx(Int iAbsPartIdx)
TComDataCU * m_pCtuAbove
pointer of above CTU.
Definition: TComDataCU.h:120
Void setCUTransquantBypassSubParts(Bool flag, UInt uiAbsPartIdx, UInt uiDepth)
UInt g_uiMaxCUHeight
Definition: TComRom.cpp:252
#define ADAPTIVE_QP_SELECTION
G382: Adaptive reconstruction levels, non-normative part for adaptive QP selection.
Definition: TypeDef.h:148
Double m_dTotalCost
sum of partition RD costs
Definition: TComDataCU.h:148
Void setInterDirSubParts(UInt uiDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
UInt g_uiMaxCUWidth
Definition: TComRom.cpp:251
#define AMVP_DECIMATION_FACTOR
Definition: TypeDef.h:163
TCoeff * m_pcTrCoeff[MAX_NUM_COMPONENT]
array of transform coefficient buffers (0->Y, 1->Cb, 2->Cr)
Definition: TComDataCU.h:105
Pel * m_pcIPCMSample[MAX_NUM_COMPONENT]
PCM sample buffer (0->Y, 1->Cb, 2->Cr)
Definition: TComDataCU.h:112
Void setTransformSkipSubParts(UInt useTransformSkip, ComponentID compID, UInt uiAbsPartIdx, UInt uiDepth)
Void setVer(Short i)
Definition: TComMv.h:81
static Bool isZeroRow(Int addr, Int numUnitsPerRow)
Definition: TComDataCU.h:534
Void copyInterPredInfoFrom(TComDataCU *pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList)
Definition: TComDataCU.cpp:827
UInt getMinCUHeight() const
Definition: TComPic.h:123
UInt getQuadtreeTUMaxDepthIntra() const
Definition: TComSlice.h:867
asymmetric motion partition, 2Nx( N/2) + 2Nx(3N/2)
Definition: TypeDef.h:399
Void deriveLeftRightTopIdxGeneral(UInt uiAbsPartIdx, UInt uiPartIdx, UInt &ruiPartIdxLT, UInt &ruiPartIdxRT)
Char getRefQP(UInt uiCurrAbsIdxInCtu)
Void getPartIndexAndSize(UInt uiPartIdx, UInt &ruiPartAddr, Int &riWidth, Int &riHeight)
Void setNumPartition(Int iNumPart)
asymmetric motion partition, (3N/2)x2N + ( N/2)x2N
Definition: TypeDef.h:402
UInt getCtxInterDir(UInt uiAbsPartIdx)
parameters for AMVP
MVP_DIR
motion vector predictor direction used in AMVP
Definition: TypeDef.h:489
UInt & getCtuRsAddr()
Definition: TComDataCU.h:207
Void getAllowedChromaDir(UInt uiAbsPartIdx, UInt *uiModeList)
UInt getPicHeightInLumaSamples() const
Definition: TComSlice.h:824
up-right diagonal scan
Definition: TypeDef.h:523
Void deriveLeftBottomIdxGeneral(UInt uiAbsPartIdx, UInt uiPartIdx, UInt &ruiPartIdxLB)
TComDataCU * getCtuLeft()
Definition: TComDataCU.h:395
MVP of above right block.
Definition: TypeDef.h:493
UInt getCUPelY() const
Definition: TComDataCU.h:211
static ChannelType toChannelType(const ComponentID id)
T Clip3(const T minVal, const T maxVal, const T a)
general min/max clip
Definition: CommonDef.h:137
TComMv const & getMv(Int iIdx) const
#define MDCS_ANGLE_LIMIT
(default 4) 0 = Horizontal/vertical only, 1 = Horizontal/vertical +/- 1, 2 = Horizontal/vertical +/- ...
Definition: TypeDef.h:189
reference list 0
Definition: TypeDef.h:417
UChar * m_puhTransformSkip[MAX_NUM_COMPONENT]
array of transform skipping flags
Definition: TComDataCU.h:102
Int TCoeff
transform coefficient
Definition: TypeDef.h:693
Void setCbfSubParts(const UInt uiCbf[MAX_NUM_COMPONENT], UInt uiAbsPartIdx, UInt uiDepth)
UInt g_auiZscanToRaster[((1<<(6))/4)*((1<<(6))/4)]
Definition: TComRom.cpp:255
Int getComponentScaleX(const ComponentID id) const
Definition: TComPic.h:126
UChar * m_ChromaQpAdj
array of chroma QP adjustments (indexed). when value = 0, cu_chroma_qp_offset_flag=0; when value>0...
Definition: TComDataCU.h:99
RefPicList
reference list index
Definition: TypeDef.h:415
UInt getCtxSkipFlag(UInt uiAbsPartIdx)
TComPicSym * getPicSym()
Definition: TComPic.h:102
UInt getMaxCuDQPDepth() const
Definition: TComSlice.h:1056
Void compressMV()
ChromaFormat
chroma formats (according to semantics of chroma_format_idc)
Definition: TypeDef.h:352
#define xFree(ptr)
Definition: CommonDef.h:157
unsigned char UChar
Definition: TypeDef.h:293
UInt getQuadtreeTULog2MinSize() const
Definition: TComSlice.h:863
#define MDCS_MAXIMUM_WIDTH
(default 8) (measured in pixels) TUs with width greater than this can only use diagonal scan ...
Definition: TypeDef.h:190
Char * getCrossComponentPredictionAlpha(ComponentID compID)
Definition: TComDataCU.h:239
Bool xGetColMVP(RefPicList eRefPicList, Int ctuRsAddr, Int uiPartUnitIdx, TComMv &rcMv, Int &riRefIdx)
UInt g_auiRasterToPelY[((1<<(6))/4)*((1<<(6))/4)]
Definition: TComRom.cpp:258
Distortion m_uiTotalDistortion
sum of partition distortion
Definition: TComDataCU.h:149
UInt m_uiCUPelX
CU position in a pixel (X)
Definition: TComDataCU.h:81
Char * m_apiMVPNum[NUM_REF_PIC_LIST_01]
array of number of possible motion vectors predictors
Definition: TComDataCU.h:140
UChar * getDepth()
Definition: TComDataCU.h:213
Void copyTo(TComCUMvField *pcCUMvFieldDst, Int iPartAddrDst) const
Void setChromaQpAdjSubParts(UChar val, Int absPartIdx, Int depth)
TComCUMvField m_acCUMvField[NUM_REF_PIC_LIST_01]
array of motion vectors.
Definition: TComDataCU.h:104
Bool isBipredRestriction(UInt puIdx)
Bool getIsUsedAsLongTerm(Int i, Int j) const
Definition: TComSlice.h:1361
Bool hasEqualMotion(UInt uiAbsPartIdx, TComDataCU *pcCandCU, UInt uiCandAbsPartIdx)
const TComPPS * getPPS() const
Definition: TComSlice.h:1309
UInt getPicWidthInLumaSamples() const
Definition: TComSlice.h:822
UInt & getTotalBits()
Definition: TComDataCU.h:474
UInt getCUPelX() const
Definition: TComDataCU.h:210
Bool CUIsFromSameSliceAndTile(const TComDataCU *pCU) const
Definition: TComDataCU.cpp:403
Int getVer() const
Definition: TComMv.h:89
UChar * getTransformSkip(ComponentID compID)
Definition: TComDataCU.h:278
ChromaFormat getChromaFormat() const
Definition: TComPic.h:128
UInt getCoefScanIdx(const UInt uiAbsPartIdx, const UInt uiWidth, const UInt uiHeight, const ComponentID compID) const
#define xMalloc(type, len)
Definition: CommonDef.h:156
reference list 1
Definition: TypeDef.h:418
Void setSubPart(T bParameter, T *pbBaseCtu, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx)
UChar * getHeight()
Definition: TComDataCU.h:249
Void setSizeSubParts(UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, UInt uiDepth)
UInt getCurrSliceIdx() const
Definition: TComPic.h:137
#define DM_CHROMA_IDX
Definition: TypeDef.h:185
Int getPOC() const
Definition: TComSlice.h:1338
#define HOR_IDX
Definition: TypeDef.h:182
Bool getEntropyCodingSyncEnabledFlag() const
Definition: TComSlice.h:1127
Int getPOC() const
Definition: TComPic.h:104
MVP of below left block.
Definition: TypeDef.h:494
Void deriveLeftRightTopIdx(UInt uiPartIdx, UInt &ruiPartIdxLT, UInt &ruiPartIdxRT)
TComDataCU * m_pCtuLeft
pointer of left CTU
Definition: TComDataCU.h:121
MVP of left block.
Definition: TypeDef.h:491
TComDataCU * getPUAboveRight(UInt &uiARPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction=true)
static Bool isZeroCol(Int addr, Int numUnitsPerRow)
Definition: TComDataCU.h:523
Bool * getCUTransquantBypass()
Definition: TComDataCU.h:242
UInt getSliceCurStartCtuTsAddr() const
Definition: TComSlice.h:1467
asymmetric motion partition, ( N/2)x2N + (3N/2)x2N
Definition: TypeDef.h:401
UChar * m_puhWidth
array of widths
Definition: TComDataCU.h:84
Void setMVPIdxSubParts(Int iMVPIdx, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
Void getInterMergeCandidates(UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField *pcMFieldNeighbours, UChar *puhInterDirNeighbours, Int &numValidMergeCand, Int mrgCandIdx=-1)
Construct a list of merging candidates.
TComPic * getPic()
Definition: TComDataCU.h:203
Void deriveLeftRightTopIdxAdi(UInt &ruiPartIdxLT, UInt &ruiPartIdxRT, UInt uiPartOffset, UInt uiPartDepth)
TComDataCU * getCtu(UInt ctuRsAddr)
Definition: TComPic.h:105
Int getMVPIdx(RefPicList eRefPicList, UInt uiIdx)
Definition: TComDataCU.h:374
Char * m_crossComponentPredictionAlpha[MAX_NUM_COMPONENT]
array of cross-component prediction alpha values
Definition: TComDataCU.h:96
Definition: TComTU.h:48
Int xGetDistScaleFactor(Int iCurrPOC, Int iCurrRefPOC, Int iColPOC, Int iColRefPOC)
compute scaling factor from POC difference
UInt m_uiNumPartition
total number of minimum partitions in a CU
Definition: TComDataCU.h:83
Void getMvField(TComDataCU *pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList, TComMvField &rcMvField)
Char * getPartitionSize()
Definition: TComDataCU.h:223
Int getRefPOC(RefPicList e, Int iRefIdx)
Definition: TComSlice.h:1356
Void getIntraDirPredictor(UInt uiAbsPartIdx, Int uiIntraDirPred[NUM_MOST_PROBABLE_MODES], const ComponentID compID, Int *piMode=0)
UInt m_ctuRsAddr
CTU (also known as LCU) address in a slice (Raster-scan address, as opposed to tile-scan/encoding ord...
Definition: TComDataCU.h:79
Void setIPCMFlagSubParts(Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
Void setQPSubParts(Int qp, UInt uiAbsPartIdx, UInt uiDepth)
Char * getPredictionMode()
Definition: TComDataCU.h:234
TComDataCU * getCtuAbove()
Definition: TComDataCU.h:396
Bool m_ArlCoeffIsAliasedAllocation
ARL coefficient buffer is an alias of the global buffer and must not be free()'d. ...
Definition: TComDataCU.h:109
Void fillMvpCand(UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo *pInfo)
Void copySubCU(TComDataCU *pcCU, UInt uiPartUnitIdx, UInt uiDepth)
Definition: TComDataCU.cpp:744
Void setTrIdxSubParts(UInt uiTrIdx, UInt uiAbsPartIdx, UInt uiDepth)
TComCUMvField * getCUMvField(RefPicList e)
Definition: TComDataCU.h:294
UInt getLog2ParallelMergeLevelMinus2() const
Definition: TComSlice.h:1164
UChar * getWidth()
Definition: TComDataCU.h:245
TCoeff * getCoeff(ComponentID component)
Definition: TComDataCU.h:296
Void bitwiseOrCbfPartRange(UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes)
Bool * m_CUTransquantBypass
array of cu_transquant_bypass flags
Definition: TComDataCU.h:97
int Int
Definition: TypeDef.h:296
basic motion vector class
Definition: TComMv.h:51
static Bool isChroma(const ComponentID id)
UInt getQuadtreeTULog2MaxSize() const
Definition: TComSlice.h:861
UInt & getTotalNumPart()
Definition: TComDataCU.h:475
Int getComponentScaleY(const ComponentID id) const
Definition: TComPic.h:127
ComponentID
Definition: TypeDef.h:368
PredMode
supported prediction type
Definition: TypeDef.h:407
Bool * getMergeFlag()
Definition: TComDataCU.h:321
Int getSliceQp() const
Definition: TComSlice.h:1339
TCoeff * m_pcArlCoeff[MAX_NUM_COMPONENT]
Definition: TComDataCU.h:107
static TCoeff * m_pcGlbArlCoeff[MAX_NUM_COMPONENT]
Definition: TComDataCU.h:108
#define MAX_DOUBLE
max. value of Double-type value
Definition: CommonDef.h:124
#define MRG_MAX_NUM_CANDS
Definition: CommonDef.h:186
Void deriveRightBottomIdx(UInt uiPartIdx, UInt &ruiPartIdxRB)
TComSlice * m_pcSlice
slice header pointer
Definition: TComDataCU.h:73
Void setSkipFlagSubParts(Bool skip, UInt absPartIdx, UInt depth)
asymmetric motion partition, 2Nx(3N/2) + 2Nx( N/2)
Definition: TypeDef.h:400
TComDataCU * m_pCtuAboveLeft
pointer of above-left CTU.
Definition: TComDataCU.h:118
TComDataCU * getQpMinCuLeft(UInt &uiLPartUnitIdx, UInt uiCurrAbsIdxInCtu)
UInt getQuadtreeTULog2MinSizeInCU(UInt uiIdx)
UChar * m_puhHeight
array of heights
Definition: TComDataCU.h:85
Bool * m_skipFlag
array of skip flags
Definition: TComDataCU.h:93
symmetric motion partition, Nx N
Definition: TypeDef.h:398
Void create(UInt uiNumPartition)
Pel * getPCMSample(ComponentID component)
Definition: TComDataCU.h:301
const TComMv scaleMv(Int iScale) const
Definition: TComMv.h:145
Void clipMv(TComMv &rcMv)
Void set(Short iHor, Short iVer)
Definition: TComMv.h:79
Bool * m_pbIPCMFlag
array of intra_pcm flags
Definition: TComDataCU.h:141
Void initEstData(const UInt uiDepth, const Int qp, const Bool bTransquantBypass)
Definition: TComDataCU.cpp:564
TComDataCU * getPUBelowLeftAdi(UInt &uiBLPartUnitIdx, UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset=1, Bool bEnforceSliceRestriction=true)
UInt getQuadtreeTUMaxDepthInter() const
Definition: TComSlice.h:866
CU data structure (header)
vertical first scan
Definition: TypeDef.h:525
slice header class
Definition: TComSlice.h:1198
Bool isLastSubCUOfCtu(const UInt absPartIdx)
Definition: TComDataCU.cpp:418
Void deriveLeftBottomIdxAdi(UInt &ruiPartIdxLB, UInt uiPartOffset, UInt uiPartDepth)
Bool isLosslessCoded(UInt absPartIdx)
Void xDeriveCenterIdx(UInt uiPartIdx, UInt &ruiPartIdxCenter)
TComMv m_acMvCand[3]
array of motion vector predictor candidates
static const UInt NUM_MOST_PROBABLE_MODES
Definition: TComDataCU.h:57
UChar * getChromaQpAdj()
array of chroma QP adjustments (indexed). when value = 0, cu_chroma_qp_offset_flag=0; when value>0...
Definition: TComDataCU.h:265
UInt getFrameWidthInCtus() const
Definition: TComPic.h:120
TComPic * getRefPic(RefPicList e, Int iRefIdx)
Definition: TComSlice.h:1355
Bool getCheckLDC() const
Definition: TComSlice.h:1363
Int m_unitSize
size of a "minimum partition"
Definition: TComDataCU.h:87
symmetric motion partition, Nx2N
Definition: TypeDef.h:397
Void setMergeIndexSubParts(UInt uiMergeIndex, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
UChar * m_explicitRdpcmMode[MAX_NUM_COMPONENT]
Stores the explicit RDPCM mode for all TUs belonging to this CU.
Definition: TComDataCU.h:153
Bool * m_pbMergeFlag
array of merge flags
Definition: TComDataCU.h:132
UInt xGetComponentBits(Int iVal)
TComDataCU * getQpMinCuAbove(UInt &uiAPartUnitIdx, UInt uiCurrAbsIdxInCtu)
UInt getMaxCUWidth() const
Definition: TComSlice.h:845
Bool xAddMVPCandOrder(AMVPInfo *pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir)
TComSlice * getSlice()
Definition: TComDataCU.h:205
Void destroy()
Definition: TComDataCU.cpp:221
const TComSPS * getSPS() const
Definition: TComSlice.h:1306
Void setPredModeSubParts(PredMode eMode, UInt uiAbsPartIdx, UInt uiDepth)
Bool isDiffMER(Int xN, Int yN, Int xP, Int yP)
TComDataCU * getPUAbove(UInt &uiAPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction=true, Bool planarAtCTUBoundary=false, Bool bEnforceTileRestriction=true)
Void setExplicitRdpcmModePartRange(UInt rdpcmMode, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes)
UChar * m_puhIntraDir[MAX_NUM_CHANNEL_TYPE]
Definition: TComDataCU.h:137