avfilter/tonemap_*: use preinit function

This commit is contained in:
gnattu
2025-03-23 02:31:07 +08:00
parent b078b0f6d6
commit d23fec2487
3 changed files with 16 additions and 11 deletions
+9 -3
View File
@@ -1813,7 +1813,7 @@ Index: FFmpeg/libavfilter/vf_tonemap_cuda.c
===================================================================
--- /dev/null
+++ FFmpeg/libavfilter/vf_tonemap_cuda.c
@@ -0,0 +1,1167 @@
@@ -0,0 +1,1173 @@
+/*
+ * This file is part of FFmpeg.
+ *
@@ -1933,10 +1933,15 @@ Index: FFmpeg/libavfilter/vf_tonemap_cuda.c
+ const AVPixFmtDescriptor *in_desc, *out_desc;
+} TonemapCUDAContext;
+
+static av_cold int init(AVFilterContext *ctx)
+static av_cold int preinit(AVFilterContext *ctx)
+{
+ TonemapCUDAContext *s = ctx->priv;
+ s->final_param = NAN;
+}
+
+static av_cold int init(AVFilterContext *ctx)
+{
+ TonemapCUDAContext *s = ctx->priv;
+
+ if (!strcmp(s->format_str, "same")) {
+ s->format = AV_PIX_FMT_NONE;
@@ -2497,7 +2502,7 @@ Index: FFmpeg/libavfilter/vf_tonemap_cuda.c
+ CONSTANT(".f32 dither_size = %.1f", (float)ff_fruit_dither_size);
+ CONSTANT(".f32 dither_quantization = %.1f", (float)((1 << s->out_desc->comp[0].depth) - 1));
+ CONSTANT(".f32 ref_white = %.4f", REFERENCE_WHITE_ALT);
+ CONSTANT(".f32 tone_param = %.4f", s->param);
+ CONSTANT(".f32 tone_param = %.4f", s->final_param);
+ CONSTANT(".f32 desat_param = %.4f", s->desat_param);
+ CONSTANT(".f32 pq_max_lum_div_ref_white = %.13lf", (float)(ST2084_MAX_LUMINANCE / REFERENCE_WHITE_ALT));
+ CONSTANT(".f32 ref_white_div_pq_max_lum = %.13lf", (float)(REFERENCE_WHITE_ALT / ST2084_MAX_LUMINANCE));
@@ -2968,6 +2973,7 @@ Index: FFmpeg/libavfilter/vf_tonemap_cuda.c
+ .name = "tonemap_cuda",
+ .description = NULL_IF_CONFIG_SMALL("GPU accelerated HDR to SDR tonemapping"),
+
+ .preinit = preinit,
+ .init = init,
+ .uninit = uninit,
+
@@ -2080,11 +2080,11 @@ Index: FFmpeg/libavfilter/vf_tonemap_opencl.c
+ ctx->initialised = 0;
+}
+
+ static av_cold int tonemap_opencl_pre_init(AVFilterContext *avctx)
+ static av_cold int tonemap_opencl_preinit(AVFilterContext *avctx)
+ {
+ TonemapOpenCLContext *ctx = avctx->priv;
+ ctx->final_param = NAN;
+ return ff_opencl_filter_init(avctx);
+ return 0;
+ }
+
+static int format_is_supported(enum AVPixelFormat fmt)
@@ -2481,12 +2481,11 @@ Index: FFmpeg/libavfilter/vf_tonemap_opencl.c
{ NULL }
};
@@ -541,7 +1092,7 @@ const AVFilter ff_vf_tonemap_opencl = {
@@ -541,6 +1092,7 @@ const AVFilter ff_vf_tonemap_opencl = {
.description = NULL_IF_CONFIG_SMALL("Perform HDR to SDR conversion with tonemapping."),
.priv_size = sizeof(TonemapOpenCLContext),
.priv_class = &tonemap_opencl_class,
- .init = &ff_opencl_filter_init,
+ .init = &tonemap_opencl_pre_init,
+ .preinit = &tonemap_opencl_preinit,
.init = &ff_opencl_filter_init,
.uninit = &tonemap_opencl_uninit,
FILTER_INPUTS(tonemap_opencl_inputs),
FILTER_OUTPUTS(tonemap_opencl_outputs),
@@ -1237,7 +1237,7 @@ Index: FFmpeg/libavfilter/vf_tonemap_videotoolbox.m
+ }
+}
+
+static av_cold int tonemap_videotoolbox_pre_init(AVFilterContext *avctx)
+static av_cold int tonemap_videotoolbox_preinit(AVFilterContext *avctx)
+{
+ TonemapVideoToolboxContext *ctx = avctx->priv;
+ ctx->final_param = NAN;
@@ -2119,7 +2119,7 @@ Index: FFmpeg/libavfilter/vf_tonemap_videotoolbox.m
+ .description = NULL_IF_CONFIG_SMALL("Perform HDR to SDR conversion with Metal."),
+ .priv_size = sizeof(TonemapVideoToolboxContext),
+ .priv_class = &tonemap_videotoolbox_class,
+ .init = tonemap_videotoolbox_pre_init,
+ .preinit = tonemap_videotoolbox_preinit,
+ .uninit = tonemap_videotoolbox_uninit,
+ FILTER_INPUTS(tonemap_videotoolbox_inputs),
+ FILTER_OUTPUTS(tonemap_videotoolbox_outputs),