Change non-uniform-quant parameters

Also adds hooks to choose different profiles for UV and intra.

Results
lowres: -0.15%
midres: -0.24%

Change-Id: I4af8bc3e9b82b6f8a061dce9f52c89afa6239ae1
diff --git a/av1/common/quant_common.c b/av1/common/quant_common.c
index 4b51016..4f3d481 100644
--- a/av1/common/quant_common.c
+++ b/av1/common/quant_common.c
@@ -20,8 +20,8 @@
 static void make_qmatrices(qm_val_t *wmatrix[NUM_QM_LEVELS][2][2][TX_SIZES],
                            qm_val_t *iwmatrix[NUM_QM_LEVELS][2][2][TX_SIZES]);
 #endif
-#if CONFIG_NEW_QUANT
 
+#if CONFIG_NEW_QUANT
 // Bin widths expressed as a fraction over 128 of the quant stepsize,
 // for the quantization bins 0-4.
 // So a value x indicates the bin is actually factor x/128 of the
@@ -47,54 +47,54 @@
 
 static const qprofile_type nuq[QUANT_PROFILES][QUANT_RANGES][COEF_BANDS] = {
   { {
-        { { 64, 128, 128 }, 0 },  // dc, band 0
-        { { 64, 128, 128 }, 0 },  // band 1
-        { { 64, 128, 128 }, 0 },  // band 2
-        { { 64, 128, 128 }, 0 },  // band 3
-        { { 64, 128, 128 }, 0 },  // band 4
-        { { 64, 128, 128 }, 0 }   // band 5
+        { { 64, 128, 128 }, 8 },   // dc, band 0
+        { { 64, 128, 128 }, 10 },   // band 1
+        { { 64, 128, 128 }, 12 },  // band 2
+        { { 72, 128, 128 }, 14 },  // band 3
+        { { 76, 128, 128 }, 16 },  // band 4
+        { { 80, 128, 128 }, 18 }   // band 5
     },
     {
-        { { 64, 128, 128 }, 0 },  // dc, band 0
-        { { 64, 128, 128 }, 0 },  // band 1
-        { { 64, 128, 128 }, 0 },  // band 2
-        { { 64, 128, 128 }, 0 },  // band 3
-        { { 64, 128, 128 }, 0 },  // band 4
-        { { 64, 128, 128 }, 0 }   // band 5
+        { { 64, 128, 128 }, 4 },   // dc, band 0
+        { { 64, 128, 128 }, 6 },  // band 1
+        { { 64, 128, 128 }, 8 },  // band 2
+        { { 64, 128, 128 }, 10 },  // band 3
+        { { 72, 128, 128 }, 12 },  // band 4
+        { { 80, 128, 128 }, 14 }   // band 5
     } },
 #if QUANT_PROFILES > 1
   { {
-        { { 64, 128, 128 }, 0 },  // dc, band 0
-        { { 64, 128, 128 }, 0 },  // band 1
-        { { 64, 128, 128 }, 0 },  // band 2
-        { { 64, 128, 128 }, 0 },  // band 3
-        { { 64, 128, 128 }, 0 },  // band 4
-        { { 64, 128, 128 }, 0 }   // band 5
+        { { 64, 128, 128 }, 6 },   // dc, band 0
+        { { 64, 128, 128 }, 8 },   // band 1
+        { { 64, 128, 128 }, 10 },  // band 2
+        { { 64, 128, 128 }, 12 },  // band 3
+        { { 72, 128, 128 }, 14 },  // band 4
+        { { 80, 128, 128 }, 16 }   // band 5
     },
     {
-        { { 64, 128, 128 }, 0 },  // dc, band 0
-        { { 64, 128, 128 }, 0 },  // band 1
-        { { 64, 128, 128 }, 0 },  // band 2
-        { { 64, 128, 128 }, 0 },  // band 3
-        { { 64, 128, 128 }, 0 },  // band 4
-        { { 64, 128, 128 }, 0 }   // band 5
+        { { 64, 128, 128 }, 4 },   // dc, band 0
+        { { 64, 128, 128 }, 6 },   // band 1
+        { { 64, 128, 128 }, 8 },  // band 2
+        { { 64, 128, 128 }, 10 },  // band 3
+        { { 72, 128, 128 }, 12 },  // band 4
+        { { 80, 128, 128 }, 14 }   // band 5
     } },
 #if QUANT_PROFILES > 2
   { {
-        { { 64, 128, 128 }, 0 },  // dc, band 0
-        { { 64, 128, 128 }, 0 },  // band 1
-        { { 64, 128, 128 }, 0 },  // band 2
-        { { 64, 128, 128 }, 0 },  // band 3
-        { { 64, 128, 128 }, 0 },  // band 4
-        { { 64, 128, 128 }, 0 },  // band 5
+        { { 64, 128, 128 }, 6 },   // dc, band 0
+        { { 64, 128, 128 }, 8 },   // band 1
+        { { 64, 128, 128 }, 10 },  // band 2
+        { { 64, 128, 128 }, 12 },  // band 3
+        { { 72, 128, 128 }, 14 },  // band 4
+        { { 80, 128, 128 }, 16 }   // band 5
     },
     {
-        { { 64, 128, 128 }, 0 },  // dc, band 0
-        { { 64, 128, 128 }, 0 },  // band 1
-        { { 64, 128, 128 }, 0 },  // band 2
-        { { 64, 128, 128 }, 0 },  // band 3
-        { { 64, 128, 128 }, 0 },  // band 4
-        { { 64, 128, 128 }, 0 },  // band 5
+        { { 64, 128, 128 }, 4 },   // dc, band 0
+        { { 64, 128, 128 }, 6 },   // band 1
+        { { 64, 128, 128 }, 8 },  // band 2
+        { { 64, 128, 128 }, 10 },  // band 3
+        { { 72, 128, 128 }, 12 },  // band 4
+        { { 80, 128, 128 }, 14 }   // band 5
     } }
 #endif  // QUANT_PROFILES > 2
 #endif  // QUANT_PROFILES > 1
diff --git a/av1/common/quant_common.h b/av1/common/quant_common.h
index a2607bf..b4d615b 100644
--- a/av1/common/quant_common.h
+++ b/av1/common/quant_common.h
@@ -70,7 +70,10 @@
 tran_low_t av1_dequant_abscoeff_nuq(int v, int q, const tran_low_t *dq);
 tran_low_t av1_dequant_coeff_nuq(int v, int q, const tran_low_t *dq);
 
-static INLINE int get_dq_profile_from_ctx(int q_ctx) {
+static INLINE int get_dq_profile_from_ctx(int q_ctx, int is_inter,
+                                          PLANE_TYPE plane_type) {
+  if (plane_type == PLANE_TYPE_UV) return 0;
+  if (!is_inter) return QUANT_PROFILES - 1;
   return AOMMIN(q_ctx, QUANT_PROFILES - 1);
 }
 #endif  // CONFIG_NEW_QUANT
diff --git a/av1/decoder/detokenize.c b/av1/decoder/detokenize.c
index fbcf8fe..4dfac3c 100644
--- a/av1/decoder/detokenize.c
+++ b/av1/decoder/detokenize.c
@@ -505,7 +505,8 @@
   const int ctx =
       get_entropy_context(tx_size, pd->above_context + x, pd->left_context + y);
 #if CONFIG_NEW_QUANT
-  int dq = get_dq_profile_from_ctx(ctx);
+  const int ref = is_inter_block(&xd->mi[0]->mbmi);
+  int dq = get_dq_profile_from_ctx(ctx, ref, pd->plane_type);
 #endif  //  CONFIG_NEW_QUANT
 
 #if !CONFIG_ANS
diff --git a/av1/encoder/encodemb.c b/av1/encoder/encodemb.c
index 18fcb37..cf37140 100644
--- a/av1/encoder/encodemb.c
+++ b/av1/encoder/encodemb.c
@@ -96,7 +96,7 @@
 #endif
   const int shift = get_tx_scale(xd, tx_type, tx_size);
 #if CONFIG_NEW_QUANT
-  int dq = get_dq_profile_from_ctx(ctx);
+  int dq = get_dq_profile_from_ctx(ctx, ref, type);
   const dequant_val_type_nuq *dequant_val = pd->dequant_val_nuq[dq];
 #else
   const int dq_step[2] = { dequant_ptr[0] >> shift, dequant_ptr[1] >> shift };
@@ -517,12 +517,12 @@
   const struct macroblockd_plane *const pd = &xd->plane[plane];
   PLANE_TYPE plane_type = (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV;
   TX_TYPE tx_type = get_tx_type(plane_type, xd, block, tx_size);
-  const scan_order *const scan_order =
-      get_scan(tx_size, tx_type, is_inter_block(&xd->mi[0]->mbmi));
+  const int is_inter = is_inter_block(&xd->mi[0]->mbmi);
+  const scan_order *const scan_order = get_scan(tx_size, tx_type, is_inter);
   tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
   tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
   tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
-  int dq = get_dq_profile_from_ctx(ctx);
+  int dq = get_dq_profile_from_ctx(ctx, is_inter, plane_type);
   uint16_t *const eob = &p->eobs[block];
   const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
   const int16_t *src_diff;
@@ -584,11 +584,11 @@
   MACROBLOCKD *const xd = &x->e_mbd;
   const struct macroblock_plane *const p = &x->plane[plane];
   const struct macroblockd_plane *const pd = &xd->plane[plane];
-  int dq = get_dq_profile_from_ctx(ctx);
+  const int is_inter = is_inter_block(&xd->mi[0]->mbmi);
   PLANE_TYPE plane_type = (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV;
   TX_TYPE tx_type = get_tx_type(plane_type, xd, block, tx_size);
-  const scan_order *const scan_order =
-      get_scan(tx_size, tx_type, is_inter_block(&xd->mi[0]->mbmi));
+  const scan_order *const scan_order = get_scan(tx_size, tx_type, is_inter);
+  int dq = get_dq_profile_from_ctx(ctx, is_inter, plane_type);
   tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
   tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
   tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
@@ -660,7 +660,8 @@
   uint16_t *const eob = &p->eobs[block];
   const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
   const int16_t *src_diff;
-  int dq = get_dq_profile_from_ctx(ctx);
+  const int is_inter = is_inter_block(&xd->mi[0]->mbmi);
+  int dq = get_dq_profile_from_ctx(ctx, is_inter, plane_type);
 
   FWD_TXFM_PARAM fwd_txfm_param;
 
@@ -720,7 +721,8 @@
   uint16_t *const eob = &p->eobs[block];
   const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
   const int16_t *src_diff;
-  int dq = get_dq_profile_from_ctx(ctx);
+  const int is_inter = is_inter_block(&xd->mi[0]->mbmi);
+  int dq = get_dq_profile_from_ctx(ctx, is_inter, plane_type);
 
   FWD_TXFM_PARAM fwd_txfm_param;