source: 3DVCSoftware/trunk/source/Lib/TLibCommon/TComPattern.cpp @ 361

Last change on this file since 361 was 296, checked in by tech, 12 years ago

Reintegrated branch 5.1-dev0 rev. 295.

  • Property svn:eol-style set to native
File size: 29.0 KB
RevLine 
[5]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
[56]4 * granted under this license. 
[5]5 *
[56]6 * Copyright (c) 2010-2012, ITU/ISO/IEC
[5]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.
[56]17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
[5]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 */
[2]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"
41
[56]42//! \ingroup TLibCommon
43//! \{
44
[2]45// ====================================================================================================================
46// Tables
47// ====================================================================================================================
48
[56]49const UChar TComPattern::m_aucIntraFilter[5] =
[2]50{
[56]51  10, //4x4
52  7, //8x8
53  1, //16x16
54  0, //32x32
55  10, //64x64
[2]56};
57
58// ====================================================================================================================
59// Public member functions (TComPatternParam)
60// ====================================================================================================================
61
62/** \param  piTexture     pixel data
63 \param  iRoiWidth     pattern width
64 \param  iRoiHeight    pattern height
65 \param  iStride       buffer stride
66 \param  iOffsetLeft   neighbour offset (left)
67 \param  iOffsetRight  neighbour offset (right)
68 \param  iOffsetAbove  neighbour offset (above)
69 \param  iOffsetBottom neighbour offset (bottom)
70 */
71Void TComPatternParam::setPatternParamPel ( Pel* piTexture,
72                                           Int iRoiWidth,
73                                           Int iRoiHeight,
74                                           Int iStride,
75                                           Int iOffsetLeft,
76                                           Int iOffsetRight,
77                                           Int iOffsetAbove,
78                                           Int iOffsetBottom )
79{
80  m_piPatternOrigin = piTexture;
81  m_iROIWidth       = iRoiWidth;
82  m_iROIHeight      = iRoiHeight;
83  m_iPatternStride  = iStride;
84  m_iOffsetLeft     = iOffsetLeft;
85  m_iOffsetAbove    = iOffsetAbove;
86  m_iOffsetRight    = iOffsetRight;
87  m_iOffsetBottom   = iOffsetBottom;
88}
89
90/**
91 \param  pcCU          CU data structure
92 \param  iComp         component index (0=Y, 1=Cb, 2=Cr)
93 \param  iRoiWidth     pattern width
94 \param  iRoiHeight    pattern height
95 \param  iStride       buffer stride
96 \param  iOffsetLeft   neighbour offset (left)
97 \param  iOffsetRight  neighbour offset (right)
98 \param  iOffsetAbove  neighbour offset (above)
99 \param  iOffsetBottom neighbour offset (bottom)
100 \param  uiPartDepth   CU depth
101 \param  uiAbsPartIdx  part index
102 */
103Void TComPatternParam::setPatternParamCU( TComDataCU* pcCU,
104                                         UChar       iComp,
105                                         UChar       iRoiWidth,
106                                         UChar       iRoiHeight,
107                                         Int         iOffsetLeft,
108                                         Int         iOffsetRight,
109                                         Int         iOffsetAbove,
110                                         Int         iOffsetBottom,
111                                         UInt        uiPartDepth,
[56]112                                         UInt        uiAbsPartIdx
[5]113#if DEPTH_MAP_GENERATION
[56]114                                         ,Bool        bPrdDepthMap
[5]115#endif
116                                         )
[2]117{
118  m_iOffsetLeft   = iOffsetLeft;
119  m_iOffsetRight  = iOffsetRight;
120  m_iOffsetAbove  = iOffsetAbove;
121  m_iOffsetBottom = iOffsetBottom;
122 
123  m_iROIWidth     = iRoiWidth;
124  m_iROIHeight    = iRoiHeight;
125 
126  UInt uiAbsZorderIdx = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
127 
[5]128#if DEPTH_MAP_GENERATION
[2]129  TComPicYuv* pcPic = ( bPrdDepthMap ? pcCU->getPic()->getPredDepthMap() : pcCU->getPic()->getPicYuvRec() );
[5]130#else
131  TComPicYuv* pcPic = pcCU->getPic()->getPicYuvRec();
132#endif
[56]133
[2]134  if ( iComp == 0 )
135  {
[21]136#if DEPTH_MAP_GENERATION
137    m_iPatternStride  = ( bPrdDepthMap ? pcCU->getPic()->getPredDepthMap()->getStride() : pcCU->getPic()->getStride() );
138#else
[2]139    m_iPatternStride  = pcCU->getPic()->getStride();
[21]140#endif
[2]141    m_piPatternOrigin = pcPic->getLumaAddr(pcCU->getAddr(), uiAbsZorderIdx) - m_iOffsetAbove * m_iPatternStride - m_iOffsetLeft;
142  }
143  else
144  {
[21]145#if DEPTH_MAP_GENERATION
146    m_iPatternStride  = ( bPrdDepthMap ? pcCU->getPic()->getPredDepthMap()->getCStride() : pcCU->getPic()->getCStride() );
147#else
[2]148    m_iPatternStride = pcCU->getPic()->getCStride();
[21]149#endif
[2]150    if ( iComp == 1 )
[56]151    {
[2]152      m_piPatternOrigin = pcPic->getCbAddr(pcCU->getAddr(), uiAbsZorderIdx) - m_iOffsetAbove * m_iPatternStride - m_iOffsetLeft;
[56]153    }
[2]154    else
[56]155    {
[2]156      m_piPatternOrigin = pcPic->getCrAddr(pcCU->getAddr(), uiAbsZorderIdx) - m_iOffsetAbove * m_iPatternStride - m_iOffsetLeft;
[56]157    }
[2]158  }
159}
160
161// ====================================================================================================================
162// Public member functions (TComPattern)
163// ====================================================================================================================
164
165Void TComPattern::initPattern ( Pel* piY,
166                               Pel* piCb,
167                               Pel* piCr,
168                               Int iRoiWidth,
169                               Int iRoiHeight,
170                               Int iStride,
171                               Int iOffsetLeft,
172                               Int iOffsetRight,
173                               Int iOffsetAbove,
174                               Int iOffsetBottom )
175{
176  m_cPatternY. setPatternParamPel( piY,  iRoiWidth,      iRoiHeight,      iStride,      iOffsetLeft,      iOffsetRight,      iOffsetAbove,      iOffsetBottom );
177  m_cPatternCb.setPatternParamPel( piCb, iRoiWidth >> 1, iRoiHeight >> 1, iStride >> 1, iOffsetLeft >> 1, iOffsetRight >> 1, iOffsetAbove >> 1, iOffsetBottom >> 1 );
178  m_cPatternCr.setPatternParamPel( piCr, iRoiWidth >> 1, iRoiHeight >> 1, iStride >> 1, iOffsetLeft >> 1, iOffsetRight >> 1, iOffsetAbove >> 1, iOffsetBottom >> 1 );
179 
180  return;
181}
182
[56]183Void TComPattern::initPattern( TComDataCU* pcCU, UInt uiPartDepth, UInt uiAbsPartIdx
[5]184#if DEPTH_MAP_GENERATION
[56]185                              , Bool bPrdDepthMap
[5]186#endif
[56]187                              )
[2]188{
189  Int   uiOffsetLeft  = 0;
190  Int   uiOffsetRight = 0;
191  Int   uiOffsetAbove = 0;
192 
193  TComPic* pcPic         = pcCU->getPic();
194  UChar uiWidth          = pcCU->getWidth (0)>>uiPartDepth;
195  UChar uiHeight         = pcCU->getHeight(0)>>uiPartDepth;
196 
197  UInt  uiAbsZorderIdx   = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
198  UInt  uiCurrPicPelX    = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsZorderIdx] ];
199  UInt  uiCurrPicPelY    = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsZorderIdx] ];
200 
201  if( uiCurrPicPelX != 0 )
[56]202  {
[2]203    uiOffsetLeft = 1;
[56]204  }
205 
[2]206  if( uiCurrPicPelY != 0 )
207  {
208    UInt uiNumPartInWidth = ( uiWidth/pcPic->getMinCUWidth() );
209    uiOffsetAbove = 1;
210   
[56]211    if( uiCurrPicPelX + uiWidth < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() )
[2]212    {
213      if( ( g_auiZscanToRaster[uiAbsZorderIdx] + uiNumPartInWidth ) % pcPic->getNumPartInWidth() ) // Not CU boundary
214      {
215        if( g_auiRasterToZscan[ (Int)g_auiZscanToRaster[uiAbsZorderIdx] - (Int)pcPic->getNumPartInWidth() + (Int)uiNumPartInWidth ] < uiAbsZorderIdx )
[56]216        {
[2]217          uiOffsetRight = 1;
[56]218        }
[2]219      }
220      else // if it is CU boundary
221      {
222        if( g_auiZscanToRaster[uiAbsZorderIdx] < pcPic->getNumPartInWidth() && (uiCurrPicPelX+uiWidth) < pcPic->getPicYuvRec()->getWidth() ) // first line
223        {
224          uiOffsetRight = 1;
225        }
226      }
227    }
228  }
229 
[5]230#if DEPTH_MAP_GENERATION
[2]231  m_cPatternY .setPatternParamCU( pcCU, 0, uiWidth,      uiHeight,      uiOffsetLeft, uiOffsetRight, uiOffsetAbove, 0, uiPartDepth, uiAbsPartIdx, bPrdDepthMap );
232  m_cPatternCb.setPatternParamCU( pcCU, 1, uiWidth >> 1, uiHeight >> 1, uiOffsetLeft, uiOffsetRight, uiOffsetAbove, 0, uiPartDepth, uiAbsPartIdx, bPrdDepthMap );
233  m_cPatternCr.setPatternParamCU( pcCU, 2, uiWidth >> 1, uiHeight >> 1, uiOffsetLeft, uiOffsetRight, uiOffsetAbove, 0, uiPartDepth, uiAbsPartIdx, bPrdDepthMap );
[5]234#else
235  m_cPatternY .setPatternParamCU( pcCU, 0, uiWidth,      uiHeight,      uiOffsetLeft, uiOffsetRight, uiOffsetAbove, 0, uiPartDepth, uiAbsPartIdx );
236  m_cPatternCb.setPatternParamCU( pcCU, 1, uiWidth >> 1, uiHeight >> 1, uiOffsetLeft, uiOffsetRight, uiOffsetAbove, 0, uiPartDepth, uiAbsPartIdx );
237  m_cPatternCr.setPatternParamCU( pcCU, 2, uiWidth >> 1, uiHeight >> 1, uiOffsetLeft, uiOffsetRight, uiOffsetAbove, 0, uiPartDepth, uiAbsPartIdx );
238#endif
[2]239}
240
[56]241  Void TComPattern::initAdiPattern( TComDataCU* pcCU, UInt uiZorderIdxInPart, UInt uiPartDepth, Int* piAdiBuf, Int iOrgBufStride, Int iOrgBufHeight, Bool& bAbove, Bool& bLeft, Bool bLMmode
[5]242#if DEPTH_MAP_GENERATION
[56]243                                  , Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY
[5]244#endif
[56]245    )
[2]246{
247  Pel*  piRoiOrigin;
248  Int*  piAdiTemp;
249  UInt  uiCuWidth   = pcCU->getWidth(0) >> uiPartDepth;
250  UInt  uiCuHeight  = pcCU->getHeight(0)>> uiPartDepth;
251  UInt  uiCuWidth2  = uiCuWidth<<1;
252  UInt  uiCuHeight2 = uiCuHeight<<1;
253  UInt  uiWidth;
254  UInt  uiHeight;
[21]255#if DEPTH_MAP_GENERATION
256  Int   iPicStride = ( bPrdDepthMap ? pcCU->getPic()->getPredDepthMap()->getStride() : pcCU->getPic()->getStride() );
257#else
[2]258  Int   iPicStride = pcCU->getPic()->getStride();
[21]259#endif
[2]260  Int   iUnitSize = 0;
261  Int   iNumUnitsInCu = 0;
262  Int   iTotalUnits = 0;
[56]263  Bool  bNeighborFlags[4 * MAX_NUM_SPU_W + 1];
[2]264  Int   iNumIntraNeighbor = 0;
265 
[56]266  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
267
[2]268 
269  pcCU->deriveLeftRightTopIdxAdi( uiPartIdxLT, uiPartIdxRT, uiZorderIdxInPart, uiPartDepth );
270  pcCU->deriveLeftBottomIdxAdi  ( uiPartIdxLB,              uiZorderIdxInPart, uiPartDepth );
271 
[56]272  iUnitSize      = g_uiMaxCUWidth >> g_uiMaxCUDepth;
273  iNumUnitsInCu  = uiCuWidth / iUnitSize;
274  iTotalUnits    = (iNumUnitsInCu << 2) + 1;
[2]275
[56]276  bNeighborFlags[iNumUnitsInCu*2] = isAboveLeftAvailable( pcCU, uiPartIdxLT );
277  iNumIntraNeighbor  += (Int)(bNeighborFlags[iNumUnitsInCu*2]);
278  iNumIntraNeighbor  += isAboveAvailable     ( pcCU, uiPartIdxLT, uiPartIdxRT, bNeighborFlags+(iNumUnitsInCu*2)+1 );
279  iNumIntraNeighbor  += isAboveRightAvailable( pcCU, uiPartIdxLT, uiPartIdxRT, bNeighborFlags+(iNumUnitsInCu*3)+1 );
280  iNumIntraNeighbor  += isLeftAvailable      ( pcCU, uiPartIdxLT, uiPartIdxLB, bNeighborFlags+(iNumUnitsInCu*2)-1 );
281  iNumIntraNeighbor  += isBelowLeftAvailable ( pcCU, uiPartIdxLT, uiPartIdxLB, bNeighborFlags+ iNumUnitsInCu   -1 );
[2]282 
283  bAbove = true;
284  bLeft  = true;
285
[21]286#if DEPTH_MAP_GENERATION
287  if ( bPrdDepthMap )
288  {
289    uiWidth  = ( uiCuWidth2  >> uiSubSampExpX ) + 1;
290    uiHeight = ( uiCuHeight2 >> uiSubSampExpY ) + 1;
291  }
292  else
293  {
[56]294    uiWidth=uiCuWidth2+1;
295    uiHeight=uiCuHeight2+1;
[21]296  }
297#else
298  uiWidth=uiCuWidth2+1;
299  uiHeight=uiCuHeight2+1;
300#endif
[2]301 
302  if (((uiWidth<<2)>iOrgBufStride)||((uiHeight<<2)>iOrgBufHeight))
[56]303  {
[2]304    return;
[56]305  }
[2]306 
307  piRoiOrigin = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiZorderIdxInPart);
308  piAdiTemp   = piAdiBuf;
309
[5]310#if DEPTH_MAP_GENERATION
[2]311  if( bPrdDepthMap )
312  {
313    piRoiOrigin = pcCU->getPic()->getPredDepthMap()->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiZorderIdxInPart );
314  }
[5]315#endif
[2]316
[5]317#if DEPTH_MAP_GENERATION
[21]318  if ( bPrdDepthMap )
[56]319    fillReferenceSamples ( pcCU, piRoiOrigin, piAdiTemp, bNeighborFlags, iNumIntraNeighbor, iUnitSize >> uiSubSampExpX, iNumUnitsInCu, iTotalUnits, uiCuWidth >> uiSubSampExpX, uiCuHeight >> uiSubSampExpY, uiWidth, uiHeight, iPicStride, bLMmode, bPrdDepthMap );
[21]320  else
[56]321    fillReferenceSamples ( pcCU, piRoiOrigin, piAdiTemp, bNeighborFlags, iNumIntraNeighbor, iUnitSize, iNumUnitsInCu, iTotalUnits, uiCuWidth, uiCuHeight, uiWidth, uiHeight, iPicStride, bLMmode, bPrdDepthMap );
[5]322#else
[56]323  fillReferenceSamples ( pcCU, piRoiOrigin, piAdiTemp, bNeighborFlags, iNumIntraNeighbor, iUnitSize, iNumUnitsInCu, iTotalUnits, uiCuWidth, uiCuHeight, uiWidth, uiHeight, iPicStride, bLMmode);
[5]324#endif
[2]325
326 
[56]327  Int   i;
[2]328  // generate filtered intra prediction samples
329  Int iBufSize = uiCuHeight2 + uiCuWidth2 + 1;  // left and left above border + above and above right border + top left corner = length of 3. filter buffer
330
331  UInt uiWH = uiWidth * uiHeight;               // number of elements in one buffer
332
333  Int* piFilteredBuf1 = piAdiBuf + uiWH;        // 1. filter buffer
334  Int* piFilteredBuf2 = piFilteredBuf1 + uiWH;  // 2. filter buffer
335  Int* piFilterBuf = piFilteredBuf2 + uiWH;     // buffer for 2. filtering (sequential)
336  Int* piFilterBufN = piFilterBuf + iBufSize;   // buffer for 1. filtering (sequential)
337
338  Int l = 0;
339  // left border from bottom to top
340  for (i = 0; i < uiCuHeight2; i++)
[56]341  {
[2]342    piFilterBuf[l++] = piAdiTemp[uiWidth * (uiCuHeight2 - i)];
[56]343  }
[2]344  // top left corner
345  piFilterBuf[l++] = piAdiTemp[0];
346  // above border from left to right
347  for (i=0; i < uiCuWidth2; i++)
[56]348  {
[2]349    piFilterBuf[l++] = piAdiTemp[1 + i];
[56]350  }
[2]351
352  // 1. filtering with [1 2 1]
353  piFilterBufN[0] = piFilterBuf[0];
354  piFilterBufN[iBufSize - 1] = piFilterBuf[iBufSize - 1];
355  for (i = 1; i < iBufSize - 1; i++)
[56]356  {
[2]357    piFilterBufN[i] = (piFilterBuf[i - 1] + 2 * piFilterBuf[i]+piFilterBuf[i + 1] + 2) >> 2;
[56]358  }
[2]359
360  // fill 1. filter buffer with filtered values
361  l=0;
362  for (i = 0; i < uiCuHeight2; i++)
[56]363  {
[2]364    piFilteredBuf1[uiWidth * (uiCuHeight2 - i)] = piFilterBufN[l++];
[56]365  }
[2]366  piFilteredBuf1[0] = piFilterBufN[l++];
367  for (i = 0; i < uiCuWidth2; i++)
[56]368  {
[2]369    piFilteredBuf1[1 + i] = piFilterBufN[l++];
[56]370  }
[2]371}
372
373Void TComPattern::initAdiPatternChroma( TComDataCU* pcCU, UInt uiZorderIdxInPart, UInt uiPartDepth, Int* piAdiBuf, Int iOrgBufStride, Int iOrgBufHeight, Bool& bAbove, Bool& bLeft )
374{
375  Pel*  piRoiOrigin;
376  Int*  piAdiTemp;
377  UInt  uiCuWidth  = pcCU->getWidth (0) >> uiPartDepth;
378  UInt  uiCuHeight = pcCU->getHeight(0) >> uiPartDepth;
379  UInt  uiWidth;
380  UInt  uiHeight;
381  Int   iPicStride = pcCU->getPic()->getCStride();
[56]382
[2]383  Int   iUnitSize = 0;
384  Int   iNumUnitsInCu = 0;
385  Int   iTotalUnits = 0;
[56]386  Bool  bNeighborFlags[4 * MAX_NUM_SPU_W + 1];
[2]387  Int   iNumIntraNeighbor = 0;
388 
[56]389  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
[2]390 
391  pcCU->deriveLeftRightTopIdxAdi( uiPartIdxLT, uiPartIdxRT, uiZorderIdxInPart, uiPartDepth );
392  pcCU->deriveLeftBottomIdxAdi  ( uiPartIdxLB,              uiZorderIdxInPart, uiPartDepth );
393 
[56]394  iUnitSize      = (g_uiMaxCUWidth >> g_uiMaxCUDepth) >> 1; // for chroma
395  iNumUnitsInCu  = (uiCuWidth / iUnitSize) >> 1;            // for chroma
396  iTotalUnits    = (iNumUnitsInCu << 2) + 1;
[2]397
[56]398  bNeighborFlags[iNumUnitsInCu*2] = isAboveLeftAvailable( pcCU, uiPartIdxLT );
399  iNumIntraNeighbor  += (Int)(bNeighborFlags[iNumUnitsInCu*2]);
400  iNumIntraNeighbor  += isAboveAvailable     ( pcCU, uiPartIdxLT, uiPartIdxRT, bNeighborFlags+(iNumUnitsInCu*2)+1 );
401  iNumIntraNeighbor  += isAboveRightAvailable( pcCU, uiPartIdxLT, uiPartIdxRT, bNeighborFlags+(iNumUnitsInCu*3)+1 );
402  iNumIntraNeighbor  += isLeftAvailable      ( pcCU, uiPartIdxLT, uiPartIdxLB, bNeighborFlags+(iNumUnitsInCu*2)-1 );
403  iNumIntraNeighbor  += isBelowLeftAvailable ( pcCU, uiPartIdxLT, uiPartIdxLB, bNeighborFlags+ iNumUnitsInCu   -1 );
[2]404 
405  bAbove = true;
406  bLeft  = true;
407 
408  uiCuWidth=uiCuWidth>>1;  // for chroma
409  uiCuHeight=uiCuHeight>>1;  // for chroma
410 
411  uiWidth=uiCuWidth*2+1;
412  uiHeight=uiCuHeight*2+1;
413 
414  if ((4*uiWidth>iOrgBufStride)||(4*uiHeight>iOrgBufHeight))
[56]415  {
[2]416    return;
[56]417  }
[2]418 
419  // get Cb pattern
420  piRoiOrigin = pcCU->getPic()->getPicYuvRec()->getCbAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiZorderIdxInPart);
421  piAdiTemp   = piAdiBuf;
422
[5]423#if DEPTH_MAP_GENERATION
[56]424  fillReferenceSamples ( pcCU, piRoiOrigin, piAdiTemp, bNeighborFlags, iNumIntraNeighbor, iUnitSize, iNumUnitsInCu, iTotalUnits, uiCuWidth, uiCuHeight, uiWidth, uiHeight, iPicStride, false, false );
[5]425#else
[56]426  fillReferenceSamples ( pcCU, piRoiOrigin, piAdiTemp, bNeighborFlags, iNumIntraNeighbor, iUnitSize, iNumUnitsInCu, iTotalUnits, uiCuWidth, uiCuHeight, uiWidth, uiHeight, iPicStride);
[5]427#endif
[2]428 
429  // get Cr pattern
430  piRoiOrigin = pcCU->getPic()->getPicYuvRec()->getCrAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiZorderIdxInPart);
431  piAdiTemp   = piAdiBuf+uiWidth*uiHeight;
432 
[5]433#if DEPTH_MAP_GENERATION
[56]434  fillReferenceSamples ( pcCU, piRoiOrigin, piAdiTemp, bNeighborFlags, iNumIntraNeighbor, iUnitSize, iNumUnitsInCu, iTotalUnits, uiCuWidth, uiCuHeight, uiWidth, uiHeight, iPicStride, false, false );
[5]435#else
[56]436  fillReferenceSamples ( pcCU, piRoiOrigin, piAdiTemp, bNeighborFlags, iNumIntraNeighbor, iUnitSize, iNumUnitsInCu, iTotalUnits, uiCuWidth, uiCuHeight, uiWidth, uiHeight, iPicStride);
[5]437#endif
[2]438
439}
440
[56]441Void TComPattern::fillReferenceSamples( TComDataCU* pcCU, Pel* piRoiOrigin, Int* piAdiTemp, Bool* bNeighborFlags, Int iNumIntraNeighbor, Int iUnitSize, Int iNumUnitsInCu, Int iTotalUnits, UInt uiCuWidth, UInt uiCuHeight, UInt uiWidth, UInt uiHeight, Int iPicStride, Bool bLMmode
[5]442#if DEPTH_MAP_GENERATION
[56]443                                       , Bool bPrdDepthMap
[5]444#endif
[56]445                                       )
[2]446{
447  Pel* piRoiTemp;
448  Int  i, j;
[5]449#if DEPTH_MAP_GENERATION
[2]450  Int  iDCValue = ( bPrdDepthMap ? PDM_UNDEFINED_DEPTH : ( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) ) );
[5]451#else
452  Int  iDCValue = ( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) );
453#endif
[56]454
[2]455  if (iNumIntraNeighbor == 0)
456  {
457    // Fill border with DC value
458    for (i=0; i<uiWidth; i++)
[56]459    {
[2]460      piAdiTemp[i] = iDCValue;
[56]461    }
[2]462    for (i=1; i<uiHeight; i++)
[56]463    {
[2]464      piAdiTemp[i*uiWidth] = iDCValue;
[56]465    }
[2]466  }
467  else if (iNumIntraNeighbor == iTotalUnits)
468  {
469    // Fill top-left border with rec. samples
470    piRoiTemp = piRoiOrigin - iPicStride - 1;
471    piAdiTemp[0] = piRoiTemp[0];
472
473    // Fill left border with rec. samples
474    piRoiTemp = piRoiOrigin - 1;
[56]475
476    if (bLMmode)
477    {
478      piRoiTemp --; // move to the second left column
479    }
480
[2]481    for (i=0; i<uiCuHeight; i++)
482    {
483      piAdiTemp[(1+i)*uiWidth] = piRoiTemp[0];
484      piRoiTemp += iPicStride;
485    }
486
487    // Fill below left border with rec. samples
488    for (i=0; i<uiCuHeight; i++)
489    {
490      piAdiTemp[(1+uiCuHeight+i)*uiWidth] = piRoiTemp[0];
491      piRoiTemp += iPicStride;
492    }
493
494    // Fill top border with rec. samples
495    piRoiTemp = piRoiOrigin - iPicStride;
496    for (i=0; i<uiCuWidth; i++)
[56]497    {
[2]498      piAdiTemp[1+i] = piRoiTemp[i];
[56]499    }
500   
[2]501    // Fill top right border with rec. samples
502    piRoiTemp = piRoiOrigin - iPicStride + uiCuWidth;
503    for (i=0; i<uiCuWidth; i++)
[56]504    {
[2]505      piAdiTemp[1+uiCuWidth+i] = piRoiTemp[i];
[56]506    }
[2]507  }
508  else // reference samples are partially available
509  {
510    Int  iNumUnits2 = iNumUnitsInCu<<1;
511    Int  iTotalSamples = iTotalUnits*iUnitSize;
[56]512    Pel  piAdiLine[5 * MAX_CU_SIZE];
[2]513    Pel  *piAdiLineTemp; 
514    Bool *pbNeighborFlags;
[56]515    Int  iNext, iCurr;
[2]516    Pel  piRef = 0;
517
518    // Initialize
519    for (i=0; i<iTotalSamples; i++)
[56]520    {
[2]521      piAdiLine[i] = iDCValue;
[56]522    }
523   
[2]524    // Fill top-left sample
525    piRoiTemp = piRoiOrigin - iPicStride - 1;
526    piAdiLineTemp = piAdiLine + (iNumUnits2*iUnitSize);
527    pbNeighborFlags = bNeighborFlags + iNumUnits2;
528    if (*pbNeighborFlags)
529    {
530      piAdiLineTemp[0] = piRoiTemp[0];
531      for (i=1; i<iUnitSize; i++)
[56]532      {
[2]533        piAdiLineTemp[i] = piAdiLineTemp[0];
[56]534      }
[2]535    }
536
537    // Fill left & below-left samples
538    piRoiTemp += iPicStride;
[56]539    if (bLMmode)
540    {
541      piRoiTemp --; // move the second left column
542    }
[2]543    piAdiLineTemp--;
544    pbNeighborFlags--;
545    for (j=0; j<iNumUnits2; j++)
546    {
547      if (*pbNeighborFlags)
548      {
549        for (i=0; i<iUnitSize; i++)
[56]550        {
[2]551          piAdiLineTemp[-i] = piRoiTemp[i*iPicStride];
[56]552        }
[2]553      }
554      piRoiTemp += iUnitSize*iPicStride;
555      piAdiLineTemp -= iUnitSize;
556      pbNeighborFlags--;
557    }
558
559    // Fill above & above-right samples
560    piRoiTemp = piRoiOrigin - iPicStride;
561    piAdiLineTemp = piAdiLine + ((iNumUnits2+1)*iUnitSize);
562    pbNeighborFlags = bNeighborFlags + iNumUnits2 + 1;
563    for (j=0; j<iNumUnits2; j++)
564    {
565      if (*pbNeighborFlags)
566      {
567        for (i=0; i<iUnitSize; i++)
[56]568        {
[2]569          piAdiLineTemp[i] = piRoiTemp[i];
[56]570        }
[2]571      }
572      piRoiTemp += iUnitSize;
573      piAdiLineTemp += iUnitSize;
574      pbNeighborFlags++;
575    }
576
577    // Pad reference samples when necessary
578    iCurr = 0;
579    iNext = 1;
580    piAdiLineTemp = piAdiLine;
581    while (iCurr < iTotalUnits)
582    {
[56]583      if (!bNeighborFlags[iCurr])
[2]584      {
[56]585        if(iCurr == 0)
586        {
587          while (iNext < iTotalUnits && !bNeighborFlags[iNext])
588          {
589            iNext++;
590          }
[2]591          piRef = piAdiLine[iNext*iUnitSize];
[56]592          // Pad unavailable samples with new value
593          while (iCurr < iNext)
594          {
595            for (i=0; i<iUnitSize; i++)
596            {
597              piAdiLineTemp[i] = piRef;
598            }
599            piAdiLineTemp += iUnitSize;
600            iCurr++;
601          }
602        }
[2]603        else
604        {
[56]605          piRef = piAdiLine[iCurr*iUnitSize-1];
[2]606          for (i=0; i<iUnitSize; i++)
[56]607          {
[2]608            piAdiLineTemp[i] = piRef;
[56]609          }
[2]610          piAdiLineTemp += iUnitSize;
611          iCurr++;
612        }
613      }
[56]614      else
615      {
616        piAdiLineTemp += iUnitSize;
617        iCurr++;
618      }
[2]619    }
620
621    // Copy processed samples
622    piAdiLineTemp = piAdiLine + uiHeight + iUnitSize - 2;
623    for (i=0; i<uiWidth; i++)
[56]624    {
[2]625      piAdiTemp[i] = piAdiLineTemp[i];
[56]626    }
[2]627    piAdiLineTemp = piAdiLine + uiHeight - 1;
628    for (i=1; i<uiHeight; i++)
[56]629    {
[2]630      piAdiTemp[i*uiWidth] = piAdiLineTemp[-i];
[56]631    }
[2]632  }
633}
634
635Int* TComPattern::getAdiOrgBuf( Int iCuWidth, Int iCuHeight, Int* piAdiBuf)
636{
637  return piAdiBuf;
638}
639
640Int* TComPattern::getAdiCbBuf( Int iCuWidth, Int iCuHeight, Int* piAdiBuf)
641{
642  return piAdiBuf;
643}
644
645Int* TComPattern::getAdiCrBuf(Int iCuWidth,Int iCuHeight, Int* piAdiBuf)
646{
647  return piAdiBuf+(iCuWidth*2+1)*(iCuHeight*2+1);
648}
649
[56]650/** Get pointer to reference samples for intra prediction
651 * \param uiDirMode   prediction mode index
652 * \param log2BlkSize size of block (2 = 4x4, 3 = 8x8, 4 = 16x16, 5 = 32x32, 6 = 64x64)
653 * \param piAdiBuf    pointer to unfiltered reference samples
654 * \return            pointer to (possibly filtered) reference samples
655 *
656 * The prediction mode index is used to determine whether a smoothed reference sample buffer is returned.
657 */
658Int* TComPattern::getPredictorPtr( UInt uiDirMode, UInt log2BlkSize, Int* piAdiBuf )
[2]659{
660  Int* piSrc;
[189]661#if LGE_EDGE_INTRA_A0070
[100]662  mapEdgeIntratoDC( uiDirMode );
663#endif
[56]664  assert(log2BlkSize >= 2 && log2BlkSize < 7);
665#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
666  mapDMMtoIntraMode( uiDirMode );
[2]667#endif
[56]668  Int diff = min<Int>(abs((Int) uiDirMode - HOR_IDX), abs((Int)uiDirMode - VER_IDX));
669  UChar ucFiltIdx = diff > m_aucIntraFilter[log2BlkSize - 2] ? 1 : 0;
670  if (uiDirMode == DC_IDX || uiDirMode == LM_CHROMA_IDX)
[2]671  {
[56]672    ucFiltIdx = 0; //no smoothing for DC or LM chroma
[2]673  }
674
675  assert( ucFiltIdx <= 1 );
676
[56]677  Int width  = 1 << log2BlkSize;
678  Int height = 1 << log2BlkSize;
679 
680  piSrc = getAdiOrgBuf( width, height, piAdiBuf );
[2]681
682  if ( ucFiltIdx )
683  {
[56]684    piSrc += (2 * width + 1) * (2 * height + 1);
[2]685  }
686
687  return piSrc;
688}
689
[56]690Bool TComPattern::isAboveLeftAvailable( TComDataCU* pcCU, UInt uiPartIdxLT )
[2]691{
692  Bool bAboveLeftFlag;
693  UInt uiPartAboveLeft;
694  TComDataCU* pcCUAboveLeft = pcCU->getPUAboveLeft( uiPartAboveLeft, uiPartIdxLT, true, false );
[56]695  if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred())
696  {
697    bAboveLeftFlag = ( pcCUAboveLeft && pcCUAboveLeft->getPredictionMode( uiPartAboveLeft ) == MODE_INTRA );
698  }
699  else
700  {
701    bAboveLeftFlag = (pcCUAboveLeft ? true : false);
702  }
[2]703  return bAboveLeftFlag;
704}
705
[56]706Int TComPattern::isAboveAvailable( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxRT, Bool *bValidFlags )
[2]707{
708  const UInt uiRasterPartBegin = g_auiZscanToRaster[uiPartIdxLT];
709  const UInt uiRasterPartEnd = g_auiZscanToRaster[uiPartIdxRT]+1;
710  const UInt uiIdxStep = 1;
711  Bool *pbValidFlags = bValidFlags;
712  Int iNumIntra = 0;
713
714  for ( UInt uiRasterPart = uiRasterPartBegin; uiRasterPart < uiRasterPartEnd; uiRasterPart += uiIdxStep )
715  {
716    UInt uiPartAbove;
717    TComDataCU* pcCUAbove = pcCU->getPUAbove( uiPartAbove, g_auiRasterToZscan[uiRasterPart], true, false );
[56]718    if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred())
[2]719    {
[56]720      if ( pcCUAbove && pcCUAbove->getPredictionMode( uiPartAbove ) == MODE_INTRA )
721      {
722        iNumIntra++;
723        *pbValidFlags = true;
724      }
725      else
726      {
727        *pbValidFlags = false;
728      }
[2]729    }
730    else
731    {
[56]732      if (pcCUAbove)
733      {
734        iNumIntra++;
735        *pbValidFlags = true;
736      }
737      else
738      {
739        *pbValidFlags = false;
740      }
[2]741    }
742    pbValidFlags++;
743  }
744  return iNumIntra;
745}
746
[56]747Int TComPattern::isLeftAvailable( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxLB, Bool *bValidFlags )
[2]748{
749  const UInt uiRasterPartBegin = g_auiZscanToRaster[uiPartIdxLT];
750  const UInt uiRasterPartEnd = g_auiZscanToRaster[uiPartIdxLB]+1;
751  const UInt uiIdxStep = pcCU->getPic()->getNumPartInWidth();
752  Bool *pbValidFlags = bValidFlags;
753  Int iNumIntra = 0;
754
755  for ( UInt uiRasterPart = uiRasterPartBegin; uiRasterPart < uiRasterPartEnd; uiRasterPart += uiIdxStep )
756  {
757    UInt uiPartLeft;
758    TComDataCU* pcCULeft = pcCU->getPULeft( uiPartLeft, g_auiRasterToZscan[uiRasterPart], true, false );
[56]759    if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred())
[2]760    {
[56]761      if ( pcCULeft && pcCULeft->getPredictionMode( uiPartLeft ) == MODE_INTRA )
762      {
763        iNumIntra++;
764        *pbValidFlags = true;
765      }
766      else
767      {
768        *pbValidFlags = false;
769      }
[2]770    }
771    else
772    {
[56]773      if ( pcCULeft )
774      {
775        iNumIntra++;
776        *pbValidFlags = true;
777      }
778      else
779      {
780        *pbValidFlags = false;
781      }
[2]782    }
783    pbValidFlags--; // opposite direction
784  }
785
786  return iNumIntra;
787}
788
[56]789Int TComPattern::isAboveRightAvailable( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxRT, Bool *bValidFlags )
[2]790{
791  const UInt uiNumUnitsInPU = g_auiZscanToRaster[uiPartIdxRT] - g_auiZscanToRaster[uiPartIdxLT] + 1;
792  const UInt uiPuWidth = uiNumUnitsInPU * pcCU->getPic()->getMinCUWidth();
793  Bool *pbValidFlags = bValidFlags;
794  Int iNumIntra = 0;
795
796  for ( UInt uiOffset = 1; uiOffset <= uiNumUnitsInPU; uiOffset++ )
797  {
798    UInt uiPartAboveRight;
799    TComDataCU* pcCUAboveRight = pcCU->getPUAboveRightAdi( uiPartAboveRight, uiPuWidth, uiPartIdxRT, uiOffset, true, false );
[56]800    if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred())
[2]801    {
[56]802      if ( pcCUAboveRight && pcCUAboveRight->getPredictionMode( uiPartAboveRight ) == MODE_INTRA )
803      {
804        iNumIntra++;
805        *pbValidFlags = true;
806      }
807      else
808      {
809        *pbValidFlags = false;
810      }
[2]811    }
812    else
813    {
[56]814      if ( pcCUAboveRight )
815      {
816        iNumIntra++;
817        *pbValidFlags = true;
818      }
819      else
820      {
821        *pbValidFlags = false;
822      }
[2]823    }
824    pbValidFlags++;
825  }
826
827  return iNumIntra;
828}
829
[56]830Int TComPattern::isBelowLeftAvailable( TComDataCU* pcCU, UInt uiPartIdxLT, UInt uiPartIdxLB, Bool *bValidFlags )
[2]831{
832  const UInt uiNumUnitsInPU = (g_auiZscanToRaster[uiPartIdxLB] - g_auiZscanToRaster[uiPartIdxLT]) / pcCU->getPic()->getNumPartInWidth() + 1;
833  const UInt uiPuHeight = uiNumUnitsInPU * pcCU->getPic()->getMinCUHeight();
834  Bool *pbValidFlags = bValidFlags;
835  Int iNumIntra = 0;
836
837  for ( UInt uiOffset = 1; uiOffset <= uiNumUnitsInPU; uiOffset++ )
838  {
839    UInt uiPartBelowLeft;
840    TComDataCU* pcCUBelowLeft = pcCU->getPUBelowLeftAdi( uiPartBelowLeft, uiPuHeight, uiPartIdxLB, uiOffset, true, false );
[56]841    if(pcCU->getSlice()->getPPS()->getConstrainedIntraPred())
[2]842    {
[56]843      if ( pcCUBelowLeft && pcCUBelowLeft->getPredictionMode( uiPartBelowLeft ) == MODE_INTRA )
844      {
845        iNumIntra++;
846        *pbValidFlags = true;
847      }
848      else
849      {
850        *pbValidFlags = false;
851      }
[2]852    }
853    else
854    {
[56]855      if ( pcCUBelowLeft )
856      {
857        iNumIntra++;
858        *pbValidFlags = true;
859      }
860      else
861      {
862        *pbValidFlags = false;
863      }
[2]864    }
865    pbValidFlags--; // opposite direction
866  }
867
868  return iNumIntra;
869}
[56]870//! \}
Note: See TracBrowser for help on using the repository browser.