From e4880aa4b7bcca9d3fa29adf4300316465b334cd Mon Sep 17 00:00:00 2001 From: Marko Viitanen Date: Thu, 20 Feb 2014 17:22:33 +0200 Subject: [PATCH] Fixed SAO bitstream generation and band offset a bit --- src/encoder.c | 17 +++++++---------- src/sao.c | 6 ++++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/encoder.c b/src/encoder.c index 74902359..dd81422e 100644 --- a/src/encoder.c +++ b/src/encoder.c @@ -1141,13 +1141,8 @@ void encode_sao_color(encoder_control *encoder, sao_info *sao, color_index color /// sao_offset_abs[][][][]: TR, cMax = (1 << (Min(bitDepth, 10) - 5)) - 1, /// cRiceParam = 0, bins = {bypass x N} - 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); + for (i = SAO_EO_CAT1; i <= SAO_EO_CAT4; ++i) { + cabac_write_unary_max_symbol_ep(&cabac, abs(sao->offsets[i]), SAO_ABS_OFFSET_MAX); } /// sao_offset_sign[][][][]: FL, cMax = 1, bins = {bypass} @@ -1157,11 +1152,13 @@ void encode_sao_color(encoder_control *encoder, sao_info *sao, color_index color if (sao->type == SAO_TYPE_BAND) { for (i = SAO_EO_CAT1; i <= SAO_EO_CAT4; ++i) { // Positive sign is coded as 0. - CABAC_BIN_EP(&cabac, sao->offsets[i] >= 0 ? 0 : 1, "sao_offset_sign"); + if(sao->offsets[i] != 0) { + CABAC_BIN_EP(&cabac, sao->offsets[i] < 0 ? 1 : 0, "sao_offset_sign"); + } } // TODO: sao_band_position - // FL cMax=31 (6 bits) - CABAC_BINS_EP(&cabac, sao->band_position, 6, "sao_band_position"); + // FL cMax=31 (5 bits) + CABAC_BINS_EP(&cabac, sao->band_position, 5, "sao_band_position"); } else if (color_i != COLOR_V) { CABAC_BINS_EP(&cabac, sao->eo_class, 2, "sao_eo_class"); } diff --git a/src/sao.c b/src/sao.c index ea829566..32823919 100644 --- a/src/sao.c +++ b/src/sao.c @@ -73,9 +73,11 @@ int calc_sao_band_offsets(int sao_bands[2][32], int offsets[4], int *band_positi // Calculate distortion for each band using N*h^2 - 2*h*E for (band = 0; band < 32; band++) { best_dist = INT_MAX; - offset = sao_bands[1][band]; + offset = sao_bands[1][band]?sao_bands[0][band]/sao_bands[1][band]:0; + dist[band] = offset==0?0:INT_MAX; + temp_offsets[band] = 0; while(offset != 0) { - temp_dist = sao_bands[0][band]*offset*offset - 2*offset*sao_bands[0][band]; + temp_dist = sao_bands[1][band]*offset*offset - 2*offset*sao_bands[0][band]; // Store best distortion and offset if(temp_dist < best_dist) {