From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 47C6C44AE1 for ; Sun, 13 Jul 2025 22:11:10 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id BFAFB68E440; Mon, 14 Jul 2025 01:11:06 +0300 (EEST) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id A28D068D0AB for ; Mon, 14 Jul 2025 01:10:59 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1752444658; bh=9l+QsHVb+kTDbDL4OidjNzB1rZ+i/5jZjrzy1FXzKAU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=tUK9H5tFPmbjMkBYw9tDPSNDHttheKjxpct9Gmcwef9S0o63rMP/wQo1cagGf6oby COZKGJFN+TWZQg/ArIBx/FYi8r6NXn7DlhWTKJmM36cHemBKSDP/2MH/GTIIV3gExV /M4o1krzPMd6bDLOF2PDNNDSzmV3DmsB8A4uPD40= Received: from localhost (unknown [IPv6:2a02:778:160:8f00:b4d8:4db5:901c:254]) by haasn.dev (Postfix) with UTF8SMTPSA id 5327D402F2; Mon, 14 Jul 2025 00:10:58 +0200 (CEST) Date: Mon, 14 Jul 2025 00:10:57 +0200 Message-ID: <20250714001057.GB17923@haasn.xyz> From: Niklas Haas To: ffmpeg-devel@ffmpeg.org In-Reply-To: <20250712185128.862167-1-dev@lynne.ee> References: <20250712185128.862167-1-dev@lynne.ee> MIME-Version: 1.0 Content-Disposition: inline Subject: Re: [FFmpeg-devel] [PATCH v2 01/13] vf_libplacebo: add support for specifying a LUT for the input 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: Lynne 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: On Sun, 13 Jul 2025 03:51:10 +0900 Lynne wrote: > This makes it possible to apply Adobe .cube files to inputs. > --- > doc/filters.texi | 30 ++++++++++++++++++++++++++++++ > libavfilter/vf_libplacebo.c | 36 ++++++++++++++++++++++++++++++++++++ > 2 files changed, 66 insertions(+) > > diff --git a/doc/filters.texi b/doc/filters.texi > index ed2956fe75..13add0ff01 100644 > --- a/doc/filters.texi > +++ b/doc/filters.texi > @@ -16321,6 +16321,36 @@ Render frames with rounded corners. The value, given as a float ranging from > square to fully circular. In other words, it gives the radius divided by half > the smaller side length. Defaults to @code{0.0}. > > +@item lut > +Specifies a custom LUT (in Adobe .cube format) to apply to the colors > +as part of color conversion. The exact interpretation depends on the value > +of @option{lut_type}. > + > +@item lut_type > +Controls the interpretation of color values fed to and from the LUT > +specified as @option{lut}. Valid values are: > + > +@table @samp > +@item auto > +Chooses the interpretation of the LUT automatically from tagged > +metadata, and otherwise falls back to @samp{native}. (Default) > + > +@item native > +Applied to raw image contents in its native RGB colorspace (non-linear > +light), before conversion to the output color space. > + > +@item normalized > +Applied to the normalized RGB image contents, in linear light, before > +conversion to the output color space. > + > +@item conversion > +Fully replaces the conversion from the image color space to the output > +color space. If such a LUT is present, it has the highest priority, and > +overrides any ICC profiles, as well as options related to tone mapping > +and output colorimetry (@option{color_primaries}, @option{color_trc}). > + > +@end table > + > @item extra_opts > Pass extra libplacebo internal configuration options. These can be specified > as a list of @var{key}=@var{value} pairs separated by ':'. The following example > diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c > index 475030c80d..cbdbe3e665 100644 > --- a/libavfilter/vf_libplacebo.c > +++ b/libavfilter/vf_libplacebo.c > @@ -159,6 +159,7 @@ typedef struct LibplaceboContext { > pl_vulkan vulkan; > pl_gpu gpu; > pl_tex tex[4]; > + struct pl_custom_lut *lut; > > /* input state */ > LibplaceboInput *inputs; > @@ -184,6 +185,8 @@ typedef struct LibplaceboContext { > AVExpr *pos_x_pexpr, *pos_y_pexpr, *pos_w_pexpr, *pos_h_pexpr; > float pad_crop_ratio; > float corner_rounding; > + char *lut_filename; > + enum pl_lut_type lut_type; > int force_original_aspect_ratio; > int force_divisible_by; > int reset_sar; > @@ -371,6 +374,26 @@ static int find_scaler(AVFilterContext *avctx, > return AVERROR(EINVAL); > } > > +static int parse_custom_lut(LibplaceboContext *s) > +{ > + int ret; > + uint8_t *lutbuf; > + size_t lutbuf_size; > + > + if ((ret = av_file_map(s->lut_filename, &lutbuf, &lutbuf_size, 0, s)) < 0) { > + av_log(s, AV_LOG_ERROR, > + "The LUT file '%s' could not be read: %s\n", > + s->lut_filename, av_err2str(ret)); > + return ret; > + } > + > + s->lut = pl_lut_parse_cube(s->log, lutbuf, lutbuf_size); > + av_file_unmap(lutbuf, lutbuf_size); > + if (!s->lut) > + return AVERROR(EINVAL); > + return 0; > +} > + > static int update_settings(AVFilterContext *ctx) > { > int err = 0; > @@ -729,6 +752,9 @@ static int init_vulkan(AVFilterContext *avctx, const AVVulkanDeviceContext *hwct > RET(parse_shader(avctx, buf, buf_len)); > } > > + if (s->lut_filename) > + RET(parse_custom_lut(s)); > + > /* Initialize inputs */ > s->inputs = av_calloc(s->nb_inputs, sizeof(*s->inputs)); > if (!s->inputs) > @@ -757,6 +783,7 @@ static void libplacebo_uninit(AVFilterContext *avctx) > av_freep(&s->inputs); > } > > + pl_lut_free(&s->lut); > #if PL_API_VER >= 351 > pl_cache_destroy(&s->cache); > #endif > @@ -1005,6 +1032,8 @@ static bool map_frame(pl_gpu gpu, pl_tex *tex, > .tex = tex, > .map_dovi = s->apply_dovi, > )); > + out->lut = s->lut; > + out->lut_type = s->lut_type; > > if (!s->apply_filmgrain) > out->film_grain.type = PL_FILM_GRAIN_NONE; > @@ -1406,6 +1435,13 @@ static const AVOption libplacebo_options[] = { > { "pad_crop_ratio", "ratio between padding and cropping when normalizing SAR (0=pad, 1=crop)", OFFSET(pad_crop_ratio), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, 1.0, DYNAMIC }, > { "fillcolor", "Background fill color", OFFSET(fillcolor), AV_OPT_TYPE_COLOR, {.str = "black@0"}, .flags = DYNAMIC }, > { "corner_rounding", "Corner rounding radius", OFFSET(corner_rounding), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 1.0, .flags = DYNAMIC }, > + { "lut", "Path to custom LUT file to apply", OFFSET(lut_filename), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = STATIC }, > + { "lut_type", "Application mode of the custom LUT", OFFSET(lut_type), AV_OPT_TYPE_INT, { .i64 = PL_LUT_UNKNOWN }, 0, PL_LUT_CONVERSION, STATIC, .unit = "lut_type" }, > + { "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = PL_LUT_UNKNOWN }, 0, 0, STATIC, .unit = "lut_type" }, > + { "native", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = PL_LUT_NATIVE }, 0, 0, STATIC, .unit = "lut_type" }, > + { "normalized", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = PL_LUT_NORMALIZED }, 0, 0, STATIC, .unit = "lut_type" }, > + { "conversion", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = PL_LUT_CONVERSION }, 0, 0, STATIC, .unit = "lut_type" }, > + > { "extra_opts", "Pass extra libplacebo-specific options using a :-separated list of key=value pairs", OFFSET(extra_opts), AV_OPT_TYPE_DICT, .flags = DYNAMIC }, > #if PL_API_VER >= 351 > { "shader_cache", "Set shader cache path", OFFSET(shader_cache), AV_OPT_TYPE_STRING, {.str = NULL}, .flags = STATIC }, > -- > 2.50.0 > _______________________________________________ > 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". Commit LGTM. _______________________________________________ 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".