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 1653946146 for ; Fri, 7 Jul 2023 14:07:35 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B416168C81A; Fri, 7 Jul 2023 17:06:19 +0300 (EEST) Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01olkn2103.outbound.protection.outlook.com [40.92.107.103]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A1D6468C7F0 for ; Fri, 7 Jul 2023 17:06:14 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CO3b0qk5lR+8GxQlTXJcyylL83/kGL/HJX4CjGdhJtuMPalw82IMFHdrR64dUe+dppk5qrzz6HPZ4QE526rJMMPzgZ14QqZldM5k7+WQ2ai63bw1Jfz4Z2lJVVo+j8nXC/TVMm6u2oKgQNgKuf5ERkRF2lWR9VOFkBh7+291dE37sSQdBAiH0BWCN/Z36ugm73FMddMGbKIDlGE5o21H9uPIEbn7mBdXMNE8Z3C3jgAeyuG2DqyP+BGZO3SfX3MPxMKY86fz1YXoStkUBOH34YaJUo5oEyvKEhGvoEqUYzPi46xLqVo4ou9vi6XXKmuKuL0gigLeiYzj4BMwaMHTNQ== 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=itZqV8xgs6rhsglJZw499/B3Nj0Lbb8Obv/hTWXwzJk=; b=R4kMhnOPaKI0bv4amFQIs5FGa3XYFjQPI3/N8PbGhgajgV07KknUdw4rZLkst0LdFUwi0aJrtNz/NAxWogav9kTmzYCdmu3iyojrMswWq/TkFUJ6sXTs8sRtAn3Jr2uW+sJ47jpsYxqYrvi2yeDLQveuhX7k33lr/SobXYzudQja0LeLQVLiZQVwnRF9OT2gGfs5Co874CGiJ7Gewwhdj1iTX2f7bYJNonVCy0jodQFR/8bTKl+18/oloCEckbUJ71sQtrNtNvcpmwUzo8B3+KGEhVnsAwOmAwoEPjJuYphF0ThG5MBMRYup9fgRPmoGNkQoe+5VNQR9i0VvJYWdMg== 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=itZqV8xgs6rhsglJZw499/B3Nj0Lbb8Obv/hTWXwzJk=; b=LhBERePiKZH/6TCrOjHwUZ/byhGMz5Ad5+ir3do3lC8pFmUsGK6xP0kocwWTeU+hzR6Vm1Ufyarkp+Bg/SEJulwIoboa+VZUwCUF/6+kNUrZkYpxDoHKee4SbegAfukqKnn94nS5GwIki5kV9TJKBwWM+TwAiI3O7Usgo5vfxFjUttlbFnIdGQrw5cBBQt5QF0uNlizPcQBUh9DFQUFDsch31TwcyWV3njc+f0NrasneRpbFXHFRY02T/xScN+w9XZ+47BUvUmVhIdXZTDYn1gUuCAFw9DhoZg8eSx6yA0SfIwFxYAj8yVYfP3V0CA+Wslr1jOOifrwCoh8fUQNbSQ== Received: from TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) by KL1PR0601MB5445.apcprd06.prod.outlook.com (2603:1096:820:c0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.25; Fri, 7 Jul 2023 14:05:59 +0000 Received: from TYSPR06MB6433.apcprd06.prod.outlook.com ([fe80::7d80:1294:fd54:a7f]) by TYSPR06MB6433.apcprd06.prod.outlook.com ([fe80::7d80:1294:fd54:a7f%7]) with mapi id 15.20.6565.016; Fri, 7 Jul 2023 14:05:59 +0000 From: Nuo Mi To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Jul 2023 22:05:37 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230707140540.10279-1-nuomi2021@gmail.com> References: <20230707140540.10279-1-nuomi2021@gmail.com> X-TMN: [lJ2qWO8R7ATmdjagtMbwGMEMD2NCQRGI] X-ClientProxiedBy: TYCP286CA0251.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:456::20) To TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) X-Microsoft-Original-Message-ID: <20230707140540.10279-12-nuomi2021@gmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 2 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYSPR06MB6433:EE_|KL1PR0601MB5445:EE_ X-MS-Office365-Filtering-Correlation-Id: e0f1ed62-66ba-45cf-96f5-08db7ef34a7a X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s8SYWKradJC4hW3VbLWgBl8Cd2E+k7UTcHb2XAPu9w8phwhhJFJHFSjvPMCfQDsDsUj/iyBO+GXjouMc1Qt7okKfvNPP8FMD+/u04bsXhEGmk12Nmc+P7POdxPVRGtZOHYQnDKkMex8u/tT80Wg/9R0X6JINIBtoWGpAGgoH8qsIkvELnsz4MsnA3gRJ/Rdez5LHycCvCVn92F9vaZbDVSagL8XOAXb9f3QLmZtSqrf7mOzV8B+jT+VTAk8vRVEUqptuqbDBDUuSkN111N8zB/rZbdZ+PM6AZSX+5Kt23WXoxP0+7x3JbblzYM3WJRhdCClaftwshQnTSh1Nw7oaAtrGL3FpP7DzAbqEqNI4rjVGsqF65YwoF0rp8OAFym+M4McKYkdEKxrDEm0cB4QU7pXYrumNLeAkwhpN8s5odvWgJUVHUSMf8iiLIFgg/DO3aS1rA/x/Zy8mehATxZWgSAishutnUeu7nuFWPgBY7aHXwA0lJj5P11/+djVIh/NPrjwCuZcbHImTooer1yuddzvuLer9Yef3OQB/eEVCQCejSpUzDM50MMqBuIal/WKac1GXE5Ge7rztwLQwombGbPUsJ5wxK+LZKTm/KATsEFXU23XKFI+ZPLvXne49N+cg X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?xyhDmnMY0bZREZcdC3yDC3fazqGq43cKdLvIJ7Jn8UpHfbYqZMDPX5TCXnzR?= =?us-ascii?Q?zeomYwDOLxWytToxQECaNuawaOOsp4kNv/wsXI6FnhE64ijK0YnXI5W+z4Tt?= =?us-ascii?Q?OrGDoVkD3B0Zzyx6msz84mybJOoHMKEHjwusxsmJBi28TofJcXJ+C1F5UXJk?= =?us-ascii?Q?5TQNabJ22IFtbG/qIqhFFMu/ylVkX6hbBIgBN2w5CqLKfTQE3RbdLqMBDjJy?= =?us-ascii?Q?3tcbj56XxmJInOeNd+cK9kXSXTN8Aox+m1s6WEyf/ADgDQpUxSowVFh4FHVS?= =?us-ascii?Q?8zm9XgNuO+L8oxmwz+u01VwpUOUKhvVLRZspbgJKZn1XofQ9aTQ/A+BYtSPL?= =?us-ascii?Q?uqnHCvz8BYKINahzLLNYzvFZLMwHZQMYPmEQKQGSi+iAHpZCBffOKFiObrGs?= =?us-ascii?Q?0UwhbGmPPpRuRwQJzGADKbQz42gJVm5qh9nFygggiFBQB2FRWnnp6CQsLaFT?= =?us-ascii?Q?FCQcx+JzFTFxF4Q3jr3gPaaIvaAzgo2WXwe5LQPtky1FCFpfsBFy2tFZf62Z?= =?us-ascii?Q?pQAAtnUgQgzNJPsx70p/5h3MJTdLz/Kb8dRpcvXArsweT4w9IbOhHEocRhAF?= =?us-ascii?Q?c04PtH8RlYQQc0U9DsiS/BoCbr/3pR1ClubZzFOAUmRsM+QLDdjHZfI5b+gi?= =?us-ascii?Q?geoNgBJ+y1MipG0PDSxEdYX0uAZlnlq+1ovkRBdWmwhtQRcPkDBfjxGvimog?= =?us-ascii?Q?l7wywi6LdI4YFTscFl2Vc35iFYl3HtPvtQp0+7WdxjoU+Z8ne018r15ySAqN?= =?us-ascii?Q?gcNNzfcqAqMRCeJeZC49fRg7J2uX4KSMRZ1fG/0su/5fZqSeVQSKkysyz0YN?= =?us-ascii?Q?IVqScKrSP8bShEAPlooEnGD6clw4NY9KUz1NX9XZueGZW060CQHMh69vxgT+?= =?us-ascii?Q?15stS9V1qkUMOzbkFup9ioTl8/OQJXzVXIEKaMrdy2cTXznRkd+ljug/V3hC?= =?us-ascii?Q?CfyeuAsiOodW9jKjv7gHKxyYTWTlUFgfm12uZMXqIu72ptiKZa/vFTJDMW3z?= =?us-ascii?Q?fmsCMnsPCudcFiQooT2jJLeuS8dm4E45ZlSp3m0rhevLtSMUVjZdJsTWKdN+?= =?us-ascii?Q?YIlWoNu6JlVNRquYCoas/kkCPgOiLQqGbJzUWD7CrSoZSojTQAK1pvkKjYFq?= =?us-ascii?Q?pDDGwMjYQdM7RQaY9z8cvTWF1ACNlUDZ3YYQUUTqhuFbinEhWL5lB/0MrX4g?= =?us-ascii?Q?6AG3ebt2BP09B6r2Vq3ZDu7C94UiK38tw1ge6YbTGeKEe+CHFwLS4XFBLUja?= =?us-ascii?Q?heACWqF/L1CZgk4h0BoE?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e0f1ed62-66ba-45cf-96f5-08db7ef34a7a X-MS-Exchange-CrossTenant-AuthSource: TYSPR06MB6433.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2023 14:05:59.7254 (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: KL1PR0601MB5445 Subject: [FFmpeg-devel] [PATCH v2 11/14] vvcdec: add dsp init and inv transform 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 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: --- libavcodec/vvc/Makefile | 3 +- libavcodec/vvc/vvcdsp.c | 323 +++++++++++++++++++++++++++++++ libavcodec/vvc/vvcdsp_template.c | 119 ++++++++++++ 3 files changed, 444 insertions(+), 1 deletion(-) create mode 100644 libavcodec/vvc/vvcdsp.c create mode 100644 libavcodec/vvc/vvcdsp_template.c diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile index 32d08ff60b..e8076329f9 100644 --- a/libavcodec/vvc/Makefile +++ b/libavcodec/vvc/Makefile @@ -3,6 +3,7 @@ clean:: OBJS-$(CONFIG_VVC_DECODER) += vvc/vvcdec.o \ executor.o \ + vvc/vvcdsp.o \ vvc/vvc_cabac.o \ vvc/vvc_ctu.o \ vvc/vvc_data.o \ @@ -12,4 +13,4 @@ OBJS-$(CONFIG_VVC_DECODER) += vvc/vvcdec.o \ vvc/vvc_itx_1d.o \ vvc/vvc_mvs.o \ vvc/vvc_ps.o \ - vvc/vvc_refs.o + vvc/vvc_refs.o \ No newline at end of file diff --git a/libavcodec/vvc/vvcdsp.c b/libavcodec/vvc/vvcdsp.c new file mode 100644 index 0000000000..bb1590838d --- /dev/null +++ b/libavcodec/vvc/vvcdsp.c @@ -0,0 +1,323 @@ +/* + * VVC DSP + * + * Copyright (C) 2021 Nuo Mi + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "vvcdsp.h" +#include "vvc_ctu.h" +#include "vvc_itx_1d.h" + +#define VVC_SIGN(v) (v < 0 ? -1 : !!v) + +DECLARE_ALIGNED(16, const int8_t, ff_vvc_chroma_filters)[3][32][4] = { + { + //1x, Table 33 + { 0, 64, 0, 0 }, + { -1, 63, 2, 0 }, + { -2, 62, 4, 0 }, + { -2, 60, 7, -1 }, + { -2, 58, 10, -2 }, + { -3, 57, 12, -2 }, + { -4, 56, 14, -2 }, + { -4, 55, 15, -2 }, + { -4, 54, 16, -2 }, + { -5, 53, 18, -2 }, + { -6, 52, 20, -2 }, + { -6, 49, 24, -3 }, + { -6, 46, 28, -4 }, + { -5, 44, 29, -4 }, + { -4, 42, 30, -4 }, + { -4, 39, 33, -4 }, + { -4, 36, 36, -4 }, + { -4, 33, 39, -4 }, + { -4, 30, 42, -4 }, + { -4, 29, 44, -5 }, + { -4, 28, 46, -6 }, + { -3, 24, 49, -6 }, + { -2, 20, 52, -6 }, + { -2, 18, 53, -5 }, + { -2, 16, 54, -4 }, + { -2, 15, 55, -4 }, + { -2, 14, 56, -4 }, + { -2, 12, 57, -3 }, + { -2, 10, 58, -2 }, + { -1, 7, 60, -2 }, + { 0, 4, 62, -2 }, + { 0, 2, 63, -1 }, + }, + { + //1.5x, Table 34 + { 12, 40, 12, 0 }, + { 11, 40, 13, 0 }, + { 10, 40, 15, -1 }, + { 9, 40, 16, -1 }, + { 8, 40, 17, -1 }, + { 8, 39, 18, -1 }, + { 7, 39, 19, -1 }, + { 6, 38, 21, -1 }, + { 5, 38, 22, -1 }, + { 4, 38, 23, -1 }, + { 4, 37, 24, -1 }, + { 3, 36, 25, 0 }, + { 3, 35, 26, 0 }, + { 2, 34, 28, 0 }, + { 2, 33, 29, 0 }, + { 1, 33, 30, 0 }, + { 1, 31, 31, 1 }, + { 0, 30, 33, 1 }, + { 0, 29, 33, 2 }, + { 0, 28, 34, 2 }, + { 0, 26, 35, 3 }, + { 0, 25, 36, 3 }, + { -1, 24, 37, 4 }, + { -1, 23, 38, 4 }, + { -1, 22, 38, 5 }, + { -1, 21, 38, 6 }, + { -1, 19, 39, 7 }, + { -1, 18, 39, 8 }, + { -1, 17, 40, 8 }, + { -1, 16, 40, 9 }, + { -1, 15, 40, 10 }, + { 0, 13, 40, 11 }, + }, + { + //2x, Table 35 + { 17, 30, 17, 0 }, + { 17, 30, 18, -1 }, + { 16, 30, 18, 0 }, + { 16, 30, 18, 0 }, + { 15, 30, 18, 1 }, + { 14, 30, 18, 2 }, + { 13, 29, 19, 3 }, + { 13, 29, 19, 3 }, + { 12, 29, 20, 3 }, + { 11, 28, 21, 4 }, + { 10, 28, 22, 4 }, + { 10, 27, 22, 5 }, + { 9, 27, 23, 5 }, + { 9, 26, 24, 5 }, + { 8, 26, 24, 6 }, + { 7, 26, 25, 6 }, + { 7, 25, 25, 7 }, + { 6, 25, 26, 7 }, + { 6, 24, 26, 8 }, + { 5, 24, 26, 9 }, + { 5, 23, 27, 9 }, + { 5, 22, 27, 10 }, + { 4, 22, 28, 10 }, + { 4, 21, 28, 11 }, + { 3, 20, 29, 12 }, + { 3, 19, 29, 13 }, + { 3, 19, 29, 13 }, + { 2, 18, 30, 14 }, + { 1, 18, 30, 15 }, + { 0, 18, 30, 16 }, + { 0, 18, 30, 16 }, + { -1, 18, 30, 17 }, + }, +}; + +DECLARE_ALIGNED(16, const int8_t, ff_vvc_luma_filters)[3][16][8] = { + { + //1x, hpelIfIdx == 0, Table 27 + { 0, 0, 0, 64, 0, 0, 0, 0 }, + { 0, 1, -3, 63, 4, -2, 1, 0 }, + { -1, 2, -5, 62, 8, -3, 1, 0 }, + { -1, 3, -8, 60, 13, -4, 1, 0 }, + { -1, 4, -10, 58, 17, -5, 1, 0 }, + { -1, 4, -11, 52, 26, -8, 3, -1 }, + { -1, 3, -9, 47, 31, -10, 4, -1 }, + { -1, 4, -11, 45, 34, -10, 4, -1 }, + { -1, 4, -11, 40, 40, -11, 4, -1 }, + { -1, 4, -10, 34, 45, -11, 4, -1 }, + { -1, 4, -10, 31, 47, -9, 3, -1 }, + { -1, 3, -8, 26, 52, -11, 4, -1 }, + { 0, 1, -5, 17, 58, -10, 4, -1 }, + { 0, 1, -4, 13, 60, -8, 3, -1 }, + { 0, 1, -3, 8, 62, -5, 2, -1 }, + { 0, 1, -2, 4, 63, -3, 1, 0 }, + }, + + { + //1x, hpelIfIdx == 1, Table 27 + { 0, 0, 0, 64, 0, 0, 0, 0 }, + { 0, 1, -3, 63, 4, -2, 1, 0 }, + { -1, 2, -5, 62, 8, -3, 1, 0 }, + { -1, 3, -8, 60, 13, -4, 1, 0 }, + { -1, 4, -10, 58, 17, -5, 1, 0 }, + { -1, 4, -11, 52, 26, -8, 3, -1 }, + { -1, 3, -9, 47, 31, -10, 4, -1 }, + { -1, 4, -11, 45, 34, -10, 4, -1 }, + { 0, 3, 9, 20, 20, 9, 3, 0 }, + { -1, 4, -10, 34, 45, -11, 4, -1 }, + { -1, 4, -10, 31, 47, -9, 3, -1 }, + { -1, 3, -8, 26, 52, -11, 4, -1 }, + { 0, 1, -5, 17, 58, -10, 4, -1 }, + { 0, 1, -4, 13, 60, -8, 3, -1 }, + { 0, 1, -3, 8, 62, -5, 2, -1 }, + { 0, 1, -2, 4, 63, -3, 1, 0 }, + }, + + { + //1x, affine, Table 30 + { 0, 0, 0, 64, 0, 0, 0, 0 }, + { 0, 1, -3, 63, 4, -2, 1, 0 }, + { 0, 1, -5, 62, 8, -3, 1, 0 }, + { 0, 2, -8, 60, 13, -4, 1, 0 }, + { 0, 3, -10, 58, 17, -5, 1, 0 }, + { 0, 3, -11, 52, 26, -8, 2, 0 }, + { 0, 2, -9, 47, 31, -10, 3, 0 }, + { 0, 3, -11, 45, 34, -10, 3, 0 }, + { 0, 3, -11, 40, 40, -11, 3, 0 }, + { 0, 3, -10, 34, 45, -11, 3, 0 }, + { 0, 3, -10, 31, 47, -9, 2, 0 }, + { 0, 2, -8, 26, 52, -11, 3, 0 }, + { 0, 1, -5, 17, 58, -10, 3, 0 }, + { 0, 1, -4, 13, 60, -8, 2, 0 }, + { 0, 1, -3, 8, 62, -5, 1, 0 }, + { 0, 1, -2, 4, 63, -3, 1, 0 }, + }, + +}; + +DECLARE_ALIGNED(16, const int8_t, ff_vvc_dmvr_filters)[16][2] = { + { 16, 0}, + { 15, 1}, + { 14, 2}, + { 13, 3}, + { 12, 4}, + { 11, 5}, + { 10, 6}, + { 9, 7}, + { 8, 8}, + { 7, 9}, + { 6, 10}, + { 5, 11}, + { 4, 12}, + { 3, 13}, + { 2, 14}, + { 1, 15}, +}; + +static void av_always_inline pad_int16(int16_t *_dst, const ptrdiff_t dst_stride, const int width, const int height) +{ + const int padded_width = width + 2; + int16_t *dst; + for (int y = 0; y < height; y++) { + dst = _dst + y * dst_stride; + for (int x = 0; x < width; x++) { + dst[-1] = dst[0]; + dst[width] = dst[width - 1]; + } + } + + _dst--; + //top + memcpy(_dst - dst_stride, _dst, padded_width * sizeof(int16_t)); + //bottom + _dst += dst_stride * height; + memcpy(_dst, _dst - dst_stride, padded_width * sizeof(int16_t)); +} + +static int vvc_sad(const int16_t *src0, const int16_t *src1, int dx, int dy, + const int block_w, const int block_h) +{ + int sad = 0; + dx -= 2; + dy -= 2; + src0 += (2 + dy) * MAX_PB_SIZE + 2 + dx; + src1 += (2 - dy) * MAX_PB_SIZE + 2 - dx; + for (int y = 0; y < block_h; y += 2) { + for (int x = 0; x < block_w; x++) { + sad += FFABS(src0[x] - src1[x]); + } + src0 += 2 * MAX_PB_SIZE; + src1 += 2 * MAX_PB_SIZE; + } + return sad; +} + +#define itx_fn(type, s) \ +static void itx_##type##_##s(int *out, ptrdiff_t out_step, const int *in, ptrdiff_t in_step) \ +{ \ + ff_vvc_inv_##type##_##s(out, out_step, in, in_step); \ +} + +#define itx_fn_common(type) \ + itx_fn(type, 4); \ + itx_fn(type, 8); \ + itx_fn(type, 16); \ + itx_fn(type, 32); \ + +itx_fn_common(dct2); +itx_fn_common(dst7); +itx_fn_common(dct8); +itx_fn(dct2, 2); +itx_fn(dct2, 64); + +typedef struct IntraEdgeParams { + uint8_t* top; + uint8_t* left; + int filter_flag; + + uint16_t left_array[3 * MAX_TB_SIZE + 3]; + uint16_t filtered_left_array[3 * MAX_TB_SIZE + 3]; + uint16_t top_array[3 * MAX_TB_SIZE + 3]; + uint16_t filtered_top_array[3 * MAX_TB_SIZE + 3]; +} IntraEdgeParams; + +#define BIT_DEPTH 8 +#include "vvcdsp_template.c" +#undef BIT_DEPTH + +#define BIT_DEPTH 10 +#include "vvcdsp_template.c" +#undef BIT_DEPTH + +#define BIT_DEPTH 12 +#include "vvcdsp_template.c" +#undef BIT_DEPTH + +void ff_vvc_dsp_init(VVCDSPContext *vvcdsp, int bit_depth) +{ +#undef FUNC +#define FUNC(a, depth) a ## _ ## depth + +#define VVC_DSP(depth) \ + FUNC(ff_vvc_inter_dsp_init, depth)(&vvcdsp->inter); \ + FUNC(ff_vvc_intra_dsp_init, depth)(&vvcdsp->intra); \ + FUNC(ff_vvc_itx_dsp_init, depth)(&vvcdsp->itx); \ + FUNC(ff_vvc_lmcs_dsp_init, depth)(&vvcdsp->lmcs); \ + FUNC(ff_vvc_lf_dsp_init, depth)(&vvcdsp->lf); \ + FUNC(ff_vvc_sao_dsp_init, depth)(&vvcdsp->sao); \ + FUNC(ff_vvc_alf_dsp_init, depth)(&vvcdsp->alf); \ + + switch (bit_depth) { + case 12: + VVC_DSP(12); + break; + case 10: + VVC_DSP(10); + break; + default: + VVC_DSP(8); + break; + } +} diff --git a/libavcodec/vvc/vvcdsp_template.c b/libavcodec/vvc/vvcdsp_template.c new file mode 100644 index 0000000000..d3998e633f --- /dev/null +++ b/libavcodec/vvc/vvcdsp_template.c @@ -0,0 +1,119 @@ +/* + * VVC transform and residual DSP + * + * Copyright (C) 2021 Nuo Mi + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavcodec/bit_depth_template.c" + +#include "vvcdec.h" + +#include "vvc_inter_template.c" +#include "vvc_intra_template.c" +#include "vvc_filter_template.c" + +static void FUNC(add_residual)(uint8_t *_dst, const int *res, + const int w, const int h, const ptrdiff_t _stride) +{ + pixel *dst = (pixel *)_dst; + + const int stride = _stride / sizeof(pixel); + + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + dst[x] = av_clip_pixel(dst[x] + *res); + res++; + } + dst += stride; + } +} + +static void FUNC(add_residual_joint)(uint8_t *_dst, const int *res, + const int w, const int h, const ptrdiff_t _stride, const int c_sign, const int shift) +{ + pixel *dst = (pixel *)_dst; + + const int stride = _stride / sizeof(pixel); + + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + const int r = ((*res) * c_sign) >> shift; + dst[x] = av_clip_pixel(dst[x] + r); + res++; + } + dst += stride; + } +} + +static void FUNC(pred_residual_joint)(int *buf, const int w, const int h, + const int c_sign, const int shift) +{ + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + *buf = ((*buf) * c_sign) >> shift; + buf++; + } + } +} + +static void FUNC(transform_bdpcm)(int *coeffs, const int width, const int height, + const int vertical, const int log2_transform_range) +{ + int x, y; + + if (vertical) { + coeffs += width; + for (y = 0; y < height - 1; y++) { + for (x = 0; x < width; x++) + coeffs[x] = av_clip_intp2(coeffs[x] + coeffs[x - width], log2_transform_range); + coeffs += width; + } + } else { + for (y = 0; y < height; y++) { + for (x = 1; x < width; x++) + coeffs[x] = av_clip_intp2(coeffs[x] + coeffs[x - 1], log2_transform_range); + coeffs += width; + } + } +} + +static void FUNC(ff_vvc_itx_dsp_init)(VVCItxDSPContext *const itx) +{ +#define VVC_ITX(TYPE, type, s) \ + itx->itx[TYPE][TX_SIZE_##s] = itx_##type##_##s; \ + +#define VVC_ITX_COMMON(TYPE, type) \ + VVC_ITX(TYPE, type, 4); \ + VVC_ITX(TYPE, type, 8); \ + VVC_ITX(TYPE, type, 16); \ + VVC_ITX(TYPE, type, 32); + + itx->add_residual = FUNC(add_residual); + itx->add_residual_joint = FUNC(add_residual_joint); + itx->pred_residual_joint = FUNC(pred_residual_joint); + itx->transform_bdpcm = FUNC(transform_bdpcm); + VVC_ITX(DCT2, dct2, 2) + VVC_ITX(DCT2, dct2, 64) + VVC_ITX_COMMON(DCT2, dct2) + VVC_ITX_COMMON(DCT8, dct8) + VVC_ITX_COMMON(DST7, dst7) + +#undef VVC_ITX +#undef VVC_ITX_COMMON +} -- 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".