From patchwork Thu Oct 24 10:25:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 52468 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:1c41:b0:48e:c0f8:d0de with SMTP id im1csp236994vqb; Thu, 24 Oct 2024 03:39:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXLbXzeiiJ9FxlXuLdVBnrIX5N21Ju0lZraEagkdT2oFvEdxkXgTyeAAtBN7hHtH7dXp+TeDKXyjTgCCrenc38f@gmail.com X-Google-Smtp-Source: AGHT+IFvIzxT1u7IlTH/5Ez+aXoG/ric1bcWrxEKRiQK+yHdWeAAiH6lZIgfmcIWqPyUf/gquODF X-Received: by 2002:a05:6000:1acb:b0:37d:4988:a37e with SMTP id ffacd0b85a97d-37efcf9aa41mr2065196f8f.13.1729766344542; Thu, 24 Oct 2024 03:39:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729766344; cv=none; d=google.com; s=arc-20240605; b=ERpDvKS3Nq8A+ydKnE8u14+IIwPmD+nLr7EKQOeZkefeCEHXxZ343c92x1u6RwsS6v daKXAc3csAvyPCiCzNikQkKT3IOl5vf9YJkRclhUn7TxssYoTj9tPubX3dzX7ix5wjxB aAUuuGEUmTW79mMF3aeUkp43IKvyiRloo0Gk3768f+lAKouWDF0G9nOj2btTlLewx9p0 vJU8hBWi+v76TP7JdEbdTTokkvI60UrDFJ80i7P4aGxeedokCiN3b0oPbaNoGSqgyPaA lRf2NX/Deff+P5NF6KA3fRescjLl1dO6MiNerg9ZVqlT5oinYdVRE9/m9bakmiE+nAKa hHAQ== 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=qwX6g6j7CuTYWItdNa6IEV/QgSzPaLwJ5WAtnO7EdZU=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=YI/0JYM0F1tduQ0LFQXdsaIjtVBY05XO1voTSyGOJp6POvq5gRGKRU/h9hpcVpAc6S yHEHadDZZnV9Cyeud++16isfPPy6Bnvl83r2gOOcA1pasHFfaBhuyG175MIXtKPEvxVy VtULKGMAuHHMEiz7v9C9wDCegGRVCyQXvJWtRyejP2nS2753QjgbQhiOTjnGbmyDsmzr I1IacFyEiP1MGWMgDKm7QcyX0U8RelgaQ5lC8QnWaX4kBUTzOW8GJ5iZpxGo8jSWs3eH kjfR9cgpT3JNnw5MgzI7Srqo6TTLeMA2+0O4liM+7AdEOYntuXQgJ8ZOxXw940qNIAL3 eICg==; 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=Fx9E5SM4; 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-a9a91333c95si684394266b.420.2024.10.24.03.39.04; Thu, 24 Oct 2024 03:39:04 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=Fx9E5SM4; 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 952BF68DBC9; Thu, 24 Oct 2024 13:28:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 033A968DD00 for ; Thu, 24 Oct 2024 13:27:47 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1729765664; bh=PAoyqkpf4P5EikpmvptFcJId57rmZs/hMuVYW9pTJdY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fx9E5SM43NOZS6jI8TYgyLaCMrhWno8F/veh7MinyXwVHnu0UdnLieXbr6lJc/trp 7irb7CWYWFdlFNcla/s6xdGqyCkG+Ma+G87c0b6XZaW7+yT544uesSkeoib5I7n8YB AKaiG1lGvL0Arxt0iJsqUznIsWWYxR5JFrhWE648= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id EC0024843B; Thu, 24 Oct 2024 12:27:43 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Thu, 24 Oct 2024 12:25:17 +0200 Message-ID: <20241024102737.792421-8-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241024102737.792421-1-ffmpeg@haasn.xyz> References: <20241024102737.792421-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 07/13] 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: YTaQXhmdLi3+ 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 4baef532b6..3996411dc8 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 * ***********************************/ @@ -109,7 +174,7 @@ typedef struct SwsContext { void *opaque; /** - * Bitmask of SWS_*. + * Bitmask of SWS_*. See `SwsFlags` for details. */ unsigned flags; @@ -225,60 +290,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