Skip to content

Commit 24b73cb

Browse files
committed
vo_gpu_next: add --target-contrast-hdr option
Should be helpful for Windows ACM/macOS cases, which only use target-contrast=auto might cause washed out colors. Wayland shouldn't need this since we have #17345 Signed-off-by: Shengyu Qu <wiagn@4d2.org>
1 parent 1d82932 commit 24b73cb

4 files changed

Lines changed: 38 additions & 1 deletion

File tree

DOCS/man/options.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7509,6 +7509,22 @@ them.
75097509
``inf`` contrast specifies display with perfect black level, in practice OLED.
75107510
(Only for ``--vo=gpu-next``)
75117511

7512+
``--target-contrast-hdr=<no|auto|10-1000000|inf>``
7513+
Same as ``--target-contrast``, but only applies when ``--target-trc`` is set to
7514+
a HDR transfer function and would override the settings of ``--target-contrast``.
7515+
This allows to specify a different contrast for HDR content, This might be useful
7516+
when user is running a host OS that supports global color management and monitor
7517+
has large contrast ratio. In this case, with some GPU API and OS combinations,
7518+
mpv can't correctly get the actual contrast ratio info of the display when
7519+
``--target-trc`` is a SDR transfer function, and only use
7520+
``--target-contrast=auto`` might cause washed out colors.
7521+
``no`` is the default value and means the contrast is only controlled by
7522+
``--target-contrast``.
7523+
``auto`` means the contrast is infinite when HDR ``--target-trc`` is used, or
7524+
the contrast would be the value of actual monitor if available from host OS.
7525+
``inf`` contrast specifies display with perfect black level, in practice OLED.
7526+
(Only for ``--vo=gpu-next``)
7527+
75127528
``--target-gamut=<value>``
75137529
Constrains the gamut of the display. You can use this option to output e.g.
75147530
DCIP3-in-BT.2020. Set ``--target-prim`` to the primaries of the containing

video/out/gpu/video.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ const struct m_sub_options gl_video_conf = {
453453
{"no", 0}, {"input", 1}, {"output", 2}, {"both", 1|2}, {"auto", 1|2|4})},
454454
{"target-contrast", OPT_CHOICE(target_contrast, {"auto", 0}, {"inf", -1}),
455455
M_RANGE(10, 10 / PL_COLOR_HDR_BLACK)},
456+
{"target-contrast-hdr", OPT_CHOICE(target_contrast_hdr, {"no", 0}, {"auto", -1}, {"inf", -2}),
457+
M_RANGE(10, 10 / PL_COLOR_HDR_BLACK)},
456458
{"target-gamut", OPT_STRING_VALIDATE(target_gamut, validate_target_gamut)},
457459
{"tone-mapping", OPT_CHOICE(tone_map.curve,
458460
{"auto", TONE_MAPPING_AUTO},

video/out/gpu/video.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ struct gl_video_opts {
142142
int sdr_adjust_gamma;
143143
int treat_srgb_as_power22;
144144
int target_contrast;
145+
int target_contrast_hdr;
145146
char *target_gamut;
146147
struct gl_tone_map_opts tone_map;
147148
bool correct_downscaling;

video/out/vo_gpu_next.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,20 @@ static void update_options(struct vo *vo)
915915
static void apply_target_contrast(struct priv *p, struct pl_color_space *color, float min_luma)
916916
{
917917
const struct gl_video_opts *opts = p->opts_cache->opts;
918+
const bool is_hdr = pl_color_space_is_hdr(color);
919+
920+
if (is_hdr && opts->target_contrast_hdr)
921+
switch (opts->target_contrast_hdr) {
922+
case -1:
923+
color->hdr.min_luma = min_luma;
924+
return;
925+
case -2:
926+
color->hdr.min_luma = 1e-7;
927+
mp_assert(color->hdr.min_luma > 0);
928+
return;
929+
default:
930+
goto apply_user_value;
931+
}
918932

919933
// Auto mode, use target value if available
920934
if (!opts->target_contrast) {
@@ -929,6 +943,7 @@ static void apply_target_contrast(struct priv *p, struct pl_color_space *color,
929943
return;
930944
}
931945

946+
apply_user_value:
932947
// Infer max_luma for current pl_color_space
933948
pl_color_space_nominal_luma_ex(pl_nominal_luma_params(
934949
.color = color,
@@ -938,7 +953,10 @@ static void apply_target_contrast(struct priv *p, struct pl_color_space *color,
938953
.out_max = &color->hdr.max_luma
939954
));
940955

941-
color->hdr.min_luma = color->hdr.max_luma / opts->target_contrast;
956+
if (is_hdr && opts->target_contrast_hdr)
957+
color->hdr.min_luma = color->hdr.max_luma / opts->target_contrast_hdr;
958+
else
959+
color->hdr.min_luma = color->hdr.max_luma / opts->target_contrast;
942960
}
943961

944962
static void apply_target_options(struct priv *p, struct pl_frame *target,

0 commit comments

Comments
 (0)