summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Wilkins <paulwilkins@google.com>2011-11-02 14:48:17 +0000
committerOn2 (Google) Code Review <on2-gerrit@google.com>2011-11-02 14:48:17 +0000
commitab9a4ce06549203a909a94c26c95c34809ac54d1 (patch)
treed10edfbf960d51e17b8d0a1f39012439a1673f66
parent2b450a460fa847c7460f51ab38ecb9ab10f18218 (diff)
parentc8ef79d22eed3e9c8d67807df5b891a5e83dba17 (diff)
downloadlibvpx-ab9a4ce06549203a909a94c26c95c34809ac54d1.tar
libvpx-ab9a4ce06549203a909a94c26c95c34809ac54d1.tar.gz
libvpx-ab9a4ce06549203a909a94c26c95c34809ac54d1.tar.bz2
libvpx-ab9a4ce06549203a909a94c26c95c34809ac54d1.zip
Merge "Change to prevent encoding of effect-less 2nd order coefficients" into experimental
-rw-r--r--vp8/encoder/encodemb.c91
1 files changed, 73 insertions, 18 deletions
diff --git a/vp8/encoder/encodemb.c b/vp8/encoder/encodemb.c
index c0e0bc4fd..73134425c 100644
--- a/vp8/encoder/encodemb.c
+++ b/vp8/encoder/encodemb.c
@@ -606,6 +606,73 @@ static void optimize_b(MACROBLOCK *mb, int ib, int type,
*a = *l = (d->eob != !type);
}
+static void check_reset_2nd_coeffs(MACROBLOCKD *x)
+{
+ int sum=0;
+ int i;
+ BLOCKD *bd = &x->block[24];
+ int eob_pos = (bd->eob<16)? vp8_default_zig_zag1d[bd->eob]:16;
+
+ for(i=0;i<bd->eob;i++)
+ {
+ int coef = bd->dqcoeff[vp8_default_zig_zag1d[i]];
+ sum+= (coef>=0)?coef:-coef;
+ }
+ /**************************************************************************
+ our inverse hadamard transform effectively is weighted sum of all 16 inputs
+ with weight either 1 or -1. It has a last stage scaling of (sum+3)>>3. And
+ dc only idct is (dc+4)>>3. So if all the sums are between -35 and 29, the
+ output after inverse wht and idct will be all zero. A sum of absolute value
+ smaller than 35 guarantees all 16 different (+1/-1) weighted sums in wht
+ fall between -35 and +35.
+ **************************************************************************/
+ if(sum < 35)
+ {
+ vpx_memset(bd->qcoeff,0,eob_pos*2);
+ vpx_memset(bd->dqcoeff,0,eob_pos*2);
+ bd->eob = 0;
+ }
+}
+static void check_reset_8x8_2nd_coeffs(MACROBLOCKD *x)
+{
+ int sum=0;
+ int i;
+ BLOCKD *bd = &x->block[24];
+ int coef;
+
+ coef = bd->dqcoeff[0];
+ sum+= (coef>=0)?coef:-coef;
+ coef = bd->dqcoeff[1];
+ sum+= (coef>=0)?coef:-coef;
+ coef = bd->dqcoeff[4];
+ sum+= (coef>=0)?coef:-coef;
+ coef = bd->dqcoeff[8];
+ sum+= (coef>=0)?coef:-coef;
+
+ /**************************************************************************
+ our inverse haar transform effectively is weighted sum of all 4 inputs
+ with weight either 1 or -1. It has a last stage scaling of (sum)>>2. And
+ dc only idct8x8 is effectively (dc+8)>>4. So if all the sums are between
+ -31 and 31, outputs after inverse txfm be all 0s. A sum of absolute value
+ smaller than 32 guarantees all 4 different (+1/-1) weighted sums in wht
+ fall between -31 and +31.
+ **************************************************************************/
+ if(sum < 32)
+ {
+ bd->qcoeff[0] = 0;
+ bd->dqcoeff[0] = 0;
+ bd->qcoeff[1] = 0;
+ bd->dqcoeff[1] = 0;
+ bd->qcoeff[4] = 0;
+ bd->dqcoeff[4] = 0;
+ bd->qcoeff[8] = 0;
+ bd->dqcoeff[8] = 0;
+ bd->eob = 0;
+ }
+}
+
+
+
static void optimize_mb(MACROBLOCK *x, const VP8_ENCODER_RTCD *rtcd)
{
int b;
@@ -642,6 +709,7 @@ static void optimize_mb(MACROBLOCK *x, const VP8_ENCODER_RTCD *rtcd)
b=24;
optimize_b(x, b, PLANE_TYPE_Y2,
ta + vp8_block2above[b], tl + vp8_block2left[b], rtcd);
+ check_reset_2nd_coeffs(&x->e_mbd);
}
}
@@ -684,6 +752,7 @@ void vp8_optimize_mby(MACROBLOCK *x, const VP8_ENCODER_RTCD *rtcd)
b=24;
optimize_b(x, b, PLANE_TYPE_Y2,
ta + vp8_block2above[b], tl + vp8_block2left[b], rtcd);
+ check_reset_2nd_coeffs(&x->e_mbd);
}
}
@@ -1040,16 +1109,8 @@ void optimize_mb_8x8(MACROBLOCK *x, const VP8_ENCODER_RTCD *rtcd)
*(tl + vp8_block2left[b]);
}
-
-
- /*
- if (has_2nd_order)
- {
- vp8_setup_temp_context(&t, x->e_mbd.above_context[Y2CONTEXT],
- x->e_mbd.left_context[Y2CONTEXT], 1);
- optimize_b(x, 24, 1, t.a, t.l, rtcd);
- }
- */
+ //8x8 always have 2nd roder haar block
+ check_reset_8x8_2nd_coeffs(&x->e_mbd);
}
void vp8_optimize_mby_8x8(MACROBLOCK *x, const VP8_ENCODER_RTCD *rtcd)
@@ -1114,14 +1175,8 @@ void vp8_optimize_mby_8x8(MACROBLOCK *x, const VP8_ENCODER_RTCD *rtcd)
}
- /*
- if (has_2nd_order)
- {
- vp8_setup_temp_context(&t, x->e_mbd.above_context[Y2CONTEXT],
- x->e_mbd.left_context[Y2CONTEXT], 1);
- optimize_b(x, 24, 1, t.a, t.l, rtcd);
- }
- */
+ //8x8 always have 2nd roder haar block
+ check_reset_8x8_2nd_coeffs(&x->e_mbd);
}
void vp8_optimize_mbuv_8x8(MACROBLOCK *x, const VP8_ENCODER_RTCD *rtcd)