Commit bf043127 authored by Debargha Mukherjee's avatar Debargha Mukherjee Committed by Gerrit Code Review
Browse files

Merge "Further changes to new-quant tables" into nextgenv2

parents 0badd020 3c42c096
...@@ -387,6 +387,7 @@ typedef struct macroblockd { ...@@ -387,6 +387,7 @@ typedef struct macroblockd {
int bd; int bd;
#endif #endif
int qindex[MAX_SEGMENTS];
int lossless[MAX_SEGMENTS]; int lossless[MAX_SEGMENTS];
int corrupted; int corrupted;
......
...@@ -131,7 +131,9 @@ extern const av1_extra_bit av1_extra_bits_high12[ENTROPY_TOKENS]; ...@@ -131,7 +131,9 @@ extern const av1_extra_bit av1_extra_bits_high12[ENTROPY_TOKENS];
distinct bands). */ distinct bands). */
#define COEFF_CONTEXTS 6 #define COEFF_CONTEXTS 6
#define BAND_COEFF_CONTEXTS(band) ((band) == 0 ? 3 : COEFF_CONTEXTS) #define COEFF_CONTEXTS0 3 // for band 0
#define BAND_COEFF_CONTEXTS(band) \
((band) == 0 ? COEFF_CONTEXTS0 : COEFF_CONTEXTS)
// #define ENTROPY_STATS // #define ENTROPY_STATS
......
...@@ -36,93 +36,54 @@ typedef struct { ...@@ -36,93 +36,54 @@ typedef struct {
uint8_t doff; // dequantization uint8_t doff; // dequantization
} qprofile_type; } qprofile_type;
   
static const qprofile_type nuq_lossless[COEF_BANDS] = { static const qprofile_type nuq[QUANT_PROFILES][COEF_BANDS] = {
{ { 64, 128, 128 }, 0 }, // dc, band 0 {
{ { 64, 128, 128 }, 0 }, // band 1 // lossless
{ { 64, 128, 128 }, 0 }, // band 2 { { 64, 128, 128 }, 0 }, // dc, band 0
{ { 64, 128, 128 }, 0 }, // band 3 { { 64, 128, 128 }, 0 }, // band 1
{ { 64, 128, 128 }, 0 }, // band 4 { { 64, 128, 128 }, 0 }, // band 2
{ { 64, 128, 128 }, 0 }, // band 5 { { 64, 128, 128 }, 0 }, // band 3
}; { { 64, 128, 128 }, 0 }, // band 4
{ { 64, 128, 128 }, 0 }, // band 5
static const qprofile_type nuq[QUANT_PROFILES][QUANT_RANGES][COEF_BANDS] = { },
{ { {
{ { 64, 128, 128 }, 8 }, // dc, band 0 { { 64, 128, 128 }, 4 }, // dc, band 0
{ { 64, 128, 128 }, 10 }, // band 1 { { 64, 128, 128 }, 6 }, // band 1
{ { 64, 128, 128 }, 12 }, // band 2 { { 64, 128, 128 }, 8 }, // band 2
{ { 72, 128, 128 }, 14 }, // band 3 { { 64, 128, 128 }, 10 }, // band 3
{ { 76, 128, 128 }, 16 }, // band 4 { { 72, 128, 128 }, 12 }, // band 4
{ { 80, 128, 128 }, 18 } // band 5 { { 80, 128, 128 }, 14 } // band 5
}, },
{ {
{ { 64, 128, 128 }, 4 }, // dc, band 0 { { 64, 128, 128 }, 6 }, // dc, band 0
{ { 64, 128, 128 }, 6 }, // band 1 { { 64, 128, 128 }, 8 }, // band 1
{ { 64, 128, 128 }, 8 }, // band 2 { { 64, 128, 128 }, 10 }, // band 2
{ { 64, 128, 128 }, 10 }, // band 3 { { 64, 128, 128 }, 12 }, // band 3
{ { 72, 128, 128 }, 12 }, // band 4 { { 72, 128, 128 }, 14 }, // band 4
{ { 80, 128, 128 }, 14 } // band 5 { { 80, 128, 128 }, 16 } // band 5
} }, },
#if QUANT_PROFILES > 1 {
{ { { { 64, 128, 128 }, 8 }, // dc, band 0
{ { 64, 128, 128 }, 6 }, // dc, band 0 { { 64, 128, 128 }, 10 }, // band 1
{ { 64, 128, 128 }, 8 }, // band 1 { { 64, 128, 128 }, 12 }, // band 2
{ { 64, 128, 128 }, 10 }, // band 2 { { 72, 128, 128 }, 14 }, // band 3
{ { 64, 128, 128 }, 12 }, // band 3 { { 76, 128, 128 }, 16 }, // band 4
{ { 72, 128, 128 }, 14 }, // band 4 { { 80, 128, 128 }, 18 } // band 5
{ { 80, 128, 128 }, 16 } // 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 }, 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 }, 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
}; };
   
static INLINE int qrange_from_qindex(int qindex) { static const uint8_t *get_nuq_knots(int band, int q_profile) {
// return high quality (1) or low quality (0) return nuq[q_profile][band].knots;
return qindex < 140 ? 1 : 0;
} }
   
static const uint8_t *get_nuq_knots(int qindex, int band, int q_profile) { static INLINE int16_t quant_to_doff_fixed(int band, int q_profile) {
if (!qindex) return nuq[q_profile][band].doff;
return nuq_lossless[band].knots;
else
return nuq[q_profile][qrange_from_qindex(qindex)][band].knots;
}
static INLINE int16_t quant_to_doff_fixed(int qindex, int band, int q_profile) {
if (!qindex)
return nuq_lossless[band].doff;
else
return nuq[q_profile][qrange_from_qindex(qindex)][band].doff;
} }
   
// get cumulative bins // get cumulative bins
static INLINE void get_cuml_bins_nuq(int q, int qindex, int band, static INLINE void get_cuml_bins_nuq(int q, int band, tran_low_t *cuml_bins,
tran_low_t *cuml_bins, int q_profile) { int q_profile) {
const uint8_t *knots = get_nuq_knots(qindex, band, q_profile); const uint8_t *knots = get_nuq_knots(band, q_profile);
int16_t cuml_knots[NUQ_KNOTS]; int16_t cuml_knots[NUQ_KNOTS];
int i; int i;
cuml_knots[0] = knots[0]; cuml_knots[0] = knots[0];
...@@ -131,22 +92,22 @@ static INLINE void get_cuml_bins_nuq(int q, int qindex, int band, ...@@ -131,22 +92,22 @@ static INLINE void get_cuml_bins_nuq(int q, int qindex, int band,
cuml_bins[i] = ROUND_POWER_OF_TWO(cuml_knots[i] * q, 7); cuml_bins[i] = ROUND_POWER_OF_TWO(cuml_knots[i] * q, 7);
} }
   
void av1_get_dequant_val_nuq(int q, int qindex, int band, tran_low_t *dq, void av1_get_dequant_val_nuq(int q, int band, tran_low_t *dq,
tran_low_t *cuml_bins, int q_profile) { tran_low_t *cuml_bins, int q_profile) {
const uint8_t *knots = get_nuq_knots(qindex, band, q_profile); const uint8_t *knots = get_nuq_knots(band, q_profile);
tran_low_t cuml_bins_[NUQ_KNOTS], *cuml_bins_ptr; tran_low_t cuml_bins_[NUQ_KNOTS], *cuml_bins_ptr;
tran_low_t doff; tran_low_t doff;
int i; int i;
cuml_bins_ptr = (cuml_bins ? cuml_bins : cuml_bins_); cuml_bins_ptr = (cuml_bins ? cuml_bins : cuml_bins_);
get_cuml_bins_nuq(q, qindex, band, cuml_bins_ptr, q_profile); get_cuml_bins_nuq(q, band, cuml_bins_ptr, q_profile);
dq[0] = 0; dq[0] = 0;
for (i = 1; i < NUQ_KNOTS; ++i) { for (i = 1; i < NUQ_KNOTS; ++i) {
doff = quant_to_doff_fixed(qindex, band, q_profile); doff = quant_to_doff_fixed(band, q_profile);
doff = ROUND_POWER_OF_TWO(doff * knots[i], 7); doff = ROUND_POWER_OF_TWO(doff * knots[i], 7);
dq[i] = dq[i] =
cuml_bins_ptr[i - 1] + ROUND_POWER_OF_TWO((knots[i] - doff * 2) * q, 8); cuml_bins_ptr[i - 1] + ROUND_POWER_OF_TWO((knots[i] - doff * 2) * q, 8);
} }
doff = quant_to_doff_fixed(qindex, band, q_profile); doff = quant_to_doff_fixed(band, q_profile);
dq[NUQ_KNOTS] = dq[NUQ_KNOTS] =
cuml_bins_ptr[NUQ_KNOTS - 1] + ROUND_POWER_OF_TWO((64 - doff) * q, 7); cuml_bins_ptr[NUQ_KNOTS - 1] + ROUND_POWER_OF_TWO((64 - doff) * q, 7);
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "aom/aom_codec.h" #include "aom/aom_codec.h"
#include "av1/common/seg_common.h" #include "av1/common/seg_common.h"
#include "av1/common/enums.h" #include "av1/common/enums.h"
#include "av1/common/entropy.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -45,7 +46,7 @@ int av1_get_qindex(const struct segmentation *seg, int segment_id, ...@@ -45,7 +46,7 @@ int av1_get_qindex(const struct segmentation *seg, int segment_id,
#if CONFIG_AOM_QM #if CONFIG_AOM_QM
// Reduce the large number of quantizers to a smaller number of levels for which // Reduce the large number of quantizers to a smaller number of levels for which
// different matrices may be defined // different matrices may be defined
static inline int aom_get_qmlevel(int qindex, int first, int last) { static INLINE int aom_get_qmlevel(int qindex, int first, int last) {
int qmlevel = (qindex * (last + 1 - first) + QINDEX_RANGE / 2) / QINDEX_RANGE; int qmlevel = (qindex * (last + 1 - first) + QINDEX_RANGE / 2) / QINDEX_RANGE;
qmlevel = AOMMIN(qmlevel + first, NUM_QM_LEVELS - 1); qmlevel = AOMMIN(qmlevel + first, NUM_QM_LEVELS - 1);
return qmlevel; return qmlevel;
...@@ -59,22 +60,41 @@ qm_val_t *aom_qmatrix(struct AV1Common *cm, int qindex, int comp, ...@@ -59,22 +60,41 @@ qm_val_t *aom_qmatrix(struct AV1Common *cm, int qindex, int comp,
#if CONFIG_NEW_QUANT #if CONFIG_NEW_QUANT
#define QUANT_PROFILES 3 #define QUANT_PROFILES 4
#define QUANT_RANGES 2 #define QUANT_RANGES 2
#define NUQ_KNOTS 3 #define NUQ_KNOTS 3
typedef tran_low_t dequant_val_type_nuq[NUQ_KNOTS + 1]; typedef tran_low_t dequant_val_type_nuq[NUQ_KNOTS + 1];
typedef tran_low_t cuml_bins_type_nuq[NUQ_KNOTS]; typedef tran_low_t cuml_bins_type_nuq[NUQ_KNOTS];
void av1_get_dequant_val_nuq(int q, int qindex, int band, tran_low_t *dq, void av1_get_dequant_val_nuq(int q, int band, tran_low_t *dq,
tran_low_t *cuml_bins, int dq_off_index); tran_low_t *cuml_bins, int dq_off_index);
tran_low_t av1_dequant_abscoeff_nuq(int v, int q, const tran_low_t *dq); 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); 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, int is_inter, static INLINE int qindex_to_qrange(int qindex) {
return (qindex < 140 ? 1 : 0);
}
static INLINE int get_dq_profile_from_ctx(int qindex, int q_ctx, int is_inter,
PLANE_TYPE plane_type) { PLANE_TYPE plane_type) {
if (plane_type == PLANE_TYPE_UV) return 0; // intra/inter, Y/UV, ctx, qrange
if (!is_inter) return QUANT_PROFILES - 1; static const int
return AOMMIN(q_ctx, QUANT_PROFILES - 1); def_dq_profile_lookup[REF_TYPES][PLANE_TYPES][COEFF_CONTEXTS0]
[QUANT_RANGES] = {
{
// intra
{ { 2, 1 }, { 2, 1 }, { 2, 1 } }, // Y
{ { 3, 1 }, { 3, 1 }, { 3, 1 } }, // UV
},
{
// inter
{ { 3, 1 }, { 2, 1 }, { 2, 1 } }, // Y
{ { 3, 1 }, { 3, 1 }, { 3, 1 } }, // UV
},
};
if (!qindex) return 0; // lossless
return def_dq_profile_lookup[is_inter][plane_type][q_ctx]
[qindex_to_qrange(qindex)];
} }
#endif // CONFIG_NEW_QUANT #endif // CONFIG_NEW_QUANT
......
...@@ -2120,9 +2120,9 @@ static void setup_segmentation_dequant(AV1_COMMON *const cm) { ...@@ -2120,9 +2120,9 @@ static void setup_segmentation_dequant(AV1_COMMON *const cm) {
#if CONFIG_NEW_QUANT #if CONFIG_NEW_QUANT
for (dq = 0; dq < QUANT_PROFILES; dq++) { for (dq = 0; dq < QUANT_PROFILES; dq++) {
for (b = 0; b < COEF_BANDS; ++b) { for (b = 0; b < COEF_BANDS; ++b) {
av1_get_dequant_val_nuq(cm->y_dequant[i][b != 0], qindex, b, av1_get_dequant_val_nuq(cm->y_dequant[i][b != 0], b,
cm->y_dequant_nuq[i][dq][b], NULL, dq); cm->y_dequant_nuq[i][dq][b], NULL, dq);
av1_get_dequant_val_nuq(cm->uv_dequant[i][b != 0], qindex, b, av1_get_dequant_val_nuq(cm->uv_dequant[i][b != 0], b,
cm->uv_dequant_nuq[i][dq][b], NULL, dq); cm->uv_dequant_nuq[i][dq][b], NULL, dq);
} }
} }
...@@ -2155,9 +2155,9 @@ static void setup_segmentation_dequant(AV1_COMMON *const cm) { ...@@ -2155,9 +2155,9 @@ static void setup_segmentation_dequant(AV1_COMMON *const cm) {
#if CONFIG_NEW_QUANT #if CONFIG_NEW_QUANT
for (dq = 0; dq < QUANT_PROFILES; dq++) { for (dq = 0; dq < QUANT_PROFILES; dq++) {
for (b = 0; b < COEF_BANDS; ++b) { for (b = 0; b < COEF_BANDS; ++b) {
av1_get_dequant_val_nuq(cm->y_dequant[0][b != 0], qindex, b, av1_get_dequant_val_nuq(cm->y_dequant[0][b != 0], b,
cm->y_dequant_nuq[0][dq][b], NULL, dq); cm->y_dequant_nuq[0][dq][b], NULL, dq);
av1_get_dequant_val_nuq(cm->uv_dequant[0][b != 0], qindex, b, av1_get_dequant_val_nuq(cm->uv_dequant[0][b != 0], b,
cm->uv_dequant_nuq[0][dq][b], NULL, dq); cm->uv_dequant_nuq[0][dq][b], NULL, dq);
} }
} }
...@@ -3370,6 +3370,7 @@ static size_t read_uncompressed_header(AV1Decoder *pbi, ...@@ -3370,6 +3370,7 @@ static size_t read_uncompressed_header(AV1Decoder *pbi,
: cm->base_qindex; : cm->base_qindex;
xd->lossless[i] = qindex == 0 && cm->y_dc_delta_q == 0 && xd->lossless[i] = qindex == 0 && cm->y_dc_delta_q == 0 &&
cm->uv_dc_delta_q == 0 && cm->uv_ac_delta_q == 0; cm->uv_dc_delta_q == 0 && cm->uv_ac_delta_q == 0;
xd->qindex[i] = qindex;
} }
} }
......
...@@ -506,7 +506,8 @@ int av1_decode_block_tokens(MACROBLOCKD *const xd, int plane, ...@@ -506,7 +506,8 @@ int av1_decode_block_tokens(MACROBLOCKD *const xd, int plane,
get_entropy_context(tx_size, pd->above_context + x, pd->left_context + y); get_entropy_context(tx_size, pd->above_context + x, pd->left_context + y);
#if CONFIG_NEW_QUANT #if CONFIG_NEW_QUANT
const int ref = is_inter_block(&xd->mi[0]->mbmi); const int ref = is_inter_block(&xd->mi[0]->mbmi);
int dq = get_dq_profile_from_ctx(ctx, ref, pd->plane_type); int dq =
get_dq_profile_from_ctx(xd->qindex[seg_id], ctx, ref, pd->plane_type);
#endif // CONFIG_NEW_QUANT #endif // CONFIG_NEW_QUANT
#if !CONFIG_ANS #if !CONFIG_ANS
......
...@@ -844,6 +844,7 @@ static void choose_partitioning(AV1_COMP *const cpi, ThreadData *const td, ...@@ -844,6 +844,7 @@ static void choose_partitioning(AV1_COMP *const cpi, ThreadData *const td,
if (cyclic_refresh_segment_id_boosted(segment_id)) { if (cyclic_refresh_segment_id_boosted(segment_id)) {
int q = av1_get_qindex(&cm->seg, segment_id, cm->base_qindex); int q = av1_get_qindex(&cm->seg, segment_id, cm->base_qindex);
assert(q == xd->qindex[segment_id]);
set_vbp_thresholds(cpi, thresholds, q); set_vbp_thresholds(cpi, thresholds, q);
} }
} }
...@@ -1597,6 +1598,7 @@ static int set_segment_rdmult(AV1_COMP *const cpi, MACROBLOCK *const x, ...@@ -1597,6 +1598,7 @@ static int set_segment_rdmult(AV1_COMP *const cpi, MACROBLOCK *const x,
av1_init_plane_quantizers(cpi, x, segment_id); av1_init_plane_quantizers(cpi, x, segment_id);
aom_clear_system_state(); aom_clear_system_state();
segment_qindex = av1_get_qindex(&cm->seg, segment_id, cm->base_qindex); segment_qindex = av1_get_qindex(&cm->seg, segment_id, cm->base_qindex);
assert(segment_qindex == x->e_mbd.qindex[segment_id]);
return av1_compute_rd_mult(cpi, segment_qindex + cm->y_dc_delta_q); return av1_compute_rd_mult(cpi, segment_qindex + cm->y_dc_delta_q);
} }
...@@ -4594,6 +4596,7 @@ static void encode_frame_internal(AV1_COMP *cpi) { ...@@ -4594,6 +4596,7 @@ static void encode_frame_internal(AV1_COMP *cpi) {
: cm->base_qindex; : cm->base_qindex;
xd->lossless[i] = qindex == 0 && cm->y_dc_delta_q == 0 && xd->lossless[i] = qindex == 0 && cm->y_dc_delta_q == 0 &&
cm->uv_dc_delta_q == 0 && cm->uv_ac_delta_q == 0; cm->uv_dc_delta_q == 0 && cm->uv_ac_delta_q == 0;
xd->qindex[i] = qindex;
} }
if (!cm->seg.enabled && xd->lossless[0]) x->optimize = 0; if (!cm->seg.enabled && xd->lossless[0]) x->optimize = 0;
...@@ -5126,7 +5129,7 @@ static void encode_superblock(AV1_COMP *cpi, ThreadData *td, TOKENEXTRA **t, ...@@ -5126,7 +5129,7 @@ static void encode_superblock(AV1_COMP *cpi, ThreadData *td, TOKENEXTRA **t,
av1_tokenize_sb(cpi, td, t, !output_enabled, AOMMAX(bsize, BLOCK_8X8)); av1_tokenize_sb(cpi, td, t, !output_enabled, AOMMAX(bsize, BLOCK_8X8));
else else
#endif #endif
av1_tokenize_sb_inter(cpi, td, t, !output_enabled, mi_row, mi_col, av1_tokenize_sb_vartx(cpi, td, t, !output_enabled, mi_row, mi_col,
AOMMAX(bsize, BLOCK_8X8)); AOMMAX(bsize, BLOCK_8X8));
#else #else
av1_tokenize_sb(cpi, td, t, !output_enabled, AOMMAX(bsize, BLOCK_8X8)); av1_tokenize_sb(cpi, td, t, !output_enabled, AOMMAX(bsize, BLOCK_8X8));
......
...@@ -80,29 +80,29 @@ int av1_optimize_b(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size, ...@@ -80,29 +80,29 @@ int av1_optimize_b(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size,
tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
const int eob = p->eobs[block]; const int eob = p->eobs[block];
const PLANE_TYPE type = pd->plane_type; const PLANE_TYPE plane_type = pd->plane_type;
const int default_eob = get_tx2d_size(tx_size); const int default_eob = get_tx2d_size(tx_size);
const int16_t *const dequant_ptr = pd->dequant; const int16_t *const dequant_ptr = pd->dequant;
const uint8_t *const band_translate = get_band_translate(tx_size); const uint8_t *const band_translate = get_band_translate(tx_size);
TX_TYPE tx_type = get_tx_type(type, xd, block, tx_size); TX_TYPE tx_type = get_tx_type(plane_type, xd, block, tx_size);
const scan_order *const so = const scan_order *const so =
get_scan(tx_size, tx_type, is_inter_block(&xd->mi[0]->mbmi)); get_scan(tx_size, tx_type, is_inter_block(&xd->mi[0]->mbmi));
const int16_t *const scan = so->scan; const int16_t *const scan = so->scan;
const int16_t *const nb = so->neighbors; const int16_t *const nb = so->neighbors;
#if CONFIG_AOM_QM #if CONFIG_AOM_QM
int seg_id = xd->mi[0]->mbmi.segment_id; int seg_id = xd->mi[0]->mbmi.segment_id;
int is_intra = !is_inter_block(&xd->mi[0]->mbmi); const qm_val_t *iqmatrix = pd->seg_iqmatrix[seg_id][!ref][tx_size];
const qm_val_t *iqmatrix = pd->seg_iqmatrix[seg_id][is_intra][tx_size];
#endif #endif
const int shift = get_tx_scale(xd, tx_type, tx_size); const int shift = get_tx_scale(xd, tx_type, tx_size);
#if CONFIG_NEW_QUANT #if CONFIG_NEW_QUANT
int dq = get_dq_profile_from_ctx(ctx, ref, type); int dq = get_dq_profile_from_ctx(xd->qindex[xd->mi[0]->mbmi.segment_id], ctx,
ref, plane_type);
const dequant_val_type_nuq *dequant_val = pd->dequant_val_nuq[dq]; const dequant_val_type_nuq *dequant_val = pd->dequant_val_nuq[dq];
#else #else
const int dq_step[2] = { dequant_ptr[0] >> shift, dequant_ptr[1] >> shift }; const int dq_step[2] = { dequant_ptr[0] >> shift, dequant_ptr[1] >> shift };
#endif // CONFIG_NEW_QUANT #endif // CONFIG_NEW_QUANT
int next = eob, sz = 0; int next = eob, sz = 0;
const int64_t rdmult = (mb->rdmult * plane_rd_mult[ref][type]) >> 1; const int64_t rdmult = (mb->rdmult * plane_rd_mult[ref][plane_type]) >> 1;
const int64_t rddiv = mb->rddiv; const int64_t rddiv = mb->rddiv;
int64_t rd_cost0, rd_cost1; int64_t rd_cost0, rd_cost1;
int rate0, rate1; int rate0, rate1;
...@@ -117,15 +117,18 @@ int av1_optimize_b(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size, ...@@ -117,15 +117,18 @@ int av1_optimize_b(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size,
const int *cat6_high_cost = av1_get_high_cost_table(8); const int *cat6_high_cost = av1_get_high_cost_table(8);
#endif #endif
unsigned int(*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] = unsigned int(*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] =
mb->token_costs[txsize_sqr_map[tx_size]][type][ref]; mb->token_costs[txsize_sqr_map[tx_size]][plane_type][ref];
const uint16_t *band_counts = &band_count_table[tx_size][band]; const uint16_t *band_counts = &band_count_table[tx_size][band];
uint16_t band_left = eob - band_cum_count_table[tx_size][band] + 1; uint16_t band_left = eob - band_cum_count_table[tx_size][band] + 1;
int shortcut = 0; int shortcut = 0;
int next_shortcut = 0; int next_shortcut = 0;
assert((xd->qindex[xd->mi[0]->mbmi.segment_id] == 0) ^
(xd->lossless[xd->mi[0]->mbmi.segment_id] == 0));
token_costs += band; token_costs += band;
assert((!type && !plane) || (type && plane)); assert((!plane_type && !plane) || (plane_type && plane));
assert(eob <= default_eob); assert(eob <= default_eob);
/* Now set up a Viterbi trellis to evaluate alternative roundings. */ /* Now set up a Viterbi trellis to evaluate alternative roundings. */
...@@ -443,8 +446,8 @@ void av1_xform_quant(MACROBLOCK *x, int plane, int block, int blk_row, ...@@ -443,8 +446,8 @@ void av1_xform_quant(MACROBLOCK *x, int plane, int block, int blk_row,
const struct macroblockd_plane *const pd = &xd->plane[plane]; const struct macroblockd_plane *const pd = &xd->plane[plane];
PLANE_TYPE plane_type = (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV; 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); TX_TYPE tx_type = get_tx_type(plane_type, xd, block, tx_size);
const scan_order *const scan_order = const int is_inter = is_inter_block(&xd->mi[0]->mbmi);
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);
tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block); tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
...@@ -452,9 +455,8 @@ void av1_xform_quant(MACROBLOCK *x, int plane, int block, int blk_row, ...@@ -452,9 +455,8 @@ void av1_xform_quant(MACROBLOCK *x, int plane, int block, int blk_row,
const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
#if CONFIG_AOM_QM #if CONFIG_AOM_QM
int seg_id = xd->mi[0]->mbmi.segment_id; int seg_id = xd->mi[0]->mbmi.segment_id;
int is_intra = !is_inter_block(&xd->mi[0]->mbmi); const qm_val_t *qmatrix = pd->seg_qmatrix[seg_id][!is_inter][tx_size];
const qm_val_t *qmatrix = pd->seg_qmatrix[seg_id][is_intra][tx_size]; const qm_val_t *iqmatrix = pd->seg_iqmatrix[seg_id][!is_inter][tx_size];
const qm_val_t *iqmatrix = pd->seg_iqmatrix[seg_id][is_intra][tx_size];
#endif #endif
const int16_t *src_diff; const int16_t *src_diff;
const int tx2d_size = get_tx2d_size(tx_size); const int tx2d_size = get_tx2d_size(tx_size);
...@@ -522,7 +524,8 @@ void av1_xform_quant_nuq(MACROBLOCK *x, int plane, int block, int blk_row, ...@@ -522,7 +524,8 @@ void av1_xform_quant_nuq(MACROBLOCK *x, int plane, int block, int blk_row,
tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block); tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
int dq = get_dq_profile_from_ctx(ctx, is_inter, plane_type); int dq = get_dq_profile_from_ctx(xd->qindex[xd->mi[0]->mbmi.segment_id], ctx,
is_inter, plane_type);
uint16_t *const eob = &p->eobs[block]; uint16_t *const eob = &p->eobs[block];
const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
const int16_t *src_diff; const int16_t *src_diff;
...@@ -530,6 +533,9 @@ void av1_xform_quant_nuq(MACROBLOCK *x, int plane, int block, int blk_row, ...@@ -530,6 +533,9 @@ void av1_xform_quant_nuq(MACROBLOCK *x, int plane, int block, int blk_row,
FWD_TXFM_PARAM fwd_txfm_param; FWD_TXFM_PARAM fwd_txfm_param;
assert((xd->qindex[xd->mi[0]->mbmi.segment_id] == 0) ^
(xd->lossless[xd->mi[0]->mbmi.segment_id] == 0));
fwd_txfm_param.tx_type = tx_type; fwd_txfm_param.tx_type = tx_type;
fwd_txfm_param.tx_size = tx_size; fwd_txfm_param.tx_size = tx_size;
fwd_txfm_param.fwd_txfm_opt = fwd_txfm_opt_list[AV1_XFORM_QUANT_FP]; fwd_txfm_param.fwd_txfm_opt = fwd_txfm_opt_list[AV1_XFORM_QUANT_FP];
...@@ -588,7 +594,8 @@ void av1_xform_quant_fp_nuq(MACROBLOCK *x, int plane, int block, int blk_row, ...@@ -588,7 +594,8 @@ void av1_xform_quant_fp_nuq(MACROBLOCK *x, int plane, int block, int blk_row,
PLANE_TYPE plane_type = (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV; 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); 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); 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); int dq = get_dq_profile_from_ctx(xd->qindex[xd->mi[0]->mbmi.segment_id], ctx,
is_inter, plane_type);
tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block); tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
...@@ -599,6 +606,9 @@ void av1_xform_quant_fp_nuq(MACROBLOCK *x, int plane, int block, int blk_row, ...@@ -599,6 +606,9 @@ void av1_xform_quant_fp_nuq(MACROBLOCK *x, int plane, int block, int blk_row,
FWD_TXFM_PARAM fwd_txfm_param; FWD_TXFM_PARAM fwd_txfm_param;
assert((xd->qindex[xd->mi[0]->mbmi.segment_id] == 0) ^
(xd->lossless[xd->mi[0]->mbmi.segment_id] == 0));
fwd_txfm_param.tx_type = tx_type; fwd_txfm_param.tx_type = tx_type;
fwd_txfm_param.tx_size = tx_size; fwd_txfm_param.tx_size = tx_size;
fwd_txfm_param.fwd_txfm_opt = fwd_txfm_opt_list[AV1_XFORM_QUANT_FP]; fwd_txfm_param.fwd_txfm_opt = fwd_txfm_opt_list[AV1_XFORM_QUANT_FP];
...@@ -661,10 +671,14 @@ void av1_xform_quant_dc_nuq(MACROBLOCK *x, int plane, int block, int blk_row, ...@@ -661,10 +671,14 @@ void av1_xform_quant_dc_nuq(MACROBLOCK *x, int plane, int block, int blk_row,
const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
const int16_t *src_diff; const int16_t *src_diff;
const int is_inter = is_inter_block(&xd->mi[0]->mbmi); const int is_inter = is_inter_block(&xd->mi[0]->mbmi);
int dq = get_dq_profile_from_ctx(ctx, is_inter, plane_type); int dq = get_dq_profile_from_ctx(xd->qindex[xd->mi[0]->mbmi.segment_id], ctx,
is_inter, plane_type);
FWD_TXFM_PARAM fwd_txfm_param; FWD_TXFM_PARAM fwd_txfm_param;
assert((xd->qindex[xd->mi[0]->mbmi.segment_id] == 0) ^
(xd->lossless[xd->mi[0]->mbmi.segment_id] == 0));
fwd_txfm_param.tx_type = tx_type; fwd_txfm_param.tx_type = tx_type;
fwd_txfm_param.tx_size = tx_size;