source: 3DVCSoftware/branches/HTM-5.1-dev3-Mediatek/source/Lib/TLibCommon/TComResidualGenerator.cpp @ 259

Last change on this file since 259 was 259, checked in by mediatek-htm, 12 years ago

Fix some bugs related to JCT3V-C0129

  • Property svn:eol-style set to native
File size: 29.4 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 HHI_INTER_VIEW_RESIDUAL_PRED
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( pcPic->getPOC() == 0 )
187  {
188    if( pcPic->getSPS()->getViewId() == 0 || m_pcSPSAccess->getResPrd() != 0 )
189    {
190      // set residual picture
191      AOT( pcPic->getResidual() );
192      if( !pcPic->getResidual() )
193      {
194        pcPic->addResidualBuffer();
195      }
196      xSetRecResidualPic( pcPic );
197    }
198  }
199  else
200  {
201    if( m_pcSPSAccess->getResPrd() != 0 && pcPic->getSPS()->getViewId() < m_pcAUPicAccess->getMaxVId() )
202    {
203      // set residual picture
204      AOT( pcPic->getResidual() );
205      if( !pcPic->getResidual() )
206      {
207        pcPic->addResidualBuffer();
208      }
209      xSetRecResidualPic( pcPic );
210
211#if OUTPUT_RESIDUAL_PICTURES
212      // dump reconstructed residual picture
213      Char acFilenameBase[1024];
214      ::sprintf( acFilenameBase,  "RecResidual_%s", ( m_bDecoder ? "Dec" : "Enc" ) );
215      xDumpResidual( pcPic, acFilenameBase );
216#endif
217    }
218  }
219}
220
221#if QC_MULTI_DIS_CAN_A0097
222#if MTK_RELEASE_DV_CONSTRAINT_C0129
223Bool
224TComResidualGenerator::getResidualSamples( TComDataCU* pcCU, UInt uiPUIdx, TComYuv* pcYuv, TComMv iDisp
225#if QC_SIMPLIFIEDIVRP_M24938
226  , Bool bRecon
227#endif
228  ) 
229#else
230Bool
231TComResidualGenerator::getResidualSamples( TComDataCU* pcCU, UInt uiPUIdx, TComYuv* pcYuv, Int iDisp
232#if QC_SIMPLIFIEDIVRP_M24938
233  , Bool bRecon
234#endif
235 ) 
236#endif
237#else
238Bool
239TComResidualGenerator::getResidualSamples( TComDataCU* pcCU, UInt uiPUIdx, TComYuv* pcYuv
240#if QC_SIMPLIFIEDIVRP_M24938
241  , Bool bRecon
242#endif
243  )
244#endif
245{
246  AOF(  pcCU );
247  UInt  uiPartAddr;
248  Int   iBlkWidth, iBlkHeight, iXPos, iYPos;
249  AOT(  uiPUIdx );
250  uiPartAddr  = 0;
251  iBlkWidth   = pcCU->getWidth  ( 0 );
252  iBlkHeight  = pcCU->getHeight ( 0 );
253  pcCU->getPic()->getPicYuvRec()->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iXPos, iYPos );
254#if QC_MULTI_DIS_CAN_A0097
255#if MTK_RELEASE_DV_CONSTRAINT_C0129
256  return getResidualSamples( pcCU->getPic(), (UInt)iXPos, (UInt)iYPos, (UInt)iBlkWidth, (UInt)iBlkHeight, pcYuv, iDisp
257#if QC_SIMPLIFIEDIVRP_M24938
258    , bRecon
259#endif
260  );
261#else
262  return getResidualSamples( pcCU->getPic(), (UInt)iXPos, (UInt)iYPos, (UInt)iBlkWidth, (UInt)iBlkHeight, pcYuv, iDisp
263#if QC_SIMPLIFIEDIVRP_M24938
264    , bRecon
265#endif
266  );
267#endif
268#else
269  return getResidualSamples( pcCU->getPic(), (UInt)iXPos, (UInt)iYPos, (UInt)iBlkWidth, (UInt)iBlkHeight, pcYuv
270#if QC_SIMPLIFIEDIVRP_M24938
271    , bRecon
272#endif
273    );
274#endif
275}
276 
277#if QC_MULTI_DIS_CAN_A0097
278#if MTK_RELEASE_DV_CONSTRAINT_C0129
279Bool
280TComResidualGenerator::getResidualSamples( TComPic* pcPic, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv, TComMv iDisp 
281#if QC_SIMPLIFIEDIVRP_M24938
282  , Bool bRecon
283#endif
284)
285#else
286Bool
287TComResidualGenerator::getResidualSamples( TComPic* pcPic, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv, Int iDisp
288#if QC_SIMPLIFIEDIVRP_M24938
289  , Bool bRecon
290#endif
291)
292#endif
293#else
294Bool
295TComResidualGenerator::getResidualSamples( TComPic* pcPic, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv
296#if QC_SIMPLIFIEDIVRP_M24938
297  , Bool bRecon
298#endif
299  )
300#endif
301{
302  UInt  uiBaseViewId  = m_pcDepthMapGenerator->getBaseViewId( 0 );
303
304  if( !pcYuv )
305  {
306    pcYuv = m_ppcYuvTmp[1];
307  }
308#if QC_SIMPLIFIEDIVRP_M24938
309  UInt uiXPosInRefView = uiXPos , uiYPosInRefView = uiYPos;
310#endif
311#if QC_MULTI_DIS_CAN_A0097
312#if MTK_RELEASE_DV_CONSTRAINT_C0129
313  xSetPredResidualBlock( pcPic, uiBaseViewId, uiXPos, uiYPos, uiBlkWidth, uiBlkHeight, pcYuv, iDisp
314#if QC_SIMPLIFIEDIVRP_M24938
315   , &uiXPosInRefView , &uiYPosInRefView , bRecon
316#endif 
317  );
318#else
319  xSetPredResidualBlock( pcPic, uiBaseViewId, uiXPos, uiYPos, uiBlkWidth, uiBlkHeight, pcYuv, iDisp
320#if QC_SIMPLIFIEDIVRP_M24938
321    , &uiXPosInRefView , &uiYPosInRefView , bRecon
322#endif 
323  );
324#endif
325#else
326  xSetPredResidualBlock( pcPic, uiBaseViewId, uiXPos, uiYPos, uiBlkWidth, uiBlkHeight, pcYuv
327#if QC_SIMPLIFIEDIVRP_M24938
328    , &uiXPosInRefView , &uiYPosInRefView , bRecon
329#endif
330    );
331#endif
332#if QC_SIMPLIFIEDIVRP_M24938
333  return xIsNonZeroByCBF( uiBaseViewId , uiXPosInRefView , uiYPosInRefView , uiBlkWidth , uiBlkHeight );
334#else
335  return xIsNonZero( pcYuv, uiBlkWidth, uiBlkHeight );
336#endif
337}
338
339#if QC_SIMPLIFIEDIVRP_M24938
340Bool TComResidualGenerator::xIsNonZeroByCBF( UInt uiBaseViewId , UInt uiXPos , UInt uiYPos, UInt uiBlkWidth , UInt uiBlkHeight )
341{
342  TComPic* pcBasePic   = m_pcAUPicAccess->getPic( uiBaseViewId );
343  const Int nMaxPicX = pcBasePic->getSPS()->getPicWidthInLumaSamples() - 1;
344  const Int nMaxPicY = pcBasePic->getSPS()->getPicHeightInLumaSamples() - 1;
345  for( UInt y = 0 ; y < uiBlkHeight ; y +=4 )
346  {
347    for( UInt x = 0 ; x <= uiBlkWidth ; x += 4 )
348    {      // to cover both the mapped CU and the 1-pixel-right-shifted mapped CU
349      Int iCuAddr = 0, iAbsZorderIdx = 0;
350      pcBasePic->getPicYuvRec()->getCUAddrAndPartIdx( Min( uiXPos + x , nMaxPicX ) , Min( uiYPos + y , nMaxPicY ) , iCuAddr , iAbsZorderIdx );
351      TComDataCU *pCUInRefView = pcBasePic->getCU( iCuAddr );
352      if( pCUInRefView->isIntra( iAbsZorderIdx ) )
353        // no inter-view residual pred from a intra CU
354        continue;
355      UInt uiTempTrDepth = pCUInRefView->getTransformIdx( iAbsZorderIdx );
356      if( pCUInRefView->getCbf( iAbsZorderIdx , TEXT_LUMA , uiTempTrDepth )
357        || pCUInRefView->getCbf( iAbsZorderIdx , TEXT_CHROMA_U , uiTempTrDepth )
358        || pCUInRefView->getCbf( iAbsZorderIdx , TEXT_CHROMA_V , uiTempTrDepth ) )
359        return( true );
360}
361  }
362
363  return( false );
364}
365#endif
366
367
368
369Void
370TComResidualGenerator::xSetRecResidualPic( TComPic* pcPic )
371{
372  AOF( pcPic );
373  AOF( pcPic->getResidual() );
374  for( UInt uiCUAddr = 0; uiCUAddr < pcPic->getPicSym()->getNumberOfCUsInFrame(); uiCUAddr++ )
375  {
376    TComDataCU* pcCU = pcPic->getCU( uiCUAddr );
377    xSetRecResidualCU( pcCU, 0, 0 );
378  }
379  pcPic->getResidual()->setBorderExtension( false );
380  pcPic->getResidual()->extendPicBorder   ();
381}
382
383
384Void
385TComResidualGenerator::xSetRecResidualCU( TComDataCU* pcCU, UInt uiDepth, UInt uiAbsPartIdx )
386{
387  UInt  uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
388  UInt  uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
389  UInt  uiRPelX   = uiLPelX           + ( g_uiMaxCUWidth  >> uiDepth ) - 1;
390  UInt  uiBPelY   = uiTPelY           + ( g_uiMaxCUHeight >> uiDepth ) - 1;
391  Bool  bBoundary = ( uiRPelX >= pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() || uiBPelY >= pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
392  Bool  bSplit    = ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) && uiDepth < ( g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary );
393  if(   bSplit )
394  {
395    UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> ( uiDepth << 1 ) ) >> 2;
396    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx += uiQNumParts )
397    {
398      uiLPelX       = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
399      uiTPelY       = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
400      Bool  bInside = ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() && uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
401      if(   bInside )
402      {
403        xSetRecResidualCU( pcCU, uiDepth + 1, uiAbsPartIdx );
404      }
405    }
406    return;
407  }
408
409  //--- set sub-CU and sub-residual ---
410  TComDataCU* pcSubCU   = m_ppcCU [ uiDepth ];
411  TComYuv*    pcSubRes  = m_ppcYuv[ uiDepth ];
412  TComPicYuv* pcPicRes  = pcCU->getPic()->getResidual();
413  UInt        uiCUAddr  = pcCU->getAddr();
414  pcSubCU->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
415
416  //--- set residual ---
417  switch( pcSubCU->getPredictionMode( 0 ) )
418  {
419  case MODE_INTRA:
420    xSetRecResidualIntraCU( pcSubCU, pcSubRes );
421    break;
422  case MODE_SKIP:
423  case MODE_INTER:
424    xSetRecResidualInterCU( pcSubCU, pcSubRes );
425    break;
426  default:
427    AOT( true );
428    break;
429  }
430
431  //--- copy sub-residual ---
432  pcSubRes->copyToPicYuv( pcPicRes, uiCUAddr, uiAbsPartIdx );
433}
434
435
436Void 
437TComResidualGenerator::xSetRecResidualIntraCU( TComDataCU* pcCU, TComYuv* pcCUResidual )
438{ 
439  //===== set residual to zero for entire CU =====
440  xClearResidual( pcCUResidual, 0, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
441}
442
443
444Void
445TComResidualGenerator::xSetRecResidualInterCU( TComDataCU* pcCU, TComYuv* pcCUResidual )
446{
447  //===== reconstruct residual from coded transform coefficient levels =====
448  xClearResidual( pcCUResidual, 0, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
449  // luma
450  UInt    uiWidth   = pcCU->getWidth  ( 0 );
451  UInt    uiHeight  = pcCU->getHeight ( 0 );
452  TCoeff* piCoeff   = pcCU->getCoeffY ();
453  Pel*    pRes      = pcCUResidual->getLumaAddr();
454  UInt    uiLumaTrMode, uiChromaTrMode;
455#if LG_RESTRICTEDRESPRED_M24766
456  Int     iPUPredResiShift[4];
457#endif
458  pcCU->convertTransIdx             ( 0, pcCU->getTransformIdx( 0 ), uiLumaTrMode, uiChromaTrMode );
459#if H0736_AVC_STYLE_QP_RANGE
460    m_pcTrQuant->setQPforQuant      ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
461#else
462    m_pcTrQuant->setQPforQuant      ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_LUMA, 0 );
463#endif
464  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pRes, 0, pcCUResidual->getStride(), uiWidth, uiHeight, uiLumaTrMode, 0, piCoeff );
465  // chroma Cb
466  uiWidth   >>= 1;
467  uiHeight  >>= 1;
468  piCoeff     = pcCU->getCoeffCb();
469  pRes        = pcCUResidual->getCbAddr();
470#if H0736_AVC_STYLE_QP_RANGE
471    m_pcTrQuant->setQPforQuant      ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), pcCU->getSlice()->getPPS()->getChromaQpOffset() );
472#else
473    m_pcTrQuant->setQPforQuant      ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC() );
474#endif
475  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pRes, 0, pcCUResidual->getCStride(), uiWidth, uiHeight, uiChromaTrMode, 0, piCoeff );
476  // chroma Cr
477  piCoeff     = pcCU->getCoeffCr();
478  pRes        = pcCUResidual->getCrAddr();
479  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pRes, 0, pcCUResidual->getCStride(), uiWidth, uiHeight, uiChromaTrMode, 0, piCoeff );
480
481  if( pcCU->getResPredFlag( 0 ) )
482  {
483    AOF( pcCU->getResPredAvail( 0 ) );
484    Bool bOK = pcCU->getResidualSamples( 0, 
485#if QC_SIMPLIFIEDIVRP_M24938
486      true,
487#endif
488      m_ppcYuvTmp[0] );
489    AOF( bOK );
490#if LG_RESTRICTEDRESPRED_M24766
491    pcCU->getPUResiPredShift(iPUPredResiShift, 0);
492    pcCUResidual->add(iPUPredResiShift, pcCU->getPartitionSize(0), m_ppcYuvTmp[0], pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
493#else
494    pcCUResidual->add( m_ppcYuvTmp[0], pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
495#endif
496  }
497
498  //===== clear inter-view predicted parts =====
499  for( UInt uiPartIdx = 0; uiPartIdx < pcCU->getNumPartInter(); uiPartIdx++ )
500  {
501    xClearIntViewResidual( pcCU, pcCUResidual, uiPartIdx );
502  }
503}
504
505
506Void
507TComResidualGenerator::xClearIntViewResidual( TComDataCU* pcCU, TComYuv* pcCUResidual, UInt uiPartIdx )
508{
509  UInt uiCurrViewId = pcCU->getSlice()->getSPS()->getViewId();
510  if(  uiCurrViewId )
511  {
512    Int             iWidth;
513    Int             iHeight;
514    UInt            uiAbsPartIdx;
515    pcCU->getPartIndexAndSize( uiPartIdx, uiAbsPartIdx, iWidth, iHeight );
516    TComCUMvField*  aiCurrMvField[2]  = { pcCU->getCUMvField( REF_PIC_LIST_0 ),        pcCU->getCUMvField( REF_PIC_LIST_1 )        };
517    Int             aiCurrRefIdx [2]  = { aiCurrMvField[0]->getRefIdx( uiAbsPartIdx ), aiCurrMvField[1]->getRefIdx( uiAbsPartIdx ) };
518    Bool            abCurrIntView[2]  = { aiCurrRefIdx[0] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_0, aiCurrRefIdx[0] )->getSPS()->getViewId() != uiCurrViewId,
519                                          aiCurrRefIdx[1] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiCurrRefIdx[1] )->getSPS()->getViewId() != uiCurrViewId };
520    Bool            bUsesInterViewPrd = ( abCurrIntView[0] || abCurrIntView[1] );
521    if( bUsesInterViewPrd )
522    { //===== set resiudal to zero =====
523      xClearResidual( pcCUResidual, uiAbsPartIdx, (UInt)iWidth, (UInt)iHeight );
524    }
525  }
526}
527
528
529Void 
530TComResidualGenerator::xClearResidual( TComYuv* pcCUResidual, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight ) 
531{
532  // luma
533  Pel* pSamplesY = pcCUResidual->getLumaAddr( uiAbsPartIdx );
534  Int  iStrideY  = pcCUResidual->getStride  ();
535  for( UInt  uiY = 0; uiY < uiHeight; uiY++, pSamplesY += iStrideY )
536  {
537    ::memset( pSamplesY, 0x00, uiWidth * sizeof( Pel ) );
538  }
539  // chroma
540  uiWidth      >>= 1;
541  uiHeight     >>= 1;
542  Pel* pSamplesU = pcCUResidual->getCbAddr ( uiAbsPartIdx );
543  Pel* pSamplesV = pcCUResidual->getCrAddr ( uiAbsPartIdx );
544  Int  iStrideC  = pcCUResidual->getCStride();
545  for( UInt  uiY = 0; uiY < uiHeight; uiY++, pSamplesU += iStrideC, pSamplesV += iStrideC )
546  {
547    ::memset( pSamplesU, 0x00, uiWidth * sizeof( Pel ) );
548    ::memset( pSamplesV, 0x00, uiWidth * sizeof( Pel ) );
549  }
550}
551
552
553#if QC_MULTI_DIS_CAN_A0097
554#if MTK_RELEASE_DV_CONSTRAINT_C0129
555Void 
556TComResidualGenerator::xSetPredResidualBlock( TComPic* pcPic, UInt uiBaseViewId, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv, TComMv iDisp
557#if QC_SIMPLIFIEDIVRP_M24938
558  , UInt * puiXPosInRefView , UInt * puiYPosInRefView , Bool bRecon
559#endif
560)
561#else
562Void 
563TComResidualGenerator::xSetPredResidualBlock( TComPic* pcPic, UInt uiBaseViewId, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv, Int iDisp
564#if QC_SIMPLIFIEDIVRP_M24938
565  , UInt * puiXPosInRefView , UInt * puiYPosInRefView , Bool bRecon
566#endif
567)
568#endif
569#else
570Void 
571TComResidualGenerator::xSetPredResidualBlock( TComPic* pcPic, UInt uiBaseViewId, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv
572#if QC_SIMPLIFIEDIVRP_M24938
573  , UInt * puiXPosInRefView , UInt * puiYPosInRefView , Bool bRecon
574#endif
575  )
576#endif
577{
578  //===== set and check some basic variables =====
579  AOF(          pcYuv     );
580  TComPic*      pcBasePic   = m_pcAUPicAccess->getPic( uiBaseViewId );
581  AOF(          pcPic     );
582  AOF(          pcBasePic );
583  TComPicYuv*   pcBaseRes   = pcBasePic->getResidual    ();
584  TComPicYuv*   pcPdmMap    = pcPic    ->getPredDepthMap();
585  AOF(          pcBaseRes );
586  AOF(          pcPdmMap  );
587  UInt          uiPicWidth  = pcBaseRes->getWidth ();
588  UInt          uiPicHeight = pcBaseRes->getHeight();
589  AOT( uiXPos + uiBlkWidth  > uiPicWidth  );
590  AOT( uiYPos + uiBlkHeight > uiPicHeight );
591
592  //===== get disparity =====
593#if QC_MULTI_DIS_CAN_A0097
594#if MTK_RELEASE_DV_CONSTRAINT_C0129
595  Int iDisparity_y = iDisp.getVer();
596  Int iDisparity   = iDisp.getHor();
597#else
598  Int iDisparity = iDisp;
599#endif
600#else
601  Int           iMidPosX    = Int( uiXPos + ( ( uiBlkWidth  - 1 ) >> 1 ) ) >> m_pcDepthMapGenerator->getSubSampExpX();
602  Int           iMidPosY    = Int( uiYPos + ( ( uiBlkHeight - 1 ) >> 1 ) ) >> m_pcDepthMapGenerator->getSubSampExpY();
603  Int           iDisparity  = m_pcDepthMapGenerator->getDisparity( pcPic, iMidPosX, iMidPosY, uiBaseViewId );
604#endif
605  //===== compensate luma =====
606  Int           iYWidth     = Int( uiBlkWidth  );
607  Int           iYHeight    = Int( uiBlkHeight );
608  Int           iYWeight1   = ( iDisparity & 3 );
609  Int           iYWeight0   = 4 - iYWeight1;
610  Int           iYRefPosX0  = Int( uiXPos )     + ( iDisparity >> 2 );
611  Int           iYRefPosX1  = iYRefPosX0        + 1;
612#if MTK_RELEASE_DV_CONSTRAINT_C0129
613  Int           iYMaxPosY   = Int( uiPicHeight ) - 1;
614  Int           iYWeight3   = ( iDisparity_y & 3 );
615  Int           iYWeight2   = 4 - iYWeight3;
616  Int           iYRefPosY0  = Max( 0, Min( iYMaxPosY, Int( uiYPos )     + ( iDisparity_y >> 2 )) );
617  Int           iYRefPosY1  = Max( 0, Min( iYMaxPosY, iYRefPosY0 + 1 ));
618#endif
619  Int           iYMaxPosX   = Int( uiPicWidth ) - 1;
620  Int           iSrcStrideY = pcBaseRes->getStride   ();
621  Int           iDesStrideY = pcYuv    ->getStride   ();
622#if MTK_RELEASE_DV_CONSTRAINT_C0129
623  Pel*          pSrcSamplesY0= pcBaseRes->getLumaAddr ( 0 ) + iYRefPosY0 * iSrcStrideY;
624  Pel*          pSrcSamplesY1= pcBaseRes->getLumaAddr ( 0 ) + iYRefPosY1 * iSrcStrideY;
625#else
626  Pel*          pSrcSamplesY= pcBaseRes->getLumaAddr ( 0 ) + uiYPos * iSrcStrideY;
627#endif
628  Pel*          pDesSamplesY= pcYuv    ->getLumaAddr ();
629
630#if QC_SIMPLIFIEDIVRP_M24938
631  if( puiXPosInRefView != NULL )
632    *puiXPosInRefView = Max( 0, Min( iYMaxPosX, iYRefPosX0 ) );
633  if( puiYPosInRefView != NULL )
634    *puiYPosInRefView = uiYPos;
635  if( bRecon == false )
636    return;
637#endif
638#if MTK_RELEASE_DV_CONSTRAINT_C0129
639  for(   Int iY = 0; iY < iYHeight; iY++, pSrcSamplesY0 += iSrcStrideY, pSrcSamplesY1 += iSrcStrideY, pDesSamplesY += iDesStrideY )
640#else
641  for(   Int iY = 0; iY < iYHeight; iY++, pSrcSamplesY += iSrcStrideY, pDesSamplesY += iDesStrideY )
642#endif
643  {
644    for( Int iX = 0; iX < iYWidth; iX++ )
645    {
646      Int iXPic0        = Max( 0, Min( iYMaxPosX, iYRefPosX0 + iX ) );
647      Int iXPic1        = Max( 0, Min( iYMaxPosX, iYRefPosX1 + iX ) );
648#if MTK_RELEASE_DV_CONSTRAINT_C0129
649      Pel Temp1,Temp2;
650      Temp1 =( iYWeight0 * pSrcSamplesY0[iXPic0] + iYWeight1 * pSrcSamplesY0[iXPic1] + 2 ) >> 2;
651      Temp2 =( iYWeight0 * pSrcSamplesY1[iXPic0] + iYWeight1 * pSrcSamplesY1[iXPic1] + 2 ) >> 2;
652      pDesSamplesY[iX]  = ( iYWeight2 * Temp1 + iYWeight3 * Temp2 + 2 ) >> 2;
653#else
654      pDesSamplesY[iX]  = ( iYWeight0 * pSrcSamplesY[iXPic0] + iYWeight1 * pSrcSamplesY[iXPic1] + 2 ) >> 2;
655#endif
656    }
657  }
658
659  //===== compensate chroma =====
660  Int           iCWidth     = Int( uiBlkWidth  >> 1 );
661  Int           iCHeight    = Int( uiBlkHeight >> 1 );
662  Int           iCWeight1   = ( iDisparity & 7 );
663  Int           iCWeight0   = 8 - iCWeight1;
664  Int           iCRefPosX0  = Int( uiXPos     >> 1 ) + ( iDisparity >> 3 );
665  Int           iCRefPosX1  = iCRefPosX0             + 1;
666#if MTK_RELEASE_DV_CONSTRAINT_C0129
667  Int           iCMaxPosY   = Int( uiPicHeight >> 1 ) - 1;
668  Int           iCWeight3   = ( iDisparity_y & 7 );
669  Int           iCWeight2   = 8 - iCWeight3;
670  Int           iCRefPosY0  = Max( 0, Min( iCMaxPosY, Int( uiYPos >> 1 )     + ( iDisparity_y >> 3 )) );
671  Int           iCRefPosY1  = Max( 0, Min( iCMaxPosY, iCRefPosY0 + 1 ));
672#endif
673  Int           iCMaxPosX   = Int( uiPicWidth >> 1 ) - 1;
674  Int           iSrcStrideC = pcBaseRes->getCStride();
675  Int           iDesStrideC = pcYuv    ->getCStride();
676#if MTK_RELEASE_DV_CONSTRAINT_C0129
677  Pel*          pSrcSamplesU0= pcBaseRes->getCbAddr ( 0 ) + ( iCRefPosY0 >> 1 ) * iSrcStrideC;
678  Pel*          pSrcSamplesU1= pcBaseRes->getCbAddr ( 0 ) + ( iCRefPosY1 >> 1 ) * iSrcStrideC;
679  Pel*          pSrcSamplesV0= pcBaseRes->getCrAddr ( 0 ) + ( iCRefPosY0 >> 1 ) * iSrcStrideC;
680  Pel*          pSrcSamplesV1= pcBaseRes->getCrAddr ( 0 ) + ( iCRefPosY1 >> 1 ) * iSrcStrideC;
681#else
682  Pel*          pSrcSamplesU= pcBaseRes->getCbAddr ( 0 ) + ( uiYPos >> 1 ) * iSrcStrideC;
683  Pel*          pSrcSamplesV= pcBaseRes->getCrAddr ( 0 ) + ( uiYPos >> 1 ) * iSrcStrideC;
684#endif
685  Pel*          pDesSamplesU= pcYuv    ->getCbAddr ();
686  Pel*          pDesSamplesV= pcYuv    ->getCrAddr ();
687#if MTK_RELEASE_DV_CONSTRAINT_C0129
688  for(   Int iY = 0; iY < iCHeight; iY++, pSrcSamplesU0 += iSrcStrideC, pSrcSamplesU1 += iSrcStrideC, pDesSamplesU += iDesStrideC,
689                                          pSrcSamplesV0 += iSrcStrideC, pSrcSamplesV1 += iSrcStrideC, pDesSamplesV += iDesStrideC )
690#else
691  for(   Int iY = 0; iY < iCHeight; iY++, pSrcSamplesU += iSrcStrideC, pDesSamplesU += iDesStrideC,
692                                          pSrcSamplesV += iSrcStrideC, pDesSamplesV += iDesStrideC )
693#endif
694  {
695    for( Int iX = 0; iX < iCWidth; iX++ )
696    {
697      Int iXPic0        = Max( 0, Min( iCMaxPosX, iCRefPosX0 + iX ) );
698      Int iXPic1        = Max( 0, Min( iCMaxPosX, iCRefPosX1 + iX ) );
699#if MTK_RELEASE_DV_CONSTRAINT_C0129
700      Pel Temp1,Temp2;
701      Temp1 =( iCWeight0 * pSrcSamplesU0[iXPic0] + iCWeight1 * pSrcSamplesU0[iXPic1] + 4 ) >> 3;
702      Temp2 =( iCWeight0 * pSrcSamplesU1[iXPic0] + iCWeight1 * pSrcSamplesU1[iXPic1] + 4 ) >> 3;
703      pDesSamplesU[iX]  = ( iCWeight2 * Temp1 + iCWeight3 * Temp2 + 4 ) >> 3;
704      Temp1 =( iCWeight0 * pSrcSamplesV0[iXPic0] + iCWeight1 * pSrcSamplesV0[iXPic1] + 4 ) >> 3;
705      Temp2 =( iCWeight0 * pSrcSamplesV1[iXPic0] + iCWeight1 * pSrcSamplesV1[iXPic1] + 4 ) >> 3;
706      pDesSamplesV[iX]  = ( iCWeight2 * Temp1 + iCWeight3 * Temp2 + 4 ) >> 3;
707#else
708      pDesSamplesU[iX]  = ( iCWeight0 * pSrcSamplesU[iXPic0] + iCWeight1 * pSrcSamplesU[iXPic1] + 4 ) >> 3;
709      pDesSamplesV[iX]  = ( iCWeight0 * pSrcSamplesV[iXPic0] + iCWeight1 * pSrcSamplesV[iXPic1] + 4 ) >> 3;
710#endif
711    }
712  }
713}
714
715
716Bool
717TComResidualGenerator::xIsNonZero( TComYuv* pcYuv, UInt uiBlkWidth, UInt uiBlkHeight )
718{
719  AOF( pcYuv );
720  //===== check luma =====
721  Int   iYWidth   = Int( uiBlkWidth  );
722  Int   iYHeight  = Int( uiBlkHeight );
723  Int   iStrideY  = pcYuv->getStride   ();
724  Pel*  pSamplesY = pcYuv->getLumaAddr ();
725  for(   Int iY = 0; iY < iYHeight; iY++, pSamplesY += iStrideY )
726  {
727    for( Int iX = 0; iX < iYWidth; iX++ )
728    {
729      ROTRS( pSamplesY[iX], true );
730    }
731  }
732  //===== compensate chroma =====
733  Int   iCWidth   = Int( uiBlkWidth  >> 1 );
734  Int   iCHeight  = Int( uiBlkHeight >> 1 );
735  Int   iStrideC  = pcYuv->getCStride();
736  Pel*  pSamplesU = pcYuv->getCbAddr ();
737  Pel*  pSamplesV = pcYuv->getCrAddr ();
738  for(   Int iY = 0; iY < iCHeight; iY++, pSamplesU += iStrideC, pSamplesV += iStrideC )
739  {
740    for( Int iX = 0; iX < iCWidth; iX++ )
741    {
742      ROTRS( pSamplesU[iX], true );
743      ROTRS( pSamplesV[iX], true );
744    }
745  }
746  return false;
747}
748
749
750
751Void
752TComResidualGenerator::xDumpResidual( TComPic* pcPic, char* pFilenameBase )
753{
754  AOF( m_bCreated && m_bInit );
755  AOF( pcPic );
756  AOF( pFilenameBase );
757  AOF( m_uiOrgDepthBitDepth == 8 + g_uiBitIncrement );
758
759  // convert to output format (just clip high absolute values, since they are very unlikely)
760  Int         iMin        = 0;
761  Int         iMax        = ( 1 << m_uiOrgDepthBitDepth )  - 1;
762  Int         iMid        = ( 1 << m_uiOrgDepthBitDepth ) >> 1;
763  UInt        uiViewId    = pcPic   ->getSPS      ()->getViewId();
764  TComPicYuv* pcPicYuv    = pcPic   ->getResidual ();
765  // luma
766  Int         iWidth      = pcPicYuv->getWidth    ();
767  Int         iHeight     = pcPicYuv->getHeight   ();
768  Int         iSrcStride  = pcPicYuv->getStride   ();
769  Int         iDstStride  = m_cTmpPic.getStride   ();
770  Pel*        pSrcSamples = pcPicYuv->getLumaAddr ( 0 );
771  Pel*        pDstSamples = m_cTmpPic.getLumaAddr ( 0 );
772  AOF( m_cTmpPic.getWidth () == iWidth  );
773  AOF( m_cTmpPic.getHeight() == iHeight );
774  for( Int iY = 0; iY < iHeight; iY++, pSrcSamples += iSrcStride, pDstSamples += iDstStride )
775  {
776    for( Int iX = 0; iX < iWidth; iX++ )
777    {
778      pDstSamples[ iX ] = Max( iMin, Min( iMax, iMid + pSrcSamples[ iX ] ) );
779    }
780  }
781  // chroma
782  iWidth    >>= 1;
783  iHeight   >>= 1;
784  iSrcStride  = pcPicYuv->getCStride();
785  iDstStride  = m_cTmpPic.getCStride();
786  Pel* pSrcCb = pcPicYuv->getCbAddr ( 0 );
787  Pel* pSrcCr = pcPicYuv->getCrAddr ( 0 );
788  Pel* pDstCb = m_cTmpPic.getCbAddr ( 0 );
789  Pel* pDstCr = m_cTmpPic.getCrAddr ( 0 );
790  for( Int iY = 0; iY < iHeight; iY++, pSrcCb += iSrcStride, pSrcCr += iSrcStride, pDstCb += iDstStride, pDstCr += iDstStride )
791  {
792    for( Int iX = 0; iX < iWidth; iX++ )
793    {
794      pDstCb[ iX ] = Max( iMin, Min( iMax, iMid + pSrcCb[ iX ] ) );
795      pDstCr[ iX ] = Max( iMin, Min( iMax, iMid + pSrcCr[ iX ] ) );
796    }
797  }
798
799  // output
800  Char  acFilename[1024];
801  ::sprintf     ( acFilename, "%s_V%d.yuv", pFilenameBase, uiViewId );
802  m_cTmpPic.dump( acFilename, ( pcPic->getPOC() != 0 )  );
803}
804
805
806#endif // HHI_INTER_VIEW_RESIDUAL_PRED
807
Note: See TracBrowser for help on using the repository browser.