oklab: chad back to D65
authorMingye Wang <arthur2e5@aosc.io>
Sat, 20 Feb 2021 11:38:45 +0000 (19:38 +0800)
committerØyvind "pippin" Kolås <pippin@gimp.org>
Thu, 28 Oct 2021 20:56:06 +0000 (20:56 +0000)
.vscode/settings.json [new file with mode: 0644]
extensions/oklab.c

diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644 (file)
index 0000000..07d7ffe
--- /dev/null
@@ -0,0 +1,6 @@
+{\r
+    "files.associations": {\r
+        "*.jnlp": "xml",\r
+        "babl-internal.h": "c"\r
+    }\r
+}
\ No newline at end of file
index 207869611517792bbb7c61bfab5b7f720fe90ca4..357a069acb3cdbd8e0915b9da6a96e2978c18788 100644 (file)
@@ -140,22 +140,22 @@ formats (void)
 \r
 /* Convertion routine (space definition). */\r
 /* It's all float. The original definition is in float. */\r
-static double[9] M1 = {\r
+static double M1[9] = {\r
   +0.8189330101, +0.0329845436, +0.0482003018,\r
   ​+0.3618667424, ​+0.9293118715, +0.2643662691,\r
   -0.1288597137, +0.0361456387, ​+0.6338517070,\r
 }\r
 \r
-static double[9] M2 = {\r
+static double M2[9] = {\r
   +0.2104542553, +0.7936177850, - 0.0040720468,\r
   +1.9779984951, -2.4285922050, + 0.4505937099,\r
   +0.0259040371, +0.7827717662, - 0.8086757660,\r
 }\r
 \r
-static float[9] M1f;\r
-static float[9] M2f;\r
-static float[9] inv_M1f;\r
-static float[9] inv_M2f;\r
+static float M1f[9];\r
+static float M2f[9];\r
+static float inv_M1f[9];\r
+static float inv_M2f[9];\r
 static int mat_ready;\r
 \r
 /* fast approximate cube root\r
@@ -184,7 +184,7 @@ _cbrtf (float x)
 static inline void\r
 XYZ_to_Oklab_step (float *xyz, float *lab_out)\r
 {\r
-  float[3] lms;\r
+  float lms[3];\r
   babl_matrix_mul_vectorff (M1f, xyz, lms);\r
   for (int i = 0; i < 3; i++)\r
     {\r
@@ -196,7 +196,7 @@ XYZ_to_Oklab_step (float *xyz, float *lab_out)
 static inline void\r
 Oklab_to_XYZ_step (float *lab, float *xyz_out)\r
 {\r
-  float[3] lms;\r
+  float lms[3];\r
   babl_matrix_mul_vectorff (inv_M2f, lab, lms);\r
   for (int i = 0; i < 3; i++)\r
     {\r
@@ -237,7 +237,7 @@ xyz_to_Oklch_step (float *xyz, float *lch_out)
 static inline void\r
 Oklch_to_XYZ_step (float *lch, float *xyz_out)\r
 {\r
-  float[3] lab = { lch[0], lch[1], lch[2] };\r
+  float lab[3] = { lch[0], lch[1], lch[2] };\r
   ch_to_ab_step (lab + 1, lab + 1);\r
   Oklab_to_XYZ_step (lab, xyz_out);\r
 }\r
@@ -245,12 +245,14 @@ Oklch_to_XYZ_step (float *lch, float *xyz_out)
 static inline void\r
 constants ()\r
 {\r
-  /* FIXME: babl xyz is D50. Should adapt back to D65xy (0.3127, 0.3290) before\r
-   * doing M1, but babl_chromatic_adaptation_matrix is private :( */\r
   if (mat_ready)\r
     return;\r
 \r
-  double[9] tmp;\r
+  double tmp[9];\r
+  double D65[3] = {0.95047, 1.0, 1.08883};\r
+  double D50[3] = {0.96420288, 1.0, 0.82490540};\r
+  babl_chromatic_adaptation_matrix (D50, D65, tmp);\r
+  babl_matrix_mul_matrix (tmp, M1, M1);\r
 \r
   babl_matrix_invert (M1, tmp);\r
   babl_matrix_to_float (tmp, inv_M1f);\r