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
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index c728491..797a84d 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -111,11 +111,6 @@
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 @@
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);
}
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index df8ba10..925336c 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -193,11 +193,6 @@
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 @@
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);
}
}
}