Changeset 1386 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComPicYuv.cpp


Ignore:
Timestamp:
13 Nov 2015, 16:29:39 (8 years ago)
Author:
tech
Message:

Merged 15.1-dev1@1381.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibCommon/TComPicYuv.cpp

    r1313 r1386  
    7979
    8080
    81 Void TComPicYuv::create ( const Int iPicWidth,                ///< picture width
    82                           const Int iPicHeight,               ///< picture height
     81Void TComPicYuv::createWithoutCUInfo ( const Int picWidth,                 ///< picture width
     82                                       const Int picHeight,                ///< picture height
     83                                       const ChromaFormat chromaFormatIDC, ///< chroma format
     84                                       const Bool bUseMargin,              ///< if true, then a margin of uiMaxCUWidth+16 and uiMaxCUHeight+16 is created around the image.
     85                                       const UInt maxCUWidth,              ///< used for margin only
     86                                       const UInt maxCUHeight)             ///< used for margin only
     87
     88{
     89  m_picWidth          = picWidth;
     90  m_picHeight         = picHeight;
     91
     92#if NH_3D_IV_MERGE
     93  m_iCuWidth        = maxCUWidth;
     94  m_iCuHeight       = maxCUHeight;
     95
     96  m_iNumCuInWidth   = picWidth / m_iCuWidth;
     97  m_iNumCuInWidth  += ( picHeight % m_iCuWidth ) ? 1 : 0;
     98  // Check if m_iBaseUnitWidth and m_iBaseUnitHeight need to be derived here
     99#endif
     100
     101  m_chromaFormatIDC   = chromaFormatIDC;
     102  m_marginX          = (bUseMargin?maxCUWidth:0) + 16;   // for 16-byte alignment
     103  m_marginY          = (bUseMargin?maxCUHeight:0) + 16;  // margin for 8-tap filter and infinite padding
     104  m_bIsBorderExtended = false;
     105
     106  // assign the picture arrays and set up the ptr to the top left of the original picture
     107  for(UInt comp=0; comp<getNumberValidComponents(); comp++)
     108  {
     109    const ComponentID ch=ComponentID(comp);
     110    m_apiPicBuf[comp] = (Pel*)xMalloc( Pel, getStride(ch) * getTotalHeight(ch));
     111    m_piPicOrg[comp]  = m_apiPicBuf[comp] + (m_marginY >> getComponentScaleY(ch)) * getStride(ch) + (m_marginX >> getComponentScaleX(ch));
     112  }
     113  // initialize pointers for unused components to NULL
     114  for(UInt comp=getNumberValidComponents();comp<MAX_NUM_COMPONENT; comp++)
     115  {
     116    m_apiPicBuf[comp] = NULL;
     117    m_piPicOrg[comp]  = NULL;
     118  }
     119
     120  for(Int chan=0; chan<MAX_NUM_CHANNEL_TYPE; chan++)
     121    {
     122    m_ctuOffsetInBuffer[chan]   = NULL;
     123    m_subCuOffsetInBuffer[chan] = NULL;
     124    }
     125  }
     126
     127
     128
     129Void TComPicYuv::create ( const Int picWidth,                 ///< picture width
     130                          const Int picHeight,                ///< picture height
    83131                          const ChromaFormat chromaFormatIDC, ///< chroma format
    84                           const UInt uiMaxCUWidth,            ///< used for generating offsets to CUs. Can use iPicWidth if no offsets are required
    85                           const UInt uiMaxCUHeight,           ///< used for generating offsets to CUs. Can use iPicHeight if no offsets are required
    86                           const UInt uiMaxCUDepth,            ///< used for generating offsets to CUs. Can use 0 if no offsets are required
     132                          const UInt maxCUWidth,              ///< used for generating offsets to CUs.
     133                          const UInt maxCUHeight,             ///< used for generating offsets to CUs.
     134                          const UInt maxCUDepth,              ///< used for generating offsets to CUs.
    87135                          const Bool bUseMargin)              ///< if true, then a margin of uiMaxCUWidth+16 and uiMaxCUHeight+16 is created around the image.
    88136
    89137{
    90   m_iPicWidth         = iPicWidth;
    91   m_iPicHeight        = iPicHeight;
     138  createWithoutCUInfo(picWidth, picHeight, chromaFormatIDC, bUseMargin, maxCUWidth, maxCUHeight);
    92139
    93140#if NH_3D_IV_MERGE
    94   m_iCuWidth        = uiMaxCUWidth;
    95   m_iCuHeight       = uiMaxCUHeight;
    96 
    97   m_iNumCuInWidth   = m_iPicWidth / m_iCuWidth;
    98   m_iNumCuInWidth  += ( m_iPicWidth % m_iCuWidth ) ? 1 : 0;
    99 
    100   m_iBaseUnitWidth  = uiMaxCUWidth  >> uiMaxCUDepth;
    101   m_iBaseUnitHeight = uiMaxCUHeight >> uiMaxCUDepth;
    102 #endif
    103 
    104   m_chromaFormatIDC   = chromaFormatIDC;
    105   m_iMarginX          = (bUseMargin?uiMaxCUWidth:0) + 16;   // for 16-byte alignment
    106   m_iMarginY          = (bUseMargin?uiMaxCUHeight:0) + 16;  // margin for 8-tap filter and infinite padding
    107   m_bIsBorderExtended = false;
    108 
    109   // assign the picture arrays and set up the ptr to the top left of the original picture
    110   {
    111     Int chan=0;
    112     for(; chan<getNumberValidComponents(); chan++)
    113     {
    114       const ComponentID ch=ComponentID(chan);
    115       m_apiPicBuf[chan] = (Pel*)xMalloc( Pel, getStride(ch)       * getTotalHeight(ch));
    116       m_piPicOrg[chan]  = m_apiPicBuf[chan] + (m_iMarginY >> getComponentScaleY(ch))   * getStride(ch)       + (m_iMarginX >> getComponentScaleX(ch));
    117     }
    118     for(;chan<MAX_NUM_COMPONENT; chan++)
    119     {
    120       m_apiPicBuf[chan] = NULL;
    121       m_piPicOrg[chan]  = NULL;
    122     }
    123   }
    124 
    125 
    126   const Int numCuInWidth  = m_iPicWidth  / uiMaxCUWidth  + (m_iPicWidth  % uiMaxCUWidth  != 0);
    127   const Int numCuInHeight = m_iPicHeight / uiMaxCUHeight + (m_iPicHeight % uiMaxCUHeight != 0);
    128   for(Int chan=0; chan<2; chan++)
    129   {
    130     const ComponentID ch=ComponentID(chan);
    131     const Int ctuHeight=uiMaxCUHeight>>getComponentScaleY(ch);
    132     const Int ctuWidth=uiMaxCUWidth>>getComponentScaleX(ch);
     141  m_iBaseUnitWidth  = maxCUWidth  >> maxCUDepth;
     142  m_iBaseUnitHeight = maxCUHeight >> maxCUDepth;
     143#endif
     144
     145
     146  const Int numCuInWidth  = m_picWidth  / maxCUWidth  + (m_picWidth  % maxCUWidth  != 0);
     147  const Int numCuInHeight = m_picHeight / maxCUHeight + (m_picHeight % maxCUHeight != 0);
     148  for(Int chan=0; chan<MAX_NUM_CHANNEL_TYPE; chan++)
     149  {
     150    const ChannelType ch= ChannelType(chan);
     151    const Int ctuHeight = maxCUHeight>>getChannelTypeScaleY(ch);
     152    const Int ctuWidth  = maxCUWidth>>getChannelTypeScaleX(ch);
    133153    const Int stride = getStride(ch);
    134154
     
    143163    }
    144164
    145     m_subCuOffsetInBuffer[chan] = new Int[(size_t)1 << (2 * uiMaxCUDepth)];
    146 
    147     const Int numSubBlockPartitions=(1<<uiMaxCUDepth);
    148     const Int minSubBlockHeight    =(ctuHeight >> uiMaxCUDepth);
    149     const Int minSubBlockWidth     =(ctuWidth  >> uiMaxCUDepth);
     165    m_subCuOffsetInBuffer[chan] = new Int[(size_t)1 << (2 * maxCUDepth)];
     166
     167    const Int numSubBlockPartitions=(1<<maxCUDepth);
     168    const Int minSubBlockHeight    =(ctuHeight >> maxCUDepth);
     169    const Int minSubBlockWidth     =(ctuWidth  >> maxCUDepth);
    150170
    151171    for (Int buRow = 0; buRow < numSubBlockPartitions; buRow++)
     
    153173      for (Int buCol = 0; buCol < numSubBlockPartitions; buCol++)
    154174      {
    155         m_subCuOffsetInBuffer[chan][(buRow << uiMaxCUDepth) + buCol] = stride  * buRow * minSubBlockHeight + buCol * minSubBlockWidth;
    156       }
    157     }
    158   }
    159   return;
     175        m_subCuOffsetInBuffer[chan][(buRow << maxCUDepth) + buCol] = stride  * buRow * minSubBlockHeight + buCol * minSubBlockWidth;
     176      }
     177    }
     178  }
    160179}
    161180
     
    164183Void TComPicYuv::destroy()
    165184{
    166   for(Int chan=0; chan<MAX_NUM_COMPONENT; chan++)
    167   {
    168     m_piPicOrg[chan] = NULL;
    169 
    170     if( m_apiPicBuf[chan] )
    171     {
    172       xFree( m_apiPicBuf[chan] );
    173       m_apiPicBuf[chan] = NULL;
     185  for(Int comp=0; comp<MAX_NUM_COMPONENT; comp++)
     186  {
     187    m_piPicOrg[comp] = NULL;
     188
     189    if( m_apiPicBuf[comp] )
     190    {
     191      xFree( m_apiPicBuf[comp] );
     192      m_apiPicBuf[comp] = NULL;
    174193    }
    175194  }
     
    194213Void  TComPicYuv::copyToPic (TComPicYuv*  pcPicYuvDst) const
    195214{
    196   assert( m_iPicWidth  == pcPicYuvDst->getWidth(COMPONENT_Y)  );
    197   assert( m_iPicHeight == pcPicYuvDst->getHeight(COMPONENT_Y) );
    198215  assert( m_chromaFormatIDC == pcPicYuvDst->getChromaFormat() );
    199216
    200   for(Int chan=0; chan<getNumberValidComponents(); chan++)
    201   {
    202     const ComponentID ch=ComponentID(chan);
    203     ::memcpy ( pcPicYuvDst->getBuf(ch), m_apiPicBuf[ch], sizeof (Pel) * getStride(ch) * getTotalHeight(ch));
    204   }
    205   return;
     217  for(Int comp=0; comp<getNumberValidComponents(); comp++)
     218  {
     219    const ComponentID compId=ComponentID(comp);
     220    const Int width     = getWidth(compId);
     221    const Int height    = getHeight(compId);
     222    const Int strideSrc = getStride(compId);
     223    assert(pcPicYuvDst->getWidth(compId) == width);
     224    assert(pcPicYuvDst->getHeight(compId) == height);
     225    if (strideSrc==pcPicYuvDst->getStride(compId))
     226  {
     227      ::memcpy ( pcPicYuvDst->getBuf(compId), getBuf(compId), sizeof(Pel)*strideSrc*getTotalHeight(compId));
     228    }
     229    else
     230    {
     231      const Pel *pSrc       = getAddr(compId);
     232            Pel *pDest      = pcPicYuvDst->getAddr(compId);
     233      const UInt strideDest = pcPicYuvDst->getStride(compId);
     234
     235      for(Int y=0; y<height; y++, pSrc+=strideSrc, pDest+=strideDest)
     236      {
     237        ::memcpy(pDest, pSrc, width*sizeof(Pel));
     238      }
     239    }
     240  }
    206241}
    207242
     
    214249  }
    215250
    216   for(Int chan=0; chan<getNumberValidComponents(); chan++)
    217   {
    218     const ComponentID ch=ComponentID(chan);
    219     Pel *piTxt=getAddr(ch); // piTxt = point to (0,0) of image within bigger picture.
    220     const Int iStride=getStride(ch);
    221     const Int iWidth=getWidth(ch);
    222     const Int iHeight=getHeight(ch);
    223     const Int iMarginX=getMarginX(ch);
    224     const Int iMarginY=getMarginY(ch);
     251  for(Int comp=0; comp<getNumberValidComponents(); comp++)
     252  {
     253    const ComponentID compId=ComponentID(comp);
     254    Pel *piTxt=getAddr(compId); // piTxt = point to (0,0) of image within bigger picture.
     255    const Int stride=getStride(compId);
     256    const Int width=getWidth(compId);
     257    const Int height=getHeight(compId);
     258    const Int marginX=getMarginX(compId);
     259    const Int marginY=getMarginY(compId);
    225260
    226261    Pel*  pi = piTxt;
    227262    // do left and right margins
    228     for (Int y = 0; y < iHeight; y++)
    229     {
    230       for (Int x = 0; x < iMarginX; x++ )
    231       {
    232         pi[ -iMarginX + x ] = pi[0];
    233         pi[    iWidth + x ] = pi[iWidth-1];
    234       }
    235       pi += iStride;
     263    for (Int y = 0; y < height; y++)
     264    {
     265      for (Int x = 0; x < marginX; x++ )
     266      {
     267        pi[ -marginX + x ] = pi[0];
     268        pi[    width + x ] = pi[width-1];
     269      }
     270      pi += stride;
    236271    }
    237272
    238273    // pi is now the (0,height) (bottom left of image within bigger picture
    239     pi -= (iStride + iMarginX);
     274    pi -= (stride + marginX);
    240275    // pi is now the (-marginX, height-1)
    241     for (Int y = 0; y < iMarginY; y++ )
    242     {
    243       ::memcpy( pi + (y+1)*iStride, pi, sizeof(Pel)*(iWidth + (iMarginX<<1)) );
     276    for (Int y = 0; y < marginY; y++ )
     277    {
     278      ::memcpy( pi + (y+1)*stride, pi, sizeof(Pel)*(width + (marginX<<1)) );
    244279    }
    245280
    246281    // pi is still (-marginX, height-1)
    247     pi -= ((iHeight-1) * iStride);
     282    pi -= ((height-1) * stride);
    248283    // pi is now (-marginX, 0)
    249     for (Int y = 0; y < iMarginY; y++ )
    250     {
    251       ::memcpy( pi - (y+1)*iStride, pi, sizeof(Pel)*(iWidth + (iMarginX<<1)) );
     284    for (Int y = 0; y < marginY; y++ )
     285    {
     286      ::memcpy( pi - (y+1)*stride, pi, sizeof(Pel)*(width + (marginX<<1)) );
    252287    }
    253288  }
     
    259294
    260295// NOTE: This function is never called, but may be useful for developers.
    261 Void TComPicYuv::dump (const Char* pFileName, const BitDepths &bitDepths, Bool bAdd) const
    262 {
    263   FILE* pFile;
    264   if (!bAdd)
    265   {
    266     pFile = fopen (pFileName, "wb");
    267   }
    268   else
    269   {
    270     pFile = fopen (pFileName, "ab");
    271   }
    272 
    273 
    274   for(Int chan = 0; chan < getNumberValidComponents(); chan++)
    275   {
    276     const ComponentID  ch     = ComponentID(chan);
    277     const Int          shift  = bitDepths.recon[toChannelType(ch)] - 8;
    278     const Int          offset = (shift>0)?(1<<(shift-1)):0;
    279     const Pel         *pi     = getAddr(ch);
    280     const Int          stride = getStride(ch);
    281     const Int          height = getHeight(ch);
    282     const Int          width  = getWidth(ch);
    283 
     296Void TComPicYuv::dump (const std::string &fileName, const BitDepths &bitDepths, const Bool bAppend, const Bool bForceTo8Bit) const
     297{
     298  FILE *pFile = fopen (fileName.c_str(), bAppend?"ab":"wb");
     299
     300  Bool is16bit=false;
     301  for(Int comp = 0; comp < getNumberValidComponents() && !bForceTo8Bit; comp++)
     302  {
     303    if (bitDepths.recon[toChannelType(ComponentID(comp))]>8)
     304  {
     305      is16bit=true;
     306    }
     307  }
     308
     309  for(Int comp = 0; comp < getNumberValidComponents(); comp++)
     310  {
     311    const ComponentID  compId = ComponentID(comp);
     312    const Pel         *pi     = getAddr(compId);
     313    const Int          stride = getStride(compId);
     314    const Int          height = getHeight(compId);
     315    const Int          width  = getWidth(compId);
     316
     317    if (is16bit)
     318    {
    284319    for (Int y = 0; y < height; y++ )
    285320    {
    286321      for (Int x = 0; x < width; x++ )
    287322      {
    288         UChar uc = (UChar)Clip3<Pel>(0, 255, (pi[x]+offset)>>shift);
     323          UChar uc = (UChar)((pi[x]>>0) & 0xff);
    289324        fwrite( &uc, sizeof(UChar), 1, pFile );
     325          uc = (UChar)((pi[x]>>8) & 0xff);
     326          fwrite( &uc, sizeof(UChar), 1, pFile );
    290327      }
    291328      pi += stride;
     329    }
     330  }
     331    else
     332    {
     333      const Int shift  = bitDepths.recon[toChannelType(compId)] - 8;
     334      const Int offset = (shift>0)?(1<<(shift-1)):0;
     335      for (Int y = 0; y < height; y++ )
     336      {
     337        for (Int x = 0; x < width; x++ )
     338        {
     339          UChar uc = (UChar)Clip3<Pel>(0, 255, (pi[x]+offset)>>shift);
     340          fwrite( &uc, sizeof(UChar), 1, pFile );
     341        }
     342        pi += stride;
     343      }
    292344    }
    293345  }
Note: See TracChangeset for help on using the changeset viewer.