Skip to content

Commit 11e8253

Browse files
committed
video/out/gpu/video: add --sdr-adjust-gamma
1 parent 5f87424 commit 11e8253

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
add `--treat-srgb-as-power22`
2+
add `--sdr-adjust-gamma`

DOCS/man/options.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7354,6 +7354,36 @@ them.
73547354
transfer function is SDR. This way you can control SDR output separately
73557355
from HDR output.
73567356

7357+
``--sdr-adjust-gamma=<auto|yes|no>``
7358+
SDR transfer functions are often ambiguous or mismatched. Even if files are
7359+
tagged with a specific function (e.g. ``bt.709``), the actual content may
7360+
not match. For example, most screen capture software tags its output as
7361+
``bt.709``, but the content is usually a direct sRGB capture.
7362+
7363+
On the target side, "sRGB" is also ambiguous, some displays are factory
7364+
calibrated to a pure power 2.2 gamma, while others may use the sRGB
7365+
piecewise curve. Both of which are typically configured as "sRGB" in the
7366+
swapchain configuration. Similar inconsistencies exist across compositor
7367+
implementations of color management, as different platforms handle this in
7368+
different ways. See also ``--treat-srgb-as-power22``.
7369+
Additionally, ``bt.1886`` requires display contrast ratio to be known for
7370+
correct rendering, which is often unavailable. Use``--target-contrast`` to
7371+
specify it.
7372+
7373+
This option controls whether SDR content should have its gamma adjusted.
7374+
It only applies to the "sRGB" swapchain target configuration, since that is
7375+
the most common and ambiguous case. If set to ``no``, content tagged as
7376+
``sRGB``, ``gamma2.2`` or ``bt.1886`` will be rendered as-is. If set to
7377+
``yes``, it will be converted based on the available metadata.
7378+
7379+
``auto`` (default) behaves like ``no``, except when ``--target-trc`` is
7380+
explicitly set, in which case it behaves like ``yes``.
7381+
7382+
Generally it's recommended to enable this option, if you can ensure that
7383+
both source and target metadata is correct.
7384+
7385+
(Only for ``--vo=gpu-next``)
7386+
73577387
``--treat-srgb-as-power22=<no|input|output|both|auto>``
73587388
When enabled, sRGB is (de)linearized using a pure power 2.2 curve instead of
73597389
the standard sRGB piecewise transfer function.

video/out/gpu/video.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ const struct m_sub_options gl_video_conf = {
446446
M_RANGE(10, 10000)},
447447
{"hdr-reference-white", OPT_CHOICE(hdr_reference_white, {"auto", 0}),
448448
M_RANGE(10, 10000)},
449+
{"sdr-adjust-gamma", OPT_CHOICE(sdr_adjust_gamma,
450+
{"auto", 0}, {"yes", 1}, {"no", -1})},
449451
{"treat-srgb-as-power22", OPT_CHOICE(treat_srgb_as_power22,
450452
{"no", 0}, {"input", 1}, {"output", 2}, {"both", 1|2}, {"auto", 1|2|4})},
451453
{"target-contrast", OPT_CHOICE(target_contrast, {"auto", 0}, {"inf", -1}),

video/out/gpu/video.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ struct gl_video_opts {
139139
int target_trc;
140140
int target_peak;
141141
int hdr_reference_white;
142+
int sdr_adjust_gamma;
142143
int treat_srgb_as_power22;
143144
int target_contrast;
144145
int target_gamut;

video/out/vo_gpu_next.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,17 @@ static bool draw_frame(struct vo *vo, struct vo_frame *frame)
12531253
pl_frame_from_swapchain(&target, &swframe);
12541254
bool strict_sw_params = target_hint && !pass_colorspace && p->next_opts->target_hint_strict;
12551255
apply_target_options(p, &target, hint.hdr.min_luma, strict_sw_params);
1256+
if (target.color.transfer == PL_COLOR_TRC_SRGB && frame->current &&
1257+
((opts->sdr_adjust_gamma == 0 && opts->target_trc == PL_COLOR_TRC_UNKNOWN) ||
1258+
opts->sdr_adjust_gamma == -1))
1259+
{
1260+
switch (frame->current->params.color.transfer) {
1261+
case PL_COLOR_TRC_BT_1886:
1262+
case PL_COLOR_TRC_GAMMA22:
1263+
case PL_COLOR_TRC_SRGB:
1264+
target.color.transfer = frame->current->params.color.transfer;
1265+
}
1266+
}
12561267
if (target.color.transfer == PL_COLOR_TRC_SRGB) {
12571268
// sRGB reference display is pure 2.2 power function, see IEC 61966-2-1-1999.
12581269
if (opts->treat_srgb_as_power22 & 2)

0 commit comments

Comments
 (0)