Skip to content

Commit 793ab6d

Browse files
committed
options: target-gamut now accepts custom CIE xy primaries
Fixes: #17633
1 parent eda0e0b commit 793ab6d

7 files changed

Lines changed: 61 additions & 6 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`--target-gamut` now accepts custom CIE xy primaries as comma-separated values (Rx,Ry,Gx,Gy,Bx,By,Wx,Wy) in addition to named primary sets

DOCS/man/options.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7366,8 +7366,13 @@ them.
73667366
Constrains the gamut of the display. You can use this option to output e.g.
73677367
DCIP3-in-BT.2020. Set ``--target-prim`` to the primaries of the containing
73687368
colorspace (into which values will be encoded), and ``--target-gamut`` to
7369-
the gamut you want to limit colors to. Takes the same values as
7370-
``--target-prim``. (Only for ``--vo=gpu-next``)
7369+
the gamut you want to limit colors to.
7370+
7371+
Accepts either a named primary set (same values as ``--target-prim``) or
7372+
8 comma-separated CIE xy chromaticity values specifying custom primaries
7373+
in the format ``Rx,Ry,Gx,Gy,Bx,By,Wx,Wy`` (red, green, blue, white point).
7374+
All values must be in the range 0.0-1.0. Use ``--target-gamut=help`` to
7375+
list all named primaries. (Only for ``--vo=gpu-next``)
73717376

73727377
.. note::
73737378

video/csputils.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "mp_image.h"
2929
#include "csputils.h"
30+
#include "common/msg.h"
3031
#include "options/m_config.h"
3132
#include "options/m_option.h"
3233

@@ -586,3 +587,40 @@ enum pl_color_primaries mp_get_best_prim_container(const struct pl_raw_primaries
586587

587588
return container;
588589
}
590+
591+
int mp_parse_raw_primaries(struct mp_log *log, const char *str,
592+
struct pl_raw_primaries *out)
593+
{
594+
if (!str)
595+
return M_OPT_INVALID;
596+
597+
if (!*str)
598+
return M_OPT_MISSING_PARAM;
599+
600+
// Comma-separated CIE xy values: Rx,Ry,Gx,Gy,Bx,By,Wx,Wy
601+
struct pl_raw_primaries prim;
602+
if (sscanf(str, "%f,%f,%f,%f,%f,%f,%f,%f",
603+
&prim.red.x, &prim.red.y, &prim.green.x, &prim.green.y,
604+
&prim.blue.x, &prim.blue.y, &prim.white.x, &prim.white.y) == 8)
605+
{
606+
if (!pl_primaries_valid(&prim))
607+
return M_OPT_OUT_OF_RANGE;
608+
*out = prim;
609+
return 1;
610+
}
611+
612+
const m_option_t choice_opt = {
613+
.priv = (void *)pl_csp_prim_names,
614+
};
615+
616+
int prim_choice;
617+
int ret = m_option_type_choice.parse(log, &choice_opt, bstr0("target-gamut"),
618+
bstr0(str), &prim_choice);
619+
if (ret >= 0) {
620+
*out = *pl_raw_primaries_get(prim_choice);
621+
} else if (ret != M_OPT_MISSING_PARAM) {
622+
mp_info(log, " Rx,Ry,Gx,Gy,Bx,By,Wx,Wy (custom CIE xy primaries)\n");
623+
}
624+
625+
return ret;
626+
}

video/csputils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,7 @@ void mp_map_fixp_color(struct pl_transform3x3 *matrix, int ibits, int in[3],
127127

128128
enum pl_color_primaries mp_get_best_prim_container(const struct pl_raw_primaries *gamut);
129129

130+
int mp_parse_raw_primaries(struct mp_log *log, const char *str,
131+
struct pl_raw_primaries *out);
132+
130133
#endif /* MPLAYER_CSPUTILS_H */

video/out/gpu/video.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ static const struct gl_video_opts gl_video_opts_def = {
413413
};
414414

415415
static OPT_STRING_VALIDATE_FUNC(validate_error_diffusion_opt);
416+
static OPT_STRING_VALIDATE_FUNC(validate_target_gamut);
416417

417418
#define OPT_BASE_STRUCT struct gl_video_opts
418419

@@ -452,7 +453,7 @@ const struct m_sub_options gl_video_conf = {
452453
{"no", 0}, {"input", 1}, {"output", 2}, {"both", 1|2}, {"auto", 1|2|4})},
453454
{"target-contrast", OPT_CHOICE(target_contrast, {"auto", 0}, {"inf", -1}),
454455
M_RANGE(10, 10 / PL_COLOR_HDR_BLACK)},
455-
{"target-gamut", OPT_CHOICE_C(target_gamut, pl_csp_prim_names)},
456+
{"target-gamut", OPT_STRING_VALIDATE(target_gamut, validate_target_gamut)},
456457
{"tone-mapping", OPT_CHOICE(tone_map.curve,
457458
{"auto", TONE_MAPPING_AUTO},
458459
{"clip", TONE_MAPPING_CLIP},
@@ -4331,6 +4332,13 @@ static int validate_error_diffusion_opt(struct mp_log *log, const m_option_t *op
43314332
return r;
43324333
}
43334334

4335+
static int validate_target_gamut(struct mp_log *log, const m_option_t *opt,
4336+
struct bstr name, const char **value)
4337+
{
4338+
struct pl_raw_primaries tmp;
4339+
return mp_parse_raw_primaries(log, *value, &tmp);
4340+
}
4341+
43344342
void gl_video_set_ambient_lux(struct gl_video *p, double lux)
43354343
{
43364344
if (p->opts.gamma_auto) {

video/out/gpu/video.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ struct gl_video_opts {
142142
int sdr_adjust_gamma;
143143
int treat_srgb_as_power22;
144144
int target_contrast;
145-
int target_gamut;
145+
char *target_gamut;
146146
struct gl_tone_map_opts tone_map;
147147
bool correct_downscaling;
148148
bool linear_downscaling;

video/out/vo_gpu_next.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ static void apply_target_options(struct priv *p, struct pl_frame *target,
925925
if ((!target->color.hdr.min_luma || !hint))
926926
apply_target_contrast(p, &target->color, min_luma);
927927
if (opts->target_gamut)
928-
target->color.hdr.prim = *pl_raw_primaries_get(opts->target_gamut);
928+
mp_parse_raw_primaries(mp_null_log, opts->target_gamut, &target->color.hdr.prim);
929929
int dither_depth = opts->dither_depth;
930930
if (dither_depth == 0) {
931931
struct ra_swapchain *sw = p->ra_ctx->swapchain;
@@ -1190,7 +1190,7 @@ static bool draw_frame(struct vo *vo, struct vo_frame *frame)
11901190
if (opts->target_prim)
11911191
hint.primaries = opts->target_prim;
11921192
if (opts->target_gamut)
1193-
hint.hdr.prim = *pl_raw_primaries_get(opts->target_gamut);
1193+
mp_parse_raw_primaries(mp_null_log, opts->target_gamut, &hint.hdr.prim);
11941194
if (opts->target_trc)
11951195
hint.transfer = opts->target_trc;
11961196
if (opts->target_peak)

0 commit comments

Comments
 (0)