Index: trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp
===================================================================
--- trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp	(revision 1313)
+++ trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp	(revision 1386)
@@ -95,4 +95,6 @@
 }
 
+static Void
+copyPlane(const TComPicYuv &src, const ComponentID srcPlane, TComPicYuv &dest, const ComponentID destPlane);
 
 // ====================================================================================================================
@@ -116,5 +118,5 @@
  * \param internalBitDepth bit-depth array to scale image data to/from when reading/writing.
  */
-Void TVideoIOYuv::open( Char* pchFile, Bool bWriteMode, const Int fileBitDepth[MAX_NUM_CHANNEL_TYPE], const Int MSBExtendedBitDepth[MAX_NUM_CHANNEL_TYPE], const Int internalBitDepth[MAX_NUM_CHANNEL_TYPE] )
+Void TVideoIOYuv::open( const std::string &fileName, Bool bWriteMode, const Int fileBitDepth[MAX_NUM_CHANNEL_TYPE], const Int MSBExtendedBitDepth[MAX_NUM_CHANNEL_TYPE], const Int internalBitDepth[MAX_NUM_CHANNEL_TYPE] )
 {
   //NOTE: files cannot have bit depth greater than 16
@@ -141,5 +143,5 @@
   if ( bWriteMode )
   {
-    m_cHandle.open( pchFile, ios::binary | ios::out );
+    m_cHandle.open( fileName.c_str(), ios::binary | ios::out );
 
     if( m_cHandle.fail() )
@@ -151,5 +153,5 @@
   else
   {
-    m_cHandle.open( pchFile, ios::binary | ios::in );
+    m_cHandle.open( fileName.c_str(), ios::binary | ios::in );
 
     if( m_cHandle.fail() )
@@ -217,5 +219,5 @@
 
   /* fall back to consuming the input */
-  Char buf[512];
+  TChar buf[512];
   const streamoff offset_mod_bufsize = offset % sizeof(buf);
   for (streamoff i = 0; i < offset - offset_mod_bufsize; i += sizeof(buf))
@@ -274,5 +276,6 @@
   const UInt stride_file      = (width444 * (is16bit ? 2 : 1)) >> csx_file;
 
-  UChar  *buf   = new UChar[stride_file];
+  std::vector<UChar> bufVec(stride_file);
+  UChar *buf=&(bufVec[0]);
 
   if (compID!=COMPONENT_Y && (fileFormat==CHROMA_400 || destFormat==CHROMA_400))
@@ -297,5 +300,4 @@
       if (fd.eof() || fd.fail() )
       {
-        delete[] buf;
         return false;
       }
@@ -311,8 +313,7 @@
       {
         // read a new line
-        fd.read(reinterpret_cast<Char*>(buf), stride_file);
+        fd.read(reinterpret_cast<TChar*>(buf), stride_file);
         if (fd.eof() || fd.fail() )
         {
-          delete[] buf;
           return false;
         }
@@ -381,5 +382,4 @@
     }
   }
-  delete[] buf;
   return true;
 }
@@ -419,5 +419,6 @@
   const UInt height_file      = height444>>csy_file;
 
-  UChar  *buf   = new UChar[stride_file];
+  std::vector<UChar> bufVec(stride_file);
+  UChar *buf=&(bufVec[0]);
 
   if (compID!=COMPONENT_Y && (fileFormat==CHROMA_400 || srcFormat==CHROMA_400))
@@ -447,8 +448,7 @@
         }
 
-        fd.write(reinterpret_cast<Char*>(buf), stride_file);
+        fd.write(reinterpret_cast<const TChar*>(buf), stride_file);
         if (fd.eof() || fd.fail() )
         {
-          delete[] buf;
           return false;
         }
@@ -506,8 +506,7 @@
         }
 
-        fd.write(reinterpret_cast<Char*>(buf), stride_file);
+        fd.write(reinterpret_cast<const TChar*>(buf), stride_file);
         if (fd.eof() || fd.fail() )
         {
-          delete[] buf;
           return false;
         }
@@ -521,5 +520,4 @@
     }
   }
-  delete[] buf;
   return true;
 }
@@ -544,5 +542,6 @@
   const UInt height_file      = height444>>csy_file;
 
-  UChar  *buf   = new UChar[stride_file * 2];
+  std::vector<UChar> bufVec(stride_file * 2);
+  UChar *buf=&(bufVec[0]);
 
   if (compID!=COMPONENT_Y && (fileFormat==CHROMA_400 || srcFormat==CHROMA_400))
@@ -577,8 +576,7 @@
         }
 
-        fd.write(reinterpret_cast<Char*>(buf), (stride_file * 2));
+        fd.write(reinterpret_cast<const TChar*>(buf), (stride_file * 2));
         if (fd.eof() || fd.fail() )
         {
-          delete[] buf;
           return false;
         }
@@ -642,8 +640,7 @@
         }
 
-        fd.write(reinterpret_cast<Char*>(buf), (stride_file * 2));
+        fd.write(reinterpret_cast<const TChar*>(buf), (stride_file * 2));
         if (fd.eof() || fd.fail() )
         {
-          delete[] buf;
           return false;
         }
@@ -658,5 +655,4 @@
     }
   }
-  delete[] buf;
   return true;
 }
@@ -760,5 +756,5 @@
   if (ipCSC!=IPCOLOURSPACE_UNCHANGED)
   {
-    cPicYuvCSCd.create(pPicYuvUser->getWidth(COMPONENT_Y), pPicYuvUser->getHeight(COMPONENT_Y), pPicYuvUser->getChromaFormat(), pPicYuvUser->getWidth(COMPONENT_Y), pPicYuvUser->getHeight(COMPONENT_Y), 0, false);
+    cPicYuvCSCd.createWithoutCUInfo(pPicYuvUser->getWidth(COMPONENT_Y), pPicYuvUser->getHeight(COMPONENT_Y), pPicYuvUser->getChromaFormat() );
     ColourSpaceConvert(*pPicYuvUser, cPicYuvCSCd, ipCSC, false);
   }
@@ -766,14 +762,6 @@
 
   // compute actual YUV frame size excluding padding size
-  const Int   iStride444 = pPicYuv->getStride(COMPONENT_Y);
-  const UInt width444  = pPicYuv->getWidth(COMPONENT_Y) - confLeft - confRight;
-  const UInt height444 = pPicYuv->getHeight(COMPONENT_Y) -  confTop  - confBottom;
   Bool is16bit = false;
   Bool nonZeroBitDepthShift=false;
-
-  if ((width444 == 0) || (height444 == 0))
-  {
-    printf ("\nWarning: writing %d x %d luma sample output picture!", width444, height444);
-  }
 
   for(UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
@@ -799,6 +787,5 @@
   {
     dstPicYuv = new TComPicYuv;
-    dstPicYuv->create( pPicYuv->getWidth(COMPONENT_Y), pPicYuv->getHeight(COMPONENT_Y), pPicYuv->getChromaFormat(), pPicYuv->getWidth(COMPONENT_Y), pPicYuv->getHeight(COMPONENT_Y), 0, false );
-    pPicYuv->copyToPic(dstPicYuv);
+    dstPicYuv->createWithoutCUInfo( pPicYuv->getWidth(COMPONENT_Y), pPicYuv->getHeight(COMPONENT_Y), pPicYuv->getChromaFormat() );
 
     for(UInt comp=0; comp<dstPicYuv->getNumberValidComponents(); comp++)
@@ -810,4 +797,5 @@
       const Pel maxval = b709Compliance? ((0xff << (m_MSBExtendedBitDepth[ch] - 8)) -1) : (1 << m_MSBExtendedBitDepth[ch]) - 1;
 
+      copyPlane(*pPicYuv, compID, *dstPicYuv, compID);
       scalePlane(dstPicYuv->getAddr(compID), dstPicYuv->getStride(compID), dstPicYuv->getWidth(compID), dstPicYuv->getHeight(compID), -m_bitdepthShift[ch], minval, maxval);
     }
@@ -817,4 +805,14 @@
     dstPicYuv = pPicYuv;
   }
+
+  const Int  stride444 = dstPicYuv->getStride(COMPONENT_Y);
+  const UInt width444  = dstPicYuv->getWidth(COMPONENT_Y) - confLeft - confRight;
+  const UInt height444 = dstPicYuv->getHeight(COMPONENT_Y) -  confTop  - confBottom;
+
+  if ((width444 == 0) || (height444 == 0))
+  {
+    printf ("\nWarning: writing %d x %d luma sample output picture!", width444, height444);
+  }
+
 #if NH_3D
   for(UInt comp=0; retval && comp< ::getNumberValidComponents(format); comp++)
@@ -825,8 +823,8 @@
     const ComponentID compID = ComponentID(comp);
     const ChannelType ch=toChannelType(compID);
-    const UInt csx = pPicYuv->getComponentScaleX(compID);
-    const UInt csy = pPicYuv->getComponentScaleY(compID);
-    const Int planeOffset =  (confLeft>>csx) + (confTop>>csy) * pPicYuv->getStride(compID);
-    if (! writePlane(m_cHandle, dstPicYuv->getAddr(compID) + planeOffset, is16bit, iStride444, width444, height444, compID, dstPicYuv->getChromaFormat(), format, m_fileBitdepth[ch]))
+    const UInt csx = dstPicYuv->getComponentScaleX(compID);
+    const UInt csy = dstPicYuv->getComponentScaleY(compID);
+    const Int planeOffset =  (confLeft>>csx) + (confTop>>csy) * dstPicYuv->getStride(compID);
+    if (! writePlane(m_cHandle, dstPicYuv->getAddr(compID) + planeOffset, is16bit, stride444, width444, height444, compID, dstPicYuv->getChromaFormat(), format, m_fileBitdepth[ch]))
     {
       retval=false;
@@ -852,6 +850,6 @@
   if (ipCSC!=IPCOLOURSPACE_UNCHANGED)
   {
-    cPicYuvTopCSCd   .create(pPicYuvUserTop   ->getWidth(COMPONENT_Y), pPicYuvUserTop   ->getHeight(COMPONENT_Y), pPicYuvUserTop   ->getChromaFormat(), pPicYuvUserTop   ->getWidth(COMPONENT_Y), pPicYuvUserTop   ->getHeight(COMPONENT_Y), 0, false);
-    cPicYuvBottomCSCd.create(pPicYuvUserBottom->getWidth(COMPONENT_Y), pPicYuvUserBottom->getHeight(COMPONENT_Y), pPicYuvUserBottom->getChromaFormat(), pPicYuvUserBottom->getWidth(COMPONENT_Y), pPicYuvUserBottom->getHeight(COMPONENT_Y), 0, false);
+    cPicYuvTopCSCd   .createWithoutCUInfo(pPicYuvUserTop   ->getWidth(COMPONENT_Y), pPicYuvUserTop   ->getHeight(COMPONENT_Y), pPicYuvUserTop   ->getChromaFormat() );
+    cPicYuvBottomCSCd.createWithoutCUInfo(pPicYuvUserBottom->getWidth(COMPONENT_Y), pPicYuvUserBottom->getHeight(COMPONENT_Y), pPicYuvUserBottom->getChromaFormat() );
     ColourSpaceConvert(*pPicYuvUserTop,    cPicYuvTopCSCd,    ipCSC, false);
     ColourSpaceConvert(*pPicYuvUserBottom, cPicYuvBottomCSCd, ipCSC, false);
@@ -892,6 +890,5 @@
     {
       dstPicYuv = new TComPicYuv;
-      dstPicYuv->create( pPicYuv->getWidth(COMPONENT_Y), pPicYuv->getHeight(COMPONENT_Y), pPicYuv->getChromaFormat(), pPicYuv->getWidth(COMPONENT_Y), pPicYuv->getHeight(COMPONENT_Y), 0, false );
-      pPicYuv->copyToPic(dstPicYuv);
+      dstPicYuv->createWithoutCUInfo( pPicYuv->getWidth(COMPONENT_Y), pPicYuv->getHeight(COMPONENT_Y), pPicYuv->getChromaFormat() );
 
       for(UInt comp=0; comp<dstPicYuv->getNumberValidComponents(); comp++)
@@ -903,4 +900,5 @@
         const Pel maxval = b709Compliance? ((0xff << (m_MSBExtendedBitDepth[ch] - 8)) -1) : (1 << m_MSBExtendedBitDepth[ch]) - 1;
 
+        copyPlane(*pPicYuv, compID, *dstPicYuv, compID);
         scalePlane(dstPicYuv->getAddr(compID), dstPicYuv->getStride(compID), dstPicYuv->getWidth(compID), dstPicYuv->getHeight(compID), -m_bitdepthShift[ch], minval, maxval);
       }
@@ -916,7 +914,4 @@
   assert(dstPicYuvTop->getNumberValidComponents() == dstPicYuvBottom->getNumberValidComponents());
   assert(dstPicYuvTop->getChromaFormat()          == dstPicYuvBottom->getChromaFormat()         );
-  assert(dstPicYuvTop->getWidth(COMPONENT_Y)      == dstPicYuvBottom->getWidth(COMPONENT_Y)    );
-  assert(dstPicYuvTop->getHeight(COMPONENT_Y)     == dstPicYuvBottom->getHeight(COMPONENT_Y)    );
-  assert(dstPicYuvTop->getStride(COMPONENT_Y)     == dstPicYuvBottom->getStride(COMPONENT_Y)    );
 
   for(UInt comp=0; retval && comp<dstPicYuvTop->getNumberValidComponents(); comp++)
@@ -925,4 +920,6 @@
     const ChannelType ch=toChannelType(compID);
 
+    assert(dstPicYuvTop->getWidth          (compID) == dstPicYuvBottom->getWidth          (compID));
+    assert(dstPicYuvTop->getHeight         (compID) == dstPicYuvBottom->getHeight         (compID));
     assert(dstPicYuvTop->getComponentScaleX(compID) == dstPicYuvBottom->getComponentScaleX(compID));
     assert(dstPicYuvTop->getComponentScaleY(compID) == dstPicYuvBottom->getComponentScaleY(compID));
Index: trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h
===================================================================
--- trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h	(revision 1313)
+++ trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h	(revision 1386)
@@ -64,5 +64,5 @@
   virtual ~TVideoIOYuv()  {}
 
-  Void  open  ( Char* pchFile, Bool bWriteMode, const Int fileBitDepth[MAX_NUM_CHANNEL_TYPE], const Int MSBExtendedBitDepth[MAX_NUM_CHANNEL_TYPE], const Int internalBitDepth[MAX_NUM_CHANNEL_TYPE] ); ///< open or create file
+  Void  open  ( const std::string &fileName, Bool bWriteMode, const Int fileBitDepth[MAX_NUM_CHANNEL_TYPE], const Int MSBExtendedBitDepth[MAX_NUM_CHANNEL_TYPE], const Int internalBitDepth[MAX_NUM_CHANNEL_TYPE] ); ///< open or create file
   Void  close ();                                           ///< close file
 
