source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibCommon/TComPic.cpp @ 1590

Last change on this file since 1590 was 1578, checked in by seregin, 9 years ago

fix memory allocation for reference layer picture and REDUCED_ENCODER_MEMORY

  • Property svn:eol-style set to native
File size: 23.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-2016, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TComPic.cpp
35    \brief    picture class
36*/
37
38#include "TComPic.h"
39#include "SEI.h"
40
41//! \ingroup TLibCommon
42//! \{
43
44// ====================================================================================================================
45// Constructor / destructor / create / destroy
46// ====================================================================================================================
47
48TComPic::TComPic()
49: m_uiTLayer                              (0)
50, m_bUsedByCurr                           (false)
51, m_bIsLongTerm                           (false)
52, m_pcPicYuvPred                          (NULL)
53, m_pcPicYuvResi                          (NULL)
54, m_bReconstructed                        (false)
55, m_bNeededForOutput                      (false)
56, m_uiCurrSliceIdx                        (0)
57, m_bCheckLTMSB                           (false)
58#if SVC_EXTENSION
59, m_layerId( 0 )
60#endif
61{
62#if SVC_EXTENSION
63  memset( m_pcFullPelBaseRec, 0, sizeof( m_pcFullPelBaseRec ) );
64  memset( m_requireResampling, false, sizeof( m_requireResampling ) );
65  memset( m_equalPictureSizeAndOffsetFlag, false, sizeof( m_equalPictureSizeAndOffsetFlag ) );
66  memset( m_mvScalingFactor, 0, sizeof( m_mvScalingFactor ) );
67  memset( m_posScalingFactor, 0, sizeof( m_posScalingFactor ) );
68#endif
69  for(UInt i=0; i<NUM_PIC_YUV; i++)
70  {
71    m_apcPicYuv[i]      = NULL;
72  }
73}
74
75TComPic::~TComPic()
76{
77  destroy();
78}
79#if SVC_EXTENSION
80#if REDUCED_ENCODER_MEMORY
81Void TComPic::create( const TComSPS &sps, const TComPPS &pps, const Bool bCreateEncoderSourcePicYuv, const Bool bCreateForImmediateReconstruction, const UInt layerId )
82#else
83Void TComPic::create( const TComSPS &sps, const TComPPS &pps, const Bool bIsVirtual, const UInt layerId )
84#endif
85{
86  destroy();
87
88  const ChromaFormat chromaFormatIDC = sps.getChromaFormatIdc();
89  const Int          iWidth          = sps.getPicWidthInLumaSamples();
90  const Int          iHeight         = sps.getPicHeightInLumaSamples();
91  const UInt         uiMaxCuWidth    = sps.getMaxCUWidth();
92  const UInt         uiMaxCuHeight   = sps.getMaxCUHeight();
93  const UInt         uiMaxDepth      = sps.getMaxTotalCUDepth();
94  const Window& conformanceWindow    = sps.getConformanceWindow();
95
96  m_layerId = layerId;
97
98#if REDUCED_ENCODER_MEMORY
99  m_picSym.create( sps, pps, uiMaxDepth, bCreateForImmediateReconstruction, layerId );
100  if (bCreateEncoderSourcePicYuv)
101#else
102  m_picSym.create( sps, pps, uiMaxDepth, layerId );
103
104  if (!bIsVirtual)
105#endif
106  {
107    m_apcPicYuv[PIC_YUV_ORG     ]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_ORG     ]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true, &conformanceWindow );
108    m_apcPicYuv[PIC_YUV_TRUE_ORG]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_TRUE_ORG]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true, &conformanceWindow );
109  }
110#if REDUCED_ENCODER_MEMORY
111  if (bCreateForImmediateReconstruction)
112  {
113#endif
114  m_apcPicYuv[PIC_YUV_REC]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_REC]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true, &conformanceWindow );
115
116  for( Int i = 0; i < MAX_LAYERS; i++ )
117  {
118    if( m_requireResampling[i] )
119    {
120      m_pcFullPelBaseRec[i] = new TComPicYuv;  m_pcFullPelBaseRec[i]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true, &conformanceWindow );
121    }
122  }
123#if REDUCED_ENCODER_MEMORY
124  }
125#endif
126
127  // there are no SEI messages associated with this picture initially
128  if (m_SEIs.size() > 0)
129  {
130    deleteSEIs (m_SEIs);
131  }
132  m_bUsedByCurr = false;
133}
134#else
135#if REDUCED_ENCODER_MEMORY
136Void TComPic::create( const TComSPS &sps, const TComPPS &pps, const Bool bCreateEncoderSourcePicYuv, const Bool bCreateForImmediateReconstruction )
137#else
138Void TComPic::create( const TComSPS &sps, const TComPPS &pps, const Bool bIsVirtual)
139#endif
140{
141  destroy();
142
143  const ChromaFormat chromaFormatIDC = sps.getChromaFormatIdc();
144  const Int          iWidth          = sps.getPicWidthInLumaSamples();
145  const Int          iHeight         = sps.getPicHeightInLumaSamples();
146  const UInt         uiMaxCuWidth    = sps.getMaxCUWidth();
147  const UInt         uiMaxCuHeight   = sps.getMaxCUHeight();
148  const UInt         uiMaxDepth      = sps.getMaxTotalCUDepth();
149
150#if REDUCED_ENCODER_MEMORY
151  m_picSym.create( sps, pps, uiMaxDepth, bCreateForImmediateReconstruction );
152  if (bCreateEncoderSourcePicYuv)
153#else
154  m_picSym.create( sps, pps, uiMaxDepth );
155  if (!bIsVirtual)
156#endif
157  {
158    m_apcPicYuv[PIC_YUV_ORG    ]   = new TComPicYuv;  m_apcPicYuv[PIC_YUV_ORG     ]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
159    m_apcPicYuv[PIC_YUV_TRUE_ORG]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_TRUE_ORG]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
160  }
161#if REDUCED_ENCODER_MEMORY
162  if (bCreateForImmediateReconstruction)
163  {
164#endif
165    m_apcPicYuv[PIC_YUV_REC]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_REC]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
166#if REDUCED_ENCODER_MEMORY
167  }
168#endif
169
170  // there are no SEI messages associated with this picture initially
171  if (m_SEIs.size() > 0)
172  {
173    deleteSEIs (m_SEIs);
174  }
175  m_bUsedByCurr = false;
176}
177#endif
178
179#if REDUCED_ENCODER_MEMORY
180Void TComPic::prepareForEncoderSourcePicYuv()
181{
182  const TComSPS &sps=m_picSym.getSPS();
183
184  const ChromaFormat chromaFormatIDC = sps.getChromaFormatIdc();
185  const Int          iWidth          = sps.getPicWidthInLumaSamples();
186  const Int          iHeight         = sps.getPicHeightInLumaSamples();
187  const UInt         uiMaxCuWidth    = sps.getMaxCUWidth();
188  const UInt         uiMaxCuHeight   = sps.getMaxCUHeight();
189  const UInt         uiMaxDepth      = sps.getMaxTotalCUDepth();
190
191#if SVC_EXTENSION
192  const Window& conformanceWindow    = sps.getConformanceWindow();
193
194  if (m_apcPicYuv[PIC_YUV_ORG    ]==NULL)
195  {
196    m_apcPicYuv[PIC_YUV_ORG    ]   = new TComPicYuv;  m_apcPicYuv[PIC_YUV_ORG     ]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true, &conformanceWindow );
197  }
198  if (m_apcPicYuv[PIC_YUV_TRUE_ORG    ]==NULL)
199  {
200    m_apcPicYuv[PIC_YUV_TRUE_ORG]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_TRUE_ORG]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true, &conformanceWindow );
201  }
202#else
203  if (m_apcPicYuv[PIC_YUV_ORG    ]==NULL)
204  {
205    m_apcPicYuv[PIC_YUV_ORG    ]   = new TComPicYuv;  m_apcPicYuv[PIC_YUV_ORG     ]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
206  }
207  if (m_apcPicYuv[PIC_YUV_TRUE_ORG    ]==NULL)
208  {
209    m_apcPicYuv[PIC_YUV_TRUE_ORG]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_TRUE_ORG]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
210  }
211#endif
212}
213
214Void TComPic::prepareForReconstruction()
215{
216  if (m_apcPicYuv[PIC_YUV_REC] == NULL)
217  {
218    const TComSPS &sps=m_picSym.getSPS();
219    const ChromaFormat chromaFormatIDC = sps.getChromaFormatIdc();
220    const Int          iWidth          = sps.getPicWidthInLumaSamples();
221    const Int          iHeight         = sps.getPicHeightInLumaSamples();
222    const UInt         uiMaxCuWidth    = sps.getMaxCUWidth();
223    const UInt         uiMaxCuHeight   = sps.getMaxCUHeight();
224    const UInt         uiMaxDepth      = sps.getMaxTotalCUDepth();
225
226#if SVC_EXTENSION
227    const Window& conformanceWindow    = sps.getConformanceWindow();
228
229    m_apcPicYuv[PIC_YUV_REC]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_REC]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true, &conformanceWindow );
230
231    for( Int i = 0; i < MAX_LAYERS; i++ )
232    {
233      if( m_requireResampling[i] )
234      {
235        m_pcFullPelBaseRec[i] = new TComPicYuv;  m_pcFullPelBaseRec[i]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true, &conformanceWindow );
236      }
237    } 
238#else
239    m_apcPicYuv[PIC_YUV_REC]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_REC]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
240#endif
241  }
242
243  // mark it should be extended
244  m_apcPicYuv[PIC_YUV_REC]->setBorderExtension(false);
245
246  m_picSym.prepareForReconstruction();
247}
248
249Void TComPic::releaseReconstructionIntermediateData()
250{
251  m_picSym.releaseReconstructionIntermediateData();
252}
253
254Void TComPic::releaseEncoderSourceImageData()
255{
256  if (m_apcPicYuv[PIC_YUV_ORG    ])
257  {
258    m_apcPicYuv[PIC_YUV_ORG]->destroy();
259    delete m_apcPicYuv[PIC_YUV_ORG];
260    m_apcPicYuv[PIC_YUV_ORG] = NULL;
261  }
262  if (m_apcPicYuv[PIC_YUV_TRUE_ORG    ])
263  {
264    m_apcPicYuv[PIC_YUV_TRUE_ORG]->destroy();
265    delete m_apcPicYuv[PIC_YUV_TRUE_ORG];
266    m_apcPicYuv[PIC_YUV_TRUE_ORG] = NULL;
267  }
268}
269
270Void TComPic::releaseAllReconstructionData()
271{
272  if (m_apcPicYuv[PIC_YUV_REC    ])
273  {
274    m_apcPicYuv[PIC_YUV_REC]->destroy();
275    delete m_apcPicYuv[PIC_YUV_REC];
276    m_apcPicYuv[PIC_YUV_REC] = NULL;
277  }
278  m_picSym.releaseAllReconstructionData();
279}
280#endif
281
282Void TComPic::destroy()
283{
284  m_picSym.destroy();
285
286  for(UInt i=0; i<NUM_PIC_YUV; i++)
287  {
288    if (m_apcPicYuv[i])
289    {
290      m_apcPicYuv[i]->destroy();
291      delete m_apcPicYuv[i];
292      m_apcPicYuv[i]  = NULL;
293    }
294  }
295
296  deleteSEIs(m_SEIs);
297#if SVC_EXTENSION
298  for( Int i = 0; i < MAX_LAYERS; i++ )
299  {
300    if( m_requireResampling[i] && m_pcFullPelBaseRec[i] )
301    {
302      m_pcFullPelBaseRec[i]->destroy();
303      delete m_pcFullPelBaseRec[i];
304      m_pcFullPelBaseRec[i]  = NULL;
305    }
306  }
307
308  for( Int comp = 0; comp < 2; comp++ )
309  {
310    if( m_mvScalingFactor[comp] )
311    {
312      delete [] m_mvScalingFactor[comp];
313      m_mvScalingFactor[comp] = NULL;
314    }
315
316    if( m_posScalingFactor[comp] )
317    {
318      delete [] m_posScalingFactor[comp];
319      m_posScalingFactor[comp] = NULL;
320    }
321  }
322#endif
323}
324
325Void TComPic::compressMotion()
326{
327  TComPicSym* pPicSym = getPicSym();
328  for ( UInt uiCUAddr = 0; uiCUAddr < pPicSym->getNumberOfCtusInFrame(); uiCUAddr++ )
329  {
330    TComDataCU* pCtu = pPicSym->getCtu(uiCUAddr);
331    pCtu->compressMV();
332  }
333}
334
335Bool  TComPic::getSAOMergeAvailability(Int currAddr, Int mergeAddr)
336{
337  Bool mergeCtbInSliceSeg = (mergeAddr >= getPicSym()->getCtuTsToRsAddrMap(getCtu(currAddr)->getSlice()->getSliceCurStartCtuTsAddr()));
338  Bool mergeCtbInTile     = (getPicSym()->getTileIdxMap(mergeAddr) == getPicSym()->getTileIdxMap(currAddr));
339  return (mergeCtbInSliceSeg && mergeCtbInTile);
340}
341
342UInt TComPic::getSubstreamForCtuAddr(const UInt ctuAddr, const Bool bAddressInRaster, TComSlice *pcSlice)
343{
344  UInt subStrm;
345  const bool bWPPEnabled=pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag();
346  const TComPicSym &picSym            = *(getPicSym());
347
348  if ((bWPPEnabled && picSym.getFrameHeightInCtus()>1) || (picSym.getNumTiles()>1)) // wavefronts, and possibly tiles being used.
349  {
350    if (bWPPEnabled)
351    {
352      const UInt ctuRsAddr                = bAddressInRaster?ctuAddr : picSym.getCtuTsToRsAddrMap(ctuAddr);
353      const UInt frameWidthInCtus         = picSym.getFrameWidthInCtus();
354      const UInt tileIndex                = picSym.getTileIdxMap(ctuRsAddr);
355      const UInt numTileColumns           = (picSym.getNumTileColumnsMinus1()+1);
356      const TComTile *pTile               = picSym.getTComTile(tileIndex);
357      const UInt firstCtuRsAddrOfTile     = pTile->getFirstCtuRsAddr();
358      const UInt tileYInCtus              = firstCtuRsAddrOfTile / frameWidthInCtus;
359      // independent tiles => substreams are "per tile"
360      const UInt ctuLine                  = ctuRsAddr / frameWidthInCtus;
361      const UInt startingSubstreamForTile =(tileYInCtus*numTileColumns) + (pTile->getTileHeightInCtus()*(tileIndex%numTileColumns));
362      subStrm = startingSubstreamForTile + (ctuLine - tileYInCtus);
363    }
364    else
365    {
366      const UInt ctuRsAddr                = bAddressInRaster?ctuAddr : picSym.getCtuTsToRsAddrMap(ctuAddr);
367      const UInt tileIndex                = picSym.getTileIdxMap(ctuRsAddr);
368      subStrm=tileIndex;
369    }
370  }
371  else
372  {
373    // dependent tiles => substreams are "per frame".
374    subStrm = 0;
375  }
376  return subStrm;
377}
378
379#if SVC_EXTENSION
380Void TComPic::createMvScalingFactor(UInt numOfILRPs)
381{
382  // picture object might be reused and hence m_mvScalingFactor[0] can be already allocated
383  if(m_mvScalingFactor[0])
384  {
385    delete m_mvScalingFactor[0];
386  }
387  m_mvScalingFactor[0] = new Int[numOfILRPs];
388
389  // picture object might be reused and hence m_mvScalingFactor[1] can be already allocated
390  if(m_mvScalingFactor[1])
391  {
392    delete m_mvScalingFactor[1];
393  }
394  m_mvScalingFactor[1] = new Int[numOfILRPs];
395}
396
397Void TComPic::createPosScalingFactor(UInt numOfILRPs)
398{
399  // picture object might be reused and hence m_posScalingFactor[0] can be already allocated
400  if(m_posScalingFactor[0])
401  {
402    delete m_posScalingFactor[0];
403  }
404  m_posScalingFactor[0] = new Int[numOfILRPs];
405
406  // picture object might be reused and hence m_posScalingFactor[1] can be already allocated
407  if(m_posScalingFactor[1])
408  {
409    delete m_posScalingFactor[1];
410  }
411  m_posScalingFactor[1] = new Int[numOfILRPs];
412}
413
414Void copyOnetoOnePicture(    // SVC_NONCOLL
415                  Pel *in,       
416                  Pel *out,     
417                  Int nCols,
418                  Int nRows, 
419                  Int fullRowWidth)
420{
421  Int rX;
422
423  for (rX = 0; rX < nRows; rX++)       
424  {
425    memcpy( out, in, sizeof(Pel) * nCols );
426    in = in + fullRowWidth;
427    out = out + fullRowWidth;
428  }
429}
430
431Void TComPic::copyUpsampledPictureYuv(TComPicYuv*   pcPicYuvIn, TComPicYuv*   pcPicYuvOut)
432{
433#if SCALABLE_REXT
434  Int upsampledRowWidthLuma = pcPicYuvOut->getStride(COMPONENT_Y); // 2 * pcPicYuvOut->getLumaMargin() + pcPicYuvOut->getWidth();
435  copyOnetoOnePicture(
436    pcPicYuvIn->getAddr(COMPONENT_Y),       
437    pcPicYuvOut->getAddr(COMPONENT_Y),     
438    pcPicYuvOut->getWidth(COMPONENT_Y), 
439    pcPicYuvOut->getHeight(COMPONENT_Y),
440    upsampledRowWidthLuma);
441
442  if(pcPicYuvOut->getChromaFormat() != CHROMA_400)
443  {
444    Int upsampledRowWidthChroma = pcPicYuvOut->getStride(COMPONENT_Cb); //2 * pcPicYuvOut->getChromaMargin() + (pcPicYuvOut->getWidth()>>1);
445
446    copyOnetoOnePicture(
447      pcPicYuvIn->getAddr(COMPONENT_Cr),       
448      pcPicYuvOut->getAddr(COMPONENT_Cr),     
449      pcPicYuvOut->getWidth(COMPONENT_Cr), 
450      pcPicYuvOut->getHeight(COMPONENT_Cr),
451      upsampledRowWidthChroma);
452    copyOnetoOnePicture(
453      pcPicYuvIn->getAddr(COMPONENT_Cb),       
454      pcPicYuvOut->getAddr(COMPONENT_Cb),     
455      pcPicYuvOut->getWidth(COMPONENT_Cb), 
456      pcPicYuvOut->getHeight(COMPONENT_Cb),
457      upsampledRowWidthChroma);
458  }
459#else
460  Int upsampledRowWidthLuma = pcPicYuvOut->getStride(COMPONENT_Y); // 2 * pcPicYuvOut->getLumaMargin() + pcPicYuvOut->getWidth();
461  Int upsampledRowWidthCroma = pcPicYuvOut->getStride(COMPONENT_Cb); //2 * pcPicYuvOut->getChromaMargin() + (pcPicYuvOut->getWidth()>>1);
462
463  copyOnetoOnePicture(
464    pcPicYuvIn->getAddr(COMPONENT_Y),       
465    pcPicYuvOut->getAddr(COMPONENT_Y),     
466    pcPicYuvOut->getWidth(COMPONENT_Y), 
467    pcPicYuvOut->getHeight(COMPONENT_Y),
468    upsampledRowWidthLuma);
469  copyOnetoOnePicture(
470    pcPicYuvIn->getAddr(COMPONENT_Cr),       
471    pcPicYuvOut->getAddr(COMPONENT_Cr),     
472    pcPicYuvOut->getWidth(COMPONENT_Y)>>1, 
473    pcPicYuvOut->getHeight(COMPONENT_Y)>>1,
474    upsampledRowWidthCroma);
475  copyOnetoOnePicture(
476    pcPicYuvIn->getAddr(COMPONENT_Cb),       
477    pcPicYuvOut->getAddr(COMPONENT_Cb),     
478    pcPicYuvOut->getWidth(COMPONENT_Y)>>1, 
479    pcPicYuvOut->getHeight(COMPONENT_Y)>>1,
480    upsampledRowWidthCroma);
481#endif
482}
483
484Void TComPic::copyUpsampledMvField(UInt refLayerIdc, Int** mvScalingFactor, Int** posScalingFactor)
485{
486  const TComSPS *sps       = getSlice(0)->getSPS();
487  const UInt uiMaxDepth    = sps->getMaxTotalCUDepth();
488  const UInt numPartitions = 1<<(uiMaxDepth<<1);
489  const UInt widthMinPU    = sps->getMaxCUWidth()  / (1<<uiMaxDepth);
490  const UInt heightMinPU   = sps->getMaxCUHeight() / (1<<uiMaxDepth);
491  const Int  unitNum       = max( 1, (Int)((16/widthMinPU)*(16/heightMinPU)) ); 
492
493  for( UInt ctuRsAddr = 0; ctuRsAddr < m_picSym.getNumberOfCtusInFrame(); ctuRsAddr++ )  //each CTU
494  {
495    TComDataCU* pcCUDes = getCtu(ctuRsAddr);
496
497#if REDUCED_ENCODER_MEMORY
498    TComPicSym::DPBPerCtuData &dpbForCtu = m_picSym.getDPBPerCtuData(ctuRsAddr);
499#endif
500
501    for(UInt absPartIdx = 0; absPartIdx < numPartitions; absPartIdx+=unitNum )  //each 16x16 unit
502    {
503      //pixel position of each unit in up-sampled layer
504      UInt pelX = pcCUDes->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[absPartIdx] ];
505      UInt pelY = pcCUDes->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[absPartIdx] ];
506      UInt baseCUAddr, baseAbsPartIdx;
507
508      TComDataCU *pcColCU = 0;
509      pcColCU = pcCUDes->getBaseColCU(refLayerIdc, pelX, pelY, baseCUAddr, baseAbsPartIdx, posScalingFactor, true);
510
511      if( pcColCU && pcColCU->getPredictionMode(baseAbsPartIdx) == MODE_INTER )  //base layer unit not skip and invalid mode
512      {
513        for(UInt refPicList = 0; refPicList < 2; refPicList++)  //for each reference list
514        {
515          TComMvField sMvFieldBase, sMvField;
516          pcColCU->getMvField( pcColCU, baseAbsPartIdx, (RefPicList)refPicList, sMvFieldBase);
517          pcCUDes->scaleBaseMV( refLayerIdc, sMvField, sMvFieldBase, mvScalingFactor );
518
519          pcCUDes->getCUMvField((RefPicList)refPicList)->setMvField(sMvField, absPartIdx);
520          pcCUDes->setPredictionMode(absPartIdx, MODE_INTER);
521        }
522      }
523      else
524      {
525        TComMvField zeroMvField;  //zero MV and invalid reference index
526        pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(zeroMvField, absPartIdx);
527        pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(zeroMvField, absPartIdx);
528        pcCUDes->setPredictionMode(absPartIdx, MODE_INTRA);
529      }
530
531#if REDUCED_ENCODER_MEMORY
532      dpbForCtu.m_CUMvField[REF_PIC_LIST_0].setMvField(pcCUDes->getCUMvField(REF_PIC_LIST_0)->getMv(absPartIdx), pcCUDes->getCUMvField(REF_PIC_LIST_0)->getRefIdx(absPartIdx), absPartIdx);
533      dpbForCtu.m_CUMvField[REF_PIC_LIST_1].setMvField(pcCUDes->getCUMvField(REF_PIC_LIST_1)->getMv(absPartIdx), pcCUDes->getCUMvField(REF_PIC_LIST_1)->getRefIdx(absPartIdx), absPartIdx);
534#endif
535
536      for(UInt i = 1; i < unitNum; i++ ) 
537      {
538        pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(pcCUDes->getCUMvField(REF_PIC_LIST_0)->getMv(absPartIdx), pcCUDes->getCUMvField(REF_PIC_LIST_0)->getRefIdx(absPartIdx), absPartIdx + i);
539        pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(pcCUDes->getCUMvField(REF_PIC_LIST_1)->getMv(absPartIdx), pcCUDes->getCUMvField(REF_PIC_LIST_1)->getRefIdx(absPartIdx), absPartIdx + i);
540
541#if REDUCED_ENCODER_MEMORY
542        dpbForCtu.m_CUMvField[REF_PIC_LIST_0].setMvField(pcCUDes->getCUMvField(REF_PIC_LIST_0)->getMv(absPartIdx), pcCUDes->getCUMvField(REF_PIC_LIST_0)->getRefIdx(absPartIdx), absPartIdx + i);
543        dpbForCtu.m_CUMvField[REF_PIC_LIST_1].setMvField(pcCUDes->getCUMvField(REF_PIC_LIST_1)->getMv(absPartIdx), pcCUDes->getCUMvField(REF_PIC_LIST_1)->getRefIdx(absPartIdx), absPartIdx + i);
544#endif
545        pcCUDes->setPredictionMode(absPartIdx+i, pcCUDes->getPredictionMode(absPartIdx));
546      }
547    }
548    memset( pcCUDes->getPartitionSize(), SIZE_2Nx2N, sizeof(*pcCUDes->getPartitionSize())*numPartitions );
549
550#if REDUCED_ENCODER_MEMORY
551    memcpy( dpbForCtu.m_pePredMode, pcCUDes->getPredictionMode(), sizeof(*pcCUDes->getPredictionMode()) * numPartitions );
552    memcpy( dpbForCtu.m_pePartSize, pcCUDes->getPartitionSize(), sizeof(*pcCUDes->getPartitionSize()) * numPartitions );
553    dpbForCtu.m_pSlice = pcCUDes->getSlice();
554#endif
555  }
556}
557
558Void TComPic::initUpsampledMvField()
559{
560  const TComSPS *sps         = getSlice(0)->getSPS();
561  const UInt uiMaxDepth      = sps->getMaxTotalCUDepth();
562  const UInt numPartitions = 1<<(uiMaxDepth<<1);
563
564  for( UInt ctuRsAddr = 0; ctuRsAddr < m_picSym.getNumberOfCtusInFrame(); ctuRsAddr++ )  //each CTU
565  {
566    TComDataCU* pcCUDes = getCtu(ctuRsAddr);
567    TComMvField zeroMvField;
568
569#if REDUCED_ENCODER_MEMORY
570    TComPicSym::DPBPerCtuData &dpbForCtu = m_picSym.getDPBPerCtuData(ctuRsAddr);
571#endif
572
573    for( UInt i = 0; i < numPartitions; i++ ) 
574    {
575      pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(zeroMvField, i);
576      pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(zeroMvField, i);
577      pcCUDes->setPredictionMode(i, MODE_INTRA);
578      pcCUDes->setPartitionSize(i, SIZE_2Nx2N);
579
580#if REDUCED_ENCODER_MEMORY
581      dpbForCtu.m_CUMvField[REF_PIC_LIST_0].setMvField(zeroMvField, i);
582      dpbForCtu.m_CUMvField[REF_PIC_LIST_1].setMvField(zeroMvField, i);
583#endif
584    }
585
586#if REDUCED_ENCODER_MEMORY
587    memcpy( dpbForCtu.m_pePredMode, pcCUDes->getPredictionMode(), sizeof(*pcCUDes->getPredictionMode()) * numPartitions );
588    memcpy( dpbForCtu.m_pePartSize, pcCUDes->getPartitionSize(), sizeof(*pcCUDes->getPartitionSize()) * numPartitions );
589    dpbForCtu.m_pSlice = pcCUDes->getSlice();
590#endif
591  }
592}
593
594Bool TComPic::checkSameRefInfo()
595{
596  Bool bSameRefInfo = true;
597  TComSlice * pSlice0 = getSlice( 0 );
598  for( UInt uSliceID = getNumAllocatedSlice() - 1 ; bSameRefInfo && uSliceID > 0 ; uSliceID-- )
599  {
600    TComSlice * pSliceN = getSlice( uSliceID );
601    if( pSlice0->getSliceType() != pSliceN->getSliceType() )
602    {
603      bSameRefInfo = false;
604    }
605    else if( pSlice0->getSliceType() != I_SLICE )
606    {
607      Int nListNum = pSlice0->getSliceType() == B_SLICE ? 2 : 1;
608      for( Int nList = 0 ; nList < nListNum ; nList++ )
609      {
610        RefPicList eRefList = ( RefPicList )nList;
611        if( pSlice0->getNumRefIdx( eRefList ) == pSliceN->getNumRefIdx( eRefList ) )
612        {
613          for( Int refIdx = pSlice0->getNumRefIdx( eRefList ) - 1 ; refIdx >= 0 ; refIdx-- )
614          {
615            if( pSlice0->getRefPic( eRefList , refIdx ) != pSliceN->getRefPic( eRefList , refIdx ) )
616            {
617              bSameRefInfo = false;
618              break;
619            }
620          }
621        }
622        else
623        {
624          bSameRefInfo = false;
625          break;
626        }
627      }
628    }
629  }
630
631  return( bSameRefInfo ); 
632}
633#endif //SVC_EXTENSION
634
635//! \}
Note: See TracBrowser for help on using the repository browser.