shithub: libvpx

Download patch

ref: 51a73fbba22e5446de93bc8044d8c408bb3c2254
parent: e8315aeea07e0389ce412b2bf4ebe0c88be1c7c6
parent: 5a5a1f25a8e8b9dc4ef189661e57ea83f004347d
author: Dmitry Kovalev <dkovalev@google.com>
date: Tue Apr 30 06:19:48 EDT 2013

Merge "Consistent names for quant-related functions and variables." into experimental

--- a/vp9/common/vp9_quant_common.c
+++ b/vp9/common/vp9_quant_common.c
@@ -11,45 +11,36 @@
 #include "vp9/common/vp9_common.h"
 #include "vp9/common/vp9_quant_common.h"
 
-static int dc_qlookup[QINDEX_RANGE];
-static int ac_qlookup[QINDEX_RANGE];
+static int16_t dc_qlookup[QINDEX_RANGE];
+static int16_t ac_qlookup[QINDEX_RANGE];
 
 #define ACDC_MIN 4
 
+// TODO(dkovalev) move to common and reuse
+static double poly3(double a, double b, double c, double d, double x) {
+  return a*x*x*x + b*x*x + c*x + d;
+}
+
 void vp9_init_quant_tables() {
-  int i;
-  int current_val = 4;
-  int last_val = 4;
-  int ac_val;
+  int i, val = 4;
 
   for (i = 0; i < QINDEX_RANGE; i++) {
-    ac_qlookup[i] = current_val;
-    current_val = (int)(current_val * 1.02);
-    if (current_val == last_val)
-      current_val++;
-    last_val = current_val;
+    const int ac_val = val;
 
-    ac_val = ac_qlookup[i];
-    dc_qlookup[i] = (int)((0.000000305 * ac_val * ac_val * ac_val) +
-                          (-0.00065 * ac_val * ac_val) +
-                          (0.9 * ac_val) + 0.5);
-    if (dc_qlookup[i] < ACDC_MIN)
-      dc_qlookup[i] = ACDC_MIN;
+    val = (int)(val * 1.02);
+    if (val == ac_val)
+      ++val;
+
+    ac_qlookup[i] = (int16_t)ac_val;
+    dc_qlookup[i] = (int16_t)MAX(ACDC_MIN, poly3(0.000000305, -0.00065, 0.9,
+                                                 0.5, ac_val));
   }
 }
 
-int vp9_dc_quant(int qindex, int delta) {
+int16_t vp9_dc_quant(int qindex, int delta) {
   return dc_qlookup[clamp(qindex + delta, 0, MAXQ)];
 }
 
-int vp9_dc_uv_quant(int qindex, int delta) {
-  return dc_qlookup[clamp(qindex + delta, 0, MAXQ)];
-}
-
-int vp9_ac_yquant(int qindex) {
-  return ac_qlookup[clamp(qindex, 0, MAXQ)];
-}
-
-int vp9_ac_uv_quant(int qindex, int delta) {
+int16_t vp9_ac_quant(int qindex, int delta) {
   return ac_qlookup[clamp(qindex + delta, 0, MAXQ)];
 }
--- a/vp9/common/vp9_quant_common.h
+++ b/vp9/common/vp9_quant_common.h
@@ -15,11 +15,8 @@
 #include "vp9/common/vp9_onyxc_int.h"
 
 void vp9_init_quant_tables();
-int vp9_ac_yquant(int qindex);
-int vp9_dc_quant(int qindex, int delta);
-int vp9_dc2quant(int qindex, int delta);
-int vp9_ac2quant(int qindex, int delta);
-int vp9_dc_uv_quant(int qindex, int delta);
-int vp9_ac_uv_quant(int qindex, int delta);
+
+int16_t vp9_dc_quant(int qindex, int delta);
+int16_t vp9_ac_quant(int qindex, int delta);
 
 #endif  // VP9_COMMON_VP9_QUANT_COMMON_H_
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -163,22 +163,20 @@
   return (vp9_prob)inv_remap_prob(delp, oldp);
 }
 
-void vp9_init_de_quantizer(VP9D_COMP *pbi) {
-  int i;
-  int q;
-  VP9_COMMON *const pc = &pbi->common;
+void vp9_init_dequantizer(VP9_COMMON *pc) {
+  int q, i;
 
   for (q = 0; q < QINDEX_RANGE; q++) {
     // DC value
-    pc->y_dequant[q][0] = (int16_t)vp9_dc_quant(q, pc->y_dc_delta_q);
-    pc->uv_dequant[q][0] = (int16_t)vp9_dc_uv_quant(q, pc->uv_dc_delta_q);
+    pc->y_dequant[q][0] = vp9_dc_quant(q, pc->y_dc_delta_q);
+    pc->uv_dequant[q][0] = vp9_dc_quant(q, pc->uv_dc_delta_q);
 
     // AC values
     for (i = 1; i < 16; i++) {
       const int rc = vp9_default_zig_zag1d_4x4[i];
 
-      pc->y_dequant[q][rc] = (int16_t)vp9_ac_yquant(q);
-      pc->uv_dequant[q][rc] = (int16_t)vp9_ac_uv_quant(q, pc->uv_ac_delta_q);
+      pc->y_dequant[q][rc] = vp9_ac_quant(q, 0);
+      pc->uv_dequant[q][rc] = vp9_ac_quant(q, pc->uv_ac_delta_q);
     }
   }
 }
@@ -1041,7 +1039,7 @@
   if (get_delta_q(r, &pc->y_dc_delta_q) |
       get_delta_q(r, &pc->uv_dc_delta_q) |
       get_delta_q(r, &pc->uv_ac_delta_q))
-    vp9_init_de_quantizer(pbi);
+    vp9_init_dequantizer(pc);
 
   mb_init_dequantizer(pc, &pbi->mb);  // MB level dequantizer setup
 }
--- a/vp9/decoder/vp9_decodframe.h
+++ b/vp9/decoder/vp9_decodframe.h
@@ -12,8 +12,8 @@
 #ifndef VP9_DECODER_VP9_DECODFRAME_H_
 #define VP9_DECODER_VP9_DECODFRAME_H_
 
-struct VP9Decompressor;
+struct VP9Common;
 
-void vp9_init_de_quantizer(struct VP9Decompressor *pbi);
+void vp9_init_dequantizer(struct VP9Common *pc);
 
 #endif  // VP9_DECODER_VP9_DECODFRAME_H_
--- a/vp9/decoder/vp9_onyxd_if.c
+++ b/vp9/decoder/vp9_onyxd_if.c
@@ -133,10 +133,10 @@
   pbi->common.current_video_frame = 0;
   pbi->ready_for_new_data = 1;
 
-  // vp9_init_de_quantizer() is first called here. Add check in
+  // vp9_init_dequantizer() is first called here. Add check in
   // frame_init_dequantizer() to avoid unnecessary calling of
-  // vp9_init_de_quantizer() for every frame.
-  vp9_init_de_quantizer(pbi);
+  // vp9_init_dequantizer() for every frame.
+  vp9_init_dequantizer(&pbi->common);
 
   vp9_loop_filter_init(&pbi->common);
 
--- a/vp9/encoder/vp9_quantize.c
+++ b/vp9/encoder/vp9_quantize.c
@@ -286,7 +286,7 @@
     cpi->common.y_dequant[q][0] = quant_val;
     cpi->zrun_zbin_boost_y1[q][0] = (quant_val * zbin_boost[0]) >> 7;
 
-    quant_val = vp9_dc_uv_quant(q, cpi->common.uv_dc_delta_q);
+    quant_val = vp9_dc_quant(q, cpi->common.uv_dc_delta_q);
     invert_quant(cpi->UVquant[q] + 0, cpi->UVquant_shift[q] + 0, quant_val);
     cpi->UVzbin[q][0] = ROUND_POWER_OF_TWO(qzbin_factor * quant_val, 7);
     cpi->UVround[q][0] = (qrounding_factor * quant_val) >> 7;
@@ -297,7 +297,7 @@
     for (i = 1; i < 16; i++) {
       int rc = vp9_default_zig_zag1d_4x4[i];
 
-      quant_val = vp9_ac_yquant(q);
+      quant_val = vp9_ac_quant(q, 0);
       invert_quant(cpi->Y1quant[q] + rc, cpi->Y1quant_shift[q] + rc, quant_val);
       cpi->Y1zbin[q][rc] = ROUND_POWER_OF_TWO(qzbin_factor * quant_val, 7);
       cpi->Y1round[q][rc] = (qrounding_factor * quant_val) >> 7;
@@ -305,7 +305,7 @@
       cpi->zrun_zbin_boost_y1[q][i] =
           ROUND_POWER_OF_TWO(quant_val * zbin_boost[i], 7);
 
-      quant_val = vp9_ac_uv_quant(q, cpi->common.uv_ac_delta_q);
+      quant_val = vp9_ac_quant(q, cpi->common.uv_ac_delta_q);
       invert_quant(cpi->UVquant[q] + rc, cpi->UVquant_shift[q] + rc, quant_val);
       cpi->UVzbin[q][rc] = ROUND_POWER_OF_TWO(qzbin_factor * quant_val, 7);
       cpi->UVround[q][rc] = (qrounding_factor * quant_val) >> 7;
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -89,7 +89,7 @@
 // tables if and when things settle down in the experimental bitstream
 double vp9_convert_qindex_to_q(int qindex) {
   // Convert the index to a real Q value (scaled down to match old Q values)
-  return vp9_ac_yquant(qindex) / 4.0;
+  return vp9_ac_quant(qindex, 0) / 4.0;
 }
 
 int vp9_gfboost_qadjust(int qindex) {
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -187,7 +187,7 @@
 }
 
 static int compute_rd_mult(int qindex) {
-  int q = vp9_dc_quant(qindex, 0);
+  const int q = vp9_dc_quant(qindex, 0);
   return (11 * q * q) >> 2;
 }