source: SHVCSoftware/branches/SHM-2.1-multilayers-dev/source/Lib/TLibCommon/TComPic.cpp @ 252

Last change on this file since 252 was 191, checked in by seregin, 12 years ago

unix2dos for *.cpp and *.h

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