shithub: libvpx

Download patch

ref: 3f6c6ffc86911d213f8df301eff3be2d0977a81c
parent: 347ad7fff0459dc8b9dfc9613e66d594c44b57b0
author: Dmitry Kovalev <dkovalev@google.com>
date: Tue Apr 30 09:39:50 EDT 2013

Adding vp9_get_qindex function.

Moving common code from encoder and decoder to vp9_get_qindex function.
Also moving quant-related constants from vp9_onyxc_int.h to
vp9_quant_common.h.

Change-Id: I70c5bfbaa1c8bf00fde0bfc459d077f88b6d46c8

--- a/vp9/common/vp9_onyxc_int.h
+++ b/vp9/common/vp9_onyxc_int.h
@@ -18,6 +18,7 @@
 #include "vp9/common/vp9_entropymv.h"
 #include "vp9/common/vp9_entropy.h"
 #include "vp9/common/vp9_entropymode.h"
+#include "vp9/common/vp9_quant_common.h"
 
 #if CONFIG_POSTPROC
 #include "vp9/common/vp9_postproc.h"
@@ -30,13 +31,6 @@
 /* Create/destroy static data structures. */
 
 void vp9_initialize_common(void);
-
-#define MINQ 0
-
-#define MAXQ 255
-#define QINDEX_BITS 8
-
-#define QINDEX_RANGE (MAXQ + 1)
 
 #if CONFIG_MULTIPLE_ARF
 #define NUM_REF_FRAMES 8
--- a/vp9/common/vp9_quant_common.c
+++ b/vp9/common/vp9_quant_common.c
@@ -10,6 +10,7 @@
 
 #include "vp9/common/vp9_common.h"
 #include "vp9/common/vp9_quant_common.h"
+#include "vp9/common/vp9_seg_common.h"
 
 static int16_t dc_qlookup[QINDEX_RANGE];
 static int16_t ac_qlookup[QINDEX_RANGE];
@@ -44,3 +45,16 @@
 int16_t vp9_ac_quant(int qindex, int delta) {
   return ac_qlookup[clamp(qindex + delta, 0, MAXQ)];
 }
+
+
+int vp9_get_qindex(MACROBLOCKD *xd, int segment_id, int base_qindex) {
+  if (vp9_segfeature_active(xd, segment_id, SEG_LVL_ALT_Q)) {
+    const int data = vp9_get_segdata(xd, segment_id, SEG_LVL_ALT_Q);
+    return xd->mb_segment_abs_delta == SEGMENT_ABSDATA ?
+               data :  // Abs value
+               clamp(base_qindex + data, 0, MAXQ);  // Delta value
+  } else {
+    return base_qindex;
+  }
+}
+
--- a/vp9/common/vp9_quant_common.h
+++ b/vp9/common/vp9_quant_common.h
@@ -12,11 +12,17 @@
 #define VP9_COMMON_VP9_QUANT_COMMON_H_
 
 #include "vp9/common/vp9_blockd.h"
-#include "vp9/common/vp9_onyxc_int.h"
 
+#define MINQ 0
+#define MAXQ 255
+#define QINDEX_RANGE (MAXQ - MINQ + 1)
+#define QINDEX_BITS 8
+
 void vp9_init_quant_tables();
 
 int16_t vp9_dc_quant(int qindex, int delta);
 int16_t vp9_ac_quant(int qindex, int delta);
+
+int vp9_get_qindex(MACROBLOCKD *mb, int segment_id, int base_qindex);
 
 #endif  // VP9_COMMON_VP9_QUANT_COMMON_H_
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -181,22 +181,10 @@
   }
 }
 
-static int get_qindex(MACROBLOCKD *mb, int segment_id, int base_qindex) {
-  // Set the Q baseline allowing for any segment level adjustment
-  if (vp9_segfeature_active(mb, segment_id, SEG_LVL_ALT_Q)) {
-    const int data = vp9_get_segdata(mb, segment_id, SEG_LVL_ALT_Q);
-    return mb->mb_segment_abs_delta == SEGMENT_ABSDATA ?
-               data :  // Abs value
-               clamp(base_qindex + data, 0, MAXQ);  // Delta value
-  } else {
-    return base_qindex;
-  }
-}
-
 static void mb_init_dequantizer(VP9_COMMON *pc, MACROBLOCKD *xd) {
   int i;
   const int segment_id = xd->mode_info_context->mbmi.segment_id;
-  xd->q_index = get_qindex(xd, segment_id, pc->base_qindex);
+  xd->q_index = vp9_get_qindex(xd, segment_id, pc->base_qindex);
 
   xd->plane[0].dequant = pc->y_dequant[xd->q_index];
   for (i = 1; i < MAX_MB_PLANE; i++)
--- a/vp9/encoder/vp9_quantize.c
+++ b/vp9/encoder/vp9_quantize.c
@@ -318,27 +318,10 @@
 
 void vp9_mb_init_quantizer(VP9_COMP *cpi, MACROBLOCK *x) {
   int i;
-  int qindex;
   MACROBLOCKD *xd = &x->e_mbd;
   int zbin_extra;
   int segment_id = xd->mode_info_context->mbmi.segment_id;
-
-  // Select the baseline MB Q index allowing for any segment level change.
-  if (vp9_segfeature_active(xd, segment_id, SEG_LVL_ALT_Q)) {
-    if (xd->mb_segment_abs_delta == SEGMENT_ABSDATA) {
-      // Abs Value
-      qindex = vp9_get_segdata(xd, segment_id, SEG_LVL_ALT_Q);
-    } else {
-      // Delta Value
-      qindex = cpi->common.base_qindex +
-                 vp9_get_segdata(xd, segment_id, SEG_LVL_ALT_Q);
-
-      // Clamp to valid range
-      qindex = clamp(qindex, 0, MAXQ);
-    }
-  } else {
-    qindex = cpi->common.base_qindex;
-  }
+  const int qindex = vp9_get_qindex(xd, segment_id, cpi->common.base_qindex);
 
   // Y
   zbin_extra = (cpi->common.y_dequant[qindex][1] *