From 812586a54a13ea618097760fc4514abcb8f49e2c Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Sun, 5 Feb 2023 14:53:19 +0100 Subject: [PATCH] tone_mapping: make HDR metadata available to tone-mappers By just sticking it inside `pl_hdr_metadata`, happen what may. We don't need access to the output metadata, so omit it. (This will probably never change, because this HDR metadata contains scene-derived values) --- meson.build | 1 + src/include/libplacebo/tone_mapping.h | 5 +++++ src/shaders/colorspace.c | 1 + src/tone_mapping.c | 3 ++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 09f17f9e..8bab6a00 100644 --- a/meson.build +++ b/meson.build @@ -12,6 +12,7 @@ project('libplacebo', ['c', 'cpp'], 5, # API version { + '245': 'add `pl_tone_map_params.hdr`', '244': 'add `pl_map_hdr_metadata`', '243': 'add `pl_color_space.nominal_min/max`', '242': 'add `pl_hdr_metadata.scene_max/avg` and `pl_hdr_metadata.ootf`', diff --git a/src/include/libplacebo/tone_mapping.h b/src/include/libplacebo/tone_mapping.h index c198d528..d2508b88 100644 --- a/src/include/libplacebo/tone_mapping.h +++ b/src/include/libplacebo/tone_mapping.h @@ -22,6 +22,7 @@ #include #include +#include PL_API_BEGIN @@ -93,6 +94,10 @@ struct pl_tone_map_params { // The desired characteristics of the output, in `output_scaling` units. float output_min; float output_max; + + // The input HDR metadata. Only used by a select few tone-mapping + // functions. (Optional) + struct pl_hdr_metadata hdr; }; #define pl_tone_map_params(...) (&(struct pl_tone_map_params) { __VA_ARGS__ }); diff --git a/src/shaders/colorspace.c b/src/shaders/colorspace.c index 92b3afd3..bf5cfcdf 100644 --- a/src/shaders/colorspace.c +++ b/src/shaders/colorspace.c @@ -1285,6 +1285,7 @@ static void tone_map(pl_shader sh, .input_max = pl_hdr_rescale(PL_HDR_NORM, PL_HDR_SQRT, src_max), .output_min = dst_min, .output_max = dst_max, + .hdr = src->hdr, }; enum pl_tone_map_mode mode = params->tone_mapping_mode; diff --git a/src/tone_mapping.c b/src/tone_mapping.c index 72e71d01..b3e15625 100644 --- a/src/tone_mapping.c +++ b/src/tone_mapping.c @@ -87,7 +87,8 @@ bool pl_tone_map_params_equal(const struct pl_tone_map_params *a, a->input_min == b->input_min && a->input_max == b->input_max && a->output_min == b->output_min && - a->output_max == b->output_max; + a->output_max == b->output_max && + pl_hdr_metadata_equal(&a->hdr, &b->hdr); } bool pl_tone_map_params_noop(const struct pl_tone_map_params *p)