diff options
author | Kacper Michajłow <kasper93@gmail.com> | 2023-01-22 14:02:11 +0100 |
---|---|---|
committer | Leo Izen <leo.izen@gmail.com> | 2023-03-02 09:37:06 -0500 |
commit | 9dc4154fecd9ef99b56b3e9e7534142df0ccae92 (patch) | |
tree | d33a040a31fb5e358054e6fefadeb07290f98226 /video | |
parent | 40af0893a94d7effa31a31ef33555271b835c3ad (diff) | |
download | mpv-9dc4154fecd9ef99b56b3e9e7534142df0ccae92.tar.bz2 mpv-9dc4154fecd9ef99b56b3e9e7534142df0ccae92.tar.xz |
vo_gpu: improve XYZ conversion
Fixes #4925
Diffstat (limited to 'video')
-rw-r--r-- | video/csputils.c | 11 | ||||
-rw-r--r-- | video/out/gpu/video.c | 9 |
2 files changed, 14 insertions, 6 deletions
diff --git a/video/csputils.c b/video/csputils.c index a0db6c8cd4..aaa32614b7 100644 --- a/video/csputils.c +++ b/video/csputils.c @@ -619,21 +619,22 @@ void mp_get_cms_matrix(struct mp_csp_primaries src, struct mp_csp_primaries dest mp_mul_matrix3x3(m, tmp); } -// get the coefficients of an SMPTE 428-1 xyz -> rgb conversion matrix +// get the coefficients of an ST 428-1 xyz -> rgb conversion matrix // intent = the rendering intent used to convert to the target primaries static void mp_get_xyz2rgb_coeffs(struct mp_csp_params *params, enum mp_render_intent intent, struct mp_cmat *m) { - struct mp_csp_primaries prim = mp_get_csp_primaries(params->color.primaries); + // Convert to DCI-P3 + struct mp_csp_primaries prim = mp_get_csp_primaries(MP_CSP_PRIM_DCI_P3); float brightness = params->brightness; mp_get_rgb2xyz_matrix(prim, m->m); mp_invert_matrix3x3(m->m); // All non-absolute mappings want to map source white to target white if (intent != MP_INTENT_ABSOLUTE_COLORIMETRIC) { - // SMPTE 428-1 defines the calibration white point as CIE xy (0.314, 0.351) - static const struct mp_csp_col_xy smpte428 = {0.314, 0.351}; - mp_apply_chromatic_adaptation(smpte428, prim.white, m->m); + // SMPTE EG 432-1 Annex H defines the white point as equal energy + static const struct mp_csp_col_xy smpte432 = {1.0/3.0, 1.0/3.0}; + mp_apply_chromatic_adaptation(smpte432, prim.white, m->m); } // Since this outputs linear RGB rather than companded RGB, we diff --git a/video/out/gpu/video.c b/video/out/gpu/video.c index 3f789b6046..df689b53c3 100644 --- a/video/out/gpu/video.c +++ b/video/out/gpu/video.c @@ -2333,7 +2333,7 @@ static void pass_convert_yuv(struct gl_video *p) // Pre-colormatrix input gamma correction if (cparams.color.space == MP_CSP_XYZ) - GLSL(color.rgb = pow(color.rgb, vec3(2.6));) // linear light + pass_linearize(p->sc, p->image_params.color.gamma); // We always explicitly normalize the range in pass_read_video cparams.input_bits = cparams.texture_bits = 0; @@ -2347,6 +2347,13 @@ static void pass_convert_yuv(struct gl_video *p) GLSL(color.rgb = mat3(colormatrix) * color.rgb + colormatrix_c;) + if (cparams.color.space == MP_CSP_XYZ) { + pass_delinearize(p->sc, p->image_params.color.gamma); + // mp_get_csp_matrix implicitly converts XYZ to DCI-P3 + p->image_params.color.space = MP_CSP_RGB; + p->image_params.color.primaries = MP_CSP_PRIM_DCI_P3; + } + if (p->image_params.color.space == MP_CSP_BT_2020_C) { // Conversion for C'rcY'cC'bc via the BT.2020 CL system: // C'bc = (B'-Y'c) / 1.9404 | C'bc <= 0 |