From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id F362D46529 for ; Sun, 21 May 2023 12:25:00 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4618E68C07E; Sun, 21 May 2023 15:24:48 +0300 (EEST) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5C6FD68BBF7 for ; Sun, 21 May 2023 15:24:41 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 163D248D5F; Sun, 21 May 2023 14:24:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1684671881; bh=vAK6XjWUjUIEtHsTGS6sLO7Z1fg0nsfBqpI3tt2ChoQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uFGUhfgjHU5hDEK0YgBXXtjY/X3r4/Hcjm938MdS1Ft2JTYt7QWzky45bfZBL/3Ml R9Gs96LBibTBLFafSiTQIxGSoP6B0H51P6i1oaco5AEENuB5+hEXs1a0OsfWW+CUe7 sZWHh9l2I4BQCspbwzbCG3ChHdQANPRk2TB9ohT8= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 21 May 2023 14:24:36 +0200 Message-Id: <20230521122438.78375-2-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230521122438.78375-1-ffmpeg@haasn.xyz> References: <20230521122438.78375-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] lavfi/vf_libplacebo: update for new tone mapping 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Niklas Haas This algorithm has once again been refactored, this time leading to a dropping of the old `tone_mapping_mode` field, to be replaced by a single tunable hybrid mode with configurable strength. We can approximately map the old modes onto the new API for backwards compatibility. Replace deprecated enums by their integer equivalents to safely preserve this API until the next bump. --- doc/filters.texi | 34 +++++-------------------- libavfilter/vf_libplacebo.c | 49 ++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 50 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 97023d5f2e8..eaa1a282209 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -16461,42 +16461,20 @@ For tunable tone mapping functions, this parameter can be used to fine-tune the curve behavior. Refer to the documentation of @code{tonemapping}. The default value of @code{0.0} is replaced by the curve's preferred default setting. -@item tonemapping_mode -This option determines how the tone mapping function specified by -@code{tonemapping} is applied to the colors in a scene. Possible values are: -@table @samp -@item auto -Automatic selection based on internal heuristics. This is the default. -@item rgb -Apply the function per-channel in the RGB colorspace. -Per-channel tone-mapping in RGB. Guarantees no clipping and heavily desaturates -the output, but distorts the colors quite significantly. Very similar to the -"Hollywood" look and feel. -@item max -Tone-mapping is performed on the brightest component found in the signal. Good -at preserving details in highlights, but has a tendency to crush blacks. -@item hybrid -Tone-map per-channel for highlights and linearly (luma-based) for -midtones/shadows, based on a fixed gamma @code{2.4} coefficient curve. -@item luma -Tone-map linearly on the luma component (CIE Y), and adjust (desaturate) the -chromaticities to compensate using a simple constant factor. This is -essentially the mode used in ITU-R BT.2446 method A. -@end table - @item inverse_tonemapping If enabled, this filter will also attempt stretching SDR signals to fill HDR output color volumes. Disabled by default. -@item tonemapping_crosstalk -Extra tone-mapping crosstalk factor, between @code{0.0} and @code{0.3}. This -can help reduce issues tone-mapping certain bright spectral colors. Defaults to -@code{0.04}. - @item tonemapping_lut_size Size of the tone-mapping LUT, between @code{2} and @code{1024}. Defaults to @code{256}. Note that this figure is squared when combined with @code{peak_detect}. + +@item hybrid_mix +If nonzero, this much of the upper range of the tone-mapped result is smoothly +mixed with a per-channel (LMS) tone-mapped version. Helps avoid unnatural +blown-out highlights when tone-mapping very bright, strongly saturated colors. +Defaults to @code{0.2}. @end table @subsubsection Dithering diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 09bb3dfac86..b8b12f9c92d 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -202,10 +202,9 @@ typedef struct LibplaceboContext { int gamut_mode; int tonemapping; float tonemapping_param; - int tonemapping_mode; int inverse_tonemapping; - float crosstalk; int tonemapping_lut_size; + float hybrid_mix; #if FF_API_LIBPLACEBO_OPTS /* for backwards compatibility */ @@ -215,6 +214,8 @@ typedef struct LibplaceboContext { int gamut_clipping; int force_icc_lut; int intent; + int tonemapping_mode; + float crosstalk; #endif /* pl_dither_params */ @@ -357,24 +358,23 @@ static int update_settings(AVFilterContext *ctx) { int err = 0; LibplaceboContext *s = ctx->priv; - enum pl_tone_map_mode tonemapping_mode = s->tonemapping_mode; int gamut_mode = s->gamut_mode; + float hybrid_mix = s->hybrid_mix; uint8_t color_rgba[4]; RET(av_parse_color(color_rgba, s->fillcolor, -1, s)); #if FF_API_LIBPLACEBO_OPTS /* backwards compatibility with older API */ - if (!tonemapping_mode && (s->desat_str >= 0.0f || s->desat_exp >= 0.0f)) { - float str = s->desat_str < 0.0f ? 0.9f : s->desat_str; - float exp = s->desat_exp < 0.0f ? 0.2f : s->desat_exp; - if (str >= 0.9f && exp <= 0.1f) { - tonemapping_mode = PL_TONE_MAP_RGB; - } else if (str > 0.1f) { - tonemapping_mode = PL_TONE_MAP_HYBRID; - } else { - tonemapping_mode = PL_TONE_MAP_LUMA; - } + switch (s->tonemapping_mode) { + case 0: /*PL_TONE_MAP_AUTO*/ + if (s->desat_str >= 0.0f) + hybrid_mix = s->desat_str; + break; + case 1: /*PL_TONE_MAP_RGB*/ hybrid_mix = 1.0f; break; + case 2: /*PL_TONE_MAP_HYBRID*/ hybrid_mix = 0.2f; break; + case 3: /*PL_TONE_MAP_LUMA*/ hybrid_mix = 0.0f; break; + case 4: /*PL_TONE_MAP_MAX*/ hybrid_mix = 0.0f; break; } switch (s->intent) { @@ -413,11 +413,15 @@ static int update_settings(AVFilterContext *ctx) ); s->color_map_params = *pl_color_map_params( +#if PL_API_VER >= 269 + .hybrid_mix = hybrid_mix, +#elif FF_API_LIBPLACEBO_OPTS + .tone_mapping_mode = s->tonemapping_mode, + .tone_mapping_crosstalk = s->crosstalk, +#endif .tone_mapping_function = pl_get_tonemapping_func(s->tonemapping), .tone_mapping_param = s->tonemapping_param, - .tone_mapping_mode = tonemapping_mode, .inverse_tone_mapping = s->inverse_tonemapping, - .tone_mapping_crosstalk = s->crosstalk, .lut_size = s->tonemapping_lut_size, ); @@ -1216,15 +1220,9 @@ static const AVOption libplacebo_options[] = { { "gamma", "Gamma function with knee", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_GAMMA}, 0, 0, STATIC, "tonemap" }, { "linear", "Perceptually linear stretch", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_LINEAR}, 0, 0, STATIC, "tonemap" }, { "tonemapping_param", "Tunable parameter for some tone-mapping functions", OFFSET(tonemapping_param), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 100.0, .flags = DYNAMIC }, - { "tonemapping_mode", "Tone-mapping mode", OFFSET(tonemapping_mode), AV_OPT_TYPE_INT, {.i64 = PL_TONE_MAP_AUTO}, 0, PL_TONE_MAP_MODE_COUNT - 1, DYNAMIC, "tonemap_mode" }, - { "auto", "Automatic selection", 0, AV_OPT_TYPE_CONST, {.i64 = PL_TONE_MAP_AUTO}, 0, 0, STATIC, "tonemap_mode" }, - { "rgb", "Per-channel (RGB)", 0, AV_OPT_TYPE_CONST, {.i64 = PL_TONE_MAP_RGB}, 0, 0, STATIC, "tonemap_mode" }, - { "max", "Maximum component", 0, AV_OPT_TYPE_CONST, {.i64 = PL_TONE_MAP_MAX}, 0, 0, STATIC, "tonemap_mode" }, - { "hybrid", "Hybrid of Luma/RGB", 0, AV_OPT_TYPE_CONST, {.i64 = PL_TONE_MAP_HYBRID}, 0, 0, STATIC, "tonemap_mode" }, - { "luma", "Luminance", 0, AV_OPT_TYPE_CONST, {.i64 = PL_TONE_MAP_LUMA}, 0, 0, STATIC, "tonemap_mode" }, { "inverse_tonemapping", "Inverse tone mapping (range expansion)", OFFSET(inverse_tonemapping), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC }, - { "tonemapping_crosstalk", "Crosstalk factor for tone-mapping", OFFSET(crosstalk), AV_OPT_TYPE_FLOAT, {.dbl = 0.04}, 0.0, 0.30, DYNAMIC }, { "tonemapping_lut_size", "Tone-mapping LUT size", OFFSET(tonemapping_lut_size), AV_OPT_TYPE_INT, {.i64 = 256}, 2, 1024, DYNAMIC }, + { "hybrid_mix", "Tone-mapping hybrid LMS mixing coefficient", OFFSET(hybrid_mix), AV_OPT_TYPE_FLOAT, {.dbl = 0.20}, 0.0, 1.00, DYNAMIC }, #if FF_API_LIBPLACEBO_OPTS /* deprecated options for backwards compatibility, defaulting to -1 to not override the new defaults */ @@ -1237,6 +1235,13 @@ static const AVOption libplacebo_options[] = { { "relative", "Relative colorimetric", 0, AV_OPT_TYPE_CONST, {.i64 = PL_INTENT_RELATIVE_COLORIMETRIC}, 0, 0, STATIC, "intent" }, { "absolute", "Absolute colorimetric", 0, AV_OPT_TYPE_CONST, {.i64 = PL_INTENT_ABSOLUTE_COLORIMETRIC}, 0, 0, STATIC, "intent" }, { "saturation", "Saturation mapping", 0, AV_OPT_TYPE_CONST, {.i64 = PL_INTENT_SATURATION}, 0, 0, STATIC, "intent" }, + { "tonemapping_mode", "Tone-mapping mode", OFFSET(tonemapping_mode), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, DYNAMIC | AV_OPT_FLAG_DEPRECATED, "tonemap_mode" }, + { "auto", "Automatic selection", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, STATIC, "tonemap_mode" }, + { "rgb", "Per-channel (RGB)", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, STATIC, "tonemap_mode" }, + { "max", "Maximum component", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, STATIC, "tonemap_mode" }, + { "hybrid", "Hybrid of Luma/RGB", 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, STATIC, "tonemap_mode" }, + { "luma", "Luminance", 0, AV_OPT_TYPE_CONST, {.i64 = 4}, 0, 0, STATIC, "tonemap_mode" }, + { "tonemapping_crosstalk", "Crosstalk factor for tone-mapping", OFFSET(crosstalk), AV_OPT_TYPE_FLOAT, {.dbl = 0.04}, 0.0, 0.30, DYNAMIC | AV_OPT_FLAG_DEPRECATED }, #endif { "dithering", "Dither method to use", OFFSET(dithering), AV_OPT_TYPE_INT, {.i64 = PL_DITHER_BLUE_NOISE}, -1, PL_DITHER_METHOD_COUNT - 1, DYNAMIC, "dither" }, -- 2.40.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".