Browse Source

Better color pipeline

Martijn Braam 1 year ago
parent
commit
10103a2834
2 changed files with 12 additions and 10 deletions
  1. 5 7
      src/gles2_debayer.c
  2. 7 3
      src/matrix.h

+ 5 - 7
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

+ 7 - 3
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]);