ref: 4038632fab26f3f1dbed423e9beb3739a520d69e
parent: 0f9521f0a82ae5eb361f2a7467c217daf3051a50
parent: ca28740570a9becaacead42aaeb4e1e126f17955
author: Jerome Jiang <jianj@google.com>
date: Mon Mar 19 15:00:55 EDT 2018
Merge "VP8: Fix out of range index for mvcost."
--- a/vp8/encoder/mcomp.c
+++ b/vp8/encoder/mcomp.c
@@ -34,10 +34,11 @@
* 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],
@@ -44,9 +45,11 @@
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;
}