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 3879F4E967 for ; Sat, 12 Jul 2025 18:51:51 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 1EF0A68F1AB; Sat, 12 Jul 2025 21:51:48 +0300 (EEST) Received: from vidala.pars.ee (vidala.pars.ee [116.203.72.101]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 648F6687D73 for ; Sat, 12 Jul 2025 21:51:42 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; s=202405r; d=lynne.ee; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1752346301; bh=0WhY3LJ2QD8rwkyd1RIn971 4ilKqgB6Y2UjDkYfU9UU=; b=d0Dw4TsPyoS2X+/Y5UXm76Tni50SuBSlnknPDXGCyIooti0kRE G/eDMI/5UG+5jL1xsVgNZxfyFKXl21ZxsjI07RKLNyYQVzyMzMZ6Q0qEed74/WMpqvu3KoudHNz R9rw2MDOkOcXpqua7EeDzUhlxOwmMieemIMmSJQ3aMT3dtNwl33ZpTFxlppBDUs1/2IL1PjUJDB f768tfHAx8xtDHdGQUdj5T6LKybivsHEzwCL0kJ/keY38MJ4n9H18Q9+IQ9RqsCo4hkpqNeVNDl jxYwlBcCvXElEefEf1uAdwLcOxqZ4YXKJ48mhTnu1RASVTF01vCxYnxdFScl2HI+BSg==; DKIM-Signature: v=1; a=ed25519-sha256; s=202405e; d=lynne.ee; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1752346301; bh=0WhY3LJ2QD8rwkyd1RIn971 4ilKqgB6Y2UjDkYfU9UU=; b=SXu+WHxftNHALJNYjtOnwQ1xsn/h+cwDMWWxZdUNj9Bk9YC+r6 OEgqVZjhrXoVDbNha0Z6tF95gPI/dOVi/aAQ==; From: Lynne To: ffmpeg-devel@ffmpeg.org Date: Sun, 13 Jul 2025 03:51:10 +0900 Message-ID: <20250712185128.862167-1-dev@lynne.ee> X-Mailer: git-send-email 2.50.0 MIME-Version: 1.0 Subject: [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: 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".