Fixed SAO bitstream generation and band offset a bit

This commit is contained in:
Marko Viitanen 2014-02-20 17:22:33 +02:00
parent 5d946c774a
commit e4880aa4b7
2 changed files with 11 additions and 12 deletions

View file

@ -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, /// sao_offset_abs[][][][]: TR, cMax = (1 << (Min(bitDepth, 10) - 5)) - 1,
/// cRiceParam = 0, bins = {bypass x N} /// cRiceParam = 0, bins = {bypass x N}
for (i = SAO_EO_CAT1; i <= SAO_EO_CAT2; ++i) { for (i = SAO_EO_CAT1; i <= SAO_EO_CAT4; ++i) {
assert(sao->offsets[i] >= 0); cabac_write_unary_max_symbol_ep(&cabac, abs(sao->offsets[i]), SAO_ABS_OFFSET_MAX);
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);
} }
/// sao_offset_sign[][][][]: FL, cMax = 1, bins = {bypass} /// 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) { if (sao->type == SAO_TYPE_BAND) {
for (i = SAO_EO_CAT1; i <= SAO_EO_CAT4; ++i) { for (i = SAO_EO_CAT1; i <= SAO_EO_CAT4; ++i) {
// Positive sign is coded as 0. // 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 // TODO: sao_band_position
// FL cMax=31 (6 bits) // FL cMax=31 (5 bits)
CABAC_BINS_EP(&cabac, sao->band_position, 6, "sao_band_position"); CABAC_BINS_EP(&cabac, sao->band_position, 5, "sao_band_position");
} else if (color_i != COLOR_V) { } else if (color_i != COLOR_V) {
CABAC_BINS_EP(&cabac, sao->eo_class, 2, "sao_eo_class"); CABAC_BINS_EP(&cabac, sao->eo_class, 2, "sao_eo_class");
} }

View file

@ -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 // Calculate distortion for each band using N*h^2 - 2*h*E
for (band = 0; band < 32; band++) { for (band = 0; band < 32; band++) {
best_dist = INT_MAX; 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) { 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 // Store best distortion and offset
if(temp_dist < best_dist) { if(temp_dist < best_dist) {