From patchwork Wed Jan 3 15:32:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuo Mi X-Patchwork-Id: 45458 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6623:b0:194:e134:edd4 with SMTP id n35csp7327815pzh; Wed, 3 Jan 2024 07:33:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IEfp928OKO1LM77DXEia8WLoT5CMqNl/+d5yOOHU3WdG1T7WcmO56EpgnMCMSK+cWaru817 X-Received: by 2002:a05:6402:3113:b0:556:ecf7:d3a1 with SMTP id dc19-20020a056402311300b00556ecf7d3a1mr15160edb.111.1704296018289; Wed, 03 Jan 2024 07:33:38 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q6-20020a056402518600b00553366d0746si12777602edd.439.2024.01.03.07.33.37; Wed, 03 Jan 2024 07:33:38 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=dlDyJRsP; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1D89568CC40; Wed, 3 Jan 2024 17:33:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01olkn2033.outbound.protection.outlook.com [40.92.107.33]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1C20468CC51 for ; Wed, 3 Jan 2024 17:33:16 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VlnGiKThWg0HT5YiOrgwQk6KiWXnzKkInJDYRCPq5kPlIeiAahe4RH5QPEYZN+bj2ryigJu5Y8Ndpp1jY5V+c9L/gb5xNm2nueS7cgmU0sq1KalIewTVxq7yuj3sNpOKdwqjLwPYkNTAdhVby6w0Ek1TEuNY0tZ4bAFY2/LxGuYP7YHXVoJHIt+NwLy5tskheotGhyMk2ndvbOpkxtJAcSySxebW+NbTZRndRo5Juh8TbJbW7FQw1JFYnbokqU3IoXm+5JybCON9FmEKuADNXEGHnCcWmPHgD7hB8tAFHmQ4dF9qttnAnTc2I7rDVovYYonGIlvLuMTT5pcpTIlY1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=n7Bv6JhmnWXk+G26rodRSTEcv0Ur2BgUR5TvaWshbC4=; b=KUKqSTqkm0oeeWyfJbTJeT2NaO7U/sU4byadCrYBQt0PkfMLBTkVegHxNbzwHzyansTptxrft7tIVZhHvDfmSXA1gWOnwdOc/gwLmw5LKQIsR5fMgK8GdlYjN7rkHbA8suuLm4YG33ab5X9sngeshL8Qt4CL60bMZHUOyTagGPLTzeD5lhCU/QddxV0Vh+9laaDocGDx4dAd2zy6gAMoxX3gP6zhNmviGV1fZP+qFLCHKkpgQCTl1hoPyTxASdv0VqjPmERPU8+5O0DU5a98sG08k/JaZ28ecoIifWJ/nZREXyY06oq4ak+v3QE+zQrl3y3Q4uckOWTDd6Pjde3Ysg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=n7Bv6JhmnWXk+G26rodRSTEcv0Ur2BgUR5TvaWshbC4=; b=dlDyJRsPZKmQg8e0gxvc0B9HSb1v8D+alM4es9hLGbH+2PfFdEzB/O7mxIOq7iVmbYHufyg71XQVYNV/mfAqin1f1yE0Ni8kAfGm60Mp0nDKMjTT+nsKTHgkuvYuxFnOt2hmw1p4l6vy6zZ9dVi7PV+/VTu20+5QyaKw9CLvn/9ku+//RcZEABbrS/uBWYge2ZxEP9OCxbSSeAHYUKHVKHM2wgYKLgctoCkMrfqvt+Y2qBTKccLjHPLDey/1GTk2gaeFxP1XqwnVtMu+LTPIwLkcsO41pdtuzW9ylMSU86w58tpgUK3I3itp9K6BVQe82HQzVlctteqzi5f0XtJOxg== Received: from TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) by SEYPR06MB5085.apcprd06.prod.outlook.com (2603:1096:101:55::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.13; Wed, 3 Jan 2024 15:33:01 +0000 Received: from TYSPR06MB6433.apcprd06.prod.outlook.com ([fe80::e139:fd7a:1b66:a3f7]) by TYSPR06MB6433.apcprd06.prod.outlook.com ([fe80::e139:fd7a:1b66:a3f7%7]) with mapi id 15.20.7159.013; Wed, 3 Jan 2024 15:33:01 +0000 From: Nuo Mi To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Jan 2024 23:32:36 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240103153238.18678-1-nuomi2021@gmail.com> References: <20240103153238.18678-1-nuomi2021@gmail.com> X-TMN: [25Av/KVDVKtze2urEVHU3mHibV5oe8Yb] X-ClientProxiedBy: SI1PR02CA0008.apcprd02.prod.outlook.com (2603:1096:4:1f7::14) To TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) X-Microsoft-Original-Message-ID: <20240103153238.18678-3-nuomi2021@gmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 2 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYSPR06MB6433:EE_|SEYPR06MB5085:EE_ X-MS-Office365-Filtering-Correlation-Id: e3f5e4ab-8a7f-45ec-15fe-08dc0c714565 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +9XxcjUraklmLq5GMeVlX6DNTH1mzp/Ckp78XBigAhSw1T6t627PUW1rsNp4dbjsHT7ySwwoOPh3Gwjq/PC+2DvdN1ekqMliddz9q5lauNhGZMMWhcOLVkuWthrSn/nMu/za4nqhHZWPwaaNMxrHa2ovgbs7AiKPMsHhNVCAuBi30d/yDoCZ6tfKh8tiutOcJ/tfd5kZTHG0lU59We2pbpvkz72Jkj89KlLfRy8F1EtaZlSSSuEQ6ck+DwgbyTCOOYtt8bbRWZYY7u2IEjNyKgVh6RSOEqqAC9QdzOd1PKhsTudU1ekkByAr8c00HgkIuAWGTeLi+27yReSqrJsFjI84rMZNlIhRzQUNdf7e2oE0rv5+3P2VTXfEZzkEzxulIo+vQKOMf3rX+RN+BU1AmAWMc7ip5Hdih7rXL6Z33qaQIOdiAJmzTFNhuwPBVwYeXZk4bcHp0kBKtgG2BFPz5nhV3rc5QKFg9gmJgAI8VvYuDYCotMuy4tU9CFcuGbu8xB1h8/WB3YVdOeWbLg6YEHuCZtDWKZG0i05ysCVG2rtsBeVmioWapt+38SJWZrA5ypvHRifM059FCO0m113DTp4rlskrga++f0LCeJBU6Rw90OFrCot6Bp2giuup9VuG X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jI6BUlyfLVao0AJp6AIXMtNWTsYjVvW4UtBjXUSXIAvvE9iBkeqcezDuSfcwITWtq/XtbUb/GHKwhy2+epPMBoxCNqVXrI+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Q6scTiaeJvVnvBUWDt75BXEy/a89i6alwaCH5cXGOSgdAK3HwdXSn60Ird2/huq59g+tkmMO60AhD0SvaIIsiXotX4hwDT3UAlCpacApq X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e3f5e4ab-8a7f-45ec-15fe-08dc0c714565 X-MS-Exchange-CrossTenant-AuthSource: TYSPR06MB6433.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2024 15:33:01.7574 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR06MB5085 Subject: [FFmpeg-devel] [PATCH 2/4] vvcdec: reuse xvc_sao_template.c 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: Nuo Mi Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 4DqvmT5N1OGg --- libavcodec/vvc/vvc_filter_template.c | 193 +-------------------------- 1 file changed, 2 insertions(+), 191 deletions(-) diff --git a/libavcodec/vvc/vvc_filter_template.c b/libavcodec/vvc/vvc_filter_template.c index a4f1792ec4..04eb9702dc 100644 --- a/libavcodec/vvc/vvc_filter_template.c +++ b/libavcodec/vvc/vvc_filter_template.c @@ -20,6 +20,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavcodec/xvc_sao_template.c" + static void FUNC(lmcs_filter_luma)(uint8_t *_dst, ptrdiff_t dst_stride, const int width, const int height, const uint8_t *_lut) { const pixel *lut = (const pixel *)_lut; @@ -33,197 +35,6 @@ static void FUNC(lmcs_filter_luma)(uint8_t *_dst, ptrdiff_t dst_stride, const in } } -static void FUNC(sao_band_filter)(uint8_t *_dst, const uint8_t *_src, ptrdiff_t dst_stride, ptrdiff_t src_stride, - const int16_t *sao_offset_val, const int sao_left_class, const int width, const int height) -{ - pixel *dst = (pixel *)_dst; - const pixel *src = (pixel *)_src; - int offset_table[32] = { 0 }; - int k, y, x; - int shift = BIT_DEPTH - 5; - - dst_stride /= sizeof(pixel); - src_stride /= sizeof(pixel); - - for (k = 0; k < 4; k++) - offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1]; - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) - dst[x] = av_clip_pixel(src[x] + offset_table[src[x] >> shift]); - dst += dst_stride; - src += src_stride; - } -} - -#define CMP(a, b) (((a) > (b)) - ((a) < (b))) - -static void FUNC(sao_edge_filter)(uint8_t *_dst, const uint8_t *_src, ptrdiff_t dst_stride, - const int16_t *sao_offset_val, const int eo, const int width, const int height) -{ - static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 }; - static const int8_t pos[4][2][2] = { - { { -1, 0 }, { 1, 0 } }, // horizontal - { { 0, -1 }, { 0, 1 } }, // vertical - { { -1, -1 }, { 1, 1 } }, // 45 degree - { { 1, -1 }, { -1, 1 } }, // 135 degree - }; - pixel *dst = (pixel *)_dst; - const pixel *src = (pixel *)_src; - int a_stride, b_stride; - int x, y; - ptrdiff_t src_stride = (2 * MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / sizeof(pixel); - dst_stride /= sizeof(pixel); - - a_stride = pos[eo][0][0] + pos[eo][0][1] * src_stride; - b_stride = pos[eo][1][0] + pos[eo][1][1] * src_stride; - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - int diff0 = CMP(src[x], src[x + a_stride]); - int diff1 = CMP(src[x], src[x + b_stride]); - int offset_val = edge_idx[2 + diff0 + diff1]; - dst[x] = av_clip_pixel(src[x] + sao_offset_val[offset_val]); - } - src += src_stride; - dst += dst_stride; - } -} - -static void FUNC(sao_edge_restore_0)(uint8_t *_dst, const uint8_t *_src, - ptrdiff_t dst_stride, ptrdiff_t src_stride, const SAOParams *sao, - const int *borders, const int _width, const int _height, const int c_idx, - const uint8_t *vert_edge, const uint8_t *horiz_edge, const uint8_t *diag_edge) -{ - int x, y; - pixel *dst = (pixel *)_dst; - const pixel *src = (pixel *)_src; - const int16_t *sao_offset_val = sao->offset_val[c_idx]; - const int sao_eo_class = sao->eo_class[c_idx]; - int init_x = 0, width = _width, height = _height; - - dst_stride /= sizeof(pixel); - src_stride /= sizeof(pixel); - - if (sao_eo_class != SAO_EO_VERT) { - if (borders[0]) { - int offset_val = sao_offset_val[0]; - for (y = 0; y < height; y++) { - dst[y * dst_stride] = av_clip_pixel(src[y * src_stride] + offset_val); - } - init_x = 1; - } - if (borders[2]) { - int offset_val = sao_offset_val[0]; - int offset = width - 1; - for (x = 0; x < height; x++) { - dst[x * dst_stride + offset] = av_clip_pixel(src[x * src_stride + offset] + offset_val); - } - width--; - } - } - if (sao_eo_class != SAO_EO_HORIZ) { - if (borders[1]) { - int offset_val = sao_offset_val[0]; - for (x = init_x; x < width; x++) - dst[x] = av_clip_pixel(src[x] + offset_val); - } - if (borders[3]) { - int offset_val = sao_offset_val[0]; - ptrdiff_t y_dst_stride = dst_stride * (height - 1); - ptrdiff_t y_src_stride = src_stride * (height - 1); - for (x = init_x; x < width; x++) - dst[x + y_dst_stride] = av_clip_pixel(src[x + y_src_stride] + offset_val); - height--; - } - } -} - -static void FUNC(sao_edge_restore_1)(uint8_t *_dst, const uint8_t *_src, - ptrdiff_t dst_stride, ptrdiff_t src_stride, const SAOParams *sao, - const int *borders, const int _width, const int _height, const int c_idx, - const uint8_t *vert_edge, const uint8_t *horiz_edge, const uint8_t *diag_edge) -{ - int x, y; - pixel *dst = (pixel *)_dst; - const pixel *src = (pixel *)_src; - const int16_t *sao_offset_val = sao->offset_val[c_idx]; - const int sao_eo_class = sao->eo_class[c_idx]; - int init_x = 0, init_y = 0, width = _width, height = _height; - - dst_stride /= sizeof(pixel); - src_stride /= sizeof(pixel); - - if (sao_eo_class != SAO_EO_VERT) { - if (borders[0]) { - int offset_val = sao_offset_val[0]; - for (y = 0; y < height; y++) { - dst[y * dst_stride] = av_clip_pixel(src[y * src_stride] + offset_val); - } - init_x = 1; - } - if (borders[2]) { - int offset_val = sao_offset_val[0]; - int offset = width - 1; - for (x = 0; x < height; x++) { - dst[x * dst_stride + offset] = av_clip_pixel(src[x * src_stride + offset] + offset_val); - } - width--; - } - } - if (sao_eo_class != SAO_EO_HORIZ) { - if (borders[1]) { - int offset_val = sao_offset_val[0]; - for (x = init_x; x < width; x++) - dst[x] = av_clip_pixel(src[x] + offset_val); - init_y = 1; - } - if (borders[3]) { - int offset_val = sao_offset_val[0]; - ptrdiff_t y_dst_stride = dst_stride * (height - 1); - ptrdiff_t y_src_stride = src_stride * (height - 1); - for (x = init_x; x < width; x++) - dst[x + y_dst_stride] = av_clip_pixel(src[x + y_src_stride] + offset_val); - height--; - } - } - - { - int save_upper_left = !diag_edge[0] && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1]; - int save_upper_right = !diag_edge[1] && sao_eo_class == SAO_EO_45D && !borders[1] && !borders[2]; - int save_lower_right = !diag_edge[2] && sao_eo_class == SAO_EO_135D && !borders[2] && !borders[3]; - int save_lower_left = !diag_edge[3] && sao_eo_class == SAO_EO_45D && !borders[0] && !borders[3]; - - // Restore pixels that can't be modified - if (vert_edge[0] && sao_eo_class != SAO_EO_VERT) { - for (y = init_y + save_upper_left; y < height - save_lower_left; y++) - dst[y * dst_stride] = src[y * src_stride]; - } - if (vert_edge[1] && sao_eo_class != SAO_EO_VERT) { - for (y = init_y + save_upper_right; y < height - save_lower_right; y++) - dst[y * dst_stride + width - 1] = src[y * src_stride + width - 1]; - } - - if (horiz_edge[0] && sao_eo_class != SAO_EO_HORIZ) { - for (x = init_x + save_upper_left; x < width - save_upper_right; x++) - dst[x] = src[x]; - } - if (horiz_edge[1] && sao_eo_class != SAO_EO_HORIZ) { - for (x = init_x + save_lower_left; x < width - save_lower_right; x++) - dst[(height - 1) * dst_stride + x] = src[(height - 1) * src_stride + x]; - } - if (diag_edge[0] && sao_eo_class == SAO_EO_135D) - dst[0] = src[0]; - if (diag_edge[1] && sao_eo_class == SAO_EO_45D) - dst[width - 1] = src[width - 1]; - if (diag_edge[2] && sao_eo_class == SAO_EO_135D) - dst[dst_stride * (height - 1) + width - 1] = src[src_stride * (height - 1) + width - 1]; - if (diag_edge[3] && sao_eo_class == SAO_EO_45D) - dst[dst_stride * (height - 1)] = src[src_stride * (height - 1)]; - - } -} - -#undef CMP - static av_always_inline int16_t FUNC(alf_clip)(pixel curr, pixel v0, pixel v1, int16_t clip) { return av_clip(v0 - curr, -clip, clip) + av_clip(v1 - curr, -clip, clip);