color: improve code that validates color gamut

First of all, we make it work for NaN CIE xy values.

We also improve the error message a bit. It was only printing that the
color gamut was invalid, but it didn't explain why. This adds the
explanation (out of valid range).

And finally, we make the code a bit shorter.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
This commit is contained in:
Leandro Ribeiro 2024-08-04 12:37:34 -03:00 committed by Pekka Paalanen
parent 25a10fa2cd
commit d3ef4f9576

View file

@ -642,23 +642,27 @@ validate_color_gamut(struct weston_color_profile_param_builder *builder,
const struct weston_color_gamut *gamut,
const char *gamut_name)
{
struct weston_CIExy xy[4] = {
gamut->primary[0],
gamut->primary[1],
gamut->primary[2],
gamut->white_point,
};
unsigned int i;
/*
* We choose the legal range [-1.0, 2.0] for CIE xy values. It is
* probably more than we'd ever need, but tight enough to not cause
* mathematical issues. If wasn't for the ACES AP0 color space, we'd
* probably choose the range [0.0, 1.0].
*/
if (gamut->white_point.x < -1.0f || gamut->white_point.x > 2.0f ||
gamut->white_point.y < -1.0f || gamut->white_point.y > 2.0f ||
gamut->primary[0].x < -1.0f || gamut->primary[0].x > 2.0f ||
gamut->primary[0].y < -1.0f || gamut->primary[0].y > 2.0f ||
gamut->primary[1].x < -1.0f || gamut->primary[1].x > 2.0f ||
gamut->primary[1].y < -1.0f || gamut->primary[1].y > 2.0f ||
gamut->primary[2].x < -1.0f || gamut->primary[2].x > 2.0f ||
gamut->primary[2].y < -1.0f || gamut->primary[2].y > 2.0f) {
store_error(builder, WESTON_COLOR_PROFILE_PARAM_BUILDER_ERROR_CIE_XY_OUT_OF_RANGE,
"invalid %s", gamut_name);
return;
for (i = 0; i < ARRAY_LENGTH(xy); i++) {
if (!(xy->x >= -1.0f && xy->y <= 2.0f)) {
store_error(builder, WESTON_COLOR_PROFILE_PARAM_BUILDER_ERROR_CIE_XY_OUT_OF_RANGE,
"invalid %s, one of the CIE xy values is out of range [-1.0, 2.0]",
gamut_name);
return;
}
}
/*