From 24ecddd2a5d5cab599ad53589dfa288eff16a109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arttu=20Yl=C3=A4-Outinen?= Date: Tue, 1 Aug 2017 15:40:49 +0300 Subject: [PATCH] Fix wrong strides in SAO reconstruction Functions kvz_sao_reconstruct and encoder_sao_reconstruct used frame->width as the stride instead of frame->rec->stride when accessing frame->rec->data. This caused errors when using tiles and SAO. --- src/encoderstate.c | 10 +++++----- src/sao.c | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/encoderstate.c b/src/encoderstate.c index dcbc3849..7f180c35 100644 --- a/src/encoderstate.c +++ b/src/encoderstate.c @@ -351,29 +351,29 @@ static void encoder_sao_reconstruct(const encoder_state_t *const state, // Copy pixels that will be filtered and bordering pixels from right and // below. const int from_index = (lcu->position_px.x + x_offsets[0]) + - (lcu->position_px.y + y_offsets[0]) * frame->width; + (lcu->position_px.y + y_offsets[0]) * frame->rec->stride; const int to_index = x_offsets[0] + y_offsets[0] * SAO_BUF_WIDTH; kvz_pixels_blit(&frame->rec->y[from_index], &sao_buf_y[to_index], width + border_right, height + border_below, - frame->width, + frame->rec->stride, SAO_BUF_WIDTH); if (state->encoder_control->chroma_format != KVZ_CSP_400) { const int from_index_c = (lcu->position_px.x + x_offsets[0])/2 + - (lcu->position_px.y + y_offsets[0])/2 * frame->width/2; + (lcu->position_px.y + y_offsets[0])/2 * frame->rec->stride/2; const int to_index_c = x_offsets[0]/2 + y_offsets[0]/2 * SAO_BUF_WIDTH_C; kvz_pixels_blit(&frame->rec->u[from_index_c], &sao_buf_u[to_index_c], width/2 + border_right, height/2 + border_below, - frame->width/2, + frame->rec->stride/2, SAO_BUF_WIDTH_C); kvz_pixels_blit(&frame->rec->v[from_index_c], &sao_buf_v[to_index_c], width/2 + border_right, height/2 + border_below, - frame->width/2, + frame->rec->stride/2, SAO_BUF_WIDTH_C); } diff --git a/src/sao.c b/src/sao.c index 016d8950..c7d20b26 100644 --- a/src/sao.c +++ b/src/sao.c @@ -291,7 +291,8 @@ void kvz_sao_reconstruct(const encoder_state_t *state, const int frame_width = frame->width >> shift; const int frame_height = frame->height >> shift; - kvz_pixel *output = &frame->rec->data[color][frame_x + frame_y * frame_width]; + const int frame_stride = frame->rec->stride >> shift; + kvz_pixel *output = &frame->rec->data[color][frame_x + frame_y * frame_stride]; if (sao->type == SAO_TYPE_EDGE) { const vector2d_t *offset = g_sao_edge_offsets[sao->eo_class]; @@ -317,7 +318,7 @@ void kvz_sao_reconstruct(const encoder_state_t *state, if (frame_y + offset[0].y < 0 || frame_y + offset[1].y < 0) { // Nothing to do for the topmost row. buffer += stride; - output += frame_width; + output += frame_stride; height -= 1; } } @@ -328,7 +329,7 @@ void kvz_sao_reconstruct(const encoder_state_t *state, output, sao, stride, - frame_width, + frame_stride, width, height, color);