From patchwork Mon Nov 21 00:26:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 39364 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp1816290pzb; Sun, 20 Nov 2022 16:27:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf6klLJRTNBUtwL11RfeVELx+/u1bvas6RaGLCePrbeO3JZ4UnSX53qxEUG/qRCn/ndMh7rE X-Received: by 2002:a50:f602:0:b0:469:4e4f:4827 with SMTP id c2-20020a50f602000000b004694e4f4827mr5938440edn.214.1668990435185; Sun, 20 Nov 2022 16:27:15 -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 i21-20020a170906251500b0078316f0b5f8si6100303ejb.88.2022.11.20.16.27.14; Sun, 20 Nov 2022 16:27:15 -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=hJIKACPc; 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=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CC02C68BC90; Mon, 21 Nov 2022 02:27:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-oln040092075081.outbound.protection.outlook.com [40.92.75.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 569A168BC90 for ; Mon, 21 Nov 2022 02:27:01 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jE2GieqOBjkU3mpRjP8/H0rBkV2P1JJHERer4ho1eklbrMf7rjjXQI26PmuU8PnXERc0SYDIrPSnIJkS9h67sllhRH2ZEioQ/jwwuqUw53L5i1gn2b+QfPklPi4J14i4pHAdd8CYF01HhLtc2+uCww1XpI8ptipBMmhV1tzJks0GZ3qczcIfCb1XOhfCpQPmA7GYbuPHbyfRUYL+sUJgP9P60EhZT9iEmUnwgPTAHDvyIDMWle/daLyLuGwbhP+70xTjczYWC/yemhL8oCgqqMF9+V6ijDvjlstvgctpHQTZSE8dFlMZzYym1vivhAqEuZilzZWSkPhK/tNt5sHJ5g== 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=M3rLHRvo/7thGPBGdVmWEGT/Iqavww7vyq12BMcSlv8=; b=GXEAsaoKgLcS54GyfrI+rAJdGNhBlh/6qm0ENUkhgC2w2cqKmPgrhGqt1me3dzQfbXmbRLvgNwwWmJ+eqGU5Tjke3NP8PtJIcY+p48Tb2dybGo/+4iLcVY7yvPguSbtDbwfNXUJOxNyyvjqJxQ+cQb/Pb3TosuHwhBpccwe4wUAMQxgHXBr1T47FmtmRe+tGSR1Y0GDmMzh1HrtS6Bax6SMwPRD3fhB1u/gFvvv+YCisVcCoTErRQxKrCALfwcy78Kt9xJjeA2/bElzL046in6KcPHA0NhQR8+ORG0ng1MMkIeFsTq5CK76XLYPOujhGIzJ4NPsJTRbiyy1/TVl17Q== 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=M3rLHRvo/7thGPBGdVmWEGT/Iqavww7vyq12BMcSlv8=; b=hJIKACPc88RnGPZNozB7WgNcfRaZfdN9iQgHkz8zNYf7tUDO/pMDVbVPMKAkw8Fg04k3jXdVgjUnN78vl2zoTTmCwva+B1Bev9doxmA3ZZX5WTesTUgrv/c1pDCvRJoGPhbXZ/bUrqCKIfM7gLR+ZH4xpnJYLFf//tmapImrd3xBeO8rTUinlQQ8kAwhvko7H890NYFeJTXqvFvUJ2I5CFBWfyMPIGRUhOrD+LaDFETDQSLRRpQCwq+SdQdabS89AxCnSwbAsv6ZL579C5VfggIXMdlj0abcWglL1jJEE0HhIjdzJEm4wrkZFQ0OP+hMK90gABmrxJLoT5qbVUsrjw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AM8P250MB0198.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:325::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.9; Mon, 21 Nov 2022 00:26:52 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::c37:cabe:316a:60b2]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::c37:cabe:316a:60b2%4]) with mapi id 15.20.5834.011; Mon, 21 Nov 2022 00:26:52 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 21 Nov 2022 01:26:59 +0100 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [YTX5Gg8j+x5dS06NPtU5g6be/m0wTXHrFSOU/U4UztM=] X-ClientProxiedBy: FR3P281CA0100.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a1::18) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20221121002701.2127898-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AM8P250MB0198:EE_ X-MS-Office365-Filtering-Correlation-Id: 7bab1c27-ad4f-4185-92a5-08dacb57168b X-MS-Exchange-SLBlob-MailProps: feAVlmA1hHUsdZ5NY64GrSxgTuvz+rP1+q+Le0IJS8EMfHz7BRcYCyQzTPtiZfFHXS4TfVdUuHJ60sSsJOfyxMcjjH3w/lWJ9RYDd44ain7uES7MMuClqlQ+yFkY8mYj3pQg7xvH9/F3c0JsU7fAVCQsGAgPSPWFOzeTL18DFsyqO47/x4OaPhBUP3s3W2yL0KRK2vaMWiwFnrK2J6j9TyjgJOAFK77f9RwjyACTjR0c4NPQahxa5AqUrsuOBbmTE/Kkp2i+qogoyUjmXKGjhsZ26jO1fKTOQI4zsHXHS9RpSA06iJiKomGdZH4jV9IyjVhH1Rwjp8IZKQE5xdCgYeiWnQ7FYYqlC36Rl+Tq6xcC6RI5gKNoK8lq4N4t/bARKVj0VsMS4xNWeztPH0VPdeK2GQ5/ksz6p67gZGKsrR9F1/eLemnxGfb1Sk6jdcNhe8BKugFAwwipYDrgXxyJZUcZVCRbABMptux9eLhZhzEOYNP3q27uJBylh+GrQMZKDNU3mkGCYqDSf/VjmR322Qs9rHn67P0gDgJVA+qd0Vksf1lyf+OCJX2ohPNoSzxV+aLLktTGk+TgBjUNkuqt+sT9tDHjc2VwOC5RJ25MNZfyS8tds+42Qo/WalGdcjes+ckpQfNCLhjcTkGAfUFC55NY4m6MTJblgzXlHRQg0FaR4eIAz3RBKSRcTYfO2mg1FcoGD6/jo7tKLlBmktx9OA== X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /5gKOFhN8CA7qJPHlFcKPZQKB1yUGdAk8FV/KhhhISL7yW77ltkrrDyEBrRNFnNwnhlX7hA82gzsvNZWkCaX4hqRCaZLadd4tDFrpwniYP7EnO+WCs4Ep8EYyvwtVUjxLCOPCTXpiKleNHeXoCKUt/UBjli688zwPk/rGbdGnrSpvhkY3xNpd5Nq5VJPuhtnP75p1qD2U4NPdgS4T8jwjjVpleBnWrbJ9LcSpOXPoxt/XRRaX8ANjT6KmQMPRep0OYUBR3RUAmgwptuIPEdStz0qPHLbnegn0u5r/xMxRCbsDR6u0Uz6NpiVPFhzfiUbWxzDDw5n8q+0C2CiYa9GigeRasEVDblUXoIy/v6R62jp4NgP0SHgqkbaL/3D6nA/SAYdZ/wZ1mjHYQwxEY7gGG6NHE6WkXmeceVY/MXrwz9bhJWqGUHoyl4v86pHneyJISine5UgW52+LKlOZM/1n9MuawX4eiLD2wq5H6+91ATzASROaYiXNVoX8G27dktAmVJhC1wirZXmwOhY8qjkoHIREu4p42O2ryZrqBzbq8F1NaLrOGX6897uJnuVKNlVGGu/ngo8nJST7hxRB8CHufMwhKzBPGDpsRgSO7CevlXlG9lntHQPNMyGHJ/2l+PdyUogm195YkihMffa67YuxP2kceKeh5CvUZInGpuJH5o= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: je6QoiQpIzUP2kLMLSSFIk6WZw2qEYSNTd+MGkgSKYZ8Vg5M5g5fDYlapgvK6yRjjheK1/mWLt8bwvKFJ0XDeWYTNTHGv2TmagxGbOLmSHlvPY6aL8tjNXRUvxp6RXBOHiDPECwrWCInUfCQltboC2Q5ygcKIHPCn413R/gvzWDhFkHPSg7RWqryu5WoHB4Fz+8QJ8XWg4RWbbZqbSWjy07birNd0xM78FT3ioAL4FKTkA9TsSlIq3b/eWsVEtO6zYdICL/KJpAE5S9n6RJmrW+b3IrbJhp3z7QJqkN/gj/SCgP6VIDp5M6ENMebBHlMlHaWzJUeC6Rslk4IKcR27hNqxCy9Vu8fgVGnS7tNAOlfCYLuj3FIyXVNFRrFItoBZMLrjXdZ0mbS4a7SXBLVm+LEi02PDHKv6I4+f0S9d9CVcaopWnvzj00jMC4Hk/IbWiTY1KfmeK/26uxYnPRq2Url+EbroByL4bk9C554soXx49W5UoJznimFo31+lOV/DzCVZZOYsSwuR7Tj6EuCPhiC3IqYpiO7O6tF6BDXt+vxZFJ+cYg9akr1oSR2VSzlKPFNpXxBw5F3QCIzRpdBMKJOJ0q7y068uSaGyWHm2kX69kamQF74eMc/YWVauLoqUb7Ettvie6OlYeS1WmqWAwxIdXYsotlOisl0DvNIRx62JZ1hZWKbYUGF+GrOO+cXHuQmQMl7YlmtEm+P8ZK/Jrj48c2XG6xWPPnnueapLW6PuIzRIQsR1FLINSnPWzS5rJrq/h4s0wzwBKxN9z7gbxRlB9hFPkrXMOq6Noj1Yak1wTV8nqopaj88WJFEj7ucgH+bjqKDbNfx7eBWaE3Sh+S5Lntin+LeaguImw8GYq/vkes0EfBjBUMAXtRy3iCteZ6u44BVrdQfjdTAJfRbiU2npc0FWnnNTOuNc1GWqsL5Mss57jj05R0/yRTLG+dDkQJMVo2DMawLxrTj2Br/fp9zi2nTeXKem5W7VaCVn80yWpZNKckMTM7FTW2k/RGspXCBFqpbuDT/6RVlThJXyK4XRESWXirF4Z102iB0JNVVRR9PiruSlY/eInjVsHbkisyQ40hJKAn7cPut36fSLdkKq3S96ZNeEPhvtDRsiOK2c6OzZ8XhdgwYLOyZ6A1zd82NOz48Ln4xCU0iLtMPUu3iqMJPADaBub0hYrYVE36UEOX3s4mP0jSTvtGsehE0/OE2isxZMwR995Jpo/6VnbTxf5xghmidg9xSpsfvuuSCMre2gfU57UEzxbaYXxHYQlR17xXyGV0vrLTx3HPb5FZUQUKCtIqB0zrO3Z8xuwzdgFw5aF8iekZcse44Umb/ X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7bab1c27-ad4f-4185-92a5-08dacb57168b X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 00:26:52.9072 (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: AM8P250MB0198 Subject: [FFmpeg-devel] [PATCH 4/6] swscale/utils: Move functions to avoid forward declarations 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: U3hQKI1YCLFf Signed-off-by: Andreas Rheinhardt --- libswscale/utils.c | 407 ++++++++++++++++++++++----------------------- 1 file changed, 200 insertions(+), 207 deletions(-) diff --git a/libswscale/utils.c b/libswscale/utils.c index fb788fc330..cdd89e4b58 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -59,13 +59,6 @@ #include "swscale.h" #include "swscale_internal.h" -static SwsVector *sws_getIdentityVec(void); -static void sws_addVec(SwsVector *a, SwsVector *b); -static void sws_shiftVec(SwsVector *a, int shift); -static void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level); - -static void handle_formats(SwsContext *c); - typedef struct FormatEntry { uint8_t is_supported_in :1; uint8_t is_supported_out :1; @@ -926,6 +919,74 @@ static void fill_xyztables(struct SwsContext *c) } } +static int handle_jpeg(enum AVPixelFormat *format) +{ + switch (*format) { + case AV_PIX_FMT_YUVJ420P: + *format = AV_PIX_FMT_YUV420P; + return 1; + case AV_PIX_FMT_YUVJ411P: + *format = AV_PIX_FMT_YUV411P; + return 1; + case AV_PIX_FMT_YUVJ422P: + *format = AV_PIX_FMT_YUV422P; + return 1; + case AV_PIX_FMT_YUVJ444P: + *format = AV_PIX_FMT_YUV444P; + return 1; + case AV_PIX_FMT_YUVJ440P: + *format = AV_PIX_FMT_YUV440P; + return 1; + case AV_PIX_FMT_GRAY8: + case AV_PIX_FMT_YA8: + case AV_PIX_FMT_GRAY9LE: + case AV_PIX_FMT_GRAY9BE: + case AV_PIX_FMT_GRAY10LE: + case AV_PIX_FMT_GRAY10BE: + case AV_PIX_FMT_GRAY12LE: + case AV_PIX_FMT_GRAY12BE: + case AV_PIX_FMT_GRAY14LE: + case AV_PIX_FMT_GRAY14BE: + case AV_PIX_FMT_GRAY16LE: + case AV_PIX_FMT_GRAY16BE: + case AV_PIX_FMT_YA16BE: + case AV_PIX_FMT_YA16LE: + return 1; + default: + return 0; + } +} + +static int handle_0alpha(enum AVPixelFormat *format) +{ + switch (*format) { + case AV_PIX_FMT_0BGR : *format = AV_PIX_FMT_ABGR ; return 1; + case AV_PIX_FMT_BGR0 : *format = AV_PIX_FMT_BGRA ; return 4; + case AV_PIX_FMT_0RGB : *format = AV_PIX_FMT_ARGB ; return 1; + case AV_PIX_FMT_RGB0 : *format = AV_PIX_FMT_RGBA ; return 4; + default: return 0; + } +} + +static int handle_xyz(enum AVPixelFormat *format) +{ + switch (*format) { + case AV_PIX_FMT_XYZ12BE : *format = AV_PIX_FMT_RGB48BE; return 1; + case AV_PIX_FMT_XYZ12LE : *format = AV_PIX_FMT_RGB48LE; return 1; + default: return 0; + } +} + +static void handle_formats(SwsContext *c) +{ + c->src0Alpha |= handle_0alpha(&c->srcFormat); + c->dst0Alpha |= handle_0alpha(&c->dstFormat); + c->srcXYZ |= handle_xyz(&c->srcFormat); + c->dstXYZ |= handle_xyz(&c->dstFormat); + if (c->srcXYZ || c->dstXYZ) + fill_xyztables(c); +} + static int range_override_needed(enum AVPixelFormat format) { return !isYUV(format) && !isGray(format); @@ -1112,74 +1173,6 @@ int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table, return 0; } -static int handle_jpeg(enum AVPixelFormat *format) -{ - switch (*format) { - case AV_PIX_FMT_YUVJ420P: - *format = AV_PIX_FMT_YUV420P; - return 1; - case AV_PIX_FMT_YUVJ411P: - *format = AV_PIX_FMT_YUV411P; - return 1; - case AV_PIX_FMT_YUVJ422P: - *format = AV_PIX_FMT_YUV422P; - return 1; - case AV_PIX_FMT_YUVJ444P: - *format = AV_PIX_FMT_YUV444P; - return 1; - case AV_PIX_FMT_YUVJ440P: - *format = AV_PIX_FMT_YUV440P; - return 1; - case AV_PIX_FMT_GRAY8: - case AV_PIX_FMT_YA8: - case AV_PIX_FMT_GRAY9LE: - case AV_PIX_FMT_GRAY9BE: - case AV_PIX_FMT_GRAY10LE: - case AV_PIX_FMT_GRAY10BE: - case AV_PIX_FMT_GRAY12LE: - case AV_PIX_FMT_GRAY12BE: - case AV_PIX_FMT_GRAY14LE: - case AV_PIX_FMT_GRAY14BE: - case AV_PIX_FMT_GRAY16LE: - case AV_PIX_FMT_GRAY16BE: - case AV_PIX_FMT_YA16BE: - case AV_PIX_FMT_YA16LE: - return 1; - default: - return 0; - } -} - -static int handle_0alpha(enum AVPixelFormat *format) -{ - switch (*format) { - case AV_PIX_FMT_0BGR : *format = AV_PIX_FMT_ABGR ; return 1; - case AV_PIX_FMT_BGR0 : *format = AV_PIX_FMT_BGRA ; return 4; - case AV_PIX_FMT_0RGB : *format = AV_PIX_FMT_ARGB ; return 1; - case AV_PIX_FMT_RGB0 : *format = AV_PIX_FMT_RGBA ; return 4; - default: return 0; - } -} - -static int handle_xyz(enum AVPixelFormat *format) -{ - switch (*format) { - case AV_PIX_FMT_XYZ12BE : *format = AV_PIX_FMT_RGB48BE; return 1; - case AV_PIX_FMT_XYZ12LE : *format = AV_PIX_FMT_RGB48LE; return 1; - default: return 0; - } -} - -static void handle_formats(SwsContext *c) -{ - c->src0Alpha |= handle_0alpha(&c->srcFormat); - c->dst0Alpha |= handle_0alpha(&c->dstFormat); - c->srcXYZ |= handle_xyz(&c->srcFormat); - c->dstXYZ |= handle_xyz(&c->dstFormat); - if (c->srcXYZ || c->dstXYZ) - fill_xyztables(c); -} - SwsContext *sws_alloc_context(void) { SwsContext *c = av_mallocz(sizeof(SwsContext)); @@ -1271,55 +1264,6 @@ static enum AVPixelFormat alphaless_fmt(enum AVPixelFormat fmt) static int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter); -static int context_init_threaded(SwsContext *c, - SwsFilter *src_filter, SwsFilter *dst_filter) -{ - int ret; - - ret = avpriv_slicethread_create(&c->slicethread, (void*)c, - ff_sws_slice_worker, NULL, c->nb_threads); - if (ret == AVERROR(ENOSYS)) { - c->nb_threads = 1; - return 0; - } else if (ret < 0) - return ret; - - c->nb_threads = ret; - - c->slice_ctx = av_calloc(c->nb_threads, sizeof(*c->slice_ctx)); - c->slice_err = av_calloc(c->nb_threads, sizeof(*c->slice_err)); - if (!c->slice_ctx || !c->slice_err) - return AVERROR(ENOMEM); - - for (int i = 0; i < c->nb_threads; i++) { - c->slice_ctx[i] = sws_alloc_context(); - if (!c->slice_ctx[i]) - return AVERROR(ENOMEM); - - c->slice_ctx[i]->parent = c; - - ret = av_opt_copy((void*)c->slice_ctx[i], (void*)c); - if (ret < 0) - return ret; - - c->slice_ctx[i]->nb_threads = 1; - - ret = sws_init_single_context(c->slice_ctx[i], src_filter, dst_filter); - if (ret < 0) - return ret; - - c->nb_slice_ctx++; - - if (c->slice_ctx[i]->dither == SWS_DITHER_ED) { - av_log(c, AV_LOG_VERBOSE, - "Error-diffusion dither is in use, scaling will be single-threaded."); - break; - } - } - - return 0; -} - static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter) { @@ -2037,6 +1981,55 @@ fail: // FIXME replace things by appropriate error codes return ret; } +static int context_init_threaded(SwsContext *c, + SwsFilter *src_filter, SwsFilter *dst_filter) +{ + int ret; + + ret = avpriv_slicethread_create(&c->slicethread, (void*)c, + ff_sws_slice_worker, NULL, c->nb_threads); + if (ret == AVERROR(ENOSYS)) { + c->nb_threads = 1; + return 0; + } else if (ret < 0) + return ret; + + c->nb_threads = ret; + + c->slice_ctx = av_calloc(c->nb_threads, sizeof(*c->slice_ctx)); + c->slice_err = av_calloc(c->nb_threads, sizeof(*c->slice_err)); + if (!c->slice_ctx || !c->slice_err) + return AVERROR(ENOMEM); + + for (int i = 0; i < c->nb_threads; i++) { + c->slice_ctx[i] = sws_alloc_context(); + if (!c->slice_ctx[i]) + return AVERROR(ENOMEM); + + c->slice_ctx[i]->parent = c; + + ret = av_opt_copy((void*)c->slice_ctx[i], (void*)c); + if (ret < 0) + return ret; + + c->slice_ctx[i]->nb_threads = 1; + + ret = sws_init_single_context(c->slice_ctx[i], src_filter, dst_filter); + if (ret < 0) + return ret; + + c->nb_slice_ctx++; + + if (c->slice_ctx[i]->dither == SWS_DITHER_ED) { + av_log(c, AV_LOG_VERBOSE, + "Error-diffusion dither is in use, scaling will be single-threaded."); + break; + } + } + + return 0; +} + av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter) { @@ -2123,89 +2116,6 @@ static void makenan_vec(SwsVector *a) a->coeff[i] = NAN; } -SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, - float lumaSharpen, float chromaSharpen, - float chromaHShift, float chromaVShift, - int verbose) -{ - SwsFilter *filter = av_malloc(sizeof(SwsFilter)); - if (!filter) - return NULL; - - if (lumaGBlur != 0.0) { - filter->lumH = sws_getGaussianVec(lumaGBlur, 3.0); - filter->lumV = sws_getGaussianVec(lumaGBlur, 3.0); - } else { - filter->lumH = sws_getIdentityVec(); - filter->lumV = sws_getIdentityVec(); - } - - if (chromaGBlur != 0.0) { - filter->chrH = sws_getGaussianVec(chromaGBlur, 3.0); - filter->chrV = sws_getGaussianVec(chromaGBlur, 3.0); - } else { - filter->chrH = sws_getIdentityVec(); - filter->chrV = sws_getIdentityVec(); - } - - if (!filter->lumH || !filter->lumV || !filter->chrH || !filter->chrV) - goto fail; - - if (chromaSharpen != 0.0) { - SwsVector *id = sws_getIdentityVec(); - if (!id) - goto fail; - sws_scaleVec(filter->chrH, -chromaSharpen); - sws_scaleVec(filter->chrV, -chromaSharpen); - sws_addVec(filter->chrH, id); - sws_addVec(filter->chrV, id); - sws_freeVec(id); - } - - if (lumaSharpen != 0.0) { - SwsVector *id = sws_getIdentityVec(); - if (!id) - goto fail; - sws_scaleVec(filter->lumH, -lumaSharpen); - sws_scaleVec(filter->lumV, -lumaSharpen); - sws_addVec(filter->lumH, id); - sws_addVec(filter->lumV, id); - sws_freeVec(id); - } - - if (chromaHShift != 0.0) - sws_shiftVec(filter->chrH, (int)(chromaHShift + 0.5)); - - if (chromaVShift != 0.0) - sws_shiftVec(filter->chrV, (int)(chromaVShift + 0.5)); - - sws_normalizeVec(filter->chrH, 1.0); - sws_normalizeVec(filter->chrV, 1.0); - sws_normalizeVec(filter->lumH, 1.0); - sws_normalizeVec(filter->lumV, 1.0); - - if (isnan_vec(filter->chrH) || - isnan_vec(filter->chrV) || - isnan_vec(filter->lumH) || - isnan_vec(filter->lumV)) - goto fail; - - if (verbose) - sws_printVec2(filter->chrH, NULL, AV_LOG_DEBUG); - if (verbose) - sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG); - - return filter; - -fail: - sws_freeVec(filter->lumH); - sws_freeVec(filter->lumV); - sws_freeVec(filter->chrH); - sws_freeVec(filter->chrV); - av_freep(&filter); - return NULL; -} - SwsVector *sws_allocVec(int length) { SwsVector *vec; @@ -2417,6 +2327,89 @@ void sws_freeFilter(SwsFilter *filter) av_free(filter); } +SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, + float lumaSharpen, float chromaSharpen, + float chromaHShift, float chromaVShift, + int verbose) +{ + SwsFilter *filter = av_malloc(sizeof(SwsFilter)); + if (!filter) + return NULL; + + if (lumaGBlur != 0.0) { + filter->lumH = sws_getGaussianVec(lumaGBlur, 3.0); + filter->lumV = sws_getGaussianVec(lumaGBlur, 3.0); + } else { + filter->lumH = sws_getIdentityVec(); + filter->lumV = sws_getIdentityVec(); + } + + if (chromaGBlur != 0.0) { + filter->chrH = sws_getGaussianVec(chromaGBlur, 3.0); + filter->chrV = sws_getGaussianVec(chromaGBlur, 3.0); + } else { + filter->chrH = sws_getIdentityVec(); + filter->chrV = sws_getIdentityVec(); + } + + if (!filter->lumH || !filter->lumV || !filter->chrH || !filter->chrV) + goto fail; + + if (chromaSharpen != 0.0) { + SwsVector *id = sws_getIdentityVec(); + if (!id) + goto fail; + sws_scaleVec(filter->chrH, -chromaSharpen); + sws_scaleVec(filter->chrV, -chromaSharpen); + sws_addVec(filter->chrH, id); + sws_addVec(filter->chrV, id); + sws_freeVec(id); + } + + if (lumaSharpen != 0.0) { + SwsVector *id = sws_getIdentityVec(); + if (!id) + goto fail; + sws_scaleVec(filter->lumH, -lumaSharpen); + sws_scaleVec(filter->lumV, -lumaSharpen); + sws_addVec(filter->lumH, id); + sws_addVec(filter->lumV, id); + sws_freeVec(id); + } + + if (chromaHShift != 0.0) + sws_shiftVec(filter->chrH, (int)(chromaHShift + 0.5)); + + if (chromaVShift != 0.0) + sws_shiftVec(filter->chrV, (int)(chromaVShift + 0.5)); + + sws_normalizeVec(filter->chrH, 1.0); + sws_normalizeVec(filter->chrV, 1.0); + sws_normalizeVec(filter->lumH, 1.0); + sws_normalizeVec(filter->lumV, 1.0); + + if (isnan_vec(filter->chrH) || + isnan_vec(filter->chrV) || + isnan_vec(filter->lumH) || + isnan_vec(filter->lumV)) + goto fail; + + if (verbose) + sws_printVec2(filter->chrH, NULL, AV_LOG_DEBUG); + if (verbose) + sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG); + + return filter; + +fail: + sws_freeVec(filter->lumH); + sws_freeVec(filter->lumV); + sws_freeVec(filter->chrH); + sws_freeVec(filter->chrV); + av_freep(&filter); + return NULL; +} + void sws_freeContext(SwsContext *c) { int i;