Add guard against illegal SAO edge offsets.

This commit is contained in:
Ari Koivula 2013-11-08 16:13:48 +02:00
parent 22d21ffac2
commit 692ef3e9d9
2 changed files with 17 additions and 5 deletions

View file

@ -799,11 +799,14 @@ void encode_sao_color(encoder_control *encoder, sao_info *sao, color_index color
if (sao->type != SAO_TYPE_NONE) {
sao_eo_cat i;
for (i = SAO_EO_CAT1; i <= SAO_EO_CAT4; ++i) {
//CABAC_BIN_EP(&cabac, abs(sao->offsets[i]), "sao_offset_abs");
// TR cMax=7 (for 8bit), cRiseParam=0
cabac_write_unary_max_symbol_ep(&cabac, abs(sao->offsets[i]),
SAO_ABS_OFFSET_MAX);
for (i = SAO_EO_CAT1; i <= SAO_EO_CAT2; ++i) {
assert(sao->offsets[i] >= 0);
cabac_write_unary_max_symbol_ep(&cabac, sao->offsets[i], SAO_ABS_OFFSET_MAX);
}
for (i = SAO_EO_CAT3; i <= SAO_EO_CAT4; ++i) {
assert(sao->offsets[i] <= 0);
cabac_write_unary_max_symbol_ep(&cabac, -sao->offsets[i], SAO_ABS_OFFSET_MAX);
}
if (sao->type == SAO_TYPE_BAND) {

View file

@ -249,6 +249,15 @@ void sao_search_best_mode(const pixel *data, const pixel *recdata,
offset = (cat_sum + (cat_cnt >> 1)) / cat_cnt;
offset = CLIP(-SAO_ABS_OFFSET_MAX, SAO_ABS_OFFSET_MAX, offset);
}
// Sharpening edge offsets can't be encoded, so set them to 0 here.
if (edge_cat >= SAO_EO_CAT1 && edge_cat <= SAO_EO_CAT2 && offset < 0) {
offset = 0;
}
if (edge_cat >= SAO_EO_CAT3 && edge_cat <= SAO_EO_CAT4 && offset > 0) {
offset = 0;
}
edge_offset[edge_cat] = offset;
// The ddistortion is amount by which the SSE of data changes. It should
// be negative for all categories, if offset was chosen correctly.