source: 3DVCSoftware/branches/HTM-6.2-dev2-Qualcomm/source/Lib/TLibCommon/TComResidualGenerator.cpp @ 351

Last change on this file since 351 was 351, checked in by qualcomm, 12 years ago

JCT3V-D0181

  • Property svn:eol-style set to native
File size: 25.3 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-2011, 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 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
35
36/** \file     TComResidualGenerator.cpp
37    \brief    residual picture generator class
38*/
39
40
41
42#include "CommonDef.h"
43#include "TComResidualGenerator.h"
44
45
46#if H3D_IVRP
47
48
49TComResidualGenerator::TComResidualGenerator()
50{
51  m_bCreated            = false;
52  m_bInit               = false;
53  m_bDecoder            = false;
54  m_pcTrQuant           = 0;
55  m_pcDepthMapGenerator = 0;
56  m_pcSPSAccess         = 0;
57  m_pcAUPicAccess       = 0;
58  m_uiMaxDepth          = 0;
59  m_uiOrgDepthBitDepth  = 0;
60  m_ppcYuvTmp           = 0;
61  m_ppcYuv              = 0;
62  m_ppcCU               = 0;
63}
64
65TComResidualGenerator::~TComResidualGenerator()
66{
67  destroy ();
68  uninit  ();
69}
70
71Void
72TComResidualGenerator::create( Bool bDecoder, UInt uiPicWidth, UInt uiPicHeight, UInt uiMaxCUDepth, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiOrgBitDepth )
73{
74  destroy();
75  m_bDecoder            = bDecoder;
76  m_uiMaxDepth          = uiMaxCUDepth;
77  m_uiOrgDepthBitDepth  = uiOrgBitDepth;
78  m_ppcYuvTmp           = new TComYuv*    [ NUM_TMP_YUV_BUFFERS ];
79  m_ppcYuv              = new TComYuv*    [ m_uiMaxDepth ];
80  m_ppcCU               = new TComDataCU* [ m_uiMaxDepth ];
81  for( UInt uiIdx = 0; uiIdx < NUM_TMP_YUV_BUFFERS; uiIdx++ )
82  {
83    m_ppcYuvTmp[uiIdx]  = new TComYuv;    m_ppcYuvTmp[uiIdx]->create( uiMaxCUWidth, uiMaxCUHeight );
84  }
85  for( UInt uiDepth = 0; uiDepth < m_uiMaxDepth; uiDepth++ )
86  {
87    UInt  uiNumPart = 1 << ( ( m_uiMaxDepth - uiDepth ) << 1 );
88    UInt  uiWidth   = uiMaxCUWidth  >> uiDepth;
89    UInt  uiHeight  = uiMaxCUHeight >> uiDepth;
90
91    m_ppcYuv[ uiDepth ] = new TComYuv;    m_ppcYuv[ uiDepth ]->create(            uiWidth, uiHeight                                           );
92    m_ppcCU [ uiDepth ] = new TComDataCU; m_ppcCU [ uiDepth ]->create( uiNumPart, uiWidth, uiHeight, true, uiMaxCUWidth >> (uiMaxCUDepth - 1) );
93  }
94  m_cTmpPic.create( uiPicWidth, uiPicHeight, uiMaxCUWidth, uiMaxCUHeight, uiMaxCUDepth );
95  m_bCreated            = true;
96}
97
98Void
99TComResidualGenerator::destroy()
100{
101  if( m_bCreated )
102  {
103    m_bCreated            = false;
104    for( UInt uiIdx = 0; uiIdx < NUM_TMP_YUV_BUFFERS; uiIdx++ )
105    {
106      m_ppcYuvTmp[uiIdx]->destroy();  delete m_ppcYuvTmp[uiIdx]; m_ppcYuvTmp[uiIdx] = 0;
107    }
108    for( UInt uiDepth = 0; uiDepth < m_uiMaxDepth; uiDepth++ )
109    {
110      m_ppcYuv[ uiDepth ]->destroy(); delete m_ppcYuv[ uiDepth ]; m_ppcYuv[ uiDepth ] = 0;
111      m_ppcCU [ uiDepth ]->destroy(); delete m_ppcCU [ uiDepth ]; m_ppcCU [ uiDepth ] = 0;
112    }
113    delete [] m_ppcYuvTmp;  m_ppcYuvTmp = 0;
114    delete [] m_ppcYuv;     m_ppcYuv = 0;
115    delete [] m_ppcCU;      m_ppcCU  = 0;
116    m_cTmpPic.destroy();
117    m_uiMaxDepth          = 0;
118    m_uiOrgDepthBitDepth  = 0;
119    m_bDecoder            = false;
120  }
121}
122
123Void
124TComResidualGenerator::init( TComTrQuant* pcTrQuant, TComDepthMapGenerator* pcDepthMapGenerator )
125{
126  AOF( pcTrQuant           );
127  AOF( pcDepthMapGenerator );
128  AOF( pcDepthMapGenerator->getSPSAccess  () );
129  AOF( pcDepthMapGenerator->getAUPicAccess() );
130  uninit();
131  m_pcTrQuant           = pcTrQuant;
132  m_pcDepthMapGenerator = pcDepthMapGenerator;
133  m_pcSPSAccess         = pcDepthMapGenerator->getSPSAccess  ();
134  m_pcAUPicAccess       = pcDepthMapGenerator->getAUPicAccess();
135  m_bInit               = true;
136}
137
138Void
139TComResidualGenerator::uninit()
140{
141  if( m_bInit )
142  {
143    m_bInit               = false;
144    m_pcTrQuant           = 0;
145    m_pcDepthMapGenerator = 0;
146    m_pcSPSAccess         = 0;
147    m_pcAUPicAccess       = 0;
148  }
149}
150
151
152
153Void 
154TComResidualGenerator::initViewComponent( TComPic* pcPic )
155{
156  AOF  ( m_bCreated && m_bInit );
157  AOF  ( pcPic );
158
159  // set pointer in SPS
160  pcPic->getSPS()->setResidualGenerator( this );
161  ROFVS( pcPic->getSPS()->getMultiviewResPredMode() );
162
163#if OUTPUT_RESIDUAL_PICTURES
164  // dump reconstructed residual picture for first AU
165  if( pcPic->getPOC() == 0 )
166  {
167    AOF( pcPic->getSPS()->getViewId() );
168    UInt       uiBaseViewId = pcPic->getSPS()->getViewId() - 1;
169    TComPic*   pcBasePic    = m_pcAUPicAccess->getPic( uiBaseViewId );
170    AOF( pcBasePic );
171    Char       acFilenameBase[1024];
172    ::sprintf( acFilenameBase,  "RecResidual_%s", ( m_bDecoder ? "Dec" : "Enc" ) );
173    xDumpResidual( pcBasePic, acFilenameBase );
174  }
175#endif
176}
177
178
179
180Void
181TComResidualGenerator::setRecResidualPic( TComPic* pcPic )
182{
183  AOF  ( m_bCreated && m_bInit );
184  AOF  ( pcPic );
185
186#if H3D_IVRP
187  if (pcPic->getSPS()->getViewId() != 0)
188  {
189    return;
190  }
191#endif
192
193  if( pcPic->getPOC() == 0 )
194  {
195    if( pcPic->getSPS()->getViewId() == 0 || m_pcSPSAccess->getResPrd() != 0 )
196    {
197      // set residual picture
198      AOT( pcPic->getResidual() );
199      if( !pcPic->getResidual() )
200      {
201        pcPic->addResidualBuffer();
202      }
203      xSetRecResidualPic( pcPic );
204    }
205  }
206  else
207  {
208    if( m_pcSPSAccess->getResPrd() != 0 && pcPic->getSPS()->getViewId() < m_pcAUPicAccess->getMaxVId() )
209    {
210      // set residual picture
211      AOT( pcPic->getResidual() );
212      if( !pcPic->getResidual() )
213      {
214        pcPic->addResidualBuffer();
215      }
216      xSetRecResidualPic( pcPic );
217
218#if OUTPUT_RESIDUAL_PICTURES
219      // dump reconstructed residual picture
220      Char acFilenameBase[1024];
221      ::sprintf( acFilenameBase,  "RecResidual_%s", ( m_bDecoder ? "Dec" : "Enc" ) );
222      xDumpResidual( pcPic, acFilenameBase );
223#endif
224    }
225  }
226}
227
228#if H3D_NBDV
229Bool
230TComResidualGenerator::getResidualSamples( TComDataCU* pcCU, UInt uiPUIdx, TComYuv* pcYuv, TComMv iDisp, Bool bRecon  ) 
231#else
232Bool
233TComResidualGenerator::getResidualSamples( TComDataCU* pcCU, UInt uiPUIdx, TComYuv* pcYuv, Bool bRecon ) 
234#endif //H3D_NBDV
235{
236  AOF(  pcCU );
237  UInt  uiPartAddr;
238  Int   iBlkWidth, iBlkHeight, iXPos, iYPos;
239  AOT(  uiPUIdx );
240  uiPartAddr  = 0;
241  iBlkWidth   = pcCU->getWidth  ( 0 );
242  iBlkHeight  = pcCU->getHeight ( 0 );
243  pcCU->getPic()->getPicYuvRec()->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iXPos, iYPos );
244#if H3D_NBDV
245  return getResidualSamples( pcCU->getPic(), (UInt)iXPos, (UInt)iYPos, (UInt)iBlkWidth, (UInt)iBlkHeight, pcYuv, iDisp, bRecon); 
246#else
247  return getResidualSamples( pcCU->getPic(), (UInt)iXPos, (UInt)iYPos, (UInt)iBlkWidth, (UInt)iBlkHeight, pcYuv, bRecon); 
248#endif // H3D_NBDV
249}
250 
251#if H3D_NBDV
252Bool
253TComResidualGenerator::getResidualSamples( TComPic* pcPic, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv, TComMv iDisp, Bool bRecon) 
254#else
255Bool
256TComResidualGenerator::getResidualSamples( TComPic* pcPic, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv, Bool bRecon) 
257#endif
258{
259  UInt  uiBaseViewId  = 0;
260  if( !pcYuv )
261  {
262    pcYuv = m_ppcYuvTmp[1];
263  }
264  UInt uiXPosInRefView = uiXPos , uiYPosInRefView = uiYPos;
265#if H3D_NBDV
266  xSetPredResidualBlock( pcPic, uiBaseViewId, uiXPos, uiYPos, uiBlkWidth, uiBlkHeight, pcYuv, iDisp, &uiXPosInRefView , &uiYPosInRefView , bRecon  );
267#else
268  xSetPredResidualBlock( pcPic, uiBaseViewId, uiXPos, uiYPos, uiBlkWidth, uiBlkHeight, pcYuv, &uiXPosInRefView , &uiYPosInRefView , bRecon    );
269#endif
270  return true;
271}
272
273Bool TComResidualGenerator::xIsNonZeroByCBF( UInt uiBaseViewId , UInt uiXPos , UInt uiYPos, UInt uiBlkWidth , UInt uiBlkHeight )
274{
275  TComPic* pcBasePic   = m_pcAUPicAccess->getPic( uiBaseViewId );
276  const Int nMaxPicX = pcBasePic->getSPS()->getPicWidthInLumaSamples() - 1;
277  const Int nMaxPicY = pcBasePic->getSPS()->getPicHeightInLumaSamples() - 1;
278  for( UInt y = 0 ; y < uiBlkHeight ; y +=4 )
279  {
280    for( UInt x = 0 ; x <= uiBlkWidth ; x += 4 )
281    {      // to cover both the mapped CU and the 1-pixel-right-shifted mapped CU
282      Int iCuAddr = 0, iAbsZorderIdx = 0;
283      pcBasePic->getPicYuvRec()->getCUAddrAndPartIdx( Min( uiXPos + x , nMaxPicX ) , Min( uiYPos + y , nMaxPicY ) , iCuAddr , iAbsZorderIdx );
284      TComDataCU *pCUInRefView = pcBasePic->getCU( iCuAddr );
285      if( pCUInRefView->isIntra( iAbsZorderIdx ) )
286        // no inter-view residual pred from a intra CU
287        continue;
288      UInt uiTempTrDepth = pCUInRefView->getTransformIdx( iAbsZorderIdx );
289      if( pCUInRefView->getCbf( iAbsZorderIdx , TEXT_LUMA , uiTempTrDepth )
290        || pCUInRefView->getCbf( iAbsZorderIdx , TEXT_CHROMA_U , uiTempTrDepth )
291        || pCUInRefView->getCbf( iAbsZorderIdx , TEXT_CHROMA_V , uiTempTrDepth ) )
292        return( true );
293}
294  }
295
296  return( false );
297}
298
299
300
301Void
302TComResidualGenerator::xSetRecResidualPic( TComPic* pcPic )
303{
304  AOF( pcPic );
305  AOF( pcPic->getResidual() );
306  for( UInt uiCUAddr = 0; uiCUAddr < pcPic->getPicSym()->getNumberOfCUsInFrame(); uiCUAddr++ )
307  {
308    TComDataCU* pcCU = pcPic->getCU( uiCUAddr );
309    xSetRecResidualCU( pcCU, 0, 0 );
310  }
311  pcPic->getResidual()->setBorderExtension( false );
312  pcPic->getResidual()->extendPicBorder   ();
313}
314
315
316Void
317TComResidualGenerator::xSetRecResidualCU( TComDataCU* pcCU, UInt uiDepth, UInt uiAbsPartIdx )
318{
319  UInt  uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
320  UInt  uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
321  UInt  uiRPelX   = uiLPelX           + ( g_uiMaxCUWidth  >> uiDepth ) - 1;
322  UInt  uiBPelY   = uiTPelY           + ( g_uiMaxCUHeight >> uiDepth ) - 1;
323  Bool  bBoundary = ( uiRPelX >= pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() || uiBPelY >= pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
324  Bool  bSplit    = ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) && uiDepth < ( g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary );
325  if(   bSplit )
326  {
327    UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> ( uiDepth << 1 ) ) >> 2;
328    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx += uiQNumParts )
329    {
330      uiLPelX       = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
331      uiTPelY       = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
332      Bool  bInside = ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() && uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
333      if(   bInside )
334      {
335        xSetRecResidualCU( pcCU, uiDepth + 1, uiAbsPartIdx );
336      }
337    }
338    return;
339  }
340
341  //--- set sub-CU and sub-residual ---
342  TComDataCU* pcSubCU   = m_ppcCU [ uiDepth ];
343  TComYuv*    pcSubRes  = m_ppcYuv[ uiDepth ];
344  TComPicYuv* pcPicRes  = pcCU->getPic()->getResidual();
345  UInt        uiCUAddr  = pcCU->getAddr();
346  pcSubCU->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
347#if QC_CU_NBDV_D0181
348  pcSubCU->copyDVInfoFrom( pcCU, uiAbsPartIdx);
349#endif
350  //--- set residual ---
351  switch( pcSubCU->getPredictionMode( 0 ) )
352  {
353  case MODE_INTRA:
354    xSetRecResidualIntraCU( pcSubCU, pcSubRes );
355    break;
356  case MODE_SKIP:
357  case MODE_INTER:
358    xSetRecResidualInterCU( pcSubCU, pcSubRes );
359    break;
360  default:
361    AOT( true );
362    break;
363  }
364
365  //--- copy sub-residual ---
366  pcSubRes->copyToPicYuv( pcPicRes, uiCUAddr, uiAbsPartIdx );
367}
368
369
370Void 
371TComResidualGenerator::xSetRecResidualIntraCU( TComDataCU* pcCU, TComYuv* pcCUResidual )
372{ 
373  //===== set residual to zero for entire CU =====
374  xClearResidual( pcCUResidual, 0, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
375}
376
377
378Void
379TComResidualGenerator::xSetRecResidualInterCU( TComDataCU* pcCU, TComYuv* pcCUResidual )
380{
381  //===== reconstruct residual from coded transform coefficient levels =====
382  xClearResidual( pcCUResidual, 0, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
383  // luma
384  UInt    uiWidth   = pcCU->getWidth  ( 0 );
385  UInt    uiHeight  = pcCU->getHeight ( 0 );
386  TCoeff* piCoeff   = pcCU->getCoeffY ();
387  Pel*    pRes      = pcCUResidual->getLumaAddr();
388  UInt    uiLumaTrMode, uiChromaTrMode;
389  pcCU->convertTransIdx             ( 0, pcCU->getTransformIdx( 0 ), uiLumaTrMode, uiChromaTrMode );
390    m_pcTrQuant->setQPforQuant      ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
391  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pRes, 0, pcCUResidual->getStride(), uiWidth, uiHeight, uiLumaTrMode, 0, piCoeff );
392  // chroma Cb
393  uiWidth   >>= 1;
394  uiHeight  >>= 1;
395  piCoeff     = pcCU->getCoeffCb();
396  pRes        = pcCUResidual->getCbAddr();
397    m_pcTrQuant->setQPforQuant      ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), pcCU->getSlice()->getPPS()->getChromaQpOffset() );
398  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pRes, 0, pcCUResidual->getCStride(), uiWidth, uiHeight, uiChromaTrMode, 0, piCoeff );
399  // chroma Cr
400  piCoeff     = pcCU->getCoeffCr();
401  pRes        = pcCUResidual->getCrAddr();
402  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pRes, 0, pcCUResidual->getCStride(), uiWidth, uiHeight, uiChromaTrMode, 0, piCoeff );
403
404  //===== clear inter-view predicted parts =====
405  for( UInt uiPartIdx = 0; uiPartIdx < pcCU->getNumPartInter(); uiPartIdx++ )
406  {
407    xClearIntViewResidual( pcCU, pcCUResidual, uiPartIdx );
408  }
409}
410
411
412Void
413TComResidualGenerator::xClearIntViewResidual( TComDataCU* pcCU, TComYuv* pcCUResidual, UInt uiPartIdx )
414{
415  UInt uiCurrViewId = pcCU->getSlice()->getSPS()->getViewId();
416  if(  uiCurrViewId )
417  {
418    Int             iWidth;
419    Int             iHeight;
420    UInt            uiAbsPartIdx;
421    pcCU->getPartIndexAndSize( uiPartIdx, uiAbsPartIdx, iWidth, iHeight );
422    TComCUMvField*  aiCurrMvField[2]  = { pcCU->getCUMvField( REF_PIC_LIST_0 ),        pcCU->getCUMvField( REF_PIC_LIST_1 )        };
423    Int             aiCurrRefIdx [2]  = { aiCurrMvField[0]->getRefIdx( uiAbsPartIdx ), aiCurrMvField[1]->getRefIdx( uiAbsPartIdx ) };
424    Bool            abCurrIntView[2]  = { aiCurrRefIdx[0] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_0, aiCurrRefIdx[0] )->getSPS()->getViewId() != uiCurrViewId,
425                                          aiCurrRefIdx[1] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiCurrRefIdx[1] )->getSPS()->getViewId() != uiCurrViewId };
426    Bool            bUsesInterViewPrd = ( abCurrIntView[0] || abCurrIntView[1] );
427    if( bUsesInterViewPrd )
428    { //===== set resiudal to zero =====
429      xClearResidual( pcCUResidual, uiAbsPartIdx, (UInt)iWidth, (UInt)iHeight );
430    }
431  }
432}
433
434
435Void 
436TComResidualGenerator::xClearResidual( TComYuv* pcCUResidual, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight ) 
437{
438  // luma
439  Pel* pSamplesY = pcCUResidual->getLumaAddr( uiAbsPartIdx );
440  Int  iStrideY  = pcCUResidual->getStride  ();
441  for( UInt  uiY = 0; uiY < uiHeight; uiY++, pSamplesY += iStrideY )
442  {
443    ::memset( pSamplesY, 0x00, uiWidth * sizeof( Pel ) );
444  }
445  // chroma
446  uiWidth      >>= 1;
447  uiHeight     >>= 1;
448  Pel* pSamplesU = pcCUResidual->getCbAddr ( uiAbsPartIdx );
449  Pel* pSamplesV = pcCUResidual->getCrAddr ( uiAbsPartIdx );
450  Int  iStrideC  = pcCUResidual->getCStride();
451  for( UInt  uiY = 0; uiY < uiHeight; uiY++, pSamplesU += iStrideC, pSamplesV += iStrideC )
452  {
453    ::memset( pSamplesU, 0x00, uiWidth * sizeof( Pel ) );
454    ::memset( pSamplesV, 0x00, uiWidth * sizeof( Pel ) );
455  }
456}
457
458
459#if H3D_NBDV
460Void 
461TComResidualGenerator::xSetPredResidualBlock( TComPic* pcPic, UInt uiBaseViewId, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv, TComMv iDisp
462                                             ,UInt * puiXPosInRefView , UInt * puiYPosInRefView , Bool bRecon )
463#else // H3D_NBDV
464Void 
465TComResidualGenerator::xSetPredResidualBlock( TComPic* pcPic, UInt uiBaseViewId, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv
466                                             , UInt * puiXPosInRefView , UInt * puiYPosInRefView , Bool bRecon  )
467#endif // H3D_NBDV
468{
469  //===== set and check some basic variables =====
470  AOF(          pcYuv     );
471  TComPic*      pcBasePic   = m_pcAUPicAccess->getPic( uiBaseViewId );
472  AOF(          pcPic     );
473  AOF(          pcBasePic );
474  TComPicYuv*   pcBaseRes   = pcBasePic->getResidual    ();
475  TComPicYuv*   pcPdmMap    = pcPic    ->getPredDepthMap();
476  AOF(          pcBaseRes );
477  AOF(          pcPdmMap  );
478  UInt          uiPicWidth  = pcBaseRes->getWidth ();
479  UInt          uiPicHeight = pcBaseRes->getHeight();
480  AOT( uiXPos + uiBlkWidth  > uiPicWidth  );
481  AOT( uiYPos + uiBlkHeight > uiPicHeight );
482
483  //===== get disparity =====
484#if H3D_NBDV
485  Int iDisparity_y = iDisp.getVer();
486  Int iDisparity   = iDisp.getHor();
487#else //H3D_NBDV
488  Int           iMidPosX    = Int( uiXPos + ( ( uiBlkWidth  - 1 ) >> 1 ) ) >> m_pcDepthMapGenerator->getSubSampExpX();
489  Int           iMidPosY    = Int( uiYPos + ( ( uiBlkHeight - 1 ) >> 1 ) ) >> m_pcDepthMapGenerator->getSubSampExpY();
490  Int           iDisparity  = m_pcDepthMapGenerator->getDisparity( pcPic, iMidPosX, iMidPosY, uiBaseViewId );
491#endif //H3D_NBDV
492  //===== compensate luma =====
493  Int           iYWidth     = Int( uiBlkWidth  );
494  Int           iYHeight    = Int( uiBlkHeight );
495  Int           iYWeight1   = ( iDisparity & 3 );
496  Int           iYWeight0   = 4 - iYWeight1;
497  Int           iYRefPosX0  = Int( uiXPos )     + ( iDisparity >> 2 );
498  Int           iYRefPosX1  = iYRefPosX0        + 1;
499  Int           iYMaxPosY   = Int( uiPicHeight ) - 1;
500  Int           iYWeight3   = ( iDisparity_y & 3 );
501  Int           iYWeight2   = 4 - iYWeight3;
502  Int           iYRefPosY0  = Max( 0, Min( iYMaxPosY, Int( uiYPos )     + ( iDisparity_y >> 2 )) );
503  Int           iYRefPosY1  = Max( 0, Min( iYMaxPosY, iYRefPosY0 + 1 ));
504  Int           iYMaxPosX   = Int( uiPicWidth ) - 1;
505  Int           iSrcStrideY = pcBaseRes->getStride   ();
506  Int           iDesStrideY = pcYuv    ->getStride   ();
507  Pel*          pSrcSamplesY0= pcBaseRes->getLumaAddr ( 0 ) + iYRefPosY0 * iSrcStrideY;
508  Pel*          pSrcSamplesY1= pcBaseRes->getLumaAddr ( 0 ) + iYRefPosY1 * iSrcStrideY;
509  Pel*          pDesSamplesY= pcYuv    ->getLumaAddr ();
510
511
512  if( puiXPosInRefView != NULL )
513    *puiXPosInRefView = Max( 0, Min( iYMaxPosX, iYRefPosX0 ) );
514  if( puiYPosInRefView != NULL )
515    *puiYPosInRefView = uiYPos;
516  if( bRecon == false )
517    return;
518
519  for(   Int iY = 0; iY < iYHeight; iY++, pSrcSamplesY0 += iSrcStrideY, pSrcSamplesY1 += iSrcStrideY, pDesSamplesY += iDesStrideY )
520  {
521    for( Int iX = 0; iX < iYWidth; iX++ )
522    {
523      Int iXPic0        = Max( 0, Min( iYMaxPosX, iYRefPosX0 + iX ) );
524      Int iXPic1        = Max( 0, Min( iYMaxPosX, iYRefPosX1 + iX ) );
525      Pel Temp1,Temp2;
526      Temp1 =( iYWeight0 * pSrcSamplesY0[iXPic0] + iYWeight1 * pSrcSamplesY0[iXPic1] + 2 ) >> 2;
527      Temp2 =( iYWeight0 * pSrcSamplesY1[iXPic0] + iYWeight1 * pSrcSamplesY1[iXPic1] + 2 ) >> 2;
528      pDesSamplesY[iX]  = ( iYWeight2 * Temp1 + iYWeight3 * Temp2 + 2 ) >> 2;
529    }
530  }
531
532  //===== compensate chroma =====
533  Int           iCWidth     = Int( uiBlkWidth  >> 1 );
534  Int           iCHeight    = Int( uiBlkHeight >> 1 );
535  Int           iCWeight1   = ( iDisparity & 7 );
536  Int           iCWeight0   = 8 - iCWeight1;
537  Int           iCRefPosX0  = Int( uiXPos     >> 1 ) + ( iDisparity >> 3 );
538  Int           iCRefPosX1  = iCRefPosX0             + 1;
539  Int           iCMaxPosY   = Int( uiPicHeight >> 1 ) - 1;
540  Int           iCWeight3   = ( iDisparity_y & 7 );
541  Int           iCWeight2   = 8 - iCWeight3;
542  Int           iCRefPosY0  = Max( 0, Min( iCMaxPosY, Int( uiYPos >> 1 )     + ( iDisparity_y >> 3 )) );
543  Int           iCRefPosY1  = Max( 0, Min( iCMaxPosY, iCRefPosY0 + 1 ));
544  Int           iCMaxPosX   = Int( uiPicWidth >> 1 ) - 1;
545  Int           iSrcStrideC = pcBaseRes->getCStride();
546  Int           iDesStrideC = pcYuv    ->getCStride();
547
548  Pel*          pSrcSamplesU0= pcBaseRes->getCbAddr ( 0 ) + iCRefPosY0 * iSrcStrideC;
549  Pel*          pSrcSamplesU1= pcBaseRes->getCbAddr ( 0 ) + iCRefPosY1 * iSrcStrideC;
550  Pel*          pSrcSamplesV0= pcBaseRes->getCrAddr ( 0 ) + iCRefPosY0 * iSrcStrideC;
551  Pel*          pSrcSamplesV1= pcBaseRes->getCrAddr ( 0 ) + iCRefPosY1 * iSrcStrideC;
552  Pel*          pDesSamplesU= pcYuv    ->getCbAddr ();
553  Pel*          pDesSamplesV= pcYuv    ->getCrAddr ();
554  for(   Int iY = 0; iY < iCHeight; iY++, pSrcSamplesU0 += iSrcStrideC, pSrcSamplesU1 += iSrcStrideC, pDesSamplesU += iDesStrideC,
555                                          pSrcSamplesV0 += iSrcStrideC, pSrcSamplesV1 += iSrcStrideC, pDesSamplesV += iDesStrideC )
556  {
557    for( Int iX = 0; iX < iCWidth; iX++ )
558    {
559      Int iXPic0        = Max( 0, Min( iCMaxPosX, iCRefPosX0 + iX ) );
560      Int iXPic1        = Max( 0, Min( iCMaxPosX, iCRefPosX1 + iX ) );
561      Pel Temp1,Temp2;
562      Temp1 =( iCWeight0 * pSrcSamplesU0[iXPic0] + iCWeight1 * pSrcSamplesU0[iXPic1] + 4 ) >> 3;
563      Temp2 =( iCWeight0 * pSrcSamplesU1[iXPic0] + iCWeight1 * pSrcSamplesU1[iXPic1] + 4 ) >> 3;
564      pDesSamplesU[iX]  = ( iCWeight2 * Temp1 + iCWeight3 * Temp2 + 4 ) >> 3;
565      Temp1 =( iCWeight0 * pSrcSamplesV0[iXPic0] + iCWeight1 * pSrcSamplesV0[iXPic1] + 4 ) >> 3;
566      Temp2 =( iCWeight0 * pSrcSamplesV1[iXPic0] + iCWeight1 * pSrcSamplesV1[iXPic1] + 4 ) >> 3;
567      pDesSamplesV[iX]  = ( iCWeight2 * Temp1 + iCWeight3 * Temp2 + 4 ) >> 3;
568    }
569  }
570}
571
572
573Bool
574TComResidualGenerator::xIsNonZero( TComYuv* pcYuv, UInt uiBlkWidth, UInt uiBlkHeight )
575{
576  AOF( pcYuv );
577  //===== check luma =====
578  Int   iYWidth   = Int( uiBlkWidth  );
579  Int   iYHeight  = Int( uiBlkHeight );
580  Int   iStrideY  = pcYuv->getStride   ();
581  Pel*  pSamplesY = pcYuv->getLumaAddr ();
582  for(   Int iY = 0; iY < iYHeight; iY++, pSamplesY += iStrideY )
583  {
584    for( Int iX = 0; iX < iYWidth; iX++ )
585    {
586      ROTRS( pSamplesY[iX], true );
587    }
588  }
589  //===== compensate chroma =====
590  Int   iCWidth   = Int( uiBlkWidth  >> 1 );
591  Int   iCHeight  = Int( uiBlkHeight >> 1 );
592  Int   iStrideC  = pcYuv->getCStride();
593  Pel*  pSamplesU = pcYuv->getCbAddr ();
594  Pel*  pSamplesV = pcYuv->getCrAddr ();
595  for(   Int iY = 0; iY < iCHeight; iY++, pSamplesU += iStrideC, pSamplesV += iStrideC )
596  {
597    for( Int iX = 0; iX < iCWidth; iX++ )
598    {
599      ROTRS( pSamplesU[iX], true );
600      ROTRS( pSamplesV[iX], true );
601    }
602  }
603  return false;
604}
605
606
607
608Void
609TComResidualGenerator::xDumpResidual( TComPic* pcPic, char* pFilenameBase )
610{
611  AOF( m_bCreated && m_bInit );
612  AOF( pcPic );
613  AOF( pFilenameBase );
614  AOF( m_uiOrgDepthBitDepth == 8 + g_uiBitIncrement );
615
616  // convert to output format (just clip high absolute values, since they are very unlikely)
617  Int         iMin        = 0;
618  Int         iMax        = ( 1 << m_uiOrgDepthBitDepth )  - 1;
619  Int         iMid        = ( 1 << m_uiOrgDepthBitDepth ) >> 1;
620  UInt        uiViewId    = pcPic   ->getSPS      ()->getViewId();
621  TComPicYuv* pcPicYuv    = pcPic   ->getResidual ();
622  // luma
623  Int         iWidth      = pcPicYuv->getWidth    ();
624  Int         iHeight     = pcPicYuv->getHeight   ();
625  Int         iSrcStride  = pcPicYuv->getStride   ();
626  Int         iDstStride  = m_cTmpPic.getStride   ();
627  Pel*        pSrcSamples = pcPicYuv->getLumaAddr ( 0 );
628  Pel*        pDstSamples = m_cTmpPic.getLumaAddr ( 0 );
629  AOF( m_cTmpPic.getWidth () == iWidth  );
630  AOF( m_cTmpPic.getHeight() == iHeight );
631  for( Int iY = 0; iY < iHeight; iY++, pSrcSamples += iSrcStride, pDstSamples += iDstStride )
632  {
633    for( Int iX = 0; iX < iWidth; iX++ )
634    {
635      pDstSamples[ iX ] = Max( iMin, Min( iMax, iMid + pSrcSamples[ iX ] ) );
636    }
637  }
638  // chroma
639  iWidth    >>= 1;
640  iHeight   >>= 1;
641  iSrcStride  = pcPicYuv->getCStride();
642  iDstStride  = m_cTmpPic.getCStride();
643  Pel* pSrcCb = pcPicYuv->getCbAddr ( 0 );
644  Pel* pSrcCr = pcPicYuv->getCrAddr ( 0 );
645  Pel* pDstCb = m_cTmpPic.getCbAddr ( 0 );
646  Pel* pDstCr = m_cTmpPic.getCrAddr ( 0 );
647  for( Int iY = 0; iY < iHeight; iY++, pSrcCb += iSrcStride, pSrcCr += iSrcStride, pDstCb += iDstStride, pDstCr += iDstStride )
648  {
649    for( Int iX = 0; iX < iWidth; iX++ )
650    {
651      pDstCb[ iX ] = Max( iMin, Min( iMax, iMid + pSrcCb[ iX ] ) );
652      pDstCr[ iX ] = Max( iMin, Min( iMax, iMid + pSrcCr[ iX ] ) );
653    }
654  }
655
656  // output
657  Char  acFilename[1024];
658  ::sprintf     ( acFilename, "%s_V%d.yuv", pFilenameBase, uiViewId );
659  m_cTmpPic.dump( acFilename, ( pcPic->getPOC() != 0 )  );
660}
661
662
663#endif // H3D_IVRP
664
Note: See TracBrowser for help on using the repository browser.