aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2018-04-10 00:01:20 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-04-10 00:01:20 +0000
commit425cb3296efea0a63c42d8642df716b9f71d9ab8 (patch)
tree2ac34bc2823d3b18dc101989d929bbefabf8cd05
parent598df4654e3c11314bbea0169570f62b691e2dc4 (diff)
parentb6df494e5d4556f6dcb1d554059ed683837cc2ed (diff)
downloadlibvpx-425cb3296efea0a63c42d8642df716b9f71d9ab8.tar.gz
Merge changes from topic "am-3fd89deb-25c4-471e-8f53-fa39f55c6d0c" into cw-f-dev
* changes: [automerger] DO NOT MERGE | libvpx: cherry pick fix to OOB of mv_cost index. am: e18a13c926 am: 4c31a8fb31 am: b0d8cf041a [automerger] DO NOT MERGE | libvpx: cherry pick fix to OOB of mv_cost index. am: e18a13c926 am: 4c31a8fb31 [automerger] DO NOT MERGE | libvpx: cherry pick fix to OOB of mv_cost index. am: e18a13c926 DO NOT MERGE | libvpx: cherry pick fix to OOB of mv_cost index.
-rw-r--r--libvpx/vp8/encoder/mcomp.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/libvpx/vp8/encoder/mcomp.c b/libvpx/vp8/encoder/mcomp.c
index 768c764ce..3d1b4df72 100644
--- a/libvpx/vp8/encoder/mcomp.c
+++ b/libvpx/vp8/encoder/mcomp.c
@@ -27,26 +27,34 @@ static int mv_ref_ct [31] [4] [2];
static int mv_mode_cts [4] [2];
#endif
-int vp8_mv_bit_cost(int_mv *mv, int_mv *ref, int *mvcost[2], int Weight)
-{
- /* MV costing is based on the distribution of vectors in the previous
- * frame and as such will tend to over state the cost of vectors. In
- * addition coding a new vector can have a knock on effect on the cost
- * of subsequent vectors and the quality of prediction from NEAR and
- * 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;
+int vp8_mv_bit_cost(int_mv *mv, int_mv *ref, int *mvcost[2], int Weight) {
+ /* MV costing is based on the distribution of vectors in the previous
+ * frame and as such will tend to over state the cost of vectors. In
+ * addition coding a new vector can have a knock on effect on the cost
+ * of subsequent vectors and the quality of prediction from NEAR and
+ * NEAREST for subsequent blocks. The "Weight" parameter allows, to a
+ * limited extent, for some account to be taken of these factors.
+ */
+ 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 + 128) >> 8;
- return 0;
+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) {
+ 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;
+ }
+ return 0;
}
static int mvsad_err_cost(int_mv *mv, int_mv *ref, int *mvsadcost[2], int error_per_bit)