Fix deblocking for luma

This commit is contained in:
Joose Sainio 2021-04-19 12:46:12 +03:00
parent 2ab005692d
commit a12f99b7a3
2 changed files with 18 additions and 17 deletions

View file

@ -950,8 +950,6 @@ static void filter_deblock_edge_chroma(encoder_state_t * const state,
const encoder_control_t * const encoder = state->encoder_control; const encoder_control_t * const encoder = state->encoder_control;
const videoframe_t * const frame = state->tile->frame; const videoframe_t * const frame = state->tile->frame;
if (dir == 0) return;
// For each subpart // For each subpart
{ {
int32_t stride = frame->rec->stride >> 1; int32_t stride = frame->rec->stride >> 1;
@ -1115,7 +1113,8 @@ static void filter_deblock_unit(encoder_state_t * const state,
int width, int width,
int height, int height,
edge_dir dir, edge_dir dir,
bool tu_boundary) bool tu_boundary,
bool previous_ctu)
{ {
// no filtering on borders (where filter would use pixels outside the picture) // no filtering on borders (where filter would use pixels outside the picture)
if (x == 0 && dir == EDGE_VER) return; if (x == 0 && dir == EDGE_VER) return;
@ -1127,10 +1126,10 @@ static void filter_deblock_unit(encoder_state_t * const state,
if (dir == EDGE_HOR) { if (dir == EDGE_HOR) {
const videoframe_t* const frame = state->tile->frame; const videoframe_t* const frame = state->tile->frame;
const int32_t x_right = x + width; const int32_t x_right = x + width;
const bool rightmost_8px_of_lcu = x_right % LCU_WIDTH == 0; const bool rightmost_8px_of_lcu = x_right % LCU_WIDTH == 0 || x_right % LCU_WIDTH == LCU_WIDTH - width;
const bool rightmost_8px_of_frame = x_right == frame->width; const bool rightmost_8px_of_frame = x_right == frame->width;
if (rightmost_8px_of_lcu && !rightmost_8px_of_frame) { if (rightmost_8px_of_lcu && !rightmost_8px_of_frame && !previous_ctu) {
// The last 8 pixels will be deblocked when processing the next LCU. // The last 8 pixels will be deblocked when processing the next LCU.
length = width - 4; length = width - 4;
length_c = (width >> 1) - 2; length_c = (width >> 1) - 2;
@ -1180,7 +1179,7 @@ static void filter_deblock_lcu_inside(encoder_state_t * const state,
for (int edge_x = x; edge_x < end_x; edge_x += 4) { for (int edge_x = x; edge_x < end_x; edge_x += 4) {
bool tu_boundary = is_tu_boundary(state, edge_x, edge_y, dir); bool tu_boundary = is_tu_boundary(state, edge_x, edge_y, dir);
if (tu_boundary || is_pu_boundary(state, edge_x, edge_y, dir)) { if (tu_boundary || is_pu_boundary(state, edge_x, edge_y, dir)) {
filter_deblock_unit(state, edge_x, edge_y, 4, 4, dir, tu_boundary); filter_deblock_unit(state, edge_x, edge_y, 4, 4, dir, tu_boundary, edge_x < x);
} }
} }
} }
@ -1199,8 +1198,8 @@ static void filter_deblock_lcu_rightmost(encoder_state_t * const state,
int32_t y_px) int32_t y_px)
{ {
// Luma // Luma
const int x = x_px - 4;
const int end = MIN(y_px + LCU_WIDTH, state->tile->frame->height); const int end = MIN(y_px + LCU_WIDTH, state->tile->frame->height);
for (int x = x_px - 8; x < x_px; x += 4) {
for (int y = y_px; y < end; y += 4) { for (int y = y_px; y < end; y += 4) {
// The top edge of the whole frame is not filtered. // The top edge of the whole frame is not filtered.
bool tu_boundary = is_tu_boundary(state, x, y, EDGE_HOR); bool tu_boundary = is_tu_boundary(state, x, y, EDGE_HOR);
@ -1209,6 +1208,7 @@ static void filter_deblock_lcu_rightmost(encoder_state_t * const state,
filter_deblock_edge_luma(state, x, y, 4, EDGE_HOR, tu_boundary); filter_deblock_edge_luma(state, x, y, 4, EDGE_HOR, tu_boundary);
} }
} }
}
// Chroma // Chroma
if (state->encoder_control->chroma_format != KVZ_CSP_400) { if (state->encoder_control->chroma_format != KVZ_CSP_400) {

View file

@ -638,6 +638,7 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth,
cur_cu->intra.mode, -1, // skip chroma cur_cu->intra.mode, -1, // skip chroma
NULL, lcu); NULL, lcu);
// TODO: This heavily relies to square CUs
if (depth != 4 || (x % 8 && y % 8) && state->encoder_control->chroma_format != KVZ_CSP_400) { if (depth != 4 || (x % 8 && y % 8) && state->encoder_control->chroma_format != KVZ_CSP_400) {
// There is almost no benefit to doing the chroma mode search for // There is almost no benefit to doing the chroma mode search for
// rd2. Possibly because the luma mode search already takes chroma // rd2. Possibly because the luma mode search already takes chroma
@ -649,7 +650,7 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth,
} }
kvz_intra_recon_cu(state, kvz_intra_recon_cu(state,
x & ~7, y & ~7, x & ~7, y & ~7, // TODO: as does this
depth, depth,
-1, cur_cu->intra.mode_chroma, // skip luma -1, cur_cu->intra.mode_chroma, // skip luma
NULL, lcu); NULL, lcu);