shithub: libvpx

Download patch

ref: 40fec9b5883f04b6f61a8bc187abf6d9be871211
parent: b6a3062d8181c48b8056458f12950bb6fd08628f
parent: c43906e2e99559325b5b662724ce3b44840adc6b
author: Dmitry Kovalev <dkovalev@google.com>
date: Thu Feb 28 08:46:43 EST 2013

Merge "Dequantization code cleanup." into experimental

--- a/vp9/decoder/vp9_dequantize.c
+++ b/vp9/decoder/vp9_dequantize.c
@@ -43,14 +43,11 @@
   }
 }
 
-void vp9_dequantize_b_c(BLOCKD *d) {
+void vp9_dequantize_b_c(BLOCKD *b) {
   int i;
-  int16_t *dq = d->dqcoeff;
-  const int16_t *q = d->qcoeff;
-  const int16_t *dqc = d->dequant;
 
   for (i = 0; i < 16; i++)
-    dq[i] = q[i] * dqc[i];
+    b->dqcoeff[i] = b->qcoeff[i] * b->dequant[i];
 }
 
 
@@ -58,17 +55,15 @@
                                const int16_t *dq,
                                uint8_t *pred, uint8_t *dest,
                                int pitch, int stride, int eob) {
-  int16_t output[16];
-  int16_t *diff_ptr = output;
   int i;
+  int16_t output[16];
 
   for (i = 0; i < 16; i++)
-    input[i] = dq[i] * input[i];
+    input[i] *= dq[i];
 
   vp9_short_iht4x4(input, output, 4, tx_type);
   vpx_memset(input, 0, 32);
-
-  add_residual(diff_ptr, pred, pitch, dest, stride, 4, 4);
+  add_residual(output, pred, pitch, dest, stride, 4, 4);
 }
 
 void vp9_ht_dequant_idct_add_8x8_c(TX_TYPE tx_type, int16_t *input,
@@ -76,12 +71,13 @@
                                    uint8_t *pred, uint8_t *dest,
                                    int pitch, int stride, int eob) {
   int16_t output[64];
-  int16_t *diff_ptr = output;
-  int i;
+
   if (eob == 0) {
-    /* All 0 DCT coefficient */
+    // All 0 DCT coefficients
     vp9_copy_mem8x8(pred, pitch, dest, stride);
   } else if (eob > 0) {
+    int i;
+
     input[0] *= dq[0];
     for (i = 1; i < 64; i++)
       input[i] *= dq[1];
@@ -88,26 +84,22 @@
 
     vp9_short_iht8x8(input, output, 8, tx_type);
     vpx_memset(input, 0, 128);
-
-    add_residual(diff_ptr, pred, pitch, dest, stride, 8, 8);
+    add_residual(output, pred, pitch, dest, stride, 8, 8);
   }
 }
 
 void vp9_dequant_idct_add_c(int16_t *input, const int16_t *dq, uint8_t *pred,
                             uint8_t *dest, int pitch, int stride) {
-  int16_t output[16];
-  int16_t *diff_ptr = output;
   int i;
+  int16_t output[16];
 
   for (i = 0; i < 16; i++)
     input[i] *= dq[i];
 
-  /* the idct halves ( >> 1) the pitch */
+  // the idct halves ( >> 1) the pitch
   vp9_short_idct4x4llm_c(input, output, 4 << 1);
-
   vpx_memset(input, 0, 32);
-
-  add_residual(diff_ptr, pred, pitch, dest, stride, 4, 4);
+  add_residual(output, pred, pitch, dest, stride, 4, 4);
 }
 
 void vp9_dequant_dc_idct_add_c(int16_t *input, const int16_t *dq, uint8_t *pred,
@@ -114,7 +106,6 @@
                                uint8_t *dest, int pitch, int stride, int dc) {
   int i;
   int16_t output[16];
-  int16_t *diff_ptr = output;
 
   input[0] = dc;
 
@@ -121,29 +112,24 @@
   for (i = 1; i < 16; i++)
     input[i] *= dq[i];
 
-  /* the idct halves ( >> 1) the pitch */
+  // the idct halves ( >> 1) the pitch
   vp9_short_idct4x4llm_c(input, output, 4 << 1);
-
   vpx_memset(input, 0, 32);
-
-  add_residual(diff_ptr, pred, pitch, dest, stride, 4, 4);
+  add_residual(output, pred, pitch, dest, stride, 4, 4);
 }
 
 void vp9_dequant_idct_add_lossless_c(int16_t *input, const int16_t *dq,
                                      uint8_t *pred, uint8_t *dest,
                                      int pitch, int stride) {
-  int16_t output[16];
-  int16_t *diff_ptr = output;
   int i;
+  int16_t output[16];
 
   for (i = 0; i < 16; i++)
     input[i] *= dq[i];
 
   vp9_short_inv_walsh4x4_x8_c(input, output, 4 << 1);
-
   vpx_memset(input, 0, 32);
-
-  add_residual(diff_ptr, pred, pitch, dest, stride, 4, 4);
+  add_residual(output, pred, pitch, dest, stride, 4, 4);
 }
 
 void vp9_dequant_dc_idct_add_lossless_c(int16_t *input, const int16_t *dq,
@@ -152,7 +138,6 @@
                                         int pitch, int stride, int dc) {
   int i;
   int16_t output[16];
-  int16_t *diff_ptr = output;
 
   input[0] = dc;
 
@@ -161,8 +146,7 @@
 
   vp9_short_inv_walsh4x4_x8_c(input, output, 4 << 1);
   vpx_memset(input, 0, 32);
-
-  add_residual(diff_ptr, pred, pitch, dest, stride, 4, 4);
+  add_residual(output, pred, pitch, dest, stride, 4, 4);
 }
 
 void vp9_dequant_idct_add_8x8_c(int16_t *input, const int16_t *dq,
@@ -169,42 +153,40 @@
                                 uint8_t *pred, uint8_t *dest, int pitch,
                                 int stride, int eob) {
   int16_t output[64];
-  int16_t *diff_ptr = output;
-  int i;
 
-  /* If dc is 1, then input[0] is the reconstructed value, do not need
-   * dequantization. Also, when dc is 1, dc is counted in eobs, namely eobs >=1.
-   */
+
+  // If dc is 1, then input[0] is the reconstructed value, do not need
+  // dequantization. Also, when dc is 1, dc is counted in eobs, namely eobs >=1.
   input[0] *= dq[0];
 
-  /* The calculation can be simplified if there are not many non-zero dct
-   * coefficients. Use eobs to decide what to do.
-   * TODO(yunqingwang): "eobs = 1" case is also handled in vp9_short_idct8x8_c.
-   * Combine that with code here.
-   */
+  // The calculation can be simplified if there are not many non-zero dct
+  // coefficients. Use eobs to decide what to do.
+  // TODO(yunqingwang): "eobs = 1" case is also handled in vp9_short_idct8x8_c.
+  // Combine that with code here.
   if (eob == 0) {
-    /* All 0 DCT coefficient */
+    // All 0 DCT coefficients
     vp9_copy_mem8x8(pred, pitch, dest, stride);
   } else if (eob == 1) {
-    /* DC only DCT coefficient. */
+    // DC only DCT coefficient
     int16_t in = input[0];
     int16_t out;
-    /* Note: the idct1 will need to be modified accordingly whenever
-     * vp9_short_idct8x8_c() is modified. */
+
+     // Note: the idct1 will need to be modified accordingly whenever
+     // vp9_short_idct8x8_c() is modified.
     vp9_short_idct1_8x8_c(&in, &out);
     input[0] = 0;
 
     add_constant_residual(out, pred, pitch, dest, stride, 8, 8);
   } else if (eob <= 10) {
-    input[1] = input[1] * dq[1];
-    input[2] = input[2] * dq[1];
-    input[3] = input[3] * dq[1];
-    input[8] = input[8] * dq[1];
-    input[9] = input[9] * dq[1];
-    input[10] = input[10] * dq[1];
-    input[16] = input[16] * dq[1];
-    input[17] = input[17] * dq[1];
-    input[24] = input[24] * dq[1];
+    input[1] *= dq[1];
+    input[2] *= dq[1];
+    input[3] *= dq[1];
+    input[8] *= dq[1];
+    input[9] *= dq[1];
+    input[10] *= dq[1];
+    input[16] *= dq[1];
+    input[17] *= dq[1];
+    input[24] *= dq[1];
 
     vp9_short_idct10_8x8_c(input, output, 16);
 
@@ -213,19 +195,18 @@
     input[16] = input[17] = 0;
     input[24] = 0;
 
-    add_residual(diff_ptr, pred, pitch, dest, stride, 8, 8);
+    add_residual(output, pred, pitch, dest, stride, 8, 8);
   } else {
+    int i;
+
     // recover quantizer for 4 4x4 blocks
     for (i = 1; i < 64; i++)
       input[i] *= dq[1];
 
     // the idct halves ( >> 1) the pitch
-    vp9_short_idct8x8_c(input, output, 16);
-
+    vp9_short_idct8x8_c(input, output, 8 << 1);
     vpx_memset(input, 0, 128);
-
-    add_residual(diff_ptr, pred, pitch, dest, stride, 8, 8);
-
+    add_residual(output, pred, pitch, dest, stride, 8, 8);
   }
 }
 
@@ -234,12 +215,13 @@
                                      uint8_t *dest, int pitch, int stride,
                                      int eob) {
   int16_t output[256];
-  int16_t *diff_ptr = output;
-  int i;
+
   if (eob == 0) {
-    /* All 0 DCT coefficient */
+    // All 0 DCT coefficients
     vp9_copy_mem16x16(pred, pitch, dest, stride);
   } else if (eob > 0) {
+    int i;
+
     input[0] *= dq[0];
 
     // recover quantizer for 4 4x4 blocks
@@ -254,7 +236,7 @@
 
     vpx_memset(input, 0, 512);
 
-    add_residual(diff_ptr, pred, pitch, dest, stride, 16, 16);
+    add_residual(output, pred, pitch, dest, stride, 16, 16);
   }
 }
 
@@ -262,8 +244,6 @@
                                   uint8_t *pred, uint8_t *dest, int pitch,
                                   int stride, int eob) {
   int16_t output[256];
-  int16_t *diff_ptr = output;
-  int i;
 
   /* The calculation can be simplified if there are not many non-zero dct
    * coefficients. Use eobs to separate different cases. */
@@ -281,17 +261,18 @@
 
     add_constant_residual(out, pred, pitch, dest, stride, 16, 16);
   } else if (eob <= 10) {
-    input[0]= input[0] * dq[0];
-    input[1] = input[1] * dq[1];
-    input[2] = input[2] * dq[1];
-    input[3] = input[3] * dq[1];
-    input[16] = input[16] * dq[1];
-    input[17] = input[17] * dq[1];
-    input[18] = input[18] * dq[1];
-    input[32] = input[32] * dq[1];
-    input[33] = input[33] * dq[1];
-    input[48] = input[48] * dq[1];
+    input[0] *= dq[0];
 
+    input[1] *= dq[1];
+    input[2] *= dq[1];
+    input[3] *= dq[1];
+    input[16] *= dq[1];
+    input[17] *= dq[1];
+    input[18] *= dq[1];
+    input[32] *= dq[1];
+    input[33] *= dq[1];
+    input[48] *= dq[1];
+
     // the idct halves ( >> 1) the pitch
     vp9_short_idct10_16x16_c(input, output, 32);
 
@@ -300,8 +281,10 @@
     input[32] = input[33] = 0;
     input[48] = 0;
 
-    add_residual(diff_ptr, pred, pitch, dest, stride, 16, 16);
+    add_residual(output, pred, pitch, dest, stride, 16, 16);
   } else {
+    int i;
+
     input[0] *= dq[0];
 
     // recover quantizer for 4 4x4 blocks
@@ -309,11 +292,11 @@
       input[i] *= dq[1];
 
     // the idct halves ( >> 1) the pitch
-    vp9_short_idct16x16_c(input, output, 32);
+    vp9_short_idct16x16_c(input, output, 16 << 1);
 
     vpx_memset(input, 0, 512);
 
-    add_residual(diff_ptr, pred, pitch, dest, stride, 16, 16);
+    add_residual(output, pred, pitch, dest, stride, 16, 16);
   }
 }
 
@@ -321,7 +304,6 @@
                                   uint8_t *pred, uint8_t *dest, int pitch,
                                   int stride, int eob) {
   int16_t output[1024];
-  int i;
 
   if (eob) {
     input[0] = input[0] * dq[0] / 2;
@@ -330,6 +312,7 @@
       add_constant_residual(output[0], pred, pitch, dest, stride, 32, 32);
       input[0] = 0;
     } else {
+      int i;
       for (i = 1; i < 1024; i++)
         input[i] = input[i] * dq[1] / 2;
       vp9_short_idct32x32_c(input, output, 64);