aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerome Jiang <jianj@google.com>2018-04-09 18:41:57 -0700
committerandroid-build-merger <android-build-merger@google.com>2018-04-09 18:41:57 -0700
commit02d851394c840cf57ca3bc19c77c1a2643408a6c (patch)
treecadf3839f1d1d689f128cbf081799ff49412b2e5
parent84c9f411011523c52bd650ac8d48f00f5129a3a2 (diff)
parent785cf816a6305ab771d05a142197f461e29bdae6 (diff)
downloadlibvpx-02d851394c840cf57ca3bc19c77c1a2643408a6c.tar.gz
Merge "DO NOT MERGE | libvpx: cherry pick fix to OOB of mv_cost index." into oc-dev
am: 785cf816a6 Change-Id: Ie16f26acb5b6b8ee7d1b541a576b0ad2caeae835
-rw-r--r--libvpx/vp8/encoder/mcomp.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/libvpx/vp8/encoder/mcomp.c b/libvpx/vp8/encoder/mcomp.c
index 970120f3b..b4a49a3b1 100644
--- a/libvpx/vp8/encoder/mcomp.c
+++ b/libvpx/vp8/encoder/mcomp.c
@@ -34,19 +34,22 @@ int vp8_mv_bit_cost(int_mv *mv, int_mv *ref, int *mvcost[2], int Weight) {
* NEAREST for subsequent blocks. The "Weight" parameter allows, to a
* limited extent, for some account to be taken of these factors.
*/
- return ((mvcost[0][(mv->as_mv.row - ref->as_mv.row) >> 1] +
- mvcost[1][(mv->as_mv.col - ref->as_mv.col) >> 1]) *
- Weight) >>
- 7;
+ const int mv_idx_row =
+ clamp((mv->as_mv.row - ref->as_mv.row) >> 1, 0, MVvals);
+ const int mv_idx_col =
+ clamp((mv->as_mv.col - ref->as_mv.col) >> 1, 0, MVvals);
+ return ((mvcost[0][mv_idx_row] + mvcost[1][mv_idx_col]) * Weight) >> 7;
}
static int mv_err_cost(int_mv *mv, int_mv *ref, int *mvcost[2],
int error_per_bit) {
/* Ignore mv costing if mvcost is NULL */
if (mvcost) {
- return ((mvcost[0][(mv->as_mv.row - ref->as_mv.row) >> 1] +
- mvcost[1][(mv->as_mv.col - ref->as_mv.col) >> 1]) *
- error_per_bit +
+ const int mv_idx_row =
+ clamp((mv->as_mv.row - ref->as_mv.row) >> 1, 0, MVvals);
+ const int mv_idx_col =
+ clamp((mv->as_mv.col - ref->as_mv.col) >> 1, 0, MVvals);
+ return ((mvcost[0][mv_idx_row] + mvcost[1][mv_idx_col]) * error_per_bit +
128) >>
8;
}