On Sun, 13 Jul 2025 03:51:10 +0900 Lynne <d...@lynne.ee> 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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".