From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 2B47D422C8 for ; Fri, 17 Dec 2021 08:46:56 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F1AC168AE77; Fri, 17 Dec 2021 10:46:53 +0200 (EET) Received: from v02.bc.feishu.cn (v02.bc.feishu.cn [101.36.218.27]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1DC0B68A255 for ; Fri, 17 Dec 2021 10:46:46 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=s1; d=bytedance-com.20200927.dkim.feishu.cn; t=1639730797; h=mime-version:from:date:message-id:subject:to; bh=BGwArzVcZtPQDFcQiPIApMRj13MbMUOzwVp7mtPQpsY=; b=cBFTJoYWlmlxZlDm7KZ0F0xcR+sC8rjkdhw2Vy6+YDv+RqB276euDa6try03WrT04rUvM0 NSgSqVf7fuktWn+49WAZgfOVK25S6yFJprTvbuNBoDQU3b3FdNiLSt9Jz7SCNrkrlucROG x1bEtp1Kfhgo3vcDah8xLGi4pp7ddcLpeXuirKOXwmGl6amVaiO5P98pVdEj3uXVwCKLag 0FFzXiBRLU/Pa/iPIIbR8Z7HJKFX2d+UgUZulao0LMcIV2gTX/k3znVApFaBx1AjgPPtjS HqB0qrUOTFOuAqJugNpqGsJcKQ3IxzWEEQ6dygb1m86Idu7oC00I+fYgs927jA== Message-Id: <20211217084611.3234-1-huangzhexiong@bytedance.com> X-Mailer: git-send-email 2.25.1 Date: Fri, 17 Dec 2021 16:46:37 +0800 Mime-Version: 1.0 To: From: "Zhexiong Huang" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [FFmpeg-devel] [PATCH] avcodec/hevcdec: fix the order of in-loop filters X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Zhexiong Huang Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: As we know, in-loop filters in HEVC are applied by the following ordered steps: firstly deblocking filter, then sample adaptive offset filter if enabled. However, in the current version of FFmpeg, pixels without being deblocking-filtered could be used by SAO filter when CTU size is 16 and chroma format is 4:2:0 or 4:2:2, which could lead to the wrong result in chroma components. This patch changes the algorithm of deblocking filter, which ensures that SAO filter is applied after deblocking filter for all the related pixels. The new algorithm fixes this decoding problem when CTU size is 16, and shall not affect performance and correctness when CTU size is 32 or 64. Signed-off-by: Zhexiong Huang --- libavcodec/hevc_filter.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libavcodec/hevc_filter.c b/libavcodec/hevc_filter.c index 3c45b5a39e..c53875d85f 100644 --- a/libavcodec/hevc_filter.c +++ b/libavcodec/hevc_filter.c @@ -512,10 +512,10 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) x_end2 = x_end; if (x_end2 != s->ps.sps->width) - x_end2 -= 8; + x_end2 += 8; for (y = y0; y < y_end; y += 8) { // vertical filtering luma - for (x = x0 ? x0 : 8; x < x_end; x += 8) { + for (x = x0 + 8; x < x_end2; x += 8) { const int bs0 = s->vertical_bs[(x + y * s->bs_width) >> 2]; const int bs1 = s->vertical_bs[(x + (y + 4) * s->bs_width) >> 2]; if (bs0 || bs1) { @@ -545,7 +545,7 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) continue; // horizontal filtering luma - for (x = x0 ? x0 - 8 : 0; x < x_end2; x += 8) { + for (x = x0; x < x_end; x += 8) { const int bs0 = s->horizontal_bs[( x + y * s->bs_width) >> 2]; const int bs1 = s->horizontal_bs[((x + 4) + y * s->bs_width) >> 2]; if (bs0 || bs1) { @@ -579,9 +579,13 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) int h = 1 << s->ps.sps->hshift[chroma]; int v = 1 << s->ps.sps->vshift[chroma]; + x_end2 = x_end; + if (x_end2 != s->ps.sps->width) + x_end2 += 8 * h; + // vertical filtering chroma for (y = y0; y < y_end; y += (8 * v)) { - for (x = x0 ? x0 : 8 * h; x < x_end; x += (8 * h)) { + for (x = x0 + 8 * h; x < x_end2; x += (8 * h)) { const int bs0 = s->vertical_bs[(x + y * s->bs_width) >> 2]; const int bs1 = s->vertical_bs[(x + (y + (4 * v)) * s->bs_width) >> 2]; @@ -612,10 +616,7 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) // horizontal filtering chroma tc_offset = x0 ? left_tc_offset : cur_tc_offset; - x_end2 = x_end; - if (x_end != s->ps.sps->width) - x_end2 = x_end - 8 * h; - for (x = x0 ? x0 - 8 * h : 0; x < x_end2; x += (8 * h)) { + for (x = x0; x < x_end; x += (8 * h)) { const int bs0 = s->horizontal_bs[( x + y * s->bs_width) >> 2]; const int bs1 = s->horizontal_bs[((x + 4 * h) + y * s->bs_width) >> 2]; if ((bs0 == 2) || (bs1 == 2)) { -- 2.25.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".