Use correct RestorationInfo when encoding tilesize

Also, factor out some long constants to avoid line wrapping.

BUG=aomedia:1009

Change-Id: I7850c27d22ef8b927c3554f1083bc7bdf2c7c6b3
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index d576bd9..165164d 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -1110,10 +1110,8 @@
 #if CONFIG_LOOP_RESTORATION
 static void decode_restoration_mode(AV1_COMMON *cm,
                                     struct aom_read_bit_buffer *rb) {
-  int p;
-  RestorationInfo *rsi;
-  for (p = 0; p < MAX_MB_PLANE; ++p) {
-    rsi = &cm->rst_info[p];
+  for (int p = 0; p < MAX_MB_PLANE; ++p) {
+    RestorationInfo *rsi = &cm->rst_info[p];
     if (aom_rb_read_bit(rb)) {
       rsi->frame_restoration_type =
           aom_rb_read_bit(rb) ? RESTORE_SGRPROJ : RESTORE_WIENER;
@@ -1122,21 +1120,24 @@
           aom_rb_read_bit(rb) ? RESTORE_SWITCHABLE : RESTORE_NONE;
     }
   }
-  cm->rst_info[0].restoration_unit_size = RESTORATION_TILESIZE_MAX;
-  cm->rst_info[1].restoration_unit_size = RESTORATION_TILESIZE_MAX;
-  cm->rst_info[2].restoration_unit_size = RESTORATION_TILESIZE_MAX;
   if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE ||
       cm->rst_info[1].frame_restoration_type != RESTORE_NONE ||
       cm->rst_info[2].frame_restoration_type != RESTORE_NONE) {
-    cm->rst_info[0].restoration_unit_size = RESTORATION_TILESIZE_MAX >> 2;
-    cm->rst_info[1].restoration_unit_size = RESTORATION_TILESIZE_MAX >> 2;
-    cm->rst_info[2].restoration_unit_size = RESTORATION_TILESIZE_MAX >> 2;
-    rsi = &cm->rst_info[0];
+    const int qsize = RESTORATION_TILESIZE_MAX >> 2;
+    for (int p = 0; p < MAX_MB_PLANE; ++p)
+      cm->rst_info[p].restoration_unit_size = qsize;
+
+    RestorationInfo *rsi = &cm->rst_info[0];
     rsi->restoration_unit_size <<= aom_rb_read_bit(rb);
-    if (rsi->restoration_unit_size != (RESTORATION_TILESIZE_MAX >> 2)) {
+    if (rsi->restoration_unit_size != qsize) {
       rsi->restoration_unit_size <<= aom_rb_read_bit(rb);
     }
+  } else {
+    const int size = RESTORATION_TILESIZE_MAX;
+    for (int p = 0; p < MAX_MB_PLANE; ++p)
+      cm->rst_info[p].restoration_unit_size = size;
   }
+
   int s = AOMMIN(cm->subsampling_x, cm->subsampling_y);
   if (s && (cm->rst_info[1].frame_restoration_type != RESTORE_NONE ||
             cm->rst_info[2].frame_restoration_type != RESTORE_NONE)) {
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index d2a8c3a..023e568 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -2446,10 +2446,8 @@
 #if CONFIG_LOOP_RESTORATION
 static void encode_restoration_mode(AV1_COMMON *cm,
                                     struct aom_write_bit_buffer *wb) {
-  int p;
-  RestorationInfo *rsi;
-  for (p = 0; p < MAX_MB_PLANE; ++p) {
-    rsi = &cm->rst_info[p];
+  for (int p = 0; p < MAX_MB_PLANE; ++p) {
+    RestorationInfo *rsi = &cm->rst_info[p];
     switch (rsi->frame_restoration_type) {
       case RESTORE_NONE:
         aom_wb_write_bit(wb, 0);
@@ -2473,11 +2471,12 @@
   if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE ||
       cm->rst_info[1].frame_restoration_type != RESTORE_NONE ||
       cm->rst_info[2].frame_restoration_type != RESTORE_NONE) {
-    aom_wb_write_bit(
-        wb, rsi->restoration_unit_size != (RESTORATION_TILESIZE_MAX >> 2));
-    if (rsi->restoration_unit_size != (RESTORATION_TILESIZE_MAX >> 2)) {
-      aom_wb_write_bit(
-          wb, rsi->restoration_unit_size != (RESTORATION_TILESIZE_MAX >> 1));
+    RestorationInfo *rsi = &cm->rst_info[0];
+    const int qsize = RESTORATION_TILESIZE_MAX >> 2;
+    const int hsize = RESTORATION_TILESIZE_MAX >> 1;
+    aom_wb_write_bit(wb, rsi->restoration_unit_size != qsize);
+    if (rsi->restoration_unit_size != qsize) {
+      aom_wb_write_bit(wb, rsi->restoration_unit_size != hsize);
     }
   }
   int s = AOMMIN(cm->subsampling_x, cm->subsampling_y);