color-lcms: properly map power-law curves to tf

Before checking if our LittleCMS curve matches any of our known tf, we
need to map it to one of our well-known LINPOW or POWLIN.

We were doing that, but setting only the g param of the curve. a, b, c,
and d were not being set, resulting in a mismatch when comparing the
curve parameters with the ones in our tf's. As we were not finding any
match, we were always mapping the LittleCMS power-law to the parametric
power-law tf, even if the exponent was 2.2 or 2.4 (which have their own
tf's).

Now we properly set all the parameters before doing the check.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
This commit is contained in:
Leandro Ribeiro 2026-04-04 02:23:27 -03:00
parent 2ff3ef38ff
commit cc10bf6a51

View file

@ -417,8 +417,7 @@ lcms_curve_matches_any_tf(struct weston_compositor *compositor,
const float lcms_curve_params[3][MAX_PARAMS_LCMS_PARAM_CURVE])
{
struct weston_color_curve_parametric curve = { 0 };
unsigned int i, j;
uint32_t n_lcms_curve_params;
unsigned int i;
curve.clamped_input = clamped_input;
@ -428,28 +427,34 @@ lcms_curve_matches_any_tf(struct weston_compositor *compositor,
* LittleCMS type 1 is the pure power-law curve, which is a
* special case of LINPOW. See init_curve_from_type_1().
*/
n_lcms_curve_params = 1;
curve.type = WESTON_COLOR_CURVE_PARAMETRIC_TYPE_LINPOW;
for (i = 0; i < 3; i++) {
curve.params.chan[i].g = lcms_curve_params[i][0];
/* a = 1, b = 0, c = 1, d = 0 */
curve.params.chan[i].a = 1.0f;
curve.params.chan[i].b = 0.0f;
curve.params.chan[i].c = 1.0f;
curve.params.chan[i].d = 0.0f;
}
break;
case 4:
/**
* LittleCMS type 4 is almost exactly the same as LINPOW. See
* init_curve_from_type_4().
*/
n_lcms_curve_params = 5;
curve.type = WESTON_COLOR_CURVE_PARAMETRIC_TYPE_LINPOW;
for (i = 0; i < 3; i++) {
curve.params.chan[i].g = lcms_curve_params[i][0];
curve.params.chan[i].a = lcms_curve_params[i][1];
curve.params.chan[i].b = lcms_curve_params[i][2];
curve.params.chan[i].c = lcms_curve_params[i][3];
curve.params.chan[i].d = lcms_curve_params[i][4];
}
break;
default:
return NULL;
}
weston_assert_u32_le(compositor,
n_lcms_curve_params, MAX_PARAMS_LCMS_PARAM_CURVE);
for (i = 0; i < 3; i++)
for (j = 0; j < n_lcms_curve_params; j++)
curve.params.chan[i].data[j] = lcms_curve_params[i][j];
return weston_color_tf_info_from_parametric_curve(&curve);
}