From patchwork Sun May 21 12:24:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 41755 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1072712pzb; Sun, 21 May 2023 05:24:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Nm2CFQ+zr/LwYzVPZ66HNO69KwvJPIAulONi2QEx/RfSBYKb8nWUCkspl1vwsin3mCCV8 X-Received: by 2002:a17:907:9614:b0:96f:65db:d6f0 with SMTP id gb20-20020a170907961400b0096f65dbd6f0mr8014703ejc.17.1684671892661; Sun, 21 May 2023 05:24:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684671892; cv=none; d=google.com; s=arc-20160816; b=s2p3Oc3zqETwYB6AMnuqD3PUDZXd4jMQqHNkkb5Yx9EdEnmTbHKp5WwxZWlFtTckt9 oTQ0D7EPsmbc2wHJ2t5HW3ywy+1J6J5tOfj1130oP5AqVIkZXtdKc0EO0OPJtiNaCw79 P/x4SKvvYdGUuOeX8mfL5BMwmGfzxY8KHsaYRczOQ/P22Zusm3lXkDM5x4YEezlnES7m JuzoFlFwm8NsDU7y67qIPUX20xWB/3+i+gPY+KYLSzRfoiRwdfRHrOG7ii9SHIEtDUYs ngknP6AFOHjhX4K3nEmztmhdrzGYhtC8J1YdG7gluzgi3M5HogriweAvazk4/7F9GFGW iyxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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:message-id:date:to:from :dkim-signature:delivered-to; bh=GcR9dPlvuMWHqDXWhMFMD6H8J/HS69IpUDg8pMCgMvk=; b=FpwBL54APGA2VybaOfgYYKhcS+6ENbdwvwgscBeJEhOmmZ/hmERFrwcZFhUbkmzKzF KqSzb7ViOOc3TFWs/fzLi0h0f3kiZKDt60kpAgscnuxAusS4XEfj74ygR4QiGYJJxlrM MIBpYAv9ak45oIrvXgBfvI671TPJZcostELklpmBtVEtBK4SqPazKJ46mbaMRfoo9FW+ 354JtgeT9ZpVn0soIs9kb/oF654WjAbX1ft62pg9qabs3ckPMxkEJaHkzYTJrvLmMKGP ZqUVjq4ja58aoNh3pOxoxYm9evDb4xqL/TNv873MmyW4np7qgk5M5AUqu0gKO9SAPw05 F0LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=I+qk5u+N; 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 z11-20020a1709067e4b00b0096a24c1ec90si2480506ejr.756.2023.05.21.05.24.52; Sun, 21 May 2023 05:24:52 -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=I+qk5u+N; 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 5922568C052; Sun, 21 May 2023 15:24:47 +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 257CB68BBF7 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 BE31742DED; Sun, 21 May 2023 14:24:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1684671880; bh=ZDqnKQTqTW+Ltvkf+jF6nuTatZV06kV6x7vXZhS7T2s=; h=From:To:Cc:Subject:Date:From; b=I+qk5u+N6ZhXrXGcu401bmMAeDx7thzpQG34PRrS8Y6sXTqDpmIDUi+HOtVfG0Jnh pXBuQEMfeMCBvtSGvPajTOw6gvRBE2aKrAALcqxOy666Hg+gUHEBqXnuSk+BYJLr8U knixG2+yuDOwLeZmgolXqXmlFgz6OPKhAQ9cYka8= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 21 May 2023 14:24:35 +0200 Message-Id: <20230521122438.78375-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] lavfi/vf_libplacebo: switch to new gamut 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: PCrBuhm9GDzo From: Niklas Haas Upstream deprecated the old ad-hoc, enum/intent-based gamut mapping API and added a new API based on colorimetrically accurate gamut mapping functions. The relevant change for us is the addition of several new modes, as well as deprecation of the old options. Update the documentation accordingly. --- doc/filters.texi | 47 ++++++++++---------- libavfilter/vf_libplacebo.c | 86 +++++++++++++++++++++++++++++-------- 2 files changed, 92 insertions(+), 41 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index ddc8529bbe9..97023d5f2e8 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -16353,37 +16353,36 @@ gamut-mapping when dealing with mismatches between wide-gamut or HDR content. In general, libplacebo relies on accurate source tagging and mastering display gamut information to produce the best results. @table @option -@item intent -Rendering intent to use when adapting between different primary color gamuts -(after tone-mapping). -@table @samp -@item perceptual -Perceptual gamut mapping. Currently equivalent to relative colorimetric. -@item relative -Relative colorimetric. This is the default. -@item absolute -Absolute colorimetric. -@item saturation -Saturation mapping. Forcibly stretches the source gamut to the target gamut. -@end table - @item gamut_mode How to handle out-of-gamut colors that can occur as a result of colorimetric gamut mapping. @table @samp @item clip -Do nothing, simply clip out-of-range colors to the RGB volume. This is the -default. -@item warn -Highlight out-of-gamut pixels (by coloring them pink). -@item darken -Linearly reduces content brightness to preserves saturated details, followed by -clipping the remaining out-of-gamut colors. As the name implies, this makes -everything darker, but provides a good balance between preserving details and -colors. +Do nothing, simply clip out-of-range colors to the RGB volume. Low quality but +extremely fast. +@item perceptual +Perceptually soft-clip colors to the gamut volume. This is the default. +@item relative +Relative colorimetric hard-clip. Similar to @code{perceptual} but without +the soft knee. +@item saturation +Saturation mapping, maps primaries directly to primaries in RGB space. +Not recommended except for artificial computer graphics for which a bright, +saturated display is desired. +@item absolute +Absolute colorimetric hard-clip. Performs no adjustment of the white point. @item desaturate Hard-desaturates out-of-gamut colors towards white, while preserving the -luminance. Has a tendency to shift colors. +luminance. Has a tendency to distort the visual appearance of bright objects. +@item darken +Linearly reduces content brightness to preserves saturated details, followed by +clipping the remaining out-of-gamut colors. +@item warn +Highlight out-of-gamut pixels (by inverting/marking them). +@item linear +Linearly reduces chromaticity of the entire image to make it fit within the +target color volume. Be careful when using this on BT.2020 sources without +proper mastering metadata, as doing so will lead to excessive desaturation. @end table @item tonemapping diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index f26d0126beb..09bb3dfac86 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -56,6 +56,19 @@ enum { TONE_MAP_COUNT, }; +enum { + GAMUT_MAP_CLIP, + GAMUT_MAP_PERCEPTUAL, + GAMUT_MAP_RELATIVE, + GAMUT_MAP_SATURATION, + GAMUT_MAP_ABSOLUTE, + GAMUT_MAP_DESATURATE, + GAMUT_MAP_DARKEN, + GAMUT_MAP_HIGHLIGHT, + GAMUT_MAP_LINEAR, + GAMUT_MAP_COUNT, +}; + static const char *const var_names[] = { "in_w", "iw", ///< width of the input video frame "in_h", "ih", ///< height of the input video frame @@ -186,7 +199,6 @@ typedef struct LibplaceboContext { /* pl_color_map_params */ struct pl_color_map_params color_map_params; - int intent; int gamut_mode; int tonemapping; float tonemapping_param; @@ -202,6 +214,7 @@ typedef struct LibplaceboContext { int gamut_warning; int gamut_clipping; int force_icc_lut; + int intent; #endif /* pl_dither_params */ @@ -272,6 +285,34 @@ static const struct pl_tone_map_function *pl_get_tonemapping_func(int tm) { } } +static void set_gamut_mode(struct pl_color_map_params *p, int gamut_mode) +{ + switch (gamut_mode) { +#if PL_API_VER >= 269 + case GAMUT_MAP_CLIP: p->gamut_mapping = &pl_gamut_map_clip; return; + case GAMUT_MAP_PERCEPTUAL: p->gamut_mapping = &pl_gamut_map_perceptual; return; + case GAMUT_MAP_RELATIVE: p->gamut_mapping = &pl_gamut_map_relative; return; + case GAMUT_MAP_SATURATION: p->gamut_mapping = &pl_gamut_map_saturation; return; + case GAMUT_MAP_ABSOLUTE: p->gamut_mapping = &pl_gamut_map_absolute; return; + case GAMUT_MAP_DESATURATE: p->gamut_mapping = &pl_gamut_map_desaturate; return; + case GAMUT_MAP_DARKEN: p->gamut_mapping = &pl_gamut_map_darken; return; + case GAMUT_MAP_HIGHLIGHT: p->gamut_mapping = &pl_gamut_map_highlight; return; + case GAMUT_MAP_LINEAR: p->gamut_mapping = &pl_gamut_map_linear; return; +#else + case GAMUT_MAP_RELATIVE: p->intent = PL_INTENT_RELATIVE_COLORIMETRIC; return; + case GAMUT_MAP_SATURATION: p->intent = PL_INTENT_SATURATION; return; + case GAMUT_MAP_ABSOLUTE: p->intent = PL_INTENT_ABSOLUTE_COLORIMETRIC; return; + case GAMUT_MAP_DESATURATE: p->gamut_mode = PL_GAMUT_DESATURATE; return; + case GAMUT_MAP_DARKEN: p->gamut_mode = PL_GAMUT_DARKEN; return; + case GAMUT_MAP_HIGHLIGHT: p->gamut_mode = PL_GAMUT_WARN; return; + /* Use defaults for all other cases */ + default: return; +#endif + } + + av_assert0(0); +}; + static int parse_shader(AVFilterContext *avctx, const void *shader, size_t len) { LibplaceboContext *s = avctx->priv; @@ -317,7 +358,7 @@ static int update_settings(AVFilterContext *ctx) int err = 0; LibplaceboContext *s = ctx->priv; enum pl_tone_map_mode tonemapping_mode = s->tonemapping_mode; - enum pl_gamut_mode gamut_mode = s->gamut_mode; + int gamut_mode = s->gamut_mode; uint8_t color_rgba[4]; RET(av_parse_color(color_rgba, s->fillcolor, -1, s)); @@ -336,10 +377,16 @@ static int update_settings(AVFilterContext *ctx) } } + switch (s->intent) { + case PL_INTENT_SATURATION: gamut_mode = GAMUT_MAP_SATURATION; break; + case PL_INTENT_RELATIVE_COLORIMETRIC: gamut_mode = GAMUT_MAP_RELATIVE; break; + case PL_INTENT_ABSOLUTE_COLORIMETRIC: gamut_mode = GAMUT_MAP_ABSOLUTE; break; + } + if (s->gamut_warning) - gamut_mode = PL_GAMUT_WARN; + gamut_mode = GAMUT_MAP_HIGHLIGHT; if (s->gamut_clipping) - gamut_mode = PL_GAMUT_DESATURATE; + gamut_mode = GAMUT_MAP_DESATURATE; #endif s->deband_params = *pl_deband_params( @@ -366,8 +413,6 @@ static int update_settings(AVFilterContext *ctx) ); s->color_map_params = *pl_color_map_params( - .intent = s->intent, - .gamut_mode = gamut_mode, .tone_mapping_function = pl_get_tonemapping_func(s->tonemapping), .tone_mapping_param = s->tonemapping_param, .tone_mapping_mode = tonemapping_mode, @@ -376,6 +421,8 @@ static int update_settings(AVFilterContext *ctx) .lut_size = s->tonemapping_lut_size, ); + set_gamut_mode(&s->color_map_params, gamut_mode); + s->dither_params = *pl_dither_params( .method = s->dithering, .lut_size = s->dither_lut_size, @@ -1143,16 +1190,16 @@ static const AVOption libplacebo_options[] = { { "scene_threshold_high", "Scene change high threshold", OFFSET(scene_high), AV_OPT_TYPE_FLOAT, {.dbl = 10.0}, -1.0, 100.0, DYNAMIC }, { "overshoot", "Tone-mapping overshoot margin", OFFSET(overshoot), AV_OPT_TYPE_FLOAT, {.dbl = 0.05}, 0.0, 1.0, DYNAMIC }, - { "intent", "Rendering intent", OFFSET(intent), AV_OPT_TYPE_INT, {.i64 = PL_INTENT_RELATIVE_COLORIMETRIC}, 0, 3, DYNAMIC, "intent" }, - { "perceptual", "Perceptual", 0, AV_OPT_TYPE_CONST, {.i64 = PL_INTENT_PERCEPTUAL}, 0, 0, STATIC, "intent" }, - { "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" }, - { "gamut_mode", "Gamut-mapping mode", OFFSET(gamut_mode), AV_OPT_TYPE_INT, {.i64 = PL_GAMUT_CLIP}, 0, PL_GAMUT_MODE_COUNT - 1, DYNAMIC, "gamut_mode" }, - { "clip", "Hard-clip gamut boundary", 0, AV_OPT_TYPE_CONST, {.i64 = PL_GAMUT_CLIP}, 0, 0, STATIC, "gamut_mode" }, - { "warn", "Highlight out-of-gamut colors", 0, AV_OPT_TYPE_CONST, {.i64 = PL_GAMUT_WARN}, 0, 0, STATIC, "gamut_mode" }, - { "darken", "Darken image to fit gamut", 0, AV_OPT_TYPE_CONST, {.i64 = PL_GAMUT_DARKEN}, 0, 0, STATIC, "gamut_mode" }, - { "desaturate", "Colorimetrically desaturate colors", 0, AV_OPT_TYPE_CONST, {.i64 = PL_GAMUT_DESATURATE}, 0, 0, STATIC, "gamut_mode" }, + { "gamut_mode", "Gamut-mapping mode", OFFSET(gamut_mode), AV_OPT_TYPE_INT, {.i64 = GAMUT_MAP_PERCEPTUAL}, 0, GAMUT_MAP_COUNT - 1, DYNAMIC, "gamut_mode" }, + { "clip", "Hard-clip (RGB per-channel)", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_CLIP}, 0, 0, STATIC, "gamut_mode" }, + { "perceptual", "Colorimetric soft clipping", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_PERCEPTUAL}, 0, 0, STATIC, "gamut_mode" }, + { "relative", "Relative colorimetric clipping", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_RELATIVE}, 0, 0, STATIC, "gamut_mode" }, + { "saturation", "Saturation mapping (RGB -> RGB)", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_SATURATION}, 0, 0, STATIC, "gamut_mode" }, + { "absolute", "Absolute colorimetric clipping", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_ABSOLUTE}, 0, 0, STATIC, "gamut_mode" }, + { "desaturate", "Colorimetrically desaturate colors towards white", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_DESATURATE}, 0, 0, STATIC, "gamut_mode" }, + { "darken", "Colorimetric clip with bias towards darkening image to fit gamut", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_DARKEN}, 0, 0, STATIC, "gamut_mode" }, + { "warn", "Highlight out-of-gamut colors", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_HIGHLIGHT}, 0, 0, STATIC, "gamut_mode" }, + { "linear", "Linearly reduce chromaticity to fit gamut", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_LINEAR}, 0, 0, STATIC, "gamut_mode" }, { "tonemapping", "Tone-mapping algorithm", OFFSET(tonemapping), AV_OPT_TYPE_INT, {.i64 = TONE_MAP_AUTO}, 0, TONE_MAP_COUNT - 1, DYNAMIC, "tonemap" }, { "auto", "Automatic selection", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_AUTO}, 0, 0, STATIC, "tonemap" }, { "clip", "No tone mapping (clip", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_CLIP}, 0, 0, STATIC, "tonemap" }, @@ -1184,7 +1231,12 @@ static const AVOption libplacebo_options[] = { { "desaturation_strength", "Desaturation strength", OFFSET(desat_str), AV_OPT_TYPE_FLOAT, {.dbl = -1.0}, -1.0, 1.0, DYNAMIC | AV_OPT_FLAG_DEPRECATED }, { "desaturation_exponent", "Desaturation exponent", OFFSET(desat_exp), AV_OPT_TYPE_FLOAT, {.dbl = -1.0}, -1.0, 10.0, DYNAMIC | AV_OPT_FLAG_DEPRECATED }, { "gamut_warning", "Highlight out-of-gamut colors", OFFSET(gamut_warning), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC | AV_OPT_FLAG_DEPRECATED }, - { "gamut_clipping", "Enable colorimetric gamut clipping", OFFSET(gamut_clipping), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC | AV_OPT_FLAG_DEPRECATED }, + { "gamut_clipping", "Enable desaturating colorimetric gamut clipping", OFFSET(gamut_clipping), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC | AV_OPT_FLAG_DEPRECATED }, + { "intent", "Rendering intent", OFFSET(intent), AV_OPT_TYPE_INT, {.i64 = PL_INTENT_PERCEPTUAL}, 0, 3, DYNAMIC | AV_OPT_FLAG_DEPRECATED, "intent" }, + { "perceptual", "Perceptual", 0, AV_OPT_TYPE_CONST, {.i64 = PL_INTENT_PERCEPTUAL}, 0, 0, STATIC, "intent" }, + { "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" }, #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" }, From patchwork Sun May 21 12:24:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 41756 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1072791pzb; Sun, 21 May 2023 05:25:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ62VRS+ic83pakXHhVBQ0wtQAnykXjujzUjR7cwEFy6UDZqrWeIV2y8l1BqfPaFwYF0b+5K X-Received: by 2002:a17:907:8a20:b0:94e:cefc:8df0 with SMTP id sc32-20020a1709078a2000b0094ecefc8df0mr8382927ejc.61.1684671903405; Sun, 21 May 2023 05:25:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684671903; cv=none; d=google.com; s=arc-20160816; b=FPABtjePv07G5bmF/BCUTEA1nSL2IHk4BVTJLdhLi/IxN52FiD/Ry/VGxGkkqpXCuL 5VZAPTmotXMhHycG+qH58YP8fGA9zGbC72KIVkQPSkI8ZBHSgqsT1xRSPAa6q+2ptVL2 RcX89Qf9dAJulfIzm+DHE7YTEXB2hPazeJrRcZ8E2qOaig1e/ohkhRsbp0VrTu+AVaXl Dl3sZUVG+mqMiPacyEkCueCtEuGL6WZZ4RbJZXXbdE61z07If8wY60h36l1SlXKcR1r3 +GVvzX8+JlZ9N8jn2hDXWqk0MbGI3obeDxl1HfM4XkUqqNAKNcWFvDITD40M3Dtkfira BZgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=FAu5dD7JPUUfYYjeYCFn0tZXvj65OVRnVXpzWELJ7ro=; b=QeGPIsSag3ZHpfb9kDB9I0kaEW2mFandhjHzJBp2+fGsEx56C7GXpuDtmHwJh4etSE 4dPYaajesKmVh9/tNJbUIoAxEo756srW6nhHDwqKN5wn/bErnkciJkajbLgYVAx6dYUT KGxGefjdBrgg7ZF2priAmPnHwloAD39GbunGkJHibrb78TvBugC+LbCMz3TKj37h8m5g yDDjB3XeZbZWW+ckU5+azVpwdewv6cSJuYUF8hupshw6eOYVokFDXZOj3AH0MSzAlLK9 9sJ9ObttQ/Xhcah0ozyKvx03as22G+h0dwLyAKu3dUCE1GkLD/cGoPnPbHDMdebJg14X nnHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=uFGUhfgj; 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 w17-20020a170906481100b0096f56df6a00si2457002ejq.661.2023.05.21.05.25.03; Sun, 21 May 2023 05:25:03 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=uFGUhfgj; 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 89A0668AFA8; Sun, 21 May 2023 15:24:48 +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 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: JuJG2+Zw9OVk 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" }, From patchwork Sun May 21 12:24:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 41757 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1072863pzb; Sun, 21 May 2023 05:25:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ76CmV7r6w78aAPaQEIV/Ag+ijz9tvyHtNz1Rv3Q75olFiH1AqdDpBsBxU4kGQuDMScC9aT X-Received: by 2002:a05:6402:78c:b0:510:5630:cd0f with SMTP id d12-20020a056402078c00b005105630cd0fmr6631783edy.35.1684671912052; Sun, 21 May 2023 05:25:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684671912; cv=none; d=google.com; s=arc-20160816; b=XaKBWJNzZHVK/SN9GcpyeoGq+GwJ5gMdJU9ejAqUl33zYU3PnflHfpTlKDeS0NOYQX 9XU1JIRvsm2kODmFNRD6emlybl5W8ztSiEZgRV2wqmhEsnSb/nwsNyKCo0KECMpE+4Ao mVJoRYg7mYQGHtaupAhKuBdXwo2AkewkNQlOGDCdlfqmP4G35CGRmCqKtUTdkdoNU1uO 5fCiS9yIWSW1bl4aFYs7LPPEKjxY7rEWO2F58LTVG70MdAexfQbCawDPWFJiPTAbFHqe f5aZ5P6HzGEn1pkHI5FWJXpg152Et46jU0uB2xVrov6lGtNec6kCF/ITei9EYb5aI5Wh /APQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=ptXWPkd7sY5T2a1Z1UFIaWlERH3qoSPYkBfc5W3qxRw=; b=KZqKKxuyXwMLMQ15/+b6V3Po3EVZcQaH8RfB/WEijspN96vgDUW73mRtZkY4az5MGo LoRfigQj1yPDf0Mj+t1tPpKkH5kbShUGA+O47b89zraTEZ4YlGaFoi2t46CtR4rRY7N9 JbY7mdczhNzTzFhi3xw+u7oyRT5RVwoyKFVnTpu6j5Ao6TlM/opZB1UhuSfuNLHir7JM Damd5RtF1HQEIsi7IfOZ4fjCcBGDuDoIXmYjYJ2egvXnlFD05yZbzPdpmLxjTulW+Rtb uojKbCd080HtyO21A8Bk8hCA5UJ5Tbzu6Lz7WxLqpi6JqFu20wtmRh0DaPstoZDWQfgJ fbOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=mPBgtU5A; 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 r22-20020a056402035600b0050d0ddf6582si2971128edw.474.2023.05.21.05.25.11; Sun, 21 May 2023 05:25:12 -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=mPBgtU5A; 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 9848C68BF98; Sun, 21 May 2023 15:24:49 +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 9837868BBF7 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 5750048F98; 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=8pqZ4JjAtLpRh7eqew8Xh60AIzk+fETSZaolLIeKgVI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mPBgtU5AwyEOE4JQAcG5SV4DX1iVRybHvW5PNp7SlUQooH4vUaUptoZ3325yVGFTN X4VC887iBvTvaJldk8bgvmqv0i4ciCCPE4rGni4LxCOeURSuSbAqdRvJxBjSGOB7Os yyQXFFnd5gy9+B+LaJ10K3aU8PzDDwOX/5bkm7h8= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 21 May 2023 14:24:37 +0200 Message-Id: <20230521122438.78375-3-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 3/4] lavfi/vf_libplacebo: update peak detection options 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: HmX6hzi1jfOS From: Niklas Haas Upstream peak detection lost one option and gained one option. Update code and documentation as required. --- doc/filters.texi | 9 +++++---- libavfilter/vf_libplacebo.c | 11 +++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index eaa1a282209..a7b091df6ec 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -16341,10 +16341,11 @@ logarithmic scale between @code{0.0} and @code{100.0}. Default to @code{5.5} and @code{10.0}, respectively. Setting either to a negative value disables this functionality. -@item overshoot -Peak smoothing overshoot margin, between @code{0.0} and @code{1.0}. Provides a -safety margin to prevent clipping as a result of peak smoothing. Defaults to -@code{0.05}, corresponding to a margin of 5%. +@item percentile +Which percentile of the frame brightness histogram to use as the source peak +for tone-mapping. Defaults to @code{99.995}, a fairly conservative value. +Setting this to @code{100.0} disables frame histogram measurement and instead +uses the true peak brightness for tone-mapping. @end table @subsubsection Tone mapping diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index b8b12f9c92d..dda6f6279c2 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -195,7 +195,7 @@ typedef struct LibplaceboContext { float min_peak; float scene_low; float scene_high; - float overshoot; + float percentile; /* pl_color_map_params */ struct pl_color_map_params color_map_params; @@ -216,6 +216,7 @@ typedef struct LibplaceboContext { int intent; int tonemapping_mode; float crosstalk; + float overshoot; #endif /* pl_dither_params */ @@ -409,7 +410,12 @@ static int update_settings(AVFilterContext *ctx) .minimum_peak = s->min_peak, .scene_threshold_low = s->scene_low, .scene_threshold_high = s->scene_high, +#if PL_API_VER >= 263 + .percentile = s->percentile, +#endif +#if FF_API_LIBPLACEBO_OPTS && PL_API_VER < 256 .overshoot_margin = s->overshoot, +#endif ); s->color_map_params = *pl_color_map_params( @@ -1192,7 +1198,7 @@ static const AVOption libplacebo_options[] = { { "minimum_peak", "Peak detection minimum peak", OFFSET(min_peak), AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 100.0, DYNAMIC }, { "scene_threshold_low", "Scene change low threshold", OFFSET(scene_low), AV_OPT_TYPE_FLOAT, {.dbl = 5.5}, -1.0, 100.0, DYNAMIC }, { "scene_threshold_high", "Scene change high threshold", OFFSET(scene_high), AV_OPT_TYPE_FLOAT, {.dbl = 10.0}, -1.0, 100.0, DYNAMIC }, - { "overshoot", "Tone-mapping overshoot margin", OFFSET(overshoot), AV_OPT_TYPE_FLOAT, {.dbl = 0.05}, 0.0, 1.0, DYNAMIC }, + { "percentile", "Peak detection percentile", OFFSET(percentile), AV_OPT_TYPE_FLOAT, {.dbl = 99.995}, 0.0, 100.0, DYNAMIC }, { "gamut_mode", "Gamut-mapping mode", OFFSET(gamut_mode), AV_OPT_TYPE_INT, {.i64 = GAMUT_MAP_PERCEPTUAL}, 0, GAMUT_MAP_COUNT - 1, DYNAMIC, "gamut_mode" }, { "clip", "Hard-clip (RGB per-channel)", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_CLIP}, 0, 0, STATIC, "gamut_mode" }, @@ -1242,6 +1248,7 @@ static const AVOption libplacebo_options[] = { { "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 }, + { "overshoot", "Tone-mapping overshoot margin", OFFSET(overshoot), AV_OPT_TYPE_FLOAT, {.dbl = 0.05}, 0.0, 1.0, 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" }, From patchwork Sun May 21 12:24:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 41758 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1072931pzb; Sun, 21 May 2023 05:25:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5F8R0rscQzEFNUU8zcNNNZQ/0yo+HKh0jT9aMMujmkJ5T565r5YIpPfJ5CZoO3eDw2Xz/1 X-Received: by 2002:a05:6402:3451:b0:510:ce80:2f24 with SMTP id l17-20020a056402345100b00510ce802f24mr5831735edc.13.1684671920623; Sun, 21 May 2023 05:25:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684671920; cv=none; d=google.com; s=arc-20160816; b=wH590myV711U1z4J3CDotZSRjuEMG+AABSpUnuxQTsUPw3CFPwUKMswaUUK9OMQQ9C kSSe72x7x1mfzW9cGaEYj/rlWrOo9Ze7kb2oebkyXhKRt3YPQ2ENFOW4a5ps2ctEhRcc HhdqXgOoDcUKSP5QJJuWDBcCa1+yyW3rN7tkvTKvnOqZPchGcaam1bJCMIJygjTqLRW/ eJUmxxAlLjVqwC/H45z6uF/Fs9h3xz8pny6/4ylhCx5GzzW22KmtVd8eV42QpVLMk6gj 5t8U1CHgtcxmS8aUCVRdaM0yVOgng8ijTIlqNTaDzpfyXN7czznZqj3juoYvlotrOtJJ Dt5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=azeb0QVOhJY7Tfswz9DUq3xfRafw3e5PtcCYLNcoO3Q=; b=A4XQZcZgV8SlVjv0196ORUmX8I6QZbuh4oQlnStOQTCBeoPgze/KGK4FEx4+K0G5Lo DzhglJwE5eJzgEZZl+vq80OCzt9/3YGtHkQr6ouk9Pu3yBHBY4q+fm8O0GHlqQyfYyWW c3FiauCygFh+u2OkaLVvPoED4lIBx8LSkTiouX+ofQDMg74oCeT3lmz+mnu+PJte1Gn8 2rMlF3ruoprgzZIoutThvS2ysHI4jqQfHvd1ME3DDA9UqerkuoZP0AtGVEFeALqmxjIa raCMo4DPjML3sNKPCVjVOVh1KH6LDvSuxRoH/vty+5wvskXJY3bCqVYeLwO4Wkp2kddt xytg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=OlMuwHEV; 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 n7-20020aa7db47000000b0050d1e0b3e2esi1858349edt.614.2023.05.21.05.25.20; Sun, 21 May 2023 05:25:20 -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=OlMuwHEV; 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 9C64C68C13B; Sun, 21 May 2023 15:24:50 +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 E7CE768C052 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 9B1DF48FA1; 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=S8gVQwQMz/jrlKH9xnYCuYJ9nqv8TzEi9EICLqNgjMw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OlMuwHEVHcKJNXg7c+7f+yGsVm9QwHNfWJpbcwPv2+d1nHmZ7hdyD168rPlp/+0Ip 5HRqFH9zbXDSMszKKTsxIUjzcMsZnnbz6y8wx5xywMVmpOwaD7/g/5GkL1YhCBGZDT xoxGh+761uGyj10gYlii0rxbN6qMDpKW5avO0lUA= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 21 May 2023 14:24:38 +0200 Message-Id: <20230521122438.78375-4-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 4/4] lavfi/vf_libplacebo: don't intrude on pl_ namespace 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: YX+vZXjJ9Ccw From: Niklas Haas No reason to use this prefix here. --- libavfilter/vf_libplacebo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index dda6f6279c2..6ff30948a78 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -267,7 +267,7 @@ static void pl_av_log(void *log_ctx, enum pl_log_level level, const char *msg) av_log(log_ctx, av_lev, "%s\n", msg); } -static const struct pl_tone_map_function *pl_get_tonemapping_func(int tm) { +static const struct pl_tone_map_function *get_tonemapping_func(int tm) { switch (tm) { case TONE_MAP_AUTO: return &pl_tone_map_auto; case TONE_MAP_CLIP: return &pl_tone_map_clip; @@ -425,7 +425,7 @@ static int update_settings(AVFilterContext *ctx) .tone_mapping_mode = s->tonemapping_mode, .tone_mapping_crosstalk = s->crosstalk, #endif - .tone_mapping_function = pl_get_tonemapping_func(s->tonemapping), + .tone_mapping_function = get_tonemapping_func(s->tonemapping), .tone_mapping_param = s->tonemapping_param, .inverse_tone_mapping = s->inverse_tonemapping, .lut_size = s->tonemapping_lut_size,