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


Ignore:
Timestamp:
11 May 2012, 21:20:17 (12 years ago)
Author:
hschwarz
Message:

updated trunk (move to HM6.1)

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

Legend:

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

    r5 r56  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license.
    5  *
    6  * Copyright (c) 2010-2011, ISO/IEC
     4 * granted under this license. 
     5 *
     6 * Copyright (c) 2010-2012, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    1515 *    this list of conditions and the following disclaimer in the documentation
    1616 *    and/or other materials provided with the distribution.
    17  *  * Neither the name of the ISO/IEC nor the names of its contributors may
     17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
    1818 *    be used to endorse or promote products derived from this software without
    1919 *    specific prior written permission.
     
    3232 */
    3333
    34 
    35 
    3634/** \file     TVideoIOYuv.cpp
    3735    \brief    YUV file I/O class
     
    4543#include <iostream>
    4644
     45#include "TLibCommon/TComRom.h"
    4746#include "TVideoIOYuv.h"
    4847
     
    5049
    5150/**
    52  * Perform division with rounding of all pixels in #img by
    53  * \f$ 2^{#shiftbits} \f$. All pixels are clipped to [minval, maxval]
    54  *
    55  * @param stride  distance between vertically adjacent pixels of #img.
    56  * @param width   width of active area in #img.
    57  * @param height  height of active area in #img.
    58  * @param minval  minimum clipping value
    59  * @param maxval  maximum clipping value
     51 * Perform division with rounding of all pixels in img by
     52 * 2<sup>shiftbits</sup>. All pixels are clipped to [minval, maxval]
     53 *
     54 * @param img        pointer to image to be transformed
     55 * @param stride     distance between vertically adjacent pixels of img.
     56 * @param width      width of active area in img.
     57 * @param height     height of active area in img.
     58 * @param shiftbits  number of rounding bits
     59 * @param minval     minimum clipping value
     60 * @param maxval     maximum clipping value
    6061 */
    6162static void invScalePlane(Pel* img, unsigned int stride, unsigned int width, unsigned int height,
     
    7576
    7677/**
    77  * Multiply all pixels in #img by \f$ 2^{#shiftbits} \f$.
    78  *
    79  * @param stride  distance between vertically adjacent pixels of #img.
    80  * @param width   width of active area in #img.
    81  * @param height  height of active area in #img.
     78 * Multiply all pixels in img by 2<sup>shiftbits</sup>.
     79 *
     80 * @param img        pointer to image to be transformed
     81 * @param stride     distance between vertically adjacent pixels of img.
     82 * @param width      width of active area in img.
     83 * @param height     height of active area in img.
     84 * @param shiftbits  number of bits to shift
    8285 */
    8386static void scalePlane(Pel* img, unsigned int stride, unsigned int width, unsigned int height,
     
    9598
    9699/**
    97  * Scale all pixels in #img depending upon sign of #shiftbits by a factor of
    98  * \f$ 2^{#shiftbits} \f$.
    99  *
    100  * @param stride  distance between vertically adjacent pixels of #img.
    101  * @param width   width of active area in #img.
    102  * @param height  height of active area in #img.
     100 * Scale all pixels in img depending upon sign of shiftbits by a factor of
     101 * 2<sup>shiftbits</sup>.
     102 *
     103 * @param img        pointer to image to be transformed
     104 * @param stride  distance between vertically adjacent pixels of img.
     105 * @param width   width of active area in img.
     106 * @param height  height of active area in img.
    103107 * @param shiftbits if zero, no operation performed
    104  *                  if > 0, multiply by \f$ 2^{#shiftbits} \f$, see scalePlane()
    105  *                  if < 0, divide and round by \f$ 2^{#shiftbits} \f$ and clip,
     108 *                  if > 0, multiply by 2<sup>shiftbits</sup>, see scalePlane()
     109 *                  if < 0, divide and round by 2<sup>shiftbits</sup> and clip,
    106110 *                          see invScalePlane().
    107111 * @param minval  minimum clipping value when dividing.
     
    134138 * Open file for reading/writing Y'CbCr frames.
    135139 *
    136  * Frames read/written have bitdepth #fileBitDepth, and are automatically
     140 * Frames read/written have bitdepth fileBitDepth, and are automatically
    137141 * formatted as 8 or 16 bit word values (see TVideoIOYuv::write()).
    138142 *
    139  * Image data read or written is converted to/from #internalBitDepth
     143 * Image data read or written is converted to/from internalBitDepth
    140144 * (See scalePlane(), TVideoIOYuv::read() and TVideoIOYuv::write() for
    141145 * further details).
     
    185189}
    186190
    187 /**
    188  * Skip @numFrames in input.
     191Bool TVideoIOYuv::isFail()
     192{
     193  return m_cHandle.fail();
     194}
     195
     196/**
     197 * Skip numFrames in input.
    189198 *
    190199 * This function correctly handles cases where the input file is not
     
    216225
    217226/**
    218  * Read \f$ #width * #height \f$ pixels from #fd into #dst, optionally
     227 * Read width*height pixels from fd into dst, optionally
    219228 * padding the left and right edges by edge-extension.  Input may be
    220229 * either 8bit or 16bit little-endian lsb-aligned words.
    221230 *
    222231 * @param dst     destination image
     232 * @param fd      input file stream
    223233 * @param is16bit true if input file carries > 8bit data, false otherwise.
    224  * @param stride  distance between vertically adjacent pixels of #dst.
    225  * @param width   width of active area in #dst.
    226  * @param height  height of active area in #dst.
     234 * @param stride  distance between vertically adjacent pixels of dst.
     235 * @param width   width of active area in dst.
     236 * @param height  height of active area in dst.
    227237 * @param pad_x   length of horizontal padding.
    228238 * @param pad_y   length of vertical padding.
    229  */
    230 static void readPlane(Pel* dst, istream& fd, bool is16bit,
     239 * @return true for success, false in case of error
     240 */
     241static bool readPlane(Pel* dst, istream& fd, bool is16bit,
    231242                      unsigned int stride,
    232243                      unsigned int width, unsigned int height,
     
    238249  {
    239250    fd.read(reinterpret_cast<char*>(buf), read_len);
    240     if (!is16bit) {
    241       for (int x = 0; x < width; x++) {
     251    if (fd.eof() || fd.fail() )
     252    {
     253      delete[] buf;
     254      return false;
     255    }
     256
     257    if (!is16bit)
     258    {
     259      for (int x = 0; x < width; x++)
     260      {
    242261        dst[x] = buf[x];
    243262      }
    244263    }
    245     else {
    246       for (int x = 0; x < width; x++) {
     264    else
     265    {
     266      for (int x = 0; x < width; x++)
     267      {
    247268        dst[x] = (buf[2*x+1] << 8) | buf[2*x];
    248269      }
     
    257278  for (int y = height; y < height + pad_y; y++)
    258279  {
    259     for (int x = width; x < width + pad_x; x++)
    260     {
    261       dst[x] = dst[x - stride];
     280    for (int x = 0; x < width + pad_x; x++)
     281    {
     282      dst[x] = (dst - stride)[x];
    262283    }
    263284    dst += stride;
    264285  }
    265286  delete[] buf;
    266 }
    267 
    268 /**
    269  * Write \f$ #width * #height \f$ pixels info #fd from #src.
    270  *
     287  return true;
     288}
     289
     290/**
     291 * Write width*height pixels info fd from src.
     292 *
     293 * @param fd      output file stream
    271294 * @param src     source image
    272295 * @param is16bit true if input file carries > 8bit data, false otherwise.
    273  * @param stride  distance between vertically adjacent pixels of #src.
    274  * @param width   width of active area in #src.
    275  * @param height  height of active area in #src.
    276  */
    277 static void writePlane(ostream& fd, Pel* src, bool is16bit,
     296 * @param stride  distance between vertically adjacent pixels of src.
     297 * @param width   width of active area in src.
     298 * @param height  height of active area in src.
     299 * @return true for success, false in case of error
     300 */
     301static bool writePlane(ostream& fd, Pel* src, bool is16bit,
    278302                       unsigned int stride,
    279303                       unsigned int width, unsigned int height)
     
    300324
    301325    fd.write(reinterpret_cast<char*>(buf), write_len);
     326    if (fd.eof() || fd.fail() )
     327    {
     328      delete[] buf;
     329      return false;
     330    }
    302331    src += stride;
    303332  }
    304333  delete[] buf;
     334  return true;
    305335}
    306336
     
    309339 * from the bitdepth of the input file to the internal bit-depth.
    310340 *
    311  * If a bit-depth reduction is requried, and internalBitdepth >= 8, then
     341 * If a bit-depth reduction is required, and internalBitdepth >= 8, then
    312342 * the input file is assumed to be ITU-R BT.601/709 compliant, and the
    313343 * resulting data is clipped to the appropriate legal range, as if the
    314344 * file had been provided at the lower-bitdepth compliant to Rec601/709.
    315345 *
    316  \param rpcPicYuv      input picture YUV buffer class pointer
    317  \param aiPad[2]       source padding size, aiPad[0] = horizontal, aiPad[1] = vertical
    318  */
    319 Void TVideoIOYuv::read ( TComPicYuv*&  rpcPicYuv, Int aiPad[2], Bool bRewind /* = false */ )
     346 * @param pPicYuv      input picture YUV buffer class pointer
     347 * @param aiPad        source padding size, aiPad[0] = horizontal, aiPad[1] = vertical
     348 * @return true for success, false in case of error
     349 */
     350bool TVideoIOYuv::read ( TComPicYuv*  pPicYuv, Int aiPad[2], Bool bRewind )
    320351{
    321352  // check end-of-file
    322   if ( isEof() ) return;
     353  if ( isEof() ) return false;
    323354 
    324   Int   iStride = rpcPicYuv->getStride();
     355  Int   iStride = pPicYuv->getStride();
    325356 
    326357  // compute actual YUV width & height excluding padding size
    327358  unsigned int pad_h = aiPad[0];
    328359  unsigned int pad_v = aiPad[1];
    329   unsigned int width_full = rpcPicYuv->getWidth();
    330   unsigned int height_full = rpcPicYuv->getHeight();
     360  unsigned int width_full = pPicYuv->getWidth();
     361  unsigned int height_full = pPicYuv->getHeight();
    331362  unsigned int width  = width_full - pad_h;
    332363  unsigned int height = height_full - pad_v;
     
    345376#endif
    346377 
    347   readPlane(rpcPicYuv->getLumaAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v);
    348   scalePlane(rpcPicYuv->getLumaAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval);
     378  if (! readPlane(pPicYuv->getLumaAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v))
     379    return false;
     380  scalePlane(pPicYuv->getLumaAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval);
    349381
    350382  iStride >>= 1;
     
    356388  pad_v >>= 1;
    357389
    358   readPlane(rpcPicYuv->getCbAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v);
    359   scalePlane(rpcPicYuv->getCbAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval);
    360 
    361   readPlane(rpcPicYuv->getCrAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v);
    362   scalePlane(rpcPicYuv->getCrAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval);
     390  if (! readPlane(pPicYuv->getCbAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v))
     391    return false;
     392  scalePlane(pPicYuv->getCbAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval);
     393
     394  if (! readPlane(pPicYuv->getCrAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v))
     395    return false;
     396  scalePlane(pPicYuv->getCrAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval);
    363397
    364398  if( bRewind )
     
    367401    m_cHandle.seekg( -iFrameSize, std::ios_base::cur );
    368402  }
    369 }
    370 
    371 /**
    372  * Write one Y'CbCr frame. No bit-depth conversion is performed, #pcPicYuv is
     403
     404  return true;
     405}
     406
     407/**
     408 * Write one Y'CbCr frame. No bit-depth conversion is performed, pcPicYuv is
    373409 * assumed to be at TVideoIO::m_fileBitdepth depth.
    374410 *
    375  \param pcPicYuv     input picture YUV buffer class pointer
    376  \param aiPad[2]     source padding size, aiPad[0] = horizontal, aiPad[1] = vertical
    377  */
    378 Void TVideoIOYuv::write( TComPicYuv* pcPicYuv, Int aiPad[2] )
     411 * @param pPicYuv     input picture YUV buffer class pointer
     412 * @param aiPad       source padding size, aiPad[0] = horizontal, aiPad[1] = vertical
     413 * @return true for success, false in case of error
     414 */
     415#if PIC_CROPPING
     416Bool TVideoIOYuv::write( TComPicYuv* pPicYuv, Int cropLeft, Int cropRight, Int cropTop, Int cropBottom )
     417#else
     418bool TVideoIOYuv::write( TComPicYuv* pPicYuv, Int aiPad[2] )
     419#endif
    379420{
    380421  // compute actual YUV frame size excluding padding size
    381   Int   iStride = pcPicYuv->getStride();
    382   unsigned int width  = pcPicYuv->getWidth() - aiPad[0];
    383   unsigned int height = pcPicYuv->getHeight() - aiPad[1];
     422  Int   iStride = pPicYuv->getStride();
     423#if PIC_CROPPING
     424  UInt  width  = pPicYuv->getWidth()  - cropLeft - cropRight;
     425  UInt  height = pPicYuv->getHeight() - cropTop  - cropBottom;
     426#else
     427  unsigned int width  = pPicYuv->getWidth() - aiPad[0];
     428  unsigned int height = pPicYuv->getHeight() - aiPad[1];
     429#endif
    384430  bool is16bit = m_fileBitdepth > 8;
    385431  TComPicYuv *dstPicYuv = NULL;
     432  bool retval = true;
    386433
    387434  if (m_bitdepthShift != 0)
    388435  {
    389436    dstPicYuv = new TComPicYuv;
    390     dstPicYuv->create( pcPicYuv->getWidth(), pcPicYuv->getHeight(), 1, 1, 0 );
    391     pcPicYuv->copyToPic(dstPicYuv);
     437    dstPicYuv->create( pPicYuv->getWidth(), pPicYuv->getHeight(), 1, 1, 0 );
     438    pPicYuv->copyToPic(dstPicYuv);
    392439
    393440    Pel minval = 0;
     
    407454  else
    408455  {
    409     dstPicYuv = pcPicYuv;
    410   }
     456    dstPicYuv = pPicYuv;
     457  }
     458#if PIC_CROPPING
     459  // location of upper left pel in a plane
     460  Int planeOffset = 0; //cropLeft + cropTop * iStride;
    411461 
    412   writePlane(m_cHandle, dstPicYuv->getLumaAddr(), is16bit, iStride, width, height);
     462  if (! writePlane(m_cHandle, dstPicYuv->getLumaAddr() + planeOffset, is16bit, iStride, width, height))
     463#else
     464  if (! writePlane(m_cHandle, dstPicYuv->getLumaAddr(), is16bit, iStride, width, height))
     465#endif
     466  {
     467    retval=false;
     468    goto exit;
     469  }
    413470
    414471  width >>= 1;
    415472  height >>= 1;
    416473  iStride >>= 1;
    417   writePlane(m_cHandle, dstPicYuv->getCbAddr(), is16bit, iStride, width, height);
    418   writePlane(m_cHandle, dstPicYuv->getCrAddr(), is16bit, iStride, width, height);
     474#if PIC_CROPPING
     475  cropLeft >>= 1;
     476  cropRight >>= 1;
     477
     478  planeOffset = 0; // cropLeft + cropTop * iStride;
     479
     480  if (! writePlane(m_cHandle, dstPicYuv->getCbAddr() + planeOffset, is16bit, iStride, width, height))
     481#else
     482  if (! writePlane(m_cHandle, dstPicYuv->getCbAddr(), is16bit, iStride, width, height))
     483#endif
     484  {
     485    retval=false;
     486    goto exit;
     487  }
     488#if PIC_CROPPING
     489  if (! writePlane(m_cHandle, dstPicYuv->getCrAddr() + planeOffset, is16bit, iStride, width, height))
     490#else
     491  if (! writePlane(m_cHandle, dstPicYuv->getCrAddr(), is16bit, iStride, width, height))
     492#endif
     493  {
     494    retval=false;
     495    goto exit;
     496  }
    419497 
     498exit:
    420499  if (m_bitdepthShift != 0)
    421500  {
     
    423502    delete dstPicYuv;
    424503  } 
    425 }
    426 
     504  return retval;
     505}
     506
  • trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h

    r5 r56  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license.
     4 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2011, ISO/IEC
     6 * Copyright (c) 2010-2012, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    1515 *    this list of conditions and the following disclaimer in the documentation
    1616 *    and/or other materials provided with the distribution.
    17  *  * Neither the name of the ISO/IEC nor the names of its contributors may
     17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
    1818 *    be used to endorse or promote products derived from this software without
    1919 *    specific prior written permission.
     
    3131 * THE POSSIBILITY OF SUCH DAMAGE.
    3232 */
    33 
    34 
    3533
    3634/** \file     TVideoIOYuv.h
     
    7068  void skipFrames(unsigned int numFrames, unsigned int width, unsigned int height);
    7169 
    72   Void  read  ( TComPicYuv*& rpcPicYuv, Int aiPad[2], Bool bRewind = false );     ///< read  one YUV frame with padding parameter
    73   Void  write ( TComPicYuv*   pcPicYuv, Int aiPad[2] );     ///< write one YUV frame with padding parameter
     70  bool  read  ( TComPicYuv*   pPicYuv, Int aiPad[2], Bool bRewind = false );     ///< read  one YUV frame with padding parameter
     71#if PIC_CROPPING
     72  Bool  write( TComPicYuv*    pPicYuv, Int cropLeft=0, Int cropRight=0, Int cropTop=0, Int cropBottom=0 );
     73#else
     74  bool  write ( TComPicYuv*   pPicYuv, Int aiPad[2] );     ///< write one YUV frame with padding parameter
     75#endif
    7476 
    75   Bool  isEof ();                                           ///< check end-of-file
     77  bool  isEof ();                                           ///< check for end-of-file
     78  bool  isFail();                                           ///< check for failure
    7679 
    7780};
Note: See TracChangeset for help on using the changeset viewer.