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

Last change on this file since 1311 was 475, checked in by nokia, 11 years ago

Integrate auxiliary picture layers (JCTVC-O0041)

  • Property svn:eol-style set to native
File size: 27.6 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-2013, 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#if SVC_EXTENSION
51, m_layerId( 0 )
52#endif
53, m_bUsedByCurr                           (false)
54, m_bIsLongTerm                           (false)
55, m_apcPicSym                             (NULL)
56, m_pcPicYuvPred                          (NULL)
57, m_pcPicYuvResi                          (NULL)
58, m_bReconstructed                        (false)
59, m_bNeededForOutput                      (false)
60, m_uiCurrSliceIdx                        (0)
61, m_pSliceSUMap                           (NULL)
62, m_pbValidSlice                          (NULL)
63, m_sliceGranularityForNDBFilter          (0)
64, m_bIndependentSliceBoundaryForNDBFilter (false)
65, m_bIndependentTileBoundaryForNDBFilter  (false)
66, m_pNDBFilterYuvTmp                      (NULL)
67, m_bCheckLTMSB                           (false)
68{
69#if SVC_EXTENSION
70  memset( m_pcFullPelBaseRec, 0, sizeof( m_pcFullPelBaseRec ) );
71  memset( m_bSpatialEnhLayer, false, sizeof( m_bSpatialEnhLayer ) );
72#endif
73  m_apcPicYuv[0]      = NULL;
74  m_apcPicYuv[1]      = NULL;
75}
76
77TComPic::~TComPic()
78{
79}
80#if SVC_UPSAMPLING
81#if AUXILIARY_PICTURES
82Void TComPic::create( Int iWidth, Int iHeight, ChromaFormat chromaFormatIDC, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
83                      Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual)
84#else
85Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
86                      Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual)
87#endif
88{
89  m_apcPicSym     = new TComPicSym;  m_apcPicSym   ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
90  if (!bIsVirtual)
91  {
92#if AUXILIARY_PICTURES
93    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
94#else
95    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
96#endif
97  }
98#if AUXILIARY_PICTURES
99  m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
100#else
101  m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
102#endif
103
104  for( Int i = 0; i < MAX_LAYERS; i++ )
105  {
106    if( m_bSpatialEnhLayer[i] )
107    {
108#if AUXILIARY_PICTURES
109      m_pcFullPelBaseRec[i] = new TComPicYuv;  m_pcFullPelBaseRec[i]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
110#else
111      m_pcFullPelBaseRec[i] = new TComPicYuv;  m_pcFullPelBaseRec[i]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
112#endif
113    }
114  }
115
116  m_layerId = pcSps ? pcSps->getLayerId() : 0;
117
118  // there are no SEI messages associated with this picture initially
119  if (m_SEIs.size() > 0)
120  {
121    deleteSEIs (m_SEIs);
122  }
123  m_bUsedByCurr = false;
124
125  /* store conformance window parameters with picture */
126  m_conformanceWindow = conformanceWindow;
127 
128  /* store display window parameters with picture */
129  m_defaultDisplayWindow = defaultDisplayWindow;
130
131  /* store number of reorder pics with picture */
132  memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int));
133
134  return;
135}
136#else
137Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
138                      Int *numReorderPics, Bool bIsVirtual)
139
140{
141  m_apcPicSym     = new TComPicSym;  m_apcPicSym   ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
142  if (!bIsVirtual)
143  {
144    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
145  }
146  m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
147 
148  // there are no SEI messages associated with this picture initially
149  if (m_SEIs.size() > 0)
150  {
151    deleteSEIs (m_SEIs);
152  }
153  m_bUsedByCurr = false;
154
155  /* store conformance window parameters with picture */
156  m_conformanceWindow = conformanceWindow;
157 
158  /* store display window parameters with picture */
159  m_defaultDisplayWindow = defaultDisplayWindow;
160
161  /* store number of reorder pics with picture */
162  memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int));
163
164  return;
165}
166#endif
167
168Void TComPic::destroy()
169{
170  if (m_apcPicSym)
171  {
172    m_apcPicSym->destroy();
173    delete m_apcPicSym;
174    m_apcPicSym = NULL;
175  }
176 
177  if (m_apcPicYuv[0])
178  {
179    m_apcPicYuv[0]->destroy();
180    delete m_apcPicYuv[0];
181    m_apcPicYuv[0]  = NULL;
182  }
183 
184  if (m_apcPicYuv[1])
185  {
186    m_apcPicYuv[1]->destroy();
187    delete m_apcPicYuv[1];
188    m_apcPicYuv[1]  = NULL;
189  }
190 
191  deleteSEIs(m_SEIs);
192#if SVC_EXTENSION && SVC_UPSAMPLING
193  for( Int i = 0; i < MAX_LAYERS; i++ )
194  {
195    if( m_bSpatialEnhLayer[i] )
196    {
197      m_pcFullPelBaseRec[i]->destroy();
198      delete m_pcFullPelBaseRec[i];
199      m_pcFullPelBaseRec[i]  = NULL;
200    }
201  }
202#endif
203}
204
205Void TComPic::compressMotion()
206{
207  TComPicSym* pPicSym = getPicSym(); 
208  for ( UInt uiCUAddr = 0; uiCUAddr < pPicSym->getFrameHeightInCU()*pPicSym->getFrameWidthInCU(); uiCUAddr++ )
209  {
210    TComDataCU* pcCU = pPicSym->getCU(uiCUAddr);
211    pcCU->compressMV(); 
212  } 
213}
214
215/** Create non-deblocked filter information
216 * \param pSliceStartAddress array for storing slice start addresses
217 * \param numSlices number of slices in picture
218 * \param sliceGranularityDepth slice granularity
219 * \param bNDBFilterCrossSliceBoundary cross-slice-boundary in-loop filtering; true for "cross".
220 * \param numTiles number of tiles in picture
221 * \param bNDBFilterCrossTileBoundary cross-tile-boundary in-loop filtering; true for "cross".
222 */
223Void TComPic::createNonDBFilterInfo(std::vector<Int> sliceStartAddress, Int sliceGranularityDepth
224                                    ,std::vector<Bool>* LFCrossSliceBoundary
225                                    ,Int numTiles
226                                    ,Bool bNDBFilterCrossTileBoundary)
227{
228  UInt maxNumSUInLCU = getNumPartInCU();
229  UInt numLCUInPic   = getNumCUsInFrame();
230#if REPN_FORMAT_IN_VPS
231  UInt picWidth      = getSlice(0)->getPicWidthInLumaSamples();
232  UInt picHeight     = getSlice(0)->getPicHeightInLumaSamples();
233#else
234  UInt picWidth      = getSlice(0)->getSPS()->getPicWidthInLumaSamples();
235  UInt picHeight     = getSlice(0)->getSPS()->getPicHeightInLumaSamples();
236#endif
237  Int  numLCUsInPicWidth = getFrameWidthInCU();
238  Int  numLCUsInPicHeight= getFrameHeightInCU();
239  UInt maxNumSUInLCUWidth = getNumPartInWidth();
240  UInt maxNumSUInLCUHeight= getNumPartInHeight();
241  Int  numSlices = (Int) sliceStartAddress.size() - 1;
242  m_bIndependentSliceBoundaryForNDBFilter = false;
243  if(numSlices > 1)
244  {
245    for(Int s=0; s< numSlices; s++)
246    {
247      if((*LFCrossSliceBoundary)[s] == false)
248      {
249        m_bIndependentSliceBoundaryForNDBFilter = true;
250      }
251    }
252  }
253  m_sliceGranularityForNDBFilter = sliceGranularityDepth;
254  m_bIndependentTileBoundaryForNDBFilter  = (bNDBFilterCrossTileBoundary)?(false) :((numTiles > 1)?(true):(false));
255
256  m_pbValidSlice = new Bool[numSlices];
257  for(Int s=0; s< numSlices; s++)
258  {
259    m_pbValidSlice[s] = true;
260  }
261  m_pSliceSUMap = new Int[maxNumSUInLCU * numLCUInPic];
262
263  //initialization
264  for(UInt i=0; i< (maxNumSUInLCU * numLCUInPic); i++ )
265  {
266    m_pSliceSUMap[i] = -1;
267  }
268  for( UInt CUAddr = 0; CUAddr < numLCUInPic ; CUAddr++ )
269  {
270    TComDataCU* pcCU = getCU( CUAddr );
271    pcCU->setSliceSUMap(m_pSliceSUMap + (CUAddr* maxNumSUInLCU)); 
272    pcCU->getNDBFilterBlocks()->clear();
273  }
274  m_vSliceCUDataLink.clear();
275
276  m_vSliceCUDataLink.resize(numSlices);
277
278  UInt startAddr, endAddr, firstCUInStartLCU, startLCU, endLCU, lastCUInEndLCU, uiAddr;
279  UInt LPelX, TPelY, LCUX, LCUY;
280  UInt currSU;
281  UInt startSU, endSU;
282
283  for(Int s=0; s< numSlices; s++)
284  {
285    //1st step: decide the real start address
286    startAddr = sliceStartAddress[s];
287    endAddr   = sliceStartAddress[s+1] -1;
288
289    startLCU            = startAddr / maxNumSUInLCU;
290    firstCUInStartLCU   = startAddr % maxNumSUInLCU;
291
292    endLCU              = endAddr   / maxNumSUInLCU;
293    lastCUInEndLCU      = endAddr   % maxNumSUInLCU;   
294
295    uiAddr = m_apcPicSym->getCUOrderMap(startLCU);
296
297    LCUX      = getCU(uiAddr)->getCUPelX();
298    LCUY      = getCU(uiAddr)->getCUPelY();
299    LPelX     = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[firstCUInStartLCU] ];
300    TPelY     = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[firstCUInStartLCU] ];
301    currSU    = firstCUInStartLCU;
302
303    Bool bMoveToNextLCU = false;
304    Bool bSliceInOneLCU = (startLCU == endLCU);
305
306    while(!( LPelX < picWidth ) || !( TPelY < picHeight ))
307    {
308      currSU ++;
309
310      if(bSliceInOneLCU)
311      {
312        if(currSU > lastCUInEndLCU)
313        {
314          m_pbValidSlice[s] = false;
315          break;
316        }
317      }
318
319      if(currSU >= maxNumSUInLCU )
320      {
321        bMoveToNextLCU = true;
322        break;
323      }
324
325      LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ];
326      TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ];
327
328    }
329
330
331    if(!m_pbValidSlice[s])
332    {
333      continue;
334    }
335
336    if(currSU != firstCUInStartLCU)
337    {
338      if(!bMoveToNextLCU)
339      {
340        firstCUInStartLCU = currSU;
341      }
342      else
343      {
344        startLCU++;
345        firstCUInStartLCU = 0;
346        assert( startLCU < getNumCUsInFrame());
347      }
348      assert(startLCU*maxNumSUInLCU + firstCUInStartLCU < endAddr);
349    }
350
351
352    //2nd step: assign NonDBFilterInfo to each processing block
353    for(UInt i= startLCU; i <= endLCU; i++)
354    {
355      startSU = (i == startLCU)?(firstCUInStartLCU):(0);
356      endSU   = (i == endLCU  )?(lastCUInEndLCU   ):(maxNumSUInLCU -1);
357
358      uiAddr = m_apcPicSym->getCUOrderMap(i);
359      Int iTileID= m_apcPicSym->getTileIdxMap(uiAddr);
360
361      TComDataCU* pcCU = getCU(uiAddr);
362      m_vSliceCUDataLink[s].push_back(pcCU);
363
364      createNonDBFilterInfoLCU(iTileID, s, pcCU, startSU, endSU, m_sliceGranularityForNDBFilter, picWidth, picHeight);
365    }
366  }
367
368  //step 3: border availability
369  for(Int s=0; s< numSlices; s++)
370  {
371    if(!m_pbValidSlice[s])
372    {
373      continue;
374    }
375
376    for(Int i=0; i< m_vSliceCUDataLink[s].size(); i++)
377    {
378      TComDataCU* pcCU = m_vSliceCUDataLink[s][i];
379      uiAddr = pcCU->getAddr();
380
381      if(pcCU->getPic()==0)
382      {
383        continue;
384      }
385      Int iTileID= m_apcPicSym->getTileIdxMap(uiAddr);
386      Bool bTopTileBoundary = false, bDownTileBoundary= false, bLeftTileBoundary= false, bRightTileBoundary= false;
387
388      if(m_bIndependentTileBoundaryForNDBFilter)
389      {
390        //left
391        if( uiAddr % numLCUsInPicWidth != 0)
392        {
393          bLeftTileBoundary = ( m_apcPicSym->getTileIdxMap(uiAddr -1) != iTileID )?true:false;
394        }
395        //right
396        if( (uiAddr % numLCUsInPicWidth) != (numLCUsInPicWidth -1) )
397        {
398          bRightTileBoundary = ( m_apcPicSym->getTileIdxMap(uiAddr +1) != iTileID)?true:false;
399        }
400        //top
401        if( uiAddr >= numLCUsInPicWidth)
402        {
403          bTopTileBoundary = (m_apcPicSym->getTileIdxMap(uiAddr - numLCUsInPicWidth) !=  iTileID )?true:false;
404        }
405        //down
406        if( uiAddr + numLCUsInPicWidth < numLCUInPic )
407        {
408          bDownTileBoundary = (m_apcPicSym->getTileIdxMap(uiAddr + numLCUsInPicWidth) != iTileID)?true:false;
409        }
410
411      }
412
413      pcCU->setNDBFilterBlockBorderAvailability(numLCUsInPicWidth, numLCUsInPicHeight, maxNumSUInLCUWidth, maxNumSUInLCUHeight,picWidth, picHeight
414        , *LFCrossSliceBoundary
415        ,bTopTileBoundary, bDownTileBoundary, bLeftTileBoundary, bRightTileBoundary
416        ,m_bIndependentTileBoundaryForNDBFilter);
417
418    }
419
420  }
421
422  if( m_bIndependentSliceBoundaryForNDBFilter || m_bIndependentTileBoundaryForNDBFilter)
423  {
424    m_pNDBFilterYuvTmp = new TComPicYuv();
425#if AUXILIARY_PICTURES
426    m_pNDBFilterYuvTmp->create(picWidth, picHeight, getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
427#else
428    m_pNDBFilterYuvTmp->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
429#endif
430
431  }
432
433}
434
435/** Create non-deblocked filter information for LCU
436 * \param tileID tile index
437 * \param sliceID slice index
438 * \param pcCU CU data pointer
439 * \param startSU start SU index in LCU
440 * \param endSU end SU index in LCU
441 * \param sliceGranularyDepth slice granularity
442 * \param picWidth picture width
443 * \param picHeight picture height
444 */
445Void TComPic::createNonDBFilterInfoLCU(Int tileID, Int sliceID, TComDataCU* pcCU, UInt startSU, UInt endSU, Int sliceGranularyDepth, UInt picWidth, UInt picHeight)
446{
447  UInt LCUX          = pcCU->getCUPelX();
448  UInt LCUY          = pcCU->getCUPelY();
449  Int* pCUSliceMap    = pcCU->getSliceSUMap();
450  UInt maxNumSUInLCU = getNumPartInCU();
451  UInt maxNumSUInSGU = maxNumSUInLCU >> (sliceGranularyDepth << 1);
452  UInt maxNumSUInLCUWidth = getNumPartInWidth();
453  UInt LPelX, TPelY;
454  UInt currSU;
455
456
457  //get the number of valid NBFilterBLock
458  currSU   = startSU;
459  while(currSU <= endSU)
460  {
461    LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ];
462    TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ];
463
464    while(!( LPelX < picWidth ) || !( TPelY < picHeight ))
465    {
466      currSU += maxNumSUInSGU;
467      if(currSU >= maxNumSUInLCU || currSU > endSU)
468      {
469        break;
470      }
471      LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ];
472      TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ];
473    }
474
475    if(currSU >= maxNumSUInLCU || currSU > endSU)
476    {
477      break;
478    }
479
480    NDBFBlockInfo NDBFBlock;
481
482    NDBFBlock.tileID  = tileID;
483    NDBFBlock.sliceID = sliceID;
484    NDBFBlock.posY    = TPelY;
485    NDBFBlock.posX    = LPelX;
486    NDBFBlock.startSU = currSU;
487
488    UInt uiLastValidSU  = currSU;
489    UInt uiIdx, uiLPelX_su, uiTPelY_su;
490    for(uiIdx = currSU; uiIdx < currSU + maxNumSUInSGU; uiIdx++)
491    {
492      if(uiIdx > endSU)
493      {
494        break;       
495      }
496      uiLPelX_su   = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
497      uiTPelY_su   = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
498      if( !(uiLPelX_su < picWidth ) || !( uiTPelY_su < picHeight ))
499      {
500        continue;
501      }
502      pCUSliceMap[uiIdx] = sliceID;
503      uiLastValidSU = uiIdx;
504    }
505    NDBFBlock.endSU = uiLastValidSU;
506
507    UInt rTLSU = g_auiZscanToRaster[ NDBFBlock.startSU ];
508    UInt rBRSU = g_auiZscanToRaster[ NDBFBlock.endSU   ];
509    NDBFBlock.widthSU  = (rBRSU % maxNumSUInLCUWidth) - (rTLSU % maxNumSUInLCUWidth)+ 1;
510    NDBFBlock.heightSU = (UInt)(rBRSU / maxNumSUInLCUWidth) - (UInt)(rTLSU / maxNumSUInLCUWidth)+ 1;
511    NDBFBlock.width    = NDBFBlock.widthSU  * getMinCUWidth();
512    NDBFBlock.height   = NDBFBlock.heightSU * getMinCUHeight();
513
514    pcCU->getNDBFilterBlocks()->push_back(NDBFBlock);
515
516    currSU += maxNumSUInSGU;
517  }
518
519}
520
521/** destroy non-deblocked filter information for LCU
522 */
523Void TComPic::destroyNonDBFilterInfo()
524{
525  if(m_pbValidSlice != NULL)
526  {
527    delete[] m_pbValidSlice;
528    m_pbValidSlice = NULL;
529  }
530
531  if(m_pSliceSUMap != NULL)
532  {
533    delete[] m_pSliceSUMap;
534    m_pSliceSUMap = NULL;
535  }
536  for( UInt CUAddr = 0; CUAddr < getNumCUsInFrame() ; CUAddr++ )
537  {
538    TComDataCU* pcCU = getCU( CUAddr );
539    pcCU->getNDBFilterBlocks()->clear();
540  }
541
542  if( m_bIndependentSliceBoundaryForNDBFilter || m_bIndependentTileBoundaryForNDBFilter)
543  {
544    m_pNDBFilterYuvTmp->destroy();
545    delete m_pNDBFilterYuvTmp;
546    m_pNDBFilterYuvTmp = NULL;
547  }
548
549}
550
551#if SVC_EXTENSION
552Void copyOnetoOnePicture(    // SVC_NONCOLL
553                  Pel *in,       
554                  Pel *out,     
555                  Int nCols,
556                  Int nRows, 
557                  Int fullRowWidth)
558{
559  Int rX;
560
561  for (rX = 0; rX < nRows; rX++)       
562  {
563    memcpy( out, in, sizeof(Pel) * nCols );
564    in = in + fullRowWidth;
565    out = out + fullRowWidth;
566  }
567}
568
569Void TComPic::copyUpsampledPictureYuv(TComPicYuv*   pcPicYuvIn, TComPicYuv*   pcPicYuvOut)
570{
571  Int upsampledRowWidthLuma = pcPicYuvOut->getStride(); // 2 * pcPicYuvOut->getLumaMargin() + pcPicYuvOut->getWidth();
572  Int upsampledRowWidthCroma = pcPicYuvOut->getCStride(); //2 * pcPicYuvOut->getChromaMargin() + (pcPicYuvOut->getWidth()>>1);
573
574  copyOnetoOnePicture(
575    pcPicYuvIn->getLumaAddr(),       
576    pcPicYuvOut->getLumaAddr(),     
577    pcPicYuvOut->getWidth(), 
578    pcPicYuvOut->getHeight(),
579    upsampledRowWidthLuma);
580  copyOnetoOnePicture(
581    pcPicYuvIn->getCrAddr(),       
582    pcPicYuvOut->getCrAddr(),     
583    pcPicYuvOut->getWidth()>>1, 
584    pcPicYuvOut->getHeight()>>1,
585    upsampledRowWidthCroma);
586  copyOnetoOnePicture(
587    pcPicYuvIn->getCbAddr(),       
588    pcPicYuvOut->getCbAddr(),     
589    pcPicYuvOut->getWidth()>>1, 
590    pcPicYuvOut->getHeight()>>1,
591    upsampledRowWidthCroma);
592}
593
594#if REF_IDX_MFM
595Void TComPic::copyUpsampledMvField(UInt refLayerIdc, TComPic* pcPicBase)
596{
597  UInt numPartitions   = 1<<(g_uiMaxCUDepth<<1);
598  UInt widthMinPU      = g_uiMaxCUWidth/(1<<g_uiMaxCUDepth);
599  UInt heightMinPU     = g_uiMaxCUHeight/(1<<g_uiMaxCUDepth);
600  Int  unitNum         = max (1, (Int)((16/widthMinPU)*(16/heightMinPU)) ); 
601
602  for(UInt cuIdx = 0; cuIdx < getPicSym()->getNumberOfCUsInFrame(); cuIdx++)  //each LCU
603  {
604    TComDataCU* pcCUDes = getCU(cuIdx);
605
606    for(UInt absPartIdx = 0; absPartIdx < numPartitions; absPartIdx+=unitNum )  //each 16x16 unit
607    {
608      //pixel position of each unit in up-sampled layer
609      UInt  pelX = pcCUDes->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[absPartIdx] ];
610      UInt  pelY = pcCUDes->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[absPartIdx] ];
611      UInt baseCUAddr, baseAbsPartIdx;
612
613      TComDataCU *pcColCU = 0;
614      pcColCU = pcCUDes->getBaseColCU(refLayerIdc, pelX + 8, pelY + 8, baseCUAddr, baseAbsPartIdx, 1);
615
616      if( pcColCU && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_NONE) && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_INTRA) )  //base layer unit not skip and invalid mode
617      {
618        for(UInt refPicList = 0; refPicList < 2; refPicList++)  //for each reference list
619        {
620          TComMvField sMvFieldBase, sMvField;
621          pcColCU->getMvField( pcColCU, baseAbsPartIdx, (RefPicList)refPicList, sMvFieldBase);
622          pcCUDes->scaleBaseMV( refLayerIdc, sMvField, sMvFieldBase );
623
624          pcCUDes->getCUMvField((RefPicList)refPicList)->setMvField(sMvField, absPartIdx);
625          pcCUDes->setPredictionMode(absPartIdx, MODE_INTER);
626        }
627      }
628      else
629      {
630        TComMvField zeroMvField;  //zero MV and invalid reference index
631        pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(zeroMvField, absPartIdx);
632        pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(zeroMvField, absPartIdx);
633        pcCUDes->setPredictionMode(absPartIdx, MODE_INTRA);
634      }
635
636      for(UInt i = 1; i < unitNum; i++ ) 
637      {
638        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);
639        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);
640        pcCUDes->setPredictionMode(absPartIdx+i, pcCUDes->getPredictionMode(absPartIdx));
641      }
642    }
643    memset( pcCUDes->getPartitionSize(), SIZE_2Nx2N, sizeof(Char)*numPartitions);
644  }
645}
646
647Void TComPic::initUpsampledMvField()
648{
649  UInt uiNumPartitions   = 1<<(g_uiMaxCUDepth<<1);
650
651  for(UInt cuIdx = 0; cuIdx < getPicSym()->getNumberOfCUsInFrame(); cuIdx++)  //each LCU
652  {
653    TComDataCU* pcCUDes = getCU(cuIdx);
654    TComMvField zeroMvField;
655    for(UInt list = 0; list < 2; list++)  //each reference list
656    {
657      for(UInt i = 0; i < uiNumPartitions; i++ ) 
658      {
659        pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(zeroMvField, i);
660        pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(zeroMvField, i);
661        pcCUDes->setPredictionMode(i, MODE_INTRA);
662        pcCUDes->setPartitionSize(i, SIZE_2Nx2N);
663      }
664    }
665  }
666  return;
667}
668#endif
669#endif
670
671#if AVC_SYNTAX
672Void TComPic::readBLSyntax( fstream* filestream, UInt numBytes )
673{
674  if( !filestream->good() )
675  {
676    return;
677  }
678
679  UInt   width      = this->getPicYuvRec()->getWidth();
680  UInt   height     = this->getPicYuvRec()->getHeight();
681
682  UInt64 poc        = (UInt64)this->getPOC();
683  UInt   partWidth  = width / 4;
684  UInt   partHeight = height / 4;
685
686  UInt numPartInWidth    = this->getNumPartInWidth();
687  UInt numPartInHeight   = this->getNumPartInHeight();
688  UInt numPartLCUInWidth = this->getFrameWidthInCU();
689
690  UInt64 uiPos = (UInt64)poc * width * height * numBytes / 16;
691   
692  filestream->seekg( uiPos, ios_base::beg );
693
694  for( Int i = 0; i < partHeight; i++ )
695  {
696    for( Int j = 0; j < partWidth; j++ )
697    {
698      UInt x = ( j / numPartInWidth );
699      UInt y = ( i / numPartInHeight );
700
701      UInt addrLCU = y * numPartLCUInWidth + x;
702      UInt partAddr = ( i - y * numPartInHeight ) * numPartInWidth + ( j - x * numPartInWidth );
703      partAddr = g_auiRasterToZscan[partAddr];
704     
705      TComDataCU* pcCU = this->getCU( addrLCU );
706     
707      TComMv mv;
708      Short temp;
709
710      // RefIdxL0
711      Char refIdxL0 = -1;
712      filestream->read( &refIdxL0, 1 );
713      assert( refIdxL0 >= -1 );
714      pcCU->getCUMvField( REF_PIC_LIST_0 )->setRefIdx( (Int)refIdxL0, partAddr );
715
716      // RefIdxL1
717      Char refIdxL1 = -1;
718      filestream->read( &refIdxL1, 1 );
719      assert( refIdxL1 >= -1 );
720      pcCU->getCUMvField( REF_PIC_LIST_1 )->setRefIdx( (Int)refIdxL1, partAddr );
721
722      // MV L0
723      temp = 0;
724      filestream->read( reinterpret_cast<char*>(&temp), 2 );
725      mv.setHor( (Short)temp );
726      temp = 0;
727      filestream->read( reinterpret_cast<char*>(&temp), 2 );
728      mv.setVer( (Short)temp );
729      pcCU->getCUMvField( REF_PIC_LIST_0 )->setMv( mv, partAddr );
730
731      // MV L1
732      temp = 0;
733      filestream->read( reinterpret_cast<char*>(&temp), 2 );
734      mv.setHor( (Short)temp );
735      temp = 0;
736      filestream->read( reinterpret_cast<char*>(&temp), 2 );
737      mv.setVer( (Short)temp );
738      pcCU->getCUMvField( REF_PIC_LIST_1 )->setMv( mv, partAddr );
739
740      // set dependent information
741      pcCU->setPredictionMode( partAddr, ( refIdxL0 == NOT_VALID && refIdxL1 == NOT_VALID ) ? MODE_INTRA : MODE_INTER );
742      UInt interDir = ( refIdxL0 != NOT_VALID ) + ( refIdxL1 != NOT_VALID && this->getSlice(0)->isInterB() ) * 2;
743      assert( interDir <= 3 );
744      pcCU->setInterDir( partAddr, interDir );     
745    }
746  }
747}
748#endif
749
750#if SYNTAX_OUTPUT
751Void TComPic::wrireBLSyntax( fstream* filestream, UInt numBytes )
752{
753  if( !filestream->good() )
754  {
755    return;
756  }
757
758  UInt   width       = this->getPicYuvRec()->getWidth();
759  UInt   height      = this->getPicYuvRec()->getHeight();
760
761  UInt64 poc        = (UInt64)this->getPOC();
762  UInt   partWidth  = width / 4;
763  UInt   partHeight = height / 4;
764
765  UInt numPartInWidth    = this->getNumPartInWidth();
766  UInt numPartInHeight   = this->getNumPartInHeight();
767  UInt numPartLCUInWidth = this->getFrameWidthInCU();
768
769  filestream->seekg( poc * width * height * numBytes / 16 );
770   
771  for( Int i = 0; i < partHeight; i++ )
772  {
773    for( Int j = 0; j < partWidth; j++ )
774    {
775      UInt x = ( j / numPartInWidth );
776      UInt y = ( i / numPartInHeight );
777
778      UInt addrLCU = y * numPartLCUInWidth + x;
779      UInt partAddr = ( i - y * numPartInHeight ) * numPartInWidth + ( j - x * numPartInWidth );
780      partAddr = g_auiRasterToZscan[partAddr];
781     
782      TComDataCU* pcCU = this->getCU( addrLCU );
783     
784      TComMv mv;
785      Short temp;
786      Char refIdxL0 = NOT_VALID, refIdxL1 = NOT_VALID;
787
788      // RefIdx
789      if( !pcCU->isIntra( partAddr ) )
790      {
791        refIdxL0 = (Char)pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( partAddr );
792        refIdxL1 = (Char)pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( partAddr );
793      }
794      assert( refIdxL0 >= - 1 && refIdxL1 >= - 1 );
795      filestream->put( refIdxL0 );
796      filestream->put( refIdxL1 );
797
798      // MV L0
799      mv.setZero();
800      if( refIdxL0 >= 0 )
801      {
802        mv = pcCU->getCUMvField( REF_PIC_LIST_0 )->getMv( partAddr );
803      }
804      temp = (Short)mv.getHor();
805      filestream->write( reinterpret_cast<char*>(&temp), 2 );
806      temp = (Short)mv.getVer();
807      filestream->write( reinterpret_cast<char*>(&temp), 2 );
808
809      // MV L1
810      mv.setZero();
811      if( refIdxL1 >= 0 )
812      {
813        mv = pcCU->getCUMvField( REF_PIC_LIST_1 )->getMv( partAddr );
814      }
815      temp = (Short)mv.getHor();
816      filestream->write( reinterpret_cast<char*>(&temp), 2 );
817      temp = (Short)mv.getVer();
818      filestream->write( reinterpret_cast<char*>(&temp), 2 );
819    }
820  }
821}
822#endif
823
824#if MFM_ENCCONSTRAINT
825Bool TComPic::checkSameRefInfo()
826{
827  Bool bSameRefInfo = true;
828  TComSlice * pSlice0 = getSlice( 0 );
829  for( UInt uSliceID = getNumAllocatedSlice() - 1 ; bSameRefInfo && uSliceID > 0 ; uSliceID-- )
830  {
831    TComSlice * pSliceN = getSlice( uSliceID );
832    if( pSlice0->getSliceType() != pSliceN->getSliceType() )
833    {
834      bSameRefInfo = false;
835    }
836    else if( pSlice0->getSliceType() != I_SLICE )
837    {
838      Int nListNum = pSlice0->getSliceType() == B_SLICE ? 2 : 1;
839      for( Int nList = 0 ; nList < nListNum ; nList++ )
840      {
841        RefPicList eRefList = ( RefPicList )nList;
842        if( pSlice0->getNumRefIdx( eRefList ) == pSliceN->getNumRefIdx( eRefList ) )
843        {
844          for( Int refIdx = pSlice0->getNumRefIdx( eRefList ) - 1 ; refIdx >= 0 ; refIdx-- )
845          {
846            if( pSlice0->getRefPic( eRefList , refIdx ) != pSliceN->getRefPic( eRefList , refIdx ) )
847            {
848              bSameRefInfo = false;
849              break;
850            }
851          }
852        }
853        else
854        {
855          bSameRefInfo = false;
856          break;
857        }
858      }
859    }
860  }
861
862  return( bSameRefInfo ); 
863}
864#endif
865
866//! \}
Note: See TracBrowser for help on using the repository browser.