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

Last change on this file since 915 was 431, checked in by seregin, 11 years ago

initial porting of HM12

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