From b791615f3b674503413c5adca808c9ee6b3a9019 Mon Sep 17 00:00:00 2001
From: spaluri <seethal.paluri@lge.com>
Date: Mon, 4 May 2020 14:52:48 -0700
Subject: [PATCH] JVET-R0186 aspect 1 rebase

---
 source/Lib/CommonLib/TypeDef.h      |  2 ++
 source/Lib/DecoderLib/VLCReader.cpp | 17 ++++++++++++++++-
 source/Lib/EncoderLib/VLCWriter.cpp | 14 ++++++++++++--
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index b03001080..092959e8d 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -51,6 +51,8 @@
 #include <cassert>
 
 //########### place macros to be removed in next cycle below this line ###############
+#define JVET_R0186_CLEANUP                                1 // JVET-R0186 aspect 1: Signal the pps_no_pic_partition_flag ahead in the PPS.
+
 #define JVET_R0330_CRS_CLIP_REM                           1 // JVET-R0330: Remove redundant clipping in chroma residual scaling factor derivation
 
 #define JVET_R0059_RPL_CLEANUP                            1 // JVET-R0059 aspect 2: Condition the signalling of ltrp_in_header_flag[ listIdx ][ rplsIdx ].
diff --git a/source/Lib/DecoderLib/VLCReader.cpp b/source/Lib/DecoderLib/VLCReader.cpp
index 8193a6694..bb717a08f 100644
--- a/source/Lib/DecoderLib/VLCReader.cpp
+++ b/source/Lib/DecoderLib/VLCReader.cpp
@@ -476,10 +476,24 @@ void HLSyntaxReader::parsePPS( PPS* pcPPS )
 
   READ_FLAG( uiCode, "output_flag_present_flag" );                    pcPPS->setOutputFlagPresentFlag( uiCode==1 );
 
+#if JVET_R0186_CLEANUP
+  READ_FLAG( uiCode, "pps_no_pic_partition_flag");                     pcPPS->setNoPicPartitionFlag(uiCode == 1);
+#endif  
   READ_FLAG( uiCode, "subpic_id_mapping_in_pps_flag" );           pcPPS->setSubPicIdMappingInPpsFlag( uiCode != 0 );
   if( pcPPS->getSubPicIdMappingInPpsFlag() )
   {
+#if JVET_R0186_CLEANUP
+    if( !pcPPS->getNoPicPartitionFlag() )
+    {
+      READ_UVLC(uiCode, "pps_num_subpics_minus1");                         pcPPS->setNumSubPics(uiCode + 1);
+    }
+    else
+    {
+      pcPPS->setNumSubPics(1);
+    }
+#else
     READ_UVLC( uiCode, "pps_num_subpics_minus1" );                         pcPPS->setNumSubPics( uiCode + 1 );
+#endif
     CHECK( uiCode > MAX_NUM_SUB_PICS-1,  "Number of sub-pictures exceeds limit");
 
     READ_UVLC( uiCode, "pps_subpic_id_len_minus1" );                       pcPPS->setSubPicIdLen( uiCode + 1 );
@@ -491,8 +505,9 @@ void HLSyntaxReader::parsePPS( PPS* pcPPS )
       READ_CODE( pcPPS->getSubPicIdLen( ), uiCode, "pps_subpic_id[i]" );   pcPPS->setSubPicId( picIdx, uiCode );
     }
   }
-
+#if !JVET_R0186_CLEANUP
   READ_FLAG( uiCode, "no_pic_partition_flag" );                       pcPPS->setNoPicPartitionFlag( uiCode == 1 );
+#endif
   if(!pcPPS->getNoPicPartitionFlag())
   {
     int colIdx, rowIdx;
diff --git a/source/Lib/EncoderLib/VLCWriter.cpp b/source/Lib/EncoderLib/VLCWriter.cpp
index 6a6cb9849..ea889f39f 100644
--- a/source/Lib/EncoderLib/VLCWriter.cpp
+++ b/source/Lib/EncoderLib/VLCWriter.cpp
@@ -291,12 +291,21 @@ void HLSWriter::codePPS( const PPS* pcPPS )
   }
 
   WRITE_FLAG( pcPPS->getOutputFlagPresentFlag() ? 1 : 0,     "output_flag_present_flag" );
+#if JVET_R0186_CLEANUP
+  WRITE_FLAG( pcPPS->getNoPicPartitionFlag() ? 1 : 0, "pps_no_pic_partition_flag" );
+#endif
   WRITE_FLAG( pcPPS->getSubPicIdMappingInPpsFlag() ? 1 : 0, "subpic_id_mapping_in_pps_flag" );
   if( pcPPS->getSubPicIdMappingInPpsFlag() )
   {
     CHECK(pcPPS->getNumSubPics() < 1, "PPS: NumSubPics cannot be less than 1");
+#if JVET_R0186_CLEANUP
+    if( !pcPPS->getNoPicPartitionFlag() )
+    {
+      WRITE_UVLC(pcPPS->getNumSubPics() - 1, "pps_num_subpics_minus1");
+    }
+#else
     WRITE_UVLC( pcPPS->getNumSubPics() - 1, "pps_num_subpics_minus1" );
-
+#endif
     CHECK(pcPPS->getSubPicIdLen() < 1, "PPS: SubPicIdLen cannot be less than 1");
     WRITE_UVLC( pcPPS->getSubPicIdLen() - 1, "pps_subpic_id_len_minus1" );
 
@@ -306,8 +315,9 @@ void HLSWriter::codePPS( const PPS* pcPPS )
       WRITE_CODE( pcPPS->getSubPicId(picIdx), pcPPS->getSubPicIdLen( ), "pps_subpic_id[i]" );
     }
   }
-
+#if !JVET_R0186_CLEANUP 
   WRITE_FLAG( pcPPS->getNoPicPartitionFlag( ) ? 1 : 0, "no_pic_partition_flag" );
+#endif
   if( !pcPPS->getNoPicPartitionFlag() )
   {
     int colIdx, rowIdx;
-- 
GitLab