From c76e4abb604d751763c7b7c51a3b9663a511ffc8 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Tue, 10 May 2022 16:26:52 +0300 Subject: [PATCH] tests/color_util: add lcmsMAT3_invert() Needed to invert device-to-PCS color transformation matrices. Signed-off-by: Pekka Paalanen --- tests/color_util.c | 44 +++++++++++++++++++++++++++++++++++++++++++- tests/color_util.h | 3 +++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/tests/color_util.c b/tests/color_util.c index cc4d3fab..86d426f1 100644 --- a/tests/color_util.c +++ b/tests/color_util.c @@ -23,13 +23,17 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ + #include "config.h" + #include -#include "color_util.h" #include #include #include #include + +#include +#include "color_util.h" #include "shared/helpers.h" static_assert(sizeof(struct color_float) == 4 * sizeof(float), @@ -288,3 +292,41 @@ process_pixel_using_pipeline(enum transfer_fn pre_curve, cf = color_float_apply_matrix(mat, cf); *out = color_float_apply_curve(post_curve, 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->d[c * 4 + 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->d[c * 4 + 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); + assert(ret == 0); + lcmsMAT3_from_weston_matrix(result, &inv); +} diff --git a/tests/color_util.h b/tests/color_util.h index 14fd6095..ec442b80 100644 --- a/tests/color_util.h +++ b/tests/color_util.h @@ -109,3 +109,6 @@ color_float_apply_matrix(const struct lcmsMAT3 *mat, struct color_float c); enum transfer_fn transfer_fn_invert(enum transfer_fn fn); + +void +lcmsMAT3_invert(struct lcmsMAT3 *result, const struct lcmsMAT3 *mat);