Commit 54de7d60 authored by Arild Fuldseth (arilfuld)'s avatar Arild Fuldseth (arilfuld) Committed by Arild Fuldseth

Disallow cm->delta_q_present_flag=1 when cm->base_qindex=0.

Delta quant doesn't make sense if the intent is to encode
the frame in lossless mode.

BUG=aomedia:393

Change-Id: Ic26e30267dd3a061d7ee5e980b6950366f06b32f
parent 6ff6af61
......@@ -4352,7 +4352,7 @@ static size_t read_uncompressed_header(AV1Decoder *pbi,
}
cm->delta_q_res = 1;
if (segment_quantizer_active == 0) {
if (segment_quantizer_active == 0 && cm->base_qindex > 0) {
cm->delta_q_present_flag = aom_rb_read_bit(rb);
} else {
cm->delta_q_present_flag = 0;
......
......@@ -890,6 +890,8 @@ static void read_intra_frame_mode_info(AV1_COMMON *const cm,
xd->current_qindex =
xd->prev_qindex +
read_delta_qindex(cm, xd, r, mbmi, mi_col, mi_row) * cm->delta_q_res;
/* Normative: Clamp to [1,MAXQ] to not interfere with lossless mode */
xd->current_qindex = clamp(xd->current_qindex, 1, MAXQ);
xd->prev_qindex = xd->current_qindex;
}
#endif
......@@ -2117,6 +2119,8 @@ static void read_inter_frame_mode_info(AV1Decoder *const pbi,
xd->current_qindex =
xd->prev_qindex +
read_delta_qindex(cm, xd, r, mbmi, mi_col, mi_row) * cm->delta_q_res;
/* Normative: Clamp to [1,MAXQ] to not interfere with lossless mode */
xd->current_qindex = clamp(xd->current_qindex, 1, MAXQ);
xd->prev_qindex = xd->current_qindex;
}
#endif
......
......@@ -1868,7 +1868,7 @@ void av1_init_plane_quantizers(const AV1_COMP *cpi, MACROBLOCK *x,
#if CONFIG_DELTA_Q
int current_q_index = AOMMAX(
0, AOMMIN(QINDEX_RANGE - 1, cpi->oxcf.aq_mode == DELTA_AQ
0, AOMMIN(QINDEX_RANGE - 1, cm->delta_q_present_flag
? cm->base_qindex + xd->delta_qindex
: cm->base_qindex));
const int qindex = av1_get_qindex(&cm->seg, segment_id, current_q_index);
......
......@@ -1604,6 +1604,7 @@ static void pack_inter_mode_mvs(AV1_COMP *cpi, const MODE_INFO *mi,
int super_block_upper_left =
((mi_row & MAX_MIB_MASK) == 0) && ((mi_col & MAX_MIB_MASK) == 0);
if ((bsize != BLOCK_64X64 || skip == 0) && super_block_upper_left) {
assert(mbmi->current_q_index > 0);
int reduced_delta_qindex =
(mbmi->current_q_index - xd->prev_qindex) / cm->delta_q_res;
write_delta_qindex(cm, xd, reduced_delta_qindex, w);
......@@ -1971,6 +1972,7 @@ static void write_mb_modes_kf(AV1_COMMON *cm, const MACROBLOCKD *xd,
if (cm->delta_q_present_flag) {
int super_block_upper_left = ((mi_row & 7) == 0) && ((mi_col & 7) == 0);
if ((bsize != BLOCK_64X64 || skip == 0) && super_block_upper_left) {
assert(mbmi->current_q_index > 0);
int reduced_delta_qindex =
(mbmi->current_q_index - xd->prev_qindex) / cm->delta_q_res;
write_delta_qindex(cm, xd, reduced_delta_qindex, w);
......@@ -4458,8 +4460,10 @@ static void write_uncompressed_header(AV1_COMP *cpi,
segment_quantizer_active = 1;
}
}
if (segment_quantizer_active == 0) {
cm->delta_q_present_flag = cpi->oxcf.aq_mode == DELTA_AQ;
if (cm->delta_q_present_flag)
assert(segment_quantizer_active == 0 && cm->base_qindex > 0);
if (segment_quantizer_active == 0 && cm->base_qindex > 0) {
aom_wb_write_bit(wb, cm->delta_q_present_flag);
if (cm->delta_q_present_flag) {
aom_wb_write_literal(wb, OD_ILOG_NZ(cm->delta_q_res) - 1, 2);
......
......@@ -2035,7 +2035,7 @@ static void update_stats(const AV1_COMMON *const cm, ThreadData *td, int mi_row,
const int dq = (mbmi->current_q_index - xd->prev_qindex) / cm->delta_q_res;
const int absdq = abs(dq);
int i;
for (i = 0; i < absdq; ++i) {
for (i = 0; i < AOMMIN(absdq, DELTA_Q_SMALL); ++i) {
td->counts->delta_q[i][1]++;
}
if (absdq < DELTA_Q_SMALL) td->counts->delta_q[absdq][0]++;
......@@ -4615,7 +4615,7 @@ static void encode_rd_sb_row(AV1_COMP *cpi, ThreadData *td,
}
#if CONFIG_DELTA_Q
if (cpi->oxcf.aq_mode == DELTA_AQ) {
if (cm->delta_q_present_flag) {
// Test mode for delta quantization
int sb_row = mi_row >> 3;
int sb_col = mi_col >> 3;
......@@ -4627,9 +4627,11 @@ static void encode_rd_sb_row(AV1_COMP *cpi, ThreadData *td,
int qmask = ~(cm->delta_q_res - 1);
int current_qindex = clamp(cm->base_qindex + offset_qindex,
cm->delta_q_res, 256 - cm->delta_q_res);
current_qindex =
((current_qindex - cm->base_qindex + cm->delta_q_res / 2) & qmask) +
cm->base_qindex;
assert(current_qindex > 0);
xd->delta_qindex = current_qindex - cm->base_qindex;
set_offsets(cpi, tile_info, x, mi_row, mi_col, BLOCK_64X64);
......@@ -5090,6 +5092,15 @@ static void encode_frame_internal(AV1_COMP *cpi) {
if (!cm->seg.enabled && xd->lossless[0]) x->optimize = 0;
cm->tx_mode = select_tx_mode(cpi, xd);
#if CONFIG_DELTA_Q
// Fix delta q resolution for the moment
cm->delta_q_res = DEFAULT_DELTA_Q_RES;
// Set delta_q_present_flag before it is used for the first time
cm->delta_q_present_flag =
cpi->oxcf.aq_mode == DELTA_AQ && cm->base_qindex > 0;
#endif
av1_frame_init_quantizer(cpi);
av1_initialize_rd_consts(cpi);
......@@ -5110,11 +5121,6 @@ static void encode_frame_internal(AV1_COMP *cpi) {
cm->height == cm->last_height && !cm->intra_only && cm->last_show_frame;
#endif
#if CONFIG_DELTA_Q
// Fix delta q resolution for the moment
cm->delta_q_res = DEFAULT_DELTA_Q_RES;
#endif
#if CONFIG_EXT_REFS
// NOTE(zoeliu): As cm->prev_frame can take neither a frame of
// show_exisiting_frame=1, nor can it take a frame not used as
......
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