Rework txfm_above and txfm_left context offset

Make the txfm_above and txfm_left be processed in the unit of
miniumum transform block size. Scale the transform block step
size with respect to the mode_info step size.

Change-Id: Iee4421e005db742cd4ff7899215560063e5f68e5
diff --git a/av1/common/alloccommon.c b/av1/common/alloccommon.c
index 1a8246c..c1b596b 100644
--- a/av1/common/alloccommon.c
+++ b/av1/common/alloccommon.c
@@ -168,7 +168,7 @@
 #if CONFIG_VAR_TX
     aom_free(cm->above_txfm_context);
     cm->above_txfm_context = (TXFM_CONTEXT *)aom_calloc(
-        aligned_mi_cols, sizeof(*cm->above_txfm_context));
+        aligned_mi_cols << TX_UNIT_WIDE_LOG2, sizeof(*cm->above_txfm_context));
     if (!cm->above_txfm_context) goto fail;
 #endif
 
diff --git a/av1/common/av1_loopfilter.c b/av1/common/av1_loopfilter.c
index 8262944..f40de33 100644
--- a/av1/common/av1_loopfilter.c
+++ b/av1/common/av1_loopfilter.c
@@ -1434,12 +1434,15 @@
 #endif
 
 #if CONFIG_VAR_TX
-    TX_SIZE tx_size_r = AOMMIN(tx_size, cm->above_txfm_context[mi_col + c]);
+    TX_SIZE tx_size_r = AOMMIN(
+        tx_size, cm->above_txfm_context[(mi_col + c) << TX_UNIT_WIDE_LOG2]);
     TX_SIZE tx_size_c =
-        AOMMIN(tx_size, cm->left_txfm_context[(mi_row + r) & MAX_MIB_MASK]);
+        AOMMIN(tx_size, cm->left_txfm_context[((mi_row + r) & MAX_MIB_MASK)
+                                              << TX_UNIT_HIGH_LOG2]);
 
-    cm->above_txfm_context[mi_col + c] = tx_size;
-    cm->left_txfm_context[(mi_row + r) & MAX_MIB_MASK] = tx_size;
+    cm->above_txfm_context[(mi_col + c) << TX_UNIT_WIDE_LOG2] = tx_size;
+    cm->left_txfm_context[((mi_row + r) & MAX_MIB_MASK) << TX_UNIT_HIGH_LOG2] =
+        tx_size;
 #else
     TX_SIZE tx_size_c = txsize_horz_map[tx_size];
     TX_SIZE tx_size_r = txsize_vert_map[tx_size];
@@ -2189,12 +2192,12 @@
   int mi_row, mi_col;
 
 #if CONFIG_VAR_TX
-  memset(cm->above_txfm_context, TX_SIZES, cm->mi_cols);
+  memset(cm->above_txfm_context, TX_SIZES, cm->mi_cols << TX_UNIT_WIDE_LOG2);
 #endif  // CONFIG_VAR_TX
   for (mi_row = start; mi_row < stop; mi_row += cm->mib_size) {
     MODE_INFO **mi = cm->mi_grid_visible + mi_row * cm->mi_stride;
 #if CONFIG_VAR_TX
-    memset(cm->left_txfm_context, TX_SIZES, MAX_MIB_SIZE);
+    memset(cm->left_txfm_context, TX_SIZES, MAX_MIB_SIZE << TX_UNIT_WIDE_LOG2);
 #endif  // CONFIG_VAR_TX
     for (mi_col = 0; mi_col < cm->mi_cols; mi_col += cm->mib_size) {
       int plane;
diff --git a/av1/common/blockd.h b/av1/common/blockd.h
index 7f0c9d9..0cffa79 100644
--- a/av1/common/blockd.h
+++ b/av1/common/blockd.h
@@ -623,7 +623,7 @@
 #if CONFIG_VAR_TX
   TXFM_CONTEXT *above_txfm_context;
   TXFM_CONTEXT *left_txfm_context;
-  TXFM_CONTEXT left_txfm_context_buffer[MAX_MIB_SIZE];
+  TXFM_CONTEXT left_txfm_context_buffer[2 * MAX_MIB_SIZE];
 
   TX_SIZE max_tx_size;
 #if CONFIG_SUPERTX
diff --git a/av1/common/common_data.h b/av1/common/common_data.h
index 79c130f..3609d70 100644
--- a/av1/common/common_data.h
+++ b/av1/common/common_data.h
@@ -785,6 +785,9 @@
   3, 2, 4, 3, 5, 4, 4, 2, 5, 3
 };
 
+#define TX_UNIT_WIDE_LOG2 (MI_SIZE_LOG2 - tx_size_wide_log2[0])
+#define TX_UNIT_HIGH_LOG2 (MI_SIZE_LOG2 - tx_size_high_log2[0])
+
 static const int tx_size_2d[TX_SIZES_ALL] = {
 #if CONFIG_CB4X4
   4,
diff --git a/av1/common/onyxc_int.h b/av1/common/onyxc_int.h
index 186ef16..090d737 100644
--- a/av1/common/onyxc_int.h
+++ b/av1/common/onyxc_int.h
@@ -386,7 +386,7 @@
   ENTROPY_CONTEXT *above_context[MAX_MB_PLANE];
 #if CONFIG_VAR_TX
   TXFM_CONTEXT *above_txfm_context;
-  TXFM_CONTEXT left_txfm_context[MAX_MIB_SIZE];
+  TXFM_CONTEXT left_txfm_context[2 * MAX_MIB_SIZE];
 #endif
   int above_context_alloc_cols;
 
@@ -877,7 +877,8 @@
   av1_zero_array(cm->above_seg_context + mi_col_start, aligned_width);
 
 #if CONFIG_VAR_TX
-  av1_zero_array(cm->above_txfm_context + mi_col_start, aligned_width);
+  av1_zero_array(cm->above_txfm_context + (mi_col_start << TX_UNIT_WIDE_LOG2),
+                 aligned_width << TX_UNIT_WIDE_LOG2);
 #endif  // CONFIG_VAR_TX
 }
 
@@ -910,16 +911,16 @@
     bh = n8_h * MI_SIZE;
   }
 
-  set_txfm_ctx(xd->above_txfm_context, bw, n8_w);
-  set_txfm_ctx(xd->left_txfm_context, bh, n8_h);
+  set_txfm_ctx(xd->above_txfm_context, bw, n8_w << TX_UNIT_WIDE_LOG2);
+  set_txfm_ctx(xd->left_txfm_context, bh, n8_h << TX_UNIT_HIGH_LOG2);
 }
 
 static INLINE void txfm_partition_update(TXFM_CONTEXT *above_ctx,
                                          TXFM_CONTEXT *left_ctx,
                                          TX_SIZE tx_size, TX_SIZE txb_size) {
   BLOCK_SIZE bsize = txsize_to_bsize[txb_size];
-  int bh = mi_size_high[bsize];
-  int bw = mi_size_wide[bsize];
+  int bh = mi_size_high[bsize] << TX_UNIT_HIGH_LOG2;
+  int bw = mi_size_wide[bsize] << TX_UNIT_WIDE_LOG2;
   uint8_t txw = tx_size_wide[tx_size];
   uint8_t txh = tx_size_high[tx_size];
   int i;