Changeset 655 in 3DVCSoftware for trunk/source/Lib/TLibVideoIO


Ignore:
Timestamp:
23 Oct 2013, 23:01:30 (11 years ago)
Author:
tech
Message:

Merged 8.1-Cleanup@654

Location:
trunk/source/Lib/TLibVideoIO
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp

    r608 r655  
    339339}
    340340
     341static Bool writeField(ostream& fd, Pel* top, Pel* bottom, Bool is16bit,
     342                       UInt stride,
     343                       UInt width, UInt height, bool isTff)
     344{
     345  Int write_len = width * (is16bit ? 2 : 1)*2;
     346  UChar *buf = new UChar[write_len];
     347  for (Int y = 0; y < height; y++)
     348  {
     349    if (!is16bit)
     350    {
     351      for (Int x = 0; x < width; x++)
     352      {
     353        buf[x] = isTff ? (UChar) top[x] : (UChar) bottom[x];
     354        buf[width+x] = isTff ? (UChar) bottom[x] : (UChar) top[x];
     355      }
     356    }
     357    else
     358    {
     359      for (Int x = 0; x < width; x++)
     360      {
     361        buf[2*x] = isTff ? top[x] & 0xff : bottom[x] & 0xff;
     362        buf[2*x+1] = isTff ? (top[x] >> 8) & 0xff : (bottom[x] >> 8) & 0xff;
     363       
     364        buf[width+2*x] = isTff ? bottom[x] & 0xff : top[x] & 0xff;
     365        buf[width+2*x+1] = isTff ? (bottom[x] >> 8) & 0xff : (top[x] >> 8) & 0xff;
     366      }
     367    }
     368   
     369    fd.write(reinterpret_cast<Char*>(buf), write_len);
     370    if (fd.eof() || fd.fail() )
     371    {
     372      delete[] buf;
     373      return false;
     374    }
     375    top += stride;
     376    bottom += stride;
     377  }
     378  delete[] buf;
     379  return true;
     380}
    341381/**
    342382 * Read one Y'CbCr frame, performing any required input scaling to change
     
    501541}
    502542
     543
     544/**
     545 * Write one Y'CbCr frame. No bit-depth conversion is performed, pcPicYuv is
     546 * assumed to be at TVideoIO::m_fileBitdepth depth.
     547 *
     548 * @param pPicTop     input top field YUV buffer class pointer
     549 * @param pPicBottom  input bottom field YUV buffer class pointer
     550 * @param aiPad       source padding size, aiPad[0] = horizontal, aiPad[1] = vertical
     551 * @return true for success, false in case of error
     552 */
     553Bool TVideoIOYuv::write( TComPicYuv* pPicTop, TComPicYuv* pPicBottom, Int cropLeft, Int cropRight, Int cropTop, Int cropBottom , bool isTff)
     554{
     555  // compute actual YUV frame size excluding padding size
     556  Int   iStride = pPicTop->getStride();
     557  UInt  width  = pPicTop->getWidth()  - cropLeft - cropRight;
     558  UInt  height = pPicTop->getHeight() - cropTop  - cropBottom;
     559  Bool is16bit = m_fileBitDepthY > 8 || m_fileBitDepthC > 8;
     560 
     561  TComPicYuv *dstPicTop = NULL;
     562  TComPicYuv *dstPicBottom = NULL;
     563 
     564  Bool retval = true;
     565 
     566  if (m_bitDepthShiftY != 0 || m_bitDepthShiftC != 0)
     567  {
     568    dstPicTop = new TComPicYuv;
     569    dstPicTop->create( pPicTop->getWidth(), pPicTop->getHeight(), 1, 1, 0 );
     570    pPicTop->copyToPic(dstPicTop);
     571   
     572    dstPicBottom = new TComPicYuv;
     573    dstPicBottom->create( pPicBottom->getWidth(), pPicBottom->getHeight(), 1, 1, 0 );
     574    pPicBottom->copyToPic(dstPicBottom);
     575   
     576    Pel minvalY = 0;
     577    Pel minvalC = 0;
     578    Pel maxvalY = (1 << m_fileBitDepthY) - 1;
     579    Pel maxvalC = (1 << m_fileBitDepthC) - 1;
     580#if CLIP_TO_709_RANGE
     581    if (-m_bitDepthShiftY < 0 && m_fileBitDepthY >= 8)
     582    {
     583      /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
     584      minvalY = 1 << (m_fileBitDepthY - 8);
     585      maxvalY = (0xff << (m_fileBitDepthY - 8)) -1;
     586    }
     587    if (-m_bitDepthShiftC < 0 && m_fileBitDepthC >= 8)
     588    {
     589      /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
     590      minvalC = 1 << (m_fileBitDepthC - 8);
     591      maxvalC = (0xff << (m_fileBitDepthC - 8)) -1;
     592    }
     593#endif
     594    scalePlane(dstPicTop->getLumaAddr(), dstPicTop->getStride(), dstPicTop->getWidth(), dstPicTop->getHeight(), -m_bitDepthShiftY, minvalY, maxvalY);
     595    scalePlane(dstPicTop->getCbAddr(), dstPicTop->getCStride(), dstPicTop->getWidth()>>1, dstPicTop->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
     596    scalePlane(dstPicTop->getCrAddr(), dstPicTop->getCStride(), dstPicTop->getWidth()>>1, dstPicTop->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
     597   
     598    scalePlane(dstPicBottom->getLumaAddr(), dstPicBottom->getStride(), dstPicBottom->getWidth(), dstPicBottom->getHeight(), -m_bitDepthShiftY, minvalY, maxvalY);
     599    scalePlane(dstPicBottom->getCbAddr(), dstPicBottom->getCStride(), dstPicBottom->getWidth()>>1, dstPicBottom->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
     600    scalePlane(dstPicBottom->getCrAddr(), dstPicBottom->getCStride(), dstPicBottom->getWidth()>>1, dstPicBottom->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
     601  }
     602  else
     603  {
     604    dstPicTop = pPicTop;
     605    dstPicBottom = pPicBottom;
     606  }
     607  // location of upper left pel in a plane
     608  Int planeOffset = 0; //cropLeft + cropTop * iStride;
     609  //Write luma
     610  if (! writeField(m_cHandle, dstPicTop->getLumaAddr() + planeOffset,  dstPicBottom->getLumaAddr() + planeOffset, is16bit, iStride, width, height, isTff))
     611  {
     612    retval=false;
     613    goto exit;
     614  }
     615 
     616  width >>= 1;
     617  height >>= 1;
     618  iStride >>= 1;
     619  cropLeft >>= 1;
     620  cropRight >>= 1;
     621 
     622  planeOffset = 0; // cropLeft + cropTop * iStride;
     623 
     624  //Write chroma U
     625  if (! writeField(m_cHandle, dstPicTop->getCbAddr() + planeOffset, dstPicBottom->getCbAddr() + planeOffset, is16bit, iStride, width, height, isTff))
     626  {
     627    retval=false;
     628    goto exit;
     629  }
     630 
     631  //Write chroma V
     632  if (! writeField(m_cHandle, dstPicTop->getCrAddr() + planeOffset, dstPicBottom->getCrAddr() + planeOffset, is16bit, iStride, width, height, isTff))
     633   
     634  {
     635    retval=false;
     636    goto exit;
     637  }
     638 
     639exit:
     640  if (m_bitDepthShiftY != 0 || m_bitDepthShiftC != 0)
     641  {
     642    dstPicTop->destroy();
     643    delete dstPicTop;
     644    dstPicBottom->destroy();
     645    delete dstPicBottom;
     646  } 
     647  return retval;
     648}
  • trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h

    r608 r655  
    7272  Bool  read  ( TComPicYuv*   pPicYuv, Int aiPad[2] );     ///< read  one YUV frame with padding parameter
    7373  Bool  write( TComPicYuv*    pPicYuv, Int confLeft=0, Int confRight=0, Int confTop=0, Int confBottom=0 );
     74  Bool  write( TComPicYuv*    pPicYuv, TComPicYuv*    pPicYuv2, Int confLeft=0, Int confRight=0, Int confTop=0, Int confBottom=0  , bool isTff=false);
    7475 
    7576  Bool  isEof ();                                           ///< check for end-of-file
Note: See TracChangeset for help on using the changeset viewer.