vo_gpu: improve XYZ conversion

Fixes #4925
This commit is contained in:
Kacper Michajłow 2023-01-22 14:02:11 +01:00 committed by Leo Izen
parent 40af0893a9
commit 9dc4154fec
2 changed files with 14 additions and 6 deletions

View File

@ -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

View File

@ -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