From 68e2471bec9757eaaf58457d55bc5167af26831a Mon Sep 17 00:00:00 2001
From: Vadim Seregin <vseregin@qti.qualcomm.com>
Date: Thu, 5 Mar 2020 17:24:51 +0100
Subject: [PATCH] Fix for cropping window in reconstructed decoded picture YUV
 output

---
 source/Lib/Utilities/VideoIOYuv.cpp | 12 +++++++++---
 source/Lib/Utilities/VideoIOYuv.h   |  2 +-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/source/Lib/Utilities/VideoIOYuv.cpp b/source/Lib/Utilities/VideoIOYuv.cpp
index 018b55748..0385c0dfb 100644
--- a/source/Lib/Utilities/VideoIOYuv.cpp
+++ b/source/Lib/Utilities/VideoIOYuv.cpp
@@ -980,7 +980,7 @@ bool VideoIOYuv::read ( PelUnitBuf& pic, PelUnitBuf& picOrg, const InputColourSp
 bool VideoIOYuv::write( uint32_t orgWidth, uint32_t orgHeight, const CPelUnitBuf& pic,
                         const InputColourSpaceConversion ipCSC,
                         const bool bPackedYUVOutputMode,
-                        int confLeft, int confRight, int confTop, int confBottom, ChromaFormat format, const bool bClipToRec709 )
+                        int confLeft, int confRight, int confTop, int confBottom, ChromaFormat format, const bool bClipToRec709, const bool subtractConfWindowOffsets )
 {
   PelStorage interm;
 
@@ -1038,6 +1038,12 @@ bool VideoIOYuv::write( uint32_t orgWidth, uint32_t orgHeight, const CPelUnitBuf
   const uint32_t    width444  = areaY.width - confLeft - confRight;
   const uint32_t    height444 = areaY.height -  confTop  - confBottom;
 
+  if( subtractConfWindowOffsets )
+  {
+    orgWidth -= confLeft + confRight;
+    orgHeight -= confTop + confBottom;
+  }
+
   if ((width444 == 0) || (height444 == 0))
   {
     msg( WARNING, "\nWarning: writing %d x %d luma sample output picture!", width444, height444);
@@ -1286,7 +1292,7 @@ bool VideoIOYuv::writeUpscaledPicture( const SPS& sps, const PPS& pps, const CPe
         confFullResolution.getWindowRightOffset() * SPS::getWinUnitX( chromaFormatIDC ),
         confFullResolution.getWindowTopOffset() * SPS::getWinUnitY( chromaFormatIDC ),
         confFullResolution.getWindowBottomOffset() * SPS::getWinUnitY( chromaFormatIDC ),
-        NUM_CHROMA_FORMAT, bClipToRec709 );
+        NUM_CHROMA_FORMAT, bClipToRec709, false );
     }
     else
     {
@@ -1299,7 +1305,7 @@ bool VideoIOYuv::writeUpscaledPicture( const SPS& sps, const PPS& pps, const CPe
         conf.getWindowRightOffset() * SPS::getWinUnitX( chromaFormatIDC ),
         conf.getWindowTopOffset() * SPS::getWinUnitY( chromaFormatIDC ),
         conf.getWindowBottomOffset() * SPS::getWinUnitY( chromaFormatIDC ),
-        NUM_CHROMA_FORMAT, bClipToRec709 );
+        NUM_CHROMA_FORMAT, bClipToRec709, false );
     }
   }
   else
diff --git a/source/Lib/Utilities/VideoIOYuv.h b/source/Lib/Utilities/VideoIOYuv.h
index 27504973e..52656b5f1 100644
--- a/source/Lib/Utilities/VideoIOYuv.h
+++ b/source/Lib/Utilities/VideoIOYuv.h
@@ -83,7 +83,7 @@ public:
   bool  write( uint32_t orgWidth, uint32_t orgHeight, const CPelUnitBuf& pic,
                const InputColourSpaceConversion ipCSC,
                const bool bPackedYUVOutputMode,
-               int confLeft = 0, int confRight = 0, int confTop = 0, int confBottom = 0, ChromaFormat format = NUM_CHROMA_FORMAT, const bool bClipToRec709 = false ); ///< write one YUV frame with padding parameter
+               int confLeft = 0, int confRight = 0, int confTop = 0, int confBottom = 0, ChromaFormat format = NUM_CHROMA_FORMAT, const bool bClipToRec709 = false, const bool subtractConfWindowOffsets = true ); ///< write one YUV frame with padding parameter
 
   // If fileFormat=NUM_CHROMA_FORMAT, use the format defined by pPicYuvTop and pPicYuvBottom
   bool  write( const CPelUnitBuf& picTop, const CPelUnitBuf& picBot,
-- 
GitLab