HEVC Test Model (HM)  HM-16.3
TComPrediction.cpp
Go to the documentation of this file.
1 /* The copyright in this software is being made available under the BSD
2  * License, included below. This software may be subject to other third party
3  * and contributor rights, including patent rights, and no such rights are
4  * granted under this license.
5  *
6  * Copyright (c) 2010-2015, ITU/ISO/IEC
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18  * be used to endorse or promote products derived from this software without
19  * specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31  * THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
38 #include <memory.h>
39 #include "TComPrediction.h"
40 #include "TComPic.h"
41 #include "TComTU.h"
42 
45 
46 // ====================================================================================================================
47 // Tables
48 // ====================================================================================================================
49 
51 {
52  { // Luma
53  10, //4x4
54  7, //8x8
55  1, //16x16
56  0, //32x32
57  10, //64x64
58  },
59  { // Chroma
60  10, //4xn
61  7, //8xn
62  1, //16xn
63  0, //32xn
64  10, //64xn
65  }
66 
67 };
68 
69 // ====================================================================================================================
70 // Constructor / destructor / initialize
71 // ====================================================================================================================
72 
74 : m_pLumaRecBuffer(0)
75 , m_iLumaRecStride(0)
76 {
77  for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
78  {
79  for(UInt buf=0; buf<2; buf++)
80  {
81  m_piYuvExt[ch][buf] = NULL;
82  }
83  }
84 }
85 
87 {
88  destroy();
89 }
90 
92 {
93  for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
94  {
95  for(UInt buf=0; buf<NUM_PRED_BUF; buf++)
96  {
97  delete [] m_piYuvExt[ch][buf];
98  m_piYuvExt[ch][buf] = NULL;
99  }
100  }
101 
102  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
103  {
104  m_acYuvPred[i].destroy();
105  }
106 
108 
109  if( m_pLumaRecBuffer )
110  {
111  delete [] m_pLumaRecBuffer;
112  m_pLumaRecBuffer = 0;
113  }
114  m_iLumaRecStride = 0;
115 
117  {
119  {
120  m_filteredBlock[i][j].destroy();
121  }
123  }
124 }
125 
127 {
128  // if it has been initialised before, but the chroma format has changed, release the memory and start again.
130  {
131  destroy();
132  }
133 
134  if( m_piYuvExt[COMPONENT_Y][PRED_BUF_UNFILTERED] == NULL ) // check if first is null (in which case, nothing initialised yet)
135  {
136  Int extWidth = MAX_CU_SIZE + 16;
137  Int extHeight = MAX_CU_SIZE + 1;
138 
140  {
141  m_filteredBlockTmp[i].create(extWidth, extHeight + 7, chromaFormatIDC);
143  {
144  m_filteredBlock[i][j].create(extWidth, extHeight, chromaFormatIDC);
145  }
146  }
147 
148  m_iYuvExtSize = (MAX_CU_SIZE*2+1) * (MAX_CU_SIZE*2+1);
149  for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
150  {
151  for(UInt buf=0; buf<NUM_PRED_BUF; buf++)
152  {
153  m_piYuvExt[ch][buf] = new Pel[ m_iYuvExtSize ];
154  }
155  }
156 
157  // new structure
158  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
159  {
160  m_acYuvPred[i] .create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC );
161  }
162 
163  m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC );
164  }
165 
166 
167  if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1)
168  {
169  m_iLumaRecStride = (MAX_CU_SIZE>>1) + 1;
170  if (!m_pLumaRecBuffer)
171  {
173  }
174  }
175 }
176 
177 // ====================================================================================================================
178 // Public member functions
179 // ====================================================================================================================
180 
181 // Function for calculating DC value of the reference samples used in Intra prediction
182 //NOTE: Bit-Limit - 25-bit source
183 Pel TComPrediction::predIntraGetPredValDC( const Pel* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, ChannelType channelType, ChromaFormat format, Bool bAbove, Bool bLeft )
184 {
185  assert(iWidth > 0 && iHeight > 0);
186  Int iInd, iSum = 0;
187  Pel pDcVal;
188 
189  if (bAbove)
190  {
191  for (iInd = 0;iInd < iWidth;iInd++)
192  {
193  iSum += pSrc[iInd-iSrcStride];
194  }
195  }
196  if (bLeft)
197  {
198  for (iInd = 0;iInd < iHeight;iInd++)
199  {
200  iSum += pSrc[iInd*iSrcStride-1];
201  }
202  }
203 
204  if (bAbove && bLeft)
205  {
206  pDcVal = (iSum + iWidth) / (iWidth + iHeight);
207  }
208  else if (bAbove)
209  {
210  pDcVal = (iSum + iWidth/2) / iWidth;
211  }
212  else if (bLeft)
213  {
214  pDcVal = (iSum + iHeight/2) / iHeight;
215  }
216  else
217  {
218  pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available
219  }
220 
221  return pDcVal;
222 }
223 
224 // Function for deriving the angular Intra predictions
225 
249 //NOTE: Bit-Limit - 25-bit source
251  const Pel* pSrc, Int srcStride,
252  Pel* pTrueDst, Int dstStrideTrue,
253  UInt uiWidth, UInt uiHeight, ChannelType channelType, ChromaFormat format,
254  UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable
255  , const Bool bEnableEdgeFilters
256  )
257 {
258  Int width=Int(uiWidth);
259  Int height=Int(uiHeight);
260 
261  // Map the mode index to main prediction direction and angle
262  assert( dirMode != PLANAR_IDX ); //no planar
263  const Bool modeDC = dirMode==DC_IDX;
264 
265  // Do the DC prediction
266  if (modeDC)
267  {
268  const Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, channelType, format, blkAboveAvailable, blkLeftAvailable);
269 
270  for (Int y=height;y>0;y--, pTrueDst+=dstStrideTrue)
271  {
272  for (Int x=0; x<width;) // width is always a multiple of 4.
273  {
274  pTrueDst[x++] = dcval;
275  }
276  }
277  }
278  else // Do angular predictions
279  {
280  const Bool bIsModeVer = (dirMode >= 18);
281  const Int intraPredAngleMode = (bIsModeVer) ? (Int)dirMode - VER_IDX : -((Int)dirMode - HOR_IDX);
282  const Int absAngMode = abs(intraPredAngleMode);
283  const Int signAng = intraPredAngleMode < 0 ? -1 : 1;
284  const Bool edgeFilter = bEnableEdgeFilters && isLuma(channelType) && (width <= MAXIMUM_INTRA_FILTERED_WIDTH) && (height <= MAXIMUM_INTRA_FILTERED_HEIGHT);
285 
286  // Set bitshifts and scale the angle parameter to block size
287  static const Int angTable[9] = {0, 2, 5, 9, 13, 17, 21, 26, 32};
288  static const Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle
289  Int invAngle = invAngTable[absAngMode];
290  Int absAng = angTable[absAngMode];
291  Int intraPredAngle = signAng * absAng;
292 
293  Pel* refMain;
294  Pel* refSide;
295 
296  Pel refAbove[2*MAX_CU_SIZE+1];
297  Pel refLeft[2*MAX_CU_SIZE+1];
298 
299  // Initialise the Main and Left reference array.
300  if (intraPredAngle < 0)
301  {
302  const Int refMainOffsetPreScale = (bIsModeVer ? height : width ) - 1;
303  const Int refMainOffset = height - 1;
304  for (Int x=0;x<width+1;x++)
305  {
306  refAbove[x+refMainOffset] = pSrc[x-srcStride-1];
307  }
308  for (Int y=0;y<height+1;y++)
309  {
310  refLeft[y+refMainOffset] = pSrc[(y-1)*srcStride-1];
311  }
312  refMain = (bIsModeVer ? refAbove : refLeft) + refMainOffset;
313  refSide = (bIsModeVer ? refLeft : refAbove) + refMainOffset;
314 
315  // Extend the Main reference to the left.
316  Int invAngleSum = 128; // rounding for (shift by 8)
317  for (Int k=-1; k>(refMainOffsetPreScale+1)*intraPredAngle>>5; k--)
318  {
319  invAngleSum += invAngle;
320  refMain[k] = refSide[invAngleSum>>8];
321  }
322  }
323  else
324  {
325  for (Int x=0;x<2*width+1;x++)
326  {
327  refAbove[x] = pSrc[x-srcStride-1];
328  }
329  for (Int y=0;y<2*height+1;y++)
330  {
331  refLeft[y] = pSrc[(y-1)*srcStride-1];
332  }
333  refMain = bIsModeVer ? refAbove : refLeft ;
334  refSide = bIsModeVer ? refLeft : refAbove;
335  }
336 
337  // swap width/height if we are doing a horizontal mode:
338  Pel tempArray[MAX_CU_SIZE*MAX_CU_SIZE];
339  const Int dstStride = bIsModeVer ? dstStrideTrue : MAX_CU_SIZE;
340  Pel *pDst = bIsModeVer ? pTrueDst : tempArray;
341  if (!bIsModeVer)
342  {
343  std::swap(width, height);
344  }
345 
346  if (intraPredAngle == 0) // pure vertical or pure horizontal
347  {
348  for (Int y=0;y<height;y++)
349  {
350  for (Int x=0;x<width;x++)
351  {
352  pDst[y*dstStride+x] = refMain[x+1];
353  }
354  }
355 
356  if (edgeFilter)
357  {
358  for (Int y=0;y<height;y++)
359  {
360  pDst[y*dstStride] = Clip3 (0, ((1 << bitDepth) - 1), pDst[y*dstStride] + (( refSide[y+1] - refSide[0] ) >> 1) );
361  }
362  }
363  }
364  else
365  {
366  Pel *pDsty=pDst;
367 
368  for (Int y=0, deltaPos=intraPredAngle; y<height; y++, deltaPos+=intraPredAngle, pDsty+=dstStride)
369  {
370  const Int deltaInt = deltaPos >> 5;
371  const Int deltaFract = deltaPos & (32 - 1);
372 
373  if (deltaFract)
374  {
375  // Do linear filtering
376  const Pel *pRM=refMain+deltaInt+1;
377  Int lastRefMainPel=*pRM++;
378  for (Int x=0;x<width;pRM++,x++)
379  {
380  Int thisRefMainPel=*pRM;
381  pDsty[x+0] = (Pel) ( ((32-deltaFract)*lastRefMainPel + deltaFract*thisRefMainPel +16) >> 5 );
382  lastRefMainPel=thisRefMainPel;
383  }
384  }
385  else
386  {
387  // Just copy the integer samples
388  for (Int x=0;x<width; x++)
389  {
390  pDsty[x] = refMain[x+deltaInt+1];
391  }
392  }
393  }
394  }
395 
396  // Flip the block if this is the horizontal mode
397  if (!bIsModeVer)
398  {
399  for (Int y=0; y<height; y++)
400  {
401  for (Int x=0; x<width; x++)
402  {
403  pTrueDst[x*dstStrideTrue] = pDst[x];
404  }
405  pTrueDst++;
406  pDst+=dstStride;
407  }
408  }
409  }
410 }
411 
412 Void TComPrediction::predIntraAng( const ComponentID compID, UInt uiDirMode, Pel* piOrg /* Will be null for decoding */, UInt uiOrgStride, Pel* piPred, UInt uiStride, TComTU &rTu, Bool bAbove, Bool bLeft, const Bool bUseFilteredPredSamples, const Bool bUseLosslessDPCM )
413 {
414  const ChromaFormat format = rTu.GetChromaFormat();
415  const ChannelType channelType = toChannelType(compID);
416  const TComRectangle &rect = rTu.getRect(isLuma(compID) ? COMPONENT_Y : COMPONENT_Cb);
417  const Int iWidth = rect.width;
418  const Int iHeight = rect.height;
419 
420  assert( g_aucConvertToBit[ iWidth ] >= 0 ); // 4x 4
421  assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128
422  //assert( iWidth == iHeight );
423 
424  Pel *pDst = piPred;
425 
426  // get starting pixel in block
427  const Int sw = (2 * iWidth + 1);
428 
429  if ( bUseLosslessDPCM )
430  {
431  const Pel *ptrSrc = getPredictorPtr( compID, false );
432  // Sample Adaptive intra-Prediction (SAP)
433  if (uiDirMode==HOR_IDX)
434  {
435  // left column filled with reference samples
436  // remaining columns filled with piOrg data (if available).
437  for(Int y=0; y<iHeight; y++)
438  {
439  piPred[y*uiStride+0] = ptrSrc[(y+1)*sw];
440  }
441  if (piOrg!=0)
442  {
443  piPred+=1; // miss off first column
444  for(Int y=0; y<iHeight; y++, piPred+=uiStride, piOrg+=uiOrgStride)
445  {
446  memcpy(piPred, piOrg, (iWidth-1)*sizeof(Pel));
447  }
448  }
449  }
450  else // VER_IDX
451  {
452  // top row filled with reference samples
453  // remaining rows filled with piOrd data (if available)
454  for(Int x=0; x<iWidth; x++)
455  {
456  piPred[x] = ptrSrc[x+1];
457  }
458  if (piOrg!=0)
459  {
460  piPred+=uiStride; // miss off the first row
461  for(Int y=1; y<iHeight; y++, piPred+=uiStride, piOrg+=uiOrgStride)
462  {
463  memcpy(piPred, piOrg, iWidth*sizeof(Pel));
464  }
465  }
466  }
467  }
468  else
469  {
470  const Pel *ptrSrc = getPredictorPtr( compID, bUseFilteredPredSamples );
471 
472  if ( uiDirMode == PLANAR_IDX )
473  {
474  xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType, format );
475  }
476  else
477  {
478  // Create the prediction
479  TComDataCU *const pcCU = rTu.getCU();
480  const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
481  const Bool enableEdgeFilters = !(pcCU->isRDPCMEnabled(uiAbsPartIdx) && pcCU->getCUTransquantBypass(uiAbsPartIdx));
482 
483 #if O0043_BEST_EFFORT_DECODING
484  xPredIntraAng( g_bitDepthInStream[channelType], ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType, format, uiDirMode, bAbove, bLeft, enableEdgeFilters );
485 #else
486  xPredIntraAng( g_bitDepth[channelType], ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType, format, uiDirMode, bAbove, bLeft, enableEdgeFilters );
487 #endif
488 
489  if(( uiDirMode == DC_IDX ) && bAbove && bLeft )
490  {
491  xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType );
492  }
493  }
494  }
495 
496 }
497 
502 {
503  if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() )
504  {
505  if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0)
506  {
507  Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC();
508  Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC();
509  if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
510  {
511  return true;
512  }
513  }
514  }
515  return false;
516 }
517 
518 Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
519 {
520  Int iWidth;
521  Int iHeight;
522  UInt uiPartAddr;
523 
524  if ( iPartIdx >= 0 )
525  {
526  pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
527  if ( eRefPicList != REF_PIC_LIST_X )
528  {
529  if( pcCU->getSlice()->getPPS()->getUseWP())
530  {
531  xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
532  }
533  else
534  {
535  xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
536  }
537  if ( pcCU->getSlice()->getPPS()->getUseWP() )
538  {
539  xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
540  }
541  }
542  else
543  {
544  if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
545  {
546  xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
547  }
548  else
549  {
550  xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
551  }
552  }
553  return;
554  }
555 
556  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ )
557  {
558  pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
559 
560  if ( eRefPicList != REF_PIC_LIST_X )
561  {
562  if( pcCU->getSlice()->getPPS()->getUseWP())
563  {
564  xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
565  }
566  else
567  {
568  xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
569  }
570  if ( pcCU->getSlice()->getPPS()->getUseWP() )
571  {
572  xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
573  }
574  }
575  else
576  {
577  if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
578  {
579  xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
580  }
581  else
582  {
583  xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
584  }
585  }
586  }
587  return;
588 }
589 
590 Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv* pcYuvPred, Bool bi )
591 {
592  Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); assert (iRefIdx >= 0);
593  TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
594  pcCU->clipMv(cMv);
595 
596  for (UInt ch=COMPONENT_Y; ch<pcYuvPred->getNumberValidComponents(); ch++)
597  {
598  xPredInterBlk (ComponentID(ch), pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi );
599  }
600 }
601 
602 Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv* pcYuvPred )
603 {
604  TComYuv* pcMbYuv;
605  Int iRefIdx[NUM_REF_PIC_LIST_01] = {-1, -1};
606 
607  for ( UInt refList = 0; refList < NUM_REF_PIC_LIST_01; refList++ )
608  {
609  RefPicList eRefPicList = (refList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
610  iRefIdx[refList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
611 
612  if ( iRefIdx[refList] < 0 )
613  {
614  continue;
615  }
616 
617  assert( iRefIdx[refList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
618 
619  pcMbYuv = &m_acYuvPred[refList];
620  if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
621  {
622  xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
623  }
624  else
625  {
626  if ( ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) ||
627  ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
628  {
629  xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
630  }
631  else
632  {
633  xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
634  }
635  }
636  }
637 
638  if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE )
639  {
640  xWeightedPredictionBi( pcCU, &m_acYuvPred[REF_PIC_LIST_0], &m_acYuvPred[REF_PIC_LIST_1], iRefIdx[REF_PIC_LIST_0], iRefIdx[REF_PIC_LIST_1], uiPartAddr, iWidth, iHeight, pcYuvPred );
641  }
642  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
643  {
644  xWeightedPredictionUni( pcCU, &m_acYuvPred[REF_PIC_LIST_0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
645  }
646  else
647  {
648  xWeightedAverage( &m_acYuvPred[REF_PIC_LIST_0], &m_acYuvPred[REF_PIC_LIST_1], iRefIdx[REF_PIC_LIST_0], iRefIdx[REF_PIC_LIST_1], uiPartAddr, iWidth, iHeight, pcYuvPred );
649  }
650 }
651 
667 Void TComPrediction::xPredInterBlk(const ComponentID compID, TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *dstPic, Bool bi )
668 {
669  Int refStride = refPic->getStride(compID);
670  Int dstStride = dstPic->getStride(compID);
671  Int shiftHor=(2+refPic->getComponentScaleX(compID));
672  Int shiftVer=(2+refPic->getComponentScaleY(compID));
673 
674  Int refOffset = (mv->getHor() >> shiftHor) + (mv->getVer() >> shiftVer) * refStride;
675 
676  Pel* ref = refPic->getAddr(compID, cu->getCtuRsAddr(), cu->getZorderIdxInCtu() + partAddr ) + refOffset;
677 
678  Pel* dst = dstPic->getAddr( compID, partAddr );
679 
680  Int xFrac = mv->getHor() & ((1<<shiftHor)-1);
681  Int yFrac = mv->getVer() & ((1<<shiftVer)-1);
682  UInt cxWidth = width >> refPic->getComponentScaleX(compID);
683  UInt cxHeight = height >> refPic->getComponentScaleY(compID);
684 
685  const ChromaFormat chFmt = cu->getPic()->getChromaFormat();
686 
687  if ( yFrac == 0 )
688  {
689  m_if.filterHor(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, xFrac, !bi, chFmt);
690  }
691  else if ( xFrac == 0 )
692  {
693  m_if.filterVer(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, yFrac, true, !bi, chFmt);
694  }
695  else
696  {
697  Int tmpStride = m_filteredBlockTmp[0].getStride(compID);
698  Pel* tmp = m_filteredBlockTmp[0].getAddr(compID);
699 
700  const Int vFilterSize = isLuma(compID) ? NTAPS_LUMA : NTAPS_CHROMA;
701 
702  m_if.filterHor(compID, ref - ((vFilterSize>>1) -1)*refStride, refStride, tmp, tmpStride, cxWidth, cxHeight+vFilterSize-1, xFrac, false, chFmt);
703  m_if.filterVer(compID, tmp + ((vFilterSize>>1) -1)*tmpStride, tmpStride, dst, dstStride, cxWidth, cxHeight, yFrac, false, !bi, chFmt);
704  }
705 }
706 
707 Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv* pcYuvDst )
708 {
709  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
710  {
711  pcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
712  }
713  else if ( iRefIdx0 >= 0 && iRefIdx1 < 0 )
714  {
715  pcYuvSrc0->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight );
716  }
717  else if ( iRefIdx0 < 0 && iRefIdx1 >= 0 )
718  {
719  pcYuvSrc1->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight );
720  }
721 }
722 
723 // AMVP
724 Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
725 {
726  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
727 
728  if( pcAMVPInfo->iN <= 1 )
729  {
730  rcMvPred = pcAMVPInfo->m_acMvCand[0];
731 
732  pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
733  pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
734  return;
735  }
736 
737  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
738  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
739  return;
740 }
741 
754 //NOTE: Bit-Limit - 24-bit source
755 Void TComPrediction::xPredIntraPlanar( const Pel* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height, ChannelType channelType, ChromaFormat format )
756 {
757  assert(width <= height);
758 
759  Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
760  UInt shift1Dhor = g_aucConvertToBit[ width ] + 2;
761  UInt shift1Dver = g_aucConvertToBit[ height ] + 2;
762 
763  // Get left and above reference column and row
764  for(Int k=0;k<width+1;k++)
765  {
766  topRow[k] = pSrc[k-srcStride];
767  }
768 
769  for (Int k=0; k < height+1; k++)
770  {
771  leftColumn[k] = pSrc[k*srcStride-1];
772  }
773 
774  // Prepare intermediate variables used in interpolation
775  Int bottomLeft = leftColumn[height];
776  Int topRight = topRow[width];
777 
778  for(Int k=0;k<width;k++)
779  {
780  bottomRow[k] = bottomLeft - topRow[k];
781  topRow[k] <<= shift1Dver;
782  }
783 
784  for(Int k=0;k<height;k++)
785  {
786  rightColumn[k] = topRight - leftColumn[k];
787  leftColumn[k] <<= shift1Dhor;
788  }
789 
790  const UInt topRowShift = 0;
791 
792  // Generate prediction signal
793  for (Int y=0;y<height;y++)
794  {
795  Int horPred = leftColumn[y] + width;
796  for (Int x=0;x<width;x++)
797  {
798  horPred += rightColumn[y];
799  topRow[x] += bottomRow[x];
800 
801  Int vertPred = ((topRow[x] + topRowShift)>>topRowShift);
802  rpDst[y*dstStride+x] = ( horPred + vertPred ) >> (shift1Dhor+1);
803  }
804  }
805 }
806 
818 Void TComPrediction::xDCPredFiltering( const Pel* pSrc, Int iSrcStride, Pel* pDst, Int iDstStride, Int iWidth, Int iHeight, ChannelType channelType )
819 {
820  Int x, y, iDstStride2, iSrcStride2;
821 
822  if (isLuma(channelType) && (iWidth <= MAXIMUM_INTRA_FILTERED_WIDTH) && (iHeight <= MAXIMUM_INTRA_FILTERED_HEIGHT))
823  {
824  //top-left
825  pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
826 
827  //top row (vertical filter)
828  for ( x = 1; x < iWidth; x++ )
829  {
830  pDst[x] = (Pel)((pSrc[x - iSrcStride] + 3 * pDst[x] + 2) >> 2);
831  }
832 
833  //left column (horizontal filter)
834  for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
835  {
836  pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
837  }
838  }
839 
840  return;
841 }
842 
843 /* Static member function */
845 {
846  return (rTu.getCU()->isRDPCMEnabled(rTu.GetAbsPartIdxTU()) ) &&
848  (uiDirMode==HOR_IDX || uiDirMode==VER_IDX);
849 }
850 
#define MAX_CU_SIZE
Definition: TComRom.h:54
Void destroy()
Destroy YUV buffer.
Definition: TComYuv.cpp:77
Int getRefIdx(Int iIdx) const
Void setMVPNumSubParts(Int iMVPNum, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
picture YUV buffer class
Definition: TComPicYuv.h:55
SliceType getSliceType() const
Definition: TComSlice.h:1337
CU data structure class.
Definition: TComDataCU.h:64
ChannelType
Definition: TypeDef.h:361
Int getHor() const
Definition: TComMv.h:88
prediction class (header)
void Void
Definition: TypeDef.h:285
Void xPredIntraPlanar(const Pel *pSrc, Int srcStride, Pel *rpDst, Int dstStride, UInt width, UInt height, ChannelType channelType, ChromaFormat format)
Int getStride(const ComponentID id) const
Definition: TComPicYuv.h:113
Void getMvPredAMVP(TComDataCU *pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv &rcMvPred)
static const UInt MAX_INTRA_FILTER_DEPTHS
TComYuv m_filteredBlock[4][4]
#define NULL
Definition: CommonDef.h:100
ChromaFormat GetChromaFormat() const
Definition: TComTU.h:124
Void motionCompensation(TComDataCU *pcCU, TComYuv *pcYuvPred, RefPicList eRefPicList=REF_PIC_LIST_X, Int iPartIdx=-1)
Char g_aucConvertToBit[(1<<(6))+1]
Definition: TComRom.cpp:558
unsigned int UInt
Definition: TypeDef.h:297
Bool isRDPCMEnabled(UInt uiAbsPartIdx)
Definition: TComDataCU.h:287
#define VER_IDX
Definition: TypeDef.h:181
TComYuv m_acYuvPred[NUM_REF_PIC_LIST_01]
Short Pel
pixel type
Definition: TypeDef.h:692
Void initTempBuff(ChromaFormat chromaFormatIDC)
#define DC_IDX
Definition: TypeDef.h:183
UChar getNumPartitions(const UInt uiAbsPartIdx=0)
static const UChar m_aucIntraFilter[MAX_NUM_CHANNEL_TYPE][MAX_INTRA_FILTER_DEPTHS]
UInt getStride(const ComponentID id) const
Definition: TComYuv.h:197
picture class (header)
Int getNumRefIdx(RefPicList e) const
Definition: TComSlice.h:1353
Void predIntraAng(const ComponentID compID, UInt uiDirMode, Pel *piOrg, UInt uiOrgStride, Pel *piPred, UInt uiStride, TComTU &rTu, Bool bAbove, Bool bLeft, const Bool bUseFilteredPredSamples, const Bool bUseLosslessDPCM=false)
#define PLANAR_IDX
Definition: TypeDef.h:180
#define LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS
Definition: TypeDef.h:212
Bool isInterB() const
Definition: TComSlice.h:1405
UInt getZorderIdxInCtu() const
Definition: TComDataCU.h:209
TComPicYuv * getPicYuvRec()
Definition: TComPic.h:109
TComYuv m_cYuvPredTemp
UInt GetAbsPartIdxTU() const
Definition: TComTU.h:119
Int iN
number of motion vector predictor candidates
general YUV buffer class
Definition: TComYuv.h:54
UInt getComponentScaleY(const ComponentID id) const
Definition: TComPicYuv.h:139
UInt getComponentScaleX(const ComponentID id) const
Definition: TComPicYuv.h:138
bool Bool
Definition: TypeDef.h:286
Void xPredIntraAng(Int bitDepth, const Pel *pSrc, Int srcStride, Pel *pDst, Int dstStride, UInt width, UInt height, ChannelType channelType, ChromaFormat format, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, const Bool bEnableEdgeFilters)
Void getPartIndexAndSize(UInt uiPartIdx, UInt &ruiPartAddr, Int &riWidth, Int &riHeight)
parameters for AMVP
UInt & getCtuRsAddr()
Definition: TComDataCU.h:207
Void create(const UInt iWidth, const UInt iHeight, const ChromaFormat chromaFormatIDC)
Create YUV buffer.
Definition: TComYuv.cpp:63
Int m_iLumaRecStride
stride of m_pLumaRecBuffer array
static ChannelType toChannelType(const ComponentID id)
T Clip3(const T minVal, const T maxVal, const T a)
general min/max clip
Definition: CommonDef.h:137
TComMv const & getMv(Int iIdx) const
reference list 0
Definition: TypeDef.h:417
Pel * getAddr(const ComponentID id)
Definition: TComYuv.h:148
RefPicList
reference list index
Definition: TypeDef.h:415
ChromaFormat
chroma formats (according to semantics of chroma_format_idc)
Definition: TypeDef.h:352
unsigned char UChar
Definition: TypeDef.h:293
const TComRectangle & getRect(const ComponentID compID) const
Definition: TComTU.h:96
TComYuv m_filteredBlockTmp[4]
UChar * getDepth()
Definition: TComDataCU.h:213
const TComPPS * getPPS() const
Definition: TComSlice.h:1309
Int getVer() const
Definition: TComMv.h:89
Bool getUseWP() const
Definition: TComSlice.h:1102
ChromaFormat getChromaFormat() const
Definition: TComPic.h:128
Void xDCPredFiltering(const Pel *pSrc, Int iSrcStride, Pel *pDst, Int iDstStride, Int iWidth, Int iHeight, ChannelType channelType)
TComDataCU * getCU()
Definition: TComTU.h:126
Void xWeightedAverage(TComYuv *pcYuvSrc0, TComYuv *pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv *pcYuvDst)
#define MAXIMUM_INTRA_FILTERED_WIDTH
Definition: TypeDef.h:103
reference list 1
Definition: TypeDef.h:418
#define HOR_IDX
Definition: TypeDef.h:182
Bool * getCUTransquantBypass()
Definition: TComDataCU.h:242
Void setMVPIdxSubParts(Int iMVPIdx, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
TComPic * getPic()
Definition: TComDataCU.h:203
Void addAvg(const TComYuv *pcYuvSrc0, const TComYuv *pcYuvSrc1, const UInt iPartUnitIdx, const UInt iWidth, const UInt iHeight)
Definition: TComYuv.cpp:352
Int g_bitDepth[MAX_NUM_CHANNEL_TYPE]
Definition: TComRom.cpp:548
AMVPInfo * getAMVPInfo()
Int getMVPIdx(RefPicList eRefPicList, UInt uiIdx)
Definition: TComDataCU.h:374
Definition: TComTU.h:48
ChromaFormat getChromaFormat() const
Definition: TComYuv.h:200
Pel * m_pLumaRecBuffer
array for downsampled reconstructed luma sample
TComInterpolationFilter m_if
static Void filterVer(Int bitDepth, Pel *src, Int srcStride, Pel *dst, Int dstStride, Int width, Int height, Bool isFirst, Bool isLast, TFilterCoeff const *coeff)
Filter a block of samples (vertical)
Pel * getAddr(const ComponentID ch)
Definition: TComPicYuv.h:127
#define MAXIMUM_INTRA_FILTERED_HEIGHT
Definition: TypeDef.h:104
Pel predIntraGetPredValDC(const Pel *pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, ChannelType channelType, ChromaFormat format, Bool bAbove, Bool bLeft)
TComCUMvField * getCUMvField(RefPicList e)
Definition: TComDataCU.h:294
Pel * getPredictorPtr(const ComponentID compID, const Bool bUseFilteredPredictions)
int Int
Definition: TypeDef.h:296
basic motion vector class
Definition: TComMv.h:51
Bool xCheckIdenticalMotion(TComDataCU *pcCU, UInt PartAddr)
virtual ~TComPrediction()
ComponentID
Definition: TypeDef.h:368
Void xPredInterBi(TComDataCU *pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv *pcYuvPred)
Void xPredInterBlk(const ComponentID compID, TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *dstPic, Bool bi)
Generate motion-compensated block.
Void clipMv(TComMv &rcMv)
special mark
Definition: TypeDef.h:420
Void xWeightedPredictionBi(TComDataCU *const pcCU, const TComYuv *const pcYuvSrc0, const TComYuv *const pcYuvSrc1, const Int iRefIdx0, const Int iRefIdx1, const UInt uiPartIdx, const Int iWidth, const Int iHeight, TComYuv *pcYuvDst)
weighted prediction for bi-pred
Bool getWPBiPred() const
Definition: TComSlice.h:1103
TComMv m_acMvCand[3]
array of motion vector predictor candidates
UInt getNumberValidComponents() const
Definition: TComYuv.h:201
Void copyPartToPartYuv(TComYuv *pcYuvDst, const UInt uiPartIdx, const UInt uiWidth, const UInt uiHeight) const
Definition: TComYuv.cpp:222
#define NTAPS_LUMA
Number of taps for luma.
Void xPredInterUni(TComDataCU *pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv *pcYuvPred, Bool bi=false)
TComPic * getRefPic(RefPicList e, Int iRefIdx)
Definition: TComSlice.h:1355
Pel * m_piYuvExt[MAX_NUM_COMPONENT][NUM_PRED_BUF]
static Bool isLuma(const ComponentID id)
#define NTAPS_CHROMA
Number of taps for chroma.
static Void filterHor(Int bitDepth, Pel *src, Int srcStride, Pel *dst, Int dstStride, Int width, Int height, Bool isLast, TFilterCoeff const *coeff)
Filter a block of samples (horizontal)
TComSlice * getSlice()
Definition: TComDataCU.h:205
Void xWeightedPredictionUni(TComDataCU *const pcCU, const TComYuv *const pcYuvSrc, const UInt uiPartAddr, const Int iWidth, const Int iHeight, const RefPicList eRefPicList, TComYuv *pcYuvPred, const Int iRefIdx=-1)
weighted prediction for uni-pred
static Bool UseDPCMForFirstPassIntraEstimation(TComTU &rTu, const UInt uiDirMode)