From patchwork Sat Jan 6 10:51:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuo Mi X-Patchwork-Id: 45500 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1093:b0:199:52ba:a72d with SMTP id w19csp587913pze; Sat, 6 Jan 2024 02:52:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHTYjl7pkC9QXNr9WiAxXAQ87RhPLz0qhBY+gs30uxKF4e03b4kdCOluHbFJTNXXk1z9TOw X-Received: by 2002:a50:f69b:0:b0:556:e1ef:4919 with SMTP id d27-20020a50f69b000000b00556e1ef4919mr431214edn.7.1704538357669; Sat, 06 Jan 2024 02:52:37 -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 w9-20020a05640234c900b00553522e101dsi1430773edc.313.2024.01.06.02.52.36; Sat, 06 Jan 2024 02:52:37 -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=YEsViFIl; 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 5FBEE68CCCF; Sat, 6 Jan 2024 12:52:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01olkn2107.outbound.protection.outlook.com [40.92.52.107]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AE76C68CBD2 for ; Sat, 6 Jan 2024 12:52:24 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FqXzBqtZSuNWawJ17V1FhTUci9Yp/n+PyjqcfZRysyaxwAOS1Ms92ohFjZYh1mkhV7XYYlo7EePQspJmSgNPeWysskJUd5k58iHFv0VT96YLMC6hgWSdr1NCMQ3Y/n216sK2mi6lEK6GUO9FZa1UhkJ0WSCQnG8liVDjrIup3frtjpQTJSztlTRQ8GHleAdVbqgXQYit7ZtSq2zX14eq8Oe/XLbtnLZU3xYhX3oGQCJN1cHXyruDV+MDykEd2pCe865x2b7guJnzZky4zhgdJCS73Fq6SRqFiNX0xsmcm63A4NYZzQKbd6v5BQ7jjfPYDdXqCFrSZonF+TBNSMVPWQ== 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=lYsniWZL07Zg/he76G+H360b/a5x8pfq6t6qxxCJUwY=; b=LFqxS9LgRe2ZBYSEkbTHe2AT7YyxSmaccWsGGH5rFonH9KQM1yVNMhsFkn9Po7xvFEpMfp3TBW1b8saGYw6Mcs4u9I26MZbWsQWen4IEqv2AkuYQv5hJHW/Q/jAabo4y4yyEAIb1bri2YkbtIUr1YhMGxHW0rLiEJXKDYMfxV8S06hcJk//W5eyMyHTr8DLD60HDp6niTm9CMDCcSTJOsLF44yyXIYbNB3OryZYCF0RV4MPamLJTwIoRQlDzy6FUfvQ1KVmILupm7sGp8TS3PZvBUDZBjyenMrFYNU+aRlKcaD6Azi3PBXMzyjPgYDY9Zg8Vwb+EQzXfkSwkKcZtmw== 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=lYsniWZL07Zg/he76G+H360b/a5x8pfq6t6qxxCJUwY=; b=YEsViFIl4ldqZyJ+G9YITYgJMtcEcNVFT7WFvPSv7DY5tgkx2pNPHd5VDfYvdjIMlvXF+UBELY1/dM4VUK2gkBv+xWhmtr4SenO5SO9gyrFiN/AOYpJeFSFI2EXTxXATNZaLbgF615SOBk+4ayEUTHApRFe0J9mF7fThpHiR4TcISbYBgBzSkJdhWtSSfS0F1aeNxpa7gjpcpEnLD+bTUOxm8GzmA2gYSv0eZoz5HWJBJOpdVHafGqLZ85DQ92y/IHjux7uoJFEhQK+Z7h9jVsK0z4nUra1Dc1iANKvnEaYttYIzGzLeR0eDKVxuVk6INxoW2xvbAgrSwxnTFqdiXA== Received: from TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) by SI2PR06MB3946.apcprd06.prod.outlook.com (2603:1096:4:ea::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.17; Sat, 6 Jan 2024 10:52:14 +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.018; Sat, 6 Jan 2024 10:52:14 +0000 From: Nuo Mi To: ffmpeg-devel@ffmpeg.org Date: Sat, 6 Jan 2024 18:51:30 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240106105132.31509-1-nuomi2021@gmail.com> References: <20240106105132.31509-1-nuomi2021@gmail.com> X-TMN: [FXPei3q+F2XP+tJpTM/kuuxEH4lhNvmD] X-ClientProxiedBy: TYAPR04CA0003.apcprd04.prod.outlook.com (2603:1096:404:15::15) To TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) X-Microsoft-Original-Message-ID: <20240106105132.31509-2-nuomi2021@gmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 2 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYSPR06MB6433:EE_|SI2PR06MB3946:EE_ X-MS-Office365-Filtering-Correlation-Id: e5e0c012-0506-4842-033a-08dc0ea58aca X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YT9Cilp/jDDzcMd2D7nOfzLZUCwDNllapT2xkfBRlbNx3QrKLZfO4oZdhOy0G6I80UXpCcV2gVGR3EJB0N92iM41c6wq4Pdy+d5mZWKJ7+QHLj8P9EhfdhlZaUQ64pHSuArlr9omd17yLkBfWMUxWGX/UFFo8HVF/h3xx0aBg8GrBcUdUtxziQZg/+tTxSpn4PHokaIeYH7IIv/KFDjEo7Ks8d5dUnTikBqczTgvFJImE/+Hhl9oOEV3RnFEFkOeOWIRPBCdYaGRvifyXY7yurxhkqtmvuF8ELFrR8Dgo9kBfDcLk5YiFdPz0UyeiLFRnZhyeWXJM6dwEPQkyN5UpcqX7lVr4nfGNFJT94Dxny7vW5IJFBFVG82het8/pvn33mVtQrlOuXWj7s5GTnUlYLyrhUf+Qe+KcuLKK0LcrkZGrVyfSyeqLyDZi3LP2oXNBlaJuPKFnXdeSL98NtGiAXZNhGf8QEnxnTrG3UMJ7jeQAPgPiy2yGRvGw60DlFihBYUA/GyhftoZ1EZuUceIvwJ0iIhPvUihoal7V6yaUpKlATa0zBnk3FO6FkXX8OjVoZ2lAErOotyf7SuRO32mVSGUEX16M/+lJ+Vp37JX7SVt2TIN6YtBjz3l7JaWlHF8 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ynO256oYqReyIJdu6ByJoRh/rRkyLmqgKENBt+CJwJy5kv6/7Mw5AjVJcI8gzM2nGb2x2r5vsQ9I6hBfM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cLHqFkkXwTk7ExHmtLlYW1CZMj2+dVr+R/MhZwoSfFYKrXIOZqyj/VMJWCGjUZ6ub0ezotWoFET3ZraPj0kxBg39bgRDxIDI03/1VjAN7J X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e5e0c012-0506-4842-033a-08dc0ea58aca X-MS-Exchange-CrossTenant-AuthSource: TYSPR06MB6433.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2024 10:52:14.3197 (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: SI2PR06MB3946 Subject: [FFmpeg-devel] [PATCH v2 2/4] vvcdec: reuse h26x/h2656_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: OqsnWr+dtcBK --- 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..9418980c33 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/h26x/h2656_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);