Add av1_inverse_transform_block

Move most of the code of inverse_transform_block to
av1_inverse_transform_block such that encoder can use the
function as well.

Use av1_inverse_transform_block in av1_encoder_block_intra.
This will make the code cleaner.

Change-Id: I84dbeef2c65e252910606dbea446ce43165d504c
diff --git a/av1/common/idct.c b/av1/common/idct.c
index aca50e1..64aec4b 100644
--- a/av1/common/idct.c
+++ b/av1/common/idct.c
@@ -2781,6 +2781,28 @@
   }
 }
 
+void av1_inverse_transform_block(MACROBLOCKD *xd, const tran_low_t *dqcoeff,
+                                 const TX_TYPE tx_type, const TX_SIZE tx_size,
+                                 uint8_t *dst, int stride, int eob) {
+  if (!eob) return;
+  INV_TXFM_PARAM inv_txfm_param;
+  inv_txfm_param.tx_type = tx_type;
+  inv_txfm_param.tx_size = tx_size;
+  inv_txfm_param.eob = eob;
+  inv_txfm_param.lossless = xd->lossless[xd->mi[0]->mbmi.segment_id];
+
+#if CONFIG_AOM_HIGHBITDEPTH
+  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
+    inv_txfm_param.bd = xd->bd;
+    av1_highbd_inv_txfm_add(dqcoeff, dst, stride, &inv_txfm_param);
+  } else {
+#endif  // CONFIG_AOM_HIGHBITDEPTH
+    av1_inv_txfm_add(dqcoeff, dst, stride, &inv_txfm_param);
+#if CONFIG_AOM_HIGHBITDEPTH
+  }
+#endif  // CONFIG_AOM_HIGHBITDEPTH
+}
+
 #if CONFIG_AOM_HIGHBITDEPTH
 void av1_highbd_inv_txfm_add(const tran_low_t *input, uint8_t *dest, int stride,
                              INV_TXFM_PARAM *inv_txfm_param) {
diff --git a/av1/common/idct.h b/av1/common/idct.h
index 90960dd..1d64c06 100644
--- a/av1/common/idct.h
+++ b/av1/common/idct.h
@@ -66,6 +66,9 @@
                           int eob, TX_TYPE tx_type);
 void av1_inv_txfm_add(const tran_low_t *input, uint8_t *dest, int stride,
                       INV_TXFM_PARAM *inv_txfm_param);
+void av1_inverse_transform_block(MACROBLOCKD *xd, const tran_low_t *dqcoeff,
+                                 const TX_TYPE tx_type, const TX_SIZE tx_size,
+                                 uint8_t *dst, int stride, int eob);
 #if CONFIG_AOM_HIGHBITDEPTH
 void av1_highbd_iwht4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
                             int eob, int bd);
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 12dd9f9..16ee7fd 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -328,22 +328,7 @@
                                     int stride, int16_t scan_line, int eob) {
   struct macroblockd_plane *const pd = &xd->plane[plane];
   tran_low_t *const dqcoeff = pd->dqcoeff;
-  INV_TXFM_PARAM inv_txfm_param;
-  inv_txfm_param.tx_type = tx_type;
-  inv_txfm_param.tx_size = tx_size;
-  inv_txfm_param.eob = eob;
-  inv_txfm_param.lossless = xd->lossless[xd->mi[0]->mbmi.segment_id];
-
-#if CONFIG_AOM_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    inv_txfm_param.bd = xd->bd;
-    av1_highbd_inv_txfm_add(dqcoeff, dst, stride, &inv_txfm_param);
-  } else {
-#endif  // CONFIG_AOM_HIGHBITDEPTH
-    av1_inv_txfm_add(dqcoeff, dst, stride, &inv_txfm_param);
-#if CONFIG_AOM_HIGHBITDEPTH
-  }
-#endif  // CONFIG_AOM_HIGHBITDEPTH
+  av1_inverse_transform_block(xd, dqcoeff, tx_type, tx_size, dst, stride, eob);
   memset(dqcoeff, 0, (scan_line + 1) * sizeof(dqcoeff[0]));
 }
 
diff --git a/av1/encoder/encodemb.c b/av1/encoder/encodemb.c
index 6fe992d..dcedfdf 100644
--- a/av1/encoder/encodemb.c
+++ b/av1/encoder/encodemb.c
@@ -1094,7 +1094,6 @@
   AV1_COMMON *cm = args->cm;
   MACROBLOCK *const x = args->x;
   MACROBLOCKD *const xd = &x->e_mbd;
-  MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
   struct macroblock_plane *const p = &x->plane[plane];
   struct macroblockd_plane *const pd = &xd->plane[plane];
   tran_low_t *dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
@@ -1107,7 +1106,6 @@
   uint8_t *dst =
       &pd->dst.buf[(blk_row * dst_stride + blk_col) << tx_size_wide_log2[0]];
   int ctx = 0;
-  INV_TXFM_PARAM inv_txfm_param;
 #if CONFIG_PVQ
   int tx_blk_size;
   int i, j;
@@ -1143,25 +1141,8 @@
 #endif  // CONFIG_NEW_QUANT
   }
 
-  if (*eob) {
-    // inverse transform
-    inv_txfm_param.tx_type = tx_type;
-    inv_txfm_param.tx_size = tx_size;
-    inv_txfm_param.eob = *eob;
-    inv_txfm_param.lossless = xd->lossless[mbmi->segment_id];
-#if CONFIG_AOM_HIGHBITDEPTH
-    inv_txfm_param.bd = xd->bd;
-    if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-      av1_highbd_inv_txfm_add(dqcoeff, dst, dst_stride, &inv_txfm_param);
-    } else {
-      av1_inv_txfm_add(dqcoeff, dst, dst_stride, &inv_txfm_param);
-    }
-#else
-    av1_inv_txfm_add(dqcoeff, dst, dst_stride, &inv_txfm_param);
-#endif  // CONFIG_AOM_HIGHBITDEPTH
-
-    *(args->skip) = 0;
-  }
+  av1_inverse_transform_block(xd, dqcoeff, tx_type, tx_size, dst, dst_stride,
+                              *eob);
 #else  // #if !CONFIG_PVQ
 
 #if CONFIG_NEW_QUANT
@@ -1197,20 +1178,8 @@
   }
 #endif  // CONFIG_AOM_HIGHBITDEPTH
 
-  inv_txfm_param.tx_type = tx_type;
-  inv_txfm_param.tx_size = tx_size;
-  inv_txfm_param.eob = *eob;
-  inv_txfm_param.lossless = xd->lossless[mbmi->segment_id];
-#if CONFIG_AOM_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    inv_txfm_param.bd = xd->bd;
-    av1_highbd_inv_txfm_add(dqcoeff, dst, dst_stride, &inv_txfm_param);
-  } else {
-#endif
-    av1_inv_txfm_add(dqcoeff, dst, dst_stride, &inv_txfm_param);
-#if CONFIG_AOM_HIGHBITDEPTH
-  }
-#endif
+  av1_inverse_transform_block(xd, dqcoeff, tx_type, tx_size, dst, dst_stride,
+                              *eob);
 #endif  // #if !CONFIG_PVQ
 
 #if !CONFIG_PVQ