Encoder quantization cleanup.
Change-Id: I633205c95f0e81ce0589580501d0be4425a3cb8e
This commit is contained in:
parent
282f36adc4
commit
220b8f8644
@ -182,7 +182,7 @@ struct macroblockd_plane {
|
|||||||
int subsampling_y;
|
int subsampling_y;
|
||||||
struct buf_2d dst;
|
struct buf_2d dst;
|
||||||
struct buf_2d pre[2];
|
struct buf_2d pre[2];
|
||||||
int16_t *dequant;
|
const int16_t *dequant;
|
||||||
ENTROPY_CONTEXT *above_context;
|
ENTROPY_CONTEXT *above_context;
|
||||||
ENTROPY_CONTEXT *left_context;
|
ENTROPY_CONTEXT *left_context;
|
||||||
};
|
};
|
||||||
|
@ -130,7 +130,8 @@ int16_t vp9_ac_quant(int qindex, int delta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int vp9_get_qindex(struct segmentation *seg, int segment_id, int base_qindex) {
|
int vp9_get_qindex(const struct segmentation *seg, int segment_id,
|
||||||
|
int base_qindex) {
|
||||||
if (vp9_segfeature_active(seg, segment_id, SEG_LVL_ALT_Q)) {
|
if (vp9_segfeature_active(seg, segment_id, SEG_LVL_ALT_Q)) {
|
||||||
const int data = vp9_get_segdata(seg, segment_id, SEG_LVL_ALT_Q);
|
const int data = vp9_get_segdata(seg, segment_id, SEG_LVL_ALT_Q);
|
||||||
return seg->abs_delta == SEGMENT_ABSDATA ?
|
return seg->abs_delta == SEGMENT_ABSDATA ?
|
||||||
|
@ -27,7 +27,8 @@ void vp9_init_quant_tables();
|
|||||||
int16_t vp9_dc_quant(int qindex, int delta);
|
int16_t vp9_dc_quant(int qindex, int delta);
|
||||||
int16_t vp9_ac_quant(int qindex, int delta);
|
int16_t vp9_ac_quant(int qindex, int delta);
|
||||||
|
|
||||||
int vp9_get_qindex(struct segmentation *seg, int segment_id, int base_qindex);
|
int vp9_get_qindex(const struct segmentation *seg, int segment_id,
|
||||||
|
int base_qindex);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
@ -83,55 +83,47 @@ void vp9_quantize_b_32x32_c(const int16_t *coeff_ptr, intptr_t n_coeffs,
|
|||||||
const int16_t *dequant_ptr,
|
const int16_t *dequant_ptr,
|
||||||
int zbin_oq_value, uint16_t *eob_ptr,
|
int zbin_oq_value, uint16_t *eob_ptr,
|
||||||
const int16_t *scan, const int16_t *iscan) {
|
const int16_t *scan, const int16_t *iscan) {
|
||||||
int i, rc, eob;
|
const int zbins[2] = { ROUND_POWER_OF_TWO(zbin_ptr[0] + zbin_oq_value, 1),
|
||||||
int zbins[2], nzbins[2];
|
ROUND_POWER_OF_TWO(zbin_ptr[1] + zbin_oq_value, 1) };
|
||||||
int x, y, z, sz;
|
const int nzbins[2] = {zbins[0] * -1, zbins[1] * -1};
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
int idx_arr[1024];
|
int idx_arr[1024];
|
||||||
|
int i, eob = -1;
|
||||||
|
|
||||||
vpx_memset(qcoeff_ptr, 0, n_coeffs*sizeof(int16_t));
|
vpx_memset(qcoeff_ptr, 0, n_coeffs * sizeof(int16_t));
|
||||||
vpx_memset(dqcoeff_ptr, 0, n_coeffs*sizeof(int16_t));
|
vpx_memset(dqcoeff_ptr, 0, n_coeffs * sizeof(int16_t));
|
||||||
|
|
||||||
eob = -1;
|
|
||||||
|
|
||||||
// Base ZBIN
|
|
||||||
zbins[0] = ROUND_POWER_OF_TWO(zbin_ptr[0] + zbin_oq_value, 1);
|
|
||||||
zbins[1] = ROUND_POWER_OF_TWO(zbin_ptr[1] + zbin_oq_value, 1);
|
|
||||||
nzbins[0] = zbins[0] * -1;
|
|
||||||
nzbins[1] = zbins[1] * -1;
|
|
||||||
|
|
||||||
if (!skip_block) {
|
if (!skip_block) {
|
||||||
// Pre-scan pass
|
// Pre-scan pass
|
||||||
for (i = 0; i < n_coeffs; i++) {
|
for (i = 0; i < n_coeffs; i++) {
|
||||||
rc = scan[i];
|
const int rc = scan[i];
|
||||||
z = coeff_ptr[rc];
|
const int coeff = coeff_ptr[rc];
|
||||||
|
|
||||||
// If the coefficient is out of the base ZBIN range, keep it for
|
// If the coefficient is out of the base ZBIN range, keep it for
|
||||||
// quantization.
|
// quantization.
|
||||||
if (z >= zbins[rc != 0] || z <= nzbins[rc != 0])
|
if (coeff >= zbins[rc != 0] || coeff <= nzbins[rc != 0])
|
||||||
idx_arr[idx++] = i;
|
idx_arr[idx++] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quantization pass: only process the coefficients selected in
|
// Quantization pass: only process the coefficients selected in
|
||||||
// pre-scan pass. Note: idx can be zero.
|
// pre-scan pass. Note: idx can be zero.
|
||||||
for (i = 0; i < idx; i++) {
|
for (i = 0; i < idx; i++) {
|
||||||
rc = scan[idx_arr[i]];
|
const int rc = scan[idx_arr[i]];
|
||||||
|
const int coeff = coeff_ptr[rc];
|
||||||
|
const int coeff_sign = (coeff >> 31);
|
||||||
|
int tmp;
|
||||||
|
int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
|
||||||
|
abs_coeff += ROUND_POWER_OF_TWO(round_ptr[rc != 0], 1);
|
||||||
|
abs_coeff = clamp(abs_coeff, INT16_MIN, INT16_MAX);
|
||||||
|
tmp = ((((abs_coeff * quant_ptr[rc != 0]) >> 16) + abs_coeff) *
|
||||||
|
quant_shift_ptr[rc != 0]) >> 15;
|
||||||
|
|
||||||
z = coeff_ptr[rc];
|
qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign;
|
||||||
sz = (z >> 31); // sign of z
|
dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0] / 2;
|
||||||
x = (z ^ sz) - sz; // x = abs(z)
|
|
||||||
|
|
||||||
x += ROUND_POWER_OF_TWO(round_ptr[rc != 0], 1);
|
if (tmp)
|
||||||
x = clamp(x, INT16_MIN, INT16_MAX);
|
eob = idx_arr[i];
|
||||||
y = ((((x * quant_ptr[rc != 0]) >> 16) + x) *
|
|
||||||
quant_shift_ptr[rc != 0]) >> 15; // quantize (x)
|
|
||||||
|
|
||||||
x = (y ^ sz) - sz; // get the sign back
|
|
||||||
qcoeff_ptr[rc] = x; // write to destination
|
|
||||||
dqcoeff_ptr[rc] = x * dequant_ptr[rc != 0] / 2; // dequantized value
|
|
||||||
|
|
||||||
if (y)
|
|
||||||
eob = idx_arr[i]; // last nonzero coeffs
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*eob_ptr = eob + 1;
|
*eob_ptr = eob + 1;
|
||||||
@ -140,8 +132,8 @@ void vp9_quantize_b_32x32_c(const int16_t *coeff_ptr, intptr_t n_coeffs,
|
|||||||
void vp9_regular_quantize_b_4x4(MACROBLOCK *x, int plane, int block,
|
void vp9_regular_quantize_b_4x4(MACROBLOCK *x, int plane, int block,
|
||||||
const int16_t *scan, const int16_t *iscan) {
|
const int16_t *scan, const int16_t *iscan) {
|
||||||
MACROBLOCKD *const xd = &x->e_mbd;
|
MACROBLOCKD *const xd = &x->e_mbd;
|
||||||
struct macroblock_plane* p = &x->plane[plane];
|
struct macroblock_plane *p = &x->plane[plane];
|
||||||
struct macroblockd_plane* pd = &xd->plane[plane];
|
struct macroblockd_plane *pd = &xd->plane[plane];
|
||||||
|
|
||||||
vp9_quantize_b(BLOCK_OFFSET(p->coeff, block),
|
vp9_quantize_b(BLOCK_OFFSET(p->coeff, block),
|
||||||
16, x->skip_block,
|
16, x->skip_block,
|
||||||
@ -227,38 +219,30 @@ void vp9_init_quantizer(VP9_COMP *cpi) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void vp9_mb_init_quantizer(VP9_COMP *cpi, MACROBLOCK *x) {
|
void vp9_mb_init_quantizer(VP9_COMP *cpi, MACROBLOCK *x) {
|
||||||
int i;
|
const VP9_COMMON *const cm = &cpi->common;
|
||||||
VP9_COMMON *const cm = &cpi->common;
|
|
||||||
MACROBLOCKD *xd = &x->e_mbd;
|
MACROBLOCKD *xd = &x->e_mbd;
|
||||||
int zbin_extra;
|
const int segment_id = xd->mi_8x8[0]->mbmi.segment_id;
|
||||||
int segment_id = xd->mi_8x8[0]->mbmi.segment_id;
|
const int qindex = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex);
|
||||||
const int qindex = vp9_get_qindex(&cpi->common.seg, segment_id,
|
const int rdmult = vp9_compute_rd_mult(cpi, qindex + cm->y_dc_delta_q);
|
||||||
cpi->common.base_qindex);
|
const int zbin = cpi->zbin_mode_boost + x->act_zbin_adj;
|
||||||
|
int i;
|
||||||
int rdmult = vp9_compute_rd_mult(cpi, qindex + cm->y_dc_delta_q);
|
|
||||||
|
|
||||||
// Y
|
// Y
|
||||||
zbin_extra = (cpi->common.y_dequant[qindex][1] *
|
|
||||||
(cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7;
|
|
||||||
|
|
||||||
x->plane[0].quant = cpi->y_quant[qindex];
|
x->plane[0].quant = cpi->y_quant[qindex];
|
||||||
x->plane[0].quant_shift = cpi->y_quant_shift[qindex];
|
x->plane[0].quant_shift = cpi->y_quant_shift[qindex];
|
||||||
x->plane[0].zbin = cpi->y_zbin[qindex];
|
x->plane[0].zbin = cpi->y_zbin[qindex];
|
||||||
x->plane[0].round = cpi->y_round[qindex];
|
x->plane[0].round = cpi->y_round[qindex];
|
||||||
x->plane[0].zbin_extra = (int16_t)zbin_extra;
|
x->plane[0].zbin_extra = (int16_t)((cm->y_dequant[qindex][1] * zbin) >> 7);
|
||||||
x->e_mbd.plane[0].dequant = cpi->common.y_dequant[qindex];
|
xd->plane[0].dequant = cm->y_dequant[qindex];
|
||||||
|
|
||||||
// UV
|
// UV
|
||||||
zbin_extra = (cpi->common.uv_dequant[qindex][1] *
|
|
||||||
(cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7;
|
|
||||||
|
|
||||||
for (i = 1; i < 3; i++) {
|
for (i = 1; i < 3; i++) {
|
||||||
x->plane[i].quant = cpi->uv_quant[qindex];
|
x->plane[i].quant = cpi->uv_quant[qindex];
|
||||||
x->plane[i].quant_shift = cpi->uv_quant_shift[qindex];
|
x->plane[i].quant_shift = cpi->uv_quant_shift[qindex];
|
||||||
x->plane[i].zbin = cpi->uv_zbin[qindex];
|
x->plane[i].zbin = cpi->uv_zbin[qindex];
|
||||||
x->plane[i].round = cpi->uv_round[qindex];
|
x->plane[i].round = cpi->uv_round[qindex];
|
||||||
x->plane[i].zbin_extra = (int16_t)zbin_extra;
|
x->plane[i].zbin_extra = (int16_t)((cm->uv_dequant[qindex][1] * zbin) >> 7);
|
||||||
x->e_mbd.plane[i].dequant = cpi->common.uv_dequant[qindex];
|
xd->plane[i].dequant = cm->uv_dequant[qindex];
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG_ALPHA
|
#if CONFIG_ALPHA
|
||||||
@ -267,18 +251,14 @@ void vp9_mb_init_quantizer(VP9_COMP *cpi, MACROBLOCK *x) {
|
|||||||
x->plane[3].zbin = cpi->a_zbin[qindex];
|
x->plane[3].zbin = cpi->a_zbin[qindex];
|
||||||
x->plane[3].round = cpi->a_round[qindex];
|
x->plane[3].round = cpi->a_round[qindex];
|
||||||
x->plane[3].zbin_extra = (int16_t)zbin_extra;
|
x->plane[3].zbin_extra = (int16_t)zbin_extra;
|
||||||
x->e_mbd.plane[3].dequant = cpi->common.a_dequant[qindex];
|
xd->plane[3].dequant = cm->a_dequant[qindex];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
x->skip_block = vp9_segfeature_active(&cpi->common.seg, segment_id,
|
x->skip_block = vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP);
|
||||||
SEG_LVL_SKIP);
|
|
||||||
|
|
||||||
/* save this macroblock QIndex for vp9_update_zbin_extra() */
|
|
||||||
x->q_index = qindex;
|
x->q_index = qindex;
|
||||||
|
|
||||||
/* R/D setup */
|
x->errorperbit = rdmult >> 6;
|
||||||
cpi->mb.errorperbit = rdmult >> 6;
|
x->errorperbit += (x->errorperbit == 0);
|
||||||
cpi->mb.errorperbit += (cpi->mb.errorperbit == 0);
|
|
||||||
|
|
||||||
vp9_initialize_me_consts(cpi, x->q_index);
|
vp9_initialize_me_consts(cpi, x->q_index);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user