Merge "Fix compiler warning when CONFIG_ACCOUNTING enabled." into nextgenv2
diff --git a/av1/common/entropymv.c b/av1/common/entropymv.c
index dfe798e..a80165e 100644
--- a/av1/common/entropymv.c
+++ b/av1/common/entropymv.c
@@ -61,8 +61,8 @@
         { { 0 }, { 0 } },  // class0_fp_cdf is computed in av1_init_mv_probs()
         { 0 },             // fp_cdf is computed from fp in av1_init_mv_probs()
 #endif
-        160,                                                   // class0_hp bit
-        128,                                                   // hp
+        160,  // class0_hp bit
+        128,  // hp
     },
     {
         // Horizontal component
@@ -79,8 +79,8 @@
         { { 0 }, { 0 } },  // class0_fp_cdf is computed in av1_init_mv_probs()
         { 0 },             // fp_cdf is computed from fp in av1_init_mv_probs()
 #endif
-        160,                                                   // class0_hp bit
-        128,                                                   // hp
+        160,  // class0_hp bit
+        128,  // hp
     } },
 };
 
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 9745d2d..b62abe0 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -251,34 +251,26 @@
 static void inverse_transform_block(MACROBLOCKD *xd, int plane,
                                     const TX_TYPE tx_type,
                                     const TX_SIZE tx_size, uint8_t *dst,
-                                    int stride, int eob) {
+                                    int stride, int16_t scan_line, int eob) {
   struct macroblockd_plane *const pd = &xd->plane[plane];
-  if (eob > 0) {
-    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];
+  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;
-      highbd_inv_txfm_add(dqcoeff, dst, stride, &inv_txfm_param);
-    } else {
+  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
+    inv_txfm_param.bd = xd->bd;
+    highbd_inv_txfm_add(dqcoeff, dst, stride, &inv_txfm_param);
+  } else {
 #endif  // CONFIG_AOM_HIGHBITDEPTH
-      inv_txfm_add(dqcoeff, dst, stride, &inv_txfm_param);
+    inv_txfm_add(dqcoeff, dst, stride, &inv_txfm_param);
 #if CONFIG_AOM_HIGHBITDEPTH
-    }
-#endif  // CONFIG_AOM_HIGHBITDEPTH
-
-    // TODO(jingning): This cleans up different reset requests from various
-    // experiments, but incurs unnecessary memset size.
-    if (eob == 1)
-      dqcoeff[0] = 0;
-    else
-      memset(dqcoeff, 0, tx_size_2d[tx_size] * sizeof(dqcoeff[0]));
   }
+#endif  // CONFIG_AOM_HIGHBITDEPTH
+  memset(dqcoeff, 0, (scan_line + 1) * sizeof(dqcoeff[0]));
 }
 
 static void predict_and_reconstruct_intra_block(AV1_COMMON *cm,
@@ -307,10 +299,13 @@
   if (!mbmi->skip) {
     TX_TYPE tx_type = get_tx_type(plane_type, xd, block_idx, tx_size);
     const SCAN_ORDER *scan_order = get_scan(cm, tx_size, tx_type, 0);
-    const int eob = av1_decode_block_tokens(
-        xd, plane, scan_order, col, row, tx_size, tx_type, r, mbmi->segment_id);
-    inverse_transform_block(xd, plane, tx_type, tx_size, dst, pd->dst.stride,
-                            eob);
+    int16_t max_scan_line = 0;
+    const int eob =
+        av1_decode_block_tokens(xd, plane, scan_order, col, row, tx_size,
+                                tx_type, &max_scan_line, r, mbmi->segment_id);
+    if (eob)
+      inverse_transform_block(xd, plane, tx_type, tx_size, dst, pd->dst.stride,
+                              max_scan_line, eob);
   }
 }
 
@@ -341,13 +336,14 @@
     PLANE_TYPE plane_type = (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV;
     TX_TYPE tx_type = get_tx_type(plane_type, xd, block, plane_tx_size);
     const SCAN_ORDER *sc = get_scan(cm, plane_tx_size, tx_type, 1);
+    int16_t max_scan_line = 0;
     const int eob =
         av1_decode_block_tokens(xd, plane, sc, blk_col, blk_row, plane_tx_size,
-                                tx_type, r, mbmi->segment_id);
+                                tx_type, &max_scan_line, r, mbmi->segment_id);
     inverse_transform_block(
         xd, plane, tx_type, plane_tx_size,
         &pd->dst.buf[4 * blk_row * pd->dst.stride + 4 * blk_col],
-        pd->dst.stride, eob);
+        pd->dst.stride, max_scan_line, eob);
     *eob_total += eob;
   } else {
     int bsl = b_width_log2_lookup[bsize];
@@ -385,12 +381,14 @@
   int block_idx = (row << 1) + col;
   TX_TYPE tx_type = get_tx_type(plane_type, xd, block_idx, tx_size);
   const SCAN_ORDER *scan_order = get_scan(cm, tx_size, tx_type, 1);
-  const int eob = av1_decode_block_tokens(xd, plane, scan_order, col, row,
-                                          tx_size, tx_type, r, segment_id);
-
-  inverse_transform_block(xd, plane, tx_type, tx_size,
-                          &pd->dst.buf[4 * row * pd->dst.stride + 4 * col],
-                          pd->dst.stride, eob);
+  int16_t max_scan_line = 0;
+  const int eob =
+      av1_decode_block_tokens(xd, plane, scan_order, col, row, tx_size, tx_type,
+                              &max_scan_line, r, segment_id);
+  if (eob)
+    inverse_transform_block(xd, plane, tx_type, tx_size,
+                            &pd->dst.buf[4 * row * pd->dst.stride + 4 * col],
+                            pd->dst.stride, max_scan_line, eob);
   return eob;
 }
 #endif  // !CONFIG_VAR_TX || CONFIG_SUPER_TX
diff --git a/av1/decoder/detokenize.c b/av1/decoder/detokenize.c
index f2f74f5..9c01b93 100644
--- a/av1/decoder/detokenize.c
+++ b/av1/decoder/detokenize.c
@@ -61,7 +61,7 @@
                         dequant_val_type_nuq *dq_val,
 #endif  // CONFIG_NEW_QUANT
                         int ctx, const int16_t *scan, const int16_t *nb,
-                        aom_reader *r)
+                        int16_t *max_scan_line, aom_reader *r)
 #endif
 {
   FRAME_COUNTS *counts = xd->counts;
@@ -166,6 +166,9 @@
       dqv_val = &dq_val[band][0];
 #endif  // CONFIG_NEW_QUANT
     }
+
+    *max_scan_line = AOMMAX(*max_scan_line, scan[c]);
+
 #if CONFIG_RANS
     cdf = &coef_cdfs[band][ctx];
     token = ONE_TOKEN +
@@ -327,7 +330,8 @@
 
 int av1_decode_block_tokens(MACROBLOCKD *const xd, int plane,
                             const SCAN_ORDER *sc, int x, int y, TX_SIZE tx_size,
-                            TX_TYPE tx_type, aom_reader *r, int seg_id) {
+                            TX_TYPE tx_type, int16_t *max_scan_line,
+                            aom_reader *r, int seg_id) {
   struct macroblockd_plane *const pd = &xd->plane[plane];
   const int16_t *const dequant = pd->seg_dequant[seg_id];
   const int ctx =
@@ -339,16 +343,16 @@
 #endif  //  CONFIG_NEW_QUANT
 
 #if CONFIG_AOM_QM
-  const int eob =
-      decode_coefs(xd, pd->plane_type, pd->dqcoeff, tx_size, tx_type, dequant,
-                   ctx, sc->scan, sc->neighbors, r, pd->seg_iqmatrix[seg_id]);
+  const int eob = decode_coefs(xd, pd->plane_type, pd->dqcoeff, tx_size,
+                               tx_type, dequant, ctx, sc->scan, sc->neighbors,
+                               &sc->max_scan_line, r, pd->seg_iqmatrix[seg_id]);
 #else
   const int eob =
       decode_coefs(xd, pd->plane_type, pd->dqcoeff, tx_size, tx_type, dequant,
 #if CONFIG_NEW_QUANT
                    pd->seg_dequant_nuq[seg_id][dq],
 #endif  // CONFIG_NEW_QUANT
-                   ctx, sc->scan, sc->neighbors, r);
+                   ctx, sc->scan, sc->neighbors, max_scan_line, r);
 #endif  // CONFIG_AOM_QM
   av1_set_contexts(xd, pd, tx_size, eob > 0, x, y);
   return eob;
diff --git a/av1/decoder/detokenize.h b/av1/decoder/detokenize.h
index 9c08ff9..1eb1e6c 100644
--- a/av1/decoder/detokenize.h
+++ b/av1/decoder/detokenize.h
@@ -28,7 +28,7 @@
 
 int av1_decode_block_tokens(MACROBLOCKD *const xd, int plane,
                             const SCAN_ORDER *sc, int x, int y, TX_SIZE tx_size,
-                            TX_TYPE tx_type,
+                            TX_TYPE tx_type, int16_t *max_scan_line,
 #if CONFIG_ANS
                             struct AnsDecoder *const r,
 #else