Assign offsets correctly to compute warped motion

Offsets for the least-squares for affine motion computation
are now set at the top left corner of the current block.

Improves stability and performance a little.

Change-Id: I68ca7e74c6102502daa8ca3373af2b2dd59400c3
diff --git a/av1/common/warped_motion.c b/av1/common/warped_motion.c
index cf93996..3183352 100644
--- a/av1/common/warped_motion.c
+++ b/av1/common/warped_motion.c
@@ -1218,7 +1218,7 @@
 #define IDET_PREC_BITS 48
 #define IDET_WARPEDMODEL_DIFF_BITS (IDET_PREC_BITS - WARPEDMODEL_PREC_BITS)
 static int find_affine_int(const int np, int *pts1, int *pts2,
-                           WarpedMotionParams *wm) {
+                           WarpedMotionParams *wm, int mi_row, int mi_col) {
   int64_t A[3][3] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };
   int64_t C[3][3] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };
   int64_t Bx[3] = { 0, 0, 0 };
@@ -1227,7 +1227,7 @@
   int64_t Det, iDet;
   int i, off;
   // Offsets to make the values in the arrays smaller
-  const int ux = pts1[0], uy = pts1[1];
+  const int ux = mi_col * MI_SIZE * 8, uy = mi_row * MI_SIZE * 8;
   // Let source points (xi, yi) map to destimation points (xi', yi'),
   //     for i = 0, 1, 2, .... n-1
   // Then if  P = [x0, y0, 1,
@@ -1326,10 +1326,12 @@
 }
 
 int find_projection(const int np, int *pts1, int *pts2,
-                    WarpedMotionParams *wm_params) {
+                    WarpedMotionParams *wm_params, int mi_row, int mi_col) {
   int result = 1;
   switch (wm_params->wmtype) {
-    case AFFINE: result = find_affine_int(np, pts1, pts2, wm_params); break;
+    case AFFINE:
+      result = find_affine_int(np, pts1, pts2, wm_params, mi_row, mi_col);
+      break;
     default: assert(0 && "Invalid warped motion type!"); return 1;
   }
   if (result == 0) {
diff --git a/av1/common/warped_motion.h b/av1/common/warped_motion.h
index f113760..cc3d019 100644
--- a/av1/common/warped_motion.h
+++ b/av1/common/warped_motion.h
@@ -87,5 +87,5 @@
                     int subsampling_y, int x_scale, int y_scale, int ref_frm);
 
 int find_projection(const int np, int *pts1, int *pts2,
-                    WarpedMotionParams *wm_params);
+                    WarpedMotionParams *wm_params, int mi_row, int mi_col);
 #endif  // AV1_COMMON_WARPED_MOTION_H_
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index dff0d5c..0b97099 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -1979,7 +1979,7 @@
     if (mbmi->motion_mode == WARPED_CAUSAL) {
       mbmi->wm_params[0].wmtype = DEFAULT_WMTYPE;
       find_projection(mbmi->num_proj_ref[0], pts, pts_inref,
-                      &mbmi->wm_params[0]);
+                      &mbmi->wm_params[0], mi_row, mi_col);
     }
 #endif  // CONFIG_WARPED_MOTION
 #if CONFIG_SUPERTX
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 210d72f..adcfc52 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -8771,7 +8771,7 @@
 #endif  // CONFIG_DUAL_FILTER
 
       if (find_projection(mbmi->num_proj_ref[0], pts, pts_inref,
-                          &mbmi->wm_params[0]) == 0) {
+                          &mbmi->wm_params[0], mi_row, mi_col) == 0) {
         int plane;
 #if CONFIG_AOM_HIGHBITDEPTH
         int use_hbd = xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH;