Add a macro to control use of domain txfm filter

Allows DomainTxfm filters to be turned off for experimentation.
Also expands the parameter set for the Self guided filters.

Change-Id: I68fdb8e079a2464d80b3a4a990005c49baaaf0b8
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index 2c87f1f..d218616 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -3324,6 +3324,7 @@
       aom_wb_write_bit(wb, 1);
       aom_wb_write_bit(wb, 0);
       break;
+#if USE_DOMAINTXFMRF
     case RESTORE_SGRPROJ:
       aom_wb_write_bit(wb, 1);
       aom_wb_write_bit(wb, 1);
@@ -3334,6 +3335,12 @@
       aom_wb_write_bit(wb, 1);
       aom_wb_write_bit(wb, 1);
       break;
+#else
+    case RESTORE_SGRPROJ:
+      aom_wb_write_bit(wb, 1);
+      aom_wb_write_bit(wb, 1);
+      break;
+#endif  // USE_DOMAINTXFMRF
     case RESTORE_SWITCHABLE:
       aom_wb_write_bit(wb, 0);
       aom_wb_write_bit(wb, 1);
@@ -3373,10 +3380,12 @@
                     SGRPROJ_PRJ_BITS);
 }
 
+#if USE_DOMAINTXFMRF
 static void write_domaintxfmrf_filter(DomaintxfmrfInfo *domaintxfmrf_info,
                                       aom_writer *wb) {
   aom_write_literal(wb, domaintxfmrf_info->sigma_r, DOMAINTXFMRF_PARAMS_BITS);
 }
+#endif  // USE_DOMAINTXFMRF
 
 static void encode_restoration(AV1_COMMON *cm, aom_writer *wb) {
   int i, p;
@@ -3398,8 +3407,10 @@
           write_wiener_filter(&rsi->wiener_info[i], wb);
         } else if (rsi->restoration_type[i] == RESTORE_SGRPROJ) {
           write_sgrproj_filter(&rsi->sgrproj_info[i], wb);
+#if USE_DOMAINTXFMRF
         } else if (rsi->restoration_type[i] == RESTORE_DOMAINTXFMRF) {
           write_domaintxfmrf_filter(&rsi->domaintxfmrf_info[i], wb);
+#endif  // USE_DOMAINTXFMRF
         }
       }
     } else if (rsi->frame_restoration_type == RESTORE_WIENER) {
@@ -3418,6 +3429,7 @@
           write_sgrproj_filter(&rsi->sgrproj_info[i], wb);
         }
       }
+#if USE_DOMAINTXFMRF
     } else if (rsi->frame_restoration_type == RESTORE_DOMAINTXFMRF) {
       for (i = 0; i < ntiles; ++i) {
         aom_write(wb, rsi->restoration_type[i] != RESTORE_NONE,
@@ -3426,6 +3438,7 @@
           write_domaintxfmrf_filter(&rsi->domaintxfmrf_info[i], wb);
         }
       }
+#endif  // USE_DOMAINTXFMRF
     }
   }
   for (p = 1; p < MAX_MB_PLANE; ++p) {
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index b0858c0..6e44361 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -714,7 +714,7 @@
 
 static void alloc_util_frame_buffers(AV1_COMP *cpi) {
 #if CONFIG_LOOP_RESTORATION
-  int i;
+  int i, extra_rstbuf_sz;
 #endif  // CONFIG_LOOP_RESTORATION
   AV1_COMMON *const cm = &cpi->common;
   if (aom_realloc_frame_buffer(&cpi->last_frame_uf, cm->width, cm->height,
@@ -746,11 +746,16 @@
                                NULL, NULL))
     aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
                        "Failed to allocate trial restored frame buffer");
-  cpi->extra_rstbuf =
-      (uint8_t *)aom_realloc(cpi->extra_rstbuf, RESTORATION_EXTBUF_SIZE);
-  if (!cpi->extra_rstbuf)
-    aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
-                       "Failed to allocate extra rstbuf for restoration");
+  extra_rstbuf_sz = RESTORATION_EXTBUF_SIZE;
+  if (extra_rstbuf_sz > 0) {
+    cpi->extra_rstbuf =
+        (uint8_t *)aom_realloc(cpi->extra_rstbuf, extra_rstbuf_sz);
+    if (!cpi->extra_rstbuf)
+      aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
+                         "Failed to allocate extra rstbuf for restoration");
+  } else {
+    cpi->extra_rstbuf = NULL;
+  }
   for (i = 0; i < MAX_MB_PLANE; ++i)
     av1_alloc_restoration_struct(cm, &cpi->rst_search[i], cm->width,
                                  cm->height);
diff --git a/av1/encoder/pickrst.c b/av1/encoder/pickrst.c
index ab24c90..bf34b77 100644
--- a/av1/encoder/pickrst.c
+++ b/av1/encoder/pickrst.c
@@ -37,7 +37,11 @@
                                       double *best_tile_cost,
                                       YV12_BUFFER_CONFIG *dst_frame);
 
+#if USE_DOMAINTXFMRF
 const int frame_level_restore_bits[RESTORE_TYPES] = { 2, 2, 3, 3, 2 };
+#else
+const int frame_level_restore_bits[RESTORE_TYPES] = { 2, 2, 2, 2 };
+#endif  // USE_DOMAINTXFMRF
 
 static int64_t sse_restoration_tile(const YV12_BUFFER_CONFIG *src,
                                     const YV12_BUFFER_CONFIG *dst,
@@ -418,6 +422,7 @@
   return cost_sgrproj;
 }
 
+#if USE_DOMAINTXFMRF
 static int64_t compute_sse(uint8_t *dgd, int width, int height, int dgd_stride,
                            uint8_t *src, int src_stride) {
   int64_t sse = 0;
@@ -640,6 +645,7 @@
   aom_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show);
   return cost_domaintxfmrf;
 }
+#endif  // USE_DOMAINTXFMRF
 
 static double find_average(uint8_t *src, int h_start, int h_end, int v_start,
                            int v_end, int stride) {
@@ -1318,7 +1324,12 @@
 void av1_pick_filter_restoration(const YV12_BUFFER_CONFIG *src, AV1_COMP *cpi,
                                  LPF_PICK_METHOD method) {
   static search_restore_type search_restore_fun[RESTORE_SWITCHABLE_TYPES] = {
-    search_norestore, search_wiener, search_sgrproj, search_domaintxfmrf,
+    search_norestore,
+    search_wiener,
+    search_sgrproj,
+#if USE_DOMAINTXFMRF
+    search_domaintxfmrf,
+#endif  // USE_DOMAINTXFMRF
   };
   AV1_COMMON *const cm = &cpi->common;
   struct loopfilter *const lf = &cm->lf;
@@ -1417,11 +1428,17 @@
          cm->rst_info[2].frame_restoration_type);
          */
   /*
+#if USE_DOMAINTXFMRF
   printf("Frame %d/%d frame_restore_type %d : %f %f %f %f %f\n",
          cm->current_video_frame, cm->show_frame,
          cm->rst_info[0].frame_restoration_type, cost_restore[0],
-  cost_restore[1],
-         cost_restore[2], cost_restore[3], cost_restore[4]);
+         cost_restore[1], cost_restore[2], cost_restore[3], cost_restore[4]);
+#else
+  printf("Frame %d/%d frame_restore_type %d : %f %f %f %f\n",
+         cm->current_video_frame, cm->show_frame,
+         cm->rst_info[0].frame_restoration_type, cost_restore[0],
+         cost_restore[1], cost_restore[2], cost_restore[3]);
+#endif  // USE_DOMAINTXFMRF
          */
 
   for (r = 0; r < RESTORE_SWITCHABLE_TYPES; r++) {