History

lavfi/vf_libplacebo: update for new tone mapping API

This algorithm has once again been refactored, this time leading to a dropping of the old `tone_mapping_mode` field, to be replaced by a single tunable hybrid mode with configurable strength. We can approximately map the old modes onto the new API for backwards compatibility. Replace deprecated enums by their integer equivalents to safely preserve this API until the next bump.

Niklas Haas committed 3 years ago

Commit 643cf2e1 parent d637f202 files · +33 −50Browse files

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/vf_libplacebo.c+27−22
@@ -204,10 +204,9 @@ typedef struct LibplaceboContext { · 203 unmodified lines
204 int gamut_mode;204 int gamut_mode;
205 int tonemapping;205 int tonemapping;
206 float tonemapping_param;206 float tonemapping_param;
207 int tonemapping_mode;
208 int inverse_tonemapping;207 int inverse_tonemapping;
209 float crosstalk;
210 int tonemapping_lut_size;208 int tonemapping_lut_size;
209 float hybrid_mix;
211 210
212#if FF_API_LIBPLACEBO_OPTS211#if FF_API_LIBPLACEBO_OPTS
213 /* for backwards compatibility */212 /* for backwards compatibility */
@@ -217,6 +216,8 @@ typedef struct LibplaceboContext { · 3 unmodified lines
217 int gamut_clipping;216 int gamut_clipping;
218 int force_icc_lut;217 int force_icc_lut;
219 int intent;218 int intent;
219 int tonemapping_mode;
220 float crosstalk;
220#endif221#endif
221 222
222 /* pl_dither_params */223 /* pl_dither_params */
@@ -359,24 +360,23 @@ static int update_settings(AVFilterContext *ctx) · 136 unmodified lines
359{360{
360 int err = 0;361 int err = 0;
361 LibplaceboContext *s = ctx->priv;362 LibplaceboContext *s = ctx->priv;
362 enum pl_tone_map_mode tonemapping_mode = s->tonemapping_mode;
363 int gamut_mode = s->gamut_mode;363 int gamut_mode = s->gamut_mode;
364 float hybrid_mix = s->hybrid_mix;
364 uint8_t color_rgba[4];365 uint8_t color_rgba[4];
365 366
366 RET(av_parse_color(color_rgba, s->fillcolor, -1, s));367 RET(av_parse_color(color_rgba, s->fillcolor, -1, s));
367 368
368#if FF_API_LIBPLACEBO_OPTS369#if FF_API_LIBPLACEBO_OPTS
369 /* backwards compatibility with older API */370 /* backwards compatibility with older API */
370 if (!tonemapping_mode && (s->desat_str >= 0.0f || s->desat_exp >= 0.0f)) {371 switch (s->tonemapping_mode) {
371 float str = s->desat_str < 0.0f ? 0.9f : s->desat_str;372 case 0: /*PL_TONE_MAP_AUTO*/
372 float exp = s->desat_exp < 0.0f ? 0.2f : s->desat_exp;373 if (s->desat_str >= 0.0f)
373 if (str >= 0.9f && exp <= 0.1f) {374 hybrid_mix = s->desat_str;
374 tonemapping_mode = PL_TONE_MAP_RGB;375 break;
375 } else if (str > 0.1f) {376 case 1: /*PL_TONE_MAP_RGB*/ hybrid_mix = 1.0f; break;
376 tonemapping_mode = PL_TONE_MAP_HYBRID;377 case 2: /*PL_TONE_MAP_HYBRID*/ hybrid_mix = 0.2f; break;
377 } else {378 case 3: /*PL_TONE_MAP_LUMA*/ hybrid_mix = 0.0f; break;
378 tonemapping_mode = PL_TONE_MAP_LUMA;379 case 4: /*PL_TONE_MAP_MAX*/ hybrid_mix = 0.0f; break;
379 }
380 }380 }
381 381
382 switch (s->intent) {382 switch (s->intent) {
@@ -415,11 +415,15 @@ static int update_settings(AVFilterContext *ctx) · 32 unmodified lines
415 );415 );
416 416
417 s->color_map_params = *pl_color_map_params(417 s->color_map_params = *pl_color_map_params(
418#if PL_API_VER >= 269
419 .hybrid_mix = hybrid_mix,
420#elif FF_API_LIBPLACEBO_OPTS
421 .tone_mapping_mode = s->tonemapping_mode,
422 .tone_mapping_crosstalk = s->crosstalk,
423#endif
418 .tone_mapping_function = pl_get_tonemapping_func(s->tonemapping),424 .tone_mapping_function = pl_get_tonemapping_func(s->tonemapping),
419 .tone_mapping_param = s->tonemapping_param,425 .tone_mapping_param = s->tonemapping_param,
420 .tone_mapping_mode = tonemapping_mode,
421 .inverse_tone_mapping = s->inverse_tonemapping,426 .inverse_tone_mapping = s->inverse_tonemapping,
422 .tone_mapping_crosstalk = s->crosstalk,
423 .lut_size = s->tonemapping_lut_size,427 .lut_size = s->tonemapping_lut_size,
424 );428 );
425 429
@@ -1228,15 +1232,9 @@ static const AVOption libplacebo_options[] = { · 802 unmodified lines
1228 { "gamma", "Gamma function with knee", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_GAMMA}, 0, 0, STATIC, "tonemap" },1232 { "gamma", "Gamma function with knee", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_GAMMA}, 0, 0, STATIC, "tonemap" },
1229 { "linear", "Perceptually linear stretch", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_LINEAR}, 0, 0, STATIC, "tonemap" },1233 { "linear", "Perceptually linear stretch", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_LINEAR}, 0, 0, STATIC, "tonemap" },
1230 { "tonemapping_param", "Tunable parameter for some tone-mapping functions", OFFSET(tonemapping_param), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 100.0, .flags = DYNAMIC },1234 { "tonemapping_param", "Tunable parameter for some tone-mapping functions", OFFSET(tonemapping_param), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 100.0, .flags = DYNAMIC },
1231 { "tonemapping_mode", "Tone-mapping mode", OFFSET(tonemapping_mode), AV_OPT_TYPE_INT, {.i64 = PL_TONE_MAP_AUTO}, 0, PL_TONE_MAP_MODE_COUNT - 1, DYNAMIC, "tonemap_mode" },
1232 { "auto", "Automatic selection", 0, AV_OPT_TYPE_CONST, {.i64 = PL_TONE_MAP_AUTO}, 0, 0, STATIC, "tonemap_mode" },
1233 { "rgb", "Per-channel (RGB)", 0, AV_OPT_TYPE_CONST, {.i64 = PL_TONE_MAP_RGB}, 0, 0, STATIC, "tonemap_mode" },
1234 { "max", "Maximum component", 0, AV_OPT_TYPE_CONST, {.i64 = PL_TONE_MAP_MAX}, 0, 0, STATIC, "tonemap_mode" },
1235 { "hybrid", "Hybrid of Luma/RGB", 0, AV_OPT_TYPE_CONST, {.i64 = PL_TONE_MAP_HYBRID}, 0, 0, STATIC, "tonemap_mode" },
1236 { "luma", "Luminance", 0, AV_OPT_TYPE_CONST, {.i64 = PL_TONE_MAP_LUMA}, 0, 0, STATIC, "tonemap_mode" },
1237 { "inverse_tonemapping", "Inverse tone mapping (range expansion)", OFFSET(inverse_tonemapping), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },1235 { "inverse_tonemapping", "Inverse tone mapping (range expansion)", OFFSET(inverse_tonemapping), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },
1238 { "tonemapping_crosstalk", "Crosstalk factor for tone-mapping", OFFSET(crosstalk), AV_OPT_TYPE_FLOAT, {.dbl = 0.04}, 0.0, 0.30, DYNAMIC },
1239 { "tonemapping_lut_size", "Tone-mapping LUT size", OFFSET(tonemapping_lut_size), AV_OPT_TYPE_INT, {.i64 = 256}, 2, 1024, DYNAMIC },1236 { "tonemapping_lut_size", "Tone-mapping LUT size", OFFSET(tonemapping_lut_size), AV_OPT_TYPE_INT, {.i64 = 256}, 2, 1024, DYNAMIC },
1237 { "hybrid_mix", "Tone-mapping hybrid LMS mixing coefficient", OFFSET(hybrid_mix), AV_OPT_TYPE_FLOAT, {.dbl = 0.20}, 0.0, 1.00, DYNAMIC },
1240 1238
1241#if FF_API_LIBPLACEBO_OPTS1239#if FF_API_LIBPLACEBO_OPTS
1242 /* deprecated options for backwards compatibility, defaulting to -1 to not override the new defaults */1240 /* deprecated options for backwards compatibility, defaulting to -1 to not override the new defaults */
@@ -1249,6 +1247,13 @@ static const AVOption libplacebo_options[] = { · 6 unmodified lines
1249 { "relative", "Relative colorimetric", 0, AV_OPT_TYPE_CONST, {.i64 = PL_INTENT_RELATIVE_COLORIMETRIC}, 0, 0, STATIC, "intent" },1247 { "relative", "Relative colorimetric", 0, AV_OPT_TYPE_CONST, {.i64 = PL_INTENT_RELATIVE_COLORIMETRIC}, 0, 0, STATIC, "intent" },
1250 { "absolute", "Absolute colorimetric", 0, AV_OPT_TYPE_CONST, {.i64 = PL_INTENT_ABSOLUTE_COLORIMETRIC}, 0, 0, STATIC, "intent" },1248 { "absolute", "Absolute colorimetric", 0, AV_OPT_TYPE_CONST, {.i64 = PL_INTENT_ABSOLUTE_COLORIMETRIC}, 0, 0, STATIC, "intent" },
1251 { "saturation", "Saturation mapping", 0, AV_OPT_TYPE_CONST, {.i64 = PL_INTENT_SATURATION}, 0, 0, STATIC, "intent" },1249 { "saturation", "Saturation mapping", 0, AV_OPT_TYPE_CONST, {.i64 = PL_INTENT_SATURATION}, 0, 0, STATIC, "intent" },
1250 { "tonemapping_mode", "Tone-mapping mode", OFFSET(tonemapping_mode), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, DYNAMIC | AV_OPT_FLAG_DEPRECATED, "tonemap_mode" },
1251 { "auto", "Automatic selection", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, STATIC, "tonemap_mode" },
1252 { "rgb", "Per-channel (RGB)", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, STATIC, "tonemap_mode" },
1253 { "max", "Maximum component", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, STATIC, "tonemap_mode" },
1254 { "hybrid", "Hybrid of Luma/RGB", 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, STATIC, "tonemap_mode" },
1255 { "luma", "Luminance", 0, AV_OPT_TYPE_CONST, {.i64 = 4}, 0, 0, STATIC, "tonemap_mode" },
1256 { "tonemapping_crosstalk", "Crosstalk factor for tone-mapping", OFFSET(crosstalk), AV_OPT_TYPE_FLOAT, {.dbl = 0.04}, 0.0, 0.30, DYNAMIC | AV_OPT_FLAG_DEPRECATED },
1252#endif1257#endif
1253 1258
1254 { "dithering", "Dither method to use", OFFSET(dithering), AV_OPT_TYPE_INT, {.i64 = PL_DITHER_BLUE_NOISE}, -1, PL_DITHER_METHOD_COUNT - 1, DYNAMIC, "dither" },1259 { "dithering", "Dither method to use", OFFSET(dithering), AV_OPT_TYPE_INT, {.i64 = PL_DITHER_BLUE_NOISE}, -1, PL_DITHER_METHOD_COUNT - 1, DYNAMIC, "dither" },

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t