Support affine/homography models for global motion

With this patch affine or homography models can be enabled
by simply changing the value of the GLOBAL_TRANS_TYPES
macro in common/mv.h to 4 and 5 respectively. Currently
it is left at supporting only rotzoom. There is a small
gain with enabling affine.

Also refactors costing to change based on the model type.

Change-Id: I46c1759de06c42c176c64ec21307ff347ddcc259
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index e4873ab..47ca2fc 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -4896,28 +4896,32 @@
     for (frame = LAST_FRAME; frame <= ALTREF_FRAME; ++frame) {
       ref_buf = get_ref_frame_buffer(cpi, frame);
       if (ref_buf) {
+        TransformationType model;
         aom_clear_system_state();
-        if (compute_global_motion_feature_based(GLOBAL_TRANS_TYPES - 1,
-                                                cpi->Source, ref_buf,
+        for (model = ROTZOOM; model < GLOBAL_TRANS_TYPES; ++model) {
+          if (compute_global_motion_feature_based(model, cpi->Source, ref_buf,
 #if CONFIG_AOM_HIGHBITDEPTH
-                                                cpi->common.bit_depth,
+                                                  cpi->common.bit_depth,
 #endif  // CONFIG_AOM_HIGHBITDEPTH
-                                                params)) {
-          convert_model_to_params(params, &cm->global_motion[frame]);
-          if (cm->global_motion[frame].wmtype != IDENTITY) {
-            erroradvantage = refine_integerized_param(
-                &cm->global_motion[frame], cm->global_motion[frame].wmtype,
+                                                  params)) {
+            convert_model_to_params(params, &cm->global_motion[frame]);
+            if (cm->global_motion[frame].wmtype != IDENTITY) {
+              erroradvantage = refine_integerized_param(
+                  &cm->global_motion[frame], cm->global_motion[frame].wmtype,
 #if CONFIG_AOM_HIGHBITDEPTH
-                xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH, xd->bd,
+                  xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH, xd->bd,
 #endif  // CONFIG_AOM_HIGHBITDEPTH
-                ref_buf->y_buffer, ref_buf->y_width, ref_buf->y_height,
-                ref_buf->y_stride, cpi->Source->y_buffer, cpi->Source->y_width,
-                cpi->Source->y_height, cpi->Source->y_stride, 3);
-            if (erroradvantage >
-                gm_advantage_thresh[cm->global_motion[frame].wmtype]) {
-              set_default_gmparams(&cm->global_motion[frame]);
+                  ref_buf->y_buffer, ref_buf->y_width, ref_buf->y_height,
+                  ref_buf->y_stride, cpi->Source->y_buffer,
+                  cpi->Source->y_width, cpi->Source->y_height,
+                  cpi->Source->y_stride, 3);
+              if (erroradvantage >
+                  gm_advantage_thresh[cm->global_motion[frame].wmtype]) {
+                set_default_gmparams(&cm->global_motion[frame]);
+              }
             }
           }
+          if (cm->global_motion[frame].wmtype != IDENTITY) break;
         }
         aom_clear_system_state();
       }