shithub: dav1d

Download patch

ref: 36f6d83c282b849f8d1b6588f636a94c2bbfc2b7
parent: a495179a8a6d2e6f49773c9a2566b23236fd55a2
author: Ronald S. Bultje <rsbultje@gmail.com>
date: Fri Mar 20 11:15:43 EDT 2020

Merge fix_mv{_int,}_precision() into get_gmv_2d()

--- a/src/decode.c
+++ b/src/decode.c
@@ -1579,7 +1579,6 @@
                     f->frame_hdr->gmv[b->ref[idx]].type == DAV1D_WM_TYPE_TRANSLATION; \
                 b->mv[idx] = get_gmv_2d(&f->frame_hdr->gmv[b->ref[idx]], \
                                         t->bx, t->by, bw4, bh4, f->frame_hdr); \
-                fix_mv_precision(f->frame_hdr, &b->mv[idx]); \
                 break; \
             case NEWMV: \
                 b->mv[idx] = mvstack[b->drl_idx].mv.mv[idx]; \
@@ -1713,7 +1712,6 @@
                     b->inter_mode = GLOBALMV;
                     b->mv[0] = get_gmv_2d(&f->frame_hdr->gmv[b->ref[0]],
                                           t->bx, t->by, bw4, bh4, f->frame_hdr);
-                    fix_mv_precision(f->frame_hdr, &b->mv[0]);
                     has_subpel_filter = imin(bw4, bh4) == 1 ||
                         f->frame_hdr->gmv[b->ref[0]].type == DAV1D_WM_TYPE_TRANSLATION;
                 } else {
--- a/src/env.h
+++ b/src/env.h
@@ -460,6 +460,22 @@
     }
 }
 
+static inline void fix_int_mv_precision(mv *const mv) {
+    mv->x = (mv->x - (mv->x >> 15) + 3) & ~7U;
+    mv->y = (mv->y - (mv->y >> 15) + 3) & ~7U;
+}
+
+static inline void fix_mv_precision(const Dav1dFrameHeader *const hdr,
+                                    mv *const mv)
+{
+    if (hdr->force_integer_mv) {
+        fix_int_mv_precision(mv);
+    } else if (!hdr->hp) {
+        mv->x = (mv->x - (mv->x >> 15)) & ~1U;
+        mv->y = (mv->y - (mv->y >> 15)) & ~1U;
+    }
+}
+
 static inline mv get_gmv_2d(const Dav1dWarpedMotionParams *const gmv,
                             const int bx4, const int by4,
                             const int bw4, const int bh4,
@@ -480,16 +496,23 @@
                        gmv->matrix[4] * x + gmv->matrix[1];
         const int shift = 16 - (3 - !hdr->hp);
         const int round = (1 << shift) >> 1;
-        return (mv) {
+        mv res = (mv) {
             .y = apply_sign(((abs(yc) + round) >> shift) << !hdr->hp, yc),
             .x = apply_sign(((abs(xc) + round) >> shift) << !hdr->hp, xc),
         };
+        if (hdr->force_integer_mv)
+            fix_int_mv_precision(&res);
+        return res;
     }
-    case DAV1D_WM_TYPE_TRANSLATION:
-        return (mv) {
+    case DAV1D_WM_TYPE_TRANSLATION: {
+        mv res = (mv) {
             .y = gmv->matrix[0] >> 13,
             .x = gmv->matrix[1] >> 13,
         };
+        if (hdr->force_integer_mv)
+            fix_int_mv_precision(&res);
+        return res;
+    }
     case DAV1D_WM_TYPE_IDENTITY:
         return (mv) { .x = 0, .y = 0 };
     }
--- a/src/refmvs.c
+++ b/src/refmvs.c
@@ -362,8 +362,6 @@
     if (ref.ref[0] > 0) {
         tgmv[0] = get_gmv_2d(&rf->frm_hdr->gmv[ref.ref[0] - 1],
                              bx4, by4, bw4, bh4, rf->frm_hdr);
-        if (rf->frm_hdr->force_integer_mv)
-            fix_int_mv_precision(&tgmv[0]);
         gmv[0] = rf->frm_hdr->gmv[ref.ref[0] - 1].type > DAV1D_WM_TYPE_TRANSLATION ?
                  tgmv[0] : (mv) { .n = INVALID_MV };
     } else {
@@ -373,8 +371,6 @@
     if (ref.ref[1] > 0) {
         tgmv[1] = get_gmv_2d(&rf->frm_hdr->gmv[ref.ref[1] - 1],
                              bx4, by4, bw4, bh4, rf->frm_hdr);
-        if (rf->frm_hdr->force_integer_mv)
-            fix_int_mv_precision(&tgmv[1]);
         gmv[1] = rf->frm_hdr->gmv[ref.ref[1] - 1].type > DAV1D_WM_TYPE_TRANSLATION ?
                  tgmv[1] : (mv) { .n = INVALID_MV };
     }
--- a/src/refmvs.h
+++ b/src/refmvs.h
@@ -230,20 +230,4 @@
     } while (--bh4);
 }
 
-static inline void fix_int_mv_precision(mv *const mv) {
-    mv->x = (mv->x - (mv->x >> 15) + 3) & ~7U;
-    mv->y = (mv->y - (mv->y >> 15) + 3) & ~7U;
-}
-
-static inline void fix_mv_precision(const Dav1dFrameHeader *const hdr,
-                                    mv *const mv)
-{
-    if (hdr->force_integer_mv) {
-        fix_int_mv_precision(mv);
-    } else if (!hdr->hp) {
-        mv->x = (mv->x - (mv->x >> 15)) & ~1U;
-        mv->y = (mv->y - (mv->y >> 15)) & ~1U;
-    }
-}
-
 #endif /* DAV1D_SRC_REF_MVS_H */