Empty the dst buffer before inv txfm when PVQ on

Change-Id: I35b2b69e3937e70a7923ba76735f035f366de27f
diff --git a/av1/common/idct.c b/av1/common/idct.c
index 64aec4b..8b6b875 100644
--- a/av1/common/idct.c
+++ b/av1/common/idct.c
@@ -2785,6 +2785,25 @@
                                  const TX_TYPE tx_type, const TX_SIZE tx_size,
                                  uint8_t *dst, int stride, int eob) {
   if (!eob) return;
+#if CONFIG_PVQ
+  const BLOCK_SIZE tx_bsize = txsize_to_bsize[tx_size];
+  const int txb_width = block_size_wide[tx_bsize];
+  const int txb_height = block_size_high[tx_bsize];
+  int r, c;
+#if CONFIG_AOM_HIGHBITDEPTH
+  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
+    uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst);
+    for (r = 0; r < txb_height; r++)
+      for (c = 0; c < txb_width; c++)
+        CONVERT_TO_SHORTPTR(dst)[r * stride + c] = 0;
+  } else {
+#endif  // CONFIG_AOM_HIGHBITDEPTH
+    for (r = 0; r < txb_height; r++)
+      for (c = 0; c < txb_width; c++) dst[r * stride + c] = 0;
+#if CONFIG_AOM_HIGHBITDEPTH
+  }
+#endif  // CONFIG_AOM_HIGHBITDEPTH
+#endif  // CONFIG_PVQ
   INV_TXFM_PARAM inv_txfm_param;
   inv_txfm_param.tx_type = tx_type;
   inv_txfm_param.tx_size = tx_size;
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 16ee7fd..7006ead 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -496,22 +496,6 @@
     eob = av1_pvq_decode_helper(xd, pvq_ref_coeff, dqcoeff, quant, plane,
                                 tx_size, tx_type, xdec, ac_dc_coded);
 
-// Since av1 does not have separate inverse transform
-// but also contains adding to predicted image,
-// pass blank dummy image to av1_inv_txfm_add_*x*(), i.e. set dst as zeros
-#if CONFIG_AOM_HIGHBITDEPTH
-    if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-      for (j = 0; j < tx_blk_size; j++)
-        for (i = 0; i < tx_blk_size; i++)
-          CONVERT_TO_SHORTPTR(dst)[j * pd->dst.stride + i] = 0;
-    } else {
-#endif
-      for (j = 0; j < tx_blk_size; j++)
-        for (i = 0; i < tx_blk_size; i++) dst[j * pd->dst.stride + i] = 0;
-#if CONFIG_AOM_HIGHBITDEPTH
-    }
-#endif
-
     inverse_transform_block(xd, plane, tx_type, tx_size, dst, pd->dst.stride,
                             max_scan_line, eob);
   }
diff --git a/av1/encoder/encodemb.c b/av1/encoder/encodemb.c
index 405943a..ceeac84 100644
--- a/av1/encoder/encodemb.c
+++ b/av1/encoder/encodemb.c
@@ -1105,10 +1105,6 @@
   const int dst_stride = pd->dst.stride;
   uint8_t *dst =
       &pd->dst.buf[(blk_row * dst_stride + blk_col) << tx_size_wide_log2[0]];
-#if CONFIG_PVQ
-  int tx_blk_size;
-  int i, j;
-#endif
 
   av1_predict_intra_block_facade(xd, plane, block_raster_idx, blk_col, blk_row,
                                  tx_size);
@@ -1133,27 +1129,7 @@
   if (!x->pvq_skip[plane]) *(args->skip) = 0;
 
   if (x->pvq_skip[plane]) return;
-
-  // transform block size in pixels
-  tx_blk_size = tx_size_wide[tx_size];
-
-// Since av1 does not have separate function which does inverse transform
-// but av1_inv_txfm_add_*x*() also does addition of predicted image to
-// inverse transformed image,
-// pass blank dummy image to av1_inv_txfm_add_*x*(), i.e. set dst as zeros
-#if CONFIG_AOM_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-    for (j = 0; j < tx_blk_size; j++)
-      for (i = 0; i < tx_blk_size; i++)
-        CONVERT_TO_SHORTPTR(dst)[j * dst_stride + i] = 0;
-  } else {
-#endif  // CONFIG_AOM_HIGHBITDEPTH
-    for (j = 0; j < tx_blk_size; j++)
-      for (i = 0; i < tx_blk_size; i++) dst[j * dst_stride + i] = 0;
-#if CONFIG_AOM_HIGHBITDEPTH
-  }
-#endif  // CONFIG_AOM_HIGHBITDEPTH
-#endif  // #if CONFIG_PVQ
+#endif  // CONFIG_PVQ
   av1_inverse_transform_block(xd, dqcoeff, tx_type, tx_size, dst, dst_stride,
                               *eob);
 #if !CONFIG_PVQ
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index f0881c8..0659ec6 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -1419,8 +1419,10 @@
     *out_sse = this_sse >> shift;
   } else {
     const BLOCK_SIZE tx_bsize = txsize_to_bsize[tx_size];
+#if !CONFIG_PVQ || CONFIG_DAALA_DIST
     const int bsw = block_size_wide[tx_bsize];
     const int bsh = block_size_high[tx_bsize];
+#endif
     const int src_stride = x->plane[plane].src.stride;
     const int dst_stride = xd->plane[plane].dst.stride;
     // Scale the transform block index to pixel unit.
@@ -1460,6 +1462,7 @@
       DECLARE_ALIGNED(16, uint8_t, recon[MAX_TX_SQUARE]);
 #endif  // CONFIG_AOM_HIGHBITDEPTH
 
+#if !CONFIG_PVQ
 #if CONFIG_AOM_HIGHBITDEPTH
       if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
         aom_highbd_convolve_copy(dst, dst_stride, recon, MAX_TX_SIZE, NULL, 0,
@@ -1467,16 +1470,10 @@
       } else
 #endif  // CONFIG_AOM_HIGHBITDEPTH
       {
-#if !CONFIG_PVQ
         aom_convolve_copy(dst, dst_stride, recon, MAX_TX_SIZE, NULL, 0, NULL, 0,
                           bsw, bsh);
-#else
-        int i, j;
-
-        for (j = 0; j < bsh; j++)
-          for (i = 0; i < bsw; i++) recon[j * MAX_TX_SIZE + i] = 0;
-#endif  // !CONFIG_PVQ
       }
+#endif  // !CONFIG_PVQ
 
       const int block_raster_idx =
           av1_block_index_to_raster_order(tx_size, block);