Consistent names for quant-related functions and variables.
authorDmitry Kovalev <dkovalev@google.com>
Fri, 26 Apr 2013 19:30:20 +0000 (12:30 -0700)
committerDmitry Kovalev <dkovalev@google.com>
Fri, 26 Apr 2013 19:30:20 +0000 (12:30 -0700)
Change-Id: I3a6d601e90e8740b9c26dd0afbfe9d467b75d367

vp9/common/vp9_quant_common.c
vp9/common/vp9_quant_common.h
vp9/decoder/vp9_decodframe.c
vp9/decoder/vp9_decodframe.h
vp9/decoder/vp9_onyxd_if.c
vp9/encoder/vp9_quantize.c
vp9/encoder/vp9_ratectrl.c
vp9/encoder/vp9_rdopt.c

index a94c772..2e9e4ca 100644 (file)
 #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;
-
-    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;
-  }
-}
+    const int ac_val = val;
 
-int vp9_dc_quant(int qindex, int delta) {
-  return dc_qlookup[clamp(qindex + delta, 0, MAXQ)];
-}
+    val = (int)(val * 1.02);
+    if (val == ac_val)
+      ++val;
 
-int vp9_dc_uv_quant(int qindex, int delta) {
-  return dc_qlookup[clamp(qindex + delta, 0, MAXQ)];
+    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_ac_yquant(int qindex) {
-  return ac_qlookup[clamp(qindex, 0, MAXQ)];
+int16_t vp9_dc_quant(int qindex, int delta) {
+  return dc_qlookup[clamp(qindex + delta, 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)];
 }
index 1520c37..7daf15d 100644 (file)
 #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_
index ad3a489..417c415 100644 (file)
@@ -163,22 +163,20 @@ static vp9_prob read_prob_diff_update(vp9_reader *r, int oldp) {
   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);
     }
   }
 }
@@ -1158,7 +1156,7 @@ static void setup_quantization(VP9D_COMP *pbi, vp9_reader *r) {
   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
 }
index 391a265..3aaae65 100644 (file)
@@ -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_
index a07a8fd..9582e8f 100644 (file)
@@ -133,10 +133,10 @@ VP9D_PTR vp9_create_decompressor(VP9D_CONFIG *oxcf) {
   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);
 
index ece1318..77e1972 100644 (file)
@@ -286,7 +286,7 @@ void vp9_init_quantizer(VP9_COMP *cpi) {
     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 @@ void vp9_init_quantizer(VP9_COMP *cpi) {
     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 @@ void vp9_init_quantizer(VP9_COMP *cpi) {
       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;
index 7a419fb..177295b 100644 (file)
@@ -89,7 +89,7 @@ static const unsigned int prior_key_frame_weight[KEY_FRAME_CONTEXT] = { 1, 2, 3,
 // 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) {
index 7de5bf7..e63f757 100644 (file)
@@ -187,7 +187,7 @@ void vp9_init_me_luts() {
 }
 
 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;
 }