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 2651C47BFD for ; Wed, 3 Jan 2024 15:33:25 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BFE1568CC3E; Wed, 3 Jan 2024 17:33:16 +0200 (EET) 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 4875F68CBF3 for ; Wed, 3 Jan 2024 17:33:10 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kfrC/sPpDUuxzfA3QWvS7T4zQm7cSL6uc2PYNP8DZq48bEstza2b/UW2jcpPvzfl2P5WoPEe3KWee0U5rN93Q8KuHNFwuXvPp/wUgUTtw5SS21LSfBu8qXSlaMYl1mMRgCB3v2EodE4Wwrk5YsHDC9ROv3u3J5tuBktsNP34n5arGWQMtjmxW+AcHrfScuy3DcuCg1/DrAnl3wPpevQ/SARprsE7VJX/AWWpNv8VHNKa4j2bOXgHJ77Lytb8zBE8dpm07LQsTlopKMifp3VjEyRyMFm7znqGCFkxHCvj0ZjerOUU0NvZNu1lPhqo1I9cxsY3AK0oms8nUf4kOLa3nA== 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=XNB+mcIHQdQsk/4jqZ62ubrukdlM4dvtbVYEvxoBkzY=; b=aoVnWp9YF86FTu4xm2qU6X57OOCJ8LZhQ8x0qGOgeI17x1+wCqb5NovJbGCKJn4JEtyGsH4h/LL8INsZjroG+wR4nof2j416QffLlFg4Wizem0RbN0ql08K25vqlhH8tBVg0SAoboP12jFZl32kYG0/kdZjl191GDsxm/oOa7vv2vu64ct3BGFp32kI2jnERgI3xmbJnIlOjp0I0z97cOD8pJLKrNh0FpRRD3fwRFK78ACaEnHMFhZh6g663xcKHNrYPzpNdIZjc6JM3zEJ0Ud75dgNDtc+7Dj+xbdvgNaaVtwH2iO8YnCIqQbuihzvQaDHTAQMZKxheQTMnnqiiPA== 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=XNB+mcIHQdQsk/4jqZ62ubrukdlM4dvtbVYEvxoBkzY=; b=cfm/fWpMBuKB4GePiJJBpcatNVXe0wnrkqWnCDPYxfdV3e7P+IVMbWQk+CBiSAJIUukorImem+SFmgoihIsInPDBRmHTPuaV0a3a6nCohwNxgPwZLPNEh0b47GMjsrT4WerDtHacMGtsWmh8tUWosRXM5oXLgCX9QlLYFxQ8E8PZYdmxHrfLeQ230AHDDBEsWqZ8omekZypWlsahkVteLDyGpQZPTORIo+vkkpP1/GPYi9G0LSrX8CoqvK+KYkD0rY/ox6W46K2V9Ku2BTSDoYplunimlkc3v+N7T9pnaDti8EekVn+ZSjDiqFnibUivRe6+Krm6S3IiTPJpNOY5bg== 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:00 +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:00 +0000 From: Nuo Mi To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Jan 2024 23:32:35 +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: [6H5kCR+WcZ0sWQ++yrHY8OSmY4cjP5d4] 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-2-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: 74ad18b8-8a12-4667-438f-08dc0c7144b2 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vdyaweFncocUBYXc3Px3LvCrpYL21PXPEG7KiUfqJ+D3dEMB2gezY9a1smW8MtkcDE8myft2WHwjPNiY9qVSpWlMvfeOqVOQUWfZdBU5Vfs35Q7pTmZMaErgd0H8mopSlIzyUmAQT1m6KsNiDHq8y9iszCKuydK2sOi17hrtZNlBEvxpiQbIqeuRB0Y4PE7zysFzjBnaG1COreqUpBCTIdfhi4SP6oMnZsvRQJcP1xCoZRVOJvS4k+Dg4XsVW5cUMLD1a6LM/1Hdq/uu9VtIdMnpmaTCcYELTA8Cq9WEZOwqkp0oEPIICN6WCsbKxdWo/VJxSReEHHC1JpYOibkQpPeqk0ZdAeRrnAO2Sj8TADgOaqegAVLiiSynS5zVeqVrzJ/+ATwmjHW068thWcIxFXrW9bTwZvbM+Pz2DgT93qzTkLX+PkEsav6xdtHr+a/E0McEgbmxJPoDMbCHAQlaAMXdaSwSTym19c9Bsm8pl74/FbPbtHU/4yax+JLvRviJ/WcITHbzHCQpkSITKGK4wxTlEcwJ/CWnyv/4nWIhsmd0LAeIelm9lQELic6kZJxQPIYQJwIIy7J9r1Kqy68xXj4Nas0H3yVmR6Y1QjIG27OW33YOQ0PN4OKgEDalJrbj X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?pNpEBoK5lWVn517kW/O84xXKKqhL5HPwScsoKYBaQwjezXi75OXGE9J03YSq?= =?us-ascii?Q?UTHV+MhEbDIXYEa3W3gqPy1hyyMrmDOwc724y0um1GJVv3oVaCQMqxd6XRWY?= =?us-ascii?Q?kaMgND4OR4sfwyhpRv6MAX/EBlcgUZMspFVErkyI/M785Y2kATcmXtia1QSs?= =?us-ascii?Q?QbNuH5Wu/H63OUlPLmXr025zFCeqBR/0TW2jXCFrIFfx4ac4w5VA+VgQnTPe?= =?us-ascii?Q?0TFJM5nxUzvsX6Cr0i10Sgm7RKKZfABCI4/rnQpfjCg1Ob8aC8UUEpBEIJuB?= =?us-ascii?Q?xhODe2hVE/wmCp5uhKkPhP6XwroAwNBeZnoWYCiKVtGRAUV/irsELTycaN6o?= =?us-ascii?Q?S7VRaQoKnY3Jex3jTTv28nr8Q8NVYMz+Xkz1rh4E6MevGe9laZFXUIZhmpZj?= =?us-ascii?Q?a2/qXAZ4zkOcQwTmcp8hsIuBJeExek2q/oqy8vyrdd0/Y3cIXzn3IPwhv2LK?= =?us-ascii?Q?suXlSCt+/c4BZJvOdQUVjZLGlIMlrYVONv3XlVkr5+UVLL1Ehm8lRgmzUhDq?= =?us-ascii?Q?0SLn3SlP7lQB4r+vQ8d3Rjez6DEyh4gDYeyELt7IbydnoN+aN7SznPMLL4AL?= =?us-ascii?Q?6l/Fof2OIWWbDroXg6iyEj7ddDjpHT3Z5nWukzLgrYatdQSJNgdwYCEy83Uc?= =?us-ascii?Q?2noTnFvD/8dZ0GAPckNJnc/uQN76S90ujDZ27PPUb/IaGe9bB5d+3wWc/7kK?= =?us-ascii?Q?iRbl1ovx8PYgFT50/PPUBZ+px93vntgtoyzFLoX8zrTN4NJlI6oncLfYhVMz?= =?us-ascii?Q?d/tuCdSCgbuEA/vxRnN5RaIukL9oicvdfD4EyF4M7peFmfk2q4aPfPTeKXFU?= =?us-ascii?Q?4KJJL3ug0xyZ3rUkjY/kM73m6EiEkan280sNAJvmGJhVQnUEzzwomextZ0Ko?= =?us-ascii?Q?QfCZZ4OmBLHdIxr30dO9gNZQdj5a5sZG3YOJRSXRED/5/Auz6tXXgFm7iY8E?= =?us-ascii?Q?WdRcUqq7t2iRWfso1zUL1CrF5bNm/6o2EoZmRIeODG05JDVxz9vXTsUc+bcu?= =?us-ascii?Q?OhtzX+YMAqsRDLKfij/LAwstarPKhDVDXPdXZrAepMuRAcJVx19PxY8rViC3?= =?us-ascii?Q?3NsEAOJ1AeQpdD2tIPAcLa1FKT5fOeuZy6+tJfrCrat2Gz9+KG06whyj3pDp?= =?us-ascii?Q?WEIsJ4TBTuOR4ieM6biWPTmTSUHcIdmjyrMiOOGdUcJ9UgYxQBX7gFDByifG?= =?us-ascii?Q?HjvppxOnLy3JbdwPSTeJjxCCQKA7s8T07G8m39nquT4kPUZ39DhtxKsR8ofp?= =?us-ascii?Q?VpYFxjUWukYpOyj+So/m?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 74ad18b8-8a12-4667-438f-08dc0c7144b2 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:00.6675 (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 1/4] hevcdec: move sao template to 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 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/hevcdsp_template.c | 196 +----------------------------- libavcodec/xvc_sao_template.c | 217 ++++++++++++++++++++++++++++++++++ 2 files changed, 218 insertions(+), 195 deletions(-) create mode 100644 libavcodec/xvc_sao_template.c diff --git a/libavcodec/hevcdsp_template.c b/libavcodec/hevcdsp_template.c index 725fab99ed..00786bb2f8 100644 --- a/libavcodec/hevcdsp_template.c +++ b/libavcodec/hevcdsp_template.c @@ -25,6 +25,7 @@ #include "bit_depth_template.c" #include "hevcdsp.h" +#include "xvc_sao_template.c" static void FUNC(put_pcm)(uint8_t *_dst, ptrdiff_t stride, int width, int height, GetBitContext *gb, int pcm_bit_depth) @@ -295,201 +296,6 @@ IDCT_DC(32) #undef SET #undef SCALE -static void FUNC(sao_band_filter)(uint8_t *_dst, const uint8_t *_src, - ptrdiff_t stride_dst, ptrdiff_t stride_src, - const int16_t *sao_offset_val, int sao_left_class, - int width, int height) -{ - pixel *dst = (pixel *)_dst; - const pixel *src = (const pixel *)_src; - int offset_table[32] = { 0 }; - int k, y, x; - int shift = BIT_DEPTH - 5; - - stride_dst /= sizeof(pixel); - stride_src /= 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) & 31]); - dst += stride_dst; - src += stride_src; - } -} - -#define CMP(a, b) (((a) > (b)) - ((a) < (b))) - -static void FUNC(sao_edge_filter)(uint8_t *_dst, const uint8_t *_src, ptrdiff_t stride_dst, const int16_t *sao_offset_val, - int eo, int width, 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 = (const pixel *)_src; - int a_stride, b_stride; - int x, y; - ptrdiff_t stride_src = (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / sizeof(pixel); - stride_dst /= sizeof(pixel); - - a_stride = pos[eo][0][0] + pos[eo][0][1] * stride_src; - b_stride = pos[eo][1][0] + pos[eo][1][1] * stride_src; - 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 += stride_src; - dst += stride_dst; - } -} - -static void FUNC(sao_edge_restore_0)(uint8_t *_dst, const uint8_t *_src, - ptrdiff_t stride_dst, ptrdiff_t stride_src, const SAOParams *sao, - const int *borders, int _width, int _height, - 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 = (const pixel *)_src; - const int16_t *sao_offset_val = sao->offset_val[c_idx]; - int sao_eo_class = sao->eo_class[c_idx]; - int init_x = 0, width = _width, height = _height; - - stride_dst /= sizeof(pixel); - stride_src /= 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 * stride_dst] = av_clip_pixel(src[y * stride_src] + 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 * stride_dst + offset] = av_clip_pixel(src[x * stride_src + 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_stride_dst = stride_dst * (height - 1); - ptrdiff_t y_stride_src = stride_src * (height - 1); - for (x = init_x; x < width; x++) - dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val); - height--; - } - } -} - -static void FUNC(sao_edge_restore_1)(uint8_t *_dst, const uint8_t *_src, - ptrdiff_t stride_dst, ptrdiff_t stride_src, const SAOParams *sao, - const int *borders, int _width, int _height, - 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 = (const pixel *)_src; - const int16_t *sao_offset_val = sao->offset_val[c_idx]; - int sao_eo_class = sao->eo_class[c_idx]; - int init_x = 0, init_y = 0, width = _width, height = _height; - - stride_dst /= sizeof(pixel); - stride_src /= 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 * stride_dst] = av_clip_pixel(src[y * stride_src] + 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 * stride_dst + offset] = av_clip_pixel(src[x * stride_src + 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_stride_dst = stride_dst * (height - 1); - ptrdiff_t y_stride_src = stride_src * (height - 1); - for (x = init_x; x < width; x++) - dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + 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*stride_dst] = src[y*stride_src]; - } - 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*stride_dst+width-1] = src[y*stride_src+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)*stride_dst+x] = src[(height-1)*stride_src+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[stride_dst*(height-1)+width-1] = src[stride_src*(height-1)+width-1]; - if(diag_edge[3] && sao_eo_class == SAO_EO_45D) - dst[stride_dst*(height-1)] = src[stride_src*(height-1)]; - - } -} - -#undef CMP - //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// diff --git a/libavcodec/xvc_sao_template.c b/libavcodec/xvc_sao_template.c new file mode 100644 index 0000000000..b3eb8a3deb --- /dev/null +++ b/libavcodec/xvc_sao_template.c @@ -0,0 +1,217 @@ +/* + * HEVC/VVC SAO template + * + * Copyright (C) 2024 Nuo Mi + * Copyright (C) 2012 - 2013 Guillaume Martres + * + * 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 + */ + +static void FUNC(sao_band_filter)(uint8_t *_dst, const uint8_t *_src, + ptrdiff_t stride_dst, ptrdiff_t stride_src, + const int16_t *sao_offset_val, int sao_left_class, + int width, int height) +{ + pixel *dst = (pixel *)_dst; + const pixel *src = (const pixel *)_src; + int offset_table[32] = { 0 }; + int k, y, x; + int shift = BIT_DEPTH - 5; + + stride_dst /= sizeof(pixel); + stride_src /= 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) & 31]); + dst += stride_dst; + src += stride_src; + } +} + +#define CMP(a, b) (((a) > (b)) - ((a) < (b))) + +static void FUNC(sao_edge_filter)(uint8_t *_dst, const uint8_t *_src, ptrdiff_t stride_dst, const int16_t *sao_offset_val, + int eo, int width, 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 = (const pixel *)_src; + int a_stride, b_stride; + int x, y; + ptrdiff_t stride_src = (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / sizeof(pixel); + stride_dst /= sizeof(pixel); + + a_stride = pos[eo][0][0] + pos[eo][0][1] * stride_src; + b_stride = pos[eo][1][0] + pos[eo][1][1] * stride_src; + 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 += stride_src; + dst += stride_dst; + } +} + +static void FUNC(sao_edge_restore_0)(uint8_t *_dst, const uint8_t *_src, + ptrdiff_t stride_dst, ptrdiff_t stride_src, const SAOParams *sao, + const int *borders, int _width, int _height, + 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 = (const pixel *)_src; + const int16_t *sao_offset_val = sao->offset_val[c_idx]; + int sao_eo_class = sao->eo_class[c_idx]; + int init_x = 0, width = _width, height = _height; + + stride_dst /= sizeof(pixel); + stride_src /= 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 * stride_dst] = av_clip_pixel(src[y * stride_src] + 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 * stride_dst + offset] = av_clip_pixel(src[x * stride_src + 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_stride_dst = stride_dst * (height - 1); + ptrdiff_t y_stride_src = stride_src * (height - 1); + for (x = init_x; x < width; x++) + dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val); + height--; + } + } +} + +static void FUNC(sao_edge_restore_1)(uint8_t *_dst, const uint8_t *_src, + ptrdiff_t stride_dst, ptrdiff_t stride_src, const SAOParams *sao, + const int *borders, int _width, int _height, + 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 = (const pixel *)_src; + const int16_t *sao_offset_val = sao->offset_val[c_idx]; + int sao_eo_class = sao->eo_class[c_idx]; + int init_x = 0, init_y = 0, width = _width, height = _height; + + stride_dst /= sizeof(pixel); + stride_src /= 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 * stride_dst] = av_clip_pixel(src[y * stride_src] + 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 * stride_dst + offset] = av_clip_pixel(src[x * stride_src + 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_stride_dst = stride_dst * (height - 1); + ptrdiff_t y_stride_src = stride_src * (height - 1); + for (x = init_x; x < width; x++) + dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + 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*stride_dst] = src[y*stride_src]; + } + 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*stride_dst+width-1] = src[y*stride_src+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)*stride_dst+x] = src[(height-1)*stride_src+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[stride_dst*(height-1)+width-1] = src[stride_src*(height-1)+width-1]; + if(diag_edge[3] && sao_eo_class == SAO_EO_45D) + dst[stride_dst*(height-1)] = src[stride_src*(height-1)]; + + } +} + +#undef CMP -- 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".