diff --git a/tests/color-icc-output-test.c b/tests/color-icc-output-test.c index 72be452aa..20c1b98e4 100644 --- a/tests/color-icc-output-test.c +++ b/tests/color-icc-output-test.c @@ -27,6 +27,7 @@ #include "config.h" #include +#include #include "weston-test-client-helper.h" #include "weston-test-assert.h" @@ -57,9 +58,7 @@ const struct lcms_pipeline pipeline_sRGB = { .Blue = { 0.150, 0.060, 1.0 } }, .pre_fn = TRANSFER_FN_SRGB_EOTF, - .mat = LCMSMAT3(1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0), + .mat = WESTON_MAT3F_IDENTITY, .post_fn = TRANSFER_FN_SRGB_EOTF_INVERSE }; @@ -71,7 +70,8 @@ const struct lcms_pipeline pipeline_adobeRGB = { .Blue = { 0.150, 0.060, 1.0 } }, .pre_fn = TRANSFER_FN_SRGB_EOTF, - .mat = LCMSMAT3( 0.715127, 0.284868, 0.000005, + .mat = WESTON_MAT3F( + 0.715127, 0.284868, 0.000005, 0.000001, 0.999995, 0.000004, -0.000003, 0.041155, 0.958848), .post_fn = TRANSFER_FN_ADOBE_RGB_EOTF_INVERSE @@ -85,7 +85,8 @@ const struct lcms_pipeline pipeline_BT2020 = { .Blue = { 0.131, 0.046, 1.0 } }, .pre_fn = TRANSFER_FN_SRGB_EOTF, - .mat = LCMSMAT3(0.627402, 0.329292, 0.043306, + .mat = WESTON_MAT3F( + 0.627402, 0.329292, 0.043306, 0.069095, 0.919544, 0.011360, 0.016394, 0.088028, 0.895578), /* this is equivalent to BT.1886 with zero black level */ @@ -354,7 +355,7 @@ process_pipeline_comparison(const struct buffer *src_buf, pix_shot = a8r8g8b8_to_float(row_ptr_shot[x]); process_pixel_using_pipeline(arg->pipeline->pre_fn, - &arg->pipeline->mat, + arg->pipeline->mat, arg->pipeline->post_fn, arg->vcgt_exponents, &pix_src, &pix_src_pipeline); @@ -437,7 +438,7 @@ convert_to_blending_space(const struct lcms_pipeline *pip, * or simply output space without the non-linear encoding */ cf = color_float_apply_curve(pip->pre_fn, cf); - return color_float_apply_matrix(&pip->mat, cf); + return color_float_apply_matrix(pip->mat, cf); } static void diff --git a/tests/color-management-test.c b/tests/color-management-test.c index c24f63880..9b27b1979 100644 --- a/tests/color-management-test.c +++ b/tests/color-management-test.c @@ -25,6 +25,8 @@ #include "config.h" +#include + #include "color-properties.h" #include "weston-test-client-helper.h" #include "weston-test-fixture-compositor.h" @@ -60,9 +62,7 @@ const struct lcms_pipeline pipeline_sRGB = { .Blue = { 0.150, 0.060, 1.0 } }, .pre_fn = TRANSFER_FN_SRGB_EOTF, - .mat = LCMSMAT3(1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0), + .mat = WESTON_MAT3F_IDENTITY, .post_fn = TRANSFER_FN_SRGB_EOTF_INVERSE }; diff --git a/tests/color_util.c b/tests/color_util.c index 413da9860..5112798b1 100644 --- a/tests/color_util.c +++ b/tests/color_util.c @@ -32,7 +32,7 @@ #include #include -#include +#include #include "color_util.h" #include "weston-test-runner.h" #include "weston-test-assert.h" @@ -303,23 +303,14 @@ color_float_unpremult(struct color_float in) * Returns the result of the matrix-vector multiplication mat * c. */ struct color_float -color_float_apply_matrix(const struct lcmsMAT3 *mat, struct color_float c) +color_float_apply_matrix(struct weston_mat3f mat, struct color_float c) { - struct color_float result; - unsigned i, j; + struct weston_vec3f v = weston_m3f_mul_v3f(mat, WESTON_VEC3F(c.r, c.g, c.b)); - /* - * The matrix has an array of columns, hence i indexes to rows and - * j indexes to columns. - */ - for (i = 0; i < 3; i++) { - result.rgb[i] = 0.0f; - for (j = 0; j < 3; j++) - result.rgb[i] += mat->v[j].n[i] * c.rgb[j]; - } - - result.a = c.a; - return result; + return (struct color_float){ + .rgb = { v.r, v.g, v.b }, + .a = c.a, + }; } bool @@ -336,7 +327,7 @@ should_include_vcgt(const double vcgt_exponents[COLOR_CHAN_NUM]) void process_pixel_using_pipeline(enum transfer_fn pre_curve, - const struct lcmsMAT3 *mat, + struct weston_mat3f mat, enum transfer_fn post_curve, const double vcgt_exponents[COLOR_CHAN_NUM], const struct color_float *in, @@ -356,44 +347,6 @@ process_pixel_using_pipeline(enum transfer_fn pre_curve, *out = cf; } -static void -weston_matrix_from_lcmsMAT3(struct weston_matrix *w, const struct lcmsMAT3 *m) -{ - unsigned r, c; - - /* column-major */ - weston_matrix_init(w); - - for (c = 0; c < 3; c++) { - for (r = 0; r < 3; r++) - w->M.col[c].el[r] = m->v[c].n[r]; - } -} - -static void -lcmsMAT3_from_weston_matrix(struct lcmsMAT3 *m, const struct weston_matrix *w) -{ - unsigned r, c; - - for (c = 0; c < 3; c++) { - for (r = 0; r < 3; r++) - m->v[c].n[r] = w->M.col[c].el[r]; - } -} - -void -lcmsMAT3_invert(struct lcmsMAT3 *result, const struct lcmsMAT3 *mat) -{ - struct weston_matrix inv; - struct weston_matrix w; - int ret; - - weston_matrix_from_lcmsMAT3(&w, mat); - ret = weston_matrix_invert(&inv, &w); - test_assert_int_eq(ret, 0); - lcmsMAT3_from_weston_matrix(result, &inv); -} - /** Update scalar statistics * * \param stat The statistics structure to update. diff --git a/tests/color_util.h b/tests/color_util.h index 52a765c3f..4785ab7e8 100644 --- a/tests/color_util.h +++ b/tests/color_util.h @@ -30,6 +30,8 @@ #include #include +#include + enum color_chan_index { COLOR_CHAN_R = 0, COLOR_CHAN_G, @@ -48,19 +50,6 @@ struct color_float { float a; }; -/* column vector */ -struct lcmsVEC3 { - float n[3]; -}; - -/* - * While LittleCMS' cmsMAT3 is row-major, this here is colum-major. - */ -struct lcmsMAT3 { - /* array of columns */ - struct lcmsVEC3 v[3]; -}; - enum transfer_fn { TRANSFER_FN_IDENTITY, TRANSFER_FN_SRGB_EOTF, @@ -71,24 +60,6 @@ enum transfer_fn { TRANSFER_FN_POWER2_4_EOTF_INVERSE, }; -/* - * A helper to lay out a matrix in the natural writing order in code - * instead of needing to transpose in your mind every time you read it. - * The matrix is laid out as written: - * ⎡ a11 a12 a13 ⎤ - * ⎢ a21 a22 a23 ⎥ - * ⎣ a31 a32 a33 ⎦ - * where the first digit is row and the second digit is column. - */ -#define LCMSMAT3(a11, a12, a13, \ - a21, a22, a23, \ - a31, a32, a33) ((struct lcmsMAT3) \ - { /* Each vector is a column => looks like a transpose */ \ - .v[0] = { .n = { a11, a21, a31} }, \ - .v[1] = { .n = { a12, a22, a32} }, \ - .v[2] = { .n = { a13, a23, a33} }, \ - }) - void sRGB_linearize(struct color_float *cf); @@ -109,7 +80,7 @@ should_include_vcgt(const double vcgt_exponents[COLOR_CHAN_NUM]); void process_pixel_using_pipeline(enum transfer_fn pre_curve, - const struct lcmsMAT3 *mat, + struct weston_mat3f mat, enum transfer_fn post_curve, const double vcgt_exponents[COLOR_CHAN_NUM], const struct color_float *in, @@ -122,7 +93,7 @@ struct color_float color_float_apply_curve(enum transfer_fn fn, struct color_float c); struct color_float -color_float_apply_matrix(const struct lcmsMAT3 *mat, struct color_float c); +color_float_apply_matrix(struct weston_mat3f mat, struct color_float c); enum transfer_fn transfer_fn_invert(enum transfer_fn fn); @@ -130,9 +101,6 @@ transfer_fn_invert(enum transfer_fn fn); const char * transfer_fn_name(enum transfer_fn fn); -void -lcmsMAT3_invert(struct lcmsMAT3 *result, const struct lcmsMAT3 *mat); - /** Scalar statistics * * See scalar_stat_update(). diff --git a/tests/lcms_util.h b/tests/lcms_util.h index 78feefa65..dc18be9b6 100644 --- a/tests/lcms_util.h +++ b/tests/lcms_util.h @@ -26,6 +26,7 @@ #pragma once #include +#include #include "color_util.h" @@ -46,7 +47,7 @@ struct lcms_pipeline { /** * Transform matrix from sRGB to target chromaticities in prim_output */ - struct lcmsMAT3 mat; + struct weston_mat3f mat; /** * tone curve enum */