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

Last change on this file since 389 was 389, checked in by qualcomm, 12 years ago

Signaling representation format in VPS (MACRO: REPN_FORMAT_IN_VPS)

Includes signaling of representation format - including picture resolution, bit depth, chroma format - in the VPS, with the option of updating them in the SPS. The configuration file has "RepFormatIdx%d" added to indicate for each layer which representation format is used. The rep_format() structures are automatically created by the encoder. If the bit depth and the chroma format are also changed across layers, some more configuration support would be needed.

From: Adarsh K. Ramasubramonian <aramasub@…>

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