ref: b1921b2f089eaa2f74c2b0ac8e2b5ddcddd69e3c
parent: 76c12ab9c9d08a76f79e6b50af278ebf1e5f49ad
author: Deb Mukherjee <[email protected]>
date: Sat Mar 16 05:26:52 EDT 2013
Context-pred fix to not use top/left on edges This fix resolves some of the mismatch issues being seen recently. While this is the right thing to do when tiling is used for this experiment, it is not the underlying cause of the the mismatches. Something else is causing writing outside of the allowable frame area in the encoder leading to this mismatch. Change-Id: If52c6f67555aa18ab8762865384e323b47237277
--- a/vp9/common/vp9_reconintra.h
+++ b/vp9/common/vp9_reconintra.h
@@ -17,9 +17,10 @@
void vp9_recon_intra_mbuv(MACROBLOCKD *xd);
B_PREDICTION_MODE vp9_find_dominant_direction(uint8_t *ptr,
- int stride, int n);
+ int stride, int n,
+ int tx, int ty);
-B_PREDICTION_MODE vp9_find_bpred_context(BLOCKD *x);
+B_PREDICTION_MODE vp9_find_bpred_context(MACROBLOCKD *xd, BLOCKD *x);
#if CONFIG_COMP_INTERINTRA_PRED
void vp9_build_interintra_16x16_predictors_mb(MACROBLOCKD *xd,
--- a/vp9/common/vp9_reconintra4x4.c
+++ b/vp9/common/vp9_reconintra4x4.c
@@ -15,17 +15,17 @@
#include "vp9_rtcd.h"
#if CONFIG_NEWBINTRAMODES
-static int find_grad_measure(uint8_t *x, int stride, int n, int t,
+static int find_grad_measure(uint8_t *x, int stride, int n, int tx, int ty,
int dx, int dy) {
int i, j;
int count = 0, gsum = 0, gdiv;
/* TODO: Make this code more efficient by breaking up into two loops */
- for (i = -t; i < n; ++i)
- for (j = -t; j < n; ++j) {
+ for (i = -ty; i < n; ++i)
+ for (j = -tx; j < n; ++j) {
int g;
if (i >= 0 && j >= 0) continue;
if (i + dy >= 0 && j + dx >= 0) continue;
- if (i + dy < -t || i + dy >= n || j + dx < -t || j + dx >= n) continue;
+ if (i + dy < -ty || i + dy >= n || j + dx < -tx || j + dx >= n) continue;
g = abs(x[(i + dy) * stride + j + dx] - x[i * stride + j]);
gsum += g * g;
count++;
@@ -36,14 +36,15 @@
#if CONTEXT_PRED_REPLACEMENTS == 6
B_PREDICTION_MODE vp9_find_dominant_direction(uint8_t *ptr,
- int stride, int n) {
+ int stride, int n,
+ int tx, int ty) {
int g[8], i, imin, imax;
- g[1] = find_grad_measure(ptr, stride, n, 4, 2, 1);
- g[2] = find_grad_measure(ptr, stride, n, 4, 1, 1);
- g[3] = find_grad_measure(ptr, stride, n, 4, 1, 2);
- g[5] = find_grad_measure(ptr, stride, n, 4, -1, 2);
- g[6] = find_grad_measure(ptr, stride, n, 4, -1, 1);
- g[7] = find_grad_measure(ptr, stride, n, 4, -2, 1);
+ g[1] = find_grad_measure(ptr, stride, n, tx, ty, 2, 1);
+ g[2] = find_grad_measure(ptr, stride, n, tx, ty, 1, 1);
+ g[3] = find_grad_measure(ptr, stride, n, tx, ty, 1, 2);
+ g[5] = find_grad_measure(ptr, stride, n, tx, ty, -1, 2);
+ g[6] = find_grad_measure(ptr, stride, n, tx, ty, -1, 1);
+ g[7] = find_grad_measure(ptr, stride, n, tx, ty, -2, 1);
imin = 1;
for (i = 2; i < 8; i += 1 + (i == 3))
imin = (g[i] < g[imin] ? i : imin);
@@ -73,12 +74,13 @@
}
#elif CONTEXT_PRED_REPLACEMENTS == 4
B_PREDICTION_MODE vp9_find_dominant_direction(uint8_t *ptr,
- int stride, int n) {
+ int stride, int n,
+ int tx, int ty) {
int g[8], i, imin, imax;
- g[1] = find_grad_measure(ptr, stride, n, 4, 2, 1);
- g[3] = find_grad_measure(ptr, stride, n, 4, 1, 2);
- g[5] = find_grad_measure(ptr, stride, n, 4, -1, 2);
- g[7] = find_grad_measure(ptr, stride, n, 4, -2, 1);
+ g[1] = find_grad_measure(ptr, stride, n, tx, ty, 2, 1);
+ g[3] = find_grad_measure(ptr, stride, n, tx, ty, 1, 2);
+ g[5] = find_grad_measure(ptr, stride, n, tx, ty, -1, 2);
+ g[7] = find_grad_measure(ptr, stride, n, tx, ty, -2, 1);
imin = 1;
for (i = 3; i < 8; i+=2)
imin = (g[i] < g[imin] ? i : imin);
@@ -104,16 +106,17 @@
}
#elif CONTEXT_PRED_REPLACEMENTS == 0
B_PREDICTION_MODE vp9_find_dominant_direction(uint8_t *ptr,
- int stride, int n) {
+ int stride, int n,
+ int tx, int ty) {
int g[8], i, imin, imax;
- g[0] = find_grad_measure(ptr, stride, n, 4, 1, 0);
- g[1] = find_grad_measure(ptr, stride, n, 4, 2, 1);
- g[2] = find_grad_measure(ptr, stride, n, 4, 1, 1);
- g[3] = find_grad_measure(ptr, stride, n, 4, 1, 2);
- g[4] = find_grad_measure(ptr, stride, n, 4, 0, 1);
- g[5] = find_grad_measure(ptr, stride, n, 4, -1, 2);
- g[6] = find_grad_measure(ptr, stride, n, 4, -1, 1);
- g[7] = find_grad_measure(ptr, stride, n, 4, -2, 1);
+ g[0] = find_grad_measure(ptr, stride, n, tx, ty, 1, 0);
+ g[1] = find_grad_measure(ptr, stride, n, tx, ty, 2, 1);
+ g[2] = find_grad_measure(ptr, stride, n, tx, ty, 1, 1);
+ g[3] = find_grad_measure(ptr, stride, n, tx, ty, 1, 2);
+ g[4] = find_grad_measure(ptr, stride, n, tx, ty, 0, 1);
+ g[5] = find_grad_measure(ptr, stride, n, tx, ty, -1, 2);
+ g[6] = find_grad_measure(ptr, stride, n, tx, ty, -1, 1);
+ g[7] = find_grad_measure(ptr, stride, n, tx, ty, -2, 1);
imax = 0;
for (i = 1; i < 8; i++)
imax = (g[i] > g[imax] ? i : imax);
@@ -144,10 +147,17 @@
}
#endif
-B_PREDICTION_MODE vp9_find_bpred_context(BLOCKD *x) {
+B_PREDICTION_MODE vp9_find_bpred_context(MACROBLOCKD *xd, BLOCKD *x) {
+ const int block_idx = x - xd->block;
+ const int have_top = (block_idx >> 2) || xd->up_available;
+ const int have_left = (block_idx & 3) || xd->left_available;
uint8_t *ptr = *(x->base_dst) + x->dst;
int stride = x->dst_stride;
- return vp9_find_dominant_direction(ptr, stride, 4);
+ int tx = have_left ? 4 : 0;
+ int ty = have_top ? 4 : 0;
+ if (!have_left && !have_top)
+ return B_DC_PRED;
+ return vp9_find_dominant_direction(ptr, stride, 4, tx, ty);
}
#endif
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -361,7 +361,7 @@
int b_mode = xd->mode_info_context->bmi[i].as_mode.first;
#if CONFIG_NEWBINTRAMODES
xd->mode_info_context->bmi[i].as_mode.context = b->bmi.as_mode.context =
- vp9_find_bpred_context(b);
+ vp9_find_bpred_context(xd, b);
#endif
if (!xd->mode_info_context->mbmi.mb_skip_coeff)
eobtotal += vp9_decode_coefs_4x4(pbi, xd, bc, PLANE_TYPE_Y_WITH_DC, i);
--- a/vp9/encoder/vp9_encodeintra.c
+++ b/vp9/encoder/vp9_encodeintra.c
@@ -44,7 +44,7 @@
TX_TYPE tx_type;
#if CONFIG_NEWBINTRAMODES
- b->bmi.as_mode.context = vp9_find_bpred_context(b);
+ b->bmi.as_mode.context = vp9_find_bpred_context(&x->e_mbd, b);
#endif
vp9_intra4x4_predict(&x->e_mbd, b, b->bmi.as_mode.first, b->predictor);
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -1168,7 +1168,7 @@
DECLARE_ALIGNED_ARRAY(16, int16_t, best_dqcoeff, 16);
#if CONFIG_NEWBINTRAMODES
- b->bmi.as_mode.context = vp9_find_bpred_context(b);
+ b->bmi.as_mode.context = vp9_find_bpred_context(xd, b);
#endif
xd->mode_info_context->mbmi.txfm_size = TX_4X4;
for (mode = B_DC_PRED; mode < LEFT4X4; mode++) {
@@ -1279,7 +1279,7 @@
bmode_costs = mb->bmode_costs[A][L];
}
#if CONFIG_NEWBINTRAMODES
- mic->bmi[i].as_mode.context = vp9_find_bpred_context(xd->block + i);
+ mic->bmi[i].as_mode.context = vp9_find_bpred_context(xd, xd->block + i);
#endif
total_rd += rd_pick_intra4x4block(