Commit ca14b47f authored by Sebastien Alaiwan's avatar Sebastien Alaiwan Committed by Fred BARBIER

Use inv_signed_literal to code signed segmentation features

This unifies the coding of signed values in the uncompressed part,
and prevents having one coding for "minus zero".

Change-Id: I3bdc1ab23a33bec0d9a8fe98d5a6bf91df90ff15
parent 95f54928
......@@ -111,11 +111,6 @@ static int read_is_valid(const uint8_t *start, size_t len, const uint8_t *end) {
return len != 0 && len <= (size_t)(end - start);
}
static int decode_unsigned_max(struct aom_read_bit_buffer *rb, int max) {
const int data = aom_rb_read_literal(rb, get_unsigned_bits(max));
return data > max ? max : data;
}
#if CONFIG_SIMPLIFY_TX_MODE
static TX_MODE read_tx_mode(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) {
if (cm->all_lossless) return ONLY_4X4;
......@@ -998,9 +993,18 @@ static void setup_segmentation(AV1_COMMON *const cm,
cm->last_active_segid = i;
#endif
av1_enable_segfeature(seg, i, j);
data = decode_unsigned_max(rb, av1_seg_feature_data_max(j));
if (av1_is_segfeature_signed(j))
data = aom_rb_read_bit(rb) ? -data : data;
const int data_max = av1_seg_feature_data_max(j);
const int data_min = -data_max;
const int ubits = get_unsigned_bits(data_max);
if (av1_is_segfeature_signed(j)) {
data = aom_rb_read_inv_signed_literal(rb, ubits);
} else {
data = aom_rb_read_literal(rb, ubits);
}
data = clamp(data, data_min, data_max);
}
av1_set_segdata(seg, i, j, data);
}
......
......@@ -193,11 +193,6 @@ static void write_inter_compound_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
INTER_COMPOUND_MODES);
}
static void encode_unsigned_max(struct aom_write_bit_buffer *wb, int data,
int max) {
aom_wb_write_literal(wb, data, get_unsigned_bits(max));
}
static void write_tx_size_vartx(const AV1_COMMON *cm, MACROBLOCKD *xd,
const MB_MODE_INFO *mbmi, TX_SIZE tx_size,
int depth, int blk_row, int blk_col,
......@@ -2784,18 +2779,19 @@ static void encode_segmentation(AV1_COMMON *cm, MACROBLOCKD *xd,
const int active = segfeature_active(seg, i, j);
aom_wb_write_bit(wb, active);
if (active) {
const int data = get_segdata(seg, i, j);
const int data_max = av1_seg_feature_data_max(j);
#if CONFIG_SPATIAL_SEGMENTATION
cm->preskip_segid |= j >= SEG_LVL_REF_FRAME;
cm->last_active_segid = i;
#endif
const int data_max = av1_seg_feature_data_max(j);
const int data_min = -data_max;
const int ubits = get_unsigned_bits(data_max);
const int data = clamp(get_segdata(seg, i, j), data_min, data_max);
if (av1_is_segfeature_signed(j)) {
encode_unsigned_max(wb, abs(data), data_max);
aom_wb_write_bit(wb, data < 0);
aom_wb_write_inv_signed_literal(wb, data, ubits);
} else {
encode_unsigned_max(wb, data, data_max);
aom_wb_write_literal(wb, data, ubits);
}
}
}
......
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