From 10103a28343fe202cf65cc91716ce44375248df3 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Tue, 25 Jul 2023 14:10:08 +0200 Subject: [PATCH] Better color pipeline --- src/gles2_debayer.c | 12 +++++------- src/matrix.h | 10 +++++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/gles2_debayer.c b/src/gles2_debayer.c index 55e5436..0740d71 100644 --- a/src/gles2_debayer.c +++ b/src/gles2_debayer.c @@ -154,15 +154,13 @@ gles2_debayer_configure(GLES2Debayer *self, } glUniform1f(self->uniform_inv_gamma, 1.0f / gamma); - if (calibration.color_matrix_1[0]) { - GLfloat transposed[9]; - float colormat_inv[9]; + if (calibration.forward_matrix_1[0]) { float colormat[9]; - invert_matrix(calibration.color_matrix_1, colormat_inv); - multiply_matrices(xyz_to_srgb, colormat_inv, colormat); - transpose_matrix(colormat, transposed); + float xyz[9]; + multiply_matrices(calibration.forward_matrix_1, XYZD50_to_D65, xyz); + multiply_matrices(xyz, XYZD65_to_sRGB, colormat); glUniformMatrix3fv( - self->uniform_color_matrix, 1, GL_FALSE, transposed); + self->uniform_color_matrix, 1, GL_FALSE, colormat); } else { static const GLfloat identity[9] = { // clang-format off diff --git a/src/matrix.h b/src/matrix.h index 3ab68c7..e4f60fc 100644 --- a/src/matrix.h +++ b/src/matrix.h @@ -1,6 +1,10 @@ -static float xyz_to_srgb[] = { 3.2404542f, -1.5371385f, -0.4985314f, - -0.9692660f, 1.8760108f, 0.0415560f, - 0.0556434f, -0.2040259f, 1.0572252f }; +static float XYZD50_to_D65[] = { 0.9555766f, -0.0230393f, 0.0631636f, + -0.0282895f, 1.0099416f, 0.0210077f, + 0.0122982f, -0.0204830f, 1.3299098f }; + +static float XYZD65_to_sRGB[] = { 3.2406f, -1.5372f, -0.4986f, + -0.9689f, 1.8758f, 0.0415f, + 0.0557f, -0.2040f, 1.0570f }; void multiply_matrices(float a[9], float b[9], float out[9]);