From patchwork Thu Oct 10 22:26:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52196 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp192794vqn; Thu, 10 Oct 2024 15:28:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVHpmgE1HCMABW3VzJ3rHZVz/k0ZfnbcSDxnHSaTiAABDuDSnUHiW6QcKiN75pM7MH24qf6DIJeveSEDjw/qjsN@gmail.com X-Google-Smtp-Source: AGHT+IFive395UKwNkfNwKlqvnWWQQeGTADGgS6gbFpMrznRV6SYHm9ObTzMMUvi+N9PPIbqAO7/ X-Received: by 2002:a2e:802:0:b0:2f6:62a1:25fe with SMTP id 38308e7fff4ca-2fb327704famr1089841fa.23.1728599297767; Thu, 10 Oct 2024 15:28:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728599297; cv=none; d=google.com; s=arc-20240605; b=CNpWweTnEiY2LawVTWMWLIDxNflSXGzbggsdmLNG4mXKIrAsHP2bKrUAQkujpCIRZw NG1JzdlQ/4vuMf2FfJLcbFEvUOjLtcBesbwG7kr8TWWyf9+SMS+FDczvxAgyZ8o5sL2d wZ8Vnm5eigoeqGq7BRF8ThxXxyV3RN+mMPMnfcDplDN0HpnPkcMQkgJoMHIjJqtQkHTV JX9Nc62FrnFWnlMqCQs0YSVQeFBZenS25mJr8z0FoB+I8JhtKMzpmpRaa8YRvfV/RLlN GnPiyr2kgvcZAZ8TZeSiLgrxU1uJa04LKBshdtw8anzYyl9TcseoHhHAgaTBwYURLGNH fnzw== 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=EN/SxNaXqandL8tLCLAGOdDMZW5kDy980ZT3vTx19HSCjqDTJX0t0/yDysp7I+6Kit V7drsoaAJYv18D5pC6arWD4V/81FFAeKodduQqqJh3Fl6h/jqs18xEYSUFQC6evIXNZ/ OcGEu+0SpvfVQx14PclEn7V3/KS3xTNf7XycrN+l0P84tMrKoguy8z/MbAhuq5M03xFX BPw0f7RX3yIWbgeoYZGRRdrbcJO1cfwU6G8XkTmIxSQdto3RmyVX12h0DARpVoG+yE9W oyd2eQFx6XGoJDANhqUedqwsBknrFyfSGGt0u0zh9EyrOx2+CYAF7UXHPVTf3s7c0ZP+ wzAg==; 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=Zqbkjen3; 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-2fb24783696si6038701fa.626.2024.10.10.15.28.17; Thu, 10 Oct 2024 15:28: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=Zqbkjen3; 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 1D77668DEFA; Fri, 11 Oct 2024 01:28: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 D3B7368DDBF for ; Fri, 11 Oct 2024 01:27:56 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599276; bh=mXPX8U50cjvwuSAod4kLpcd3Nsnm7p3+BdVDRdisZUo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zqbkjen30uY3q1vq2RNvAgsj69vI7G+2KKqIVPaWGqvrkHJ1CtatQyh36J8nCXa0S t9sMja1yyVNdEb8r1IdeGRDzcCm2J1UHjyY4yml03uA7tPRRxuWH5UCzJORSgYj6pv CmoVqubt9iVzgtAPeR8rHyKkoZr9W/fx9ztDSXgA= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 47A854255F; Fri, 11 Oct 2024 00:27:56 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:26:48 +0200 Message-ID: <20241010222750.582921-2-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/19] 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: kU9IongsDrAt 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 Thu Oct 10 22:26:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52197 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp192857vqn; Thu, 10 Oct 2024 15:28:29 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUcQhrP7cD/xpQrSGY/t30mY+aNQiQFjCDTkk2yIh2MEmOr7YmopBUDUvHoS0xdxOqwWRtmRIOwKZvZykgto1or@gmail.com X-Google-Smtp-Source: AGHT+IHm/kxq5k4lDUIhBAkPt1MSYvzLqA5OUwoZjKSWxTOFn1jyUvgiFpaFEKJ52x/9XC1SsmSD X-Received: by 2002:a05:6512:3196:b0:539:89f7:3187 with SMTP id 2adb3069b0e04-539da583db0mr108839e87.47.1728599309635; Thu, 10 Oct 2024 15:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728599309; cv=none; d=google.com; s=arc-20240605; b=Nk1VEC1I5Ql7wblBNIDXF5RFgzy8iDALObYpR7MwLF+I4yCS3Ds1cNRvguQHl7Gxaf Xoqv7+OM607gySRlN2TIwKVUdxcVvjtWbkYLgLtUqzVmiR30kBlDV4qYsSisFqqXPPWq ND9YDJoim5o/QdcED2avHDKSNLv+JxewRqePBlG4bQ4JwV3TZ5IsAk2RJwQJHU4PPJdI ebOqbxIwbpWhsxYcCyK1SwaCCZCN6MsaSKh3JTTimoyGd834jmIS+cyzoIGKFOzlJYHc rVm5fWRSeycpoOIvYEvrzLAuiFKQZfoB4KdrxN11Rm1X2oQibEzLy20SrSFxOV7CrGoZ WXJQ== 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=NUWS9pOXjZ/CBDhknff5vo+ZrYTMe8UFPwLLUoBmaPI=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=SusVUq+Bz6E4ckOiRO1V6wwMOfbF7KYLzCmgFe87PBO26xqWD2nPtzKB5bpsjTIdLG O9QtBa8VHgYqDF1mVJ19tngWL/2rJZXzQSLZjrb6VbTI+VcDNeXLu0lyaWAKbPwUZ3o+ 9li1SL5ZiuGl6nYs0n6e9OS/Yt2uq/2nc6ZGwsmFSDI61j+fqrudLyLEpAWB1KYzc8uo 3ns1mEoSVeHIccUUs8zbai+eB7Zv0Pj9YcU+o+D/tAhTAVycJYunhDayiZHzr9KW5r1p ajwNfQmi9xm6I0S6dBpSUslazedLN+hcqOs+aHQHy8XeasA1IP20drL+nIlQFqI8eWmN Z0Hw==; 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=LJWYSEwI; 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-539cba15ca8si899310e87.601.2024.10.10.15.28.29; Thu, 10 Oct 2024 15:28:29 -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=LJWYSEwI; 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 E8ECD68DEE1; Fri, 11 Oct 2024 01:28: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 E7D3968DEC1 for ; Fri, 11 Oct 2024 01:27:56 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599276; bh=M/Vqlg8v2X2fw3Tk9S7SQg88Dy6PMfmTuBLETze7pkU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LJWYSEwIawpxfjToXS2ZutOD3PLlV6zG6HQqYAT4mH2NzFpGsfxZCC6iEj/+E1cBi tGKsdWkdV76+GjyxCT3QX1eA2sbJcv+s8fmGWsKLepFZX8K8aRV5dIGiDO8YsCtQob JWl2R+nyZjVuffinHHMx0HlSGcW5NkKNqPdTLTZA= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 87DEE425D8; Fri, 11 Oct 2024 00:27:56 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:26:49 +0200 Message-ID: <20241010222750.582921-3-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/19] 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: LquWusJJ3U0r 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 | 86 ++++++------ 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, 624 insertions(+), 572 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 35c1fb771e..378f49fb69 100644 --- a/libswscale/input.c +++ b/libswscale/input.c @@ -1359,7 +1359,7 @@ static void rgbaf16##endian_name##ToA_c(uint8_t *_dst, const uint8_t *_src, cons 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 31921a3cce..57853a6b47 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, @@ -2565,7 +2565,7 @@ yuv2ya8_X_c(SwsContext *c, const int16_t *lumFilter, } static void -yuv2ayuv64le_X_c(SwsContext *c, const int16_t *lumFilter, +yuv2ayuv64le_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, @@ -2614,7 +2614,7 @@ yuv2ayuv64le_X_c(SwsContext *c, const int16_t *lumFilter, } static void -yuv2xv30le_X_c(SwsContext *c, const int16_t *lumFilter, +yuv2xv30le_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, @@ -2642,7 +2642,7 @@ yuv2xv30le_X_c(SwsContext *c, const int16_t *lumFilter, } static void -yuv2xv36le_X_c(SwsContext *c, const int16_t *lumFilter, +yuv2xv36le_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, @@ -2669,7 +2669,7 @@ yuv2xv36le_X_c(SwsContext *c, const int16_t *lumFilter, } static void -yuv2vuyX_X_c(SwsContext *c, const int16_t *lumFilter, +yuv2vuyX_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, @@ -2726,7 +2726,7 @@ yuv2vuyX_X_c(SwsContext *c, const int16_t *lumFilter, #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, \ @@ -2763,7 +2763,7 @@ yuv2y2xx_wrapper(12) #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..f9b5f60ef0 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; + SwsInternal *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; + SwsInternal *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; + SwsInternal *sws; AVLFG rand; int res = -1; int i; diff --git a/libswscale/utils.c b/libswscale/utils.c index e2ad71a38d..b75c9a2bb4 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -281,7 +281,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; @@ -299,10 +300,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) { @@ -390,7 +391,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; @@ -828,7 +829,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]; @@ -922,7 +923,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; @@ -1016,7 +1017,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); @@ -1031,10 +1032,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; @@ -1148,7 +1150,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; @@ -1162,8 +1164,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; @@ -1194,11 +1196,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) { @@ -1220,9 +1223,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; @@ -1231,7 +1234,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) @@ -1309,15 +1312,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; @@ -1339,7 +1340,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); @@ -1614,7 +1615,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], @@ -1636,7 +1637,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); @@ -1648,7 +1649,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; } @@ -1728,7 +1729,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; @@ -1739,8 +1740,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; @@ -2021,12 +2022,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; @@ -2042,24 +2044,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; @@ -2069,9 +2073,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; @@ -2093,13 +2098,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, @@ -2107,20 +2112,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) @@ -2433,8 +2438,9 @@ fail: return NULL; } -void sws_freeContext(SwsContext *c) +void sws_freeContext(SwsContext *sws) { + SwsInternal *c = sws_internal(sws); int i; if (!c) return; @@ -2505,17 +2511,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, @@ -2524,7 +2532,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 || @@ -2539,13 +2547,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; @@ -2561,12 +2570,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..33af90fd41 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(struct SwsInternal *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 af9434073a..02bb76b742 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 Thu Oct 10 22:26:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52213 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp236228vqn; Thu, 10 Oct 2024 17:23:24 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU6gCiRw9HaK6LasWlj3XcBgKjHv7+XEDtWMo3f9fivQ81GvJf6/aCadIl/6BtRWQ6YluwzaYTe29NYsrifjbEQ@gmail.com X-Google-Smtp-Source: AGHT+IE34/X498QqQw3kzMK9NSSpQ/IPsFrL02f9TOwlpvAkxtSd3ArmiDGCeqbvfwuqk32vlhLK X-Received: by 2002:a17:907:843:b0:a99:550e:2216 with SMTP id a640c23a62f3a-a99b93c2d1dmr53529466b.17.1728606203760; Thu, 10 Oct 2024 17:23:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728606203; cv=none; d=google.com; s=arc-20240605; b=IkmAdiXgL2jqbDoQcEWNuv4VJpwLsZDNFArdroRBPQCePquvsm4QSh1G0IMvIR+waN f/CSUY3/d4LLuCx0BHUfgk45yE86mMd7dkkpQQmONcn4nGCd8Fpne1yJcy3qwHHOr3Uz QNrxbuVIcB+yZ3C3xQu2Y8FN9ujJL2gjLR/JWAr1adyz5BPHQiasRsd9K9usLJ5aP+Au Z4sbn+Mf4ASgchG0EyM1LNYzXE6vdy5tcaKy9CaGSYrSATZEN2Wm9yehJcFu/foa5KAA PX3C5p+Z14BzfMsLVlotborRJ5+VDe5VnAsPKtQt+qfetJYN/ShTIQQIg+dnUA2N+Tdu P7bA== 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=WYIevCfIz8lyUkF+S9ZIUYHeLcaga8eLO1VJHVLFJ+RBAW3yxSrCOr/WdLIc96ai+w e5YmmwYnY52cfP6LIW+6aFB21U9qurLbxFEXEldKkzg4OwRmNnrQFWSipX0mEK/Gn2Cs GsfWyxPoZOaNtjL2/NUx5l+sIdhbVQzb14HO05aW8x/Slp2WeMq8fd3Chp7PaB8MihOJ 2kOzqVRT7Z/j+XuIaNEkv2z+xlKoGimHh3qaRX2CtmWaEKtLgj29/3lJv9Qhj4DMbLkj nsQOVumUQZ/2SG000uPGW8MLcTpV94PkY64ExZ591KMSLvkCMfy21m6gF7kraB1qE+8A TVNg==; 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=mdS3Em7B; 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-a99a80e712asi164391466b.517.2024.10.10.17.23.23; Thu, 10 Oct 2024 17:23:23 -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=mdS3Em7B; 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 0EE4368DEF6; Fri, 11 Oct 2024 01:28: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 28A6568DDBF for ; Fri, 11 Oct 2024 01:27:57 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599276; bh=y2yM8lBsYwl+kLdrCEI6jpvQGLX9bAuFjSUOfqnSt5A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mdS3Em7Brq6OWbfTlfjzt5dqs0LBNKFtZLNhgByh9Nx+KGKTMTV8BP/MDNO1axdTE hyQRcKU4H2FwXcfJcsEKBhiDgTqrWmomH2engDGxVmSeprJbJ493lU8EDDjJ8PHUd5 jGVf7/Nvv0V2RHivkYSkf5f+AVRKZD5cjWeZxdes= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id DAA55425E2; Fri, 11 Oct 2024 00:27:56 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:26:50 +0200 Message-ID: <20241010222750.582921-4-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/19] 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: h5ktJeY/n1G6 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 Thu Oct 10 22:26:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52207 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp213864vqn; Thu, 10 Oct 2024 16:23:22 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVBfNbLLq8zXyokW4DHMjLWCDb+PfFgBMPo/cvQNxIuH6hE2j62Q0ka1EtTnZ149uVgGtFpRk8IkN9NQpCx5zdM@gmail.com X-Google-Smtp-Source: AGHT+IGqZZmfSHR5E8GsyPHpalJU9+wq2xAChk17D7lBVNruzMBMWt3a3lHBVCGGu2wjxAEQITpk X-Received: by 2002:a2e:a989:0:b0:2fa:c455:23c with SMTP id 38308e7fff4ca-2fb329f3559mr2637971fa.42.1728602602612; Thu, 10 Oct 2024 16:23:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728602602; cv=none; d=google.com; s=arc-20240605; b=QxKquW8umBQTaVYLIuxpyG1sGKgBPNwRJlisLhHwBTyU7TmC+ffQr3IL1YgpZztSpw URmj97iCRBXtFG7FxHFyj6H1Bk36tWVS6j5r7JME2hWm9MEP9FDoZbDe5crghSpu5cFS NhykLVRN/oKK4TakAxzmmbQVKsFx37e64tcvj+ENt+Ayh5UjfnQglWCr0HOSlAoAq/Cy yrQntiMuzT173zFHcrMJZTqnXiVDReQriIPZdjV4F5VhEOqBa7bbpIBwJbnI8t0tB3Nn vsaviCrgAfCeGQlfpyMYiDzZlbzRsG1sMkYnw4nGDqPzLLNoiBns/FFsXWWB9IG56GXh 4EbQ== 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=I25wPLuXC0j2dmgz6ImrgyAP5zaXXycEP+D8A1NgplA=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=aMZJY/0RUFW667Nus9zx0k+erBQvQgZyZCwSQlYyRLzm4E/IkGcTgyUcqeyduUO35s KUYttoCbjBicjLKtZHtqeMSoFDh20o+oHZzeefRG6S0Qe7hAAJzTmnfBFEGsJE8rV0No pKfCKfWh/WTgAR0dHE3cMUbKQ9uojFoBtla3MB8oAhu88ylD2hYJtLbqclaIGor2advq CyRssx+SwzeBa1B+LFXmtZg9q74qMW9MpKoGAJb9P/+lSIwMUyUwF1Y4vLzEZDqR9NOA XPu1W60nv+7T4Di2K7MBB+SB8/+fR0/frfDN31EQsnD0cNtmZj5tdh3GFDPuHR7quuxp N34w==; 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="Sstx6/+B"; 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-2fb2456e520si7098551fa.83.2024.10.10.16.23.22; Thu, 10 Oct 2024 16:23:22 -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="Sstx6/+B"; 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 52D8B68DF10; Fri, 11 Oct 2024 01:28: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 68C3168DDBF for ; Fri, 11 Oct 2024 01:27:57 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599277; bh=NCMO2f5+YQYQpKtcUKjw5VGDIMe3oCcHRl/0uEO+cWI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sstx6/+BHqLVuYK5Ic1JLDUAfr16EOmZuk3iaCImCcSWzUQbfiSRyXsp0gUCV7hAq ABvp8UyXztImdtOm8rpfevSAryhTs/OdAR6nHcRzPyEfNyA42eCsCMXSbCWdJtywrn UesDCxfVQInWUJ+0JIRG89CoILdNJSeZFtOmQQM8= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 26F89429CA; Fri, 11 Oct 2024 00:27:57 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:26:51 +0200 Message-ID: <20241010222750.582921-5-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/19] 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: /mAI2CS2CByF 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 b75c9a2bb4..d80a3f0a80 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -2514,6 +2514,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 Thu Oct 10 22:26:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52214 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp259821vqn; Thu, 10 Oct 2024 18:33:23 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWNE+7w0BY7uV0JZQNJKUuemXRJuq76A9bxih8vW69/flm7eDChhqZKTWVWB/YU1GgKJ1EvNLIz2S2SDgZtg2P8@gmail.com X-Google-Smtp-Source: AGHT+IGW4udRKK63319wfl/Tw1tMNSbYCfI4cbAxiM7tAYWCjxI3CJ8Nuhb8biXdfXnxwgM/XoHg X-Received: by 2002:a05:651c:551:b0:2f3:f4e2:869c with SMTP id 38308e7fff4ca-2fb32b242ddmr3547411fa.44.1728610402780; Thu, 10 Oct 2024 18:33:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728610402; cv=none; d=google.com; s=arc-20240605; b=Z/MIrc2fr/WBbVXJ5Nosha2sn6RsdU6Ewkw//hoUfqzbAXqUW8SjooavN+I/kPuEAg t0K44navd5mf0iM0rXsJFay3mejEebo+/gTyNnNoBZJfUpT0G32YQ1lsZHfalceB3Qpf oVxkew7mH7I/1iVcASptcAGbTTzayaCW7aDyv9VqN9svOvESKxGyPYkXAAlQOiSvXqKE N3YJPvb0FMo0SwxjclGrqBPc2MUb+sUbAkPavLca61+Y5umfiZ8Wfba7nlK4mM6uv6GQ DKjtoQcAPgMStN4izmILQFjERx7O7we5l3MY1Fo4IJQ6Jiv14m4N0qsI4UJcqAa8hj2n Yfzg== 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=MZyzjW7E22qyDAWC3FaYfMdmYiNWWVje++GrD2iy/G4=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=en3/qgHdrVe8XHeU2OtjwTJVOreK0XTVzJ6hePOSH4Gd9nABH8BtB82g7BKCBCZMf5 ScDu/muKgxUmsrfbjFPDd7Q3Ul5RWdUnxH9u80lhbxqE6gSstbPD9/+qnitqxpNTqHZM T2gTE/DDo0w55dWYf9/UdcscJK9ZhVt5m2IXMLXh6fytJnv6ekIX12OPN1w0afyPxIwC /Tfdti08l9U98JJj3ha1Y04goi2aa1Q9SeyCeaZEkytBat7A30B3el1F8AsGhW6+zPZQ 3QYfJxyNG6r61Auye1e6ed66OLzuBs1H5+9VKsDj0wnd8MLdUBJ6M6st7c51BNu6Iq1f u8bQ==; 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=en2vIwoW; 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-2fb24585003si6869131fa.139.2024.10.10.18.33.22; Thu, 10 Oct 2024 18:33:22 -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=en2vIwoW; 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 44C6F68DF3E; Fri, 11 Oct 2024 01:28: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 1CA2C68DF05 for ; Fri, 11 Oct 2024 01:28:02 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599277; bh=UdZFZP4BOKUeBwn9VdsO35BA6Vb+cndblLMbI80DL3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=en2vIwoWic4WMConNkPUf+aqdDZSrdZRYCj+x5SQOatN2yUz4ko0FLL7ZmLh//u/Q vIGkCjGP+zd2Wxb+r9KNJEUJ6Wc1o1tE3BUX8EFV1RWqKPf8Tqaytzj4BvlaeLeBWU YhI6iiTBaR1saDOtLOjapQNX8p3EVSp13Q+ffGs0= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 6484C42DD0; Fri, 11 Oct 2024 00:27:57 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:26:52 +0200 Message-ID: <20241010222750.582921-6-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/19] 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: sECTUObb4dWn 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 | 65 ++++++++++++++++++++++++++++++++++++++++++ libswscale/utils.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 libswscale/utils.h diff --git a/libswscale/utils.c b/libswscale/utils.c index d80a3f0a80..074be65410 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; @@ -2647,3 +2649,66 @@ 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) +{ + 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) { + av_assert1(!(fmt.height & 1)); + fmt.height >>= 1; + fmt.interlaced = 1; + } + + return fmt; +} diff --git a/libswscale/utils.h b/libswscale/utils.h new file mode 100644 index 0000000000..3d0b08ffe1 --- /dev/null +++ b/libswscale/utils.h @@ -0,0 +1,70 @@ +/* + * 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" + +/* 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); + +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 Thu Oct 10 22:26:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52199 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp196455vqn; Thu, 10 Oct 2024 15:38:22 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUBTg/oxJmPsFyfD9NiJp65IzP7mSaWr6Jhil5EOrWewNyblCEyVPrH3MMUscp8Eq9mcWMt4Naf75SUzKwbXLnm@gmail.com X-Google-Smtp-Source: AGHT+IEcXwRjYhsqPeme4c/NBM21Y9xDMgkJxNVObjm8bVXPt4StvoIzs/v5+tgQwMcMSFu57Qsl X-Received: by 2002:a05:6512:31c3:b0:539:9ee4:bab3 with SMTP id 2adb3069b0e04-539da598f02mr168786e87.59.1728599902116; Thu, 10 Oct 2024 15:38:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728599902; cv=none; d=google.com; s=arc-20240605; b=DdjqlT7+M9zLiENQiPxWaRXxZcia/+bg0QgsJ3KMkVP/Mc9QNRWoZ7eIhV/kOKyjfA 1QBAx0L6XFBSJTT63HbDtAAAcfOsfL+osa+0bQUsTCCJy5EMqNqG7a7JfVravsOKmsbC J0D3WS/7Dj5axNnvWWqDUVhS4Ch5fZGkY07zlVdNMKLQP251WyYNeTIl/CGRDwjEuPJb OmTeLNKqutoXb/ZLYkgNLcUF5S4zfwO8dM9Oe6aS3vpiybldi/DUclnE424DROVqIvb5 hfKSBDSF7poRWZfbTYWn/yjIjQeCRtZwhXu7onVLea2gGpML0gWyedhYX2DzkJ/t4Yp0 gIzQ== 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=yMzyjGaeLpHkLUShhxDJ/Tkmuy/Csh3QDjzt2VYrAzE=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=dafe0wqci46OJdgOjlqTyOixJvs2Qeo3n6zcPWdj6xrhorPTpHPSSV7PO1zlCE4So0 rDP744qjlNo4rf9Ia6RYliwkDfIKNB+8zhrZkPImuNVHUS08J9uK95dXzP2lYHKon6pq y+x1PhAy/CbaJeqyhLrYQEd9e42qvo42AX/q5lJrx+MYM/QNwWHyVOptS3il60BD6bER Y8q3W7ShGfDJQBNXjmW03UuRw5VjgF3qVqiVlNEDpdhP+FCvaZTimSID5T9FKr/MsvWr CiXMl2a9ewhvv136ZLNorlFKOJfuXXzgm/9ChQ48hM+qfSrwgjkC9DjWfgaCxz7gHHhE jIfA==; 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=ewBHNciq; 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-539cb8da822si890571e87.316.2024.10.10.15.38.21; Thu, 10 Oct 2024 15:38:22 -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=ewBHNciq; 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 251A36800A4; Fri, 11 Oct 2024 01:28: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 13D8968DEF2 for ; Fri, 11 Oct 2024 01:28:02 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599277; bh=UzZAgRVIV/fED8yhZJkiaUYE2dbg6kUAFu6VHLBgGhc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ewBHNciq0mapY6F7sGqYK03QwOOPA8rIvNrNaSrlkl4/5uBGLtuAO7xOIC1xlRLCa DzfgX6HBsZ5rrlPgNgKn4hMHLEmWpmUWevypHkqFnNvaqTmNWkNA4+zj3N2qtkSMnO a+MRDc3p2f8Q5+ROyHrQZe3JfVa3v16Pxp2WMDcc= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 9F26A4350D; Fri, 11 Oct 2024 00:27:57 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:26:53 +0200 Message-ID: <20241010222750.582921-7-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/19] 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: TfBysUayJDoX 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. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/swscale.h | 54 ++++++++++++++++++++++++++++++++++++++++++++ libswscale/utils.c | 46 +++++++++++++++++++++++++++++++++++++ libswscale/utils.h | 2 ++ 3 files changed, 102 insertions(+) diff --git a/libswscale/swscale.h b/libswscale/swscale.h index f9fd340240..f36efa4183 100644 --- a/libswscale/swscale.h +++ b/libswscale/swscale.h @@ -85,6 +85,60 @@ 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. 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 074be65410..22411d3429 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -2712,3 +2712,49 @@ SwsFormat ff_fmt_from_frame(const AVFrame *frame) 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 1; /* TODO: implement once primaries conversions are supported */ +} + +int sws_test_transfer(enum AVColorTransferCharacteristic trc, int output) +{ + return 1; /* TODO: implement once gamma conversions are supported */ +} + +int ff_test_fmt(const SwsFormat *fmt, int output) +{ + return sws_test_format (fmt->format, output) && + sws_test_colorspace(fmt->csp, output) && + sws_test_primaries (fmt->prim, output) && + sws_test_transfer (fmt->trc, output); +} + +int sws_test_frame(const AVFrame *frame, int output) +{ + const SwsFormat fmt = ff_fmt_from_frame(frame); + return ff_test_fmt(&fmt, output); +} diff --git a/libswscale/utils.h b/libswscale/utils.h index 3d0b08ffe1..6678364abb 100644 --- a/libswscale/utils.h +++ b/libswscale/utils.h @@ -67,4 +67,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 Thu Oct 10 22:26:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52211 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp213921vqn; Thu, 10 Oct 2024 16:23:30 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUFDavJHfZJrt87WAZEILScQmsnVaHX6zw9F3K/+xbXtiHSVHRA+UREsO3F8tssm0TGLWhHHsLweK7hXzuXWA/8@gmail.com X-Google-Smtp-Source: AGHT+IFAKJFd9LROuc3LCuB4+ixQNud2r1FGHh49TORPVTpLXbrx7dh6jRjpeIIAynJ/mcOseqwm X-Received: by 2002:a05:6402:1eca:b0:5c9:1f1f:8317 with SMTP id 4fb4d7f45d1cf-5c948d58c16mr231712a12.26.1728602610544; Thu, 10 Oct 2024 16:23:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728602610; cv=none; d=google.com; s=arc-20240605; b=kjq+uQ+cFwzVi7JeFCOk4knYe1VVIsSHVETniQcIBkZ3E/qbLlnnfonwP5EuS5C4sw uiFUFf6h9YiEoj61HnJ7PTV1YT3N3ATArLh/CXYAwmEOwhxZtSt6N393VGH/fOTpWXyi vZsmle5THQpfVYwkoyKdyPyy/qRmKYeXF2AzqkLbTBCLkqVXrap5LHdoP9Km+5eI52BA zl+wMBI25zrEANNIds0JtUqrLVSCDDmvIc7cpJyyM7tsXfy8X9bSaZ8dh/7wPYO0+wzR k5jdffBfQVPqPVlKTksQRHEKPKdZIUJNauvTvgI72abyFXqv0T7GrKyC2ijF/6A3BptK wkqw== 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=cTQ1f+LlhmyT9ZJMod1GaK4QU46tbRf3H9nDfuuRUiI=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=It1P+WBZVDLpnW9th0qrItILonb/NiMrj4nOYnhlJeXGGeKHYhEYnzzvXIIUccepID Ck9/8c24andX8qSjWw8BlP1w5nvblT4wnehOXOhcCykK75tvtXe/G+XHJ4M5cUdLfdul //Aj2Ns/ExlYGvJvYOjhtEZeoIFKOSBjW5wuFfkZgGXy8gfea+KYstP9IlBT1ispjzdj hFWA2BEYaXU32O/WfV+p6E1m2EoSeL0cxYYKZjq3sqbiajMZLFSsQg5gx2xH8F4hLjZJ MgcPZDqp15E6YfgRkUdvHMgd95rJTbJoxlSoL4r8u16rI8hydaqAVGBAxhQaEzr+EqoU 4FwA==; 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=njWRPi4W; 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-5c944380698si848050a12.599.2024.10.10.16.23.30; Thu, 10 Oct 2024 16:23:30 -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=njWRPi4W; 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 E0EE368DF36; Fri, 11 Oct 2024 01:28: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 14CD068DF04 for ; Fri, 11 Oct 2024 01:28:02 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599277; bh=R6DZvW8ni4dWSZf9AkuufUUNRFzckg+uN9R6VhYz/hY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=njWRPi4WaK1Ri+7J6BXuctoVy5F0OceU1hcZrS67UQr93v1TKK6YoXl2++AfQ3b8i y16HFlmbWtxUrJs3iVNk+jtww3PE4XENM+DmaQvd4U7UkWHvskVOgP5hyoBA6amAIN 4GNg+7bqhA8bmXrJbQLnf9JM0VAN/G//Y9//5Hpc= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id D9BAF436B4; Fri, 11 Oct 2024 00:27:57 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:26:54 +0200 Message-ID: <20241010222750.582921-8-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/19] 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: 8gbs9pWcfvpc 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 | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/libswscale/swscale.h b/libswscale/swscale.h index f36efa4183..d7ea9bd714 100644 --- a/libswscale/swscale.h +++ b/libswscale/swscale.h @@ -139,6 +139,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 22411d3429..01fe474020 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -2758,3 +2758,10 @@ int sws_test_frame(const AVFrame *frame, int output) const SwsFormat fmt = ff_fmt_from_frame(frame); return ff_test_fmt(&fmt, output); } + +int sws_is_noop(const AVFrame *dst, const AVFrame *src) +{ + SwsFormat dst_fmt = ff_fmt_from_frame(dst); + SwsFormat src_fmt = ff_fmt_from_frame(src); + return ff_fmt_equal(&dst_fmt, &src_fmt); +} From patchwork Thu Oct 10 22:26:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52200 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp196474vqn; Thu, 10 Oct 2024 15:38:26 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUfyupHwxz7wtl/TI1RNYl4E2rzW84CO0qKl5tRPoWryKDowuUYGiADDJv6eZFV4niRTrpPLgIp4yvEuxTj4niG@gmail.com X-Google-Smtp-Source: AGHT+IFn/bX8OIv27qPPcWEEWFT3E+yVtG5kJS225+gJgEqguxPRr3HoS2K8XH3sZLluBp1KQ7nH X-Received: by 2002:a05:6512:3195:b0:539:8b49:893e with SMTP id 2adb3069b0e04-539da552f0emr153321e87.38.1728599906665; Thu, 10 Oct 2024 15:38:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728599906; cv=none; d=google.com; s=arc-20240605; b=fcYIJ8Zwi8FXXNeniQYIYNheyM7kzJLwkP0o3fLZvSeGUatjAHPbHDbK4pjXJ2C1ub j+c+4Cfykpt/tG1n3+C9P+fsWgPXf7stpqR6YziZqF7BItajxQOjY+u1PbBwuGzqpAj3 LdpsQ3VQaLDyxA4lPubu+Flm0cvs+iSY5GCFwuLilBR1boGhDZnvPXTo293Cs/unUuF5 ZsWJNQcWanYEQQDg+CsKN9SXjzQsQ08iqAyhswaBDDMc1uJ5sybIkbOwidImh/frZxut haiy/0wjKn7gg2oL0oEvwL8XG/ZYZJ/TIaZQQaVidpQnxLL2IhYZwycREy3UvDPIiWDu ulDA== 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=lU/dYMdOljmgPuHoW3z2gpoJ1oB7ti3YIBszC/AvTWRjXaJbKWOir2jWfSWolJK701 0RceaPS/axBBoQLzkCqIRSYFGuSsJN8Hez6ldByJX7pVok5RglnU9pFNMGCiK/+lMB52 d3r69fI7AKmrHJz8nQF88uGaXVOLXm2UHMvdMkB1FXku/1Rc3Mt+tnbBLQXv0i0RkKys N8bNq1p8gRnJwM4rE8SSqXP8bNcfCEhIvZpCP9IzYh19jewfku349sJFDFyNWn02ntpf LTPx221+S+rKFdfYQZXsFZJsYCq6eH6LrK7wsAy/v+PcDJbseUa/iYnrIdQldxhWnYR8 syJA==; 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=aaBcc6V+; 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-539cb6c492esi866588e87.109.2024.10.10.15.38.25; Thu, 10 Oct 2024 15:38:26 -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=aaBcc6V+; 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 9193A68DEE6; Fri, 11 Oct 2024 01:28: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 231EB68DF06 for ; Fri, 11 Oct 2024 01:28:02 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599278; bh=v0o9PLYlpcbgjZcNCudik2TKUMsGZ/amgqvwXjoHUfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aaBcc6V+KitpwCgF8sqGjvLigC+bpTRhFzzBiE6koAxyaimksaDLrYsSfQmvBub5g hZovalJkU1Y+GjeMZwN0/QO1RCRI165mErgklIX2e1qRST4ESg2zNijmrYjEMlMVSg G2BjJKLhEoIweNlPeXhKrSk3oKtNJR6TcSntQWEM= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 25EFA43F06; Fri, 11 Oct 2024 00:27:58 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:26:55 +0200 Message-ID: <20241010222750.582921-9-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/19] 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: O5kmmVrEKAj+ 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 Thu Oct 10 22:26:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52205 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp201321vqn; Thu, 10 Oct 2024 15:53:27 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXSYsJBU/3R3b1/CgyM17wIJtrNvnnXgc6jmzr8PUoI0YLxbA8coCRWgelyUt8P9fVV/ZkABY+ukfTiz4KHoFgj@gmail.com X-Google-Smtp-Source: AGHT+IGS7G+fNjn1jbEmJbdfmiHZ5DdbS+qgz73o9ghh44jUEfMXncBQZDXnDHfZUHQUhvaODkMb X-Received: by 2002:a17:907:efcb:b0:a99:462c:8730 with SMTP id a640c23a62f3a-a99b945e515mr44505766b.22.1728600807629; Thu, 10 Oct 2024 15:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728600807; cv=none; d=google.com; s=arc-20240605; b=Z1LWQ/Zg5erL2VUXSiRlenMHH8UtD1IGv3aaN1qLe9/dVzy5LVNQByo+yqoviMs+Jc n67eVs/aPYlxjETxtc8/zRmVQit22j10FJc0NR3X484LGS5LNoLaAMFDgak0zCJ8/UXP cUK3oHNVPBRbeaAvyYDWqlA6WF17BCHkhxbry+0+eNmEtdF7qtwEzOqbHOQR41PM7dsc vhmbsa6gaoY42onx+RUqKGTpX8r8QaAgfJCQiBXlHe1HhoyzvtFCt3icyh45cGboaUak PQotSj1mwmRVUhpngJoH3ZJ8LcKa2x9KSpeZ1eegDCNtA9yeDFRYuc6Wws2X/3G7BuYb 4Qdw== 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=huuBBsrL5Enf8OJjwMLZixym5PeTGj0FJL2NitGDrlI=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=lBtWLYG28/0ZTF6nUPhChtqZTOpw2CotsMyOzGdKykq4OV1GHSrOoRuSZmYNQWzMG0 O3vCcRVLHGcHb7M2FmQtm5ZDOPbC6pEMDPrBUE9gux4mKbKBEHUyLOAV+h5BvLnCFqTP b5Ne8Jr3BBlyXcrVSmaeEreqJnx3qrNYDc7h55/v5hcD4aSaITls0VYak7Ov3nXzNfaz nbpCO0/6eywIvOwlQaq4sr7AikryPSo6dQq+fx834nIuoXVt4PAoPqq8qm4hBUnByJrP QjXDK7lUOaW68v9NXZB1ouh3/ElzKDIWnn0ovmIgOKx82x5uDmFC+Ev6JePaiHCpF0AJ 3vkw==; 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=pJEV7B3p; 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-a99a7f46dfdsi143867466b.215.2024.10.10.15.53.27; Thu, 10 Oct 2024 15:53:27 -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=pJEV7B3p; 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 B380C68DF46; Fri, 11 Oct 2024 01:28: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 3965168DEF2 for ; Fri, 11 Oct 2024 01:28:02 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599278; bh=ox+0C4C6tPENUPE1kLL4EFiLDyk8RbZV6FgC+yYqGjY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pJEV7B3p+B06cJWB5MKEKJVhdhAnkPn6fK+ZeAUkgDigW8hyThhp4LD+O+wQpuUek adTyja8fRm3sr3/8T6oeUVdvf580JNDSeZJQuWSw3Lj1bs4FBP6f9SoMAgNdNNA+fs 1BAlwDBTrxyHXxXGxLgycNptpGNA1YN7RXGvhV3g= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 648DC440BF; Fri, 11 Oct 2024 00:27:58 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:26:56 +0200 Message-ID: <20241010222750.582921-10-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/19] 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: HObokwIDXaR8 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 | 9 +++++++++ libswscale/utils.c | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index 1817815b01..9b346c4fd9 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,14 @@ 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"); + +/* 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"); + 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 01fe474020..f5833548a7 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -1227,7 +1227,8 @@ SwsContext *sws_alloc_context(void) { SwsInternal *c = av_mallocz(sizeof(SwsInternal)); - av_assert0(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInternal, dither32)); + static_assert(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInternal, dither32), + "dither32 must be at the same offset as redDither + DITHER32_INT"); if (c) { c->av_class = &ff_sws_context_class; From patchwork Thu Oct 10 22:26:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52206 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp201334vqn; Thu, 10 Oct 2024 15:53:30 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVwZPSVZfLelGQfcARp9Cm3/oCyBEeGxzTrM6E/rSFX/q9KLGVTq8zPLhKaPUAVDkORRdNoOavB1+EyV86eeRLS@gmail.com X-Google-Smtp-Source: AGHT+IEF+Uhn17WFwdwWrwiqHee2s4pCDLa5tlt31dGlUd9G+UOvv2cT3V25UCKpGBKdWtf989De X-Received: by 2002:a05:6512:12d4:b0:539:a3cd:97ca with SMTP id 2adb3069b0e04-539da50f0c9mr200068e87.36.1728600810036; Thu, 10 Oct 2024 15:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728600810; cv=none; d=google.com; s=arc-20240605; b=V4yRlPkcsNNy2RMaBSiov3KOfLGzWur92AlEIVOY+SB3iQGwpGxj2EK3+i+aKgKPSF XQhIJ3XGmPy3injQpYJKSdW5547+KfebHICieUw8jqPERk2Y33W4zFTdApL+m8ydXLVE Hm/PBB0ueAOvVX08VDs/DbPo4acLuvdhszXr//fuFXCXpWibNQyujv5sCsxnbAgPODvc iE/GwjlIWF57yfWumE8XJb+e97v+9trtxnoiBb1DER0HB2RbQp6Dui9j4PCUD0z7BA7d meY8xWZamUIN9XoOulFGfGiYPqCdxEYffn+UHimxIm1fxsSTL1OI4eKleraFK/mCM4wB otWg== 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=3JMMNzHJlTb5RhIuf86nnSATGLshUqM+j5XFKOgPXHI=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=Wi3N9SynPrG6pbcztrDcFar3NPpF2j+ikp8hjKlyoB5pNVsZqwtOKH/jDYF0a8wtYh EWgXskF4Bz7xEGa2vdwcpAmxpt2Bvlt8ekx75qZqgk7CVlF7HWgqSOrkFumbJuzIM5bY npA4j6wNsZoumt2WXHQTCwKcrZsPDA+pgAD0pfq68k6dQfuw6sH/iDp4VYyVJToAudXD ZhfIVQj+SXZT5oTq1nP+VD2QivoR1BhOS0f98so+QBVsy7HKX3BLf65bL5Xffn4WhFSj CbbfOYU8p8j4ldozuIYY9Md+LUiIPDU7Url/i23sur51gnER/mpedS0XJLLX6xqLmls8 NVuQ==; 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=gvhJVDic; 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-539cba16334si881981e87.639.2024.10.10.15.53.29; Thu, 10 Oct 2024 15:53:30 -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=gvhJVDic; 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 A575668DF4F; Fri, 11 Oct 2024 01:28:23 +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 483AF68DF08 for ; Fri, 11 Oct 2024 01:28:02 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599278; bh=OZMaU5YIiOmCAUbKUdcN6tU9WA8vzHtjdxRBaaL3/kg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gvhJVDico5+JaBua6u3CQRxUY/wGIv/MAiTWzEgv/4wEZXLyU04PzWyrfGc1Gtn6B ircsS+N27WB8oC4s75z062IAaLmKZu4eIrxOXO3v71OUux8A5to4X5AVwX8kCuI8P0 LEe5q8Xc5qGlfs9UQVVQFhMU5TkoS/WJHBsLUDiM= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id A16D1441F2; Fri, 11 Oct 2024 00:27:58 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:26:57 +0200 Message-ID: <20241010222750.582921-11-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/19] 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: sHRvYr19e5im 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 9b346c4fd9..b58d1bb12a 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 Thu Oct 10 22:26:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52210 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp213893vqn; Thu, 10 Oct 2024 16:23:27 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWzYWPLY7OPUrdvtGlcTRDB/+ehiONpCFUIS70noaAv4N1Q5xffTAGNGXoVWLDnCk8plCdUmjfcEqvSQcFBUAZ7@gmail.com X-Google-Smtp-Source: AGHT+IH8HtP35fAiohBCaghIel2DEr8qWedhxXV0y2Y9/017HguN4l6VHMb7X8/ssLZv3vtnidjs X-Received: by 2002:a05:6512:3b25:b0:52c:99c9:bef6 with SMTP id 2adb3069b0e04-539da3c1dfemr164022e87.7.1728602606599; Thu, 10 Oct 2024 16:23:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728602606; cv=none; d=google.com; s=arc-20240605; b=Skp202IttlmwTNXn8WUd+dxZfdsiqpLSWGni8QPjSZWPbuZWC/0Va8LChlx7jEBiSg xhmVDuXIiTuIbbETzy+b+nmVkkgoMZ8kUneX234Nr0+WAAG1kqVinAYBnab1/JPmVoq+ 2mriPx/wJSUtLtQQYbrejG4+8GB1ROmOxsP5F/xDEGdfMDBLsSUkIyw7yLbh2d0/wQKq GzrGPjnPImqH2pc0Myrtd+MWvH9PORcTmUlTbVNnms32hsJ9UgjAEW+aI5HVY+EuEuzI /lqC6WnIn+Y0xYmRIj5qxKzRJWaw21BZoBRYP7gCs//fJVhT/IA2FaIL4fyWeaExY+uj iu2Q== 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=rZlRo+HWA3PhBn63GwTpbIiwdimp4tj0D2migdyf470=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=IIuI+yb6Gh0cR8xPL3q3ct6VhgMHuuFLwux9kOeOnU8ykokSVDUnfcmhGNshgqfYzq RmycdVjC54ph8xg/9j60RCADQKW+uI+HTid7OT/BWIskzi9zy7E87X6r1J18ZlRJ4YfH /BLIzaub6+zzSTFLetUGaS3HrDKiY2CtO1FA/c5I1d+mVY6fYw+vxB3YtEabvqaEsMtL Lp7cYuKh9QVUdxyNcmzwthloaj85lQlNqlN9LqubF0IGytzXxZ/XB1lgi6SKN8664zvO SdPRxSFgfH0Ru+ZoWleqeThueilfVbNQu2frmT7rhRsElZmyQj9yRlH+S2nVIOya6KgC VhUw==; 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=koNcB9dn; 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-539cb90b79dsi826689e87.464.2024.10.10.16.23.26; Thu, 10 Oct 2024 16:23:26 -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=koNcB9dn; 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 D57C768DF5C; Fri, 11 Oct 2024 01:28:25 +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 661F168DF0C for ; Fri, 11 Oct 2024 01:28:02 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599279; bh=UN5NXVguMvAR0FpxxhBtSZWOJqWYNiCRL0PGfLFSoSQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=koNcB9dn+2THNMBTICHEULh2wXyboN8yL5GtpvIOXJlh6yHxFSqU4NS+N+TeghfJR rQFwo16Jo3FkhP7/2lLfSd0m2joQk1jDy5QfXm47ucu3qzHSkfxg5SzecdlgAV+TBN Z1FIttQ5gwBPEfVwI3LrMTusYSKJ8iohSIrzxptY= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id E347C4442C; Fri, 11 Oct 2024 00:27:58 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:26:58 +0200 Message-ID: <20241010222750.582921-12-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/19] swscale/internal: group user-facing options together 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: myeHgONm9kY0 From: Niklas Haas This is a preliminary step to separating these into a new struct. This commit contains no functional changes, it is a pure search-and-replace. 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 | 32 +- libswscale/output.c | 24 +- libswscale/ppc/swscale_altivec.c | 6 +- libswscale/ppc/swscale_vsx.c | 18 +- libswscale/ppc/yuv2rgb_altivec.c | 18 +- libswscale/ppc/yuv2yuv_altivec.c | 14 +- libswscale/riscv/swscale.c | 6 +- libswscale/slice.c | 22 +- libswscale/swscale.c | 162 +++++----- libswscale/swscale_internal.h | 51 ++-- libswscale/swscale_unscaled.c | 286 +++++++++--------- libswscale/utils.c | 278 ++++++++--------- libswscale/vscale.c | 10 +- libswscale/x86/output.asm | 2 +- libswscale/x86/swscale.c | 64 ++-- libswscale/x86/swscale_template.c | 20 +- libswscale/x86/yuv2rgb.c | 14 +- libswscale/yuv2rgb.c | 80 ++--- tests/checkasm/sw_gbrp.c | 16 +- tests/checkasm/sw_range_convert.c | 16 +- tests/checkasm/sw_rgb.c | 10 +- tests/checkasm/sw_scale.c | 18 +- 36 files changed, 685 insertions(+), 680 deletions(-) diff --git a/libswscale/aarch64/swscale.c b/libswscale/aarch64/swscale.c index 4c31b78ed8..1037eccf85 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->opts.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->opts.src_format) || c->opts.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->opts.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->opts.src_format) || c->opts.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->opts.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->opts.src_format) || c->opts.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->opts.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->opts.src_format) || c->opts.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->opts.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->opts.src_format) || c->opts.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->opts.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->opts.src_format) || c->opts.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->opts.src_range != c->opts.dst_range && !isAnyRGB(c->opts.dst_format)) { if (c->dstBpc <= 14) { - if (c->srcRange) { + if (c->opts.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->opts.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..fdecafd94b 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->opts.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->opts.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->opts.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->opts.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->opts.src_w, dst[0], dstStride[0]); - if (c->srcFormat == AV_PIX_FMT_NV24) + if (c->opts.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->opts.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->opts.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->opts.src_format == AV_PIX_FMT_##IFMT \ + && c->opts.dst_format == AV_PIX_FMT_##OFMT \ + && !(c->opts.src_h & 1) \ + && !(c->opts.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->opts.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->opts.dst_format == AV_PIX_FMT_YUV420P && + (c->opts.src_format == AV_PIX_FMT_NV24 || c->opts.src_format == AV_PIX_FMT_NV42) && + !(c->opts.src_h & 1) && !(c->opts.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..f9484bcc91 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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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..5c3074a0cd 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->opts.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->opts.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->opts.src_format == AV_PIX_FMT_##IFMT \ + && c->opts.dst_format == AV_PIX_FMT_##OFMT \ + && !(c->opts.src_h & 1) \ + && !(c->opts.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->opts.flags & SWS_ACCURATE_RND; + if (c->opts.src_format == AV_PIX_FMT_RGBA + && c->opts.dst_format == AV_PIX_FMT_NV12 + && (c->opts.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 378f49fb69..992a29bbf1 100644 --- a/libswscale/input.c +++ b/libswscale/input.c @@ -1367,7 +1367,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->opts.src_format; *chrToYV12 = NULL; switch (srcFormat) { diff --git a/libswscale/loongarch/input_lasx.c b/libswscale/loongarch/input_lasx.c index b682179c6e..046f395ae5 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->opts.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..c0e5627690 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->opts.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..21d0a501b0 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->opts.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->opts.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->opts.flags & SWS_FULL_CHR_H_INT) { + switch (c->opts.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->opts.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..24e6de5535 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->opts.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->opts.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->opts.flags & SWS_FULL_CHR_H_INT) { + switch (c->opts.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->opts.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..374b0a6f32 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->opts.src_range != c->opts.dst_range && !isAnyRGB(c->opts.dst_format)) { if (c->dstBpc <= 14) { - if (c->srcRange) { + if (c->opts.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->opts.src_range != c->opts.dst_range && !isAnyRGB(c->opts.dst_format)) { if (c->dstBpc <= 14) { - if (c->srcRange) { + if (c->opts.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->opts.src_format == AV_PIX_FMT_YUV420P) { + switch (c->opts.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->opts.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->opts.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->opts.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->opts.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->opts.src_format == AV_PIX_FMT_YUV420P) { + switch (c->opts.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->opts.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->opts.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->opts.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->opts.src_format)) { break; } else return yuv420_abgr32_lsx; diff --git a/libswscale/loongarch/swscale_lasx.c b/libswscale/loongarch/swscale_lasx.c index 79fa4c64b0..fcaca3123b 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->opts.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->opts.src_format) || c->opts.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->opts.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->opts.src_format) || c->opts.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..fce09800fe 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->opts.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->opts.src_format) || c->opts.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->opts.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->opts.src_format) || c->opts.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..e9e4a63a0a 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->opts.dst_w + 7) & ~7; \ h_size = y >> 4; \ res = y & 15; \ \ - vshift = c->srcFormat != AV_PIX_FMT_YUV422P; \ + vshift = c->opts.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->opts.dst_w + 7) & ~7; \ h_size = y >> 4; \ res = y & 15; \ \ - vshift = c->srcFormat != AV_PIX_FMT_YUV422P; \ + vshift = c->opts.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..6339d07d6c 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->opts.dst_w >> 4; \ + res = (c->opts.dst_w & 15) >> 1; \ + vshift = c->opts.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->opts.dst_w >> 4; \ + res = (c->opts.dst_w & 15) >> 1; \ + vshift = c->opts.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..6248e5f4b5 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(SwsInternal, opts.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,7 @@ const AVClass ff_sws_context_class = { .class_name = "SWScaler", .item_name = sws_context_to_name, .option = swscale_options, - .parent_log_context_offset = OFFSET(parent), + .parent_log_context_offset = offsetof(SwsInternal, parent), .category = AV_CLASS_CATEGORY_SWSCALER, .version = LIBAVUTIL_VERSION_INT, }; diff --git a/libswscale/output.c b/libswscale/output.c index 57853a6b47..80dc30ce0f 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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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]); @@ -2772,7 +2772,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->opts.dst_format; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat); if (isSemiPlanarYUV(dstFormat) && isDataInHighBits(dstFormat)) { @@ -2820,7 +2820,7 @@ av_cold void ff_sws_init_output_funcs(SwsInternal *c, *yuv2nv12cX = yuv2nv12cX_c; } - if(c->flags & SWS_FULL_CHR_H_INT) { + if(c->opts.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..c76c0b6d78 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->opts.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->opts.flags & (SWS_BITEXACT | SWS_FULL_CHR_H_INT)) && !c->needAlpha) { + switch (c->opts.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..5ea3407644 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->opts.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->opts.src_format) || c->opts.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->opts.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->opts.src_format) || c->opts.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->opts.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->opts.flags & SWS_FAST_BILINEAR && c->opts.dst_w >= c->opts.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->opts.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->opts.flags & SWS_BITEXACT) return; #if !HAVE_BIGENDIAN - if (c->flags & SWS_FULL_CHR_H_INT) { + if (c->opts.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..57574c4ab3 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->opts.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->opts.src_w; int h = srcSliceH; int i, j; vector unsigned char uyvy; @@ -545,20 +545,20 @@ av_cold SwsFunc ff_yuv2rgb_init_ppc(SwsInternal *c) * boom with X11 bad match. * */ - if ((c->srcW & 0xf) != 0) + if ((c->opts.src_w & 0xf) != 0) return NULL; - switch (c->srcFormat) { + switch (c->opts.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->opts.src_h & 0x1) != 0) return NULL; - switch (c->dstFormat) { + switch (c->opts.dst_format) { case AV_PIX_FMT_RGB24: av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGB24\n"); return altivec_yuv2_rgb24; @@ -582,7 +582,7 @@ av_cold SwsFunc ff_yuv2rgb_init_ppc(SwsInternal *c) break; case AV_PIX_FMT_UYVY422: - switch (c->dstFormat) { + switch (c->opts.dst_format) { case AV_PIX_FMT_BGR32: av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space UYVY -> RGB32\n"); return altivec_uyvy_rgb32; @@ -742,7 +742,7 @@ static av_always_inline void yuv2packedX_altivec(SwsInternal *c, if (!printed_error_message) { av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n", - av_get_pix_fmt_name(c->dstFormat)); + av_get_pix_fmt_name(c->opts.dst_format)); printed_error_message = 1; } return; @@ -830,7 +830,7 @@ static av_always_inline void yuv2packedX_altivec(SwsInternal *c, /* Unreachable, I think. */ av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n", - av_get_pix_fmt_name(c->dstFormat)); + av_get_pix_fmt_name(c->opts.dst_format)); return; } diff --git a/libswscale/ppc/yuv2yuv_altivec.c b/libswscale/ppc/yuv2yuv_altivec.c index 0ae5223760..7884c38d69 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->opts.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->opts.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->opts.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->opts.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->opts.src_w & 15) && !(c->opts.flags & SWS_BITEXACT) && + c->opts.src_format == AV_PIX_FMT_YUV420P) { + enum AVPixelFormat dstFormat = c->opts.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..eca5769c4e 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->opts.src_range != c->opts.dst_range && !isAnyRGB(c->opts.dst_format) && c->dstBpc <= 14 && (flags & AV_CPU_FLAG_RVV_I32) && (flags & AV_CPU_FLAG_RVB)) { - bool from = c->srcRange != 0; + bool from = c->opts.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->opts.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..72e88be318 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->opts.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->opts.dst_format) && !isGray(c->opts.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->opts.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->opts.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->opts.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->opts.src_format, c->opts.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->opts.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->opts.src_w*2+78, 16), c->opts.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->opts.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->opts.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->opts.dst_format, c->opts.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..ea4c7b00d1 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->opts.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->opts.src_format) || c->opts.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->opts.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->opts.src_format) || c->opts.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; } @@ -237,15 +237,15 @@ 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->opts.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->opts.dst_w; + int dstH = c->opts.dst_h; - const enum AVPixelFormat dstFormat = c->dstFormat; - const int flags = c->flags; + const enum AVPixelFormat dstFormat = c->opts.dst_format; + const int flags = c->opts.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->opts.src_format) || + is16BPS(c->opts.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->opts.src_format)) { src2[0] = src2[1] = src2[2] = @@ -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->opts.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->opts.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->opts.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->opts.src_h, firstLumSrcY + vLumFilterSize) - 1; + int lastLumSrcY2 = FFMIN(c->opts.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->opts.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->opts.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->opts.src_range != c->opts.dst_range && !isAnyRGB(c->opts.dst_format)) { if (c->dstBpc <= 14) { - if (c->srcRange) { + if (c->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.src_format == AV_PIX_FMT_GRAY8 || c->opts.src_format == AV_PIX_FMT_GRAY8A) { r = g = b = i; } else { - av_assert1(c->srcFormat == AV_PIX_FMT_BGR4_BYTE); + av_assert1(c->opts.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->opts.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->opts.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->opts.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 = sws_internal(c->cascaded_context[0])->opts.dst_h; int ret = scale_internal(c->cascaded_context[0], srcSlice, srcStride, srcSliceY, srcSliceH, c->cascaded_tmp[0], c->cascaded_tmpStride[0], @@ -905,13 +905,13 @@ 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 < c->opts.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(c->opts.src_format) ? 2 : (1 << c->chrSrcVSubSample); + int macro_height_dst = isBayer(c->opts.dst_format) ? 2 : (1 << c->chrDstVSubSample); // copy strides, so they can safely be modified int srcStride2[4]; int dstStride2[4]; @@ -923,25 +923,25 @@ static int scale_internal(SwsContext *sws, } if ((srcSliceY & (macro_height_src - 1)) || - ((srcSliceH & (macro_height_src - 1)) && srcSliceY + srcSliceH != c->srcH) || - srcSliceY + srcSliceH > c->srcH || - (isBayer(c->srcFormat) && srcSliceH <= 1)) { + ((srcSliceH & (macro_height_src - 1)) && srcSliceY + srcSliceH != c->opts.src_h) || + srcSliceY + srcSliceH > c->opts.src_h || + (isBayer(c->opts.src_format) && srcSliceH <= 1)) { av_log(c, 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) { + ((dstSliceH & (macro_height_dst - 1)) && dstSliceY + dstSliceH != c->opts.dst_h) || + dstSliceY + dstSliceH > c->opts.dst_h) { av_log(c, AV_LOG_ERROR, "Slice parameters %d, %d are invalid\n", dstSliceY, dstSliceH); return AVERROR(EINVAL); } - if (!check_image_pointers(srcSlice, c->srcFormat, srcStride)) { + if (!check_image_pointers(srcSlice, c->opts.src_format, srcStride)) { av_log(c, AV_LOG_ERROR, "bad src image pointers\n"); return AVERROR(EINVAL); } - if (!check_image_pointers((const uint8_t* const*)dstSlice, c->dstFormat, dstStride)) { + if (!check_image_pointers((const uint8_t* const*)dstSlice, c->opts.dst_format, dstStride)) { av_log(c, AV_LOG_ERROR, "bad dst image pointers\n"); return AVERROR(EINVAL); } @@ -950,22 +950,22 @@ static int scale_internal(SwsContext *sws, if (srcSliceH == 0) return 0; - if (c->gamma_flag && c->cascaded_context[0]) + if (c->opts.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) + srcSliceH == sws_internal(c->cascaded_context[0])->opts.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 && (c->opts.flags & SWS_BITEXACT) && c->opts.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]) * (c->opts.dst_w+2)); - if (usePal(c->srcFormat)) + if (usePal(c->opts.src_format)) ff_update_palette(c, (const uint32_t *)srcSlice[1]); memcpy(src2, srcSlice, sizeof(src2)); @@ -974,7 +974,7 @@ static int scale_internal(SwsContext *sws, memcpy(dstStride2, dstStride, sizeof(dstStride2)); if (frame_start && !scale_dst) { - if (srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) { + if (srcSliceY != 0 && srcSliceY + srcSliceH != c->opts.src_h) { av_log(c, AV_LOG_ERROR, "Slices start in the middle!\n"); return AVERROR(EINVAL); } @@ -983,7 +983,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(c->opts.dst_format)) { uint8_t *base; int x,y; @@ -995,15 +995,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*c->opts.src_w); + for (x=c->src0Alpha-1; x<4*c->opts.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 && c->opts.src_w==c->opts.dst_w && c->opts.src_h==c->opts.dst_h)) { uint8_t *base; av_fast_malloc(&c->xyz_scratch, &c->xyz_scratch_allocated, @@ -1014,7 +1014,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], c->opts.src_w, srcSliceH); src2[0] = base; } @@ -1026,19 +1026,19 @@ static int scale_internal(SwsContext *sws, } src2[0] += (srcSliceH - 1) * srcStride[0]; - if (!usePal(c->srcFormat)) + if (!usePal(c->opts.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] += ( c->opts.dst_h - 1) * dstStride[0]; + dst2[1] += ((c->opts.dst_h >> c->chrDstVSubSample) - 1) * dstStride[1]; + dst2[2] += ((c->opts.dst_h >> c->chrDstVSubSample) - 1) * dstStride[2]; + dst2[3] += ( c->opts.dst_h - 1) * dstStride[3]; - srcSliceY_internal = c->srcH-srcSliceY-srcSliceH; + srcSliceY_internal = c->opts.src_h-srcSliceY-srcSliceH; } - reset_ptr(src2, c->srcFormat); - reset_ptr((void*)dst2, c->dstFormat); + reset_ptr(src2, c->opts.src_format); + reset_ptr((void*)dst2, c->opts.dst_format); if (c->convert_unscaled) { int offset = srcSliceY_internal; @@ -1048,13 +1048,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(c->opts.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(c->opts.dst_format))) break; dst2[i] -= (dstSliceY >> ((i == 1 || i == 2) ? c->chrDstVSubSample : 0)) * dstStride2[i]; } @@ -1071,7 +1071,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 && c->opts.src_w==c->opts.dst_w && c->opts.src_h==c->opts.dst_h)) { uint8_t *dst; if (scale_dst) { @@ -1081,16 +1081,16 @@ static int scale_internal(SwsContext *sws, av_assert0(dstY >= ret); av_assert0(ret >= 0); - av_assert0(c->dstH >= dstY); + av_assert0(c->opts.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], c->opts.dst_w, ret); } /* reset slice direction at end of frame */ - if ((srcSliceY_internal + srcSliceH == c->srcH) || scale_dst) + if ((srcSliceY_internal + srcSliceH == c->opts.src_h) || scale_dst) c->sliceDir = 0; return ret; @@ -1114,9 +1114,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 = c->opts.dst_w; + dst->height = c->opts.dst_h; + dst->format = c->opts.dst_format; ret = av_frame_get_buffer(dst, 0); if (ret < 0) @@ -1167,10 +1167,10 @@ 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 == c->opts.src_h)) return AVERROR(EAGAIN); - if ((slice_start > 0 || slice_height < c->dstH) && + if ((slice_start > 0 || slice_height < c->opts.dst_h) && (slice_start % align || slice_height % align)) { av_log(c, AV_LOG_ERROR, "Incorrectly aligned output: %u/%u not multiples of %u\n", @@ -1182,7 +1182,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 (sws_internal(c->slice_ctx[0])->opts.dither == SWS_DITHER_ED) nb_jobs = 1; c->dst_slice_start = slice_start; @@ -1208,7 +1208,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, c->opts.src_h, dst, c->frame_dst->linesize, slice_start, slice_height); } @@ -1246,7 +1246,7 @@ int attribute_align_arg sws_scale(SwsContext *sws, } return scale_internal(sws, srcSlice, srcStride, srcSliceY, srcSliceH, - dst, dstStride, 0, c->dstH); + dst, dstStride, 0, c->opts.dst_h); } void ff_sws_slice_worker(void *priv, int jobnr, int threadnr, @@ -1274,7 +1274,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, c->opts.src_h, 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 b58d1bb12a..c1cd547ec4 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -329,10 +329,31 @@ 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; + /* Currently active user-facing options. */ + struct { + const AVClass *av_class; + + double scaler_params[2]; ///< Input parameters for scaling algorithms that need them. + int flags; ///< Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc... + int threads; ///< Number of threads used for scaling + + int src_w; ///< Width of source luma/alpha planes. + int src_h; ///< Height of source luma/alpha planes. + int dst_w; ///< Width of destination luma/alpha planes. + int dst_h; ///< Height of destination luma/alpha planes. + enum AVPixelFormat src_format; ///< Source pixel format. + enum AVPixelFormat dst_format; ///< Destination pixel format. + int src_range; ///< 0 = MPG YUV range, 1 = JPG YUV range (source image). + int dst_range; ///< 0 = MPG YUV range, 1 = JPG YUV range (destination image). + int src_h_chr_pos; + int dst_h_chr_pos; + int src_v_chr_pos; + int dst_v_chr_pos; + int gamma_flag; + + SwsDither dither; + SwsAlphaBlend alpha_blend; + } opts; SwsContext *parent; @@ -350,18 +371,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 +386,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 +402,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 +471,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 +496,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 +687,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 @@ -711,7 +712,7 @@ static_assert(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInt /* 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) == 40316, "yuv2rgb_y_offset must be updated in x86 asm"); SwsFunc ff_yuv2rgb_get_func_ptr(SwsInternal *c); diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c index 1a293483c4..292acaba17 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->opts.src_w, dstParam[0], dstStride[0]); - if (c->dstFormat == AV_PIX_FMT_NV12) + if (c->opts.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->opts.src_w, dstParam[0], dstStride[0]); - if (c->srcFormat == AV_PIX_FMT_NV12) + if (c->opts.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->opts.src_w, dstParam[0], dstStride[0]); - if (c->dstFormat == AV_PIX_FMT_NV24) + if (c->opts.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->opts.src_w, dstParam[0], dstStride[0]); - if (c->srcFormat == AV_PIX_FMT_NV24) + if (c->opts.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->opts.src_w, dstParam[0], dstStride[0]); - if (c->srcFormat == AV_PIX_FMT_NV24) + if (c->opts.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->opts.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->opts.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->opts.src_format); + const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.src_format; + const enum AVPixelFormat dstFormat = c->opts.dst_format; void (*conv)(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette) = NULL; int i; @@ -599,7 +599,7 @@ static int palToRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int 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->opts.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->opts.src_format); + const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->opts.dst_format); int bpc = dst_format->comp[0].depth; int alpha = src_format->flags & AV_PIX_FMT_FLAG_ALPHA; int swap = 0; @@ -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->opts.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->opts.src_w); break; case AV_PIX_FMT_BGR48LE: case AV_PIX_FMT_BGR48BE: @@ -791,7 +791,7 @@ 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->opts.src_w); break; default: av_log(c, AV_LOG_ERROR, @@ -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->opts.src_format); + const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->opts.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) || @@ -947,30 +947,30 @@ static int planarRgb16ToRgb16Wrapper(SwsInternal *c, const uint8_t *const src[], src_format->name, dst_format->name); return srcSliceH; } - switch (c->dstFormat) { + switch (c->opts.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->opts.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->opts.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->opts.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->opts.src_w); break; default: av_log(c, AV_LOG_ERROR, @@ -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) { + if (c->opts.src_format != 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)); + av_get_pix_fmt_name(c->opts.src_format), + av_get_pix_fmt_name(c->opts.dst_format)); return srcSliceH; } - switch (c->dstFormat) { + switch (c->opts.dst_format) { case AV_PIX_FMT_BGR24: gbr24ptopacked24(src102, stride102, dst[0] + srcSliceY * dstStride[0], dstStride[0], - srcSliceH, c->srcW); + srcSliceH, c->opts.src_w); break; case AV_PIX_FMT_RGB24: gbr24ptopacked24(src201, stride201, dst[0] + srcSliceY * dstStride[0], dstStride[0], - srcSliceH, c->srcW); + srcSliceH, c->opts.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->opts.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->opts.src_w); break; default: 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)); + av_get_pix_fmt_name(c->opts.src_format), + av_get_pix_fmt_name(c->opts.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) { + if (c->opts.src_format != 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)); + av_get_pix_fmt_name(c->opts.src_format), + av_get_pix_fmt_name(c->opts.dst_format)); return srcSliceH; } - switch (c->dstFormat) { + switch (c->opts.dst_format) { case AV_PIX_FMT_BGR24: gbr24ptopacked24(src102, stride102, dst[0] + srcSliceY * dstStride[0], dstStride[0], - srcSliceH, c->srcW); + srcSliceH, c->opts.src_w); break; case AV_PIX_FMT_RGB24: gbr24ptopacked24(src201, stride201, dst[0] + srcSliceY * dstStride[0], dstStride[0], - srcSliceH, c->srcW); + srcSliceH, c->opts.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->opts.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->opts.src_w); break; default: 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)); + av_get_pix_fmt_name(c->opts.src_format), + av_get_pix_fmt_name(c->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.src_w); break; default: 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)); + av_get_pix_fmt_name(c->opts.src_format), + av_get_pix_fmt_name(c->opts.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->opts.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->opts.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->opts.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->opts.src_w); } else if (i < srcSliceH) - copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW); + copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->opts.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->opts.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->opts.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->opts.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->opts.src_w); } else if (i < srcSliceH) - copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW); + copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.src_format; + const enum AVPixelFormat dstFormat = c->opts.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->opts.flags & SWS_BITEXACT) if ((dstFormat == AV_PIX_FMT_RGB32 || dstFormat == AV_PIX_FMT_BGR32 ) && !isRGBA32(srcFormat) && ALT32_CORR>0) return NULL; @@ -1627,10 +1627,10 @@ 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->opts.src_format; + const enum AVPixelFormat dstFormat = c->opts.dst_format; + const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->opts.src_format); + const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->opts.dst_format); const int srcBpp = (c->srcFormatBpp + 7) >> 3; const int dstBpp = (c->dstFormatBpp + 7) >> 3; rgbConvFn conv = findRgbConvFn(c); @@ -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->opts.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; jopts.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->opts.src_w * srcBpp); }else - conv(srcPtr, dstPtr, c->srcW * srcBpp); + conv(srcPtr, dstPtr, c->opts.src_w * srcBpp); if(dst_bswap) - for(j=0; jsrcW; j++) + for(j=0; jopts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.src_w <= FFABS(dstStride[0]) && + length + c->opts.src_w <= FFABS(srcStride[0])) + length += c->opts.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->opts.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->opts.src_format); + const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->opts.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->opts.src_w : AV_CEIL_RSHIFT(c->opts.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->opts.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->opts.dst_format) || isNBPS(c->opts.dst_format)) { fillPlane16(dst[plane], dstStride[plane], length, height, y, plane == 3, desc_dst->comp[plane].depth, - isBE(c->dstFormat)); + isBE(c->opts.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->opts.src_format) || isNBPS(c->opts.dst_format) + || (is16BPS(c->opts.src_format) != is16BPS(c->opts.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->opts.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->opts.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->opts.src_format) == HAVE_BIGENDIAN && + isBE(c->opts.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->opts.src_format)){ + if(isBE(c->opts.dst_format)){ COPY_UP(AV_RB16, AV_WB16) } else { COPY_UP(AV_RB16, AV_WL16) } } else { - if(isBE(c->dstFormat)){ + if(isBE(c->opts.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->opts.src_format) == HAVE_BIGENDIAN){ + if(isBE(c->opts.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->opts.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->opts.src_format) && is16BPS(c->opts.dst_format) && + isBE(c->opts.src_format) != isBE(c->opts.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->opts.src_format) && isFloat(c->opts.dst_format) && + isBE(c->opts.src_format) != isBE(c->opts.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->opts.src_format) && is16BPS(c->opts.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->opts.src_format; + const enum AVPixelFormat dstFormat = c->opts.dst_format; + const int flags = c->opts.flags; + const int dstH = c->opts.dst_h; + const int dstW = c->opts.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->opts.dither == SWS_DITHER_BAYER || c->opts.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->opts.flags&(SWS_FAST_BILINEAR|SWS_POINT)))) c->convert_unscaled = rgbToRgbWrapper; /* RGB to planar RGB */ @@ -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->opts.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->opts.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 f5833548a7..db996f24c5 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -289,17 +289,17 @@ static SwsContext *alloc_set_opts(int srcW, int srcH, enum AVPixelFormat srcForm if (!c) return NULL; - c->flags = flags; - c->srcW = srcW; - c->srcH = srcH; - c->dstW = dstW; - c->dstH = dstH; - c->srcFormat = srcFormat; - c->dstFormat = dstFormat; + c->opts.flags = flags; + c->opts.src_w = srcW; + c->opts.src_h = srcH; + c->opts.dst_w = dstW; + c->opts.dst_h = dstH; + c->opts.src_format = srcFormat; + c->opts.dst_format = dstFormat; if (param) { - c->param[0] = param[0]; - c->param[1] = param[1]; + c->opts.scaler_params[0] = param[0]; + c->opts.scaler_params[1] = param[1]; } return sws; @@ -1021,10 +1021,10 @@ static int handle_xyz(enum AVPixelFormat *format) static void handle_formats(SwsInternal *c) { - c->src0Alpha |= handle_0alpha(&c->srcFormat); - c->dst0Alpha |= handle_0alpha(&c->dstFormat); - c->srcXYZ |= handle_xyz(&c->srcFormat); - c->dstXYZ |= handle_xyz(&c->dstFormat); + c->src0Alpha |= handle_0alpha(&c->opts.src_format); + c->dst0Alpha |= handle_0alpha(&c->opts.dst_format); + c->srcXYZ |= handle_xyz(&c->opts.src_format); + c->dstXYZ |= handle_xyz(&c->opts.dst_format); if (c->srcXYZ || c->dstXYZ) fill_xyztables(c); } @@ -1057,16 +1057,16 @@ int sws_setColorspaceDetails(SwsContext *sws, const int inv_table[4], } handle_formats(c); - desc_dst = av_pix_fmt_desc_get(c->dstFormat); - desc_src = av_pix_fmt_desc_get(c->srcFormat); + desc_dst = av_pix_fmt_desc_get(c->opts.dst_format); + desc_src = av_pix_fmt_desc_get(c->opts.src_format); - if(range_override_needed(c->dstFormat)) + if(range_override_needed(c->opts.dst_format)) dstRange = 0; - if(range_override_needed(c->srcFormat)) + if(range_override_needed(c->opts.src_format)) srcRange = 0; - if (c->srcRange != srcRange || - c->dstRange != dstRange || + if (c->opts.src_range != srcRange || + c->opts.dst_range != dstRange || c->brightness != brightness || c->contrast != contrast || c->saturation != saturation || @@ -1083,8 +1083,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; + c->opts.src_range = srcRange; + c->opts.dst_range = dstRange; if (need_reinit) { ff_sws_init_range_convert(c); @@ -1106,27 +1106,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(c->opts.dst_format) || isGray(c->opts.dst_format)) && (isYUV(c->opts.src_format) || isGray(c->opts.src_format))) { if (!c->cascaded_context[0] && memcmp(c->dstColorspaceTable, c->srcColorspaceTable, sizeof(int) * 4) && - c->srcW && c->srcH && c->dstW && c->dstH) { + c->opts.src_w && c->opts.src_h && c->opts.dst_w && c->opts.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 = c->opts.src_w; + int srcH = c->opts.src_h; + int dstW = c->opts.dst_w; + int dstH = c->opts.dst_h; int ret; av_log(c, 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(c->opts.dst_format) || is16BPS(c->opts.dst_format)) { + if (isALPHA(c->opts.src_format) && isALPHA(c->opts.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(c->opts.src_format) && isALPHA(c->opts.dst_format)) { tmp_format = AV_PIX_FMT_BGRA; } else { tmp_format = AV_PIX_FMT_BGR24; @@ -1146,13 +1146,14 @@ 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, c->opts.src_format, tmp_width, tmp_height, tmp_format, - c->flags, c->param); + c->opts.flags, + c->opts.scaler_params); if (!c->cascaded_context[0]) return -1; - sws_internal(c->cascaded_context[0])->alphablend = c->alphablend; + sws_internal(c->cascaded_context[0])->opts.alpha_blend = c->opts.alpha_blend; ret = sws_init_context(c->cascaded_context[0], NULL , NULL); if (ret < 0) return ret; @@ -1162,12 +1163,13 @@ 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, c->opts.dst_format, + c->opts.flags, + c->opts.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; + sws_internal(c->cascaded_context[1])->opts.src_range = srcRange; + sws_internal(c->cascaded_context[1])->opts.dst_range = dstRange; ret = sws_init_context(c->cascaded_context[1], NULL , NULL); if (ret < 0) return ret; @@ -1182,7 +1184,7 @@ int sws_setColorspaceDetails(SwsContext *sws, const int inv_table[4], return 0; } - if (!isYUV(c->dstFormat) && !isGray(c->dstFormat)) { + if (!isYUV(c->opts.dst_format) && !isGray(c->opts.dst_format)) { ff_yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness, contrast, saturation); // FIXME factorize @@ -1214,8 +1216,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(c->opts.src_format) ? 1 : c->opts.src_range; + *dstRange = range_override_needed(c->opts.dst_format) ? 1 : c->opts.dst_range; *brightness = c->brightness; *contrast = c->contrast; *saturation = c->saturation; @@ -1227,11 +1229,8 @@ SwsContext *sws_alloc_context(void) { SwsInternal *c = av_mallocz(sizeof(SwsInternal)); - static_assert(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInternal, dither32), - "dither32 must be at the same offset as redDither + DITHER32_INT"); - if (c) { - c->av_class = &ff_sws_context_class; + c->opts.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); @@ -1323,10 +1322,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 = c->opts.src_w; + int srcH = c->opts.src_h; + int dstW = c->opts.dst_w; + int dstH = c->opts.dst_h; int dst_stride = FFALIGN(dstW * sizeof(int16_t) + 66, 16); int flags, cpu_flags; enum AVPixelFormat srcFormat, dstFormat; @@ -1337,25 +1336,25 @@ 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 = c->opts.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], c->opts.src_range, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], - c->dstRange, 0, 1 << 16, 1 << 16); + c->opts.dst_range, 0, 1 << 16, 1 << 16); handle_formats(c); - srcFormat = c->srcFormat; - dstFormat = c->dstFormat; + srcFormat = c->opts.src_format; + dstFormat = c->opts.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; + c->opts.alpha_blend = SWS_ALPHA_BLEND_NONE; if (!(unscaled && sws_isSupportedEndiannessConversion(srcFormat) && av_pix_fmt_swap_endianness(srcFormat) == dstFormat)) { @@ -1392,7 +1391,7 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter flags |= SWS_BICUBIC; else flags |= SWS_BICUBIC; - c->flags = flags; + c->opts.flags = flags; } else if (i & (i - 1)) { av_log(c, AV_LOG_ERROR, "Exactly one scaler algorithm must be chosen, got %X\n", i); @@ -1409,7 +1408,7 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter if (flags & SWS_FAST_BILINEAR) { if (srcW < 8 || dstW < 8) { flags ^= SWS_FAST_BILINEAR | SWS_BILINEAR; - c->flags = flags; + c->opts.flags = flags; } } @@ -1442,46 +1441,46 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter if (dstW&1) { av_log(c, AV_LOG_DEBUG, "Forcing full internal H chroma due to odd output size\n"); flags |= SWS_FULL_CHR_H_INT; - c->flags = flags; + c->opts.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) + && c->opts.dither != SWS_DITHER_BAYER //SWS_FULL_CHR_H_INT is currently not supported with SWS_DITHER_BAYER + && !(c->opts.flags & SWS_FAST_BILINEAR) ) { av_log(c, 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; + c->opts.flags = flags; } } - if (c->dither == SWS_DITHER_AUTO) { + if (c->opts.dither == SWS_DITHER_AUTO) { if (flags & SWS_ERROR_DIFFUSION) - c->dither = SWS_DITHER_ED; + c->opts.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 (c->opts.dither == SWS_DITHER_AUTO) + c->opts.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) { + if (c->opts.dither == SWS_DITHER_ED || c->opts.dither == SWS_DITHER_A_DITHER || c->opts.dither == SWS_DITHER_X_DITHER || c->opts.dither == SWS_DITHER_NONE) { av_log(c, 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; + c->opts.flags = flags; } } if (flags & SWS_FULL_CHR_H_INT) { - if (c->dither == SWS_DITHER_BAYER) { + if (c->opts.dither == SWS_DITHER_BAYER) { av_log(c, 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; + c->opts.dither = SWS_DITHER_ED; } } } @@ -1491,7 +1490,7 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter "%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; + c->opts.flags = flags; } } @@ -1523,7 +1522,7 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter "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; + c->opts.flags = flags; } if (isAnyRGB(dstFormat) && !(flags & SWS_FULL_CHR_H_INT)) c->chrDstHSubSample = 1; @@ -1585,7 +1584,7 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter av_log(c, 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(c->opts.src_format) || is16BPS(c->opts.src_format) || isAnyRGB(c->opts.src_format)) c->canMMXEXTBeUsed = 0; } else c->canMMXEXTBeUsed = 0; @@ -1617,7 +1616,7 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter tmpFmt = AV_PIX_FMT_RGBA64LE; - if (!unscaled && c->gamma_flag && (srcFormat != tmpFmt || dstFormat != tmpFmt)) { + if (!unscaled && c->opts.gamma_flag && (srcFormat != tmpFmt || dstFormat != tmpFmt)) { SwsInternal *c2; c->cascaded_context[0] = NULL; @@ -1628,14 +1627,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, + c->opts.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, + c->opts.scaler_params); if (!c->cascaded_context[1]) return AVERROR(ENOMEM); @@ -1665,8 +1666,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, + c->opts.scaler_params); if (!c->cascaded_context[2]) return AVERROR(ENOMEM); } @@ -1686,13 +1688,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, + c->opts.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, + c->opts.scaler_params); if (!c->cascaded_context[1]) return AVERROR(ENOMEM); return 0; @@ -1715,11 +1719,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 && c->opts.alpha_blend != SWS_ALPHA_BLEND_NONE) { if (!unscaled || dstFormat != tmpFormat || usesHFilter || usesVFilter || - c->srcRange != c->dstRange + c->opts.src_range != c->opts.dst_range ) { c->cascaded_mainindex = 1; ret = av_image_alloc(c->cascaded_tmp[0], c->cascaded_tmpStride[0], @@ -1729,22 +1733,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, c->opts.scaler_params); if (!c->cascaded_context[0]) return AVERROR(EINVAL); - sws_internal(c->cascaded_context[0])->alphablend = c->alphablend; + sws_internal(c->cascaded_context[0])->opts.alpha_blend = c->opts.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, c->opts.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; + sws_internal(c->cascaded_context[1])->opts.src_range = c->opts.src_range; + sws_internal(c->cascaded_context[1])->opts.dst_range = c->opts.dst_range; ret = sws_init_context(c->cascaded_context[1], srcFilter , dstFilter); if (ret < 0) return ret; @@ -1756,9 +1760,9 @@ 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 && + c->opts.alpha_blend != SWS_ALPHA_BLEND_NONE && isALPHA(srcFormat) && - (c->srcRange == c->dstRange || isAnyRGB(dstFormat)) && + (c->opts.src_range == c->opts.dst_range || isAnyRGB(dstFormat)) && alphaless_fmt(srcFormat) == dstFormat ) { c->convert_unscaled = ff_sws_alphablendaway; @@ -1772,7 +1776,7 @@ 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) || + (c->opts.src_range == c->opts.dst_range || isAnyRGB(dstFormat) || isFloat(srcFormat) || isFloat(dstFormat) || isBayer(srcFormat))){ ff_get_unscaled_swscale(c); @@ -1868,7 +1872,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, + c->opts.scaler_params, get_local_pos(c, 0, 0, 0), get_local_pos(c, 0, 0, 0))) < 0) goto fail; @@ -1879,9 +1883,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) + c->opts.scaler_params, + get_local_pos(c, c->chrSrcHSubSample, c->opts.src_h_chr_pos, 0), + get_local_pos(c, c->chrDstHSubSample, c->opts.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; @@ -1898,7 +1902,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, + c->opts.scaler_params, get_local_pos(c, 0, 0, 1), get_local_pos(c, 0, 0, 1))) < 0) goto fail; @@ -1907,18 +1911,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) + c->opts.scaler_params, + get_local_pos(c, c->chrSrcVSubSample, c->opts.src_v_chr_pos, 1), + get_local_pos(c, c->chrDstVSubSample, c->opts.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 * c->opts.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 * c->opts.dst_h; i++) { int j; short *p = (short *)&c->vYCoeffsBank[i]; for (j = 0; j < 8; j++) @@ -1935,10 +1939,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], c->opts.dst_w + 3)) goto nomem; - c->needAlpha = (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat) && isALPHA(c->dstFormat)) ? 1 : 0; + c->needAlpha = (CONFIG_SWSCALE_ALPHA && isALPHA(c->opts.src_format) && isALPHA(c->opts.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); @@ -1980,7 +1984,7 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter av_log(c, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH); av_log(c, 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); + c->opts.src_w, c->opts.src_h, c->opts.dst_w, c->opts.dst_h, c->lumXInc, c->lumYInc); av_log(c, 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, @@ -2011,13 +2015,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, + c->opts.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, + c->opts.scaler_params); if (!c->cascaded_context[1]) return AVERROR(ENOMEM); return 0; @@ -2032,21 +2038,21 @@ 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, c->opts.threads); if (ret == AVERROR(ENOSYS)) { - c->nb_threads = 1; + c->opts.threads = 1; return 0; } else if (ret < 0) return ret; - c->nb_threads = ret; + c->opts.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(c->opts.threads, sizeof(*c->slice_ctx)); + c->slice_err = av_calloc(c->opts.threads, sizeof(*c->slice_err)); if (!c->slice_ctx || !c->slice_err) return AVERROR(ENOMEM); - for (int i = 0; i < c->nb_threads; i++) { + for (int i = 0; i < c->opts.threads; i++) { SwsInternal *c2; c->slice_ctx[i] = sws_alloc_context(); if (!c->slice_ctx[i]) @@ -2060,13 +2066,13 @@ static int context_init_threaded(SwsContext *sws, if (ret < 0) return ret; - c2->nb_threads = 1; + c2->opts.threads = 1; ret = sws_init_single_context(c->slice_ctx[i], src_filter, dst_filter); if (ret < 0) return ret; - if (c2->dither == SWS_DITHER_ED) { + if (c2->opts.dither == SWS_DITHER_ED) { av_log(c, AV_LOG_VERBOSE, "Error-diffusion dither is in use, scaling will be single-threaded."); break; @@ -2092,17 +2098,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 = c->opts.src_format; + dst_format = c->opts.dst_format; + c->opts.src_range |= handle_jpeg(&c->opts.src_format); + c->opts.dst_range |= handle_jpeg(&c->opts.dst_format); - if (src_format != c->srcFormat || dst_format != c->dstFormat) + if (src_format != c->opts.src_format || dst_format != c->opts.dst_format) av_log(c, AV_LOG_WARNING, "deprecated pixel format used, make sure you did set range correctly\n"); - if (c->nb_threads != 1) { + if (c->opts.threads != 1) { ret = context_init_threaded(sws, srcFilter, dstFilter); - if (ret < 0 || c->nb_threads > 1) + if (ret < 0 || c->opts.threads > 1) return ret; // threading disabled in this build, init as single-threaded } @@ -2546,15 +2552,15 @@ SwsContext *sws_getCachedContext(SwsContext *sws, int srcW, 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])) { + (context->opts.src_w != srcW || + context->opts.src_h != srcH || + context->opts.src_format != srcFormat || + context->opts.dst_w != dstW || + context->opts.dst_h != dstH || + context->opts.dst_format != dstFormat || + context->opts.flags != flags || + context->opts.scaler_params[0] != param[0] || + context->opts.scaler_params[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); @@ -2568,15 +2574,15 @@ SwsContext *sws_getCachedContext(SwsContext *sws, int srcW, 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]; + context->opts.src_w = srcW; + context->opts.src_h = srcH; + context->opts.src_format = srcFormat; + context->opts.dst_w = dstW; + context->opts.dst_h = dstH; + context->opts.dst_format = dstFormat; + context->opts.flags = flags; + context->opts.scaler_params[0] = param[0]; + context->opts.scaler_params[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); diff --git a/libswscale/vscale.c b/libswscale/vscale.c index 9b700ec58e..e972bd70e2 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->opts.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); @@ -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->opts.dst_format) || (isGray(c->opts.dst_format) && !isALPHA(c->opts.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->opts.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->opts.dst_format) || (isGray(c->opts.dst_format) && !isALPHA(c->opts.dst_format))) { + if (!isGray(c->opts.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..dec1d27f9a 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 40316 ; 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 16182124c0..a7a5315ed5 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->opts.dst_h; + const int flags= c->opts.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->opts.dst_format == AV_PIX_FMT_RGB555 || c->opts.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->opts.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->opts.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->opts.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->opts.src_range != c->opts.dst_range && !isAnyRGB(c->opts.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->opts.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->opts.src_format==AV_PIX_FMT_PAL8||isAnyRGB(c->opts.src_format)) && av_pix_fmt_desc_get(c->opts.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->opts.dst_format) && !isSemiPlanarYUV(c->opts.dst_format)) vscalefn = ff_yuv2planeX_10_ ## opt; break; \ + case 9: if (!isBE(c->opts.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->opts.dst_format)) vscalefn = ff_yuv2plane1_16_ ## opt; break; \ + case 10: if (!isBE(c->opts.dst_format) && !isSemiPlanarYUV(c->opts.dst_format)) vscalefn = ff_yuv2plane1_10_ ## opt; break; \ + case 9: if (!isBE(c->opts.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->opts.flags & SWS_ACCURATE_RND)) ASSIGN_VSCALE_FUNC(c->yuv2plane1, sse2); - switch (c->srcFormat) { + switch (c->opts.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->opts.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->opts.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->opts.dst_format) && !(c->opts.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->opts.flags & SWS_ACCURATE_RND)) ASSIGN_VSCALE_FUNC(c->yuv2plane1, avx); - switch (c->srcFormat) { + switch (c->opts.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->opts.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->opts.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->opts.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->opts.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,18 +783,14 @@ switch(c->dstBpc){ \ } if (EXTERNAL_AVX2_FAST(cpu_flags)) { - switch (c->srcFormat) { + switch (c->opts.src_format) { INPUT_PLANER_RGB_YUVA_ALL_CASES(avx2) default: break; } } - 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); + if(c->opts.flags & SWS_FULL_CHR_H_INT) { #define YUV2ANYX_FUNC_CASE(fmt, name, opt) \ case fmt: \ @@ -826,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->opts.dst_format) { YUV2ANYX_GBRAP_CASES(sse2) default: break; @@ -834,7 +830,7 @@ switch(c->dstBpc){ \ } if (EXTERNAL_SSE4(cpu_flags)) { - switch (c->dstFormat) { + switch (c->opts.dst_format) { YUV2ANYX_GBRAP_CASES(sse4) default: break; @@ -842,7 +838,7 @@ switch(c->dstBpc){ \ } if (EXTERNAL_AVX2_FAST(cpu_flags)) { - switch (c->dstFormat) { + switch (c->opts.dst_format) { YUV2ANYX_GBRAP_CASES(avx2) default: break; diff --git a/libswscale/x86/swscale_template.c b/libswscale/x86/swscale_template.c index cffafccb24..e09310ab91 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->opts.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->opts.flags & SWS_BITEXACT)) { + if (c->opts.flags & SWS_ACCURATE_RND) { + if (!(c->opts.flags & SWS_FULL_CHR_H_INT)) { + switch (c->opts.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->opts.flags & SWS_FULL_CHR_H_INT)) { + switch (c->opts.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->opts.flags & SWS_FULL_CHR_H_INT)) { + switch (c->opts.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->opts.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..a1463867a2 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->opts.dst_w + 7) & ~7; \ if (h_size * depth > FFABS(dstStride[0])) \ h_size -= 8; \ \ - vshift = c->srcFormat != AV_PIX_FMT_YUV422P; \ + vshift = c->opts.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->opts.dst_w + 7) & ~7; if (h_size * 3 > FFABS(dstStride[0])) h_size -= 8; - vshift = c->srcFormat != AV_PIX_FMT_YUV422P; + vshift = c->opts.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->opts.dst_format) { case AV_PIX_FMT_RGB32: - if (c->srcFormat == AV_PIX_FMT_YUVA420P) { + if (c->opts.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->opts.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..ff8e013da4 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->opts.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->opts.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->opts.dst_w & 7) { int av_unused Y, U, V; - int pixels_left = c->dstW & 7; + int pixels_left = c->opts.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]; @@ -575,10 +575,10 @@ SwsFunc ff_yuv2rgb_get_func_ptr(SwsInternal *c) av_log(c, 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->opts.src_format), av_get_pix_fmt_name(c->opts.dst_format)); - if (c->srcFormat == AV_PIX_FMT_YUV422P) { - switch (c->dstFormat) { + if (c->opts.src_format == AV_PIX_FMT_YUV422P) { + switch (c->opts.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->opts.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->opts.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->opts.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->opts.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->opts.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->opts.dst_format == AV_PIX_FMT_RGB32 || + c->opts.dst_format == AV_PIX_FMT_RGB32_1 || + c->opts.dst_format == AV_PIX_FMT_BGR24 || + c->opts.dst_format == AV_PIX_FMT_RGB565BE || + c->opts.dst_format == AV_PIX_FMT_RGB565LE || + c->opts.dst_format == AV_PIX_FMT_RGB555BE || + c->opts.dst_format == AV_PIX_FMT_RGB555LE || + c->opts.dst_format == AV_PIX_FMT_RGB444BE || + c->opts.dst_format == AV_PIX_FMT_RGB444LE || + c->opts.dst_format == AV_PIX_FMT_X2RGB10BE || + c->opts.dst_format == AV_PIX_FMT_X2RGB10LE || + c->opts.dst_format == AV_PIX_FMT_RGB8 || + c->opts.dst_format == AV_PIX_FMT_RGB4 || + c->opts.dst_format == AV_PIX_FMT_RGB4_BYTE || + c->opts.dst_format == AV_PIX_FMT_MONOBLACK; + const int isNotNe = c->opts.dst_format == AV_PIX_FMT_NE(RGB565LE, RGB565BE) || + c->opts.dst_format == AV_PIX_FMT_NE(RGB555LE, RGB555BE) || + c->opts.dst_format == AV_PIX_FMT_NE(RGB444LE, RGB444BE) || + c->opts.dst_format == AV_PIX_FMT_NE(BGR565LE, BGR565BE) || + c->opts.dst_format == AV_PIX_FMT_NE(BGR555LE, BGR555BE) || + c->opts.dst_format == AV_PIX_FMT_NE(BGR444LE, BGR444BE) || + c->opts.dst_format == AV_PIX_FMT_NE(X2RGB10LE, X2RGB10BE) || + c->opts.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->opts.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->opts.dst_format == AV_PIX_FMT_RGB32_1 || + c->opts.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->opts.src_format); if (!needAlpha) abase = (base + 24) & 31; ALLOC_YUV_TABLE(table_plane_size * 3 * 4); @@ -953,7 +953,7 @@ 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) + if(!isPlanar(c->opts.dst_format) || bpp <= 24) av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp); return AVERROR(EINVAL); } diff --git a/tests/checkasm/sw_gbrp.c b/tests/checkasm/sw_gbrp.c index 039be8006b..79b2e0e82e 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; + c->opts.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]; + c->opts.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; + c->opts.src_format = planar_fmts[fmi]; + c->opts.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; + c->opts.src_format = planar_fmts[fmi]; + c->opts.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; + c->opts.src_format = planar_fmts[fmi]; + c->opts.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..4a2cca2225 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; + c->opts.src_format = from ? AV_PIX_FMT_YUVJ444P : AV_PIX_FMT_YUV444P; + c->opts.dst_format = from ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P; + c->opts.src_range = from; + c->opts.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; + c->opts.src_format = from ? AV_PIX_FMT_YUVJ444P : AV_PIX_FMT_YUV444P; + c->opts.dst_format = from ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P; + c->opts.src_range = from; + c->opts.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 02bb76b742..dd82dd356a 100644 --- a/tests/checkasm/sw_rgb.c +++ b/tests/checkasm/sw_rgb.c @@ -370,7 +370,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]; + ctx->opts.src_format = rgb_formats[i]; ff_sws_init_scale(ctx); for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) { @@ -389,7 +389,7 @@ 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)) + (ctx->opts.src_format == AV_PIX_FMT_RGB32 || ctx->opts.src_format == AV_PIX_FMT_RGB32_1)) bench_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL); } } @@ -417,8 +417,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; + ctx->opts.src_format = src_fmt; + ctx->opts.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 +441,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)) + (ctx->opts.src_format == AV_PIX_FMT_RGB32 || ctx->opts.src_format == AV_PIX_FMT_RGB32_1)) bench_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL); } } diff --git a/tests/checkasm/sw_scale.c b/tests/checkasm/sw_scale.c index b383fa0930..8951ddce43 100644 --- a/tests/checkasm/sw_scale.c +++ b/tests/checkasm/sw_scale.c @@ -126,7 +126,7 @@ static void check_yuv2yuv1(int accurate) sws = sws_alloc_context(); c = sws_internal(sws); if (accurate) - c->flags |= SWS_ACCURATE_RND; + c->opts.flags |= SWS_ACCURATE_RND; if (sws_init_context(sws, NULL, NULL) < 0) fail(); @@ -194,7 +194,7 @@ static void check_yuv2yuvX(int accurate) sws = sws_alloc_context(); c = sws_internal(sws); if (accurate) - c->flags |= SWS_ACCURATE_RND; + c->opts.flags |= SWS_ACCURATE_RND; if (sws_init_context(sws, NULL, NULL) < 0) fail(); @@ -344,20 +344,20 @@ static void check_hscale(void) filter[SRC_PIXELS * width + i] = rnd(); } - c->dstW = c->chrDstW = input_sizes[dstWi]; + c->opts.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, c->opts.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, c->opts.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, c->opts.dst_w, src, filter, filterPos, width); + call_new(NULL, dst1, c->opts.dst_w, src, filterAvx2, filterPosAvx, width); + if (memcmp(dst0, dst1, c->opts.dst_w * sizeof(dst0[0]))) fail(); - bench_new(NULL, dst0, c->dstW, src, filter, filterPosAvx, width); + bench_new(NULL, dst0, c->opts.dst_w, src, filter, filterPosAvx, width); } } } From patchwork Thu Oct 10 22:26:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52209 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp213912vqn; Thu, 10 Oct 2024 16:23:29 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU0D3StfPsnb6NsyFdEX5D/vjVJFGaNl+GILD+/IQlMVHJXNYffTk1l96JwLJF+evPgzIIAJOBZNE/IiRNapkVI@gmail.com X-Google-Smtp-Source: AGHT+IFs6nE6gwgscTyP55HOtiUUQRDz+B6W8vYbwYxiZXWXaOjLijIWS12IM2R/lQ7kNIKqu94a X-Received: by 2002:a17:907:f1cd:b0:a99:9ff2:a85e with SMTP id a640c23a62f3a-a99b941b4a3mr44767766b.39.1728602609135; Thu, 10 Oct 2024 16:23:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728602609; cv=none; d=google.com; s=arc-20240605; b=gI/QkucH9wnHqhffwPPEs8Qj/NAQlTsrIYsTteCweQyxJg05REXumyA8JMn3NoZHwQ GnFpLFeeHqDU+us7swne9JZFDoTaB1s7XKTWwR6h1mBLmK95IU6em6S2ktfMNrNrUPKA /+LlVOx9go1UvkUAT/KaiI4wkYjeJe43KJMyrrFyAPSnFfWYrDk2q1wtAJGjdFPVJEXa A6+6fAW5rwd3RGNQBiLDu6/yma9H7V6rUZnqOnfqzvWPEEkHdOsZEx3RLi10jQK/FS/t g8SErYsYEauebUf40FasUY8SItqRU5tnvH1Ja1ccTYHmaCbrf21y3+gw2kXlzl83eSMM t36g== 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=/Z6nq/MqhZYqH10k9LXW4vTdyWpPHIO+yTwaFiGRS8c=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=iNehp7H1BbbGu1aWuaKNzZNODt2OxaHAz064xx+omhwSBm0XtbapmZ3cg+iNen85EA i+LhKdYZipubn8OcRlLOM9iBnHqvDWCg0YSIVezi+ZgdAZFpgM77xoXIKgEPYSCeg8t9 uQRTr5NMZLmyhENyQQfTyAShJMMHT2l/1PWjeTGESqW7muUwscRH05+eM/HSqmYrGLSt JWjtGHnxfXi1gp184wG2XPWBCqXnM+ZAH7dc2hdZSBALhkaodQP8dsiDAWHJlWHA3zaj mCzoPgZfsV1uLOG769Uiv4Dfzj7mUdnnP75zLIu8WU122+0duWlm2K6LN5VUgJr65x4p 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="Ir/3MoHM"; 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-a99a80d3159si161116266b.398.2024.10.10.16.23.28; Thu, 10 Oct 2024 16:23:29 -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="Ir/3MoHM"; 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 8CB6468DF55; Fri, 11 Oct 2024 01:28:24 +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 56DAB68DF05 for ; Fri, 11 Oct 2024 01:28:02 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599279; bh=bG5c67iVAUQ+d9Ava1prZiyzoozxgfoweaNbXg+4n4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ir/3MoHMTa2Sw+Y4PJRVUkneavbAxUpzSD596Zmd79kshyEuZwSmt83z6RJ980xvy Vd+1zyymE2ftjcEcQsJnPoXxz8BDxrfhwLzRnQ+fj8lSNtiXx8EGRUtWlKPEQImchO ijlP6sWwi/O2UhCd2jO9BUd5BjVxe00HeGvvK+zs= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 4D89E44644; Fri, 11 Oct 2024 00:27:59 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:26:59 +0200 Message-ID: <20241010222750.582921-13-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/19] 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: p5RIU+v1o5oJ From: Niklas Haas Following in the footsteps of the work in the previous commit, it's now relatively straightforward to expose the options struct publicly as SwsContext. This is a step towards making this more user friendly, as well as following API conventions established elsewhere. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/options.c | 3 +- libswscale/swscale.c | 2 +- libswscale/swscale.h | 102 +++++++++++++++++++-- libswscale/swscale_internal.h | 49 ++-------- libswscale/utils.c | 165 +++++++++++++++++----------------- libswscale/x86/output.asm | 2 +- tests/checkasm/sw_scale.c | 8 +- 7 files changed, 187 insertions(+), 144 deletions(-) diff --git a/libswscale/options.c b/libswscale/options.c index 6248e5f4b5..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, opts.x) +#define OFFSET(x) offsetof(SwsContext, x) #define DEFAULT 0 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM @@ -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 = offsetof(SwsInternal, parent), .category = AV_CLASS_CATEGORY_SWSCALER, .version = LIBAVUTIL_VERSION_INT, }; diff --git a/libswscale/swscale.c b/libswscale/swscale.c index ea4c7b00d1..d5be07193d 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -1252,7 +1252,7 @@ int attribute_align_arg sws_scale(SwsContext *sws, 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); diff --git a/libswscale/swscale.h b/libswscale/swscale.h index d7ea9bd714..f3ee93984b 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_*. + */ + int64_t 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); @@ -254,7 +338,9 @@ int sws_isSupportedOutput(enum AVPixelFormat pix_fmt); int sws_isSupportedEndiannessConversion(enum AVPixelFormat pix_fmt); /** - * Initialize the swscaler context sws_context. + * Initialize the swscaler context sws_context. This function fixes the + * values of any options set in the SwsContext; further adjustments will + * not affect the scaling process. * * @return zero or positive value on success, a negative value on * error diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index c1cd547ec4..470a9636bb 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,32 +312,10 @@ struct SwsFilterDescriptor; /* This struct should be aligned on at least a 32-byte boundary. */ struct SwsInternal { - /* Currently active user-facing options. */ - struct { - const AVClass *av_class; - - double scaler_params[2]; ///< Input parameters for scaling algorithms that need them. - int flags; ///< Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc... - int threads; ///< Number of threads used for scaling - - int src_w; ///< Width of source luma/alpha planes. - int src_h; ///< Height of source luma/alpha planes. - int dst_w; ///< Width of destination luma/alpha planes. - int dst_h; ///< Height of destination luma/alpha planes. - enum AVPixelFormat src_format; ///< Source pixel format. - enum AVPixelFormat dst_format; ///< Destination pixel format. - int src_range; ///< 0 = MPG YUV range, 1 = JPG YUV range (source image). - int dst_range; ///< 0 = MPG YUV range, 1 = JPG YUV range (destination image). - int src_h_chr_pos; - int dst_h_chr_pos; - int src_v_chr_pos; - int dst_v_chr_pos; - int gamma_flag; - - SwsDither dither; - SwsAlphaBlend alpha_blend; - } opts; + /* Shallow copy of the main scaler context, contains currently active options */ + SwsContext opts; + /* Parent context (for cascaded/sliced contexts) */ SwsContext *parent; AVSliceThread *slicethread; @@ -712,7 +673,7 @@ static_assert(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInt /* 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) == 40316, +static_assert(offsetof(SwsInternal, yuv2rgb_y_offset) == 40332, "yuv2rgb_y_offset must be updated in x86 asm"); SwsFunc ff_yuv2rgb_get_func_ptr(SwsInternal *c); diff --git a/libswscale/utils.c b/libswscale/utils.c index db996f24c5..d01ab0efc0 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -284,22 +284,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->opts.flags = flags; - c->opts.src_w = srcW; - c->opts.src_h = srcH; - c->opts.dst_w = dstW; - c->opts.dst_h = dstH; - c->opts.src_format = srcFormat; - c->opts.dst_format = 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->opts.scaler_params[0] = param[0]; - c->opts.scaler_params[1] = param[1]; + sws->scaler_params[0] = param[0]; + sws->scaler_params[1] = param[1]; } return sws; @@ -1080,11 +1078,11 @@ int sws_setColorspaceDetails(SwsContext *sws, const int inv_table[4], - c->brightness = brightness; - c->contrast = contrast; - c->saturation = saturation; - c->opts.src_range = srcRange; - c->opts.dst_range = dstRange; + c->brightness = brightness; + c->contrast = contrast; + c->saturation = saturation; + c->opts.src_range = srcRange; + c->opts.dst_range = dstRange; if (need_reinit) { ff_sws_init_range_convert(c); @@ -1153,7 +1151,7 @@ int sws_setColorspaceDetails(SwsContext *sws, const int inv_table[4], if (!c->cascaded_context[0]) return -1; - sws_internal(c->cascaded_context[0])->opts.alpha_blend = c->opts.alpha_blend; + c->cascaded_context[0]->alpha_blend = c->opts.alpha_blend; ret = sws_init_context(c->cascaded_context[0], NULL , NULL); if (ret < 0) return ret; @@ -1168,8 +1166,8 @@ int sws_setColorspaceDetails(SwsContext *sws, const int inv_table[4], c->opts.scaler_params); if (!c->cascaded_context[1]) return -1; - sws_internal(c->cascaded_context[1])->opts.src_range = srcRange; - sws_internal(c->cascaded_context[1])->opts.dst_range = 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; @@ -1227,16 +1225,23 @@ 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; - if (c) { - c->opts.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; } - return (SwsContext *) c; + sws->av_class = &ff_sws_context_class; + av_opt_set_defaults(sws); + atomic_init(&c->stride_unaligned_warned, 0); + atomic_init(&c->data_unaligned_warned, 0); + + return sws; } static uint16_t * alloc_gamma_tbl(double e) @@ -1314,6 +1319,7 @@ static enum AVPixelFormat alphaless_fmt(enum AVPixelFormat fmt) } } +/* Assumes c->opts is already initialized */ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter, SwsFilter *dstFilter) { @@ -1736,7 +1742,7 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter flags, c->opts.scaler_params); if (!c->cascaded_context[0]) return AVERROR(EINVAL); - sws_internal(c->cascaded_context[0])->opts.alpha_blend = c->opts.alpha_blend; + c->cascaded_context[0]->alpha_blend = c->opts.alpha_blend; ret = sws_init_context(c->cascaded_context[0], NULL , NULL); if (ret < 0) return ret; @@ -1747,8 +1753,8 @@ static av_cold int sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter if (!c->cascaded_context[1]) return AVERROR(EINVAL); - sws_internal(c->cascaded_context[1])->opts.src_range = c->opts.src_range; - sws_internal(c->cascaded_context[1])->opts.dst_range = c->opts.dst_range; + c->cascaded_context[1]->src_range = c->opts.src_range; + c->cascaded_context[1]->dst_range = c->opts.dst_range; ret = sws_init_context(c->cascaded_context[1], srcFilter , dstFilter); if (ret < 0) return ret; @@ -2057,15 +2063,11 @@ static int context_init_threaded(SwsContext *sws, 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++; - c2->parent = sws; - - ret = av_opt_copy((void*)c->slice_ctx[i], (void*)c); - if (ret < 0) - return ret; + c2 = sws_internal(c->slice_ctx[i]); + c2->parent = sws; + c2->opts = c->opts; /* copy initialized opts directly */ c2->opts.threads = 1; ret = sws_init_single_context(c->slice_ctx[i], src_filter, dst_filter); @@ -2090,6 +2092,11 @@ av_cold int sws_init_context(SwsContext *sws, SwsFilter *srcFilter, enum AVPixelFormat src_format, dst_format; int ret; + /* Apply options from main context. Note that this also copies the + * AVClass, for logging */ + c->opts = *sws; + c->opts.internal = NULL; /* sanity */ + c->frame_src = av_frame_alloc(); c->frame_dst = av_frame_alloc(); if (!c->frame_src || !c->frame_dst) @@ -2520,6 +2527,7 @@ void sws_freeContext(SwsContext *sws) ff_free_filters(c); + av_free(c); av_free(sws); } @@ -2533,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, @@ -2541,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->opts.src_w != srcW || - context->opts.src_h != srcH || - context->opts.src_format != srcFormat || - context->opts.dst_w != dstW || - context->opts.dst_h != dstH || - context->opts.dst_format != dstFormat || - context->opts.flags != flags || - context->opts.scaler_params[0] != param[0] || - context->opts.scaler_params[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->opts.src_w = srcW; - context->opts.src_h = srcH; - context->opts.src_format = srcFormat; - context->opts.dst_w = dstW; - context->opts.dst_h = dstH; - context->opts.dst_format = dstFormat; - context->opts.flags = flags; - context->opts.scaler_params[0] = param[0]; - context->opts.scaler_params[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/x86/output.asm b/libswscale/x86/output.asm index dec1d27f9a..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 40316 ; 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/tests/checkasm/sw_scale.c b/tests/checkasm/sw_scale.c index 8951ddce43..119bff96d9 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->opts.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->opts.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]; From patchwork Thu Oct 10 22:27:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52202 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp196500vqn; Thu, 10 Oct 2024 15:38:29 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXIoWQQKS4vj/Dwkt4kETZBShDj1zjE7Jdd8aD13yzgKdGM5re3qQruqPqVu/5lJrldyfsocQlkM3+zgGCVJV9X@gmail.com X-Google-Smtp-Source: AGHT+IEi+n5cCkUgLAppxUvonqwdfE2yiVd6+ESKobmfMQjE15WmfuuTEJekHGgH2oPKfwxqESDW X-Received: by 2002:a17:907:f7aa:b0:a99:4eeb:5700 with SMTP id a640c23a62f3a-a99b96b0c00mr37330666b.51.1728599908860; Thu, 10 Oct 2024 15:38:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728599908; cv=none; d=google.com; s=arc-20240605; b=CEF2wl5wUZf50kDW0feL0CJKckshp5jUHnvYnTIgU5EXeti69e6jSpxq2nmtZ16ewl dK6+Xq2MfYnzUSXu34QQsD4s6sCvdamKh/NYhYqC5YQOLZR2bzbkMchehRicZsDninxA kitAuLad4e2aXFk8g7KcSVsFhTe1EES6QSIcn+3nypTgBW2VSWcSPmsvW/tLAKAiyHl+ +3hyfwg1FHOLxGbPJqBKl1O31j2X354o1SepwN5CT7Eq4/liCu9mzyz+8fTElwTc0x5O faGX9bzYMAOr6Yg3jH1ptQLVv3shiJOJIXd5H8V7IETL4Z1jWfCUfgBFjHnhV9Eov9n0 hnJg== 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=dV9RWJYV2v9JZjLqcd/R13qUxDc9aQshEteCNeteZ18=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=jTlfsI5Cv+ynvaXYWmV6dBw2G7e0hVPgANSF9VyQnph4Ec9zqLZkywnEDbrahffG3C UDk3uTbV97iZ4CwIfVf2K5l0IpIAD9xTYzICzcpc6VZMhsewhbQ8fpso0wwKBM/OYR7W 1rpcH/mK6SiUtCWDF/U95HwB1xvpXcikQNEyrwbB0ZMuykgusN2nCKAetB04Jo3VdGxU FdGmCxt287+SFqoNY3jeTTMfu92fnndHeLKSG22/DLpxERlDmmAoVWzik1TwFeZJcYcd jYWtQDVrJlbDM8uSdBRAv+KVcePQ9VOiXUh3+LllCPqYPG26HdLwFTrNDyOHheeQQcQG QCgw==; 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="SKXtt4/6"; 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-a99a80d5988si156806066b.463.2024.10.10.15.38.28; Thu, 10 Oct 2024 15:38:28 -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="SKXtt4/6"; 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 58E5B68DF13; Fri, 11 Oct 2024 01:28: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 90CBC68DDBF for ; Fri, 11 Oct 2024 01:28:02 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599279; bh=6zJ1YFKWOe9bOMDkUX/Q1owXiUCZ1CCPyfwoY0c19aU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SKXtt4/6nsqDG2UmTg7gbiWeI02M9BgzAsENFStHbr2btdeYR7XotZaSSkLS9TMcM g/1dBakdyl2NTRt947qMRPA8wokIiGKOl1T2ttm9RgMy21x2eteS9Wz9r0lm91Lb1U NMZ52Lipcqc0Ya/d89am1CoHijgT7e0CN94c9gmg= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 8EF454679C; Fri, 11 Oct 2024 00:27:59 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:27:00 +0200 Message-ID: <20241010222750.582921-14-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/19] 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: eq48bLy30zfi 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 f3ee93984b..a98285685b 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, ///< log scaling parameters + + /** + * 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. */ int64_t flags; @@ -229,60 +294,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 Thu Oct 10 22:27:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52198 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp193074vqn; Thu, 10 Oct 2024 15:29:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVcVIb7Ze05L3zXK9cw262ATPa7Woh4KLBhaQSY6WvHsPII98iRHWfc3LX2kqQ7djmBBkqr6FrLXdghpQMWHR+y@gmail.com X-Google-Smtp-Source: AGHT+IGArG3/CpfE8mRjvtbAS1zDpn90FPgLTwGSpSgd8QKArEzAQmoU8KpELJFlGpOJ4079+TXh X-Received: by 2002:a17:906:730f:b0:a86:9d39:a2a with SMTP id a640c23a62f3a-a99b9307063mr37286266b.8.1728599346487; Thu, 10 Oct 2024 15:29:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728599346; cv=none; d=google.com; s=arc-20240605; b=WLMGmDYN2ibxMC4OcoUGzBjRaGWL1bnZPT/FL3E1YwdFCe4sq73l2igOeY84AvGElr M6TRgQquiIFatKgi6tBm0CWaM+0YyGs41KRWS0PapztPxtHR5Q8Dig5BnRdVeqQS7gfj Fs7hzEzecanthrozwSE87nF2tiXFm6h5f41K60sQku30+h4Edo4+EbtM2KxNAebYWOAq cOLej3WD5O8lJdT7tyh2tJLTeNN9nK3GBxRALpAG8vuq2QjEAG0xzGmHSE7CunyAThpO zdh+9sBB6/oSmqztNY0+Z7uMMM7bx5OTQ14NYawrP8vbmRXlPnio3bEQm2+j4vReRHNI /A/Q== 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=cWd9Lmm6a8ewtg2gFOXxa0ViFMnI86nJeFIUggRTQRs=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=Pxhw84BFfExP7xJeXPtOYUhT1o0bDr/2bWiaai15SvCho/+EPMQsbe76GtarRVh3mZ Fz17CFqlPrIcQXA2keh0gJuWq6u/R2Akk24Oy2R215sybrD7ePv0X/ITJwHXj8ZRHieg pO2YMNEgMi7T4dL0SKl4SyeAMF7E+EjA63eCfISLwKFhBzxEs26r4hwD8m1JgeGNGHxV lpW54Xwtod6HXBsc4Dx12TGRGFhQS6+drVs71IsQsKF9C/NDaJK57mGZJQyH+wTf6ire X/qnlAzQdSGtxHxk6Q7nFn9nCKs023PzcXxZz9CnOni5UA/R8ud8nCNr6SzWxVDeErqv oLQQ==; 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=EPDNGHsV; 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-a99a80e9cd0si147109266b.653.2024.10.10.15.29.06; Thu, 10 Oct 2024 15:29: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=EPDNGHsV; 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 4EE1568DDBF; Fri, 11 Oct 2024 01:28: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 9EF0468DED7 for ; Fri, 11 Oct 2024 01:28:02 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599279; bh=u0LoxBQL04Mdi28fog+QJPXvhOdEo+SMKemVN7rxJMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EPDNGHsVhLfQQZDOTyhj5llsO2RGCMy1dTlu295h8XQNGARsNlhzueB57Kd62ifhp D1fpm/0NhAWYwsdK5d9Uh81aICHH0h2LzDRAozsUC87ijNjdCa7EX0YqE00J5kwNEA hFMj17XQkDhfVnlBw6GFJezjlp9ucpCgCajZntgY= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id C894F46CA8; Fri, 11 Oct 2024 00:27:59 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:27:01 +0200 Message-ID: <20241010222750.582921-15-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/19] 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: Xobqw46AvMMQ 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 | 4 ++++ libswscale/utils.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index 470a9636bb..21d8113e5a 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -955,6 +955,10 @@ extern const int32_t ff_yuv2rgb_coeffs[11][4]; extern const AVClass ff_sws_context_class; +/* Assumes c->opts is already initialized */ +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 d01ab0efc0..04d3f99970 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -1320,8 +1320,8 @@ static enum AVPixelFormat alphaless_fmt(enum AVPixelFormat fmt) } /* Assumes c->opts is already initialized */ -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 Thu Oct 10 22:27:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52208 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp213885vqn; Thu, 10 Oct 2024 16:23:25 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXdoxLLZyKBlS8XkJTS4NOB0HpUTvjXfO51FLb0Uk+bPc40Ggs5vAffevoPiEBj9YAKenzrNsMCKZzuqspp2uhp@gmail.com X-Google-Smtp-Source: AGHT+IG6VrnQtObma3L1CbtGiuMG6IiI65n9r6ShkdXYT/KJv6O3hkVKwcGzA7r+NQuQXHTh4Trv X-Received: by 2002:a17:906:d7df:b0:a99:8edf:a367 with SMTP id a640c23a62f3a-a99b95a7629mr43855766b.57.1728602604807; Thu, 10 Oct 2024 16:23:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728602604; cv=none; d=google.com; s=arc-20240605; b=hPBCyAuhkmrRk4Dv6rAzT5cXIrHoS5snhlxxQI2gh63BAlgzFZDQHZscSEBTRzndrj +NwWYR14Q7G9JMgNU8Hm3g/WToAqqNKgOOxzGuh6iEjFq0u40jFBTXUenGzeQmW0o3Tt ZvI28L1lJEPm+ibmL7jFfcWNVMmJiNLdsZBCd/MiVZcptCg3l/3nfFM4amaSdWr+21Uq ++lFdtXHy0zl3FK5qKH92T939D1tMp7UvdepcWb4aB6OtC1TZqj1tacRLowDAVAUr7oA nk+D9TvbNyIEs8QQHD4lHfRBMxbHh5pN2zL5X8ZoffuBrWraRBJi6Acn3KuLJ8vKDvN2 PSAw== 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=NIxFTJSQVekDYeBXtn69KYb8vQbUFXWX+iean5uHJ1Y=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=NM400suACr93fZ/F7VlAdsfX1S7M3c2skXV6tXjSoASdsaXV+S/tumg8JVXXVJMoQs 0f8Mf2Epe9mnk4lY+lark3QYkYIK6+KVP3UdsD/04CrhNf40Yqispce+1qxdtfR4atjM rBVLzkOP64MbNNJtyw4UfwgEpzgqjyRIZjunMTdyt7FCsL5QnpWXJJo0xo9NgpHWG/XW vjUctKsw9QYJVoNYMeAkspSNAo2z5X0QmILiTw4rKn8R4i9wFHXF47kkAfQGyCKCN6JT EHBBq4C1xujSTtFlnEAfj8uH/frAjX4JBNek3sWTkIs/DcZCnpVM2PPTw/hWpLiYVV0w gN7w==; 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=mHGJ7hug; 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-a99a80d48c5si160121966b.384.2024.10.10.16.23.24; Thu, 10 Oct 2024 16:23:24 -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=mHGJ7hug; 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 6648768DF07; Fri, 11 Oct 2024 01:28: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 B372F68DDBF for ; Fri, 11 Oct 2024 01:28:02 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599280; bh=qa4M6FH6QH7lfZgn4mfl0NOcrocZs6S7Z8uXM+BRCpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mHGJ7hugBKgUyK5fjmngm6qLw4VKHECrSk5kZzop51KLDMXvTM5EKH9UO51hHGCDh z+DPFHYuPpg7LKe2zbFgGHGfxzkywBB+hgy1cXjEchlKj7zndVS5rWC4+BVkkEHPah aF8+kkTbEDMOVCTwmpnKDNNuxGBoFrFz+JV3pz0Y= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 1855D46F63; Fri, 11 Oct 2024 00:28:00 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:27:02 +0200 Message-ID: <20241010222750.582921-16-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/19] 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: 7dRRkaAXO6t+ 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. 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 | 501 ++++++++++++++++++++++++++++++++++++++++++++ libswscale/graph.h | 123 +++++++++++ 3 files changed, 625 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..ac438ae2c0 --- /dev/null +++ b/libswscale/graph.c @@ -0,0 +1,501 @@ +/* + * 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/mem.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" +#include "libavutil/slicethread.h" + +#include "libswscale/swscale.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, + SwsField in, SwsField out, int slice_align) +{ + SwsPass *pass = av_mallocz(sizeof(*pass)); + int ret; + + pass->graph = graph; + 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 void setup_swscale(const SwsField *out, const SwsField *in, + const SwsPass *pass) +{ + SwsInternal *c = pass->priv; + if (c->opts.flags & SWS_BITEXACT && c->opts.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]) * (c->opts.dst_w + 2)); + } + + if (usePal(c->opts.src_format)) + ff_update_palette(c, (const uint32_t *) in->data[1]); +} + +static void run_rgb0(const SwsField *out, const SwsField *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 SwsField *out, const SwsField *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 SwsField *out, const SwsField *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 SwsField *out, const SwsField *in, int y, int h, + const SwsPass *pass) +{ + SwsInternal *c = pass->priv; + const uint8_t *src_data[4]; + + for (int i = 0; i < 4; i++) { + const int vshift = (i == 1 || i == 2) ? c->chrSrcVSubSample : 0; + src_data[i] = in->data[i]; + if (src_data[i] && (!i || !usePal(c->opts.src_format))) + src_data[i] += (y >> vshift) * in->linesize[i]; + } + + c->convert_unscaled(c, src_data, in->linesize, y, h, out->data, out->linesize); +} + +static void run_swscale(const SwsField *out, const SwsField *in, int y, int h, + const SwsPass *pass) +{ + SwsInternal *c = pass->priv; + const SwsGraph *const graph = pass->graph; + const int src_h = graph->src.height; + const int sub_y = graph->dst.desc->log2_chroma_h; + const uint8_t *src_data[4]; + uint8_t *dst_data[4]; + int src_stride[4]; + + 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(c->opts.src_format)) { + memcpy(c->pal_yuv, parent->pal_yuv, sizeof(c->pal_yuv)); + memcpy(c->pal_rgb, parent->pal_rgb, sizeof(c->pal_rgb)); + } + } + + for (int i = 0; i < 4; i++) { + const int vshift = (i == 1 || i == 2) ? sub_y : 0; + src_stride[i] = in->linesize[i]; + src_data[i] = in->data[i]; + dst_data[i] = out->data[i]; + if (dst_data[i] && (!i || !usePal(c->opts.dst_format))) + dst_data[i] += (y >> vshift) * out->linesize[i]; + } + + ff_swscale(c, src_data, src_stride, 0, src_h, dst_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, + SwsField input, SwsField output) +{ + SwsInternal *c = sws_internal(sws); + const int src_w = c->opts.src_w, src_h = c->opts.src_h; + const int dst_w = c->opts.dst_w, dst_h = c->opts.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 */ + SwsField 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 (c->opts.dither == SWS_DITHER_ED && !c->convert_unscaled) + align = 0; /* disable slice threading */ + + if (c->src0Alpha && !c->dst0Alpha && isALPHA(c->opts.dst_format)) { + SwsField tmp = { .linesize = { FFALIGN(src_w * sizeof(uint8_t[4]), 16) }}; + SwsPass *sub = pass_add(graph, c, src_w, src_h, input, tmp, 1); + if (!sub || pass_alloc_output(sub) < 0) + return AVERROR(ENOMEM); + sub->run = run_rgb0; + input = sub->output; + } + + if (c->srcXYZ && !(c->dstXYZ && unscaled)) { + SwsField tmp = { .linesize = { FFALIGN(src_w * sizeof(uint16_t[3]), 16) }}; + SwsPass *sub = pass_add(graph, c, src_w, src_h, input, tmp, 1); + if (!sub || pass_alloc_output(sub) < 0) + return AVERROR(ENOMEM); + sub->run = run_xyz2rgb; + input = sub->output; + } + + pass = pass_add(graph, c, dst_w, dst_h, input, output, align); + if (!pass) + return AVERROR(ENOMEM); + pass->setup = setup_swscale; + pass->run = c->convert_unscaled ? run_unscaled : run_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++) { + SwsInternal *c2; + c->slice_ctx[i] = sws_alloc_context(); + if (!c->slice_ctx[i]) + return AVERROR(ENOMEM); + c->nb_slice_ctx++; + + c2 = sws_internal(c->slice_ctx[i]); + c2->parent = sws; + c2->opts = c->opts; + + ret = sws_init_single_context(c->slice_ctx[i], NULL, NULL); + if (ret < 0) + return ret; + + sws_setColorspaceDetails(c->slice_ctx[i], c->srcColorspaceTable, + c->opts.src_range, c->dstColorspaceTable, + c->opts.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, output, output, 1); + if (!sub) + return AVERROR(ENOMEM); + sub->run = run_rgb2xyz; + } + + return 0; +} + +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; + + 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, SWS_INPUT, SWS_OUTPUT); + if (ret < 0) + return ret; + + return 0; +} + +const uint8_t sws_input_sentinel, sws_output_sentinel; + +static const SwsField *resolve_field(SwsGraph *graph, const SwsField *field) +{ + if (field->data[0] == &sws_input_sentinel) + return &graph->exec.input; + else if (field->data[0] == &sws_output_sentinel) + return &graph->exec.output; + else + return field; +} + +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 SwsField *input = resolve_field(graph, &pass->input); + const SwsField *output = resolve_field(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; +} + +void sws_graph_run(SwsGraph *graph, const SwsField *out, const SwsField *in) +{ + graph->exec.input = *in; + graph->exec.output = *out; + + 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..afa2c134d7 --- /dev/null +++ b/libswscale/graph.h @@ -0,0 +1,123 @@ +/* + * 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 SwsField { + uint8_t *data[4]; /* points to y=0 */ + int linesize[4]; +} SwsField; + +enum { + FIELD_TOP, /* top/even rows, or progressive */ + FIELD_BOTTOM, /* bottom/odd rows */ +}; + +/** + * Sentinel values to refer to the overall image input / output during + * filter graph construction, as the true values are not known. + */ +extern const uint8_t sws_input_sentinel, sws_output_sentinel; +#define SWS_INPUT ((SwsField) {{ (uint8_t *) &sws_input_sentinel }}) +#define SWS_OUTPUT ((SwsField) {{ (uint8_t *) &sws_output_sentinel }}) + +typedef struct SwsPass SwsPass; +typedef struct SwsGraph SwsGraph; + +struct SwsPass { + const SwsGraph *graph; + uint8_t *buf; /* temporary buffer for this pass, freed automatically */ + + int width, height; /* new output size */ + int pixel_bytes; /* bytes per pixel */ + int slice_h; /* filter granularity */ + int num_slices; + + /* Filter input/output. */ + SwsField input; + SwsField 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 SwsField *out, const SwsField *in, + const SwsPass *pass); + + /** + * Output `slice_h` lines of filtered data. `src` and `dst` point to the + * start of the image buffer for this pass. + */ + void (*run)(const SwsField *out, const SwsField *in, int y, int h, + 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; + + /* Temporary execution state inside sws_graph_run */ + struct { + const SwsPass *pass; /* current filter pass */ + SwsField input; + SwsField 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); + +/** + * Dispatch the filter graph on a single field. Internally threaded. + */ +void sws_graph_run(SwsGraph *graph, const SwsField *out, const SwsField *in); + +#endif /* SWSCALE_GRAPH_H */ From patchwork Thu Oct 10 22:27:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52203 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp196501vqn; Thu, 10 Oct 2024 15:38:29 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUT4Tf0yA3mQBsWmDuBgsaSZTToxtt9W4Rfw7XdE/UDdXzxjnhK0eLmQkMQPubEgmBD5b4rd9xkE8oeAGitDfHc@gmail.com X-Google-Smtp-Source: AGHT+IFTOmzZiK7qca+vqdCglJWK433wd2mgse+sfw40j4k2pWsIjI5fkzjKjkQWvuTH4iRql+PH X-Received: by 2002:a05:6512:2813:b0:533:4b38:3983 with SMTP id 2adb3069b0e04-539da3c866emr115264e87.20.1728599908959; Thu, 10 Oct 2024 15:38:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728599908; cv=none; d=google.com; s=arc-20240605; b=Nj9I4XRKBMvzha8jG27Ea9xaV6kTLLy58O//VpbbKvNa2T0YVJU9jO6U/qliZMtcIf SwOl/uwHZWfjSiASyjPyfmz5AzT+6nPYHixMSDqE7D2ArF46vyM5HMKALnSTUA6bHKWC 3oYL+TpvYs2tQUA9SudqhHIKKR9yug4/3o2SpOWCGK2iOANIYLcoxK0j+h+18sx011/g 9WbR2mGTVkUMBqME5zmAue7Ulv0EIJ7iJsYC99fp/gFuE3PTJvwNuv/E9QeNMiUCj0su nH5RTBFK9N0G8dCjgj1gjtyvRNng15GGaI06ZRCTK+5FBDDTpOO50d6h+UaDiV22qOei mXDg== 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=vZNCQcphCE2Bp8qauILb267z2gdjYlGEL4sEFI9L+HU=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=T3SKt7nvbcaUMV38Ikchox5paHl90yUTgsB8LbiKK542iskoFw5FAWa12MOgIU0HM6 M1EVDJAsxo9bEpQ/xAqt3i6yRCGLkXlaNwn3pTkw10UaW8S3JeD0CeC5UUzE/LDdd70Y 0C2WRXBNv+gpL2ThHCJk2SeNGFXrM1gdwTENvAYfDvzXxtPkF0y3leybI2crKaoinP/m MtRM44ufC2m+/U3/GmF/u4mrRb/cFBEmZEvQDWikSHBVqp5KxfFPKMhjhYK8aSYej/z5 QhRL/OdS3Xoh6tZobF7JNWiI6qP3eF46KiEpGCV3hyE30MDQgzQDcVQZsQZ5Eh0W/JQz t4RA==; 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=HmJuXONK; 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-539cb8f4228si797294e87.358.2024.10.10.15.38.28; Thu, 10 Oct 2024 15:38:28 -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=HmJuXONK; 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 59F5368DF23; Fri, 11 Oct 2024 01:28: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 CB49268DED7 for ; Fri, 11 Oct 2024 01:28:02 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599280; bh=Cp+wlqGDxG5EMZ/vKT9CnkMf9X7b9nGA3sXZGp7VTpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HmJuXONKAxpM/B69ZWNvBUofUDasq0v5ceBRux0bRrEeoPFC9R/xAysLB9cuJKo2F 5tALYEkNjuvWBknsLWetP7kHzwq5MOPzp5FYQmPxAcIBPZnAcY/BC1+b0cMxNrgJep SYjvZ7azZYMh32r+MmUp8lj6jsXTOJi8Jx16C06c= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 59BFC4710F; Fri, 11 Oct 2024 00:28:00 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:27:03 +0200 Message-ID: <20241010222750.582921-17-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/19] 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: OXzqW7fsq85W 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. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/swscale.c | 223 +++++++++++++++++++++++++++++++++- libswscale/swscale.h | 91 ++++++++++---- libswscale/swscale_internal.h | 6 +- libswscale/utils.c | 4 + libswscale/x86/output.asm | 2 +- 5 files changed, 297 insertions(+), 29 deletions(-) diff --git a/libswscale/swscale.c b/libswscale/swscale.c index d5be07193d..2f4221deee 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -1212,19 +1212,232 @@ int sws_receive_slice(SwsContext *sws, unsigned int slice_start, dst, c->frame_dst->linesize, slice_start, slice_height); } +static SwsField get_field(const AVFrame *frame, int field) +{ + SwsField f = { +#define COPY4(x) { x[0], x[1], x[2], x[3] } + .data = COPY4(frame->data), + .linesize = COPY4(frame->linesize), + }; + + if (!(frame->flags & AV_FRAME_FLAG_INTERLACED)) { + av_assert1(!field); + return f; + } + + 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 < FF_ARRAY_ELEMS(f.data); i++) { + f.data[i] += f.linesize[i]; + if (desc->flags & AV_PIX_FMT_FLAG_PAL) + break; + } + } + + /* Take only every second line */ + for (int i = 0; i < FF_ARRAY_ELEMS(f.linesize); i++) + f.linesize[i] <<= 1; + + return f; +} + +/* Subset of av_frame_ref() that only copies (video) data buffers */ +static int frame_refcopy(AVFrame *dst, const AVFrame *src) +{ + int ret; + + /* TODO: handle hwframes? */ + + /* copy frame data if it's not refcounted, or if dst buffers exist */ + if (!src->buf[0] || dst->buf[0]) { + if (!dst->data[0]) { + ret = av_frame_get_buffer(dst, 0); + if (ret < 0) + return ret; + } + ret = av_frame_copy(dst, src); + if (ret < 0) + return ret; + return 0; + } + + /* 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]) { + SwsGraph *graph = c->graph[0]; + av_assert0(graph); + if (ff_fmt_equal(&graph->dst, &graph->src)) { + ret = frame_refcopy(dst, src); + if (ret < 0) + return ret; + } else { + if (!dst->data[0]) { + ret = av_frame_get_buffer(dst, 0); + if (ret < 0) + return ret; + } + + for (int field = 0; field < 2; field++) { + SwsField dst_field = get_field(dst, field); + SwsField src_field = get_field(src, field); + sws_graph_run(c->graph[field], &dst_field, &src_field); + if (!graph->src.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; +} + +/* Tests only options relevant to sws_frame_setup() */ +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_frame_setup(SwsContext *ctx, const AVFrame *dst, const AVFrame *src) +{ + SwsInternal *s = ctx->internal; + SwsFormat src_fmt, dst_fmt; + const char *err_msg; + int ret; + + if (!src || !dst) + return AVERROR(EINVAL); + if ((ret = validate_params(ctx)) < 0) + return ret; + + src_fmt = ff_fmt_from_frame(src); + dst_fmt = ff_fmt_from_frame(dst); + + 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; + } + + /* Try to re-use already initialized graph */ + if (s->graph[0] && + ff_fmt_equal(&dst_fmt, &s->graph[0]->dst) && + ff_fmt_equal(&src_fmt, &s->graph[0]->src) && + opts_equal(ctx, &s->graph[0]->opts)) + return 0; + + 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; + } + + /* TODO: remove once implemented */ + if (dst_fmt.prim != src_fmt.prim || dst_fmt.trc != src_fmt.trc) { + av_log(ctx, AV_LOG_WARNING, "Conversions between different primaries / " + "transfer functions are not currently implemented, expect " + "wrong results.\n"); + } + + /* Re-initialize scaling graph */ + for (int i = 0; i < FF_ARRAY_ELEMS(s->graph); i++) + sws_graph_free(&s->graph[i]); + + for (int field = 0; field < 2; field++) { + ret = sws_graph_create(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) + break; + } + + return 0; - sws_frame_end(sws); +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; } diff --git a/libswscale/swscale.h b/libswscale/swscale.h index a98285685b..e111db31b4 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 swscale.c:opts_equal() */ } SwsContext; /** @@ -288,12 +299,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 fixes the * values of any options set in the SwsContext; further adjustments will * not affect the scaling process. + + * 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 @@ -399,7 +460,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 @@ -426,27 +488,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). @@ -517,7 +563,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(). @@ -527,7 +574,7 @@ int sws_receive_slice(SwsContext *c, unsigned int slice_start, unsigned int sws_receive_slice_alignment(const SwsContext *c); /** - * @param c the scaling context + * @param c the scaling context, must have been initialized with sws_init_context() * @param dstRange flag indicating the while-black range of the output (1=jpeg / 0=mpeg) * @param srcRange flag indicating the while-black range of the input (1=jpeg / 0=mpeg) * @param table the yuv2rgb coefficients describing the output yuv space, normally ff_yuv2rgb_coeffs[x] diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index 21d8113e5a..e4cdc1c7a5 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]; /* even, odd fields */ + // values passed to current sws_receive_slice() call int dst_slice_start; int dst_slice_height; @@ -673,7 +677,7 @@ static_assert(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInt /* 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"); SwsFunc ff_yuv2rgb_get_func_ptr(SwsInternal *c); diff --git a/libswscale/utils.c b/libswscale/utils.c index 04d3f99970..8ebc6de0ed 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 Thu Oct 10 22:27:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52212 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp236222vqn; Thu, 10 Oct 2024 17:23:23 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWRbggY6lRg/42Cbs8SBUx/8rM88sup5dxh5XmjuRPBl0EN1JXVmxEHrgpI1PAB3uRyI/U9Ok38gR3U2MPcv3YZ@gmail.com X-Google-Smtp-Source: AGHT+IFTbORc2xgtaf5vPcaltwWkL1mzm11fUA+WYfriGjy95ZNEa29eeMfD2Aw+ury/8n3mqDMG X-Received: by 2002:a05:651c:2128:b0:2fa:c6b3:bf1c with SMTP id 38308e7fff4ca-2fb326f5594mr2900341fa.8.1728606202724; Thu, 10 Oct 2024 17:23:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728606202; cv=none; d=google.com; s=arc-20240605; b=DwOX7soccn1Qv/vEGyx+2ZH4DM/bsMPGwHRtDTBG9n+6/zATrLwz8HHP5LyxXIE/eO pQREHSghYUSLLuXbciuTumy2L36W6ET3Edcr1ZE4aSemSQxVRgO3LOBKF59E2xhAiMkj lrkH9q+e6Q7FRogOuWt/qoZ0dz/hgnmMsdLopKo17nRpQGpKrZ26EA9NsI6Gzz0jMQXa Q720+DZd9VJS+f13Fzla6/Q9rt3V9YwGoAv5uAgmYnafJ7l1KHx8ujvDGt+mY9v+NjhL 6JeYOJxzmkqO4BUEPUCc6qKsbjY8EZkJdTIz/H5vLNjLOrYsaHlKUUpCXh/GniC8ikjI 3fmw== 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=Dr6yY04e+71IbVeMsq4YlQqBp46g6gXGBYg/sVSiRmo=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=WJQMDnpGCqSse+46pIL6n5kxvksBm1IuJePGvJ1aYlaTt/Hmq74fAD5Y31PYNLj/Om UdgNATDGBA/SiHNUzOxtaevKCvPbhNAT7OWrcaAHZCJ28e9GAE2hSspLwuUB/0rBgmUs J+P9qrFhUzBAE9jxFg45XbzEcPlqUET9/B3Gty8DtY7/Z+cN1pypOrsDlx1dvoC7m+DM 2/q39wlMRhHSDoU9qfHlLdQoLbWVv05AUFNIuAjR9sETkxGSVSqpY759Vnl2Tki7VK9d Pssbn8Nw54ZsB4wt9GA4dmw4oHG/UWRLpi/XjhH1oT+O0l5D0rHlVMeciPuo3cKmcCgz 8DSA==; 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="uImPqZk/"; 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-2fb246f6a41si6454681fa.214.2024.10.10.17.23.22; Thu, 10 Oct 2024 17:23:22 -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="uImPqZk/"; 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 B165868DF2F; Fri, 11 Oct 2024 01:28: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 D0AF168DEDF for ; Fri, 11 Oct 2024 01:28:02 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599280; bh=g1mRZJV71RdilmXttKYujPDjtY2iodE+vl4vSDOVMbs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uImPqZk/uApmQ9qrx8Qv+5SukzVw9IeaTybsaHj9L0JC5Ctfyghzdb4dDCEki7EBR WQuxwJiohspleTu18zjGraS/gPrkwEgIIELZaXolItW9Uh1UUaP+3+JhoKtronJ9+0 ZrGhmKoljbO9CMU2iKmbQpMODHbsVkvlmuzAJ6CE= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 9684D472A8; Fri, 11 Oct 2024 00:28:00 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:27:04 +0200 Message-ID: <20241010222750.582921-18-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/19] 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: 9q16v7gud2Xw 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 f9b5f60ef0..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; - SwsInternal *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) { - SwsInternal *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; - SwsInternal *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 Thu Oct 10 22:27:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52204 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp201296vqn; Thu, 10 Oct 2024 15:53:22 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVnhumpza4LLIhplYn4TIBth61p09pWbzkR4B2k9F4B+5P/1JBVPh/K5Z95p505zYDH9frmtXy7EBb9V9+sxxwo@gmail.com X-Google-Smtp-Source: AGHT+IFeGxZ/GGBWix4NGdJzIt+j4+HqpNLt2eQ0SFPvOqRUzob5YYzSf845f1Dxge2DK4XbLRAP X-Received: by 2002:a05:6512:3052:b0:536:54ff:51c8 with SMTP id 2adb3069b0e04-539da3c4bc8mr261843e87.17.1728600801944; Thu, 10 Oct 2024 15:53:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728600801; cv=none; d=google.com; s=arc-20240605; b=B7d1L0qLy/Nqo8LA61wJJGKRmBfKlK8bmvTO4PlyQy5vCh9lirviP62u0cfNfuPyJI vSCbCBXWE/RaTFuT++kxd21sTW1d7Jq/ugBl+WD0xc1PA1Gno1qHD8ucKUyZ1X0R+J8m 8C9RSLa7v+hdeLrVqFG1OqRcnM+HFvlq+heFg5LeIRVnf0j/XegwH/4WX010P4y4UOZV hV1Zo4iNIXWM5m0Pk8qOZJnm3LVqSGOe5AyltRvg6/7DTxdFNHqsdLjvz+ulKmOaCHM7 VMJIMbgQBTrJ0IzP0VXu4WsCW05xuDS452eKhUpJfP/hoZ8Z12eKKjERyR4cEqGLVt2z nv0Q== 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=U6fF2Qg57t0oq0UR8eb41iglNcoJt9NAt9S6Iak1ZR7L8+GLTsyaYt93RyUo/7qbn3 TiBZcRQnZciBaa+1gYpErUL7V3xfil5DmgmpZNeWGVjpkJfA49FLcBg+TZIKNLwL7O6P grhp1LoUM3w+H3EosDO8qC/iPd/iHVobfjrxK3c8qldpJbstX1ld+jfuHC0K6pYesKtN DMQ9hHNY8aK9X6lRQYWfMtKULu7F1VWap+kjRh/fL2bK9PrgBB9uKGc1NzCWFXubqa7q QsOENmwud1zxt+Xg55kAfKpiMRo8ZuQlaZyI/Qiv22kskKP4ZL+SiuJLL4XCMY8Wqk22 h6sw==; 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=UnqwMVgi; 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-a99a80d15b4si150813366b.362.2024.10.10.15.53.21; Thu, 10 Oct 2024 15:53:21 -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=UnqwMVgi; 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 58F2168DF22; Fri, 11 Oct 2024 01:28:12 +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 BB82568DEDA for ; Fri, 11 Oct 2024 01:28:02 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599280; bh=2mtYBl/3UewOGpaBqqCYdLlOK7bQAP6Z2F1VT/TMzU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UnqwMVgi2RKh4p6KU/SHWzXGuTmjdsjR+LODItVXdIDH6/hBaf06iurr1zU/MtYOk 8bg1vdYPlwI+e+HfhUxT1RtVAIpYH/R6u4yVHM9NzLVHS0YexE3yF0/qSV8Y+9MIBH jRbBEdoXHkjr41W9E8qyldxei6aqh7Zn8t0XuF34= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id D4A04476F4; Fri, 11 Oct 2024 00:28:00 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:27:05 +0200 Message-ID: <20241010222750.582921-19-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/19] 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: Iau0gB5VPE+d 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 Thu Oct 10 22:27:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52201 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:998b:0:b0:48e:c0f8:d0de with SMTP id g11csp196489vqn; Thu, 10 Oct 2024 15:38:27 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWNcMWqqKL+pNJ9B2vWY9zOrBU/I9wa34VSH8kf93JCk3lpL5aGOm8SIhqdvpWClloLVAG4MYXuLQlzqkNGgt3r@gmail.com X-Google-Smtp-Source: AGHT+IHbv5YFjzuYkIxkWmUB3tggukxHpu9W3ky/gPa8jjQnhI3kX5giOBXWA07thNFhKzx0vYqf X-Received: by 2002:a05:6512:15a0:b0:539:d428:fbdd with SMTP id 2adb3069b0e04-539da592951mr122941e87.53.1728599907694; Thu, 10 Oct 2024 15:38:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728599907; cv=none; d=google.com; s=arc-20240605; b=Qhf/5U0/14qmTQlJO0KfV7i2nXf7+Kc9nSClMGV6tOAfl+5n3h6Ok3FYgDBwhJPrq1 EErPiMDrOrCHD224fJaXBFO3k3OcrnRelDdIivI9BZzXkGIg0jSEvqMBNvIGkpM7jrX/ SpZjIZ+1H6iZg+su9bSI/b84vgjLZc0yo1HZGq5ktFWRyjQibCShvzofFOolbWveylLB fUW64Jyk6JUogGymilZC9dcZ3bhiqs1NwRWmF5vVi0GGRY+uD3w9ZiRCJgksng2/OiLK 233BPtuxG0+ihG8X7wdXmOBmeC+2afrjJcQwbKg0pSRTbwPgfLk8lBERAbPtoAOCngt2 tkXQ== 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=SagP1upyJf7XjDjpoDcRrIB8hgWvTQwDAHGh5V7vY1M=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=YPrM5/clMZ7BUTS6E2r2LCaXojsRxEUU8BvfRF7fj/MfvuXa9vp8E9ALmBj7/kDeWl Mh6pYlBAShOQxAJSj2zCLWwuBAxY7YB1gwVughwZLNwswwz07fCAsiqdI2+1+Fk9XYLJ 0AsxLeI8qhuBMwDSx8Doh8jAxOQq7bmRwndHi2EKJCA6YAS/8PKPKGQ911bbSiaRwa/m +79m4In42t+/twTNGQGQHDsWjwYVqxiQTaeEQAuoi+qFTe+hMd3W3mSYNpBt7Umb67Xi RuWSN5eiqNA+htENys8eE2/hjrymTiMhUTiUrQMcTqd//utHJPoM5gEvSyrLUlDJ/2Zp LZ9g==; 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=Ew4+0fjB; 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-539cb90b8e0si902183e87.482.2024.10.10.15.38.27; Thu, 10 Oct 2024 15:38:27 -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=Ew4+0fjB; 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 5B72E68DF0A; Fri, 11 Oct 2024 01:28: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 D5BE768DEE0 for ; Fri, 11 Oct 2024 01:28:02 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1728599281; bh=e2FWi1m3qksrVv55s8RCwRZ03kQLSXqRj7j9m2atMYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ew4+0fjBTyy0mr4ZGZ3qX/DGNsH3sK4XHnzB41tIzWOvRW2/UDxD9V02niXgQ4iMt JcBdyhYaVmGnudU8R/1B/IAiYmAPyWzSHfmUhYmWOLnn5WYVeOccHRr/Bv5/NjVJ7F Kkfl1KzmDvV9C75YXQAxIX1AtrpW0lfRpMehuLq0= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 1E537478BF; Fri, 11 Oct 2024 00:28:01 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2024 00:27:06 +0200 Message-ID: <20241010222750.582921-20-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010222750.582921-1-ffmpeg@haasn.xyz> References: <20241010222750.582921-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/19] 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: e9eN7cPnAhZ7 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 3319428d9c..f4859dcd76 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(AVFilterContext *ctx) @@ -483,10 +447,9 @@ static int query_formats(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, &ctx->inputs[0]->outcfg.formats)) < 0) @@ -496,18 +459,24 @@ static int query_formats(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, &ctx->outputs[0]->incfg.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), - &ctx->inputs[0]->outcfg.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, &ctx->inputs[0]->outcfg.color_spaces)) < 0) return ret; if ((ret = ff_formats_ref(ff_all_color_ranges(), @@ -515,9 +484,18 @@ static int query_formats(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, &ctx->outputs[0]->incfg.color_spaces)) < 0) return ret; @@ -619,50 +597,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; @@ -670,12 +604,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) @@ -699,107 +629,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), @@ -866,56 +701,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) @@ -927,12 +712,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 || @@ -1011,11 +793,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; @@ -1025,6 +802,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; @@ -1033,26 +822,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); @@ -1230,8 +1024,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; } @@ -1279,10 +1073,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" }, @@ -1348,7 +1138,7 @@ static void *scale2ref_child_next(void *obj, void *prev) { ScaleContext *s = obj; if (!prev) - return s->sws_opts; + return s->sws; return NULL; }