source: 3DVCSoftware/branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPrediction.cpp @ 487

Last change on this file since 487 was 446, checked in by tech, 12 years ago

Added missing parts.

  • Property svn:eol-style set to native
File size: 24.9 KB
Line 
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-2013, 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
34/** \file     TComPrediction.cpp
35    \brief    prediction class
36*/
37
38#include <memory.h>
39#include "TComPrediction.h"
40
41//! \ingroup TLibCommon
42//! \{
43
44// ====================================================================================================================
45// Constructor / destructor / initialize
46// ====================================================================================================================
47
48TComPrediction::TComPrediction()
49: m_pLumaRecBuffer(0)
50, m_iLumaRecStride(0)
51{
52  m_piYuvExt = NULL;
53}
54
55TComPrediction::~TComPrediction()
56{
57 
58  delete[] m_piYuvExt;
59
60  m_acYuvPred[0].destroy();
61  m_acYuvPred[1].destroy();
62
63  m_cYuvPredTemp.destroy();
64
65  if( m_pLumaRecBuffer )
66  {
67    delete [] m_pLumaRecBuffer;
68  }
69 
70  Int i, j;
71  for (i = 0; i < 4; i++)
72  {
73    for (j = 0; j < 4; j++)
74    {
75      m_filteredBlock[i][j].destroy();
76    }
77    m_filteredBlockTmp[i].destroy();
78  }
79}
80
81Void TComPrediction::initTempBuff()
82{
83  if( m_piYuvExt == NULL )
84  {
85    Int extWidth  = MAX_CU_SIZE + 16; 
86    Int extHeight = MAX_CU_SIZE + 1;
87    Int i, j;
88    for (i = 0; i < 4; i++)
89    {
90      m_filteredBlockTmp[i].create(extWidth, extHeight + 7);
91      for (j = 0; j < 4; j++)
92      {
93        m_filteredBlock[i][j].create(extWidth, extHeight);
94      }
95    }
96    m_iYuvExtHeight  = ((MAX_CU_SIZE + 2) << 4);
97    m_iYuvExtStride = ((MAX_CU_SIZE  + 8) << 4);
98    m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ];
99
100    // new structure
101    m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE );
102    m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE );
103
104    m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE );
105  }
106
107  if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1)
108  {
109    m_iLumaRecStride =  (MAX_CU_SIZE>>1) + 1;
110    if (!m_pLumaRecBuffer)
111    {
112      m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ];
113    }
114  }
115}
116
117// ====================================================================================================================
118// Public member functions
119// ====================================================================================================================
120
121// Function for calculating DC value of the reference samples used in Intra prediction
122Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft )
123{
124  Int iInd, iSum = 0;
125  Pel pDcVal;
126
127  if (bAbove)
128  {
129    for (iInd = 0;iInd < iWidth;iInd++)
130    {
131      iSum += pSrc[iInd-iSrcStride];
132    }
133  }
134  if (bLeft)
135  {
136    for (iInd = 0;iInd < iHeight;iInd++)
137    {
138      iSum += pSrc[iInd*iSrcStride-1];
139    }
140  }
141
142  if (bAbove && bLeft)
143  {
144    pDcVal = (iSum + iWidth) / (iWidth + iHeight);
145  }
146  else if (bAbove)
147  {
148    pDcVal = (iSum + iWidth/2) / iWidth;
149  }
150  else if (bLeft)
151  {
152    pDcVal = (iSum + iHeight/2) / iHeight;
153  }
154  else
155  {
156    pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available
157  }
158 
159  return pDcVal;
160}
161
162// Function for deriving the angular Intra predictions
163
164/** Function for deriving the simplified angular intra predictions.
165 * \param pSrc pointer to reconstructed sample array
166 * \param srcStride the stride of the reconstructed sample array
167 * \param rpDst reference to pointer for the prediction sample array
168 * \param dstStride the stride of the prediction sample array
169 * \param width the width of the block
170 * \param height the height of the block
171 * \param dirMode the intra prediction mode index
172 * \param blkAboveAvailable boolean indication if the block above is available
173 * \param blkLeftAvailable boolean indication if the block to the left is available
174 *
175 * This function derives the prediction samples for the angular mode based on the prediction direction indicated by
176 * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and
177 * the reference row above the block in the case of vertical prediction or displacement of the rightmost column
178 * of the block and reference column left from the block in the case of the horizontal prediction. The displacement
179 * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples,
180 * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken
181 * from the extended main reference.
182 */
183Void TComPrediction::xPredIntraAng(Int bitDepth, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, Bool bFilter )
184{
185  Int k,l;
186  Int blkSize        = width;
187  Pel* pDst          = rpDst;
188
189  // Map the mode index to main prediction direction and angle
190  assert( dirMode > 0 ); //no planar
191  Bool modeDC        = dirMode < 2;
192  Bool modeHor       = !modeDC && (dirMode < 18);
193  Bool modeVer       = !modeDC && !modeHor;
194  Int intraPredAngle = modeVer ? (Int)dirMode - VER_IDX : modeHor ? -((Int)dirMode - HOR_IDX) : 0;
195  Int absAng         = abs(intraPredAngle);
196  Int signAng        = intraPredAngle < 0 ? -1 : 1;
197
198  // Set bitshifts and scale the angle parameter to block size
199  Int angTable[9]    = {0,    2,    5,   9,  13,  17,  21,  26,  32};
200  Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle
201  Int invAngle       = invAngTable[absAng];
202  absAng             = angTable[absAng];
203  intraPredAngle     = signAng * absAng;
204
205  // Do the DC prediction
206  if (modeDC)
207  {
208    Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable);
209
210    for (k=0;k<blkSize;k++)
211    {
212      for (l=0;l<blkSize;l++)
213      {
214        pDst[k*dstStride+l] = dcval;
215      }
216    }
217  }
218
219  // Do angular predictions
220  else
221  {
222    Pel* refMain;
223    Pel* refSide;
224    Pel  refAbove[2*MAX_CU_SIZE+1];
225    Pel  refLeft[2*MAX_CU_SIZE+1];
226
227    // Initialise the Main and Left reference array.
228    if (intraPredAngle < 0)
229    {
230      for (k=0;k<blkSize+1;k++)
231      {
232        refAbove[k+blkSize-1] = pSrc[k-srcStride-1];
233      }
234      for (k=0;k<blkSize+1;k++)
235      {
236        refLeft[k+blkSize-1] = pSrc[(k-1)*srcStride-1];
237      }
238      refMain = (modeVer ? refAbove : refLeft) + (blkSize-1);
239      refSide = (modeVer ? refLeft : refAbove) + (blkSize-1);
240
241      // Extend the Main reference to the left.
242      Int invAngleSum    = 128;       // rounding for (shift by 8)
243      for (k=-1; k>blkSize*intraPredAngle>>5; k--)
244      {
245        invAngleSum += invAngle;
246        refMain[k] = refSide[invAngleSum>>8];
247      }
248    }
249    else
250    {
251      for (k=0;k<2*blkSize+1;k++)
252      {
253        refAbove[k] = pSrc[k-srcStride-1];
254      }
255      for (k=0;k<2*blkSize+1;k++)
256      {
257        refLeft[k] = pSrc[(k-1)*srcStride-1];
258      }
259      refMain = modeVer ? refAbove : refLeft;
260      refSide = modeVer ? refLeft  : refAbove;
261    }
262
263    if (intraPredAngle == 0)
264    {
265      for (k=0;k<blkSize;k++)
266      {
267        for (l=0;l<blkSize;l++)
268        {
269          pDst[k*dstStride+l] = refMain[l+1];
270        }
271      }
272
273      if ( bFilter )
274      {
275        for (k=0;k<blkSize;k++)
276        {
277          pDst[k*dstStride] = Clip3(0, (1<<bitDepth)-1, pDst[k*dstStride] + (( refSide[k+1] - refSide[0] ) >> 1) );
278        }
279      }
280    }
281    else
282    {
283      Int deltaPos=0;
284      Int deltaInt;
285      Int deltaFract;
286      Int refMainIndex;
287
288      for (k=0;k<blkSize;k++)
289      {
290        deltaPos += intraPredAngle;
291        deltaInt   = deltaPos >> 5;
292        deltaFract = deltaPos & (32 - 1);
293
294        if (deltaFract)
295        {
296          // Do linear filtering
297          for (l=0;l<blkSize;l++)
298          {
299            refMainIndex        = l+deltaInt+1;
300            pDst[k*dstStride+l] = (Pel) ( ((32-deltaFract)*refMain[refMainIndex]+deltaFract*refMain[refMainIndex+1]+16) >> 5 );
301          }
302        }
303        else
304        {
305          // Just copy the integer samples
306          for (l=0;l<blkSize;l++)
307          {
308            pDst[k*dstStride+l] = refMain[l+deltaInt+1];
309          }
310        }
311      }
312    }
313
314    // Flip the block if this is the horizontal mode
315    if (modeHor)
316    {
317      Pel  tmp;
318      for (k=0;k<blkSize-1;k++)
319      {
320        for (l=k+1;l<blkSize;l++)
321        {
322          tmp                 = pDst[k*dstStride+l];
323          pDst[k*dstStride+l] = pDst[l*dstStride+k];
324          pDst[l*dstStride+k] = tmp;
325        }
326      }
327    }
328  }
329}
330
331Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
332{
333  Pel *pDst = piPred;
334  Int *ptrSrc;
335
336  assert( g_aucConvertToBit[ iWidth ] >= 0 ); //   4x  4
337  assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128
338  assert( iWidth == iHeight  );
339
340  ptrSrc = pcTComPattern->getPredictorPtr( uiDirMode, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
341
342  // get starting pixel in block
343  Int sw = 2 * iWidth + 1;
344
345  // Create the prediction
346  if ( uiDirMode == PLANAR_IDX )
347  {
348    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
349  }
350  else
351  {
352    if ( (iWidth > 16) || (iHeight > 16) )
353    {
354      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
355    }
356    else
357    {
358      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true );
359
360      if( (uiDirMode == DC_IDX ) && bAbove && bLeft )
361      {
362        xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight);
363      }
364    }
365  }
366}
367
368// Angular chroma
369Void TComPrediction::predIntraChromaAng( Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
370{
371  Pel *pDst = piPred;
372  Int *ptrSrc = piSrc;
373
374  // get starting pixel in block
375  Int sw = 2 * iWidth + 1;
376
377  if ( uiDirMode == PLANAR_IDX )
378  {
379    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
380  }
381  else
382  {
383    // Create the prediction
384    xPredIntraAng(g_bitDepthC, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
385  }
386}
387
388/** Function for checking identical motion.
389 * \param TComDataCU* pcCU
390 * \param UInt PartAddr
391 */
392Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr )
393{
394  if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() )
395  {
396    if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0)
397    {
398      Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC();
399      Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC();
400      if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
401      {
402        return true;
403      }
404    }
405  }
406  return false;
407}
408
409
410Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
411{
412  Int         iWidth;
413  Int         iHeight;
414  UInt        uiPartAddr;
415
416  if ( iPartIdx >= 0 )
417  {
418    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
419    if ( eRefPicList != REF_PIC_LIST_X )
420    {
421      if( pcCU->getSlice()->getPPS()->getUseWP())
422      {
423        xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
424      }
425      else
426      {
427        xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
428      }
429      if ( pcCU->getSlice()->getPPS()->getUseWP() )
430      {
431        xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
432      }
433    }
434    else
435    {
436      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
437      {
438        xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
439      }
440      else
441      {
442        xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
443      }
444    }
445    return;
446  }
447
448  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
449  {
450    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
451
452    if ( eRefPicList != REF_PIC_LIST_X )
453    {
454      if( pcCU->getSlice()->getPPS()->getUseWP())
455      {
456        xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
457      }
458      else
459      {
460        xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
461      }
462      if ( pcCU->getSlice()->getPPS()->getUseWP() )
463      {
464        xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
465      }
466    }
467    else
468    {
469      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
470      {
471        xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
472      }
473      else
474      {
475        xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
476      }
477    }
478  }
479  return;
480}
481
482Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
483{
484  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
485  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
486  pcCU->clipMv(cMv);
487  xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
488  xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
489}
490
491Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
492{
493  TComYuv* pcMbYuv;
494  Int      iRefIdx[2] = {-1, -1};
495
496  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
497  {
498    RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
499    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
500
501    if ( iRefIdx[iRefList] < 0 )
502    {
503      continue;
504    }
505
506    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
507
508    pcMbYuv = &m_acYuvPred[iRefList];
509    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
510    {
511      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
512    }
513    else
514    {
515      if ( ( pcCU->getSlice()->getPPS()->getUseWP()       && pcCU->getSlice()->getSliceType() == P_SLICE ) || 
516           ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
517      {
518        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
519      }
520      else
521      {
522        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
523      }
524    }
525  }
526
527  if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE  )
528  {
529    xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
530  } 
531  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
532  {
533    xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred ); 
534  }
535  else
536  {
537    xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
538  }
539}
540
541/**
542 * \brief Generate motion-compensated luma block
543 *
544 * \param cu       Pointer to current CU
545 * \param refPic   Pointer to reference picture
546 * \param partAddr Address of block within CU
547 * \param mv       Motion vector
548 * \param width    Width of block
549 * \param height   Height of block
550 * \param dstPic   Pointer to destination picture
551 * \param bi       Flag indicating whether bipred is used
552 */
553Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi )
554{
555  Int refStride = refPic->getStride(); 
556  Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride;
557  Pel *ref      = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
558 
559  Int dstStride = dstPic->getStride();
560  Pel *dst      = dstPic->getLumaAddr( partAddr );
561 
562  Int xFrac = mv->getHor() & 0x3;
563  Int yFrac = mv->getVer() & 0x3;
564
565  if ( yFrac == 0 )
566  {
567    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi );
568  }
569  else if ( xFrac == 0 )
570  {
571    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi );
572  }
573  else
574  {
575    Int tmpStride = m_filteredBlockTmp[0].getStride();
576    Short *tmp    = m_filteredBlockTmp[0].getLumaAddr();
577
578    Int filterSize = NTAPS_LUMA;
579    Int halfFilterSize = ( filterSize >> 1 );
580
581    m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false     );
582    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi);   
583  }
584}
585
586/**
587 * \brief Generate motion-compensated chroma block
588 *
589 * \param cu       Pointer to current CU
590 * \param refPic   Pointer to reference picture
591 * \param partAddr Address of block within CU
592 * \param mv       Motion vector
593 * \param width    Width of block
594 * \param height   Height of block
595 * \param dstPic   Pointer to destination picture
596 * \param bi       Flag indicating whether bipred is used
597 */
598Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi )
599{
600  Int     refStride  = refPic->getCStride();
601  Int     dstStride  = dstPic->getCStride();
602 
603  Int     refOffset  = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride;
604 
605  Pel*    refCb     = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
606  Pel*    refCr     = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
607 
608  Pel* dstCb = dstPic->getCbAddr( partAddr );
609  Pel* dstCr = dstPic->getCrAddr( partAddr );
610 
611  Int     xFrac  = mv->getHor() & 0x7;
612  Int     yFrac  = mv->getVer() & 0x7;
613  UInt    cxWidth  = width  >> 1;
614  UInt    cxHeight = height >> 1;
615 
616  Int     extStride = m_filteredBlockTmp[0].getStride();
617  Short*  extY      = m_filteredBlockTmp[0].getLumaAddr();
618 
619  Int filterSize = NTAPS_CHROMA;
620 
621  Int halfFilterSize = (filterSize>>1);
622 
623  if ( yFrac == 0 )
624  {
625    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi);   
626    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi);   
627  }
628  else if ( xFrac == 0 )
629  {
630    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi);   
631    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi);   
632  }
633  else
634  {
635    m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false);
636    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi);
637   
638    m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false);
639    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi);   
640  }
641}
642
643Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
644{
645  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
646  {
647    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
648  }
649  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
650  {
651    pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
652  }
653  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
654  {
655    pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
656  }
657}
658
659// AMVP
660Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
661{
662  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
663  if( pcAMVPInfo->iN <= 1 )
664  {
665    rcMvPred = pcAMVPInfo->m_acMvCand[0];
666
667    pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
668    pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
669    return;
670  }
671
672  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
673  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
674  return;
675}
676
677/** Function for deriving planar intra prediction.
678 * \param pSrc pointer to reconstructed sample array
679 * \param srcStride the stride of the reconstructed sample array
680 * \param rpDst reference to pointer for the prediction sample array
681 * \param dstStride the stride of the prediction sample array
682 * \param width the width of the block
683 * \param height the height of the block
684 *
685 * This function derives the prediction samples for planar mode (intra coding).
686 */
687Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
688{
689  assert(width == height);
690
691  Int k, l, bottomLeft, topRight;
692  Int horPred;
693  Int leftColumn[MAX_CU_SIZE], topRow[MAX_CU_SIZE], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
694  UInt blkSize = width;
695  UInt offset2D = width;
696  UInt shift1D = g_aucConvertToBit[ width ] + 2;
697  UInt shift2D = shift1D + 1;
698
699  // Get left and above reference column and row
700  for(k=0;k<blkSize+1;k++)
701  {
702    topRow[k] = pSrc[k-srcStride];
703    leftColumn[k] = pSrc[k*srcStride-1];
704  }
705
706  // Prepare intermediate variables used in interpolation
707  bottomLeft = leftColumn[blkSize];
708  topRight   = topRow[blkSize];
709  for (k=0;k<blkSize;k++)
710  {
711    bottomRow[k]   = bottomLeft - topRow[k];
712    rightColumn[k] = topRight   - leftColumn[k];
713    topRow[k]      <<= shift1D;
714    leftColumn[k]  <<= shift1D;
715  }
716
717  // Generate prediction signal
718  for (k=0;k<blkSize;k++)
719  {
720    horPred = leftColumn[k] + offset2D;
721    for (l=0;l<blkSize;l++)
722    {
723      horPred += rightColumn[k];
724      topRow[l] += bottomRow[l];
725      rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D );
726    }
727  }
728}
729
730/** Function for filtering intra DC predictor.
731 * \param pSrc pointer to reconstructed sample array
732 * \param iSrcStride the stride of the reconstructed sample array
733 * \param rpDst reference to pointer for the prediction sample array
734 * \param iDstStride the stride of the prediction sample array
735 * \param iWidth the width of the block
736 * \param iHeight the height of the block
737 *
738 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
739 */
740Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )
741{
742  Pel* pDst = rpDst;
743  Int x, y, iDstStride2, iSrcStride2;
744
745  // boundary pixels processing
746  pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
747
748  for ( x = 1; x < iWidth; x++ )
749  {
750    pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2);
751  }
752
753  for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
754  {
755    pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
756  }
757
758  return;
759}
760//! \}
Note: See TracBrowser for help on using the repository browser.