From patchwork Sun Oct 20 20:05:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52408 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2238695vqi; Sun, 20 Oct 2024 13:09:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXgnjk6p3kWU6yzDM0bzEiH22h/jQE6GT1u2fLt1iAKYD8fGoVHWPmCKrzWkBsGJdTLiL2EEAkRBzgvsXtq1zif@gmail.com X-Google-Smtp-Source: AGHT+IEJjcYuoyEUy5CyNh7Z9+18OG5w6r7Fuc7MNp77s8UlvQbha928ybexpMA6rcIfOlYvqAjy X-Received: by 2002:a17:907:7e83:b0:a9a:59f:dfb9 with SMTP id a640c23a62f3a-a9a699694a4mr889569766b.5.1729454957767; Sun, 20 Oct 2024 13:09:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729454957; cv=none; d=google.com; s=arc-20240605; b=ONUGuKsr5WPlA9XMUvrHySPU1zeMWpzNWpo1v/3hvs7QmQ3olU25RY70DxG7zUFCPZ Rk9BGvhys2wZ793BY9/nwV86ZbMbOSiOJtxtN5gOJoY1dP6eOcoQG2ngudsOBoDHYDIj ZGHUfkNrMJuGg1sq5e+9xGNv/tP8GdW+MLwAWX9v9QhOnQ/A8UlNumksLzKwgPkmnsq/ SaRqQRTpJPL4BGkU7Z4APyK3weZnPeCQcOYMPZDULOr60lBV3we7zajsEIq7vd6tK3G9 asO796ggCnIQ3Tw/qPLMYafbdlQyCttLTE9L3/nUxL0VaBjDzPSyOc0QTwUagYmY7qfi N2fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=tZ7rAIYcf2aZ36FJoJhiJiyN3IE3NEAUES7hZghaSsg=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=gloQI7gdTocbx9hwlpdEEqk9PY+ZNXjLMEMCd5QB+M3mVN03nXc6IUq9qlCNJQQe4d GzKs/Ys4mGHpu2WtQ7arfUG8xcc1teEtrcEPdK0WWYL0QvzViCQylVACXOIeqgr0SX6o zywHxS6woZaIlp8Dw16Yol590y33Ul1H2T4JNrQfOJc+81gC7KcA3XoV+Lupx3pIpW8v 1N8K2XzBqIHAIM9KI4dswjyY9mO03akSc6aPgpGOhzW1ZOTWdkMlU4v3OzHDD0Vn+rt+ EpR9HBS7HDjiriyne7BkKbZdw07kdwDeUrFQXWJu15Nj55UOeiJbIicvifF5ZpBYyV6u vxuQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=tLo4yA3G; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a9a9133392asi148685266b.429.2024.10.20.13.09.16; Sun, 20 Oct 2024 13:09:17 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b=tLo4yA3G; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1F8C468D8E1; Sun, 20 Oct 2024 23:09:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8E06D68D9E8 for ; Sun, 20 Oct 2024 23:08:54 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454934; bh=mXPX8U50cjvwuSAod4kLpcd3Nsnm7p3+BdVDRdisZUo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tLo4yA3GweiF/FIc9tT9LJnEWbi2b2MfclTF3EX8ggux2Eg6M3Y6MyszLkknjYYNE p836xEPc0CL43tdIH3h431HWNv1HlRR8FUFjA8oP87FKTDb7xl7ydfV3AwlNzsGu3D jrN8DDgtYLAOyiqm53/S3FsHZ5oKJC2Zc0t32grg= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 4C5EC434F7; Sun, 20 Oct 2024 22:08:54 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:10 +0200 Message-ID: <20241020200851.1414766-2-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 01/18] swscale: publicly typedef struct SwsContext 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: RHLIar/T+eZk From: Niklas Haas Slightly more convenient, especially for the upcoming refactor which will turn SwsContext into a public struct. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/swscale.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/libswscale/swscale.h b/libswscale/swscale.h index e575695c05..2604eb1624 100644 --- a/libswscale/swscale.h +++ b/libswscale/swscale.h @@ -150,7 +150,7 @@ typedef struct SwsFilter { SwsVector *chrV; } SwsFilter; -struct SwsContext; +typedef struct SwsContext SwsContext; /** * Return a positive value if pix_fmt is a supported input format, 0 @@ -176,7 +176,7 @@ int sws_isSupportedEndiannessConversion(enum AVPixelFormat pix_fmt); * sws_init_context(). For filling see AVOptions, options.c and * sws_setColorspaceDetails(). */ -struct SwsContext *sws_alloc_context(void); +SwsContext *sws_alloc_context(void); /** * Initialize the swscaler context sws_context. @@ -185,13 +185,13 @@ struct SwsContext *sws_alloc_context(void); * error */ av_warn_unused_result -int sws_init_context(struct SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter); +int sws_init_context(SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter); /** * Free the swscaler context swsContext. * If swsContext is NULL, then does nothing. */ -void sws_freeContext(struct SwsContext *swsContext); +void sws_freeContext(SwsContext *swsContext); /** * Allocate and return an SwsContext. You need it to perform @@ -214,10 +214,10 @@ void sws_freeContext(struct SwsContext *swsContext); * @note this function is to be removed after a saner alternative is * written */ -struct SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, - int dstW, int dstH, enum AVPixelFormat dstFormat, - int flags, SwsFilter *srcFilter, - SwsFilter *dstFilter, const double *param); +SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, + int dstW, int dstH, enum AVPixelFormat dstFormat, + int flags, SwsFilter *srcFilter, + SwsFilter *dstFilter, const double *param); /** * Scale the image slice in srcSlice and put the resulting scaled @@ -245,7 +245,7 @@ struct SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcForm * the destination image * @return the height of the output slice */ -int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], +int sws_scale(SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]); @@ -265,7 +265,7 @@ int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], * * @return 0 on success, a negative AVERROR code on failure */ -int sws_scale_frame(struct SwsContext *c, AVFrame *dst, const AVFrame *src); +int sws_scale_frame(SwsContext *c, AVFrame *dst, const AVFrame *src); /** * Initialize the scaling process for a given pair of source/destination frames. @@ -292,7 +292,7 @@ int sws_scale_frame(struct SwsContext *c, AVFrame *dst, const AVFrame *src); * * @see sws_frame_end() */ -int sws_frame_start(struct SwsContext *c, AVFrame *dst, const AVFrame *src); +int sws_frame_start(SwsContext *c, AVFrame *dst, const AVFrame *src); /** * Finish the scaling process for a pair of source/destination frames previously @@ -302,7 +302,7 @@ int sws_frame_start(struct SwsContext *c, AVFrame *dst, const AVFrame *src); * * @param c The scaling context */ -void sws_frame_end(struct SwsContext *c); +void sws_frame_end(SwsContext *c); /** * Indicate that a horizontal slice of input data is available in the source @@ -316,7 +316,7 @@ void sws_frame_end(struct SwsContext *c); * * @return a non-negative number on success, a negative AVERROR code on failure. */ -int sws_send_slice(struct SwsContext *c, unsigned int slice_start, +int sws_send_slice(SwsContext *c, unsigned int slice_start, unsigned int slice_height); /** @@ -336,7 +336,7 @@ int sws_send_slice(struct SwsContext *c, unsigned int slice_start, * output can be produced * another negative AVERROR code on other kinds of scaling failure */ -int sws_receive_slice(struct SwsContext *c, unsigned int slice_start, +int sws_receive_slice(SwsContext *c, unsigned int slice_start, unsigned int slice_height); /** @@ -347,7 +347,7 @@ int sws_receive_slice(struct SwsContext *c, unsigned int slice_start, * Slice offsets and sizes passed to sws_receive_slice() must be * multiples of the value returned from this function. */ -unsigned int sws_receive_slice_alignment(const struct SwsContext *c); +unsigned int sws_receive_slice_alignment(const SwsContext *c); /** * @param c the scaling context @@ -362,7 +362,7 @@ unsigned int sws_receive_slice_alignment(const struct SwsContext *c); * @return A negative error code on error, non negative otherwise. * If `LIBSWSCALE_VERSION_MAJOR < 7`, returns -1 if not supported. */ -int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4], +int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation); @@ -370,7 +370,7 @@ int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4], * @return A negative error code on error, non negative otherwise. * If `LIBSWSCALE_VERSION_MAJOR < 7`, returns -1 if not supported. */ -int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table, +int sws_getColorspaceDetails(SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation); @@ -415,7 +415,7 @@ void sws_freeFilter(SwsFilter *filter); * Be warned that srcFilter and dstFilter are not checked, they * are assumed to remain the same. */ -struct SwsContext *sws_getCachedContext(struct SwsContext *context, +struct SwsContext *sws_getCachedContext(SwsContext *context, int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, From patchwork Sun Oct 20 20:05:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52418 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2246468vqi; Sun, 20 Oct 2024 13:34:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXTRaHLk3Nb/vFqCyxAmSFDDUud6tjJqExA/gQcfETeb4U/N9aOUbN4KF/8FcHLfwAD5hC2u85gcYOqtVDKHhJI@gmail.com X-Google-Smtp-Source: AGHT+IHvS9t3ZVHNLg6ukgqa60lAX0rmUJRv5v9za269luHIaZLxRs2xkzchhbowCU2gy77SAiuD X-Received: by 2002:a05:651c:888:b0:2fa:ce18:9e4 with SMTP id 38308e7fff4ca-2fb82ea1d2fmr13879841fa.6.1729456444345; Sun, 20 Oct 2024 13:34:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729456444; cv=none; d=google.com; s=arc-20240605; b=RGGYA3v4Jw7/ou77WE6zsiUyQpyuRTZcQynDyI55S+/i2GuI0qrbAsuI6t8MjpQqi6 t6eSYiJacXrdsPyBN9WUtom9Ha9zAWLx/TLMjoS4TvLTdrUYpeqxTjOPS/h5hIW/Zo8o lHMdMotgRhr24dW/TceXVwSds9sKu2etFR60JEBH3Wz7xKKVq/OsGz26Nh/HHOQ842/R mhfwuQ2NyMPWYXy/c0T5UGFIko2Ty7JzWjF3uHjk9AIUPfNntC4UJaMnGrh/gHKYuCAd +afO11B9ON4RxYAd6mkyM0w5Tcaneu7DItmvxiJiBJZhXPCKqRxSV3X8inOqOqrpkIHw xTEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=P1Xr+NZVxFnxJ4mdVec1Fd2M92BYqhgLNjawRcTUzYQ=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=jVL898BC1QIRSSwSOCnrkdnu5j5rSdXdUc6lLPScpVjF23l2hFsHDEZzx0gJHJumHe aC7978h6UYggPZp9RiM222s+0WWOulXFlDw9/Lhiq+E4/ifPSmWXGKNqzkPx1+ot2LUr EmlIk5e8GRDOghbNarHJXLbztU83BKFRMat76xcW7TUoMc9Blfd0krN0MoraYnZp3LvN oW71llxJJhLz4WpMGfsx5FlksZF9CBWqjhlmqP9LgaHRPCBQLczcGK6tWPwmsVfE0U5E lUOQjDx9a3aE/HomQkuMOT8J29UWov+9Wu+4JzSOm4rpBYsS4mR6e7N/zvJHo3xpiXEx Yeew==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=fXGyxpZi; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38308e7fff4ca-2fb9adc260bsi5304261fa.94.2024.10.20.13.34.03; Sun, 20 Oct 2024 13:34:04 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b=fXGyxpZi; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3A98868DB94; Sun, 20 Oct 2024 23:09:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0263D68D9E8 for ; Sun, 20 Oct 2024 23:08:54 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454934; bh=hgh7WOBihCHeZ4GtCiQKvXcVn3sxgECYGk7lYL2lxHI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fXGyxpZifE9jFyz3NEvcdNzlWcpXnXC5qCG4S2mzI+LdoS7xVEoZmYW9bsvqX8SvZ kp5lCWLhe9NUvxUehqB+2L6tLIxrVOwR8A3p7QaTPwPKIrxP5BdmNp5CEt3zWjzjvd vxWrH9gyF+pZwXYlUjEnwgGLojTs2lj0nXxyOFrc= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 8F6B144608; Sun, 20 Oct 2024 22:08:54 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:11 +0200 Message-ID: <20241020200851.1414766-3-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 02/18] swscale: rename SwsContext to SwsInternal 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 5rDGG4SPKY4n From: Niklas Haas And preserve the public SwsContext as separate name. The motivation here is that I want to turn SwsContext into a public struct, while keeping the internal implementation hidden. Additionally, I also want to be able to use multiple internal implementations, e.g. for GPU devices. This commit does not include any functional changes. For the most part, it is a simple rename. The only complications arise from the public facing API functions, which preserve their current type (and hence require an additional unwrapping step internally), and the checkasm test framework, which directly accesses SwsInternal. For consistency, the affected functions that need to maintain a distionction have generally been changed to refer to the SwsContext as *sws, and the SwsInternal as *c. In an upcoming commit, I will provide a backing definition for the public SwsContext, and update `sws_internal()` to dereference the internal struct instead of merely casting it. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/aarch64/hscale.S | 10 +- libswscale/aarch64/swscale.c | 18 +-- libswscale/aarch64/swscale_unscaled.c | 14 +- libswscale/alphablend.c | 2 +- libswscale/arm/swscale.c | 4 +- libswscale/arm/swscale_unscaled.c | 14 +- libswscale/gamma.c | 3 +- libswscale/hscale.c | 10 +- libswscale/hscale_fast_bilinear.c | 4 +- libswscale/input.c | 2 +- libswscale/loongarch/input_lasx.c | 2 +- libswscale/loongarch/input_lsx.c | 2 +- libswscale/loongarch/output_lasx.c | 22 +-- libswscale/loongarch/output_lsx.c | 22 +-- libswscale/loongarch/swscale.S | 8 +- libswscale/loongarch/swscale_init_loongarch.c | 6 +- libswscale/loongarch/swscale_lasx.c | 8 +- libswscale/loongarch/swscale_loongarch.h | 52 +++---- libswscale/loongarch/swscale_lsx.c | 4 +- libswscale/loongarch/yuv2rgb_lasx.c | 4 +- libswscale/loongarch/yuv2rgb_lsx.c | 4 +- libswscale/options.c | 2 +- libswscale/output.c | 108 +++++++-------- libswscale/ppc/swscale_altivec.c | 2 +- libswscale/ppc/swscale_ppc_template.c | 2 +- libswscale/ppc/swscale_vsx.c | 38 +++--- libswscale/ppc/yuv2rgb_altivec.c | 14 +- libswscale/ppc/yuv2rgb_altivec.h | 2 +- libswscale/ppc/yuv2yuv_altivec.c | 6 +- libswscale/riscv/swscale.c | 4 +- libswscale/slice.c | 6 +- libswscale/swscale.c | 104 ++++++++------ libswscale/swscale_internal.h | 128 ++++++++--------- libswscale/swscale_unscaled.c | 72 +++++----- libswscale/tests/floatimg_cmp.c | 2 +- libswscale/tests/swscale.c | 6 +- libswscale/utils.c | 129 ++++++++++-------- libswscale/vscale.c | 14 +- libswscale/x86/hscale_fast_bilinear_simd.c | 4 +- libswscale/x86/output.asm | 18 +-- libswscale/x86/scale.asm | 2 +- libswscale/x86/scale_avx2.asm | 2 +- libswscale/x86/swscale.c | 14 +- libswscale/x86/swscale_template.c | 44 +++--- libswscale/x86/w64xmmtest.c | 2 +- libswscale/x86/yuv2rgb.c | 20 +-- libswscale/yuv2rgb.c | 6 +- tests/checkasm/sw_gbrp.c | 80 ++++++----- tests/checkasm/sw_range_convert.c | 44 +++--- tests/checkasm/sw_rgb.c | 22 +-- tests/checkasm/sw_scale.c | 66 +++++---- tests/checkasm/sw_yuv2rgb.c | 20 +-- tests/checkasm/sw_yuv2yuv.c | 20 +-- 53 files changed, 635 insertions(+), 583 deletions(-) diff --git a/libswscale/aarch64/hscale.S b/libswscale/aarch64/hscale.S index b3873fc4b7..435460c1af 100644 --- a/libswscale/aarch64/hscale.S +++ b/libswscale/aarch64/hscale.S @@ -27,7 +27,7 @@ ; horizontal line scaling ; ; void hscaleto__ -; (SwsContext *c, int{16,32}_t *dst, +; (SwsInternal *c, int{16,32}_t *dst, ; int dstW, const uint{8,16}_t *src, ; const int16_t *filter, ; const int32_t *filterPos, int filterSize); @@ -92,7 +92,7 @@ function ff_hscale8to15_X8_neon, export=1 endfunc function ff_hscale8to15_X4_neon, export=1 -// x0 SwsContext *c (not used) +// x0 SwsInternal *c (not used) // x1 int16_t *dst // w2 int dstW // x3 const uint8_t *src @@ -199,7 +199,7 @@ function ff_hscale8to15_X4_neon, export=1 endfunc function ff_hscale8to15_4_neon, export=1 -// x0 SwsContext *c (not used) +// x0 SwsInternal *c (not used) // x1 int16_t *dst // x2 int dstW // x3 const uint8_t *src @@ -349,7 +349,7 @@ function ff_hscale8to15_4_neon, export=1 endfunc function ff_hscale8to19_4_neon, export=1 - // x0 SwsContext *c (unused) + // x0 SwsInternal *c (unused) // x1 int32_t *dst // w2 int dstW // x3 const uint8_t *src // treat it as uint16_t *src @@ -542,7 +542,7 @@ function ff_hscale8to19_X8_neon, export=1 endfunc function ff_hscale8to19_X4_neon, export=1 - // x0 SwsContext *c (not used) + // x0 SwsInternal *c (not used) // x1 int16_t *dst // w2 int dstW // x3 const uint8_t *src diff --git a/libswscale/aarch64/swscale.c b/libswscale/aarch64/swscale.c index eb907284e7..4c31b78ed8 100644 --- a/libswscale/aarch64/swscale.c +++ b/libswscale/aarch64/swscale.c @@ -41,7 +41,7 @@ void ff_hscale16to19_X4_neon_asm(int shift, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize); -static void ff_hscale16to15_4_neon(SwsContext *c, int16_t *_dst, int dstW, +static void ff_hscale16to15_4_neon(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { @@ -57,7 +57,7 @@ static void ff_hscale16to15_4_neon(SwsContext *c, int16_t *_dst, int dstW, } -static void ff_hscale16to15_X8_neon(SwsContext *c, int16_t *_dst, int dstW, +static void ff_hscale16to15_X8_neon(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { @@ -73,7 +73,7 @@ static void ff_hscale16to15_X8_neon(SwsContext *c, int16_t *_dst, int dstW, } -static void ff_hscale16to15_X4_neon(SwsContext *c, int16_t *_dst, int dstW, +static void ff_hscale16to15_X4_neon(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { @@ -88,7 +88,7 @@ static void ff_hscale16to15_X4_neon(SwsContext *c, int16_t *_dst, int dstW, ff_hscale16to15_X4_neon_asm(sh, _dst, dstW, _src, filter, filterPos, filterSize); } -static void ff_hscale16to19_4_neon(SwsContext *c, int16_t *_dst, int dstW, +static void ff_hscale16to19_4_neon(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { @@ -106,7 +106,7 @@ static void ff_hscale16to19_4_neon(SwsContext *c, int16_t *_dst, int dstW, } -static void ff_hscale16to19_X8_neon(SwsContext *c, int16_t *_dst, int dstW, +static void ff_hscale16to19_X8_neon(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { @@ -124,7 +124,7 @@ static void ff_hscale16to19_X8_neon(SwsContext *c, int16_t *_dst, int dstW, } -static void ff_hscale16to19_X4_neon(SwsContext *c, int16_t *_dst, int dstW, +static void ff_hscale16to19_X4_neon(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { @@ -144,7 +144,7 @@ static void ff_hscale16to19_X4_neon(SwsContext *c, int16_t *_dst, int dstW, #define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt) \ void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n ## _ ## opt( \ - SwsContext *c, int16_t *data, \ + SwsInternal *c, int16_t *data, \ int dstW, const uint8_t *src, \ const int16_t *filter, \ const int32_t *filterPos, int filterSize) @@ -223,7 +223,7 @@ void ff_chrRangeFromJpeg_neon(int16_t *dstU, int16_t *dstV, int width); void ff_lumRangeToJpeg_neon(int16_t *dst, int width); void ff_chrRangeToJpeg_neon(int16_t *dstU, int16_t *dstV, int width); -av_cold void ff_sws_init_range_convert_aarch64(SwsContext *c) +av_cold void ff_sws_init_range_convert_aarch64(SwsInternal *c) { if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) { if (c->dstBpc <= 14) { @@ -238,7 +238,7 @@ av_cold void ff_sws_init_range_convert_aarch64(SwsContext *c) } } -av_cold void ff_sws_init_swscale_aarch64(SwsContext *c) +av_cold void ff_sws_init_swscale_aarch64(SwsInternal *c) { int cpu_flags = av_get_cpu_flags(); diff --git a/libswscale/aarch64/swscale_unscaled.c b/libswscale/aarch64/swscale_unscaled.c index a7db4c033d..4f54120445 100644 --- a/libswscale/aarch64/swscale_unscaled.c +++ b/libswscale/aarch64/swscale_unscaled.c @@ -37,7 +37,7 @@ int ff_##ifmt##_to_##ofmt##_neon(int w, int h, int y_offset, \ int y_coeff); \ \ -static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *const src[], \ +static int ifmt##_to_##ofmt##_neon_wrapper(SwsInternal *c, const uint8_t *const src[], \ const int srcStride[], int srcSliceY, \ int srcSliceH, uint8_t *const dst[], \ const int dstStride[]) { \ @@ -65,7 +65,7 @@ int ff_##ifmt##_to_##ofmt##_neon(int w, int h, uint8_t *dst1, int linesize1, \ uint8_t *dst2, int linesize2); \ \ -static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *const src[], \ +static int ifmt##_to_##ofmt##_neon_wrapper(SwsInternal *c, const uint8_t *const src[], \ const int srcStride[], int srcSliceY, \ int srcSliceH, uint8_t *const dst[], \ const int dstStride[]) { \ @@ -102,7 +102,7 @@ int ff_##ifmt##_to_##ofmt##_neon(int w, int h, int y_offset, \ int y_coeff); \ \ -static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *const src[], \ +static int ifmt##_to_##ofmt##_neon_wrapper(SwsInternal *c, const uint8_t *const src[], \ const int srcStride[], int srcSliceY, \ int srcSliceH, uint8_t *const dst[], \ const int dstStride[]) { \ @@ -127,7 +127,7 @@ int ff_##ifmt##_to_##ofmt##_neon(int w, int h, uint8_t *dst1, int linesize1, \ uint8_t *dst2, int linesize2); \ \ -static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *const src[], \ +static int ifmt##_to_##ofmt##_neon_wrapper(SwsInternal *c, const uint8_t *const src[], \ const int srcStride[], int srcSliceY, \ int srcSliceH, uint8_t *const dst[], \ const int dstStride[]) { \ @@ -148,7 +148,7 @@ void ff_nv24_to_yuv420p_chroma_neon(uint8_t *dst1, int dstStride1, const uint8_t *src, int srcStride, int w, int h); -static int nv24_to_yuv420p_neon_wrapper(SwsContext *c, const uint8_t *const src[], +static int nv24_to_yuv420p_neon_wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -199,7 +199,7 @@ DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21) SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, gbrp, GBRP, accurate_rnd); \ } while (0) -static void get_unscaled_swscale_neon(SwsContext *c) { +static void get_unscaled_swscale_neon(SwsInternal *c) { int accurate_rnd = c->flags & SWS_ACCURATE_RND; SET_FF_NVX_TO_ALL_RGBX_FUNC(nv12, NV12, accurate_rnd); @@ -213,7 +213,7 @@ static void get_unscaled_swscale_neon(SwsContext *c) { c->convert_unscaled = nv24_to_yuv420p_neon_wrapper; } -void ff_get_unscaled_swscale_aarch64(SwsContext *c) +void ff_get_unscaled_swscale_aarch64(SwsInternal *c) { int cpu_flags = av_get_cpu_flags(); if (have_neon(cpu_flags)) diff --git a/libswscale/alphablend.c b/libswscale/alphablend.c index 8993a5bcd0..4ee23d3aee 100644 --- a/libswscale/alphablend.c +++ b/libswscale/alphablend.c @@ -20,7 +20,7 @@ #include "swscale_internal.h" -int ff_sws_alphablendaway(SwsContext *c, const uint8_t *const src[], +int ff_sws_alphablendaway(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { diff --git a/libswscale/arm/swscale.c b/libswscale/arm/swscale.c index 5f2fd2ce49..f4a96292eb 100644 --- a/libswscale/arm/swscale.c +++ b/libswscale/arm/swscale.c @@ -22,7 +22,7 @@ #include "libswscale/swscale_internal.h" #include "libavutil/arm/cpu.h" -void ff_hscale_8_to_15_neon(SwsContext *c, int16_t *dst, int dstW, +void ff_hscale_8_to_15_neon(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize); @@ -30,7 +30,7 @@ void ff_yuv2planeX_8_neon(const int16_t *filter, int filterSize, const int16_t **src, uint8_t *dest, int dstW, const uint8_t *dither, int offset); -av_cold void ff_sws_init_swscale_arm(SwsContext *c) +av_cold void ff_sws_init_swscale_arm(SwsInternal *c) { int cpu_flags = av_get_cpu_flags(); diff --git a/libswscale/arm/swscale_unscaled.c b/libswscale/arm/swscale_unscaled.c index 10216aaa4c..14685dbc50 100644 --- a/libswscale/arm/swscale_unscaled.c +++ b/libswscale/arm/swscale_unscaled.c @@ -34,7 +34,7 @@ extern void rgbx_to_nv12_neon_16(const uint8_t *src, uint8_t *y, uint8_t *chroma int y_stride, int c_stride, int src_stride, int32_t coeff_tbl[9]); -static int rgbx_to_nv12_neon_32_wrapper(SwsContext *context, const uint8_t *const src[], +static int rgbx_to_nv12_neon_32_wrapper(SwsInternal *context, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -48,7 +48,7 @@ static int rgbx_to_nv12_neon_32_wrapper(SwsContext *context, const uint8_t *cons return 0; } -static int rgbx_to_nv12_neon_16_wrapper(SwsContext *context, const uint8_t *const src[], +static int rgbx_to_nv12_neon_16_wrapper(SwsInternal *context, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], int dstStride[]) { @@ -78,7 +78,7 @@ int ff_##ifmt##_to_##ofmt##_neon(int w, int h, int y_offset, \ int y_coeff); \ \ -static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *const src[], \ +static int ifmt##_to_##ofmt##_neon_wrapper(SwsInternal *c, const uint8_t *const src[], \ const int srcStride[], int srcSliceY, \ int srcSliceH, uint8_t *const dst[], \ const int dstStride[]) { \ @@ -114,7 +114,7 @@ int ff_##ifmt##_to_##ofmt##_neon(int w, int h, int y_offset, \ int y_coeff); \ \ -static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *const src[], \ +static int ifmt##_to_##ofmt##_neon_wrapper(SwsInternal *c, const uint8_t *const src[], \ const int srcStride[], int srcSliceY, \ int srcSliceH, uint8_t *const dst[], \ const int dstStride[]) { \ @@ -160,7 +160,7 @@ DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21) SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, bgra, BGRA, accurate_rnd); \ } while (0) -static void get_unscaled_swscale_neon(SwsContext *c) { +static void get_unscaled_swscale_neon(SwsInternal *c) { int accurate_rnd = c->flags & SWS_ACCURATE_RND; if (c->srcFormat == AV_PIX_FMT_RGBA && c->dstFormat == AV_PIX_FMT_NV12 @@ -175,14 +175,14 @@ static void get_unscaled_swscale_neon(SwsContext *c) { SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv422p, YUV422P, accurate_rnd); } -void ff_get_unscaled_swscale_arm(SwsContext *c) +void ff_get_unscaled_swscale_arm(SwsInternal *c) { int cpu_flags = av_get_cpu_flags(); if (have_neon(cpu_flags)) get_unscaled_swscale_neon(c); } #else -void ff_get_unscaled_swscale_arm(SwsContext *c) +void ff_get_unscaled_swscale_arm(SwsInternal *c) { } #endif diff --git a/libswscale/gamma.c b/libswscale/gamma.c index 7c5534e1b7..7fb1b7763f 100644 --- a/libswscale/gamma.c +++ b/libswscale/gamma.c @@ -28,7 +28,7 @@ typedef struct GammaContext // gamma_convert expects 16 bit rgb format // it writes directly in src slice thus it must be modifiable (done through cascade context) -static int gamma_convert(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) +static int gamma_convert(SwsInternal *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) { GammaContext *instance = desc->instance; uint16_t *table = instance->table; @@ -70,4 +70,3 @@ int ff_init_gamma_convert(SwsFilterDescriptor *desc, SwsSlice * src, uint16_t *t return 0; } - diff --git a/libswscale/hscale.c b/libswscale/hscale.c index 5a949732bf..6cf910bf6e 100644 --- a/libswscale/hscale.c +++ b/libswscale/hscale.c @@ -36,7 +36,7 @@ typedef struct ColorContext uint32_t *pal; } ColorContext; -static int lum_h_scale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) +static int lum_h_scale(SwsInternal *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) { FilterContext *instance = desc->instance; int srcW = desc->src->width; @@ -84,7 +84,7 @@ static int lum_h_scale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int return sliceH; } -static int lum_convert(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) +static int lum_convert(SwsInternal *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) { int srcW = desc->src->width; ColorContext * instance = desc->instance; @@ -164,7 +164,7 @@ int ff_init_desc_hscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, return 0; } -static int chr_h_scale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) +static int chr_h_scale(SwsInternal *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) { FilterContext *instance = desc->instance; int srcW = AV_CEIL_RSHIFT(desc->src->width, desc->src->h_chr_sub_sample); @@ -200,7 +200,7 @@ static int chr_h_scale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int return sliceH; } -static int chr_convert(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) +static int chr_convert(SwsInternal *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) { int srcW = AV_CEIL_RSHIFT(desc->src->width, desc->src->h_chr_sub_sample); ColorContext * instance = desc->instance; @@ -270,7 +270,7 @@ int ff_init_desc_chscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst return 0; } -static int no_chr_scale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) +static int no_chr_scale(SwsInternal *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) { desc->dst->plane[1].sliceY = sliceY + sliceH - desc->dst->plane[1].available_lines; desc->dst->plane[1].sliceH = desc->dst->plane[1].available_lines; diff --git a/libswscale/hscale_fast_bilinear.c b/libswscale/hscale_fast_bilinear.c index 82d6177bde..abcfb95e2c 100644 --- a/libswscale/hscale_fast_bilinear.c +++ b/libswscale/hscale_fast_bilinear.c @@ -20,7 +20,7 @@ #include "swscale_internal.h" -void ff_hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth, +void ff_hyscale_fast_c(SwsInternal *c, int16_t *dst, int dstWidth, const uint8_t *src, int srcW, int xInc) { int i; @@ -35,7 +35,7 @@ void ff_hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth, dst[i] = src[srcW-1]*128; } -void ff_hcscale_fast_c(SwsContext *c, int16_t *dst1, int16_t *dst2, +void ff_hcscale_fast_c(SwsInternal *c, int16_t *dst1, int16_t *dst2, int dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc) { diff --git a/libswscale/input.c b/libswscale/input.c index bb5e31a428..a733ef35f8 100644 --- a/libswscale/input.c +++ b/libswscale/input.c @@ -1538,7 +1538,7 @@ static void rgbf16##endian_name##ToY_c(uint8_t *_dst, const uint8_t *_src, const rgbaf16_funcs_endian(le, 0) rgbaf16_funcs_endian(be, 1) -av_cold void ff_sws_init_input_funcs(SwsContext *c, +av_cold void ff_sws_init_input_funcs(SwsInternal *c, planar1_YV12_fn *lumToYV12, planar1_YV12_fn *alpToYV12, planar2_YV12_fn *chrToYV12, diff --git a/libswscale/loongarch/input_lasx.c b/libswscale/loongarch/input_lasx.c index 0f1d954880..b682179c6e 100644 --- a/libswscale/loongarch/input_lasx.c +++ b/libswscale/loongarch/input_lasx.c @@ -201,7 +201,7 @@ void planar_rgb_to_y_lasx(uint8_t *_dst, const uint8_t *src[4], int width, } } -av_cold void ff_sws_init_input_lasx(SwsContext *c) +av_cold void ff_sws_init_input_lasx(SwsInternal *c) { enum AVPixelFormat srcFormat = c->srcFormat; diff --git a/libswscale/loongarch/input_lsx.c b/libswscale/loongarch/input_lsx.c index 1bb04457bb..2bc7577961 100644 --- a/libswscale/loongarch/input_lsx.c +++ b/libswscale/loongarch/input_lsx.c @@ -21,7 +21,7 @@ #include "swscale_loongarch.h" -av_cold void ff_sws_init_input_lsx(SwsContext *c) +av_cold void ff_sws_init_input_lsx(SwsInternal *c) { enum AVPixelFormat srcFormat = c->srcFormat; diff --git a/libswscale/loongarch/output_lasx.c b/libswscale/loongarch/output_lasx.c index bc8ab8cf36..4e5ad3d802 100644 --- a/libswscale/loongarch/output_lasx.c +++ b/libswscale/loongarch/output_lasx.c @@ -227,7 +227,7 @@ yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2, } static void -yuv2rgb_X_template_lasx(SwsContext *c, const int16_t *lumFilter, +yuv2rgb_X_template_lasx(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, @@ -515,7 +515,7 @@ yuv2rgb_X_template_lasx(SwsContext *c, const int16_t *lumFilter, } static void -yuv2rgb_2_template_lasx(SwsContext *c, const int16_t *buf[2], +yuv2rgb_2_template_lasx(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, @@ -625,7 +625,7 @@ yuv2rgb_2_template_lasx(SwsContext *c, const int16_t *buf[2], } static void -yuv2rgb_1_template_lasx(SwsContext *c, const int16_t *buf0, +yuv2rgb_1_template_lasx(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target, @@ -782,7 +782,7 @@ yuv2rgb_1_template_lasx(SwsContext *c, const int16_t *buf0, } #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \ -static void name ## ext ## _X_lasx(SwsContext *c, const int16_t *lumFilter, \ +static void name ## ext ## _X_lasx(SwsInternal *c, const int16_t *lumFilter, \ const int16_t **lumSrc, int lumFilterSize, \ const int16_t *chrFilter, const int16_t **chrUSrc, \ const int16_t **chrVSrc, int chrFilterSize, \ @@ -796,7 +796,7 @@ static void name ## ext ## _X_lasx(SwsContext *c, const int16_t *lumFilter, #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \ YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \ -static void name ## ext ## _2_lasx(SwsContext *c, const int16_t *buf[2], \ +static void name ## ext ## _2_lasx(SwsInternal *c, const int16_t *buf[2], \ const int16_t *ubuf[2], const int16_t *vbuf[2], \ const int16_t *abuf[2], uint8_t *dest, int dstW, \ int yalpha, int uvalpha, int y) \ @@ -807,7 +807,7 @@ static void name ## ext ## _2_lasx(SwsContext *c, const int16_t *buf[2], #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \ YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \ -static void name ## ext ## _1_lasx(SwsContext *c, const int16_t *buf0, \ +static void name ## ext ## _1_lasx(SwsInternal *c, const int16_t *buf0, \ const int16_t *ubuf[2], const int16_t *vbuf[2], \ const int16_t *abuf0, uint8_t *dest, int dstW, \ int uvalpha, int y) \ @@ -834,7 +834,7 @@ YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0) YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0) // This function is copied from libswscale/output.c -static av_always_inline void yuv2rgb_write_full(SwsContext *c, +static av_always_inline void yuv2rgb_write_full(SwsInternal *c, uint8_t *dest, int i, int R, int A, int G, int B, int y, enum AVPixelFormat target, int hasAlpha, int err[4]) { @@ -1015,7 +1015,7 @@ static av_always_inline void yuv2rgb_write_full(SwsContext *c, } static void -yuv2rgb_full_X_template_lasx(SwsContext *c, const int16_t *lumFilter, +yuv2rgb_full_X_template_lasx(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, @@ -1222,7 +1222,7 @@ yuv2rgb_full_X_template_lasx(SwsContext *c, const int16_t *lumFilter, } static void -yuv2rgb_full_2_template_lasx(SwsContext *c, const int16_t *buf[2], +yuv2rgb_full_2_template_lasx(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, @@ -1435,7 +1435,7 @@ yuv2rgb_full_2_template_lasx(SwsContext *c, const int16_t *buf[2], } static void -yuv2rgb_full_1_template_lasx(SwsContext *c, const int16_t *buf0, +yuv2rgb_full_1_template_lasx(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target, @@ -1775,7 +1775,7 @@ YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0) YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0) -av_cold void ff_sws_init_output_lasx(SwsContext *c, +av_cold void ff_sws_init_output_lasx(SwsInternal *c, yuv2planar1_fn *yuv2plane1, yuv2planarX_fn *yuv2planeX, yuv2interleavedX_fn *yuv2nv12cX, diff --git a/libswscale/loongarch/output_lsx.c b/libswscale/loongarch/output_lsx.c index de9b1534ee..29fe30758a 100644 --- a/libswscale/loongarch/output_lsx.c +++ b/libswscale/loongarch/output_lsx.c @@ -148,7 +148,7 @@ yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2, } static void -yuv2rgb_X_template_lsx(SwsContext *c, const int16_t *lumFilter, +yuv2rgb_X_template_lsx(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, @@ -476,7 +476,7 @@ yuv2rgb_X_template_lsx(SwsContext *c, const int16_t *lumFilter, } static void -yuv2rgb_2_template_lsx(SwsContext *c, const int16_t *buf[2], +yuv2rgb_2_template_lsx(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, @@ -583,7 +583,7 @@ yuv2rgb_2_template_lsx(SwsContext *c, const int16_t *buf[2], } static void -yuv2rgb_1_template_lsx(SwsContext *c, const int16_t *buf0, +yuv2rgb_1_template_lsx(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target, @@ -733,7 +733,7 @@ yuv2rgb_1_template_lsx(SwsContext *c, const int16_t *buf0, } #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \ -static void name ## ext ## _X_lsx(SwsContext *c, const int16_t *lumFilter, \ +static void name ## ext ## _X_lsx(SwsInternal *c, const int16_t *lumFilter, \ const int16_t **lumSrc, int lumFilterSize, \ const int16_t *chrFilter, const int16_t **chrUSrc, \ const int16_t **chrVSrc, int chrFilterSize, \ @@ -747,7 +747,7 @@ static void name ## ext ## _X_lsx(SwsContext *c, const int16_t *lumFilter, #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \ YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \ -static void name ## ext ## _2_lsx(SwsContext *c, const int16_t *buf[2], \ +static void name ## ext ## _2_lsx(SwsInternal *c, const int16_t *buf[2], \ const int16_t *ubuf[2], const int16_t *vbuf[2], \ const int16_t *abuf[2], uint8_t *dest, int dstW, \ int yalpha, int uvalpha, int y) \ @@ -758,7 +758,7 @@ static void name ## ext ## _2_lsx(SwsContext *c, const int16_t *buf[2], #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \ YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \ -static void name ## ext ## _1_lsx(SwsContext *c, const int16_t *buf0, \ +static void name ## ext ## _1_lsx(SwsInternal *c, const int16_t *buf0, \ const int16_t *ubuf[2], const int16_t *vbuf[2], \ const int16_t *abuf0, uint8_t *dest, int dstW, \ int uvalpha, int y) \ @@ -784,7 +784,7 @@ YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0) YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0) // This function is copied from libswscale/output.c -static av_always_inline void yuv2rgb_write_full(SwsContext *c, +static av_always_inline void yuv2rgb_write_full(SwsInternal *c, uint8_t *dest, int i, int R, int A, int G, int B, int y, enum AVPixelFormat target, int hasAlpha, int err[4]) { @@ -964,7 +964,7 @@ static av_always_inline void yuv2rgb_write_full(SwsContext *c, } static void -yuv2rgb_full_X_template_lsx(SwsContext *c, const int16_t *lumFilter, +yuv2rgb_full_X_template_lsx(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, @@ -1143,7 +1143,7 @@ yuv2rgb_full_X_template_lsx(SwsContext *c, const int16_t *lumFilter, } static void -yuv2rgb_full_2_template_lsx(SwsContext *c, const int16_t *buf[2], +yuv2rgb_full_2_template_lsx(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, @@ -1332,7 +1332,7 @@ yuv2rgb_full_2_template_lsx(SwsContext *c, const int16_t *buf[2], } static void -yuv2rgb_full_1_template_lsx(SwsContext *c, const int16_t *buf0, +yuv2rgb_full_1_template_lsx(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target, @@ -1624,7 +1624,7 @@ YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0) YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0) -av_cold void ff_sws_init_output_lsx(SwsContext *c, +av_cold void ff_sws_init_output_lsx(SwsInternal *c, yuv2planar1_fn *yuv2plane1, yuv2planarX_fn *yuv2planeX, yuv2interleavedX_fn *yuv2nv12cX, diff --git a/libswscale/loongarch/swscale.S b/libswscale/loongarch/swscale.S index 67b1bc834d..a7e8513192 100644 --- a/libswscale/loongarch/swscale.S +++ b/libswscale/loongarch/swscale.S @@ -23,7 +23,7 @@ #include "libavcodec/loongarch/loongson_asm.S" -/* void ff_hscale_8_to_15_lsx(SwsContext *c, int16_t *dst, int dstW, +/* void ff_hscale_8_to_15_lsx(SwsInternal *c, int16_t *dst, int dstW, * const uint8_t *src, const int16_t *filter, * const int32_t *filterPos, int filterSize) */ @@ -470,7 +470,7 @@ function ff_hscale_8_to_15_lsx addi.d sp, sp, 72 endfunc -/* void ff_hscale_8_to_19_lsx(SwsContext *c, int16_t *dst, int dstW, +/* void ff_hscale_8_to_19_lsx(SwsInternal *c, int16_t *dst, int dstW, * const uint8_t *src, const int16_t *filter, * const int32_t *filterPos, int filterSize) */ @@ -917,7 +917,7 @@ function ff_hscale_8_to_19_lsx addi.d sp, sp, 72 endfunc -/* void ff_hscale_16_to_15_sub_lsx(SwsContext *c, int16_t *dst, int dstW, +/* void ff_hscale_16_to_15_sub_lsx(SwsInternal *c, int16_t *dst, int dstW, * const uint8_t *src, const int16_t *filter, * const int32_t *filterPos, int filterSize, int sh) */ @@ -1392,7 +1392,7 @@ function ff_hscale_16_to_15_sub_lsx addi.d sp, sp, 72 endfunc -/* void ff_hscale_16_to_19_sub_lsx(SwsContext *c, int16_t *dst, int dstW, +/* void ff_hscale_16_to_19_sub_lsx(SwsInternal *c, int16_t *dst, int dstW, * const uint8_t *src, const int16_t *filter, * const int32_t *filterPos, int filterSize, int sh) */ diff --git a/libswscale/loongarch/swscale_init_loongarch.c b/libswscale/loongarch/swscale_init_loongarch.c index 2a95ede6d9..7cc92be216 100644 --- a/libswscale/loongarch/swscale_init_loongarch.c +++ b/libswscale/loongarch/swscale_init_loongarch.c @@ -24,7 +24,7 @@ #include "libswscale/rgb2rgb.h" #include "libavutil/loongarch/cpu.h" -av_cold void ff_sws_init_range_convert_loongarch(SwsContext *c) +av_cold void ff_sws_init_range_convert_loongarch(SwsInternal *c) { int cpu_flags = av_get_cpu_flags(); @@ -58,7 +58,7 @@ av_cold void ff_sws_init_range_convert_loongarch(SwsContext *c) #endif // #if HAVE_LASX } -av_cold void ff_sws_init_swscale_loongarch(SwsContext *c) +av_cold void ff_sws_init_swscale_loongarch(SwsInternal *c) { int cpu_flags = av_get_cpu_flags(); if (have_lsx(cpu_flags)) { @@ -107,7 +107,7 @@ av_cold void rgb2rgb_init_loongarch(void) #endif // #if HAVE_LASX } -av_cold SwsFunc ff_yuv2rgb_init_loongarch(SwsContext *c) +av_cold SwsFunc ff_yuv2rgb_init_loongarch(SwsInternal *c) { int cpu_flags = av_get_cpu_flags(); #if HAVE_LASX diff --git a/libswscale/loongarch/swscale_lasx.c b/libswscale/loongarch/swscale_lasx.c index 3e0bae2cc2..79fa4c64b0 100644 --- a/libswscale/loongarch/swscale_lasx.c +++ b/libswscale/loongarch/swscale_lasx.c @@ -311,7 +311,7 @@ out = __lasx_xvadd_w(out, out0); \ } -void ff_hscale_8_to_15_lasx(SwsContext *c, int16_t *dst, int dstW, +void ff_hscale_8_to_15_lasx(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize) { @@ -471,7 +471,7 @@ void ff_hscale_8_to_15_lasx(SwsContext *c, int16_t *dst, int dstW, } } -void ff_hscale_8_to_19_lasx(SwsContext *c, int16_t *_dst, int dstW, +void ff_hscale_8_to_19_lasx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize) { @@ -673,7 +673,7 @@ void ff_hscale_8_to_19_lasx(SwsContext *c, int16_t *_dst, int dstW, out = __lasx_xvadd_w(out, out0); \ } -void ff_hscale_16_to_15_lasx(SwsContext *c, int16_t *dst, int dstW, +void ff_hscale_16_to_15_lasx(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { @@ -820,7 +820,7 @@ void ff_hscale_16_to_15_lasx(SwsContext *c, int16_t *dst, int dstW, } } -void ff_hscale_16_to_19_lasx(SwsContext *c, int16_t *_dst, int dstW, +void ff_hscale_16_to_19_lasx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { diff --git a/libswscale/loongarch/swscale_loongarch.h b/libswscale/loongarch/swscale_loongarch.h index a8f2a3214f..15aa983f20 100644 --- a/libswscale/loongarch/swscale_loongarch.h +++ b/libswscale/loongarch/swscale_loongarch.h @@ -26,27 +26,27 @@ #include "libswscale/swscale_internal.h" #include "config.h" -void ff_hscale_8_to_15_lsx(SwsContext *c, int16_t *dst, int dstW, +void ff_hscale_8_to_15_lsx(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize); -void ff_hscale_8_to_19_lsx(SwsContext *c, int16_t *_dst, int dstW, +void ff_hscale_8_to_19_lsx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize); -void ff_hscale_16_to_15_lsx(SwsContext *c, int16_t *_dst, int dstW, +void ff_hscale_16_to_15_lsx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize); -void ff_hscale_16_to_15_sub_lsx(SwsContext *c, int16_t *_dst, int dstW, +void ff_hscale_16_to_15_sub_lsx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize, int sh); -void ff_hscale_16_to_19_lsx(SwsContext *c, int16_t *_dst, int dstW, +void ff_hscale_16_to_19_lsx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize); -void ff_hscale_16_to_19_sub_lsx(SwsContext *c, int16_t *_dst, int dstW, +void ff_hscale_16_to_19_sub_lsx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize, int sh); @@ -89,9 +89,9 @@ void abgrToA_lsx(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, void rgbaToA_lsx(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused, void *opq); -av_cold void ff_sws_init_input_lsx(SwsContext *c); +av_cold void ff_sws_init_input_lsx(SwsInternal *c); -av_cold void ff_sws_init_output_lsx(SwsContext *c, +av_cold void ff_sws_init_output_lsx(SwsInternal *c, yuv2planar1_fn *yuv2plane1, yuv2planarX_fn *yuv2planeX, yuv2interleavedX_fn *yuv2nv12cX, @@ -100,38 +100,38 @@ av_cold void ff_sws_init_output_lsx(SwsContext *c, yuv2packedX_fn *yuv2packedX, yuv2anyX_fn *yuv2anyX); -int yuv420_rgb24_lsx(SwsContext *c, const uint8_t *const src[], const int srcStride[], +int yuv420_rgb24_lsx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]); -int yuv420_bgr24_lsx(SwsContext *c, const uint8_t *const src[], const int srcStride[], +int yuv420_bgr24_lsx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]); -int yuv420_rgba32_lsx(SwsContext *c, const uint8_t *const src[], const int srcStride[], +int yuv420_rgba32_lsx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]); -int yuv420_bgra32_lsx(SwsContext *c, const uint8_t *const src[], const int srcStride[], +int yuv420_bgra32_lsx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]); -int yuv420_argb32_lsx(SwsContext *c, const uint8_t *const src[], const int srcStride[], +int yuv420_argb32_lsx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]); -int yuv420_abgr32_lsx(SwsContext *c, const uint8_t *const src[], const int srcStride[], +int yuv420_abgr32_lsx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]); #if HAVE_LASX -void ff_hscale_8_to_15_lasx(SwsContext *c, int16_t *dst, int dstW, +void ff_hscale_8_to_15_lasx(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize); -void ff_hscale_8_to_19_lasx(SwsContext *c, int16_t *_dst, int dstW, +void ff_hscale_8_to_19_lasx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize); -void ff_hscale_16_to_19_lasx(SwsContext *c, int16_t *_dst, int dstW, +void ff_hscale_16_to_19_lasx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize); -void ff_hscale_16_to_15_lasx(SwsContext *c, int16_t *dst, int dstW, +void ff_hscale_16_to_15_lasx(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize); @@ -146,22 +146,22 @@ void planar_rgb_to_uv_lasx(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *src[4] void planar_rgb_to_y_lasx(uint8_t *_dst, const uint8_t *src[4], int width, int32_t *rgb2yuv, void *opq); -int yuv420_rgb24_lasx(SwsContext *c, const uint8_t *const src[], const int srcStride[], +int yuv420_rgb24_lasx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]); -int yuv420_bgr24_lasx(SwsContext *c, const uint8_t *const src[], const int srcStride[], +int yuv420_bgr24_lasx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]); -int yuv420_rgba32_lasx(SwsContext *c, const uint8_t *const src[], const int srcStride[], +int yuv420_rgba32_lasx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]); -int yuv420_bgra32_lasx(SwsContext *c, const uint8_t *const src[], const int srcStride[], +int yuv420_bgra32_lasx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]); -int yuv420_argb32_lasx(SwsContext *c, const uint8_t *const src[], const int srcStride[], +int yuv420_argb32_lasx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]); -int yuv420_abgr32_lasx(SwsContext *c, const uint8_t *const src[], const int srcStride[], +int yuv420_abgr32_lasx(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]); void ff_interleave_bytes_lasx(const uint8_t *src1, const uint8_t *src2, @@ -196,9 +196,9 @@ void abgrToA_lasx(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, void rgbaToA_lasx(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused, void *opq); -av_cold void ff_sws_init_input_lasx(SwsContext *c); +av_cold void ff_sws_init_input_lasx(SwsInternal *c); -av_cold void ff_sws_init_output_lasx(SwsContext *c, +av_cold void ff_sws_init_output_lasx(SwsInternal *c, yuv2planar1_fn *yuv2plane1, yuv2planarX_fn *yuv2planeX, yuv2interleavedX_fn *yuv2nv12cX, diff --git a/libswscale/loongarch/swscale_lsx.c b/libswscale/loongarch/swscale_lsx.c index da8eabfca3..dbdaf18de6 100644 --- a/libswscale/loongarch/swscale_lsx.c +++ b/libswscale/loongarch/swscale_lsx.c @@ -23,7 +23,7 @@ #include "swscale_loongarch.h" -void ff_hscale_16_to_15_lsx(SwsContext *c, int16_t *_dst, int dstW, +void ff_hscale_16_to_15_lsx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { @@ -39,7 +39,7 @@ void ff_hscale_16_to_15_lsx(SwsContext *c, int16_t *_dst, int dstW, ff_hscale_16_to_15_sub_lsx(c, _dst, dstW, _src, filter, filterPos, filterSize, sh); } -void ff_hscale_16_to_19_lsx(SwsContext *c, int16_t *_dst, int dstW, +void ff_hscale_16_to_19_lsx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { diff --git a/libswscale/loongarch/yuv2rgb_lasx.c b/libswscale/loongarch/yuv2rgb_lasx.c index 8bf6a7955a..1b36d617b5 100644 --- a/libswscale/loongarch/yuv2rgb_lasx.c +++ b/libswscale/loongarch/yuv2rgb_lasx.c @@ -160,7 +160,7 @@ } #define YUV2RGBFUNC(func_name, dst_type, alpha) \ - int func_name(SwsContext *c, const uint8_t *const src[], \ + int func_name(SwsInternal *c, const uint8_t *const src[], \ const int srcStride[], int srcSliceY, int srcSliceH, \ uint8_t *const dst[], const int dstStride[]) \ { \ @@ -188,7 +188,7 @@ for(x = 0; x < h_size; x++) { \ #define YUV2RGBFUNC32(func_name, dst_type, alpha) \ - int func_name(SwsContext *c, const uint8_t *const src[], \ + int func_name(SwsInternal *c, const uint8_t *const src[], \ const int srcStride[], int srcSliceY, int srcSliceH, \ uint8_t *const dst[], const int dstStride[]) \ { \ diff --git a/libswscale/loongarch/yuv2rgb_lsx.c b/libswscale/loongarch/yuv2rgb_lsx.c index 31f22a764f..f2f424265f 100644 --- a/libswscale/loongarch/yuv2rgb_lsx.c +++ b/libswscale/loongarch/yuv2rgb_lsx.c @@ -113,7 +113,7 @@ } #define YUV2RGBFUNC(func_name, dst_type, alpha) \ - int func_name(SwsContext *c, const uint8_t *const src[], \ + int func_name(SwsInternal *c, const uint8_t *const src[], \ const int srcStride[], int srcSliceY, int srcSliceH, \ uint8_t *const dst[], const int dstStride[]) \ { \ @@ -142,7 +142,7 @@ for(x = 0; x < h_size; x++) { \ #define YUV2RGBFUNC32(func_name, dst_type, alpha) \ - int func_name(SwsContext *c, const uint8_t *const src[], \ + int func_name(SwsInternal *c, const uint8_t *const src[], \ const int srcStride[], int srcSliceY, int srcSliceH, \ uint8_t *const dst[], const int dstStride[]) \ { \ diff --git a/libswscale/options.c b/libswscale/options.c index 6337a9f28d..56b1d2235d 100644 --- a/libswscale/options.c +++ b/libswscale/options.c @@ -27,7 +27,7 @@ static const char *sws_context_to_name(void *ptr) return "swscaler"; } -#define OFFSET(x) offsetof(SwsContext, x) +#define OFFSET(x) offsetof(SwsInternal, x) #define DEFAULT 0 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM diff --git a/libswscale/output.c b/libswscale/output.c index c95ccdfc36..56f16dfd34 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -597,7 +597,7 @@ yuv2p01x_wrapper(12) } static av_always_inline void -yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter, +yuv2mono_X_c_template(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, @@ -650,7 +650,7 @@ yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter, } static av_always_inline void -yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2], +yuv2mono_2_c_template(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, @@ -711,7 +711,7 @@ yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2], } static av_always_inline void -yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0, +yuv2mono_1_c_template(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target) @@ -762,7 +762,7 @@ yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0, #undef accumulate_bit #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \ -static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \ +static void name ## ext ## _X_c(SwsInternal *c, const int16_t *lumFilter, \ const int16_t **lumSrc, int lumFilterSize, \ const int16_t *chrFilter, const int16_t **chrUSrc, \ const int16_t **chrVSrc, int chrFilterSize, \ @@ -774,7 +774,7 @@ static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \ alpSrc, dest, dstW, y, fmt); \ } \ \ -static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \ +static void name ## ext ## _2_c(SwsInternal *c, const int16_t *buf[2], \ const int16_t *ubuf[2], const int16_t *vbuf[2], \ const int16_t *abuf[2], uint8_t *dest, int dstW, \ int yalpha, int uvalpha, int y) \ @@ -783,7 +783,7 @@ static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \ dest, dstW, yalpha, uvalpha, y, fmt); \ } \ \ -static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \ +static void name ## ext ## _1_c(SwsInternal *c, const int16_t *buf0, \ const int16_t *ubuf[2], const int16_t *vbuf[2], \ const int16_t *abuf0, uint8_t *dest, int dstW, \ int uvalpha, int y) \ @@ -815,7 +815,7 @@ YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK) } static av_always_inline void -yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter, +yuv2422_X_c_template(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, @@ -854,7 +854,7 @@ yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter, } static av_always_inline void -yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2], +yuv2422_2_c_template(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, @@ -887,7 +887,7 @@ yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2], } static av_always_inline void -yuv2422_1_c_template(SwsContext *c, const int16_t *buf0, +yuv2422_1_c_template(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target) @@ -947,7 +947,7 @@ YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422) } static av_always_inline void -yuv2ya16_X_c_template(SwsContext *c, const int16_t *lumFilter, +yuv2ya16_X_c_template(SwsInternal *c, const int16_t *lumFilter, const int32_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int32_t **unused_chrUSrc, const int32_t **unused_chrVSrc, int unused_chrFilterSize, @@ -986,7 +986,7 @@ yuv2ya16_X_c_template(SwsContext *c, const int16_t *lumFilter, } static av_always_inline void -yuv2ya16_2_c_template(SwsContext *c, const int32_t *buf[2], +yuv2ya16_2_c_template(SwsInternal *c, const int32_t *buf[2], const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2], const int32_t *abuf[2], uint16_t *dest, int dstW, int yalpha, int unused_uvalpha, int y, @@ -1019,7 +1019,7 @@ yuv2ya16_2_c_template(SwsContext *c, const int32_t *buf[2], } static av_always_inline void -yuv2ya16_1_c_template(SwsContext *c, const int32_t *buf0, +yuv2ya16_1_c_template(SwsInternal *c, const int32_t *buf0, const int32_t *unused_ubuf[2], const int32_t *unused_vbuf[2], const int32_t *abuf0, uint16_t *dest, int dstW, int unused_uvalpha, int y, enum AVPixelFormat target, @@ -1046,7 +1046,7 @@ yuv2ya16_1_c_template(SwsContext *c, const int32_t *buf0, } static av_always_inline void -yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter, +yuv2rgba64_X_c_template(SwsInternal *c, const int16_t *lumFilter, const int32_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int32_t **chrUSrc, const int32_t **chrVSrc, int chrFilterSize, @@ -1129,7 +1129,7 @@ yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter, } static av_always_inline void -yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2], +yuv2rgba64_2_c_template(SwsInternal *c, const int32_t *buf[2], const int32_t *ubuf[2], const int32_t *vbuf[2], const int32_t *abuf[2], uint16_t *dest, int dstW, int yalpha, int uvalpha, int y, @@ -1195,7 +1195,7 @@ yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2], } static av_always_inline void -yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0, +yuv2rgba64_1_c_template(SwsInternal *c, const int32_t *buf0, const int32_t *ubuf[2], const int32_t *vbuf[2], const int32_t *abuf0, uint16_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target, @@ -1299,7 +1299,7 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0, } static av_always_inline void -yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter, +yuv2rgba64_full_X_c_template(SwsInternal *c, const int16_t *lumFilter, const int32_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int32_t **chrUSrc, const int32_t **chrVSrc, int chrFilterSize, @@ -1364,7 +1364,7 @@ yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter, } static av_always_inline void -yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2], +yuv2rgba64_full_2_c_template(SwsInternal *c, const int32_t *buf[2], const int32_t *ubuf[2], const int32_t *vbuf[2], const int32_t *abuf[2], uint16_t *dest, int dstW, int yalpha, int uvalpha, int y, @@ -1417,7 +1417,7 @@ yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2], } static av_always_inline void -yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, +yuv2rgba64_full_1_c_template(SwsInternal *c, const int32_t *buf0, const int32_t *ubuf[2], const int32_t *vbuf[2], const int32_t *abuf0, uint16_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target, @@ -1499,7 +1499,7 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, #undef b_r #define YUV2PACKED16WRAPPER_EXT(name, base, ext, fmt, is_be, hasAlpha, eightbytes) \ -static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \ +static void name ## ext ## _X_c(SwsInternal *c, const int16_t *lumFilter, \ const int16_t **_lumSrc, int lumFilterSize, \ const int16_t *chrFilter, const int16_t **_chrUSrc, \ const int16_t **_chrVSrc, int chrFilterSize, \ @@ -1516,7 +1516,7 @@ static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \ alpSrc, dest, dstW, y, fmt, hasAlpha, eightbytes, is_be); \ } \ \ -static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \ +static void name ## ext ## _2_c(SwsInternal *c, const int16_t *_buf[2], \ const int16_t *_ubuf[2], const int16_t *_vbuf[2], \ const int16_t *_abuf[2], uint8_t *_dest, int dstW, \ int yalpha, int uvalpha, int y) \ @@ -1530,7 +1530,7 @@ static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \ dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha, eightbytes, is_be); \ } \ \ -static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \ +static void name ## ext ## _1_c(SwsInternal *c, const int16_t *_buf0, \ const int16_t *_ubuf[2], const int16_t *_vbuf[2], \ const int16_t *_abuf0, uint8_t *_dest, int dstW, \ int uvalpha, int y) \ @@ -1709,7 +1709,7 @@ yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2, } static av_always_inline void -yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter, +yuv2rgb_X_c_template(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, @@ -1763,7 +1763,7 @@ yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter, } static av_always_inline void -yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2], +yuv2rgb_2_c_template(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, @@ -1803,7 +1803,7 @@ yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2], } static av_always_inline void -yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0, +yuv2rgb_1_c_template(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target, @@ -1859,7 +1859,7 @@ yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0, } #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \ -static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \ +static void name ## ext ## _X_c(SwsInternal *c, const int16_t *lumFilter, \ const int16_t **lumSrc, int lumFilterSize, \ const int16_t *chrFilter, const int16_t **chrUSrc, \ const int16_t **chrVSrc, int chrFilterSize, \ @@ -1873,7 +1873,7 @@ static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \ #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \ YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \ -static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \ +static void name ## ext ## _2_c(SwsInternal *c, const int16_t *buf[2], \ const int16_t *ubuf[2], const int16_t *vbuf[2], \ const int16_t *abuf[2], uint8_t *dest, int dstW, \ int yalpha, int uvalpha, int y) \ @@ -1884,7 +1884,7 @@ static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \ #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \ YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \ -static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \ +static void name ## ext ## _1_c(SwsInternal *c, const int16_t *buf0, \ const int16_t *ubuf[2], const int16_t *vbuf[2], \ const int16_t *abuf0, uint8_t *dest, int dstW, \ int uvalpha, int y) \ @@ -1915,7 +1915,7 @@ YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0) YUV2RGBWRAPPER(yuv2, rgb, x2rgb10, AV_PIX_FMT_X2RGB10, 0) YUV2RGBWRAPPER(yuv2, rgb, x2bgr10, AV_PIX_FMT_X2BGR10, 0) -static av_always_inline void yuv2rgb_write_full(SwsContext *c, +static av_always_inline void yuv2rgb_write_full(SwsInternal *c, uint8_t *dest, int i, int Y, int A, int U, int V, int y, enum AVPixelFormat target, int hasAlpha, int err[4]) { @@ -2066,7 +2066,7 @@ static av_always_inline void yuv2rgb_write_full(SwsContext *c, } static av_always_inline void -yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter, +yuv2rgb_full_X_c_template(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, @@ -2116,7 +2116,7 @@ yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter, } static av_always_inline void -yuv2rgb_full_2_c_template(SwsContext *c, const int16_t *buf[2], +yuv2rgb_full_2_c_template(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, @@ -2161,7 +2161,7 @@ yuv2rgb_full_2_c_template(SwsContext *c, const int16_t *buf[2], } static av_always_inline void -yuv2rgb_full_1_c_template(SwsContext *c, const int16_t *buf0, +yuv2rgb_full_1_c_template(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target, @@ -2242,7 +2242,7 @@ YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0) YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0) static void -yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter, +yuv2gbrp_full_X_c(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, @@ -2324,7 +2324,7 @@ yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter, } static void -yuv2gbrp16_full_X_c(SwsContext *c, const int16_t *lumFilter, +yuv2gbrp16_full_X_c(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrcx, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrcx, const int16_t **chrVSrcx, int chrFilterSize, @@ -2396,7 +2396,7 @@ yuv2gbrp16_full_X_c(SwsContext *c, const int16_t *lumFilter, } static void -yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t *lumFilter, +yuv2gbrpf32_full_X_c(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrcx, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrcx, const int16_t **chrVSrcx, int chrFilterSize, @@ -2472,7 +2472,7 @@ yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t *lumFilter, } static void -yuv2ya8_1_c(SwsContext *c, const int16_t *buf0, +yuv2ya8_1_c(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y) @@ -2498,7 +2498,7 @@ yuv2ya8_1_c(SwsContext *c, const int16_t *buf0, } static void -yuv2ya8_2_c(SwsContext *c, const int16_t *buf[2], +yuv2ya8_2_c(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) @@ -2529,7 +2529,7 @@ yuv2ya8_2_c(SwsContext *c, const int16_t *buf[2], } static void -yuv2ya8_X_c(SwsContext *c, const int16_t *lumFilter, +yuv2ya8_X_c(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, @@ -2572,7 +2572,7 @@ yuv2ya8_X_c(SwsContext *c, const int16_t *lumFilter, } static av_always_inline void -yuv2ayuv64_X_c(SwsContext *c, const int16_t *lumFilter, +yuv2ayuv64_X_c(SwsInternal *c, const int16_t *lumFilter, const int16_t **_lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **_chrUSrc, const int16_t **_chrVSrc, int chrFilterSize, @@ -2624,7 +2624,7 @@ yuv2ayuv64_X_c(SwsContext *c, const int16_t *lumFilter, #define YUV2AYUV64(BE_LE, is_be) \ static void \ -yuv2ayuv64 ## BE_LE ##_X_c(SwsContext *c, const int16_t *lumFilter, \ +yuv2ayuv64 ## BE_LE ##_X_c(SwsInternal *c, const int16_t *lumFilter, \ const int16_t **lumSrc, int lumFilterSize, \ const int16_t *chrFilter, const int16_t **chrUSrc, \ const int16_t **chrVSrc, int chrFilterSize, \ @@ -2639,7 +2639,7 @@ YUV2AYUV64(le, 0) YUV2AYUV64(be, 1) static av_always_inline void -yuv2v30_X_c_template(SwsContext *c, const int16_t *lumFilter, +yuv2v30_X_c_template(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, @@ -2671,7 +2671,7 @@ yuv2v30_X_c_template(SwsContext *c, const int16_t *lumFilter, } #define V30LE_WRAPPER(name, shift) \ -static void yuv2 ## name ## _X_c(SwsContext *c, const int16_t *lumFilter, \ +static void yuv2 ## name ## _X_c(SwsInternal *c, const int16_t *lumFilter, \ const int16_t **lumSrc, int lumFilterSize, \ const int16_t *chrFilter, const int16_t **chrUSrc, \ const int16_t **chrVSrc, int chrFilterSize, \ @@ -2694,7 +2694,7 @@ V30LE_WRAPPER(v30xle, 2) } static void -yuv2xv36_X_c(SwsContext *c, const int16_t *lumFilter, +yuv2xv36_X_c(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, @@ -2724,7 +2724,7 @@ yuv2xv36_X_c(SwsContext *c, const int16_t *lumFilter, #define YUV2XV36(BE_LE, is_be) \ static void \ -yuv2xv36 ## BE_LE ##_X_c(SwsContext *c, const int16_t *lumFilter, \ +yuv2xv36 ## BE_LE ##_X_c(SwsInternal *c, const int16_t *lumFilter, \ const int16_t **lumSrc, int lumFilterSize, \ const int16_t *chrFilter, const int16_t **chrUSrc, \ const int16_t **chrVSrc, int chrFilterSize, \ @@ -2757,7 +2757,7 @@ YUV2XV36(be, 1) } static av_always_inline void -yuv2ayuv_1_c_template(SwsContext *c, const int16_t *buf0, +yuv2ayuv_1_c_template(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target) @@ -2813,7 +2813,7 @@ yuv2ayuv_1_c_template(SwsContext *c, const int16_t *buf0, } static av_always_inline void -yuv2ayuv_2_c_template(SwsContext *c, const int16_t *buf[2], +yuv2ayuv_2_c_template(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, @@ -2855,7 +2855,7 @@ yuv2ayuv_2_c_template(SwsContext *c, const int16_t *buf[2], } static av_always_inline void -yuv2ayuv_X_c_template(SwsContext *c, const int16_t *lumFilter, +yuv2ayuv_X_c_template(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, @@ -2908,7 +2908,7 @@ yuv2ayuv_X_c_template(SwsContext *c, const int16_t *lumFilter, #undef output_pixels #define AYUVPACKEDWRAPPER(name, fmt) \ -static void yuv2 ## name ## _X_c(SwsContext *c, const int16_t *lumFilter, \ +static void yuv2 ## name ## _X_c(SwsInternal *c, const int16_t *lumFilter, \ const int16_t **lumSrc, int lumFilterSize, \ const int16_t *chrFilter, const int16_t **chrUSrc, \ const int16_t **chrVSrc, int chrFilterSize, \ @@ -2920,7 +2920,7 @@ static void yuv2 ## name ## _X_c(SwsContext *c, const int16_t *lumFilter, \ alpSrc, dest, dstW, y, fmt); \ } \ \ -static void yuv2 ## name ## _2_c(SwsContext *c, const int16_t *buf[2], \ +static void yuv2 ## name ## _2_c(SwsInternal *c, const int16_t *buf[2], \ const int16_t *ubuf[2], const int16_t *vbuf[2], \ const int16_t *abuf[2], uint8_t *dest, int dstW, \ int yalpha, int uvalpha, int y) \ @@ -2929,7 +2929,7 @@ static void yuv2 ## name ## _2_c(SwsContext *c, const int16_t *buf[2], \ dest, dstW, yalpha, uvalpha, y, fmt); \ } \ \ -static void yuv2 ## name ## _1_c(SwsContext *c, const int16_t *buf0, \ +static void yuv2 ## name ## _1_c(SwsInternal *c, const int16_t *buf0, \ const int16_t *ubuf[2], const int16_t *vbuf[2], \ const int16_t *abuf0, uint8_t *dest, int dstW, \ int uvalpha, int y) \ @@ -2948,7 +2948,7 @@ AYUVPACKEDWRAPPER(uyva, AV_PIX_FMT_UYVA) #define yuv2y2xx_wrapper(bits) \ static void \ - yuv2y2 ## bits ## le_X_c(SwsContext *c, const int16_t *lumFilter, \ + yuv2y2 ## bits ## le_X_c(SwsInternal *c, const int16_t *lumFilter, \ const int16_t **lumSrc, int lumFilterSize, \ const int16_t *chrFilter, \ const int16_t **chrUSrc, \ @@ -2984,7 +2984,7 @@ yuv2y2xx_wrapper(10) yuv2y2xx_wrapper(12) static void -yuv2vyu444_1_c(SwsContext *c, const int16_t *buf0, +yuv2vyu444_1_c(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y) @@ -3029,7 +3029,7 @@ yuv2vyu444_1_c(SwsContext *c, const int16_t *buf0, } static void -yuv2vyu444_2_c(SwsContext *c, const int16_t *buf[2], +yuv2vyu444_2_c(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) @@ -3063,7 +3063,7 @@ yuv2vyu444_2_c(SwsContext *c, const int16_t *buf[2], } static void -yuv2vyu444_X_c(SwsContext *c, const int16_t *lumFilter, +yuv2vyu444_X_c(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, @@ -3104,7 +3104,7 @@ yuv2vyu444_X_c(SwsContext *c, const int16_t *lumFilter, #undef output_pixel -av_cold void ff_sws_init_output_funcs(SwsContext *c, +av_cold void ff_sws_init_output_funcs(SwsInternal *c, yuv2planar1_fn *yuv2plane1, yuv2planarX_fn *yuv2planeX, yuv2interleavedX_fn *yuv2nv12cX, diff --git a/libswscale/ppc/swscale_altivec.c b/libswscale/ppc/swscale_altivec.c index 9bf72738df..836aaab1f8 100644 --- a/libswscale/ppc/swscale_altivec.c +++ b/libswscale/ppc/swscale_altivec.c @@ -229,7 +229,7 @@ yuv2plane1_float(yuv2plane1_float_bswap_altivec, uint32_t, BE) #endif /* HAVE_ALTIVEC */ -av_cold void ff_sws_init_swscale_ppc(SwsContext *c) +av_cold void ff_sws_init_swscale_ppc(SwsInternal *c) { #if HAVE_ALTIVEC enum AVPixelFormat dstFormat = c->dstFormat; diff --git a/libswscale/ppc/swscale_ppc_template.c b/libswscale/ppc/swscale_ppc_template.c index 3c2addd4a4..46fd2bee62 100644 --- a/libswscale/ppc/swscale_ppc_template.c +++ b/libswscale/ppc/swscale_ppc_template.c @@ -97,7 +97,7 @@ static void FUNC(yuv2planeX)(const int16_t *filter, int filterSize, yuv2planeX_u(filter, filterSize, src, dest, dstW, dither, offset, i); } -static void FUNC(hScale_real)(SwsContext *c, int16_t *dst, int dstW, +static void FUNC(hScale_real)(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize) { diff --git a/libswscale/ppc/swscale_vsx.c b/libswscale/ppc/swscale_vsx.c index 7080a16aee..f83bb96ec9 100644 --- a/libswscale/ppc/swscale_vsx.c +++ b/libswscale/ppc/swscale_vsx.c @@ -526,7 +526,7 @@ yuv2NBPSX(16, LE, 0, 16, int32_t) } static av_always_inline void -yuv2rgb_full_X_vsx_template(SwsContext *c, const int16_t *lumFilter, +yuv2rgb_full_X_vsx_template(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, @@ -677,7 +677,7 @@ yuv2rgb_full_X_vsx_template(SwsContext *c, const int16_t *lumFilter, static av_always_inline void -yuv2rgb_full_2_vsx_template(SwsContext *c, const int16_t *buf[2], +yuv2rgb_full_2_vsx_template(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, @@ -799,7 +799,7 @@ yuv2rgb_full_2_vsx_template(SwsContext *c, const int16_t *buf[2], } static av_always_inline void -yuv2rgb_2_vsx_template(SwsContext *c, const int16_t *buf[2], +yuv2rgb_2_vsx_template(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, @@ -975,7 +975,7 @@ yuv2rgb_2_vsx_template(SwsContext *c, const int16_t *buf[2], #undef SETUP static av_always_inline void -yuv2rgb_full_1_vsx_template(SwsContext *c, const int16_t *buf0, +yuv2rgb_full_1_vsx_template(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target, @@ -1104,7 +1104,7 @@ yuv2rgb_full_1_vsx_template(SwsContext *c, const int16_t *buf0, } static av_always_inline void -yuv2rgb_1_vsx_template(SwsContext *c, const int16_t *buf0, +yuv2rgb_1_vsx_template(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target, @@ -1290,7 +1290,7 @@ yuv2rgb_1_vsx_template(SwsContext *c, const int16_t *buf0, #undef WRITERGB #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \ -static void name ## ext ## _X_vsx(SwsContext *c, const int16_t *lumFilter, \ +static void name ## ext ## _X_vsx(SwsInternal *c, const int16_t *lumFilter, \ const int16_t **lumSrc, int lumFilterSize, \ const int16_t *chrFilter, const int16_t **chrUSrc, \ const int16_t **chrVSrc, int chrFilterSize, \ @@ -1303,7 +1303,7 @@ static void name ## ext ## _X_vsx(SwsContext *c, const int16_t *lumFilter, \ } #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \ -static void name ## ext ## _2_vsx(SwsContext *c, const int16_t *buf[2], \ +static void name ## ext ## _2_vsx(SwsInternal *c, const int16_t *buf[2], \ const int16_t *ubuf[2], const int16_t *vbuf[2], \ const int16_t *abuf[2], uint8_t *dest, int dstW, \ int yalpha, int uvalpha, int y) \ @@ -1313,7 +1313,7 @@ static void name ## ext ## _2_vsx(SwsContext *c, const int16_t *buf[2], \ } #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \ -static void name ## ext ## _1_vsx(SwsContext *c, const int16_t *buf0, \ +static void name ## ext ## _1_vsx(SwsInternal *c, const int16_t *buf0, \ const int16_t *ubuf[2], const int16_t *vbuf[2], \ const int16_t *abuf0, uint8_t *dest, int dstW, \ int uvalpha, int y) \ @@ -1425,7 +1425,7 @@ write422(const vec_s16 vy1, const vec_s16 vy2, } static av_always_inline void -yuv2422_X_vsx_template(SwsContext *c, const int16_t *lumFilter, +yuv2422_X_vsx_template(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, @@ -1533,7 +1533,7 @@ yuv2422_X_vsx_template(SwsContext *c, const int16_t *lumFilter, } static av_always_inline void -yuv2422_2_vsx_template(SwsContext *c, const int16_t *buf[2], +yuv2422_2_vsx_template(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y, @@ -1567,7 +1567,7 @@ yuv2422_2_vsx_template(SwsContext *c, const int16_t *buf[2], #undef SETUP static av_always_inline void -yuv2422_1_vsx_template(SwsContext *c, const int16_t *buf0, +yuv2422_1_vsx_template(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum AVPixelFormat target) @@ -1627,7 +1627,7 @@ yuv2422_1_vsx_template(SwsContext *c, const int16_t *buf0, } #define YUV2PACKEDWRAPPERX(name, base, ext, fmt) \ -static void name ## ext ## _X_vsx(SwsContext *c, const int16_t *lumFilter, \ +static void name ## ext ## _X_vsx(SwsInternal *c, const int16_t *lumFilter, \ const int16_t **lumSrc, int lumFilterSize, \ const int16_t *chrFilter, const int16_t **chrUSrc, \ const int16_t **chrVSrc, int chrFilterSize, \ @@ -1641,7 +1641,7 @@ static void name ## ext ## _X_vsx(SwsContext *c, const int16_t *lumFilter, \ #define YUV2PACKEDWRAPPER2(name, base, ext, fmt) \ YUV2PACKEDWRAPPERX(name, base, ext, fmt) \ -static void name ## ext ## _2_vsx(SwsContext *c, const int16_t *buf[2], \ +static void name ## ext ## _2_vsx(SwsInternal *c, const int16_t *buf[2], \ const int16_t *ubuf[2], const int16_t *vbuf[2], \ const int16_t *abuf[2], uint8_t *dest, int dstW, \ int yalpha, int uvalpha, int y) \ @@ -1652,7 +1652,7 @@ static void name ## ext ## _2_vsx(SwsContext *c, const int16_t *buf[2], \ #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \ YUV2PACKEDWRAPPER2(name, base, ext, fmt) \ -static void name ## ext ## _1_vsx(SwsContext *c, const int16_t *buf0, \ +static void name ## ext ## _1_vsx(SwsInternal *c, const int16_t *buf0, \ const int16_t *ubuf[2], const int16_t *vbuf[2], \ const int16_t *abuf0, uint8_t *dest, int dstW, \ int uvalpha, int y) \ @@ -1666,7 +1666,7 @@ YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422) YUV2PACKEDWRAPPER(yuv2, 422, yvyu422, AV_PIX_FMT_YVYU422) YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422) -static void hyscale_fast_vsx(SwsContext *c, int16_t *dst, int dstWidth, +static void hyscale_fast_vsx(SwsInternal *c, int16_t *dst, int dstWidth, const uint8_t *src, int srcW, int xInc) { int i; @@ -1781,7 +1781,7 @@ static void hyscale_fast_vsx(SwsContext *c, int16_t *dst, int dstWidth, vec_st((vec_s16) vd_l, 0, &out[i]); \ vec_st((vec_s16) vd_r, 0, &out[i + 8]) -static void hcscale_fast_vsx(SwsContext *c, int16_t *dst1, int16_t *dst2, +static void hcscale_fast_vsx(SwsInternal *c, int16_t *dst1, int16_t *dst2, int dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc) { @@ -1858,7 +1858,7 @@ static void hcscale_fast_vsx(SwsContext *c, int16_t *dst1, int16_t *dst2, #undef HCSCALE -static void hScale16To19_vsx(SwsContext *c, int16_t *_dst, int dstW, +static void hScale16To19_vsx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { @@ -1936,7 +1936,7 @@ static void hScale16To19_vsx(SwsContext *c, int16_t *_dst, int dstW, } } -static void hScale16To15_vsx(SwsContext *c, int16_t *dst, int dstW, +static void hScale16To15_vsx(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { @@ -2016,7 +2016,7 @@ static void hScale16To15_vsx(SwsContext *c, int16_t *dst, int dstW, #endif /* HAVE_VSX */ -av_cold void ff_sws_init_swscale_vsx(SwsContext *c) +av_cold void ff_sws_init_swscale_vsx(SwsInternal *c) { #if HAVE_VSX enum AVPixelFormat dstFormat = c->dstFormat; diff --git a/libswscale/ppc/yuv2rgb_altivec.c b/libswscale/ppc/yuv2rgb_altivec.c index 3ba6461dfb..9db305f43f 100644 --- a/libswscale/ppc/yuv2rgb_altivec.c +++ b/libswscale/ppc/yuv2rgb_altivec.c @@ -252,7 +252,7 @@ static const vector unsigned char (vector unsigned short) \ vec_max(y, ((vector signed short) { 0 }))) -static inline void cvtyuvtoRGB(SwsContext *c, vector signed short Y, +static inline void cvtyuvtoRGB(SwsInternal *c, vector signed short Y, vector signed short U, vector signed short V, vector signed short *R, vector signed short *G, vector signed short *B) @@ -295,7 +295,7 @@ static inline vector unsigned char vec_xl(signed long long offset, const ubyte * #endif /* !HAVE_VSX */ #define DEFCSP420_CVT(name, out_pixels) \ -static int altivec_ ## name(SwsContext *c, const unsigned char *const *in, \ +static int altivec_ ## name(SwsInternal *c, const unsigned char *const *in, \ const int *instrides, int srcSliceY, int srcSliceH, \ unsigned char *const *oplanes, const int *outstrides) \ { \ @@ -471,7 +471,7 @@ static const vector unsigned char /* * this is so I can play live CCIR raw video */ -static int altivec_uyvy_rgb32(SwsContext *c, const unsigned char *const *in, +static int altivec_uyvy_rgb32(SwsInternal *c, const unsigned char *const *in, const int *instrides, int srcSliceY, int srcSliceH, unsigned char *const *oplanes, const int *outstrides) { @@ -532,7 +532,7 @@ static int altivec_uyvy_rgb32(SwsContext *c, const unsigned char *const *in, * * So we just fall back to the C codes for this. */ -av_cold SwsFunc ff_yuv2rgb_init_ppc(SwsContext *c) +av_cold SwsFunc ff_yuv2rgb_init_ppc(SwsInternal *c) { #if HAVE_ALTIVEC if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) @@ -595,7 +595,7 @@ av_cold SwsFunc ff_yuv2rgb_init_ppc(SwsContext *c) return NULL; } -av_cold void ff_yuv2rgb_init_tables_ppc(SwsContext *c, +av_cold void ff_yuv2rgb_init_tables_ppc(SwsInternal *c, const int inv_table[4], int brightness, int contrast, @@ -630,7 +630,7 @@ av_cold void ff_yuv2rgb_init_tables_ppc(SwsContext *c, #if HAVE_ALTIVEC -static av_always_inline void yuv2packedX_altivec(SwsContext *c, +static av_always_inline void yuv2packedX_altivec(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, @@ -839,7 +839,7 @@ static av_always_inline void yuv2packedX_altivec(SwsContext *c, } #define YUV2PACKEDX_WRAPPER(suffix, pixfmt) \ -void ff_yuv2 ## suffix ## _X_altivec(SwsContext *c, \ +void ff_yuv2 ## suffix ## _X_altivec(SwsInternal *c, \ const int16_t *lumFilter, \ const int16_t **lumSrc, \ int lumFilterSize, \ diff --git a/libswscale/ppc/yuv2rgb_altivec.h b/libswscale/ppc/yuv2rgb_altivec.h index aa52a4743e..b57194a813 100644 --- a/libswscale/ppc/yuv2rgb_altivec.h +++ b/libswscale/ppc/yuv2rgb_altivec.h @@ -29,7 +29,7 @@ #include "libswscale/swscale_internal.h" #define YUV2PACKEDX_HEADER(suffix) \ - void ff_yuv2 ## suffix ## _X_altivec(SwsContext *c, \ + void ff_yuv2 ## suffix ## _X_altivec(SwsInternal *c, \ const int16_t *lumFilter, \ const int16_t **lumSrc, \ int lumFilterSize, \ diff --git a/libswscale/ppc/yuv2yuv_altivec.c b/libswscale/ppc/yuv2yuv_altivec.c index d63feb6012..0ae5223760 100644 --- a/libswscale/ppc/yuv2yuv_altivec.c +++ b/libswscale/ppc/yuv2yuv_altivec.c @@ -31,7 +31,7 @@ #if HAVE_ALTIVEC -static int yv12toyuy2_unscaled_altivec(SwsContext *c, const uint8_t *const src[], +static int yv12toyuy2_unscaled_altivec(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride_a[]) @@ -107,7 +107,7 @@ static int yv12toyuy2_unscaled_altivec(SwsContext *c, const uint8_t *const src[] return srcSliceH; } -static int yv12touyvy_unscaled_altivec(SwsContext *c, const uint8_t *const src[], +static int yv12touyvy_unscaled_altivec(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride_a[]) @@ -184,7 +184,7 @@ static int yv12touyvy_unscaled_altivec(SwsContext *c, const uint8_t *const src[] #endif /* HAVE_ALTIVEC */ -av_cold void ff_get_unscaled_swscale_ppc(SwsContext *c) +av_cold void ff_get_unscaled_swscale_ppc(SwsInternal *c) { #if HAVE_ALTIVEC if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) diff --git a/libswscale/riscv/swscale.c b/libswscale/riscv/swscale.c index c452d93e5d..8ed9ce969e 100644 --- a/libswscale/riscv/swscale.c +++ b/libswscale/riscv/swscale.c @@ -26,7 +26,7 @@ void ff_range_chr_to_jpeg_16_rvv(int16_t *, int16_t *, int); void ff_range_lum_from_jpeg_16_rvv(int16_t *, int); void ff_range_chr_from_jpeg_16_rvv(int16_t *, int16_t *, int); -av_cold static void ff_sws_init_range_convert_riscv(SwsContext *c, int flags) +av_cold static void ff_sws_init_range_convert_riscv(SwsInternal *c, int flags) { #if HAVE_RVV static const struct { @@ -65,7 +65,7 @@ RVV_INPUT(bgra32); RVV_INPUT(rgb24); RVV_INPUT(rgba32); -av_cold void ff_sws_init_swscale_riscv(SwsContext *c) +av_cold void ff_sws_init_swscale_riscv(SwsInternal *c) { int flags = av_get_cpu_flags(); diff --git a/libswscale/slice.c b/libswscale/slice.c index 119bfbdb8d..f13a839f98 100644 --- a/libswscale/slice.c +++ b/libswscale/slice.c @@ -218,7 +218,7 @@ static void fill_ones(SwsSlice *s, int n, int bpc) The n lines are needed only when there is not enough src lines to output a single dst line, then we should buffer these lines to process them on the next call to scale. */ -static void get_min_buffer_size(SwsContext *c, int *out_lum_size, int *out_chr_size) +static void get_min_buffer_size(SwsInternal *c, int *out_lum_size, int *out_chr_size) { int lumY; int dstH = c->dstH; @@ -247,7 +247,7 @@ static void get_min_buffer_size(SwsContext *c, int *out_lum_size, int *out_chr_s -int ff_init_filters(SwsContext * c) +int ff_init_filters(SwsInternal * c) { int i; int index; @@ -387,7 +387,7 @@ cleanup: return res; } -int ff_free_filters(SwsContext *c) +int ff_free_filters(SwsInternal *c) { int i; if (c->desc) { diff --git a/libswscale/swscale.c b/libswscale/swscale.c index 0f5e520515..c368c68fea 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -62,7 +62,7 @@ static av_always_inline void fillPlane(uint8_t *plane, int stride, int width, } } -static void hScale16To19_c(SwsContext *c, int16_t *_dst, int dstW, +static void hScale16To19_c(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { @@ -92,7 +92,7 @@ static void hScale16To19_c(SwsContext *c, int16_t *_dst, int dstW, } } -static void hScale16To15_c(SwsContext *c, int16_t *dst, int dstW, +static void hScale16To15_c(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { @@ -121,7 +121,7 @@ static void hScale16To15_c(SwsContext *c, int16_t *dst, int dstW, } // bilinear / bicubic scaling -static void hScale8To15_c(SwsContext *c, int16_t *dst, int dstW, +static void hScale8To15_c(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize) { @@ -137,7 +137,7 @@ static void hScale8To15_c(SwsContext *c, int16_t *dst, int dstW, } } -static void hScale8To19_c(SwsContext *c, int16_t *_dst, int dstW, +static void hScale8To19_c(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize) { @@ -233,7 +233,7 @@ static void lumRangeFromJpeg16_c(int16_t *_dst, int width) if (DEBUG_SWSCALE_BUFFERS) \ av_log(c, AV_LOG_DEBUG, __VA_ARGS__) -int ff_swscale(SwsContext *c, const uint8_t *const src[], const int srcStride[], +int ff_swscale(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[], int dstSliceY, int dstSliceH) { @@ -318,7 +318,7 @@ int ff_swscale(SwsContext *c, const uint8_t *const src[], const int srcStride[], if (dstStride[0]&15 || dstStride[1]&15 || dstStride[2]&15 || dstStride[3]&15) { - SwsContext *const ctx = c->parent ? c->parent : c; + SwsInternal *const ctx = c->parent ? sws_internal(c->parent) : c; if (flags & SWS_PRINT_INFO && !atomic_exchange_explicit(&ctx->stride_unaligned_warned, 1, memory_order_relaxed)) { av_log(c, AV_LOG_WARNING, @@ -333,7 +333,7 @@ int ff_swscale(SwsContext *c, const uint8_t *const src[], const int srcStride[], || dstStride[0]&15 || dstStride[1]&15 || dstStride[2]&15 || dstStride[3]&15 || srcStride2[0]&15 || srcStride2[1]&15 || srcStride2[2]&15 || srcStride2[3]&15 ) { - SwsContext *const ctx = c->parent ? c->parent : c; + SwsInternal *const ctx = c->parent ? sws_internal(c->parent) : c; int cpu_flags = av_get_cpu_flags(); if (flags & SWS_PRINT_INFO && HAVE_MMXEXT && (cpu_flags & AV_CPU_FLAG_SSE2) && !atomic_exchange_explicit(&ctx->stride_unaligned_warned,1, memory_order_relaxed)) { @@ -539,7 +539,7 @@ int ff_swscale(SwsContext *c, const uint8_t *const src[], const int srcStride[], return dstY - lastDstY; } -av_cold void ff_sws_init_range_convert(SwsContext *c) +av_cold void ff_sws_init_range_convert(SwsInternal *c) { c->lumConvertRange = NULL; c->chrConvertRange = NULL; @@ -564,7 +564,7 @@ av_cold void ff_sws_init_range_convert(SwsContext *c) } } -static av_cold void sws_init_swscale(SwsContext *c) +static av_cold void sws_init_swscale(SwsInternal *c) { enum AVPixelFormat srcFormat = c->srcFormat; @@ -597,7 +597,7 @@ static av_cold void sws_init_swscale(SwsContext *c) c->needs_hcscale = 1; } -void ff_sws_init_scale(SwsContext *c) +void ff_sws_init_scale(SwsInternal *c) { sws_init_swscale(c); @@ -645,7 +645,7 @@ static int check_image_pointers(const uint8_t * const data[4], enum AVPixelForma return 1; } -void ff_xyz12Torgb48(const SwsContext *c, uint8_t *dst, int dst_stride, +void ff_xyz12Torgb48(const SwsInternal *c, uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); @@ -704,7 +704,7 @@ void ff_xyz12Torgb48(const SwsContext *c, uint8_t *dst, int dst_stride, } } -void ff_rgb48Toxyz12(const SwsContext *c, uint8_t *dst, int dst_stride, +void ff_rgb48Toxyz12(const SwsInternal *c, uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat); @@ -763,7 +763,7 @@ void ff_rgb48Toxyz12(const SwsContext *c, uint8_t *dst, int dst_stride, } } -void ff_update_palette(SwsContext *c, const uint32_t *pal) +void ff_update_palette(SwsInternal *c, const uint32_t *pal) { for (int i = 0; i < 256; i++) { int r, g, b, y, u, v, a = 0xff; @@ -838,13 +838,13 @@ void ff_update_palette(SwsContext *c, const uint32_t *pal) } } -static int scale_internal(SwsContext *c, +static int scale_internal(SwsContext *sws, const uint8_t * const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstSlice[], const int dstStride[], int dstSliceY, int dstSliceH); -static int scale_gamma(SwsContext *c, +static int scale_gamma(SwsInternal *c, const uint8_t * const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t * const dstSlice[], const int dstStride[], @@ -870,39 +870,40 @@ static int scale_gamma(SwsContext *c, return ret; if (c->cascaded_context[2]) { + const int dstY1 = sws_internal(c->cascaded_context[1])->dstY; ret = scale_internal(c->cascaded_context[2], (const uint8_t * const *)c->cascaded_tmp[1], - c->cascaded_tmpStride[1], c->cascaded_context[1]->dstY - ret, - c->cascaded_context[1]->dstY, + c->cascaded_tmpStride[1], dstY1 - ret, dstY1, dstSlice, dstStride, dstSliceY, dstSliceH); } return ret; } -static int scale_cascaded(SwsContext *c, +static int scale_cascaded(SwsInternal *c, const uint8_t * const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t * const dstSlice[], const int dstStride[], int dstSliceY, int dstSliceH) { + const int dstH0 = sws_internal(c->cascaded_context[0])->dstH; int ret = scale_internal(c->cascaded_context[0], srcSlice, srcStride, srcSliceY, srcSliceH, c->cascaded_tmp[0], c->cascaded_tmpStride[0], - 0, c->cascaded_context[0]->dstH); + 0, dstH0); if (ret < 0) return ret; ret = scale_internal(c->cascaded_context[1], (const uint8_t * const * )c->cascaded_tmp[0], c->cascaded_tmpStride[0], - 0, c->cascaded_context[0]->dstH, - dstSlice, dstStride, dstSliceY, dstSliceH); + 0, dstH0, dstSlice, dstStride, dstSliceY, dstSliceH); return ret; } -static int scale_internal(SwsContext *c, +static int scale_internal(SwsContext *sws, const uint8_t * const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstSlice[], const int dstStride[], int dstSliceY, int dstSliceH) { + SwsInternal *c = sws_internal(sws); const int scale_dst = dstSliceY > 0 || dstSliceH < c->dstH; const int frame_start = scale_dst || !c->sliceDir; int i, ret; @@ -952,9 +953,12 @@ static int scale_internal(SwsContext *c, return scale_gamma(c, srcSlice, srcStride, srcSliceY, srcSliceH, dstSlice, dstStride, dstSliceY, dstSliceH); - if (c->cascaded_context[0] && srcSliceY == 0 && srcSliceH == c->cascaded_context[0]->srcH) + if (c->cascaded_context[0] && srcSliceY == 0 && + srcSliceH == sws_internal(c->cascaded_context[0])->srcH) + { return scale_cascaded(c, srcSlice, srcStride, srcSliceY, srcSliceH, dstSlice, dstStride, dstSliceY, dstSliceH); + } if (!srcSliceY && (c->flags & SWS_BITEXACT) && c->dither == SWS_DITHER_ED && c->dither_error[0]) for (i = 0; i < 4; i++) @@ -1091,15 +1095,17 @@ static int scale_internal(SwsContext *c, return ret; } -void sws_frame_end(struct SwsContext *c) +void sws_frame_end(SwsContext *sws) { + SwsInternal *c = sws_internal(sws); av_frame_unref(c->frame_src); av_frame_unref(c->frame_dst); c->src_ranges.nb_ranges = 0; } -int sws_frame_start(struct SwsContext *c, AVFrame *dst, const AVFrame *src) +int sws_frame_start(SwsContext *sws, AVFrame *dst, const AVFrame *src) { + SwsInternal *c = sws_internal(sws); int ret, allocated = 0; ret = av_frame_ref(c->frame_src, src); @@ -1128,9 +1134,10 @@ int sws_frame_start(struct SwsContext *c, AVFrame *dst, const AVFrame *src) return 0; } -int sws_send_slice(struct SwsContext *c, unsigned int slice_start, +int sws_send_slice(SwsContext *sws, unsigned int slice_start, unsigned int slice_height) { + SwsInternal *c = sws_internal(sws); int ret; ret = ff_range_add(&c->src_ranges, slice_start, slice_height); @@ -1140,18 +1147,20 @@ int sws_send_slice(struct SwsContext *c, unsigned int slice_start, return 0; } -unsigned int sws_receive_slice_alignment(const struct SwsContext *c) +unsigned int sws_receive_slice_alignment(const SwsContext *sws) { + SwsInternal *c = sws_internal(sws); if (c->slice_ctx) - return c->slice_ctx[0]->dst_slice_align; + return sws_internal(c->slice_ctx[0])->dst_slice_align; return c->dst_slice_align; } -int sws_receive_slice(struct SwsContext *c, unsigned int slice_start, +int sws_receive_slice(SwsContext *sws, unsigned int slice_start, unsigned int slice_height) { - unsigned int align = sws_receive_slice_alignment(c); + SwsInternal *c = sws_internal(sws); + unsigned int align = sws_receive_slice_alignment(sws); uint8_t *dst[4]; /* wait until complete input has been received */ @@ -1169,9 +1178,12 @@ int sws_receive_slice(struct SwsContext *c, unsigned int slice_start, } if (c->slicethread) { - int nb_jobs = c->slice_ctx[0]->dither == SWS_DITHER_ED ? 1 : c->nb_slice_ctx; + int nb_jobs = c->nb_slice_ctx; int ret = 0; + if (sws_internal(c->slice_ctx[0])->dither == SWS_DITHER_ED) + nb_jobs = 1; + c->dst_slice_start = slice_start; c->dst_slice_height = slice_height; @@ -1194,24 +1206,24 @@ int sws_receive_slice(struct SwsContext *c, unsigned int slice_start, dst[i] = FF_PTR_ADD(c->frame_dst->data[i], offset); } - return scale_internal(c, (const uint8_t * const *)c->frame_src->data, + return scale_internal(sws, (const uint8_t * const *)c->frame_src->data, c->frame_src->linesize, 0, c->srcH, dst, c->frame_dst->linesize, slice_start, slice_height); } -int sws_scale_frame(struct SwsContext *c, AVFrame *dst, const AVFrame *src) +int sws_scale_frame(SwsContext *sws, AVFrame *dst, const AVFrame *src) { int ret; - ret = sws_frame_start(c, dst, src); + ret = sws_frame_start(sws, dst, src); if (ret < 0) return ret; - ret = sws_send_slice(c, 0, src->height); + ret = sws_send_slice(sws, 0, src->height); if (ret >= 0) - ret = sws_receive_slice(c, 0, dst->height); + ret = sws_receive_slice(sws, 0, dst->height); - sws_frame_end(c); + sws_frame_end(sws); return ret; } @@ -1220,24 +1232,28 @@ int sws_scale_frame(struct SwsContext *c, AVFrame *dst, const AVFrame *src) * swscale wrapper, so we don't need to export the SwsContext. * Assumes planar YUV to be in YUV order instead of YVU. */ -int attribute_align_arg sws_scale(struct SwsContext *c, +int attribute_align_arg sws_scale(SwsContext *sws, const uint8_t * const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { - if (c->nb_slice_ctx) - c = c->slice_ctx[0]; + SwsInternal *c = sws_internal(sws); + if (c->nb_slice_ctx) { + sws = c->slice_ctx[0]; + c = sws_internal(sws); + } - return scale_internal(c, srcSlice, srcStride, srcSliceY, srcSliceH, + return scale_internal(sws, srcSlice, srcStride, srcSliceY, srcSliceH, dst, dstStride, 0, c->dstH); } void ff_sws_slice_worker(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads) { - SwsContext *parent = priv; - SwsContext *c = parent->slice_ctx[threadnr]; + SwsInternal *parent = priv; + SwsContext *sws = parent->slice_ctx[threadnr]; + SwsInternal *c = sws_internal(sws); const int slice_height = FFALIGN(FFMAX((parent->dst_slice_height + nb_jobs - 1) / nb_jobs, 1), c->dst_slice_align); @@ -1256,7 +1272,7 @@ void ff_sws_slice_worker(void *priv, int jobnr, int threadnr, dst[i] = parent->frame_dst->data[i] + offset; } - err = scale_internal(c, (const uint8_t * const *)parent->frame_src->data, + err = scale_internal(sws, (const uint8_t * const *)parent->frame_src->data, parent->frame_src->linesize, 0, c->srcH, dst, parent->frame_dst->linesize, parent->dst_slice_start + slice_start, slice_end - slice_start); diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index ce71f7c096..1817815b01 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -24,6 +24,7 @@ #include #include "config.h" +#include "swscale.h" #include "libavutil/avassert.h" #include "libavutil/common.h" @@ -64,7 +65,12 @@ #define RETCODE_USE_CASCADE -12345 -typedef struct SwsContext SwsContext; +typedef struct SwsInternal SwsInternal; + +static inline SwsInternal *sws_internal(const SwsContext *sws) +{ + return (SwsInternal *) sws; +} typedef enum SwsDither { SWS_DITHER_NONE = 0, @@ -96,7 +102,7 @@ typedef struct RangeList { int ff_range_add(RangeList *r, unsigned int start, unsigned int len); -typedef int (*SwsFunc)(SwsContext *c, const uint8_t *const src[], +typedef int (*SwsFunc)(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]); @@ -185,7 +191,7 @@ typedef void (*yuv2interleavedX_fn)(enum AVPixelFormat dstFormat, * but can be used to generate comfort noise using dithering * for some output formats. */ -typedef void (*yuv2packed1_fn)(struct SwsContext *c, const int16_t *lumSrc, +typedef void (*yuv2packed1_fn)(SwsInternal *c, const int16_t *lumSrc, const int16_t *chrUSrc[2], const int16_t *chrVSrc[2], const int16_t *alpSrc, uint8_t *dest, @@ -218,7 +224,7 @@ typedef void (*yuv2packed1_fn)(struct SwsContext *c, const int16_t *lumSrc, * but can be used to generate comfort noise using dithering * for some output formats. */ -typedef void (*yuv2packed2_fn)(struct SwsContext *c, const int16_t *lumSrc[2], +typedef void (*yuv2packed2_fn)(SwsInternal *c, const int16_t *lumSrc[2], const int16_t *chrUSrc[2], const int16_t *chrVSrc[2], const int16_t *alpSrc[2], @@ -250,7 +256,7 @@ typedef void (*yuv2packed2_fn)(struct SwsContext *c, const int16_t *lumSrc[2], * but can be used to generate comfort noise using dithering * or some output formats. */ -typedef void (*yuv2packedX_fn)(struct SwsContext *c, const int16_t *lumFilter, +typedef void (*yuv2packedX_fn)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, @@ -284,7 +290,7 @@ typedef void (*yuv2packedX_fn)(struct SwsContext *c, const int16_t *lumFilter, * but can be used to generate comfort noise using dithering * or some output formats. */ -typedef void (*yuv2anyX_fn)(struct SwsContext *c, const int16_t *lumFilter, +typedef void (*yuv2anyX_fn)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, @@ -321,16 +327,16 @@ struct SwsSlice; struct SwsFilterDescriptor; /* This struct should be aligned on at least a 32-byte boundary. */ -struct SwsContext { +struct SwsInternal { /** * info on struct for av_log */ const AVClass *av_class; - struct SwsContext *parent; + SwsContext *parent; AVSliceThread *slicethread; - struct SwsContext **slice_ctx; + SwsContext **slice_ctx; int *slice_err; int nb_slice_ctx; @@ -375,7 +381,7 @@ struct SwsContext { * sequential steps, this is for example used to limit the maximum * downscaling factor that needs to be supported in one scaler. */ - struct SwsContext *cascaded_context[3]; + SwsContext *cascaded_context[3]; int cascaded_tmpStride[2][4]; uint8_t *cascaded_tmp[2][4]; int cascaded_mainindex; @@ -602,7 +608,7 @@ struct SwsContext { /** * Scale one horizontal line of input data using a bilinear filter - * to produce one line of output data. Compared to SwsContext->hScale(), + * to produce one line of output data. Compared to SwsInternal->hScale(), * please take note of the following caveats when using these: * - Scaling is done using only 7 bits instead of 14-bit coefficients. * - You can use no more than 5 input pixels to produce 4 output @@ -616,13 +622,13 @@ struct SwsContext { * two input pixels per output pixel in bilinear scaling, this is * impossible and thus downscaling by any size will create artifacts. * To enable this type of scaling, set SWS_FLAG_FAST_BILINEAR - * in SwsContext->flags. + * in SwsInternal->flags. */ /** @{ */ - void (*hyscale_fast)(struct SwsContext *c, + void (*hyscale_fast)(SwsInternal *c, int16_t *dst, int dstWidth, const uint8_t *src, int srcW, int xInc); - void (*hcscale_fast)(struct SwsContext *c, + void (*hcscale_fast)(SwsInternal *c, int16_t *dst1, int16_t *dst2, int dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc); @@ -634,15 +640,15 @@ struct SwsContext { * * @param dst pointer to destination buffer for horizontally scaled * data. If the number of bits per component of one - * destination pixel (SwsContext->dstBpc) is <= 10, data + * destination pixel (SwsInternal->dstBpc) is <= 10, data * will be 15 bpc in 16 bits (int16_t) width. Else (i.e. - * SwsContext->dstBpc == 16), data will be 19bpc in + * SwsInternal->dstBpc == 16), data will be 19bpc in * 32 bits (int32_t) width. * @param dstW width of destination image * @param src pointer to source data to be scaled. If the number of - * bits per component of a source pixel (SwsContext->srcBpc) + * bits per component of a source pixel (SwsInternal->srcBpc) * is 8, this is 8bpc in 8 bits (uint8_t) width. Else - * (i.e. SwsContext->dstBpc > 8), this is native depth + * (i.e. SwsInternal->dstBpc > 8), this is native depth * in 16 bits (uint16_t) width. In other words, for 9-bit * YUV input, this is 9bpc, for 10-bit YUV input, this is * 10bpc, and for 16-bit RGB or YUV, this is 16bpc. @@ -659,10 +665,10 @@ struct SwsContext { * to simplify creating SIMD code. */ /** @{ */ - void (*hyScale)(struct SwsContext *c, int16_t *dst, int dstW, + void (*hyScale)(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize); - void (*hcScale)(struct SwsContext *c, int16_t *dst, int dstW, + void (*hcScale)(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize); /** @} */ @@ -698,25 +704,25 @@ struct SwsContext { }; //FIXME check init (where 0) -SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c); -int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], +SwsFunc ff_yuv2rgb_get_func_ptr(SwsInternal *c); +int ff_yuv2rgb_c_init_tables(SwsInternal *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation); -void ff_yuv2rgb_init_tables_ppc(SwsContext *c, const int inv_table[4], +void ff_yuv2rgb_init_tables_ppc(SwsInternal *c, const int inv_table[4], int brightness, int contrast, int saturation); -void ff_updateMMXDitherTables(SwsContext *c, int dstY); +void ff_updateMMXDitherTables(SwsInternal *c, int dstY); -void ff_update_palette(SwsContext *c, const uint32_t *pal); +void ff_update_palette(SwsInternal *c, const uint32_t *pal); -av_cold void ff_sws_init_range_convert(SwsContext *c); -av_cold void ff_sws_init_range_convert_aarch64(SwsContext *c); -av_cold void ff_sws_init_range_convert_loongarch(SwsContext *c); -av_cold void ff_sws_init_range_convert_x86(SwsContext *c); +av_cold void ff_sws_init_range_convert(SwsInternal *c); +av_cold void ff_sws_init_range_convert_aarch64(SwsInternal *c); +av_cold void ff_sws_init_range_convert_loongarch(SwsInternal *c); +av_cold void ff_sws_init_range_convert_x86(SwsInternal *c); -SwsFunc ff_yuv2rgb_init_x86(SwsContext *c); -SwsFunc ff_yuv2rgb_init_ppc(SwsContext *c); -SwsFunc ff_yuv2rgb_init_loongarch(SwsContext *c); +SwsFunc ff_yuv2rgb_init_x86(SwsInternal *c); +SwsFunc ff_yuv2rgb_init_ppc(SwsInternal *c); +SwsFunc ff_yuv2rgb_init_loongarch(SwsInternal *c); static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt) { @@ -981,21 +987,21 @@ extern const AVClass ff_sws_context_class; * Set c->convert_unscaled to an unscaled converter if one exists for the * specific source and destination formats, bit depths, flags, etc. */ -void ff_get_unscaled_swscale(SwsContext *c); -void ff_get_unscaled_swscale_ppc(SwsContext *c); -void ff_get_unscaled_swscale_arm(SwsContext *c); -void ff_get_unscaled_swscale_aarch64(SwsContext *c); +void ff_get_unscaled_swscale(SwsInternal *c); +void ff_get_unscaled_swscale_ppc(SwsInternal *c); +void ff_get_unscaled_swscale_arm(SwsInternal *c); +void ff_get_unscaled_swscale_aarch64(SwsInternal *c); -void ff_sws_init_scale(SwsContext *c); +void ff_sws_init_scale(SwsInternal *c); -void ff_sws_init_input_funcs(SwsContext *c, +void ff_sws_init_input_funcs(SwsInternal *c, planar1_YV12_fn *lumToYV12, planar1_YV12_fn *alpToYV12, planar2_YV12_fn *chrToYV12, planarX_YV12_fn *readLumPlanar, planarX_YV12_fn *readAlpPlanar, planarX2_YV12_fn *readChrPlanar); -void ff_sws_init_output_funcs(SwsContext *c, +void ff_sws_init_output_funcs(SwsInternal *c, yuv2planar1_fn *yuv2plane1, yuv2planarX_fn *yuv2planeX, yuv2interleavedX_fn *yuv2nv12cX, @@ -1003,30 +1009,30 @@ void ff_sws_init_output_funcs(SwsContext *c, yuv2packed2_fn *yuv2packed2, yuv2packedX_fn *yuv2packedX, yuv2anyX_fn *yuv2anyX); -void ff_sws_init_swscale_ppc(SwsContext *c); -void ff_sws_init_swscale_vsx(SwsContext *c); -void ff_sws_init_swscale_x86(SwsContext *c); -void ff_sws_init_swscale_aarch64(SwsContext *c); -void ff_sws_init_swscale_arm(SwsContext *c); -void ff_sws_init_swscale_loongarch(SwsContext *c); -void ff_sws_init_swscale_riscv(SwsContext *c); - -void ff_hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth, +void ff_sws_init_swscale_ppc(SwsInternal *c); +void ff_sws_init_swscale_vsx(SwsInternal *c); +void ff_sws_init_swscale_x86(SwsInternal *c); +void ff_sws_init_swscale_aarch64(SwsInternal *c); +void ff_sws_init_swscale_arm(SwsInternal *c); +void ff_sws_init_swscale_loongarch(SwsInternal *c); +void ff_sws_init_swscale_riscv(SwsInternal *c); + +void ff_hyscale_fast_c(SwsInternal *c, int16_t *dst, int dstWidth, const uint8_t *src, int srcW, int xInc); -void ff_hcscale_fast_c(SwsContext *c, int16_t *dst1, int16_t *dst2, +void ff_hcscale_fast_c(SwsInternal *c, int16_t *dst1, int16_t *dst2, int dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc); int ff_init_hscaler_mmxext(int dstW, int xInc, uint8_t *filterCode, int16_t *filter, int32_t *filterPos, int numSplits); -void ff_hyscale_fast_mmxext(SwsContext *c, int16_t *dst, +void ff_hyscale_fast_mmxext(SwsInternal *c, int16_t *dst, int dstWidth, const uint8_t *src, int srcW, int xInc); -void ff_hcscale_fast_mmxext(SwsContext *c, int16_t *dst1, int16_t *dst2, +void ff_hcscale_fast_mmxext(SwsInternal *c, int16_t *dst1, int16_t *dst2, int dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc); -int ff_sws_alphablendaway(SwsContext *c, const uint8_t *const src[], +int ff_sws_alphablendaway(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]); @@ -1034,10 +1040,10 @@ void ff_copyPlane(const uint8_t *src, int srcStride, int srcSliceY, int srcSliceH, int width, uint8_t *dst, int dstStride); -void ff_xyz12Torgb48(const SwsContext *c, uint8_t *dst, int dst_stride, +void ff_xyz12Torgb48(const SwsInternal *c, uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h); -void ff_rgb48Toxyz12(const SwsContext *c, uint8_t *dst, int dst_stride, +void ff_rgb48Toxyz12(const SwsInternal *c, uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h); static inline void fillPlane16(uint8_t *plane, int stride, int width, int height, int y, @@ -1116,7 +1122,7 @@ typedef struct SwsFilterDescriptor void *instance; ///< Filter instance data /// Function for processing input slice sliceH lines starting from line sliceY - int (*process)(SwsContext *c, struct SwsFilterDescriptor *desc, int sliceY, int sliceH); + int (*process)(SwsInternal *c, struct SwsFilterDescriptor *desc, int sliceY, int sliceH); } SwsFilterDescriptor; // warp input lines in the form (src + width*i + j) to slice format (line[i][j]) @@ -1125,10 +1131,10 @@ int ff_init_slice_from_src(SwsSlice * s, uint8_t *const src[4], const int stride int srcW, int lumY, int lumH, int chrY, int chrH, int relative); // Initialize scaler filter descriptor chain -int ff_init_filters(SwsContext *c); +int ff_init_filters(SwsInternal *c); // Free all filter data -int ff_free_filters(SwsContext *c); +int ff_free_filters(SwsInternal *c); /* function for applying ring buffer logic into slice s @@ -1156,17 +1162,17 @@ int ff_init_desc_chscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst int ff_init_desc_no_chr(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst); /// initializes vertical scaling descriptors -int ff_init_vscale(SwsContext *c, SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst); +int ff_init_vscale(SwsInternal *c, SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst); /// setup vertical scaler functions -void ff_init_vscale_pfn(SwsContext *c, yuv2planar1_fn yuv2plane1, yuv2planarX_fn yuv2planeX, +void ff_init_vscale_pfn(SwsInternal *c, yuv2planar1_fn yuv2plane1, yuv2planarX_fn yuv2planeX, yuv2interleavedX_fn yuv2nv12cX, yuv2packed1_fn yuv2packed1, yuv2packed2_fn yuv2packed2, yuv2packedX_fn yuv2packedX, yuv2anyX_fn yuv2anyX, int use_mmx); void ff_sws_slice_worker(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads); -int ff_swscale(SwsContext *c, const uint8_t *const src[], const int srcStride[], +int ff_swscale(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[], int dstSliceY, int dstSliceH); @@ -1175,5 +1181,5 @@ int ff_swscale(SwsContext *c, const uint8_t *const src[], const int srcStride[], #define MAX_LINES_AHEAD 4 //shuffle filter and filterPos for hyScale and hcScale filters in avx2 -int ff_shuffle_filter_coefficients(SwsContext *c, int* filterPos, int filterSize, int16_t *filter, int dstW); +int ff_shuffle_filter_coefficients(SwsInternal *c, int* filterPos, int filterSize, int16_t *filter, int dstW); #endif /* SWSCALE_SWSCALE_INTERNAL_H */ diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c index edb51a8250..1a293483c4 100644 --- a/libswscale/swscale_unscaled.c +++ b/libswscale/swscale_unscaled.c @@ -139,7 +139,7 @@ void ff_copyPlane(const uint8_t *src, int srcStride, } } -static int planarToNv12Wrapper(SwsContext *c, const uint8_t *const src[], +static int planarToNv12Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[]) @@ -159,7 +159,7 @@ static int planarToNv12Wrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int nv12ToPlanarWrapper(SwsContext *c, const uint8_t *const src[], +static int nv12ToPlanarWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[]) @@ -180,7 +180,7 @@ static int nv12ToPlanarWrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int planarToNv24Wrapper(SwsContext *c, const uint8_t *const src[], +static int planarToNv24Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[]) @@ -200,7 +200,7 @@ static int planarToNv24Wrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int nv24ToPlanarWrapper(SwsContext *c, const uint8_t *const src[], +static int nv24ToPlanarWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[]) @@ -243,7 +243,7 @@ static void nv24_to_yuv420p_chroma(uint8_t *dst1, int dstStride1, } } -static int nv24ToYuv420Wrapper(SwsContext *c, const uint8_t *const src[], +static int nv24ToYuv420Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[]) { @@ -263,7 +263,7 @@ static int nv24ToYuv420Wrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int planarToP01xWrapper(SwsContext *c, const uint8_t *const src8[], +static int planarToP01xWrapper(SwsInternal *c, const uint8_t *const src8[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam8[], const int dstStride[]) @@ -323,7 +323,7 @@ static int planarToP01xWrapper(SwsContext *c, const uint8_t *const src8[], #define output_pixel(p, v) (*p) = (v) #endif -static int planar8ToP01xleWrapper(SwsContext *c, const uint8_t *const src[], +static int planar8ToP01xleWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam8[], const int dstStride[]) @@ -366,7 +366,7 @@ static int planar8ToP01xleWrapper(SwsContext *c, const uint8_t *const src[], #undef output_pixel -static int planarToYuy2Wrapper(SwsContext *c, const uint8_t *const src[], +static int planarToYuy2Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[]) { @@ -378,7 +378,7 @@ static int planarToYuy2Wrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int planarToUyvyWrapper(SwsContext *c, const uint8_t *const src[], +static int planarToUyvyWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[]) { @@ -390,7 +390,7 @@ static int planarToUyvyWrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int yuv422pToYuy2Wrapper(SwsContext *c, const uint8_t *const src[], +static int yuv422pToYuy2Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[]) { @@ -402,7 +402,7 @@ static int yuv422pToYuy2Wrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int yuv422pToUyvyWrapper(SwsContext *c, const uint8_t *const src[], +static int yuv422pToUyvyWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[]) { @@ -414,7 +414,7 @@ static int yuv422pToUyvyWrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int yuyvToYuv420Wrapper(SwsContext *c, const uint8_t *const src[], +static int yuyvToYuv420Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[]) { @@ -431,7 +431,7 @@ static int yuyvToYuv420Wrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int yuyvToYuv422Wrapper(SwsContext *c, const uint8_t *const src[], +static int yuyvToYuv422Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[]) { @@ -445,7 +445,7 @@ static int yuyvToYuv422Wrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int uyvyToYuv420Wrapper(SwsContext *c, const uint8_t *const src[], +static int uyvyToYuv420Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[]) { @@ -462,7 +462,7 @@ static int uyvyToYuv420Wrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int uyvyToYuv422Wrapper(SwsContext *c, const uint8_t *const src[], +static int uyvyToYuv422Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[]) { @@ -507,7 +507,7 @@ static void gray8aToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, } } -static int bswap_16bpc(SwsContext *c, const uint8_t *const src[], +static int bswap_16bpc(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -534,7 +534,7 @@ static int bswap_16bpc(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int bswap_32bpc(SwsContext *c, const uint8_t *const src[], +static int bswap_32bpc(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -562,7 +562,7 @@ static int bswap_32bpc(SwsContext *c, const uint8_t *const src[], } -static int palToRgbWrapper(SwsContext *c, const uint8_t *const src[], const int srcStride[], +static int palToRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -742,7 +742,7 @@ static void packed16togbra16(const uint8_t *src, int srcStride, } } -static int Rgb16ToPlanarRgb16Wrapper(SwsContext *c, const uint8_t *const src[], +static int Rgb16ToPlanarRgb16Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -921,7 +921,7 @@ static void gbr16ptopacked16(const uint16_t *src[], const int srcStride[], } } -static int planarRgb16ToRgb16Wrapper(SwsContext *c, const uint8_t *const src[], +static int planarRgb16ToRgb16Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -1057,7 +1057,7 @@ static void gbraptopacked32(const uint8_t *src[], const int srcStride[], } } -static int planarRgbaToRgbWrapper(SwsContext *c, const uint8_t *const src[], +static int planarRgbaToRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -1113,7 +1113,7 @@ static int planarRgbaToRgbWrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int planarRgbToRgbWrapper(SwsContext *c, const uint8_t *const src[], +static int planarRgbToRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -1169,7 +1169,7 @@ static int planarRgbToRgbWrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int planarRgbToplanarRgbWrapper(SwsContext *c, +static int planarRgbToplanarRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) @@ -1215,7 +1215,7 @@ static void packedtogbr24p(const uint8_t *src, int srcStride, } } -static int rgbToPlanarRgbWrapper(SwsContext *c, const uint8_t *const src[], +static int rgbToPlanarRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -1320,7 +1320,7 @@ static int rgbToPlanarRgbWrapper(SwsContext *c, const uint8_t *const src[], #define BAYER_RENAME(x) bayer_rggb16be_to_##x #include "bayer_template.c" -static int bayer_to_rgb24_wrapper(SwsContext *c, const uint8_t *const src[], +static int bayer_to_rgb24_wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -1370,7 +1370,7 @@ static int bayer_to_rgb24_wrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int bayer_to_rgb48_wrapper(SwsContext *c, const uint8_t *const src[], +static int bayer_to_rgb48_wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -1420,7 +1420,7 @@ static int bayer_to_rgb48_wrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int bayer_to_yv12_wrapper(SwsContext *c, const uint8_t *const src[], +static int bayer_to_yv12_wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -1499,7 +1499,7 @@ static int bayer_to_yv12_wrapper(SwsContext *c, const uint8_t *const src[], /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */ typedef void (* rgbConvFn) (const uint8_t *, uint8_t *, int); -static rgbConvFn findRgbConvFn(SwsContext *c) +static rgbConvFn findRgbConvFn(SwsInternal *c) { const enum AVPixelFormat srcFormat = c->srcFormat; const enum AVPixelFormat dstFormat = c->dstFormat; @@ -1622,7 +1622,7 @@ static rgbConvFn findRgbConvFn(SwsContext *c) } /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */ -static int rgbToRgbWrapper(SwsContext *c, const uint8_t *const src[], const int srcStride[], +static int rgbToRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) @@ -1683,7 +1683,7 @@ static int rgbToRgbWrapper(SwsContext *c, const uint8_t *const src[], const int return srcSliceH; } -static int bgr24ToYv12Wrapper(SwsContext *c, const uint8_t *const src[], +static int bgr24ToYv12Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -1700,7 +1700,7 @@ static int bgr24ToYv12Wrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int yvu9ToYv12Wrapper(SwsContext *c, const uint8_t *const src[], +static int yvu9ToYv12Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -1716,7 +1716,7 @@ static int yvu9ToYv12Wrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int uint_y_to_float_y_wrapper(SwsContext *c, const uint8_t *const src[], +static int uint_y_to_float_y_wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -1736,7 +1736,7 @@ static int uint_y_to_float_y_wrapper(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static int float_y_to_uint_y_wrapper(SwsContext *c, +static int float_y_to_uint_y_wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], @@ -1759,7 +1759,7 @@ static int float_y_to_uint_y_wrapper(SwsContext *c, } /* unscaled copy like stuff (assumes nearly identical formats) */ -static int packedCopyWrapper(SwsContext *c, const uint8_t *const src[], +static int packedCopyWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -1846,7 +1846,7 @@ static int packedCopyWrapper(SwsContext *c, const uint8_t *const src[], }\ } -static int planarCopyWrapper(SwsContext *c, const uint8_t *const src[], +static int planarCopyWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { @@ -2019,7 +2019,7 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t *const src[], (src_fmt == pix_fmt ## LE && dst_fmt == pix_fmt ## BE)) -void ff_get_unscaled_swscale(SwsContext *c) +void ff_get_unscaled_swscale(SwsInternal *c) { const enum AVPixelFormat srcFormat = c->srcFormat; const enum AVPixelFormat dstFormat = c->dstFormat; diff --git a/libswscale/tests/floatimg_cmp.c b/libswscale/tests/floatimg_cmp.c index 5c67594fb6..0744e64f8e 100644 --- a/libswscale/tests/floatimg_cmp.c +++ b/libswscale/tests/floatimg_cmp.c @@ -83,7 +83,7 @@ int main(int argc, char **argv) double sum; float minimum, maximum, diff; - struct SwsContext *sws = NULL; + SwsContext *sws = NULL; AVLFG rand; FILE *fp = NULL; diff --git a/libswscale/tests/swscale.c b/libswscale/tests/swscale.c index 8e57c0a7cf..af8069f728 100644 --- a/libswscale/tests/swscale.c +++ b/libswscale/tests/swscale.c @@ -117,7 +117,7 @@ static int doTest(const uint8_t * const ref[4], int refStride[4], int w, int h, int dstStride[4] = {0}; int i; uint64_t ssdY, ssdU = 0, ssdV = 0, ssdA = 0; - struct SwsContext *dstContext = NULL, *outContext = NULL; + SwsContext *dstContext = NULL, *outContext = NULL; uint32_t crc = 0; int res = 0; @@ -125,7 +125,7 @@ static int doTest(const uint8_t * const ref[4], int refStride[4], int w, int h, return 0; if (cur_srcFormat != srcFormat || cur_srcW != srcW || cur_srcH != srcH) { - struct SwsContext *srcContext = NULL; + SwsContext *srcContext = NULL; int p; for (p = 0; p < 4; p++) @@ -427,7 +427,7 @@ int main(int argc, char **argv) const uint8_t * const src[4] = { data, data + W * H, data + W * H * 2, data + W * H * 3 }; int stride[4] = { W, W, W, W }; int x, y; - struct SwsContext *sws; + SwsContext *sws; AVLFG rand; int res = -1; int i; diff --git a/libswscale/utils.c b/libswscale/utils.c index 9b23df4dbb..4b5106cb57 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -287,7 +287,8 @@ static SwsContext *alloc_set_opts(int srcW, int srcH, enum AVPixelFormat srcForm int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, const double *param) { - SwsContext *c = sws_alloc_context(); + SwsContext *sws = sws_alloc_context(); + SwsInternal *c = sws_internal(sws); if (!c) return NULL; @@ -305,10 +306,10 @@ static SwsContext *alloc_set_opts(int srcW, int srcH, enum AVPixelFormat srcForm c->param[1] = param[1]; } - return c; + return sws; } -int ff_shuffle_filter_coefficients(SwsContext *c, int *filterPos, +int ff_shuffle_filter_coefficients(SwsInternal *c, int *filterPos, int filterSize, int16_t *filter, int dstW) { @@ -396,7 +397,7 @@ static double getSplineCoeff(double a, double b, double c, double d, dist - 1.0); } -static av_cold int get_local_pos(SwsContext *s, int chr_subsample, int pos, int dir) +static av_cold int get_local_pos(SwsInternal *s, int chr_subsample, int pos, int dir) { if (pos == -1 || pos <= -513) { pos = (128 << chr_subsample) - 128; @@ -834,7 +835,7 @@ done: return ret; } -static void fill_rgb2yuv_table(SwsContext *c, const int table[4], int dstRange) +static void fill_rgb2yuv_table(SwsInternal *c, const int table[4], int dstRange) { int64_t W, V, Z, Cy, Cu, Cv; int64_t vr = table[0]; @@ -928,7 +929,7 @@ static void fill_rgb2yuv_table(SwsContext *c, const int table[4], int dstRange) AV_WL16(p + 16*4 + 2*i, map[i] >= 0 ? c->input_rgb2yuv_table[map[i]] : 0); } -static void fill_xyztables(struct SwsContext *c) +static void fill_xyztables(SwsInternal *c) { int i; double xyzgamma = XYZ_GAMMA; @@ -1022,7 +1023,7 @@ static int handle_xyz(enum AVPixelFormat *format) } } -static void handle_formats(SwsContext *c) +static void handle_formats(SwsInternal *c) { c->src0Alpha |= handle_0alpha(&c->srcFormat); c->dst0Alpha |= handle_0alpha(&c->dstFormat); @@ -1037,10 +1038,11 @@ static int range_override_needed(enum AVPixelFormat format) return !isYUV(format) && !isGray(format); } -int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4], +int sws_setColorspaceDetails(SwsContext *sws, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation) { + SwsInternal *c = sws_internal(sws); const AVPixFmtDescriptor *desc_dst; const AVPixFmtDescriptor *desc_src; int need_reinit = 0; @@ -1154,7 +1156,7 @@ int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4], if (!c->cascaded_context[0]) return -1; - c->cascaded_context[0]->alphablend = c->alphablend; + sws_internal(c->cascaded_context[0])->alphablend = c->alphablend; ret = sws_init_context(c->cascaded_context[0], NULL , NULL); if (ret < 0) return ret; @@ -1168,8 +1170,8 @@ int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4], c->flags, c->param); if (!c->cascaded_context[1]) return -1; - c->cascaded_context[1]->srcRange = srcRange; - c->cascaded_context[1]->dstRange = dstRange; + sws_internal(c->cascaded_context[1])->srcRange = srcRange; + sws_internal(c->cascaded_context[1])->dstRange = dstRange; ret = sws_init_context(c->cascaded_context[1], NULL , NULL); if (ret < 0) return ret; @@ -1200,11 +1202,12 @@ int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4], return 0; } -int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table, +int sws_getColorspaceDetails(SwsContext *sws, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation) { - if (!c ) + SwsInternal *c = sws_internal(sws); + if (!c) return -1; if (c->nb_slice_ctx) { @@ -1226,9 +1229,9 @@ int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table, SwsContext *sws_alloc_context(void) { - SwsContext *c = av_mallocz(sizeof(SwsContext)); + SwsInternal *c = av_mallocz(sizeof(SwsInternal)); - av_assert0(offsetof(SwsContext, redDither) + DITHER32_INT == offsetof(SwsContext, dither32)); + av_assert0(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInternal, dither32)); if (c) { c->av_class = &ff_sws_context_class; @@ -1237,7 +1240,7 @@ SwsContext *sws_alloc_context(void) atomic_init(&c->data_unaligned_warned, 0); } - return c; + return (SwsContext *) c; } static uint16_t * alloc_gamma_tbl(double e) @@ -1315,15 +1318,13 @@ static enum AVPixelFormat alphaless_fmt(enum AVPixelFormat fmt) } } -static int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter, - SwsFilter *dstFilter); - -static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter, +static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter, SwsFilter *dstFilter) { int i; int usesVFilter, usesHFilter; int unscaled; + SwsInternal *c = sws_internal(sws); SwsFilter dummyFilter = { NULL, NULL, NULL, NULL }; int srcW = c->srcW; int srcH = c->srcH; @@ -1345,7 +1346,7 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter, unscaled = (srcW == dstW && srcH == dstH); if (!c->contrast && !c->saturation && !c->dstFormatBpp) - sws_setColorspaceDetails(c, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], c->srcRange, + sws_setColorspaceDetails(sws, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], c->srcRange, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], c->dstRange, 0, 1 << 16, 1 << 16); @@ -1620,7 +1621,7 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter, if (!unscaled && c->gamma_flag && (srcFormat != tmpFmt || dstFormat != tmpFmt)) { - SwsContext *c2; + SwsInternal *c2; c->cascaded_context[0] = NULL; ret = av_image_alloc(c->cascaded_tmp[0], c->cascaded_tmpStride[0], @@ -1642,7 +1643,7 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter, if (!c->cascaded_context[1]) return AVERROR(ENOMEM); - c2 = c->cascaded_context[1]; + c2 = sws_internal(c->cascaded_context[1]); c2->is_internal_gamma = 1; c2->gamma = alloc_gamma_tbl( c->gamma_value); c2->inv_gamma = alloc_gamma_tbl(1.f/c->gamma_value); @@ -1654,7 +1655,7 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter, // we have to re-initialize it ff_free_filters(c2); if ((ret = ff_init_filters(c2)) < 0) { - sws_freeContext(c2); + sws_freeContext(c->cascaded_context[1]); c->cascaded_context[1] = NULL; return ret; } @@ -1734,7 +1735,7 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter, flags, c->param); if (!c->cascaded_context[0]) return AVERROR(EINVAL); - c->cascaded_context[0]->alphablend = c->alphablend; + sws_internal(c->cascaded_context[0])->alphablend = c->alphablend; ret = sws_init_context(c->cascaded_context[0], NULL , NULL); if (ret < 0) return ret; @@ -1745,8 +1746,8 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter, if (!c->cascaded_context[1]) return AVERROR(EINVAL); - c->cascaded_context[1]->srcRange = c->srcRange; - c->cascaded_context[1]->dstRange = c->dstRange; + sws_internal(c->cascaded_context[1])->srcRange = c->srcRange; + sws_internal(c->cascaded_context[1])->dstRange = c->dstRange; ret = sws_init_context(c->cascaded_context[1], srcFilter , dstFilter); if (ret < 0) return ret; @@ -2027,12 +2028,13 @@ fail: // FIXME replace things by appropriate error codes return ret; } -static int context_init_threaded(SwsContext *c, +static int context_init_threaded(SwsContext *sws, SwsFilter *src_filter, SwsFilter *dst_filter) { + SwsInternal *c = sws_internal(sws); int ret; - ret = avpriv_slicethread_create(&c->slicethread, (void*)c, + ret = avpriv_slicethread_create(&c->slicethread, (void*) sws, ff_sws_slice_worker, NULL, c->nb_threads); if (ret == AVERROR(ENOSYS)) { c->nb_threads = 1; @@ -2048,24 +2050,26 @@ static int context_init_threaded(SwsContext *c, return AVERROR(ENOMEM); for (int i = 0; i < c->nb_threads; i++) { + SwsInternal *c2; c->slice_ctx[i] = sws_alloc_context(); if (!c->slice_ctx[i]) return AVERROR(ENOMEM); + c2 = sws_internal(c->slice_ctx[i]); c->nb_slice_ctx++; - c->slice_ctx[i]->parent = c; + c2->parent = sws; ret = av_opt_copy((void*)c->slice_ctx[i], (void*)c); if (ret < 0) return ret; - c->slice_ctx[i]->nb_threads = 1; + c2->nb_threads = 1; ret = sws_init_single_context(c->slice_ctx[i], src_filter, dst_filter); if (ret < 0) return ret; - if (c->slice_ctx[i]->dither == SWS_DITHER_ED) { + if (c2->dither == SWS_DITHER_ED) { av_log(c, AV_LOG_VERBOSE, "Error-diffusion dither is in use, scaling will be single-threaded."); break; @@ -2075,9 +2079,10 @@ static int context_init_threaded(SwsContext *c, return 0; } -av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter, +av_cold int sws_init_context(SwsContext *sws, SwsFilter *srcFilter, SwsFilter *dstFilter) { + SwsInternal *c = sws_internal(sws); static AVOnce rgb2rgb_once = AV_ONCE_INIT; enum AVPixelFormat src_format, dst_format; int ret; @@ -2099,13 +2104,13 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter, av_log(c, AV_LOG_WARNING, "deprecated pixel format used, make sure you did set range correctly\n"); if (c->nb_threads != 1) { - ret = context_init_threaded(c, srcFilter, dstFilter); + ret = context_init_threaded(sws, srcFilter, dstFilter); if (ret < 0 || c->nb_threads > 1) return ret; // threading disabled in this build, init as single-threaded } - return sws_init_single_context(c, srcFilter, dstFilter); + return sws_init_single_context(sws, srcFilter, dstFilter); } SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, @@ -2113,20 +2118,20 @@ SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param) { - SwsContext *c; + SwsContext *sws; - c = alloc_set_opts(srcW, srcH, srcFormat, - dstW, dstH, dstFormat, - flags, param); - if (!c) + sws = alloc_set_opts(srcW, srcH, srcFormat, + dstW, dstH, dstFormat, + flags, param); + if (!sws) return NULL; - if (sws_init_context(c, srcFilter, dstFilter) < 0) { - sws_freeContext(c); + if (sws_init_context(sws, srcFilter, dstFilter) < 0) { + sws_freeContext(sws); return NULL; } - return c; + return sws; } static int isnan_vec(SwsVector *a) @@ -2439,8 +2444,9 @@ fail: return NULL; } -void sws_freeContext(SwsContext *c) +void sws_freeContext(SwsContext *sws) { + SwsInternal *c = sws_internal(sws); int i; if (!c) return; @@ -2511,17 +2517,19 @@ void sws_freeContext(SwsContext *c) ff_free_filters(c); - av_free(c); + av_free(sws); } -struct SwsContext *sws_getCachedContext(struct SwsContext *context, int srcW, - int srcH, enum AVPixelFormat srcFormat, - int dstW, int dstH, - enum AVPixelFormat dstFormat, int flags, - SwsFilter *srcFilter, - SwsFilter *dstFilter, - const double *param) +SwsContext *sws_getCachedContext(SwsContext *sws, int srcW, + int srcH, enum AVPixelFormat srcFormat, + int dstW, int dstH, + enum AVPixelFormat dstFormat, int flags, + SwsFilter *srcFilter, + SwsFilter *dstFilter, + const double *param) { + SwsInternal *context; + static const double default_param[2] = { SWS_PARAM_DEFAULT, SWS_PARAM_DEFAULT }; int64_t src_h_chr_pos = -513, dst_h_chr_pos = -513, @@ -2530,7 +2538,7 @@ struct SwsContext *sws_getCachedContext(struct SwsContext *context, int srcW, if (!param) param = default_param; - if (context && + if ((context = sws_internal(sws)) && (context->srcW != srcW || context->srcH != srcH || context->srcFormat != srcFormat || @@ -2545,13 +2553,14 @@ struct SwsContext *sws_getCachedContext(struct SwsContext *context, int srcW, av_opt_get_int(context, "src_v_chr_pos", 0, &src_v_chr_pos); av_opt_get_int(context, "dst_h_chr_pos", 0, &dst_h_chr_pos); av_opt_get_int(context, "dst_v_chr_pos", 0, &dst_v_chr_pos); - sws_freeContext(context); - context = NULL; + sws_freeContext(sws); + sws = NULL; } - if (!context) { - if (!(context = sws_alloc_context())) + if (!sws) { + if (!(sws = sws_alloc_context())) return NULL; + context = sws_internal(sws); context->srcW = srcW; context->srcH = srcH; context->srcFormat = srcFormat; @@ -2567,12 +2576,12 @@ struct SwsContext *sws_getCachedContext(struct SwsContext *context, int srcW, av_opt_set_int(context, "dst_h_chr_pos", dst_h_chr_pos, 0); av_opt_set_int(context, "dst_v_chr_pos", dst_v_chr_pos, 0); - if (sws_init_context(context, srcFilter, dstFilter) < 0) { - sws_freeContext(context); + if (sws_init_context(sws, srcFilter, dstFilter) < 0) { + sws_freeContext(sws); return NULL; } } - return context; + return sws; } int ff_range_add(RangeList *rl, unsigned int start, unsigned int len) diff --git a/libswscale/vscale.c b/libswscale/vscale.c index 5b3234198d..9b700ec58e 100644 --- a/libswscale/vscale.c +++ b/libswscale/vscale.c @@ -38,7 +38,7 @@ typedef struct VScalerContext } VScalerContext; -static int lum_planar_vscale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) +static int lum_planar_vscale(SwsInternal *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) { VScalerContext *inst = desc->instance; int dstW = desc->dst->width; @@ -71,7 +71,7 @@ static int lum_planar_vscale(SwsContext *c, SwsFilterDescriptor *desc, int slice return 1; } -static int chr_planar_vscale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) +static int chr_planar_vscale(SwsInternal *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) { const int chrSkipMask = (1 << desc->dst->v_chr_sub_sample) - 1; if (sliceY & chrSkipMask) @@ -106,7 +106,7 @@ static int chr_planar_vscale(SwsContext *c, SwsFilterDescriptor *desc, int slice return 1; } -static int packed_vscale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) +static int packed_vscale(SwsInternal *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) { VScalerContext *inst = desc->instance; int dstW = desc->dst->width; @@ -170,7 +170,7 @@ static int packed_vscale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, i return 1; } -static int any_vscale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) +static int any_vscale(SwsInternal *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) { VScalerContext *inst = desc->instance; int dstW = desc->dst->width; @@ -211,7 +211,7 @@ static int any_vscale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int } -int ff_init_vscale(SwsContext *c, SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst) +int ff_init_vscale(SwsInternal *c, SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst) { VScalerContext *lumCtx = NULL; VScalerContext *chrCtx = NULL; @@ -255,7 +255,7 @@ int ff_init_vscale(SwsContext *c, SwsFilterDescriptor *desc, SwsSlice *src, SwsS return 0; } -void ff_init_vscale_pfn(SwsContext *c, +void ff_init_vscale_pfn(SwsInternal *c, yuv2planar1_fn yuv2plane1, yuv2planarX_fn yuv2planeX, yuv2interleavedX_fn yuv2nv12cX, @@ -319,5 +319,3 @@ void ff_init_vscale_pfn(SwsContext *c, lumCtx->pfn.yuv2anyX = yuv2anyX; } } - - diff --git a/libswscale/x86/hscale_fast_bilinear_simd.c b/libswscale/x86/hscale_fast_bilinear_simd.c index f6409b4fc5..47ca020004 100644 --- a/libswscale/x86/hscale_fast_bilinear_simd.c +++ b/libswscale/x86/hscale_fast_bilinear_simd.c @@ -190,7 +190,7 @@ av_cold int ff_init_hscaler_mmxext(int dstW, int xInc, uint8_t *filterCode, return fragmentPos + 1; } -void ff_hyscale_fast_mmxext(SwsContext *c, int16_t *dst, +void ff_hyscale_fast_mmxext(SwsInternal *c, int16_t *dst, int dstWidth, const uint8_t *src, int srcW, int xInc) { @@ -280,7 +280,7 @@ void ff_hyscale_fast_mmxext(SwsContext *c, int16_t *dst, dst[i] = src[srcW-1]*128; } -void ff_hcscale_fast_mmxext(SwsContext *c, int16_t *dst1, int16_t *dst2, +void ff_hcscale_fast_mmxext(SwsInternal *c, int16_t *dst1, int16_t *dst2, int dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc) { diff --git a/libswscale/x86/output.asm b/libswscale/x86/output.asm index 95ec2fa885..0f854e521d 100644 --- a/libswscale/x86/output.asm +++ b/libswscale/x86/output.asm @@ -572,7 +572,7 @@ yuv2nv12cX_fn yuv2nv21 ;----------------------------------------------------------------------------- ; planar grb yuv2anyX functions -; void ff_yuv2_full_X_(SwsContext *c, const int16_t *lumFilter, +; void ff_yuv2_full_X_(SwsInternal *c, const int16_t *lumFilter, ; const int16_t **lumSrcx, int lumFilterSize, ; const int16_t *chrFilter, const int16_t **chrUSrcx, ; const int16_t **chrVSrcx, int chrFilterSize, @@ -581,8 +581,8 @@ yuv2nv12cX_fn yuv2nv21 ;----------------------------------------------------------------------------- %if ARCH_X86_64 -struc SwsContext - .padding: resb 40292 ; offsetof(SwsContext, yuv2rgb_y_offset) +struc SwsInternal + .padding: resb 40292 ; offsetof(SwsInternal, yuv2rgb_y_offset) .yuv2rgb_y_offset: resd 1 .yuv2rgb_y_coeff: resd 1 .yuv2rgb_v2r_coeff: resd 1 @@ -795,12 +795,12 @@ endstruc %endif cglobal yuv2%1_full_X, 12, 14, 16, ptr, lumFilter, lumSrcx, lumFilterSize, chrFilter, chrUSrcx, chrVSrcx, chrFilterSize, alpSrcx, dest, dstW, y, x, j - VBROADCASTSS m10, dword [ptrq + SwsContext.yuv2rgb_y_offset] - VBROADCASTSS m11, dword [ptrq + SwsContext.yuv2rgb_y_coeff] - VBROADCASTSS m12, dword [ptrq + SwsContext.yuv2rgb_v2r_coeff] - VBROADCASTSS m13, dword [ptrq + SwsContext.yuv2rgb_v2g_coeff] - VBROADCASTSS m14, dword [ptrq + SwsContext.yuv2rgb_u2g_coeff] - VBROADCASTSS m15, dword [ptrq + SwsContext.yuv2rgb_u2b_coeff] + VBROADCASTSS m10, dword [ptrq + SwsInternal.yuv2rgb_y_offset] + VBROADCASTSS m11, dword [ptrq + SwsInternal.yuv2rgb_y_coeff] + VBROADCASTSS m12, dword [ptrq + SwsInternal.yuv2rgb_v2r_coeff] + VBROADCASTSS m13, dword [ptrq + SwsInternal.yuv2rgb_v2g_coeff] + VBROADCASTSS m14, dword [ptrq + SwsInternal.yuv2rgb_u2g_coeff] + VBROADCASTSS m15, dword [ptrq + SwsInternal.yuv2rgb_u2b_coeff] %if DEPTH >= 16 movu m9, [pd_yuv2gbrp16_start] diff --git a/libswscale/x86/scale.asm b/libswscale/x86/scale.asm index baf03d52fa..85a96dc57e 100644 --- a/libswscale/x86/scale.asm +++ b/libswscale/x86/scale.asm @@ -33,7 +33,7 @@ SECTION .text ; horizontal line scaling ; ; void hscaleto__ -; (SwsContext *c, int{16,32}_t *dst, +; (SwsInternal *c, int{16,32}_t *dst, ; int dstW, const uint{8,16}_t *src, ; const int16_t *filter, ; const int32_t *filterPos, int filterSize); diff --git a/libswscale/x86/scale_avx2.asm b/libswscale/x86/scale_avx2.asm index 179895666a..b4b852d60b 100644 --- a/libswscale/x86/scale_avx2.asm +++ b/libswscale/x86/scale_avx2.asm @@ -33,7 +33,7 @@ SECTION .text ; horizontal line scaling ; ; void hscale8to15__ -; (SwsContext *c, int16_t *dst, +; (SwsInternal *c, int16_t *dst, ; int dstW, const uint8_t *src, ; const int16_t *filter, ; const int32_t *filterPos, int filterSize); diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c index 43319fd6b2..16182124c0 100644 --- a/libswscale/x86/swscale.c +++ b/libswscale/x86/swscale.c @@ -61,7 +61,7 @@ DECLARE_ASM_ALIGNED(8, const uint64_t, ff_w1111) = 0x0001000100010001ULL; #include "swscale_template.c" #endif -void ff_updateMMXDitherTables(SwsContext *c, int dstY) +void ff_updateMMXDitherTables(SwsInternal *c, int dstY) { const int dstH= c->dstH; const int flags= c->flags; @@ -226,7 +226,7 @@ YUV2YUVX_FUNC(avx2, 64) #define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt) \ void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n ## _ ## opt( \ - SwsContext *c, int16_t *data, \ + SwsInternal *c, int16_t *data, \ int dstW, const uint8_t *src, \ const int16_t *filter, \ const int32_t *filterPos, int filterSize) @@ -337,7 +337,7 @@ YUV2NV_DECL(nv12, avx2); YUV2NV_DECL(nv21, avx2); #define YUV2GBRP_FN_DECL(fmt, opt) \ -void ff_yuv2##fmt##_full_X_ ##opt(SwsContext *c, const int16_t *lumFilter, \ +void ff_yuv2##fmt##_full_X_ ##opt(SwsInternal *c, const int16_t *lumFilter, \ const int16_t **lumSrcx, int lumFilterSize, \ const int16_t *chrFilter, const int16_t **chrUSrcx, \ const int16_t **chrVSrcx, int chrFilterSize, \ @@ -472,7 +472,7 @@ void ff_chrRangeToJpeg_ ##opt(int16_t *dstU, int16_t *dstV, int width); \ RANGE_CONVERT_FUNCS_DECL(sse2); RANGE_CONVERT_FUNCS_DECL(avx2); -av_cold void ff_sws_init_range_convert_x86(SwsContext *c) +av_cold void ff_sws_init_range_convert_x86(SwsInternal *c) { if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) { int cpu_flags = av_get_cpu_flags(); @@ -484,7 +484,7 @@ av_cold void ff_sws_init_range_convert_x86(SwsContext *c) } } -av_cold void ff_sws_init_swscale_x86(SwsContext *c) +av_cold void ff_sws_init_swscale_x86(SwsInternal *c) { int cpu_flags = av_get_cpu_flags(); @@ -792,9 +792,9 @@ switch(c->dstBpc){ \ if(c->flags & SWS_FULL_CHR_H_INT) { - /* yuv2gbrp uses the SwsContext for yuv coefficients + /* yuv2gbrp uses the SwsInternal for yuv coefficients if struct offsets change the asm needs to be updated too */ - av_assert0(offsetof(SwsContext, yuv2rgb_y_offset) == 40292); + av_assert0(offsetof(SwsInternal, yuv2rgb_y_offset) == 40292); #define YUV2ANYX_FUNC_CASE(fmt, name, opt) \ case fmt: \ diff --git a/libswscale/x86/swscale_template.c b/libswscale/x86/swscale_template.c index 6bff2a44aa..cffafccb24 100644 --- a/libswscale/x86/swscale_template.c +++ b/libswscale/x86/swscale_template.c @@ -250,7 +250,7 @@ " jb 1b \n\t" #define WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t) REAL_WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t) -static void RENAME(yuv2rgb32_X_ar)(SwsContext *c, const int16_t *lumFilter, +static void RENAME(yuv2rgb32_X_ar)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, @@ -283,7 +283,7 @@ static void RENAME(yuv2rgb32_X_ar)(SwsContext *c, const int16_t *lumFilter, } } -static void RENAME(yuv2rgb32_X)(SwsContext *c, const int16_t *lumFilter, +static void RENAME(yuv2rgb32_X)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, @@ -312,7 +312,7 @@ static void RENAME(yuv2rgb32_X)(SwsContext *c, const int16_t *lumFilter, } } -static void RENAME(yuv2bgr32_X)(SwsContext *c, const int16_t *lumFilter, +static void RENAME(yuv2bgr32_X)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, @@ -369,7 +369,7 @@ static void RENAME(yuv2bgr32_X)(SwsContext *c, const int16_t *lumFilter, " jb 1b \n\t" #define WRITERGB16(dst, dstw, index) REAL_WRITERGB16(dst, dstw, index) -static void RENAME(yuv2rgb565_X_ar)(SwsContext *c, const int16_t *lumFilter, +static void RENAME(yuv2rgb565_X_ar)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, @@ -391,7 +391,7 @@ static void RENAME(yuv2rgb565_X_ar)(SwsContext *c, const int16_t *lumFilter, YSCALEYUV2PACKEDX_END } -static void RENAME(yuv2rgb565_X)(SwsContext *c, const int16_t *lumFilter, +static void RENAME(yuv2rgb565_X)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, @@ -442,7 +442,7 @@ static void RENAME(yuv2rgb565_X)(SwsContext *c, const int16_t *lumFilter, " jb 1b \n\t" #define WRITERGB15(dst, dstw, index) REAL_WRITERGB15(dst, dstw, index) -static void RENAME(yuv2rgb555_X_ar)(SwsContext *c, const int16_t *lumFilter, +static void RENAME(yuv2rgb555_X_ar)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, @@ -464,7 +464,7 @@ static void RENAME(yuv2rgb555_X_ar)(SwsContext *c, const int16_t *lumFilter, YSCALEYUV2PACKEDX_END } -static void RENAME(yuv2rgb555_X)(SwsContext *c, const int16_t *lumFilter, +static void RENAME(yuv2rgb555_X)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, @@ -591,7 +591,7 @@ static void RENAME(yuv2rgb555_X)(SwsContext *c, const int16_t *lumFilter, #define WRITEBGR24(dst, dstw, index) WRITEBGR24MMXEXT(dst, dstw, index) #if HAVE_6REGS -static void RENAME(yuv2bgr24_X_ar)(SwsContext *c, const int16_t *lumFilter, +static void RENAME(yuv2bgr24_X_ar)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, @@ -616,7 +616,7 @@ static void RENAME(yuv2bgr24_X_ar)(SwsContext *c, const int16_t *lumFilter, ); } -static void RENAME(yuv2bgr24_X)(SwsContext *c, const int16_t *lumFilter, +static void RENAME(yuv2bgr24_X)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, @@ -659,7 +659,7 @@ static void RENAME(yuv2bgr24_X)(SwsContext *c, const int16_t *lumFilter, " jb 1b \n\t" #define WRITEYUY2(dst, dstw, index) REAL_WRITEYUY2(dst, dstw, index) -static void RENAME(yuv2yuyv422_X_ar)(SwsContext *c, const int16_t *lumFilter, +static void RENAME(yuv2yuyv422_X_ar)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, @@ -680,7 +680,7 @@ static void RENAME(yuv2yuyv422_X_ar)(SwsContext *c, const int16_t *lumFilter, YSCALEYUV2PACKEDX_END } -static void RENAME(yuv2yuyv422_X)(SwsContext *c, const int16_t *lumFilter, +static void RENAME(yuv2yuyv422_X)(SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, @@ -781,7 +781,7 @@ static void RENAME(yuv2yuyv422_X)(SwsContext *c, const int16_t *lumFilter, /** * vertical bilinear scale YV12 to RGB */ -static void RENAME(yuv2rgb32_2)(SwsContext *c, const int16_t *buf[2], +static void RENAME(yuv2rgb32_2)(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) @@ -845,7 +845,7 @@ static void RENAME(yuv2rgb32_2)(SwsContext *c, const int16_t *buf[2], } } -static void RENAME(yuv2bgr24_2)(SwsContext *c, const int16_t *buf[2], +static void RENAME(yuv2bgr24_2)(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) @@ -868,7 +868,7 @@ static void RENAME(yuv2bgr24_2)(SwsContext *c, const int16_t *buf[2], ); } -static void RENAME(yuv2rgb555_2)(SwsContext *c, const int16_t *buf[2], +static void RENAME(yuv2rgb555_2)(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) @@ -895,7 +895,7 @@ static void RENAME(yuv2rgb555_2)(SwsContext *c, const int16_t *buf[2], ); } -static void RENAME(yuv2rgb565_2)(SwsContext *c, const int16_t *buf[2], +static void RENAME(yuv2rgb565_2)(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) @@ -962,7 +962,7 @@ static void RENAME(yuv2rgb565_2)(SwsContext *c, const int16_t *buf[2], #define YSCALEYUV2PACKED(index, c) REAL_YSCALEYUV2PACKED(index, c) -static void RENAME(yuv2yuyv422_2)(SwsContext *c, const int16_t *buf[2], +static void RENAME(yuv2yuyv422_2)(SwsInternal *c, const int16_t *buf[2], const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) @@ -1101,7 +1101,7 @@ static void RENAME(yuv2yuyv422_2)(SwsContext *c, const int16_t *buf[2], /** * YV12 to RGB without scaling or interpolating */ -static void RENAME(yuv2rgb32_1)(SwsContext *c, const int16_t *buf0, +static void RENAME(yuv2rgb32_1)(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y) @@ -1170,7 +1170,7 @@ static void RENAME(yuv2rgb32_1)(SwsContext *c, const int16_t *buf0, } } -static void RENAME(yuv2bgr24_1)(SwsContext *c, const int16_t *buf0, +static void RENAME(yuv2bgr24_1)(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y) @@ -1211,7 +1211,7 @@ static void RENAME(yuv2bgr24_1)(SwsContext *c, const int16_t *buf0, } } -static void RENAME(yuv2rgb555_1)(SwsContext *c, const int16_t *buf0, +static void RENAME(yuv2rgb555_1)(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y) @@ -1260,7 +1260,7 @@ static void RENAME(yuv2rgb555_1)(SwsContext *c, const int16_t *buf0, } } -static void RENAME(yuv2rgb565_1)(SwsContext *c, const int16_t *buf0, +static void RENAME(yuv2rgb565_1)(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y) @@ -1346,7 +1346,7 @@ static void RENAME(yuv2rgb565_1)(SwsContext *c, const int16_t *buf0, "psraw $7, %%mm7 \n\t" #define YSCALEYUV2PACKED1b(index, c) REAL_YSCALEYUV2PACKED1b(index, c) -static void RENAME(yuv2yuyv422_1)(SwsContext *c, const int16_t *buf0, +static void RENAME(yuv2yuyv422_1)(SwsInternal *c, const int16_t *buf0, const int16_t *ubuf[2], const int16_t *vbuf[2], const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y) @@ -1382,7 +1382,7 @@ static void RENAME(yuv2yuyv422_1)(SwsContext *c, const int16_t *buf0, ); } } -static av_cold void RENAME(sws_init_swscale)(SwsContext *c) +static av_cold void RENAME(sws_init_swscale)(SwsInternal *c) { enum AVPixelFormat dstFormat = c->dstFormat; diff --git a/libswscale/x86/w64xmmtest.c b/libswscale/x86/w64xmmtest.c index 88143d9687..d405a0eab4 100644 --- a/libswscale/x86/w64xmmtest.c +++ b/libswscale/x86/w64xmmtest.c @@ -22,7 +22,7 @@ #include "libavutil/x86/w64xmmtest.h" #include "libswscale/swscale.h" -wrap(sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], +wrap(sws_scale(SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])) { diff --git a/libswscale/x86/yuv2rgb.c b/libswscale/x86/yuv2rgb.c index 3ee13304fd..93a6b9a6e2 100644 --- a/libswscale/x86/yuv2rgb.c +++ b/libswscale/x86/yuv2rgb.c @@ -86,7 +86,7 @@ extern void ff_yuv_420_gbrp24_ssse3(x86_reg index, uint8_t *image, uint8_t *dst_ const uint8_t *py_2index); #endif -static inline int yuv420_rgb15_ssse3(SwsContext *c, const uint8_t *const src[], +static inline int yuv420_rgb15_ssse3(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) @@ -104,7 +104,7 @@ static inline int yuv420_rgb15_ssse3(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static inline int yuv420_rgb16_ssse3(SwsContext *c, const uint8_t *const src[], +static inline int yuv420_rgb16_ssse3(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) @@ -122,7 +122,7 @@ static inline int yuv420_rgb16_ssse3(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static inline int yuv420_rgb32_ssse3(SwsContext *c, const uint8_t *const src[], +static inline int yuv420_rgb32_ssse3(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) @@ -136,7 +136,7 @@ static inline int yuv420_rgb32_ssse3(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static inline int yuv420_bgr32_ssse3(SwsContext *c, const uint8_t *const src[], +static inline int yuv420_bgr32_ssse3(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) @@ -150,7 +150,7 @@ static inline int yuv420_bgr32_ssse3(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static inline int yuva420_rgb32_ssse3(SwsContext *c, const uint8_t *const src[], +static inline int yuva420_rgb32_ssse3(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) @@ -164,7 +164,7 @@ static inline int yuva420_rgb32_ssse3(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static inline int yuva420_bgr32_ssse3(SwsContext *c, const uint8_t *const src[], +static inline int yuva420_bgr32_ssse3(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) @@ -179,7 +179,7 @@ static inline int yuva420_bgr32_ssse3(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static inline int yuv420_rgb24_ssse3(SwsContext *c, const uint8_t *const src[], +static inline int yuv420_rgb24_ssse3(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) @@ -193,7 +193,7 @@ static inline int yuv420_rgb24_ssse3(SwsContext *c, const uint8_t *const src[], return srcSliceH; } -static inline int yuv420_bgr24_ssse3(SwsContext *c, const uint8_t *const src[], +static inline int yuv420_bgr24_ssse3(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) @@ -208,7 +208,7 @@ static inline int yuv420_bgr24_ssse3(SwsContext *c, const uint8_t *const src[], } #if ARCH_X86_64 -static inline int yuv420_gbrp_ssse3(SwsContext *c, const uint8_t *const src[], +static inline int yuv420_gbrp_ssse3(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) @@ -238,7 +238,7 @@ static inline int yuv420_gbrp_ssse3(SwsContext *c, const uint8_t *const src[], #endif /* HAVE_X86ASM */ -av_cold SwsFunc ff_yuv2rgb_init_x86(SwsContext *c) +av_cold SwsFunc ff_yuv2rgb_init_x86(SwsInternal *c) { #if HAVE_X86ASM int cpu_flags = av_get_cpu_flags(); diff --git a/libswscale/yuv2rgb.c b/libswscale/yuv2rgb.c index 941971d1ab..f4fa1c0549 100644 --- a/libswscale/yuv2rgb.c +++ b/libswscale/yuv2rgb.c @@ -135,7 +135,7 @@ const int *sws_getCoefficients(int colorspace) dst2_##l[2 * i + 1] = r[Y]; #define YUV2RGBFUNC(func_name, dst_type, alpha, yuv422, nb_dst_planes) \ - static int func_name(SwsContext *c, const uint8_t *const src[], \ + static int func_name(SwsInternal *c, const uint8_t *const src[], \ const int srcStride[], int srcSliceY, int srcSliceH, \ uint8_t *const dst[], const int dstStride[]) \ { \ @@ -558,7 +558,7 @@ YUV422FUNC_DITHER(yuv422p_bgr8, uint8_t, LOADDITHER8, PUTRGB8, 8) YUV422FUNC_DITHER(yuv422p_bgr4, uint8_t, LOADDITHER4D, PUTRGB4D, 4) YUV422FUNC_DITHER(yuv422p_bgr4_byte, uint8_t, LOADDITHER4DB, PUTRGB4DB, 8) -SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c) +SwsFunc ff_yuv2rgb_get_func_ptr(SwsInternal *c) { SwsFunc t = NULL; @@ -702,7 +702,7 @@ static uint16_t roundToInt16(int64_t f) return r; } -av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], +av_cold int ff_yuv2rgb_c_init_tables(SwsInternal *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation) { diff --git a/tests/checkasm/sw_gbrp.c b/tests/checkasm/sw_gbrp.c index d843730f3e..039be8006b 100644 --- a/tests/checkasm/sw_gbrp.c +++ b/tests/checkasm/sw_gbrp.c @@ -63,7 +63,8 @@ static const int planar_fmts[] = { static void check_output_yuv2gbrp(void) { - struct SwsContext *ctx; + SwsContext *sws; + SwsInternal *c; const AVPixFmtDescriptor *desc; int fmi, fsi, isi, i; int dstW, byte_size, luma_filter_size, chr_filter_size; @@ -76,7 +77,7 @@ static void check_output_yuv2gbrp(void) uint8_t *dst0[4]; uint8_t *dst1[4]; - declare_func(void, struct SwsContext *c, const int16_t *lumFilter, + declare_func(void, SwsInternal *c, const int16_t *lumFilter, const int16_t **lumSrcx, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrcx, const int16_t **chrVSrcx, int chrFilterSize, @@ -130,17 +131,18 @@ static void check_output_yuv2gbrp(void) alpha[i] = (int16_t *)(src_a + i*LARGEST_INPUT_SIZE); } - ctx = sws_alloc_context(); - if (sws_init_context(ctx, NULL, NULL) < 0) + sws = sws_alloc_context(); + if (sws_init_context(sws, NULL, NULL) < 0) fail(); - ctx->flags |= SWS_FULL_CHR_H_INT; + c = sws_internal(sws); + c->flags |= SWS_FULL_CHR_H_INT; for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) { for (fsi = 0; fsi < FILTER_SIZES; fsi++) { for (isi = 0; isi < INPUT_SIZES; isi++ ) { desc = av_pix_fmt_desc_get(planar_fmts[fmi]); - ctx->dstFormat = planar_fmts[fmi]; + c->dstFormat = planar_fmts[fmi]; dstW = input_sizes[isi]; luma_filter_size = filter_sizes[fsi]; @@ -154,17 +156,17 @@ static void check_output_yuv2gbrp(void) byte_size = 1; } - ff_sws_init_scale(ctx); - if (check_func(ctx->yuv2anyX, "yuv2%s_full_X_%d_%d", desc->name, luma_filter_size, dstW)) { + ff_sws_init_scale(c); + if (check_func(c->yuv2anyX, "yuv2%s_full_X_%d_%d", desc->name, luma_filter_size, dstW)) { for (i = 0; i < 4; i ++) { memset(dst0[i], 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t)); memset(dst1[i], 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t)); } - call_ref(ctx, luma_filter, luma, luma_filter_size, + call_ref(c, luma_filter, luma, luma_filter_size, chr_filter, chru, chrv, chr_filter_size, alpha, dst0, dstW, 0); - call_new(ctx, luma_filter, luma, luma_filter_size, + call_new(c, luma_filter, luma, luma_filter_size, chr_filter, chru, chrv, chr_filter_size, alpha, dst1, dstW, 0); @@ -174,14 +176,14 @@ static void check_output_yuv2gbrp(void) memcmp(dst0[3], dst1[3], dstW * byte_size) ) fail(); - bench_new(ctx, luma_filter, luma, luma_filter_size, + bench_new(c, luma_filter, luma, luma_filter_size, chr_filter, chru, chrv, chr_filter_size, alpha, dst1, dstW, 0); } } } } - sws_freeContext(ctx); + sws_freeContext(sws); } #undef LARGEST_INPUT_SIZE @@ -189,7 +191,8 @@ static void check_output_yuv2gbrp(void) static void check_input_planar_rgb_to_y(void) { - struct SwsContext *ctx; + SwsContext *sws; + SwsInternal *c; const AVPixFmtDescriptor *desc; int fmi, isi; int dstW, byte_size; @@ -221,20 +224,21 @@ static void check_input_planar_rgb_to_y(void) src[2] = (uint8_t*)src_r; src[3] = (uint8_t*)src_a; - ctx = sws_alloc_context(); - if (sws_init_context(ctx, NULL, NULL) < 0) + sws = sws_alloc_context(); + if (sws_init_context(sws, NULL, NULL) < 0) fail(); + c = sws_internal(sws); for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) { for (isi = 0; isi < INPUT_SIZES; isi++ ) { desc = av_pix_fmt_desc_get(planar_fmts[fmi]); - ctx->srcFormat = planar_fmts[fmi]; - ctx->dstFormat = AV_PIX_FMT_YUVA444P16; + c->srcFormat = planar_fmts[fmi]; + c->dstFormat = AV_PIX_FMT_YUVA444P16; byte_size = 2; dstW = input_sizes[isi]; - ff_sws_init_scale(ctx); - if(check_func(ctx->readLumPlanar, "planar_%s_to_y_%d", desc->name, dstW)) { + ff_sws_init_scale(c); + if(check_func(c->readLumPlanar, "planar_%s_to_y_%d", desc->name, dstW)) { memset(dst0_y, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t)); memset(dst1_y, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t)); @@ -249,7 +253,7 @@ static void check_input_planar_rgb_to_y(void) } } } - sws_freeContext(ctx); + sws_freeContext(sws); } #undef LARGEST_INPUT_SIZE @@ -257,7 +261,8 @@ static void check_input_planar_rgb_to_y(void) static void check_input_planar_rgb_to_uv(void) { - struct SwsContext *ctx; + SwsContext *sws; + SwsInternal *c; const AVPixFmtDescriptor *desc; int fmi, isi; int dstW, byte_size; @@ -292,20 +297,21 @@ static void check_input_planar_rgb_to_uv(void) src[2] = (uint8_t*)src_r; src[3] = (uint8_t*)src_a; - ctx = sws_alloc_context(); - if (sws_init_context(ctx, NULL, NULL) < 0) + sws = sws_alloc_context(); + if (sws_init_context(sws, NULL, NULL) < 0) fail(); + c = sws_internal(sws); for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) { for (isi = 0; isi < INPUT_SIZES; isi++ ) { desc = av_pix_fmt_desc_get(planar_fmts[fmi]); - ctx->srcFormat = planar_fmts[fmi]; - ctx->dstFormat = AV_PIX_FMT_YUVA444P16; + c->srcFormat = planar_fmts[fmi]; + c->dstFormat = AV_PIX_FMT_YUVA444P16; byte_size = 2; dstW = input_sizes[isi]; - ff_sws_init_scale(ctx); - if(check_func(ctx->readChrPlanar, "planar_%s_to_uv_%d", desc->name, dstW)) { + ff_sws_init_scale(c); + if(check_func(c->readChrPlanar, "planar_%s_to_uv_%d", desc->name, dstW)) { memset(dst0_u, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t)); memset(dst0_v, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t)); memset(dst1_u, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t)); @@ -322,7 +328,7 @@ static void check_input_planar_rgb_to_uv(void) } } } - sws_freeContext(ctx); + sws_freeContext(sws); } #undef LARGEST_INPUT_SIZE @@ -330,7 +336,8 @@ static void check_input_planar_rgb_to_uv(void) static void check_input_planar_rgb_to_a(void) { - struct SwsContext *ctx; + SwsContext *sws; + SwsInternal *c; const AVPixFmtDescriptor *desc; int fmi, isi; int dstW, byte_size; @@ -362,23 +369,24 @@ static void check_input_planar_rgb_to_a(void) src[2] = (uint8_t*)src_r; src[3] = (uint8_t*)src_a; - ctx = sws_alloc_context(); - if (sws_init_context(ctx, NULL, NULL) < 0) + sws = sws_alloc_context(); + if (sws_init_context(sws, NULL, NULL) < 0) fail(); + c = sws_internal(sws); for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) { for (isi = 0; isi < INPUT_SIZES; isi++ ) { desc = av_pix_fmt_desc_get(planar_fmts[fmi]); if (!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) continue; - ctx->srcFormat = planar_fmts[fmi]; - ctx->dstFormat = AV_PIX_FMT_YUVA444P16; + c->srcFormat = planar_fmts[fmi]; + c->dstFormat = AV_PIX_FMT_YUVA444P16; byte_size = 2; dstW = input_sizes[isi]; - ff_sws_init_scale(ctx); - if(check_func(ctx->readAlpPlanar, "planar_%s_to_a_%d", desc->name, dstW)) { + ff_sws_init_scale(c); + if(check_func(c->readAlpPlanar, "planar_%s_to_a_%d", desc->name, dstW)) { memset(dst0_a, 0x00, LARGEST_INPUT_SIZE * sizeof(int32_t)); memset(dst1_a, 0x00, LARGEST_INPUT_SIZE * sizeof(int32_t)); @@ -391,7 +399,7 @@ static void check_input_planar_rgb_to_a(void) } } } - sws_freeContext(ctx); + sws_freeContext(sws); } void checkasm_check_sw_gbrp(void) diff --git a/tests/checkasm/sw_range_convert.c b/tests/checkasm/sw_range_convert.c index 08029103d1..7da29b896e 100644 --- a/tests/checkasm/sw_range_convert.c +++ b/tests/checkasm/sw_range_convert.c @@ -34,21 +34,23 @@ static void check_lumConvertRange(int from) #define LARGEST_INPUT_SIZE 512 #define INPUT_SIZES 6 static const int input_sizes[] = {8, 24, 128, 144, 256, 512}; - struct SwsContext *ctx; + SwsContext *sws; + SwsInternal *c; LOCAL_ALIGNED_32(int16_t, dst0, [LARGEST_INPUT_SIZE]); LOCAL_ALIGNED_32(int16_t, dst1, [LARGEST_INPUT_SIZE]); declare_func(void, int16_t *dst, int width); - ctx = sws_alloc_context(); - if (sws_init_context(ctx, NULL, NULL) < 0) + sws = sws_alloc_context(); + if (sws_init_context(sws, NULL, NULL) < 0) fail(); - ctx->srcFormat = from ? AV_PIX_FMT_YUVJ444P : AV_PIX_FMT_YUV444P; - ctx->dstFormat = from ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P; - ctx->srcRange = from; - ctx->dstRange = !from; + c = sws_internal(sws); + c->srcFormat = from ? AV_PIX_FMT_YUVJ444P : AV_PIX_FMT_YUV444P; + c->dstFormat = from ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P; + c->srcRange = from; + c->dstRange = !from; for (int dstWi = 0; dstWi < INPUT_SIZES; dstWi++) { int width = input_sizes[dstWi]; @@ -57,8 +59,8 @@ static void check_lumConvertRange(int from) dst0[i] = (int16_t) r << 7; dst1[i] = (int16_t) r << 7; } - ff_sws_init_scale(ctx); - if (check_func(ctx->lumConvertRange, "%s_%d", func_str, width)) { + ff_sws_init_scale(c); + if (check_func(c->lumConvertRange, "%s_%d", func_str, width)) { call_ref(dst0, width); call_new(dst1, width); if (memcmp(dst0, dst1, width * sizeof(int16_t))) @@ -67,7 +69,7 @@ static void check_lumConvertRange(int from) } } - sws_freeContext(ctx); + sws_freeContext(sws); } #undef LARGEST_INPUT_SIZE #undef INPUT_SIZES @@ -78,7 +80,8 @@ static void check_chrConvertRange(int from) #define LARGEST_INPUT_SIZE 512 #define INPUT_SIZES 6 static const int input_sizes[] = {8, 24, 128, 144, 256, 512}; - struct SwsContext *ctx; + SwsContext *sws; + SwsInternal *c; LOCAL_ALIGNED_32(int16_t, dstU0, [LARGEST_INPUT_SIZE]); LOCAL_ALIGNED_32(int16_t, dstV0, [LARGEST_INPUT_SIZE]); @@ -87,14 +90,15 @@ static void check_chrConvertRange(int from) declare_func(void, int16_t *dstU, int16_t *dstV, int width); - ctx = sws_alloc_context(); - if (sws_init_context(ctx, NULL, NULL) < 0) + sws = sws_alloc_context(); + if (sws_init_context(sws, NULL, NULL) < 0) fail(); - ctx->srcFormat = from ? AV_PIX_FMT_YUVJ444P : AV_PIX_FMT_YUV444P; - ctx->dstFormat = from ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P; - ctx->srcRange = from; - ctx->dstRange = !from; + c = sws_internal(sws); + c->srcFormat = from ? AV_PIX_FMT_YUVJ444P : AV_PIX_FMT_YUV444P; + c->dstFormat = from ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P; + c->srcRange = from; + c->dstRange = !from; for (int dstWi = 0; dstWi < INPUT_SIZES; dstWi++) { int width = input_sizes[dstWi]; @@ -105,8 +109,8 @@ static void check_chrConvertRange(int from) dstU1[i] = (int16_t) r << 7; dstV1[i] = (int16_t) r << 7; } - ff_sws_init_scale(ctx); - if (check_func(ctx->chrConvertRange, "%s_%d", func_str, width)) { + ff_sws_init_scale(c); + if (check_func(c->chrConvertRange, "%s_%d", func_str, width)) { call_ref(dstU0, dstV0, width); call_new(dstU1, dstV1, width); if (memcmp(dstU0, dstU1, width * sizeof(int16_t)) || @@ -116,7 +120,7 @@ static void check_chrConvertRange(int from) } } - sws_freeContext(ctx); + sws_freeContext(sws); } #undef LARGEST_INPUT_SIZE #undef INPUT_SIZES diff --git a/tests/checkasm/sw_rgb.c b/tests/checkasm/sw_rgb.c index cdd43df8ba..7af82f0fc7 100644 --- a/tests/checkasm/sw_rgb.c +++ b/tests/checkasm/sw_rgb.c @@ -127,7 +127,7 @@ static int cmp_off_by_n(const uint8_t *ref, const uint8_t *test, size_t n, int a return 0; } -static void check_rgb24toyv12(struct SwsContext *ctx) +static void check_rgb24toyv12(SwsInternal *ctx) { static const int input_sizes[] = {16, 128, 512, MAX_LINE_SIZE, -MAX_LINE_SIZE}; @@ -353,7 +353,7 @@ static const enum AVPixelFormat rgb_formats[] = { AV_PIX_FMT_ARGB, }; -static void check_rgb_to_y(struct SwsContext *ctx) +static void check_rgb_to_y(SwsInternal *ctx) { LOCAL_ALIGNED_16(uint8_t, src24, [MAX_LINE_SIZE * 3]); LOCAL_ALIGNED_16(uint8_t, src32, [MAX_LINE_SIZE * 4]); @@ -396,7 +396,7 @@ static void check_rgb_to_y(struct SwsContext *ctx) } } -static void check_rgb_to_uv(struct SwsContext *ctx) +static void check_rgb_to_uv(SwsInternal *ctx) { LOCAL_ALIGNED_16(uint8_t, src24, [MAX_LINE_SIZE * 3]); LOCAL_ALIGNED_16(uint8_t, src32, [MAX_LINE_SIZE * 4]); @@ -450,7 +450,8 @@ static void check_rgb_to_uv(struct SwsContext *ctx) void checkasm_check_sw_rgb(void) { - struct SwsContext *ctx; + SwsContext *sws; + SwsInternal *c; ff_sws_rgb2rgb_init(); @@ -478,20 +479,21 @@ void checkasm_check_sw_rgb(void) check_deinterleave_bytes(); report("deinterleave_bytes"); - ctx = sws_getContext(MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_RGB24, + sws = sws_getContext(MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_RGB24, MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_YUV420P, SWS_ACCURATE_RND | SWS_BITEXACT, NULL, NULL, NULL); - if (!ctx) + if (!sws) fail(); - check_rgb_to_y(ctx); + c = sws_internal(sws); + check_rgb_to_y(c); report("rgb_to_y"); - check_rgb_to_uv(ctx); + check_rgb_to_uv(c); report("rgb_to_uv"); - check_rgb24toyv12(ctx); + check_rgb24toyv12(c); report("rgb24toyv12"); - sws_freeContext(ctx); + sws_freeContext(sws); } diff --git a/tests/checkasm/sw_scale.c b/tests/checkasm/sw_scale.c index 32a5d1c1ac..b383fa0930 100644 --- a/tests/checkasm/sw_scale.c +++ b/tests/checkasm/sw_scale.c @@ -99,7 +99,8 @@ static size_t show_differences(uint8_t *a, uint8_t *b, size_t len) static void check_yuv2yuv1(int accurate) { - struct SwsContext *ctx; + SwsContext *sws; + SwsInternal *c; int osi, isi; int dstW, offset; size_t fail_offset; @@ -122,18 +123,19 @@ static void check_yuv2yuv1(int accurate) randomize_buffers((uint8_t*)dither, 8); randomize_buffers((uint8_t*)src_pixels, LARGEST_INPUT_SIZE * sizeof(int16_t)); - ctx = sws_alloc_context(); + sws = sws_alloc_context(); + c = sws_internal(sws); if (accurate) - ctx->flags |= SWS_ACCURATE_RND; - if (sws_init_context(ctx, NULL, NULL) < 0) + c->flags |= SWS_ACCURATE_RND; + if (sws_init_context(sws, NULL, NULL) < 0) fail(); - ff_sws_init_scale(ctx); + ff_sws_init_scale(c); for (isi = 0; isi < INPUT_SIZES; ++isi) { dstW = input_sizes[isi]; for (osi = 0; osi < OFFSET_SIZES; osi++) { offset = offsets[osi]; - if (check_func(ctx->yuv2plane1, "yuv2yuv1_%d_%d_%s", offset, dstW, accurate_str)){ + if (check_func(c->yuv2plane1, "yuv2yuv1_%d_%d_%s", offset, dstW, accurate_str)){ memset(dst0, 0, LARGEST_INPUT_SIZE * sizeof(dst0[0])); memset(dst1, 0, LARGEST_INPUT_SIZE * sizeof(dst1[0])); @@ -154,12 +156,13 @@ static void check_yuv2yuv1(int accurate) } } } - sws_freeContext(ctx); + sws_freeContext(sws); } static void check_yuv2yuvX(int accurate) { - struct SwsContext *ctx; + SwsContext *sws; + SwsInternal *c; int fsi, osi, isi, i, j; int dstW; #define LARGEST_FILTER 16 @@ -188,13 +191,14 @@ static void check_yuv2yuvX(int accurate) uint8_t d_val = rnd(); memset(dither, d_val, LARGEST_INPUT_SIZE); randomize_buffers((uint8_t*)src_pixels, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int16_t)); - ctx = sws_alloc_context(); + sws = sws_alloc_context(); + c = sws_internal(sws); if (accurate) - ctx->flags |= SWS_ACCURATE_RND; - if (sws_init_context(ctx, NULL, NULL) < 0) + c->flags |= SWS_ACCURATE_RND; + if (sws_init_context(sws, NULL, NULL) < 0) fail(); - ff_sws_init_scale(ctx); + ff_sws_init_scale(c); for(isi = 0; isi < INPUT_SIZES; ++isi){ dstW = input_sizes[isi]; for(osi = 0; osi < 64; osi += 16){ @@ -225,9 +229,9 @@ static void check_yuv2yuvX(int accurate) for(j = 0; j < 4; ++j) vFilterData[i].coeff[j + 4] = filter_coeff[i]; } - if (check_func(ctx->yuv2planeX, "yuv2yuvX_%d_%d_%d_%s", filter_sizes[fsi], osi, dstW, accurate_str)){ + if (check_func(c->yuv2planeX, "yuv2yuvX_%d_%d_%d_%s", filter_sizes[fsi], osi, dstW, accurate_str)){ // use vFilterData for the mmx function - const int16_t *filter = ctx->use_mmx_vfilter ? (const int16_t*)vFilterData : &filter_coeff[0]; + const int16_t *filter = c->use_mmx_vfilter ? (const int16_t*)vFilterData : &filter_coeff[0]; memset(dst0, 0, LARGEST_INPUT_SIZE * sizeof(dst0[0])); memset(dst1, 0, LARGEST_INPUT_SIZE * sizeof(dst1[0])); @@ -250,7 +254,7 @@ static void check_yuv2yuvX(int accurate) } } } - sws_freeContext(ctx); + sws_freeContext(sws); #undef FILTER_SIZES } @@ -274,7 +278,8 @@ static void check_hscale(void) static const int input_sizes[INPUT_SIZES] = {8, 24, 128, 144, 256, 512}; int i, j, fsi, hpi, width, dstWi; - struct SwsContext *ctx; + SwsContext *sws; + SwsInternal *c; // padded LOCAL_ALIGNED_32(uint8_t, src, [FFALIGN(SRC_PIXELS + MAX_FILTER_WIDTH - 1, 4)]); @@ -293,10 +298,11 @@ static void check_hscale(void) const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize); - ctx = sws_alloc_context(); - if (sws_init_context(ctx, NULL, NULL) < 0) + sws = sws_alloc_context(); + if (sws_init_context(sws, NULL, NULL) < 0) fail(); + c = sws_internal(sws); randomize_buffers(src, SRC_PIXELS + MAX_FILTER_WIDTH - 1); for (hpi = 0; hpi < HSCALE_PAIRS; hpi++) { @@ -304,9 +310,9 @@ static void check_hscale(void) for (dstWi = 0; dstWi < INPUT_SIZES; dstWi++) { width = filter_sizes[fsi]; - ctx->srcBpc = hscale_pairs[hpi][0]; - ctx->dstBpc = hscale_pairs[hpi][1]; - ctx->hLumFilterSize = ctx->hChrFilterSize = width; + c->srcBpc = hscale_pairs[hpi][0]; + c->dstBpc = hscale_pairs[hpi][1]; + c->hLumFilterSize = c->hChrFilterSize = width; for (i = 0; i < SRC_PIXELS; i++) { filterPos[i] = i; @@ -338,25 +344,25 @@ static void check_hscale(void) filter[SRC_PIXELS * width + i] = rnd(); } - ctx->dstW = ctx->chrDstW = input_sizes[dstWi]; - ff_sws_init_scale(ctx); + c->dstW = c->chrDstW = input_sizes[dstWi]; + ff_sws_init_scale(c); memcpy(filterAvx2, filter, sizeof(uint16_t) * (SRC_PIXELS * MAX_FILTER_WIDTH + MAX_FILTER_WIDTH)); - ff_shuffle_filter_coefficients(ctx, filterPosAvx, width, filterAvx2, ctx->dstW); + ff_shuffle_filter_coefficients(c, filterPosAvx, width, filterAvx2, c->dstW); - if (check_func(ctx->hcScale, "hscale_%d_to_%d__fs_%d_dstW_%d", ctx->srcBpc, ctx->dstBpc + 1, width, ctx->dstW)) { + if (check_func(c->hcScale, "hscale_%d_to_%d__fs_%d_dstW_%d", c->srcBpc, c->dstBpc + 1, width, c->dstW)) { memset(dst0, 0, SRC_PIXELS * sizeof(dst0[0])); memset(dst1, 0, SRC_PIXELS * sizeof(dst1[0])); - call_ref(NULL, dst0, ctx->dstW, src, filter, filterPos, width); - call_new(NULL, dst1, ctx->dstW, src, filterAvx2, filterPosAvx, width); - if (memcmp(dst0, dst1, ctx->dstW * sizeof(dst0[0]))) + call_ref(NULL, dst0, c->dstW, src, filter, filterPos, width); + call_new(NULL, dst1, c->dstW, src, filterAvx2, filterPosAvx, width); + if (memcmp(dst0, dst1, c->dstW * sizeof(dst0[0]))) fail(); - bench_new(NULL, dst0, ctx->dstW, src, filter, filterPosAvx, width); + bench_new(NULL, dst0, c->dstW, src, filter, filterPosAvx, width); } } } } - sws_freeContext(ctx); + sws_freeContext(sws); } void checkasm_check_sw_scale(void) diff --git a/tests/checkasm/sw_yuv2rgb.c b/tests/checkasm/sw_yuv2rgb.c index 5125f83968..c25fb99ca2 100644 --- a/tests/checkasm/sw_yuv2rgb.c +++ b/tests/checkasm/sw_yuv2rgb.c @@ -107,7 +107,7 @@ static void check_yuv2rgb(int src_pix_fmt) static const int input_sizes[] = {8, 128, 1080, MAX_LINE_SIZE}; declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, - int, SwsContext *c, const uint8_t *src[], + int, SwsInternal *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[]); @@ -147,7 +147,8 @@ static void check_yuv2rgb(int src_pix_fmt) const AVPixFmtDescriptor *dst_desc = av_pix_fmt_desc_get(dst_pix_fmt); int sample_size = av_get_padded_bits_per_pixel(dst_desc) >> 3; for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++) { - struct SwsContext *ctx; + SwsContext *sws; + SwsInternal *c; int log_level; int width = input_sizes[isi]; int srcSliceY = 0; @@ -168,14 +169,15 @@ static void check_yuv2rgb(int src_pix_fmt) // "No accelerated colorspace conversion found from %s to %s" log_level = av_log_get_level(); av_log_set_level(AV_LOG_ERROR); - ctx = sws_getContext(width, srcSliceH, src_pix_fmt, + sws = sws_getContext(width, srcSliceH, src_pix_fmt, width, srcSliceH, dst_pix_fmt, 0, NULL, NULL, NULL); av_log_set_level(log_level); - if (!ctx) + if (!sws) fail(); - if (check_func(ctx->convert_unscaled, "%s_%s_%d", src_desc->name, dst_desc->name, width)) { + c = sws_internal(sws); + if (check_func(c->convert_unscaled, "%s_%s_%d", src_desc->name, dst_desc->name, width)) { memset(dst0_0, 0xFF, 2 * MAX_LINE_SIZE * 6); memset(dst1_0, 0xFF, 2 * MAX_LINE_SIZE * 6); if (dst_pix_fmt == AV_PIX_FMT_GBRP) { @@ -185,9 +187,9 @@ static void check_yuv2rgb(int src_pix_fmt) memset(dst1_2, 0xFF, MAX_LINE_SIZE); } - call_ref(ctx, src, srcStride, srcSliceY, + call_ref(c, src, srcStride, srcSliceY, srcSliceH, dst0, dstStride); - call_new(ctx, src, srcStride, srcSliceY, + call_new(c, src, srcStride, srcSliceY, srcSliceH, dst1, dstStride); if (dst_pix_fmt == AV_PIX_FMT_ARGB || @@ -218,10 +220,10 @@ static void check_yuv2rgb(int src_pix_fmt) fail(); } - bench_new(ctx, src, srcStride, srcSliceY, + bench_new(c, src, srcStride, srcSliceY, srcSliceH, dst0, dstStride); } - sws_freeContext(ctx); + sws_freeContext(sws); } } } diff --git a/tests/checkasm/sw_yuv2yuv.c b/tests/checkasm/sw_yuv2yuv.c index 90a51601ed..6fe8e47d19 100644 --- a/tests/checkasm/sw_yuv2yuv.c +++ b/tests/checkasm/sw_yuv2yuv.c @@ -46,7 +46,7 @@ static void check_semiplanar(int dst_pix_fmt) static const int input_sizes[] = {8, 128, 1080, MAX_LINE_SIZE}; declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, - int, SwsContext *c, const uint8_t *src[], + int, SwsInternal *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[]); @@ -71,7 +71,8 @@ static void check_semiplanar(int dst_pix_fmt) int src_pix_fmt = src_fmts[sfi]; const AVPixFmtDescriptor *src_desc = av_pix_fmt_desc_get(src_pix_fmt); for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++) { - struct SwsContext *ctx; + SwsContext *sws; + SwsInternal *c; int log_level; int width = input_sizes[isi]; int srcSliceY = 0; @@ -90,14 +91,15 @@ static void check_semiplanar(int dst_pix_fmt) // "No accelerated colorspace conversion found from %s to %s" log_level = av_log_get_level(); av_log_set_level(AV_LOG_ERROR); - ctx = sws_getContext(width, srcSliceH, src_pix_fmt, + sws = sws_getContext(width, srcSliceH, src_pix_fmt, width, srcSliceH, dst_pix_fmt, 0, NULL, NULL, NULL); av_log_set_level(log_level); - if (!ctx) + if (!sws) fail(); - if (check_func(ctx->convert_unscaled, "%s_%s_%d", src_desc->name, dst_desc->name, width)) { + c = sws_internal(sws); + if (check_func(c->convert_unscaled, "%s_%s_%d", src_desc->name, dst_desc->name, width)) { memset(dst0_y, 0xFF, MAX_LINE_SIZE * NUM_LINES); memset(dst0_u, 0xFF, MAX_LINE_SIZE * NUM_LINES / 2); memset(dst0_v, 0xFF, MAX_LINE_SIZE * NUM_LINES / 2); @@ -105,9 +107,9 @@ static void check_semiplanar(int dst_pix_fmt) memset(dst1_u, 0xFF, MAX_LINE_SIZE * NUM_LINES / 2); memset(dst1_v, 0xFF, MAX_LINE_SIZE * NUM_LINES / 2); - call_ref(ctx, src, srcStride, srcSliceY, + call_ref(c, src, srcStride, srcSliceY, srcSliceH, dst0, dstStride); - call_new(ctx, src, srcStride, srcSliceY, + call_new(c, src, srcStride, srcSliceY, srcSliceH, dst1, dstStride); if (memcmp(dst0_y, dst1_y, MAX_LINE_SIZE * NUM_LINES) || @@ -115,10 +117,10 @@ static void check_semiplanar(int dst_pix_fmt) memcmp(dst0_v, dst1_v, MAX_LINE_SIZE * NUM_LINES / 2)) fail(); - bench_new(ctx, src, srcStride, srcSliceY, + bench_new(c, src, srcStride, srcSliceY, srcSliceH, dst0, dstStride); } - sws_freeContext(ctx); + sws_freeContext(sws); } } } From patchwork Sun Oct 20 20:05:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52413 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2241982vqi; Sun, 20 Oct 2024 13:19:10 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUsrvfFCigkFdepP6SysuFRSn1nJUHHx+wAqyYWKCbBgrL++UR/TK/3WCX2YTcS0LapOFYtcGi1z4ZyDPWgmsnW@gmail.com X-Google-Smtp-Source: AGHT+IGxqTKMQTlHrDDto44xJgNIBiCW9bXIqSI3Ed0QGF1BjjIdZZeESux29/soHmYI3pOlLyzi X-Received: by 2002:a17:907:60ca:b0:a9a:daa:ef3c with SMTP id a640c23a62f3a-a9a69a7b429mr1052069466b.14.1729455549785; Sun, 20 Oct 2024 13:19:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729455549; cv=none; d=google.com; s=arc-20240605; b=iIHY8Lj454PlxCZZJpJ64/gW0411bxHPHtCi8WgDxPVYusWdsTBl1SPVjnAduBW1tY DKgCibBT0AcOkhPoIfUejPlvKni/4d3HHQyEqJDC9e6GzFUly8+W4aYrk+Rl6H9KTWik GVj9jzaHoymb60tjb5VFAnplpmDpRjiDsm01AzD9qLiPe13oKgSQN4AH122TGdlmb6Dw iY5w7QfKzyEWhAVytHICv8er5sYfdrQUp3JRxfqMamfreVJ4sUvsVLxtP4qTzYcFihAf CuSQKYhujCiin6iq1F6ONs/028NukyIGZH+YCG3bP8ndsOEroHpdgBDn2jfEFot5PYB+ A1ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=x0LcrFiHEOXkJrA++dCyopeavdbElHmw1CJ+02VWYzc=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=TTBNm7QljWgmdsw79+1wNQuX9xtS6v5J7V1LLnsURv2b0QLLnCotHSm4f48hS2bpxE c2KTFuI9lZj/z9VXgKf0l9z+gyEhx6wczwkhI1HBdJint5UGQHX3uSJ857nblSOcSMwP qTzrlMNeEkeT4tVr2Gq3gvrrYDZJvJB2i75k4plBh1ePPuDn8jHEpDxu8cgtxKpyAJR4 Ju9dr1ZBjfHIKsrhdT7BFdj213eMneuODldfwlKnMWtl8G+pGvtU3jBx8ybAAV6O1Ht3 Bgj3y0BobY5vX1UN9uoefwJbzWqSmbvFOUgqVAlY3qOKbn/l3CJNnPK/9D/beYLqz2Ns 3KHg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=qLyQG7u5; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a9a9129121fsi151992266b.17.2024.10.20.13.19.09; Sun, 20 Oct 2024 13:19:09 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b=qLyQG7u5; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 37A9168DC25; Sun, 20 Oct 2024 23:09:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2804668DA3F for ; Sun, 20 Oct 2024 23:08:55 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454934; bh=y2yM8lBsYwl+kLdrCEI6jpvQGLX9bAuFjSUOfqnSt5A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qLyQG7u5LRWww3kml0VJjnPtpxvy9kBwgYXEKuFflfsdKzsWT0F7H94X3DlOGJ/ny /ETUl1m9PLm60PLIrksDuxY+G2ZmgUJ4AParzADCwVsAvslOqLJk32fARUzW2YjLxK r8ZUDBJvv6Vc+57dstmj6zP1VMjQW/nYZNs5Xguc= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id E14A64818D; Sun, 20 Oct 2024 22:08:54 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:12 +0200 Message-ID: <20241020200851.1414766-4-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 03/18] swscale: slightly reorder header 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: wAPP/36qv0d8 From: Niklas Haas I want to start grouping "legacy" functions which I tend to deprecate together, away from the new ones. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/swscale.h | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/libswscale/swscale.h b/libswscale/swscale.h index 2604eb1624..b5dea09bef 100644 --- a/libswscale/swscale.h +++ b/libswscale/swscale.h @@ -41,6 +41,8 @@ #include "version.h" #endif +typedef struct SwsContext SwsContext; + /** * @defgroup libsws libswscale * Color conversion and scaling library. @@ -61,6 +63,21 @@ const char *swscale_configuration(void); */ const char *swscale_license(void); +/** + * Get the AVClass for swsContext. It can be used in combination with + * AV_OPT_SEARCH_FAKE_OBJ for examining options. + * + * @see av_opt_find(). + */ +const AVClass *sws_get_class(void); + +/** + * Allocate an empty SwsContext. This must be filled and passed to + * sws_init_context(). For filling see AVOptions, options.c and + * sws_setColorspaceDetails(). + */ +SwsContext *sws_alloc_context(void); + /* values for the flags, the stuff on the command line is different */ #define SWS_FAST_BILINEAR 1 #define SWS_BILINEAR 2 @@ -150,8 +167,6 @@ typedef struct SwsFilter { SwsVector *chrV; } SwsFilter; -typedef struct SwsContext SwsContext; - /** * Return a positive value if pix_fmt is a supported input format, 0 * otherwise. @@ -171,13 +186,6 @@ int sws_isSupportedOutput(enum AVPixelFormat pix_fmt); */ int sws_isSupportedEndiannessConversion(enum AVPixelFormat pix_fmt); -/** - * Allocate an empty SwsContext. This must be filled and passed to - * sws_init_context(). For filling see AVOptions, options.c and - * sws_setColorspaceDetails(). - */ -SwsContext *sws_alloc_context(void); - /** * Initialize the swscaler context sws_context. * @@ -445,14 +453,6 @@ void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pix */ void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette); -/** - * Get the AVClass for swsContext. It can be used in combination with - * AV_OPT_SEARCH_FAKE_OBJ for examining options. - * - * @see av_opt_find(). - */ -const AVClass *sws_get_class(void); - /** * @} */ From patchwork Sun Oct 20 20:05:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52411 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2238865vqi; Sun, 20 Oct 2024 13:09:47 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVCYA8ux6k8R3Hlds8jufvAn8bolkN8wNkzOEJdnj/2PBy+DmX9R7dHNSdirE09akBrk6BlLYDxrHJddXBFbEZQ@gmail.com X-Google-Smtp-Source: AGHT+IFGpXwzxR6aGrYqzrINdaUaYuqd0kGcvxFoYh0SgOXWt99rUn51VGg3ErqOCyVHJjZ9wr/x X-Received: by 2002:a05:6402:35d6:b0:5c9:72c7:95a2 with SMTP id 4fb4d7f45d1cf-5ca0af9e2d7mr7613267a12.22.1729454987383; Sun, 20 Oct 2024 13:09:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729454987; cv=none; d=google.com; s=arc-20240605; b=knGNRviLb2BHUEkmRqdNKgZvRpNmzZYjePQ4f/8UmdK2YPgnK8io/G5qzPOUtMgr6k 7GWxi7OS9dIcwUNYc+bbeawCDJNDmdKdtQrMmboXgr8DxofQ10CJn5dIBVNTvF+aR+yW husTxTNX0K0ICNtbpMWmkZxxzsgmj6/g+U24VTkiYYY8hM8Y2MZHfxrGABE80Dv7bkbv SCN4uEO6zu13kM5nnP554LIp+bSVL8qJbqWh6XfsJwUMx+5j4SoGrOB2B8NhChZxsc7C 4ZqGyX//iEUVWxcQyB9Gn/lFPdgD+zgeRfAU/TlpeWJgE4dOzUn+KjprFI3KbNtTukL0 TYIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=xnh+rth6NEFM6ibyMd5i0UPXM8KGN5u8Ec+ryARv3qE=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=dYsn6fFdYPJGldlXgiILkr1umyGb1Vet7unsIvR6s6p29cmIMFg3hCEwTBfr9rJ2Cv nK7gBrfjtYRdyJrM5GhoiYaTMJLAKXIaoiRDlYcdJSiGuGy6kb9dD0eM1Aa7UVfpayYh FBvmvVBJXHtiu2XcNQDDYnPC0jHfkEDZyOOw9JpMH6OAS16DO9jQl6WRn5OeiXjKJSYW kG1emE0SMom8XGsfoURTlqG3DYrPlpKjudSODyHIYC9tdnbZthC7lrbAFWUlbAfKGpCE Hc0ouNASij2PkSSVPekdO+TDubz+TT99biZXjEvHNHmWoSRL0Ah6YQLM3eXj2cWMzmSO HEMg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=a50klP9v; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-5cb66e703c6si1537525a12.534.2024.10.20.13.09.47; Sun, 20 Oct 2024 13:09:47 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b=a50klP9v; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 72DEC68DC49; Sun, 20 Oct 2024 23:09:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6B6B168DA64 for ; Sun, 20 Oct 2024 23:08:55 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454935; bh=BsDX2EF6igbNN9VptF+766nb8O65vujb9ym1NIHrQrw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a50klP9vKLIrTluO89RjkI65wh0q928aRgWpkUrHwQ5gBXQhyc5oFAicVSITLuJgU 5M1MYd6xn4erzoBuNGVkTHBK7aiKlcCtB6XTpCv4j7Evu0uwJ0VPq5HYQg/RYdUuk3 sfcdeNkxAVB4/PvaIOXgPWSi7tI2Wgff6Mr182tM= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 2AF554845A; Sun, 20 Oct 2024 22:08:55 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:13 +0200 Message-ID: <20241020200851.1414766-5-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 04/18] swscale: add sws_free_context() 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 2yLh4VS2ejwq From: Niklas Haas Merely a convenience wrapper around sws_freeContext(). The name change is for parity with the other sws_* functions. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/swscale.h | 7 +++++++ libswscale/utils.c | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/libswscale/swscale.h b/libswscale/swscale.h index b5dea09bef..f9fd340240 100644 --- a/libswscale/swscale.h +++ b/libswscale/swscale.h @@ -1,4 +1,5 @@ /* + * Copyright (C) 2024 Niklas Haas * Copyright (C) 2001-2011 Michael Niedermayer * * This file is part of FFmpeg. @@ -78,6 +79,12 @@ const AVClass *sws_get_class(void); */ SwsContext *sws_alloc_context(void); +/** + * Free the context and everything associated with it, and write NULL + * to the provided pointer. + */ +void sws_free_context(SwsContext **ctx); + /* values for the flags, the stuff on the command line is different */ #define SWS_FAST_BILINEAR 1 #define SWS_BILINEAR 2 diff --git a/libswscale/utils.c b/libswscale/utils.c index 4b5106cb57..650785a989 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -2520,6 +2520,16 @@ void sws_freeContext(SwsContext *sws) av_free(sws); } +void sws_free_context(SwsContext **pctx) +{ + SwsContext *ctx = *pctx; + if (!ctx) + return; + + sws_freeContext(ctx); + *pctx = NULL; +} + SwsContext *sws_getCachedContext(SwsContext *sws, int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, From patchwork Sun Oct 20 20:05:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52426 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2294302vqi; Sun, 20 Oct 2024 16:09:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWbYChuJ0gzUo2gSfPck+lOqhi7LPUxlPK7AcwAe4g0UIdIvI98foU8nt8+d7weQACJUnt0/meGPz2ylANXo4+8@gmail.com X-Google-Smtp-Source: AGHT+IE7jbXrbHckRuinTQWDKgbl7zVyhWy7VOXWAGoY7gs+ajDffswNlWSuBb/rkSRWkluBdTog X-Received: by 2002:a2e:701:0:b0:2fb:3445:a4af with SMTP id 38308e7fff4ca-2fb82eb0637mr34344941fa.21.1729465743006; Sun, 20 Oct 2024 16:09:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729465742; cv=none; d=google.com; s=arc-20240605; b=b9bwmTYXZatUtIQzzoPxjQ7nC3DOxuBnKIPwR10tfoenFQ/MZi/TKTm42BF5xLXC5w C9uzl7zk6bGr76J7PyXTb6/S1QYbY1OT19P71SdlaSrF3WNfdgFP4lqHSs0H1ZY+603I zknu4n5ZIPMG6Nn1Zn+yXXWaY55470hBEDiz28dcgR4ru79NROfUONhG8GnZEAAden3g 3sVZyE1YoeETGFdodHxFa0aqNKYTA3Yu9q7H6+TR+UQuaRoN0TMLunr0XpFO0nr9G6k5 y0bc5VFoNs1xyM4LFVn5w3mCLnIrnN6mKRuZeDoyGsDHHwBuxyLgaPN+3jVtsnZ7u9pr nwLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=opDuRQkULgUc+Nt3BZ4cQ4PaST21aun8ycYEpzk1SqE=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=KvgCqeTa88hs4OflrOQIX1KYwXMwN/2EwpdcKo8wDL+TeYHYzWK3anoVRwPsRMuNwj a8xgsKz+5xvgrL3+It66/l05ZZe0U38tgynElb4no/mO8NH6pubBXfs1FX5aBd6zred/ TzkLlWCJYZmfjRxdfd39Ucv1ZAlGTIFHWlnwao3YJthIvv5sLghfpda5C/PmwwPgtrkV ff4+ISXG+e9faxKTJBKAgNqNTSrHi9kKtgGYF5p6d/Po9Opg3sLInUdek3AGoDQSkIhF ZccxpKHA9rg8QrWsTGk8fqqZDJUQxZhq/wpMvnMOw3VHvmpy/Ec+AssnlqLkJG4ZyWOc kStQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=TXM9ODty; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38308e7fff4ca-2fb9ae7d5fcsi6789991fa.407.2024.10.20.16.09.02; Sun, 20 Oct 2024 16:09:02 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b=TXM9ODty; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 642A568DC37; Sun, 20 Oct 2024 23:09:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 96F9668DBC1 for ; Sun, 20 Oct 2024 23:08:59 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454935; bh=l1Biv9oDRjjdWGSEIKWcDo6poiJ80BJRu9SvXS9QOzs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TXM9ODty2n0GrzeVyTXFOyrPvcjwoe4FWdPWmvINJ6yUNerh2Fnt/JXI1ipq48OHd DSvTruqg1i3b9biaoIYRASVnrUGcCaj66J+oGymS6dJ9pru6BQXcSUee0CSn4u5uMx PrlcHYP+xiwglv4s4u9S5+oOLADPAM65SQ/LGOS0= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 694D4434F2; Sun, 20 Oct 2024 22:08:55 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:14 +0200 Message-ID: <20241020200851.1414766-6-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 05/18] swscale/utils: add SwsFormat abstraction and helpers 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: lQ6rCQKVOeej From: Niklas Haas Groups together all relevant color metadata from an AVFrame. While we could use AVFrame directly, keeping it a separate struct has three advantages: 1. Functions accepting an SwsFormat will definitely not care about the data pointers. 2. It clearly separates sanitized and raw metadata, since the function to construct an SwsFormat from an AVFrame will also sanitize. 3. It's slightly more lightweight to pass around. Move these into a new header file "utils.h" to avoid crowding swscale_internal.h even more, and also to solve a circular dependency issue down the line. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/utils.c | 64 +++++++++++++++++++++++++++++++++++++++ libswscale/utils.h | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 libswscale/utils.h diff --git a/libswscale/utils.c b/libswscale/utils.c index 650785a989..af913eadab 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -1,4 +1,5 @@ /* + * Copyright (C) 2024 Niklas Haas * Copyright (C) 2001-2003 Michael Niedermayer * * This file is part of FFmpeg. @@ -59,6 +60,7 @@ #include "rgb2rgb.h" #include "swscale.h" #include "swscale_internal.h" +#include "utils.h" typedef struct FormatEntry { uint8_t is_supported_in :1; @@ -2653,3 +2655,65 @@ int ff_range_add(RangeList *rl, unsigned int start, unsigned int len) return 0; } + +/** + * This function also sanitizes and strips the input data, removing irrelevant + * fields for certain formats. + */ +SwsFormat ff_fmt_from_frame(const AVFrame *frame, int field) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); + SwsFormat fmt = { + .width = frame->width, + .height = frame->height, + .format = frame->format, + .range = frame->color_range, + .prim = frame->color_primaries, + .trc = frame->color_trc, + .csp = frame->colorspace, + .loc = frame->chroma_location, + .desc = desc, + }; + + av_assert1(fmt.width > 0); + av_assert1(fmt.height > 0); + av_assert1(fmt.format != AV_PIX_FMT_NONE); + av_assert0(desc); + if (desc->flags & (AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_PAL | AV_PIX_FMT_FLAG_BAYER)) { + /* RGB-like family */ + fmt.csp = AVCOL_SPC_RGB; + fmt.range = AVCOL_RANGE_JPEG; + } else if (desc->flags & AV_PIX_FMT_FLAG_XYZ) { + fmt.csp = AVCOL_SPC_UNSPECIFIED; + fmt.prim = AVCOL_PRI_SMPTE428; + fmt.trc = AVCOL_TRC_SMPTE428; + } else if (desc->nb_components < 3) { + /* Grayscale formats */ + fmt.prim = AVCOL_PRI_UNSPECIFIED; + fmt.csp = AVCOL_SPC_UNSPECIFIED; + if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) + fmt.range = AVCOL_RANGE_UNSPECIFIED; + else + fmt.range = AVCOL_RANGE_JPEG; // FIXME: this restriction should be lifted + } + + switch (frame->format) { + case AV_PIX_FMT_YUVJ420P: + case AV_PIX_FMT_YUVJ411P: + case AV_PIX_FMT_YUVJ422P: + case AV_PIX_FMT_YUVJ444P: + case AV_PIX_FMT_YUVJ440P: + fmt.range = AVCOL_RANGE_JPEG; + break; + } + + if (!desc->log2_chroma_w && !desc->log2_chroma_h) + fmt.loc = AVCHROMA_LOC_UNSPECIFIED; + + if (frame->flags & AV_FRAME_FLAG_INTERLACED) { + fmt.height = (fmt.height + (field == FIELD_TOP)) >> 1; + fmt.interlaced = 1; + } + + return fmt; +} diff --git a/libswscale/utils.h b/libswscale/utils.h new file mode 100644 index 0000000000..a210b646b0 --- /dev/null +++ b/libswscale/utils.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2024 Niklas Haas + * + * 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 + */ + +#ifndef SWSCALE_UTILS_H +#define SWSCALE_UTILS_H + +#include "libavutil/pixdesc.h" + +#include "swscale.h" + +enum { + FIELD_TOP, /* top/even rows, or progressive */ + FIELD_BOTTOM, /* bottom/odd rows */ +}; + +/* Subset of AVFrame parameters that uniquely determine pixel representation */ +typedef struct SwsFormat { + int width, height; + int interlaced; + enum AVPixelFormat format; + enum AVColorRange range; + enum AVColorPrimaries prim; + enum AVColorTransferCharacteristic trc; + enum AVColorSpace csp; + enum AVChromaLocation loc; + const AVPixFmtDescriptor *desc; /* convenience */ +} SwsFormat; + +/** + * This function also sanitizes and strips the input data, removing irrelevant + * fields for certain formats. + */ +SwsFormat ff_fmt_from_frame(const AVFrame *frame, int field); + +static inline int ff_fmt_equal(const SwsFormat *fmt1, const SwsFormat *fmt2) +{ + return fmt1->width == fmt2->width && + fmt1->height == fmt2->height && + fmt1->interlaced == fmt2->interlaced && + fmt1->format == fmt2->format && + fmt1->range == fmt2->range && + fmt1->prim == fmt2->prim && + fmt1->trc == fmt2->trc && + fmt1->csp == fmt2->csp && + fmt1->loc == fmt2->loc; +} + +static inline int ff_fmt_align(enum AVPixelFormat fmt) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt); + if (desc->flags & AV_PIX_FMT_FLAG_BAYER) { + return 2; + } else { + return 1 << desc->log2_chroma_h; + } +} + +#endif /* SWSCALE_UTILS_H */ From patchwork Sun Oct 20 20:05:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52424 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2271678vqi; Sun, 20 Oct 2024 14:59:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUhnAYPb+1EbMzKmRfwzUYZiQZwb1/aUnkIHOUV+DU96zqmqFnvrIm357maFCXUstO04oPETEWlA1ttcEWV+fzA@gmail.com X-Google-Smtp-Source: AGHT+IFpSLMFAt8X18v1yrhYL8DJ00IHeKT1OX6+8DnwZjAIQKPqOM13m/WI+c6UOhqdTkwtOlCN X-Received: by 2002:a05:6512:1244:b0:539:e9f8:d45d with SMTP id 2adb3069b0e04-53a154f9980mr4445538e87.52.1729461542930; Sun, 20 Oct 2024 14:59:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729461542; cv=none; d=google.com; s=arc-20240605; b=VEX5dgJKy+Y3aIvj5xvjeDfU+gwVu3BJ8bKAYlAp6yJE1mp1H11V1rarnp2LBqQUX0 2imoo3DWdK6ew7OL8w+/NvbCHCsJH0GW79hJpGZpMDdZ9X5sQEBUJqVkQnFhhLgrTFh0 cxI+iLJUQf0B0AJD8hIeZB0vbLdzfLN8Q/nLVOo/vkoDNfrPHVgKVnukvN6rpw/CVZJ0 sF4EUHt8zYtqONhV1dhmXaWeOGtMVUDX5NOZQ9hvqiYepmFoh733ORAw99matII3PEHJ JTr8mJ/QAEVmOtiObjzjHGQcuQ5Dp9VhpHm/eoFcT5N8RZOGwfA3DwnmZPxcnD+SjfDc tdYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=JBZU5n4kIHs2H0+ul3v5kgAqqxzUQR+SqNWWEkGClgg=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=dWzcf3/t+Ep61w0xN876i9DWsfQroJdLdOiL00wBIqPJkg4t6nWoLUv3LH1kM8HJCa zUwptUMeOALOHd4TWpiZgr+z63JnrMYyuWzclR8Blj6kM9PuJIU21vtIqJ3QLSgxFzHK EysSoOM1U1bBmVS2w/dZejkylcEn0JyVBA3VW5pAgvsK43SvbNGqlPJnznHdRlNg5rkw WBEMNdMWUVA9PZCbatxdBr1Dngio4ry/1lfpzDga2QyURXk5Sd5xXZIuerwOwXx+3lWu QHrqX1UnvjTBy6QYBoSP5kyk7igjsvUi9QS5J7PsZwNnTBU4B8pzOPOqQGEFNwkxB5yQ CZzw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b="g/74ZCKb"; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 2adb3069b0e04-53a2245a59esi727402e87.647.2024.10.20.14.59.02; Sun, 20 Oct 2024 14:59:02 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b="g/74ZCKb"; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6DE9A68DD37; Sun, 20 Oct 2024 23:09:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A6D3068DBA5 for ; Sun, 20 Oct 2024 23:08:59 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454935; bh=tzHM6pEftd5cckNgFZW48yrJQd6fehj7fHfs1Jar+nM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g/74ZCKbbY7oYRzBwIrunQ3d5MxbnM/51M99IaPJbFu6piwo1bYvtFKJVUf2XWTNi TvACHsXBwWeGzx753S+5/plGlOH9AyVNQZMvsg+pgAFwQNrqzO5oMIEMz3FCzSCjwS rH82iZf2VV1LLuNqZFaeEiBdwxD5npIcgqYoE3yo= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id A91AB4BE81; Sun, 20 Oct 2024 22:08:55 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:15 +0200 Message-ID: <20241020200851.1414766-7-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 06/18] swscale: add new frame testing API 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: RCaQYKngF2we From: Niklas Haas Replacing the old sws_isSupported* API with a more consistent family of functions that follows the same signature and naming convention, including a placeholder for testing the color space parameters that we don't currently implement conversions for. These functions also perform some extra basic sanity checking. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/swscale.h | 55 +++++++++++++++++++++++++++++++++++ libswscale/utils.c | 68 ++++++++++++++++++++++++++++++++++++++++++++ libswscale/utils.h | 2 ++ 3 files changed, 125 insertions(+) diff --git a/libswscale/swscale.h b/libswscale/swscale.h index f9fd340240..ba944cdc6f 100644 --- a/libswscale/swscale.h +++ b/libswscale/swscale.h @@ -85,6 +85,61 @@ SwsContext *sws_alloc_context(void); */ void sws_free_context(SwsContext **ctx); +/*************************** + * Supported frame formats * + ***************************/ + +/** + * Test if a given pixel format is supported. + * + * @param output If 0, test if compatible with the source/input frame; + * otherwise, with the destination/output frame. + * @param format The format to check. + * + * @return A positive integer if supported, 0 otherwise. + */ +int sws_test_format(enum AVPixelFormat format, int output); + +/** + * Test if a given color space is supported. + * + * @param output If 0, test if compatible with the source/input frame; + * otherwise, with the destination/output frame. + * @param colorspace The colorspace to check. + * + * @return A positive integer if supported, 0 otherwise. + */ +int sws_test_colorspace(enum AVColorSpace colorspace, int output); + +/** + * Test if a given set of color primaries is supported. + * + * @param output If 0, test if compatible with the source/input frame; + * otherwise, with the destination/output frame. + * @param primaries The color primaries to check. + * + * @return A positive integer if supported, 0 otherwise. + */ +int sws_test_primaries(enum AVColorPrimaries primaries, int output); + +/** + * Test if a given color transfer function is supported. + * + * @param output If 0, test if compatible with the source/input frame; + * otherwise, with the destination/output frame. + * @param trc The color transfer function to check. + * + * @return A positive integer if supported, 0 otherwise. + */ +int sws_test_transfer(enum AVColorTransferCharacteristic trc, int output); + +/** + * Helper function to run all sws_test_* against a frame, as well as testing + * the basic frame properties for sanity. Ignores irrelevant properties - for + * example, AVColorSpace is not checked for RGB frames. + */ +int sws_test_frame(const AVFrame *frame, int output); + /* values for the flags, the stuff on the command line is different */ #define SWS_FAST_BILINEAR 1 #define SWS_BILINEAR 2 diff --git a/libswscale/utils.c b/libswscale/utils.c index af913eadab..5339bbe099 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -2717,3 +2717,71 @@ SwsFormat ff_fmt_from_frame(const AVFrame *frame, int field) return fmt; } + +int sws_test_format(enum AVPixelFormat format, int output) +{ + return output ? sws_isSupportedOutput(format) : sws_isSupportedInput(format); +} + +int sws_test_colorspace(enum AVColorSpace csp, int output) +{ + switch (csp) { + case AVCOL_SPC_UNSPECIFIED: + case AVCOL_SPC_RGB: + case AVCOL_SPC_BT709: + case AVCOL_SPC_BT470BG: + case AVCOL_SPC_SMPTE170M: + case AVCOL_SPC_FCC: + case AVCOL_SPC_SMPTE240M: + case AVCOL_SPC_BT2020_NCL: + return 1; + default: + return 0; + } +} + +int sws_test_primaries(enum AVColorPrimaries prim, int output) +{ + return prim > AVCOL_PRI_RESERVED0 && prim < AVCOL_PRI_NB && + prim != AVCOL_PRI_RESERVED; +} + +int sws_test_transfer(enum AVColorTransferCharacteristic trc, int output) +{ + return trc > AVCOL_TRC_RESERVED0 && trc < AVCOL_TRC_NB && + trc != AVCOL_TRC_RESERVED; +} + +static int test_range(enum AVColorRange range) +{ + return range >= 0 && range < AVCOL_RANGE_NB; +} + +static int test_loc(enum AVChromaLocation loc) +{ + return loc >= 0 && loc < AVCHROMA_LOC_NB; +} + +int ff_test_fmt(const SwsFormat *fmt, int output) +{ + return fmt->width > 0 && fmt->height > 0 && + sws_test_format (fmt->format, output) && + sws_test_colorspace(fmt->csp, output) && + sws_test_primaries (fmt->prim, output) && + sws_test_transfer (fmt->trc, output) && + test_range (fmt->range) && + test_loc (fmt->loc); +} + +int sws_test_frame(const AVFrame *frame, int output) +{ + for (int field = 0; field < 2; field++) { + const SwsFormat fmt = ff_fmt_from_frame(frame, field); + if (!ff_test_fmt(&fmt, output)) + return 0; + if (!fmt.interlaced) + break; + } + + return 1; +} diff --git a/libswscale/utils.h b/libswscale/utils.h index a210b646b0..4d204ef6cc 100644 --- a/libswscale/utils.h +++ b/libswscale/utils.h @@ -72,4 +72,6 @@ static inline int ff_fmt_align(enum AVPixelFormat fmt) } } +int ff_test_fmt(const SwsFormat *fmt, int output); + #endif /* SWSCALE_UTILS_H */ From patchwork Sun Oct 20 20:05:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52415 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2244957vqi; Sun, 20 Oct 2024 13:29:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVZD3QBE+HAa308INpnqqZrZejWDKRGTg4W2IBaVOCdnV+fu5yxGJv4GdBBmHikNuJc2Tfj+gaNhU/VOSug48Sv@gmail.com X-Google-Smtp-Source: AGHT+IFfGBZnBR8rqm5J7muLRtOawUa95yrz/Zx6gNrJzVsCo5u59VqLDcRIzmCxJG+TKuXGJ40q X-Received: by 2002:a05:651c:2222:b0:2fb:591d:3de1 with SMTP id 38308e7fff4ca-2fb831f193bmr13462721fa.7.1729456145254; Sun, 20 Oct 2024 13:29:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729456145; cv=none; d=google.com; s=arc-20240605; b=hdI7piHShzj9kWdXcnG7ny6K4cmf/izApBky8FA7zR2hHW08mbgPYqYugD4aN1+dnD ieUfWTuhJekZ4KPWFL0HBuww2UKS6qp2o/SCvQI2aIQaUh2uMluc9ww1cBs0jzN9tWYD qod+LLYzB9oE9JYuYlpkVLKaXcYeX0fxoFqWqxq8mOXNqc13AOUgW8mLIq+R6vLkwGYs VqltdtV32qaAa3FjrXMwDrC3XF8+226EJCXMUXGp7s0O/IEfmTfOl5NT/d02zG/VwyzR 3S3wCGjCYWIFKI71NJN45pmK2gWiM5ahK31/8USaAvHINpLdcxpsS5/u5eNzrzmm34XR 51Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=YiJ4aVEpdU+zKzPJWYVzfCL0ZXARfkYQeFz1d/LJHbc=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=H4h1vwyyIujNHyEWpEnxdq/yuDBGayX5pFocwSUPU/rsE4i62oEdtJDxW4E1j/1Foo J+qac4u/KcI8c6pRwU9P4BaifXNAJKjIMSDJMrt/Xjaq+6U54F18CgeqMdcKRMn+t+/Y h4qrItuBIRlAfS5RH6vO8s5RKI5uCADfuk4VHNOZCmddcZ6DLUde70g5SMlIiVYhVQXQ qS+JFH5F3ZOefhxllxsifvwVY78CTOLnDuLCy5NDcoBA99XWo30ykkJgqmQArDbrQh7w gu7NV1ORoJZfNICAWSdh7oKB027r+dSKEq0Z5hTEStDJ21Wg5HjK+4g+SpXNY+aTw2Da 7gJw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=JayNHPF3; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 2adb3069b0e04-53a2243491csi725881e87.363.2024.10.20.13.29.04; Sun, 20 Oct 2024 13:29:05 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b=JayNHPF3; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 92F8968DA89; Sun, 20 Oct 2024 23:09:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C6A4468DBEE for ; Sun, 20 Oct 2024 23:08:59 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454935; bh=p4X3/6nqQHX+07QLRfvKy3afNVZnOmCynd2fowAVJ48=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JayNHPF3NJxI7WoJJTZd27gRYlQWg31n46EHnPvQrWcxDWL+fp0+k4FPgRqpyRT+S OT/HpUKU3fZgraemsCi42fYLSObbrgYTjTvb0/29JojMB3J3HcmYm+p2byFID99dPv 75laaFa3QyNjFWiMwQxvU+qAdhn5fP2VTFev9XBA= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id E53014BE84; Sun, 20 Oct 2024 22:08:55 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:16 +0200 Message-ID: <20241020200851.1414766-8-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 07/18] swscale: add sws_is_noop() 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: JDxbSt0A/ie/ From: Niklas Haas Exactly what it says on the tin. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/swscale.h | 6 ++++++ libswscale/utils.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/libswscale/swscale.h b/libswscale/swscale.h index ba944cdc6f..f544387769 100644 --- a/libswscale/swscale.h +++ b/libswscale/swscale.h @@ -140,6 +140,12 @@ int sws_test_transfer(enum AVColorTransferCharacteristic trc, int output); */ int sws_test_frame(const AVFrame *frame, int output); +/** + * Check if a given conversion is a noop. Returns a positive integer if + * no operation needs to be performed, 0 otherwise. + */ +int sws_is_noop(const AVFrame *dst, const AVFrame *src); + /* values for the flags, the stuff on the command line is different */ #define SWS_FAST_BILINEAR 1 #define SWS_BILINEAR 2 diff --git a/libswscale/utils.c b/libswscale/utils.c index 5339bbe099..5dff3c5476 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -2785,3 +2785,17 @@ int sws_test_frame(const AVFrame *frame, int output) return 1; } + +int sws_is_noop(const AVFrame *dst, const AVFrame *src) +{ + for (int field = 0; field < 2; field++) { + SwsFormat dst_fmt = ff_fmt_from_frame(dst, field); + SwsFormat src_fmt = ff_fmt_from_frame(src, field); + if (!ff_fmt_equal(&dst_fmt, &src_fmt)) + return 0; + if (!dst_fmt.interlaced) + break; + } + + return 1; +} From patchwork Sun Oct 20 20:05:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52409 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2241958vqi; Sun, 20 Oct 2024 13:19:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUnjIQ7qpGjVB1oO1T9PpGT3RBK2pbnD57zTqreFyKUbAO1fyH1VfXBzvPSOoCNAXoIwnifrpQPf2YSC4WTN6gG@gmail.com X-Google-Smtp-Source: AGHT+IEL6udgc/lzic0wMjpgRHNrl5BJ9scQDfk17EmsbKg6TP7I5H6Cb04tIDF+5KvHQ+qyxYQe X-Received: by 2002:a17:907:6e94:b0:a99:ee42:1f38 with SMTP id a640c23a62f3a-a9a69bab545mr954892166b.31.1729455544999; Sun, 20 Oct 2024 13:19:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729455544; cv=none; d=google.com; s=arc-20240605; b=LP2tXGyxSaQ+z57nV2gQJo7rNDGWTIOi/IURFrpVWHathEw+U1KR8nj6v/V5yvJSvX fj/0XsBHI73NHyJunKtER3lnOvMisfvwJrz/DP4he5tJ75MBUXTc1CZ9u6MiyY5gEAoF WYpL9P+QxjYuzp95TQhQxpm5e+0W3oSK5zLUlU1VZXGRDQACJsvKopjWGyjaJQ5GuBXy asws2/s0yXGUEpgAhIyp0jEjtBOqrQeTqIuaj43uwTr6gGHjPVS9m4z4Y8hWEcjQhemN 77zNFILzpAn42JOiuiOnPfFwYGy2SSmYw1+t/wwqZozFCp/6/rS6aTELvFxs9HRURnlG CYpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=BtlX/TbUn090N4vjaTMgRB75TeCUfx/iPRGkcyqQrH4=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=M5D4xjTp3BpWF/gRXXhTKVjcVCCl8vRCw9gARInWgZm6NQz3uas4U6jSoFFAiJg0yX 9+LRdyJ3V2wgWvULpvkdVeVp0mdO02vvEYQLrblNNJDHwbM3lwsohktn6qp+eatiX2LH eZ28KIlSQ/vUZ0XQGZf+RCt/jGa1ZjfjLg/TCWV48f7pRxFeKjMUnnJOOvdQxoTyRDJo BYlWCnnR/QEeSre6uU7/PAtifQZvzq0JJOELcf7RNcrlwL496Bsc17knA+xjDY4iCBjk 5EK+oBuErAbn+g7zXlzJEENg1amlRjJ0Hydx7IEGMTPZibl3WDVBYtluZbxqVz7c3TIp jhlA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=jHtyY2fr; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a9a91559b54si156724066b.714.2024.10.20.13.19.04; Sun, 20 Oct 2024 13:19:04 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b=jHtyY2fr; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9020368DD5F; Sun, 20 Oct 2024 23:09:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BB3CE68DBE8 for ; Sun, 20 Oct 2024 23:08:59 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454936; bh=v0o9PLYlpcbgjZcNCudik2TKUMsGZ/amgqvwXjoHUfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jHtyY2frgK8D3PEGGTEQgO12n1EFZztRkgHBpiJ5GwMnSIWNRcAMZ11dDGfJ2mqhW 5TiniQVE+Bfzg/cuT7RQE+T1eAGLggYyzqvNjUfSETD+kq6RGdbGEsMeh7z6slkqZT upsw0T48pWIN4whrpeApD2m3PGx5j6b8lYc/hg30= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 308224BE85; Sun, 20 Oct 2024 22:08:56 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:17 +0200 Message-ID: <20241020200851.1414766-9-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 08/18] swscale/options: cosmetic changes 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: s8DvzKMg5GFZ From: Niklas Haas Reorganize the list, fix whitespace, make indentation consistent, and rename some descriptions for clarity, consistency or informativeness. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/options.c | 86 ++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/libswscale/options.c b/libswscale/options.c index 56b1d2235d..e64e289cf3 100644 --- a/libswscale/options.c +++ b/libswscale/options.c @@ -32,55 +32,57 @@ static const char *sws_context_to_name(void *ptr) #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM static const AVOption swscale_options[] = { - { "sws_flags", "scaler flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, { .i64 = SWS_BICUBIC }, 0, UINT_MAX, VE, .unit = "sws_flags" }, - { "fast_bilinear", "fast bilinear", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_FAST_BILINEAR }, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, - { "bilinear", "bilinear", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_BILINEAR }, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, - { "bicubic", "bicubic", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_BICUBIC }, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, - { "experimental", "experimental", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_X }, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, - { "neighbor", "nearest neighbor", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_POINT }, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, - { "area", "averaging area", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_AREA }, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, - { "bicublin", "luma bicubic, chroma bilinear", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_BICUBLIN }, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, - { "gauss", "Gaussian", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_GAUSS }, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, - { "sinc", "sinc", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_SINC }, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, - { "lanczos", "Lanczos", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_LANCZOS }, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, - { "spline", "natural bicubic spline", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_SPLINE }, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, - { "print_info", "print info", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_PRINT_INFO }, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, - { "accurate_rnd", "accurate rounding", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ACCURATE_RND }, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, - { "full_chroma_int", "full chroma interpolation", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_FULL_CHR_H_INT }, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, - { "full_chroma_inp", "full chroma input", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_FULL_CHR_H_INP }, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, - { "bitexact", "", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_BITEXACT }, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, - { "error_diffusion", "error diffusion dither", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ERROR_DIFFUSION}, INT_MIN, INT_MAX, VE, .unit = "sws_flags" }, + { "sws_flags", "swscale flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, { .i64 = SWS_BICUBIC }, .flags = VE, .unit = "sws_flags", .max = UINT_MAX }, + { "fast_bilinear", "fast bilinear", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_FAST_BILINEAR }, .flags = VE, .unit = "sws_flags" }, + { "bilinear", "bilinear", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_BILINEAR }, .flags = VE, .unit = "sws_flags" }, + { "bicubic", "bicubic", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_BICUBIC }, .flags = VE, .unit = "sws_flags" }, + { "experimental", "experimental", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_X }, .flags = VE, .unit = "sws_flags" }, + { "neighbor", "nearest neighbor", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_POINT }, .flags = VE, .unit = "sws_flags" }, + { "area", "averaging area", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_AREA }, .flags = VE, .unit = "sws_flags" }, + { "bicublin", "luma bicubic, chroma bilinear", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_BICUBLIN }, .flags = VE, .unit = "sws_flags" }, + { "gauss", "gaussian approximation", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_GAUSS }, .flags = VE, .unit = "sws_flags" }, + { "sinc", "sinc", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_SINC }, .flags = VE, .unit = "sws_flags" }, + { "lanczos", "lanczos (sinc/sinc)", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_LANCZOS }, .flags = VE, .unit = "sws_flags" }, + { "spline", "natural bicubic spline", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_SPLINE }, .flags = VE, .unit = "sws_flags" }, + { "print_info", "print info", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_PRINT_INFO }, .flags = VE, .unit = "sws_flags" }, + { "accurate_rnd", "accurate rounding", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ACCURATE_RND }, .flags = VE, .unit = "sws_flags" }, + { "full_chroma_int", "full chroma interpolation", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_FULL_CHR_H_INT }, .flags = VE, .unit = "sws_flags" }, + { "full_chroma_inp", "full chroma input", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_FULL_CHR_H_INP }, .flags = VE, .unit = "sws_flags" }, + { "bitexact", "bit-exact mode", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_BITEXACT }, .flags = VE, .unit = "sws_flags" }, + { "error_diffusion", "error diffusion dither", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ERROR_DIFFUSION}, .flags = VE, .unit = "sws_flags" }, - { "srcw", "source width", OFFSET(srcW), AV_OPT_TYPE_INT, { .i64 = 16 }, 1, INT_MAX, VE }, - { "srch", "source height", OFFSET(srcH), AV_OPT_TYPE_INT, { .i64 = 16 }, 1, INT_MAX, VE }, - { "dstw", "destination width", OFFSET(dstW), AV_OPT_TYPE_INT, { .i64 = 16 }, 1, INT_MAX, VE }, - { "dsth", "destination height", OFFSET(dstH), AV_OPT_TYPE_INT, { .i64 = 16 }, 1, INT_MAX, VE }, + { "param0", "scaler param 0", OFFSET(param[0]), AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT }, INT_MIN, INT_MAX, VE }, + { "param1", "scaler param 1", OFFSET(param[1]), AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT }, INT_MIN, INT_MAX, VE }, + + { "srcw", "source width", OFFSET(srcW), AV_OPT_TYPE_INT, { .i64 = 16 }, 1, INT_MAX, VE }, + { "srch", "source height", OFFSET(srcH), AV_OPT_TYPE_INT, { .i64 = 16 }, 1, INT_MAX, VE }, + { "dstw", "destination width", OFFSET(dstW), AV_OPT_TYPE_INT, { .i64 = 16 }, 1, INT_MAX, VE }, + { "dsth", "destination height", OFFSET(dstH), AV_OPT_TYPE_INT, { .i64 = 16 }, 1, INT_MAX, VE }, { "src_format", "source format", OFFSET(srcFormat), AV_OPT_TYPE_PIXEL_FMT,{ .i64 = DEFAULT }, 0, INT_MAX, VE }, { "dst_format", "destination format", OFFSET(dstFormat), AV_OPT_TYPE_PIXEL_FMT,{ .i64 = DEFAULT }, 0, INT_MAX, VE }, - { "src_range", "source is full range", OFFSET(srcRange), AV_OPT_TYPE_BOOL, { .i64 = DEFAULT }, 0, 1, VE }, - { "dst_range", "destination is full range", OFFSET(dstRange), AV_OPT_TYPE_BOOL, { .i64 = DEFAULT }, 0, 1, VE }, - { "param0", "scaler param 0", OFFSET(param[0]), AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT }, INT_MIN, INT_MAX, VE }, - { "param1", "scaler param 1", OFFSET(param[1]), AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT }, INT_MIN, INT_MAX, VE }, + { "src_range", "source is full range", OFFSET(srcRange), AV_OPT_TYPE_BOOL, { .i64 = DEFAULT }, 0, 1, VE }, + { "dst_range", "destination is full range", OFFSET(dstRange), AV_OPT_TYPE_BOOL, { .i64 = DEFAULT }, 0, 1, VE }, + { "gamma", "gamma correct scaling", OFFSET(gamma_flag),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, + + { "src_v_chr_pos", "source vertical chroma position in luma grid/256" , OFFSET(src_v_chr_pos), AV_OPT_TYPE_INT, { .i64 = -513 }, -513, 1024, VE }, + { "src_h_chr_pos", "source horizontal chroma position in luma grid/256", OFFSET(src_h_chr_pos), AV_OPT_TYPE_INT, { .i64 = -513 }, -513, 1024, VE }, + { "dst_v_chr_pos", "destination vertical chroma position in luma grid/256" , OFFSET(dst_v_chr_pos), AV_OPT_TYPE_INT, { .i64 = -513 }, -513, 1024, VE }, + { "dst_h_chr_pos", "destination horizontal chroma position in luma grid/256", OFFSET(dst_h_chr_pos), AV_OPT_TYPE_INT, { .i64 = -513 }, -513, 1024, VE }, - { "src_v_chr_pos", "source vertical chroma position in luma grid/256" , OFFSET(src_v_chr_pos), AV_OPT_TYPE_INT, { .i64 = -513 }, -513, 1024, VE }, - { "src_h_chr_pos", "source horizontal chroma position in luma grid/256", OFFSET(src_h_chr_pos), AV_OPT_TYPE_INT, { .i64 = -513 }, -513, 1024, VE }, - { "dst_v_chr_pos", "destination vertical chroma position in luma grid/256" , OFFSET(dst_v_chr_pos), AV_OPT_TYPE_INT, { .i64 = -513 }, -513, 1024, VE }, - { "dst_h_chr_pos", "destination horizontal chroma position in luma grid/256", OFFSET(dst_h_chr_pos), AV_OPT_TYPE_INT, { .i64 = -513 }, -513, 1024, VE }, + { "sws_dither", "set dithering algorithm", OFFSET(dither), AV_OPT_TYPE_INT, { .i64 = SWS_DITHER_AUTO }, .flags = VE, .unit = "sws_dither", .max = SWS_DITHER_NB - 1 }, + { "auto", "automatic selection", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_DITHER_AUTO }, .flags = VE, .unit = "sws_dither" }, + { "bayer", "ordered matrix dither", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_DITHER_BAYER }, .flags = VE, .unit = "sws_dither" }, + { "ed", "full error diffusion", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_DITHER_ED }, .flags = VE, .unit = "sws_dither" }, + { "a_dither", "arithmetic addition dither", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_DITHER_A_DITHER }, .flags = VE, .unit = "sws_dither" }, + { "x_dither", "arithmetic xor dither", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_DITHER_X_DITHER }, .flags = VE, .unit = "sws_dither" }, - { "sws_dither", "set dithering algorithm", OFFSET(dither), AV_OPT_TYPE_INT, { .i64 = SWS_DITHER_AUTO }, 0, SWS_DITHER_NB, VE, .unit = "sws_dither" }, - { "auto", "leave choice to sws", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_DITHER_AUTO }, INT_MIN, INT_MAX, VE, .unit = "sws_dither" }, - { "bayer", "bayer dither", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_DITHER_BAYER }, INT_MIN, INT_MAX, VE, .unit = "sws_dither" }, - { "ed", "error diffusion", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_DITHER_ED }, INT_MIN, INT_MAX, VE, .unit = "sws_dither" }, - { "a_dither", "arithmetic addition dither", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_DITHER_A_DITHER}, INT_MIN, INT_MAX, VE, .unit = "sws_dither" }, - { "x_dither", "arithmetic xor dither", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_DITHER_X_DITHER}, INT_MIN, INT_MAX, VE, .unit = "sws_dither" }, - { "gamma", "gamma correct scaling", OFFSET(gamma_flag),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, - { "alphablend", "mode for alpha -> non alpha", OFFSET(alphablend),AV_OPT_TYPE_INT, { .i64 = SWS_ALPHA_BLEND_NONE}, 0, SWS_ALPHA_BLEND_NB-1, VE, .unit = "alphablend" }, - { "none", "ignore alpha", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ALPHA_BLEND_NONE}, INT_MIN, INT_MAX, VE, .unit = "alphablend" }, - { "uniform_color", "blend onto a uniform color", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ALPHA_BLEND_UNIFORM},INT_MIN, INT_MAX, VE, .unit = "alphablend" }, - { "checkerboard", "blend onto a checkerboard", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ALPHA_BLEND_CHECKERBOARD},INT_MIN, INT_MAX, VE, .unit = "alphablend" }, + { "alphablend", "mode for alpha -> non alpha", OFFSET(alphablend), AV_OPT_TYPE_INT, { .i64 = SWS_ALPHA_BLEND_NONE}, .flags = VE, .unit = "alphablend", .max = SWS_ALPHA_BLEND_NB - 1 }, + { "none", "ignore alpha", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ALPHA_BLEND_NONE}, .flags = VE, .unit = "alphablend" }, + { "uniform_color", "blend onto a uniform color", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ALPHA_BLEND_UNIFORM}, .flags = VE, .unit = "alphablend" }, + { "checkerboard", "blend onto a checkerboard", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ALPHA_BLEND_CHECKERBOARD}, .flags = VE, .unit = "alphablend" }, { "threads", "number of threads", OFFSET(nb_threads), AV_OPT_TYPE_INT, {.i64 = 1 }, 0, INT_MAX, VE, .unit = "threads" }, - { "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, .flags = VE, .unit = "threads" }, + { "auto", "automatic selection", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, .flags = VE, .unit = "threads" }, { NULL } }; From patchwork Sun Oct 20 20:05:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52414 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2241994vqi; Sun, 20 Oct 2024 13:19:12 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWFH9fcziobtN4vfo1oH3DfU57ITNmsd8efPUZm3Bqe/fIgLhNVnzB9Udz2Ko4EiXRl9HutWo05pnKVcC/FTON9@gmail.com X-Google-Smtp-Source: AGHT+IG9oCPPA5Q6kHMFK/wJMcrGjNyde7t87gAeQvkzwVCyNK9gniqXXa2p4zH6/yDrSVqQq1yq X-Received: by 2002:a05:600c:3b9c:b0:42c:b9c8:2b95 with SMTP id 5b1f17b1804b1-4316168fec8mr29746045e9.6.1729455551511; Sun, 20 Oct 2024 13:19:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729455551; cv=none; d=google.com; s=arc-20240605; b=T2QxPWxjfqMF/0bAs3gnf+/VSiQCClCGMsuA36P1hl4JnyoXTmzk223UW7/WVBROz6 lABBhWqlQJT2VNp3Ua4xaqa9cPvkrQ6iIBy+068MxbF1IuPdUp9c19ZfX3JQasdwxYqy hnSTL4qVU0yQ/6gqt62Us/CVBK73YtPM26Xmd1IfaQ8I1YS/HFWhLKRw2uevrF5/J3ud /TniATUQfJ3Q1e7zyauLAaW9sSLOv/KqC/NOhjz5k8vtoZ3YAkbTcN+FL3hGss4mIUZr jyufKxctlOoJXSRrMm+JsG4NaN3jMeheVQUx7/7Cn5bTdCBuN2BYE38hxenGFakGQkQb GXVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=/xuXJjz54IDlApjAgIVqg1B5+Cnm20F43y0eJ08Z/tw=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=NjwvCb7yHXjTDWOE0A1o+PrVRB4ouOGhI04tKA+DMPJGdXOUl1jPPz22+x5Kwl0Zmz wWu4yHSn7AQXbohbm90X7bfoAg7m4Ox/7kPVsvNC59bSrDmnK5XFaBh6+sJrOMqetCee 4cwUhBac7wBJfvygmW1Zg8lWq926oTHZWPTG4V+255j6BvQ2xuhusC4J7bpUwhnf0BrT iuE2HainJtqGFKVjEgarNZ3qS1W9NaTYBOSQV0A7S4HAVV7T3coeTP6KBIKPQOd37rqR LrpMaRSyoGYTkEVjIwNRts0CyCat8omCVVyJI1I8JAxppvmKWrb766pk/qpogrWnvhtu YFzA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=hEeWiYUm; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-5cb66e70f59si1550531a12.611.2024.10.20.13.19.11; Sun, 20 Oct 2024 13:19:11 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b=hEeWiYUm; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B70E568DD86; Sun, 20 Oct 2024 23:09:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4F54E68DC29 for ; Sun, 20 Oct 2024 23:09:00 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454936; bh=ElqGUZhMrwOEStFi9iSCjeHlfoYrBXaCOi+0dWO285Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hEeWiYUmmKnCZy9znig2/Y5WdVGwjoOiCkpLod1lupgZuDgFF1hDKytTeqvvaWKqQ vzIKldoS+k182B6DI2SfmdqFQuycJuhOWWQfJsyf9C9P05FPpkAsQrVMkfJpUgL0Fb HoTrK4YTFdU7VX11pXN5JT5dlTFfXwJXT5shUw10= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 73E994BE87; Sun, 20 Oct 2024 22:08:56 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:18 +0200 Message-ID: <20241020200851.1414766-10-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 09/18] swscale/internal: use static_assert for enforcing offsets 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: UNh4xSAK11yL From: Niklas Haas Instead of sprinkling av_assert0 into random init functions. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/swscale_internal.h | 11 +++++++++++ libswscale/utils.c | 2 -- libswscale/x86/swscale.c | 4 ---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index 1817815b01..5b92c3f72a 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -22,6 +22,7 @@ #define SWSCALE_SWSCALE_INTERNAL_H #include +#include #include "config.h" #include "swscale.h" @@ -704,6 +705,16 @@ struct SwsInternal { }; //FIXME check init (where 0) +static_assert(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInternal, dither32), + "dither32 must be at the same offset as redDither + DITHER32_INT"); + +#if ARCH_X86_64 +/* x86 yuv2gbrp uses the SwsInternal for yuv coefficients + if struct offsets change the asm needs to be updated too */ +static_assert(offsetof(SwsInternal, yuv2rgb_y_offset) == 40292, + "yuv2rgb_y_offset must be updated in x86 asm"); +#endif + SwsFunc ff_yuv2rgb_get_func_ptr(SwsInternal *c); int ff_yuv2rgb_c_init_tables(SwsInternal *c, const int inv_table[4], int fullRange, int brightness, diff --git a/libswscale/utils.c b/libswscale/utils.c index 5dff3c5476..3ce9a92504 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -1233,8 +1233,6 @@ SwsContext *sws_alloc_context(void) { SwsInternal *c = av_mallocz(sizeof(SwsInternal)); - av_assert0(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInternal, dither32)); - if (c) { c->av_class = &ff_sws_context_class; av_opt_set_defaults(c); diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c index 16182124c0..48f0aea3f2 100644 --- a/libswscale/x86/swscale.c +++ b/libswscale/x86/swscale.c @@ -792,10 +792,6 @@ switch(c->dstBpc){ \ if(c->flags & SWS_FULL_CHR_H_INT) { - /* yuv2gbrp uses the SwsInternal for yuv coefficients - if struct offsets change the asm needs to be updated too */ - av_assert0(offsetof(SwsInternal, yuv2rgb_y_offset) == 40292); - #define YUV2ANYX_FUNC_CASE(fmt, name, opt) \ case fmt: \ c->yuv2anyX = ff_yuv2##name##_full_X_##opt; \ From patchwork Sun Oct 20 20:05:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52417 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2246489vqi; Sun, 20 Oct 2024 13:34:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWlWsQG5+wu1rjLQHpEFnOmub75Kuk76MpVnPsrJZ4ESM4zLhCv/BXjiFvqqXqbx/2qNLl3juTBYIJ8/IrFMF5+@gmail.com X-Google-Smtp-Source: AGHT+IHFPfN4ptymxnowGWvHboEMOp4VnApspY7ODdlUBdFvjKe4v1xC1i6tC1XaHEB83ex2rEGt X-Received: by 2002:a17:906:a28a:b0:a9a:8216:2f4d with SMTP id a640c23a62f3a-a9a8216326fmr234040866b.3.1729456446178; Sun, 20 Oct 2024 13:34:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729456446; cv=none; d=google.com; s=arc-20240605; b=TknDcj9ydhZIWODNTkq//yqzv65u97aWy9EuzGHb4v2FlLeV7WXDCHut4//jxEIG8Z 0/K7/p8eUr1keL/muH5+wwbymtUhS8Wzd7rm/IccYjZ59mMiI+LG1zC/f179IdRpvYQx fuMhYwsvmhZ+k0ThgMRj6G833SgDqGYNbH/upfUdB2SRrs9BjQT6Rj2/AkzZUNO2vyrY M5OTrIZ+FQUu+Et6EWDf5F5vpyqy6SYrEcFXOwU0ULpUWcxEubewIi+czH4d7pwvRUWT 1klaH7oMIsAF23AolPVsO1tsazQbau/qfPEbXkzURGhFrJ25AvAWbGieCb3cpoypTqtx XoRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=Li8gOJFE63knzY3g3YLWLq8SZehCuTENiy1qpyrCv+Q=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=F3p3HosfkdflHhM0TS5gQmBLsuc8yA27CfYDamquZJqTnQ/exqfsgim4hdA1UF+w4K VixqFLgiggVfgvmLpaygDB9Fuu+Rlld97t/rKRHWhueJxe5bl1LlHXsHvhyKCB3ZCMpU zTFuiEsddv7dGxpQ/qbQ+8H6tpqeGZttEqGdTyBQutMPoSydpHGsXk3N3LN5YBdYfI9c XLoL5t0NGU51TUfccqDDkNphMHwKBAXvwAActs4GJG/7rE8M1dtdLcISjpWOTK5UpB2F afsya1nPo6GIizLktTZNqLniy7qHEIJYwiOpfH9KuQRQ+JHpnNelOoJG8KENfkwpw0DY CNXA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=ZOBJbiyX; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a9a9157597dsi156115166b.950.2024.10.20.13.34.05; Sun, 20 Oct 2024 13:34:06 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b=ZOBJbiyX; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F131268DD9B; Sun, 20 Oct 2024 23:09:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5F0B968DC3F for ; Sun, 20 Oct 2024 23:09:00 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454936; bh=hoG+IjZmKVR74cLy8XcKi3Eaaqa15OC4lrgFLL6gzVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZOBJbiyX1a9MM0JnmZfRWlKrMYYSzHJiXnfkjy7Iw1rpA6bdIymPZ0eWRXO0b6ddH DUr6p8Ab928PEOIab/5uaOFr5IGJfnFGiMhAKrMz0YeAG84J0YJsbQzMKgWc8hmK7p XZdB5CmQz7TB0OVoUTZBCSElfQRTy083z3SWmmmI= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id B34614BE89; Sun, 20 Oct 2024 22:08:56 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:19 +0200 Message-ID: <20241020200851.1414766-11-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 10/18] swscale/x86: use dedicated int for self-modifying MMX dstW 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ZcfbEEc3YPl4 From: Niklas Haas I want to pull options out of SwsInternal, so we need to make this field a dedicated int that gets updated as appropriate in ff_swscale(). Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/swscale.c | 1 + libswscale/swscale_internal.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libswscale/swscale.c b/libswscale/swscale.c index c368c68fea..e0a9e0279f 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -488,6 +488,7 @@ int ff_swscale(SwsInternal *c, const uint8_t *const src[], const int srcStride[] #if HAVE_MMX_INLINE ff_updateMMXDitherTables(c, dstY); + c->dstW_mmx = c->dstW; #endif if (should_dither) { c->chrDither8 = ff_dither_8x8_128[chrDstY & 7]; diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index 5b92c3f72a..6b85ecadae 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -352,6 +352,7 @@ struct SwsInternal { SwsFunc convert_unscaled; int srcW; ///< Width of source luma/alpha planes. int srcH; ///< Height of source luma/alpha planes. + int dstW; ///< Width of destination luma/alpha planes. int dstH; ///< Height of destination luma/alpha planes. int chrSrcW; ///< Width of source chroma planes. int chrSrcH; ///< Height of source chroma planes. @@ -541,7 +542,7 @@ struct SwsInternal { DECLARE_ALIGNED(8, uint64_t, vOffset); int32_t lumMmxFilter[4 * MAX_FILTER_SIZE]; int32_t chrMmxFilter[4 * MAX_FILTER_SIZE]; - int dstW; ///< Width of destination luma/alpha planes. + int dstW_mmx; DECLARE_ALIGNED(8, uint64_t, esp); DECLARE_ALIGNED(8, uint64_t, vRounder); DECLARE_ALIGNED(8, uint64_t, u_temp); From patchwork Sun Oct 20 20:05:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52423 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2255722vqi; Sun, 20 Oct 2024 14:04:07 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWlh79OOd6MIjukL5slYN5tIuPiuFnFXCQvkPoOc7mUfe3InMclBXLhGhYpcuELs2lxZj8/ip4DmfP4KGubYWpO@gmail.com X-Google-Smtp-Source: AGHT+IFpKfE+8wCl5CPpfMxg83D6Isuk2R2LkUQGsmwMrBW/sxc3yKOoFAc/ECiQJCbw0LPpM+fU X-Received: by 2002:a17:907:7f12:b0:a99:2ab0:d973 with SMTP id a640c23a62f3a-a9a69ca1f86mr842468666b.55.1729458246709; Sun, 20 Oct 2024 14:04:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729458246; cv=none; d=google.com; s=arc-20240605; b=OYaQg1isVwtDXMVBDR8qKj6fmkmn0HACtzPHQpfFZuKcaIGJVtNfz2QFaK666HtCiF ikZN4GmBlnt2jPVHzzEwBFgExGkJyUL4P9V3cKD4Rs3nSLeDeuXNrjaWhYEQU46j2QQ2 TMX5sQbzzEYLRONIKx0nK2ulPsI/TPCzhrcx4/gIsSz9PLzT1Do1ANyMMICm3lHCVsRz uPGKfbEEyIvm7JZgdEf2C0Cp5di2dvTImFs3pp7kipVXfAYrLTrUrE+Gs0QdmS0/pIqJ aRxDCLahUiM3qf4eUXtI56y9NyUsKdnKe/Qrjy80wUHKDgNfCVLnVBRlC8RlAfEyPGrv VS4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=dkkRvHygWZJ4LnHjCk36Y37q7dIFk+4RGZS8qNubntQ=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=G6wZ77lig7VAz8kdOOXyxV5k50hXn7dxa8Zsa4AKjJwElN/oV/cF7UouC19Wfd2Ohm iRYSTAiVydS/OD9xqJTnK0iybbFmDyy5BoM0duy4Nuew1iu9MEhq7GrOS61Lx4o1oK7k ZU/fmtsQNHi0FYkMbckPB0HtnKqy2Y0r4VsyQrZgVJILtQNXtqKjkAn+FWHf6hR+ay/P WiKjEoFN8q6Lli4KZ33CCP7OSbKlfAVD+uljqE57enSSKU3txLaMd3ItWqeaGVbktaz9 BU2Bc/sozFYu2PbOI9eRKMKgxorGaPmVNy4/UVKqgIGamUx91l/0WFjT68/Nb+rrjXRY S7Wg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b="NhZ/VhXr"; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a9a913339fbsi157068366b.342.2024.10.20.14.04.05; Sun, 20 Oct 2024 14:04:06 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b="NhZ/VhXr"; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DC42F68DDA7; Sun, 20 Oct 2024 23:09:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 64F4768DC40 for ; Sun, 20 Oct 2024 23:09:00 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454937; bh=Qc/bh3ixFwD4pNnSOJo/cjBw+TsglvlGegFLZB3tut4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NhZ/VhXrfKECtx8lmMNbQwnSvvybAeXOoiDGV5ZbnX73knAwZvJh1x+QBy1N83vNU oeHuWWfXL8c98uawY12NQ3+aYuZul3kKCSRJuuKTi/IGUdsJjOX8Vx0qcixQYkeOpC uBlsg7ex5qSaayVlbAVZqJ9vl0VOD35u2Rjfx04c= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 0B6124BE8A; Sun, 20 Oct 2024 22:08:57 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:20 +0200 Message-ID: <20241020200851.1414766-12-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 11/18] swscale: expose SwsContext publicly 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: qzfFo73PxJ2M From: Niklas Haas This commit does the ardous work of splitting the options out of SwsInternal. To avoid having to change leaf functions too much in one commit, we simply leave behind a pointer to the main context, and replace all references to the corresponding options by a simple search-and-replace. Only the functions inside swscale.c and utils.c are modified in nontrivial ways, since they retain the SwsContext public signature. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/aarch64/swscale.c | 30 +- libswscale/aarch64/swscale_unscaled.c | 34 +- libswscale/alphablend.c | 16 +- libswscale/arm/swscale_unscaled.c | 24 +- libswscale/input.c | 2 +- libswscale/loongarch/input_lasx.c | 2 +- libswscale/loongarch/input_lsx.c | 2 +- libswscale/loongarch/output_lasx.c | 10 +- libswscale/loongarch/output_lsx.c | 10 +- libswscale/loongarch/swscale_init_loongarch.c | 32 +- libswscale/loongarch/swscale_lasx.c | 8 +- libswscale/loongarch/swscale_lsx.c | 8 +- libswscale/loongarch/yuv2rgb_lasx.c | 8 +- libswscale/loongarch/yuv2rgb_lsx.c | 12 +- libswscale/options.c | 31 +- libswscale/output.c | 24 +- libswscale/ppc/swscale_altivec.c | 6 +- libswscale/ppc/swscale_vsx.c | 18 +- libswscale/ppc/yuv2rgb_altivec.c | 36 +- libswscale/ppc/yuv2yuv_altivec.c | 14 +- libswscale/riscv/swscale.c | 6 +- libswscale/slice.c | 22 +- libswscale/swscale.c | 187 ++++---- libswscale/swscale.h | 98 ++++- libswscale/swscale_internal.h | 48 +- libswscale/swscale_unscaled.c | 310 ++++++------- libswscale/utils.c | 414 +++++++++--------- libswscale/vscale.c | 12 +- libswscale/x86/output.asm | 2 +- libswscale/x86/swscale.c | 60 +-- libswscale/x86/swscale_template.c | 20 +- libswscale/x86/yuv2rgb.c | 14 +- libswscale/yuv2rgb.c | 84 ++-- tests/checkasm/sw_gbrp.c | 16 +- tests/checkasm/sw_range_convert.c | 16 +- tests/checkasm/sw_rgb.c | 28 +- tests/checkasm/sw_scale.c | 22 +- 37 files changed, 867 insertions(+), 819 deletions(-) diff --git a/libswscale/aarch64/swscale.c b/libswscale/aarch64/swscale.c index 4c31b78ed8..60a189c142 100644 --- a/libswscale/aarch64/swscale.c +++ b/libswscale/aarch64/swscale.c @@ -45,11 +45,11 @@ static void ff_hscale16to15_4_neon(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->src_format); int sh = desc->comp[0].depth - 1; if (sh<15) { - sh = isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1); + sh = isAnyRGB(c->sws->src_format) || c->sws->src_format==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1); } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */ sh = 16 - 1; } @@ -61,11 +61,11 @@ static void ff_hscale16to15_X8_neon(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->src_format); int sh = desc->comp[0].depth - 1; if (sh<15) { - sh = isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1); + sh = isAnyRGB(c->sws->src_format) || c->sws->src_format==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1); } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */ sh = 16 - 1; } @@ -77,11 +77,11 @@ static void ff_hscale16to15_X4_neon(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->src_format); int sh = desc->comp[0].depth - 1; if (sh<15) { - sh = isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1); + sh = isAnyRGB(c->sws->src_format) || c->sws->src_format==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1); } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */ sh = 16 - 1; } @@ -92,11 +92,11 @@ static void ff_hscale16to19_4_neon(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->src_format); int bits = desc->comp[0].depth - 1; int sh = bits - 4; - if ((isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8) && desc->comp[0].depth<16) { + if ((isAnyRGB(c->sws->src_format) || c->sws->src_format==AV_PIX_FMT_PAL8) && desc->comp[0].depth<16) { sh = 9; } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */ sh = 16 - 1 - 4; @@ -110,11 +110,11 @@ static void ff_hscale16to19_X8_neon(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->src_format); int bits = desc->comp[0].depth - 1; int sh = bits - 4; - if ((isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8) && desc->comp[0].depth<16) { + if ((isAnyRGB(c->sws->src_format) || c->sws->src_format==AV_PIX_FMT_PAL8) && desc->comp[0].depth<16) { sh = 9; } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */ sh = 16 - 1 - 4; @@ -128,11 +128,11 @@ static void ff_hscale16to19_X4_neon(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->src_format); int bits = desc->comp[0].depth - 1; int sh = bits - 4; - if ((isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8) && desc->comp[0].depth<16) { + if ((isAnyRGB(c->sws->src_format) || c->sws->src_format==AV_PIX_FMT_PAL8) && desc->comp[0].depth<16) { sh = 9; } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */ sh = 16 - 1 - 4; @@ -225,9 +225,9 @@ void ff_chrRangeToJpeg_neon(int16_t *dstU, int16_t *dstV, int width); av_cold void ff_sws_init_range_convert_aarch64(SwsInternal *c) { - if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) { + if (c->sws->src_range != c->sws->dst_range && !isAnyRGB(c->sws->dst_format)) { if (c->dstBpc <= 14) { - if (c->srcRange) { + if (c->sws->src_range) { c->lumConvertRange = ff_lumRangeFromJpeg_neon; c->chrConvertRange = ff_chrRangeFromJpeg_neon; } else { @@ -249,7 +249,7 @@ av_cold void ff_sws_init_swscale_aarch64(SwsInternal *c) if (c->dstBpc == 8) { c->yuv2planeX = ff_yuv2planeX_8_neon; } - switch (c->srcFormat) { + switch (c->sws->src_format) { case AV_PIX_FMT_ABGR: c->lumToYV12 = ff_abgr32ToY_neon; if (c->chrSrcHSubSample) diff --git a/libswscale/aarch64/swscale_unscaled.c b/libswscale/aarch64/swscale_unscaled.c index 4f54120445..29f08f7ca9 100644 --- a/libswscale/aarch64/swscale_unscaled.c +++ b/libswscale/aarch64/swscale_unscaled.c @@ -43,7 +43,7 @@ static int ifmt##_to_##ofmt##_neon_wrapper(SwsInternal *c, const uint8_t *const const int dstStride[]) { \ const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \ \ - return ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \ + return ff_##ifmt##_to_##ofmt##_neon(c->sws->src_w, srcSliceH, \ dst[0] + srcSliceY * dstStride[0], dstStride[0], \ src[0], srcStride[0], \ src[1], srcStride[1], \ @@ -71,7 +71,7 @@ static int ifmt##_to_##ofmt##_neon_wrapper(SwsInternal *c, const uint8_t *const const int dstStride[]) { \ const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \ \ - return ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \ + return ff_##ifmt##_to_##ofmt##_neon(c->sws->src_w, srcSliceH, \ dst[0] + srcSliceY * dstStride[0], dstStride[0], \ src[0], srcStride[0], \ src[1], srcStride[1], \ @@ -108,7 +108,7 @@ static int ifmt##_to_##ofmt##_neon_wrapper(SwsInternal *c, const uint8_t *const const int dstStride[]) { \ const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \ \ - return ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \ + return ff_##ifmt##_to_##ofmt##_neon(c->sws->src_w, srcSliceH, \ dst[0] + srcSliceY * dstStride[0], dstStride[0], \ src[0], srcStride[0], src[1], srcStride[1], \ yuv2rgb_table, \ @@ -133,7 +133,7 @@ static int ifmt##_to_##ofmt##_neon_wrapper(SwsInternal *c, const uint8_t *const const int dstStride[]) { \ const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \ \ - return ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \ + return ff_##ifmt##_to_##ofmt##_neon(c->sws->src_w, srcSliceH, \ dst[0] + srcSliceY * dstStride[0], dstStride[0], \ src[0], srcStride[0], src[1], srcStride[1], \ yuv2rgb_table, \ @@ -155,15 +155,17 @@ static int nv24_to_yuv420p_neon_wrapper(SwsInternal *c, const uint8_t *const src uint8_t *dst1 = dst[1] + dstStride[1] * srcSliceY / 2; uint8_t *dst2 = dst[2] + dstStride[2] * srcSliceY / 2; - ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW, + ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->sws->src_w, dst[0], dstStride[0]); - if (c->srcFormat == AV_PIX_FMT_NV24) + if (c->sws->src_format == AV_PIX_FMT_NV24) ff_nv24_to_yuv420p_chroma_neon(dst1, dstStride[1], dst2, dstStride[2], - src[1], srcStride[1], c->srcW / 2, srcSliceH); + src[1], srcStride[1], c->sws->src_w / 2, + srcSliceH); else ff_nv24_to_yuv420p_chroma_neon(dst2, dstStride[2], dst1, dstStride[1], - src[1], srcStride[1], c->srcW / 2, srcSliceH); + src[1], srcStride[1], c->sws->src_w / 2, + srcSliceH); return srcSliceH; } @@ -183,10 +185,10 @@ DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21) * assembly might be writing as much as 4*15=60 extra bytes at the end of the * line, which won't fit the 32-bytes buffer alignment. */ #define SET_FF_NVX_TO_RGBX_FUNC(ifmt, IFMT, ofmt, OFMT, accurate_rnd) do { \ - if (c->srcFormat == AV_PIX_FMT_##IFMT \ - && c->dstFormat == AV_PIX_FMT_##OFMT \ - && !(c->srcH & 1) \ - && !(c->srcW & 15) \ + if (c->sws->src_format == AV_PIX_FMT_##IFMT \ + && c->sws->dst_format == AV_PIX_FMT_##OFMT \ + && !(c->sws->src_h & 1) \ + && !(c->sws->src_w & 15) \ && !accurate_rnd) \ c->convert_unscaled = ifmt##_to_##ofmt##_neon_wrapper; \ } while (0) @@ -200,16 +202,16 @@ DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21) } while (0) static void get_unscaled_swscale_neon(SwsInternal *c) { - int accurate_rnd = c->flags & SWS_ACCURATE_RND; + int accurate_rnd = c->sws->flags & SWS_ACCURATE_RND; SET_FF_NVX_TO_ALL_RGBX_FUNC(nv12, NV12, accurate_rnd); SET_FF_NVX_TO_ALL_RGBX_FUNC(nv21, NV21, accurate_rnd); SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv420p, YUV420P, accurate_rnd); SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv422p, YUV422P, accurate_rnd); - if (c->dstFormat == AV_PIX_FMT_YUV420P && - (c->srcFormat == AV_PIX_FMT_NV24 || c->srcFormat == AV_PIX_FMT_NV42) && - !(c->srcH & 1) && !(c->srcW & 15) && !accurate_rnd) + if (c->sws->dst_format == AV_PIX_FMT_YUV420P && + (c->sws->src_format == AV_PIX_FMT_NV24 || c->sws->src_format == AV_PIX_FMT_NV42) && + !(c->sws->src_h & 1) && !(c->sws->src_w & 15) && !accurate_rnd) c->convert_unscaled = nv24_to_yuv420p_neon_wrapper; } diff --git a/libswscale/alphablend.c b/libswscale/alphablend.c index 4ee23d3aee..db3bd7f17f 100644 --- a/libswscale/alphablend.c +++ b/libswscale/alphablend.c @@ -24,10 +24,10 @@ int ff_sws_alphablendaway(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->src_format); int nb_components = desc->nb_components; int plane, x, ysrc; - int plane_count = isGray(c->srcFormat) ? 1 : 3; + int plane_count = isGray(c->sws->src_format) ? 1 : 3; int sixteen_bits = desc->comp[0].depth >= 9; unsigned off = 1<<(desc->comp[0].depth - 1); unsigned shift = desc->comp[0].depth; @@ -36,7 +36,7 @@ int ff_sws_alphablendaway(SwsInternal *c, const uint8_t *const src[], for (plane = 0; plane < plane_count; plane++) { int a = 0, b = 0; - if (c->alphablend == SWS_ALPHA_BLEND_CHECKERBOARD) { + if (c->sws->alpha_blend == SWS_ALPHA_BLEND_CHECKERBOARD) { a = (1<<(desc->comp[0].depth - 1))/2; b = 3*(1<<(desc->comp[0].depth-1))/2; } @@ -47,7 +47,7 @@ int ff_sws_alphablendaway(SwsInternal *c, const uint8_t *const src[], av_assert0(plane_count == nb_components - 1); if (desc->flags & AV_PIX_FMT_FLAG_PLANAR) { for (plane = 0; plane < plane_count; plane++) { - int w = plane ? c->chrSrcW : c->srcW; + int w = plane ? c->chrSrcW : c->sws->src_w; int x_subsample = plane ? desc->log2_chroma_w: 0; int y_subsample = plane ? desc->log2_chroma_h: 0; for (ysrc = 0; ysrc < AV_CEIL_RSHIFT(srcSliceH, y_subsample); ysrc++) { @@ -60,7 +60,7 @@ int ff_sws_alphablendaway(SwsInternal *c, const uint8_t *const src[], const uint16_t *s = (const uint16_t *)(src[plane ] + srcStride[plane ] * ysrc); const uint16_t *a = (const uint16_t *)(src[plane_count] + (srcStride[plane_count] * ysrc << y_subsample)); uint16_t *d = ( uint16_t *)(dst[plane ] + dstStride[plane ] * y); - if ((!isBE(c->srcFormat)) == !HAVE_BIGENDIAN) { + if ((!isBE(c->sws->src_format)) == !HAVE_BIGENDIAN) { for (x = 0; x < w; x++) { if (y_subsample) { alpha = (a[2*x] + a[2*x + 1] + 2 + @@ -101,7 +101,7 @@ int ff_sws_alphablendaway(SwsInternal *c, const uint8_t *const src[], const uint16_t *s = (const uint16_t *)(src[plane ] + srcStride[plane ] * ysrc); const uint16_t *a = (const uint16_t *)(src[plane_count] + srcStride[plane_count] * ysrc); uint16_t *d = ( uint16_t *)(dst[plane ] + dstStride[plane ] * y); - if ((!isBE(c->srcFormat)) == !HAVE_BIGENDIAN) { + if ((!isBE(c->sws->src_format)) == !HAVE_BIGENDIAN) { for (x = 0; x < w; x++) { unsigned u = s[x]*a[x] + target_table[((x^y)>>5)&1][plane]*(max-a[x]) + off; d[x] = av_clip((u + (u >> shift)) >> shift, 0, max); @@ -127,14 +127,14 @@ int ff_sws_alphablendaway(SwsInternal *c, const uint8_t *const src[], } } else { int alpha_pos = desc->comp[plane_count].offset; - int w = c->srcW; + int w = c->sws->src_w; for (ysrc = 0; ysrc < srcSliceH; ysrc++) { int y = ysrc + srcSliceY; if (sixteen_bits) { const uint16_t *s = (const uint16_t *)(src[0] + srcStride[0] * ysrc + 2*!alpha_pos); const uint16_t *a = (const uint16_t *)(src[0] + srcStride[0] * ysrc + alpha_pos); uint16_t *d = ( uint16_t *)(dst[0] + dstStride[0] * y); - if ((!isBE(c->srcFormat)) == !HAVE_BIGENDIAN) { + if ((!isBE(c->sws->src_format)) == !HAVE_BIGENDIAN) { for (x = 0; x < w; x++) { for (plane = 0; plane < plane_count; plane++) { int x_index = (plane_count + 1) * x; diff --git a/libswscale/arm/swscale_unscaled.c b/libswscale/arm/swscale_unscaled.c index 14685dbc50..8b23bc01eb 100644 --- a/libswscale/arm/swscale_unscaled.c +++ b/libswscale/arm/swscale_unscaled.c @@ -41,7 +41,7 @@ static int rgbx_to_nv12_neon_32_wrapper(SwsInternal *context, const uint8_t *con rgbx_to_nv12_neon_32(src[0] + srcSliceY * srcStride[0], dst[0] + srcSliceY * dstStride[0], dst[1] + (srcSliceY / 2) * dstStride[1], - context->srcW, srcSliceH, + context->opts.src_w, srcSliceH, dstStride[0], dstStride[1], srcStride[0], context->input_rgb2yuv_table); @@ -55,7 +55,7 @@ static int rgbx_to_nv12_neon_16_wrapper(SwsInternal *context, const uint8_t *con rgbx_to_nv12_neon_16(src[0] + srcSliceY * srcStride[0], dst[0] + srcSliceY * dstStride[0], dst[1] + (srcSliceY / 2) * dstStride[1], - context->srcW, srcSliceH, + context->opts.src_w, srcSliceH, dstStride[0], dstStride[1], srcStride[0], context->input_rgb2yuv_table); @@ -84,7 +84,7 @@ static int ifmt##_to_##ofmt##_neon_wrapper(SwsInternal *c, const uint8_t *const const int dstStride[]) { \ const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \ \ - ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \ + ff_##ifmt##_to_##ofmt##_neon(c->sws->src_w, srcSliceH, \ dst[0] + srcSliceY * dstStride[0], dstStride[0], \ src[0], srcStride[0], \ src[1], srcStride[1], \ @@ -120,7 +120,7 @@ static int ifmt##_to_##ofmt##_neon_wrapper(SwsInternal *c, const uint8_t *const const int dstStride[]) { \ const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \ \ - ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \ + ff_##ifmt##_to_##ofmt##_neon(c->sws->src_w, srcSliceH, \ dst[0] + srcSliceY * dstStride[0], dstStride[0], \ src[0], srcStride[0], src[1], srcStride[1], \ yuv2rgb_table, \ @@ -144,10 +144,10 @@ DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21) * assembly might be writing as much as 4*15=60 extra bytes at the end of the * line, which won't fit the 32-bytes buffer alignment. */ #define SET_FF_NVX_TO_RGBX_FUNC(ifmt, IFMT, ofmt, OFMT, accurate_rnd) do { \ - if (c->srcFormat == AV_PIX_FMT_##IFMT \ - && c->dstFormat == AV_PIX_FMT_##OFMT \ - && !(c->srcH & 1) \ - && !(c->srcW & 15) \ + if (c->sws->src_format == AV_PIX_FMT_##IFMT \ + && c->sws->dst_format == AV_PIX_FMT_##OFMT \ + && !(c->sws->src_h & 1) \ + && !(c->sws->src_w & 15) \ && !accurate_rnd) { \ c->convert_unscaled = ifmt##_to_##ofmt##_neon_wrapper; \ } \ @@ -161,10 +161,10 @@ DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21) } while (0) static void get_unscaled_swscale_neon(SwsInternal *c) { - int accurate_rnd = c->flags & SWS_ACCURATE_RND; - if (c->srcFormat == AV_PIX_FMT_RGBA - && c->dstFormat == AV_PIX_FMT_NV12 - && (c->srcW >= 16)) { + int accurate_rnd = c->sws->flags & SWS_ACCURATE_RND; + if (c->sws->src_format == AV_PIX_FMT_RGBA + && c->sws->dst_format == AV_PIX_FMT_NV12 + && (c->sws->src_w >= 16)) { c->convert_unscaled = accurate_rnd ? rgbx_to_nv12_neon_32_wrapper : rgbx_to_nv12_neon_16_wrapper; } diff --git a/libswscale/input.c b/libswscale/input.c index a733ef35f8..f90239a2b2 100644 --- a/libswscale/input.c +++ b/libswscale/input.c @@ -1546,7 +1546,7 @@ av_cold void ff_sws_init_input_funcs(SwsInternal *c, planarX_YV12_fn *readAlpPlanar, planarX2_YV12_fn *readChrPlanar) { - enum AVPixelFormat srcFormat = c->srcFormat; + enum AVPixelFormat srcFormat = c->sws->src_format; *chrToYV12 = NULL; switch (srcFormat) { diff --git a/libswscale/loongarch/input_lasx.c b/libswscale/loongarch/input_lasx.c index b682179c6e..2057f898e9 100644 --- a/libswscale/loongarch/input_lasx.c +++ b/libswscale/loongarch/input_lasx.c @@ -203,7 +203,7 @@ void planar_rgb_to_y_lasx(uint8_t *_dst, const uint8_t *src[4], int width, av_cold void ff_sws_init_input_lasx(SwsInternal *c) { - enum AVPixelFormat srcFormat = c->srcFormat; + enum AVPixelFormat srcFormat = c->sws->src_format; switch (srcFormat) { case AV_PIX_FMT_YUYV422: diff --git a/libswscale/loongarch/input_lsx.c b/libswscale/loongarch/input_lsx.c index 2bc7577961..164fa94d46 100644 --- a/libswscale/loongarch/input_lsx.c +++ b/libswscale/loongarch/input_lsx.c @@ -23,7 +23,7 @@ av_cold void ff_sws_init_input_lsx(SwsInternal *c) { - enum AVPixelFormat srcFormat = c->srcFormat; + enum AVPixelFormat srcFormat = c->sws->src_format; switch (srcFormat) { case AV_PIX_FMT_YUYV422: diff --git a/libswscale/loongarch/output_lasx.c b/libswscale/loongarch/output_lasx.c index 4e5ad3d802..59e4e4f21a 100644 --- a/libswscale/loongarch/output_lasx.c +++ b/libswscale/loongarch/output_lasx.c @@ -888,7 +888,7 @@ static av_always_inline void yuv2rgb_write_full(SwsInternal *c, { int r,g,b; - switch (c->dither) { + switch (c->sws->dither) { default: case SWS_DITHER_AUTO: case SWS_DITHER_ED: @@ -1784,7 +1784,7 @@ av_cold void ff_sws_init_output_lasx(SwsInternal *c, yuv2packedX_fn *yuv2packedX, yuv2anyX_fn *yuv2anyX) { - enum AVPixelFormat dstFormat = c->dstFormat; + enum AVPixelFormat dstFormat = c->sws->dst_format; /* Add initialization once optimized */ if (isSemiPlanarYUV(dstFormat) && isDataInHighBits(dstFormat)) { @@ -1797,8 +1797,8 @@ av_cold void ff_sws_init_output_lasx(SwsInternal *c, *yuv2planeX = yuv2planeX_8_lasx; } - if(c->flags & SWS_FULL_CHR_H_INT) { - switch (c->dstFormat) { + if(c->sws->flags & SWS_FULL_CHR_H_INT) { + switch (c->sws->dst_format) { case AV_PIX_FMT_RGBA: #if CONFIG_SMALL c->yuv2packedX = yuv2rgba32_full_X_lasx; @@ -1911,7 +1911,7 @@ av_cold void ff_sws_init_output_lasx(SwsInternal *c, break; } } else { - switch (c->dstFormat) { + switch (c->sws->dst_format) { case AV_PIX_FMT_RGB32: case AV_PIX_FMT_BGR32: #if CONFIG_SMALL diff --git a/libswscale/loongarch/output_lsx.c b/libswscale/loongarch/output_lsx.c index 29fe30758a..536b9b841c 100644 --- a/libswscale/loongarch/output_lsx.c +++ b/libswscale/loongarch/output_lsx.c @@ -838,7 +838,7 @@ static av_always_inline void yuv2rgb_write_full(SwsInternal *c, { int r,g,b; - switch (c->dither) { + switch (c->sws->dither) { default: case SWS_DITHER_AUTO: case SWS_DITHER_ED: @@ -1633,7 +1633,7 @@ av_cold void ff_sws_init_output_lsx(SwsInternal *c, yuv2packedX_fn *yuv2packedX, yuv2anyX_fn *yuv2anyX) { - enum AVPixelFormat dstFormat = c->dstFormat; + enum AVPixelFormat dstFormat = c->sws->dst_format; /* Add initialization once optimized */ if (isSemiPlanarYUV(dstFormat) && isDataInHighBits(dstFormat)) { @@ -1646,8 +1646,8 @@ av_cold void ff_sws_init_output_lsx(SwsInternal *c, *yuv2planeX = yuv2planeX_8_lsx; } - if(c->flags & SWS_FULL_CHR_H_INT) { - switch (c->dstFormat) { + if(c->sws->flags & SWS_FULL_CHR_H_INT) { + switch (c->sws->dst_format) { case AV_PIX_FMT_RGBA: #if CONFIG_SMALL c->yuv2packedX = yuv2rgba32_full_X_lsx; @@ -1760,7 +1760,7 @@ av_cold void ff_sws_init_output_lsx(SwsInternal *c, break; } } else { - switch (c->dstFormat) { + switch (c->sws->dst_format) { case AV_PIX_FMT_RGB32: case AV_PIX_FMT_BGR32: #if CONFIG_SMALL diff --git a/libswscale/loongarch/swscale_init_loongarch.c b/libswscale/loongarch/swscale_init_loongarch.c index 7cc92be216..455a9c7f0c 100644 --- a/libswscale/loongarch/swscale_init_loongarch.c +++ b/libswscale/loongarch/swscale_init_loongarch.c @@ -29,9 +29,9 @@ av_cold void ff_sws_init_range_convert_loongarch(SwsInternal *c) int cpu_flags = av_get_cpu_flags(); if (have_lsx(cpu_flags)) { - if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) { + if (c->sws->src_range != c->sws->dst_range && !isAnyRGB(c->sws->dst_format)) { if (c->dstBpc <= 14) { - if (c->srcRange) { + if (c->sws->src_range) { c->lumConvertRange = lumRangeFromJpeg_lsx; c->chrConvertRange = chrRangeFromJpeg_lsx; } else { @@ -43,9 +43,9 @@ av_cold void ff_sws_init_range_convert_loongarch(SwsInternal *c) } #if HAVE_LASX if (have_lasx(cpu_flags)) { - if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) { + if (c->sws->src_range != c->sws->dst_range && !isAnyRGB(c->sws->dst_format)) { if (c->dstBpc <= 14) { - if (c->srcRange) { + if (c->sws->src_range) { c->lumConvertRange = lumRangeFromJpeg_lasx; c->chrConvertRange = chrRangeFromJpeg_lasx; } else { @@ -112,29 +112,29 @@ av_cold SwsFunc ff_yuv2rgb_init_loongarch(SwsInternal *c) int cpu_flags = av_get_cpu_flags(); #if HAVE_LASX if (have_lasx(cpu_flags)) { - if (c->srcFormat == AV_PIX_FMT_YUV420P) { - switch (c->dstFormat) { + if (c->sws->src_format == AV_PIX_FMT_YUV420P) { + switch (c->sws->dst_format) { case AV_PIX_FMT_RGB24: return yuv420_rgb24_lasx; case AV_PIX_FMT_BGR24: return yuv420_bgr24_lasx; case AV_PIX_FMT_RGBA: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->sws->src_format)) { break; } else return yuv420_rgba32_lasx; case AV_PIX_FMT_ARGB: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->sws->src_format)) { break; } else return yuv420_argb32_lasx; case AV_PIX_FMT_BGRA: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->sws->src_format)) { break; } else return yuv420_bgra32_lasx; case AV_PIX_FMT_ABGR: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->sws->src_format)) { break; } else return yuv420_abgr32_lasx; @@ -143,29 +143,29 @@ av_cold SwsFunc ff_yuv2rgb_init_loongarch(SwsInternal *c) } #endif // #if HAVE_LASX if (have_lsx(cpu_flags)) { - if (c->srcFormat == AV_PIX_FMT_YUV420P) { - switch (c->dstFormat) { + if (c->sws->src_format == AV_PIX_FMT_YUV420P) { + switch (c->sws->dst_format) { case AV_PIX_FMT_RGB24: return yuv420_rgb24_lsx; case AV_PIX_FMT_BGR24: return yuv420_bgr24_lsx; case AV_PIX_FMT_RGBA: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->sws->src_format)) { break; } else return yuv420_rgba32_lsx; case AV_PIX_FMT_ARGB: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->sws->src_format)) { break; } else return yuv420_argb32_lsx; case AV_PIX_FMT_BGRA: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->sws->src_format)) { break; } else return yuv420_bgra32_lsx; case AV_PIX_FMT_ABGR: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->sws->src_format)) { break; } else return yuv420_abgr32_lsx; diff --git a/libswscale/loongarch/swscale_lasx.c b/libswscale/loongarch/swscale_lasx.c index 79fa4c64b0..8ad0966d4f 100644 --- a/libswscale/loongarch/swscale_lasx.c +++ b/libswscale/loongarch/swscale_lasx.c @@ -677,7 +677,7 @@ void ff_hscale_16_to_15_lasx(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->src_format); int i; const uint16_t *src = (const uint16_t *) _src; int sh = desc->comp[0].depth - 1; @@ -688,7 +688,7 @@ void ff_hscale_16_to_15_lasx(SwsInternal *c, int16_t *dst, int dstW, __m256i zero = __lasx_xvldi(0); if (sh < 15) { - sh = isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8 ? 13 : + sh = isAnyRGB(c->sws->src_format) || c->sws->src_format==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1); } else if (desc->flags && AV_PIX_FMT_FLAG_FLOAT) { sh = 15; @@ -824,7 +824,7 @@ void ff_hscale_16_to_19_lasx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->src_format); int i; int32_t *dst = (int32_t *) _dst; const uint16_t *src = (const uint16_t *) _src; @@ -835,7 +835,7 @@ void ff_hscale_16_to_19_lasx(SwsInternal *c, int16_t *_dst, int dstW, __m256i shift; __m256i zero = __lasx_xvldi(0); - if ((isAnyRGB(c->srcFormat) || c->srcFormat == AV_PIX_FMT_PAL8) + if ((isAnyRGB(c->sws->src_format) || c->sws->src_format == AV_PIX_FMT_PAL8) && desc->comp[0].depth<16) { sh = 9; } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { diff --git a/libswscale/loongarch/swscale_lsx.c b/libswscale/loongarch/swscale_lsx.c index dbdaf18de6..c611810a6d 100644 --- a/libswscale/loongarch/swscale_lsx.c +++ b/libswscale/loongarch/swscale_lsx.c @@ -27,11 +27,11 @@ void ff_hscale_16_to_15_lsx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->src_format); int sh = desc->comp[0].depth - 1; if (sh < 15) { - sh = isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8 ? 13 : + sh = isAnyRGB(c->sws->src_format) || c->sws->src_format==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1); } else if (desc->flags && AV_PIX_FMT_FLAG_FLOAT) { sh = 15; @@ -43,11 +43,11 @@ void ff_hscale_16_to_19_lsx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->src_format); int bits = desc->comp[0].depth - 1; int sh = bits - 4; - if ((isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8) && desc->comp[0].depth<16) { + if ((isAnyRGB(c->sws->src_format) || c->sws->src_format==AV_PIX_FMT_PAL8) && desc->comp[0].depth<16) { sh = 9; } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */ diff --git a/libswscale/loongarch/yuv2rgb_lasx.c b/libswscale/loongarch/yuv2rgb_lasx.c index 1b36d617b5..11d79ac71c 100644 --- a/libswscale/loongarch/yuv2rgb_lasx.c +++ b/libswscale/loongarch/yuv2rgb_lasx.c @@ -173,11 +173,11 @@ __m256i shuf3 = {0x1E0F0E1C0D0C1A0B, 0x0101010101010101, \ 0x1E0F0E1C0D0C1A0B, 0x0101010101010101}; \ YUV2RGB_LOAD_COE \ - y = (c->dstW + 7) & ~7; \ + y = (c->sws->dst_w + 7) & ~7; \ h_size = y >> 4; \ res = y & 15; \ \ - vshift = c->srcFormat != AV_PIX_FMT_YUV422P; \ + vshift = c->sws->src_format != AV_PIX_FMT_YUV422P; \ for (y = 0; y < srcSliceH; y += 2) { \ dst_type *image1 = (dst_type *)(dst[0] + (y + srcSliceY) * dstStride[0]);\ dst_type *image2 = (dst_type *)(image1 + dstStride[0]);\ @@ -199,11 +199,11 @@ __m256i a = __lasx_xvldi(0xFF); \ \ YUV2RGB_LOAD_COE \ - y = (c->dstW + 7) & ~7; \ + y = (c->sws->dst_w + 7) & ~7; \ h_size = y >> 4; \ res = y & 15; \ \ - vshift = c->srcFormat != AV_PIX_FMT_YUV422P; \ + vshift = c->sws->src_format != AV_PIX_FMT_YUV422P; \ for (y = 0; y < srcSliceH; y += 2) { \ int yd = y + srcSliceY; \ dst_type av_unused *r, *g, *b; \ diff --git a/libswscale/loongarch/yuv2rgb_lsx.c b/libswscale/loongarch/yuv2rgb_lsx.c index f2f424265f..a12159d555 100644 --- a/libswscale/loongarch/yuv2rgb_lsx.c +++ b/libswscale/loongarch/yuv2rgb_lsx.c @@ -128,9 +128,9 @@ \ YUV2RGB_LOAD_COE \ \ - h_size = c->dstW >> 4; \ - res = (c->dstW & 15) >> 1; \ - vshift = c->srcFormat != AV_PIX_FMT_YUV422P; \ + h_size = c->sws->dst_w >> 4; \ + res = (c->sws->dst_w & 15) >> 1; \ + vshift = c->sws->src_format != AV_PIX_FMT_YUV422P; \ for (y = 0; y < srcSliceH; y += 2) { \ dst_type av_unused *r, *g, *b; \ dst_type *image1 = (dst_type *)(dst[0] + (y + srcSliceY) * dstStride[0]);\ @@ -156,9 +156,9 @@ \ YUV2RGB_LOAD_COE \ \ - h_size = c->dstW >> 4; \ - res = (c->dstW & 15) >> 1; \ - vshift = c->srcFormat != AV_PIX_FMT_YUV422P; \ + h_size = c->sws->dst_w >> 4; \ + res = (c->sws->dst_w & 15) >> 1; \ + vshift = c->sws->src_format != AV_PIX_FMT_YUV422P; \ for (y = 0; y < srcSliceH; y += 2) { \ int yd = y + srcSliceY; \ dst_type av_unused *r, *g, *b; \ diff --git a/libswscale/options.c b/libswscale/options.c index e64e289cf3..4ce7d8a36a 100644 --- a/libswscale/options.c +++ b/libswscale/options.c @@ -27,7 +27,7 @@ static const char *sws_context_to_name(void *ptr) return "swscaler"; } -#define OFFSET(x) offsetof(SwsInternal, x) +#define OFFSET(x) offsetof(SwsContext, x) #define DEFAULT 0 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM @@ -51,18 +51,18 @@ static const AVOption swscale_options[] = { { "bitexact", "bit-exact mode", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_BITEXACT }, .flags = VE, .unit = "sws_flags" }, { "error_diffusion", "error diffusion dither", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ERROR_DIFFUSION}, .flags = VE, .unit = "sws_flags" }, - { "param0", "scaler param 0", OFFSET(param[0]), AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT }, INT_MIN, INT_MAX, VE }, - { "param1", "scaler param 1", OFFSET(param[1]), AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT }, INT_MIN, INT_MAX, VE }, + { "param0", "scaler param 0", OFFSET(scaler_params[0]), AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT }, INT_MIN, INT_MAX, VE }, + { "param1", "scaler param 1", OFFSET(scaler_params[1]), AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT }, INT_MIN, INT_MAX, VE }, - { "srcw", "source width", OFFSET(srcW), AV_OPT_TYPE_INT, { .i64 = 16 }, 1, INT_MAX, VE }, - { "srch", "source height", OFFSET(srcH), AV_OPT_TYPE_INT, { .i64 = 16 }, 1, INT_MAX, VE }, - { "dstw", "destination width", OFFSET(dstW), AV_OPT_TYPE_INT, { .i64 = 16 }, 1, INT_MAX, VE }, - { "dsth", "destination height", OFFSET(dstH), AV_OPT_TYPE_INT, { .i64 = 16 }, 1, INT_MAX, VE }, - { "src_format", "source format", OFFSET(srcFormat), AV_OPT_TYPE_PIXEL_FMT,{ .i64 = DEFAULT }, 0, INT_MAX, VE }, - { "dst_format", "destination format", OFFSET(dstFormat), AV_OPT_TYPE_PIXEL_FMT,{ .i64 = DEFAULT }, 0, INT_MAX, VE }, - { "src_range", "source is full range", OFFSET(srcRange), AV_OPT_TYPE_BOOL, { .i64 = DEFAULT }, 0, 1, VE }, - { "dst_range", "destination is full range", OFFSET(dstRange), AV_OPT_TYPE_BOOL, { .i64 = DEFAULT }, 0, 1, VE }, - { "gamma", "gamma correct scaling", OFFSET(gamma_flag),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, + { "srcw", "source width", OFFSET(src_w), AV_OPT_TYPE_INT, { .i64 = 16 }, 1, INT_MAX, VE }, + { "srch", "source height", OFFSET(src_h), AV_OPT_TYPE_INT, { .i64 = 16 }, 1, INT_MAX, VE }, + { "dstw", "destination width", OFFSET(dst_w), AV_OPT_TYPE_INT, { .i64 = 16 }, 1, INT_MAX, VE }, + { "dsth", "destination height", OFFSET(dst_h), AV_OPT_TYPE_INT, { .i64 = 16 }, 1, INT_MAX, VE }, + { "src_format", "source format", OFFSET(src_format), AV_OPT_TYPE_PIXEL_FMT, { .i64 = DEFAULT }, 0, INT_MAX, VE }, + { "dst_format", "destination format", OFFSET(dst_format), AV_OPT_TYPE_PIXEL_FMT, { .i64 = DEFAULT }, 0, INT_MAX, VE }, + { "src_range", "source is full range", OFFSET(src_range), AV_OPT_TYPE_BOOL, { .i64 = DEFAULT }, 0, 1, VE }, + { "dst_range", "destination is full range", OFFSET(dst_range), AV_OPT_TYPE_BOOL, { .i64 = DEFAULT }, 0, 1, VE }, + { "gamma", "gamma correct scaling", OFFSET(gamma_flag), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, { "src_v_chr_pos", "source vertical chroma position in luma grid/256" , OFFSET(src_v_chr_pos), AV_OPT_TYPE_INT, { .i64 = -513 }, -513, 1024, VE }, { "src_h_chr_pos", "source horizontal chroma position in luma grid/256", OFFSET(src_h_chr_pos), AV_OPT_TYPE_INT, { .i64 = -513 }, -513, 1024, VE }, @@ -76,13 +76,13 @@ static const AVOption swscale_options[] = { { "a_dither", "arithmetic addition dither", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_DITHER_A_DITHER }, .flags = VE, .unit = "sws_dither" }, { "x_dither", "arithmetic xor dither", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_DITHER_X_DITHER }, .flags = VE, .unit = "sws_dither" }, - { "alphablend", "mode for alpha -> non alpha", OFFSET(alphablend), AV_OPT_TYPE_INT, { .i64 = SWS_ALPHA_BLEND_NONE}, .flags = VE, .unit = "alphablend", .max = SWS_ALPHA_BLEND_NB - 1 }, + { "alphablend", "mode for alpha -> non alpha", OFFSET(alpha_blend), AV_OPT_TYPE_INT, { .i64 = SWS_ALPHA_BLEND_NONE}, .flags = VE, .unit = "alphablend", .max = SWS_ALPHA_BLEND_NB - 1 }, { "none", "ignore alpha", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ALPHA_BLEND_NONE}, .flags = VE, .unit = "alphablend" }, { "uniform_color", "blend onto a uniform color", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ALPHA_BLEND_UNIFORM}, .flags = VE, .unit = "alphablend" }, { "checkerboard", "blend onto a checkerboard", 0, AV_OPT_TYPE_CONST, { .i64 = SWS_ALPHA_BLEND_CHECKERBOARD}, .flags = VE, .unit = "alphablend" }, - { "threads", "number of threads", OFFSET(nb_threads), AV_OPT_TYPE_INT, {.i64 = 1 }, 0, INT_MAX, VE, .unit = "threads" }, - { "auto", "automatic selection", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, .flags = VE, .unit = "threads" }, + { "threads", "number of threads", OFFSET(threads), AV_OPT_TYPE_INT, {.i64 = 1 }, .flags = VE, .unit = "threads", .max = INT_MAX }, + { "auto", "automatic selection", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, .flags = VE, .unit = "threads" }, { NULL } }; @@ -91,7 +91,6 @@ const AVClass ff_sws_context_class = { .class_name = "SWScaler", .item_name = sws_context_to_name, .option = swscale_options, - .parent_log_context_offset = OFFSET(parent), .category = AV_CLASS_CATEGORY_SWSCALER, .version = LIBAVUTIL_VERSION_INT, }; diff --git a/libswscale/output.c b/libswscale/output.c index 56f16dfd34..cb1adefdee 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -624,7 +624,7 @@ yuv2mono_X_c_template(SwsInternal *c, const int16_t *lumFilter, Y1 = av_clip_uint8(Y1); Y2 = av_clip_uint8(Y2); } - if (c->dither == SWS_DITHER_ED) { + if (c->sws->dither == SWS_DITHER_ED) { Y1 += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4; c->dither_error[0][i] = err; acc = 2*acc + (Y1 >= 128); @@ -662,7 +662,7 @@ yuv2mono_2_c_template(SwsInternal *c, const int16_t *buf[2], int i; av_assert2(yalpha <= 4096U); - if (c->dither == SWS_DITHER_ED) { + if (c->sws->dither == SWS_DITHER_ED) { int err = 0; int acc = 0; for (i = 0; i < dstW; i +=2) { @@ -719,7 +719,7 @@ yuv2mono_1_c_template(SwsInternal *c, const int16_t *buf0, const uint8_t * const d128 = ff_dither_8x8_220[y & 7]; int i; - if (c->dither == SWS_DITHER_ED) { + if (c->sws->dither == SWS_DITHER_ED) { int err = 0; int acc = 0; for (i = 0; i < dstW; i +=2) { @@ -1976,7 +1976,7 @@ static av_always_inline void yuv2rgb_write_full(SwsInternal *c, { int r,g,b; - switch (c->dither) { + switch (c->sws->dither) { case SWS_DITHER_NONE: if (isrgb8) { r = av_clip_uintp2(R >> 27, 3); @@ -2249,7 +2249,7 @@ yuv2gbrp_full_X_c(SwsInternal *c, const int16_t *lumFilter, const int16_t **alpSrc, uint8_t **dest, int dstW, int y) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->dst_format); int i; int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc; uint16_t **dest16 = (uint16_t**)dest; @@ -2312,7 +2312,7 @@ yuv2gbrp_full_X_c(SwsInternal *c, const int16_t *lumFilter, dest[3][i] = A >> 19; } } - if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) { + if (SH != 22 && (!isBE(c->sws->dst_format)) != (!HAVE_BIGENDIAN)) { for (i = 0; i < dstW; i++) { dest16[0][i] = av_bswap16(dest16[0][i]); dest16[1][i] = av_bswap16(dest16[1][i]); @@ -2331,7 +2331,7 @@ yuv2gbrp16_full_X_c(SwsInternal *c, const int16_t *lumFilter, const int16_t **alpSrcx, uint8_t **dest, int dstW, int y) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->dst_format); int i; int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx; uint16_t **dest16 = (uint16_t**)dest; @@ -2384,7 +2384,7 @@ yuv2gbrp16_full_X_c(SwsInternal *c, const int16_t *lumFilter, if (hasAlpha) dest16[3][i] = av_clip_uintp2(A, 30) >> 14; } - if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) { + if ((!isBE(c->sws->dst_format)) != (!HAVE_BIGENDIAN)) { for (i = 0; i < dstW; i++) { dest16[0][i] = av_bswap16(dest16[0][i]); dest16[1][i] = av_bswap16(dest16[1][i]); @@ -2403,7 +2403,7 @@ yuv2gbrpf32_full_X_c(SwsInternal *c, const int16_t *lumFilter, const int16_t **alpSrcx, uint8_t **dest, int dstW, int y) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->dst_format); int i; int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx; uint32_t **dest32 = (uint32_t**)dest; @@ -2460,7 +2460,7 @@ yuv2gbrpf32_full_X_c(SwsInternal *c, const int16_t *lumFilter, if (hasAlpha) dest32[3][i] = av_float2int(float_mult * (float)(av_clip_uintp2(A, 30) >> 14)); } - if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) { + if ((!isBE(c->sws->dst_format)) != (!HAVE_BIGENDIAN)) { for (i = 0; i < dstW; i++) { dest32[0][i] = av_bswap32(dest32[0][i]); dest32[1][i] = av_bswap32(dest32[1][i]); @@ -3113,7 +3113,7 @@ av_cold void ff_sws_init_output_funcs(SwsInternal *c, yuv2packedX_fn *yuv2packedX, yuv2anyX_fn *yuv2anyX) { - enum AVPixelFormat dstFormat = c->dstFormat; + enum AVPixelFormat dstFormat = c->sws->dst_format; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat); if (isSemiPlanarYUV(dstFormat) && isDataInHighBits(dstFormat)) { @@ -3161,7 +3161,7 @@ av_cold void ff_sws_init_output_funcs(SwsInternal *c, *yuv2nv12cX = yuv2nv12cX_c; } - if(c->flags & SWS_FULL_CHR_H_INT) { + if(c->sws->flags & SWS_FULL_CHR_H_INT) { switch (dstFormat) { case AV_PIX_FMT_RGBA: #if CONFIG_SMALL diff --git a/libswscale/ppc/swscale_altivec.c b/libswscale/ppc/swscale_altivec.c index 836aaab1f8..fb03b17be9 100644 --- a/libswscale/ppc/swscale_altivec.c +++ b/libswscale/ppc/swscale_altivec.c @@ -232,7 +232,7 @@ yuv2plane1_float(yuv2plane1_float_bswap_altivec, uint32_t, BE) av_cold void ff_sws_init_swscale_ppc(SwsInternal *c) { #if HAVE_ALTIVEC - enum AVPixelFormat dstFormat = c->dstFormat; + enum AVPixelFormat dstFormat = c->sws->dst_format; if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) return; @@ -256,8 +256,8 @@ av_cold void ff_sws_init_swscale_ppc(SwsInternal *c) /* The following list of supported dstFormat values should * match what's found in the body of ff_yuv2packedX_altivec() */ - if (!(c->flags & (SWS_BITEXACT | SWS_FULL_CHR_H_INT)) && !c->needAlpha) { - switch (c->dstFormat) { + if (!(c->sws->flags & (SWS_BITEXACT | SWS_FULL_CHR_H_INT)) && !c->needAlpha) { + switch (c->sws->dst_format) { case AV_PIX_FMT_ABGR: c->yuv2packedX = ff_yuv2abgr_X_altivec; break; diff --git a/libswscale/ppc/swscale_vsx.c b/libswscale/ppc/swscale_vsx.c index f83bb96ec9..2d18e1ebcf 100644 --- a/libswscale/ppc/swscale_vsx.c +++ b/libswscale/ppc/swscale_vsx.c @@ -1862,7 +1862,7 @@ static void hScale16To19_vsx(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->src_format); int i, j; int32_t *dst = (int32_t *) _dst; const uint16_t *src = (const uint16_t *) _src; @@ -1891,7 +1891,7 @@ static void hScale16To19_vsx(SwsInternal *c, int16_t *_dst, int dstW, }; const vec_u8 vunused = vunusedtab[filterSize % 8]; - if ((isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8) && desc->comp[0].depth<16) { + if ((isAnyRGB(c->sws->src_format) || c->sws->src_format==AV_PIX_FMT_PAL8) && desc->comp[0].depth<16) { sh = 9; } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */ sh = 16 - 1 - 4; @@ -1940,7 +1940,7 @@ static void hScale16To15_vsx(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->src_format); int i, j; const uint16_t *src = (const uint16_t *) _src; int sh = desc->comp[0].depth - 1; @@ -1968,7 +1968,7 @@ static void hScale16To15_vsx(SwsInternal *c, int16_t *dst, int dstW, const vec_u8 vunused = vunusedtab[filterSize % 8]; if (sh<15) { - sh = isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1); + sh = isAnyRGB(c->sws->src_format) || c->sws->src_format==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1); } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */ sh = 16 - 1; } @@ -2019,7 +2019,7 @@ static void hScale16To15_vsx(SwsInternal *c, int16_t *dst, int dstW, av_cold void ff_sws_init_swscale_vsx(SwsInternal *c) { #if HAVE_VSX - enum AVPixelFormat dstFormat = c->dstFormat; + enum AVPixelFormat dstFormat = c->sws->dst_format; const int cpu_flags = av_get_cpu_flags(); const unsigned char power8 = HAVE_POWER8 && cpu_flags & AV_CPU_FLAG_POWER8; @@ -2030,7 +2030,7 @@ av_cold void ff_sws_init_swscale_vsx(SwsInternal *c) if (c->srcBpc == 8) { if (c->dstBpc <= 14) { c->hyScale = c->hcScale = hScale_real_vsx; - if (c->flags & SWS_FAST_BILINEAR && c->dstW >= c->srcW && c->chrDstW >= c->chrSrcW) { + if (c->sws->flags & SWS_FAST_BILINEAR && c->sws->dst_w >= c->sws->src_w && c->chrDstW >= c->chrSrcW) { c->hyscale_fast = hyscale_fast_vsx; c->hcscale_fast = hcscale_fast_vsx; } @@ -2048,7 +2048,7 @@ av_cold void ff_sws_init_swscale_vsx(SwsInternal *c) } #endif - if (!(c->flags & (SWS_BITEXACT | SWS_FULL_CHR_H_INT)) && !c->needAlpha) { + if (!(c->sws->flags & (SWS_BITEXACT | SWS_FULL_CHR_H_INT)) && !c->needAlpha) { switch (c->dstBpc) { case 8: c->yuv2plane1 = yuv2plane1_8_vsx; @@ -2082,11 +2082,11 @@ av_cold void ff_sws_init_swscale_vsx(SwsInternal *c) } } - if (c->flags & SWS_BITEXACT) + if (c->sws->flags & SWS_BITEXACT) return; #if !HAVE_BIGENDIAN - if (c->flags & SWS_FULL_CHR_H_INT) { + if (c->sws->flags & SWS_FULL_CHR_H_INT) { switch (dstFormat) { case AV_PIX_FMT_RGB24: if (power8) { diff --git a/libswscale/ppc/yuv2rgb_altivec.c b/libswscale/ppc/yuv2rgb_altivec.c index 9db305f43f..e03382aac6 100644 --- a/libswscale/ppc/yuv2rgb_altivec.c +++ b/libswscale/ppc/yuv2rgb_altivec.c @@ -299,7 +299,7 @@ static int altivec_ ## name(SwsInternal *c, const unsigned char *const *in, \ const int *instrides, int srcSliceY, int srcSliceH, \ unsigned char *const *oplanes, const int *outstrides) \ { \ - int w = c->srcW; \ + int w = c->sws->src_w; \ int h = srcSliceH; \ int i, j; \ int instrides_scl[3]; \ @@ -475,7 +475,7 @@ static int altivec_uyvy_rgb32(SwsInternal *c, const unsigned char *const *in, const int *instrides, int srcSliceY, int srcSliceH, unsigned char *const *oplanes, const int *outstrides) { - int w = c->srcW; + int w = c->sws->src_w; int h = srcSliceH; int i, j; vector unsigned char uyvy; @@ -545,46 +545,46 @@ av_cold SwsFunc ff_yuv2rgb_init_ppc(SwsInternal *c) * boom with X11 bad match. * */ - if ((c->srcW & 0xf) != 0) + if ((c->sws->src_w & 0xf) != 0) return NULL; - switch (c->srcFormat) { + switch (c->sws->src_format) { case AV_PIX_FMT_YUV410P: case AV_PIX_FMT_YUV420P: /*case IMGFMT_CLPL: ??? */ case AV_PIX_FMT_GRAY8: case AV_PIX_FMT_NV12: case AV_PIX_FMT_NV21: - if ((c->srcH & 0x1) != 0) + if ((c->sws->src_h & 0x1) != 0) return NULL; - switch (c->dstFormat) { + switch (c->sws->dst_format) { case AV_PIX_FMT_RGB24: - av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGB24\n"); + av_log(c->sws, AV_LOG_WARNING, "ALTIVEC: Color Space RGB24\n"); return altivec_yuv2_rgb24; case AV_PIX_FMT_BGR24: - av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space BGR24\n"); + av_log(c->sws, AV_LOG_WARNING, "ALTIVEC: Color Space BGR24\n"); return altivec_yuv2_bgr24; case AV_PIX_FMT_ARGB: - av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space ARGB\n"); + av_log(c->sws, AV_LOG_WARNING, "ALTIVEC: Color Space ARGB\n"); return altivec_yuv2_argb; case AV_PIX_FMT_ABGR: - av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space ABGR\n"); + av_log(c->sws, AV_LOG_WARNING, "ALTIVEC: Color Space ABGR\n"); return altivec_yuv2_abgr; case AV_PIX_FMT_RGBA: - av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGBA\n"); + av_log(c->sws, AV_LOG_WARNING, "ALTIVEC: Color Space RGBA\n"); return altivec_yuv2_rgba; case AV_PIX_FMT_BGRA: - av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space BGRA\n"); + av_log(c->sws, AV_LOG_WARNING, "ALTIVEC: Color Space BGRA\n"); return altivec_yuv2_bgra; default: return NULL; } break; case AV_PIX_FMT_UYVY422: - switch (c->dstFormat) { + switch (c->sws->dst_format) { case AV_PIX_FMT_BGR32: - av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space UYVY -> RGB32\n"); + av_log(c->sws, AV_LOG_WARNING, "ALTIVEC: Color Space UYVY -> RGB32\n"); return altivec_uyvy_rgb32; default: return NULL; } @@ -740,9 +740,9 @@ static av_always_inline void yuv2packedX_altivec(SwsInternal *c, * instead. */ static int printed_error_message; if (!printed_error_message) { - av_log(c, AV_LOG_ERROR, + av_log(c->sws, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n", - av_get_pix_fmt_name(c->dstFormat)); + av_get_pix_fmt_name(c->sws->dst_format)); printed_error_message = 1; } return; @@ -828,9 +828,9 @@ static av_always_inline void yuv2packedX_altivec(SwsInternal *c, break; default: /* Unreachable, I think. */ - av_log(c, AV_LOG_ERROR, + av_log(c->sws, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n", - av_get_pix_fmt_name(c->dstFormat)); + av_get_pix_fmt_name(c->sws->dst_format)); return; } diff --git a/libswscale/ppc/yuv2yuv_altivec.c b/libswscale/ppc/yuv2yuv_altivec.c index 0ae5223760..906531fe8f 100644 --- a/libswscale/ppc/yuv2yuv_altivec.c +++ b/libswscale/ppc/yuv2yuv_altivec.c @@ -37,12 +37,12 @@ static int yv12toyuy2_unscaled_altivec(SwsInternal *c, const uint8_t *const src[ const int dstStride_a[]) { uint8_t *dst = dstParam[0] + dstStride_a[0] * srcSliceY; - // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, + // yv12toyuy2(src[0], src[1], src[2], dst, c->sws->src_w, srcSliceH, // srcStride[0], srcStride[1], dstStride[0]); const uint8_t *ysrc = src[0]; const uint8_t *usrc = src[1]; const uint8_t *vsrc = src[2]; - const int width = c->srcW; + const int width = c->sws->src_w; const int height = srcSliceH; const int lumStride = srcStride[0]; const int chromStride = srcStride[1]; @@ -113,12 +113,12 @@ static int yv12touyvy_unscaled_altivec(SwsInternal *c, const uint8_t *const src[ const int dstStride_a[]) { uint8_t *dst = dstParam[0] + dstStride_a[0] * srcSliceY; - // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, + // yv12toyuy2(src[0], src[1], src[2], dst, c->sws->src_w, srcSliceH, // srcStride[0], srcStride[1], dstStride[0]); const uint8_t *ysrc = src[0]; const uint8_t *usrc = src[1]; const uint8_t *vsrc = src[2]; - const int width = c->srcW; + const int width = c->sws->src_w; const int height = srcSliceH; const int lumStride = srcStride[0]; const int chromStride = srcStride[1]; @@ -190,9 +190,9 @@ av_cold void ff_get_unscaled_swscale_ppc(SwsInternal *c) if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) return; - if (!(c->srcW & 15) && !(c->flags & SWS_BITEXACT) && - c->srcFormat == AV_PIX_FMT_YUV420P) { - enum AVPixelFormat dstFormat = c->dstFormat; + if (!(c->sws->src_w & 15) && !(c->sws->flags & SWS_BITEXACT) && + c->sws->src_format == AV_PIX_FMT_YUV420P) { + enum AVPixelFormat dstFormat = c->sws->dst_format; // unscaled YV12 -> packed YUV, we want speed if (dstFormat == AV_PIX_FMT_YUYV422) diff --git a/libswscale/riscv/swscale.c b/libswscale/riscv/swscale.c index 8ed9ce969e..7e44a85bcf 100644 --- a/libswscale/riscv/swscale.c +++ b/libswscale/riscv/swscale.c @@ -37,10 +37,10 @@ av_cold static void ff_sws_init_range_convert_riscv(SwsInternal *c, int flags) { ff_range_lum_from_jpeg_16_rvv, ff_range_chr_from_jpeg_16_rvv }, }; - if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat) && + if (c->sws->src_range != c->sws->dst_range && !isAnyRGB(c->sws->dst_format) && c->dstBpc <= 14 && (flags & AV_CPU_FLAG_RVV_I32) && (flags & AV_CPU_FLAG_RVB)) { - bool from = c->srcRange != 0; + bool from = c->sws->src_range != 0; c->lumConvertRange = convs[from].lum; c->chrConvertRange = convs[from].chr; @@ -71,7 +71,7 @@ av_cold void ff_sws_init_swscale_riscv(SwsInternal *c) #if HAVE_RVV if ((flags & AV_CPU_FLAG_RVV_I32) && (flags & AV_CPU_FLAG_RVB)) { - switch (c->srcFormat) { + switch (c->sws->src_format) { case AV_PIX_FMT_ABGR: c->lumToYV12 = ff_abgr32ToY_rvv; if (c->chrSrcHSubSample) diff --git a/libswscale/slice.c b/libswscale/slice.c index f13a839f98..b2fde00d0d 100644 --- a/libswscale/slice.c +++ b/libswscale/slice.c @@ -221,7 +221,7 @@ static void fill_ones(SwsSlice *s, int n, int bpc) static void get_min_buffer_size(SwsInternal *c, int *out_lum_size, int *out_chr_size) { int lumY; - int dstH = c->dstH; + int dstH = c->sws->dst_h; int chrDstH = c->chrDstH; int *lumFilterPos = c->vLumFilterPos; int *chrFilterPos = c->vChrFilterPos; @@ -253,14 +253,14 @@ int ff_init_filters(SwsInternal * c) int index; int num_ydesc; int num_cdesc; - int num_vdesc = isPlanarYUV(c->dstFormat) && !isGray(c->dstFormat) ? 2 : 1; + int num_vdesc = isPlanarYUV(c->sws->dst_format) && !isGray(c->sws->dst_format) ? 2 : 1; int need_lum_conv = c->lumToYV12 || c->readLumPlanar || c->alpToYV12 || c->readAlpPlanar; int need_chr_conv = c->chrToYV12 || c->readChrPlanar; int need_gamma = c->is_internal_gamma; int srcIdx, dstIdx; - int dst_stride = FFALIGN(c->dstW * sizeof(int16_t) + 66, 16); + int dst_stride = FFALIGN(c->sws->dst_w * sizeof(int16_t) + 66, 16); - uint32_t * pal = usePal(c->srcFormat) ? c->pal_yuv : (uint32_t*)c->input_rgb2yuv_table; + uint32_t * pal = usePal(c->sws->src_format) ? c->pal_yuv : (uint32_t*)c->input_rgb2yuv_table; int res = 0; int lumBufSize; @@ -284,7 +284,7 @@ int ff_init_filters(SwsInternal * c) c->descIndex[0] = num_ydesc + (need_gamma ? 1 : 0); c->descIndex[1] = num_ydesc + num_cdesc + (need_gamma ? 1 : 0); - if (isFloat16(c->srcFormat)) { + if (isFloat16(c->sws->src_format)) { c->h2f_tables = av_malloc(sizeof(*c->h2f_tables)); if (!c->h2f_tables) return AVERROR(ENOMEM); @@ -301,25 +301,25 @@ int ff_init_filters(SwsInternal * c) goto cleanup; } - res = alloc_slice(&c->slice[0], c->srcFormat, c->srcH, c->chrSrcH, c->chrSrcHSubSample, c->chrSrcVSubSample, 0); + res = alloc_slice(&c->slice[0], c->sws->src_format, c->sws->src_h, c->chrSrcH, c->chrSrcHSubSample, c->chrSrcVSubSample, 0); if (res < 0) goto cleanup; for (i = 1; i < c->numSlice-2; ++i) { - res = alloc_slice(&c->slice[i], c->srcFormat, lumBufSize, chrBufSize, c->chrSrcHSubSample, c->chrSrcVSubSample, 0); + res = alloc_slice(&c->slice[i], c->sws->src_format, lumBufSize, chrBufSize, c->chrSrcHSubSample, c->chrSrcVSubSample, 0); if (res < 0) goto cleanup; - res = alloc_lines(&c->slice[i], FFALIGN(c->srcW*2+78, 16), c->srcW); + res = alloc_lines(&c->slice[i], FFALIGN(c->sws->src_w*2+78, 16), c->sws->src_w); if (res < 0) goto cleanup; } // horizontal scaler output - res = alloc_slice(&c->slice[i], c->srcFormat, lumBufSize, chrBufSize, c->chrDstHSubSample, c->chrDstVSubSample, 1); + res = alloc_slice(&c->slice[i], c->sws->src_format, lumBufSize, chrBufSize, c->chrDstHSubSample, c->chrDstVSubSample, 1); if (res < 0) goto cleanup; - res = alloc_lines(&c->slice[i], dst_stride, c->dstW); + res = alloc_lines(&c->slice[i], dst_stride, c->sws->dst_w); if (res < 0) goto cleanup; fill_ones(&c->slice[i], dst_stride>>1, c->dstBpc); // vertical scaler output ++i; - res = alloc_slice(&c->slice[i], c->dstFormat, c->dstH, c->chrDstH, c->chrDstHSubSample, c->chrDstVSubSample, 0); + res = alloc_slice(&c->slice[i], c->sws->dst_format, c->sws->dst_h, c->chrDstH, c->chrDstHSubSample, c->chrDstVSubSample, 0); if (res < 0) goto cleanup; index = 0; diff --git a/libswscale/swscale.c b/libswscale/swscale.c index e0a9e0279f..bb4faaa708 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -66,14 +66,14 @@ static void hScale16To19_c(SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->src_format); int i; int32_t *dst = (int32_t *) _dst; const uint16_t *src = (const uint16_t *) _src; int bits = desc->comp[0].depth - 1; int sh = bits - 4; - if ((isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8) && desc->comp[0].depth<16) { + if ((isAnyRGB(c->sws->src_format) || c->sws->src_format==AV_PIX_FMT_PAL8) && desc->comp[0].depth<16) { sh = 9; } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */ sh = 16 - 1 - 4; @@ -96,13 +96,13 @@ static void hScale16To15_c(SwsInternal *c, int16_t *dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->src_format); int i; const uint16_t *src = (const uint16_t *) _src; int sh = desc->comp[0].depth - 1; if (sh<15) { - sh = isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1); + sh = isAnyRGB(c->sws->src_format) || c->sws->src_format==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1); } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */ sh = 16 - 1; } @@ -231,21 +231,21 @@ static void lumRangeFromJpeg16_c(int16_t *_dst, int width) #define DEBUG_SWSCALE_BUFFERS 0 #define DEBUG_BUFFERS(...) \ if (DEBUG_SWSCALE_BUFFERS) \ - av_log(c, AV_LOG_DEBUG, __VA_ARGS__) + av_log(c->sws, AV_LOG_DEBUG, __VA_ARGS__) int ff_swscale(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[], int dstSliceY, int dstSliceH) { - const int scale_dst = dstSliceY > 0 || dstSliceH < c->dstH; + const int scale_dst = dstSliceY > 0 || dstSliceH < c->sws->dst_h; /* load a few things into local vars to make the code more readable? * and faster */ - const int dstW = c->dstW; - int dstH = c->dstH; + const int dstW = c->sws->dst_w; + int dstH = c->sws->dst_h; - const enum AVPixelFormat dstFormat = c->dstFormat; - const int flags = c->flags; + const enum AVPixelFormat dstFormat = c->sws->dst_format; + const int flags = c->sws->flags; int32_t *vLumFilterPos = c->vLumFilterPos; int32_t *vChrFilterPos = c->vChrFilterPos; @@ -261,8 +261,8 @@ int ff_swscale(SwsInternal *c, const uint8_t *const src[], const int srcStride[] yuv2anyX_fn yuv2anyX = c->yuv2anyX; const int chrSrcSliceY = srcSliceY >> c->chrSrcVSubSample; const int chrSrcSliceH = AV_CEIL_RSHIFT(srcSliceH, c->chrSrcVSubSample); - int should_dither = isNBPS(c->srcFormat) || - is16BPS(c->srcFormat); + int should_dither = isNBPS(c->sws->src_format) || + is16BPS(c->sws->src_format); int lastDstY; /* vars which will change and which we need to store back in the context */ @@ -289,7 +289,7 @@ int ff_swscale(SwsInternal *c, const uint8_t *const src[], const int srcStride[] const uint8_t *src2[4]; int srcStride2[4]; - if (isPacked(c->srcFormat)) { + if (isPacked(c->sws->src_format)) { src2[0] = src2[1] = src2[2] = @@ -321,7 +321,7 @@ int ff_swscale(SwsInternal *c, const uint8_t *const src[], const int srcStride[] SwsInternal *const ctx = c->parent ? sws_internal(c->parent) : c; if (flags & SWS_PRINT_INFO && !atomic_exchange_explicit(&ctx->stride_unaligned_warned, 1, memory_order_relaxed)) { - av_log(c, AV_LOG_WARNING, + av_log(c->sws, AV_LOG_WARNING, "Warning: dstStride is not aligned!\n" " ->cannot do aligned memory accesses anymore\n"); } @@ -337,7 +337,7 @@ int ff_swscale(SwsInternal *c, const uint8_t *const src[], const int srcStride[] int cpu_flags = av_get_cpu_flags(); if (flags & SWS_PRINT_INFO && HAVE_MMXEXT && (cpu_flags & AV_CPU_FLAG_SSE2) && !atomic_exchange_explicit(&ctx->stride_unaligned_warned,1, memory_order_relaxed)) { - av_log(c, AV_LOG_WARNING, "Warning: data is not aligned! This can lead to a speed loss\n"); + av_log(c->sws, AV_LOG_WARNING, "Warning: data is not aligned! This can lead to a speed loss\n"); } } #endif @@ -364,10 +364,10 @@ int ff_swscale(SwsInternal *c, const uint8_t *const src[], const int srcStride[] ff_init_vscale_pfn(c, yuv2plane1, yuv2planeX, yuv2nv12cX, yuv2packed1, yuv2packed2, yuv2packedX, yuv2anyX, c->use_mmx_vfilter); - ff_init_slice_from_src(src_slice, (uint8_t**)src2, srcStride2, c->srcW, + ff_init_slice_from_src(src_slice, (uint8_t**)src2, srcStride2, c->sws->src_w, srcSliceY, srcSliceH, chrSrcSliceY, chrSrcSliceH, 1); - ff_init_slice_from_src(vout_slice, (uint8_t**)dst, dstStride, c->dstW, + ff_init_slice_from_src(vout_slice, (uint8_t**)dst, dstStride, c->sws->dst_w, dstY, dstSliceH, dstY >> c->chrDstVSubSample, AV_CEIL_RSHIFT(dstSliceH, c->chrDstVSubSample), scale_dst); if (srcSliceY == 0) { @@ -389,13 +389,13 @@ int ff_swscale(SwsInternal *c, const uint8_t *const src[], const int srcStride[] // First line needed as input const int firstLumSrcY = FFMAX(1 - vLumFilterSize, vLumFilterPos[dstY]); - const int firstLumSrcY2 = FFMAX(1 - vLumFilterSize, vLumFilterPos[FFMIN(dstY | ((1 << c->chrDstVSubSample) - 1), c->dstH - 1)]); + const int firstLumSrcY2 = FFMAX(1 - vLumFilterSize, vLumFilterPos[FFMIN(dstY | ((1 << c->chrDstVSubSample) - 1), c->sws->dst_h - 1)]); // First line needed as input const int firstChrSrcY = FFMAX(1 - vChrFilterSize, vChrFilterPos[chrDstY]); // Last line needed as input - int lastLumSrcY = FFMIN(c->srcH, firstLumSrcY + vLumFilterSize) - 1; - int lastLumSrcY2 = FFMIN(c->srcH, firstLumSrcY2 + vLumFilterSize) - 1; + int lastLumSrcY = FFMIN(c->sws->src_h, firstLumSrcY + vLumFilterSize) - 1; + int lastLumSrcY2 = FFMIN(c->sws->src_h, firstLumSrcY2 + vLumFilterSize) - 1; int lastChrSrcY = FFMIN(c->chrSrcH, firstChrSrcY + vChrFilterSize) - 1; int enough_lines; @@ -488,13 +488,13 @@ int ff_swscale(SwsInternal *c, const uint8_t *const src[], const int srcStride[] #if HAVE_MMX_INLINE ff_updateMMXDitherTables(c, dstY); - c->dstW_mmx = c->dstW; + c->dstW_mmx = c->sws->dst_w; #endif if (should_dither) { c->chrDither8 = ff_dither_8x8_128[chrDstY & 7]; c->lumDither8 = ff_dither_8x8_128[dstY & 7]; } - if (dstY >= c->dstH - 2) { + if (dstY >= c->sws->dst_h - 2) { /* hmm looks like we can't use MMX here without overwriting * this array's tail */ ff_sws_init_output_funcs(c, &yuv2plane1, &yuv2planeX, &yuv2nv12cX, @@ -544,9 +544,9 @@ av_cold void ff_sws_init_range_convert(SwsInternal *c) { c->lumConvertRange = NULL; c->chrConvertRange = NULL; - if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) { + if (c->sws->src_range != c->sws->dst_range && !isAnyRGB(c->sws->dst_format)) { if (c->dstBpc <= 14) { - if (c->srcRange) { + if (c->sws->src_range) { c->lumConvertRange = lumRangeFromJpeg_c; c->chrConvertRange = chrRangeFromJpeg_c; } else { @@ -554,7 +554,7 @@ av_cold void ff_sws_init_range_convert(SwsInternal *c) c->chrConvertRange = chrRangeToJpeg_c; } } else { - if (c->srcRange) { + if (c->sws->src_range) { c->lumConvertRange = lumRangeFromJpeg16_c; c->chrConvertRange = chrRangeFromJpeg16_c; } else { @@ -567,7 +567,7 @@ av_cold void ff_sws_init_range_convert(SwsInternal *c) static av_cold void sws_init_swscale(SwsInternal *c) { - enum AVPixelFormat srcFormat = c->srcFormat; + enum AVPixelFormat srcFormat = c->sws->src_format; ff_sws_init_output_funcs(c, &c->yuv2plane1, &c->yuv2planeX, &c->yuv2nv12cX, &c->yuv2packed1, @@ -579,7 +579,7 @@ static av_cold void sws_init_swscale(SwsInternal *c) if (c->srcBpc == 8) { if (c->dstBpc <= 14) { c->hyScale = c->hcScale = hScale8To15_c; - if (c->flags & SWS_FAST_BILINEAR) { + if (c->sws->flags & SWS_FAST_BILINEAR) { c->hyscale_fast = ff_hyscale_fast_c; c->hcscale_fast = ff_hcscale_fast_c; } @@ -593,7 +593,7 @@ static av_cold void sws_init_swscale(SwsInternal *c) ff_sws_init_range_convert(c); - if (!(isGray(srcFormat) || isGray(c->dstFormat) || + if (!(isGray(srcFormat) || isGray(c->sws->dst_format) || srcFormat == AV_PIX_FMT_MONOBLACK || srcFormat == AV_PIX_FMT_MONOWHITE)) c->needs_hcscale = 1; } @@ -649,7 +649,7 @@ static int check_image_pointers(const uint8_t * const data[4], enum AVPixelForma void ff_xyz12Torgb48(const SwsInternal *c, uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->src_format); for (int yp = 0; yp < h; yp++) { const uint16_t *src16 = (const uint16_t *) src; @@ -708,7 +708,7 @@ void ff_xyz12Torgb48(const SwsInternal *c, uint8_t *dst, int dst_stride, void ff_rgb48Toxyz12(const SwsInternal *c, uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->sws->dst_format); for (int yp = 0; yp < h; yp++) { uint16_t *src16 = (uint16_t *) src; @@ -768,28 +768,28 @@ void ff_update_palette(SwsInternal *c, const uint32_t *pal) { for (int i = 0; i < 256; i++) { int r, g, b, y, u, v, a = 0xff; - if (c->srcFormat == AV_PIX_FMT_PAL8) { + if (c->sws->src_format == AV_PIX_FMT_PAL8) { uint32_t p = pal[i]; a = (p >> 24) & 0xFF; r = (p >> 16) & 0xFF; g = (p >> 8) & 0xFF; b = p & 0xFF; - } else if (c->srcFormat == AV_PIX_FMT_RGB8) { + } else if (c->sws->src_format == AV_PIX_FMT_RGB8) { r = ( i >> 5 ) * 36; g = ((i >> 2) & 7) * 36; b = ( i & 3) * 85; - } else if (c->srcFormat == AV_PIX_FMT_BGR8) { + } else if (c->sws->src_format == AV_PIX_FMT_BGR8) { b = ( i >> 6 ) * 85; g = ((i >> 3) & 7) * 36; r = ( i & 7) * 36; - } else if (c->srcFormat == AV_PIX_FMT_RGB4_BYTE) { + } else if (c->sws->src_format == AV_PIX_FMT_RGB4_BYTE) { r = ( i >> 3 ) * 255; g = ((i >> 1) & 3) * 85; b = ( i & 1) * 255; - } else if (c->srcFormat == AV_PIX_FMT_GRAY8 || c->srcFormat == AV_PIX_FMT_GRAY8A) { + } else if (c->sws->src_format == AV_PIX_FMT_GRAY8 || c->sws->src_format == AV_PIX_FMT_GRAY8A) { r = g = b = i; } else { - av_assert1(c->srcFormat == AV_PIX_FMT_BGR4_BYTE); + av_assert1(c->sws->src_format == AV_PIX_FMT_BGR4_BYTE); b = ( i >> 3 ) * 255; g = ((i >> 1) & 3) * 85; r = ( i & 1) * 255; @@ -810,7 +810,7 @@ void ff_update_palette(SwsInternal *c, const uint32_t *pal) v = av_clip_uint8((RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT); c->pal_yuv[i]= y + (u<<8) + (v<<16) + ((unsigned)a<<24); - switch (c->dstFormat) { + switch (c->sws->dst_format) { case AV_PIX_FMT_BGR32: #if !HAVE_BIGENDIAN case AV_PIX_FMT_RGB24: @@ -853,7 +853,7 @@ static int scale_gamma(SwsInternal *c, { int ret = scale_internal(c->cascaded_context[0], srcSlice, srcStride, srcSliceY, srcSliceH, - c->cascaded_tmp[0], c->cascaded_tmpStride[0], 0, c->srcH); + c->cascaded_tmp[0], c->cascaded_tmpStride[0], 0, c->sws->src_h); if (ret < 0) return ret; @@ -861,7 +861,7 @@ static int scale_gamma(SwsInternal *c, if (c->cascaded_context[2]) ret = scale_internal(c->cascaded_context[1], (const uint8_t * const *)c->cascaded_tmp[0], c->cascaded_tmpStride[0], srcSliceY, srcSliceH, - c->cascaded_tmp[1], c->cascaded_tmpStride[1], 0, c->dstH); + c->cascaded_tmp[1], c->cascaded_tmpStride[1], 0, c->sws->dst_h); else ret = scale_internal(c->cascaded_context[1], (const uint8_t * const *)c->cascaded_tmp[0], c->cascaded_tmpStride[0], srcSliceY, srcSliceH, @@ -885,7 +885,7 @@ static int scale_cascaded(SwsInternal *c, uint8_t * const dstSlice[], const int dstStride[], int dstSliceY, int dstSliceH) { - const int dstH0 = sws_internal(c->cascaded_context[0])->dstH; + const int dstH0 = c->cascaded_context[0]->dst_h; int ret = scale_internal(c->cascaded_context[0], srcSlice, srcStride, srcSliceY, srcSliceH, c->cascaded_tmp[0], c->cascaded_tmpStride[0], @@ -905,44 +905,44 @@ static int scale_internal(SwsContext *sws, int dstSliceY, int dstSliceH) { SwsInternal *c = sws_internal(sws); - const int scale_dst = dstSliceY > 0 || dstSliceH < c->dstH; + const int scale_dst = dstSliceY > 0 || dstSliceH < sws->dst_h; const int frame_start = scale_dst || !c->sliceDir; int i, ret; const uint8_t *src2[4]; uint8_t *dst2[4]; - int macro_height_src = isBayer(c->srcFormat) ? 2 : (1 << c->chrSrcVSubSample); - int macro_height_dst = isBayer(c->dstFormat) ? 2 : (1 << c->chrDstVSubSample); + int macro_height_src = isBayer(sws->src_format) ? 2 : (1 << c->chrSrcVSubSample); + int macro_height_dst = isBayer(sws->dst_format) ? 2 : (1 << c->chrDstVSubSample); // copy strides, so they can safely be modified int srcStride2[4]; int dstStride2[4]; int srcSliceY_internal = srcSliceY; if (!srcStride || !dstStride || !dstSlice || !srcSlice) { - av_log(c, AV_LOG_ERROR, "One of the input parameters to sws_scale() is NULL, please check the calling code\n"); + av_log(sws, AV_LOG_ERROR, "One of the input parameters to sws_scale() is NULL, please check the calling code\n"); return AVERROR(EINVAL); } if ((srcSliceY & (macro_height_src - 1)) || - ((srcSliceH & (macro_height_src - 1)) && srcSliceY + srcSliceH != c->srcH) || - srcSliceY + srcSliceH > c->srcH || - (isBayer(c->srcFormat) && srcSliceH <= 1)) { - av_log(c, AV_LOG_ERROR, "Slice parameters %d, %d are invalid\n", srcSliceY, srcSliceH); + ((srcSliceH & (macro_height_src - 1)) && srcSliceY + srcSliceH != sws->src_h) || + srcSliceY + srcSliceH > sws->src_h || + (isBayer(sws->src_format) && srcSliceH <= 1)) { + av_log(sws, AV_LOG_ERROR, "Slice parameters %d, %d are invalid\n", srcSliceY, srcSliceH); return AVERROR(EINVAL); } if ((dstSliceY & (macro_height_dst - 1)) || - ((dstSliceH & (macro_height_dst - 1)) && dstSliceY + dstSliceH != c->dstH) || - dstSliceY + dstSliceH > c->dstH) { - av_log(c, AV_LOG_ERROR, "Slice parameters %d, %d are invalid\n", dstSliceY, dstSliceH); + ((dstSliceH & (macro_height_dst - 1)) && dstSliceY + dstSliceH != sws->dst_h) || + dstSliceY + dstSliceH > sws->dst_h) { + av_log(sws, AV_LOG_ERROR, "Slice parameters %d, %d are invalid\n", dstSliceY, dstSliceH); return AVERROR(EINVAL); } - if (!check_image_pointers(srcSlice, c->srcFormat, srcStride)) { - av_log(c, AV_LOG_ERROR, "bad src image pointers\n"); + if (!check_image_pointers(srcSlice, sws->src_format, srcStride)) { + av_log(sws, AV_LOG_ERROR, "bad src image pointers\n"); return AVERROR(EINVAL); } - if (!check_image_pointers((const uint8_t* const*)dstSlice, c->dstFormat, dstStride)) { - av_log(c, AV_LOG_ERROR, "bad dst image pointers\n"); + if (!check_image_pointers((const uint8_t* const*)dstSlice, sws->dst_format, dstStride)) { + av_log(sws, AV_LOG_ERROR, "bad dst image pointers\n"); return AVERROR(EINVAL); } @@ -950,22 +950,19 @@ static int scale_internal(SwsContext *sws, if (srcSliceH == 0) return 0; - if (c->gamma_flag && c->cascaded_context[0]) + if (sws->gamma_flag && c->cascaded_context[0]) return scale_gamma(c, srcSlice, srcStride, srcSliceY, srcSliceH, dstSlice, dstStride, dstSliceY, dstSliceH); - if (c->cascaded_context[0] && srcSliceY == 0 && - srcSliceH == sws_internal(c->cascaded_context[0])->srcH) - { + if (c->cascaded_context[0] && srcSliceY == 0 && srcSliceH == c->cascaded_context[0]->src_h) return scale_cascaded(c, srcSlice, srcStride, srcSliceY, srcSliceH, dstSlice, dstStride, dstSliceY, dstSliceH); - } - if (!srcSliceY && (c->flags & SWS_BITEXACT) && c->dither == SWS_DITHER_ED && c->dither_error[0]) + if (!srcSliceY && (sws->flags & SWS_BITEXACT) && sws->dither == SWS_DITHER_ED && c->dither_error[0]) for (i = 0; i < 4; i++) - memset(c->dither_error[i], 0, sizeof(c->dither_error[0][0]) * (c->dstW+2)); + memset(c->dither_error[i], 0, sizeof(c->dither_error[0][0]) * (sws->dst_w+2)); - if (usePal(c->srcFormat)) + if (usePal(sws->src_format)) ff_update_palette(c, (const uint32_t *)srcSlice[1]); memcpy(src2, srcSlice, sizeof(src2)); @@ -974,8 +971,8 @@ static int scale_internal(SwsContext *sws, memcpy(dstStride2, dstStride, sizeof(dstStride2)); if (frame_start && !scale_dst) { - if (srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) { - av_log(c, AV_LOG_ERROR, "Slices start in the middle!\n"); + if (srcSliceY != 0 && srcSliceY + srcSliceH != sws->src_h) { + av_log(sws, AV_LOG_ERROR, "Slices start in the middle!\n"); return AVERROR(EINVAL); } @@ -983,7 +980,7 @@ static int scale_internal(SwsContext *sws, } else if (scale_dst) c->sliceDir = 1; - if (c->src0Alpha && !c->dst0Alpha && isALPHA(c->dstFormat)) { + if (c->src0Alpha && !c->dst0Alpha && isALPHA(sws->dst_format)) { uint8_t *base; int x,y; @@ -995,15 +992,15 @@ static int scale_internal(SwsContext *sws, base = srcStride[0] < 0 ? c->rgb0_scratch - srcStride[0] * (srcSliceH-1) : c->rgb0_scratch; for (y=0; ysrcW); - for (x=c->src0Alpha-1; x<4*c->srcW; x+=4) { + memcpy(base + srcStride[0]*y, src2[0] + srcStride[0]*y, 4*sws->src_w); + for (x=c->src0Alpha-1; x<4*sws->src_w; x+=4) { base[ srcStride[0]*y + x] = 0xFF; } } src2[0] = base; } - if (c->srcXYZ && !(c->dstXYZ && c->srcW==c->dstW && c->srcH==c->dstH)) { + if (c->srcXYZ && !(c->dstXYZ && sws->src_w==sws->dst_w && sws->src_h==sws->dst_h)) { uint8_t *base; av_fast_malloc(&c->xyz_scratch, &c->xyz_scratch_allocated, @@ -1014,7 +1011,7 @@ static int scale_internal(SwsContext *sws, base = srcStride[0] < 0 ? c->xyz_scratch - srcStride[0] * (srcSliceH-1) : c->xyz_scratch; - ff_xyz12Torgb48(c, base, srcStride[0], src2[0], srcStride[0], c->srcW, srcSliceH); + ff_xyz12Torgb48(c, base, srcStride[0], src2[0], srcStride[0], sws->src_w, srcSliceH); src2[0] = base; } @@ -1026,19 +1023,19 @@ static int scale_internal(SwsContext *sws, } src2[0] += (srcSliceH - 1) * srcStride[0]; - if (!usePal(c->srcFormat)) + if (!usePal(sws->src_format)) src2[1] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[1]; src2[2] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[2]; src2[3] += (srcSliceH - 1) * srcStride[3]; - dst2[0] += ( c->dstH - 1) * dstStride[0]; - dst2[1] += ((c->dstH >> c->chrDstVSubSample) - 1) * dstStride[1]; - dst2[2] += ((c->dstH >> c->chrDstVSubSample) - 1) * dstStride[2]; - dst2[3] += ( c->dstH - 1) * dstStride[3]; + dst2[0] += ( sws->dst_h - 1) * dstStride[0]; + dst2[1] += ((sws->dst_h >> c->chrDstVSubSample) - 1) * dstStride[1]; + dst2[2] += ((sws->dst_h >> c->chrDstVSubSample) - 1) * dstStride[2]; + dst2[3] += ( sws->dst_h - 1) * dstStride[3]; - srcSliceY_internal = c->srcH-srcSliceY-srcSliceH; + srcSliceY_internal = sws->src_h-srcSliceY-srcSliceH; } - reset_ptr(src2, c->srcFormat); - reset_ptr((void*)dst2, c->dstFormat); + reset_ptr(src2, sws->src_format); + reset_ptr((void*)dst2, sws->dst_format); if (c->convert_unscaled) { int offset = srcSliceY_internal; @@ -1048,13 +1045,13 @@ static int scale_internal(SwsContext *sws, if (scale_dst) { av_assert0(offset == 0); for (i = 0; i < 4 && src2[i]; i++) { - if (!src2[i] || (i > 0 && usePal(c->srcFormat))) + if (!src2[i] || (i > 0 && usePal(sws->src_format))) break; src2[i] += (dstSliceY >> ((i == 1 || i == 2) ? c->chrSrcVSubSample : 0)) * srcStride2[i]; } for (i = 0; i < 4 && dst2[i]; i++) { - if (!dst2[i] || (i > 0 && usePal(c->dstFormat))) + if (!dst2[i] || (i > 0 && usePal(sws->dst_format))) break; dst2[i] -= (dstSliceY >> ((i == 1 || i == 2) ? c->chrDstVSubSample : 0)) * dstStride2[i]; } @@ -1071,7 +1068,7 @@ static int scale_internal(SwsContext *sws, dst2, dstStride2, dstSliceY, dstSliceH); } - if (c->dstXYZ && !(c->srcXYZ && c->srcW==c->dstW && c->srcH==c->dstH)) { + if (c->dstXYZ && !(c->srcXYZ && sws->src_w==sws->dst_w && sws->src_h==sws->dst_h)) { uint8_t *dst; if (scale_dst) { @@ -1081,16 +1078,16 @@ static int scale_internal(SwsContext *sws, av_assert0(dstY >= ret); av_assert0(ret >= 0); - av_assert0(c->dstH >= dstY); + av_assert0(sws->dst_h >= dstY); dst = dst2[0] + (dstY - ret) * dstStride2[0]; } /* replace on the same data */ - ff_rgb48Toxyz12(c, dst, dstStride2[0], dst, dstStride2[0], c->dstW, ret); + ff_rgb48Toxyz12(c, dst, dstStride2[0], dst, dstStride2[0], sws->dst_w, ret); } /* reset slice direction at end of frame */ - if ((srcSliceY_internal + srcSliceH == c->srcH) || scale_dst) + if ((srcSliceY_internal + srcSliceH == sws->src_h) || scale_dst) c->sliceDir = 0; return ret; @@ -1114,9 +1111,9 @@ int sws_frame_start(SwsContext *sws, AVFrame *dst, const AVFrame *src) return ret; if (!dst->buf[0]) { - dst->width = c->dstW; - dst->height = c->dstH; - dst->format = c->dstFormat; + dst->width = sws->dst_w; + dst->height = sws->dst_h; + dst->format = sws->dst_format; ret = av_frame_get_buffer(dst, 0); if (ret < 0) @@ -1167,12 +1164,12 @@ int sws_receive_slice(SwsContext *sws, unsigned int slice_start, /* wait until complete input has been received */ if (!(c->src_ranges.nb_ranges == 1 && c->src_ranges.ranges[0].start == 0 && - c->src_ranges.ranges[0].len == c->srcH)) + c->src_ranges.ranges[0].len == sws->src_h)) return AVERROR(EAGAIN); - if ((slice_start > 0 || slice_height < c->dstH) && + if ((slice_start > 0 || slice_height < sws->dst_h) && (slice_start % align || slice_height % align)) { - av_log(c, AV_LOG_ERROR, + av_log(sws, AV_LOG_ERROR, "Incorrectly aligned output: %u/%u not multiples of %u\n", slice_start, slice_height, align); return AVERROR(EINVAL); @@ -1182,7 +1179,7 @@ int sws_receive_slice(SwsContext *sws, unsigned int slice_start, int nb_jobs = c->nb_slice_ctx; int ret = 0; - if (sws_internal(c->slice_ctx[0])->dither == SWS_DITHER_ED) + if (c->slice_ctx[0]->dither == SWS_DITHER_ED) nb_jobs = 1; c->dst_slice_start = slice_start; @@ -1208,7 +1205,7 @@ int sws_receive_slice(SwsContext *sws, unsigned int slice_start, } return scale_internal(sws, (const uint8_t * const *)c->frame_src->data, - c->frame_src->linesize, 0, c->srcH, + c->frame_src->linesize, 0, sws->src_h, dst, c->frame_dst->linesize, slice_start, slice_height); } @@ -1246,13 +1243,13 @@ int attribute_align_arg sws_scale(SwsContext *sws, } return scale_internal(sws, srcSlice, srcStride, srcSliceY, srcSliceH, - dst, dstStride, 0, c->dstH); + dst, dstStride, 0, sws->dst_h); } void ff_sws_slice_worker(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads) { - SwsInternal *parent = priv; + SwsInternal *parent = sws_internal(priv); SwsContext *sws = parent->slice_ctx[threadnr]; SwsInternal *c = sws_internal(sws); @@ -1274,7 +1271,7 @@ void ff_sws_slice_worker(void *priv, int jobnr, int threadnr, } err = scale_internal(sws, (const uint8_t * const *)parent->frame_src->data, - parent->frame_src->linesize, 0, c->srcH, + parent->frame_src->linesize, 0, sws->src_h, dst, parent->frame_dst->linesize, parent->dst_slice_start + slice_start, slice_end - slice_start); } diff --git a/libswscale/swscale.h b/libswscale/swscale.h index f544387769..0718469a73 100644 --- a/libswscale/swscale.h +++ b/libswscale/swscale.h @@ -42,8 +42,6 @@ #include "version.h" #endif -typedef struct SwsContext SwsContext; - /** * @defgroup libsws libswscale * Color conversion and scaling library. @@ -65,17 +63,103 @@ const char *swscale_configuration(void); const char *swscale_license(void); /** - * Get the AVClass for swsContext. It can be used in combination with + * Get the AVClass for SwsContext. It can be used in combination with * AV_OPT_SEARCH_FAKE_OBJ for examining options. * * @see av_opt_find(). */ const AVClass *sws_get_class(void); -/** - * Allocate an empty SwsContext. This must be filled and passed to - * sws_init_context(). For filling see AVOptions, options.c and - * sws_setColorspaceDetails(). +/****************************** + * Flags and quality settings * + ******************************/ + +typedef enum SwsDither { + SWS_DITHER_NONE = 0, /* disable dithering */ + SWS_DITHER_AUTO, /* auto-select from preset */ + SWS_DITHER_BAYER, /* ordered dither matrix */ + SWS_DITHER_ED, /* error diffusion */ + SWS_DITHER_A_DITHER, /* arithmetic addition */ + SWS_DITHER_X_DITHER, /* arithmetic xor */ + SWS_DITHER_NB, /* not part of the ABI */ +} SwsDither; + +typedef enum SwsAlphaBlend { + SWS_ALPHA_BLEND_NONE = 0, + SWS_ALPHA_BLEND_UNIFORM, + SWS_ALPHA_BLEND_CHECKERBOARD, + SWS_ALPHA_BLEND_NB, /* not part of the ABI */ +} SwsAlphaBlend; + +/*********************************** + * Context creation and management * + ***********************************/ + +/** + * Main external API structure. New fields can be added to the end with + * minor version bumps. Removal, reordering and changes to existing fields + * require a major version bump. sizeof(SwsContext) is not part of the ABI. + */ +typedef struct SwsContext { + const AVClass *av_class; + + /** + * Private context used for internal data. + */ + struct SwsInternal *internal; + + /** + * Private data of the user, can be used to carry app specific stuff. + */ + void *opaque; + + /** + * Bitmask of SWS_*. + */ + unsigned flags; + + /** + * Extra parameters for fine-tuning certain scalers. + */ + double scaler_params[2]; + + /** + * How many threads to use for processing, or 0 for automatic selection. + */ + int threads; + + /** + * Dither mode. + */ + SwsDither dither; + + /** + * Alpha blending mode. See `SwsAlphaBlend` for details. + */ + SwsAlphaBlend alpha_blend; + + /** + * Use gamma correct scaling. + */ + int gamma_flag; + + /** + * Frame property overrides. + */ + int src_w, src_h; ///< Width and height of the source frame + int dst_w, dst_h; ///< Width and height of the destination frame + int src_format; ///< Source pixel format + int dst_format; ///< Destination pixel format + int src_range; ///< Source is full range + int dst_range; ///< Destination is full range + int src_v_chr_pos; ///< Source vertical chroma position in luma grid / 256 + int src_h_chr_pos; ///< Source horizontal chroma position + int dst_v_chr_pos; ///< Destination vertical chroma position + int dst_h_chr_pos; ///< Destination horizontal chroma position +} SwsContext; + +/** + * Allocate an empty SwsContext and set its fields to default values. */ SwsContext *sws_alloc_context(void); diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index 6b85ecadae..1f95966bd1 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -70,26 +70,9 @@ typedef struct SwsInternal SwsInternal; static inline SwsInternal *sws_internal(const SwsContext *sws) { - return (SwsInternal *) sws; + return sws ? sws->internal : NULL; } -typedef enum SwsDither { - SWS_DITHER_NONE = 0, - SWS_DITHER_AUTO, - SWS_DITHER_BAYER, - SWS_DITHER_ED, - SWS_DITHER_A_DITHER, - SWS_DITHER_X_DITHER, - SWS_DITHER_NB, -} SwsDither; - -typedef enum SwsAlphaBlend { - SWS_ALPHA_BLEND_NONE = 0, - SWS_ALPHA_BLEND_UNIFORM, - SWS_ALPHA_BLEND_CHECKERBOARD, - SWS_ALPHA_BLEND_NB, -} SwsAlphaBlend; - typedef struct Range { unsigned int start; unsigned int len; @@ -329,11 +312,10 @@ struct SwsFilterDescriptor; /* This struct should be aligned on at least a 32-byte boundary. */ struct SwsInternal { - /** - * info on struct for av_log - */ - const AVClass *av_class; + /* Associated context/options, for convenience use by leaf functions */ + SwsContext *sws; + /* Parent context (for slice contexts) */ SwsContext *parent; AVSliceThread *slicethread; @@ -350,18 +332,12 @@ struct SwsInternal { * sws_scale() wrapper so they can be freely modified here. */ SwsFunc convert_unscaled; - int srcW; ///< Width of source luma/alpha planes. - int srcH; ///< Height of source luma/alpha planes. - int dstW; ///< Width of destination luma/alpha planes. - int dstH; ///< Height of destination luma/alpha planes. int chrSrcW; ///< Width of source chroma planes. int chrSrcH; ///< Height of source chroma planes. int chrDstW; ///< Width of destination chroma planes. int chrDstH; ///< Height of destination chroma planes. int lumXInc, chrXInc; int lumYInc, chrYInc; - enum AVPixelFormat dstFormat; ///< Destination pixel format. - enum AVPixelFormat srcFormat; ///< Source pixel format. int dstFormatBpp; ///< Number of bits per pixel of the destination pixel format. int srcFormatBpp; ///< Number of bits per pixel of the source pixel format. int dstBpc, srcBpc; @@ -371,8 +347,6 @@ struct SwsInternal { int chrDstVSubSample; ///< Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in destination image. int vChrDrop; ///< Binary logarithm of extra vertical subsampling factor in source image chroma planes specified by user. int sliceDir; ///< Direction that slices are fed to the scaler (1 = top-to-bottom, -1 = bottom-to-top). - int nb_threads; ///< Number of threads used for scaling - double param[2]; ///< Input parameters for scaling algorithms that need them. AVFrame *frame_src; AVFrame *frame_dst; @@ -389,7 +363,6 @@ struct SwsInternal { int cascaded_mainindex; double gamma_value; - int gamma_flag; int is_internal_gamma; uint16_t *gamma; uint16_t *inv_gamma; @@ -459,7 +432,6 @@ struct SwsInternal { int warned_unuseable_bilinear; int dstY; ///< Last destination vertical line output from last slice. - int flags; ///< Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc... void *yuvTable; // pointer to the yuv->rgb table start so it can be freed() // alignment ensures the offset can be added in a single // instruction on e.g. ARM @@ -485,16 +457,10 @@ struct SwsInternal { int contrast, brightness, saturation; // for sws_getColorspaceDetails int srcColorspaceTable[4]; int dstColorspaceTable[4]; - int srcRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (source image). - int dstRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (destination image). int src0Alpha; int dst0Alpha; int srcXYZ; int dstXYZ; - int src_h_chr_pos; - int dst_h_chr_pos; - int src_v_chr_pos; - int dst_v_chr_pos; int yuv2rgb_y_offset; int yuv2rgb_y_coeff; int yuv2rgb_v2r_coeff; @@ -682,10 +648,6 @@ struct SwsInternal { int needs_hcscale; ///< Set if there are chroma planes to be converted. - SwsDither dither; - - SwsAlphaBlend alphablend; - // scratch buffer for converting packed rgb0 sources // filled with a copy of the input frame + fully opaque alpha, // then passed as input to further conversion @@ -712,7 +674,7 @@ static_assert(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInt #if ARCH_X86_64 /* x86 yuv2gbrp uses the SwsInternal for yuv coefficients if struct offsets change the asm needs to be updated too */ -static_assert(offsetof(SwsInternal, yuv2rgb_y_offset) == 40292, +static_assert(offsetof(SwsInternal, yuv2rgb_y_offset) == 40332, "yuv2rgb_y_offset must be updated in x86 asm"); #endif diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c index 1a293483c4..ca3f9476c4 100644 --- a/libswscale/swscale_unscaled.c +++ b/libswscale/swscale_unscaled.c @@ -146,10 +146,10 @@ static int planarToNv12Wrapper(SwsInternal *c, const uint8_t *const src[], { uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY / 2; - ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW, + ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->sws->src_w, dstParam[0], dstStride[0]); - if (c->dstFormat == AV_PIX_FMT_NV12) + if (c->sws->dst_format == AV_PIX_FMT_NV12) interleaveBytes(src[1], src[2], dst, c->chrSrcW, (srcSliceH + 1) / 2, srcStride[1], srcStride[2], dstStride[1]); else @@ -167,10 +167,10 @@ static int nv12ToPlanarWrapper(SwsInternal *c, const uint8_t *const src[], uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY / 2; uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY / 2; - ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW, + ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->sws->src_w, dstParam[0], dstStride[0]); - if (c->srcFormat == AV_PIX_FMT_NV12) + if (c->sws->src_format == AV_PIX_FMT_NV12) deinterleaveBytes(src[1], dst1, dst2, c->chrSrcW, (srcSliceH + 1) / 2, srcStride[1], dstStride[1], dstStride[2]); else @@ -187,10 +187,10 @@ static int planarToNv24Wrapper(SwsInternal *c, const uint8_t *const src[], { uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY; - ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW, + ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->sws->src_w, dstParam[0], dstStride[0]); - if (c->dstFormat == AV_PIX_FMT_NV24) + if (c->sws->dst_format == AV_PIX_FMT_NV24) interleaveBytes(src[1], src[2], dst, c->chrSrcW, srcSliceH, srcStride[1], srcStride[2], dstStride[1]); else @@ -208,10 +208,10 @@ static int nv24ToPlanarWrapper(SwsInternal *c, const uint8_t *const src[], uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY; uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY; - ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW, + ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->sws->src_w, dstParam[0], dstStride[0]); - if (c->srcFormat == AV_PIX_FMT_NV24) + if (c->sws->src_format == AV_PIX_FMT_NV24) deinterleaveBytes(src[1], dst1, dst2, c->chrSrcW, srcSliceH, srcStride[1], dstStride[1], dstStride[2]); else @@ -250,15 +250,15 @@ static int nv24ToYuv420Wrapper(SwsInternal *c, const uint8_t *const src[], uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY / 2; uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY / 2; - ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW, + ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->sws->src_w, dstParam[0], dstStride[0]); - if (c->srcFormat == AV_PIX_FMT_NV24) + if (c->sws->src_format == AV_PIX_FMT_NV24) nv24_to_yuv420p_chroma(dst1, dstStride[1], dst2, dstStride[2], - src[1], srcStride[1], c->srcW / 2, srcSliceH); + src[1], srcStride[1], c->sws->src_w / 2, srcSliceH); else nv24_to_yuv420p_chroma(dst2, dstStride[2], dst1, dstStride[1], - src[1], srcStride[1], c->srcW / 2, srcSliceH); + src[1], srcStride[1], c->sws->src_w / 2, srcSliceH); return srcSliceH; } @@ -268,8 +268,8 @@ static int planarToP01xWrapper(SwsInternal *c, const uint8_t *const src8[], int srcSliceH, uint8_t *const dstParam8[], const int dstStride[]) { - const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->srcFormat); - const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->dstFormat); + const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->sws->src_format); + const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->sws->dst_format); const uint16_t **src = (const uint16_t**)src8; uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY); uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2); @@ -291,7 +291,7 @@ static int planarToP01xWrapper(SwsInternal *c, const uint8_t *const src8[], for (y = 0; y < srcSliceH; y++) { uint16_t *tdstY = dstY; const uint16_t *tsrc0 = src[0]; - for (x = c->srcW; x > 0; x--) { + for (x = c->sws->src_w; x > 0; x--) { *tdstY++ = *tsrc0++ << shift[0]; } src[0] += srcStride[0] / 2; @@ -301,7 +301,7 @@ static int planarToP01xWrapper(SwsInternal *c, const uint8_t *const src8[], uint16_t *tdstUV = dstUV; const uint16_t *tsrc1 = src[1]; const uint16_t *tsrc2 = src[2]; - for (x = c->srcW / 2; x > 0; x--) { + for (x = c->sws->src_w / 2; x > 0; x--) { *tdstUV++ = *tsrc1++ << shift[1]; *tdstUV++ = *tsrc2++ << shift[2]; } @@ -338,7 +338,7 @@ static int planar8ToP01xleWrapper(SwsInternal *c, const uint8_t *const src[], for (y = 0; y < srcSliceH; y++) { uint16_t *tdstY = dstY; const uint8_t *tsrc0 = src0; - for (x = c->srcW; x > 0; x--) { + for (x = c->sws->src_w; x > 0; x--) { t = *tsrc0++; output_pixel(tdstY++, t | (t << 8)); } @@ -349,7 +349,7 @@ static int planar8ToP01xleWrapper(SwsInternal *c, const uint8_t *const src[], uint16_t *tdstUV = dstUV; const uint8_t *tsrc1 = src1; const uint8_t *tsrc2 = src2; - for (x = c->srcW / 2; x > 0; x--) { + for (x = c->sws->src_w / 2; x > 0; x--) { t = *tsrc1++; output_pixel(tdstUV++, t | (t << 8)); t = *tsrc2++; @@ -372,7 +372,7 @@ static int planarToYuy2Wrapper(SwsInternal *c, const uint8_t *const src[], { uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY; - yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], + yv12toyuy2(src[0], src[1], src[2], dst, c->sws->src_w, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); return srcSliceH; @@ -384,7 +384,7 @@ static int planarToUyvyWrapper(SwsInternal *c, const uint8_t *const src[], { uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY; - yv12touyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], + yv12touyvy(src[0], src[1], src[2], dst, c->sws->src_w, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); return srcSliceH; @@ -396,7 +396,7 @@ static int yuv422pToYuy2Wrapper(SwsInternal *c, const uint8_t *const src[], { uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY; - yuv422ptoyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], + yuv422ptoyuy2(src[0], src[1], src[2], dst, c->sws->src_w, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); return srcSliceH; @@ -408,7 +408,7 @@ static int yuv422pToUyvyWrapper(SwsInternal *c, const uint8_t *const src[], { uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY; - yuv422ptouyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], + yuv422ptouyvy(src[0], src[1], src[2], dst, c->sws->src_w, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); return srcSliceH; @@ -422,11 +422,11 @@ static int yuyvToYuv420Wrapper(SwsInternal *c, const uint8_t *const src[], uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2; uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2; - yuyvtoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], + yuyvtoyuv420(ydst, udst, vdst, src[0], c->sws->src_w, srcSliceH, dstStride[0], dstStride[1], srcStride[0]); if (dstParam[3]) - fillPlane(dstParam[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255); + fillPlane(dstParam[3], dstStride[3], c->sws->src_w, srcSliceH, srcSliceY, 255); return srcSliceH; } @@ -439,7 +439,7 @@ static int yuyvToYuv422Wrapper(SwsInternal *c, const uint8_t *const src[], uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY; uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY; - yuyvtoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], + yuyvtoyuv422(ydst, udst, vdst, src[0], c->sws->src_w, srcSliceH, dstStride[0], dstStride[1], srcStride[0]); return srcSliceH; @@ -453,11 +453,11 @@ static int uyvyToYuv420Wrapper(SwsInternal *c, const uint8_t *const src[], uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2; uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2; - uyvytoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], + uyvytoyuv420(ydst, udst, vdst, src[0], c->sws->src_w, srcSliceH, dstStride[0], dstStride[1], srcStride[0]); if (dstParam[3]) - fillPlane(dstParam[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255); + fillPlane(dstParam[3], dstStride[3], c->sws->src_w, srcSliceH, srcSliceY, 255); return srcSliceH; } @@ -470,7 +470,7 @@ static int uyvyToYuv422Wrapper(SwsInternal *c, const uint8_t *const src[], uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY; uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY; - uyvytoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], + uyvytoyuv422(ydst, udst, vdst, src[0], c->sws->src_w, srcSliceH, dstStride[0], dstStride[1], srcStride[0]); return srcSliceH; @@ -566,8 +566,8 @@ static int palToRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { - const enum AVPixelFormat srcFormat = c->srcFormat; - const enum AVPixelFormat dstFormat = c->dstFormat; + const enum AVPixelFormat srcFormat = c->sws->src_format; + const enum AVPixelFormat dstFormat = c->sws->dst_format; void (*conv)(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette) = NULL; int i; @@ -595,11 +595,11 @@ static int palToRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int } if (!conv) - av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n", + av_log(c->sws, AV_LOG_ERROR, "internal error %s -> %s converter\n", av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat)); else { for (i = 0; i < srcSliceH; i++) { - conv(srcPtr, dstPtr, c->srcW, (uint8_t *) c->pal_rgb); + conv(srcPtr, dstPtr, c->sws->src_w, (uint8_t *) c->pal_rgb); srcPtr += srcStride[0]; dstPtr += dstStride[0]; } @@ -750,8 +750,8 @@ static int Rgb16ToPlanarRgb16Wrapper(SwsInternal *c, const uint8_t *const src[], uint16_t *dst1023[] = { (uint16_t *)dst[1], (uint16_t *)dst[0], (uint16_t *)dst[2], (uint16_t *)dst[3] }; int stride2013[] = { dstStride[2], dstStride[0], dstStride[1], dstStride[3] }; int stride1023[] = { dstStride[1], dstStride[0], dstStride[2], dstStride[3] }; - const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->srcFormat); - const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->dstFormat); + const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->sws->src_format); + const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->sws->dst_format); int bpc = dst_format->comp[0].depth; int alpha = src_format->flags & AV_PIX_FMT_FLAG_ALPHA; int swap = 0; @@ -766,7 +766,7 @@ static int Rgb16ToPlanarRgb16Wrapper(SwsInternal *c, const uint8_t *const src[], if ((dst_format->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) != (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB) || bpc < 9) { - av_log(c, AV_LOG_ERROR, "unsupported conversion to planar RGB %s -> %s\n", + av_log(c->sws, AV_LOG_ERROR, "unsupported conversion to planar RGB %s -> %s\n", src_format->name, dst_format->name); return srcSliceH; } @@ -776,14 +776,14 @@ static int Rgb16ToPlanarRgb16Wrapper(SwsInternal *c, const uint8_t *const src[], dst1023[i] += stride1023[i] * srcSliceY / 2; } - switch (c->srcFormat) { + switch (c->sws->src_format) { case AV_PIX_FMT_RGB48LE: case AV_PIX_FMT_RGB48BE: case AV_PIX_FMT_RGBA64LE: case AV_PIX_FMT_RGBA64BE: packed16togbra16(src[0], srcStride[0], dst2013, stride2013, srcSliceH, alpha, swap, - 16 - bpc, c->srcW); + 16 - bpc, c->sws->src_w); break; case AV_PIX_FMT_BGR48LE: case AV_PIX_FMT_BGR48BE: @@ -791,10 +791,10 @@ static int Rgb16ToPlanarRgb16Wrapper(SwsInternal *c, const uint8_t *const src[], case AV_PIX_FMT_BGRA64BE: packed16togbra16(src[0], srcStride[0], dst1023, stride1023, srcSliceH, alpha, swap, - 16 - bpc, c->srcW); + 16 - bpc, c->sws->src_w); break; default: - av_log(c, AV_LOG_ERROR, + av_log(c->sws, AV_LOG_ERROR, "unsupported conversion to planar RGB %s -> %s\n", src_format->name, dst_format->name); } @@ -929,8 +929,8 @@ static int planarRgb16ToRgb16Wrapper(SwsInternal *c, const uint8_t *const src[], const uint16_t *src201[] = { (uint16_t *)src[2], (uint16_t *)src[0], (uint16_t *)src[1], (uint16_t *)src[3] }; int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] }; int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] }; - const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->srcFormat); - const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->dstFormat); + const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->sws->src_format); + const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->sws->dst_format); int bits_per_sample = src_format->comp[0].depth; int swap = 0; if ( HAVE_BIGENDIAN && !(src_format->flags & AV_PIX_FMT_FLAG_BE) || @@ -943,37 +943,37 @@ static int planarRgb16ToRgb16Wrapper(SwsInternal *c, const uint8_t *const src[], if ((src_format->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) != (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB) || bits_per_sample <= 8) { - av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n", + av_log(c->sws, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n", src_format->name, dst_format->name); return srcSliceH; } - switch (c->dstFormat) { + switch (c->sws->dst_format) { case AV_PIX_FMT_BGR48LE: case AV_PIX_FMT_BGR48BE: gbr16ptopacked16(src102, stride102, dst[0] + srcSliceY * dstStride[0], dstStride[0], - srcSliceH, 0, swap, bits_per_sample, c->srcW); + srcSliceH, 0, swap, bits_per_sample, c->sws->src_w); break; case AV_PIX_FMT_RGB48LE: case AV_PIX_FMT_RGB48BE: gbr16ptopacked16(src201, stride201, dst[0] + srcSliceY * dstStride[0], dstStride[0], - srcSliceH, 0, swap, bits_per_sample, c->srcW); + srcSliceH, 0, swap, bits_per_sample, c->sws->src_w); break; case AV_PIX_FMT_RGBA64LE: case AV_PIX_FMT_RGBA64BE: gbr16ptopacked16(src201, stride201, dst[0] + srcSliceY * dstStride[0], dstStride[0], - srcSliceH, 1, swap, bits_per_sample, c->srcW); + srcSliceH, 1, swap, bits_per_sample, c->sws->src_w); break; case AV_PIX_FMT_BGRA64LE: case AV_PIX_FMT_BGRA64BE: gbr16ptopacked16(src102, stride102, dst[0] + srcSliceY * dstStride[0], dstStride[0], - srcSliceH, 1, swap, bits_per_sample, c->srcW); + srcSliceH, 1, swap, bits_per_sample, c->sws->src_w); break; default: - av_log(c, AV_LOG_ERROR, + av_log(c->sws, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n", src_format->name, dst_format->name); } @@ -1067,24 +1067,24 @@ static int planarRgbaToRgbWrapper(SwsInternal *c, const uint8_t *const src[], int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] }; int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] }; - if (c->srcFormat != AV_PIX_FMT_GBRAP) { - av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n", - av_get_pix_fmt_name(c->srcFormat), - av_get_pix_fmt_name(c->dstFormat)); + if (c->sws->src_format != AV_PIX_FMT_GBRAP) { + av_log(c->sws, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n", + av_get_pix_fmt_name(c->sws->src_format), + av_get_pix_fmt_name(c->sws->dst_format)); return srcSliceH; } - switch (c->dstFormat) { + switch (c->sws->dst_format) { case AV_PIX_FMT_BGR24: gbr24ptopacked24(src102, stride102, dst[0] + srcSliceY * dstStride[0], dstStride[0], - srcSliceH, c->srcW); + srcSliceH, c->sws->src_w); break; case AV_PIX_FMT_RGB24: gbr24ptopacked24(src201, stride201, dst[0] + srcSliceY * dstStride[0], dstStride[0], - srcSliceH, c->srcW); + srcSliceH, c->sws->src_w); break; case AV_PIX_FMT_ARGB: @@ -1092,7 +1092,7 @@ static int planarRgbaToRgbWrapper(SwsInternal *c, const uint8_t *const src[], case AV_PIX_FMT_RGBA: gbraptopacked32(src201, stride201, dst[0] + srcSliceY * dstStride[0], dstStride[0], - srcSliceH, alpha_first, c->srcW); + srcSliceH, alpha_first, c->sws->src_w); break; case AV_PIX_FMT_ABGR: @@ -1100,14 +1100,14 @@ static int planarRgbaToRgbWrapper(SwsInternal *c, const uint8_t *const src[], case AV_PIX_FMT_BGRA: gbraptopacked32(src102, stride102, dst[0] + srcSliceY * dstStride[0], dstStride[0], - srcSliceH, alpha_first, c->srcW); + srcSliceH, alpha_first, c->sws->src_w); break; default: - av_log(c, AV_LOG_ERROR, + av_log(c->sws, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n", - av_get_pix_fmt_name(c->srcFormat), - av_get_pix_fmt_name(c->dstFormat)); + av_get_pix_fmt_name(c->sws->src_format), + av_get_pix_fmt_name(c->sws->dst_format)); } return srcSliceH; @@ -1123,24 +1123,24 @@ static int planarRgbToRgbWrapper(SwsInternal *c, const uint8_t *const src[], int stride102[] = { srcStride[1], srcStride[0], srcStride[2] }; int stride201[] = { srcStride[2], srcStride[0], srcStride[1] }; - if (c->srcFormat != AV_PIX_FMT_GBRP) { - av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n", - av_get_pix_fmt_name(c->srcFormat), - av_get_pix_fmt_name(c->dstFormat)); + if (c->sws->src_format != AV_PIX_FMT_GBRP) { + av_log(c->sws, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n", + av_get_pix_fmt_name(c->sws->src_format), + av_get_pix_fmt_name(c->sws->dst_format)); return srcSliceH; } - switch (c->dstFormat) { + switch (c->sws->dst_format) { case AV_PIX_FMT_BGR24: gbr24ptopacked24(src102, stride102, dst[0] + srcSliceY * dstStride[0], dstStride[0], - srcSliceH, c->srcW); + srcSliceH, c->sws->src_w); break; case AV_PIX_FMT_RGB24: gbr24ptopacked24(src201, stride201, dst[0] + srcSliceY * dstStride[0], dstStride[0], - srcSliceH, c->srcW); + srcSliceH, c->sws->src_w); break; case AV_PIX_FMT_ARGB: @@ -1148,7 +1148,7 @@ static int planarRgbToRgbWrapper(SwsInternal *c, const uint8_t *const src[], case AV_PIX_FMT_RGBA: gbr24ptopacked32(src201, stride201, dst[0] + srcSliceY * dstStride[0], dstStride[0], - srcSliceH, alpha_first, c->srcW); + srcSliceH, alpha_first, c->sws->src_w); break; case AV_PIX_FMT_ABGR: @@ -1156,14 +1156,14 @@ static int planarRgbToRgbWrapper(SwsInternal *c, const uint8_t *const src[], case AV_PIX_FMT_BGRA: gbr24ptopacked32(src102, stride102, dst[0] + srcSliceY * dstStride[0], dstStride[0], - srcSliceH, alpha_first, c->srcW); + srcSliceH, alpha_first, c->sws->src_w); break; default: - av_log(c, AV_LOG_ERROR, + av_log(c->sws, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n", - av_get_pix_fmt_name(c->srcFormat), - av_get_pix_fmt_name(c->dstFormat)); + av_get_pix_fmt_name(c->sws->src_format), + av_get_pix_fmt_name(c->sws->dst_format)); } return srcSliceH; @@ -1174,14 +1174,14 @@ static int planarRgbToplanarRgbWrapper(SwsInternal *c, int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { - ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW, + ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->sws->src_w, dst[0], dstStride[0]); - ff_copyPlane(src[1], srcStride[1], srcSliceY, srcSliceH, c->srcW, + ff_copyPlane(src[1], srcStride[1], srcSliceY, srcSliceH, c->sws->src_w, dst[1], dstStride[1]); - ff_copyPlane(src[2], srcStride[2], srcSliceY, srcSliceH, c->srcW, + ff_copyPlane(src[2], srcStride[2], srcSliceY, srcSliceH, c->sws->src_w, dst[2], dstStride[2]); if (dst[3]) - fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255); + fillPlane(dst[3], dstStride[3], c->sws->src_w, srcSliceH, srcSliceY, 255); return srcSliceH; } @@ -1229,32 +1229,32 @@ static int rgbToPlanarRgbWrapper(SwsInternal *c, const uint8_t *const src[], dst[0] + srcSliceY * dstStride[0], dst[1] + srcSliceY * dstStride[1] }; - switch (c->srcFormat) { + switch (c->sws->src_format) { case AV_PIX_FMT_RGB24: packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201, - stride201, srcSliceH, alpha_first, 3, c->srcW); + stride201, srcSliceH, alpha_first, 3, c->sws->src_w); break; case AV_PIX_FMT_BGR24: packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102, - stride102, srcSliceH, alpha_first, 3, c->srcW); + stride102, srcSliceH, alpha_first, 3, c->sws->src_w); break; case AV_PIX_FMT_ARGB: alpha_first = 1; case AV_PIX_FMT_RGBA: packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201, - stride201, srcSliceH, alpha_first, 4, c->srcW); + stride201, srcSliceH, alpha_first, 4, c->sws->src_w); break; case AV_PIX_FMT_ABGR: alpha_first = 1; case AV_PIX_FMT_BGRA: packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102, - stride102, srcSliceH, alpha_first, 4, c->srcW); + stride102, srcSliceH, alpha_first, 4, c->sws->src_w); break; default: - av_log(c, AV_LOG_ERROR, + av_log(c->sws, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n", - av_get_pix_fmt_name(c->srcFormat), - av_get_pix_fmt_name(c->dstFormat)); + av_get_pix_fmt_name(c->sws->src_format), + av_get_pix_fmt_name(c->sws->dst_format)); } return srcSliceH; @@ -1330,7 +1330,7 @@ static int bayer_to_rgb24_wrapper(SwsInternal *c, const uint8_t *const src[], void (*copy) (const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width); void (*interpolate)(const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width); - switch(c->srcFormat) { + switch(c->sws->src_format) { #define CASE(pixfmt, prefix) \ case pixfmt: copy = bayer_##prefix##_to_rgb24_copy; \ interpolate = bayer_##prefix##_to_rgb24_interpolate; \ @@ -1353,20 +1353,20 @@ static int bayer_to_rgb24_wrapper(SwsInternal *c, const uint8_t *const src[], av_assert0(srcSliceH > 1); - copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW); + copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->sws->src_w); srcPtr += 2 * srcStride[0]; dstPtr += 2 * dstStride[0]; for (i = 2; i < srcSliceH - 2; i += 2) { - interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW); + interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0], c->sws->src_w); srcPtr += 2 * srcStride[0]; dstPtr += 2 * dstStride[0]; } if (i + 1 == srcSliceH) { - copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0], c->srcW); + copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0], c->sws->src_w); } else if (i < srcSliceH) - copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW); + copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->sws->src_w); return srcSliceH; } @@ -1380,7 +1380,7 @@ static int bayer_to_rgb48_wrapper(SwsInternal *c, const uint8_t *const src[], void (*copy) (const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width); void (*interpolate)(const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width); - switch(c->srcFormat) { + switch(c->sws->src_format) { #define CASE(pixfmt, prefix) \ case pixfmt: copy = bayer_##prefix##_to_rgb48_copy; \ interpolate = bayer_##prefix##_to_rgb48_interpolate; \ @@ -1403,20 +1403,20 @@ static int bayer_to_rgb48_wrapper(SwsInternal *c, const uint8_t *const src[], av_assert0(srcSliceH > 1); - copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW); + copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->sws->src_w); srcPtr += 2 * srcStride[0]; dstPtr += 2 * dstStride[0]; for (i = 2; i < srcSliceH - 2; i += 2) { - interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW); + interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0], c->sws->src_w); srcPtr += 2 * srcStride[0]; dstPtr += 2 * dstStride[0]; } if (i + 1 == srcSliceH) { - copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0], c->srcW); + copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0], c->sws->src_w); } else if (i < srcSliceH) - copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW); + copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->sws->src_w); return srcSliceH; } @@ -1432,7 +1432,7 @@ static int bayer_to_yv12_wrapper(SwsInternal *c, const uint8_t *const src[], void (*copy) (const uint8_t *src, int src_stride, uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, int luma_stride, int width, const int32_t *rgb2yuv); void (*interpolate)(const uint8_t *src, int src_stride, uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, int luma_stride, int width, const int32_t *rgb2yuv); - switch(c->srcFormat) { + switch(c->sws->src_format) { #define CASE(pixfmt, prefix) \ case pixfmt: copy = bayer_##prefix##_to_yv12_copy; \ interpolate = bayer_##prefix##_to_yv12_interpolate; \ @@ -1455,14 +1455,14 @@ static int bayer_to_yv12_wrapper(SwsInternal *c, const uint8_t *const src[], av_assert0(srcSliceH > 1); - copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table); + copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->sws->src_w, c->input_rgb2yuv_table); srcPtr += 2 * srcStride[0]; dstY += 2 * dstStride[0]; dstU += dstStride[1]; dstV += dstStride[1]; for (i = 2; i < srcSliceH - 2; i += 2) { - interpolate(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table); + interpolate(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->sws->src_w, c->input_rgb2yuv_table); srcPtr += 2 * srcStride[0]; dstY += 2 * dstStride[0]; dstU += dstStride[1]; @@ -1470,9 +1470,9 @@ static int bayer_to_yv12_wrapper(SwsInternal *c, const uint8_t *const src[], } if (i + 1 == srcSliceH) { - copy(srcPtr, -srcStride[0], dstY, dstU, dstV, -dstStride[0], c->srcW, c->input_rgb2yuv_table); + copy(srcPtr, -srcStride[0], dstY, dstU, dstV, -dstStride[0], c->sws->src_w, c->input_rgb2yuv_table); } else if (i < srcSliceH) - copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table); + copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->sws->src_w, c->input_rgb2yuv_table); return srcSliceH; } @@ -1501,8 +1501,8 @@ static int bayer_to_yv12_wrapper(SwsInternal *c, const uint8_t *const src[], typedef void (* rgbConvFn) (const uint8_t *, uint8_t *, int); static rgbConvFn findRgbConvFn(SwsInternal *c) { - const enum AVPixelFormat srcFormat = c->srcFormat; - const enum AVPixelFormat dstFormat = c->dstFormat; + const enum AVPixelFormat srcFormat = c->sws->src_format; + const enum AVPixelFormat dstFormat = c->sws->dst_format; const int srcId = c->srcFormatBpp; const int dstId = c->dstFormatBpp; rgbConvFn conv = NULL; @@ -1614,7 +1614,7 @@ static rgbConvFn findRgbConvFn(SwsInternal *c) return NULL; // Maintain symmetry between endianness - if (c->flags & SWS_BITEXACT) + if (c->sws->flags & SWS_BITEXACT) if ((dstFormat == AV_PIX_FMT_RGB32 || dstFormat == AV_PIX_FMT_BGR32 ) && !isRGBA32(srcFormat) && ALT32_CORR>0) return NULL; @@ -1627,16 +1627,16 @@ static int rgbToRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int const int dstStride[]) { - const enum AVPixelFormat srcFormat = c->srcFormat; - const enum AVPixelFormat dstFormat = c->dstFormat; - const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat); - const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat); + const enum AVPixelFormat srcFormat = c->sws->src_format; + const enum AVPixelFormat dstFormat = c->sws->dst_format; + const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->sws->src_format); + const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->sws->dst_format); const int srcBpp = (c->srcFormatBpp + 7) >> 3; const int dstBpp = (c->dstFormatBpp + 7) >> 3; rgbConvFn conv = findRgbConvFn(c); if (!conv) { - av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n", + av_log(c->sws, AV_LOG_ERROR, "internal error %s -> %s converter\n", av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat)); } else { const uint8_t *srcPtr = src[0]; @@ -1660,20 +1660,20 @@ static int rgbToRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int if (dstStride[0] * srcBpp == srcStride[0] * dstBpp && srcStride[0] > 0 && !(srcStride[0] % srcBpp) && !dst_bswap && !src_bswap) conv(srcPtr, dstPtr + dstStride[0] * srcSliceY, - (srcSliceH - 1) * srcStride[0] + c->srcW * srcBpp); + (srcSliceH - 1) * srcStride[0] + c->sws->src_w * srcBpp); else { int i, j; dstPtr += dstStride[0] * srcSliceY; for (i = 0; i < srcSliceH; i++) { if(src_bswap) { - for(j=0; jsrcW; j++) + for(j=0; jsws->src_w; j++) ((uint16_t*)c->formatConvBuffer)[j] = av_bswap16(((uint16_t*)srcPtr)[j]); - conv(c->formatConvBuffer, dstPtr, c->srcW * srcBpp); + conv(c->formatConvBuffer, dstPtr, c->sws->src_w * srcBpp); }else - conv(srcPtr, dstPtr, c->srcW * srcBpp); + conv(srcPtr, dstPtr, c->sws->src_w * srcBpp); if(dst_bswap) - for(j=0; jsrcW; j++) + for(j=0; jsws->src_w; j++) ((uint16_t*)dstPtr)[j] = av_bswap16(((uint16_t*)dstPtr)[j]); srcPtr += srcStride[0]; dstPtr += dstStride[0]; @@ -1692,11 +1692,11 @@ static int bgr24ToYv12Wrapper(SwsInternal *c, const uint8_t *const src[], dst[0] + srcSliceY * dstStride[0], dst[1] + (srcSliceY >> 1) * dstStride[1], dst[2] + (srcSliceY >> 1) * dstStride[2], - c->srcW, srcSliceH, + c->sws->src_w, srcSliceH, dstStride[0], dstStride[1], srcStride[0], c->input_rgb2yuv_table); if (dst[3]) - fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255); + fillPlane(dst[3], dstStride[3], c->sws->src_w, srcSliceH, srcSliceY, 255); return srcSliceH; } @@ -1704,7 +1704,7 @@ static int yvu9ToYv12Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { - ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW, + ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->sws->src_w, dst[0], dstStride[0]); planar2x(src[1], dst[1] + dstStride[1] * (srcSliceY >> 1), c->chrSrcW, @@ -1712,7 +1712,7 @@ static int yvu9ToYv12Wrapper(SwsInternal *c, const uint8_t *const src[], planar2x(src[2], dst[2] + dstStride[2] * (srcSliceY >> 1), c->chrSrcW, srcSliceH >> 2, srcStride[2], dstStride[2]); if (dst[3]) - fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255); + fillPlane(dst[3], dstStride[3], c->sws->src_w, srcSliceH, srcSliceY, 255); return srcSliceH; } @@ -1726,7 +1726,7 @@ static int uint_y_to_float_y_wrapper(SwsInternal *c, const uint8_t *const src[], float *dstPtr = (float *)(dst[0] + dstStride[0] * srcSliceY); for (y = 0; y < srcSliceH; ++y){ - for (x = 0; x < c->srcW; ++x){ + for (x = 0; x < c->sws->src_w; ++x){ dstPtr[x] = c->uint2float_lut[srcPtr[x]]; } srcPtr += srcStride[0]; @@ -1748,7 +1748,7 @@ static int float_y_to_uint_y_wrapper(SwsInternal *c, uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY; for (y = 0; y < srcSliceH; ++y){ - for (x = 0; x < c->srcW; ++x){ + for (x = 0; x < c->sws->src_w; ++x){ dstPtr[x] = av_clip_uint8(lrintf(255.0f * srcPtr[x])); } srcPtr += srcStrideFloat; @@ -1772,9 +1772,9 @@ static int packedCopyWrapper(SwsInternal *c, const uint8_t *const src[], int length = 0; /* universal length finder */ - while (length + c->srcW <= FFABS(dstStride[0]) && - length + c->srcW <= FFABS(srcStride[0])) - length += c->srcW; + while (length + c->sws->src_w <= FFABS(dstStride[0]) && + length + c->sws->src_w <= FFABS(srcStride[0])) + length += c->sws->src_w; av_assert1(length != 0); for (i = 0; i < srcSliceH; i++) { @@ -1788,7 +1788,7 @@ static int packedCopyWrapper(SwsInternal *c, const uint8_t *const src[], #define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\ unsigned shift= src_depth-dst_depth, tmp;\ - if (c->dither == SWS_DITHER_NONE) {\ + if (c->sws->dither == SWS_DITHER_NONE) {\ for (i = 0; i < height; i++) {\ for (j = 0; j < length-7; j+=8) {\ dst[j+0] = dbswap(bswap(src[j+0])>>shift);\ @@ -1850,31 +1850,31 @@ static int planarCopyWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]) { - const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat); - const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat); + const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->sws->src_format); + const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->sws->dst_format); int plane, i, j; for (plane = 0; plane < 4 && dst[plane] != NULL; plane++) { - int length = (plane == 0 || plane == 3) ? c->srcW : AV_CEIL_RSHIFT(c->srcW, c->chrDstHSubSample); + int length = (plane == 0 || plane == 3) ? c->sws->src_w : AV_CEIL_RSHIFT(c->sws->src_w, c->chrDstHSubSample); int y = (plane == 0 || plane == 3) ? srcSliceY: AV_CEIL_RSHIFT(srcSliceY, c->chrDstVSubSample); int height = (plane == 0 || plane == 3) ? srcSliceH: AV_CEIL_RSHIFT(srcSliceH, c->chrDstVSubSample); const uint8_t *srcPtr = src[plane]; uint8_t *dstPtr = dst[plane] + dstStride[plane] * y; - int shiftonly = plane == 1 || plane == 2 || (!c->srcRange && plane == 0); + int shiftonly = plane == 1 || plane == 2 || (!c->sws->src_range && plane == 0); // ignore palette for GRAY8 if (plane == 1 && !dst[2]) continue; if (!src[plane] || (plane == 1 && !src[2])) { - if (is16BPS(c->dstFormat) || isNBPS(c->dstFormat)) { + if (is16BPS(c->sws->dst_format) || isNBPS(c->sws->dst_format)) { fillPlane16(dst[plane], dstStride[plane], length, height, y, plane == 3, desc_dst->comp[plane].depth, - isBE(c->dstFormat)); + isBE(c->sws->dst_format)); } else { fillPlane(dst[plane], dstStride[plane], length, height, y, (plane == 3) ? 255 : 128); } } else { - if(isNBPS(c->srcFormat) || isNBPS(c->dstFormat) - || (is16BPS(c->srcFormat) != is16BPS(c->dstFormat)) + if(isNBPS(c->sws->src_format) || isNBPS(c->sws->dst_format) + || (is16BPS(c->sws->src_format) != is16BPS(c->sws->dst_format)) ) { const int src_depth = desc_src->comp[plane].depth; const int dst_depth = desc_dst->comp[plane].depth; @@ -1882,7 +1882,7 @@ static int planarCopyWrapper(SwsInternal *c, const uint8_t *const src[], uint16_t *dstPtr2 = (uint16_t*)dstPtr; if (dst_depth == 8) { - if(isBE(c->srcFormat) == HAVE_BIGENDIAN){ + if(isBE(c->sws->src_format) == HAVE_BIGENDIAN){ DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, , ) } else { DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, av_bswap16, ) @@ -1898,7 +1898,7 @@ static int planarCopyWrapper(SwsInternal *c, const uint8_t *const src[], w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\ (srcPtr[j]>>(2*8-dst_depth)));\ } - if(isBE(c->dstFormat)){ + if(isBE(c->sws->dst_format)){ COPY816(AV_WB16) } else { COPY816(AV_WL16) @@ -1909,8 +1909,8 @@ static int planarCopyWrapper(SwsInternal *c, const uint8_t *const src[], } else if (src_depth <= dst_depth) { for (i = 0; i < height; i++) { j = 0; - if(isBE(c->srcFormat) == HAVE_BIGENDIAN && - isBE(c->dstFormat) == HAVE_BIGENDIAN && + if(isBE(c->sws->src_format) == HAVE_BIGENDIAN && + isBE(c->sws->dst_format) == HAVE_BIGENDIAN && shiftonly) { unsigned shift = dst_depth - src_depth; #if HAVE_FAST_64BIT @@ -1945,14 +1945,14 @@ static int planarCopyWrapper(SwsInternal *c, const uint8_t *const src[], (v>>(2*src_depth-dst_depth)));\ }\ } - if(isBE(c->srcFormat)){ - if(isBE(c->dstFormat)){ + if(isBE(c->sws->src_format)){ + if(isBE(c->sws->dst_format)){ COPY_UP(AV_RB16, AV_WB16) } else { COPY_UP(AV_RB16, AV_WL16) } } else { - if(isBE(c->dstFormat)){ + if(isBE(c->sws->dst_format)){ COPY_UP(AV_RL16, AV_WB16) } else { COPY_UP(AV_RL16, AV_WL16) @@ -1962,22 +1962,22 @@ static int planarCopyWrapper(SwsInternal *c, const uint8_t *const src[], srcPtr2 += srcStride[plane]/2; } } else { - if(isBE(c->srcFormat) == HAVE_BIGENDIAN){ - if(isBE(c->dstFormat) == HAVE_BIGENDIAN){ + if(isBE(c->sws->src_format) == HAVE_BIGENDIAN){ + if(isBE(c->sws->dst_format) == HAVE_BIGENDIAN){ DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , ) } else { DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , av_bswap16) } }else{ - if(isBE(c->dstFormat) == HAVE_BIGENDIAN){ + if(isBE(c->sws->dst_format) == HAVE_BIGENDIAN){ DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, ) } else { DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, av_bswap16) } } } - } else if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat) && - isBE(c->srcFormat) != isBE(c->dstFormat)) { + } else if (is16BPS(c->sws->src_format) && is16BPS(c->sws->dst_format) && + isBE(c->sws->src_format) != isBE(c->sws->dst_format)) { for (i = 0; i < height; i++) { for (j = 0; j < length; j++) @@ -1985,8 +1985,8 @@ static int planarCopyWrapper(SwsInternal *c, const uint8_t *const src[], srcPtr += srcStride[plane]; dstPtr += dstStride[plane]; } - } else if (isFloat(c->srcFormat) && isFloat(c->dstFormat) && - isBE(c->srcFormat) != isBE(c->dstFormat)) { /* swap float plane */ + } else if (isFloat(c->sws->src_format) && isFloat(c->sws->dst_format) && + isBE(c->sws->src_format) != isBE(c->sws->dst_format)) { /* swap float plane */ for (i = 0; i < height; i++) { for (j = 0; j < length; j++) ((uint32_t *) dstPtr)[j] = av_bswap32(((const uint32_t *) srcPtr)[j]); @@ -1998,7 +1998,7 @@ static int planarCopyWrapper(SwsInternal *c, const uint8_t *const src[], memcpy(dst[plane] + dstStride[plane] * y, src[plane], height * dstStride[plane]); } else { - if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat)) + if (is16BPS(c->sws->src_format) && is16BPS(c->sws->dst_format)) length *= 2; else if (desc_src->comp[0].depth == 1) length >>= 3; // monowhite/black @@ -2021,11 +2021,11 @@ static int planarCopyWrapper(SwsInternal *c, const uint8_t *const src[], void ff_get_unscaled_swscale(SwsInternal *c) { - const enum AVPixelFormat srcFormat = c->srcFormat; - const enum AVPixelFormat dstFormat = c->dstFormat; - const int flags = c->flags; - const int dstH = c->dstH; - const int dstW = c->dstW; + const enum AVPixelFormat srcFormat = c->sws->src_format; + const enum AVPixelFormat dstFormat = c->sws->dst_format; + const int flags = c->sws->flags; + const int dstH = c->sws->dst_h; + const int dstW = c->sws->dst_w; int needsDither; needsDither = isAnyRGB(dstFormat) && @@ -2055,7 +2055,7 @@ void ff_get_unscaled_swscale(SwsInternal *c) /* yuv2bgr */ if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUV422P || srcFormat == AV_PIX_FMT_YUVA420P) && isAnyRGB(dstFormat) && - !(flags & SWS_ACCURATE_RND) && (c->dither == SWS_DITHER_BAYER || c->dither == SWS_DITHER_AUTO) && !(dstH & 1)) { + !(flags & SWS_ACCURATE_RND) && (c->sws->dither == SWS_DITHER_BAYER || c->sws->dither == SWS_DITHER_AUTO) && !(dstH & 1)) { c->convert_unscaled = ff_yuv2rgb_get_func_ptr(c); c->dst_slice_align = 2; } @@ -2088,7 +2088,7 @@ void ff_get_unscaled_swscale(SwsInternal *c) /* RGB/BGR -> RGB/BGR (no dither needed forms) */ if (isAnyRGB(srcFormat) && isAnyRGB(dstFormat) && findRgbConvFn(c) - && (!needsDither || (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)))) + && (!needsDither || (c->sws->flags&(SWS_FAST_BILINEAR|SWS_POINT)))) c->convert_unscaled = rgbToRgbWrapper; /* RGB to planar RGB */ @@ -2153,7 +2153,7 @@ void ff_get_unscaled_swscale(SwsInternal *c) else if (dstFormat == AV_PIX_FMT_YUV420P) c->convert_unscaled = bayer_to_yv12_wrapper; else if (!isBayer(dstFormat)) { - av_log(c, AV_LOG_ERROR, "unsupported bayer conversion\n"); + av_log(c->sws, AV_LOG_ERROR, "unsupported bayer conversion\n"); av_assert0(0); } } @@ -2235,7 +2235,7 @@ void ff_get_unscaled_swscale(SwsInternal *c) } /* LQ converters if -sws 0 or -sws 4*/ - if (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)) { + if (c->sws->flags&(SWS_FAST_BILINEAR|SWS_POINT)) { /* yv12_to_yuy2 */ if (srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) { if (dstFormat == AV_PIX_FMT_YUYV422) @@ -2271,7 +2271,7 @@ void ff_get_unscaled_swscale(SwsInternal *c) c->chrDstVSubSample == c->chrSrcVSubSample && !isSemiPlanarYUV(srcFormat) && !isSemiPlanarYUV(dstFormat)))) { - if (isPacked(c->srcFormat)) + if (isPacked(c->sws->src_format)) c->convert_unscaled = packedCopyWrapper; else /* Planar YUV or gray */ c->convert_unscaled = planarCopyWrapper; diff --git a/libswscale/utils.c b/libswscale/utils.c index 3ce9a92504..49387694cd 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -290,22 +290,20 @@ static SwsContext *alloc_set_opts(int srcW, int srcH, enum AVPixelFormat srcForm int flags, const double *param) { SwsContext *sws = sws_alloc_context(); - SwsInternal *c = sws_internal(sws); - - if (!c) + if (!sws) return NULL; - c->flags = flags; - c->srcW = srcW; - c->srcH = srcH; - c->dstW = dstW; - c->dstH = dstH; - c->srcFormat = srcFormat; - c->dstFormat = dstFormat; + sws->flags = flags; + sws->src_w = srcW; + sws->src_h = srcH; + sws->dst_w = dstW; + sws->dst_h = dstH; + sws->src_format = srcFormat; + sws->dst_format = dstFormat; if (param) { - c->param[0] = param[0]; - c->param[1] = param[1]; + sws->scaler_params[0] = param[0]; + sws->scaler_params[1] = param[1]; } return sws; @@ -1025,12 +1023,13 @@ static int handle_xyz(enum AVPixelFormat *format) } } -static void handle_formats(SwsInternal *c) +static void handle_formats(SwsContext *sws) { - c->src0Alpha |= handle_0alpha(&c->srcFormat); - c->dst0Alpha |= handle_0alpha(&c->dstFormat); - c->srcXYZ |= handle_xyz(&c->srcFormat); - c->dstXYZ |= handle_xyz(&c->dstFormat); + SwsInternal *c = sws_internal(sws); + c->src0Alpha |= handle_0alpha(&sws->src_format); + c->dst0Alpha |= handle_0alpha(&sws->dst_format); + c->srcXYZ |= handle_xyz(&sws->src_format); + c->dstXYZ |= handle_xyz(&sws->dst_format); if (c->srcXYZ || c->dstXYZ) fill_xyztables(c); } @@ -1062,17 +1061,17 @@ int sws_setColorspaceDetails(SwsContext *sws, const int inv_table[4], return parent_ret; } - handle_formats(c); - desc_dst = av_pix_fmt_desc_get(c->dstFormat); - desc_src = av_pix_fmt_desc_get(c->srcFormat); + handle_formats(sws); + desc_dst = av_pix_fmt_desc_get(sws->dst_format); + desc_src = av_pix_fmt_desc_get(sws->src_format); - if(range_override_needed(c->dstFormat)) + if(range_override_needed(sws->dst_format)) dstRange = 0; - if(range_override_needed(c->srcFormat)) + if(range_override_needed(sws->src_format)) srcRange = 0; - if (c->srcRange != srcRange || - c->dstRange != dstRange || + if (sws->src_range != srcRange || + sws->dst_range != dstRange || c->brightness != brightness || c->contrast != contrast || c->saturation != saturation || @@ -1089,8 +1088,8 @@ int sws_setColorspaceDetails(SwsContext *sws, const int inv_table[4], c->brightness = brightness; c->contrast = contrast; c->saturation = saturation; - c->srcRange = srcRange; - c->dstRange = dstRange; + sws->src_range = srcRange; + sws->dst_range = dstRange; if (need_reinit) { ff_sws_init_range_convert(c); @@ -1112,27 +1111,27 @@ int sws_setColorspaceDetails(SwsContext *sws, const int inv_table[4], if (!need_reinit) return 0; - if ((isYUV(c->dstFormat) || isGray(c->dstFormat)) && (isYUV(c->srcFormat) || isGray(c->srcFormat))) { + if ((isYUV(sws->dst_format) || isGray(sws->dst_format)) && (isYUV(sws->src_format) || isGray(sws->src_format))) { if (!c->cascaded_context[0] && memcmp(c->dstColorspaceTable, c->srcColorspaceTable, sizeof(int) * 4) && - c->srcW && c->srcH && c->dstW && c->dstH) { + sws->src_w && sws->src_h && sws->dst_w && sws->dst_h) { enum AVPixelFormat tmp_format; int tmp_width, tmp_height; - int srcW = c->srcW; - int srcH = c->srcH; - int dstW = c->dstW; - int dstH = c->dstH; + int srcW = sws->src_w; + int srcH = sws->src_h; + int dstW = sws->dst_w; + int dstH = sws->dst_h; int ret; - av_log(c, AV_LOG_VERBOSE, "YUV color matrix differs for YUV->YUV, using intermediate RGB to convert\n"); + av_log(sws, AV_LOG_VERBOSE, "YUV color matrix differs for YUV->YUV, using intermediate RGB to convert\n"); - if (isNBPS(c->dstFormat) || is16BPS(c->dstFormat)) { - if (isALPHA(c->srcFormat) && isALPHA(c->dstFormat)) { + if (isNBPS(sws->dst_format) || is16BPS(sws->dst_format)) { + if (isALPHA(sws->src_format) && isALPHA(sws->dst_format)) { tmp_format = AV_PIX_FMT_BGRA64; } else { tmp_format = AV_PIX_FMT_BGR48; } } else { - if (isALPHA(c->srcFormat) && isALPHA(c->dstFormat)) { + if (isALPHA(sws->src_format) && isALPHA(sws->dst_format)) { tmp_format = AV_PIX_FMT_BGRA; } else { tmp_format = AV_PIX_FMT_BGR24; @@ -1152,13 +1151,13 @@ int sws_setColorspaceDetails(SwsContext *sws, const int inv_table[4], if (ret < 0) return ret; - c->cascaded_context[0] = alloc_set_opts(srcW, srcH, c->srcFormat, + c->cascaded_context[0] = alloc_set_opts(srcW, srcH, sws->src_format, tmp_width, tmp_height, tmp_format, - c->flags, c->param); + sws->flags, sws->scaler_params); if (!c->cascaded_context[0]) return -1; - sws_internal(c->cascaded_context[0])->alphablend = c->alphablend; + c->cascaded_context[0]->alpha_blend = sws->alpha_blend; ret = sws_init_context(c->cascaded_context[0], NULL , NULL); if (ret < 0) return ret; @@ -1168,12 +1167,12 @@ int sws_setColorspaceDetails(SwsContext *sws, const int inv_table[4], brightness, contrast, saturation); c->cascaded_context[1] = alloc_set_opts(tmp_width, tmp_height, tmp_format, - dstW, dstH, c->dstFormat, - c->flags, c->param); + dstW, dstH, sws->dst_format, + sws->flags, sws->scaler_params); if (!c->cascaded_context[1]) return -1; - sws_internal(c->cascaded_context[1])->srcRange = srcRange; - sws_internal(c->cascaded_context[1])->dstRange = dstRange; + c->cascaded_context[1]->src_range = srcRange; + c->cascaded_context[1]->dst_range = dstRange; ret = sws_init_context(c->cascaded_context[1], NULL , NULL); if (ret < 0) return ret; @@ -1188,7 +1187,7 @@ int sws_setColorspaceDetails(SwsContext *sws, const int inv_table[4], return 0; } - if (!isYUV(c->dstFormat) && !isGray(c->dstFormat)) { + if (!isYUV(sws->dst_format) && !isGray(sws->dst_format)) { ff_yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness, contrast, saturation); // FIXME factorize @@ -1220,8 +1219,8 @@ int sws_getColorspaceDetails(SwsContext *sws, int **inv_table, *inv_table = c->srcColorspaceTable; *table = c->dstColorspaceTable; - *srcRange = range_override_needed(c->srcFormat) ? 1 : c->srcRange; - *dstRange = range_override_needed(c->dstFormat) ? 1 : c->dstRange; + *srcRange = range_override_needed(sws->src_format) ? 1 : sws->src_range; + *dstRange = range_override_needed(sws->dst_format) ? 1 : sws->dst_range; *brightness = c->brightness; *contrast = c->contrast; *saturation = c->saturation; @@ -1231,16 +1230,24 @@ int sws_getColorspaceDetails(SwsContext *sws, int **inv_table, SwsContext *sws_alloc_context(void) { - SwsInternal *c = av_mallocz(sizeof(SwsInternal)); + SwsInternal *c; + SwsContext *sws = (SwsContext *) av_mallocz(sizeof(SwsContext)); + if (!sws) + return NULL; + sws->av_class = &ff_sws_context_class; - if (c) { - c->av_class = &ff_sws_context_class; - av_opt_set_defaults(c); - atomic_init(&c->stride_unaligned_warned, 0); - atomic_init(&c->data_unaligned_warned, 0); + c = sws->internal = av_mallocz(sizeof(SwsInternal)); + if (!c) { + av_free(sws); + return NULL; } + c->sws = sws; + + av_opt_set_defaults(sws); + atomic_init(&c->stride_unaligned_warned, 0); + atomic_init(&c->data_unaligned_warned, 0); - return (SwsContext *) c; + return sws; } static uint16_t * alloc_gamma_tbl(double e) @@ -1326,10 +1333,10 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter int unscaled; SwsInternal *c = sws_internal(sws); SwsFilter dummyFilter = { NULL, NULL, NULL, NULL }; - int srcW = c->srcW; - int srcH = c->srcH; - int dstW = c->dstW; - int dstH = c->dstH; + int srcW = sws->src_w; + int srcH = sws->src_h; + int dstW = sws->dst_w; + int dstH = sws->dst_h; int dst_stride = FFALIGN(dstW * sizeof(int16_t) + 66, 16); int flags, cpu_flags; enum AVPixelFormat srcFormat, dstFormat; @@ -1340,35 +1347,35 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter static const float float_mult = 1.0f / 255.0f; cpu_flags = av_get_cpu_flags(); - flags = c->flags; + flags = sws->flags; emms_c(); unscaled = (srcW == dstW && srcH == dstH); if (!c->contrast && !c->saturation && !c->dstFormatBpp) - sws_setColorspaceDetails(sws, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], c->srcRange, + sws_setColorspaceDetails(sws, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], sws->src_range, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], - c->dstRange, 0, 1 << 16, 1 << 16); + sws->dst_range, 0, 1 << 16, 1 << 16); - handle_formats(c); - srcFormat = c->srcFormat; - dstFormat = c->dstFormat; + handle_formats(sws); + srcFormat = sws->src_format; + dstFormat = sws->dst_format; desc_src = av_pix_fmt_desc_get(srcFormat); desc_dst = av_pix_fmt_desc_get(dstFormat); // If the source has no alpha then disable alpha blendaway if (c->src0Alpha) - c->alphablend = SWS_ALPHA_BLEND_NONE; + sws->alpha_blend = SWS_ALPHA_BLEND_NONE; if (!(unscaled && sws_isSupportedEndiannessConversion(srcFormat) && av_pix_fmt_swap_endianness(srcFormat) == dstFormat)) { if (!sws_isSupportedInput(srcFormat)) { - av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n", + av_log(sws, AV_LOG_ERROR, "%s is not supported as input pixel format\n", av_get_pix_fmt_name(srcFormat)); return AVERROR(EINVAL); } if (!sws_isSupportedOutput(dstFormat)) { - av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n", + av_log(sws, AV_LOG_ERROR, "%s is not supported as output pixel format\n", av_get_pix_fmt_name(dstFormat)); return AVERROR(EINVAL); } @@ -1395,9 +1402,9 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter flags |= SWS_BICUBIC; else flags |= SWS_BICUBIC; - c->flags = flags; + sws->flags = flags; } else if (i & (i - 1)) { - av_log(c, AV_LOG_ERROR, + av_log(sws, AV_LOG_ERROR, "Exactly one scaler algorithm must be chosen, got %X\n", i); return AVERROR(EINVAL); } @@ -1405,14 +1412,14 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter if (srcW < 1 || srcH < 1 || dstW < 1 || dstH < 1) { /* FIXME check if these are enough and try to lower them after * fixing the relevant parts of the code */ - av_log(c, AV_LOG_ERROR, "%dx%d -> %dx%d is invalid scaling dimension\n", + av_log(sws, AV_LOG_ERROR, "%dx%d -> %dx%d is invalid scaling dimension\n", srcW, srcH, dstW, dstH); return AVERROR(EINVAL); } if (flags & SWS_FAST_BILINEAR) { if (srcW < 8 || dstW < 8) { flags ^= SWS_FAST_BILINEAR | SWS_BILINEAR; - c->flags = flags; + sws->flags = flags; } } @@ -1443,58 +1450,58 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter if (isAnyRGB(dstFormat) && !(flags&SWS_FULL_CHR_H_INT)) { if (dstW&1) { - av_log(c, AV_LOG_DEBUG, "Forcing full internal H chroma due to odd output size\n"); + av_log(sws, AV_LOG_DEBUG, "Forcing full internal H chroma due to odd output size\n"); flags |= SWS_FULL_CHR_H_INT; - c->flags = flags; + sws->flags = flags; } if ( c->chrSrcHSubSample == 0 && c->chrSrcVSubSample == 0 - && c->dither != SWS_DITHER_BAYER //SWS_FULL_CHR_H_INT is currently not supported with SWS_DITHER_BAYER - && !(c->flags & SWS_FAST_BILINEAR) + && sws->dither != SWS_DITHER_BAYER //SWS_FULL_CHR_H_INT is currently not supported with SWS_DITHER_BAYER + && !(sws->flags & SWS_FAST_BILINEAR) ) { - av_log(c, AV_LOG_DEBUG, "Forcing full internal H chroma due to input having non subsampled chroma\n"); + av_log(sws, AV_LOG_DEBUG, "Forcing full internal H chroma due to input having non subsampled chroma\n"); flags |= SWS_FULL_CHR_H_INT; - c->flags = flags; + sws->flags = flags; } } - if (c->dither == SWS_DITHER_AUTO) { + if (sws->dither == SWS_DITHER_AUTO) { if (flags & SWS_ERROR_DIFFUSION) - c->dither = SWS_DITHER_ED; + sws->dither = SWS_DITHER_ED; } if(dstFormat == AV_PIX_FMT_BGR4_BYTE || dstFormat == AV_PIX_FMT_RGB4_BYTE || dstFormat == AV_PIX_FMT_BGR8 || dstFormat == AV_PIX_FMT_RGB8) { - if (c->dither == SWS_DITHER_AUTO) - c->dither = (flags & SWS_FULL_CHR_H_INT) ? SWS_DITHER_ED : SWS_DITHER_BAYER; + if (sws->dither == SWS_DITHER_AUTO) + sws->dither = (flags & SWS_FULL_CHR_H_INT) ? SWS_DITHER_ED : SWS_DITHER_BAYER; if (!(flags & SWS_FULL_CHR_H_INT)) { - if (c->dither == SWS_DITHER_ED || c->dither == SWS_DITHER_A_DITHER || c->dither == SWS_DITHER_X_DITHER || c->dither == SWS_DITHER_NONE) { - av_log(c, AV_LOG_DEBUG, + if (sws->dither == SWS_DITHER_ED || sws->dither == SWS_DITHER_A_DITHER || sws->dither == SWS_DITHER_X_DITHER || sws->dither == SWS_DITHER_NONE) { + av_log(sws, AV_LOG_DEBUG, "Desired dithering only supported in full chroma interpolation for destination format '%s'\n", av_get_pix_fmt_name(dstFormat)); flags |= SWS_FULL_CHR_H_INT; - c->flags = flags; + sws->flags = flags; } } if (flags & SWS_FULL_CHR_H_INT) { - if (c->dither == SWS_DITHER_BAYER) { - av_log(c, AV_LOG_DEBUG, + if (sws->dither == SWS_DITHER_BAYER) { + av_log(sws, AV_LOG_DEBUG, "Ordered dither is not supported in full chroma interpolation for destination format '%s'\n", av_get_pix_fmt_name(dstFormat)); - c->dither = SWS_DITHER_ED; + sws->dither = SWS_DITHER_ED; } } } if (isPlanarRGB(dstFormat)) { if (!(flags & SWS_FULL_CHR_H_INT)) { - av_log(c, AV_LOG_DEBUG, + av_log(sws, AV_LOG_DEBUG, "%s output is not supported with half chroma resolution, switching to full\n", av_get_pix_fmt_name(dstFormat)); flags |= SWS_FULL_CHR_H_INT; - c->flags = flags; + sws->flags = flags; } } @@ -1522,11 +1529,11 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter dstFormat != AV_PIX_FMT_BGR8 && dstFormat != AV_PIX_FMT_RGB8 ) { - av_log(c, AV_LOG_WARNING, + av_log(sws, AV_LOG_WARNING, "full chroma interpolation for destination format '%s' not yet implemented\n", av_get_pix_fmt_name(dstFormat)); flags &= ~SWS_FULL_CHR_H_INT; - c->flags = flags; + sws->flags = flags; } if (isAnyRGB(dstFormat) && !(flags & SWS_FULL_CHR_H_INT)) c->chrDstHSubSample = 1; @@ -1585,10 +1592,10 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter && (flags & SWS_FAST_BILINEAR)) { if (flags & SWS_PRINT_INFO) - av_log(c, AV_LOG_INFO, + av_log(sws, AV_LOG_INFO, "output width is not a multiple of 32 -> no MMXEXT scaler\n"); } - if (usesHFilter || isNBPS(c->srcFormat) || is16BPS(c->srcFormat) || isAnyRGB(c->srcFormat)) + if (usesHFilter || isNBPS(sws->src_format) || is16BPS(sws->src_format) || isAnyRGB(sws->src_format)) c->canMMXEXTBeUsed = 0; } else c->canMMXEXTBeUsed = 0; @@ -1619,8 +1626,7 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter c->gamma_value = 2.2; tmpFmt = AV_PIX_FMT_RGBA64LE; - - if (!unscaled && c->gamma_flag && (srcFormat != tmpFmt || dstFormat != tmpFmt)) { + if (!unscaled && sws->gamma_flag && (srcFormat != tmpFmt || dstFormat != tmpFmt)) { SwsInternal *c2; c->cascaded_context[0] = NULL; @@ -1631,14 +1637,16 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter c->cascaded_context[0] = sws_getContext(srcW, srcH, srcFormat, srcW, srcH, tmpFmt, - flags, NULL, NULL, c->param); + flags, NULL, NULL, + sws->scaler_params); if (!c->cascaded_context[0]) { return AVERROR(ENOMEM); } c->cascaded_context[1] = sws_getContext(srcW, srcH, tmpFmt, dstW, dstH, tmpFmt, - flags, srcFilter, dstFilter, c->param); + flags, srcFilter, dstFilter, + sws->scaler_params); if (!c->cascaded_context[1]) return AVERROR(ENOMEM); @@ -1668,8 +1676,9 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter return ret; c->cascaded_context[2] = sws_getContext(dstW, dstH, tmpFmt, - dstW, dstH, dstFormat, - flags, NULL, NULL, c->param); + dstW, dstH, dstFormat, + flags, NULL, NULL, + sws->scaler_params); if (!c->cascaded_context[2]) return AVERROR(ENOMEM); } @@ -1689,13 +1698,15 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter c->cascaded_context[0] = sws_getContext(srcW, srcH, srcFormat, srcW, srcH, tmpFormat, - flags, srcFilter, NULL, c->param); + flags, srcFilter, NULL, + sws->scaler_params); if (!c->cascaded_context[0]) return AVERROR(ENOMEM); c->cascaded_context[1] = sws_getContext(srcW, srcH, tmpFormat, dstW, dstH, dstFormat, - flags, NULL, dstFilter, c->param); + flags, NULL, dstFilter, + sws->scaler_params); if (!c->cascaded_context[1]) return AVERROR(ENOMEM); return 0; @@ -1718,11 +1729,11 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter if (CONFIG_SWSCALE_ALPHA && isALPHA(srcFormat) && !isALPHA(dstFormat)) { enum AVPixelFormat tmpFormat = alphaless_fmt(srcFormat); - if (tmpFormat != AV_PIX_FMT_NONE && c->alphablend != SWS_ALPHA_BLEND_NONE) { + if (tmpFormat != AV_PIX_FMT_NONE && sws->alpha_blend != SWS_ALPHA_BLEND_NONE) { if (!unscaled || dstFormat != tmpFormat || usesHFilter || usesVFilter || - c->srcRange != c->dstRange + sws->src_range != sws->dst_range ) { c->cascaded_mainindex = 1; ret = av_image_alloc(c->cascaded_tmp[0], c->cascaded_tmpStride[0], @@ -1732,22 +1743,22 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter c->cascaded_context[0] = alloc_set_opts(srcW, srcH, srcFormat, srcW, srcH, tmpFormat, - flags, c->param); + flags, sws->scaler_params); if (!c->cascaded_context[0]) return AVERROR(EINVAL); - sws_internal(c->cascaded_context[0])->alphablend = c->alphablend; + c->cascaded_context[0]->alpha_blend = sws->alpha_blend; ret = sws_init_context(c->cascaded_context[0], NULL , NULL); if (ret < 0) return ret; c->cascaded_context[1] = alloc_set_opts(srcW, srcH, tmpFormat, dstW, dstH, dstFormat, - flags, c->param); + flags, sws->scaler_params); if (!c->cascaded_context[1]) return AVERROR(EINVAL); - sws_internal(c->cascaded_context[1])->srcRange = c->srcRange; - sws_internal(c->cascaded_context[1])->dstRange = c->dstRange; + c->cascaded_context[1]->src_range = sws->src_range; + c->cascaded_context[1]->dst_range = sws->dst_range; ret = sws_init_context(c->cascaded_context[1], srcFilter , dstFilter); if (ret < 0) return ret; @@ -1759,15 +1770,15 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter /* alpha blend special case, note this has been split via cascaded contexts if its scaled */ if (unscaled && !usesHFilter && !usesVFilter && - c->alphablend != SWS_ALPHA_BLEND_NONE && + sws->alpha_blend != SWS_ALPHA_BLEND_NONE && isALPHA(srcFormat) && - (c->srcRange == c->dstRange || isAnyRGB(dstFormat)) && + (sws->src_range == sws->dst_range || isAnyRGB(dstFormat)) && alphaless_fmt(srcFormat) == dstFormat ) { c->convert_unscaled = ff_sws_alphablendaway; if (flags & SWS_PRINT_INFO) - av_log(c, AV_LOG_INFO, + av_log(sws, AV_LOG_INFO, "using alpha blendaway %s -> %s special converter\n", av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat)); return 0; @@ -1775,14 +1786,14 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter /* unscaled special cases */ if (unscaled && !usesHFilter && !usesVFilter && - (c->srcRange == c->dstRange || isAnyRGB(dstFormat) || + (sws->src_range == sws->dst_range || isAnyRGB(dstFormat) || isFloat(srcFormat) || isFloat(dstFormat) || isBayer(srcFormat))){ ff_get_unscaled_swscale(c); if (c->convert_unscaled) { if (flags & SWS_PRINT_INFO) - av_log(c, AV_LOG_INFO, + av_log(sws, AV_LOG_INFO, "using unscaled %s -> %s special converter\n", av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat)); return 0; @@ -1834,7 +1845,7 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter if (!c->lumMmxextFilterCode || !c->chrMmxextFilterCode) #endif { - av_log(c, AV_LOG_ERROR, "Failed to allocate MMX2FilterCode\n"); + av_log(sws, AV_LOG_ERROR, "Failed to allocate MMX2FilterCode\n"); return AVERROR(ENOMEM); } @@ -1852,7 +1863,7 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter #if USE_MMAP if ( mprotect(c->lumMmxextFilterCode, c->lumMmxextFilterCodeSize, PROT_EXEC | PROT_READ) == -1 || mprotect(c->chrMmxextFilterCode, c->chrMmxextFilterCodeSize, PROT_EXEC | PROT_READ) == -1) { - av_log(c, AV_LOG_ERROR, "mprotect failed, cannot use fast bilinear scaler\n"); + av_log(sws, AV_LOG_ERROR, "mprotect failed, cannot use fast bilinear scaler\n"); ret = AVERROR(EINVAL); goto fail; } @@ -1871,7 +1882,7 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter srcW, dstW, filterAlign, 1 << 14, (flags & SWS_BICUBLIN) ? (flags | SWS_BICUBIC) : flags, cpu_flags, srcFilter->lumH, dstFilter->lumH, - c->param, + sws->scaler_params, get_local_pos(c, 0, 0, 0), get_local_pos(c, 0, 0, 0))) < 0) goto fail; @@ -1882,9 +1893,9 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter c->chrSrcW, c->chrDstW, filterAlign, 1 << 14, (flags & SWS_BICUBLIN) ? (flags | SWS_BILINEAR) : flags, cpu_flags, srcFilter->chrH, dstFilter->chrH, - c->param, - get_local_pos(c, c->chrSrcHSubSample, c->src_h_chr_pos, 0), - get_local_pos(c, c->chrDstHSubSample, c->dst_h_chr_pos, 0))) < 0) + sws->scaler_params, + get_local_pos(c, c->chrSrcHSubSample, sws->src_h_chr_pos, 0), + get_local_pos(c, c->chrDstHSubSample, sws->dst_h_chr_pos, 0))) < 0) goto fail; if (ff_shuffle_filter_coefficients(c, c->hChrFilterPos, c->hChrFilterSize, c->hChrFilter, c->chrDstW) < 0) goto nomem; @@ -1901,7 +1912,7 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter c->lumYInc, srcH, dstH, filterAlign, (1 << 12), (flags & SWS_BICUBLIN) ? (flags | SWS_BICUBIC) : flags, cpu_flags, srcFilter->lumV, dstFilter->lumV, - c->param, + sws->scaler_params, get_local_pos(c, 0, 0, 1), get_local_pos(c, 0, 0, 1))) < 0) goto fail; @@ -1910,18 +1921,18 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter filterAlign, (1 << 12), (flags & SWS_BICUBLIN) ? (flags | SWS_BILINEAR) : flags, cpu_flags, srcFilter->chrV, dstFilter->chrV, - c->param, - get_local_pos(c, c->chrSrcVSubSample, c->src_v_chr_pos, 1), - get_local_pos(c, c->chrDstVSubSample, c->dst_v_chr_pos, 1))) < 0) + sws->scaler_params, + get_local_pos(c, c->chrSrcVSubSample, sws->src_v_chr_pos, 1), + get_local_pos(c, c->chrDstVSubSample, sws->dst_v_chr_pos, 1))) < 0) goto fail; #if HAVE_ALTIVEC - if (!FF_ALLOC_TYPED_ARRAY(c->vYCoeffsBank, c->vLumFilterSize * c->dstH) || + if (!FF_ALLOC_TYPED_ARRAY(c->vYCoeffsBank, c->vLumFilterSize * sws->dst_h) || !FF_ALLOC_TYPED_ARRAY(c->vCCoeffsBank, c->vChrFilterSize * c->chrDstH)) goto nomem; - for (i = 0; i < c->vLumFilterSize * c->dstH; i++) { + for (i = 0; i < c->vLumFilterSize * sws->dst_h; i++) { int j; short *p = (short *)&c->vYCoeffsBank[i]; for (j = 0; j < 8; j++) @@ -1938,10 +1949,10 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter } for (i = 0; i < 4; i++) - if (!FF_ALLOCZ_TYPED_ARRAY(c->dither_error[i], c->dstW + 3)) + if (!FF_ALLOCZ_TYPED_ARRAY(c->dither_error[i], sws->dst_w + 3)) goto nomem; - c->needAlpha = (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat) && isALPHA(c->dstFormat)) ? 1 : 0; + c->needAlpha = (CONFIG_SWSCALE_ALPHA && isALPHA(sws->src_format) && isALPHA(sws->dst_format)) ? 1 : 0; // 64 / c->scalingBpp is the same as 16 / sizeof(scaling_intermediate) c->uv_off = (dst_stride>>1) + 64 / (c->dstBpc &~ 7); @@ -1960,7 +1971,7 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter } if (!scaler) scaler = "ehh flags invalid?!"; - av_log(c, AV_LOG_INFO, "%s scaler, from %s to %s%s ", + av_log(sws, AV_LOG_INFO, "%s scaler, from %s to %s%s ", scaler, av_get_pix_fmt_name(srcFormat), dstFormat == AV_PIX_FMT_BGR555 || dstFormat == AV_PIX_FMT_BGR565 || @@ -1978,13 +1989,13 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter else cpucaps = "C"; - av_log(c, AV_LOG_INFO, "using %s\n", cpucaps); + av_log(sws, AV_LOG_INFO, "using %s\n", cpucaps); - av_log(c, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH); - av_log(c, AV_LOG_DEBUG, + av_log(sws, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH); + av_log(sws, AV_LOG_DEBUG, "lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", - c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc); - av_log(c, AV_LOG_DEBUG, + sws->src_w, sws->src_h, sws->dst_w, sws->dst_h, c->lumXInc, c->lumYInc); + av_log(sws, AV_LOG_DEBUG, "chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH, c->chrXInc, c->chrYInc); @@ -2014,13 +2025,15 @@ fail: // FIXME replace things by appropriate error codes c->cascaded_context[0] = sws_getContext(srcW, srcH, srcFormat, tmpW, tmpH, tmpFormat, - flags, srcFilter, NULL, c->param); + flags, srcFilter, NULL, + sws->scaler_params); if (!c->cascaded_context[0]) return AVERROR(ENOMEM); c->cascaded_context[1] = sws_getContext(tmpW, tmpH, tmpFormat, dstW, dstH, dstFormat, - flags, NULL, dstFilter, c->param); + flags, NULL, dstFilter, + sws->scaler_params); if (!c->cascaded_context[1]) return AVERROR(ENOMEM); return 0; @@ -2035,42 +2048,39 @@ static int context_init_threaded(SwsContext *sws, int ret; ret = avpriv_slicethread_create(&c->slicethread, (void*) sws, - ff_sws_slice_worker, NULL, c->nb_threads); + ff_sws_slice_worker, NULL, sws->threads); if (ret == AVERROR(ENOSYS)) { - c->nb_threads = 1; + sws->threads = 1; return 0; } else if (ret < 0) return ret; - c->nb_threads = ret; + sws->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)); + c->slice_ctx = av_calloc(sws->threads, sizeof(*c->slice_ctx)); + c->slice_err = av_calloc(sws->threads, sizeof(*c->slice_err)); if (!c->slice_ctx || !c->slice_err) return AVERROR(ENOMEM); - for (int i = 0; i < c->nb_threads; i++) { - SwsInternal *c2; - c->slice_ctx[i] = sws_alloc_context(); - if (!c->slice_ctx[i]) + for (int i = 0; i < sws->threads; i++) { + SwsContext *slice; + slice = c->slice_ctx[i] = sws_alloc_context(); + if (!slice) return AVERROR(ENOMEM); - c2 = sws_internal(c->slice_ctx[i]); - + sws_internal(slice)->parent = sws; c->nb_slice_ctx++; - c2->parent = sws; - ret = av_opt_copy((void*)c->slice_ctx[i], (void*)c); + ret = av_opt_copy(slice, sws); if (ret < 0) return ret; + slice->threads = 1; - c2->nb_threads = 1; - - ret = sws_init_single_context(c->slice_ctx[i], src_filter, dst_filter); + ret = sws_init_single_context(slice, src_filter, dst_filter); if (ret < 0) return ret; - if (c2->dither == SWS_DITHER_ED) { - av_log(c, AV_LOG_VERBOSE, + if (slice->dither == SWS_DITHER_ED) { + av_log(sws, AV_LOG_VERBOSE, "Error-diffusion dither is in use, scaling will be single-threaded."); break; } @@ -2095,17 +2105,17 @@ av_cold int sws_init_context(SwsContext *sws, SwsFilter *srcFilter, if (ff_thread_once(&rgb2rgb_once, ff_sws_rgb2rgb_init) != 0) return AVERROR_UNKNOWN; - src_format = c->srcFormat; - dst_format = c->dstFormat; - c->srcRange |= handle_jpeg(&c->srcFormat); - c->dstRange |= handle_jpeg(&c->dstFormat); + src_format = sws->src_format; + dst_format = sws->dst_format; + sws->src_range |= handle_jpeg(&sws->src_format); + sws->dst_range |= handle_jpeg(&sws->dst_format); - if (src_format != c->srcFormat || dst_format != c->dstFormat) - av_log(c, AV_LOG_WARNING, "deprecated pixel format used, make sure you did set range correctly\n"); + if (src_format != sws->src_format || dst_format != sws->dst_format) + av_log(sws, AV_LOG_WARNING, "deprecated pixel format used, make sure you did set range correctly\n"); - if (c->nb_threads != 1) { + if (sws->threads != 1) { ret = context_init_threaded(sws, srcFilter, dstFilter); - if (ret < 0 || c->nb_threads > 1) + if (ret < 0 || sws->threads > 1) return ret; // threading disabled in this build, init as single-threaded } @@ -2517,6 +2527,7 @@ void sws_freeContext(SwsContext *sws) ff_free_filters(c); + av_free(c); av_free(sws); } @@ -2530,7 +2541,7 @@ void sws_free_context(SwsContext **pctx) *pctx = NULL; } -SwsContext *sws_getCachedContext(SwsContext *sws, int srcW, +SwsContext *sws_getCachedContext(SwsContext *prev, int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, @@ -2538,59 +2549,48 @@ SwsContext *sws_getCachedContext(SwsContext *sws, int srcW, SwsFilter *dstFilter, const double *param) { - SwsInternal *context; - + SwsContext *sws; static const double default_param[2] = { SWS_PARAM_DEFAULT, SWS_PARAM_DEFAULT }; - int64_t src_h_chr_pos = -513, dst_h_chr_pos = -513, - src_v_chr_pos = -513, dst_v_chr_pos = -513; if (!param) param = default_param; - if ((context = sws_internal(sws)) && - (context->srcW != srcW || - context->srcH != srcH || - context->srcFormat != srcFormat || - context->dstW != dstW || - context->dstH != dstH || - context->dstFormat != dstFormat || - context->flags != flags || - context->param[0] != param[0] || - context->param[1] != param[1])) { - - av_opt_get_int(context, "src_h_chr_pos", 0, &src_h_chr_pos); - av_opt_get_int(context, "src_v_chr_pos", 0, &src_v_chr_pos); - av_opt_get_int(context, "dst_h_chr_pos", 0, &dst_h_chr_pos); - av_opt_get_int(context, "dst_v_chr_pos", 0, &dst_v_chr_pos); - sws_freeContext(sws); - sws = NULL; - } - - if (!sws) { - if (!(sws = sws_alloc_context())) - return NULL; - context = sws_internal(sws); - context->srcW = srcW; - context->srcH = srcH; - context->srcFormat = srcFormat; - context->dstW = dstW; - context->dstH = dstH; - context->dstFormat = dstFormat; - context->flags = flags; - context->param[0] = param[0]; - context->param[1] = param[1]; - - av_opt_set_int(context, "src_h_chr_pos", src_h_chr_pos, 0); - av_opt_set_int(context, "src_v_chr_pos", src_v_chr_pos, 0); - av_opt_set_int(context, "dst_h_chr_pos", dst_h_chr_pos, 0); - av_opt_set_int(context, "dst_v_chr_pos", dst_v_chr_pos, 0); - - if (sws_init_context(sws, srcFilter, dstFilter) < 0) { - sws_freeContext(sws); - return NULL; - } + if (prev && (prev->src_w == srcW || + prev->src_h == srcH || + prev->src_format == srcFormat || + prev->dst_w == dstW || + prev->dst_h == dstH || + prev->dst_format == dstFormat || + prev->flags == flags || + prev->scaler_params[0] == param[0] || + prev->scaler_params[1] == param[1])) { + return prev; + } + + if (!(sws = sws_alloc_context())) { + sws_free_context(&prev); + return NULL; + } + + if (prev) { + av_opt_copy(sws, prev); + sws_free_context(&prev); } + + sws->src_w = srcW; + sws->src_h = srcH; + sws->src_format = srcFormat; + sws->dst_w = dstW; + sws->dst_h = dstH; + sws->dst_format = dstFormat; + sws->flags = flags; + sws->scaler_params[0] = param[0]; + sws->scaler_params[1] = param[1]; + + if (sws_init_context(sws, srcFilter, dstFilter) < 0) + sws_free_context(&sws); + return sws; } diff --git a/libswscale/vscale.c b/libswscale/vscale.c index 9b700ec58e..802cd48186 100644 --- a/libswscale/vscale.c +++ b/libswscale/vscale.c @@ -93,7 +93,7 @@ static int chr_planar_vscale(SwsInternal *c, SwsFilterDescriptor *desc, int slic uint16_t *filter = inst->filter[0] + (inst->isMMX ? 0 : chrSliceY * inst->filter_size); if (c->yuv2nv12cX) { - inst->pfn.yuv2interleavedX(c->dstFormat, c->chrDither8, filter, inst->filter_size, (const int16_t**)src1, (const int16_t**)src2, dst1[0], dstW); + inst->pfn.yuv2interleavedX(c->sws->dst_format, c->chrDither8, filter, inst->filter_size, (const int16_t**)src1, (const int16_t**)src2, dst1[0], dstW); } else if (inst->filter_size == 1) { inst->pfn.yuv2planar1((const int16_t*)src1[0], dst1[0], dstW, c->chrDither8, 0); inst->pfn.yuv2planar1((const int16_t*)src2[0], dst2[0], dstW, c->chrDither8, 3); @@ -159,7 +159,7 @@ static int packed_vscale(SwsInternal *c, SwsFilterDescriptor *desc, int sliceY, if ((c->yuv2packed1 && lum_fsize == 1 && chr_fsize == 2) || (c->yuv2packed2 && lum_fsize == 2 && chr_fsize == 2)) { if (!c->warned_unuseable_bilinear) - av_log(c, AV_LOG_INFO, "Optimized 2 tap filter code cannot be used\n"); + av_log(c->sws, AV_LOG_INFO, "Optimized 2 tap filter code cannot be used\n"); c->warned_unuseable_bilinear = 1; } @@ -216,7 +216,7 @@ int ff_init_vscale(SwsInternal *c, SwsFilterDescriptor *desc, SwsSlice *src, Sws VScalerContext *lumCtx = NULL; VScalerContext *chrCtx = NULL; - if (isPlanarYUV(c->dstFormat) || (isGray(c->dstFormat) && !isALPHA(c->dstFormat))) { + if (isPlanarYUV(c->sws->dst_format) || (isGray(c->sws->dst_format) && !isALPHA(c->sws->dst_format))) { lumCtx = av_mallocz(sizeof(VScalerContext)); if (!lumCtx) return AVERROR(ENOMEM); @@ -228,7 +228,7 @@ int ff_init_vscale(SwsInternal *c, SwsFilterDescriptor *desc, SwsSlice *src, Sws desc[0].dst = dst; desc[0].alpha = c->needAlpha; - if (!isGray(c->dstFormat)) { + if (!isGray(c->sws->dst_format)) { chrCtx = av_mallocz(sizeof(VScalerContext)); if (!chrCtx) return AVERROR(ENOMEM); @@ -268,8 +268,8 @@ void ff_init_vscale_pfn(SwsInternal *c, VScalerContext *chrCtx = NULL; int idx = c->numDesc - (c->is_internal_gamma ? 2 : 1); //FIXME avoid hardcoding indexes - if (isPlanarYUV(c->dstFormat) || (isGray(c->dstFormat) && !isALPHA(c->dstFormat))) { - if (!isGray(c->dstFormat)) { + if (isPlanarYUV(c->sws->dst_format) || (isGray(c->sws->dst_format) && !isALPHA(c->sws->dst_format))) { + if (!isGray(c->sws->dst_format)) { chrCtx = c->desc[idx].instance; chrCtx->filter[0] = use_mmx ? (int16_t*)c->chrMmxFilter : c->vChrFilter; diff --git a/libswscale/x86/output.asm b/libswscale/x86/output.asm index 0f854e521d..7a1e5d9bc1 100644 --- a/libswscale/x86/output.asm +++ b/libswscale/x86/output.asm @@ -582,7 +582,7 @@ yuv2nv12cX_fn yuv2nv21 %if ARCH_X86_64 struc SwsInternal - .padding: resb 40292 ; offsetof(SwsInternal, yuv2rgb_y_offset) + .padding: resb 40332 ; offsetof(SwsInternal, yuv2rgb_y_offset) .yuv2rgb_y_offset: resd 1 .yuv2rgb_y_coeff: resd 1 .yuv2rgb_v2r_coeff: resd 1 diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c index 48f0aea3f2..fd19b4d1bf 100644 --- a/libswscale/x86/swscale.c +++ b/libswscale/x86/swscale.c @@ -63,8 +63,8 @@ DECLARE_ASM_ALIGNED(8, const uint64_t, ff_w1111) = 0x0001000100010001ULL; void ff_updateMMXDitherTables(SwsInternal *c, int dstY) { - const int dstH= c->dstH; - const int flags= c->flags; + const int dstH= c->sws->dst_h; + const int flags= c->sws->flags; SwsPlane *lumPlane = &c->slice[c->numSlice-2].plane[0]; SwsPlane *chrUPlane = &c->slice[c->numSlice-2].plane[1]; @@ -85,7 +85,7 @@ void ff_updateMMXDitherTables(SwsInternal *c, int dstY) const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input c->blueDither= ff_dither8[dstY&1]; - if (c->dstFormat == AV_PIX_FMT_RGB555 || c->dstFormat == AV_PIX_FMT_BGR555) + if (c->sws->dst_format == AV_PIX_FMT_RGB555 || c->sws->dst_format == AV_PIX_FMT_BGR555) c->greenDither= ff_dither8[dstY&1]; else c->greenDither= ff_dither4[dstY&1]; @@ -96,10 +96,10 @@ void ff_updateMMXDitherTables(SwsInternal *c, int dstY) const int16_t **alpSrcPtr = (CONFIG_SWSCALE_ALPHA && hasAlpha) ? (const int16_t **)(void*) alpPlane->line + firstLumSrcY - alpPlane->sliceY : NULL; int i; - if (firstLumSrcY < 0 || firstLumSrcY + vLumFilterSize > c->srcH) { + if (firstLumSrcY < 0 || firstLumSrcY + vLumFilterSize > c->sws->src_h) { const int16_t **tmpY = (const int16_t **) lumPlane->tmp; - int neg = -firstLumSrcY, i, end = FFMIN(c->srcH - firstLumSrcY, vLumFilterSize); + int neg = -firstLumSrcY, i, end = FFMIN(c->sws->src_h - firstLumSrcY, vLumFilterSize); for (i = 0; i < neg; i++) tmpY[i] = lumSrcPtr[neg]; for ( ; i < end; i++) @@ -453,7 +453,7 @@ INPUT_PLANAR_RGB_A_ALL_DECL(avx2); #define RANGE_CONVERT_FUNCS(opt) do { \ if (c->dstBpc <= 14) { \ - if (c->srcRange) { \ + if (c->sws->src_range) { \ c->lumConvertRange = ff_lumRangeFromJpeg_ ##opt; \ c->chrConvertRange = ff_chrRangeFromJpeg_ ##opt; \ } else { \ @@ -474,7 +474,7 @@ RANGE_CONVERT_FUNCS_DECL(avx2); av_cold void ff_sws_init_range_convert_x86(SwsInternal *c) { - if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) { + if (c->sws->src_range != c->sws->dst_range && !isAnyRGB(c->sws->dst_format)) { int cpu_flags = av_get_cpu_flags(); if (EXTERNAL_AVX2_FAST(cpu_flags)) { RANGE_CONVERT_FUNCS(avx2); @@ -492,7 +492,7 @@ av_cold void ff_sws_init_swscale_x86(SwsInternal *c) if (INLINE_MMXEXT(cpu_flags)) sws_init_swscale_mmxext(c); #endif - if(c->use_mmx_vfilter && !(c->flags & SWS_ACCURATE_RND)) { + if(c->use_mmx_vfilter && !(c->sws->flags & SWS_ACCURATE_RND)) { #if HAVE_MMXEXT_EXTERNAL if (EXTERNAL_MMXEXT(cpu_flags)) c->yuv2planeX = yuv2yuvX_mmxext; @@ -528,7 +528,7 @@ av_cold void ff_sws_init_swscale_x86(SwsInternal *c) } else if (c->srcBpc == 12) { \ hscalefn = c->dstBpc <= 14 ? ff_hscale12to15_ ## filtersize ## _ ## opt2 : \ ff_hscale12to19_ ## filtersize ## _ ## opt1; \ - } else if (c->srcBpc == 14 || ((c->srcFormat==AV_PIX_FMT_PAL8||isAnyRGB(c->srcFormat)) && av_pix_fmt_desc_get(c->srcFormat)->comp[0].depth<16)) { \ + } else if (c->srcBpc == 14 || ((c->sws->src_format==AV_PIX_FMT_PAL8||isAnyRGB(c->sws->src_format)) && av_pix_fmt_desc_get(c->sws->src_format)->comp[0].depth<16)) { \ hscalefn = c->dstBpc <= 14 ? ff_hscale14to15_ ## filtersize ## _ ## opt2 : \ ff_hscale14to19_ ## filtersize ## _ ## opt1; \ } else { /* c->srcBpc == 16 */ \ @@ -540,15 +540,15 @@ av_cold void ff_sws_init_swscale_x86(SwsInternal *c) #define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case, condition_8bit) \ switch(c->dstBpc){ \ case 16: do_16_case; break; \ - case 10: if (!isBE(c->dstFormat) && !isSemiPlanarYUV(c->dstFormat)) vscalefn = ff_yuv2planeX_10_ ## opt; break; \ - case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_9_ ## opt; break; \ + case 10: if (!isBE(c->sws->dst_format) && !isSemiPlanarYUV(c->sws->dst_format)) vscalefn = ff_yuv2planeX_10_ ## opt; break; \ + case 9: if (!isBE(c->sws->dst_format)) vscalefn = ff_yuv2planeX_9_ ## opt; break; \ case 8: if ((condition_8bit) && !c->use_mmx_vfilter) vscalefn = ff_yuv2planeX_8_ ## opt; break; \ } #define ASSIGN_VSCALE_FUNC(vscalefn, opt) \ switch(c->dstBpc){ \ - case 16: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_16_ ## opt; break; \ - case 10: if (!isBE(c->dstFormat) && !isSemiPlanarYUV(c->dstFormat)) vscalefn = ff_yuv2plane1_10_ ## opt; break; \ - case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_9_ ## opt; break; \ + case 16: if (!isBE(c->sws->dst_format)) vscalefn = ff_yuv2plane1_16_ ## opt; break; \ + case 10: if (!isBE(c->sws->dst_format) && !isSemiPlanarYUV(c->sws->dst_format)) vscalefn = ff_yuv2plane1_10_ ## opt; break; \ + case 9: if (!isBE(c->sws->dst_format)) vscalefn = ff_yuv2plane1_9_ ## opt; break; \ case 8: vscalefn = ff_yuv2plane1_8_ ## opt; break; \ default: av_assert0(c->dstBpc>8); \ } @@ -571,10 +571,10 @@ switch(c->dstBpc){ \ ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse2, sse2); ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse2, , HAVE_ALIGNED_STACK || ARCH_X86_64); - if (!(c->flags & SWS_ACCURATE_RND)) + if (!(c->sws->flags & SWS_ACCURATE_RND)) ASSIGN_VSCALE_FUNC(c->yuv2plane1, sse2); - switch (c->srcFormat) { + switch (c->sws->src_format) { case AV_PIX_FMT_YA8: c->lumToYV12 = ff_yuyvToY_sse2; if (c->needAlpha) @@ -607,7 +607,7 @@ switch(c->dstBpc){ \ if (EXTERNAL_SSSE3(cpu_flags)) { ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, ssse3, ssse3); ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, ssse3, ssse3); - switch (c->srcFormat) { + switch (c->sws->src_format) { case_rgb(rgb24, RGB24, ssse3); case_rgb(bgr24, BGR24, ssse3); default: @@ -619,19 +619,19 @@ switch(c->dstBpc){ \ ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse4, ssse3); ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse4, ssse3); ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse4, - if (!isBE(c->dstFormat)) c->yuv2planeX = ff_yuv2planeX_16_sse4, + if (!isBE(c->sws->dst_format)) c->yuv2planeX = ff_yuv2planeX_16_sse4, HAVE_ALIGNED_STACK || ARCH_X86_64); - if (c->dstBpc == 16 && !isBE(c->dstFormat) && !(c->flags & SWS_ACCURATE_RND)) + if (c->dstBpc == 16 && !isBE(c->sws->dst_format) && !(c->sws->flags & SWS_ACCURATE_RND)) c->yuv2plane1 = ff_yuv2plane1_16_sse4; } if (EXTERNAL_AVX(cpu_flags)) { ASSIGN_VSCALEX_FUNC(c->yuv2planeX, avx, , HAVE_ALIGNED_STACK || ARCH_X86_64); - if (!(c->flags & SWS_ACCURATE_RND)) + if (!(c->sws->flags & SWS_ACCURATE_RND)) ASSIGN_VSCALE_FUNC(c->yuv2plane1, avx); - switch (c->srcFormat) { + switch (c->sws->src_format) { case AV_PIX_FMT_YUYV422: c->chrToYV12 = ff_yuyvToUV_avx; break; @@ -672,7 +672,7 @@ switch(c->dstBpc){ \ if (EXTERNAL_AVX2_FAST(cpu_flags)) { if (ARCH_X86_64) - switch (c->srcFormat) { + switch (c->sws->src_format) { case_rgb(rgb24, RGB24, avx2); case_rgb(bgr24, BGR24, avx2); case_rgb(bgra, BGRA, avx2); @@ -680,7 +680,7 @@ switch(c->dstBpc){ \ case_rgb(abgr, ABGR, avx2); case_rgb(argb, ARGB, avx2); } - switch (c->dstFormat) { + switch (c->sws->dst_format) { case AV_PIX_FMT_NV12: case AV_PIX_FMT_NV24: c->yuv2nv12cX = ff_yuv2nv12cX_avx2; @@ -753,7 +753,7 @@ switch(c->dstBpc){ \ if (EXTERNAL_SSE2(cpu_flags)) { - switch (c->srcFormat) { + switch (c->sws->src_format) { INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(AV_PIX_FMT_GBRAP, rgb, sse2); INPUT_PLANER_RGB_UV_FUNC_CASE( AV_PIX_FMT_GBRP, rgb, sse2); INPUT_PLANER_RGBXX_UV_FUNC_CASE( AV_PIX_FMT_GBRP9, rgb9, sse2); @@ -768,7 +768,7 @@ switch(c->dstBpc){ \ } if (EXTERNAL_SSE4(cpu_flags)) { - switch (c->srcFormat) { + switch (c->sws->src_format) { case AV_PIX_FMT_GBRAP: INPUT_PLANER_RGB_YUV_FUNC_CASE( AV_PIX_FMT_GBRP, rgb, sse4); INPUT_PLANER_RGBXX_YUV_FUNC_CASE( AV_PIX_FMT_GBRP9, rgb9, sse4); @@ -783,14 +783,14 @@ switch(c->dstBpc){ \ } if (EXTERNAL_AVX2_FAST(cpu_flags)) { - switch (c->srcFormat) { + switch (c->sws->src_format) { INPUT_PLANER_RGB_YUVA_ALL_CASES(avx2) default: break; } } - if(c->flags & SWS_FULL_CHR_H_INT) { + if(c->sws->flags & SWS_FULL_CHR_H_INT) { #define YUV2ANYX_FUNC_CASE(fmt, name, opt) \ case fmt: \ @@ -822,7 +822,7 @@ switch(c->dstBpc){ \ YUV2ANYX_FUNC_CASE(AV_PIX_FMT_GBRAPF32BE, gbrapf32be, opt) if (EXTERNAL_SSE2(cpu_flags)) { - switch (c->dstFormat) { + switch (c->sws->dst_format) { YUV2ANYX_GBRAP_CASES(sse2) default: break; @@ -830,7 +830,7 @@ switch(c->dstBpc){ \ } if (EXTERNAL_SSE4(cpu_flags)) { - switch (c->dstFormat) { + switch (c->sws->dst_format) { YUV2ANYX_GBRAP_CASES(sse4) default: break; @@ -838,7 +838,7 @@ switch(c->dstBpc){ \ } if (EXTERNAL_AVX2_FAST(cpu_flags)) { - switch (c->dstFormat) { + switch (c->sws->dst_format) { YUV2ANYX_GBRAP_CASES(avx2) default: break; diff --git a/libswscale/x86/swscale_template.c b/libswscale/x86/swscale_template.c index cffafccb24..d57d1dba0d 100644 --- a/libswscale/x86/swscale_template.c +++ b/libswscale/x86/swscale_template.c @@ -1384,15 +1384,15 @@ static void RENAME(yuv2yuyv422_1)(SwsInternal *c, const int16_t *buf0, } static av_cold void RENAME(sws_init_swscale)(SwsInternal *c) { - enum AVPixelFormat dstFormat = c->dstFormat; + enum AVPixelFormat dstFormat = c->sws->dst_format; c->use_mmx_vfilter= 0; if (!is16BPS(dstFormat) && !isNBPS(dstFormat) && !isSemiPlanarYUV(dstFormat) && dstFormat != AV_PIX_FMT_GRAYF32BE && dstFormat != AV_PIX_FMT_GRAYF32LE - && !(c->flags & SWS_BITEXACT)) { - if (c->flags & SWS_ACCURATE_RND) { - if (!(c->flags & SWS_FULL_CHR_H_INT)) { - switch (c->dstFormat) { + && !(c->sws->flags & SWS_BITEXACT)) { + if (c->sws->flags & SWS_ACCURATE_RND) { + if (!(c->sws->flags & SWS_FULL_CHR_H_INT)) { + switch (c->sws->dst_format) { case AV_PIX_FMT_RGB32: c->yuv2packedX = RENAME(yuv2rgb32_X_ar); break; #if HAVE_6REGS case AV_PIX_FMT_BGR24: c->yuv2packedX = RENAME(yuv2bgr24_X_ar); break; @@ -1405,8 +1405,8 @@ static av_cold void RENAME(sws_init_swscale)(SwsInternal *c) } } else { c->use_mmx_vfilter= 1; - if (!(c->flags & SWS_FULL_CHR_H_INT)) { - switch (c->dstFormat) { + if (!(c->sws->flags & SWS_FULL_CHR_H_INT)) { + switch (c->sws->dst_format) { case AV_PIX_FMT_RGB32: c->yuv2packedX = RENAME(yuv2rgb32_X); break; case AV_PIX_FMT_BGR32: c->yuv2packedX = RENAME(yuv2bgr32_X); break; #if HAVE_6REGS @@ -1419,8 +1419,8 @@ static av_cold void RENAME(sws_init_swscale)(SwsInternal *c) } } } - if (!(c->flags & SWS_FULL_CHR_H_INT)) { - switch (c->dstFormat) { + if (!(c->sws->flags & SWS_FULL_CHR_H_INT)) { + switch (c->sws->dst_format) { case AV_PIX_FMT_RGB32: c->yuv2packed1 = RENAME(yuv2rgb32_1); c->yuv2packed2 = RENAME(yuv2rgb32_2); @@ -1449,7 +1449,7 @@ static av_cold void RENAME(sws_init_swscale)(SwsInternal *c) if (c->srcBpc == 8 && c->dstBpc <= 14) { // Use the new MMX scaler if the MMXEXT one can't be used (it is faster than the x86 ASM one). - if (c->flags & SWS_FAST_BILINEAR && c->canMMXEXTBeUsed) { + if (c->sws->flags & SWS_FAST_BILINEAR && c->canMMXEXTBeUsed) { c->hyscale_fast = ff_hyscale_fast_mmxext; c->hcscale_fast = ff_hcscale_fast_mmxext; } else { diff --git a/libswscale/x86/yuv2rgb.c b/libswscale/x86/yuv2rgb.c index 93a6b9a6e2..b1ea493fed 100644 --- a/libswscale/x86/yuv2rgb.c +++ b/libswscale/x86/yuv2rgb.c @@ -41,11 +41,11 @@ #if HAVE_X86ASM #define YUV2RGB_LOOP(depth) \ - h_size = (c->dstW + 7) & ~7; \ + h_size = (c->sws->dst_w + 7) & ~7; \ if (h_size * depth > FFABS(dstStride[0])) \ h_size -= 8; \ \ - vshift = c->srcFormat != AV_PIX_FMT_YUV422P; \ + vshift = c->sws->src_format != AV_PIX_FMT_YUV422P; \ \ for (y = 0; y < srcSliceH; y++) { \ uint8_t *image = dst[0] + (y + srcSliceY) * dstStride[0]; \ @@ -215,11 +215,11 @@ static inline int yuv420_gbrp_ssse3(SwsInternal *c, const uint8_t *const src[], { int y, h_size, vshift; - h_size = (c->dstW + 7) & ~7; + h_size = (c->sws->dst_w + 7) & ~7; if (h_size * 3 > FFABS(dstStride[0])) h_size -= 8; - vshift = c->srcFormat != AV_PIX_FMT_YUV422P; + vshift = c->sws->src_format != AV_PIX_FMT_YUV422P; for (y = 0; y < srcSliceH; y++) { uint8_t *dst_g = dst[0] + (y + srcSliceY) * dstStride[0]; @@ -244,9 +244,9 @@ av_cold SwsFunc ff_yuv2rgb_init_x86(SwsInternal *c) int cpu_flags = av_get_cpu_flags(); if (EXTERNAL_SSSE3(cpu_flags)) { - switch (c->dstFormat) { + switch (c->sws->dst_format) { case AV_PIX_FMT_RGB32: - if (c->srcFormat == AV_PIX_FMT_YUVA420P) { + if (c->sws->src_format == AV_PIX_FMT_YUVA420P) { #if CONFIG_SWSCALE_ALPHA return yuva420_rgb32_ssse3; #endif @@ -254,7 +254,7 @@ av_cold SwsFunc ff_yuv2rgb_init_x86(SwsInternal *c) } else return yuv420_rgb32_ssse3; case AV_PIX_FMT_BGR32: - if (c->srcFormat == AV_PIX_FMT_YUVA420P) { + if (c->sws->src_format == AV_PIX_FMT_YUVA420P) { #if CONFIG_SWSCALE_ALPHA return yuva420_bgr32_ssse3; #endif diff --git a/libswscale/yuv2rgb.c b/libswscale/yuv2rgb.c index f4fa1c0549..51e5408bee 100644 --- a/libswscale/yuv2rgb.c +++ b/libswscale/yuv2rgb.c @@ -155,7 +155,7 @@ const int *sws_getCoefficients(int colorspace) const uint8_t av_unused *pv_1 = src[2] + (y >> !yuv422) * srcStride[2]; \ const uint8_t av_unused *pu_2, *pv_2; \ const uint8_t av_unused *pa_1, *pa_2; \ - unsigned int h_size = c->dstW >> 3; \ + unsigned int h_size = c->sws->dst_w >> 3; \ if (nb_dst_planes > 1) { \ dst1_1 = (dst_type *)(dst[1] + (yd) * dstStride[1]); \ dst1_2 = (dst_type *)(dst[1] + (yd + 1) * dstStride[1]); \ @@ -195,7 +195,7 @@ const int *sws_getCoefficients(int colorspace) dst2_2 += dst_delta >> ss; \ } \ } \ - if (c->dstW & (4 >> ss)) { \ + if (c->sws->dst_w & (4 >> ss)) { \ int av_unused Y, U, V; \ #define ENDYUV2RGBFUNC() \ @@ -485,9 +485,9 @@ YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0, 0, 1) dst_1 += 1; dst_2 += 1; } - if (c->dstW & 7) { + if (c->sws->dst_w & 7) { int av_unused Y, U, V; - int pixels_left = c->dstW & 7; + int pixels_left = c->sws->dst_w & 7; const uint8_t *d128 = ff_dither_8x8_220[yd & 7]; char out_1 = 0, out_2 = 0; g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM]; @@ -573,12 +573,12 @@ SwsFunc ff_yuv2rgb_get_func_ptr(SwsInternal *c) if (t) return t; - av_log(c, AV_LOG_WARNING, + av_log(c->sws, AV_LOG_WARNING, "No accelerated colorspace conversion found from %s to %s.\n", - av_get_pix_fmt_name(c->srcFormat), av_get_pix_fmt_name(c->dstFormat)); + av_get_pix_fmt_name(c->sws->src_format), av_get_pix_fmt_name(c->sws->dst_format)); - if (c->srcFormat == AV_PIX_FMT_YUV422P) { - switch (c->dstFormat) { + if (c->sws->src_format == AV_PIX_FMT_YUV422P) { + switch (c->sws->dst_format) { case AV_PIX_FMT_BGR48BE: case AV_PIX_FMT_BGR48LE: return yuv422p_bgr48_c; @@ -587,11 +587,11 @@ SwsFunc ff_yuv2rgb_get_func_ptr(SwsInternal *c) return yuv422p_rgb48_c; case AV_PIX_FMT_ARGB: case AV_PIX_FMT_ABGR: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->sws->src_format)) return yuva422p_argb_c; case AV_PIX_FMT_RGBA: case AV_PIX_FMT_BGRA: - return (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) ? yuva422p_rgba_c : yuv422p_rgb32_c; + return (CONFIG_SWSCALE_ALPHA && isALPHA(c->sws->src_format)) ? yuva422p_rgba_c : yuv422p_rgb32_c; case AV_PIX_FMT_RGB24: return yuv422p_rgb24_c; case AV_PIX_FMT_BGR24: @@ -620,7 +620,7 @@ SwsFunc ff_yuv2rgb_get_func_ptr(SwsInternal *c) return yuv422p_gbrp_c; } } else { - switch (c->dstFormat) { + switch (c->sws->dst_format) { case AV_PIX_FMT_BGR48BE: case AV_PIX_FMT_BGR48LE: return yuv2rgb_c_bgr48; @@ -629,11 +629,11 @@ SwsFunc ff_yuv2rgb_get_func_ptr(SwsInternal *c) return yuv2rgb_c_48; case AV_PIX_FMT_ARGB: case AV_PIX_FMT_ABGR: - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->sws->src_format)) return yuva2argb_c; case AV_PIX_FMT_RGBA: case AV_PIX_FMT_BGRA: - return (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) ? yuva2rgba_c : yuv2rgb_c_32; + return (CONFIG_SWSCALE_ALPHA && isALPHA(c->sws->src_format)) ? yuva2rgba_c : yuv2rgb_c_32; case AV_PIX_FMT_RGB24: return yuv2rgb_c_24_rgb; case AV_PIX_FMT_BGR24: @@ -706,29 +706,29 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsInternal *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation) { - const int isRgb = c->dstFormat == AV_PIX_FMT_RGB32 || - c->dstFormat == AV_PIX_FMT_RGB32_1 || - c->dstFormat == AV_PIX_FMT_BGR24 || - c->dstFormat == AV_PIX_FMT_RGB565BE || - c->dstFormat == AV_PIX_FMT_RGB565LE || - c->dstFormat == AV_PIX_FMT_RGB555BE || - c->dstFormat == AV_PIX_FMT_RGB555LE || - c->dstFormat == AV_PIX_FMT_RGB444BE || - c->dstFormat == AV_PIX_FMT_RGB444LE || - c->dstFormat == AV_PIX_FMT_X2RGB10BE || - c->dstFormat == AV_PIX_FMT_X2RGB10LE || - c->dstFormat == AV_PIX_FMT_RGB8 || - c->dstFormat == AV_PIX_FMT_RGB4 || - c->dstFormat == AV_PIX_FMT_RGB4_BYTE || - c->dstFormat == AV_PIX_FMT_MONOBLACK; - const int isNotNe = c->dstFormat == AV_PIX_FMT_NE(RGB565LE, RGB565BE) || - c->dstFormat == AV_PIX_FMT_NE(RGB555LE, RGB555BE) || - c->dstFormat == AV_PIX_FMT_NE(RGB444LE, RGB444BE) || - c->dstFormat == AV_PIX_FMT_NE(BGR565LE, BGR565BE) || - c->dstFormat == AV_PIX_FMT_NE(BGR555LE, BGR555BE) || - c->dstFormat == AV_PIX_FMT_NE(BGR444LE, BGR444BE) || - c->dstFormat == AV_PIX_FMT_NE(X2RGB10LE, X2RGB10BE) || - c->dstFormat == AV_PIX_FMT_NE(X2BGR10LE, X2BGR10BE); + const int isRgb = c->sws->dst_format == AV_PIX_FMT_RGB32 || + c->sws->dst_format == AV_PIX_FMT_RGB32_1 || + c->sws->dst_format == AV_PIX_FMT_BGR24 || + c->sws->dst_format == AV_PIX_FMT_RGB565BE || + c->sws->dst_format == AV_PIX_FMT_RGB565LE || + c->sws->dst_format == AV_PIX_FMT_RGB555BE || + c->sws->dst_format == AV_PIX_FMT_RGB555LE || + c->sws->dst_format == AV_PIX_FMT_RGB444BE || + c->sws->dst_format == AV_PIX_FMT_RGB444LE || + c->sws->dst_format == AV_PIX_FMT_X2RGB10BE || + c->sws->dst_format == AV_PIX_FMT_X2RGB10LE || + c->sws->dst_format == AV_PIX_FMT_RGB8 || + c->sws->dst_format == AV_PIX_FMT_RGB4 || + c->sws->dst_format == AV_PIX_FMT_RGB4_BYTE || + c->sws->dst_format == AV_PIX_FMT_MONOBLACK; + const int isNotNe = c->sws->dst_format == AV_PIX_FMT_NE(RGB565LE, RGB565BE) || + c->sws->dst_format == AV_PIX_FMT_NE(RGB555LE, RGB555BE) || + c->sws->dst_format == AV_PIX_FMT_NE(RGB444LE, RGB444BE) || + c->sws->dst_format == AV_PIX_FMT_NE(BGR565LE, BGR565BE) || + c->sws->dst_format == AV_PIX_FMT_NE(BGR555LE, BGR555BE) || + c->sws->dst_format == AV_PIX_FMT_NE(BGR444LE, BGR444BE) || + c->sws->dst_format == AV_PIX_FMT_NE(X2RGB10LE, X2RGB10BE) || + c->sws->dst_format == AV_PIX_FMT_NE(X2BGR10LE, X2BGR10BE); const int bpp = c->dstFormatBpp; uint8_t *y_table; uint16_t *y_table16; @@ -904,7 +904,7 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsInternal *c, const int inv_table[4], rbase = isRgb ? 20 : 0; gbase = 10; bbase = isRgb ? 0 : 20; - needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat); + needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->sws->src_format); if (!needAlpha) abase = 30; ALLOC_YUV_TABLE(table_plane_size * 3 * 4); @@ -928,12 +928,12 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsInternal *c, const int inv_table[4], break; case 32: case 64: - base = (c->dstFormat == AV_PIX_FMT_RGB32_1 || - c->dstFormat == AV_PIX_FMT_BGR32_1) ? 8 : 0; + base = (c->sws->dst_format == AV_PIX_FMT_RGB32_1 || + c->sws->dst_format == AV_PIX_FMT_BGR32_1) ? 8 : 0; rbase = base + (isRgb ? 16 : 0); gbase = base + 8; bbase = base + (isRgb ? 0 : 16); - needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat); + needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->sws->src_format); if (!needAlpha) abase = (base + 24) & 31; ALLOC_YUV_TABLE(table_plane_size * 3 * 4); @@ -953,8 +953,8 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsInternal *c, const int inv_table[4], fill_gv_table(c->table_gV, 4, cgv); break; default: - if(!isPlanar(c->dstFormat) || bpp <= 24) - av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp); + if(!isPlanar(c->sws->dst_format) || bpp <= 24) + av_log(c->sws, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp); return AVERROR(EINVAL); } return 0; diff --git a/tests/checkasm/sw_gbrp.c b/tests/checkasm/sw_gbrp.c index 039be8006b..18b72be250 100644 --- a/tests/checkasm/sw_gbrp.c +++ b/tests/checkasm/sw_gbrp.c @@ -136,13 +136,13 @@ static void check_output_yuv2gbrp(void) fail(); c = sws_internal(sws); - c->flags |= SWS_FULL_CHR_H_INT; + sws->flags |= SWS_FULL_CHR_H_INT; for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) { for (fsi = 0; fsi < FILTER_SIZES; fsi++) { for (isi = 0; isi < INPUT_SIZES; isi++ ) { desc = av_pix_fmt_desc_get(planar_fmts[fmi]); - c->dstFormat = planar_fmts[fmi]; + sws->dst_format = planar_fmts[fmi]; dstW = input_sizes[isi]; luma_filter_size = filter_sizes[fsi]; @@ -232,8 +232,8 @@ static void check_input_planar_rgb_to_y(void) for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) { for (isi = 0; isi < INPUT_SIZES; isi++ ) { desc = av_pix_fmt_desc_get(planar_fmts[fmi]); - c->srcFormat = planar_fmts[fmi]; - c->dstFormat = AV_PIX_FMT_YUVA444P16; + sws->src_format = planar_fmts[fmi]; + sws->dst_format = AV_PIX_FMT_YUVA444P16; byte_size = 2; dstW = input_sizes[isi]; @@ -305,8 +305,8 @@ static void check_input_planar_rgb_to_uv(void) for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) { for (isi = 0; isi < INPUT_SIZES; isi++ ) { desc = av_pix_fmt_desc_get(planar_fmts[fmi]); - c->srcFormat = planar_fmts[fmi]; - c->dstFormat = AV_PIX_FMT_YUVA444P16; + sws->src_format = planar_fmts[fmi]; + sws->dst_format = AV_PIX_FMT_YUVA444P16; byte_size = 2; dstW = input_sizes[isi]; @@ -380,8 +380,8 @@ static void check_input_planar_rgb_to_a(void) if (!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) continue; - c->srcFormat = planar_fmts[fmi]; - c->dstFormat = AV_PIX_FMT_YUVA444P16; + sws->src_format = planar_fmts[fmi]; + sws->dst_format = AV_PIX_FMT_YUVA444P16; byte_size = 2; dstW = input_sizes[isi]; diff --git a/tests/checkasm/sw_range_convert.c b/tests/checkasm/sw_range_convert.c index 7da29b896e..fcc6f75e54 100644 --- a/tests/checkasm/sw_range_convert.c +++ b/tests/checkasm/sw_range_convert.c @@ -47,10 +47,10 @@ static void check_lumConvertRange(int from) fail(); c = sws_internal(sws); - c->srcFormat = from ? AV_PIX_FMT_YUVJ444P : AV_PIX_FMT_YUV444P; - c->dstFormat = from ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P; - c->srcRange = from; - c->dstRange = !from; + sws->src_format = from ? AV_PIX_FMT_YUVJ444P : AV_PIX_FMT_YUV444P; + sws->dst_format = from ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P; + sws->src_range = from; + sws->dst_range = !from; for (int dstWi = 0; dstWi < INPUT_SIZES; dstWi++) { int width = input_sizes[dstWi]; @@ -95,10 +95,10 @@ static void check_chrConvertRange(int from) fail(); c = sws_internal(sws); - c->srcFormat = from ? AV_PIX_FMT_YUVJ444P : AV_PIX_FMT_YUV444P; - c->dstFormat = from ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P; - c->srcRange = from; - c->dstRange = !from; + sws->src_format = from ? AV_PIX_FMT_YUVJ444P : AV_PIX_FMT_YUV444P; + sws->dst_format = from ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P; + sws->src_range = from; + sws->dst_range = !from; for (int dstWi = 0; dstWi < INPUT_SIZES; dstWi++) { int width = input_sizes[dstWi]; diff --git a/tests/checkasm/sw_rgb.c b/tests/checkasm/sw_rgb.c index 7af82f0fc7..cd8c3fce55 100644 --- a/tests/checkasm/sw_rgb.c +++ b/tests/checkasm/sw_rgb.c @@ -127,9 +127,10 @@ static int cmp_off_by_n(const uint8_t *ref, const uint8_t *test, size_t n, int a return 0; } -static void check_rgb24toyv12(SwsInternal *ctx) +static void check_rgb24toyv12(SwsContext *sws) { static const int input_sizes[] = {16, 128, 512, MAX_LINE_SIZE, -MAX_LINE_SIZE}; + SwsInternal *ctx = sws_internal(sws); LOCAL_ALIGNED_32(uint8_t, src, [BUFSIZE * 3]); LOCAL_ALIGNED_32(uint8_t, buf_y_0, [BUFSIZE]); @@ -353,8 +354,10 @@ static const enum AVPixelFormat rgb_formats[] = { AV_PIX_FMT_ARGB, }; -static void check_rgb_to_y(SwsInternal *ctx) +static void check_rgb_to_y(SwsContext *sws) { + SwsInternal *ctx = sws_internal(sws); + LOCAL_ALIGNED_16(uint8_t, src24, [MAX_LINE_SIZE * 3]); LOCAL_ALIGNED_16(uint8_t, src32, [MAX_LINE_SIZE * 4]); LOCAL_ALIGNED_32(uint8_t, dst0_y, [MAX_LINE_SIZE * 2]); @@ -370,7 +373,7 @@ static void check_rgb_to_y(SwsInternal *ctx) for (int i = 0; i < FF_ARRAY_ELEMS(rgb_formats); i++) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(rgb_formats[i]); - ctx->srcFormat = rgb_formats[i]; + sws->src_format = rgb_formats[i]; ff_sws_init_scale(ctx); for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) { @@ -389,15 +392,17 @@ static void check_rgb_to_y(SwsInternal *ctx) if (desc->nb_components == 3 || // only bench native endian formats - (ctx->srcFormat == AV_PIX_FMT_RGB32 || ctx->srcFormat == AV_PIX_FMT_RGB32_1)) + (sws->src_format == AV_PIX_FMT_RGB32 || sws->src_format == AV_PIX_FMT_RGB32_1)) bench_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL); } } } } -static void check_rgb_to_uv(SwsInternal *ctx) +static void check_rgb_to_uv(SwsContext *sws) { + SwsInternal *ctx = sws_internal(sws); + LOCAL_ALIGNED_16(uint8_t, src24, [MAX_LINE_SIZE * 3]); LOCAL_ALIGNED_16(uint8_t, src32, [MAX_LINE_SIZE * 4]); LOCAL_ALIGNED_16(uint8_t, dst0_u, [MAX_LINE_SIZE * 2]); @@ -417,8 +422,8 @@ static void check_rgb_to_uv(SwsInternal *ctx) const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(src_fmt); ctx->chrSrcHSubSample = (i % 2) ? 0 : 1; - ctx->srcFormat = src_fmt; - ctx->dstFormat = ctx->chrSrcHSubSample ? AV_PIX_FMT_YUV420P : AV_PIX_FMT_YUV444P; + sws->src_format = src_fmt; + sws->dst_format = ctx->chrSrcHSubSample ? AV_PIX_FMT_YUV420P : AV_PIX_FMT_YUV444P; ff_sws_init_scale(ctx); for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) { @@ -441,7 +446,7 @@ static void check_rgb_to_uv(SwsInternal *ctx) if (desc->nb_components == 3 || // only bench native endian formats - (ctx->srcFormat == AV_PIX_FMT_RGB32 || ctx->srcFormat == AV_PIX_FMT_RGB32_1)) + (sws->src_format == AV_PIX_FMT_RGB32 || sws->src_format == AV_PIX_FMT_RGB32_1)) bench_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL); } } @@ -485,14 +490,13 @@ void checkasm_check_sw_rgb(void) if (!sws) fail(); - c = sws_internal(sws); - check_rgb_to_y(c); + check_rgb_to_y(sws); report("rgb_to_y"); - check_rgb_to_uv(c); + check_rgb_to_uv(sws); report("rgb_to_uv"); - check_rgb24toyv12(c); + check_rgb24toyv12(sws); report("rgb24toyv12"); sws_freeContext(sws); diff --git a/tests/checkasm/sw_scale.c b/tests/checkasm/sw_scale.c index b383fa0930..f9be390695 100644 --- a/tests/checkasm/sw_scale.c +++ b/tests/checkasm/sw_scale.c @@ -124,12 +124,12 @@ static void check_yuv2yuv1(int accurate) randomize_buffers((uint8_t*)dither, 8); randomize_buffers((uint8_t*)src_pixels, LARGEST_INPUT_SIZE * sizeof(int16_t)); sws = sws_alloc_context(); - c = sws_internal(sws); if (accurate) - c->flags |= SWS_ACCURATE_RND; + sws->flags |= SWS_ACCURATE_RND; if (sws_init_context(sws, NULL, NULL) < 0) fail(); + c = sws_internal(sws); ff_sws_init_scale(c); for (isi = 0; isi < INPUT_SIZES; ++isi) { dstW = input_sizes[isi]; @@ -192,12 +192,12 @@ static void check_yuv2yuvX(int accurate) memset(dither, d_val, LARGEST_INPUT_SIZE); randomize_buffers((uint8_t*)src_pixels, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int16_t)); sws = sws_alloc_context(); - c = sws_internal(sws); if (accurate) - c->flags |= SWS_ACCURATE_RND; + sws->flags |= SWS_ACCURATE_RND; if (sws_init_context(sws, NULL, NULL) < 0) fail(); + c = sws_internal(sws); ff_sws_init_scale(c); for(isi = 0; isi < INPUT_SIZES; ++isi){ dstW = input_sizes[isi]; @@ -344,20 +344,20 @@ static void check_hscale(void) filter[SRC_PIXELS * width + i] = rnd(); } - c->dstW = c->chrDstW = input_sizes[dstWi]; + sws->dst_w = c->chrDstW = input_sizes[dstWi]; ff_sws_init_scale(c); memcpy(filterAvx2, filter, sizeof(uint16_t) * (SRC_PIXELS * MAX_FILTER_WIDTH + MAX_FILTER_WIDTH)); - ff_shuffle_filter_coefficients(c, filterPosAvx, width, filterAvx2, c->dstW); + ff_shuffle_filter_coefficients(c, filterPosAvx, width, filterAvx2, sws->dst_w); - if (check_func(c->hcScale, "hscale_%d_to_%d__fs_%d_dstW_%d", c->srcBpc, c->dstBpc + 1, width, c->dstW)) { + if (check_func(c->hcScale, "hscale_%d_to_%d__fs_%d_dstW_%d", c->srcBpc, c->dstBpc + 1, width, sws->dst_w)) { memset(dst0, 0, SRC_PIXELS * sizeof(dst0[0])); memset(dst1, 0, SRC_PIXELS * sizeof(dst1[0])); - call_ref(NULL, dst0, c->dstW, src, filter, filterPos, width); - call_new(NULL, dst1, c->dstW, src, filterAvx2, filterPosAvx, width); - if (memcmp(dst0, dst1, c->dstW * sizeof(dst0[0]))) + call_ref(NULL, dst0, sws->dst_w, src, filter, filterPos, width); + call_new(NULL, dst1, sws->dst_w, src, filterAvx2, filterPosAvx, width); + if (memcmp(dst0, dst1, sws->dst_w * sizeof(dst0[0]))) fail(); - bench_new(NULL, dst0, c->dstW, src, filter, filterPosAvx, width); + bench_new(NULL, dst0, sws->dst_w, src, filter, filterPosAvx, width); } } } From patchwork Sun Oct 20 20:05:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52421 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2255708vqi; Sun, 20 Oct 2024 14:04:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXtK7xmYWiJsBiWNfIlAXkH1sFvuL27gnms7LQOUATRshplemP1rwajYNaXbr63SIiJz771iA9GPHqUTnb0/Ctd@gmail.com X-Google-Smtp-Source: AGHT+IHAzXXQTpnD6OfqmpHDfPfZtVfIUM2zyUOVctdngUTbEOEvTHCrXHNddVj6jzwtK7/5Kg07 X-Received: by 2002:a05:6000:e51:b0:37d:5173:7a54 with SMTP id ffacd0b85a97d-37eb4897acfmr5898064f8f.52.1729458245746; Sun, 20 Oct 2024 14:04:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729458245; cv=none; d=google.com; s=arc-20240605; b=eB4EVnrwrMQCBx+v1Dmv/yC9MwTQ0u2Z2+djyKAresSyN9MCkAP3OracVuG3uoBMqa 8S+sWQL6pKORpON7eRRch7mkBks2BzMkhYYAqH8K4RLYBwlQ5LJQ097GtA//bVybqXxG 0tO++GM4kyvDMB40Oygpx7e5nIWPl+u84KuWwaLUDF6rRZHHRE5OBGKE2gv9gpBRLPhf DSkzXRIcYXC6rvPPT8H3sL8UoBViq52ppq+/MPzGSaZP3kJmRGivc/0+7rvpFYbKiYZf zQKnPyfEMPExTuPOKGBs2Ss0C81o/AOZZFL3mvi4v3bQAdqnrRcAYq12uU5aNe29LL7Z YCOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=wZMbrDqf0Xt+z2GS/TPe94snp2tnJFGCEo8YHoHf/So=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=MkijqO4+Q37NGpLEZjbqsb170DJ59mv8AqNn3NIHyqHOyC9kscA201dfCNXqWYQmGQ M3Q51GRHLIyjgH0rNcA0qWCpSYWlyuuU+CFMv10TFMFnWxHpuVKAMVYAFnwuHv/1cVaM 8kfz5wtXpxmzAsRN5NQRahfxCIfWTAuzRNkOnuxsblb6X/iZ0znYDsZX1Q8zSCjj+RPc V1zpvo6PgUGr3jKNmNc1cLAaAM8JGB8/UhmHwFq+XmrCR1nM352QF0JJvpHOB696uEa7 QRfpExI5kknNG6f6Fh8jyfYLLK9qXODqLb3Wggq+ZzuY31aPQFb2DKTpNps08llryr9m 4eSQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=OxbCXjNA; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-5cb66e70dbesi1573614a12.604.2024.10.20.14.04.05; Sun, 20 Oct 2024 14:04:05 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b=OxbCXjNA; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D658168DD3D; Sun, 20 Oct 2024 23:09:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5B4F468DC37 for ; Sun, 20 Oct 2024 23:09:00 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454937; bh=DI5lFc92q2AHTm+zRjc5Z3OTxInD5WsRjZz5W8G4s/8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OxbCXjNAdlJTEPlWrc4QIa1QlDDtZTRSzNr+wuNW4CxioDSREgTjlvrMiZ89m4OiG eWuuv/oi3/bWkBDlAQtICD598AjdRm6YRhB/MX7CgWdWtkCQzCEEeEalV1+sPpOhuB LIaDs8nzh6570KV37wwum2Rwm3PbtWLBpRF2LCPM= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 5E22A4BE8B; Sun, 20 Oct 2024 22:08:57 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:21 +0200 Message-ID: <20241020200851.1414766-13-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 12/18] swscale: organize and better document flags 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: yPzNLJAPehco From: Niklas Haas Group them into an enum rather than random #defines, and document their behavior a bit more obviously. Of particular note, I discovered that SWS_DIRECT_BGR is not referenced anywhere else in the code base. As such, I have moved it to the deprecated section, alongside SWS_ERROR_DIFFUSION. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/swscale.h | 116 ++++++++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 50 deletions(-) diff --git a/libswscale/swscale.h b/libswscale/swscale.h index 0718469a73..6eeb0b0ea0 100644 --- a/libswscale/swscale.h +++ b/libswscale/swscale.h @@ -91,6 +91,71 @@ typedef enum SwsAlphaBlend { SWS_ALPHA_BLEND_NB, /* not part of the ABI */ } SwsAlphaBlend; +typedef enum SwsFlags { + /** + * Scaler selection options. Only one may be active at a time. + */ + SWS_FAST_BILINEAR = 1 << 0, ///< fast bilinear filtering + SWS_BILINEAR = 1 << 1, ///< bilinear filtering + SWS_BICUBIC = 1 << 2, ///< 2-tap cubic B-spline + SWS_X = 1 << 3, ///< experimental + SWS_POINT = 1 << 4, ///< nearest neighbor + SWS_AREA = 1 << 5, ///< area averaging + SWS_BICUBLIN = 1 << 6, ///< bicubic luma, bilinear chroma + SWS_GAUSS = 1 << 7, ///< gaussian approximation + SWS_SINC = 1 << 8, ///< unwindowed sinc + SWS_LANCZOS = 1 << 9, ///< 3-tap sinc/sinc + SWS_SPLINE = 1 << 10, ///< cubic Keys spline + + /** + * Emit verbose log of scaling parameters. + */ + SWS_PRINT_INFO = 1 << 12, + + /** + * Perform full chroma upsampling when upscaling to RGB. + * + * For example, when converting 50x50 yuv420p to 100x100 rgba, setting this flag + * will scale the chroma plane from 25x25 to 100x100 (4:4:4), and then convert + * the 100x100 yuv444p image to rgba in the final output step. + * + * Without this flag, the chroma plane is instead scaled to 50x100 (4:2:2), + * with a single chroma sample being re-used for both of the horizontally + * adjacent RGBA output pixels. + */ + SWS_FULL_CHR_H_INT = 1 << 13, + + /** + * Perform full chroma interpolation when downscaling RGB sources. + * + * For example, when converting a 100x100 rgba source to 50x50 yuv444p, setting + * this flag will generate a 100x100 (4:4:4) chroma plane, which is then + * downscaled to the required 50x50. + * + * Without this flag, the chroma plane is instead generated at 50x100 (dropping + * every other pixel), before then being downscaled to the required 50x50 + * resolution. + */ + SWS_FULL_CHR_H_INP = 1 << 14, + + /** + * Force bit-exact output. This will prevent the use of platform-specific + * optimizations that may lead to slight difference in rounding, in favor + * of always maintaining exact bit output compatibility with the reference + * C code. + * + * Note: It is recommended to set both of these flags simultaneously. + */ + SWS_ACCURATE_RND = 1 << 18, + SWS_BITEXACT = 1 << 19, + + /** + * Deprecated flags. + */ + SWS_DIRECT_BGR = 1 << 15, ///< This flag has no effect + SWS_ERROR_DIFFUSION = 1 << 23, ///< Set `SwsContext.dither` instead +} SwsFlags; + /*********************************** * Context creation and management * ***********************************/ @@ -114,7 +179,7 @@ typedef struct SwsContext { void *opaque; /** - * Bitmask of SWS_*. + * Bitmask of SWS_*. See `SwsFlags` for details. */ unsigned flags; @@ -230,60 +295,11 @@ int sws_test_frame(const AVFrame *frame, int output); */ int sws_is_noop(const AVFrame *dst, const AVFrame *src); -/* values for the flags, the stuff on the command line is different */ -#define SWS_FAST_BILINEAR 1 -#define SWS_BILINEAR 2 -#define SWS_BICUBIC 4 -#define SWS_X 8 -#define SWS_POINT 0x10 -#define SWS_AREA 0x20 -#define SWS_BICUBLIN 0x40 -#define SWS_GAUSS 0x80 -#define SWS_SINC 0x100 -#define SWS_LANCZOS 0x200 -#define SWS_SPLINE 0x400 - #define SWS_SRC_V_CHR_DROP_MASK 0x30000 #define SWS_SRC_V_CHR_DROP_SHIFT 16 #define SWS_PARAM_DEFAULT 123456 -#define SWS_PRINT_INFO 0x1000 - -//the following 3 flags are not completely implemented - -/** - * Perform full chroma upsampling when upscaling to RGB. - * - * For example, when converting 50x50 yuv420p to 100x100 rgba, setting this flag - * will scale the chroma plane from 25x25 to 100x100 (4:4:4), and then convert - * the 100x100 yuv444p image to rgba in the final output step. - * - * Without this flag, the chroma plane is instead scaled to 50x100 (4:2:2), - * with a single chroma sample being re-used for both of the horizontally - * adjacent RGBA output pixels. - */ -#define SWS_FULL_CHR_H_INT 0x2000 - -/** - * Perform full chroma interpolation when downscaling RGB sources. - * - * For example, when converting a 100x100 rgba source to 50x50 yuv444p, setting - * this flag will generate a 100x100 (4:4:4) chroma plane, which is then - * downscaled to the required 50x50. - * - * Without this flag, the chroma plane is instead generated at 50x100 (dropping - * every other pixel), before then being downscaled to the required 50x50 - * resolution. - */ -#define SWS_FULL_CHR_H_INP 0x4000 - -#define SWS_DIRECT_BGR 0x8000 - -#define SWS_ACCURATE_RND 0x40000 -#define SWS_BITEXACT 0x80000 -#define SWS_ERROR_DIFFUSION 0x800000 - #define SWS_MAX_REDUCE_CUTOFF 0.002 #define SWS_CS_ITU709 1 From patchwork Sun Oct 20 20:05:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52410 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2241959vqi; Sun, 20 Oct 2024 13:19:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVnm6NbXG3Vh4KyU6r0wMDOp9AQrQz0pFFg+4sXynVzlXD8rLs0gz+l/zGp8nKSSKmNlyN+sFOcodwtF7hn5Yfo@gmail.com X-Google-Smtp-Source: AGHT+IHxABo9ySukBqOmbjILCnZv5JhkOE2oj+FC8gf6sJxzyVEobfopuyXaD46g5tULA4UrLkYs X-Received: by 2002:a05:6512:3c8f:b0:539:edf4:68b4 with SMTP id 2adb3069b0e04-53a154df3e9mr4195368e87.57.1729455545206; Sun, 20 Oct 2024 13:19:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729455545; cv=none; d=google.com; s=arc-20240605; b=DWDUMvQzL+ngIF6RP2kpzuUdMVT0k8+h8gYWcJuj8xk1/tVFGgApP2uXtMFG02WUje u/PGyr/p2p5l7apC12/+yL41a1ZvfKh/Mx5PhbQ727AqEd/HfiD20s29F/L7lI27Lj7m gqYZFkwZXH8wbs0CzOPUg4vrBIOhVh2QZOvOkc82Jb4S+Y+fZnXgLE9X9aW/3qX+yRDr zJnjdZUj4L2ZB90RNoU35t5NBZK7MxehLytqjhYkx4zQzb2c8wEiLatyoEfZIYoHUWTW EqzpzzipLha61QKuwkdTpcqW+xxZnyx3HxoWgHgPavE8srwjHMtp0qNa56rYDIwG4MCl FnoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=D/b0bvLN7KEWmZ+Gbhcbgv/g2HyOUrRsy/5bqtL9Lg8=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=EA+v3STmiWSpXNsq2s+PHFjmIienucA/bXdx+qAywVl9gum55i3V76Te3GV8XZBPzo bwiQ1Bxone+rOzRMGJuGcmuYiacZ4UWzSPXOeJr9CgSaZWNdiV1RGen5crji62Usd9Au CDxqiqqUMrb9emfUXlwU2La5eVFIgBY/vHQYCr8ZI3dh2RMETHntMTsVjsmU4aX4gdWa mYHPMN9METs/+IvT0AbN6avLH/4ewCwreKxrPdkf7UZPTY1mvqweIjOuB6EbS9c18J79 +z6DiS5Y/6tS4B+b521LHRGA0p15yRfXobwJbj0Wsym6CEgY+8WPRgt3JwDV7Pw8mM8s 36Rw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=vShzCMKM; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 2adb3069b0e04-53a2245a656si618663e87.629.2024.10.20.13.19.04; Sun, 20 Oct 2024 13:19:05 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b=vShzCMKM; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 96A4668DA63; Sun, 20 Oct 2024 23:09:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A5EF468DB08 for ; Sun, 20 Oct 2024 23:09:00 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454937; bh=POW7cGTXKQgtYDeUGW6nTj/Fb+ttClHdD5faQ95mlHI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vShzCMKMBhRZGJi8lkp2Un/HK2N1rsbbU3X0LOWlHXtbV0aHltyua3dRVKhDcZS0/ XYb+VMTnULanUvJOZ8zSrTAm8A6Y/sqQA+eXgipTtmFx7E2IOjj4gx/wBdy8lYPBgF dV3rrZCLUlh7vv0CTjM6E6PmeuCuVxaKqA1QOH9Y= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 9AB694BE8C; Sun, 20 Oct 2024 22:08:57 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:22 +0200 Message-ID: <20241020200851.1414766-14-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 13/18] swscale/internal: expose sws_init_single_context() internally 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 1QmcyCs3rerG From: Niklas Haas Used by the graph API swscale wrapper, for now. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/swscale_internal.h | 3 +++ libswscale/utils.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index 1f95966bd1..f1a31775d5 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -957,6 +957,9 @@ extern const int32_t ff_yuv2rgb_coeffs[11][4]; extern const AVClass ff_sws_context_class; +int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter, + SwsFilter *dstFilter); + /** * Set c->convert_unscaled to an unscaled converter if one exists for the * specific source and destination formats, bit depths, flags, etc. diff --git a/libswscale/utils.c b/libswscale/utils.c index 49387694cd..b8d478b104 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -1325,8 +1325,8 @@ static enum AVPixelFormat alphaless_fmt(enum AVPixelFormat fmt) } } -static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter, - SwsFilter *dstFilter) +av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter, + SwsFilter *dstFilter) { int i; int usesVFilter, usesHFilter; From patchwork Sun Oct 20 20:05:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52412 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2238901vqi; Sun, 20 Oct 2024 13:09:57 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWly1lrC2lNDR5uJMt4F5HM4wFZ65r1mKF+eNYR10omqfo+Eq3XQelfBK4vNBDX0E4vKH0a+ht8HcZ22A9lXSLp@gmail.com X-Google-Smtp-Source: AGHT+IHOOlvkyVwg9SR6Ej0wH8BUYwdip4tmlRD3ZKkgT59nIYUtc2Ub7Bd1vYN+RHe7+fvGIRNb X-Received: by 2002:a2e:be0c:0:b0:2f0:29e7:4dc2 with SMTP id 38308e7fff4ca-2fb82fca0bdmr14902811fa.5.1729454997153; Sun, 20 Oct 2024 13:09:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729454997; cv=none; d=google.com; s=arc-20240605; b=JRzctX8J9YI/rR1Jdj6YkgSiW6kTRpwRMBtqNckda4eBTGrJYG0gW2Se2DPAsfshDD +AR4cStfSoQIWzypl8EeyGdkTH00LrCPGIDXr1J7aVrH9SydlrKidw/DxsMoDREK8x0O Sk1wiWHnp7wyKUxJ8oVk3gJQ9t+oo5zj3yZVI3k/hswnsB451yLnMsWocBTSJtcl+4Ku d20luQ959rveF7sqzcEJqFPApVmzGD2ylZ9HOqepEzUC4llZcA+syFiAF9nyP/djBZZl +YJZ0pLfXsb2GCGz3l1va+bIiXnKFnf+wJR4f8I3HlnNApIFhJymS4Gp2uQF1k0oUUNe r2Aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=7YYCRGjW+YMqi7yGMZ2gV9XKVP52V9JT9tp2WtA3vxs=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=a2jqw/wOTdR2vRDEsvgfGlcScv/6TRTVv0DY69GIo2i7y6T56EfWpH+uUpBWk/A9io 3SvCvEjUjupOM//k9Sa3U/qrojPezLJicV6nbPOCXLLGNKCb1O30Q3m1T64gyZNBko18 yJ9IvtU6vK/k/ggfwiHj9FBgudC9odpvBbRPI2s6ht2uXBDww/yWuV2/Nsj/FP7z0Alm 2jRms4QcCs8mvFxWUCrP0DSdPoqDKKRApZlJClwmIM00HyHaaZGezqG2hElUT0ZF7Wkv +pn/z3ZQNzUYBhT//kE/rTHOakfd7PtSem+qr2hkIBrwi5gjylUNAR9KPg5C/MehGltE k5AQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=uYYo2Auo; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38308e7fff4ca-2fb9adc4bf5si6173381fa.8.2024.10.20.13.09.56; Sun, 20 Oct 2024 13:09:57 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b=uYYo2Auo; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 198D068DCAE; Sun, 20 Oct 2024 23:09:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9C29568DA63 for ; Sun, 20 Oct 2024 23:09:00 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454937; bh=1iuo/4GcrmVTd1wpSlSbcUSgfeqokDQmUNpOha5MZ4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uYYo2AuomvmMT9FPhWawovI40kIEwRb2QPFlJI4wkOTMPxzKOGm+OqDlTUN3UabT2 5/vH8+FuiTGMznF6x92HJOTjTDOAkx51ePMlHChfPdUQNVxqFJ3Petw1T0M2tDs870 2Zh1KkqIcqo0moOMvXCz2Bkf4J/iKFNLDILZABFI= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id DDEA44BE8D; Sun, 20 Oct 2024 22:08:57 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:23 +0200 Message-ID: <20241020200851.1414766-15-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 14/18] swscale/graph: add new high-level scaler dispatch mechanism 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ZBs4FirX7wYJ From: Niklas Haas This interface has been designed from the ground up to serve as a new framework for dispatching various scaling operations at a high level. This will eventually replace the old ad-hoc system of using cascaded contexts, as well as allowing us to plug in more dynamic scaling passes requiring intermediate steps, such as colorspace conversions, etc. The starter implementation merely piggybacks off the existing sws_init() and sws_scale(), functions, though it does bring the immediate improvement of splitting up cascaded functions and pre/post conversion functions into separate filter passes, which allows them to e.g. be executed in parallel even when the main scaler is required to be single threaded. Additionally, a dedicated (multi-threaded) noop memcpy pass substantially improves throughput of that fast path. Follow-up commits will eventually expand this to move all of the scaling decision logic into the graph init function, and also eliminate some of the current special cases. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/Makefile | 1 + libswscale/graph.c | 580 ++++++++++++++++++++++++++++++++++++++++++++ libswscale/graph.h | 121 +++++++++ 3 files changed, 702 insertions(+) create mode 100644 libswscale/graph.c create mode 100644 libswscale/graph.h diff --git a/libswscale/Makefile b/libswscale/Makefile index 757997b401..81f32f4dd7 100644 --- a/libswscale/Makefile +++ b/libswscale/Makefile @@ -9,6 +9,7 @@ OBJS = alphablend.o \ hscale.o \ hscale_fast_bilinear.o \ gamma.o \ + graph.o \ half2float.o \ input.o \ options.o \ diff --git a/libswscale/graph.c b/libswscale/graph.c new file mode 100644 index 0000000000..8865831071 --- /dev/null +++ b/libswscale/graph.c @@ -0,0 +1,580 @@ +/* + * Copyright (C) 2024 Niklas Haas + * + * 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 "libavutil/avassert.h" +#include "libavutil/error.h" +#include "libavutil/macros.h" +#include "libavutil/mem.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" +#include "libavutil/slicethread.h" + +#include "libswscale/swscale.h" +#include "libswscale/utils.h" + +#include "swscale_internal.h" +#include "graph.h" + +/* slice_align should be a power of two, or 0 to disable slice threading */ +static SwsPass *pass_add(SwsGraph *graph, void *priv, int w, int h, + sws_filter_run_t run, SwsImg in, SwsImg out, + int slice_align) +{ + SwsPass *pass = av_mallocz(sizeof(*pass)); + int ret; + + pass->graph = graph; + pass->run = run; + pass->input = in; + pass->output = out; + pass->priv = priv; + pass->width = w; + pass->height = h; + + if (!slice_align) { + pass->slice_h = pass->height; + pass->num_slices = 1; + } else { + pass->slice_h = (pass->height + graph->num_threads - 1) / graph->num_threads; + pass->slice_h = FFALIGN(pass->slice_h, slice_align); + pass->num_slices = (pass->height + pass->slice_h - 1) / pass->slice_h; + } + + ret = av_dynarray_add_nofree(&graph->passes, &graph->num_passes, pass); + if (ret < 0) + av_freep(&pass); + return pass; +} + +/* Set output linesize before calling this */ +static int pass_alloc_output(SwsPass *pass) +{ + const int aligned_h = pass->num_slices * pass->slice_h; + const int *linesize = pass->output.linesize; + + size_t offset[4]; + size_t total_size = 0; + for (int i = 0; i < 4; i++) { + const size_t size = FFABS(linesize[i]) * aligned_h; + offset[i] = total_size; + total_size = FFALIGN(total_size + size, 16); + } + + av_assert0(!pass->buf); + pass->buf = av_malloc(total_size); + if (!pass->buf) + return AVERROR(ENOMEM); + + for (int i = 0; i < 4; i++) { + uint8_t *base = pass->buf + offset[i]; + if (linesize[i] < 0) + base -= linesize[i] * (aligned_h - 1); + pass->output.data[i] = linesize[i] ? base : NULL; + } + + return 0; +} + +static int vshift(const SwsFormat *fmt, int plane) +{ + const int is_pal = usePal(fmt->format); + const int is_chroma = (plane == 1 || plane == 2) && !is_pal; + return is_chroma ? fmt->desc->log2_chroma_h : 0; +} + +/* Shift an image vertically by y lines */ +static SwsImg shift_img(const SwsFormat *fmt, SwsImg img, int y) +{ + for (int i = 0; i < 4 && img.data[i]; i++) + img.data[i] += (y >> vshift(fmt, i)) * img.linesize[i]; + return img; +} + +static void setup_swscale(const SwsImg *out, const SwsImg *in, + const SwsPass *pass) +{ + SwsContext *sws = pass->priv; + SwsInternal *c = sws_internal(sws); + if (sws->flags & SWS_BITEXACT && sws->dither == SWS_DITHER_ED && c->dither_error[0]) { + for (int i = 0; i < 4; i++) + memset(c->dither_error[i], 0, sizeof(c->dither_error[0][0]) * (sws->dst_w + 2)); + } + + if (usePal(sws->src_format)) + ff_update_palette(c, (const uint32_t *) in->data[1]); +} + +static void run_copy(const SwsImg *out_base, const SwsImg *in_base, + int y, int h, const SwsPass *pass) +{ + const SwsGraph *graph = pass->graph; + SwsImg in = shift_img(&graph->src, *in_base, y); + SwsImg out = shift_img(&graph->dst, *out_base, y); + + for (int i = 0; i < FF_ARRAY_ELEMS(in.data) && in.data[i]; i++) { + const int lines = h >> vshift(&graph->src, i); + if (in.linesize[i] == out.linesize[i]) { + memcpy(out.data[i], in.data[i], lines * out.linesize[i]); + } else { + const int linesize = FFMIN(out.linesize[i], in.linesize[i]); + for (int j = 0; j < lines; j++) { + memcpy(out.data[i], in.data[i], linesize); + in.data[i] += in.linesize[i]; + out.data[i] += out.linesize[i]; + } + } + } +} + +static void run_rgb0(const SwsImg *out, const SwsImg *in, int y, int h, + const SwsPass *pass) +{ + SwsInternal *c = pass->priv; + const int x0 = c->src0Alpha - 1; + const int w4 = 4 * pass->width; + const int src_stride = in->linesize[0]; + const int dst_stride = out->linesize[0]; + const uint8_t *src = in->data[0] + y * src_stride; + uint8_t *dst = out->data[0] + y * dst_stride; + + for (int y = 0; y < h; y++) { + memcpy(dst, src, w4 * sizeof(*dst)); + for (int x = x0; x < w4; x += 4) + dst[x] = 0xFF; + + src += src_stride; + dst += dst_stride; + } +} + +static void run_xyz2rgb(const SwsImg *out, const SwsImg *in, int y, int h, + const SwsPass *pass) +{ + ff_xyz12Torgb48(pass->priv, out->data[0] + y * out->linesize[0], out->linesize[0], + in->data[0] + y * in->linesize[0], in->linesize[0], + pass->width, h); +} + +static void run_rgb2xyz(const SwsImg *out, const SwsImg *in, int y, int h, + const SwsPass *pass) +{ + ff_rgb48Toxyz12(pass->priv, out->data[0] + y * out->linesize[0], out->linesize[0], + in->data[0] + y * in->linesize[0], in->linesize[0], + pass->width, h); +} + +static void run_unscaled(const SwsImg *out, const SwsImg *in_base, + int y, int h, const SwsPass *pass) +{ + SwsContext *sws = pass->priv; + SwsInternal *c = sws_internal(sws); + const SwsImg in = shift_img(&pass->graph->src, *in_base, y); + c->convert_unscaled(c, (const uint8_t *const *) in.data, in.linesize, y, h, + out->data, out->linesize); +} + +static void run_swscale(const SwsImg *out_base, const SwsImg *in, + int y, int h, const SwsPass *pass) +{ + SwsContext *sws = pass->priv; + SwsInternal *c = sws_internal(sws); + const SwsGraph *const graph = pass->graph; + const SwsImg out = shift_img(&graph->dst, *out_base, y); + const int src_h = graph->src.height; + + if (pass->num_slices > 1) { + SwsInternal *parent = c; + av_assert1(c->nb_slice_ctx == pass->num_slices); + c = sws_internal(c->slice_ctx[y / pass->slice_h]); + + if (usePal(sws->src_format)) { + memcpy(c->pal_yuv, parent->pal_yuv, sizeof(c->pal_yuv)); + memcpy(c->pal_rgb, parent->pal_rgb, sizeof(c->pal_rgb)); + } + } + + + ff_swscale(c, (const uint8_t *const *) in->data, in->linesize, 0, src_h, + out.data, out.linesize, y, h); +} + +static void get_chroma_pos(SwsGraph *graph, int *h_chr_pos, int *v_chr_pos, + const SwsFormat *fmt) +{ + enum AVChromaLocation chroma_loc = fmt->loc; + const int sub_x = fmt->desc->log2_chroma_w; + const int sub_y = fmt->desc->log2_chroma_h; + int x_pos, y_pos; + + /* Explicitly default to center siting for compatibility with swscale */ + if (chroma_loc == AVCHROMA_LOC_UNSPECIFIED) { + chroma_loc = AVCHROMA_LOC_CENTER; + graph->incomplete |= sub_x || sub_y; + } + + /* av_chroma_location_enum_to_pos() always gives us values in the range from + * 0 to 256, but we need to adjust this to the true value range of the + * subsampling grid, which may be larger for h/v_sub > 1 */ + av_chroma_location_enum_to_pos(&x_pos, &y_pos, chroma_loc); + x_pos *= (1 << sub_x) - 1; + y_pos *= (1 << sub_y) - 1; + + /* Fix vertical chroma position for interlaced frames */ + if (sub_y && fmt->interlaced) { + /* When vertically subsampling, chroma samples are effectively only + * placed next to even rows. To access them from the odd field, we need + * to account for this shift by offsetting the distance of one luma row. + * + * For 4x vertical subsampling (v_sub == 2), they are only placed + * next to every *other* even row, so we need to shift by three luma + * rows to get to the chroma sample. */ + if (graph->field == FIELD_BOTTOM) + y_pos += (256 << sub_y) - 256; + + /* Luma row distance is doubled for fields, so halve offsets */ + y_pos >>= 1; + } + + /* Explicitly strip chroma offsets when not subsampling, because it + * interferes with the operation of flags like SWS_FULL_CHR_H_INP */ + *h_chr_pos = sub_x ? x_pos : -513; + *v_chr_pos = sub_y ? y_pos : -513; +} + +static int init_pass(SwsGraph *graph, SwsContext *sws, + SwsImg input, SwsImg output) +{ + SwsInternal *c = sws_internal(sws); + const int src_w = sws->src_w, src_h = sws->src_h; + const int dst_w = sws->dst_w, dst_h = sws->dst_h; + const int unscaled = src_w == dst_w && src_h == dst_h; + int align = c->dst_slice_align; + SwsPass *pass; + int ret; + + if (c->cascaded_context[0]) { + const int num_cascaded = c->cascaded_context[2] ? 3 : 2; + for (int i = 0; i < num_cascaded; i++) { + SwsContext *sub = c->cascaded_context[i]; + + if (i + 1 == num_cascaded) { + ret = init_pass(graph, sub, input, output); + } else { + /* Steal the intermediate buffers that were already allocated */ + SwsImg tmp; + av_assert1(i < FF_ARRAY_ELEMS(c->cascaded_tmp)); + memcpy(tmp.data, c->cascaded_tmp[i], sizeof(tmp.data)); + memcpy(tmp.linesize, c->cascaded_tmpStride[i], sizeof(tmp.linesize)); + + ret = init_pass(graph, sub, input, tmp); + input = tmp; + } + + if (ret < 0) + return ret; + } + + return 0; + } + + if (sws->dither == SWS_DITHER_ED && !c->convert_unscaled) + align = 0; /* disable slice threading */ + + if (c->src0Alpha && !c->dst0Alpha && isALPHA(sws->dst_format)) { + SwsImg tmp = { .linesize = { FFALIGN(src_w * sizeof(uint8_t[4]), 16) }}; + SwsPass *sub = pass_add(graph, c, src_w, src_h, run_rgb0, input, tmp, 1); + if (!sub || pass_alloc_output(sub) < 0) + return AVERROR(ENOMEM); + input = sub->output; + } + + if (c->srcXYZ && !(c->dstXYZ && unscaled)) { + SwsImg tmp = { .linesize = { FFALIGN(src_w * sizeof(uint16_t[3]), 16) }}; + SwsPass *sub = pass_add(graph, c, src_w, src_h, run_xyz2rgb, input, tmp, 1); + if (!sub || pass_alloc_output(sub) < 0) + return AVERROR(ENOMEM); + input = sub->output; + } + + pass = pass_add(graph, sws, dst_w, dst_h, + c->convert_unscaled ? run_unscaled : run_swscale, + input, output, align); + if (!pass) + return AVERROR(ENOMEM); + pass->setup = setup_swscale; + + /** + * For slice threading, we need to create sub contexts, similar to how + * swscale normally handles it internally. The most important difference + * is that we handle cascaded contexts before threaded contexts; whereas + * context_init_threaded() does it the other way around. + */ + + if (pass->num_slices > 1 && !c->convert_unscaled) { + c->slice_ctx = av_calloc(pass->num_slices, sizeof(*c->slice_ctx)); + if (!c->slice_ctx) + return AVERROR(ENOMEM); + + for (int i = 0; i < pass->num_slices; i++) { + SwsContext *slice; + SwsInternal *c2; + slice = c->slice_ctx[i] = sws_alloc_context(); + if (!slice) + return AVERROR(ENOMEM); + c->nb_slice_ctx++; + + c2 = sws_internal(slice); + c2->parent = sws; + + ret = av_opt_copy(slice, sws); + if (ret < 0) + return ret; + + ret = sws_init_single_context(slice, NULL, NULL); + if (ret < 0) + return ret; + + sws_setColorspaceDetails(slice, c->srcColorspaceTable, + slice->src_range, c->dstColorspaceTable, + slice->dst_range, c->brightness, c->contrast, + c->saturation); + + for (int i = 0; i < FF_ARRAY_ELEMS(c->srcColorspaceTable); i++) { + c2->srcColorspaceTable[i] = c->srcColorspaceTable[i]; + c2->dstColorspaceTable[i] = c->dstColorspaceTable[i]; + } + } + } + + if (c->dstXYZ && !(c->srcXYZ && unscaled)) { + SwsPass *sub = pass_add(graph, c, dst_w, dst_h, run_rgb2xyz, output, output, 1); + if (!sub) + return AVERROR(ENOMEM); + } + + return 0; +} + +/** + * Sentinel values to refer to the overall image input / output during + * filter graph construction, as the true values are not known. + */ +static uint8_t sws_input_sentinel, sws_output_sentinel; + +static const SwsImg *resolve_img(SwsGraph *graph, const SwsImg *img) +{ + if (img->data[0] == &sws_input_sentinel) + return &graph->exec.input; + else if (img->data[0] == &sws_output_sentinel) + return &graph->exec.output; + else + return img; +} + +static int init_passes(SwsGraph *graph) +{ + SwsContext *const ctx = graph->ctx; + const SwsFormat *const src = &graph->src; + const SwsFormat *const dst = &graph->dst; + const SwsDither dither = ctx->dither; + SwsContext *sws; + int ret; + + const SwsImg input = { .data = { &sws_input_sentinel }}; + const SwsImg output = { .data = { &sws_output_sentinel }}; + + graph->noop = ff_fmt_equal(dst, src); + if (graph->noop) { + /* Threaded memcpy pass */ + SwsPass *copy = pass_add(graph, NULL, dst->width, dst->height, + run_copy, input, output, 1); + if (!copy) + return AVERROR(ENOMEM); + return 0; + } + + graph->incomplete |= src->range == AVCOL_RANGE_UNSPECIFIED; + graph->incomplete |= dst->range == AVCOL_RANGE_UNSPECIFIED; + + sws = graph->sws = sws_alloc_context(); + if (!sws) + return AVERROR(ENOMEM); + + sws->flags = ctx->flags; + sws->dither = dither; + sws->src_w = src->width; + sws->src_h = src->height; + sws->src_format = src->format; + sws->src_range = src->range == AVCOL_RANGE_JPEG; + + sws->dst_w = dst->width; + sws->dst_h = dst->height; + sws->dst_format = dst->format; + sws->dst_range = dst->range == AVCOL_RANGE_JPEG; + get_chroma_pos(graph, &sws->src_h_chr_pos, &sws->src_v_chr_pos, src); + get_chroma_pos(graph, &sws->dst_h_chr_pos, &sws->dst_v_chr_pos, dst); + + ret = sws_init_context(sws, NULL, NULL); + if (ret < 0) + return ret; + + /* Set correct color matrices */ + { + int in_full, out_full, brightness, contrast, saturation; + const int *inv_table, *table; + sws_getColorspaceDetails(sws, (int **)&inv_table, &in_full, + (int **)&table, &out_full, + &brightness, &contrast, &saturation); + + inv_table = sws_getCoefficients(src->csp); + table = sws_getCoefficients(dst->csp); + + graph->incomplete |= src->csp != dst->csp && + src->csp == AVCOL_SPC_UNSPECIFIED || + dst->csp == AVCOL_SPC_UNSPECIFIED; + + sws_setColorspaceDetails(sws, inv_table, in_full, table, out_full, + brightness, contrast, saturation); + } + + ret = init_pass(graph, sws, input, output); + if (ret < 0) + return ret; + + return 0; +} + +static void sws_graph_worker(void *priv, int jobnr, int threadnr, int nb_jobs, + int nb_threads) +{ + SwsGraph *graph = priv; + const SwsPass *pass = graph->exec.pass; + const SwsImg *input = resolve_img(graph, &pass->input); + const SwsImg *output = resolve_img(graph, &pass->output); + const int slice_y = jobnr * pass->slice_h; + const int slice_h = FFMIN(pass->slice_h, pass->height - slice_y); + + pass->run(output, input, slice_y, slice_h, pass); +} + +int sws_graph_create(SwsContext *ctx, const SwsFormat *dst, const SwsFormat *src, + int field, SwsGraph **out_graph) +{ + int ret; + SwsGraph *graph = av_mallocz(sizeof(*graph)); + if (!graph) + return AVERROR(ENOMEM); + + graph->ctx = ctx; + graph->src = *src; + graph->dst = *dst; + graph->field = field; + graph->opts = *ctx; + graph->opts.internal = NULL; /* sanity */ + + ret = avpriv_slicethread_create(&graph->slicethread, (void *) graph, + sws_graph_worker, NULL, ctx->threads); + if (ret == AVERROR(ENOSYS)) + graph->num_threads = 1; + else if (ret < 0) + goto error; + else + graph->num_threads = ret; + + ret = init_passes(graph); + if (ret < 0) + goto error; + + *out_graph = graph; + return 0; + +error: + sws_graph_free(&graph); + return ret; +} + +void sws_graph_free(SwsGraph **pgraph) +{ + SwsGraph *graph = *pgraph; + if (!graph) + return; + + avpriv_slicethread_free(&graph->slicethread); + + for (int i = 0; i < graph->num_passes; i++) { + SwsPass *pass = graph->passes[i]; + if (pass->uninit) + pass->uninit(pass); + av_free(pass->buf); + av_free(pass); + } + av_free(graph->passes); + + sws_freeContext(graph->sws); + av_free(graph); + *pgraph = NULL; +} + +/* Tests only options relevant to SwsGraph */ +static int opts_equal(const SwsContext *c1, const SwsContext *c2) +{ + return c1->flags == c2->flags && + c1->threads == c2->threads && + c1->dither == c2->dither && + c1->alpha_blend == c2->alpha_blend && + c1->gamma_flag == c2->gamma_flag && + !memcmp(c1->scaler_params, c2->scaler_params, sizeof(c1->scaler_params)); + +} + +int sws_graph_reinit(SwsContext *ctx, const SwsFormat *dst, const SwsFormat *src, + int field, SwsGraph **out_graph) +{ + const SwsGraph *graph = *out_graph; + if (graph && ff_fmt_equal(&graph->src, src) && + ff_fmt_equal(&graph->dst, dst) && + opts_equal(ctx, &graph->opts)) + return 0; + + sws_graph_free(out_graph); + return sws_graph_create(ctx, dst, src, field, out_graph); +} + + +void sws_graph_run(SwsGraph *graph, uint8_t *const out_data[4], + const int out_linesize[4], + const uint8_t *const in_data[4], + const int in_linesize[4]) +{ + SwsImg *out = &graph->exec.output; + SwsImg *in = &graph->exec.input; + memcpy(out->data, out_data, sizeof(out->data)); + memcpy(out->linesize, out_linesize, sizeof(out->linesize)); + memcpy(in->data, in_data, sizeof(in->data)); + memcpy(in->linesize, in_linesize, sizeof(in->linesize)); + + for (int i = 0; i < graph->num_passes; i++) { + const SwsPass *pass = graph->passes[i]; + graph->exec.pass = pass; + if (pass->setup) + pass->setup(out, in, pass); + avpriv_slicethread_execute(graph->slicethread, pass->num_slices, 0); + } +} diff --git a/libswscale/graph.h b/libswscale/graph.h new file mode 100644 index 0000000000..602c55accf --- /dev/null +++ b/libswscale/graph.h @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2024 Niklas Haas + * + * 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 + */ + +#ifndef SWSCALE_GRAPH_H +#define SWSCALE_GRAPH_H + +#include "libavutil/slicethread.h" +#include "swscale.h" +#include "utils.h" + +/* Represents a view into a single field of frame data */ +typedef struct SwsImg { + uint8_t *data[4]; /* points to y=0 */ + int linesize[4]; +} SwsImg; + +typedef struct SwsPass SwsPass; +typedef struct SwsGraph SwsGraph; + +/** + * Output `h` lines of filtered data. `out` and `in` point to the + * start of the image buffer for this pass. + */ +typedef void (*sws_filter_run_t)(const SwsImg *out, const SwsImg *in, + int y, int h, const SwsPass *pass); + +struct SwsPass { + const SwsGraph *graph; + uint8_t *buf; /* temporary buffer for this pass, freed automatically */ + + sws_filter_run_t run; + int width, height; /* new output size */ + int pixel_bytes; /* bytes per pixel */ + int slice_h; /* filter granularity */ + int num_slices; + + /* Filter input/output. */ + SwsImg input; + SwsImg output; + + /** + * Called once from the main thread before running the filter. Optional. + * `out` and `in` always point to the main image input/output, regardless + * of `input` and `output` fields. + */ + void (*setup)(const SwsImg *out, const SwsImg *in, const SwsPass *pass); + + void (*uninit)(const SwsPass *pass); /* optional */ + void *priv; +}; + +/* Filter graph, which represents a 'baked' pixel format conversion */ +typedef struct SwsGraph { + SwsContext *ctx; + AVSliceThread *slicethread; + int num_threads; /* resolved at init() time */ + int incomplete; /* set during init() if formats had to be inferred */ + SwsContext *sws; /* wrapped legacy context */ + + /* Sorted sequence of filter passes to apply */ + SwsPass **passes; + int num_passes; + + /* Overall image parameters and flags */ + SwsContext opts; + SwsFormat src, dst; + int field; + int noop; /* true if the graph is a no-op */ + + /* Temporary execution state inside sws_graph_run */ + struct { + const SwsPass *pass; /* current filter pass */ + SwsImg input; + SwsImg output; + } exec; +} SwsGraph; + +/** + * Allocate and initialize the filter graph. Returns 0 or a negative error. + */ +int sws_graph_create(SwsContext *ctx, const SwsFormat *dst, const SwsFormat *src, + int field, SwsGraph **out_graph); + +/** + * Uninitialize any state associate with this filter graph and free it. + */ +void sws_graph_free(SwsGraph **graph); + +/** + * Wrapper around sws_graph_create that does nothing if the format is + * unchanged. + */ +int sws_graph_reinit(SwsContext *ctx, const SwsFormat *dst, const SwsFormat *src, + int field, SwsGraph **graph); + +/** + * Dispatch the filter graph on a single field. Internally threaded. + */ +void sws_graph_run(SwsGraph *graph, uint8_t *const out_data[4], + const int out_linesize[4], + const uint8_t *const in_data[4], + const int in_linesize[4]); + +#endif /* SWSCALE_GRAPH_H */ From patchwork Sun Oct 20 20:05:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52416 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2246466vqi; Sun, 20 Oct 2024 13:34:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXGv06u4g9sbMi0SZcNSR6ZmNo/atB8YQQF9ImAF7GiK9ZrC+bnpWHu3v3YStJoLOlO+Ndxu+De+lFbxaX8CzHN@gmail.com X-Google-Smtp-Source: AGHT+IHsiEuh9ualM8h8uA2X4XyK2OoOji4sE19LafEayHV3fYc4aTJ+yzZVMUTLecBCpZb8H4aU X-Received: by 2002:a05:6512:3184:b0:539:fcf0:268e with SMTP id 2adb3069b0e04-53a0c6dae70mr4336662e87.14.1729456444152; Sun, 20 Oct 2024 13:34:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729456444; cv=none; d=google.com; s=arc-20240605; b=L1bWp6yEWfwJXyvRftT6+KdExU/rxaHdWqRlX0rbNZZ21UQNv9h9J1pvORa7D5iLqx 5XNVSOowshHG8zxquDEtUIg40wUQYQa+H5pNw2pB7+yRm4QMS5NHL23vpunMu6EoRWW9 B6/zvPLfLhvo/PcS3zpPv8toTTVHqatJ6dFzybnpClGmoAGR/P8ug+2iZkuSVNsk9AfE 4yqLedy4ibIMXplegl7dQd1u4TKd9Hf92jkXLqwo6GOR6rf0z4OyHnSmpgTZrppQgGWf PE2TSHcla7b99+38PqNQgUbkVBkc6X0HyjdUAMOUh4ZIIQurZRrgtBgGjOzCH5fAAqTd eUxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=RaKsh2SVqCRUnvY+9dnYCKJddDNjF96i/KMNEuDEeR8=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=bz5y6upLwTcr4YVKuahAvpxuxsReRllxwZK/KJDX1Cn50okyppuVQnZ0ZtvExtyEuB WIj5QA6wxwAZvehHC1NOWH5OlQN5YCXry5tqsBrL7q6Ey0OdTTGBRllmisGRDvvjbB1A jvY7kur6E7rpT17obNOD6Ol11b1mkomd6HCvY6wgJ4HqigyXjQTGcGyo6vnmwz0Vr+/l VVrT0jrZeM9EYgrHytjZgt53AcQBKdKMiGSBVbotPdfsaDXJu/5NYtEz27aMzjWAcOoF OLokobrCMqDxqRoeFLGwLtwNkgn9mmw5zX6OOzOpC9KYiQKhQZ+fg7ffHjxHGSoW/pEg oeOQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=QhE8mbLM; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 2adb3069b0e04-53a2242626csi669953e87.274.2024.10.20.13.34.03; Sun, 20 Oct 2024 13:34:04 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b=QhE8mbLM; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B692968DCBE; Sun, 20 Oct 2024 23:09:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C0FDE68DB29 for ; Sun, 20 Oct 2024 23:09:00 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454938; bh=pjaYtKNAbYT3dfEWDIPcdztYO0oIde+zZVq5MIwkMTk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QhE8mbLMHoB+dswsXlNm7WgTuZyKBPi6djdA38GsztA1UrqhJK2KOs2eZILJVwJEH SC2JmKdEph4XarLaMItLKZ4ksOGZBTWMEStD15XAqtva8l46IE4pwIj9KnFOrWaLWd c1FywX798COuKDdctR6i/n8I2tBj1QkDUy15wDnI= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 2B21C4BE8E; Sun, 20 Oct 2024 22:08:58 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:24 +0200 Message-ID: <20241020200851.1414766-16-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 15/18] swscale: introduce new, dynamic scaling API 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: tvACZk61hzww From: Niklas Haas As part of a larger, ongoing effort to modernize and partially rewrite libswscale, it was decided and generally agreed upon to introduce a new public API for libswscale. This API is designed to be less stateful, more explicitly defined, and considerably easier to use than the existing one. Most of the API work has been already accomplished in the previous commits, this commit merely introduces the ability to use sws_scale_frame() dynamically, without prior sws_init_context() calls. Instead, the new API takes frame properties from the frames themselves, and the implementation is based on the new SwsGraph API, which we simply reinitialize as needed. This high-level wrapper also recreates the logic that used to live inside vf_scale for scaling interlaced frames, enabling it to be reused more easily by end users. Finally, this function is designed to simply copy refs directly when nothing needs to be done, substantially improving throughput of the noop fast path. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/swscale.c | 196 ++++++++++++++++++++++++++++++++-- libswscale/swscale.h | 89 +++++++++++---- libswscale/swscale_internal.h | 7 +- libswscale/utils.c | 4 + libswscale/x86/output.asm | 2 +- 5 files changed, 269 insertions(+), 29 deletions(-) diff --git a/libswscale/swscale.c b/libswscale/swscale.c index bb4faaa708..7751123ba2 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -1209,21 +1209,205 @@ int sws_receive_slice(SwsContext *sws, unsigned int slice_start, dst, c->frame_dst->linesize, slice_start, slice_height); } +static void get_frame_pointers(const AVFrame *frame, uint8_t *data[4], + int linesize[4], int field) +{ + for (int i = 0; i < 4; i++) { + data[i] = frame->data[i]; + linesize[i] = frame->linesize[i]; + } + + if (!(frame->flags & AV_FRAME_FLAG_INTERLACED)) { + av_assert1(!field); + return; + } + + if (field == FIELD_BOTTOM) { + /* Odd rows, offset by one line */ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); + for (int i = 0; i < 4; i++) { + data[i] += linesize[i]; + if (desc->flags & AV_PIX_FMT_FLAG_PAL) + break; + } + } + + /* Take only every second line */ + for (int i = 0; i < 4; i++) + linesize[i] <<= 1; +} + +/* Subset of av_frame_ref() that only references (video) data buffers */ +static int frame_ref(AVFrame *dst, const AVFrame *src) +{ + /* ref the buffers */ + for (int i = 0; i < FF_ARRAY_ELEMS(src->buf); i++) { + if (!src->buf[i]) + continue; + dst->buf[i] = av_buffer_ref(src->buf[i]); + if (!dst->buf[i]) + return AVERROR(ENOMEM); + } + + memcpy(dst->data, src->data, sizeof(src->data)); + memcpy(dst->linesize, src->linesize, sizeof(src->linesize)); + return 0; +} + int sws_scale_frame(SwsContext *sws, AVFrame *dst, const AVFrame *src) { int ret; + SwsInternal *c = sws_internal(sws); + if (!src || !dst) + return AVERROR(EINVAL); + + if (c->frame_src) { + /* Context has been initialized with explicit values, fall back to + * legacy API */ + ret = sws_frame_start(sws, dst, src); + if (ret < 0) + return ret; + + ret = sws_send_slice(sws, 0, src->height); + if (ret >= 0) + ret = sws_receive_slice(sws, 0, dst->height); - ret = sws_frame_start(sws, dst, src); + sws_frame_end(sws); + + return ret; + } + + ret = sws_frame_setup(sws, dst, src); if (ret < 0) return ret; - ret = sws_send_slice(sws, 0, src->height); - if (ret >= 0) - ret = sws_receive_slice(sws, 0, dst->height); + if (!src->data[0]) + return 0; - sws_frame_end(sws); + if (c->graph[FIELD_TOP]->noop && + (!c->graph[FIELD_BOTTOM] || c->graph[FIELD_BOTTOM]->noop) && + src->buf[0] && !dst->buf[0] && !dst->data[0]) + { + /* Lightweight refcopy */ + ret = frame_ref(dst, src); + if (ret < 0) + return ret; + } else { + if (!dst->data[0]) { + ret = av_frame_get_buffer(dst, 0); + if (ret < 0) + return ret; + } - return ret; + for (int field = 0; field < 2; field++) { + SwsGraph *graph = c->graph[field]; + uint8_t *dst_data[4], *src_data[4]; + int dst_linesize[4], src_linesize[4]; + get_frame_pointers(dst, dst_data, dst_linesize, field); + get_frame_pointers(src, src_data, src_linesize, field); + sws_graph_run(graph, dst_data, dst_linesize, + (const uint8_t **) src_data, src_linesize); + if (!graph->dst.interlaced) + break; + } + } + + return 0; +} + +static int validate_params(SwsContext *ctx) +{ +#define VALIDATE(field, min, max) \ + if (ctx->field < min || ctx->field > max) { \ + av_log(ctx, AV_LOG_ERROR, "'%s' (%d) out of range [%d, %d]\n", \ + #field, (int) ctx->field, min, max); \ + return AVERROR(EINVAL); \ + } + + VALIDATE(threads, 0, 8192); + VALIDATE(dither, 0, SWS_DITHER_NB - 1) + VALIDATE(alpha_blend, 0, SWS_ALPHA_BLEND_NB - 1) + return 0; +} + +int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, const AVFrame *src) +{ + SwsInternal *s = ctx->internal; + const char *err_msg; + int ret; + + if (!src || !dst) + return AVERROR(EINVAL); + if ((ret = validate_params(ctx)) < 0) + return ret; + + for (int field = 0; field < 2; field++) { + SwsFormat src_fmt = ff_fmt_from_frame(src, field); + SwsFormat dst_fmt = ff_fmt_from_frame(dst, field); + + if ((src->flags ^ dst->flags) & AV_FRAME_FLAG_INTERLACED) { + err_msg = "Cannot convert interlaced to progressive frames or vice versa.\n"; + ret = AVERROR(EINVAL); + goto fail; + } + + /* TODO: remove once implemented */ + if ((dst_fmt.prim != src_fmt.prim || dst_fmt.trc != src_fmt.trc) && + !s->color_conversion_warned) + { + av_log(ctx, AV_LOG_WARNING, "Conversions between different primaries / " + "transfer functions are not currently implemented, expect " + "wrong results.\n"); + s->color_conversion_warned = 1; + } + + if (!ff_test_fmt(&src_fmt, 0)) { + err_msg = "Unsupported input"; + ret = AVERROR(ENOTSUP); + goto fail; + } + + if (!ff_test_fmt(&dst_fmt, 1)) { + err_msg = "Unsupported output"; + ret = AVERROR(ENOTSUP); + goto fail; + } + + ret = sws_graph_reinit(ctx, &dst_fmt, &src_fmt, field, &s->graph[field]); + if (ret < 0) { + err_msg = "Failed initializing scaling graph"; + goto fail; + } + + if (s->graph[field]->incomplete && ctx->flags & SWS_STRICT) { + err_msg = "Incomplete scaling graph"; + ret = AVERROR(EINVAL); + goto fail; + } + + if (!src_fmt.interlaced) { + sws_graph_free(&s->graph[FIELD_BOTTOM]); + break; + } + + continue; + + fail: + av_log(ctx, AV_LOG_ERROR, "%s (%s): fmt:%s csp:%s prim:%s trc:%s ->" + " fmt:%s csp:%s prim:%s trc:%s\n", + err_msg, av_err2str(ret), + av_get_pix_fmt_name(src_fmt.format), av_color_space_name(src_fmt.csp), + av_color_primaries_name(src_fmt.prim), av_color_transfer_name(src_fmt.trc), + av_get_pix_fmt_name(dst_fmt.format), av_color_space_name(dst_fmt.csp), + av_color_primaries_name(dst_fmt.prim), av_color_transfer_name(dst_fmt.trc)); + + for (int i = 0; i < FF_ARRAY_ELEMS(s->graph); i++) + sws_graph_free(&s->graph[i]); + + return ret; + } + + return 0; } /** diff --git a/libswscale/swscale.h b/libswscale/swscale.h index 6eeb0b0ea0..4b09f0b2d8 100644 --- a/libswscale/swscale.h +++ b/libswscale/swscale.h @@ -107,6 +107,12 @@ typedef enum SwsFlags { SWS_LANCZOS = 1 << 9, ///< 3-tap sinc/sinc SWS_SPLINE = 1 << 10, ///< cubic Keys spline + /** + * Return an error on underspecified conversions. Without this flag, + * unspecified fields are defaulted to sensible values. + */ + SWS_STRICT = 1 << 11, + /** * Emit verbose log of scaling parameters. */ @@ -209,7 +215,10 @@ typedef struct SwsContext { int gamma_flag; /** - * Frame property overrides. + * Deprecated frame property overrides, for the legacy API only. + * + * Ignored by sws_scale_frame() when used in dynamic mode, in which + * case all properties are instead taken from the frame directly. */ int src_w, src_h; ///< Width and height of the source frame int dst_w, dst_h; ///< Width and height of the destination frame @@ -221,6 +230,8 @@ typedef struct SwsContext { int src_h_chr_pos; ///< Source horizontal chroma position int dst_v_chr_pos; ///< Destination vertical chroma position int dst_h_chr_pos; ///< Destination horizontal chroma position + + /* Remember to add new fields to graph.c:opts_equal() */ } SwsContext; /** @@ -289,12 +300,57 @@ int sws_test_transfer(enum AVColorTransferCharacteristic trc, int output); */ int sws_test_frame(const AVFrame *frame, int output); +/** + * Like `sws_scale_frame`, but without actually scaling. It will instead + * merely initialize internal state that *would* be required to perform the + * operation, as well as returning the correct error code for unsupported + * frame combinations. + * + * @param ctx The scaling context. + * @param dst The destination frame to consider. + * @param src The source frame to consider. + * @return 0 on success, a negative AVERROR code on failure. + */ +int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, const AVFrame *src); + +/******************** + * Main scaling API * + ********************/ + /** * Check if a given conversion is a noop. Returns a positive integer if * no operation needs to be performed, 0 otherwise. */ int sws_is_noop(const AVFrame *dst, const AVFrame *src); +/** + * Scale source data from `src` and write the output to `dst`. + * + * This function can be used directly on an allocated context, without setting + * up any frame properties or calling `sws_init_context()`. Such usage is fully + * dynamic and does not require reallocation if the frame properties change. + * + * Alternatively, this function can be called on a context that has been + * explicitly initialized. However, this is provided only for backwards + * compatibility. In this usage mode, all frame properties must be correctly + * set at init time, and may no longer change after initialization. + * + * @param ctx The scaling context. + * @param dst The destination frame. The data buffers may either be already + * allocated by the caller or left clear, in which case they will + * be allocated by the scaler. The latter may have performance + * advantages - e.g. in certain cases some (or all) output planes + * may be references to input planes, rather than copies. + * @param src The source frame. If the data buffers are set to NULL, then + * this function behaves identically to `sws_frame_setup`. + * @return 0 on success, a negative AVERROR code on failure. + */ +int sws_scale_frame(SwsContext *c, AVFrame *dst, const AVFrame *src); + +/************************* + * Legacy (stateful) API * + *************************/ + #define SWS_SRC_V_CHR_DROP_MASK 0x30000 #define SWS_SRC_V_CHR_DROP_SHIFT 16 @@ -357,6 +413,11 @@ int sws_isSupportedEndiannessConversion(enum AVPixelFormat pix_fmt); /** * Initialize the swscaler context sws_context. * + * This function is considered deprecated, and provided only for backwards + * compatibility with sws_scale() and sws_start_frame(). The preferred way to + * use libswscale is to set all frame properties correctly and call + * sws_scale_frame() directly, without explicitly initializing the context. + * * @return zero or positive value on success, a negative value on * error */ @@ -398,7 +459,8 @@ SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, /** * Scale the image slice in srcSlice and put the resulting scaled * slice in the image in dst. A slice is a sequence of consecutive - * rows in an image. + * rows in an image. Requires a context that has been previously + * been initialized with sws_init_context(). * * Slices have to be provided in sequential order, either in * top-bottom or bottom-top order. If slices are provided in @@ -425,27 +487,11 @@ int sws_scale(SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[]); -/** - * Scale source data from src and write the output to dst. - * - * This is merely a convenience wrapper around - * - sws_frame_start() - * - sws_send_slice(0, src->height) - * - sws_receive_slice(0, dst->height) - * - sws_frame_end() - * - * @param c The scaling context - * @param dst The destination frame. See documentation for sws_frame_start() for - * more details. - * @param src The source frame. - * - * @return 0 on success, a negative AVERROR code on failure - */ -int sws_scale_frame(SwsContext *c, AVFrame *dst, const AVFrame *src); - /** * Initialize the scaling process for a given pair of source/destination frames. * Must be called before any calls to sws_send_slice() and sws_receive_slice(). + * Requires a context that has been previously been initialized with + * sws_init_context(). * * This function will retain references to src and dst, so they must both use * refcounted buffers (if allocated by the caller, in case of dst). @@ -516,7 +562,8 @@ int sws_receive_slice(SwsContext *c, unsigned int slice_start, unsigned int slice_height); /** - * Get the alignment required for slices + * Get the alignment required for slices. Requires a context that has been + * previously been initialized with sws_init_context(). * * @param c The scaling context * @return alignment required for output slices requested with sws_receive_slice(). diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index f1a31775d5..69f8e8a838 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -26,6 +26,7 @@ #include "config.h" #include "swscale.h" +#include "graph.h" #include "libavutil/avassert.h" #include "libavutil/common.h" @@ -323,6 +324,9 @@ struct SwsInternal { int *slice_err; int nb_slice_ctx; + /* Scaling graph, reinitialized dynamically as needed. */ + SwsGraph *graph[2]; /* top, bottom fields */ + // values passed to current sws_receive_slice() call int dst_slice_start; int dst_slice_height; @@ -663,6 +667,7 @@ struct SwsInternal { unsigned int dst_slice_align; atomic_int stride_unaligned_warned; atomic_int data_unaligned_warned; + int color_conversion_warned; Half2FloatTables *h2f_tables; }; @@ -674,7 +679,7 @@ static_assert(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInt #if ARCH_X86_64 /* x86 yuv2gbrp uses the SwsInternal for yuv coefficients if struct offsets change the asm needs to be updated too */ -static_assert(offsetof(SwsInternal, yuv2rgb_y_offset) == 40332, +static_assert(offsetof(SwsInternal, yuv2rgb_y_offset) == 40348, "yuv2rgb_y_offset must be updated in x86 asm"); #endif diff --git a/libswscale/utils.c b/libswscale/utils.c index b8d478b104..f56d2926b8 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -61,6 +61,7 @@ #include "swscale.h" #include "swscale_internal.h" #include "utils.h" +#include "graph.h" typedef struct FormatEntry { uint8_t is_supported_in :1; @@ -2461,6 +2462,9 @@ void sws_freeContext(SwsContext *sws) if (!c) return; + for (i = 0; i < FF_ARRAY_ELEMS(c->graph); i++) + sws_graph_free(&c->graph[i]); + for (i = 0; i < c->nb_slice_ctx; i++) sws_freeContext(c->slice_ctx[i]); av_freep(&c->slice_ctx); diff --git a/libswscale/x86/output.asm b/libswscale/x86/output.asm index 7a1e5d9bc1..f2e884780a 100644 --- a/libswscale/x86/output.asm +++ b/libswscale/x86/output.asm @@ -582,7 +582,7 @@ yuv2nv12cX_fn yuv2nv21 %if ARCH_X86_64 struc SwsInternal - .padding: resb 40332 ; offsetof(SwsInternal, yuv2rgb_y_offset) + .padding: resb 40348 ; offsetof(SwsInternal, yuv2rgb_y_offset) .yuv2rgb_y_offset: resd 1 .yuv2rgb_y_coeff: resd 1 .yuv2rgb_v2r_coeff: resd 1 From patchwork Sun Oct 20 20:05:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52422 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2255700vqi; Sun, 20 Oct 2024 14:04:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVNfUw5SX+mpXHdPCdbkTImdCtk2AIcUhxQss7OkEoKRUgAepmNb0CFH4cvuvi8jg0WcE/yrGJGr6Enth24SxpS@gmail.com X-Google-Smtp-Source: AGHT+IFScdZaQICVdrFHBIhV8dCX7RW7KR94dmzeQEFQlRgzphnMA6pt/9nsyPzJsxNhU2hwHKUf X-Received: by 2002:a17:907:7f90:b0:a9a:76d:e86c with SMTP id a640c23a62f3a-a9a69c9b27dmr983127866b.49.1729458245076; Sun, 20 Oct 2024 14:04:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729458245; cv=none; d=google.com; s=arc-20240605; b=YWO3Mu82zkpjUQvpygVaD5mGlRpr3GIsgKBqWk5R2z5V9ynqTqzEU3Tf1BxdqmvrpB j9cJOdWF7jmy14xRGRn8eswxbkwKVv0tQQDpE8gbLMjMoec0U9PDuEyqur/NdcRWlO2+ Nm+Hf5I3M7HUJjqdPrAsBPwglzC7dyYyWEKPDZ/QRQpdaA26KFnRZfb8S6+cMGK+INr0 i/iSRuWFBBk7OftbzKyKs4IvV6QL+iF6OcLiHAVQMk93o6jQje+w+dmRfyTU58GTo4tC Hh4ucPETDMB+23L475hfoWurlfTV23qW6ybXhZzGnT5AmPqPSmrKRucjZPBQstbP/2FS 9FTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=Fva/aK+HKDczOstMrVilOD530N6JTAyAZas1FTYTUuA=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=IgYuIRUefsLn4cmd/aXVbNAhqtmJo+4rspOJoA3OjgMI2NQGblzCTO2tLNYfzamlnt 0TnoeUmOoT4jVIF4vZo8Qu99fZnNKi34soqHa7VG+Q2YfRnGJWT4T8ajnp+P6wTqy79f OT2/p4fS5/UmhOzjjeIfAwlc8NTc0Jnhoh/Y5EhuCFek3XE9TmjfWtF9rbCVFR4/iOMt GN5hCrUCB+DNas41kofo7CqvT9XnCsC3aCsqPra7x9BSuVR9BMCHYMjCE/1wCRJ5eoJI qGowQmpDDLTJVO4Da5kVYwJtiN3t1WzfzA/fKxevW4F5+WV7OFUQx4CpRDrg/W4Ti9o8 e0pg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=ihnI8bw9; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a9a91333bc7si149405166b.390.2024.10.20.14.04.03; Sun, 20 Oct 2024 14:04:05 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b=ihnI8bw9; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F320B68DB5D; Sun, 20 Oct 2024 23:09:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C6AC568DAE3 for ; Sun, 20 Oct 2024 23:09:00 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454938; bh=VUsSZg00n3tkpTgsiWaQvNVYtGSoiGk6kvvJndy0Ujc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ihnI8bw9K2xMG/KcOJX77Jkh93OnbhK2osKxoreIrQR62X0nKR41vyALFpUFJp68B phx7oovzhRM0JhSSHkMlIyftsHXZdMWsZ9a3LHwrDJlYXwhCgVNdjNGjbAWlY0dV7Q aV+tCmY5sIlcyGTze5D6YRdoONitQIVYGz0ORTok= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 703F84BE8F; Sun, 20 Oct 2024 22:08:58 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:25 +0200 Message-ID: <20241020200851.1414766-17-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 16/18] tests/swscale: rewrite on top of new API 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: j14UMNJvTiD8 From: Niklas Haas This rewrite cleans up the code to use AVFrames and the new swscale API. The log format has also been simplified and expanded to account for the new options. (Not yet implemented) The self testing code path has also been expanded to test the new swscale implementation against the old one, to serve as an unchanging reference. This does not accomplish much yet, but serves as a framework for future work. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/tests/swscale.c | 665 ++++++++++++++++--------------------- 1 file changed, 284 insertions(+), 381 deletions(-) diff --git a/libswscale/tests/swscale.c b/libswscale/tests/swscale.c index af8069f728..c11a46024e 100644 --- a/libswscale/tests/swscale.c +++ b/libswscale/tests/swscale.c @@ -1,4 +1,5 @@ /* + * Copyright (C) 2024 Nikles Haas * Copyright (C) 2003-2011 Michael Niedermayer * * This file is part of FFmpeg. @@ -26,424 +27,307 @@ #undef HAVE_AV_CONFIG_H #include "libavutil/cpu.h" -#include "libavutil/imgutils.h" -#include "libavutil/mem.h" -#include "libavutil/avutil.h" -#include "libavutil/crc.h" -#include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "libavutil/lfg.h" #include "libavutil/sfc64.h" +#include "libavutil/frame.h" +#include "libavutil/pixfmt.h" +#include "libavutil/avassert.h" +#include "libavutil/macros.h" #include "libswscale/swscale.h" -/* HACK Duplicated from swscale_internal.h. - * Should be removed when a cleaner pixel format system exists. */ -#define isGray(x) \ - ((x) == AV_PIX_FMT_GRAY8 || \ - (x) == AV_PIX_FMT_YA8 || \ - (x) == AV_PIX_FMT_GRAY16BE || \ - (x) == AV_PIX_FMT_GRAY16LE || \ - (x) == AV_PIX_FMT_YA16BE || \ - (x) == AV_PIX_FMT_YA16LE) -#define hasChroma(x) \ - (!(isGray(x) || \ - (x) == AV_PIX_FMT_MONOBLACK || \ - (x) == AV_PIX_FMT_MONOWHITE)) - -static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt) -{ - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); - return desc->flags & AV_PIX_FMT_FLAG_ALPHA; -} +enum { + WIDTH = 96, + HEIGHT = 96, +}; -static double prob = 1; -FFSFC64 prng_state; +struct options { + enum AVPixelFormat src_fmt; + enum AVPixelFormat dst_fmt; + double prob; +}; -static uint64_t getSSD(const uint8_t *src1, const uint8_t *src2, - int stride1, int stride2, int w, int h) -{ - int x, y; - uint64_t ssd = 0; +struct mode { + SwsFlags flags; + SwsDither dither; +}; - for (y = 0; y < h; y++) { - for (x = 0; x < w; x++) { - int d = src1[x + y * stride1] - src2[x + y * stride2]; - ssd += d * d; - } - } - return ssd; -} +const int dst_w[] = { WIDTH, WIDTH - WIDTH / 3, WIDTH + WIDTH / 3 }; +const int dst_h[] = { HEIGHT, HEIGHT - HEIGHT / 3, HEIGHT + HEIGHT / 3 }; + +const struct mode modes[] = { + { SWS_FAST_BILINEAR }, + { SWS_BILINEAR }, + { SWS_BICUBIC }, + { SWS_X | SWS_BITEXACT }, + { SWS_POINT }, + { SWS_AREA | SWS_ACCURATE_RND }, + { SWS_BICUBIC | SWS_FULL_CHR_H_INT | SWS_FULL_CHR_H_INP }, + {0}, // test defaults +}; -static uint64_t getSSD0(int ref, const uint8_t *src1, int stride1, - int w, int h) -{ - int x, y; - uint64_t ssd = 0; +static FFSFC64 prng_state; +static SwsContext *sws[3]; /* reused between tests for efficiency */ - for (y = 0; y < h; y++) { - for (x = 0; x < w; x++) { - int d = src1[x + y * stride1] - ref; - ssd += d * d; - } - } - return ssd; +static int fmt_comps(enum AVPixelFormat fmt) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt); + int comps = desc->nb_components >= 3 ? 0b111 : 0b1; + if (desc->flags & AV_PIX_FMT_FLAG_ALPHA) + comps |= 0b1000; + return comps; } -struct Results { - uint64_t ssdY; - uint64_t ssdU; - uint64_t ssdV; - uint64_t ssdA; - uint32_t crc; -}; - -// test by ref -> src -> dst -> out & compare out against ref -// ref & out are YV12 -static int doTest(const uint8_t * const ref[4], int refStride[4], int w, int h, - enum AVPixelFormat srcFormat, enum AVPixelFormat dstFormat, - int srcW, int srcH, int dstW, int dstH, int flags, - struct Results *r) +static void get_mse(int mse[4], const AVFrame *a, const AVFrame *b, int comps) { - const AVPixFmtDescriptor *desc_yuva420p = av_pix_fmt_desc_get(AV_PIX_FMT_YUVA420P); - const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(srcFormat); - const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(dstFormat); - static enum AVPixelFormat cur_srcFormat; - static int cur_srcW, cur_srcH; - static const uint8_t *src[4]; - static int srcStride[4]; - uint8_t *dst[4] = { 0 }; - uint8_t *out[4] = { 0 }; - int dstStride[4] = {0}; - int i; - uint64_t ssdY, ssdU = 0, ssdV = 0, ssdA = 0; - SwsContext *dstContext = NULL, *outContext = NULL; - uint32_t crc = 0; - int res = 0; - - if (ff_sfc64_get(&prng_state) > UINT64_MAX * prob) - return 0; - - if (cur_srcFormat != srcFormat || cur_srcW != srcW || cur_srcH != srcH) { - SwsContext *srcContext = NULL; - int p; - - for (p = 0; p < 4; p++) - av_freep(&src[p]); - - res = av_image_fill_linesizes(srcStride, srcFormat, srcW); - if (res < 0) { - fprintf(stderr, "av_image_fill_linesizes failed\n"); - goto end; - } - for (p = 0; p < 4; p++) { - srcStride[p] = FFALIGN(srcStride[p], 16); - if (srcStride[p]) - src[p] = av_mallocz(srcStride[p] * srcH + 16); - if (srcStride[p] && !src[p]) { - perror("Malloc"); - res = -1; - goto end; + av_assert1(a->format == AV_PIX_FMT_YUVA420P); + av_assert1(b->format == a->format); + av_assert1(b->width == a->width && b->height == a->height); + + for (int p = 0; p < 4; p++) { + const int is_chroma = p == 1 || p == 2; + const int stride_a = a->linesize[p]; + const int stride_b = b->linesize[p]; + const int w = (a->width + is_chroma) >> is_chroma; + const int h = (a->height + is_chroma) >> is_chroma; + uint64_t sum = 0; + + if (comps & (1 << p)) { + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + int d = a->data[p][y * stride_a + x] - b->data[p][y * stride_b + x]; + sum += d * d; + } + } + } else { + const int ref = is_chroma ? 128 : 0xFF; + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + int d = a->data[p][y * stride_a + x] - ref; + sum += d * d; + } } } - srcContext = sws_getContext(w, h, AV_PIX_FMT_YUVA420P, srcW, srcH, - srcFormat, SWS_BILINEAR, NULL, NULL, NULL); - if (!srcContext) { - fprintf(stderr, "Failed to get %s ---> %s\n", - desc_yuva420p->name, - desc_src->name); - res = -1; - goto end; - } - sws_scale(srcContext, ref, refStride, 0, h, - (uint8_t * const *) src, srcStride); - sws_freeContext(srcContext); - cur_srcFormat = srcFormat; - cur_srcW = srcW; - cur_srcH = srcH; + mse[p] = sum / (w * h); } +} - res = av_image_fill_linesizes(dstStride, dstFormat, dstW); - if (res < 0) { - fprintf(stderr, "av_image_fill_linesizes failed\n"); - goto end; - } +static int scale_legacy(AVFrame *dst, const AVFrame *src, struct mode mode) +{ + SwsContext *sws_legacy; + int ret; - for (i = 0; i < 4; i++) { - /* Image buffers passed into libswscale can be allocated any way you - * prefer, as long as they're aligned enough for the architecture, and - * they're freed appropriately (such as using av_free for buffers - * allocated with av_malloc). */ - /* An extra 16 bytes is being allocated because some scalers may write - * out of bounds. */ - dstStride[i] = FFALIGN(dstStride[i], 16); - if (dstStride[i]) - dst[i] = av_mallocz(dstStride[i] * dstH + 16); - if (dstStride[i] && !dst[i]) { - perror("Malloc"); - res = -1; - - goto end; - } - } + sws_legacy = sws_alloc_context(); + if (!sws_legacy) + return -1; + + sws_legacy->src_w = src->width; + sws_legacy->src_h = src->height; + sws_legacy->src_format = src->format; + sws_legacy->dst_w = dst->width; + sws_legacy->dst_h = dst->height; + sws_legacy->dst_format = dst->format; + sws_legacy->flags = mode.flags; + sws_legacy->dither = mode.dither; + + ret = sws_init_context(sws_legacy, NULL, NULL); + if (!ret) + ret = sws_scale_frame(sws_legacy, dst, src); + + sws_freeContext(sws_legacy); + return ret; +} + +/* Runs a series of ref -> src -> dst -> out, and compares out vs ref */ +static int run_test(enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt, + int dst_w, int dst_h, struct mode mode, const AVFrame *ref, + const int mse_ref[4]) +{ + AVFrame *src = NULL, *dst = NULL, *out = NULL; + int mse[4], mse_sws[4], ret = -1; + const int comps = fmt_comps(src_fmt) & fmt_comps(dst_fmt); + + src = av_frame_alloc(); + dst = av_frame_alloc(); + out = av_frame_alloc(); + if (!src || !dst || !out) + goto error; - dstContext = sws_alloc_context(); - if (!dstContext) { - fprintf(stderr, "Failed to alloc %s ---> %s\n", - desc_src->name, desc_dst->name); - res = -1; - goto end; + av_frame_copy_props(src, ref); + av_frame_copy_props(dst, ref); + av_frame_copy_props(out, ref); + src->width = out->width = ref->width; + src->height = out->height = ref->height; + out->format = ref->format; + src->format = src_fmt; + dst->format = dst_fmt; + dst->width = dst_w; + dst->height = dst_h; + + if (sws_scale_frame(sws[0], src, ref) < 0) { + fprintf(stderr, "Failed %s ---> %s\n", av_get_pix_fmt_name(ref->format), + av_get_pix_fmt_name(src->format)); + goto error; } - av_opt_set_int(dstContext, "sws_flags", flags, 0); - av_opt_set_int(dstContext, "srcw", srcW, 0); - av_opt_set_int(dstContext, "srch", srcH, 0); - av_opt_set_int(dstContext, "dstw", dstW, 0); - av_opt_set_int(dstContext, "dsth", dstH, 0); - av_opt_set_int(dstContext, "src_format", srcFormat, 0); - av_opt_set_int(dstContext, "dst_format", dstFormat, 0); - av_opt_set(dstContext, "alphablend", "none", 0); - - if (sws_init_context(dstContext, NULL, NULL) < 0) { - sws_freeContext(dstContext); - fprintf(stderr, "Failed to init %s ---> %s\n", - desc_src->name, desc_dst->name); - res = -1; - goto end; + sws[1]->flags = mode.flags; + sws[1]->dither = mode.dither; + if (sws_scale_frame(sws[1], dst, src) < 0) { + fprintf(stderr, "Failed %s ---> %s\n", av_get_pix_fmt_name(src->format), + av_get_pix_fmt_name(dst->format)); + goto error; } - printf(" %s %dx%d -> %s %3dx%3d flags=%2d", - desc_src->name, srcW, srcH, - desc_dst->name, dstW, dstH, - flags); - fflush(stdout); + if (sws_scale_frame(sws[2], out, dst) < 0) { + fprintf(stderr, "Failed %s ---> %s\n", av_get_pix_fmt_name(dst->format), + av_get_pix_fmt_name(out->format)); + goto error; + } - sws_scale(dstContext, (const uint8_t * const*)src, srcStride, 0, srcH, dst, dstStride); - - for (i = 0; i < 4 && dstStride[i]; i++) - crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), crc, dst[i], - dstStride[i] * dstH); - - if (r && crc == r->crc) { - ssdY = r->ssdY; - ssdU = r->ssdU; - ssdV = r->ssdV; - ssdA = r->ssdA; - } else { - for (i = 0; i < 4; i++) { - refStride[i] = FFALIGN(refStride[i], 16); - if (refStride[i]) - out[i] = av_mallocz(refStride[i] * h); - if (refStride[i] && !out[i]) { - perror("Malloc"); - res = -1; - goto end; - } - } - outContext = sws_getContext(dstW, dstH, dstFormat, w, h, - AV_PIX_FMT_YUVA420P, SWS_BILINEAR, - NULL, NULL, NULL); - if (!outContext) { - fprintf(stderr, "Failed to get %s ---> %s\n", - desc_dst->name, - desc_yuva420p->name); - res = -1; - goto end; - } - sws_scale(outContext, (const uint8_t * const *) dst, dstStride, 0, dstH, - out, refStride); - - ssdY = getSSD(ref[0], out[0], refStride[0], refStride[0], w, h); - if (hasChroma(srcFormat) && hasChroma(dstFormat)) { - //FIXME check that output is really gray - ssdU = getSSD(ref[1], out[1], refStride[1], refStride[1], - (w + 1) >> 1, (h + 1) >> 1); - ssdV = getSSD(ref[2], out[2], refStride[2], refStride[2], - (w + 1) >> 1, (h + 1) >> 1); - } else { - ssdU = getSSD0(128, out[1], refStride[1], - (w + 1) >> 1, (h + 1) >> 1); - ssdV = getSSD0(128, out[2], refStride[2], - (w + 1) >> 1, (h + 1) >> 1); - } - if (isALPHA(srcFormat) && isALPHA(dstFormat)) { - ssdA = getSSD(ref[3], out[3], refStride[3], refStride[3], w, h); - } else { - ssdA = getSSD0(0xFF, out[3], refStride[3], w, h); + get_mse(mse, out, ref, comps); + printf("%s %dx%d -> %s %3dx%3d, flags=%u dither=%u, " + "MSE={%5d %5d %5d %5d}\n", + av_get_pix_fmt_name(src->format), src->width, src->height, + av_get_pix_fmt_name(dst->format), dst->width, dst->height, + mode.flags, mode.dither, + mse[0], mse[1], mse[2], mse[3]); + + if (!mse_ref) { + /* Compare against the legacy swscale API as a reference */ + if (scale_legacy(dst, src, mode) < 0) { + fprintf(stderr, "Failed ref %s ---> %s\n", av_get_pix_fmt_name(src->format), + av_get_pix_fmt_name(dst->format)); + goto error; } - ssdY /= w * h; - ssdU /= w * h / 4; - ssdV /= w * h / 4; - ssdA /= w * h; - - sws_freeContext(outContext); + if (sws_scale_frame(sws[2], out, dst) < 0) + goto error; - for (i = 0; i < 4; i++) - if (refStride[i]) - av_free(out[i]); + get_mse(mse_sws, out, ref, comps); + mse_ref = mse_sws; } - if(r){ - if(ssdY>r->ssdY*1.02+1 || ssdU>r->ssdU*1.02+1 || ssdV>r->ssdV*1.02+1|| ssdA>r->ssdA*1.02+1) - printf("WORSE SSD=%5"PRId64",%5"PRId64",%5"PRId64",%5"PRId64"", - r->ssdY, r->ssdU, r->ssdV, r->ssdA); - else if(ssdY>r->ssdY || ssdU>r->ssdU || ssdV>r->ssdV|| ssdA>r->ssdA) - printf("worse SSD=%5"PRId64",%5"PRId64",%5"PRId64",%5"PRId64"", - r->ssdY, r->ssdU, r->ssdV, r->ssdA); + for (int i = 0; i < 4; i++) { + if (mse[i] > mse_ref[i]) { + int bad = mse[i] > mse_ref[i] * 1.02 + 1; + printf("\033[1;31m %s, ref MSE={%5d %5d %5d %5d}\033[0m\n", + bad ? "WORSE" : "worse", + mse_ref[0], mse_ref[1], mse_ref[2], mse_ref[3]); + if (bad) + goto error; + break; + } } - printf(" CRC=%08x SSD=%5"PRId64 ",%5"PRId64 ",%5"PRId64 ",%5"PRId64 "\n", - crc, ssdY, ssdU, ssdV, ssdA); - -end: - sws_freeContext(dstContext); - - for (i = 0; i < 4; i++) - if (dstStride[i]) - av_free(dst[i]); - - return !!res; + fflush(stdout); + ret = 0; /* fall through */ + error: + av_frame_free(&src); + av_frame_free(&dst); + av_frame_free(&out); + return ret; } -static void selfTest(const uint8_t * const ref[4], int refStride[4], - int w, int h, - enum AVPixelFormat srcFormat_in, - enum AVPixelFormat dstFormat_in) +static int run_self_tests(const AVFrame *ref, struct options opts) { - const int flags[] = { SWS_FAST_BILINEAR, - SWS_BILINEAR, SWS_BICUBIC, - SWS_X|SWS_BITEXACT , SWS_POINT , SWS_AREA|SWS_ACCURATE_RND, - SWS_BICUBIC|SWS_FULL_CHR_H_INT|SWS_FULL_CHR_H_INP, 0}; - const int srcW = w; - const int srcH = h; - const int dstW[] = { srcW - srcW / 3, srcW, srcW + srcW / 3, 0 }; - const int dstH[] = { srcH - srcH / 3, srcH, srcH + srcH / 3, 0 }; - enum AVPixelFormat srcFormat, dstFormat; - const AVPixFmtDescriptor *desc_src, *desc_dst; - - for (srcFormat = srcFormat_in != AV_PIX_FMT_NONE ? srcFormat_in : 0; - srcFormat < AV_PIX_FMT_NB; srcFormat++) { - if (!sws_isSupportedInput(srcFormat) || - !sws_isSupportedOutput(srcFormat)) + enum AVPixelFormat src_fmt, dst_fmt, + src_fmt_min = 0, + dst_fmt_min = 0, + src_fmt_max = AV_PIX_FMT_NB - 1, + dst_fmt_max = AV_PIX_FMT_NB - 1; + + if (opts.src_fmt != AV_PIX_FMT_NONE) + src_fmt_min = src_fmt_max = opts.src_fmt; + if (opts.dst_fmt != AV_PIX_FMT_NONE) + dst_fmt_min = dst_fmt_max = opts.dst_fmt; + + for (src_fmt = src_fmt_min; src_fmt <= src_fmt_max; src_fmt++) { + if (!sws_test_format(src_fmt, 0) || !sws_test_format(src_fmt, 1)) continue; - - desc_src = av_pix_fmt_desc_get(srcFormat); - - for (dstFormat = dstFormat_in != AV_PIX_FMT_NONE ? dstFormat_in : 0; - dstFormat < AV_PIX_FMT_NB; dstFormat++) { - int i, j, k; - int res = 0; - - if (!sws_isSupportedInput(dstFormat) || - !sws_isSupportedOutput(dstFormat)) + for (dst_fmt = dst_fmt_min; dst_fmt <= dst_fmt_max; dst_fmt++) { + if (!sws_test_format(dst_fmt, 0) || !sws_test_format(dst_fmt, 1)) continue; - - desc_dst = av_pix_fmt_desc_get(dstFormat); - - printf("%s -> %s\n", desc_src->name, desc_dst->name); - fflush(stdout); - - for (k = 0; flags[k] && !res; k++) - for (i = 0; dstW[i] && !res; i++) - for (j = 0; dstH[j] && !res; j++) - res = doTest(ref, refStride, w, h, - srcFormat, dstFormat, - srcW, srcH, dstW[i], dstH[j], flags[k], - NULL); - if (dstFormat_in != AV_PIX_FMT_NONE) - break; + for (int h = 0; h < FF_ARRAY_ELEMS(dst_h); h++) + for (int w = 0; w < FF_ARRAY_ELEMS(dst_w); w++) + for (int m = 0; m < FF_ARRAY_ELEMS(modes); m++) { + if (ff_sfc64_get(&prng_state) > UINT64_MAX * opts.prob) + continue; + if (run_test(src_fmt, dst_fmt, dst_w[w], dst_h[h], + modes[m], ref, NULL) < 0) + return -1; + } } - if (srcFormat_in != AV_PIX_FMT_NONE) - break; } + + return 0; } -static int fileTest(const uint8_t * const ref[4], int refStride[4], - int w, int h, FILE *fp, - enum AVPixelFormat srcFormat_in, - enum AVPixelFormat dstFormat_in) +static int run_file_tests(const AVFrame *ref, FILE *fp, struct options opts) { char buf[256]; + int ret; while (fgets(buf, sizeof(buf), fp)) { - struct Results r; - enum AVPixelFormat srcFormat; - char srcStr[21]; - int srcW = 0, srcH = 0; - enum AVPixelFormat dstFormat; - char dstStr[21]; - int dstW = 0, dstH = 0; - int flags; - int ret; + char src_fmt_str[20], dst_fmt_str[20]; + enum AVPixelFormat src_fmt; + enum AVPixelFormat dst_fmt; + int sw, sh, dw, dh, mse[4]; + struct mode mode; ret = sscanf(buf, - " %20s %dx%d -> %20s %dx%d flags=%d CRC=%x" - " SSD=%"SCNu64 ", %"SCNu64 ", %"SCNu64 ", %"SCNu64 "\n", - srcStr, &srcW, &srcH, dstStr, &dstW, &dstH, - &flags, &r.crc, &r.ssdY, &r.ssdU, &r.ssdV, &r.ssdA); - if (ret != 12) { - srcStr[0] = dstStr[0] = 0; - ret = sscanf(buf, "%20s -> %20s\n", srcStr, dstStr); + " %20s %dx%d -> %20s %dx%d, flags=%u dither=%u, " + "MSE={%d %d %d %d}\n", + src_fmt_str, &sw, &sh, dst_fmt_str, &dw, &dh, + &mode.flags, &mode.dither, + &mse[0], &mse[1], &mse[2], &mse[3]); + if (ret != 13) { + printf("%s", buf); + continue; } - srcFormat = av_get_pix_fmt(srcStr); - dstFormat = av_get_pix_fmt(dstStr); - - if (srcFormat == AV_PIX_FMT_NONE || dstFormat == AV_PIX_FMT_NONE || - srcW > 8192U || srcH > 8192U || dstW > 8192U || dstH > 8192U) { + src_fmt = av_get_pix_fmt(src_fmt_str); + dst_fmt = av_get_pix_fmt(dst_fmt_str); + if (src_fmt == AV_PIX_FMT_NONE || dst_fmt == AV_PIX_FMT_NONE || + sw != ref->width || sh != ref->height || dw > 8192 || dh > 8192 || + mode.dither >= SWS_DITHER_NB) { fprintf(stderr, "malformed input file\n"); return -1; } - if ((srcFormat_in != AV_PIX_FMT_NONE && srcFormat_in != srcFormat) || - (dstFormat_in != AV_PIX_FMT_NONE && dstFormat_in != dstFormat)) - continue; - if (ret != 12) { - printf("%s", buf); + + if (opts.src_fmt != AV_PIX_FMT_NONE && src_fmt != opts.src_fmt || + opts.dst_fmt != AV_PIX_FMT_NONE && dst_fmt != opts.dst_fmt) continue; - } - doTest(ref, refStride, w, h, - srcFormat, dstFormat, - srcW, srcH, dstW, dstH, flags, - &r); + if (run_test(src_fmt, dst_fmt, dw, dh, mode, ref, mse) < 0) + return -1; } return 0; } -#define W 96 -#define H 96 - int main(int argc, char **argv) { - enum AVPixelFormat srcFormat = AV_PIX_FMT_NONE; - enum AVPixelFormat dstFormat = AV_PIX_FMT_NONE; - uint8_t *rgb_data = av_malloc(W * H * 4); - const uint8_t * const rgb_src[4] = { rgb_data, NULL, NULL, NULL }; - int rgb_stride[4] = { 4 * W, 0, 0, 0 }; - uint8_t *data = av_malloc(4 * W * H); - const uint8_t * const src[4] = { data, data + W * H, data + W * H * 2, data + W * H * 3 }; - int stride[4] = { W, W, W, W }; - int x, y; - SwsContext *sws; - AVLFG rand; - int res = -1; - int i; - FILE *fp = NULL; + struct options opts = { + .src_fmt = AV_PIX_FMT_NONE, + .dst_fmt = AV_PIX_FMT_NONE, + .prob = 1.0, + }; - if (!rgb_data || !data) - return -1; + AVFrame *rgb = NULL, *ref = NULL; + FILE *fp = NULL; + AVLFG rand; + int ret = -1; - for (i = 1; i < argc; i += 2) { + for (int i = 1; i < argc; i += 2) { if (!strcmp(argv[i], "-help") || !strcmp(argv[i], "--help")) { fprintf(stderr, "swscale [options...]\n" " -help\n" " This text\n" " -ref \n" - " Uses file as reference to compae tests againsts. Tests that have become worse will contain the string worse or WORSE\n" + " Uses file as reference to compare tests againsts. Tests that have become worse will contain the string worse or WORSE\n" " -p \n" " The percentage of tests or comparisons to perform. Doing all tests will take long and generate over a hundred MB text output\n" " It is often convenient to perform a random subset\n" @@ -454,7 +338,7 @@ int main(int argc, char **argv) " -cpuflags \n" " Uses the specified cpuflags in the tests\n" ); - goto error; + return 0; } if (argv[i][0] != '-' || i + 1 == argc) goto bad_option; @@ -466,26 +350,26 @@ int main(int argc, char **argv) } } else if (!strcmp(argv[i], "-cpuflags")) { unsigned flags = av_get_cpu_flags(); - int ret = av_parse_cpu_caps(&flags, argv[i + 1]); - if (ret < 0) { + int res = av_parse_cpu_caps(&flags, argv[i + 1]); + if (res < 0) { fprintf(stderr, "invalid cpu flags %s\n", argv[i + 1]); - return ret; + goto error; } av_force_cpu_flags(flags); } else if (!strcmp(argv[i], "-src")) { - srcFormat = av_get_pix_fmt(argv[i + 1]); - if (srcFormat == AV_PIX_FMT_NONE) { + opts.src_fmt = av_get_pix_fmt(argv[i + 1]); + if (opts.src_fmt == AV_PIX_FMT_NONE) { fprintf(stderr, "invalid pixel format %s\n", argv[i + 1]); - return -1; + goto error; } } else if (!strcmp(argv[i], "-dst")) { - dstFormat = av_get_pix_fmt(argv[i + 1]); - if (dstFormat == AV_PIX_FMT_NONE) { + opts.dst_fmt = av_get_pix_fmt(argv[i + 1]); + if (opts.dst_fmt == AV_PIX_FMT_NONE) { fprintf(stderr, "invalid pixel format %s\n", argv[i + 1]); - return -1; + goto error; } } else if (!strcmp(argv[i], "-p")) { - prob = atof(argv[i + 1]); + opts.prob = atof(argv[i + 1]); } else { bad_option: fprintf(stderr, "bad option or argument missing (%s) see -help\n", argv[i]); @@ -494,32 +378,51 @@ bad_option: } ff_sfc64_init(&prng_state, 0, 0, 0, 12); - - sws = sws_getContext(W / 12, H / 12, AV_PIX_FMT_RGB32, W, H, - AV_PIX_FMT_YUVA420P, SWS_BILINEAR, NULL, NULL, NULL); - av_lfg_init(&rand, 1); - for (y = 0; y < H; y++) - for (x = 0; x < W * 4; x++) - rgb_data[ x + y * 4 * W] = av_lfg_get(&rand); - res = sws_scale(sws, rgb_src, rgb_stride, 0, H / 12, (uint8_t * const *) src, stride); - if (res < 0 || res != H) { - res = -1; - goto error; + for (int i = 0; i < 3; i++) { + sws[i] = sws_alloc_context(); + if (!sws[i]) + goto error; + sws[i]->flags = SWS_BILINEAR; } - sws_freeContext(sws); - av_free(rgb_data); - if(fp) { - res = fileTest(src, stride, W, H, fp, srcFormat, dstFormat); - fclose(fp); - } else { - selfTest(src, stride, W, H, srcFormat, dstFormat); - res = 0; + rgb = av_frame_alloc(); + if (!rgb) + goto error; + rgb->width = WIDTH / 12; + rgb->height = HEIGHT / 12; + rgb->format = AV_PIX_FMT_RGBA; + if (av_frame_get_buffer(rgb, 32) < 0) + goto error; + + for (int y = 0; y < rgb->height; y++) { + for (int x = 0; x < rgb->width; x++) { + for (int c = 0; c < 4; c++) + rgb->data[0][y * rgb->linesize[0] + x * 4 + c] = av_lfg_get(&rand); + } } -error: - av_free(data); - return res; + ref = av_frame_alloc(); + if (!ref) + goto error; + ref->width = WIDTH; + ref->height = HEIGHT; + ref->format = AV_PIX_FMT_YUVA420P; + + if (sws_scale_frame(sws[0], ref, rgb) < 0) + goto error; + + ret = fp ? run_file_tests(ref, fp, opts) + : run_self_tests(ref, opts); + + /* fall through */ +error: + for (int i = 0; i < 3; i++) + sws_free_context(&sws[i]); + av_frame_free(&rgb); + av_frame_free(&ref); + if (fp) + fclose(fp); + return ret; } From patchwork Sun Oct 20 20:05:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52420 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2253537vqi; Sun, 20 Oct 2024 13:59:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVwSrFGCGGvN+jgKGubppdXCEnOS73bzyMGDS/lDkFAojRmLejIQKZWTQCzaklQqH7GXIECFtJyx731/GxT7Y0d@gmail.com X-Google-Smtp-Source: AGHT+IE47sfZKZ/MvnObbtlCmxEkZb3e8yRRtuuTT0w+d+Mxp8BjUmkCO7xaXeTdnZXofSDCaeui X-Received: by 2002:a05:651c:88b:b0:2fa:bf5f:f97e with SMTP id 38308e7fff4ca-2fb832432bcmr13834251fa.8.1729457943543; Sun, 20 Oct 2024 13:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729457943; cv=none; d=google.com; s=arc-20240605; b=bApQjfIvNPPRI5ZjzzCvtDvSapMk5j8c9EDQgwnGpkxUgHLNnmKnVAi/9U3oGEqV+t dULjns7mAFiQFFnUtgVYtt6bdYHoMnvWprJWTDoJI0tE5ZmqB5SuIDtgPhlNNyZJfSWj ti/7ksTr8VgoLJmlwwh44bN86wJYCwoRpgGizdDd3RLQtvRlaB281/DlDocc3Rs+6QJb NYXKtaA/kXD2tPDIbZeKKvEPSP8McFXLO2P1QVjPfGGIJqkYNUKrmLvEpsKfLB8pMdcm kQvuhjSxqTnQTf+Sp2Uc9iqjxT9bOtDCDvMkxG0WanJtA/5J8szlEtdE8Ty+JOHzS6KF B1JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=P12XIiv3laDUb/dZoIrUhpjlE0oskQfFZ1JF5R6XKts=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=Gz/Bo6WkfNqCOKr7HK/3VsUj5/DCMpmH4z5fHVoOplfCA8UmqXgM7lXS7ZSZuppOf/ IEUPNmsJDdKwnBlQ9x89qU82Z1yRkcPZS5A5XmT4jDqCLwEi/axB9zrXJ/Q4lN9fq6iL Hj8/d47DbDc+b/5jgJiPOTH87CkjokmdN+D7U1JvlRwDTZeqEn+921azw4AKFigwS5dI amJjnTWsVJw4Fz4QzOtce0LfMUIrn7WcFJCF7snSUeMqA4LH28T+M63Urw6CfjOFoTU6 dfBXaJLYcqOeO5rQXmEm+E7JHdeDX8BgIRLutABraqS3DArq6tOv05bz9aC2RUzwSQ+h jWFA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=dlnXkOfF; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38308e7fff4ca-2fb9adc584csi6341521fa.7.2024.10.20.13.59.03; Sun, 20 Oct 2024 13:59:03 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b=dlnXkOfF; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 30F1068DAE3; Sun, 20 Oct 2024 23:09:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E0F6368DB08 for ; Sun, 20 Oct 2024 23:09:00 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454938; bh=2mtYBl/3UewOGpaBqqCYdLlOK7bQAP6Z2F1VT/TMzU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dlnXkOfFkDBSJqCylPDY6Z//AgtXIHGIwH1C2Wfjn1mEm9VteVoEgLS0ZsbVV6AmT nwgZ87+5SAyiAko6ajgM7xlI5fQW6ZwoSPJBPPC0N5JrM/Ub2zIxjV/piHyMSEM1SP xnQuPLi1qL1k2cKfbXjZXg29xuSrbjgm0y7dEULE= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id AC9FC4BE92; Sun, 20 Oct 2024 22:08:58 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:26 +0200 Message-ID: <20241020200851.1414766-18-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 17/18] tests/swscale: add a benchmarking mode 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 0CBOWZM+7yLk From: Niklas Haas With the ability to set the thread count as well. This benchmark includes the constant overhead of context initialization. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/tests/swscale.c | 93 ++++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 25 deletions(-) diff --git a/libswscale/tests/swscale.c b/libswscale/tests/swscale.c index c11a46024e..f5ad4b3132 100644 --- a/libswscale/tests/swscale.c +++ b/libswscale/tests/swscale.c @@ -31,21 +31,22 @@ #include "libavutil/lfg.h" #include "libavutil/sfc64.h" #include "libavutil/frame.h" +#include "libavutil/opt.h" +#include "libavutil/time.h" #include "libavutil/pixfmt.h" #include "libavutil/avassert.h" #include "libavutil/macros.h" #include "libswscale/swscale.h" -enum { - WIDTH = 96, - HEIGHT = 96, -}; - struct options { enum AVPixelFormat src_fmt; enum AVPixelFormat dst_fmt; double prob; + int w, h; + int threads; + int iters; + int bench; }; struct mode { @@ -53,9 +54,6 @@ struct mode { SwsDither dither; }; -const int dst_w[] = { WIDTH, WIDTH - WIDTH / 3, WIDTH + WIDTH / 3 }; -const int dst_h[] = { HEIGHT, HEIGHT - HEIGHT / 3, HEIGHT + HEIGHT / 3 }; - const struct mode modes[] = { { SWS_FAST_BILINEAR }, { SWS_BILINEAR }, @@ -114,7 +112,8 @@ static void get_mse(int mse[4], const AVFrame *a, const AVFrame *b, int comps) } } -static int scale_legacy(AVFrame *dst, const AVFrame *src, struct mode mode) +static int scale_legacy(AVFrame *dst, const AVFrame *src, struct mode mode, + struct options opts) { SwsContext *sws_legacy; int ret; @@ -131,23 +130,28 @@ static int scale_legacy(AVFrame *dst, const AVFrame *src, struct mode mode) sws_legacy->dst_format = dst->format; sws_legacy->flags = mode.flags; sws_legacy->dither = mode.dither; + sws_legacy->threads = opts.threads; + + if ((ret = sws_init_context(sws_legacy, NULL, NULL)) < 0) + goto error; - ret = sws_init_context(sws_legacy, NULL, NULL); - if (!ret) + for (int i = 0; i < opts.iters; i++) ret = sws_scale_frame(sws_legacy, dst, src); +error: sws_freeContext(sws_legacy); return ret; } /* Runs a series of ref -> src -> dst -> out, and compares out vs ref */ static int run_test(enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt, - int dst_w, int dst_h, struct mode mode, const AVFrame *ref, - const int mse_ref[4]) + int dst_w, int dst_h, struct mode mode, struct options opts, + const AVFrame *ref, const int mse_ref[4]) { AVFrame *src = NULL, *dst = NULL, *out = NULL; int mse[4], mse_sws[4], ret = -1; const int comps = fmt_comps(src_fmt) & fmt_comps(dst_fmt); + int64_t time, time_ref = 0; src = av_frame_alloc(); dst = av_frame_alloc(); @@ -174,12 +178,20 @@ static int run_test(enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt, sws[1]->flags = mode.flags; sws[1]->dither = mode.dither; - if (sws_scale_frame(sws[1], dst, src) < 0) { - fprintf(stderr, "Failed %s ---> %s\n", av_get_pix_fmt_name(src->format), - av_get_pix_fmt_name(dst->format)); - goto error; + sws[1]->threads = opts.threads; + + time = av_gettime_relative(); + + for (int i = 0; i < opts.iters; i++) { + if (sws_scale_frame(sws[1], dst, src) < 0) { + fprintf(stderr, "Failed %s ---> %s\n", av_get_pix_fmt_name(src->format), + av_get_pix_fmt_name(dst->format)); + goto error; + } } + time = av_gettime_relative() - time; + if (sws_scale_frame(sws[2], out, dst) < 0) { fprintf(stderr, "Failed %s ---> %s\n", av_get_pix_fmt_name(dst->format), av_get_pix_fmt_name(out->format)); @@ -196,11 +208,13 @@ static int run_test(enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt, if (!mse_ref) { /* Compare against the legacy swscale API as a reference */ - if (scale_legacy(dst, src, mode) < 0) { + time_ref = av_gettime_relative(); + if (scale_legacy(dst, src, mode, opts) < 0) { fprintf(stderr, "Failed ref %s ---> %s\n", av_get_pix_fmt_name(src->format), av_get_pix_fmt_name(dst->format)); goto error; } + time_ref = av_gettime_relative() - time_ref; if (sws_scale_frame(sws[2], out, dst) < 0) goto error; @@ -221,6 +235,15 @@ static int run_test(enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt, } } + if (opts.bench && time_ref) { + printf(" time=%"PRId64" us, ref=%"PRId64" us, speedup=%.3fx %s\n", + time / opts.iters, time_ref / opts.iters, + (double) time_ref / time, + time <= time_ref ? "faster" : "\033[1;33mslower\033[0m"); + } else if (opts.bench) { + printf(" time=%"PRId64" us\n", time / opts.iters); + } + fflush(stdout); ret = 0; /* fall through */ error: @@ -232,6 +255,9 @@ static int run_test(enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt, static int run_self_tests(const AVFrame *ref, struct options opts) { + const int dst_w[] = { opts.w, opts.w - opts.w / 3, opts.w + opts.w / 3 }; + const int dst_h[] = { opts.h, opts.h - opts.h / 3, opts.h + opts.h / 3 }; + enum AVPixelFormat src_fmt, dst_fmt, src_fmt_min = 0, dst_fmt_min = 0, @@ -254,8 +280,9 @@ static int run_self_tests(const AVFrame *ref, struct options opts) for (int m = 0; m < FF_ARRAY_ELEMS(modes); m++) { if (ff_sfc64_get(&prng_state) > UINT64_MAX * opts.prob) continue; + if (run_test(src_fmt, dst_fmt, dst_w[w], dst_h[h], - modes[m], ref, NULL) < 0) + modes[m], opts, ref, NULL) < 0) return -1; } } @@ -300,7 +327,7 @@ static int run_file_tests(const AVFrame *ref, FILE *fp, struct options opts) opts.dst_fmt != AV_PIX_FMT_NONE && dst_fmt != opts.dst_fmt) continue; - if (run_test(src_fmt, dst_fmt, dw, dh, mode, ref, mse) < 0) + if (run_test(src_fmt, dst_fmt, dw, dh, mode, opts, ref, mse) < 0) return -1; } @@ -312,7 +339,11 @@ int main(int argc, char **argv) struct options opts = { .src_fmt = AV_PIX_FMT_NONE, .dst_fmt = AV_PIX_FMT_NONE, - .prob = 1.0, + .w = 96, + .h = 96, + .threads = 1, + .iters = 1, + .prob = 1.0, }; AVFrame *rgb = NULL, *ref = NULL; @@ -335,6 +366,10 @@ int main(int argc, char **argv) " Only test the specified destination pixel format\n" " -src \n" " Only test the specified source pixel format\n" + " -bench \n" + " Run benchmarks with the specified number of iterations. This mode also increases the size of the test images\n" + " -threads \n" + " Use the specified number of threads\n" " -cpuflags \n" " Uses the specified cpuflags in the tests\n" ); @@ -368,6 +403,14 @@ int main(int argc, char **argv) fprintf(stderr, "invalid pixel format %s\n", argv[i + 1]); goto error; } + } else if (!strcmp(argv[i], "-bench")) { + opts.bench = 1; + opts.iters = atoi(argv[i + 1]); + opts.iters = FFMAX(opts.iters, 1); + opts.w = 1920; + opts.h = 1080; + } else if (!strcmp(argv[i], "-threads")) { + opts.threads = atoi(argv[i + 1]); } else if (!strcmp(argv[i], "-p")) { opts.prob = atof(argv[i + 1]); } else { @@ -390,8 +433,8 @@ bad_option: rgb = av_frame_alloc(); if (!rgb) goto error; - rgb->width = WIDTH / 12; - rgb->height = HEIGHT / 12; + rgb->width = opts.w / 12; + rgb->height = opts.h / 12; rgb->format = AV_PIX_FMT_RGBA; if (av_frame_get_buffer(rgb, 32) < 0) goto error; @@ -406,8 +449,8 @@ bad_option: ref = av_frame_alloc(); if (!ref) goto error; - ref->width = WIDTH; - ref->height = HEIGHT; + ref->width = opts.w; + ref->height = opts.h; ref->format = AV_PIX_FMT_YUVA420P; if (sws_scale_frame(sws[0], ref, rgb) < 0) From patchwork Sun Oct 20 20:05:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52425 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2284782vqi; Sun, 20 Oct 2024 15:39:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVKqaHlIpEcEB0+b1cj/5vczJ1OrYMGJQWJ2OJltgEg0xuGACA4piyMJwRqqngBDI4PN/Bew3+9maHZmriLRpxQ@gmail.com X-Google-Smtp-Source: AGHT+IH92qlJYK/eelLR5p9H1pw+lo9FGa5bZA/dniFLMaz/16gJUlnlN4JHUrU7bjAPXyN+yhFC X-Received: by 2002:a05:6512:1293:b0:52c:dd3d:85af with SMTP id 2adb3069b0e04-53a15229a3emr4425976e87.25.1729463943033; Sun, 20 Oct 2024 15:39:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729463943; cv=none; d=google.com; s=arc-20240605; b=QOR9lri2FupqpAVnvn+GMZK7eOJib28T/uM/qWAD/wz6SRA06oIThU5+UALIfxi2DZ 7Dagi4whAqc44ZjIT2pSR44OfpJiXX+YnwYlPZqk6pdbQtiKoTx+waYz+smF1j8UlsT9 bKgEs8nYHsWIDxhUa3UAC8HFeKXNpYQ3mKk7JpAAlauMdTV0pjzCUE9F6KzndTmlYnIN E9IEQJALiJc1Ptzlw/uat55V0iPMIzBU2TtVqMqoOUjw4v2o0ssoJOX0BLPTMGC6SKbK W8ZI2PeeoVTwKyVNbbr0/a/iOm3jtToMk5+F1ZuGwIHsrC1HI3BrrGha4vzkSCquyY80 XSQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=/icOaZLpSzQftKbr46v6KKCGRVdiINLyvQwHvUyWa2s=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=PuwPYpUTDMeEEurk+5wuJwYXGgh86PhAJ/eEgvukyU47B06nuyTVr4+r2SWOMwSnRd gxsecZNDLxFkjViAKJohxYnByMfYMEYSLDV8RBeVKqIfeD2rKBfuQJRiA1xXhxWq47ww H5A3zFmbaYFPP8q7yDlLFBGeuu+Vnw4ogyykP+tlej3709/SJKGRJhrrD2hxWGfQKzZ2 7woxpvZZEVJr/PUdP9CY/lS+9bp8pcBL8IAwP7UN6Qir9vV5N7H5eFGjv0tdpRwB3oEm pHvbqt/hBCf+cGqxAs6M+VPr1DXEOF2uCt0HOLg/gANCeJt6x4qQCfJbudijnnSrPEoi bJoA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=XgOsYkIb; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 2adb3069b0e04-53a224488c9si762626e87.559.2024.10.20.15.39.02; Sun, 20 Oct 2024 15:39:02 -0700 (PDT) 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=@haasn.xyz header.s=mail header.b=XgOsYkIb; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2811B68DC48; Sun, 20 Oct 2024 23:09:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F045168DB29 for ; Sun, 20 Oct 2024 23:09:00 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454939; bh=bqa8CO++aVW9uZYV/SieSVuIDf54r58JvnC/9mKBoIw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XgOsYkIbZD4tdF9VHOW6I15JrAiBqf6Y47L6ZrEoYwkQTixFTId1+Nflch5OKLnND x4wN4lgIwSA3KKFH9cP4Kp4c7GXdHcqCpVG6sy1mrpBAztWFpMlm5bSAXTyLP2NEdH ntCmgDAaIIUEy9hsfT47tuCX8FNUpQztFLnWwhNY= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id EBA1B4BE95; Sun, 20 Oct 2024 22:08:58 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:27 +0200 Message-ID: <20241020200851.1414766-19-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 18/18] avfilter/vf_scale: switch to new swscale API 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: cpwA6F+9g/5/ From: Niklas Haas Most logic from this filter has been co-opted into swscale itself, allowing the resulting filter to be substantially simpler as it no longer has to worry about context initialization, interlacing, etc. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libavfilter/vf_scale.c | 354 +++++++++-------------------------------- 1 file changed, 72 insertions(+), 282 deletions(-) diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index a89ebe8c47..4afad8d958 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -31,6 +31,7 @@ #include "filters.h" #include "formats.h" #include "framesync.h" +#include "libavutil/pixfmt.h" #include "scale_eval.h" #include "video.h" #include "libavutil/eval.h" @@ -131,10 +132,7 @@ enum EvalMode { typedef struct ScaleContext { const AVClass *class; - struct SwsContext *sws; ///< software scaler context - struct SwsContext *isws[2]; ///< software scaler context for interlaced material - // context used for forwarding options to sws - struct SwsContext *sws_opts; + SwsContext *sws; FFFrameSync fs; /** @@ -149,8 +147,6 @@ typedef struct ScaleContext { int hsub, vsub; ///< chroma subsampling int slice_y; ///< top of current output slice - int input_is_pal; ///< set to 1 if the input format is paletted - int output_is_pal; ///< set to 1 if the output format is paletted int interlaced; int uses_ref; @@ -170,10 +166,6 @@ typedef struct ScaleContext { int in_chroma_loc; int out_chroma_loc; - int out_h_chr_pos; - int out_v_chr_pos; - int in_h_chr_pos; - int in_v_chr_pos; int force_original_aspect_ratio; int force_divisible_by; @@ -334,40 +326,24 @@ revert: static av_cold int preinit(AVFilterContext *ctx) { ScaleContext *scale = ctx->priv; - int ret; - scale->sws_opts = sws_alloc_context(); - if (!scale->sws_opts) + scale->sws = sws_alloc_context(); + if (!scale->sws) return AVERROR(ENOMEM); // set threads=0, so we can later check whether the user modified it - ret = av_opt_set_int(scale->sws_opts, "threads", 0, 0); - if (ret < 0) - return ret; + scale->sws->threads = 0; ff_framesync_preinit(&scale->fs); return 0; } -static const int sws_colorspaces[] = { - AVCOL_SPC_UNSPECIFIED, - AVCOL_SPC_RGB, - AVCOL_SPC_BT709, - AVCOL_SPC_BT470BG, - AVCOL_SPC_SMPTE170M, - AVCOL_SPC_FCC, - AVCOL_SPC_SMPTE240M, - AVCOL_SPC_BT2020_NCL, - -1 -}; - static int do_scale(FFFrameSync *fs); static av_cold int init(AVFilterContext *ctx) { ScaleContext *scale = ctx->priv; - int64_t threads; int ret; if (ctx->filter == &ff_vf_scale2ref) @@ -407,14 +383,13 @@ static av_cold int init(AVFilterContext *ctx) if (ret < 0) return ret; - if (scale->in_color_matrix != -1 && - !ff_fmt_is_in(scale->in_color_matrix, sws_colorspaces)) { + if (scale->in_color_matrix != -1 && !sws_test_colorspace(scale->in_color_matrix, 0)) { av_log(ctx, AV_LOG_ERROR, "Unsupported input color matrix '%s'\n", av_color_space_name(scale->in_color_matrix)); return AVERROR(EINVAL); } - if (!ff_fmt_is_in(scale->out_color_matrix, sws_colorspaces)) { + if (scale->out_color_matrix != -1 && !sws_test_colorspace(scale->out_color_matrix, 1)) { av_log(ctx, AV_LOG_ERROR, "Unsupported output color matrix '%s'\n", av_color_space_name(scale->out_color_matrix)); return AVERROR(EINVAL); @@ -424,25 +399,18 @@ static av_cold int init(AVFilterContext *ctx) scale->w_expr, scale->h_expr, (char *)av_x_if_null(scale->flags_str, ""), scale->interlaced); if (scale->flags_str && *scale->flags_str) { - ret = av_opt_set(scale->sws_opts, "sws_flags", scale->flags_str, 0); + ret = av_opt_set(scale->sws, "sws_flags", scale->flags_str, 0); if (ret < 0) return ret; } for (int i = 0; i < FF_ARRAY_ELEMS(scale->param); i++) - if (scale->param[i] != DBL_MAX) { - ret = av_opt_set_double(scale->sws_opts, i ? "param1" : "param0", - scale->param[i], 0); - if (ret < 0) - return ret; - } + if (scale->param[i] != DBL_MAX) + scale->sws->scaler_params[i] = scale->param[i]; // use generic thread-count if the user did not set it explicitly - ret = av_opt_get_int(scale->sws_opts, "threads", 0, &threads); - if (ret < 0) - return ret; - if (!threads) - av_opt_set_int(scale->sws_opts, "threads", ff_filter_get_nb_threads(ctx), 0); + if (!scale->sws->threads) + scale->sws->threads = ff_filter_get_nb_threads(ctx); if (ctx->filter != &ff_vf_scale2ref && scale->uses_ref) { AVFilterPad pad = { @@ -464,11 +432,7 @@ static av_cold void uninit(AVFilterContext *ctx) av_expr_free(scale->h_pexpr); scale->w_pexpr = scale->h_pexpr = NULL; ff_framesync_uninit(&scale->fs); - sws_freeContext(scale->sws_opts); - sws_freeContext(scale->sws); - sws_freeContext(scale->isws[0]); - sws_freeContext(scale->isws[1]); - scale->sws = NULL; + sws_free_context(&scale->sws); } static int query_formats(const AVFilterContext *ctx, @@ -485,10 +449,9 @@ static int query_formats(const AVFilterContext *ctx, formats = NULL; while ((desc = av_pix_fmt_desc_next(desc))) { pix_fmt = av_pix_fmt_desc_get_id(desc); - if ((sws_isSupportedInput(pix_fmt) || - sws_isSupportedEndiannessConversion(pix_fmt)) - && (ret = ff_add_format(&formats, pix_fmt)) < 0) { - return ret; + if (sws_test_format(pix_fmt, 0)) { + if ((ret = ff_add_format(&formats, pix_fmt)) < 0) + return ret; } } if ((ret = ff_formats_ref(formats, &cfg_in[0]->formats)) < 0) @@ -498,18 +461,24 @@ static int query_formats(const AVFilterContext *ctx, formats = NULL; while ((desc = av_pix_fmt_desc_next(desc))) { pix_fmt = av_pix_fmt_desc_get_id(desc); - if ((sws_isSupportedOutput(pix_fmt) || pix_fmt == AV_PIX_FMT_PAL8 || - sws_isSupportedEndiannessConversion(pix_fmt)) - && (ret = ff_add_format(&formats, pix_fmt)) < 0) { - return ret; + if (sws_test_format(pix_fmt, 1) || pix_fmt == AV_PIX_FMT_PAL8) { + if ((ret = ff_add_format(&formats, pix_fmt)) < 0) + return ret; } } if ((ret = ff_formats_ref(formats, &cfg_out[0]->formats)) < 0) return ret; /* accept all supported inputs, even if user overrides their properties */ - if ((ret = ff_formats_ref(ff_make_format_list(sws_colorspaces), - &cfg_in[0]->color_spaces)) < 0) + formats = ff_all_color_spaces(); + for (int i = 0; i < formats->nb_formats; i++) { + if (!sws_test_colorspace(formats->formats[i], 0)) { + for (int j = i--; j < formats->nb_formats; j++) + formats->formats[j] = formats->formats[j + 1]; + formats->nb_formats--; + } + } + if ((ret = ff_formats_ref(formats, &cfg_in[0]->color_spaces)) < 0) return ret; if ((ret = ff_formats_ref(ff_all_color_ranges(), @@ -517,9 +486,18 @@ static int query_formats(const AVFilterContext *ctx, return ret; /* propagate output properties if overridden */ - formats = scale->out_color_matrix != AVCOL_SPC_UNSPECIFIED - ? ff_make_formats_list_singleton(scale->out_color_matrix) - : ff_make_format_list(sws_colorspaces); + if (scale->out_color_matrix != AVCOL_SPC_UNSPECIFIED) { + formats = ff_make_formats_list_singleton(scale->out_color_matrix); + } else { + formats = ff_all_color_spaces(); + for (int i = 0; i < formats->nb_formats; i++) { + if (!sws_test_colorspace(formats->formats[i], 1)) { + for (int j = i--; j < formats->nb_formats; j++) + formats->formats[j] = formats->formats[j + 1]; + formats->nb_formats--; + } + } + } if ((ret = ff_formats_ref(formats, &cfg_out[0]->color_spaces)) < 0) return ret; @@ -621,50 +599,6 @@ fail: return ret; } -static void calc_chroma_pos(int *h_pos_out, int *v_pos_out, int chroma_loc, - int h_pos_override, int v_pos_override, - int h_sub, int v_sub, int index) -{ - int h_pos, v_pos; - - /* Explicitly default to center siting for compatibility with swscale */ - if (chroma_loc == AVCHROMA_LOC_UNSPECIFIED) - chroma_loc = AVCHROMA_LOC_CENTER; - - /* av_chroma_location_enum_to_pos() always gives us values in the range from - * 0 to 256, but we need to adjust this to the true value range of the - * subsampling grid, which may be larger for h/v_sub > 1 */ - av_chroma_location_enum_to_pos(&h_pos, &v_pos, chroma_loc); - h_pos *= (1 << h_sub) - 1; - v_pos *= (1 << v_sub) - 1; - - if (h_pos_override != -513) - h_pos = h_pos_override; - if (v_pos_override != -513) - v_pos = v_pos_override; - - /* Fix vertical chroma position for interlaced frames */ - if (v_sub && index > 0) { - /* When vertically subsampling, chroma samples are effectively only - * placed next to even rows. To access them from the odd field, we need - * to account for this shift by offsetting the distance of one luma row. - * - * For 4x vertical subsampling (v_sub == 2), they are only placed - * next to every *other* even row, so we need to shift by three luma - * rows to get to the chroma sample. */ - if (index == 2) - v_pos += (256 << v_sub) - 256; - - /* Luma row distance is doubled for fields, so halve offsets */ - v_pos >>= 1; - } - - /* Explicitly strip chroma offsets when not subsampling, because it - * interferes with the operation of flags like SWS_FULL_CHR_H_INP */ - *h_pos_out = h_sub ? h_pos : -513; - *v_pos_out = v_sub ? v_pos : -513; -} - static int config_props(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; @@ -672,12 +606,8 @@ static int config_props(AVFilterLink *outlink) AVFilterLink *inlink = ctx->filter == &ff_vf_scale2ref ? outlink->src->inputs[1] : outlink->src->inputs[0]; - enum AVPixelFormat outfmt = outlink->format; - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); - const AVPixFmtDescriptor *outdesc = av_pix_fmt_desc_get(outfmt); ScaleContext *scale = ctx->priv; uint8_t *flags_val = NULL; - int in_range, in_colorspace; int ret; if ((ret = scale_eval_dimensions(ctx)) < 0) @@ -701,107 +631,12 @@ static int config_props(AVFilterLink *outlink) /* TODO: make algorithm configurable */ - scale->input_is_pal = desc->flags & AV_PIX_FMT_FLAG_PAL; - if (outfmt == AV_PIX_FMT_PAL8) outfmt = AV_PIX_FMT_BGR8; - scale->output_is_pal = av_pix_fmt_desc_get(outfmt)->flags & AV_PIX_FMT_FLAG_PAL; - - in_range = scale->in_range; - if (in_range == AVCOL_RANGE_UNSPECIFIED) - in_range = inlink0->color_range; - - in_colorspace = scale->in_color_matrix; - if (in_colorspace == -1 /* auto */) - in_colorspace = inlink0->colorspace; - - if (scale->sws) - sws_freeContext(scale->sws); - if (scale->isws[0]) - sws_freeContext(scale->isws[0]); - if (scale->isws[1]) - sws_freeContext(scale->isws[1]); - scale->isws[0] = scale->isws[1] = scale->sws = NULL; - if (inlink0->w == outlink->w && - inlink0->h == outlink->h && - in_range == outlink->color_range && - in_colorspace == outlink->colorspace && - inlink0->format == outlink->format && - scale->in_chroma_loc == scale->out_chroma_loc) - ; - else { - struct SwsContext **swscs[3] = {&scale->sws, &scale->isws[0], &scale->isws[1]}; - int i; - - for (i = 0; i < 3; i++) { - int in_full, out_full, brightness, contrast, saturation; - int h_chr_pos, v_chr_pos; - const int *inv_table, *table; - struct SwsContext *const s = sws_alloc_context(); - if (!s) - return AVERROR(ENOMEM); - *swscs[i] = s; - - ret = av_opt_copy(s, scale->sws_opts); - if (ret < 0) - return ret; - - av_opt_set_int(s, "srcw", inlink0 ->w, 0); - av_opt_set_int(s, "srch", inlink0 ->h >> !!i, 0); - av_opt_set_int(s, "src_format", inlink0->format, 0); - av_opt_set_int(s, "dstw", outlink->w, 0); - av_opt_set_int(s, "dsth", outlink->h >> !!i, 0); - av_opt_set_int(s, "dst_format", outfmt, 0); - if (in_range != AVCOL_RANGE_UNSPECIFIED) - av_opt_set_int(s, "src_range", - in_range == AVCOL_RANGE_JPEG, 0); - if (outlink->color_range != AVCOL_RANGE_UNSPECIFIED) - av_opt_set_int(s, "dst_range", - outlink->color_range == AVCOL_RANGE_JPEG, 0); - - calc_chroma_pos(&h_chr_pos, &v_chr_pos, scale->in_chroma_loc, - scale->in_h_chr_pos, scale->in_v_chr_pos, - desc->log2_chroma_w, desc->log2_chroma_h, i); - av_opt_set_int(s, "src_h_chr_pos", h_chr_pos, 0); - av_opt_set_int(s, "src_v_chr_pos", v_chr_pos, 0); - - calc_chroma_pos(&h_chr_pos, &v_chr_pos, scale->out_chroma_loc, - scale->out_h_chr_pos, scale->out_v_chr_pos, - outdesc->log2_chroma_w, outdesc->log2_chroma_h, i); - av_opt_set_int(s, "dst_h_chr_pos", h_chr_pos, 0); - av_opt_set_int(s, "dst_v_chr_pos", v_chr_pos, 0); - - if ((ret = sws_init_context(s, NULL, NULL)) < 0) - return ret; - - sws_getColorspaceDetails(s, (int **)&inv_table, &in_full, - (int **)&table, &out_full, - &brightness, &contrast, &saturation); - - if (scale->in_color_matrix == -1 /* auto */) - inv_table = sws_getCoefficients(inlink0->colorspace); - else if (scale->in_color_matrix != AVCOL_SPC_UNSPECIFIED) - inv_table = sws_getCoefficients(scale->in_color_matrix); - if (outlink->colorspace != AVCOL_SPC_UNSPECIFIED) - table = sws_getCoefficients(outlink->colorspace); - else if (scale->in_color_matrix != AVCOL_SPC_UNSPECIFIED) - table = inv_table; - - sws_setColorspaceDetails(s, inv_table, in_full, - table, out_full, - brightness, contrast, saturation); - - if (!scale->interlaced) - break; - } - } - if (inlink0->sample_aspect_ratio.num){ outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h * inlink0->w, outlink->w * inlink0->h}, inlink0->sample_aspect_ratio); } else outlink->sample_aspect_ratio = inlink0->sample_aspect_ratio; - if (scale->sws) - av_opt_get(scale->sws, "sws_flags", 0, &flags_val); - + av_opt_get(scale->sws, "sws_flags", 0, &flags_val); av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s csp:%s range:%s sar:%d/%d -> w:%d h:%d fmt:%s csp:%s range:%s sar:%d/%d flags:%s\n", inlink ->w, inlink ->h, av_get_pix_fmt_name( inlink->format), av_color_space_name(inlink->colorspace), av_color_range_name(inlink->color_range), @@ -868,56 +703,6 @@ static int request_frame_ref(AVFilterLink *outlink) return ff_request_frame(outlink->src->inputs[1]); } -static void frame_offset(AVFrame *frame, int dir, int is_pal) -{ - for (int i = 0; i < 4 && frame->data[i]; i++) { - if (i == 1 && is_pal) - break; - frame->data[i] += frame->linesize[i] * dir; - } -} - -static int scale_field(ScaleContext *scale, AVFrame *dst, AVFrame *src, - int field) -{ - int orig_h_src = src->height; - int orig_h_dst = dst->height; - int ret; - - // offset the data pointers for the bottom field - if (field) { - frame_offset(src, 1, scale->input_is_pal); - frame_offset(dst, 1, scale->output_is_pal); - } - - // take every second line - for (int i = 0; i < 4; i++) { - src->linesize[i] *= 2; - dst->linesize[i] *= 2; - } - src->height /= 2; - dst->height /= 2; - - ret = sws_scale_frame(scale->isws[field], dst, src); - if (ret < 0) - return ret; - - // undo the changes we made above - for (int i = 0; i < 4; i++) { - src->linesize[i] /= 2; - dst->linesize[i] /= 2; - } - src->height = orig_h_src; - dst->height = orig_h_dst; - - if (field) { - frame_offset(src, -1, scale->input_is_pal); - frame_offset(dst, -1, scale->output_is_pal); - } - - return 0; -} - /* Takes over ownership of *frame_in, passes ownership of *frame_out to caller */ static int scale_frame(AVFilterLink *link, AVFrame **frame_in, AVFrame **frame_out) @@ -929,12 +714,9 @@ static int scale_frame(AVFilterLink *link, AVFrame **frame_in, AVFrame *out, *in = *frame_in; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format); char buf[32]; - int ret; - int frame_changed; + int ret, flags_orig, frame_changed; *frame_in = NULL; - if (in->colorspace == AVCOL_SPC_YCGCO) - av_log(link->dst, AV_LOG_WARNING, "Detected unsupported YCgCo colorspace.\n"); frame_changed = in->width != link->w || in->height != link->h || @@ -1013,11 +795,6 @@ FF_ENABLE_DEPRECATION_WARNINGS } scale: - if (!scale->sws) { - *frame_out = in; - return 0; - } - scale->hsub = desc->log2_chroma_w; scale->vsub = desc->log2_chroma_h; @@ -1027,6 +804,18 @@ scale: goto err; } + if (scale->in_color_matrix != -1) + in->colorspace = scale->in_color_matrix; + if (scale->in_range != AVCOL_RANGE_UNSPECIFIED) + in->color_range = scale->in_range; + in->chroma_location = scale->in_chroma_loc; + + flags_orig = in->flags; + if (scale->interlaced > 0) + in->flags |= AV_FRAME_FLAG_INTERLACED; + else if (!scale->interlaced) + in->flags &= ~AV_FRAME_FLAG_INTERLACED; + av_frame_copy_props(out, in); out->width = outlink->w; out->height = outlink->h; @@ -1035,26 +824,31 @@ scale: if (scale->out_chroma_loc != AVCHROMA_LOC_UNSPECIFIED) out->chroma_location = scale->out_chroma_loc; - if (scale->output_is_pal) - avpriv_set_systematic_pal2((uint32_t*)out->data[1], outlink->format == AV_PIX_FMT_PAL8 ? AV_PIX_FMT_BGR8 : outlink->format); - av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den, (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w, (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h, INT_MAX); - if (scale->interlaced>0 || (scale->interlaced<0 && - (in->flags & AV_FRAME_FLAG_INTERLACED))) { - ret = scale_field(scale, out, in, 0); - if (ret >= 0) - ret = scale_field(scale, out, in, 1); - } else { - ret = sws_scale_frame(scale->sws, out, in); + if (sws_is_noop(out, in)) { + av_frame_free(&out); + in->flags = flags_orig; + *frame_out = in; + return 0; } + if (out->format == AV_PIX_FMT_PAL8) { + out->format = AV_PIX_FMT_BGR8; + avpriv_set_systematic_pal2((uint32_t*) out->data[1], out->format); + } + + ret = sws_scale_frame(scale->sws, out, in); + av_frame_free(&in); + out->flags = flags_orig; + out->format = outlink->format; /* undo PAL8 handling */ if (ret < 0) av_frame_free(&out); *frame_out = out; + return ret; err: av_frame_free(&in); @@ -1232,8 +1026,8 @@ static void *child_next(void *obj, void *prev) { ScaleContext *s = obj; if (!prev) - return s->sws_opts; - if (prev == s->sws_opts) + return s->sws; + if (prev == s->sws) return &s->fs; return NULL; } @@ -1281,10 +1075,6 @@ static const AVOption scale_options[] = { {"top", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_TOP}, 0, 0, FLAGS, .unit = "chroma_loc"}, {"bottomleft", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_BOTTOMLEFT}, 0, 0, FLAGS, .unit = "chroma_loc"}, {"bottom", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_BOTTOM}, 0, 0, FLAGS, .unit = "chroma_loc"}, - { "in_v_chr_pos", "input vertical chroma position in luma grid/256" , OFFSET(in_v_chr_pos), AV_OPT_TYPE_INT, { .i64 = -513}, -513, 512, FLAGS }, - { "in_h_chr_pos", "input horizontal chroma position in luma grid/256", OFFSET(in_h_chr_pos), AV_OPT_TYPE_INT, { .i64 = -513}, -513, 512, FLAGS }, - { "out_v_chr_pos", "output vertical chroma position in luma grid/256" , OFFSET(out_v_chr_pos), AV_OPT_TYPE_INT, { .i64 = -513}, -513, 512, FLAGS }, - { "out_h_chr_pos", "output horizontal chroma position in luma grid/256", OFFSET(out_h_chr_pos), AV_OPT_TYPE_INT, { .i64 = -513}, -513, 512, FLAGS }, { "force_original_aspect_ratio", "decrease or increase w/h if necessary to keep the original AR", OFFSET(force_original_aspect_ratio), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 2, FLAGS, .unit = "force_oar" }, { "disable", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, 0, 0, FLAGS, .unit = "force_oar" }, { "decrease", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0, FLAGS, .unit = "force_oar" }, @@ -1350,7 +1140,7 @@ static void *scale2ref_child_next(void *obj, void *prev) { ScaleContext *s = obj; if (!prev) - return s->sws_opts; + return s->sws; return NULL; }