From d3ef4f9576118028d5244ee628853090bd34ea2a Mon Sep 17 00:00:00 2001 From: Leandro Ribeiro Date: Sun, 4 Aug 2024 12:37:34 -0300 Subject: [PATCH] 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 --- libweston/color-profile-param-builder.c | 26 ++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/libweston/color-profile-param-builder.c b/libweston/color-profile-param-builder.c index 7587ae56f..bb903e66e 100644 --- a/libweston/color-profile-param-builder.c +++ b/libweston/color-profile-param-builder.c @@ -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; + } } /*