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