Commit 765bb015 authored by Debargha Mukherjee's avatar Debargha Mukherjee

Refactor to seaprate the enc/dec sides of qprofile

Change-Id: I5100bce92f904e09b6067f5060dee5fdb3118933
parent 84dc6e97
......@@ -21,155 +21,232 @@
// So a value x indicates the bin is actually factor x/128 of the
// nominal quantization step. The width is only
// for one side of zero, so the actual width is twice that.
//
// Functions with nuq correspond to "non uniform quantization"
// TODO(sarahparker, debargha): Optimize these tables
// These are needed only on the encoder side.
static const uint8_t x0_nuq[QUANT_PROFILES][2] = {
{
// lossless
64, 64, // dc, ac
},
typedef struct {
uint8_t zbin; // zero-bin width
uint8_t doff; // dequantization offset
} qprofile_type;
// dq_type = 1
{
// Y/intra, dq_type 1, low quality
64, 64, // dc, ac
},
{
// Y/intra, dq_type 1, high quality
64, 64, // dc, ac
},
{
// UV/intra, dq_type 1, low quality
64, 64, // dc, ac
},
{
// UV/intra, dq_type 1, high quality
64, 64, // dc, ac
},
{
// Y/inter, dq_type 1, low quality
64, 64, // dc, ac
},
{
// Y/inter, dq_type 1, high quality
64, 64, // dc, ac
},
{
// UV/inter, dq_type 1, low quality
64, 64, // dc, ac
},
{
// UV/inter, dq_type 1, high quality
64, 64, // dc, ac
},
static const qprofile_type nuq[QUANT_PROFILES][2] = {
// dq_type = 2
{
// Y/intra, dq_type 2, low quality
72, 72, // dc, ac
},
{
// Y/intra, dq_type 2, high quality
72, 72, // dc, ac
},
{
// UV/intra, dq_type 2, low quality
72, 72, // dc, ac
},
{
// UV/intra, dq_type 2, high quality
72, 72, // dc, ac
},
{
// Y/inter, dq_type 2, low quality
72, 72, // dc, ac
},
{
// Y/inter, dq_type 2, high quality
72, 72, // dc, ac
},
{
// UV/inter, dq_type 2, low quality
72, 72, // dc, ac
},
{
// UV/inter, dq_type 2, high quality
72, 72, // dc, ac
},
// dq_type = 3
{
// Y/intra, dq_type 3, low quality
80, 80, // dc, ac
},
{
// Y/intra, dq_type 3, high quality
82, 82, // dc, ac
},
{
// UV/intra, dq_type 3, low quality
80, 80, // dc, ac
},
{
// UV/intra, dq_type 3, high quality
82, 82, // dc, ac
},
{
// Y/inter, dq_type 3, low quality
80, 80, // dc, ac
},
{
// Y/inter, dq_type 3, high quality
82, 82, // dc, ac
},
{
// UV/inter, dq_type 3, low quality
80, 80, // dc, ac
},
{
// UV/inter, dq_type 3, high quality
82, 82, // dc, ac
},
};
// Offset tables needed on the decoder side
static const int8_t doff_nuq[QUANT_PROFILES][2] = {
{
// lossless
{ 64, 0 }, // dc
{ 64, 0 }, // ac
0, 0, // dc, ac
},
// dq_type = 1
{
// Y/intra, dq_type 1, low quality
{ 64, 4 }, // dc
{ 64, 6 }, // ac
-4, -6, // dc, ac
},
{
// Y/intra, dq_type 1, high quality
{ 64, 2 }, // dc
{ 64, 3 }, // ac
-2, -3, // dc, ac
},
{
// UV/intra, dq_type 1, low quality
{ 64, 4 }, // dc
{ 64, 6 }, // ac
-4, -6, // dc, ac
},
{
// UV/intra, dq_type 1, high quality
{ 64, 2 }, // dc
{ 64, 3 }, // ac
-2, -3, // dc, ac
},
{
// Y/inter, dq_type 1, low quality
{ 64, 4 }, // dc
{ 64, 6 }, // ac
-4, -6, // dc, ac
},
{
// Y/inter, dq_type 1, high quality
{ 64, 3 }, // dc
{ 64, 4 }, // ac
-3, -4, // dc, ac
},
{
// UV/inter, dq_type 1, low quality
{ 64, 4 }, // dc
{ 64, 6 }, // ac
-4, -6, // dc, ac
},
{
// UV/inter, dq_type 1, high quality
{ 64, 3 }, // dc
{ 64, 4 }, // ac
-3, -4, // dc, ac
},
// dq_type = 2
{
// Y/intra, dq_type 2, low quality
{ 72, 12 }, // dc
{ 72, 14 }, // ac
0, -2, // dc, ac
},
{
// Y/intra, dq_type 2, high quality
{ 72, 6 }, // dc
{ 72, 8 }, // ac
5, 3, // dc, ac
},
{
// UV/intra, dq_type 2, low quality
{ 72, 14 }, // dc
{ 72, 16 }, // ac
-1, -3, // dc, ac
},
{
// UV/intra, dq_type 2, high quality
{ 72, 8 }, // dc
{ 72, 10 }, // ac
4, 2, // dc, ac
},
{
// Y/inter, dq_type 2, low quality
{ 72, 16 }, // dc
{ 72, 18 }, // ac
-2, -4, // dc, ac
},
{
// Y/inter, dq_type 2, high quality
{ 72, 10 }, // dc
{ 72, 12 }, // ac
2, 1, // dc, ac
},
{
// UV/inter, dq_type 2, low quality
{ 72, 18 }, // dc
{ 72, 20 }, // ac
-3, -5, // dc, ac
},
{
// UV/inter, dq_type 2, high quality
{ 72, 12 }, // dc
{ 72, 14 }, // ac
1, 0, // dc, ac
},
// dq_type = 3
{
// Y/intra, dq_type 3, low quality
{ 80, 12 }, // dc
{ 80, 14 }, // ac
4, 2, // dc, ac
},
{
// Y/intra, dq_type 3, high quality
{ 82, 6 }, // dc
{ 82, 8 }, // ac
12, 10, // dc, ac
},
{
// UV/intra, dq_type 3, low quality
{ 80, 14 }, // dc
{ 80, 16 }, // ac
2, 0, // dc, ac
},
{
// UV/intra, dq_type 3, high quality
{ 82, 8 }, // dc
{ 82, 10 }, // ac
10, 8, // dc, ac
},
{
// Y/inter, dq_type 3, low quality
{ 80, 16 }, // dc
{ 80, 18 }, // ac
0, -2, // dc, ac
},
{
// Y/inter, dq_type 3, high quality
{ 82, 10 }, // dc
{ 82, 12 }, // ac
8, 6, // dc, ac
},
{
// UV/inter, dq_type 3, low quality
{ 80, 18 }, // dc
{ 80, 20 }, // ac
-2, -4, // dc, ac
},
{
// UV/inter, dq_type 3, high quality
{ 82, 12 }, // dc
{ 82, 14 }, // ac
6, 4, // dc, ac
},
};
static INLINE uint8_t get_nuq_zbin(int is_ac_coeff, int q_profile) {
return nuq[q_profile][is_ac_coeff].zbin;
return x0_nuq[q_profile][is_ac_coeff];
}
static INLINE uint8_t quant_to_doff_fixed(int is_ac_coeff, int q_profile) {
return nuq[q_profile][is_ac_coeff].doff;
static INLINE int8_t quant_to_doff_fixed(int is_ac_coeff, int q_profile) {
return doff_nuq[q_profile][is_ac_coeff];
}
// get zero bin width
......@@ -179,21 +256,19 @@ static INLINE void get_cuml_bins_nuq(int q, int is_ac_coeff,
zbin_width[0] = ROUND_POWER_OF_TWO(zbin * q, 7);
}
void av1_get_dequant_val_nuq(int q, int is_ac_coeff, tran_low_t *dq,
tran_low_t *cuml_bins, int q_profile) {
tran_low_t cuml_bins_[NUQ_KNOTS], *cuml_bins_ptr;
tran_low_t doff;
void av1_get_cuml_bins_nuq(int q, int is_ac_coeff, tran_low_t *cuml_bins,
int q_profile) {
// Get the quantization boundary for the zero bin
const uint8_t zbin = get_nuq_zbin(is_ac_coeff, q_profile);
cuml_bins_ptr = (cuml_bins ? cuml_bins : cuml_bins_);
get_cuml_bins_nuq(q, is_ac_coeff, cuml_bins_ptr, q_profile);
get_cuml_bins_nuq(q, is_ac_coeff, cuml_bins, q_profile);
}
void av1_get_dequant_val_nuq(int q, int is_ac_coeff, tran_low_t *dq,
int q_profile) {
// Get the dequantization offset that will be applied to all non-zero bins.
// This is computed as: ((x0 - 64 - d) / 128) * Q
doff = quant_to_doff_fixed(is_ac_coeff, q_profile);
dq[0] = ROUND_POWER_OF_TWO((zbin - 64 - doff) * q, 7);
dq[1] = ROUND_POWER_OF_TWO((zbin - 64 - doff) * q, 8);
dq[2] = ROUND_POWER_OF_TWO((zbin - 64 - doff) * q, 9);
const tran_low_t doff = quant_to_doff_fixed(is_ac_coeff, q_profile);
dq[0] = ROUND_POWER_OF_TWO_SIGNED(doff * q, 7);
dq[1] = ROUND_POWER_OF_TWO_SIGNED(doff * q, 8);
dq[2] = ROUND_POWER_OF_TWO_SIGNED(doff * q, 9);
}
tran_low_t av1_dequant_abscoeff_nuq(int v, int q, const tran_low_t *dq,
......
......@@ -69,7 +69,9 @@ const qm_val_t *aom_qmatrix(struct AV1Common *cm, int qindex, int comp,
typedef tran_low_t dequant_val_type_nuq[NUQ_KNOTS * 3];
typedef tran_low_t cuml_bins_type_nuq[NUQ_KNOTS];
void av1_get_dequant_val_nuq(int q, int is_ac_coeff, tran_low_t *dq,
tran_low_t *cuml_bins, int dq_off_index);
int dq_off_index);
void av1_get_cuml_bins_nuq(int q, int is_ac_coeff, tran_low_t *cuml_bins,
int q_profile);
tran_low_t av1_dequant_abscoeff_nuq(int v, int q, const tran_low_t *dq,
int shift);
tran_low_t av1_dequant_coeff_nuq(int v, int q, const tran_low_t *dq, int shift);
......
......@@ -1118,11 +1118,11 @@ static void setup_segmentation_dequant(AV1_COMMON *const cm) {
// DC and AC coefs
for (int b = 0; b < 2; ++b) {
av1_get_dequant_val_nuq(cm->y_dequant_QTX[i][b != 0], b,
cm->y_dequant_nuq_QTX[i][dq][b], NULL, dq);
cm->y_dequant_nuq_QTX[i][dq][b], dq);
av1_get_dequant_val_nuq(cm->u_dequant_QTX[i][b != 0], b,
cm->u_dequant_nuq_QTX[i][dq][b], NULL, dq);
cm->u_dequant_nuq_QTX[i][dq][b], dq);
av1_get_dequant_val_nuq(cm->v_dequant_QTX[i][b != 0], b,
cm->v_dequant_nuq_QTX[i][dq][b], NULL, dq);
cm->v_dequant_nuq_QTX[i][dq][b], dq);
}
}
#endif // CONFIG_NEW_QUANT
......
......@@ -1542,14 +1542,17 @@ void av1_build_quantizer(aom_bit_depth_t bit_depth, int y_dc_delta_q,
const int u_quant = deq->u_dequant_QTX[q][i != 0];
const int v_quant = deq->v_dequant_QTX[q][i != 0];
av1_get_dequant_val_nuq(y_quant, i,
deq->y_dequant_val_nuq_QTX[dq][q][i],
quants->y_cuml_bins_nuq[dq][q][i], dq);
deq->y_dequant_val_nuq_QTX[dq][q][i], dq);
av1_get_dequant_val_nuq(u_quant, i,
deq->u_dequant_val_nuq_QTX[dq][q][i],
quants->u_cuml_bins_nuq[dq][q][i], dq);
deq->u_dequant_val_nuq_QTX[dq][q][i], dq);
av1_get_dequant_val_nuq(v_quant, i,
deq->v_dequant_val_nuq_QTX[dq][q][i],
quants->v_cuml_bins_nuq[dq][q][i], dq);
deq->v_dequant_val_nuq_QTX[dq][q][i], dq);
av1_get_cuml_bins_nuq(y_quant, i, quants->y_cuml_bins_nuq[dq][q][i],
dq);
av1_get_cuml_bins_nuq(u_quant, i, quants->u_cuml_bins_nuq[dq][q][i],
dq);
av1_get_cuml_bins_nuq(v_quant, i, quants->v_cuml_bins_nuq[dq][q][i],
dq);
}
}
#endif // CONFIG_NEW_QUANT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment