Index: trunk/source/Lib/TLibVideoIO/TVideoIOBits.cpp
===================================================================
--- trunk/source/Lib/TLibVideoIO/TVideoIOBits.cpp	(revision 5)
+++ 	(revision )
@@ -1,258 +1,0 @@
-/* The copyright in this software is being made available under the BSD
- * License, included below. This software may be subject to other third party
- * and contributor rights, including patent rights, and no such rights are
- * granted under this license.
- *
- * Copyright (c) 2010-2011, ISO/IEC
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *  * Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *  * Neither the name of the ISO/IEC nor the names of its contributors may
- *    be used to endorse or promote products derived from this software without
- *    specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-
-/** \file     TVideoIOBits.cpp
-    \brief    bitstream file I/O class
-*/
-
-#include <cstdlib>
-#include <fcntl.h>
-#include <assert.h>
-#include <sys/stat.h>
-#include <fstream>
-#include <iostream>
-
-#include "TVideoIOBits.h"
-
-using namespace std;
-
-// ====================================================================================================================
-// Public member functions
-// ====================================================================================================================
-
-/**
- \param pchFile    file name string
- \param bWriteMode file open mode
- */
-Void TVideoIOBits::openBits( char* pchFile, Bool bWriteMode )
-{
-  if ( bWriteMode )
-  {
-    m_cHandle.open( pchFile, ios::binary | ios::out );
-    
-    if( m_cHandle.fail() )
-    {
-      printf("\nfailed to write Bitstream file\n");
-      exit(0);
-    }
-  }
-  else
-  {
-    m_cHandle.open( pchFile, ios::binary | ios::in );
-    
-    if( m_cHandle.fail() )
-    {
-      printf("\nfailed to read Bitstream file\n");
-      exit(0);
-    }
-  }
-  
-  return;
-}
-
-Void TVideoIOBits::closeBits()
-{
-  m_cHandle.close();
-}
-
-/**
- \param  rpcBitstream    bitstream class pointer
- \retval                 true if EOF is reached
- */
-Bool TVideoIOBits::readBits( TComBitstream*& rpcBitstream )
-{
-  UInt  uiBytes = 0;
-  
-  rpcBitstream->rewindStreamPacket();
-  
-  // check end-of-file
-  if ( m_cHandle.eof() ) return true;
-  
-  // read 32-bit packet size
-  m_cHandle.read( reinterpret_cast<char*>(&uiBytes), sizeof (Int) );
-  
-  // kolya
-  if ( m_cHandle.eof() ) return true; //additional insertion to avoid over-reading, for <fstream>
-  
-  // read packet data
-  m_cHandle.read(  reinterpret_cast<char*>(rpcBitstream->getBuffer()), uiBytes );
-  
-  // initialize parsing process
-  rpcBitstream->initParsing ( uiBytes );
-  
-  assert (uiBytes >= 4);
-  
-  return false;
-}
-
-/** \param  pcBitstream   bitstream class pointer
- */
-Void TVideoIOBits::writeBits( TComBitstream* pcBitstream )
-{
-  UInt*  plBuff  = pcBitstream->getStartStream();
-  UInt   uiBytes = pcBitstream->getNumberOfWrittenBits() >> 3;
-  
-  // write 32-bit packet size
-  m_cHandle.write( reinterpret_cast<char*>(&uiBytes ), sizeof(UInt) );
-  
-  // write packet data
-  m_cHandle.write( reinterpret_cast<char*>(plBuff   ), uiBytes      );
-}
-
-////////////////////////////////////////////////////////////////////
-
-Void TVideoIOBitsStartCode::openBits( char* pchFile, Bool bWriteMode )
-{
-  if ( bWriteMode )
-  {
-    m_cHandle.open( pchFile, ios::binary | ios::out );
-    
-    if( m_cHandle.fail() )
-    {
-      printf("\nfailed to write Bitstream file\n");
-      exit(0);
-    }
-  }
-  else
-  {
-    m_cHandle.open( pchFile, ios::binary | ios::in );
-    
-    if( m_cHandle.fail() )
-    {
-      printf("\nfailed to read Bitstream file\n");
-      exit(0);
-    }
-  }
-  
-  return;
-}
-
-Void TVideoIOBitsStartCode::closeBits()
-{
-  m_cHandle.close();
-}
-
-/**
- \param  rpcBitstream    bitstream class pointer
- \retval                 true if EOF is reached
- */
-Bool TVideoIOBitsStartCode::readBits( TComBitstream*& rpcBitstream )
-{
-  rpcBitstream->rewindStreamPacket();
-  
-  // check end-of-file
-  if ( m_cHandle.eof() ) return true;
-  
-  UInt uiPacketSize = 0;
-  if( 0 != xFindNextStartCode( uiPacketSize, reinterpret_cast<UChar*>(rpcBitstream->getBuffer()) ) )
-  {
-    return true;
-  }
-  
-  // initialize parsing process
-  rpcBitstream->initParsingConvertPayloadToRBSP( uiPacketSize );
-  return false;
-}
-
-int TVideoIOBitsStartCode::xFindNextStartCode(UInt& ruiPacketSize, UChar* pucBuffer)
-{
-  UInt uiDummy = 0;
-  m_cHandle.read( reinterpret_cast<char*>(&uiDummy), 3 );
-  if ( m_cHandle.eof() ) return -1;
-  assert( 0 == uiDummy );
-  
-  m_cHandle.read( reinterpret_cast<char*>(&uiDummy), 1 );
-  if ( m_cHandle.eof() ) return -1;
-  assert( 1 == uiDummy );
-  
-  Int iNextStartCodeBytes = 0;
-  Int iBytesRead = 0;
-  UInt uiZeros = 0;
-  while( true )
-  {
-    UChar ucByte = 0;
-    m_cHandle.read( reinterpret_cast<char*>(&ucByte), 1 );
-    if ( m_cHandle.eof() )
-    {
-      iNextStartCodeBytes = 0;
-      break;
-    }
-    pucBuffer[iBytesRead++] = ucByte;
-    if( 1 < ucByte )
-    {
-      uiZeros = 0;
-    }
-    else if( 0 == ucByte )
-    {
-      uiZeros++;
-    }
-    else if( uiZeros > 2)
-    {
-      iNextStartCodeBytes = 3 + 1;
-      break;
-    }
-    else
-    {
-      uiZeros = 0;
-    }
-  }
-  
-  ruiPacketSize = iBytesRead - iNextStartCodeBytes;
-  
-  m_cHandle.seekg( -iNextStartCodeBytes, ios::cur );
-  return 0;
-}
-
-/**
- \param  pcBitstream   bitstream class pointer
- */
-Void TVideoIOBitsStartCode::writeBits( TComBitstream* pcBitstream )
-{
-  UInt*  plBuff  = pcBitstream->getStartStream();
-  UInt   uiBytes = pcBitstream->getNumberOfWrittenBits() >> 3;
-  Char   ucZero = 0;
-  Char   ucOne = 1;
-  
-  // write 32-bit packet size
-  m_cHandle.write( &ucZero , sizeof(Char) );
-  m_cHandle.write( &ucZero , sizeof(Char) );
-  m_cHandle.write( &ucZero , sizeof(Char) );
-  m_cHandle.write( &ucOne  , sizeof(Char) );
-  
-  // write packet data
-  m_cHandle.write( reinterpret_cast<char*>(plBuff   ), uiBytes      );
-}
-
-
Index: trunk/source/Lib/TLibVideoIO/TVideoIOBits.h
===================================================================
--- trunk/source/Lib/TLibVideoIO/TVideoIOBits.h	(revision 5)
+++ 	(revision )
@@ -1,100 +1,0 @@
-/* The copyright in this software is being made available under the BSD
- * License, included below. This software may be subject to other third party
- * and contributor rights, including patent rights, and no such rights are
- * granted under this license.
- *
- * Copyright (c) 2010-2011, ISO/IEC
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *  * Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *  * Neither the name of the ISO/IEC nor the names of its contributors may
- *    be used to endorse or promote products derived from this software without
- *    specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-
-/** \file     TVideoIOBits.h
-    \brief    bitstream file I/O class (header)
-*/
-
-#ifndef __TVIDEOIOBITS__
-#define __TVIDEOIOBITS__
-
-#include <stdio.h>
-#include <fstream>
-#include <iostream>
-#include "../TLibCommon/CommonDef.h"
-#include "../TLibCommon/TComBitStream.h"
-
-// ====================================================================================================================
-// Class definition
-// ====================================================================================================================
-
-/// bitstream file I/O class
-class TVideoIOBits
-{
-private:
-  std::fstream   m_cHandle;                                      ///< file handle
-  
-public:
-  TVideoIOBits()            {}
-  virtual ~TVideoIOBits()   {}
-  
-  Void openBits   ( char* pchFile,  Bool bWriteMode );      ///< open or create file
-  Void closeBits  ();                                       ///< close file
-  
-  Bool readBits   ( TComBitstream*& rpcBitstream    );      ///< read  one packet from file
-  Void writeBits  ( TComBitstream*  pcBitstream     );      ///< write one packet to   file
-  
-};
-
-/// bitstream file I/O class
-class TVideoIOBitsStartCode
-{
-private:
-  std::fstream   m_cHandle;                                      ///< file handle
-  
-public:
-  TVideoIOBitsStartCode()            
-  {
-  }
-  virtual ~TVideoIOBitsStartCode()   {}
-  
-  Void openBits   ( char* pchFile,  Bool bWriteMode );      ///< open or create file
-  Void closeBits  ();                                       ///< close file
-  
-  Bool readBits   ( TComBitstream*& rpcBitstream    );      ///< read  one packet from file
-  Void writeBits  ( TComBitstream*  pcBitstream     );      ///< write one packet to   file
-  
-  std::streampos   getFileLocation      ()                          { return m_cHandle.tellg();                           }
-  Void             setFileLocation      (std::streampos uiLocation) { m_cHandle.seekg(uiLocation, std::ios_base::beg);    }
-  Void             clear                ()                          { m_cHandle.clear();                                  }
-  Bool             good                 ()                          { return m_cHandle.good();                            }
-
-private:
-  int xFindNextStartCode(UInt& ruiPacketSize, UChar* pucBuffer); ///< get packet size and number of startcode bytes and seeks to the packet's start position
-  
-};
-
-#endif // __TVIDEOIOBITS__
-
Index: trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp
===================================================================
--- trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp	(revision 5)
+++ trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp	(revision 56)
@@ -2,7 +2,7 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.
- *
- * Copyright (c) 2010-2011, ISO/IEC
+ * granted under this license.  
+ *
+ * Copyright (c) 2010-2012, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -15,5 +15,5 @@
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
- *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
  *    be used to endorse or promote products derived from this software without
  *    specific prior written permission.
@@ -32,6 +32,4 @@
  */
 
-
-
 /** \file     TVideoIOYuv.cpp
     \brief    YUV file I/O class
@@ -45,4 +43,5 @@
 #include <iostream>
 
+#include "TLibCommon/TComRom.h"
 #include "TVideoIOYuv.h"
 
@@ -50,12 +49,14 @@
 
 /**
- * Perform division with rounding of all pixels in #img by
- * \f$ 2^{#shiftbits} \f$. All pixels are clipped to [minval, maxval]
- *
- * @param stride  distance between vertically adjacent pixels of #img.
- * @param width   width of active area in #img.
- * @param height  height of active area in #img.
- * @param minval  minimum clipping value
- * @param maxval  maximum clipping value
+ * Perform division with rounding of all pixels in img by
+ * 2<sup>shiftbits</sup>. All pixels are clipped to [minval, maxval]
+ *
+ * @param img        pointer to image to be transformed
+ * @param stride     distance between vertically adjacent pixels of img.
+ * @param width      width of active area in img.
+ * @param height     height of active area in img.
+ * @param shiftbits  number of rounding bits
+ * @param minval     minimum clipping value
+ * @param maxval     maximum clipping value
  */
 static void invScalePlane(Pel* img, unsigned int stride, unsigned int width, unsigned int height,
@@ -75,9 +76,11 @@
 
 /**
- * Multiply all pixels in #img by \f$ 2^{#shiftbits} \f$.
- *
- * @param stride  distance between vertically adjacent pixels of #img.
- * @param width   width of active area in #img.
- * @param height  height of active area in #img.
+ * Multiply all pixels in img by 2<sup>shiftbits</sup>.
+ *
+ * @param img        pointer to image to be transformed
+ * @param stride     distance between vertically adjacent pixels of img.
+ * @param width      width of active area in img.
+ * @param height     height of active area in img.
+ * @param shiftbits  number of bits to shift
  */
 static void scalePlane(Pel* img, unsigned int stride, unsigned int width, unsigned int height,
@@ -95,13 +98,14 @@
 
 /**
- * Scale all pixels in #img depending upon sign of #shiftbits by a factor of
- * \f$ 2^{#shiftbits} \f$.
- *
- * @param stride  distance between vertically adjacent pixels of #img.
- * @param width   width of active area in #img.
- * @param height  height of active area in #img.
+ * Scale all pixels in img depending upon sign of shiftbits by a factor of
+ * 2<sup>shiftbits</sup>.
+ *
+ * @param img        pointer to image to be transformed
+ * @param stride  distance between vertically adjacent pixels of img.
+ * @param width   width of active area in img.
+ * @param height  height of active area in img.
  * @param shiftbits if zero, no operation performed
- *                  if > 0, multiply by \f$ 2^{#shiftbits} \f$, see scalePlane()
- *                  if < 0, divide and round by \f$ 2^{#shiftbits} \f$ and clip,
+ *                  if > 0, multiply by 2<sup>shiftbits</sup>, see scalePlane()
+ *                  if < 0, divide and round by 2<sup>shiftbits</sup> and clip,
  *                          see invScalePlane().
  * @param minval  minimum clipping value when dividing.
@@ -134,8 +138,8 @@
  * Open file for reading/writing Y'CbCr frames.
  *
- * Frames read/written have bitdepth #fileBitDepth, and are automatically
+ * Frames read/written have bitdepth fileBitDepth, and are automatically
  * formatted as 8 or 16 bit word values (see TVideoIOYuv::write()).
  *
- * Image data read or written is converted to/from #internalBitDepth
+ * Image data read or written is converted to/from internalBitDepth
  * (See scalePlane(), TVideoIOYuv::read() and TVideoIOYuv::write() for
  * further details).
@@ -185,6 +189,11 @@
 }
 
-/**
- * Skip @numFrames in input.
+Bool TVideoIOYuv::isFail()
+{
+  return m_cHandle.fail();
+}
+
+/**
+ * Skip numFrames in input.
  *
  * This function correctly handles cases where the input file is not
@@ -216,17 +225,19 @@
 
 /**
- * Read \f$ #width * #height \f$ pixels from #fd into #dst, optionally
+ * Read width*height pixels from fd into dst, optionally
  * padding the left and right edges by edge-extension.  Input may be
  * either 8bit or 16bit little-endian lsb-aligned words.
  *
  * @param dst     destination image
+ * @param fd      input file stream
  * @param is16bit true if input file carries > 8bit data, false otherwise.
- * @param stride  distance between vertically adjacent pixels of #dst.
- * @param width   width of active area in #dst.
- * @param height  height of active area in #dst.
+ * @param stride  distance between vertically adjacent pixels of dst.
+ * @param width   width of active area in dst.
+ * @param height  height of active area in dst.
  * @param pad_x   length of horizontal padding.
  * @param pad_y   length of vertical padding.
- */
-static void readPlane(Pel* dst, istream& fd, bool is16bit,
+ * @return true for success, false in case of error
+ */
+static bool readPlane(Pel* dst, istream& fd, bool is16bit,
                       unsigned int stride,
                       unsigned int width, unsigned int height,
@@ -238,11 +249,21 @@
   {
     fd.read(reinterpret_cast<char*>(buf), read_len);
-    if (!is16bit) {
-      for (int x = 0; x < width; x++) {
+    if (fd.eof() || fd.fail() )
+    {
+      delete[] buf;
+      return false;
+    }
+
+    if (!is16bit)
+    {
+      for (int x = 0; x < width; x++)
+      {
         dst[x] = buf[x];
       }
     }
-    else {
-      for (int x = 0; x < width; x++) {
+    else
+    {
+      for (int x = 0; x < width; x++)
+      {
         dst[x] = (buf[2*x+1] << 8) | buf[2*x];
       }
@@ -257,23 +278,26 @@
   for (int y = height; y < height + pad_y; y++)
   {
-    for (int x = width; x < width + pad_x; x++)
-    {
-      dst[x] = dst[x - stride];
+    for (int x = 0; x < width + pad_x; x++)
+    {
+      dst[x] = (dst - stride)[x];
     }
     dst += stride;
   }
   delete[] buf;
-}
-
-/**
- * Write \f$ #width * #height \f$ pixels info #fd from #src.
- *
+  return true;
+}
+
+/**
+ * Write width*height pixels info fd from src.
+ *
+ * @param fd      output file stream
  * @param src     source image
  * @param is16bit true if input file carries > 8bit data, false otherwise.
- * @param stride  distance between vertically adjacent pixels of #src.
- * @param width   width of active area in #src.
- * @param height  height of active area in #src.
- */
-static void writePlane(ostream& fd, Pel* src, bool is16bit,
+ * @param stride  distance between vertically adjacent pixels of src.
+ * @param width   width of active area in src.
+ * @param height  height of active area in src.
+ * @return true for success, false in case of error
+ */
+static bool writePlane(ostream& fd, Pel* src, bool is16bit,
                        unsigned int stride,
                        unsigned int width, unsigned int height)
@@ -300,7 +324,13 @@
 
     fd.write(reinterpret_cast<char*>(buf), write_len);
+    if (fd.eof() || fd.fail() )
+    {
+      delete[] buf;
+      return false;
+    }
     src += stride;
   }
   delete[] buf;
+  return true;
 }
 
@@ -309,24 +339,25 @@
  * from the bitdepth of the input file to the internal bit-depth.
  *
- * If a bit-depth reduction is requried, and internalBitdepth >= 8, then
+ * If a bit-depth reduction is required, and internalBitdepth >= 8, then
  * the input file is assumed to be ITU-R BT.601/709 compliant, and the
  * resulting data is clipped to the appropriate legal range, as if the
  * file had been provided at the lower-bitdepth compliant to Rec601/709.
  *
- \param rpcPicYuv      input picture YUV buffer class pointer
- \param aiPad[2]       source padding size, aiPad[0] = horizontal, aiPad[1] = vertical
- */
-Void TVideoIOYuv::read ( TComPicYuv*&  rpcPicYuv, Int aiPad[2], Bool bRewind /* = false */ )
+ * @param pPicYuv      input picture YUV buffer class pointer
+ * @param aiPad        source padding size, aiPad[0] = horizontal, aiPad[1] = vertical
+ * @return true for success, false in case of error
+ */
+bool TVideoIOYuv::read ( TComPicYuv*  pPicYuv, Int aiPad[2], Bool bRewind )
 {
   // check end-of-file
-  if ( isEof() ) return;
+  if ( isEof() ) return false;
   
-  Int   iStride = rpcPicYuv->getStride();
+  Int   iStride = pPicYuv->getStride();
   
   // compute actual YUV width & height excluding padding size
   unsigned int pad_h = aiPad[0];
   unsigned int pad_v = aiPad[1];
-  unsigned int width_full = rpcPicYuv->getWidth();
-  unsigned int height_full = rpcPicYuv->getHeight();
+  unsigned int width_full = pPicYuv->getWidth();
+  unsigned int height_full = pPicYuv->getHeight();
   unsigned int width  = width_full - pad_h;
   unsigned int height = height_full - pad_v;
@@ -345,6 +376,7 @@
 #endif
   
-  readPlane(rpcPicYuv->getLumaAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v);
-  scalePlane(rpcPicYuv->getLumaAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval);
+  if (! readPlane(pPicYuv->getLumaAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v))
+    return false;
+  scalePlane(pPicYuv->getLumaAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval);
 
   iStride >>= 1;
@@ -356,9 +388,11 @@
   pad_v >>= 1;
 
-  readPlane(rpcPicYuv->getCbAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v);
-  scalePlane(rpcPicYuv->getCbAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval);
-
-  readPlane(rpcPicYuv->getCrAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v);
-  scalePlane(rpcPicYuv->getCrAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval);
+  if (! readPlane(pPicYuv->getCbAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v))
+    return false;
+  scalePlane(pPicYuv->getCbAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval);
+
+  if (! readPlane(pPicYuv->getCrAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v))
+    return false;
+  scalePlane(pPicYuv->getCrAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval);
 
   if( bRewind )
@@ -367,27 +401,40 @@
     m_cHandle.seekg( -iFrameSize, std::ios_base::cur );
   }
-}
-
-/**
- * Write one Y'CbCr frame. No bit-depth conversion is performed, #pcPicYuv is
+
+  return true;
+}
+
+/**
+ * Write one Y'CbCr frame. No bit-depth conversion is performed, pcPicYuv is
  * assumed to be at TVideoIO::m_fileBitdepth depth.
  *
- \param pcPicYuv     input picture YUV buffer class pointer
- \param aiPad[2]     source padding size, aiPad[0] = horizontal, aiPad[1] = vertical
- */
-Void TVideoIOYuv::write( TComPicYuv* pcPicYuv, Int aiPad[2] )
+ * @param pPicYuv     input picture YUV buffer class pointer
+ * @param aiPad       source padding size, aiPad[0] = horizontal, aiPad[1] = vertical
+ * @return true for success, false in case of error
+ */
+#if PIC_CROPPING
+Bool TVideoIOYuv::write( TComPicYuv* pPicYuv, Int cropLeft, Int cropRight, Int cropTop, Int cropBottom )
+#else
+bool TVideoIOYuv::write( TComPicYuv* pPicYuv, Int aiPad[2] )
+#endif
 {
   // compute actual YUV frame size excluding padding size
-  Int   iStride = pcPicYuv->getStride();
-  unsigned int width  = pcPicYuv->getWidth() - aiPad[0];
-  unsigned int height = pcPicYuv->getHeight() - aiPad[1];
+  Int   iStride = pPicYuv->getStride();
+#if PIC_CROPPING
+  UInt  width  = pPicYuv->getWidth()  - cropLeft - cropRight;
+  UInt  height = pPicYuv->getHeight() - cropTop  - cropBottom;
+#else
+  unsigned int width  = pPicYuv->getWidth() - aiPad[0];
+  unsigned int height = pPicYuv->getHeight() - aiPad[1];
+#endif
   bool is16bit = m_fileBitdepth > 8;
   TComPicYuv *dstPicYuv = NULL;
+  bool retval = true;
 
   if (m_bitdepthShift != 0)
   {
     dstPicYuv = new TComPicYuv;
-    dstPicYuv->create( pcPicYuv->getWidth(), pcPicYuv->getHeight(), 1, 1, 0 );
-    pcPicYuv->copyToPic(dstPicYuv);
+    dstPicYuv->create( pPicYuv->getWidth(), pPicYuv->getHeight(), 1, 1, 0 );
+    pPicYuv->copyToPic(dstPicYuv);
 
     Pel minval = 0;
@@ -407,15 +454,47 @@
   else
   {
-    dstPicYuv = pcPicYuv;
-  }
+    dstPicYuv = pPicYuv;
+  }
+#if PIC_CROPPING
+  // location of upper left pel in a plane
+  Int planeOffset = 0; //cropLeft + cropTop * iStride;
   
-  writePlane(m_cHandle, dstPicYuv->getLumaAddr(), is16bit, iStride, width, height);
+  if (! writePlane(m_cHandle, dstPicYuv->getLumaAddr() + planeOffset, is16bit, iStride, width, height))
+#else
+  if (! writePlane(m_cHandle, dstPicYuv->getLumaAddr(), is16bit, iStride, width, height))
+#endif
+  {
+    retval=false; 
+    goto exit;
+  }
 
   width >>= 1;
   height >>= 1;
   iStride >>= 1;
-  writePlane(m_cHandle, dstPicYuv->getCbAddr(), is16bit, iStride, width, height);
-  writePlane(m_cHandle, dstPicYuv->getCrAddr(), is16bit, iStride, width, height);
+#if PIC_CROPPING
+  cropLeft >>= 1;
+  cropRight >>= 1;
+
+  planeOffset = 0; // cropLeft + cropTop * iStride;
+
+  if (! writePlane(m_cHandle, dstPicYuv->getCbAddr() + planeOffset, is16bit, iStride, width, height))
+#else
+  if (! writePlane(m_cHandle, dstPicYuv->getCbAddr(), is16bit, iStride, width, height))
+#endif
+  {
+    retval=false; 
+    goto exit;
+  }
+#if PIC_CROPPING
+  if (! writePlane(m_cHandle, dstPicYuv->getCrAddr() + planeOffset, is16bit, iStride, width, height))
+#else
+  if (! writePlane(m_cHandle, dstPicYuv->getCrAddr(), is16bit, iStride, width, height))
+#endif
+  {
+    retval=false; 
+    goto exit;
+  }
   
+exit:
   if (m_bitdepthShift != 0)
   {
@@ -423,4 +502,5 @@
     delete dstPicYuv;
   }  
-}
-
+  return retval;
+}
+
Index: trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h
===================================================================
--- trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h	(revision 5)
+++ trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h	(revision 56)
@@ -2,7 +2,7 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.
+ * granted under this license.  
  *
- * Copyright (c) 2010-2011, ISO/IEC
+ * Copyright (c) 2010-2012, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -15,5 +15,5 @@
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
- *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
  *    be used to endorse or promote products derived from this software without
  *    specific prior written permission.
@@ -31,6 +31,4 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
-
-
 
 /** \file     TVideoIOYuv.h
@@ -70,8 +68,13 @@
   void skipFrames(unsigned int numFrames, unsigned int width, unsigned int height);
   
-  Void  read  ( TComPicYuv*& rpcPicYuv, Int aiPad[2], Bool bRewind = false );     ///< read  one YUV frame with padding parameter
-  Void  write ( TComPicYuv*   pcPicYuv, Int aiPad[2] );     ///< write one YUV frame with padding parameter
+  bool  read  ( TComPicYuv*   pPicYuv, Int aiPad[2], Bool bRewind = false );     ///< read  one YUV frame with padding parameter
+#if PIC_CROPPING
+  Bool  write( TComPicYuv*    pPicYuv, Int cropLeft=0, Int cropRight=0, Int cropTop=0, Int cropBottom=0 );
+#else
+  bool  write ( TComPicYuv*   pPicYuv, Int aiPad[2] );     ///< write one YUV frame with padding parameter
+#endif
   
-  Bool  isEof ();                                           ///< check end-of-file
+  bool  isEof ();                                           ///< check for end-of-file
+  bool  isFail();                                           ///< check for failure
   
 };
