source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibCommon/TComPattern.cpp @ 1289

Last change on this file since 1289 was 1289, checked in by seregin, 10 years ago

port rev 4323 (g_uiMaxCUWidth, g_uiMaxCUHeight)

  • Property svn:eol-style set to native
File size: 24.0 KB
RevLine 
[313]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
[1029]4 * granted under this license.
[313]5 *
[1259]6 * Copyright (c) 2010-2015, ITU/ISO/IEC
[313]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     TComPattern.cpp
35    \brief    neighbouring pixel access classes
36*/
37
38#include "TComPic.h"
39#include "TComPattern.h"
40#include "TComDataCU.h"
[1029]41#include "TComTU.h"
42#include "Debug.h"
43#include "TComPrediction.h"
[313]44
45//! \ingroup TLibCommon
46//! \{
47
[1029]48// Forward declarations
[313]49
[1029]50/// padding of unavailable reference samples for intra prediction
51#if O0043_BEST_EFFORT_DECODING
52Void fillReferenceSamples( const Int bitDepth, const Int bitDepthDelta, TComDataCU* pcCU, const Pel* piRoiOrigin, Pel* piAdiTemp, const Bool* bNeighborFlags,
53#else
54Void fillReferenceSamples( const Int bitDepth, TComDataCU* pcCU, const Pel* piRoiOrigin, Pel* piAdiTemp, const Bool* bNeighborFlags,
55#endif
56                           const Int iNumIntraNeighbor, const Int unitWidth, const Int unitHeight, const Int iAboveUnits, const Int iLeftUnits,
57                           const UInt uiCuWidth, const UInt uiCuHeight, const UInt uiWidth, const UInt uiHeight, const Int iPicStride,
58                           const ChannelType chType, const ChromaFormat chFmt );
[313]59
[1029]60/// constrained intra prediction
61Bool  isAboveLeftAvailable  ( TComDataCU* pcCU, UInt uiPartIdxLT );
62Int   isAboveAvailable      ( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxRT, Bool* bValidFlags );
63Int   isLeftAvailable       ( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxLB, Bool* bValidFlags );
64Int   isAboveRightAvailable ( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxRT, Bool* bValidFlags );
65Int   isBelowLeftAvailable  ( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxLB, Bool* bValidFlags );
66
67
[313]68// ====================================================================================================================
69// Public member functions (TComPatternParam)
70// ====================================================================================================================
71
[1260]72/**
73 \param  piTexture     pixel data
[313]74 \param  iRoiWidth     pattern width
75 \param  iRoiHeight    pattern height
76 \param  iStride       buffer stride
77 */
78Void TComPatternParam::setPatternParamPel ( Pel* piTexture,
79                                           Int iRoiWidth,
80                                           Int iRoiHeight,
[1287]81                                           Int iStride,
82                                           Int bitDepth
[1029]83                                           )
[313]84{
[1029]85  m_piROIOrigin    = piTexture;
[1287]86  m_iROIWidth      = iRoiWidth;
87  m_iROIHeight     = iRoiHeight;
88  m_iPatternStride = iStride;
89  m_bitDepth       = bitDepth;
[313]90}
91
92// ====================================================================================================================
93// Public member functions (TComPattern)
94// ====================================================================================================================
95
[1029]96Void TComPattern::initPattern (Pel* piY,
[313]97                               Int iRoiWidth,
98                               Int iRoiHeight,
[1287]99                               Int iStride,
100                               Int bitDepthLuma)
[313]101{
[1287]102  m_cPatternY. setPatternParamPel( piY,  iRoiWidth, iRoiHeight, iStride, bitDepthLuma);
[313]103}
104
[1029]105
106// TODO: move this function to TComPrediction.cpp.
107Void TComPrediction::initAdiPatternChType( TComTU &rTu, Bool& bAbove, Bool& bLeft, const ComponentID compID, const Bool bFilterRefSamples DEBUG_STRING_FN_DECLARE(sDebug))
[313]108{
[1029]109  const ChannelType chType    = toChannelType(compID);
[313]110
[1029]111  TComDataCU *pcCU=rTu.getCU();
[1289]112  const TComSPS &sps = *(pcCU->getSlice()->getSPS());
[1029]113  const UInt uiZorderIdxInPart=rTu.GetAbsPartIdxTU();
114  const UInt uiTuWidth        = rTu.getRect(compID).width;
115  const UInt uiTuHeight       = rTu.getRect(compID).height;
116  const UInt uiTuWidth2       = uiTuWidth  << 1;
117  const UInt uiTuHeight2      = uiTuHeight << 1;
118
[1289]119  const Int  iBaseUnitSize    = sps.getMaxCUWidth() >> g_uiMaxCUDepth;
[1029]120  const Int  iUnitWidth       = iBaseUnitSize  >> pcCU->getPic()->getPicYuvRec()->getComponentScaleX(compID);
121  const Int  iUnitHeight      = iBaseUnitSize  >> pcCU->getPic()->getPicYuvRec()->getComponentScaleY(compID);
122  const Int  iTUWidthInUnits  = uiTuWidth  / iUnitWidth;
123  const Int  iTUHeightInUnits = uiTuHeight / iUnitHeight;
124  const Int  iAboveUnits      = iTUWidthInUnits  << 1;
125  const Int  iLeftUnits       = iTUHeightInUnits << 1;
[1287]126#if SVC_EXTENSION
127  const Int  bitDepthForChannel = pcCU->getSlice()->getBitDepth(chType);
128#else
[1289]129  const Int  bitDepthForChannel = sps.getBitDepth(chType);
[1287]130#endif
[1029]131
132  assert(iTUHeightInUnits > 0 && iTUWidthInUnits > 0);
133
134  const Int  iPartIdxStride   = pcCU->getPic()->getNumPartInCtuWidth();
135  const UInt uiPartIdxLT      = pcCU->getZorderIdxInCtu() + uiZorderIdxInPart;
136  const UInt uiPartIdxRT      = g_auiRasterToZscan[ g_auiZscanToRaster[ uiPartIdxLT ] +   iTUWidthInUnits  - 1                   ];
137  const UInt uiPartIdxLB      = g_auiRasterToZscan[ g_auiZscanToRaster[ uiPartIdxLT ] + ((iTUHeightInUnits - 1) * iPartIdxStride)];
138
139  Int   iPicStride = pcCU->getPic()->getStride(compID);
[313]140  Bool  bNeighborFlags[4 * MAX_NUM_SPU_W + 1];
141  Int   iNumIntraNeighbor = 0;
142
[1029]143  bNeighborFlags[iLeftUnits] = isAboveLeftAvailable( pcCU, uiPartIdxLT );
144  iNumIntraNeighbor += bNeighborFlags[iLeftUnits] ? 1 : 0;
145  iNumIntraNeighbor  += isAboveAvailable     ( pcCU, uiPartIdxLT, uiPartIdxRT, (bNeighborFlags + iLeftUnits + 1)                    );
146  iNumIntraNeighbor  += isAboveRightAvailable( pcCU, uiPartIdxLT, uiPartIdxRT, (bNeighborFlags + iLeftUnits + 1 + iTUWidthInUnits ) );
147  iNumIntraNeighbor  += isLeftAvailable      ( pcCU, uiPartIdxLT, uiPartIdxLB, (bNeighborFlags + iLeftUnits - 1)                    );
148  iNumIntraNeighbor  += isBelowLeftAvailable ( pcCU, uiPartIdxLT, uiPartIdxLB, (bNeighborFlags + iLeftUnits - 1 - iTUHeightInUnits) );
[313]149
150  bAbove = true;
151  bLeft  = true;
152
[1029]153  const ChromaFormat chFmt       = rTu.GetChromaFormat();
154  const UInt         uiROIWidth  = uiTuWidth2+1;
155  const UInt         uiROIHeight = uiTuHeight2+1;
[313]156
[1029]157  assert(uiROIWidth*uiROIHeight <= m_iYuvExtSize);
[313]158
[1029]159#ifdef DEBUG_STRING
160  std::stringstream ss(stringstream::out);
161#endif
[313]162
163  {
[1029]164    Pel *piAdiTemp   = m_piYuvExt[compID][PRED_BUF_UNFILTERED];
165    Pel *piRoiOrigin = pcCU->getPic()->getPicYuvRec()->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu()+uiZorderIdxInPart);
166#if O0043_BEST_EFFORT_DECODING
[1289]167    const Int  bitDepthForChannelInStream = sps.getStreamBitDepth(chType);
[1287]168    fillReferenceSamples (bitDepthForChannelInStream, bitDepthForChannelInStream - bitDepthForChannel, pcCU, piRoiOrigin, piAdiTemp, bNeighborFlags, iNumIntraNeighbor,  iUnitWidth, iUnitHeight, iAboveUnits, iLeftUnits,
[1029]169#else
[1287]170    fillReferenceSamples (bitDepthForChannel, pcCU, piRoiOrigin, piAdiTemp, bNeighborFlags, iNumIntraNeighbor,  iUnitWidth, iUnitHeight, iAboveUnits, iLeftUnits,
[1029]171#endif
172                          uiTuWidth, uiTuHeight, uiROIWidth, uiROIHeight, iPicStride, toChannelType(compID), chFmt);
[313]173
[1029]174
175#ifdef DEBUG_STRING
176    if (DebugOptionList::DebugString_Pred.getInt()&DebugStringGetPredModeMask(MODE_INTRA))
[313]177    {
[1029]178      ss << "###: generating Ref Samples for channel " << compID << " and " << rTu.getRect(compID).width << " x " << rTu.getRect(compID).height << "\n";
179      for (UInt y=0; y<uiROIHeight; y++)
[313]180      {
[1029]181        ss << "###: - ";
182        for (UInt x=0; x<uiROIWidth; x++)
183        {
184          if (x==0 || y==0)
[1246]185          {
[1029]186            ss << piAdiTemp[y*uiROIWidth + x] << ", ";
187//          if (x%16==15) ss << "\nPart size: ~ ";
[1246]188          }
[1029]189        }
190        ss << "\n";
[313]191      }
[1029]192    }
193#endif
194
195    if (bFilterRefSamples)
196    {
197      // generate filtered intra prediction samples
198
199            Int          stride    = uiROIWidth;
200      const Pel         *piSrcPtr  = piAdiTemp                             + (stride * uiTuHeight2); // bottom left
201            Pel         *piDestPtr = m_piYuvExt[compID][PRED_BUF_FILTERED] + (stride * uiTuHeight2); // bottom left
202
203      //------------------------------------------------
204
[1289]205      Bool useStrongIntraSmoothing = isLuma(chType) && sps.getUseStrongIntraSmoothing();
[1029]206
207      const Pel bottomLeft = piAdiTemp[stride * uiTuHeight2];
208      const Pel topLeft    = piAdiTemp[0];
209      const Pel topRight   = piAdiTemp[uiTuWidth2];
210
211      if (useStrongIntraSmoothing)
[313]212      {
[1029]213#if O0043_BEST_EFFORT_DECODING
[1287]214        const Int  threshold     = 1 << (bitDepthForChannelInStream - 5);
[1029]215#else
[1287]216        const Int  threshold     = 1 << (bitDepthForChannel - 5);
[1029]217#endif
218        const Bool bilinearLeft  = abs((bottomLeft + topLeft ) - (2 * piAdiTemp[stride * uiTuHeight])) < threshold; //difference between the
219        const Bool bilinearAbove = abs((topLeft    + topRight) - (2 * piAdiTemp[         uiTuWidth ])) < threshold; //ends and the middle
220        if ((uiTuWidth < 32) || (!bilinearLeft) || (!bilinearAbove))
[1246]221        {
[1029]222          useStrongIntraSmoothing = false;
[1246]223        }
[313]224      }
[1029]225
226      *piDestPtr = *piSrcPtr; // bottom left is not filtered
227      piDestPtr -= stride;
228      piSrcPtr  -= stride;
229
230      //------------------------------------------------
231
232      //left column (bottom to top)
233
234      if (useStrongIntraSmoothing)
235      {
236        const Int shift = g_aucConvertToBit[uiTuHeight] + 3; //log2(uiTuHeight2)
237
238        for(UInt i=1; i<uiTuHeight2; i++, piDestPtr-=stride)
239        {
240          *piDestPtr = (((uiTuHeight2 - i) * bottomLeft) + (i * topLeft) + uiTuHeight) >> shift;
241        }
242
243        piSrcPtr -= stride * (uiTuHeight2 - 1);
244      }
245      else
246      {
247        for(UInt i=1; i<uiTuHeight2; i++, piDestPtr-=stride, piSrcPtr-=stride)
248        {
249          *piDestPtr = ( piSrcPtr[stride] + 2*piSrcPtr[0] + piSrcPtr[-stride] + 2 ) >> 2;
250        }
251      }
252
253      //------------------------------------------------
254
255      //top-left
256
257      if (useStrongIntraSmoothing)
258      {
259        *piDestPtr = piSrcPtr[0];
260      }
261      else
262      {
263        *piDestPtr = ( piSrcPtr[stride] + 2*piSrcPtr[0] + piSrcPtr[1] + 2 ) >> 2;
264      }
265      piDestPtr += 1;
266      piSrcPtr  += 1;
267
268      //------------------------------------------------
269
270      //top row (left-to-right)
271
272      if (useStrongIntraSmoothing)
273      {
274        const Int shift = g_aucConvertToBit[uiTuWidth] + 3; //log2(uiTuWidth2)
275
276        for(UInt i=1; i<uiTuWidth2; i++, piDestPtr++)
277        {
278          *piDestPtr = (((uiTuWidth2 - i) * topLeft) + (i * topRight) + uiTuWidth) >> shift;
279        }
280
281        piSrcPtr += uiTuWidth2 - 1;
282      }
283      else
284      {
285        for(UInt i=1; i<uiTuWidth2; i++, piDestPtr++, piSrcPtr++)
286        {
287          *piDestPtr = ( piSrcPtr[1] + 2*piSrcPtr[0] + piSrcPtr[-1] + 2 ) >> 2;
288        }
289      }
290
291      //------------------------------------------------
292
293      *piDestPtr=*piSrcPtr; // far right is not filtered
294
295#ifdef DEBUG_STRING
296    if (DebugOptionList::DebugString_Pred.getInt()&DebugStringGetPredModeMask(MODE_INTRA))
[313]297    {
[1029]298      ss << "###: filtered result for channel " << compID <<"\n";
299      for (UInt y=0; y<uiROIHeight; y++)
[313]300      {
[1029]301        ss << "###: - ";
302        for (UInt x=0; x<uiROIWidth; x++)
303        {
304          if (x==0 || y==0)
[1246]305          {
[1029]306            ss << m_piYuvExt[compID][PRED_BUF_FILTERED][y*uiROIWidth + x] << ", ";
307//          if (x%16==15) ss << "\nPart size: ~ ";
[1246]308          }
[1029]309        }
310        ss << "\n";
[313]311      }
312    }
[1029]313#endif
[313]314
315
[1029]316    }
[313]317  }
[1029]318  DEBUG_STRING_APPEND(sDebug, ss.str())
[313]319}
320
[1029]321#if O0043_BEST_EFFORT_DECODING
322Void fillReferenceSamples( const Int bitDepth, const Int bitDepthDelta, TComDataCU* pcCU, const Pel* piRoiOrigin, Pel* piAdiTemp, const Bool* bNeighborFlags,
323#else
324Void fillReferenceSamples( const Int bitDepth, TComDataCU* pcCU, const Pel* piRoiOrigin, Pel* piAdiTemp, const Bool* bNeighborFlags,
325#endif
326                           const Int iNumIntraNeighbor, const Int unitWidth, const Int unitHeight, const Int iAboveUnits, const Int iLeftUnits,
327                           const UInt uiCuWidth, const UInt uiCuHeight, const UInt uiWidth, const UInt uiHeight, const Int iPicStride,
328                           const ChannelType chType, const ChromaFormat chFmt )
[313]329{
[1029]330  const Pel* piRoiTemp;
[313]331  Int  i, j;
332  Int  iDCValue = 1 << (bitDepth - 1);
[1029]333  const Int iTotalUnits = iAboveUnits + iLeftUnits + 1; //+1 for top-left
[313]334
335  if (iNumIntraNeighbor == 0)
336  {
337    // Fill border with DC value
338    for (i=0; i<uiWidth; i++)
339    {
340      piAdiTemp[i] = iDCValue;
341    }
342    for (i=1; i<uiHeight; i++)
343    {
344      piAdiTemp[i*uiWidth] = iDCValue;
345    }
346  }
347  else if (iNumIntraNeighbor == iTotalUnits)
348  {
[1029]349    // Fill top-left border and top and top right with rec. samples
[313]350    piRoiTemp = piRoiOrigin - iPicStride - 1;
351
[1029]352    for (i=0; i<uiWidth; i++)
[313]353    {
[1029]354#if O0043_BEST_EFFORT_DECODING
355      piAdiTemp[i] = piRoiTemp[i] << bitDepthDelta;
356#else
357      piAdiTemp[i] = piRoiTemp[i];
358#endif
[313]359    }
360
[1029]361    // Fill left and below left border with rec. samples
362    piRoiTemp = piRoiOrigin - 1;
[313]363
[1029]364    for (i=1; i<uiHeight; i++)
[313]365    {
[1029]366#if O0043_BEST_EFFORT_DECODING
367      piAdiTemp[i*uiWidth] = (*(piRoiTemp)) << bitDepthDelta;
368#else
369      piAdiTemp[i*uiWidth] = *(piRoiTemp);
370#endif
[313]371      piRoiTemp += iPicStride;
372    }
373  }
374  else // reference samples are partially available
375  {
[1029]376    // all above units have "unitWidth" samples each, all left/below-left units have "unitHeight" samples each
377    const Int  iTotalSamples = (iLeftUnits * unitHeight) + ((iAboveUnits + 1) * unitWidth);
[313]378    Pel  piAdiLine[5 * MAX_CU_SIZE];
[1029]379    Pel  *piAdiLineTemp;
380    const Bool *pbNeighborFlags;
[313]381
[1029]382
[313]383    // Initialize
384    for (i=0; i<iTotalSamples; i++)
385    {
386      piAdiLine[i] = iDCValue;
387    }
[1029]388
[313]389    // Fill top-left sample
390    piRoiTemp = piRoiOrigin - iPicStride - 1;
[1029]391    piAdiLineTemp = piAdiLine + (iLeftUnits * unitHeight);
392    pbNeighborFlags = bNeighborFlags + iLeftUnits;
[313]393    if (*pbNeighborFlags)
394    {
[1029]395#if O0043_BEST_EFFORT_DECODING
396      Pel topLeftVal=piRoiTemp[0] << bitDepthDelta;
397#else
398      Pel topLeftVal=piRoiTemp[0];
399#endif
400      for (i=0; i<unitWidth; i++)
[313]401      {
[1029]402        piAdiLineTemp[i] = topLeftVal;
[313]403      }
404    }
405
[1029]406    // Fill left & below-left samples (downwards)
[313]407    piRoiTemp += iPicStride;
408    piAdiLineTemp--;
409    pbNeighborFlags--;
[1029]410
411    for (j=0; j<iLeftUnits; j++)
[313]412    {
413      if (*pbNeighborFlags)
414      {
[1029]415        for (i=0; i<unitHeight; i++)
[313]416        {
[1029]417#if O0043_BEST_EFFORT_DECODING
418          piAdiLineTemp[-i] = piRoiTemp[i*iPicStride] << bitDepthDelta;
419#else
[313]420          piAdiLineTemp[-i] = piRoiTemp[i*iPicStride];
[1029]421#endif
[313]422        }
423      }
[1029]424      piRoiTemp += unitHeight*iPicStride;
425      piAdiLineTemp -= unitHeight;
[313]426      pbNeighborFlags--;
427    }
428
[1029]429    // Fill above & above-right samples (left-to-right) (each unit has "unitWidth" samples)
[313]430    piRoiTemp = piRoiOrigin - iPicStride;
[1029]431    // offset line buffer by iNumUints2*unitHeight (for left/below-left) + unitWidth (for above-left)
432    piAdiLineTemp = piAdiLine + (iLeftUnits * unitHeight) + unitWidth;
433    pbNeighborFlags = bNeighborFlags + iLeftUnits + 1;
434    for (j=0; j<iAboveUnits; j++)
[313]435    {
436      if (*pbNeighborFlags)
437      {
[1029]438        for (i=0; i<unitWidth; i++)
[313]439        {
[1029]440#if O0043_BEST_EFFORT_DECODING
441          piAdiLineTemp[i] = piRoiTemp[i] << bitDepthDelta;
442#else
[313]443          piAdiLineTemp[i] = piRoiTemp[i];
[1029]444#endif
[313]445        }
446      }
[1029]447      piRoiTemp += unitWidth;
448      piAdiLineTemp += unitWidth;
[313]449      pbNeighborFlags++;
450    }
451
452    // Pad reference samples when necessary
[1029]453    Int iCurrJnit = 0;
454    Pel  *piAdiLineCur   = piAdiLine;
455    const UInt piAdiLineTopRowOffset = iLeftUnits * (unitHeight - unitWidth);
456
457    if (!bNeighborFlags[0])
[313]458    {
[1029]459      // very bottom unit of bottom-left; at least one unit will be valid.
[313]460      {
[1029]461        Int   iNext = 1;
462        while (iNext < iTotalUnits && !bNeighborFlags[iNext])
[313]463        {
[1029]464          iNext++;
465        }
466        Pel *piAdiLineNext = piAdiLine + ((iNext < iLeftUnits) ? (iNext * unitHeight) : (piAdiLineTopRowOffset + (iNext * unitWidth)));
467        const Pel refSample = *piAdiLineNext;
468        // Pad unavailable samples with new value
469        Int iNextOrTop = std::min<Int>(iNext, iLeftUnits);
470        // fill left column
471        while (iCurrJnit < iNextOrTop)
472        {
473          for (i=0; i<unitHeight; i++)
[313]474          {
[1029]475            piAdiLineCur[i] = refSample;
[313]476          }
[1029]477          piAdiLineCur += unitHeight;
478          iCurrJnit++;
479        }
480        // fill top row
481        while (iCurrJnit < iNext)
482        {
483          for (i=0; i<unitWidth; i++)
[313]484          {
[1029]485            piAdiLineCur[i] = refSample;
[313]486          }
[1029]487          piAdiLineCur += unitWidth;
488          iCurrJnit++;
[313]489        }
[1029]490      }
491    }
492
493    // pad all other reference samples.
494    while (iCurrJnit < iTotalUnits)
495    {
496      if (!bNeighborFlags[iCurrJnit]) // samples not available
497      {
[313]498        {
[1029]499          const Int numSamplesInCurrUnit = (iCurrJnit >= iLeftUnits) ? unitWidth : unitHeight;
500          const Pel refSample = *(piAdiLineCur-1);
501          for (i=0; i<numSamplesInCurrUnit; i++)
[313]502          {
[1029]503            piAdiLineCur[i] = refSample;
[313]504          }
[1029]505          piAdiLineCur += numSamplesInCurrUnit;
506          iCurrJnit++;
[313]507        }
508      }
509      else
510      {
[1029]511        piAdiLineCur += (iCurrJnit >= iLeftUnits) ? unitWidth : unitHeight;
512        iCurrJnit++;
[313]513      }
514    }
515
516    // Copy processed samples
[1029]517
518    piAdiLineTemp = piAdiLine + uiHeight + unitWidth - 2;
519    // top left, top and top right samples
[313]520    for (i=0; i<uiWidth; i++)
521    {
522      piAdiTemp[i] = piAdiLineTemp[i];
523    }
[1029]524
[313]525    piAdiLineTemp = piAdiLine + uiHeight - 1;
526    for (i=1; i<uiHeight; i++)
527    {
528      piAdiTemp[i*uiWidth] = piAdiLineTemp[-i];
529    }
530  }
531}
532
[1029]533Bool TComPrediction::filteringIntraReferenceSamples(const ComponentID compID, UInt uiDirMode, UInt uiTuChWidth, UInt uiTuChHeight, const ChromaFormat chFmt, const Bool intraReferenceSmoothingDisabled)
[313]534{
[1029]535  Bool bFilter;
536
537  if (!filterIntraReferenceSamples(toChannelType(compID), chFmt, intraReferenceSmoothingDisabled))
[313]538  {
[1029]539    bFilter=false;
[313]540  }
[1029]541  else
542  {
543    assert(uiTuChWidth>=4 && uiTuChHeight>=4 && uiTuChWidth<128 && uiTuChHeight<128);
[313]544
[1029]545    if (uiDirMode == DC_IDX)
546    {
547      bFilter=false; //no smoothing for DC or LM chroma
548    }
549    else
550    {
551      Int diff = min<Int>(abs((Int) uiDirMode - HOR_IDX), abs((Int)uiDirMode - VER_IDX));
552      UInt sizeIndex=g_aucConvertToBit[uiTuChWidth];
553      assert(sizeIndex < MAX_INTRA_FILTER_DEPTHS);
554      bFilter = diff > m_aucIntraFilter[toChannelType(compID)][sizeIndex];
555    }
[313]556  }
[1029]557  return bFilter;
[313]558}
559
[1029]560Bool isAboveLeftAvailable( TComDataCU* pcCU, UInt uiPartIdxLT )
[313]561{
562  Bool bAboveLeftFlag;
563  UInt uiPartAboveLeft;
564  TComDataCU* pcCUAboveLeft = pcCU->getPUAboveLeft( uiPartAboveLeft, uiPartIdxLT );
565  if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred())
566  {
[1029]567    bAboveLeftFlag = ( pcCUAboveLeft && pcCUAboveLeft->isIntra( uiPartAboveLeft ) );
[313]568  }
569  else
570  {
571    bAboveLeftFlag = (pcCUAboveLeft ? true : false);
572  }
573  return bAboveLeftFlag;
574}
575
[1029]576Int isAboveAvailable( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxRT, Bool *bValidFlags )
[313]577{
578  const UInt uiRasterPartBegin = g_auiZscanToRaster[uiPartIdxLT];
579  const UInt uiRasterPartEnd = g_auiZscanToRaster[uiPartIdxRT]+1;
580  const UInt uiIdxStep = 1;
581  Bool *pbValidFlags = bValidFlags;
582  Int iNumIntra = 0;
583
584  for ( UInt uiRasterPart = uiRasterPartBegin; uiRasterPart < uiRasterPartEnd; uiRasterPart += uiIdxStep )
585  {
586    UInt uiPartAbove;
587    TComDataCU* pcCUAbove = pcCU->getPUAbove( uiPartAbove, g_auiRasterToZscan[uiRasterPart] );
588    if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred())
589    {
[1029]590      if ( pcCUAbove && pcCUAbove->isIntra( uiPartAbove ) )
[313]591      {
592        iNumIntra++;
593        *pbValidFlags = true;
594      }
595      else
596      {
597        *pbValidFlags = false;
598      }
599    }
600    else
601    {
602      if (pcCUAbove)
603      {
604        iNumIntra++;
605        *pbValidFlags = true;
606      }
607      else
608      {
609        *pbValidFlags = false;
610      }
611    }
612    pbValidFlags++;
613  }
614  return iNumIntra;
615}
616
[1029]617Int isLeftAvailable( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxLB, Bool *bValidFlags )
[313]618{
619  const UInt uiRasterPartBegin = g_auiZscanToRaster[uiPartIdxLT];
620  const UInt uiRasterPartEnd = g_auiZscanToRaster[uiPartIdxLB]+1;
[1029]621  const UInt uiIdxStep = pcCU->getPic()->getNumPartInCtuWidth();
[313]622  Bool *pbValidFlags = bValidFlags;
623  Int iNumIntra = 0;
624
625  for ( UInt uiRasterPart = uiRasterPartBegin; uiRasterPart < uiRasterPartEnd; uiRasterPart += uiIdxStep )
626  {
627    UInt uiPartLeft;
628    TComDataCU* pcCULeft = pcCU->getPULeft( uiPartLeft, g_auiRasterToZscan[uiRasterPart] );
629    if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred())
630    {
[1029]631      if ( pcCULeft && pcCULeft->isIntra( uiPartLeft ) )
[313]632      {
633        iNumIntra++;
634        *pbValidFlags = true;
635      }
636      else
637      {
638        *pbValidFlags = false;
639      }
640    }
641    else
642    {
643      if ( pcCULeft )
644      {
645        iNumIntra++;
646        *pbValidFlags = true;
647      }
648      else
649      {
650        *pbValidFlags = false;
651      }
652    }
653    pbValidFlags--; // opposite direction
654  }
655
656  return iNumIntra;
657}
658
[1029]659Int isAboveRightAvailable( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxRT, Bool *bValidFlags )
[313]660{
661  const UInt uiNumUnitsInPU = g_auiZscanToRaster[uiPartIdxRT] - g_auiZscanToRaster[uiPartIdxLT] + 1;
662  Bool *pbValidFlags = bValidFlags;
663  Int iNumIntra = 0;
664
665  for ( UInt uiOffset = 1; uiOffset <= uiNumUnitsInPU; uiOffset++ )
666  {
667    UInt uiPartAboveRight;
668    TComDataCU* pcCUAboveRight = pcCU->getPUAboveRightAdi( uiPartAboveRight, uiPartIdxRT, uiOffset );
669    if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred())
670    {
[1029]671      if ( pcCUAboveRight && pcCUAboveRight->isIntra( uiPartAboveRight ) )
[313]672      {
673        iNumIntra++;
674        *pbValidFlags = true;
675      }
676      else
677      {
678        *pbValidFlags = false;
679      }
680    }
681    else
682    {
683      if ( pcCUAboveRight )
684      {
685        iNumIntra++;
686        *pbValidFlags = true;
687      }
688      else
689      {
690        *pbValidFlags = false;
691      }
692    }
693    pbValidFlags++;
694  }
695
696  return iNumIntra;
697}
698
[1029]699Int isBelowLeftAvailable( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxLB, Bool *bValidFlags )
[313]700{
[1029]701  const UInt uiNumUnitsInPU = (g_auiZscanToRaster[uiPartIdxLB] - g_auiZscanToRaster[uiPartIdxLT]) / pcCU->getPic()->getNumPartInCtuWidth() + 1;
[313]702  Bool *pbValidFlags = bValidFlags;
703  Int iNumIntra = 0;
704
705  for ( UInt uiOffset = 1; uiOffset <= uiNumUnitsInPU; uiOffset++ )
706  {
707    UInt uiPartBelowLeft;
708    TComDataCU* pcCUBelowLeft = pcCU->getPUBelowLeftAdi( uiPartBelowLeft, uiPartIdxLB, uiOffset );
709    if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred())
710    {
[1029]711      if ( pcCUBelowLeft && pcCUBelowLeft->isIntra( uiPartBelowLeft ) )
[313]712      {
713        iNumIntra++;
714        *pbValidFlags = true;
715      }
716      else
717      {
718        *pbValidFlags = false;
719      }
720    }
721    else
722    {
723      if ( pcCUBelowLeft )
724      {
725        iNumIntra++;
726        *pbValidFlags = true;
727      }
728      else
729      {
730        *pbValidFlags = false;
731      }
732    }
733    pbValidFlags--; // opposite direction
734  }
735
736  return iNumIntra;
737}
738//! \}
Note: See TracBrowser for help on using the repository browser.