Fix lossless mode with new_quant experiment

Change-Id: Ia0b00746e3f7aacf8d9488db3522ab72d9dc22fd
This commit is contained in:
Debargha Mukherjee 2015-06-04 02:45:54 -07:00
parent f35fb46c48
commit b8a793458a
6 changed files with 57 additions and 24 deletions

View File

@ -389,6 +389,18 @@ static INLINE int partition_plane_context(const MACROBLOCKD *xd,
return (left * 2 + above) + bsl * PARTITION_PLOFFSET;
}
static INLINE int16_t vp9_get_quant(VP9_COMMON *const cm,
int qindex, int isuv, int isac) {
int quant;
if (!isuv) {
quant = isac == 0 ? vp9_dc_quant(qindex, cm->y_dc_delta_q, cm->bit_depth)
: vp9_ac_quant(qindex, 0, cm->bit_depth);
} else {
quant = isac == 0 ? vp9_dc_quant(qindex, cm->uv_dc_delta_q, cm->bit_depth)
: vp9_ac_quant(qindex, cm->uv_ac_delta_q, cm->bit_depth);
}
return quant;
}
#ifdef __cplusplus
} // extern "C"
#endif

View File

@ -29,6 +29,18 @@ int tx_skip_q_thresh_intra = 255;
// There are four sets of values for 4 different quantizer ranges.
//
// TODO(debargha): Optimize these tables
static const uint8_t vp9_nuq_knotes_lossless[COEF_BANDS][NUQ_KNOTES] = {
{64, 128, 128, 128, 128}, // dc, band 0
{64, 128, 128, 128, 128}, // band 1
{64, 128, 128, 128, 128}, // band 2
{64, 128, 128, 128, 128}, // band 3
{64, 128, 128, 128, 128}, // band 4
{64, 128, 128, 128, 128}, // band 5
#if CONFIG_TX_SKIP
{64, 128, 128, 128, 128}, // band 6
#endif // CONFIG_TX_SKIP
};
static const uint8_t vp9_nuq_knotes_tiny[COEF_BANDS][NUQ_KNOTES] = {
{84, 124, 128, 128, 128}, // dc, band 0
{84, 124, 128, 128, 128}, // band 1
@ -85,6 +97,11 @@ static const uint8_t vp9_nuq_knotes_huge[COEF_BANDS][NUQ_KNOTES] = {
#endif // CONFIG_TX_SKIP
};
static const uint8_t vp9_nuq_doff_lossless[COEF_BANDS] = { 0, 0, 0, 0, 0, 0
#if CONFIG_TX_SKIP
, 0
#endif // CONFIG_TX_SKIP
};
static const uint8_t vp9_nuq_doff_tiny[COEF_BANDS] = { 8, 16, 17, 22, 23, 24
#if CONFIG_TX_SKIP
, 8
@ -114,8 +131,11 @@ static const uint8_t vp9_nuq_doff_huge[COEF_BANDS] = { 8, 16, 17, 22, 23, 24
// Allow different quantization profiles in different q ranges,
// to enable entropy-constraints in scalar quantization.
static const uint8_t *get_nuq_knotes(int16_t quant, int band, int bd) {
static const uint8_t *get_nuq_knotes(int16_t quant, int lossless,
int band, int bd) {
const int shift = bd - 8;
if (lossless)
return vp9_nuq_knotes_lossless[band];
if (quant > (512 << shift))
return vp9_nuq_knotes_huge[band];
else if (quant > (256 << shift))
@ -128,8 +148,11 @@ static const uint8_t *get_nuq_knotes(int16_t quant, int band, int bd) {
return vp9_nuq_knotes_tiny[band];
}
static INLINE int16_t quant_to_doff_fixed(int16_t quant, int band, int bd) {
static INLINE int16_t quant_to_doff_fixed(int16_t quant, int lossless,
int band, int bd) {
const int shift = bd - 8;
if (lossless)
return vp9_nuq_doff_lossless[band];
if (quant > (512 << shift))
return vp9_nuq_doff_huge[band];
else if (quant > (256 << shift))
@ -142,9 +165,9 @@ static INLINE int16_t quant_to_doff_fixed(int16_t quant, int band, int bd) {
return vp9_nuq_doff_tiny[band];
}
static INLINE void get_cumbins_nuq(int q, int band, int bd,
static INLINE void get_cumbins_nuq(int q, int lossless, int band, int bd,
tran_low_t *cumbins) {
const uint8_t *knotes = get_nuq_knotes(q, band, bd);
const uint8_t *knotes = get_nuq_knotes(q, lossless, band, bd);
int16_t cumknotes[NUQ_KNOTES];
int i;
cumknotes[0] = knotes[0];
@ -154,22 +177,22 @@ static INLINE void get_cumbins_nuq(int q, int band, int bd,
cumbins[i] = (cumknotes[i] * q + 64) >> 7;
}
void vp9_get_dequant_val_nuq(int q, int band, int bd,
void vp9_get_dequant_val_nuq(int q, int lossless, int band, int bd,
tran_low_t *dq, tran_low_t *cumbins) {
const uint8_t *knotes = get_nuq_knotes(q, band, bd);
const uint8_t *knotes = get_nuq_knotes(q, lossless, band, bd);
tran_low_t cumbins_[NUQ_KNOTES], *cumbins_ptr;
tran_low_t doff;
int i;
cumbins_ptr = (cumbins ? cumbins : cumbins_);
get_cumbins_nuq(q, band, bd, cumbins_ptr);
get_cumbins_nuq(q, lossless, band, bd, cumbins_ptr);
dq[0] = 0;
for (i = 1; i < NUQ_KNOTES; ++i) {
const int16_t qstep = (knotes[i] * q + 64) >> 7;
doff = quant_to_doff_fixed(qstep, band, bd);
doff = quant_to_doff_fixed(qstep, lossless, band, bd);
doff = (2 * doff * qstep + q) / (2 * q);
dq[i] = cumbins_ptr[i - 1] + (((knotes[i] - doff * 2) * q + 128) >> 8);
}
doff = quant_to_doff_fixed(q, band, bd);
doff = quant_to_doff_fixed(q, lossless, band, bd);
dq[NUQ_KNOTES] =
cumbins_ptr[NUQ_KNOTES - 1] + (((64 - doff) * q + 64) >> 7);
}

View File

@ -14,6 +14,7 @@
#include <stdio.h>
#include "vpx/vpx_codec.h"
#include "vp9/common/vp9_common.h"
#include "vp9/common/vp9_seg_common.h"
#ifdef __cplusplus
@ -46,7 +47,7 @@ static INLINE int16_t vp9_round_factor_to_round(int16_t quant,
#define NUQ_KNOTES 5
typedef tran_low_t dequant_val_type_nuq[NUQ_KNOTES + 1];
typedef tran_low_t cumbins_type_nuq[NUQ_KNOTES];
void vp9_get_dequant_val_nuq(int q, int band, int bd,
void vp9_get_dequant_val_nuq(int q, int lossless, int band, int bd,
tran_low_t *dq, tran_low_t *cumbins);
tran_low_t vp9_dequant_abscoeff_nuq(int v, int q, const tran_low_t *dq);
tran_low_t vp9_dequant_coeff_nuq(int v, int q, const tran_low_t *dq);

View File

@ -1336,9 +1336,8 @@ static void dec_build_inter_predictors(MACROBLOCKD *xd, int plane, int block,
#if CONFIG_INTRABC
const int is_intrabc = is_intrabc_mode(mi->mbmi.mode);
struct scale_factors sf1;
int use_highbitdepth = (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH);
#if CONFIG_VP9_HIGHBITDEPTH
int use_highbitdepth = (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH);
vp9_setup_scale_factors_for_frame(&sf1, 64, 64, 64, 64, use_highbitdepth);
#else
vp9_setup_scale_factors_for_frame(&sf1, 64, 64, 64, 64);

View File

@ -2847,10 +2847,10 @@ void vp9_init_dequantizer(VP9_COMMON *cm) {
#if CONFIG_NEW_QUANT
for (b = 0; b < COEF_BANDS; ++b) {
vp9_get_dequant_val_nuq(
cm->y_dequant[q][b != 0], b, cm->bit_depth,
cm->y_dequant[q][b != 0], q == 0, b, cm->bit_depth,
cm->y_dequant_val_nuq[q][b], NULL);
vp9_get_dequant_val_nuq(
cm->uv_dequant[q][b != 0], b, cm->bit_depth,
cm->uv_dequant[q][b != 0], q == 0, b, cm->bit_depth,
cm->uv_dequant_val_nuq[q][b], NULL);
}
#endif // CONFIG_NEW_QUANT
@ -2864,10 +2864,10 @@ void vp9_init_dequantizer(VP9_COMMON *cm) {
#if CONFIG_NEW_QUANT
for (b = 0; b < COEF_BANDS; ++b) {
vp9_get_dequant_val_nuq(
cm->y_dequant_pxd[q][b != 0], b, cm->bit_depth,
cm->y_dequant_pxd[q][b != 0], q == 0, b, cm->bit_depth,
cm->y_dequant_val_nuq_pxd[q][b], NULL);
vp9_get_dequant_val_nuq(
cm->uv_dequant_pxd[q][b != 0], b, cm->bit_depth,
cm->uv_dequant_pxd[q][b != 0], q == 0, b, cm->bit_depth,
cm->uv_dequant_val_nuq_pxd[q][b], NULL);
}
#endif // CONFIG_NEW_QUANT

View File

@ -1964,8 +1964,7 @@ void vp9_init_quantizer(VP9_COMP *cpi) {
const int qrounding_factor_fp = q == 0 ? 64 : (i == 0 ? 48 : 42);
// y
quant = i == 0 ? vp9_dc_quant(q, cm->y_dc_delta_q, cm->bit_depth)
: vp9_ac_quant(q, 0, cm->bit_depth);
quant = vp9_get_quant(cm, q, 0, i > 0);
invert_quant(&quants->y_quant[q][i], &quants->y_quant_shift[q][i], quant);
quants->y_quant_fp[q][i] = (1 << 16) / quant;
quants->y_round_fp[q][i] =
@ -1976,8 +1975,7 @@ void vp9_init_quantizer(VP9_COMP *cpi) {
cm->y_dequant[q][i] = quant;
// uv
quant = i == 0 ? vp9_dc_quant(q, cm->uv_dc_delta_q, cm->bit_depth)
: vp9_ac_quant(q, cm->uv_ac_delta_q, cm->bit_depth);
quant = vp9_get_quant(cm, q, 1, i > 0);
invert_quant(&quants->uv_quant[q][i],
&quants->uv_quant_shift[q][i], quant);
quants->uv_quant_fp[q][i] = (1 << 16) / quant;
@ -1993,10 +1991,10 @@ void vp9_init_quantizer(VP9_COMP *cpi) {
for (i = 0; i < COEF_BANDS; i++) {
const int quant = cm->y_dequant[q][i != 0];
const int uvquant = cm->uv_dequant[q][i != 0];
vp9_get_dequant_val_nuq(quant, i, cm->bit_depth,
vp9_get_dequant_val_nuq(quant, q == 0, i, cm->bit_depth,
cm->y_dequant_val_nuq[q][i],
quants->y_cumbins_nuq[q][i]);
vp9_get_dequant_val_nuq(uvquant, i, cm->bit_depth,
vp9_get_dequant_val_nuq(uvquant, q == 0, i, cm->bit_depth,
cm->uv_dequant_val_nuq[q][i],
quants->uv_cumbins_nuq[q][i]);
}
@ -2044,10 +2042,10 @@ void vp9_init_quantizer(VP9_COMP *cpi) {
for (i = 0; i < COEF_BANDS; i++) {
const int quant = cm->y_dequant_pxd[q][i != 0];
const int uvquant = cm->uv_dequant_pxd[q][i != 0];
vp9_get_dequant_val_nuq(quant, i, cm->bit_depth,
vp9_get_dequant_val_nuq(quant, q == 0, i, cm->bit_depth,
cm->y_dequant_val_nuq_pxd[q][i],
quants->y_cumbins_nuq_pxd[q][i]);
vp9_get_dequant_val_nuq(uvquant, i, cm->bit_depth,
vp9_get_dequant_val_nuq(uvquant, q == 0, i, cm->bit_depth,
cm->uv_dequant_val_nuq_pxd[q][i],
quants->uv_cumbins_nuq_pxd[q][i]);
}