HEVC Test Model (HM)  HM-16.2
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-2014, 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 "TComTU.h"
41 
44 
45 // ====================================================================================================================
46 // Tables
47 // ====================================================================================================================
48 
50 {
51  { // Luma
52  10, //4x4
53  7, //8x8
54  1, //16x16
55  0, //32x32
56  10, //64x64
57  },
58  { // Chroma
59  10, //4xn
60  7, //8xn
61  1, //16xn
62  0, //32xn
63  10, //64xn
64  }
65 
66 };
67 
68 // ====================================================================================================================
69 // Constructor / destructor / initialize
70 // ====================================================================================================================
71 
73 : m_pLumaRecBuffer(0)
74 , m_iLumaRecStride(0)
75 {
76  for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
77  {
78  for(UInt buf=0; buf<2; buf++)
79  {
80  m_piYuvExt[ch][buf] = NULL;
81  }
82  }
83 }
84 
86 {
87  destroy();
88 }
89 
91 {
92  for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
93  {
94  for(UInt buf=0; buf<NUM_PRED_BUF; buf++)
95  {
96  delete [] m_piYuvExt[ch][buf];
97  m_piYuvExt[ch][buf] = NULL;
98  }
99  }
100 
101  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
102  {
103  m_acYuvPred[i].destroy();
104  }
105 
107 
108  if( m_pLumaRecBuffer )
109  {
110  delete [] m_pLumaRecBuffer;
111  m_pLumaRecBuffer = 0;
112  }
113  m_iLumaRecStride = 0;
114 
116  {
118  {
119  m_filteredBlock[i][j].destroy();
120  }
122  }
123 }
124 
126 {
127  // if it has been initialised before, but the chroma format has changed, release the memory and start again.
129  {
130  destroy();
131  }
132 
133  if( m_piYuvExt[COMPONENT_Y][PRED_BUF_UNFILTERED] == NULL ) // check if first is null (in which case, nothing initialised yet)
134  {
135  Int extWidth = MAX_CU_SIZE + 16;
136  Int extHeight = MAX_CU_SIZE + 1;
137 
139  {
140  m_filteredBlockTmp[i].create(extWidth, extHeight + 7, chromaFormatIDC);
142  {
143  m_filteredBlock[i][j].create(extWidth, extHeight, chromaFormatIDC);
144  }
145  }
146 
147  m_iYuvExtSize = (MAX_CU_SIZE*2+1) * (MAX_CU_SIZE*2+1);
148  for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
149  {
150  for(UInt buf=0; buf<NUM_PRED_BUF; buf++)
151  {
152  m_piYuvExt[ch][buf] = new Pel[ m_iYuvExtSize ];
153  }
154  }
155 
156  // new structure
157  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
158  {
159  m_acYuvPred[i] .create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC );
160  }
161 
162  m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC );
163  }
164 
165 
166  if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1)
167  {
168  m_iLumaRecStride = (MAX_CU_SIZE>>1) + 1;
169  if (!m_pLumaRecBuffer)
170  {
172  }
173  }
174 }
175 
176 // ====================================================================================================================
177 // Public member functions
178 // ====================================================================================================================
179 
180 // Function for calculating DC value of the reference samples used in Intra prediction
181 //NOTE: Bit-Limit - 25-bit source
182 Pel TComPrediction::predIntraGetPredValDC( const Pel* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, ChannelType channelType, ChromaFormat format, Bool bAbove, Bool bLeft )
183 {
184  assert(iWidth > 0 && iHeight > 0);
185  Int iInd, iSum = 0;
186  Pel pDcVal;
187 
188  if (bAbove)
189  {
190  for (iInd = 0;iInd < iWidth;iInd++)
191  {
192  iSum += pSrc[iInd-iSrcStride];
193  }
194  }
195  if (bLeft)
196  {
197  for (iInd = 0;iInd < iHeight;iInd++)
198  {
199  iSum += pSrc[iInd*iSrcStride-1];
200  }
201  }
202 
203  if (bAbove && bLeft)
204  {
205  pDcVal = (iSum + iWidth) / (iWidth + iHeight);
206  }
207  else if (bAbove)
208  {
209  pDcVal = (iSum + iWidth/2) / iWidth;
210  }
211  else if (bLeft)
212  {
213  pDcVal = (iSum + iHeight/2) / iHeight;
214  }
215  else
216  {
217  pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available
218  }
219 
220  return pDcVal;
221 }
222 
223 // Function for deriving the angular Intra predictions
224 
244 //NOTE: Bit-Limit - 25-bit source
246  const Pel* pSrc, Int srcStride,
247  Pel* pTrueDst, Int dstStrideTrue,
248  UInt uiWidth, UInt uiHeight, ChannelType channelType, ChromaFormat format,
249  UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable
250  , const Bool bEnableEdgeFilters
251  )
252 {
253  Int width=Int(uiWidth);
254  Int height=Int(uiHeight);
255 
256  // Map the mode index to main prediction direction and angle
257  assert( dirMode != PLANAR_IDX ); //no planar
258  const Bool modeDC = dirMode==DC_IDX;
259 
260  // Do the DC prediction
261  if (modeDC)
262  {
263  const Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, channelType, format, blkAboveAvailable, blkLeftAvailable);
264 
265  for (Int y=height;y>0;y--, pTrueDst+=dstStrideTrue)
266  {
267  for (Int x=0; x<width;) // width is always a multiple of 4.
268  {
269  pTrueDst[x++] = dcval;
270  }
271  }
272  }
273  else // Do angular predictions
274  {
275  const Bool bIsModeVer = (dirMode >= 18);
276  const Int intraPredAngleMode = (bIsModeVer) ? (Int)dirMode - VER_IDX : -((Int)dirMode - HOR_IDX);
277  const Int absAngMode = abs(intraPredAngleMode);
278  const Int signAng = intraPredAngleMode < 0 ? -1 : 1;
279  const Bool edgeFilter = bEnableEdgeFilters && isLuma(channelType) && (width <= MAXIMUM_INTRA_FILTERED_WIDTH) && (height <= MAXIMUM_INTRA_FILTERED_HEIGHT);
280 
281  // Set bitshifts and scale the angle parameter to block size
282  static const Int angTable[9] = {0, 2, 5, 9, 13, 17, 21, 26, 32};
283  static const Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle
284  Int invAngle = invAngTable[absAngMode];
285  Int absAng = angTable[absAngMode];
286  Int intraPredAngle = signAng * absAng;
287 
288  Pel* refMain;
289  Pel* refSide;
290 
291  Pel refAbove[2*MAX_CU_SIZE+1];
292  Pel refLeft[2*MAX_CU_SIZE+1];
293 
294  // Initialise the Main and Left reference array.
295  if (intraPredAngle < 0)
296  {
297  const Int refMainOffsetPreScale = (bIsModeVer ? height : width ) - 1;
298  const Int refMainOffset = height - 1;
299  for (Int x=0;x<width+1;x++)
300  {
301  refAbove[x+refMainOffset] = pSrc[x-srcStride-1];
302  }
303  for (Int y=0;y<height+1;y++)
304  {
305  refLeft[y+refMainOffset] = pSrc[(y-1)*srcStride-1];
306  }
307  refMain = (bIsModeVer ? refAbove : refLeft) + refMainOffset;
308  refSide = (bIsModeVer ? refLeft : refAbove) + refMainOffset;
309 
310  // Extend the Main reference to the left.
311  Int invAngleSum = 128; // rounding for (shift by 8)
312  for (Int k=-1; k>(refMainOffsetPreScale+1)*intraPredAngle>>5; k--)
313  {
314  invAngleSum += invAngle;
315  refMain[k] = refSide[invAngleSum>>8];
316  }
317  }
318  else
319  {
320  for (Int x=0;x<2*width+1;x++)
321  {
322  refAbove[x] = pSrc[x-srcStride-1];
323  }
324  for (Int y=0;y<2*height+1;y++)
325  {
326  refLeft[y] = pSrc[(y-1)*srcStride-1];
327  }
328  refMain = bIsModeVer ? refAbove : refLeft ;
329  refSide = bIsModeVer ? refLeft : refAbove;
330  }
331 
332  // swap width/height if we are doing a horizontal mode:
333  Pel tempArray[MAX_CU_SIZE*MAX_CU_SIZE];
334  const Int dstStride = bIsModeVer ? dstStrideTrue : MAX_CU_SIZE;
335  Pel *pDst = bIsModeVer ? pTrueDst : tempArray;
336  if (!bIsModeVer)
337  {
338  std::swap(width, height);
339  }
340 
341  if (intraPredAngle == 0) // pure vertical or pure horizontal
342  {
343  for (Int y=0;y<height;y++)
344  {
345  for (Int x=0;x<width;x++)
346  {
347  pDst[y*dstStride+x] = refMain[x+1];
348  }
349  }
350 
351  if (edgeFilter)
352  {
353  for (Int y=0;y<height;y++)
354  {
355  pDst[y*dstStride] = Clip3 (0, ((1 << bitDepth) - 1), pDst[y*dstStride] + (( refSide[y+1] - refSide[0] ) >> 1) );
356  }
357  }
358  }
359  else
360  {
361  Pel *pDsty=pDst;
362 
363  for (Int y=0, deltaPos=intraPredAngle; y<height; y++, deltaPos+=intraPredAngle, pDsty+=dstStride)
364  {
365  const Int deltaInt = deltaPos >> 5;
366  const Int deltaFract = deltaPos & (32 - 1);
367 
368  if (deltaFract)
369  {
370  // Do linear filtering
371  const Pel *pRM=refMain+deltaInt+1;
372  Int lastRefMainPel=*pRM++;
373  for (Int x=0;x<width;pRM++,x++)
374  {
375  Int thisRefMainPel=*pRM;
376  pDsty[x+0] = (Pel) ( ((32-deltaFract)*lastRefMainPel + deltaFract*thisRefMainPel +16) >> 5 );
377  lastRefMainPel=thisRefMainPel;
378  }
379  }
380  else
381  {
382  // Just copy the integer samples
383  for (Int x=0;x<width; x++)
384  {
385  pDsty[x] = refMain[x+deltaInt+1];
386  }
387  }
388  }
389  }
390 
391  // Flip the block if this is the horizontal mode
392  if (!bIsModeVer)
393  {
394  for (Int y=0; y<height; y++)
395  {
396  for (Int x=0; x<width; x++)
397  {
398  pTrueDst[x*dstStrideTrue] = pDst[x];
399  }
400  pTrueDst++;
401  pDst+=dstStride;
402  }
403  }
404  }
405 }
406 
407 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 )
408 {
409  const ChromaFormat format = rTu.GetChromaFormat();
410  const ChannelType channelType = toChannelType(compID);
411  const TComRectangle &rect = rTu.getRect(isLuma(compID) ? COMPONENT_Y : COMPONENT_Cb);
412  const Int iWidth = rect.width;
413  const Int iHeight = rect.height;
414 
415  assert( g_aucConvertToBit[ iWidth ] >= 0 ); // 4x 4
416  assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128
417  //assert( iWidth == iHeight );
418 
419  Pel *pDst = piPred;
420 
421  // get starting pixel in block
422  const Int sw = (2 * iWidth + 1);
423 
424  if ( bUseLosslessDPCM )
425  {
426  const Pel *ptrSrc = getPredictorPtr( compID, false );
427  // Sample Adaptive intra-Prediction (SAP)
428  if (uiDirMode==HOR_IDX)
429  {
430  // left column filled with reference samples
431  // remaining columns filled with piOrg data (if available).
432  for(Int y=0; y<iHeight; y++)
433  {
434  piPred[y*uiStride+0] = ptrSrc[(y+1)*sw];
435  }
436  if (piOrg!=0)
437  {
438  piPred+=1; // miss off first column
439  for(Int y=0; y<iHeight; y++, piPred+=uiStride, piOrg+=uiOrgStride)
440  {
441  memcpy(piPred, piOrg, (iWidth-1)*sizeof(Pel));
442  }
443  }
444  }
445  else // VER_IDX
446  {
447  // top row filled with reference samples
448  // remaining rows filled with piOrd data (if available)
449  for(Int x=0; x<iWidth; x++)
450  {
451  piPred[x] = ptrSrc[x+1];
452  }
453  if (piOrg!=0)
454  {
455  piPred+=uiStride; // miss off the first row
456  for(Int y=1; y<iHeight; y++, piPred+=uiStride, piOrg+=uiOrgStride)
457  {
458  memcpy(piPred, piOrg, iWidth*sizeof(Pel));
459  }
460  }
461  }
462  }
463  else
464  {
465  const Pel *ptrSrc = getPredictorPtr( compID, bUseFilteredPredSamples );
466 
467  if ( uiDirMode == PLANAR_IDX )
468  {
469  xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType, format );
470  }
471  else
472  {
473  // Create the prediction
474  TComDataCU *const pcCU = rTu.getCU();
475  const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
476  const Bool enableEdgeFilters = !(pcCU->isRDPCMEnabled(uiAbsPartIdx) && pcCU->getCUTransquantBypass(uiAbsPartIdx));
477 
478 #if O0043_BEST_EFFORT_DECODING
479  xPredIntraAng( g_bitDepthInStream[channelType], ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType, format, uiDirMode, bAbove, bLeft, enableEdgeFilters );
480 #else
481  xPredIntraAng( g_bitDepth[channelType], ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType, format, uiDirMode, bAbove, bLeft, enableEdgeFilters );
482 #endif
483 
484  if(( uiDirMode == DC_IDX ) && bAbove && bLeft )
485  {
486  xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType );
487  }
488  }
489  }
490 
491 }
492 
498 {
499  if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() )
500  {
501  if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0)
502  {
503  Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC();
504  Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC();
505  if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
506  {
507  return true;
508  }
509  }
510  }
511  return false;
512 }
513 
514 Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
515 {
516  Int iWidth;
517  Int iHeight;
518  UInt uiPartAddr;
519 
520  if ( iPartIdx >= 0 )
521  {
522  pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
523  if ( eRefPicList != REF_PIC_LIST_X )
524  {
525  if( pcCU->getSlice()->getPPS()->getUseWP())
526  {
527  xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
528  }
529  else
530  {
531  xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
532  }
533  if ( pcCU->getSlice()->getPPS()->getUseWP() )
534  {
535  xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
536  }
537  }
538  else
539  {
540  if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
541  {
542  xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
543  }
544  else
545  {
546  xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
547  }
548  }
549  return;
550  }
551 
552  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ )
553  {
554  pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
555 
556  if ( eRefPicList != REF_PIC_LIST_X )
557  {
558  if( pcCU->getSlice()->getPPS()->getUseWP())
559  {
560  xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
561  }
562  else
563  {
564  xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
565  }
566  if ( pcCU->getSlice()->getPPS()->getUseWP() )
567  {
568  xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
569  }
570  }
571  else
572  {
573  if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
574  {
575  xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
576  }
577  else
578  {
579  xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
580  }
581  }
582  }
583  return;
584 }
585 
586 Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv* pcYuvPred, Bool bi )
587 {
588  Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); assert (iRefIdx >= 0);
589  TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
590  pcCU->clipMv(cMv);
591 
592  for (UInt ch=COMPONENT_Y; ch<pcYuvPred->getNumberValidComponents(); ch++)
593  {
594  xPredInterBlk (ComponentID(ch), pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi );
595  }
596 }
597 
598 Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv* pcYuvPred )
599 {
600  TComYuv* pcMbYuv;
601  Int iRefIdx[NUM_REF_PIC_LIST_01] = {-1, -1};
602 
603  for ( UInt refList = 0; refList < NUM_REF_PIC_LIST_01; refList++ )
604  {
605  RefPicList eRefPicList = (refList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
606  iRefIdx[refList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
607 
608  if ( iRefIdx[refList] < 0 )
609  {
610  continue;
611  }
612 
613  assert( iRefIdx[refList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
614 
615  pcMbYuv = &m_acYuvPred[refList];
616  if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
617  {
618  xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
619  }
620  else
621  {
622  if ( ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) ||
623  ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
624  {
625  xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
626  }
627  else
628  {
629  xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
630  }
631  }
632  }
633 
634  if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE )
635  {
636  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 );
637  }
638  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
639  {
640  xWeightedPredictionUni( pcCU, &m_acYuvPred[REF_PIC_LIST_0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
641  }
642  else
643  {
644  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 );
645  }
646 }
647 
662 Void TComPrediction::xPredInterBlk(const ComponentID compID, TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *dstPic, Bool bi )
663 {
664  Int refStride = refPic->getStride(compID);
665  Int dstStride = dstPic->getStride(compID);
666  Int shiftHor=(2+refPic->getComponentScaleX(compID));
667  Int shiftVer=(2+refPic->getComponentScaleY(compID));
668 
669  Int refOffset = (mv->getHor() >> shiftHor) + (mv->getVer() >> shiftVer) * refStride;
670 
671  Pel* ref = refPic->getAddr(compID, cu->getCtuRsAddr(), cu->getZorderIdxInCtu() + partAddr ) + refOffset;
672 
673  Pel* dst = dstPic->getAddr( compID, partAddr );
674 
675  Int xFrac = mv->getHor() & ((1<<shiftHor)-1);
676  Int yFrac = mv->getVer() & ((1<<shiftVer)-1);
677  UInt cxWidth = width >> refPic->getComponentScaleX(compID);
678  UInt cxHeight = height >> refPic->getComponentScaleY(compID);
679 
680  const ChromaFormat chFmt = cu->getPic()->getChromaFormat();
681 
682  if ( yFrac == 0 )
683  {
684  m_if.filterHor(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, xFrac, !bi, chFmt);
685  }
686  else if ( xFrac == 0 )
687  {
688  m_if.filterVer(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, yFrac, true, !bi, chFmt);
689  }
690  else
691  {
692  Int tmpStride = m_filteredBlockTmp[0].getStride(compID);
693  Pel* tmp = m_filteredBlockTmp[0].getAddr(compID);
694 
695  const Int vFilterSize = isLuma(compID) ? NTAPS_LUMA : NTAPS_CHROMA;
696 
697  m_if.filterHor(compID, ref - ((vFilterSize>>1) -1)*refStride, refStride, tmp, tmpStride, cxWidth, cxHeight+vFilterSize-1, xFrac, false, chFmt);
698  m_if.filterVer(compID, tmp + ((vFilterSize>>1) -1)*tmpStride, tmpStride, dst, dstStride, cxWidth, cxHeight, yFrac, false, !bi, chFmt);
699  }
700 }
701 
702 Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv* pcYuvDst )
703 {
704  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
705  {
706  pcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
707  }
708  else if ( iRefIdx0 >= 0 && iRefIdx1 < 0 )
709  {
710  pcYuvSrc0->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight );
711  }
712  else if ( iRefIdx0 < 0 && iRefIdx1 >= 0 )
713  {
714  pcYuvSrc1->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight );
715  }
716 }
717 
718 // AMVP
719 Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
720 {
721  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
722 
723  if( pcAMVPInfo->iN <= 1 )
724  {
725  rcMvPred = pcAMVPInfo->m_acMvCand[0];
726 
727  pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
728  pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
729  return;
730  }
731 
732  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
733  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
734  return;
735 }
736 
747 //NOTE: Bit-Limit - 24-bit source
748 Void TComPrediction::xPredIntraPlanar( const Pel* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height, ChannelType channelType, ChromaFormat format )
749 {
750  assert(width <= height);
751 
752  Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
753  UInt shift1Dhor = g_aucConvertToBit[ width ] + 2;
754  UInt shift1Dver = g_aucConvertToBit[ height ] + 2;
755 
756  // Get left and above reference column and row
757  for(Int k=0;k<width+1;k++)
758  {
759  topRow[k] = pSrc[k-srcStride];
760  }
761 
762  for (Int k=0; k < height+1; k++)
763  {
764  leftColumn[k] = pSrc[k*srcStride-1];
765  }
766 
767  // Prepare intermediate variables used in interpolation
768  Int bottomLeft = leftColumn[height];
769  Int topRight = topRow[width];
770 
771  for(Int k=0;k<width;k++)
772  {
773  bottomRow[k] = bottomLeft - topRow[k];
774  topRow[k] <<= shift1Dver;
775  }
776 
777  for(Int k=0;k<height;k++)
778  {
779  rightColumn[k] = topRight - leftColumn[k];
780  leftColumn[k] <<= shift1Dhor;
781  }
782 
783  const UInt topRowShift = 0;
784 
785  // Generate prediction signal
786  for (Int y=0;y<height;y++)
787  {
788  Int horPred = leftColumn[y] + width;
789  for (Int x=0;x<width;x++)
790  {
791  horPred += rightColumn[y];
792  topRow[x] += bottomRow[x];
793 
794  Int vertPred = ((topRow[x] + topRowShift)>>topRowShift);
795  rpDst[y*dstStride+x] = ( horPred + vertPred ) >> (shift1Dhor+1);
796  }
797  }
798 }
799 
810 Void TComPrediction::xDCPredFiltering( const Pel* pSrc, Int iSrcStride, Pel* pDst, Int iDstStride, Int iWidth, Int iHeight, ChannelType channelType )
811 {
812  Int x, y, iDstStride2, iSrcStride2;
813 
814  if (isLuma(channelType) && (iWidth <= MAXIMUM_INTRA_FILTERED_WIDTH) && (iHeight <= MAXIMUM_INTRA_FILTERED_HEIGHT))
815  {
816  //top-left
817  pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
818 
819  //top row (vertical filter)
820  for ( x = 1; x < iWidth; x++ )
821  {
822  pDst[x] = (Pel)((pSrc[x - iSrcStride] + 3 * pDst[x] + 2) >> 2);
823  }
824 
825  //left column (horizontal filter)
826  for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
827  {
828  pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
829  }
830  }
831 
832  return;
833 }
834 
835 /* Static member function */
837 {
838  return (rTu.getCU()->isRDPCMEnabled(rTu.GetAbsPartIdxTU()) ) &&
840  (uiDirMode==HOR_IDX || uiDirMode==VER_IDX);
841 }
842 
#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:1330
CU data structure class.
Definition: TComDataCU.h:66
ChannelType
Definition: TypeDef.h:360
Int getHor() const
Definition: TComMv.h:89
prediction class (header)
void Void
Definition: TypeDef.h:284
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:296
Bool isRDPCMEnabled(UInt uiAbsPartIdx)
Definition: TComDataCU.h:289
#define VER_IDX
Definition: TypeDef.h:181
TComYuv m_acYuvPred[NUM_REF_PIC_LIST_01]
Short Pel
pixel type
Definition: TypeDef.h:691
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:198
Int getNumRefIdx(RefPicList e) const
Definition: TComSlice.h:1346
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:1398
UInt getZorderIdxInCtu() const
Definition: TComDataCU.h:211
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:55
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:285
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:209
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:416
Pel * getAddr(const ComponentID id)
Definition: TComYuv.h:149
RefPicList
reference list index
Definition: TypeDef.h:414
ChromaFormat
chroma formats (according to semantics of chroma_format_idc)
Definition: TypeDef.h:351
unsigned char UChar
Definition: TypeDef.h:292
const TComRectangle & getRect(const ComponentID compID) const
Definition: TComTU.h:96
TComYuv m_filteredBlockTmp[4]
UChar * getDepth()
Definition: TComDataCU.h:215
const TComPPS * getPPS() const
Definition: TComSlice.h:1302
Int getVer() const
Definition: TComMv.h:90
Bool getUseWP() const
Definition: TComSlice.h:1095
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:417
#define HOR_IDX
Definition: TypeDef.h:182
Bool * getCUTransquantBypass()
Definition: TComDataCU.h:244
Void setMVPIdxSubParts(Int iMVPIdx, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
TComPic * getPic()
Definition: TComDataCU.h:205
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:376
Definition: TComTU.h:48
ChromaFormat getChromaFormat() const
Definition: TComYuv.h:201
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:296
Pel * getPredictorPtr(const ComponentID compID, const Bool bUseFilteredPredictions)
int Int
Definition: TypeDef.h:295
basic motion vector class
Definition: TComMv.h:52
Bool xCheckIdenticalMotion(TComDataCU *pcCU, UInt PartAddr)
virtual ~TComPrediction()
ComponentID
Definition: TypeDef.h:367
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:419
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)
Bool getWPBiPred() const
Definition: TComSlice.h:1096
TComMv m_acMvCand[3]
array of motion vector predictor candidates
UInt getNumberValidComponents() const
Definition: TComYuv.h:202
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:1348
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:207
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)
static Bool UseDPCMForFirstPassIntraEstimation(TComTU &rTu, const UInt uiDirMode)