From 999e155f55f07238e9900d4ec25ff4ac311a5f92 Mon Sep 17 00:00:00 2001
From: Yaowu Xu <yaowu@google.com>
Date: Tue, 25 Jan 2011 22:24:22 -0800
Subject: [PATCH] cap the best quantizer for 2nd order DC

This commit also removes artificial RDMULT cap for low quantizers.
The intention is to address some abnormal behavior of mode selections
at the low quantizer end, where many macroblocks were coded with
SPLITMV with all partitions using same motion vector including (0,0).
This change improves the compression quality substantially for high
quality encodings in both PSNR and SSIM terms. Overall effect on
mid/low rate range is also positive for all metrics, but smaller
in magnitude.

Change-Id: I864b29c4bd9ff610d2545fa94a19cc7e80c02667
---
 vp8/encoder/onyx_if.c | 4 ++++
 vp8/encoder/rdopt.c   | 5 ++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c
index 9007853643..77cec73739 100644
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -3127,6 +3127,10 @@ static void set_quantizer(VP8_COMP *cpi, int Q)
     cm->uvdc_delta_q = 0;
     cm->uvac_delta_q = 0;
 
+    if(Q<4)
+    {
+        cm->y2dc_delta_q = 4-Q;
+    }
     // Set Segment specific quatizers
     mbd->segment_feature_data[MB_LVL_ALT_Q][0] = cpi->segment_feature_data[MB_LVL_ALT_Q][0];
     mbd->segment_feature_data[MB_LVL_ALT_Q][1] = cpi->segment_feature_data[MB_LVL_ALT_Q][1];
diff --git a/vp8/encoder/rdopt.c b/vp8/encoder/rdopt.c
index 3b898f1b27..36420aad13 100644
--- a/vp8/encoder/rdopt.c
+++ b/vp8/encoder/rdopt.c
@@ -243,10 +243,9 @@ void vp8_initialize_rd_consts(VP8_COMP *cpi, int Qvalue)
             cpi->RDMULT += (cpi->RDMULT * rd_iifactor[cpi->next_iiratio]) >> 4;
     }
 
-    if (cpi->RDMULT < 125)
-        cpi->RDMULT = 125;
-
     cpi->mb.errorperbit = (cpi->RDMULT / 100);
+    cpi->mb.errorperbit += (cpi->mb.errorperbit==0);
+
     vp8_set_speed_features(cpi);
 
     if (cpi->common.simpler_lpf)
-- 
GitLab