From 2a763fa603a14c500d96f4070bc8edf03fc22d40 Mon Sep 17 00:00:00 2001
From: Taoran Lu <tlu@dolby.com>
Date: Tue, 29 Oct 2019 10:31:26 -0700
Subject: [PATCH] P0335 change HDR PQ CTC

---
 cfg/per-class/classH1.cfg           | 25 +++++++++++++------------
 source/App/EncoderApp/EncAppCfg.cpp |  5 +++++
 source/Lib/CommonLib/TypeDef.h      |  2 ++
 3 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/cfg/per-class/classH1.cfg b/cfg/per-class/classH1.cfg
index 7890dc553..67dba5ff2 100644
--- a/cfg/per-class/classH1.cfg
+++ b/cfg/per-class/classH1.cfg
@@ -1,23 +1,24 @@
 # ======== Luma adaptive QP ==========
-LumaLevelToDeltaQPMode        : 1           # Change luma delta QP based on average luma
+LumaLevelToDeltaQPMode        : 0           # Change luma delta QP based on average luma
 isSDR                         : 0           # 1: SDR in PQ container,   0: HDR
 
 # ======= LMCS =======================
-LMCSEnable                    : 0           # turned off in HDR CTC 
+LMCSEnable                    : 1           # turned off in HDR CTC 
 LMCSSignalType                : 1           # Input signal type: 0:SDR, 1:HDR-PQ, 2:HDR-HLG
 
 #======== Chroma QP scale ============
-WCGPPSEnable                  : 1           # enable WCG Chroma scale
-WCGPPSChromaQpScale           : -0.46       # Linear chroma QP offset mapping (scale) based on QP
-WCGPPSChromaQpOffset          : 9.26        # Linear chroma QP offset mapping (offset) based on QP
-WCGPPSCbQpScale               : 1.14        # Scale factor depending on capture and representation color space
-WCGPPSCrQpScale               : 1.79        # Scale factor depending on capture and representation color space 
+WCGPPSEnable                  : 0           # enable WCG Chroma scale
 
-CbQpOffset                          : 0
-CrQpOffset                          : 0
-SameCQPTablesForAllChroma           : 1
-QpInValCb                           : 9 23 33 42
-QpOutValCb                          : 9 24 33 37
+CbQpOffset                    : 0
+CrQpOffset                    : 0
+
+SameCQPTablesForAllChroma     : 0
+QpInValCb                     : 13 20 36 38 43 54
+QpOutValCb                    : 13 21 29 29 32 37
+QpInValCr                     : 13 20 37 41 44 54
+QpOutValCr                    : 13 21 27 29 32 37
+QpInValCbCr                   : 12 21 41 43 54
+QpOutValCbCr                  : 12 22 30 32 37
 
 CclmCollocatedChroma          : 1
 
diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp
index 635e0046c..d59ede449 100644
--- a/source/App/EncoderApp/EncAppCfg.cpp
+++ b/source/App/EncoderApp/EncAppCfg.cpp
@@ -2676,8 +2676,13 @@ bool EncAppCfg::xCheckParameter()
 #endif
   if (m_lumaLevelToDeltaQPMapping.mode && m_lumaReshapeEnable)
   {
+#if !JVET_P0335_HDRCTC_CHANGE
     msg(WARNING, "For HDR-PQ, reshaper should be used mutual-exclusively with Luma-level-based Delta QP. If use luma DQP, turn reshaper off.\n");
     m_lumaReshapeEnable = false;
+#else
+    msg(WARNING, "For HDR-PQ, LMCS should be used mutual-exclusively with Luma-level-based Delta QP. If use LMCS, turn lumaDQP off.\n");
+    m_lumaLevelToDeltaQPMapping.mode = LUMALVL_TO_DQP_DISABLED;
+#endif
   }
   if (!m_lumaReshapeEnable)
   {
diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index 579b04df0..74da1006c 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -143,6 +143,8 @@
 
 #define JVET_P0418_ALIGN_MLRP_CCLM                        1 // JVET-P0418: Align MLRP with CCLM in terms of reference lines/columns
 
+#define JVET_P0335_HDRCTC_CHANGE                          1 // JVET-P0335: change of HDR PQ CTC: enable LMCS and use QPc table in P0335, and disable lumaDQP and WCGPPSOffset
+
 #define JVET_P0158_ALIGN_ALF_VB                           1 // JVET-P0158: Apply ALF VB on the bottom CTU row
 
 #define JVET_O0145_ENTRYPOINT_SIGNALLING                  0 // JVET-O0145: Not signalling num_entry_point_offsets but derive it at decoder
-- 
GitLab