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


Ignore:
Timestamp:
1 Sep 2013, 22:47:26 (11 years ago)
Author:
tech
Message:

Merged DEV-2.0-dev0@604.

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

Legend:

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

    r296 r608  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    6060 * @param maxval     maximum clipping value
    6161 */
    62 static void invScalePlane(Pel* img, unsigned int stride, unsigned int width, unsigned int height,
    63                        unsigned int shiftbits, Pel minval, Pel maxval)
     62static void invScalePlane(Pel* img, UInt stride, UInt width, UInt height,
     63                       UInt shiftbits, Pel minval, Pel maxval)
    6464{
    6565  Pel offset = 1 << (shiftbits-1);
    66   for (unsigned int y = 0; y < height; y++)
    67   {
    68     for (unsigned int x = 0; x < width; x++)
     66  for (UInt y = 0; y < height; y++)
     67  {
     68    for (UInt x = 0; x < width; x++)
    6969    {
    7070      Pel val = (img[x] + offset) >> shiftbits;
     
    8484 * @param shiftbits  number of bits to shift
    8585 */
    86 static void scalePlane(Pel* img, unsigned int stride, unsigned int width, unsigned int height,
    87                        unsigned int shiftbits)
    88 {
    89   for (unsigned int y = 0; y < height; y++)
    90   {
    91     for (unsigned int x = 0; x < width; x++)
     86static void scalePlane(Pel* img, UInt stride, UInt width, UInt height,
     87                       UInt shiftbits)
     88{
     89  for (UInt y = 0; y < height; y++)
     90  {
     91    for (UInt x = 0; x < width; x++)
    9292    {
    9393      img[x] <<= shiftbits;
     
    112112 * @param maxval  maximum clipping value when dividing.
    113113 */
    114 static void scalePlane(Pel* img, unsigned int stride, unsigned int width, unsigned int height,
    115                        int shiftbits, Pel minval, Pel maxval)
     114static void scalePlane(Pel* img, UInt stride, UInt width, UInt height,
     115                       Int shiftbits, Pel minval, Pel maxval)
    116116{
    117117  if (shiftbits == 0)
     
    147147 * \param pchFile          file name string
    148148 * \param bWriteMode       file open mode: true=read, false=write
    149  * \param fileBitDepth     bit-depth of input/output file data.
    150  * \param internalBitDepth bit-depth to scale image data to/from when reading/writing.
    151  */
    152 Void TVideoIOYuv::open( char* pchFile, Bool bWriteMode, unsigned int fileBitDepth, unsigned int internalBitDepth )
    153 {
    154   m_bitdepthShift = internalBitDepth - fileBitDepth;
    155   m_fileBitdepth = fileBitDepth;
     149 * \param fileBitDepthY     bit-depth of input/output file data (luma component).
     150 * \param fileBitDepthC     bit-depth of input/output file data (chroma components).
     151 * \param internalBitDepthY bit-depth to scale image data to/from when reading/writing (luma component).
     152 * \param internalBitDepthC bit-depth to scale image data to/from when reading/writing (chroma components).
     153 */
     154Void TVideoIOYuv::open( Char* pchFile, Bool bWriteMode, Int fileBitDepthY, Int fileBitDepthC, Int internalBitDepthY, Int internalBitDepthC)
     155{
     156  m_bitDepthShiftY = internalBitDepthY - fileBitDepthY;
     157  m_bitDepthShiftC = internalBitDepthC - fileBitDepthC;
     158  m_fileBitDepthY = fileBitDepthY;
     159  m_fileBitDepthC = fileBitDepthC;
    156160
    157161  if ( bWriteMode )
     
    200204 * seekable, by consuming bytes.
    201205 */
    202 void TVideoIOYuv::skipFrames(unsigned int numFrames, unsigned int width, unsigned int height)
     206void TVideoIOYuv::skipFrames(UInt numFrames, UInt width, UInt height)
    203207{
    204208  if (!numFrames)
    205209    return;
    206210
    207   const unsigned int wordsize = m_fileBitdepth > 8 ? 2 : 1;
     211  const UInt wordsize = (m_fileBitDepthY > 8 || m_fileBitDepthC > 8) ? 2 : 1;
    208212  const streamoff framesize = wordsize * width * height * 3 / 2;
    209213  const streamoff offset = framesize * numFrames;
     
    215219
    216220  /* fall back to consuming the input */
    217   char buf[512];
    218   const unsigned offset_mod_bufsize = offset % sizeof(buf);
     221  Char buf[512];
     222  const UInt offset_mod_bufsize = offset % sizeof(buf);
    219223  for (streamoff i = 0; i < offset - offset_mod_bufsize; i += sizeof(buf))
    220224  {
     
    239243 * @return true for success, false in case of error
    240244 */
    241 static bool readPlane(Pel* dst, istream& fd, bool is16bit,
    242                       unsigned int stride,
    243                       unsigned int width, unsigned int height,
    244                       unsigned int pad_x, unsigned int pad_y)
    245 {
    246   int read_len = width * (is16bit ? 2 : 1);
    247   unsigned char *buf = new unsigned char[read_len];
    248   for (int y = 0; y < height; y++)
    249   {
    250     fd.read(reinterpret_cast<char*>(buf), read_len);
     245static Bool readPlane(Pel* dst, istream& fd, Bool is16bit,
     246                      UInt stride,
     247                      UInt width, UInt height,
     248                      UInt pad_x, UInt pad_y)
     249{
     250  Int read_len = width * (is16bit ? 2 : 1);
     251  UChar *buf = new UChar[read_len];
     252  for (Int y = 0; y < height; y++)
     253  {
     254    fd.read(reinterpret_cast<Char*>(buf), read_len);
    251255    if (fd.eof() || fd.fail() )
    252256    {
     
    257261    if (!is16bit)
    258262    {
    259       for (int x = 0; x < width; x++)
     263      for (Int x = 0; x < width; x++)
    260264      {
    261265        dst[x] = buf[x];
     
    264268    else
    265269    {
    266       for (int x = 0; x < width; x++)
     270      for (Int x = 0; x < width; x++)
    267271      {
    268272        dst[x] = (buf[2*x+1] << 8) | buf[2*x];
     
    270274    }
    271275
    272     for (int x = width; x < width + pad_x; x++)
     276    for (Int x = width; x < width + pad_x; x++)
    273277    {
    274278      dst[x] = dst[width - 1];
     
    276280    dst += stride;
    277281  }
    278   for (int y = height; y < height + pad_y; y++)
    279   {
    280     for (int x = 0; x < width + pad_x; x++)
     282  for (Int y = height; y < height + pad_y; y++)
     283  {
     284    for (Int x = 0; x < width + pad_x; x++)
    281285    {
    282286      dst[x] = (dst - stride)[x];
     
    299303 * @return true for success, false in case of error
    300304 */
    301 static bool writePlane(ostream& fd, Pel* src, bool is16bit,
    302                        unsigned int stride,
    303                        unsigned int width, unsigned int height)
    304 {
    305   int write_len = width * (is16bit ? 2 : 1);
    306   unsigned char *buf = new unsigned char[write_len];
    307   for (int y = 0; y < height; y++)
     305static Bool writePlane(ostream& fd, Pel* src, Bool is16bit,
     306                       UInt stride,
     307                       UInt width, UInt height)
     308{
     309  Int write_len = width * (is16bit ? 2 : 1);
     310  UChar *buf = new UChar[write_len];
     311  for (Int y = 0; y < height; y++)
    308312  {
    309313    if (!is16bit)
    310314    {
    311       for (int x = 0; x < width; x++)
     315      for (Int x = 0; x < width; x++)
    312316      {
    313         buf[x] = (unsigned char) src[x];
     317        buf[x] = (UChar) src[x];
    314318      }
    315319    }
    316320    else
    317321    {
    318       for (int x = 0; x < width; x++)
     322      for (Int x = 0; x < width; x++)
    319323      {
    320324        buf[2*x] = src[x] & 0xff;
     
    323327    }
    324328
    325     fd.write(reinterpret_cast<char*>(buf), write_len);
     329    fd.write(reinterpret_cast<Char*>(buf), write_len);
    326330    if (fd.eof() || fd.fail() )
    327331    {
     
    348352 * @return true for success, false in case of error
    349353 */
    350 bool TVideoIOYuv::read ( TComPicYuv*  pPicYuv, Int aiPad[2], Bool bRewind )
     354Bool TVideoIOYuv::read ( TComPicYuv*  pPicYuv, Int aiPad[2] )
    351355{
    352356  // check end-of-file
     
    356360 
    357361  // compute actual YUV width & height excluding padding size
    358   unsigned int pad_h = aiPad[0];
    359   unsigned int pad_v = aiPad[1];
    360   unsigned int width_full = pPicYuv->getWidth();
    361   unsigned int height_full = pPicYuv->getHeight();
    362   unsigned int width  = width_full - pad_h;
    363   unsigned int height = height_full - pad_v;
    364   bool is16bit = m_fileBitdepth > 8;
    365 
    366   int desired_bitdepth = m_fileBitdepth + m_bitdepthShift;
    367   Pel minval = 0;
    368   Pel maxval = (1 << desired_bitdepth) - 1;
     362  UInt pad_h = aiPad[0];
     363  UInt pad_v = aiPad[1];
     364  UInt width_full = pPicYuv->getWidth();
     365  UInt height_full = pPicYuv->getHeight();
     366  UInt width  = width_full - pad_h;
     367  UInt height = height_full - pad_v;
     368  Bool is16bit = m_fileBitDepthY > 8 || m_fileBitDepthC > 8;
     369
     370  Int desired_bitdepthY = m_fileBitDepthY + m_bitDepthShiftY;
     371  Int desired_bitdepthC = m_fileBitDepthC + m_bitDepthShiftC;
     372  Pel minvalY = 0;
     373  Pel minvalC = 0;
     374  Pel maxvalY = (1 << desired_bitdepthY) - 1;
     375  Pel maxvalC = (1 << desired_bitdepthC) - 1;
    369376#if CLIP_TO_709_RANGE
    370   if (m_bitdepthShift < 0 && desired_bitdepth >= 8)
     377  if (m_bitdepthShiftY < 0 && desired_bitdepthY >= 8)
    371378  {
    372379    /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
    373     minval = 1 << (desired_bitdepth - 8);
    374     maxval = (0xff << (desired_bitdepth - 8)) -1;
     380    minvalY = 1 << (desired_bitdepthY - 8);
     381    maxvalY = (0xff << (desired_bitdepthY - 8)) -1;
     382  }
     383  if (m_bitdepthShiftC < 0 && desired_bitdepthC >= 8)
     384  {
     385    /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
     386    minvalC = 1 << (desired_bitdepthC - 8);
     387    maxvalC = (0xff << (desired_bitdepthC - 8)) -1;
    375388  }
    376389#endif
     
    378391  if (! readPlane(pPicYuv->getLumaAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v))
    379392    return false;
    380   scalePlane(pPicYuv->getLumaAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval);
     393  scalePlane(pPicYuv->getLumaAddr(), iStride, width_full, height_full, m_bitDepthShiftY, minvalY, maxvalY);
    381394
    382395  iStride >>= 1;
     
    390403  if (! readPlane(pPicYuv->getCbAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v))
    391404    return false;
    392   scalePlane(pPicYuv->getCbAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval);
     405  scalePlane(pPicYuv->getCbAddr(), iStride, width_full, height_full, m_bitDepthShiftC, minvalC, maxvalC);
    393406
    394407  if (! readPlane(pPicYuv->getCrAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v))
    395408    return false;
    396   scalePlane(pPicYuv->getCrAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval);
    397 
    398   if( bRewind )
    399   {
    400     Int iFrameSize = ( is16bit ? 2 : 1 ) * 6 * width * height;
    401     m_cHandle.seekg( -iFrameSize, std::ios_base::cur );
    402   }
     409  scalePlane(pPicYuv->getCrAddr(), iStride, width_full, height_full, m_bitDepthShiftC, minvalC, maxvalC);
    403410
    404411  return true;
     
    413420 * @return true for success, false in case of error
    414421 */
    415 Bool TVideoIOYuv::write( TComPicYuv* pPicYuv, Int cropLeft, Int cropRight, Int cropTop, Int cropBottom )
     422Bool TVideoIOYuv::write( TComPicYuv* pPicYuv, Int confLeft, Int confRight, Int confTop, Int confBottom )
    416423{
    417424  // compute actual YUV frame size excluding padding size
    418425  Int   iStride = pPicYuv->getStride();
    419   UInt  width  = pPicYuv->getWidth()  - cropLeft - cropRight;
    420   UInt  height = pPicYuv->getHeight() - cropTop  - cropBottom;
    421   bool is16bit = m_fileBitdepth > 8;
     426  UInt  width  = pPicYuv->getWidth()  - confLeft - confRight;
     427  UInt  height = pPicYuv->getHeight() - confTop  - confBottom;
     428  Bool is16bit = m_fileBitDepthY > 8 || m_fileBitDepthC > 8;
    422429  TComPicYuv *dstPicYuv = NULL;
    423   bool retval = true;
    424 
    425   if (m_bitdepthShift != 0)
     430  Bool retval = true;
     431
     432  if (m_bitDepthShiftY != 0 || m_bitDepthShiftC != 0)
    426433  {
    427434    dstPicYuv = new TComPicYuv;
     
    429436    pPicYuv->copyToPic(dstPicYuv);
    430437
    431     Pel minval = 0;
    432     Pel maxval = (1 << m_fileBitdepth) - 1;
     438    Pel minvalY = 0;
     439    Pel minvalC = 0;
     440    Pel maxvalY = (1 << m_fileBitDepthY) - 1;
     441    Pel maxvalC = (1 << m_fileBitDepthC) - 1;
    433442#if CLIP_TO_709_RANGE
    434     if (-m_bitdepthShift < 0 && m_fileBitdepth >= 8)
     443    if (-m_bitDepthShiftY < 0 && m_fileBitDepthY >= 8)
    435444    {
    436445      /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
    437       minval = 1 << (m_fileBitdepth - 8);
    438       maxval = (0xff << (m_fileBitdepth - 8)) -1;
     446      minvalY = 1 << (m_fileBitDepthY - 8);
     447      maxvalY = (0xff << (m_fileBitDepthY - 8)) -1;
     448    }
     449    if (-m_bitDepthShiftC < 0 && m_fileBitDepthC >= 8)
     450    {
     451      /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
     452      minvalC = 1 << (m_fileBitDepthC - 8);
     453      maxvalC = (0xff << (m_fileBitDepthC - 8)) -1;
    439454    }
    440455#endif
    441     scalePlane(dstPicYuv->getLumaAddr(), dstPicYuv->getStride(), dstPicYuv->getWidth(), dstPicYuv->getHeight(), -m_bitdepthShift, minval, maxval);
    442     scalePlane(dstPicYuv->getCbAddr(), dstPicYuv->getCStride(), dstPicYuv->getWidth()>>1, dstPicYuv->getHeight()>>1, -m_bitdepthShift, minval, maxval);
    443     scalePlane(dstPicYuv->getCrAddr(), dstPicYuv->getCStride(), dstPicYuv->getWidth()>>1, dstPicYuv->getHeight()>>1, -m_bitdepthShift, minval, maxval);
     456    scalePlane(dstPicYuv->getLumaAddr(), dstPicYuv->getStride(), dstPicYuv->getWidth(), dstPicYuv->getHeight(), -m_bitDepthShiftY, minvalY, maxvalY);
     457    scalePlane(dstPicYuv->getCbAddr(), dstPicYuv->getCStride(), dstPicYuv->getWidth()>>1, dstPicYuv->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
     458    scalePlane(dstPicYuv->getCrAddr(), dstPicYuv->getCStride(), dstPicYuv->getWidth()>>1, dstPicYuv->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
    444459  }
    445460  else
     
    448463  }
    449464  // location of upper left pel in a plane
    450   Int planeOffset = 0; //cropLeft + cropTop * iStride;
     465  Int planeOffset = confLeft + confTop * iStride;
    451466 
    452467  if (! writePlane(m_cHandle, dstPicYuv->getLumaAddr() + planeOffset, is16bit, iStride, width, height))
     
    459474  height >>= 1;
    460475  iStride >>= 1;
    461   cropLeft >>= 1;
    462   cropRight >>= 1;
    463 
    464   planeOffset = 0; // cropLeft + cropTop * iStride;
     476  confLeft >>= 1;
     477  confRight >>= 1;
     478  confTop >>= 1;
     479  confBottom >>= 1;
     480
     481  planeOffset = confLeft + confTop * iStride;
    465482
    466483  if (! writePlane(m_cHandle, dstPicYuv->getCbAddr() + planeOffset, is16bit, iStride, width, height))
     
    476493 
    477494exit:
    478   if (m_bitdepthShift != 0)
     495  if (m_bitDepthShiftY != 0 || m_bitDepthShiftC != 0)
    479496  {
    480497    dstPicYuv->destroy();
  • trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h

    r296 r608  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    4242#include <fstream>
    4343#include <iostream>
    44 #include "../TLibCommon/CommonDef.h"
    45 #include "../TLibCommon/TComPicYuv.h"
     44#include "TLibCommon/CommonDef.h"
     45#include "TLibCommon/TComPicYuv.h"
    4646
    4747using namespace std;
     
    5656private:
    5757  fstream   m_cHandle;                                      ///< file handle
    58   unsigned int m_fileBitdepth; ///< bitdepth of input/output video file
    59   int m_bitdepthShift;  ///< number of bits to increase or decrease image by before/after write/read
     58  Int m_fileBitDepthY; ///< bitdepth of input/output video file luma component
     59  Int m_fileBitDepthC; ///< bitdepth of input/output video file chroma component
     60  Int m_bitDepthShiftY;  ///< number of bits to increase or decrease luma by before/after write/read
     61  Int m_bitDepthShiftC;  ///< number of bits to increase or decrease chroma by before/after write/read
    6062 
    6163public:
     
    6365  virtual ~TVideoIOYuv()  {}
    6466 
    65   Void  open  ( char* pchFile, Bool bWriteMode, unsigned int fileBitDepth, unsigned int internalBitDepth ); ///< open or create file
     67  Void  open  ( Char* pchFile, Bool bWriteMode, Int fileBitDepthY, Int fileBitDepthC, Int internalBitDepthY, Int internalBitDepthC ); ///< open or create file
    6668  Void  close ();                                           ///< close file
    6769
    68   void skipFrames(unsigned int numFrames, unsigned int width, unsigned int height);
     70  void skipFrames(UInt numFrames, UInt width, UInt height);
    6971 
    70   bool  read  ( TComPicYuv*   pPicYuv, Int aiPad[2], Bool bRewind = false );     ///< read  one YUV frame with padding parameter
    71   Bool  write( TComPicYuv*    pPicYuv, Int cropLeft=0, Int cropRight=0, Int cropTop=0, Int cropBottom=0 );
     72  Bool  read  ( TComPicYuv*   pPicYuv, Int aiPad[2] );     ///< read  one YUV frame with padding parameter
     73  Bool  write( TComPicYuv*    pPicYuv, Int confLeft=0, Int confRight=0, Int confTop=0, Int confBottom=0 );
    7274 
    73   bool  isEof ();                                           ///< check for end-of-file
    74   bool  isFail();                                           ///< check for failure
     75  Bool  isEof ();                                           ///< check for end-of-file
     76  Bool  isFail();                                           ///< check for failure
    7577 
    7678};
Note: See TracChangeset for help on using the changeset viewer.