From patchwork Sun Oct 20 20:05:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52421 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp2255708vqi; Sun, 20 Oct 2024 14:04:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXtK7xmYWiJsBiWNfIlAXkH1sFvuL27gnms7LQOUATRshplemP1rwajYNaXbr63SIiJz771iA9GPHqUTnb0/Ctd@gmail.com X-Google-Smtp-Source: AGHT+IHAzXXQTpnD6OfqmpHDfPfZtVfIUM2zyUOVctdngUTbEOEvTHCrXHNddVj6jzwtK7/5Kg07 X-Received: by 2002:a05:6000:e51:b0:37d:5173:7a54 with SMTP id ffacd0b85a97d-37eb4897acfmr5898064f8f.52.1729458245746; Sun, 20 Oct 2024 14:04:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729458245; cv=none; d=google.com; s=arc-20240605; b=eB4EVnrwrMQCBx+v1Dmv/yC9MwTQ0u2Z2+djyKAresSyN9MCkAP3OracVuG3uoBMqa 8S+sWQL6pKORpON7eRRch7mkBks2BzMkhYYAqH8K4RLYBwlQ5LJQ097GtA//bVybqXxG 0tO++GM4kyvDMB40Oygpx7e5nIWPl+u84KuWwaLUDF6rRZHHRE5OBGKE2gv9gpBRLPhf DSkzXRIcYXC6rvPPT8H3sL8UoBViq52ppq+/MPzGSaZP3kJmRGivc/0+7rvpFYbKiYZf zQKnPyfEMPExTuPOKGBs2Ss0C81o/AOZZFL3mvi4v3bQAdqnrRcAYq12uU5aNe29LL7Z YCOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=wZMbrDqf0Xt+z2GS/TPe94snp2tnJFGCEo8YHoHf/So=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=MkijqO4+Q37NGpLEZjbqsb170DJ59mv8AqNn3NIHyqHOyC9kscA201dfCNXqWYQmGQ M3Q51GRHLIyjgH0rNcA0qWCpSYWlyuuU+CFMv10TFMFnWxHpuVKAMVYAFnwuHv/1cVaM 8kfz5wtXpxmzAsRN5NQRahfxCIfWTAuzRNkOnuxsblb6X/iZ0znYDsZX1Q8zSCjj+RPc V1zpvo6PgUGr3jKNmNc1cLAaAM8JGB8/UhmHwFq+XmrCR1nM352QF0JJvpHOB696uEa7 QRfpExI5kknNG6f6Fh8jyfYLLK9qXODqLb3Wggq+ZzuY31aPQFb2DKTpNps08llryr9m 4eSQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=OxbCXjNA; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-5cb66e70dbesi1573614a12.604.2024.10.20.14.04.05; Sun, 20 Oct 2024 14:04:05 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=OxbCXjNA; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D658168DD3D; Sun, 20 Oct 2024 23:09:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5B4F468DC37 for ; Sun, 20 Oct 2024 23:09:00 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729454937; bh=DI5lFc92q2AHTm+zRjc5Z3OTxInD5WsRjZz5W8G4s/8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OxbCXjNAdlJTEPlWrc4QIa1QlDDtZTRSzNr+wuNW4CxioDSREgTjlvrMiZ89m4OiG eWuuv/oi3/bWkBDlAQtICD598AjdRm6YRhB/MX7CgWdWtkCQzCEEeEalV1+sPpOhuB LIaDs8nzh6570KV37wwum2Rwm3PbtWLBpRF2LCPM= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 5E22A4BE8B; Sun, 20 Oct 2024 22:08:57 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Oct 2024 22:05:21 +0200 Message-ID: <20241020200851.1414766-13-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241020200851.1414766-1-ffmpeg@haasn.xyz> References: <20241020200851.1414766-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 12/18] swscale: organize and better document flags X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: yPzNLJAPehco From: Niklas Haas Group them into an enum rather than random #defines, and document their behavior a bit more obviously. Of particular note, I discovered that SWS_DIRECT_BGR is not referenced anywhere else in the code base. As such, I have moved it to the deprecated section, alongside SWS_ERROR_DIFFUSION. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas --- libswscale/swscale.h | 116 ++++++++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 50 deletions(-) diff --git a/libswscale/swscale.h b/libswscale/swscale.h index 0718469a73..6eeb0b0ea0 100644 --- a/libswscale/swscale.h +++ b/libswscale/swscale.h @@ -91,6 +91,71 @@ typedef enum SwsAlphaBlend { SWS_ALPHA_BLEND_NB, /* not part of the ABI */ } SwsAlphaBlend; +typedef enum SwsFlags { + /** + * Scaler selection options. Only one may be active at a time. + */ + SWS_FAST_BILINEAR = 1 << 0, ///< fast bilinear filtering + SWS_BILINEAR = 1 << 1, ///< bilinear filtering + SWS_BICUBIC = 1 << 2, ///< 2-tap cubic B-spline + SWS_X = 1 << 3, ///< experimental + SWS_POINT = 1 << 4, ///< nearest neighbor + SWS_AREA = 1 << 5, ///< area averaging + SWS_BICUBLIN = 1 << 6, ///< bicubic luma, bilinear chroma + SWS_GAUSS = 1 << 7, ///< gaussian approximation + SWS_SINC = 1 << 8, ///< unwindowed sinc + SWS_LANCZOS = 1 << 9, ///< 3-tap sinc/sinc + SWS_SPLINE = 1 << 10, ///< cubic Keys spline + + /** + * Emit verbose log of scaling parameters. + */ + SWS_PRINT_INFO = 1 << 12, + + /** + * Perform full chroma upsampling when upscaling to RGB. + * + * For example, when converting 50x50 yuv420p to 100x100 rgba, setting this flag + * will scale the chroma plane from 25x25 to 100x100 (4:4:4), and then convert + * the 100x100 yuv444p image to rgba in the final output step. + * + * Without this flag, the chroma plane is instead scaled to 50x100 (4:2:2), + * with a single chroma sample being re-used for both of the horizontally + * adjacent RGBA output pixels. + */ + SWS_FULL_CHR_H_INT = 1 << 13, + + /** + * Perform full chroma interpolation when downscaling RGB sources. + * + * For example, when converting a 100x100 rgba source to 50x50 yuv444p, setting + * this flag will generate a 100x100 (4:4:4) chroma plane, which is then + * downscaled to the required 50x50. + * + * Without this flag, the chroma plane is instead generated at 50x100 (dropping + * every other pixel), before then being downscaled to the required 50x50 + * resolution. + */ + SWS_FULL_CHR_H_INP = 1 << 14, + + /** + * Force bit-exact output. This will prevent the use of platform-specific + * optimizations that may lead to slight difference in rounding, in favor + * of always maintaining exact bit output compatibility with the reference + * C code. + * + * Note: It is recommended to set both of these flags simultaneously. + */ + SWS_ACCURATE_RND = 1 << 18, + SWS_BITEXACT = 1 << 19, + + /** + * Deprecated flags. + */ + SWS_DIRECT_BGR = 1 << 15, ///< This flag has no effect + SWS_ERROR_DIFFUSION = 1 << 23, ///< Set `SwsContext.dither` instead +} SwsFlags; + /*********************************** * Context creation and management * ***********************************/ @@ -114,7 +179,7 @@ typedef struct SwsContext { void *opaque; /** - * Bitmask of SWS_*. + * Bitmask of SWS_*. See `SwsFlags` for details. */ unsigned flags; @@ -230,60 +295,11 @@ int sws_test_frame(const AVFrame *frame, int output); */ int sws_is_noop(const AVFrame *dst, const AVFrame *src); -/* values for the flags, the stuff on the command line is different */ -#define SWS_FAST_BILINEAR 1 -#define SWS_BILINEAR 2 -#define SWS_BICUBIC 4 -#define SWS_X 8 -#define SWS_POINT 0x10 -#define SWS_AREA 0x20 -#define SWS_BICUBLIN 0x40 -#define SWS_GAUSS 0x80 -#define SWS_SINC 0x100 -#define SWS_LANCZOS 0x200 -#define SWS_SPLINE 0x400 - #define SWS_SRC_V_CHR_DROP_MASK 0x30000 #define SWS_SRC_V_CHR_DROP_SHIFT 16 #define SWS_PARAM_DEFAULT 123456 -#define SWS_PRINT_INFO 0x1000 - -//the following 3 flags are not completely implemented - -/** - * Perform full chroma upsampling when upscaling to RGB. - * - * For example, when converting 50x50 yuv420p to 100x100 rgba, setting this flag - * will scale the chroma plane from 25x25 to 100x100 (4:4:4), and then convert - * the 100x100 yuv444p image to rgba in the final output step. - * - * Without this flag, the chroma plane is instead scaled to 50x100 (4:2:2), - * with a single chroma sample being re-used for both of the horizontally - * adjacent RGBA output pixels. - */ -#define SWS_FULL_CHR_H_INT 0x2000 - -/** - * Perform full chroma interpolation when downscaling RGB sources. - * - * For example, when converting a 100x100 rgba source to 50x50 yuv444p, setting - * this flag will generate a 100x100 (4:4:4) chroma plane, which is then - * downscaled to the required 50x50. - * - * Without this flag, the chroma plane is instead generated at 50x100 (dropping - * every other pixel), before then being downscaled to the required 50x50 - * resolution. - */ -#define SWS_FULL_CHR_H_INP 0x4000 - -#define SWS_DIRECT_BGR 0x8000 - -#define SWS_ACCURATE_RND 0x40000 -#define SWS_BITEXACT 0x80000 -#define SWS_ERROR_DIFFUSION 0x800000 - #define SWS_MAX_REDUCE_CUTOFF 0.002 #define SWS_CS_ITU709 1