mirror of
https://gitlab.freedesktop.org/wayland/weston.git
synced 2025-12-20 05:50:10 +01:00
color: add Bradford matrix computation
This function is required for media-relative rendering intents. Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
parent
b32f353003
commit
3b3fa61c31
3 changed files with 53 additions and 0 deletions
|
|
@ -152,6 +152,9 @@ weston_normalized_primary_matrix_init(struct weston_mat3f *npm,
|
||||||
const struct weston_color_gamut *gamut,
|
const struct weston_color_gamut *gamut,
|
||||||
enum weston_npm_direction dir);
|
enum weston_npm_direction dir);
|
||||||
|
|
||||||
|
struct weston_mat3f
|
||||||
|
weston_bradford_adaptation(struct weston_CIExy from, struct weston_CIExy to);
|
||||||
|
|
||||||
/** Color primaries known by libweston */
|
/** Color primaries known by libweston */
|
||||||
enum weston_color_primaries {
|
enum weston_color_primaries {
|
||||||
WESTON_PRIMARIES_CICP_SRGB = 0,
|
WESTON_PRIMARIES_CICP_SRGB = 0,
|
||||||
|
|
|
||||||
|
|
@ -1038,3 +1038,35 @@ weston_normalized_primary_matrix_init(struct weston_mat3f *npm,
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Compute linearized Bradford transformation
|
||||||
|
*
|
||||||
|
* \param from Source adapted white point.
|
||||||
|
* \param to Destination adapted white point.
|
||||||
|
* \return Full adaptation matrix.
|
||||||
|
*
|
||||||
|
* Based on ICC.1:2022 (ICC v4.4), annex E.
|
||||||
|
*/
|
||||||
|
WL_EXPORT struct weston_mat3f
|
||||||
|
weston_bradford_adaptation(struct weston_CIExy from, struct weston_CIExy to)
|
||||||
|
{
|
||||||
|
static const struct weston_mat3f bradford = WESTON_MAT3F(
|
||||||
|
0.8951, 0.2664, -0.1614,
|
||||||
|
-0.7502, 1.7135, 0.0367,
|
||||||
|
0.0389, -0.0685, 1.0296
|
||||||
|
);
|
||||||
|
struct weston_mat3f inv;
|
||||||
|
struct weston_vec3f from_cr;
|
||||||
|
struct weston_vec3f to_cr;
|
||||||
|
struct weston_vec3f r;
|
||||||
|
struct weston_mat3f tmp;
|
||||||
|
|
||||||
|
weston_m3f_invert(&inv, bradford);
|
||||||
|
from_cr = weston_m3f_mul_v3f(bradford, CIExy_to_XYZ(from));
|
||||||
|
to_cr = weston_m3f_mul_v3f(bradford, CIExy_to_XYZ(to));
|
||||||
|
r = WESTON_VEC3F(to_cr.x / from_cr.x,
|
||||||
|
to_cr.y / from_cr.y,
|
||||||
|
to_cr.z / from_cr.z);
|
||||||
|
tmp = weston_m3f_mul_m3f(weston_m3f_diag(r), bradford);
|
||||||
|
return weston_m3f_mul_m3f(inv, tmp);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -356,3 +356,21 @@ TEST_P(npm, npm_test_cases)
|
||||||
|
|
||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* https://www.color.org/chadtag.xalter */
|
||||||
|
TEST(bradform_adaptation_D65_D50)
|
||||||
|
{
|
||||||
|
const struct weston_CIExy D65 = { 0.3127, 0.3290 };
|
||||||
|
const struct weston_CIExy D50 = { 0.3457, 0.3585 };
|
||||||
|
const struct weston_mat3f ref = WESTON_MAT3F(
|
||||||
|
1.04790738171017, 0.0229333845542104, -0.0502016347980104,
|
||||||
|
0.0296059594177168, 0.990456039910785, -0.01707552919587,
|
||||||
|
-0.00924679432678241, 0.0150626801401488, 0.751791232609078
|
||||||
|
);
|
||||||
|
struct weston_mat3f M;
|
||||||
|
|
||||||
|
M = weston_bradford_adaptation(D65, D50);
|
||||||
|
test_assert_f32_ge(diff_precision(M, ref), 13);
|
||||||
|
|
||||||
|
return RESULT_OK;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue