changeset 775:6daee65aa014

Merged multicoreware/xhevc into default
author Deepthi Devaki Akkoorath <deepthidevaki@multicorewareinc.com>
date Tue, 23 Apr 2013 18:24:06 +0530
parents eb50336c8520 (current diff) 0e66af1883ad (diff)
children 77b56bf695f2
files source/Lib/TLibVideoIO/TVideoIO.h source/Lib/TLibVideoIO/TVideoIOY4m.cpp source/Lib/TLibVideoIO/TVideoIOY4m.h source/Lib/TLibVideoIO/TVideoIOYuv.cpp source/Lib/TLibVideoIO/TVideoIOYuv.h source/encoder/vec/macroblock.inc
diffstat 32 files changed, 908 insertions(+-), 1752 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Tue Apr 23 11:07:40 2013 +0530
+++ b/.hgignore	Tue Apr 23 18:24:06 2013 +0530
@@ -4,3 +4,4 @@ build/
 **.orig
 **.hevc
 **.yuv
+**.y4m
--- a/build/BuildEncoderApplications.bat	Tue Apr 23 11:07:40 2013 +0530
+++ b/build/BuildEncoderApplications.bat	Tue Apr 23 18:24:06 2013 +0530
@@ -1,60 +1,60 @@
 @echo off
 
-cd "%builddir%"
-mkdir enabled
-cd enabled
-set solution="x265.sln"
-
-echo SET(ENABLE_TESTS ON CACHE BOOL "Enable Unit Tests" FORCE ^) >> enablecache.txt
-echo SET(HIGH_BIT_DEPTH ON CACHE BOOL "Use 16bit pixels internally" FORCE ^) >> enablecache.txt
-echo SET(ENABLE_PRIMITIVES ON CACHE BOOL "Enable use of optimized encoder primitives" FORCE ^) >> enablecache.txt
-
-cmake -G %makefile%  -C enablecache.txt ..\..\..\source 
-
-if exist %solution% (
-    call %vcvars%
-    MSBuild /property:Configuration="Release" x265.sln >> BuildLog.txt
-
-    if %errorlevel% equ 1 (
-        echo Build with primitive enabled unsuccessfull for %makefile% refer the build log  >> "%LOG%"
-        exit 1
-    )
-    echo Build with primitives enabled successfull for %makefile% >> "%LOG%"
+   cd "%builddir%"
+   mkdir enabled
+   cd enabled
+   set solution="x265.sln"
 
-    if exist Release\x265-cli.exe (
-        echo build Application with primitive enable successfull for %makefile% >> "%LOG%"			
-    ) else (
-       echo build Application with primitive enable unsuccessfull for %makefile%  refer the Build log >> "%LOG%"
-    )     
-) else (
-    echo Primitive Enable solution is not created for %makefile% >> "%LOG%"
-)
-
-cd "%builddir%"
-mkdir disable
-cd disable
-
-echo SET(ENABLE_TESTS ON CACHE BOOL "Enable Unit Tests" FORCE^) >> disablecache.txt
-echo SET(ENABLE_PRIMITIVES OFF CACHE BOOL "Enable use of optimized encoder primitives" FORCE^) >> disablecache.txt
-echo SET(ENABLE_PRIMITIVES_VEC OFF CACHE BOOL "Enable use of optimized encoder primitives" FORCE^) >> disablecache.txt
+	echo SET(ENABLE_TESTS ON CACHE BOOL "Enable Unit Tests" FORCE ^) >> enablecache.txt
+	echo SET(HIGH_BIT_DEPTH ON CACHE BOOL "Use 16bit pixels internally" FORCE ^) >> enablecache.txt
+	echo SET(ENABLE_PRIMITIVES ON CACHE BOOL "Enable use of optimized encoder primitives" FORCE ^) >> enablecache.txt
 
-cmake -G %makefile% -C disablecache.txt ..\..\..\source 
-
-if exist %solution% (
-    call %vcvars%
-    MSBuild /property:Configuration="Release" x265.sln >> BuildLog.txt
+	cmake -G %makefile%  -C enablecache.txt ..\..\..\source 
 
-    if %errorlevel% equ 1 (
-        echo Build with primitive disable unsuccessfull for %makefile% refer the build log  >> "%LOG%"
-        exit 1
-    )
-    echo Build with primitives disable successfull for %makefile% >> "%LOG%"
+	if exist %solution% (
+  		call %vcvars%
+		MSBuild /property:Configuration="Release" x265.sln >> BuildLog.txt
+		
+		if %errorlevel% equ 1 (
+			echo Build with primitive enabled unsuccessfull for %makefile% refer the build log  >> "%LOG%"
+			exit 1
+		)
+		echo Build with primitives enabled successfull for %makefile% >> "%LOG%"
 
-    if exist Release\x265-cli.exe (
-        echo build Application with primitive disable successfull for %makefile% >> "%LOG%"			
-    ) else (
-        echo build Application with primitive disable unsuccessfull for %makefile%  refer the Build log >> "%LOG%"
-    )     
-) else (
-    echo Primitive Disable solution is not created for %makefile% >> "%LOG%"
-)
+		if exist Release\x265-cli.exe (
+  			echo build Application with primitive enable successfull for %makefile% >> "%LOG%"			
+		) else (
+			echo build Application with primitive enable unsuccessfull for %makefile%  refer the Build log >> "%LOG%"
+		)     
+        ) else ( echo Primitive Enable solution is not created for %makefile% >> "%LOG%"
+        )
+
+
+   cd "%builddir%"
+   mkdir disable
+   cd disable
+ 
+	echo SET(ENABLE_TESTS ON CACHE BOOL "Enable Unit Tests" FORCE^) >> disablecache.txt
+	echo SET(ENABLE_PRIMITIVES OFF CACHE BOOL "Enable use of optimized encoder primitives" FORCE^) >> disablecache.txt
+	echo SET(ENABLE_PRIMITIVES_VEC OFF CACHE BOOL "Enable use of optimized encoder primitives" FORCE^) >> disablecache.txt
+
+	cmake -G %makefile% -C disablecache.txt ..\..\..\source 
+
+	if exist %solution% (
+  		call %vcvars%
+		MSBuild /property:Configuration="Release" x265.sln >> BuildLog.txt
+
+		if %errorlevel% equ 1 (
+			echo Build with primitive disable unsuccessfull for %makefile% refer the build log  >> "%LOG%"
+			exit 1
+		)
+		echo Build with primitives disable successfull for %makefile% >> "%LOG%"
+
+		if exist Release\x265-cli.exe (
+  			echo build Application with primitive disable successfull for %makefile% >> "%LOG%"			
+		) else (
+			echo build Application with primitive disable unsuccessfull for %makefile%  refer the Build log >> "%LOG%"
+		)     
+        ) else ( echo Primitive Disable solution is not created for %makefile% >> "%LOG%"
+        )
+
--- a/build/CreateRegressionPackage.bat	Tue Apr 23 11:07:40 2013 +0530
+++ b/build/CreateRegressionPackage.bat	Tue Apr 23 18:24:06 2013 +0530
@@ -1,19 +1,20 @@
 @echo off
 
-for /f "tokens=1,2,3 delims==" %%a in (config.txt) do (
+for /f "tokens=1,2,3,4,5,6 delims==" %%a in (config.txt) do (
 if %%a==workingdir set workingdir=%%b
 if %%a==testdir set testdir=%%b
 if %%a==repository set repository=%%b
+if %%a==video set video=%%b
 )
 
 set HG=hg
-set currentworkingdir="%workingdir%"RegressionTest
+set currentworkingdir=%workingdir%RegressionTest
 set Buildbat="BuildEncoderApplications.bat"
 
 if exist "%currentworkingdir%" rd /s /q %currentworkingdir%
 
 mkdir "%currentworkingdir%"
-cd "%currentworkingdir%"
+cd  /d "%currentworkingdir%"
 
 set LOG="%currentworkingdir%"\RegressionTester.log
 
@@ -44,40 +45,51 @@ if  not "%VS110COMNTOOLS%" == "" (
 	set makefile="Visual Studio 11 Win64"
 	set vcvars="%VS110COMNTOOLS%\..\..\VC\vcvarsall.bat"
 	call "%workingdir%BuildEncoderApplications.bat"
+	call "%workingdir%RunEncoderApplications.bat"
 
 	set builddir="%currentworkingdir%"\build\vc11-x86   
 	set makefile="Visual Studio 11"
 	call "%workingdir%BuildEncoderApplications.bat"     
+	call "%workingdir%RunEncoderApplications.bat"
 )
 
 ::Build the solution and applications for VS 10
 
+set builddir=""
+set makefile=""
+set vcvars=""
+
 if  not "%VS100COMNTOOLS%" == "" ( 
 	echo Regression Test	-	VS 10 Compiler found >> "%LOG%"
 	set builddir="%currentworkingdir%"\build\vc10-x86_64
 	set makefile="Visual Studio 10 Win64"
 	set vcvars="%VS100COMNTOOLS%\..\..\VC\vcvarsall.bat"
 	call "%workingdir%BuildEncoderApplications.bat"
+	call "%workingdir%RunEncoderApplications.bat"
 
 	set builddir="%currentworkingdir%"\build\vc10-x86        
 	set makefile="Visual Studio 10"
 	call "%workingdir%BuildEncoderApplications.bat"
+	call "%workingdir%RunEncoderApplications.bat"
 )
 
 ::Build the solution and applications foe VS 09
 
+set builddir=""
+set makefile=""
+set vcvars=""
+
 if  not "%%VS90COMNTOOLS%" == "" ( 
 	echo Regression Test	-	VS 09 Compiler found >> "%LOG%"
 	set builddir="%currentworkingdir%"\build\vc9-x86_64
-	set makefile="Visual Studio 9 2008"
+	set makefile="Visual Studio 9 2008 Win64"
 	set vcvars="%%VS90COMNTOOLS%%\..\..\VC\vcvarsall.bat"
 	call "%workingdir%BuildEncoderApplications.bat"
+	call "%workingdir%RunEncoderApplications.bat"
 
 	set builddir="%currentworkingdir%"\build\vc9-x86        
-	set makefile="Visual Studio 10"
+	set makefile="Visual Studio 9 2008"
 	call "%workingdir%BuildEncoderApplications.bat"
+	call "%workingdir%RunEncoderApplications.bat"
 )
 
-
-:: To do list 
-:: Running the test bench and Encoder Application for all the build version
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/build/CreateRegressionPackage.sh	Tue Apr 23 18:24:06 2013 +0530
@@ -0,0 +1,124 @@
+#!/bin/sh
+
+CONFIG_FILE=config.txt
+
+if [[ -f $CONFIG_FILE ]]; then
+        . $CONFIG_FILE
+fi
+
+HG=hg
+CWD=$WD/RegressionTest
+LOG=$CWD/RegressionTester.log
+
+
+if [ ! -d $CWD ]
+	then 
+		mkdir $CWD
+		if [ $? -ne 0 ] 
+			then	
+				echo -e "Unable to create Working directory" >> $LOG
+				exit
+		fi
+		echo "Working directory created\n" >> $LOG
+		cd $CWD
+		
+		$HG init
+		$HG pull $repository
+		$HG update
+	
+		if [ $? -ne 0 ] 
+			then	
+				echo -e "Unable to pull from $REPOSITORY" >> $LOG
+				exit
+		fi
+		echo "Pull successfull from $REPOSITORY\n" >> $LOG		
+fi
+
+
+## Building for msys
+
+BUILDDIR=$CWD/build/msys
+
+cd $BUILDDIR
+mkdir enabled
+cd enabled
+
+echo  "SET(ENABLE_TESTS ON CACHE BOOL \"Enable Unit Tests\" FORCE )" >> enablecache.txt
+echo  "SET(HIGH_BIT_DEPTH ON CACHE BOOL \"Use 16bit pixels internally\" FORCE )" >> enablecache.txt
+echo  "SET(ENABLE_PRIMITIVES ON CACHE BOOL \"Enable use of optimized encoder primitives\" FORCE ) " >> enablecache.txt
+
+cmake -G "MSYS Makefiles" -C enablecache.txt ../../../source
+make all
+if [ $? -ne 0 ] 
+	then	
+		echo -e "Unable to build for MSYS\n" >> $LOG
+fi
+echo -e "Build successfull for MSYS\n" >> $LOG
+echo -e "Running the encoder\n" >> $LOG
+./x265-cli.exe -c $CWD/cfg/encoder_all_I.cfg -c $CWD/cfg/per-sequence/BasketballDrive.cfg -f 3 -i $WD/$VIDEO >> ExecLog.txt
+./test/TestBench.exe >> test/TestBenchLog.txt
+
+cd $BUILDDIR
+mkdir disabled
+cd disabled
+
+echo "SET(ENABLE_TESTS ON CACHE BOOL \"Enable Unit Tests\" FORCE )" >> disablecache.txt
+echo "SET(ENABLE_PRIMITIVES OFF CACHE BOOL \"Use 16bit pixels internally\" FORCE )" >> disablecache.txt
+echo "SET(ENABLE_PRIMITIVES_VEC OFF CACHE BOOL \"Enable use of optimized encoder primitives\" FORCE )" >> disablecache.txt
+
+cmake -G "MSYS Makefiles" -C disablecache.txt ../../../source
+make all
+if [ $? -ne 0 ] 
+	then	
+		echo -e "Unable to build for MSYS, primitives disabled\n" >> $LOG
+fi
+echo -e "Build successfull for MSYS, primitives disabled\n" >> $LOG
+echo -e "Running the encoder\n" >> $LOG
+./x265-cli.exe -c $CWD/cfg/encoder_all_I.cfg -c $CWD/cfg/per-sequence/BasketballDrive.cfg -f 3 -i $WD/$VIDEO >> ExecLog.txt
+./test/TestBench.exe >> test/TestBenchLog.txt
+
+
+## Building for linux
+
+BUILDDIR=$CWD/build/linux
+
+cd $BUILDDIR
+mkdir enabled
+cd enabled
+
+echo "SET(ENABLE_TESTS ON CACHE BOOL \"Enable Unit Tests\" FORCE )" >> enablecache.txt
+echo "SET(HIGH_BIT_DEPTH ON CACHE BOOL \"Use 16bit pixels internally\" FORCE )" >> enablecache.txt
+echo "SET(ENABLE_PRIMITIVES ON CACHE BOOL \"Enable use of optimized encoder primitives\" FORCE )" >> enablecache.txt
+
+cmake -G "Unix Makefiles" -C enablecache.txt ../../../source
+make all
+if [ $? -ne 0 ] 
+	then	
+		echo -e "Unable to build for Unix\n" >> $LOG
+fi
+echo -e "Build successfull for Unix\n" >> $LOG
+echo -e "Running the encoder\n" >> $LOG
+./x265-cli.exe -c $CWD/cfg/encoder_all_I.cfg -c $CWD/cfg/per-sequence/BasketballDrive.cfg -f 3 -i $WD/$VIDEO >> ExecLog.txt
+./test/TestBench.exe >> test/TestBenchLog.txt
+
+
+cd $BUILDDIR
+mkdir disabled
+cd disabled
+
+echo "SET(ENABLE_TESTS ON CACHE BOOL \"Enable Unit Tests\" FORCE )" >> disablecache.txt
+echo "SET(ENABLE_PRIMITIVES OFF CACHE BOOL \"Use 16bit pixels internally\" FORCE )" >> disablecache.txt
+echo "SET(ENABLE_PRIMITIVES_VEC OFF CACHE BOOL \"Enable use of optimized encoder primitives\" FORCE )" >> disablecache.txt
+
+cmake -G "Unix Makefiles" -C disablecache.txt ../../../source
+make all
+if [ $? -ne 0 ] 
+	then	
+		echo -e "Unable to build for Unix, primitives disabled\n" >> $LOG
+fi
+echo -e "Build successfull for Unix, primitives disabled\n" >> $LOG
+echo -e "Running the encoder\n" >> $LOG
+./x265-cli.exe -c $CWD/cfg/encoder_all_I.cfg -c $CWD/cfg/per-sequence/BasketballDrive.cfg -f 3 -i $WD/$VIDEO >> ExecLog.txt
+./test/TestBench.exe >> test/TestBenchLog.txt
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/build/RunEncoderApplications.bat	Tue Apr 23 18:24:06 2013 +0530
@@ -0,0 +1,24 @@
+@echo off
+
+   cd "%builddir%\enabled"
+	if exist Release\x265-cli.exe (
+		cd Release
+		x265-cli.exe -c "%currentworkingdir%"\cfg\encoder_all_I.cfg -c "%currentworkingdir%"\cfg\per-sequence\BasketballDrive.cfg -f 3 -i "%video%" >> ExecLog.txt
+	)
+
+   cd "%builddir%\enabled"
+	if exist test\Release\TestBench.exe (
+		cd test\Release
+		TestBench.exe >> TestLog.txt
+	) 
+
+   cd "%builddir%\disable\Release"
+ 	if exist x265-cli.exe (
+		
+		x265-cli.exe -c "%currentworkingdir%"\cfg\encoder_all_I.cfg -c "%currentworkingdir%"\cfg\per-sequence\BasketballDrive.cfg -f 3 -i "%video%" >> ExecLog.txt
+	) 
+   cd "%builddir%\disable"
+	if exist test\Release\TestBench.exe (
+		cd test\Release
+		TestBench.exe >> TestLog.txt
+	) 
--- a/build/config.txt	Tue Apr 23 11:07:40 2013 +0530
+++ b/build/config.txt	Tue Apr 23 18:24:06 2013 +0530
@@ -1,4 +1,6 @@
-workingdir=E:\\
+workingdir=D:\\
 testdir=TestEncoder
 repository=https://ggopu@bitbucket.org/multicoreware/xhevc
-
+video=D:\\Videos\BasketballDrive_1920x1080_50\BasketballDrive_1920x1080_50.yuv
+WD=/d
+VIDEO=Videos/BasketballDrive_1920x1080_50/BasketballDrive_1920x1080_50.yuv
\ No newline at end of file
--- a/source/CMakeLists.txt	Tue Apr 23 11:07:40 2013 +0530
+++ b/source/CMakeLists.txt	Tue Apr 23 18:24:06 2013 +0530
@@ -86,12 +86,14 @@ if(ENABLE_CLI)
     set_source_files_properties(x265main.cpp PROPERTIES COMPILE_FLAGS -DX265_VERSION=${X265_VERSION})
 
     add_subdirectory(input)
+    add_subdirectory(output)
+
     add_executable(x265-cli
         x265main.cpp ${EXTRAS}
         x265cfg.cpp x265cfg.h
         x265enc.cpp x265enc.h)
 
-    target_link_libraries(x265-cli HM x265 InputFiles)
+    target_link_libraries(x265-cli HM x265 InputFiles OutputFiles)
     if(ENABLE_PPA)
         target_link_libraries(x265-cli PPA)
         if(UNIX)
--- a/source/Lib/CMakeLists.txt	Tue Apr 23 11:07:40 2013 +0530
+++ b/source/Lib/CMakeLists.txt	Tue Apr 23 18:24:06 2013 +0530
@@ -16,11 +16,9 @@ endif(MSVC)
 file(GLOB APPCOMMON  TAppCommon/*.h TAppCommon/*.cpp)
 file(GLOB LIBCOMMON  TLibCommon/*.h TLibCommon/*.cpp)
 file(GLOB LIBENCODER TLibEncoder/*.h TLibEncoder/*.cpp)
-file(GLOB LIBVIDEOIO TLibVideoIO/*.h TLibVideoIO/*.cpp)
 
-source_group(TLibVideoIO FILES ${LIBVIDEOIO})
 source_group(TAppCommon  FILES ${APPCOMMON})
 source_group(TLibCommon  FILES ${LIBCOMMON})
 source_group(TLibEncoder FILES ${LIBENCODER})
 
-add_library(HM ${LIBCOMMON} ${LIBENCODER} ${APPCOMMON} ${LIBVIDEOIO})
+add_library(HM ${LIBCOMMON} ${LIBENCODER} ${APPCOMMON})
--- a/source/Lib/TLibCommon/TComLoopFilter.cpp	Tue Apr 23 11:07:40 2013 +0530
+++ b/source/Lib/TLibCommon/TComLoopFilter.cpp	Tue Apr 23 18:24:06 2013 +0530
@@ -758,23 +758,23 @@ Void TComLoopFilter::xEdgeFilterChroma(T
 {
     Int delta;
 
-    Pel m4  = piSrc[0];
-    Pel m3  = piSrc[-iOffset];
-    Pel m5  = piSrc[iOffset];
-    Pel m2  = piSrc[-iOffset * 2];
-    Pel m6  = piSrc[iOffset * 2];
-    Pel m1  = piSrc[-iOffset * 3];
-    Pel m7  = piSrc[iOffset * 3];
-    Pel m0  = piSrc[-iOffset * 4];
+    Short m4  = (Short) piSrc[0];
+    Short m3  = (Short) piSrc[-iOffset];
+    Short m5  = (Short) piSrc[iOffset];
+    Short m2  = (Short) piSrc[-iOffset * 2];
+    Short m6  = (Short) piSrc[iOffset * 2];
+    Short m1  = (Short) piSrc[-iOffset * 3];
+    Short m7  = (Short) piSrc[iOffset * 3];
+    Short m0  = (Short) piSrc[-iOffset * 4];
 
     if (sw)
     {
-        piSrc[-iOffset]   = Clip3(m3 - 2 * tc, m3 + 2 * tc, ((m1 + 2 * m2 + 2 * m3 + 2 * m4 + m5 + 4) >> 3));
-        piSrc[0]          = Clip3(m4 - 2 * tc, m4 + 2 * tc, ((m2 + 2 * m3 + 2 * m4 + 2 * m5 + m6 + 4) >> 3));
-        piSrc[-iOffset * 2] = Clip3(m2 - 2 * tc, m2 + 2 * tc, ((m1 + m2 + m3 + m4 + 2) >> 2));
-        piSrc[iOffset]   = Clip3(m5 - 2 * tc, m5 + 2 * tc, ((m3 + m4 + m5 + m6 + 2) >> 2));
-        piSrc[-iOffset * 3] = Clip3(m1 - 2 * tc, m1 + 2 * tc, ((2 * m0 + 3 * m1 + m2 + m3 + m4 + 4) >> 3));
-        piSrc[iOffset * 2] = Clip3(m6 - 2 * tc, m6 + 2 * tc, ((m3 + m4 + m5 + 3 * m6 + 2 * m7 + 4) >> 3));
+        piSrc[-iOffset]   = (Pel) Clip3(m3 - 2 * tc, m3 + 2 * tc, ((m1 + 2 * m2 + 2 * m3 + 2 * m4 + m5 + 4) >> 3));
+        piSrc[0]          = (Pel) Clip3(m4 - 2 * tc, m4 + 2 * tc, ((m2 + 2 * m3 + 2 * m4 + 2 * m5 + m6 + 4) >> 3));
+        piSrc[-iOffset * 2] = (Pel) Clip3(m2 - 2 * tc, m2 + 2 * tc, ((m1 + m2 + m3 + m4 + 2) >> 2));
+        piSrc[iOffset]   = (Pel) Clip3(m5 - 2 * tc, m5 + 2 * tc, ((m3 + m4 + m5 + m6 + 2) >> 2));
+        piSrc[-iOffset * 3] = (Pel) Clip3(m1 - 2 * tc, m1 + 2 * tc, ((2 * m0 + 3 * m1 + m2 + m3 + m4 + 4) >> 3));
+        piSrc[iOffset * 2] = (Pel) Clip3(m6 - 2 * tc, m6 + 2 * tc, ((m3 + m4 + m5 + 3 * m6 + 2 * m7 + 4) >> 3));
     }
     else
     {
@@ -784,34 +784,34 @@ Void TComLoopFilter::xEdgeFilterChroma(T
         if (abs(delta) < iThrCut)
         {
             delta = Clip3(-tc, tc, delta);
-            piSrc[-iOffset] = ClipY((m3 + delta));
-            piSrc[0] = ClipY((m4 - delta));
+            piSrc[-iOffset] = (Pel) ClipY((m3 + delta));
+            piSrc[0] = (Pel) ClipY((m4 - delta));
 
             Int tc2 = tc >> 1;
             if (bFilterSecondP)
             {
                 Int delta1 = Clip3(-tc2, tc2, ((((m1 + m3 + 1) >> 1) - m2 + delta) >> 1));
-                piSrc[-iOffset * 2] = ClipY((m2 + delta1));
+                piSrc[-iOffset * 2] = (Pel) ClipY((m2 + delta1));
             }
             if (bFilterSecondQ)
             {
                 Int delta2 = Clip3(-tc2, tc2, ((((m6 + m4 + 1) >> 1) - m5 - delta) >> 1));
-                piSrc[iOffset] = ClipY((m5 + delta2));
+                piSrc[iOffset] = (Pel) ClipY((m5 + delta2));
             }
         }
     }
 
     if (bPartPNoFilter)
     {
-        piSrc[-iOffset] = m3;
-        piSrc[-iOffset * 2] = m2;
-        piSrc[-iOffset * 3] = m1;
+        piSrc[-iOffset] = (Pel) m3;
+        piSrc[-iOffset * 2] = (Pel) m2;
+        piSrc[-iOffset * 3] = (Pel) m1;
     }
     if (bPartQNoFilter)
     {
-        piSrc[0] = m4;
-        piSrc[iOffset] = m5;
-        piSrc[iOffset * 2] = m6;
+        piSrc[0] = (Pel) m4;
+        piSrc[iOffset] = (Pel) m5;
+        piSrc[iOffset * 2] = (Pel) m6;
     }
 }
 
@@ -828,22 +828,22 @@ Void TComLoopFilter::xEdgeFilterChroma(T
 {
     Int delta;
 
-    Pel m4  = piSrc[0];
-    Pel m3  = piSrc[-iOffset];
-    Pel m5  = piSrc[iOffset];
-    Pel m2  = piSrc[-iOffset * 2];
+    Short m4  = (Short) piSrc[0];
+    Short m3  = (Short) piSrc[-iOffset];
+    Short m5  = (Short) piSrc[iOffset];
+    Short m2  = (Short) piSrc[-iOffset * 2];
 
     delta = Clip3(-tc, tc, ((((m4 - m3) << 2) + m2 - m5 + 4) >> 3));
-    piSrc[-iOffset] = ClipC(m3 + delta);
-    piSrc[0] = ClipC(m4 - delta);
+    piSrc[-iOffset] = (Pel) ClipC(m3 + delta);
+    piSrc[0] = (Pel) ClipC(m4 - delta);
 
     if (bPartPNoFilter)
     {
-        piSrc[-iOffset] = m3;
+        piSrc[-iOffset] = (Pel) m3;
     }
     if (bPartQNoFilter)
     {
-        piSrc[0] = m4;
+        piSrc[0] = (Pel) m4;
     }
 }
 
@@ -858,10 +858,10 @@ Void TComLoopFilter::xEdgeFilterChroma(T
  */
 __inline Bool TComLoopFilter::xUseStrongFiltering(Int offset, Int d, Int beta, Int tc, Pel* piSrc)
 {
-    Pel m4  = piSrc[0];
-    Pel m3  = piSrc[-offset];
-    Pel m7  = piSrc[offset * 3];
-    Pel m0  = piSrc[-offset * 4];
+    Short m4  = (Short) piSrc[0];
+    Short m3  = (Short) piSrc[-offset];
+    Short m7  = (Short) piSrc[offset * 3];
+    Short m0  = (Short) piSrc[-offset * 4];
 
     Int d_strong = abs(m0 - m3) + abs(m7 - m4);
 
@@ -870,12 +870,12 @@ Void TComLoopFilter::xEdgeFilterChroma(T
 
 __inline Int TComLoopFilter::xCalcDP(Pel* piSrc, Int iOffset)
 {
-    return abs(piSrc[-iOffset * 3] - 2 * piSrc[-iOffset * 2] + piSrc[-iOffset]);
+    return abs(static_cast<Int>(piSrc[-iOffset * 3]) - 2 * piSrc[-iOffset * 2] + piSrc[-iOffset]);
 }
 
 __inline Int TComLoopFilter::xCalcDQ(Pel* piSrc, Int iOffset)
 {
-    return abs(piSrc[0] - 2 * piSrc[iOffset] + piSrc[iOffset * 2]);
+    return abs(static_cast<Int> (piSrc[0]) - 2 * piSrc[iOffset] + piSrc[iOffset * 2]);
 }
 
 //! \}
--- a/source/Lib/TLibCommon/TComPrediction.cpp	Tue Apr 23 11:07:40 2013 +0530
+++ b/source/Lib/TLibCommon/TComPrediction.cpp	Tue Apr 23 18:24:06 2013 +0530
@@ -279,7 +279,7 @@ Void TComPrediction::xPredIntraAng(Int b
             {
                 for (k = 0; k < blkSize; k++)
                 {
-                    pDst[k * dstStride] = Clip3(0, (1 << bitDepth) - 1, pDst[k * dstStride] + ((refSide[k + 1] - refSide[0]) >> 1));
+                    pDst[k * dstStride] = Clip3(0, (1 << bitDepth) - 1, static_cast<Int> (pDst[k * dstStride]) + ((refSide[k + 1] - refSide[0]) >> 1));
                 }
             }
         }
--- a/source/Lib/TLibCommon/TComTrQuant.cpp	Tue Apr 23 11:07:40 2013 +0530
+++ b/source/Lib/TLibCommon/TComTrQuant.cpp	Tue Apr 23 18:24:06 2013 +0530
@@ -914,8 +914,13 @@ void xITrMxN(Int bitDepth, Short *coeff,
     }
     else if (iWidth == 16 && iHeight == 16)
     {
+#ifdef ENABLE_PRIMITIVES
+        x265::primitives.partial_butterfly[x265::BUTTERFLY_INVERSE_16](coeff, tmp, shift_1st, iWidth);
+        x265::primitives.partial_butterfly[x265::BUTTERFLY_INVERSE_16](tmp, block, shift_2nd, iHeight);
+#else
         partialButterflyInverse16(coeff, tmp, shift_1st, iWidth);
         partialButterflyInverse16(tmp, block, shift_2nd, iHeight);
+#endif
     }
     else if (iWidth == 32 && iHeight == 32)
     {
--- a/source/Lib/TLibEncoder/TEncTop.h	Tue Apr 23 11:07:40 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncTop.h	Tue Apr 23 18:24:06 2013 +0530
@@ -45,9 +45,6 @@
 #include "TLibCommon/TComPrediction.h"
 #include "TLibCommon/TComTrQuant.h"
 #include "TLibCommon/AccessUnit.h"
-
-#include "TLibVideoIO/TVideoIOYuv.h"
-
 #include "TEncCfg.h"
 #include "TEncGOP.h"
 #include "TEncSlice.h"
@@ -58,6 +55,7 @@
 #include "TEncSampleAdaptiveOffset.h"
 #include "TEncPreanalyzer.h"
 #include "TEncRateCtrl.h"
+
 //! \ingroup TLibEncoder
 //! \{
 
--- a/source/Lib/TLibVideoIO/TVideoIO.h	Tue Apr 23 11:07:40 2013 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,98 +0,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-2013, ITU/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 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.
- *
- * 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     TVideoIO.h
-    \brief    YUV file I/O class (header)
-*/
-
-#ifndef __TVIDEOIO__
-#define __TVIDEOIO__
-
-#include <stdio.h>
-#include <fstream>
-#include <iostream>
-#include "TLibCommon/CommonDef.h"
-#include "TLibCommon/TComPicYuv.h"
-
-using namespace std;
-
-typedef void *hnd_t;
-
-typedef struct
-{
-    Int width;
-    Int height;
-    Int FrameRate;
-    Int interlaced;
-} video_info_t;
-
-// ====================================================================================================================
-// Class definition
-// ====================================================================================================================
-
-/// YUV file I/O class
-class TVideoIO
-{
-public:
-
-    TVideoIO()           {}
-
-    virtual ~TVideoIO()  {}
-
-    virtual Void  open(Char * pchFile,
-                       Bool bWriteMode,
-                       Int internalBitDepthY,
-                       Int fileBitDepthY,
-                       Int internalBitDepthC,
-                       Int fileBitDepthC,
-                       hnd_t * &handler,
-                       video_info_t video_info,
-                       Int aiPad[2]) = 0;                                                                                                                                                               ///< open or create file
-    virtual  Void  close(hnd_t* &handler) = 0;                                          ///< close file
-
-    virtual void skipFrames(UInt numFrames, UInt width, UInt height, hnd_t* &handler) = 0;
-
-    virtual Bool  read(TComPicYuv * pPicYuv, hnd_t* &handler) = 0;      ///< read  one YUV frame with padding parameter
-    virtual Bool  write(TComPicYuv* pPicYuv,
-                        hnd_t* &    handler,
-                        Int         confLeft = 0,
-                        Int         confRight = 0,
-                        Int         confTop = 0,
-                        Int         confBottom = 0) = 0;
-
-    virtual Bool  isEof(hnd_t* &handler) = 0;                                          ///< check for end-of-file
-    virtual Bool  isFail(hnd_t* &handler) = 0;                                         ///< check for failure
-    virtual Void  getVideoInfo(video_info_t &video_info, hnd_t* &handler) = 0;
-};
-
-#endif // __TVIDEOIO__
--- a/source/Lib/TLibVideoIO/TVideoIOY4m.cpp	Tue Apr 23 11:07:40 2013 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,746 +0,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-2013, ITU/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 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.
- *
- * 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     TVideoIOYuv.cpp
-    \brief    YUV file I/O class
-*/
-
-#include <cmath>
-#include <cstdlib>
-#include <fcntl.h>
-#include <assert.h>
-#include <sys/stat.h>
-#include <fstream>
-#include <iostream>
-
-#include "TLibCommon/TComRom.h"
-#include "TVideoIOY4m.h"
-
-using namespace std;
-
-/**
- * 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, UInt stride, UInt width, UInt height,
-                          UInt shiftbits, Pel minval, Pel maxval)
-{
-    Pel offset = 1 << (shiftbits - 1);
-
-    for (UInt y = 0; y < height; y++)
-    {
-        for (UInt x = 0; x < width; x++)
-        {
-            Pel val = (img[x] + offset) >> shiftbits;
-            img[x] = Clip3(minval, maxval, val);
-        }
-
-        img += stride;
-    }
-}
-
-/**
- * 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, UInt stride, UInt width, UInt height,
-                       UInt shiftbits)
-{
-    for (UInt y = 0; y < height; y++)
-    {
-        for (UInt x = 0; x < width; x++)
-        {
-            img[x] <<= shiftbits;
-        }
-
-        img += stride;
-    }
-}
-
-/**
- * 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 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.
- * @param maxval  maximum clipping value when dividing.
- */
-static void scalePlane(Pel* img, UInt stride, UInt width, UInt height,
-                       Int shiftbits, Pel minval, Pel maxval)
-{
-    if (shiftbits == 0)
-    {
-        return;
-    }
-
-    if (shiftbits > 0)
-    {
-        scalePlane(img, stride, width, height, shiftbits);
-    }
-    else
-    {
-        invScalePlane(img, stride, width, height, -shiftbits, minval, maxval);
-    }
-}
-
-// ====================================================================================================================
-// Public member functions
-// ====================================================================================================================
-
-/**
- * Open file for reading/writing Y'CbCr frames.
- *
- * 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
- * (See scalePlane(), TVideoIOYuv::read() and TVideoIOYuv::write() for
- * further details).
- *
- * \param pchFile          file name string
- * \param bWriteMode       file open mode: true=read, false=write
- * \param fileBitDepthY     bit-depth of input/output file data (luma component).
- * \param fileBitDepthC     bit-depth of input/output file data (chroma components).
- * \param internalBitDepthY bit-depth to scale image data to/from when reading/writing (luma component).
- * \param internalBitDepthC bit-depth to scale image data to/from when reading/writing (chroma components).
- */
-Void TVideoIOY4m::open(Char*        pchFile,
-                       Bool         bWriteMode,
-                       Int          internalBitDepthY,
-                       Int          fileBitDepthY,
-                       Int          internalBitDepthC,
-                       Int          fileBitDepthC,
-                       hnd_t* &     handler,
-                       video_info_t video_info,
-                       Int          aiPad[2])
-{
-    y4m_hnd_t* y4m_handler = NULL;
-
-    if ((y4m_hnd_t*)handler == NULL)
-    {
-        y4m_handler = new y4m_hnd_t();
-        //yuv_hnd_t *yuv_handler = malloc( sizeof(yuv_hnd_t) );
-
-        if (bWriteMode)
-        {
-            y4m_handler->m_cHandle.open(pchFile, ios::binary | ios::out);
-
-            if (y4m_handler->m_cHandle.fail())
-            {
-                printf("\nfailed to write reconstructed YUV file\n");
-                exit(0);
-            }
-        }
-        else
-        {
-            y4m_handler->m_cHandle.open(pchFile, ios::binary | ios::in);
-
-            if (y4m_handler->m_cHandle.fail())
-            {
-                printf("\nfailed to open Input YUV file\n");
-                exit(0);
-            }
-        }
-    }
-    else
-    {
-        y4m_handler = (y4m_hnd_t*)handler;
-        y4m_handler->m_cHandle.seekg(y4m_handler->headerLength);
-    }
-
-    y4m_handler->bitDepthShiftY = internalBitDepthY - fileBitDepthY;
-    y4m_handler->bitDepthShiftC = internalBitDepthC - fileBitDepthC;
-    y4m_handler->fileBitDepthY = fileBitDepthY;
-    y4m_handler->fileBitDepthC = fileBitDepthC;
-    y4m_handler->aiPad[0] = aiPad[0];
-    y4m_handler->aiPad[1] = aiPad[1];
-    handler =  (hnd_t*)y4m_handler;
-}
-
-Void  TVideoIOY4m::getVideoInfo(video_info_t &video_info, hnd_t* &handler)
-{
-    y4m_hnd_t* y4m_handler = (y4m_hnd_t*)handler;
-    /*stripping off the plaintext, quasi-freeform header */
-    Char source[5];
-    Int width = 0;
-    Int height = 0;
-    Int rateNumerator = 0;
-    Int rateDenominator = 0;
-    //Int headerLength = 0 ;
-    Double rate = 30.0;
-
-    while (1)
-    {
-        source[0] = 0x0;
-
-        while ((source[0] != 0x20) && (source[0] != 0x0a))
-        {
-            y4m_handler->m_cHandle.read(source, 1);
-            //headerLength++;
-            if (y4m_handler->m_cHandle.eof() || y4m_handler->m_cHandle.fail())
-            {
-                break;
-            }
-        }
-
-        if (source[0] == 0x00)
-        {
-            break;
-        }
-
-        while (source[0] == 0x20)
-        {
-            //  read parameter identifier
-
-            y4m_handler->m_cHandle.read(source + 1, 1);
-            //headerLength++;
-            if (source[1] == 'W')
-            {
-                width = 0;
-                while (true)
-                {
-                    y4m_handler->m_cHandle.read(source, 1);
-
-                    if (source[0] == 0x20 || source[0] == 0x0a)
-                    {
-                        break;
-                    }
-                    else
-                    {
-                        width = width * 10 + (source[0] - '0');
-                    }
-                }
-
-                continue;
-            }
-
-            if (source[1] == 'H')
-            {
-                height = 0;
-                while (true)
-                {
-                    y4m_handler->m_cHandle.read(source, 1);
-                    if (source[0] == 0x20 || source[0] == 0x0a)
-                    {
-                        break;
-                    }
-                    else
-                    {
-                        height = height * 10 + (source[0] - '0');
-                    }
-                }
-
-                continue;
-            }
-
-            if (source[1] == 'F')
-            {
-                rateNumerator = 0;
-                rateDenominator = 0;
-                while (true)
-                {
-                    y4m_handler->m_cHandle.read(source, 1);
-                    if (source[0] == '.')
-                    {
-                        rateDenominator = 1;
-                        while (true)
-                        {
-                            y4m_handler->m_cHandle.read(source, 1);
-                            if (source[0] == 0x20 || source[0] == 0x10)
-                            {
-                                break;
-                            }
-                            else
-                            {
-                                rateNumerator = rateNumerator * 10 + (source[0] - '0');
-                                rateDenominator = rateDenominator * 10;
-                            }
-                        }
-
-                        rate = (Double)rateNumerator / rateDenominator;
-                        break;
-                    }
-                    else if (source[0] == ':')
-                    {
-                        while (true)
-                        {
-                            y4m_handler->m_cHandle.read(source, 1);
-                            if (source[0] == 0x20 || source[0] == 0x0a)
-                            {
-                                break;
-                            }
-                            else
-                                rateDenominator = rateDenominator * 10 + (source[0] - '0');
-                        }
-
-                        rate = (Double)rateNumerator / rateDenominator;
-                        break;
-                    }
-                    else
-                    {
-                        rateNumerator = rateNumerator * 10 + (source[0] - '0');
-                    }
-                }
-
-                continue;
-            }
-
-            break;
-        }
-
-        if (source[0] == 0x0a)
-        {
-            break;
-        }
-    }
-
-    y4m_handler->headerLength = y4m_handler->m_cHandle.tellg();
-    video_info.width = width;
-    video_info.height = height;
-    video_info.FrameRate = ceil(rate);
-}
-
-Void TVideoIOY4m::close(hnd_t* &handler)
-{
-    y4m_hnd_t* y4m_handler = (y4m_hnd_t*)handler;
-
-    y4m_handler->m_cHandle.close();
-}
-
-Bool TVideoIOY4m::isEof(hnd_t* &handler)
-{
-    y4m_hnd_t* y4m_handler = (y4m_hnd_t*)handler;
-
-    return y4m_handler->m_cHandle.eof();
-}
-
-Bool TVideoIOY4m::isFail(hnd_t* &handler)
-{
-    y4m_hnd_t* y4m_handler = (y4m_hnd_t*)handler;
-
-    return y4m_handler->m_cHandle.fail();
-}
-
-/**
- * Skip numFrames in input.
- *
- * This function correctly handles cases where the input file is not
- * seekable, by consuming bytes.
- */
-void TVideoIOY4m::skipFrames(UInt numFrames, UInt width, UInt height, hnd_t* &handler)
-{
-    y4m_hnd_t* y4m_handler = (y4m_hnd_t*)handler;
-
-    if (!numFrames)
-        return;
-
-    const UInt wordsize = (y4m_handler->fileBitDepthY > 8 || y4m_handler->fileBitDepthC > 8) ? 2 : 1;
-    const streamoff framesize = wordsize * width * height * 3 / 2;
-    const streamoff offset = framesize * numFrames;
-
-    /* attempt to seek */
-    if (!!y4m_handler->m_cHandle.seekg(offset, ios::cur))
-        return; /* success */
-
-    y4m_handler->m_cHandle.clear();
-
-    /* fall back to consuming the input */
-    Char buf[512];
-    const UInt offset_mod_bufsize = offset % sizeof(buf);
-    for (streamoff i = 0; i < offset - offset_mod_bufsize; i += sizeof(buf))
-    {
-        y4m_handler->m_cHandle.read(buf, sizeof(buf));
-    }
-
-    y4m_handler->m_cHandle.read(buf, offset_mod_bufsize);
-}
-
-/**
- * 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 pad_x   length of horizontal padding.
- * @param pad_y   length of vertical padding.
- * @return true for success, false in case of error
- */
-static Bool readPlane(Pel* dst, istream& fd, Bool is16bit,
-                      UInt stride,
-                      UInt width, UInt height,
-                      UInt pad_x, UInt pad_y)
-{
-    Int read_len = width * (is16bit ? 2 : 1);
-    UChar *buf = new UChar[read_len];
-
-    for (Int y = 0; y < height; y++)
-    {
-        fd.read(reinterpret_cast<Char*>(buf), read_len);
-        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++)
-            {
-                dst[x] = (buf[2 * x + 1] << 8) | buf[2 * x];
-            }
-        }
-
-        for (Int x = width; x < width + pad_x; x++)
-        {
-            dst[x] = dst[width - 1];
-        }
-
-        dst += stride;
-    }
-
-    for (Int y = height; y < height + pad_y; y++)
-    {
-        for (Int x = 0; x < width + pad_x; x++)
-        {
-            dst[x] = (dst - stride)[x];
-        }
-
-        dst += stride;
-    }
-
-    delete[] buf;
-    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.
- * @return true for success, false in case of error
- */
-static Bool writePlane(ostream& fd, Pel* src, Bool is16bit,
-                       UInt stride,
-                       UInt width, UInt height)
-{
-    Int write_len = width * (is16bit ? 2 : 1);
-    UChar *buf = new UChar[write_len];
-
-    for (Int y = 0; y < height; y++)
-    {
-        if (!is16bit)
-        {
-            for (Int x = 0; x < width; x++)
-            {
-                buf[x] = (UChar)src[x];
-            }
-        }
-        else
-        {
-#ifdef HIGH_BIT_DEPTH
-            for (Int x = 0; x < width; x++)
-            {
-                buf[2 * x] = src[x] & 0xff;
-                buf[2 * x + 1] = (src[x] >> 8) & 0xff;
-            }
-#endif
-        }
-
-        fd.write(reinterpret_cast<Char*>(buf), write_len);
-        if (fd.eof() || fd.fail())
-        {
-            delete[] buf;
-            return false;
-        }
-
-        src += stride;
-    }
-
-    delete[] buf;
-    return true;
-}
-
-/**
- * Read one Y'CbCr frame, performing any required input scaling to change
- * from the bitdepth of the input file to the internal bit-depth.
- *
- * 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 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 TVideoIOY4m::read(TComPicYuv* pPicYuv,  hnd_t* &handler)
-{
-    y4m_hnd_t* y4m_handler = (y4m_hnd_t*)handler;
-
-    // check end-of-file
-    if (isEof(handler)) return false;
-
-    Int   iStride = pPicYuv->getStride();
-
-    // compute actual YUV width & height excluding padding size
-    UInt pad_h = y4m_handler->aiPad[0];
-    UInt pad_v = y4m_handler->aiPad[1];
-    UInt width_full = pPicYuv->getWidth();
-    UInt height_full = pPicYuv->getHeight();
-    UInt width  = width_full - pad_h;
-    UInt height = height_full - pad_v;
-    Bool is16bit = y4m_handler->fileBitDepthY > 8 || y4m_handler->fileBitDepthC > 8;
-
-    Int desired_bitdepthY = y4m_handler->fileBitDepthY + y4m_handler->bitDepthShiftY;
-    Int desired_bitdepthC = y4m_handler->fileBitDepthC + y4m_handler->bitDepthShiftC;
-    Pel minvalY = 0;
-    Pel minvalC = 0;
-    Pel maxvalY = (1 << desired_bitdepthY) - 1;
-    Pel maxvalC = (1 << desired_bitdepthC) - 1;
-#if CLIP_TO_709_RANGE
-    if (y4m_handler->bitdepthShiftY < 0 && desired_bitdepthY >= 8)
-    {
-        /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
-        minvalY = 1 << (desired_bitdepthY - 8);
-        maxvalY = (0xff << (desired_bitdepthY - 8)) - 1;
-    }
-
-    if (y4m_handler->bitdepthShiftC < 0 && desired_bitdepthC >= 8)
-    {
-        /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
-        minvalC = 1 << (desired_bitdepthC - 8);
-        maxvalC = (0xff << (desired_bitdepthC - 8)) - 1;
-    }
-
-#endif // if CLIP_TO_709_RANGE
-
-    /*stripe off the FRAME header */
-    char byte[1];
-    Int cur_pointer = y4m_handler->m_cHandle.tellg();
-    cur_pointer += Y4M_FRAME_MAGIC;
-    y4m_handler->m_cHandle.seekg(cur_pointer);
-    while (1)
-    {
-        byte[0] = 0;
-        y4m_handler->m_cHandle.read(byte, 1);
-        if (y4m_handler->m_cHandle.eof() || y4m_handler->m_cHandle.fail())
-        {
-            break;
-        }
-
-        //if(*byte==0x0a){
-        //	break;
-        //}
-label:
-        while (*byte != 0x0a)
-        {
-            y4m_handler->m_cHandle.read(byte, 1);
-        }
-
-        y4m_handler->m_cHandle.read(byte, 1);
-        if (*(byte) == 0x20)
-        {
-            goto label;
-        }
-        else
-        {
-            break;
-        }
-    }
-
-    cur_pointer = y4m_handler->m_cHandle.tellg();
-    y4m_handler->m_cHandle.seekg(cur_pointer - 1);
-    cur_pointer = y4m_handler->m_cHandle.tellg();
-
-    if (!readPlane(pPicYuv->getLumaAddr(), y4m_handler->m_cHandle, is16bit, iStride, width, height, pad_h, pad_v))
-        return false;
-
-    cur_pointer = y4m_handler->m_cHandle.tellg();
-    scalePlane(pPicYuv->getLumaAddr(), iStride, width_full, height_full, y4m_handler->bitDepthShiftY, minvalY, maxvalY);
-
-    iStride >>= 1;
-    width_full >>= 1;
-    height_full >>= 1;
-    width >>= 1;
-    height >>= 1;
-    pad_h >>= 1;
-    pad_v >>= 1;
-
-    if (!readPlane(pPicYuv->getCbAddr(), y4m_handler->m_cHandle, is16bit, iStride, width, height, pad_h, pad_v))
-        return false;
-
-    cur_pointer = y4m_handler->m_cHandle.tellg();
-    scalePlane(pPicYuv->getCbAddr(), iStride, width_full, height_full, y4m_handler->bitDepthShiftC, minvalC, maxvalC);
-
-    if (!readPlane(pPicYuv->getCrAddr(), y4m_handler->m_cHandle, is16bit, iStride, width, height, pad_h, pad_v))
-        return false;
-
-    cur_pointer = y4m_handler->m_cHandle.tellg();
-    scalePlane(pPicYuv->getCrAddr(), iStride, width_full, height_full, y4m_handler->bitDepthShiftC, minvalC, maxvalC);
-    cur_pointer = y4m_handler->m_cHandle.tellg();
-    return true;
-}
-
-/**
- * Write one Y'CbCr frame. No bit-depth conversion is performed, pcPicYuv is
- * assumed to be at TVideoIO::m_fileBitdepth depth.
- *
- * @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 TVideoIOY4m::write(TComPicYuv* pPicYuv, hnd_t* &handler, Int confLeft, Int confRight, Int confTop, Int confBottom)
-{
-    y4m_hnd_t* y4m_handler = (y4m_hnd_t*)handler;
-    // compute actual YUV frame size excluding padding size
-    Int   iStride = pPicYuv->getStride();
-    UInt  width  = pPicYuv->getWidth()  - confLeft - confRight;
-    UInt  height = pPicYuv->getHeight() - confTop  - confBottom;
-    Bool is16bit = y4m_handler->fileBitDepthY > 8 || y4m_handler->fileBitDepthC > 8;
-    TComPicYuv *dstPicYuv = NULL;
-    Bool retval = true;
-
-    if (y4m_handler->bitDepthShiftY != 0 || y4m_handler->bitDepthShiftC != 0)
-    {
-        dstPicYuv = new TComPicYuv;
-        dstPicYuv->create(pPicYuv->getWidth(), pPicYuv->getHeight(), 1, 1, 0);
-        pPicYuv->copyToPic(dstPicYuv);
-
-        Pel minvalY = 0;
-        Pel minvalC = 0;
-        Pel maxvalY = (1 << y4m_handler->fileBitDepthY) - 1;
-        Pel maxvalC = (1 << y4m_handler->fileBitDepthC) - 1;
-#if CLIP_TO_709_RANGE
-        if (-y4m_handler->bitDepthShiftY < 0 && y4m_handler->fileBitDepthY >= 8)
-        {
-            /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
-            minvalY = 1 << (y4m_handler->fileBitDepthY - 8);
-            maxvalY = (0xff << (y4m_handler->fileBitDepthY - 8)) - 1;
-        }
-
-        if (-y4m_handler->bitDepthShiftC < 0 && y4m_handler->fileBitDepthC >= 8)
-        {
-            /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
-            minvalC = 1 << (y4m_handler->fileBitDepthC - 8);
-            maxvalC = (0xff << (y4m_handler->fileBitDepthC - 8)) - 1;
-        }
-
-#endif // if CLIP_TO_709_RANGE
-        scalePlane(dstPicYuv->getLumaAddr(), dstPicYuv->getStride(), dstPicYuv->getWidth(),
-                   dstPicYuv->getHeight(), -y4m_handler->bitDepthShiftY, minvalY, maxvalY);
-        scalePlane(dstPicYuv->getCbAddr(), dstPicYuv->getCStride(), dstPicYuv->getWidth() >> 1,
-                   dstPicYuv->getHeight() >> 1, -y4m_handler->bitDepthShiftC, minvalC, maxvalC);
-        scalePlane(dstPicYuv->getCrAddr(), dstPicYuv->getCStride(), dstPicYuv->getWidth() >> 1,
-                   dstPicYuv->getHeight() >> 1, -y4m_handler->bitDepthShiftC, minvalC, maxvalC);
-    }
-    else
-    {
-        dstPicYuv = pPicYuv;
-    }
-
-    // location of upper left pel in a plane
-    Int planeOffset = confLeft + confTop * iStride;
-
-    if (!writePlane(y4m_handler->m_cHandle, dstPicYuv->getLumaAddr() + planeOffset, is16bit, iStride, width, height))
-    {
-        retval = false;
-        goto exit;
-    }
-
-    width >>= 1;
-    height >>= 1;
-    iStride >>= 1;
-    confLeft >>= 1;
-    confRight >>= 1;
-    confTop >>= 1;
-    confBottom >>= 1;
-
-    planeOffset = confLeft + confTop * iStride;
-
-    if (!writePlane(y4m_handler->m_cHandle, dstPicYuv->getCbAddr() + planeOffset, is16bit, iStride, width, height))
-    {
-        retval = false;
-        goto exit;
-    }
-
-    if (!writePlane(y4m_handler->m_cHandle, dstPicYuv->getCrAddr() + planeOffset, is16bit, iStride, width, height))
-    {
-        retval = false;
-        goto exit;
-    }
-
-exit:
-    if (y4m_handler->bitDepthShiftY != 0 || y4m_handler->bitDepthShiftC != 0)
-    {
-        dstPicYuv->destroy();
-        delete dstPicYuv;
-    }
-
-    return retval;
-}
--- a/source/Lib/TLibVideoIO/TVideoIOY4m.h	Tue Apr 23 11:07:40 2013 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,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-2013, ITU/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 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.
- *
- * 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     TVideoIOYuv.h
-    \brief    YUV file I/O class (header)
-*/
-
-#ifndef __TVIDEOIOY4M__
-#define __TVIDEOIOY4M__
-
-#include <stdio.h>
-#include <fstream>
-#include <iostream>
-#include "TVideoIO.h"
-#include "TLibCommon/CommonDef.h"
-#include "TLibCommon/TComPicYuv.h"
-
-using namespace std;
-
-typedef struct
-{
-    fstream   m_cHandle;                                  ///< file handle
-    Int fileBitDepthY; ///< bitdepth of input/output video file luma component
-    Int fileBitDepthC; ///< bitdepth of input/output video file chroma component
-    Int bitDepthShiftY; ///< number of bits to increase or decrease luma by before/after write/read
-    Int bitDepthShiftC; ///< number of bits to increase or decrease chroma by before/after write/read
-    Int width;
-    Int height;
-    Int FrameRate;
-    Int aiPad[2];
-    Int headerLength;
-}y4m_hnd_t;
-#define Y4M_FRAME_MAGIC 5 //"FRAME"
-
-// ====================================================================================================================
-// Class definition
-// ====================================================================================================================
-
-/// YUV file I/O class
-class TVideoIOY4m :  virtual public TVideoIO
-{
-public:
-
-    TVideoIOY4m()           {}
-
-    virtual ~TVideoIOY4m()  {}
-
-    Void  open(Char * pchFile, Bool bWriteMode, Int internalBitDepthY, Int fileBitDepthY, Int internalBitDepthC, Int fileBitDepthC, hnd_t * &handler, video_info_t video_info, Int aiPad[2]);   ///< open or create file
-    Void  close(hnd_t* &handler);                                          ///< close file
-
-    Void skipFrames(UInt numFrames, UInt width, UInt height, hnd_t* &handler);
-
-    Bool  read(TComPicYuv * pPicYuv, hnd_t* &handler);        ///< read  one YUV frame with padding parameter
-    Bool  write(TComPicYuv* pPicYuv, hnd_t* &handler, Int confLeft = 0, Int confRight = 0, Int confTop = 0, Int confBottom = 0);
-
-    Bool  isEof(hnd_t* &handler);                                          ///< check for end-of-file
-    Bool  isFail(hnd_t* &handler);                                         ///< check for failure
-    Void  getVideoInfo(video_info_t &video_info, hnd_t* &handler);
-};
-
-#endif // __TVIDEOIOY4M__
--- a/source/Lib/TLibVideoIO/TVideoIOYuv.cpp	Tue Apr 23 11:07:40 2013 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,553 +0,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-2013, ITU/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 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.
- *
- * 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     TVideoIOYuv.cpp
-    \brief    YUV file I/O class
-*/
-
-#include <cstdlib>
-#include <fcntl.h>
-#include <assert.h>
-#include <sys/stat.h>
-#include <fstream>
-#include <iostream>
-
-#include "TLibCommon/TComRom.h"
-#include "TVideoIOYuv.h"
-
-using namespace std;
-
-/**
- * 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, UInt stride, UInt width, UInt height,
-                          UInt shiftbits, Pel minval, Pel maxval)
-{
-    Pel offset = 1 << (shiftbits - 1);
-
-    for (UInt y = 0; y < height; y++)
-    {
-        for (UInt x = 0; x < width; x++)
-        {
-            Pel val = (img[x] + offset) >> shiftbits;
-            img[x] = Clip3(minval, maxval, val);
-        }
-
-        img += stride;
-    }
-}
-
-/**
- * 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, UInt stride, UInt width, UInt height,
-                       UInt shiftbits)
-{
-    for (UInt y = 0; y < height; y++)
-    {
-        for (UInt x = 0; x < width; x++)
-        {
-            img[x] <<= shiftbits;
-        }
-
-        img += stride;
-    }
-}
-
-/**
- * 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 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.
- * @param maxval  maximum clipping value when dividing.
- */
-static void scalePlane(Pel* img, UInt stride, UInt width, UInt height,
-                       Int shiftbits, Pel minval, Pel maxval)
-{
-    if (shiftbits == 0)
-    {
-        return;
-    }
-
-    if (shiftbits > 0)
-    {
-        scalePlane(img, stride, width, height, shiftbits);
-    }
-    else
-    {
-        invScalePlane(img, stride, width, height, -shiftbits, minval, maxval);
-    }
-}
-
-// ====================================================================================================================
-// Public member functions
-// ====================================================================================================================
-
-/**
- * Open file for reading/writing Y'CbCr frames.
- *
- * 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
- * (See scalePlane(), TVideoIOYuv::read() and TVideoIOYuv::write() for
- * further details).
- *
- * \param pchFile          file name string
- * \param bWriteMode       file open mode: true=read, false=write
- * \param fileBitDepthY     bit-depth of input/output file data (luma component).
- * \param fileBitDepthC     bit-depth of input/output file data (chroma components).
- * \param internalBitDepthY bit-depth to scale image data to/from when reading/writing (luma component).
- * \param internalBitDepthC bit-depth to scale image data to/from when reading/writing (chroma components).
- */
-Void TVideoIOYuv::open(Char*        pchFile,
-                       Bool         bWriteMode,
-                       Int          internalBitDepthY,
-                       Int          fileBitDepthY,
-                       Int          internalBitDepthC,
-                       Int          fileBitDepthC,
-                       hnd_t* &     handler,
-                       video_info_t video_info,
-                       Int          aiPad[2])
-{
-    yuv_hnd_t* yuv_handler = new yuv_hnd_t();
-
-    //yuv_hnd_t *yuv_handler = malloc( sizeof(yuv_hnd_t) );
-    yuv_handler->bitDepthShiftY = internalBitDepthY - fileBitDepthY;
-    yuv_handler->bitDepthShiftC = internalBitDepthC - fileBitDepthC;
-    yuv_handler->fileBitDepthY = fileBitDepthY;
-    yuv_handler->fileBitDepthC = fileBitDepthC;
-    yuv_handler->aiPad[0] = aiPad[0];
-    yuv_handler->aiPad[1] = aiPad[1];
-    if (bWriteMode)
-    {
-        yuv_handler->m_cHandle.open(pchFile, ios::binary | ios::out);
-
-        if (yuv_handler->m_cHandle.fail())
-        {
-            printf("\nfailed to write reconstructed YUV file\n");
-            exit(0);
-        }
-    }
-    else
-    {
-        yuv_handler->m_cHandle.open(pchFile, ios::binary | ios::in);
-
-        if (yuv_handler->m_cHandle.fail())
-        {
-            printf("\nfailed to open Input YUV file\n");
-            exit(0);
-        }
-    }
-
-    handler =  (hnd_t*)yuv_handler;
-}
-
-Void TVideoIOYuv::getVideoInfo(video_info_t &video_info, hnd_t* &handler) {}
-
-Void TVideoIOYuv::close(hnd_t* &handler)
-{
-    yuv_hnd_t* yuv_handler = (yuv_hnd_t*)handler;
-
-    yuv_handler->m_cHandle.close();
-}
-
-Bool TVideoIOYuv::isEof(hnd_t* &handler)
-{
-    yuv_hnd_t* yuv_handler = (yuv_hnd_t*)handler;
-
-    return yuv_handler->m_cHandle.eof();
-}
-
-Bool TVideoIOYuv::isFail(hnd_t* &handler)
-{
-    yuv_hnd_t* yuv_handler = (yuv_hnd_t*)handler;
-
-    return yuv_handler->m_cHandle.fail();
-}
-
-/**
- * Skip numFrames in input.
- *
- * This function correctly handles cases where the input file is not
- * seekable, by consuming bytes.
- */
-void TVideoIOYuv::skipFrames(UInt numFrames, UInt width, UInt height, hnd_t* &handler)
-{
-    yuv_hnd_t* yuv_handler = (yuv_hnd_t*)handler;
-
-    if (!numFrames)
-        return;
-
-    const UInt wordsize = (yuv_handler->fileBitDepthY > 8 || yuv_handler->fileBitDepthC > 8) ? 2 : 1;
-    const streamoff framesize = wordsize * width * height * 3 / 2;
-    const streamoff offset = framesize * numFrames;
-
-    /* attempt to seek */
-    if (!!yuv_handler->m_cHandle.seekg(offset, ios::cur))
-        return; /* success */
-
-    yuv_handler->m_cHandle.clear();
-
-    /* fall back to consuming the input */
-    Char buf[512];
-    const UInt offset_mod_bufsize = offset % sizeof(buf);
-    for (streamoff i = 0; i < offset - offset_mod_bufsize; i += sizeof(buf))
-    {
-        yuv_handler->m_cHandle.read(buf, sizeof(buf));
-    }
-
-    yuv_handler->m_cHandle.read(buf, offset_mod_bufsize);
-}
-
-/**
- * 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 pad_x   length of horizontal padding.
- * @param pad_y   length of vertical padding.
- * @return true for success, false in case of error
- */
-static Bool readPlane(Pel* dst, istream& fd, Bool is16bit,
-                      UInt stride,
-                      UInt width, UInt height,
-                      UInt pad_x, UInt pad_y)
-{
-    Int read_len = width * (is16bit ? 2 : 1);
-    UChar *buf = new UChar[read_len];
-
-    for (Int y = 0; y < height; y++)
-    {
-        fd.read(reinterpret_cast<Char*>(buf), read_len);
-        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++)
-            {
-                dst[x] = (buf[2 * x + 1] << 8) | buf[2 * x];
-            }
-        }
-
-        for (Int x = width; x < width + pad_x; x++)
-        {
-            dst[x] = dst[width - 1];
-        }
-
-        dst += stride;
-    }
-
-    for (Int y = height; y < height + pad_y; y++)
-    {
-        for (Int x = 0; x < width + pad_x; x++)
-        {
-            dst[x] = (dst - stride)[x];
-        }
-
-        dst += stride;
-    }
-
-    delete[] buf;
-    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.
- * @return true for success, false in case of error
- */
-static Bool writePlane(ostream& fd, Pel* src, Bool is16bit,
-                       UInt stride,
-                       UInt width, UInt height)
-{
-    Int write_len = width * (is16bit ? 2 : 1);
-    UChar *buf = new UChar[write_len];
-
-    for (Int y = 0; y < height; y++)
-    {
-        if (!is16bit)
-        {
-            for (Int x = 0; x < width; x++)
-            {
-                buf[x] = (UChar)src[x];
-            }
-        }
-        else
-        {
-#ifdef HIGH_BIT_DEPTH
-            for (Int x = 0; x < width; x++)
-            {
-                buf[2 * x] = src[x] & 0xff;
-                buf[2 * x + 1] = (src[x] >> 8) & 0xff;
-            }
-#endif
-        }
-
-        fd.write(reinterpret_cast<Char*>(buf), write_len);
-        if (fd.eof() || fd.fail())
-        {
-            delete[] buf;
-            return false;
-        }
-
-        src += stride;
-    }
-
-    delete[] buf;
-    return true;
-}
-
-/**
- * Read one Y'CbCr frame, performing any required input scaling to change
- * from the bitdepth of the input file to the internal bit-depth.
- *
- * 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 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,  hnd_t* &handler)
-{
-    yuv_hnd_t* yuv_handler = (yuv_hnd_t*)handler;
-
-    // check end-of-file
-    if (isEof(handler)) return false;
-
-    Int   iStride = pPicYuv->getStride();
-
-    // compute actual YUV width & height excluding padding size
-    UInt pad_h = yuv_handler->aiPad[0];
-    UInt pad_v = yuv_handler->aiPad[1];
-    UInt width_full = pPicYuv->getWidth();
-    UInt height_full = pPicYuv->getHeight();
-    UInt width  = width_full - pad_h;
-    UInt height = height_full - pad_v;
-    Bool is16bit = yuv_handler->fileBitDepthY > 8 || yuv_handler->fileBitDepthC > 8;
-
-    Int desired_bitdepthY = yuv_handler->fileBitDepthY + yuv_handler->bitDepthShiftY;
-    Int desired_bitdepthC = yuv_handler->fileBitDepthC + yuv_handler->bitDepthShiftC;
-    Pel minvalY = 0;
-    Pel minvalC = 0;
-    Pel maxvalY = (1 << desired_bitdepthY) - 1;
-    Pel maxvalC = (1 << desired_bitdepthC) - 1;
-#if CLIP_TO_709_RANGE
-    if (yuv_handler->bitdepthShiftY < 0 && desired_bitdepthY >= 8)
-    {
-        /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
-        minvalY = 1 << (desired_bitdepthY - 8);
-        maxvalY = (0xff << (desired_bitdepthY - 8)) - 1;
-    }
-
-    if (yuv_handler->bitdepthShiftC < 0 && desired_bitdepthC >= 8)
-    {
-        /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
-        minvalC = 1 << (desired_bitdepthC - 8);
-        maxvalC = (0xff << (desired_bitdepthC - 8)) - 1;
-    }
-
-#endif // if CLIP_TO_709_RANGE
-
-    if (!readPlane(pPicYuv->getLumaAddr(), yuv_handler->m_cHandle, is16bit, iStride, width, height, pad_h, pad_v))
-        return false;
-
-    scalePlane(pPicYuv->getLumaAddr(), iStride, width_full, height_full, yuv_handler->bitDepthShiftY, minvalY, maxvalY);
-
-    iStride >>= 1;
-    width_full >>= 1;
-    height_full >>= 1;
-    width >>= 1;
-    height >>= 1;
-    pad_h >>= 1;
-    pad_v >>= 1;
-
-    if (!readPlane(pPicYuv->getCbAddr(), yuv_handler->m_cHandle, is16bit, iStride, width, height, pad_h, pad_v))
-        return false;
-
-    scalePlane(pPicYuv->getCbAddr(), iStride, width_full, height_full, yuv_handler->bitDepthShiftC, minvalC, maxvalC);
-
-    if (!readPlane(pPicYuv->getCrAddr(), yuv_handler->m_cHandle, is16bit, iStride, width, height, pad_h, pad_v))
-        return false;
-
-    scalePlane(pPicYuv->getCrAddr(), iStride, width_full, height_full, yuv_handler->bitDepthShiftC, minvalC, maxvalC);
-
-    return true;
-}
-
-/**
- * Write one Y'CbCr frame. No bit-depth conversion is performed, pcPicYuv is
- * assumed to be at TVideoIO::m_fileBitdepth depth.
- *
- * @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::write(TComPicYuv* pPicYuv, hnd_t* &handler, Int confLeft, Int confRight, Int confTop, Int confBottom)
-{
-    yuv_hnd_t* yuv_handler = (yuv_hnd_t*)handler;
-    // compute actual YUV frame size excluding padding size
-    Int   iStride = pPicYuv->getStride();
-    UInt  width  = pPicYuv->getWidth()  - confLeft - confRight;
-    UInt  height = pPicYuv->getHeight() - confTop  - confBottom;
-    Bool is16bit = yuv_handler->fileBitDepthY > 8 || yuv_handler->fileBitDepthC > 8;
-    TComPicYuv *dstPicYuv = NULL;
-    Bool retval = true;
-
-    if (yuv_handler->bitDepthShiftY != 0 || yuv_handler->bitDepthShiftC != 0)
-    {
-        dstPicYuv = new TComPicYuv;
-        dstPicYuv->create(pPicYuv->getWidth(), pPicYuv->getHeight(), 1, 1, 0);
-        pPicYuv->copyToPic(dstPicYuv);
-
-        Pel minvalY = 0;
-        Pel minvalC = 0;
-        Pel maxvalY = (1 << yuv_handler->fileBitDepthY) - 1;
-        Pel maxvalC = (1 << yuv_handler->fileBitDepthC) - 1;
-#if CLIP_TO_709_RANGE
-        if (-yuv_handler->bitDepthShiftY < 0 && yuv_handler->fileBitDepthY >= 8)
-        {
-            /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
-            minvalY = 1 << (yuv_handler->fileBitDepthY - 8);
-            maxvalY = (0xff << (yuv_handler->fileBitDepthY - 8)) - 1;
-        }
-
-        if (-yuv_handler->bitDepthShiftC < 0 && yuv_handler->fileBitDepthC >= 8)
-        {
-            /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
-            minvalC = 1 << (yuv_handler->fileBitDepthC - 8);
-            maxvalC = (0xff << (yuv_handler->fileBitDepthC - 8)) - 1;
-        }
-
-#endif // if CLIP_TO_709_RANGE
-        scalePlane(dstPicYuv->getLumaAddr(), dstPicYuv->getStride(), dstPicYuv->getWidth(),
-                   dstPicYuv->getHeight(), -yuv_handler->bitDepthShiftY, minvalY, maxvalY);
-        scalePlane(dstPicYuv->getCbAddr(), dstPicYuv->getCStride(), dstPicYuv->getWidth() >> 1,
-                   dstPicYuv->getHeight() >> 1, -yuv_handler->bitDepthShiftC, minvalC, maxvalC);
-        scalePlane(dstPicYuv->getCrAddr(), dstPicYuv->getCStride(), dstPicYuv->getWidth() >> 1,
-                   dstPicYuv->getHeight() >> 1, -yuv_handler->bitDepthShiftC, minvalC, maxvalC);
-    }
-    else
-    {
-        dstPicYuv = pPicYuv;
-    }
-
-    // location of upper left pel in a plane
-    Int planeOffset = confLeft + confTop * iStride;
-
-    if (!writePlane(yuv_handler->m_cHandle, dstPicYuv->getLumaAddr() + planeOffset, is16bit, iStride, width, height))
-    {
-        retval = false;
-        goto exit;
-    }
-
-    width >>= 1;
-    height >>= 1;
-    iStride >>= 1;
-    confLeft >>= 1;
-    confRight >>= 1;
-    confTop >>= 1;
-    confBottom >>= 1;
-
-    planeOffset = confLeft + confTop * iStride;
-
-    if (!writePlane(yuv_handler->m_cHandle, dstPicYuv->getCbAddr() + planeOffset, is16bit, iStride, width, height))
-    {
-        retval = false;
-        goto exit;
-    }
-
-    if (!writePlane(yuv_handler->m_cHandle, dstPicYuv->getCrAddr() + planeOffset, is16bit, iStride, width, height))
-    {
-        retval = false;
-        goto exit;
-    }
-
-exit:
-    if (yuv_handler->bitDepthShiftY != 0 || yuv_handler->bitDepthShiftC != 0)
-    {
-        dstPicYuv->destroy();
-        delete dstPicYuv;
-    }
-
-    return retval;
-}
--- a/source/Lib/TLibVideoIO/TVideoIOYuv.h	Tue Apr 23 11:07:40 2013 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,94 +0,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-2013, ITU/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 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.
- *
- * 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     TVideoIOYuv.h
-    \brief    YUV file I/O class (header)
-*/
-
-#ifndef __TVIDEOIOYUV__
-#define __TVIDEOIOYUV__
-
-#include <stdio.h>
-#include <fstream>
-#include <iostream>
-#include "TVideoIO.h"
-#include "TLibCommon/CommonDef.h"
-#include "TLibCommon/TComPicYuv.h"
-
-using namespace std;
-
-typedef struct
-{
-    fstream   m_cHandle;                                  ///< file handle
-    Int fileBitDepthY; ///< bitdepth of input/output video file luma component
-    Int fileBitDepthC; ///< bitdepth of input/output video file chroma component
-    Int bitDepthShiftY; ///< number of bits to increase or decrease luma by before/after write/read
-    Int bitDepthShiftC; ///< number of bits to increase or decrease chroma by before/after write/read
-    Int aiPad[2];
-}yuv_hnd_t;
-
-// ====================================================================================================================
-// Class definition
-// ====================================================================================================================
-
-/// YUV file I/O class
-class TVideoIOYuv :  virtual public TVideoIO
-{
-public:
-
-    TVideoIOYuv()           {}
-
-    virtual ~TVideoIOYuv()  {}
-
-    Void  open(Char * pchFile,
-               Bool bWriteMode,
-               Int internalBitDepthY,
-               Int fileBitDepthY,
-               Int internalBitDepthC,
-               Int fileBitDepthC,
-               hnd_t * &handler,
-               video_info_t video_info,
-               Int aiPad[2]);                                                                                                                                                                 ///< open or create file
-    Void  close(hnd_t* &handler);                                          ///< close file
-
-    Void skipFrames(UInt numFrames, UInt width, UInt height, hnd_t* &handler);
-
-    Bool  read(TComPicYuv * pPicYuv, hnd_t* &handler);        ///< read  one YUV frame with padding parameter
-    Bool  write(TComPicYuv* pPicYuv, hnd_t* &handler, Int confLeft = 0, Int confRight = 0, Int confTop = 0, Int confBottom = 0);
-
-    Bool  isEof(hnd_t* &handler);                                          ///< check for end-of-file
-    Bool  isFail(hnd_t* &handler);                                         ///< check for failure
-    Void  getVideoInfo(video_info_t &video_info, hnd_t* &handler);
-};
-
-#endif // __TVIDEOIOYUV__
--- a/source/encoder/macroblock.cpp	Tue Apr 23 11:07:40 2013 +0530
+++ b/source/encoder/macroblock.cpp	Tue Apr 23 18:24:06 2013 +0530
@@ -451,6 +451,57 @@ void CDECL partialButterflyInverse8(Shor
         dst += 8;
     }
 }
+
+void CDECL partialButterflyInverse16(short *src, short *dst, int shift, int line)
+{
+    Int j, k;
+    Int E[8], O[8];
+    Int EE[4], EO[4];
+    Int EEE[2], EEO[2];
+    Int add = 1 << (shift - 1);
+
+    for (j = 0; j < line; j++)
+    {
+        /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */
+        for (k = 0; k < 8; k++)
+        {
+            O[k] = g_aiT16[1][k] * src[line] + g_aiT16[3][k] * src[3 * line] + g_aiT16[5][k] * src[5 * line] + g_aiT16[7][k] * src[7 * line] +
+                g_aiT16[9][k] * src[9 * line] + g_aiT16[11][k] * src[11 * line] + g_aiT16[13][k] * src[13 * line] + g_aiT16[15][k] * src[15 * line];
+        }
+
+        for (k = 0; k < 4; k++)
+        {
+            EO[k] = g_aiT16[2][k] * src[2 * line] + g_aiT16[6][k] * src[6 * line] + g_aiT16[10][k] * src[10 * line] + g_aiT16[14][k] * src[14 * line];
+        }
+
+        EEO[0] = g_aiT16[4][0] * src[4 * line] + g_aiT16[12][0] * src[12 * line];
+        EEE[0] = g_aiT16[0][0] * src[0] + g_aiT16[8][0] * src[8 * line];
+        EEO[1] = g_aiT16[4][1] * src[4 * line] + g_aiT16[12][1] * src[12 * line];
+        EEE[1] = g_aiT16[0][1] * src[0] + g_aiT16[8][1] * src[8 * line];
+
+        /* Combining even and odd terms at each hierarchy levels to calculate the final spatial domain vector */
+        for (k = 0; k < 2; k++)
+        {
+            EE[k] = EEE[k] + EEO[k];
+            EE[k + 2] = EEE[1 - k] - EEO[1 - k];
+        }
+
+        for (k = 0; k < 4; k++)
+        {
+            E[k] = EE[k] + EO[k];
+            E[k + 4] = EE[3 - k] - EO[3 - k];
+        }
+
+        for (k = 0; k < 8; k++)
+        {
+            dst[k]   = (short)Clip3(-32768, 32767, (E[k] + O[k] + add) >> shift);
+            dst[k + 8] = (short)Clip3(-32768, 32767, (E[7 - k] - O[7 - k] + add) >> shift);
+        }
+
+        src++;
+        dst += 16;
+    }
+}
 }  // closing - anonymous file-static namespace
 
 namespace x265 {
@@ -485,5 +536,6 @@ void Setup_C_MacroblockPrimitives(Encode
     p.partial_butterfly[BUTTERFLY_8] = partialButterfly8;
     p.partial_butterfly[BUTTERFLY_INVERSE_4] = partialButterflyInverse4;
     p.partial_butterfly[BUTTERFLY_INVERSE_8] = partialButterflyInverse8;
+    p.partial_butterfly[BUTTERFLY_INVERSE_16] = partialButterflyInverse16;
 }
 }
--- a/source/encoder/vec/macroblock.inc	Tue Apr 23 11:07:40 2013 +0530
+++ b/source/encoder/vec/macroblock.inc	Tue Apr 23 18:24:06 2013 +0530
@@ -1062,6 +1062,7 @@ void CDECL partialButterflyInverse8(shor
     int add = 1 << (shift - 1);
 
     Vec4i dst_second(32767);
+    Vec4i dst_first(-32768);
 
     for (j = 0; j < line; j++)
     {
@@ -1098,10 +1099,12 @@ void CDECL partialButterflyInverse8(shor
         E_O_diff = permute4i<3, 2, 1, 0>(E_O_diff);
 
         Vec4i first_four_min_value;
-        first_four_min_value = min(dst_second, E_O_sum);
+        first_four_min_value = max(dst_first, E_O_sum);
+        first_four_min_value = min(first_four_min_value, dst_second);
 
         Vec4i second_four_min_value;
-        second_four_min_value = min(dst_second, E_O_diff);
+        second_four_min_value = max(dst_first, E_O_diff);
+        second_four_min_value = min(second_four_min_value, dst_second);
 
         Vec4i all_zero(0);
         Vec8s first_four_final_value = compress(first_four_min_value, all_zero);
@@ -1115,6 +1118,89 @@ void CDECL partialButterflyInverse8(shor
     }
 }
 
+void CDECL partialButterflyInverse16(short *src, short *dst, int shift, int line)
+{
+    int j;
+
+    Vec4i dst_second(32767);
+    Vec4i dst_first(-32768);
+    int add = 1 << (shift - 1);
+
+    for (j = 0; j < line; j++)
+    {
+        int O_first = 90 * src[line] + 87 * src[3 * line] + 80 * src[5 * line] + 70 * src[7 * line] + 57 * src[9 * line] + 43 * src[11 * line] +  25 * src[13 * line] + 9 * src[15 * line];
+        int O_second = 87 * src[line] + 57 * src[3 * line] + 9 * src[5 * line] + (-43) * src[7 * line] + (-80) * src[9 * line] + (-90) * src[11 * line] +  (-70) * src[13 * line] + (-25) * src[15 * line];
+        int O_third = 80 * src[line] + 9 * src[3 * line] + (-70) * src[5 * line] + (-87) * src[7 * line] + (-25) * src[9 * line] + (57) * src[11 * line] +  (90) * src[13 * line] + (43) * src[15 * line];
+        int O_fourth = 70 * src[line] +  (-43) * src[3 * line] + (-87) * src[5 * line] + (9) * src[7 * line] + (90) * src[9 * line] + (25) * src[11 * line] +  (-80) * src[13 * line] + (-57) * src[15 * line];
+        int O_fifth = 57 * src[line] +  (-80) * src[3 * line] + (-25) * src[5 * line] + (90) * src[7 * line] + (-9) * src[9 * line] + (-87) * src[11 * line] +  (43) * src[13 * line] + (70) * src[15 * line];
+        int O_sixth = 43 * src[line] +  (-90) * src[3 * line] + (57) * src[5 * line] + (25) * src[7 * line] + (-87) * src[9 * line] + (70) * src[11 * line] +  (9) * src[13 * line] + (-80) * src[15 * line];
+        int O_seventh = 25 * src[line] +  (-70) * src[3 * line] + (90) * src[5 * line] + (-80) * src[7 * line] + (43) * src[9 * line] + (9) * src[11 * line] +  (-57) * src[13 * line] + (87) * src[15 * line];
+        int O_eight = 9 * src[line] +  (-25) * src[3 * line] + (43) * src[5 * line] + (-57) * src[7 * line] + (70) * src[9 * line] + (-80) * src[11 * line] +  (87) * src[13 * line] + (-90) * src[15 * line];
+
+        Vec4i O_first_half(O_first, O_second, O_third, O_fourth);
+        Vec4i O_second_half(O_fifth, O_sixth, O_seventh, O_eight);
+
+        int EO_zero = 89 * src[2 * line] + 75 * src[6 * line] + 50 * src[10 * line] + 18 * src[14 * line];
+        int EO_one = 75 * src[2 * line] + (-18) * src[6 * line] + -89 * src[10 * line] + (-50) * src[14 * line];
+        int EO_two = 50 * src[2 * line] + -89 * src[6 * line] + 18 * src[10 * line] + 75 * src[14 * line];
+        int EO_three = 18 * src[2 * line] + -50 * src[6 * line] + 75 * src[10 * line] + -89 * src[14 * line];
+
+        Vec4i EO(EO_zero, EO_one, EO_two, EO_three);
+
+        int EEO_zero = 83 * src[4 * line] + 36 * src[12 * line];
+        int EEE_zero = 64 * src[0] + 64 * src[8 * line];
+        int EEO_one  = 36 * src[4 * line] + -83 * src[12 * line];
+        int EEE_one  = 64 * src[0] +  -64 * src[8 * line];
+
+        int EE_zero = EEE_zero + EEO_zero;
+        int EE_one = EEE_one + EEO_one;
+        int EE_two = EEE_one - EEO_one;
+        int EE_three = EEE_zero - EEO_zero;
+
+        Vec4i EE(EE_zero, EE_one, EE_two, EE_three);
+        Vec4i E_first_half = EE + EO;
+        Vec4i E_second_half = EE - EO;
+        E_second_half = permute4i<3, 2, 1, 0>(E_second_half);
+
+        Vec4i first_four_min_value;
+        Vec4i second_four_min_value;
+        Vec4i dst_third_first_four = (E_first_half + O_first_half + add);
+        dst_third_first_four = dst_third_first_four >> shift;
+        Vec4i dst_third_second_four = (E_second_half + O_second_half + add);
+        dst_third_second_four = dst_third_second_four >> shift;
+
+        first_four_min_value = max(dst_first, dst_third_first_four);
+        first_four_min_value = min(first_four_min_value, dst_second);
+        second_four_min_value = max(dst_first, dst_third_second_four);
+        second_four_min_value = min(second_four_min_value, dst_second);
+
+        Vec8s first_eight_final_value = compress(first_four_min_value, second_four_min_value);
+        first_eight_final_value.store(dst);
+
+        Vec4i dst_third_third_four = E_second_half - O_second_half;
+        dst_third_third_four = (dst_third_third_four + add);
+        dst_third_third_four = dst_third_third_four  >> shift;
+        dst_third_third_four = permute4i<3, 2, 1, 0>(dst_third_third_four);
+
+        Vec4i dst_third_four_four = E_first_half - O_first_half;
+        dst_third_four_four = (dst_third_four_four + add);
+        dst_third_four_four = dst_third_four_four >> shift;
+        dst_third_four_four = permute4i<3, 2, 1, 0>(dst_third_four_four);
+
+        Vec4i third_four_min_value;
+        Vec4i four_four_min_value;
+        third_four_min_value = max(dst_first, dst_third_third_four);
+        third_four_min_value = min(third_four_min_value, dst_second);
+        four_four_min_value = max(dst_first, dst_third_four_four);
+        four_four_min_value = min(four_four_min_value, dst_second);
+
+        Vec8s second_eight_final_value = compress(third_four_min_value, four_four_min_value);
+        second_eight_final_value.store(dst + 8);
+        src++;
+        dst += 16;
+    }
+}
+
 void Setup_Vec_MacroblockPrimitives(EncoderPrimitives &p)
 {
     p.inversedst = inversedst;
@@ -1144,4 +1230,5 @@ void Setup_Vec_MacroblockPrimitives(Enco
     p.partial_butterfly[BUTTERFLY_8] = partialButterfly8;
     p.partial_butterfly[BUTTERFLY_INVERSE_4] = partialButterflyInverse4;
     p.partial_butterfly[BUTTERFLY_INVERSE_8] = partialButterflyInverse8;
+    p.partial_butterfly[BUTTERFLY_INVERSE_16] = partialButterflyInverse16;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/output/CMakeLists.txt	Tue Apr 23 18:24:06 2013 +0530
@@ -0,0 +1,4 @@
+add_library(OutputFiles
+    output.cpp output.h
+    y4m.cpp y4m.h
+    yuv.cpp yuv.h)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/output/output.cpp	Tue Apr 23 18:24:06 2013 +0530
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (C) 2013 x265 project
+ *
+ * Authors: Steve Borho <steve@borho.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing@multicorewareinc.com.
+ *****************************************************************************/
+
+#include "output.h"
+#include "yuv.h"
+#include "y4m.h"
+#include <string.h>
+
+using namespace x265;
+
+Output* Output::Open(const char *fname, int width, int height, int bitdepth)
+{
+    const char * s = strrchr(fname, '.');
+    if (s && !strcmp(s, ".y4m"))
+        return new Y4MOutput(fname, width, height, bitdepth);
+    else
+        return new YUVOutput(fname, width, height, bitdepth);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/output/output.h	Tue Apr 23 18:24:06 2013 +0530
@@ -0,0 +1,52 @@
+/*****************************************************************************
+ * Copyright (C) 2013 x265 project
+ *
+ * Authors: Steve Borho <steve@borho.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing@multicorewareinc.com.
+ *****************************************************************************/
+
+#ifndef _OUTPUT_H_
+#define _OUTPUT_H_
+
+#include "x265.h"
+#include <stdint.h>
+
+namespace x265 {
+// private x265 namespace
+
+class Output
+{
+
+protected:
+
+    virtual ~Output()  {}
+
+public:
+
+    Output()           {}
+
+    static  Output* Open(const char *fname, int width, int height, int bitdepth);
+
+    virtual void release() = 0;
+
+    virtual bool writePicture(const x265_picture& pic) = 0;
+};
+}
+
+#endif // _OUTPUT_H_
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/output/y4m.cpp	Tue Apr 23 18:24:06 2013 +0530
@@ -0,0 +1,107 @@
+/*****************************************************************************
+ * Copyright (C) 2013 x265 project
+ *
+ * Authors: Steve Borho <steve@borho.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing@multicorewareinc.com.
+ *****************************************************************************/
+
+#include "output.h"
+#include "y4m.h"
+#include <stdio.h>
+#include <assert.h>
+
+using namespace x265;
+
+Y4MOutput::Y4MOutput(const char *filename, int t_width, int t_height, int bitdepth)
+{
+    fp = fopen(filename, "wb");
+    width = t_width;
+    height = t_height;
+    assert(bitdepth == 8);
+    buf = new char[width];
+    if (fp)
+    {
+        // TODO: need to get frame rate
+        fprintf(fp, "YUV4MPEG2 W%d H%d F30:1 Ip C420\n", width, height);
+    }
+}
+
+Y4MOutput::~Y4MOutput()
+{
+    if (fp) fclose(fp);
+    if (buf) delete [] buf;
+}
+
+
+bool Y4MOutput::writePicture(const x265_picture& pic)
+{
+    fprintf(fp, "FRAME\n");
+
+    if (pic.bitDepth > 8)
+    {
+        // encoder gave us short pixels, downscale, then write
+        short *Y = (short*)pic.planes[0];
+        for (int i = 0; i < height; i++)
+        {
+            for (int j = 0; j < width; j++)
+                buf[j] = (char) Y[j];
+            fwrite(buf, sizeof(char), width, fp);
+            Y += pic.stride[0];
+        }
+        short *U = (short*)pic.planes[1];
+        for (int i = 0; i < height >> 1; i++)
+        {
+            for (int j = 0; j < width >> 1; j++)
+                buf[j] = (char) U[j];
+            fwrite(buf, sizeof(char), width >> 1, fp);
+            U += pic.stride[1];
+        }
+        short *V = (short*)pic.planes[2];
+        for (int i = 0; i < height >> 1; i++)
+        {
+            for (int j = 0; j < width >> 1; j++)
+                buf[j] = (char) V[j];
+            fwrite(buf, sizeof(char), width >> 1, fp);
+            V += pic.stride[2];
+        }
+    }
+    else
+    {
+        char *Y = (char*)pic.planes[0];
+        for (int i = 0; i < height; i++)
+        {
+            fwrite(Y, sizeof(char), width, fp);
+            Y += pic.stride[0];
+        }
+        char *U = (char*)pic.planes[1];
+        for (int i = 0; i < height >> 1; i++)
+        {
+            fwrite(U, sizeof(char), width >> 1, fp);
+            U += pic.stride[1];
+        }
+        char *V = (char*)pic.planes[2];
+        for (int i = 0; i < height >> 1; i++)
+        {
+            fwrite(V, sizeof(char), width >> 1, fp);
+            V += pic.stride[2];
+        }
+    }
+
+    return true;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/output/y4m.h	Tue Apr 23 18:24:06 2013 +0530
@@ -0,0 +1,59 @@
+/*****************************************************************************
+ * Copyright (C) 2013 x265 project
+ *
+ * Authors: Steve Borho <steve@borho.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing@multicorewareinc.com.
+ *****************************************************************************/
+
+#ifndef _Y4M_H_
+#define _Y4M_H_
+
+#include "output.h"
+#include <stdio.h>
+
+namespace x265 {
+// private x265 namespace
+
+class Y4MOutput : public Output
+{
+protected:
+
+    int width;
+
+    int height;
+
+    FILE* fp;
+
+    char *buf;
+
+    void writeHeader();
+
+public:
+
+    Y4MOutput(const char *filename, int width, int height, int bitdepth);
+
+    virtual ~Y4MOutput();
+
+    void release()                                { delete this; }
+
+    bool writePicture(const x265_picture& pic);
+};
+}
+
+#endif // _Y4M_H_
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/output/yuv.cpp	Tue Apr 23 18:24:06 2013 +0530
@@ -0,0 +1,99 @@
+/*****************************************************************************
+ * Copyright (C) 2013 x265 project
+ *
+ * Authors: Steve Borho <steve@borho.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing@multicorewareinc.com.
+ *****************************************************************************/
+
+#include "output.h"
+#include "yuv.h"
+
+using namespace x265;
+
+YUVOutput::YUVOutput(const char *filename, int t_width, int t_height, int t_bitdepth)
+{
+    fp = fopen(filename, "wb");
+    width = t_width;
+    height = t_height;
+    depth = t_bitdepth;
+    buf = new char[width];
+}
+
+YUVOutput::~YUVOutput()
+{
+    if (fp) fclose(fp);
+    if (buf) delete [] buf;
+}
+
+bool YUVOutput::writePicture(const x265_picture& pic)
+{
+    int pixelbytes = (depth > 8) ? 2 : 1;
+
+    if (pic.bitDepth > 8 && depth == 8)
+    {
+        // encoder gave us short pixels, downscale, then write
+        short *Y = (short*)pic.planes[0];
+        for (int i = 0; i < height; i++)
+        {
+            for (int j = 0; j < width; j++)
+                buf[j] = (char) Y[j];
+            fwrite(buf, sizeof(char), width, fp);
+            Y += pic.stride[0];
+        }
+        short *U = (short*)pic.planes[1];
+        for (int i = 0; i < height >> 1; i++)
+        {
+            for (int j = 0; j < width >> 1; j++)
+                buf[j] = (char) U[j];
+            fwrite(buf, sizeof(char), width >> 1, fp);
+            U += pic.stride[1];
+        }
+        short *V = (short*)pic.planes[2];
+        for (int i = 0; i < height >> 1; i++)
+        {
+            for (int j = 0; j < width >> 1; j++)
+                buf[j] = (char) V[j];
+            fwrite(buf, sizeof(char), width >> 1, fp);
+            V += pic.stride[2];
+        }
+    }
+    else
+    {
+        // encoder gave us byte pixels, write them directly
+        char *Y = (char*)pic.planes[0];
+        for (int i = 0; i < height; i++)
+        {
+            fwrite(Y, sizeof(char), width * pixelbytes, fp);
+            Y += pic.stride[0] * pixelbytes;
+        }
+        char *U = (char*)pic.planes[1];
+        for (int i = 0; i < height >> 1; i++)
+        {
+            fwrite(U, sizeof(char), (width>>1) * pixelbytes, fp);
+            U += pic.stride[1] * pixelbytes;
+        }
+        char *V = (char*)pic.planes[2];
+        for (int i = 0; i < height >> 1; i++)
+        {
+            fwrite(V, sizeof(char), (width>>1) * pixelbytes, fp);
+            V += pic.stride[2] * pixelbytes;
+        }
+    }
+    return true;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/output/yuv.h	Tue Apr 23 18:24:06 2013 +0530
@@ -0,0 +1,59 @@
+/*****************************************************************************
+ * Copyright (C) 2013 x265 project
+ *
+ * Authors: Steve Borho <steve@borho.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing@multicorewareinc.com.
+ *****************************************************************************/
+
+#ifndef _YUV_H_
+#define _YUV_H_
+
+#include "output.h"
+#include <stdio.h>
+
+namespace x265 {
+// private x265 namespace
+
+class YUVOutput : public Output
+{
+protected:
+
+    int width;
+
+    int height;
+
+    int depth;
+
+    char *buf;
+
+    FILE *fp;
+
+public:
+
+    YUVOutput(const char *filename , int width, int height, int bitdepth);
+
+    virtual ~YUVOutput();
+
+    void release()                                { delete this; }
+
+    bool writePicture(const x265_picture& pic);
+};
+}
+
+#endif // _YUV_H_
--- a/source/test/mbdstharness.cpp	Tue Apr 23 11:07:40 2013 +0530
+++ b/source/test/mbdstharness.cpp	Tue Apr 23 18:24:06 2013 +0530
@@ -224,6 +224,27 @@ bool MBDstHarness::check_butterfly8_inve
     return true;
 }
 
+bool MBDstHarness::check_butterfly16_inverse_primitive(butterfly ref, butterfly opt)
+{
+    int j = 0;
+    int mem_cmp_size = 320; // 2*16*10 -> sizeof(short)*number of elements*number of lines
+
+    for (int i = 0; i <= 5; i++)
+    {
+        opt(mbuf1 + j, mbuf2, 3, 10);
+        ref(mbuf1 + j, mbuf3, 3, 10);
+
+        if (memcmp(mbuf2, mbuf3, mem_cmp_size))
+            return false;
+
+        j += 16;
+        memset(mbuf2, 0, mem_cmp_size);
+        memset(mbuf3, 0, mem_cmp_size);
+    }
+
+    return true;
+}
+
 bool MBDstHarness::testCorrectness(const EncoderPrimitives& ref, const EncoderPrimitives& opt)
 {
     if (opt.inversedst)
@@ -280,6 +301,15 @@ bool MBDstHarness::testCorrectness(const
         }
     }
 
+    if (opt.partial_butterfly[butterfly_inverse_16])
+    {
+        if (!check_butterfly16_inverse_primitive(ref.partial_butterfly[butterfly_inverse_16], opt.partial_butterfly[butterfly_inverse_16]))
+        {
+            printf("\npartialButterfly%s failed\n", ButterflyConf_names[butterfly_inverse_16]);
+            return false;
+        }
+    }
+
     return true;
 }
 
@@ -293,8 +323,8 @@ void MBDstHarness::measureSpeed(const En
     {
         printf("InverseDST");
         REPORT_SPEEDUP(MBDST_ITERATIONS,
-            opt.inversedst(mbuf1, mbuf2, 16),
-            ref.inversedst(mbuf1, mbuf2, 16));
+                       opt.inversedst(mbuf1, mbuf2, 16),
+                       ref.inversedst(mbuf1, mbuf2, 16));
     }
 
     for (int value = 0; value < 8; value++)
@@ -305,8 +335,8 @@ void MBDstHarness::measureSpeed(const En
         {
             printf("partialButterfly%s", ButterflyConf_names[value]);
             REPORT_SPEEDUP(MBDST_ITERATIONS,
-                opt.partial_butterfly[value](mbuf1, mbuf2, 3, 10),
-                ref.partial_butterfly[value](mbuf1, mbuf2, 3, 10));
+                           opt.partial_butterfly[value](mbuf1, mbuf2, 3, 10),
+                           ref.partial_butterfly[value](mbuf1, mbuf2, 3, 10));
         }
     }
 
--- a/source/test/mbdstharness.h	Tue Apr 23 11:07:40 2013 +0530
+++ b/source/test/mbdstharness.h	Tue Apr 23 18:24:06 2013 +0530
@@ -41,6 +41,7 @@ protected:
     bool check_butterfly8_primitive(x265::butterfly ref, x265::butterfly opt);
     bool check_butterfly4_inverse_primitive(x265::butterfly ref, x265::butterfly opt);
     bool check_butterfly8_inverse_primitive(x265::butterfly ref, x265::butterfly opt);
+    bool check_butterfly16_inverse_primitive(x265::butterfly ref, x265::butterfly opt);
 
 public:
 
--- a/source/x265cfg.cpp	Tue Apr 23 11:07:40 2013 +0530
+++ b/source/x265cfg.cpp	Tue Apr 23 18:24:06 2013 +0530
@@ -61,16 +61,15 @@ namespace po = df::program_options_lite;
 // ====================================================================================================================
 
 TAppEncCfg::TAppEncCfg()
-    : m_pchInputFile()
-    , m_pchBitstreamFile()
-    , m_pchReconFile()
+    : m_pchBitstreamFile()
     , m_pchdQPFile()
     , m_pColumnWidth()
     , m_pRowHeight()
     , m_scalingListFile()
 {
     m_aidQP = NULL;
-    handler_recon = NULL;
+    m_input = NULL;
+    m_recon = NULL;
 #if J0149_TONE_MAPPING_SEI
     m_startOfCodedInterval = NULL;
     m_codedPivotValue = NULL;
@@ -80,6 +79,14 @@ TAppEncCfg::TAppEncCfg()
 
 TAppEncCfg::~TAppEncCfg()
 {
+    if (m_input)
+    {
+        m_input->release();
+    }
+    if (m_recon)
+    {
+        m_recon->release();
+    }
     if (m_aidQP)
     {
         delete[] m_aidQP;
@@ -101,9 +108,7 @@ TAppEncCfg::~TAppEncCfg()
         m_targetPivotValue = NULL;
     }
 #endif // if J0149_TONE_MAPPING_SEI
-    free(m_pchInputFile);
     free(m_pchBitstreamFile);
-    free(m_pchReconFile);
     free(m_pchdQPFile);
     free(m_pColumnWidth);
     free(m_pRowHeight);
@@ -259,8 +264,8 @@ Bool TAppEncCfg::parseCfg(Int argc, Char
     int cpuid;
 
     string cfg_InputFile;
+    string cfg_ReconFile;
     string cfg_BitstreamFile;
-    string cfg_ReconFile;
     string cfg_dQPFile;
     string cfg_ColumnWidth;
     string cfg_RowHeight;
@@ -617,19 +622,17 @@ Bool TAppEncCfg::parseCfg(Int argc, Char
      * Set any derived parameters
      */
     /* convert std::string to c string for compatability */
-    m_pchInputFile = cfg_InputFile.empty() ? NULL : strdup(cfg_InputFile.c_str());
     m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
-    m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str());
     m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str());
 
     /* parse the width, height, frame rate from the y4m files if it is not given in the configuration file */
-    m_input = x265::Input::Open(m_pchInputFile);
-
+    m_input = x265::Input::Open(cfg_InputFile.c_str());
     if (!m_input || m_input->isFail())
     {
         printf("Unable to open source file\n");
         return 1;
     }
+    printf("Input          File          : %s\n", cfg_InputFile.c_str());
 
     if (m_input->getWidth())
     {
@@ -651,6 +654,16 @@ Bool TAppEncCfg::parseCfg(Int argc, Char
     if (!m_outputBitDepthY) { m_outputBitDepthY = m_internalBitDepthY; }
     if (!m_outputBitDepthC) { m_outputBitDepthC = m_internalBitDepthC; }
 
+    if (m_FrameSkip && m_input)
+    {
+        m_input->skipFrames(m_FrameSkip);
+    }
+    if (!cfg_ReconFile.empty())
+    {
+        printf("Reconstruction File          : %s\n", cfg_ReconFile.c_str());
+        m_recon = x265::Output::Open(cfg_ReconFile.c_str(), m_iSourceWidth, m_iSourceHeight, m_outputBitDepthY);
+    }
+
     Char *pColumnWidth = cfg_ColumnWidth.empty() ? NULL : strdup(cfg_ColumnWidth.c_str());
     Char *pRowHeight = cfg_RowHeight.empty() ? NULL : strdup(cfg_RowHeight.c_str());
     if (m_iUniformSpacingIdr == 0 && m_iNumColumnsMinus1 > 0)
@@ -880,10 +893,11 @@ Bool TAppEncCfg::parseCfg(Int argc, Char
         }
     }
 #endif // if J0149_TONE_MAPPING_SEI
+
     // check validity of input parameters
     xCheckParameter();
 
-    // set global varibles
+    // set global variables
     xSetGlobal();
 
     // print-out parameters
@@ -1604,9 +1618,7 @@ Void TAppEncCfg::xSetGlobal()
 Void TAppEncCfg::xPrintParameter()
 {
     printf("\n");
-    printf("Input          File          : %s\n", m_pchInputFile);
     printf("Bitstream      File          : %s\n", m_pchBitstreamFile);
-    printf("Reconstruction File          : %s\n", m_pchReconFile);
     printf("Real     Format              : %dx%d %dHz\n", m_iSourceWidth - m_confLeft - m_confRight, m_iSourceHeight - m_confTop - m_confBottom, m_iFrameRate);
     printf("Internal Format              : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate);
     printf("Frame index                  : %u - %d (%d frames)\n", m_FrameSkip, m_FrameSkip + m_framesToBeEncoded - 1, m_framesToBeEncoded);
--- a/source/x265cfg.h	Tue Apr 23 11:07:40 2013 +0530
+++ b/source/x265cfg.h	Tue Apr 23 18:24:06 2013 +0530
@@ -39,10 +39,8 @@
 #define __TAPPENCCFG__
 
 #include "TLibCommon/CommonDef.h"
-
-#include "TLibEncoder/TEncCfg.h"
-#include "TLibVideoIO/TVideoIO.h"
 #include "input/input.h"
+#include "output/output.h"
 #include <sstream>
 
 //! \ingroup TAppEncoder
@@ -56,12 +54,13 @@
 class TAppEncCfg
 {
 protected:
+    x265::Input*  m_input;
+    x265::Output* m_recon;
 
     // file I/O
-    Char*     m_pchInputFile;                                 ///< source file name
     Char*     m_pchBitstreamFile;                             ///< output bitstream file
-    Char*     m_pchReconFile;                                 ///< output reconstruction file
     Double    m_adLambdaModifier[MAX_TLAYER];                 ///< Lambda modifier array for each temporal layer
+
     // source specification
     Int       m_iFrameRate;                                   ///< source frame-rates (Hz)
     UInt      m_FrameSkip;                                    ///< number of skipped frames from the beginning
@@ -75,12 +74,6 @@ protected:
     Int       m_framesToBeEncoded;                            ///< number of encoded frames
     Int       m_aiPad[2];                                     ///< number of padded pixels for width and height
 
-    //Input source file handlers
-    x265::Input* m_input;
-    TVideoIO* m_cTVideoIOReconFile;     ///< output reconstruction file
-    hnd_t*    handler_recon;
-    video_info_t  video_info;
-
     // profile/level
     Profile::Name m_profile;
     Level::Tier   m_levelTier;
--- a/source/x265enc.cpp	Tue Apr 23 11:07:40 2013 +0530
+++ b/source/x265enc.cpp	Tue Apr 23 18:24:06 2013 +0530
@@ -391,36 +391,11 @@ Void TAppEncTop::xInitLibCfg()
 
 Void TAppEncTop::xCreateLib()
 {
-    if (m_FrameSkip && m_input)
-        m_input->skipFrames(m_FrameSkip);
-
-    if (m_pchReconFile)
-    {
-        m_cTVideoIOReconFile = new TVideoIOYuv();
-        m_cTVideoIOReconFile->open(m_pchReconFile,
-                                   true,
-                                   m_outputBitDepthY,
-                                   m_outputBitDepthC,
-                                   m_internalBitDepthY,
-                                   m_internalBitDepthC,
-                                   handler_recon,
-                                   video_info,
-                                   m_aiPad); // write mode
-    }
-
-    // Neo Decoder
     m_cTEncTop.create();
 }
 
 Void TAppEncTop::xDestroyLib()
 {
-    // Video I/O
-    if (m_input)
-        m_input->release();
-    if (m_pchReconFile)
-        m_cTVideoIOReconFile->close(handler_recon);
-
-    // Neo Decoder
     m_cTEncTop.destroy();
 }
 
@@ -582,12 +557,17 @@ Void TAppEncTop::xWriteOutput(std::ostre
         --iterPicYuvRec;
     }
 
+    x265_picture pic;
     for (i = 0; i < iNumEncoded; i++)
     {
-        TComPicYuv  *pcPicYuvRec  = *(iterPicYuvRec++);
-        if (m_pchReconFile)
+        if (m_recon)
         {
-            m_cTVideoIOReconFile->write(pcPicYuvRec, handler_recon, m_confLeft, m_confRight, m_confTop, m_confBottom);
+            TComPicYuv  *pcPicYuvRec  = *(iterPicYuvRec++);
+            pic.planes[0] = pcPicYuvRec->getLumaAddr(); pic.stride[0] = pcPicYuvRec->getStride();
+            pic.planes[1] = pcPicYuvRec->getCbAddr();   pic.stride[1] = pcPicYuvRec->getCStride();
+            pic.planes[2] = pcPicYuvRec->getCrAddr();   pic.stride[2] = pcPicYuvRec->getCStride();
+            pic.bitDepth = sizeof(Pel) == 8 ? 8 : 16;
+            m_recon->writePicture(pic);
         }
 
         const AccessUnit &au = *(iterBitstream++);
--- a/source/x265enc.h	Tue Apr 23 11:07:40 2013 +0530
+++ b/source/x265enc.h	Tue Apr 23 18:24:06 2013 +0530
@@ -42,7 +42,6 @@
 #include <ostream>
 
 #include "TLibEncoder/TEncTop.h"
-#include "TLibVideoIO/TVideoIOYuv.h"
 #include "TLibCommon/AccessUnit.h"
 #include "x265cfg.h"