Run up to 8 iterations of Gauss-Newton, choose the best error

We're seeing profiles that really stress the limits of this
strategy, so we're probably going to have change our approach.
For now, this dramatically improves the results on the last
two profiles we've received via bug reports.

Bug: chromium:869115
Bug: chromium:1017960

Change-Id: I2565e3eb3f67d1e957ec6211f11d818f922c92d8
Reviewed-on: https://skia-review.googlesource.com/c/skcms/+/254189
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/profiles/color.org/Upper_Left.icc.txt b/profiles/color.org/Upper_Left.icc.txt
index bdadebe..da07519 100644
--- a/profiles/color.org/Upper_Left.icc.txt
+++ b/profiles/color.org/Upper_Left.icc.txt
@@ -20,11 +20,11 @@
  A2B : "M", Matrix, "B"
  "M" : 3 inputs
   M0 : 16-bit table with 256 entries
-  ~= : 3.278764, 0.6213684, 0.2607365, 1.412451, 0.003921569, -0.006866455, 0 (Max error: 0.367269) (D-gap: 0.000154649) (f(1) = 0.65572)
+  ~= : 2.034415, 1, -6.80238e-06, 1.290439, 0.05490196, 0.06838989, 0 (Max error: 0.162423) (D-gap: 0.000268772) (f(1) = 1.06838)
   M1 : 16-bit table with 256 entries
-  ~= : 3.278764, 0.6213684, 0.2607365, 1.412451, 0.003921569, -0.006866455, 0 (Max error: 0.367269) (D-gap: 0.000154649) (f(1) = 0.65572)
+  ~= : 2.034415, 1, -6.80238e-06, 1.290439, 0.05490196, 0.06838989, 0 (Max error: 0.162423) (D-gap: 0.000268772) (f(1) = 1.06838)
   M2 : 16-bit table with 256 entries
-  ~= : 3.278764, 0.6213684, 0.2607365, 1.412451, 0.003921569, -0.006866455, 0 (Max error: 0.367269) (D-gap: 0.000154649) (f(1) = 0.65572)
+  ~= : 2.034415, 1, -6.80238e-06, 1.290439, 0.05490196, 0.06838989, 0 (Max error: 0.162423) (D-gap: 0.000268772) (f(1) = 1.06838)
 Mtrx : | 0.959396958 0.84733814 0.314814538 -0.503105104 |
        | 0.489433438 1.57752109 0.133390293 -0.521812081 |
        | 0.0305781476 0.213589266 1.57086837 -0.430443883 |
diff --git a/profiles/color.org/Upper_Right.icc.txt b/profiles/color.org/Upper_Right.icc.txt
index 3005af2..1e74a0c 100644
--- a/profiles/color.org/Upper_Right.icc.txt
+++ b/profiles/color.org/Upper_Right.icc.txt
@@ -22,11 +22,11 @@
 CLUT : 2 x 2 x 2 (16 bpp)
  "M" : 3 inputs
   M0 : 16-bit table with 256 entries
-  ~= : 5.635474, 0.536911, 0.3392392, 0.9400777, 0.05882353, 0.05212021, 0 (Max error: 0.362454) (D-gap: 0.000554256) (f(1) = 0.52655)
+  ~= : 2.470196, 1, -9.961426e-06, 0.9400777, 0.05882353, 0.05463409, 0 (Max error: 0.168172) (D-gap: 0.000247952) (f(1) = 1.05461)
   M1 : 16-bit table with 256 entries
-  ~= : 5.635474, 0.536911, 0.3392392, 0.9400777, 0.05882353, 0.05212021, 0 (Max error: 0.362454) (D-gap: 0.000554256) (f(1) = 0.52655)
+  ~= : 2.470196, 1, -9.961426e-06, 0.9400777, 0.05882353, 0.05463409, 0 (Max error: 0.168172) (D-gap: 0.000247952) (f(1) = 1.05461)
   M2 : 16-bit table with 256 entries
-  ~= : 5.635474, 0.536911, 0.3392392, 0.9400777, 0.05882353, 0.05212021, 0 (Max error: 0.362454) (D-gap: 0.000554256) (f(1) = 0.52655)
+  ~= : 2.470196, 1, -9.961426e-06, 0.9400777, 0.05882353, 0.05463409, 0 (Max error: 0.168172) (D-gap: 0.000247952) (f(1) = 1.05461)
 Mtrx : | 2.20205379 1.94485557 0.72255367 -0.733356714 |
        | 1.12339592 3.6207943 0.306147665 -0.760608494 |
        | 0.0701893568 0.490257412 3.60553575 -0.62743181 |
diff --git a/profiles/fuzz/fit_pq.icc.txt b/profiles/fuzz/fit_pq.icc.txt
index 93a0b93..776fd54 100644
--- a/profiles/fuzz/fit_pq.icc.txt
+++ b/profiles/fuzz/fit_pq.icc.txt
@@ -8,8 +8,14 @@
  'kTRC' : 'curv' :    110 : 32
 
 rTRC : 16-bit table with 5 entries
+  ~= : 1, 1, 7.629395e-06, 0.003997864, 0.5, -0.4979935, 0 (Max error: 0.745052) (D-gap: 1.52283e-05) (f(1) = 0.502007)
 gTRC : 16-bit table with 5 entries
+  ~= : 1, 1, 7.629395e-06, 0.003997864, 0.5, -0.4979935, 0 (Max error: 0.745052) (D-gap: 1.52283e-05) (f(1) = 0.502007)
 bTRC : 16-bit table with 5 entries
+  ~= : 1, 1, 7.629395e-06, 0.003997864, 0.5, -0.4979935, 0 (Max error: 0.745052) (D-gap: 1.52283e-05) (f(1) = 0.502007)
+Best : 1, 1, 7.629395e-06, 0.003997864, 0.5, -0.4979935, 0 (D-gap: 1.52283e-05) (f(1) = 0.502007)
+Inv  : 1, 1, 0.4979935, 250.1336, 0.001998932, 0, -0 (D-gap: -1.90735e-06) (f(1) = 1.49799)
+Best Error: | 0.745052 0.745052 0.745052 |
  XYZ : | 0.95799255 0 0 |
        | 0 1.0027313 0 |
        | 0 0 0.81640625 |
diff --git a/profiles/fuzz/inf_a.icc.txt b/profiles/fuzz/inf_a.icc.txt
index cd86e3a..fcdfc95 100644
--- a/profiles/fuzz/inf_a.icc.txt
+++ b/profiles/fuzz/inf_a.icc.txt
@@ -12,14 +12,14 @@
  'kTRC' : 'curv' :    544 : 388
 
 rTRC : 16-bit table with 257 entries
-  ~= : 0.03983583, 0.1516733, -0.0005732282, 0.1250019, 0.00390625, -0.6482544, 0 (Max error: 1.84306e+06) (D-gap: 0.000110619) (f(1) = 0.27919)
+  ~= : 0.07488938, 0.007860422, -3.070464e-05, 0.1250019, 0.00390625, -0.1817474, 0 (Max error: 1181.7) (D-gap: 5.7213e-05) (f(1) = 0.513702)
 gTRC : 16-bit table with 257 entries
-  ~= : 0.03983583, 0.1516733, -0.0005732282, 0.1250019, 0.00390625, -0.6482544, 0 (Max error: 1.84306e+06) (D-gap: 0.000110619) (f(1) = 0.27919)
+  ~= : 0.07488938, 0.007860422, -3.070464e-05, 0.1250019, 0.00390625, -0.1817474, 0 (Max error: 1181.7) (D-gap: 5.7213e-05) (f(1) = 0.513702)
 bTRC : 16-bit table with 257 entries
-  ~= : 0.03983583, 0.1516733, -0.0005732282, 0.1250019, 0.00390625, -0.6482544, 0 (Max error: 1.84306e+06) (D-gap: 0.000110619) (f(1) = 0.27919)
-Best : 0.03983583, 0.1516733, -0.0005732282, 0.1250019, 0.00390625, -0.6482544, 0 (D-gap: 0.000110619) (f(1) = 0.27919)
-Inv  : 25.10303, 1.07798, 0.6988053, 7.999878, 0.0004882887, 0.005870819, -0 (D-gap: 0.00209078) (f(1) = 1.84306e+06)
-Best Error: | 1.84306e+06 1.84306e+06 1.84306e+06 |
+  ~= : 0.07488938, 0.007860422, -3.070464e-05, 0.1250019, 0.00390625, -0.1817474, 0 (Max error: 1181.7) (D-gap: 5.7213e-05) (f(1) = 0.513702)
+Best : 0.07488938, 0.007860422, -3.070464e-05, 0.1250019, 0.00390625, -0.1817474, 0 (D-gap: 5.7213e-05) (f(1) = 0.513702)
+Inv  : 13.35303, 1.437515, 0.2612647, 7.999878, 0.0004882887, 0.003726959, -0 (D-gap: -0.000179274) (f(1) = 1181.82)
+Best Error: | 1181.7 1181.7 1181.7 |
  XYZ : | 0.9614258 0 0 |
        | 0 1.0004883 0 |
        | 0 0 0.82470703 |
diff --git a/profiles/fuzz/inverse_tf_adb_negative.icc.txt b/profiles/fuzz/inverse_tf_adb_negative.icc.txt
index 08a3352..47f6b50 100644
--- a/profiles/fuzz/inverse_tf_adb_negative.icc.txt
+++ b/profiles/fuzz/inverse_tf_adb_negative.icc.txt
@@ -18,8 +18,11 @@
  'gTRC' : 'curv' :   2080 : 508
 
 rTRC : 16-bit table with 1024 entries
+  ~= : 11.04649, 1, -0.0009775171, 0.4995193, 0.0009775171, 0.0003890991, 0 (Max error: 1) (D-gap: -9.91896e-05) (f(1) = 0.989616)
 gTRC : 16-bit table with 1024 entries
+  ~= : 11.04649, 1, -0.0009775171, 0.4995193, 0.0009775171, 0.0003890991, 0 (Max error: 1) (D-gap: -9.91896e-05) (f(1) = 0.989616)
 bTRC : 16-bit table with 1024 entries
+  ~= : 11.04649, 1, -0.0009775171, 0.4995193, 0.0009775171, 0.0003890991, 0 (Max error: 1) (D-gap: -9.91896e-05) (f(1) = 0.989616)
  XYZ : | 8224.125 8224.125 8224.125 |
        | 8224.125 8224.125 8224.125 |
        | -0.0034179688 8224.125 8224.125 |
diff --git a/profiles/fuzz/inverse_tf_huge_g.icc.txt b/profiles/fuzz/inverse_tf_huge_g.icc.txt
index 88ea7fe..162d8be 100644
--- a/profiles/fuzz/inverse_tf_huge_g.icc.txt
+++ b/profiles/fuzz/inverse_tf_huge_g.icc.txt
@@ -10,8 +10,14 @@
  'kTRC' : 'curv' :    244 : 212
 
 rTRC : 16-bit table with 43 entries
+  ~= : 2.985061, 1, -1.594611e-05, 41.95129, 0.02380952, 0.9988265, 0 (Max error: 0.97938) (D-gap: 4.17233e-07) (f(1) = 1.99879)
 gTRC : 16-bit table with 43 entries
+  ~= : 2.985061, 1, -1.594611e-05, 41.95129, 0.02380952, 0.9988265, 0 (Max error: 0.97938) (D-gap: 4.17233e-07) (f(1) = 1.99879)
 bTRC : 16-bit table with 43 entries
+  ~= : 2.985061, 1, -1.594611e-05, 41.95129, 0.02380952, 0.9988265, 0 (Max error: 0.97938) (D-gap: 4.17233e-07) (f(1) = 1.99879)
+Best : 2.985061, 1, -1.594611e-05, 41.95129, 0.02380952, 0.9988265, 0 (D-gap: 4.17233e-07) (f(1) = 1.99879)
+Inv  : 0.3350015, 1, -0.9988265, 0.02383717, 0.9988403, 3.814697e-06, -0 (D-gap: -0.000247927) (f(1) = 0.104296)
+Best Error: | 0.97938 0.97938 0.97938 |
  XYZ : | 0.9642029 0 0 |
        | 0 1 0 |
        | 0 0 0.8249054 |
diff --git a/profiles/fuzz/inverse_tf_not_invertible.icc.txt b/profiles/fuzz/inverse_tf_not_invertible.icc.txt
index 8dcd999..8f416d3 100644
--- a/profiles/fuzz/inverse_tf_not_invertible.icc.txt
+++ b/profiles/fuzz/inverse_tf_not_invertible.icc.txt
@@ -16,14 +16,14 @@
  'bTRC' : 'curv' :   8204 : 320
 
 rTRC : 16-bit table with 4096 entries
-  ~= : 3.239427, 0.7659531, 0.7326652, 0.07707816, 0.04078144, -0.4143219, 0 (Max error: 0.761265) (D-gap: 0.000436735) (f(1) = 3.29344)
+  ~= : 1.403709, 0.9121704, 0.2242268, 0.07707816, 0.04078144, -0.1487198, 0 (Max error: 0.662578) (D-gap: 0.00021739) (f(1) = 1.04768)
 gTRC : 16-bit table with 4096 entries
-  ~= : 3.239427, 0.7659531, 0.7326652, 0.07707816, 0.04078144, -0.4143219, 0 (Max error: 0.761265) (D-gap: 0.000436735) (f(1) = 3.29344)
+  ~= : 1.403709, 0.9121704, 0.2242268, 0.07707816, 0.04078144, -0.1487198, 0 (Max error: 0.662578) (D-gap: 0.00021739) (f(1) = 1.04768)
 bTRC : 16-bit table with 4096 entries
-  ~= : 3.239427, 0.7659531, 0.7326652, 0.07707816, 0.04078144, -0.4143219, 0 (Max error: 0.761265) (D-gap: 0.000436735) (f(1) = 3.29344)
-Best : 3.239427, 0.7659531, 0.7326652, 0.07707816, 0.04078144, -0.4143219, 0 (D-gap: 0.000436735) (f(1) = 3.29344)
-Inv  : 0.3086966, 2.37207, 0.9828007, 12.97384, 0.003143358, -0.9564362, -0 (D-gap: -0.00023884) (f(1) = 0.496567)
-Best Error: | 0.761265 0.761265 0.761265 |
+  ~= : 1.403709, 0.9121704, 0.2242268, 0.07707816, 0.04078144, -0.1487198, 0 (Max error: 0.662578) (D-gap: 0.00021739) (f(1) = 1.04768)
+Best : 1.403709, 0.9121704, 0.2242268, 0.07707816, 0.04078144, -0.1487198, 0 (D-gap: 0.00021739) (f(1) = 1.04768)
+Inv  : 0.7123984, 1.137833, 0.1692182, 12.97384, 0.003143358, -0.2457199, -0 (D-gap: -0.000215951) (f(1) = 0.964401)
+Best Error: | 0.662578 0.662578 0.662578 |
  XYZ : | 0.43606567 0.3850708 0.14305115 |
        | 0.22250366 0.71687317 0.06060791 |
        | 0.013916016 0.09706116 0.71398926 |
diff --git a/profiles/fuzz/nan_s.icc.txt b/profiles/fuzz/nan_s.icc.txt
index db820b1..a2e14b5 100644
--- a/profiles/fuzz/nan_s.icc.txt
+++ b/profiles/fuzz/nan_s.icc.txt
@@ -8,14 +8,14 @@
  'kTRC' : 'curv' :    528 : 48
 
 rTRC : 16-bit table with 258 entries
-  ~= : 0.2315896, 0.001808926, 0.0004575932, 206.8078, 0.00389105, 0.635603, 0 (Max error: 6.768) (D-gap: -2.68221e-06) (f(1) = 0.879673)
+  ~= : 2.025319, 1, 2.325047e-06, 206.8078, 0.00389105, 0.8047485, 0 (Max error: 0.999377) (D-gap: 6.19888e-05) (f(1) = 1.80476)
 gTRC : 16-bit table with 258 entries
-  ~= : 0.2315896, 0.001808926, 0.0004575932, 206.8078, 0.00389105, 0.635603, 0 (Max error: 6.768) (D-gap: -2.68221e-06) (f(1) = 0.879673)
+  ~= : 2.025319, 1, 2.325047e-06, 206.8078, 0.00389105, 0.8047485, 0 (Max error: 0.999377) (D-gap: 6.19888e-05) (f(1) = 1.80476)
 bTRC : 16-bit table with 258 entries
-  ~= : 0.2315896, 0.001808926, 0.0004575932, 206.8078, 0.00389105, 0.635603, 0 (Max error: 6.768) (D-gap: -2.68221e-06) (f(1) = 0.879673)
-Best : 0.2315896, 0.001808926, 0.0004575932, 206.8078, 0.00389105, 0.635603, 0 (D-gap: -2.68221e-06) (f(1) = 0.879673)
-Inv  : 4.317984, 4.316589, -2.743637, 0.004835406, 0.8046997, -0.2521896, -0 (D-gap: 0.000728548) (f(1) = 6.81654)
-Best Error: | 6.768 6.768 6.768 |
+  ~= : 2.025319, 1, 2.325047e-06, 206.8078, 0.00389105, 0.8047485, 0 (Max error: 0.999377) (D-gap: 6.19888e-05) (f(1) = 1.80476)
+Best : 2.025319, 1, 2.325047e-06, 206.8078, 0.00389105, 0.8047485, 0 (D-gap: 6.19888e-05) (f(1) = 1.80476)
+Inv  : 0.4937495, 1, -0.8046997, 0.004835406, 0.8046997, -3.051758e-05, -0 (D-gap: -0.00392157) (f(1) = 0.446409)
+Best Error: | 0.999377 0.999377 0.999377 |
  XYZ : | 0.95739746 0 0 |
        | 0 1.0083008 0 |
        | 0 0 0.8161621 |
diff --git a/profiles/fuzz/negative_a_when_inverted.icc.txt b/profiles/fuzz/negative_a_when_inverted.icc.txt
index 8c157bb..ec6f323 100644
--- a/profiles/fuzz/negative_a_when_inverted.icc.txt
+++ b/profiles/fuzz/negative_a_when_inverted.icc.txt
@@ -8,8 +8,14 @@
  'kTRC' : 'curv' :    102 : 32
 
 rTRC : 16-bit table with 41 entries
+  ~= : 3.471169, 1, -7.677823e-06, 10.00992, 0.05, 0.500597, 0 (Max error: 0.987463) (D-gap: 0.000131547) (f(1) = 1.50057)
 gTRC : 16-bit table with 41 entries
+  ~= : 3.471169, 1, -7.677823e-06, 10.00992, 0.05, 0.500597, 0 (Max error: 0.987463) (D-gap: 0.000131547) (f(1) = 1.50057)
 bTRC : 16-bit table with 41 entries
+  ~= : 3.471169, 1, -7.677823e-06, 10.00992, 0.05, 0.500597, 0 (Max error: 0.987463) (D-gap: 0.000131547) (f(1) = 1.50057)
+Best : 3.471169, 1, -7.677823e-06, 10.00992, 0.05, 0.500597, 0 (D-gap: 0.000131547) (f(1) = 1.50057)
+Inv  : 0.2880874, 1, -0.5004959, 0.09990092, 0.5004959, -2.288818e-05, -0 (D-gap: -0.0500229) (f(1) = 0.81871)
+Best Error: | 0.987463 0.987463 0.987463 |
  XYZ : | 0.95751953 0 0 |
        | 0 1.0004883 0 |
        | 0 0 0.82029724 |
diff --git a/profiles/fuzz/one_d_clut.icc.txt b/profiles/fuzz/one_d_clut.icc.txt
index ea2f08f..6842b1f 100644
--- a/profiles/fuzz/one_d_clut.icc.txt
+++ b/profiles/fuzz/one_d_clut.icc.txt
@@ -20,10 +20,11 @@
 CLUT : 2 (16 bpp)
  "M" : 3 inputs
   M0 : 16-bit table with 256 entries
+  ~= : 2.470196, 1, -9.961426e-06, 0.9400777, 0.05882353, 0.05463409, 0 (Max error: 0.235662) (D-gap: 0.000247952) (f(1) = 1.05461)
   M1 : 16-bit table with 256 entries
-  ~= : 2.556935, 0.8069916, 0.1048158, 1.058366, 0.003921569, 0.0008773804, 0 (Max error: 0.473545) (D-gap: 0.000101503) (f(1) = 0.790394)
+  ~= : 2.470196, 1, -9.961426e-06, 0.9400777, 0.05882353, 0.05463409, 0 (Max error: 0.388634) (D-gap: 0.000247952) (f(1) = 1.05461)
   M2 : 16-bit table with 256 entries
-  ~= : 2.512288, 0.9082756, 0.1125738, 1.058366, 0.003921569, -8.392334e-05, 0 (Max error: 0.194256) (D-gap: 0.00024071) (f(1) = 1.05297)
+  ~= : 2.470196, 1, -9.961426e-06, 0.9400777, 0.05882353, 0.05463409, 0 (Max error: 0.172776) (D-gap: 0.000247952) (f(1) = 1.05461)
 Mtrx : | 2.20205379 1.94485557 4.72249269 -0.733356714 |
        | 1.12339592 3.6207943 0.306147665 -0.760608494 |
        | 0.0701893568 0.490257412 3.60553575 -0.62743181 |
diff --git a/profiles/fuzz/polytf_nan_after_update.icc.txt b/profiles/fuzz/polytf_nan_after_update.icc.txt
index 69b2efe..686138b 100644
--- a/profiles/fuzz/polytf_nan_after_update.icc.txt
+++ b/profiles/fuzz/polytf_nan_after_update.icc.txt
@@ -17,9 +17,11 @@
  'bTRC' : 'curv' :    524 : 1592
 
 rTRC : 16-bit table with 256 entries
+  ~= : 3.045648, 1, -5.939649e-05, 32, 0.003921569, 0.1258659, 0 (Max error: 0.913669) (D-gap: 0.000375792) (f(1) = 1.12568)
 gTRC : 16-bit table with 256 entries
+  ~= : 3.045648, 1, -5.939649e-05, 32, 0.003921569, 0.1258659, 0 (Max error: 0.772618) (D-gap: 0.000375792) (f(1) = 1.12568)
 bTRC : 16-bit table with 256 entries
-  ~= : 0.0886098, 25.71094, -0.1004161, 254.1323, 0.003921569, 0.4954681, 0 (Max error: 0.996099) (D-gap: 7.62939e-06) (f(1) = 1.82837)
+  ~= : 3.045648, 1, 0.0003229971, 254.1323, 0.003921569, 0.9965984, 0 (Max error: 0.975963) (D-gap: 1.13249e-06) (f(1) = 1.99757)
  XYZ : | 8224.125 8224.125 8224.125 |
        | 8224.125 8224.125 8224.125 |
        | 8224.125 8224.125 8224.125 |
diff --git a/profiles/misc/BenQ_GL2450.icc.txt b/profiles/misc/BenQ_GL2450.icc.txt
index 5afe421..24d672f 100644
--- a/profiles/misc/BenQ_GL2450.icc.txt
+++ b/profiles/misc/BenQ_GL2450.icc.txt
@@ -21,14 +21,14 @@
  'bTRC' : 'curv' :   2060 : 4936
 
 rTRC : 16-bit table with 1024 entries
-  ~= : 1.999662, 0.9999352, 0.009358991, 0, 0, -0.0001144409, 0 (Max error: 0.0113029) (f(1) = 1.01849)
+  ~= : 1.993112, 1.001831, -0, 0, 0, -1.525879e-05, 0 (Max error: 0.00890554) (f(1) = 1.00362)
 gTRC : 16-bit table with 1024 entries
-  ~= : 1.999662, 0.9999352, 0.009358991, 0, 0, -0.0001144409, 0 (Max error: 0.0113029) (f(1) = 1.01849)
+  ~= : 1.993112, 1.001831, -0, 0, 0, -1.525879e-05, 0 (Max error: 0.00890554) (f(1) = 1.00362)
 bTRC : 16-bit table with 1024 entries
-  ~= : 1.999662, 0.9999352, 0.009358991, 0, 0, -0.0001144409, 0 (Max error: 0.0113029) (f(1) = 1.01849)
-Best : 1.999662, 0.9999352, 0.009358991, 0, 0, -0.0001144409, 0 (f(1) = 1.01849)
-Inv  : 0.5000845, 1.00013, 0.0001144558, 0, 0, -0.009284973, 0 (f(1) = 0.990837)
-Best Error: | 0.0113029 0.0113029 0.0113029 |
+  ~= : 1.993112, 1.001831, -0, 0, 0, -1.525879e-05, 0 (Max error: 0.00890554) (f(1) = 1.00362)
+Best : 1.993112, 1.001831, -0, 0, 0, -1.525879e-05, 0 (f(1) = 1.00362)
+Inv  : 0.5017281, 0.9963799, 1.520355e-05, 0, 0, -2.288818e-05, 0 (f(1) = 0.998169)
+Best Error: | 0.00890554 0.00890554 0.00890554 |
  XYZ : | 0.38839722 0.40229797 0.20140076 |
        | 0.19389343 0.7411041 0.065093994 |
        | 0.010299683 0.061203003 1.0146027 |
diff --git a/profiles/misc/BenQ_RL2455.icc.txt b/profiles/misc/BenQ_RL2455.icc.txt
index 5a81e4f..151b950 100644
--- a/profiles/misc/BenQ_RL2455.icc.txt
+++ b/profiles/misc/BenQ_RL2455.icc.txt
@@ -31,25 +31,25 @@
  'K071' : 'ui08' :     10 : 52024
 
 rTRC : 16-bit table with 5 entries
-  ~= : 2.201905, 0.9993172, 0.000747185, 0.189456, 0.25, -0.0001144409, 0 (Max error: 0.0248416) (D-gap: 2.13832e-06) (f(1) = 1.00002)
+  ~= : 2.201753, 0.9993706, 0.0006862282, 0.189456, 0.25, -9.918213e-05, 0 (Max error: 0.0248302) (D-gap: 7.38353e-06) (f(1) = 1.00002)
 gTRC : 16-bit table with 5 entries
-  ~= : 2.201905, 0.9993172, 0.000747185, 0.189456, 0.25, -0.0001144409, 0 (Max error: 0.0248416) (D-gap: 2.13832e-06) (f(1) = 1.00002)
+  ~= : 2.201753, 0.9993706, 0.0006862282, 0.189456, 0.25, -9.918213e-05, 0 (Max error: 0.0248302) (D-gap: 7.38353e-06) (f(1) = 1.00002)
 bTRC : 16-bit table with 5 entries
-  ~= : 2.201905, 0.9993172, 0.000747185, 0.189456, 0.25, -0.0001144409, 0 (Max error: 0.0248416) (D-gap: 2.13832e-06) (f(1) = 1.00002)
-Best : 2.201905, 0.9993172, 0.000747185, 0.189456, 0.25, -0.0001144409, 0 (D-gap: 2.13832e-06) (f(1) = 1.00002)
-Inv  : 0.4541523, 1.001511, 0.0001146138, 5.27827, 0.047364, -0.0007400513, -0 (D-gap: -1.89245e-06) (f(1) = 0.999992)
-Best Error: | 0.0248416 0.0248416 0.0248416 |
+  ~= : 2.201753, 0.9993706, 0.0006862282, 0.189456, 0.25, -9.918213e-05, 0 (Max error: 0.0248302) (D-gap: 7.38353e-06) (f(1) = 1.00002)
+Best : 2.201753, 0.9993706, 0.0006862282, 0.189456, 0.25, -9.918213e-05, 0 (D-gap: 7.38353e-06) (f(1) = 1.00002)
+Inv  : 0.4541835, 1.001389, 9.931985e-05, 5.27827, 0.047364, -0.0006790161, -0 (D-gap: -1.71512e-05) (f(1) = 0.999985)
+Best Error: | 0.0248302 0.0248302 0.0248302 |
  XYZ : | 0.4651947 0.35595703 0.14302063 |
        | 0.23188782 0.6815338 0.08656311 |
        | 0.009918213 0.09286499 0.72210693 |
  A2B : "A", CLUT, "B"
  "A" : 3 inputs
   A0 : 16-bit table with 256 entries
-  ~= : 2.199462, 1.000076, -0.0001402027, 0.005188067, 0.01176471, -7.629395e-06, 0 (Max error: 0.00392157) (D-gap: -1.30855e-05) (f(1) = 0.999855)
+  ~= : 2.199956, 1, -7.76723e-07, 0.005188067, 0.01176471, -3.051758e-05, 0 (Max error: 0.00392157) (D-gap: -3.46322e-05) (f(1) = 0.999985)
   A1 : 16-bit table with 256 entries
-  ~= : 2.199462, 1.000076, -0.0001402027, 0.005188067, 0.01176471, -7.629395e-06, 0 (Max error: 0.00392157) (D-gap: -1.30855e-05) (f(1) = 0.999855)
+  ~= : 2.199956, 1, -7.76723e-07, 0.005188067, 0.01176471, -3.051758e-05, 0 (Max error: 0.00392157) (D-gap: -3.46322e-05) (f(1) = 0.999985)
   A2 : 16-bit table with 256 entries
-  ~= : 2.199462, 1.000076, -0.0001402027, 0.005188067, 0.01176471, -7.629395e-06, 0 (Max error: 0.00392157) (D-gap: -1.30855e-05) (f(1) = 0.999855)
+  ~= : 2.199956, 1, -7.76723e-07, 0.005188067, 0.01176471, -3.051758e-05, 0 (Max error: 0.00392157) (D-gap: -3.46322e-05) (f(1) = 0.999985)
 CLUT : 16 x 16 x 16 (16 bpp)
  "B" : 3 outputs
   B0 : 16-bit table with 4096 entries
diff --git a/profiles/misc/Coated_FOGRA27_CMYK.icc.txt b/profiles/misc/Coated_FOGRA27_CMYK.icc.txt
index 0d24e19..b5f7c9d 100644
--- a/profiles/misc/Coated_FOGRA27_CMYK.icc.txt
+++ b/profiles/misc/Coated_FOGRA27_CMYK.icc.txt
@@ -19,13 +19,13 @@
  A2B : "A", CLUT, "B"
  "A" : 4 inputs
   A0 : 16-bit table with 256 entries
-  ~= : 1.161658, 0.965477, 0.08204222, 0.8236057, 0.02352941, -0.05311584, 0 (Max error: 0.00190735) (D-gap: 0.000240505) (f(1) = 1.00216)
+  ~= : 1.160143, 0.9660683, 0.08091594, 0.8236057, 0.02352941, -0.0524826, 0 (Max error: 0.00185394) (D-gap: 0.000224769) (f(1) = 1.00209)
   A1 : 16-bit table with 256 entries
-  ~= : 1.185196, 0.9845772, 0.0416452, 0.7782102, 0.01960784, -0.02090454, 0 (Max error: 0.00865173) (D-gap: 0.000137096) (f(1) = 1.01015)
+  ~= : 1.144584, 1, -8.940697e-07, 0.7782102, 0.01960784, 0.004161835, 0 (Max error: 0.00600672) (D-gap: 7.39656e-06) (f(1) = 1.00418)
   A2 : 16-bit table with 256 entries
-  ~= : 1.187326, 0.9800682, 0.03831189, 0.7821012, 0.03529412, -0.01689911, 0 (Max error: 0.00418091) (D-gap: 0.000131184) (f(1) = 1.00489)
+  ~= : 1.187467, 0.9799652, 0.03853871, 0.7821012, 0.03529412, -0.0170517, 0 (Max error: 0.00417328) (D-gap: 0.000124509) (f(1) = 1.00488)
   A3 : 16-bit table with 256 entries
-  ~= : 1.788781, 0.7681046, 0.3830559, 0.7655641, 0.01568628, -0.1776505, 0 (Max error: 0.0762317) (D-gap: 0.000264938) (f(1) = 1.10848)
+  ~= : 1.394918, 0.9022636, 0.1104887, 0.7655641, 0.01568628, -0.04253387, 0 (Max error: 0.0248531) (D-gap: 0.000222261) (f(1) = 0.975243)
 CLUT : 9 x 9 x 9 x 9 (16 bpp)
  "B" : 3 outputs
   B0 : 1, 1, 0, 0, 0, 0, 0 (f(1) = 1) (~Identity)
diff --git a/profiles/misc/Coated_FOGRA39_CMYK.icc.txt b/profiles/misc/Coated_FOGRA39_CMYK.icc.txt
index 75d74c6..90177f7 100644
--- a/profiles/misc/Coated_FOGRA39_CMYK.icc.txt
+++ b/profiles/misc/Coated_FOGRA39_CMYK.icc.txt
@@ -23,13 +23,13 @@
  A2B : "A", CLUT, "B"
  "A" : 4 inputs
   A0 : 16-bit table with 256 entries
-  ~= : 1.054374, 1.018814, -0.007990699, 0.8365758, 0.007843138, 0.006622314, 0 (Max error: 0.0168037) (D-gap: 6.0935e-05) (f(1) = 1.018)
+  ~= : 1.054482, 1.018707, -0.007989861, 0.8365758, 0.007843138, 0.006626129, 0 (Max error: 0.0167007) (D-gap: 6.47497e-05) (f(1) = 1.01789)
   A1 : 16-bit table with 256 entries
   ~= : 1.113842, 1.019768, 0.006776623, 0.7665369, 0.007843138, -0.003089905, 0 (Max error: 0.0232544) (D-gap: 4.07971e-05) (f(1) = 1.02643)
   A2 : 16-bit table with 256 entries
-  ~= : 1.181166, 0.9961662, 0.03711115, 0.7081712, 0.007843138, -0.01995087, 0 (Max error: 0.0163422) (D-gap: 0.000101243) (f(1) = 1.01937)
+  ~= : 1.098878, 1.066177, -0.1630624, 0.7986631, 0.1529412, 0.1223068, 0 (Max error: 0.0139961) (D-gap: 0.000158347) (f(1) = 1.01624)
   A3 : 16-bit table with 256 entries
-  ~= : 1.671706, 0.8024101, 0.3172798, 0.7159533, 0.007843137, -0.1457214, 0 (Max error: 0.0433578) (D-gap: 0.000295554) (f(1) = 1.06207)
+  ~= : 1.253323, 1, -8.940697e-07, 0.7159533, 0.007843137, 0.003326416, 0 (Max error: 0.0246906) (D-gap: 7.42497e-06) (f(1) = 1.00334)
 CLUT : 11 x 11 x 11 x 11 (16 bpp)
  "B" : 3 outputs
   B0 : 1, 1, 0, 0, 0, 0, 0 (f(1) = 1) (~Identity)
diff --git a/profiles/misc/ColorLogic_ISO_Coated_CMYK.icc.txt b/profiles/misc/ColorLogic_ISO_Coated_CMYK.icc.txt
index 14035e3..2704028 100644
--- a/profiles/misc/ColorLogic_ISO_Coated_CMYK.icc.txt
+++ b/profiles/misc/ColorLogic_ISO_Coated_CMYK.icc.txt
@@ -23,11 +23,11 @@
  A2B : "A", CLUT, "B"
  "A" : 4 inputs
   A0 : 16-bit table with 256 entries
-  ~= : 0.4499924, 7.476257, 4.947246, 1.200778, 0.01960784, -2.056915, 0 (Max error: 0.0593643) (D-gap: -7.66497e-05) (f(1) = 1.05045)
+  ~= : 0.8066898, 1, -4.139543e-05, 1.245091, 0.3372549, 0.003826141, 0 (Max error: 0.0194793) (D-gap: -3.12328e-05) (f(1) = 1.0038)
   A1 : 16-bit table with 256 entries
-  ~= : 0.4521776, 7.18457, 4.681381, 1.205447, 0.01960784, -2.013153, 0 (Max error: 0.0558319) (D-gap: -7.66553e-05) (f(1) = 1.04721)
+  ~= : 0.8070059, 1, -3.948808e-05, 1.244774, 0.3372549, 0.003868103, 0 (Max error: 0.0195671) (D-gap: -2.35736e-05) (f(1) = 1.00385)
   A2 : 16-bit table with 256 entries
-  ~= : 0.7746541, 0.9274139, -0.1297604, 1.241552, 0.1490196, 0.1603584, 0 (Max error: 0.0166886) (D-gap: 9.95845e-05) (f(1) = 0.999653)
+  ~= : 0.7474884, 0.9664421, -0.1072783, 1.241552, 0.1490196, 0.1005783, 0 (Max error: 0.0143543) (D-gap: 0.000175521) (f(1) = 0.993221)
   A3 : 16-bit table with 256 entries
   ~= : 0.7854362, 0.9449272, -0.01005363, 1.182879, 0.01568628, 0.00359726, 0 (Max error: 0.0640945) (D-gap: 5.65797e-05) (f(1) = 0.951984)
 CLUT : 17 x 17 x 17 x 17 (16 bpp)
diff --git a/profiles/misc/DisplayCal_ASUS_NonMonotonic.icc.txt b/profiles/misc/DisplayCal_ASUS_NonMonotonic.icc.txt
index 8c9607d..0b05379 100644
--- a/profiles/misc/DisplayCal_ASUS_NonMonotonic.icc.txt
+++ b/profiles/misc/DisplayCal_ASUS_NonMonotonic.icc.txt
@@ -31,25 +31,25 @@
  'meta' : 'dict' :   2312 : 738448
 
 rTRC : 16-bit table with 256 entries
-  ~= : 2.006128, 1.167313, -0.1089448, 0.03579767, 0.1176471, 0.003585815, 0 (Max error: 0.0831201) (D-gap: 0.000162528) (f(1) = 1.12387)
+  ~= : 2.298276, 1, -2.088398e-05, 0.03579767, 0.1176471, -0.003074646, 0 (Max error: 0.0831201) (D-gap: 1.95443e-05) (f(1) = 0.996887)
 gTRC : 16-bit table with 256 entries
-  ~= : 2.287943, 0.9762955, 0.03624173, 0.03112842, 0.1921569, -0.02638245, 0 (Max error: 0.0558824) (D-gap: 0.000189447) (f(1) = 1.00244)
+  ~= : 2.272159, 1, -5.811453e-06, 0.03112842, 0.1921569, -0.01746368, 0 (Max error: 0.0558824) (D-gap: 0.000121736) (f(1) = 0.982525)
 bTRC : 16-bit table with 256 entries
-  ~= : 2.463363, 1.063622, 0.02862149, 1.546164e-09, 0.02352941, -0.000541687, 0 (Max error: 0.152941) (D-gap: 0.000200205) (f(1) = 1.24191)
-Best : 2.463363, 1.063622, 0.02862149, 1.546164e-09, 0.02352941, -0.000541687, 0 (D-gap: 0.000200205) (f(1) = 1.24191)
-Inv  : 0.4059491, 0.8591919, 0.0004654131, 6.467617e+08, 3.638034e-11, -0.02680969, -0 (D-gap: -0.00594747) (f(1) = 0.913582)
-Best Error: | 0.11724 0.104035 0.152941 |
+  ~= : 2.330241, 1, -4.805624e-07, 1.546164e-09, 0.02352941, -0.0001525879, 0 (Max error: 0.152941) (D-gap: 7.89479e-06) (f(1) = 0.999863)
+Best : 2.330241, 1, -4.805624e-07, 1.546164e-09, 0.02352941, -0.0001525879, 0 (D-gap: 7.89479e-06) (f(1) = 0.999863)
+Inv  : 0.4291402, 1, 0.0001525879, 6.467617e+08, 3.638034e-11, 0, -0 (D-gap: -0.000505093) (f(1) = 1.00006)
+Best Error: | 0.100611 0.0871768 0.152941 |
  XYZ : | 0.43673706 0.38032532 0.1471405 |
        | 0.21763611 0.72984314 0.052520752 |
        | 0.0026550293 0.06440735 0.75782776 |
  A2B : "A", CLUT, "B"
  "A" : 3 inputs
   A0 : 16-bit table with 2049 entries
-  ~= : 0.9956406, 1.001862, -0.1228046, 1.000015, 0.125, 0.1227303, 0 (Max error: 0.0187137) (D-gap: 0.00022085) (f(1) = 1.00217)
+  ~= : 1.000023, 1, -0, 1.000015, 0.125, 0, 0 (Max error: 0.0181866) (D-gap: -6.67572e-06) (f(1) = 1) (~Identity)
   A1 : 16-bit table with 2049 entries
-  ~= : 0.9935906, 1.002388, -0.1220437, 1.000015, 0.125, 0.1218605, 0 (Max error: 0.0171154) (D-gap: 0.000234798) (f(1) = 1.00281)
+  ~= : 1.000023, 1, -0, 1.000015, 0.125, 0, 0 (Max error: 0.0163393) (D-gap: -6.67572e-06) (f(1) = 1) (~Identity)
   A2 : 16-bit table with 2049 entries
-  ~= : 0.9960349, 1.003311, -0.02821074, 1.000015, 0.03125, 0.02817535, 0 (Max error: 0.020617) (D-gap: 0.000140041) (f(1) = 1.00331)
+  ~= : 1.001317, 1, 2.384186e-07, 1.000015, 0.03125, 0.000125885, 0 (Max error: 0.0195436) (D-gap: -1.65701e-05) (f(1) = 1.00014) (~Identity)
 CLUT : 33 x 33 x 33 (16 bpp)
  "B" : 3 outputs
   B0 : 1, 1, 0, 0, 0, 0, 0 (f(1) = 1) (~Identity)
diff --git a/profiles/misc/Dot_Gain_20_Grayscale.icc.txt b/profiles/misc/Dot_Gain_20_Grayscale.icc.txt
index cf691f8..07ba151 100644
--- a/profiles/misc/Dot_Gain_20_Grayscale.icc.txt
+++ b/profiles/misc/Dot_Gain_20_Grayscale.icc.txt
@@ -12,13 +12,13 @@
  'kTRC' : 'curv' :    524 : 388
 
 rTRC : 16-bit table with 256 entries
-  ~= : 1.73703, 0.9999313, 3.373019e-05, 0.06290532, 0.02352941, -1.525879e-05, 0 (Max error: 0.000202144) (D-gap: -7.88318e-06) (f(1) = 0.999931)
+  ~= : 1.736919, 1, -3.613532e-07, 0.06290532, 0.02352941, 0, 0 (Max error: 0.000202144) (D-gap: 4.44008e-06) (f(1) = 1.00002)
 gTRC : 16-bit table with 256 entries
-  ~= : 1.73703, 0.9999313, 3.373019e-05, 0.06290532, 0.02352941, -1.525879e-05, 0 (Max error: 0.000202144) (D-gap: -7.88318e-06) (f(1) = 0.999931)
+  ~= : 1.736919, 1, -3.613532e-07, 0.06290532, 0.02352941, 0, 0 (Max error: 0.000202144) (D-gap: 4.44008e-06) (f(1) = 1.00002)
 bTRC : 16-bit table with 256 entries
-  ~= : 1.73703, 0.9999313, 3.373019e-05, 0.06290532, 0.02352941, -1.525879e-05, 0 (Max error: 0.000202144) (D-gap: -7.88318e-06) (f(1) = 0.999931)
-Best : 1.73703, 0.9999313, 3.373019e-05, 0.06290532, 0.02352941, -1.525879e-05, 0 (D-gap: -7.88318e-06) (f(1) = 0.999931)
-Inv  : 0.5756955, 1.000122, 1.526065e-05, 15.89691, 0.001480125, -3.051758e-05, -0 (D-gap: 7.43829e-05) (f(1) = 1.00005)
+  ~= : 1.736919, 1, -3.613532e-07, 0.06290532, 0.02352941, 0, 0 (Max error: 0.000202144) (D-gap: 4.44008e-06) (f(1) = 1.00002)
+Best : 1.736919, 1, -3.613532e-07, 0.06290532, 0.02352941, 0, 0 (D-gap: 4.44008e-06) (f(1) = 1.00002)
+Inv  : 0.5757321, 1, -0, 15.89691, 0.001480125, -1.525879e-05, -0 (D-gap: -5.66281e-05) (f(1) = 0.999985)
 Best Error: | 0.000202144 0.000202144 0.000202144 |
  XYZ : | 0.9642029 0 0 |
        | 0 1 0 |
diff --git a/profiles/misc/Japan_Color_2001_Coated.icc.txt b/profiles/misc/Japan_Color_2001_Coated.icc.txt
index 789cb6c..bc5d969 100644
--- a/profiles/misc/Japan_Color_2001_Coated.icc.txt
+++ b/profiles/misc/Japan_Color_2001_Coated.icc.txt
@@ -19,13 +19,13 @@
  A2B : "A", CLUT, "B"
  "A" : 4 inputs
   A0 : 16-bit table with 256 entries
-  ~= : 1.0495, 1.034943, 0.003219063, 0.5252918, 0.003921569, -0.003570557, 0 (Max error: 0.0335426) (D-gap: 7.2716e-05) (f(1) = 1.03641)
+  ~= : 1.019037, 1, -6.263144e-07, 0.5252918, 0.003921569, -0.001449585, 0 (Max error: 0.0260987) (D-gap: 1.86695e-05) (f(1) = 0.998566)
   A1 : 16-bit table with 256 entries
   ~= : 1.117985, 1.022064, -0.02805667, 0.6270149, 0.02745098, 0.01732254, 0 (Max error: 0.00931168) (D-gap: 0.000110364) (f(1) = 1.01061)
   A2 : 16-bit table with 256 entries
-  ~= : 1.159545, 0.9914627, 0.03615639, 0.3346303, 0.003921568, -0.02250671, 0 (Max error: 0.00820923) (D-gap: 0.000145535) (f(1) = 1.0095)
+  ~= : 1.153396, 0.9972305, 0.02092885, 0.3346303, 0.003921568, -0.01270294, 0 (Max error: 0.00709534) (D-gap: 7.538e-05) (f(1) = 1.0082)
   A3 : 16-bit table with 256 entries
-  ~= : 1.517888, 0.8733749, 0.1790551, 0.3229572, 0.003921569, -0.07411957, 0 (Max error: 0.0159897) (D-gap: 0.000226001) (f(1) = 1.00636)
+  ~= : 1.283242, 1, -8.650124e-06, 0.5892779, 0.03529412, 0.007137299, 0 (Max error: 0.0155337) (D-gap: 2.102e-05) (f(1) = 1.00714)
 CLUT : 9 x 9 x 9 x 9 (16 bpp)
  "B" : 3 outputs
   B0 : 1, 1, 0, 0, 0, 0, 0 (f(1) = 1) (~Identity)
diff --git a/profiles/misc/Kodak_sRGB.icc.txt b/profiles/misc/Kodak_sRGB.icc.txt
index c321094..f2705a2 100644
--- a/profiles/misc/Kodak_sRGB.icc.txt
+++ b/profiles/misc/Kodak_sRGB.icc.txt
@@ -21,14 +21,14 @@
  'bTRC' : 'curv' :    524 : 149844
 
 rTRC : 16-bit table with 256 entries
-  ~= : 2.384167, 0.9483299, 0.03699977, 1.070039, 0.003921569, 0.003894806, 0 (Max error: 0.0147646) (D-gap: 0.000183304) (f(1) = 0.969177)
+  ~= : 2.429111, 0.937191, 0.06168338, 1.070039, 0.003921569, 0.003055573, 0 (Max error: 0.00426031) (D-gap: 0.000184181) (f(1) = 1.00032)
 gTRC : 16-bit table with 256 entries
-  ~= : 2.384167, 0.9483299, 0.03699977, 1.070039, 0.003921569, 0.003894806, 0 (Max error: 0.0147646) (D-gap: 0.000183304) (f(1) = 0.969177)
+  ~= : 2.429111, 0.937191, 0.06168338, 1.070039, 0.003921569, 0.003055573, 0 (Max error: 0.00426031) (D-gap: 0.000184181) (f(1) = 1.00032)
 bTRC : 16-bit table with 256 entries
-  ~= : 2.384167, 0.9483299, 0.03699977, 1.070039, 0.003921569, 0.003894806, 0 (Max error: 0.0147646) (D-gap: 0.000183304) (f(1) = 0.969177)
-Best : 2.384167, 0.9483299, 0.03699977, 1.070039, 0.003921569, 0.003894806, 0 (D-gap: 0.000183304) (f(1) = 0.969177)
-Inv  : 0.4194337, 1.135002, -0.004420613, 0.9345455, 0.004196231, -0.03895569, -0 (D-gap: -0.00769717) (f(1) = 1.01379)
-Best Error: | 0.0147646 0.0147646 0.0147646 |
+  ~= : 2.429111, 0.937191, 0.06168338, 1.070039, 0.003921569, 0.003055573, 0 (Max error: 0.00426031) (D-gap: 0.000184181) (f(1) = 1.00032)
+Best : 2.429111, 0.937191, 0.06168338, 1.070039, 0.003921569, 0.003055573, 0 (D-gap: 0.000184181) (f(1) = 1.00032)
+Inv  : 0.4116732, 1.170876, -0.003577695, 0.9345455, 0.004196231, -0.06580353, -0 (D-gap: -0.00415665) (f(1) = 0.99987)
+Best Error: | 0.00426031 0.00426031 0.00426031 |
  XYZ : | 0.43763733 0.38841248 0.14241028 |
        | 0.21495056 0.7129059 0.072128296 |
        | 0.011260986 0.080718994 0.72587585 |
diff --git a/profiles/misc/MR2416GSDF.icc.txt b/profiles/misc/MR2416GSDF.icc.txt
index d36d6aa..4036b3f 100644
--- a/profiles/misc/MR2416GSDF.icc.txt
+++ b/profiles/misc/MR2416GSDF.icc.txt
@@ -18,14 +18,14 @@
  'bTRC' : 'curv' :    524 : 1592
 
 rTRC : 16-bit table with 256 entries
-  ~= : 3.713728, 0.8151588, 0.1128933, 0.04863813, 0.01568628, 0.0004997253, 0 (Max error: 0.0891655) (D-gap: 0.000188509) (f(1) = 0.75806)
+  ~= : 6.107902, 0.5691719, 0.4350795, 0.04863813, 0.01568628, -0.005722046, 0 (Max error: 0.0100443) (D-gap: 0.000529933) (f(1) = 1.02042)
 gTRC : 16-bit table with 256 entries
-  ~= : 3.713728, 0.8151588, 0.1128933, 0.04863813, 0.01568628, 0.0004997253, 0 (Max error: 0.0891655) (D-gap: 0.000188509) (f(1) = 0.75806)
+  ~= : 6.107902, 0.5691719, 0.4350795, 0.04863813, 0.01568628, -0.005722046, 0 (Max error: 0.0100443) (D-gap: 0.000529933) (f(1) = 1.02042)
 bTRC : 16-bit table with 256 entries
-  ~= : 3.713728, 0.8151588, 0.1128933, 0.04863813, 0.01568628, 0.0004997253, 0 (Max error: 0.0891655) (D-gap: 0.000188509) (f(1) = 0.75806)
-Best : 3.713728, 0.8151588, 0.1128933, 0.04863813, 0.01568628, 0.0004997253, 0 (D-gap: 0.000188509) (f(1) = 0.75806)
-Inv  : 0.2692712, 2.136414, -0.00106762, 20.56, 0.0007629511, -0.1383667, -0 (D-gap: -0.0207493) (f(1) = 1.08822)
-Best Error: | 0.0891655 0.0891655 0.0891655 |
+  ~= : 6.107902, 0.5691719, 0.4350795, 0.04863813, 0.01568628, -0.005722046, 0 (Max error: 0.0100443) (D-gap: 0.000529933) (f(1) = 1.02042)
+Best : 6.107902, 0.5691719, 0.4350795, 0.04863813, 0.01568628, -0.005722046, 0 (D-gap: 0.000529933) (f(1) = 1.02042)
+Inv  : 0.1637223, 31.27466, 0.178955, 20.56, 0.0007629511, -0.7644653, -0 (D-gap: -0.0100443) (f(1) = 0.994202)
+Best Error: | 0.0100443 0.0100443 0.0100443 |
  XYZ : | 0.4459076 0.3938141 0.13781738 |
        | 0.22624207 0.73461914 0.053771973 |
        | 0.004348755 0.08099365 0.7522278 |
diff --git a/profiles/misc/Phase_One_P25.icc.txt b/profiles/misc/Phase_One_P25.icc.txt
index 9076f1c..d344772 100644
--- a/profiles/misc/Phase_One_P25.icc.txt
+++ b/profiles/misc/Phase_One_P25.icc.txt
@@ -19,10 +19,14 @@
  'tech' : 'sig ' :     12 : 219352
 
 rTRC : 16-bit table with 256 entries
-  ~= : 0.3872528, 1.663193, 0.01272831, 3.844358, 0.007843138, -0.212326, 0 (Max error: 0.0204617) (D-gap: 1.67042e-05) (f(1) = 1.00896)
+  ~= : 0.378341, 1.767159, 0.01614364, 3.844358, 0.007843138, -0.2351913, 0 (Max error: 0.0199992) (D-gap: 9.07481e-06) (f(1) = 1.00939)
 gTRC : 16-bit table with 256 entries
+  ~= : 0.2420229, 17.14722, 0.625267, 5.754864, 0.003921569, -0.8921661, 0 (Max error: 0.223358) (D-gap: 0.000140799) (f(1) = 1.1144)
 bTRC : 16-bit table with 256 entries
-  ~= : 0.688842, 1.047989, -0.01162482, 2.721141, 0.01176471, 0.0254097, 0 (Max error: 0.0697136) (D-gap: 0.000136185) (f(1) = 1.05024)
+  ~= : 0.669867, 1, -1.56872e-05, 2.64747, 0.05882354, 0.005882263, 0 (Max error: 0.0488108) (D-gap: -4.27663e-06) (f(1) = 1.00588)
+Best : 0.378341, 1.767159, 0.01614364, 3.844358, 0.007843138, -0.2351913, 0 (D-gap: 9.07481e-06) (f(1) = 1.00939)
+Inv  : 2.643118, 0.806221, 0.1896162, 0.2601215, 0.03015183, -0.009002686, -0 (D-gap: 0.000124334) (f(1) = 0.980007)
+Best Error: | 0.0199992 0.102694 0.124728 |
  XYZ : | 0.64790344 0.35736084 0.15641785 |
        | 0.3829193 1.109726 0 |
        | 0.08326721 0.6792755 0.52342224 |
@@ -30,8 +34,11 @@
  A2B : "A", CLUT, "B"
  "A" : 3 inputs
   A0 : 16-bit table with 256 entries
+  ~= : 0.4952933, 1, -8.765608e-06, 7.968518, 0.04313726, 0.1330681, 0 (Max error: 0.267904) (D-gap: 9.10759e-05) (f(1) = 1.13308)
   A1 : 16-bit table with 256 entries
+  ~= : 0.4952933, 1, -8.765608e-06, 7.968518, 0.04313726, 0.1330681, 0 (Max error: 0.267904) (D-gap: 9.10759e-05) (f(1) = 1.13308)
   A2 : 16-bit table with 256 entries
+  ~= : 0.4952933, 1, -8.765608e-06, 7.968518, 0.04313726, 0.1330681, 0 (Max error: 0.267904) (D-gap: 9.10759e-05) (f(1) = 1.13308)
 CLUT : 33 x 33 x 33 (16 bpp)
  "B" : 3 outputs
   B0 : 1, 1, 0, 0, 0, 0, 0 (f(1) = 1) (~Identity)
diff --git a/profiles/misc/SM245B.icc.txt b/profiles/misc/SM245B.icc.txt
index 7575c03..0d233bb 100644
--- a/profiles/misc/SM245B.icc.txt
+++ b/profiles/misc/SM245B.icc.txt
@@ -20,13 +20,13 @@
  'view' : 'view' :     36 : 2368
 
 rTRC : 16-bit table with 256 entries
-  ~= : 2.200449, 0.9998741, 0.0001119216, 0.00389105, 0.01176471, -2.288818e-05, 0 (Max error: 0.00392157) (D-gap: -1.06799e-05) (f(1) = 0.99995)
+  ~= : 2.200056, 1, -7.76723e-07, 0.00389105, 0.01176471, 0, 0 (Max error: 0.00392157) (D-gap: 1.11191e-05) (f(1) = 1.00002)
 gTRC : 16-bit table with 256 entries
-  ~= : 2.200449, 0.9998741, 0.0001119216, 0.00389105, 0.01176471, -2.288818e-05, 0 (Max error: 0.00392157) (D-gap: -1.06799e-05) (f(1) = 0.99995)
+  ~= : 2.200056, 1, -7.76723e-07, 0.00389105, 0.01176471, 0, 0 (Max error: 0.00392157) (D-gap: 1.11191e-05) (f(1) = 1.00002)
 bTRC : 16-bit table with 256 entries
-  ~= : 2.200449, 0.9998741, 0.0001119216, 0.00389105, 0.01176471, -2.288818e-05, 0 (Max error: 0.00392157) (D-gap: -1.06799e-05) (f(1) = 0.99995)
-Best : 2.200449, 0.9998741, 0.0001119216, 0.00389105, 0.01176471, -2.288818e-05, 0 (D-gap: -1.06799e-05) (f(1) = 0.99995)
-Inv  : 0.4544528, 1.000282, 2.289464e-05, 257, 4.577707e-05, -0.0001144409, -0 (D-gap: 0.000944732) (f(1) = 1.00002)
+  ~= : 2.200056, 1, -7.76723e-07, 0.00389105, 0.01176471, 0, 0 (Max error: 0.00392157) (D-gap: 1.11191e-05) (f(1) = 1.00002)
+Best : 2.200056, 1, -7.76723e-07, 0.00389105, 0.01176471, 0, 0 (D-gap: 1.11191e-05) (f(1) = 1.00002)
+Inv  : 0.4545339, 1, -0, 257, 4.577707e-05, 0, -0 (D-gap: -0.00110817) (f(1) = 1)
 Best Error: | 0.00392157 0.00392157 0.00392157 |
  XYZ : | 0.45872498 0.32295227 0.16848755 |
        | 0.2328949 0.6973877 0.06971741 |
diff --git a/profiles/misc/SWOP_Coated_20_GCR_CMYK.icc.txt b/profiles/misc/SWOP_Coated_20_GCR_CMYK.icc.txt
index ea34877..15ada1b 100644
--- a/profiles/misc/SWOP_Coated_20_GCR_CMYK.icc.txt
+++ b/profiles/misc/SWOP_Coated_20_GCR_CMYK.icc.txt
@@ -20,13 +20,13 @@
  A2B : "A", CLUT, "B"
  "A" : 4 inputs
   A0 : 16-bit table with 256 entries
-  ~= : 3.096739, 0.7520752, 0.6144606, 0.7579767, 0.01960784, -0.223053, 0 (Max error: 0.397942) (D-gap: 0.00023533) (f(1) = 2.4071)
+  ~= : 1.257261, 1, -3.280118e-06, 0.7579767, 0.01960784, 0.007762909, 0 (Max error: 0.0241022) (D-gap: 2.92771e-05) (f(1) = 1.00777)
   A1 : 16-bit table with 256 entries
-  ~= : 1.250859, 0.5047684, 9.68434, 0.7043536, 0.2078432, -17.20215, 0 (Max error: 0.104106) (D-gap: -0.0011314) (f(1) = 1.03662)
+  ~= : 1.388345, 1, -8.363277e-07, 0.6634241, 0.01568628, 0.007305145, 0 (Max error: 0.0358348) (D-gap: 2.25063e-05) (f(1) = 1.00732)
   A2 : 16-bit table with 256 entries
-  ~= : 1.250859, 0.5047684, 9.68434, 0.7043536, 0.2078432, -17.20215, 0 (Max error: 0.104106) (D-gap: -0.0011314) (f(1) = 1.03662)
+  ~= : 1.388345, 1, -8.363277e-07, 0.6634241, 0.01568628, 0.007305145, 0 (Max error: 0.0358348) (D-gap: 2.25063e-05) (f(1) = 1.00732)
   A3 : 16-bit table with 256 entries
-  ~= : 1.250859, 0.5047684, 9.68434, 0.7043536, 0.2078432, -17.20215, 0 (Max error: 0.104106) (D-gap: -0.0011314) (f(1) = 1.03662)
+  ~= : 1.388345, 1, -8.363277e-07, 0.6634241, 0.01568628, 0.007305145, 0 (Max error: 0.0358348) (D-gap: 2.25063e-05) (f(1) = 1.00732)
 CLUT : 16 x 16 x 16 x 16 (16 bpp)
  "B" : 3 outputs
   B0 : 1, 1, 0, 0, 0, 0, 0 (f(1) = 1) (~Identity)
diff --git a/profiles/misc/US_Web_Coated_SWOP_CMYK.icc.txt b/profiles/misc/US_Web_Coated_SWOP_CMYK.icc.txt
index 990ab81..c1f3b7a 100644
--- a/profiles/misc/US_Web_Coated_SWOP_CMYK.icc.txt
+++ b/profiles/misc/US_Web_Coated_SWOP_CMYK.icc.txt
@@ -19,13 +19,13 @@
  A2B : "A", CLUT, "B"
  "A" : 4 inputs
   A0 : 16-bit table with 256 entries
-  ~= : 0.7884726, 1.139404, 0.1396209, 2.132296, 0.003921569, -0.2085495, 0 (Max error: 0.00648499) (D-gap: 0.000136248) (f(1) = 1.00553)
+  ~= : 0.7457523, 1.273102, 0.2824915, 2.132296, 0.003921569, -0.3862457, 0 (Max error: 0.00514561) (D-gap: 5.51855e-05) (f(1) = 1.00403)
   A1 : 16-bit table with 256 entries
   ~= : 1.001599, 0.9828033, -0.01541652, 1.622568, 0.01568628, 0.02549744, 0 (Max error: 0.00873214) (D-gap: 4.53889e-05) (f(1) = 0.992756)
   A2 : 16-bit table with 256 entries
   ~= : 1.043431, 1.001129, -0.01570399, 1.68677, 0.01568628, 0.02659988, 0 (Max error: 0.0127546) (D-gap: 0.00014074) (f(1) = 1.01135)
   A3 : 16-bit table with 256 entries
-  ~= : 2.249374, 0.7321663, 1.020107, 1.840467, 0.003921569, -1.044983, 0 (Max error: 0.515724) (D-gap: 8.38134e-05) (f(1) = 2.4856)
+  ~= : 1.144744, 0.9138336, 0.1820309, 1.840467, 0.003921569, -0.1380463, 0 (Max error: 0.0261459) (D-gap: 0.000190625) (f(1) = 0.972252)
 CLUT : 9 x 9 x 9 x 9 (16 bpp)
  "B" : 3 outputs
   B0 : 1, 1, 0, 0, 0, 0, 0 (f(1) = 1) (~Identity)
diff --git a/profiles/misc/calibrated_nonzero_black.icc.txt b/profiles/misc/calibrated_nonzero_black.icc.txt
index 3d398a2..6c191f1 100644
--- a/profiles/misc/calibrated_nonzero_black.icc.txt
+++ b/profiles/misc/calibrated_nonzero_black.icc.txt
@@ -19,14 +19,14 @@
  'vcgt' : 'vcgt' :   1554 : 2180
 
 rTRC : 16-bit table with 256 entries
-  ~= : 2.199836, 0.9994049, -3.469951e-05, 0.3307393, 0.003921569, 0.001289368, 0 (Max error: 0.0047445) (D-gap: -2.67266e-06) (f(1) = 0.999908)
+  ~= : 2.199834, 0.9994049, -3.508671e-05, 0.3307393, 0.003921569, 0.001289368, 0 (Max error: 0.00474447) (D-gap: -2.67371e-06) (f(1) = 0.999908)
 gTRC : 16-bit table with 256 entries
-  ~= : 2.199836, 0.9994049, -3.469951e-05, 0.3307393, 0.003921569, 0.001289368, 0 (Max error: 0.0047445) (D-gap: -2.67266e-06) (f(1) = 0.999908)
+  ~= : 2.199834, 0.9994049, -3.508671e-05, 0.3307393, 0.003921569, 0.001289368, 0 (Max error: 0.00474447) (D-gap: -2.67371e-06) (f(1) = 0.999908)
 bTRC : 16-bit table with 256 entries
-  ~= : 2.199836, 0.9994049, -3.469951e-05, 0.3307393, 0.003921569, 0.001289368, 0 (Max error: 0.0047445) (D-gap: -2.67266e-06) (f(1) = 0.999908)
-Best : 2.199836, 0.9994049, -3.469951e-05, 0.3307393, 0.003921569, 0.001289368, 0 (D-gap: -2.67266e-06) (f(1) = 0.999908)
-Inv  : 0.4545792, 1.001312, -0.00129106, 3.02353, 0.001297017, 1.907349e-05, -0 (D-gap: 0.000822931) (f(1) = 1.00003)
-Best Error: | 0.0047445 0.0047445 0.0047445 |
+  ~= : 2.199834, 0.9994049, -3.508671e-05, 0.3307393, 0.003921569, 0.001289368, 0 (Max error: 0.00474447) (D-gap: -2.67371e-06) (f(1) = 0.999908)
+Best : 2.199834, 0.9994049, -3.508671e-05, 0.3307393, 0.003921569, 0.001289368, 0 (D-gap: -2.67371e-06) (f(1) = 0.999908)
+Inv  : 0.4545797, 1.001312, -0.00129106, 3.02353, 0.001297017, 1.907349e-05, -0 (D-gap: 0.000822901) (f(1) = 1.00003)
+Best Error: | 0.00474447 0.00474447 0.00474447 |
  XYZ : | 0.436615 0.38534546 0.14224243 |
        | 0.22212219 0.71839905 0.0594635 |
        | 0.012954712 0.09654236 0.71539307 |
diff --git a/profiles/misc/crbug_1017960_19.icc.txt b/profiles/misc/crbug_1017960_19.icc.txt
index 5707278..21ae4f3 100644
--- a/profiles/misc/crbug_1017960_19.icc.txt
+++ b/profiles/misc/crbug_1017960_19.icc.txt
@@ -21,14 +21,14 @@
  'mmod' : 'mmod' :     40 : 3860
 
 rTRC : 16-bit table with 256 entries
-  ~= : 4.841902, 0.719986, 0.3762827, 0.1407054, 0.2431373, -0.02175903, 0 (Max error: 0.127342) (D-gap: -2.65129e-05) (f(1) = 1.53802)
+  ~= : 6.241715, 0.4478817, 0.5665821, 0.1407054, 0.2431373, -0.05149078, 0 (Max error: 0.0142212) (D-gap: 0.000690889) (f(1) = 1.04203)
 gTRC : 16-bit table with 256 entries
-  ~= : 2.197707, 1.013412, -0.02046552, 0.09246967, 0.1333333, 0.003822327, 0 (Max error: 0.0139048) (D-gap: 5.78072e-05) (f(1) = 0.988342)
+  ~= : 2.198663, 1.013107, -0.02007966, 0.09246967, 0.1333333, 0.00378418, 0 (Max error: 0.0138438) (D-gap: 5.86417e-05) (f(1) = 0.988472)
 bTRC : 16-bit table with 256 entries
-  ~= : 1.923471, 1.129272, 0.06547091, 0.0077821, 0.003921569, -0.005767822, 0 (Max error: 0.169685) (D-gap: 0.00018987) (f(1) = 1.40215)
-Best : 4.841902, 0.719986, 0.3762827, 0.1407054, 0.2431373, -0.02175903, 0 (D-gap: -2.65129e-05) (f(1) = 1.53802)
-Inv  : 0.2065304, 4.906921, 0.1067699, 7.107047, 0.03421073, -0.5224304, -0 (D-gap: 0.000164136) (f(1) = 0.872658)
-Best Error: | 0.127342 0.127342 0.127342 |
+  ~= : 1.462179, 1, -2.393499e-07, 0.0077821, 0.003921569, -0.0002593994, 0 (Max error: 0.0897047) (D-gap: 1.28816e-05) (f(1) = 0.999756)
+Best : 2.198663, 1.013107, -0.02007966, 0.09246967, 0.1333333, 0.00378418, 0 (D-gap: 5.86417e-05) (f(1) = 0.988472)
+Inv  : 0.4548219, 0.971817, -0.00367753, 10.81436, 0.01232929, 0.01985931, -0 (D-gap: -0.000332966) (f(1) = 1.00521)
+Best Error: | 0.0450786 0.0138438 0.154441 |
  XYZ : | 0.3805542 0.434021 0.14962769 |
        | 0.21951294 0.68196106 0.098526 |
        | 0.04006958 0.088272095 0.6965637 |
diff --git a/profiles/misc/crbug_976551.icc.txt b/profiles/misc/crbug_976551.icc.txt
index c1b823a..2e7d10b 100644
--- a/profiles/misc/crbug_976551.icc.txt
+++ b/profiles/misc/crbug_976551.icc.txt
@@ -21,14 +21,14 @@
  'mmod' : 'mmod' :     40 : 13080
 
 rTRC : 16-bit table with 1024 entries
-  ~= : 1.439447, 1.07946, -0.07423442, 0.1001471, 0.07526882, 0.006874084, 0 (Max error: 0.0193188) (D-gap: 0.00012941) (f(1) = 1.01437)
+  ~= : 1.585101, 1, -1.342595e-05, 0.1001471, 0.07526882, -0.008956909, 0 (Max error: 0.0193188) (D-gap: 6.78343e-05) (f(1) = 0.991028)
 gTRC : 16-bit table with 1024 entries
-  ~= : 1.436169, 1.070824, -0.07745938, 0.1031524, 0.07233626, 0.007606506, 0 (Max error: 0.0184169) (D-gap: 0.000144845) (f(1) = 0.998066)
+  ~= : 1.586461, 1, -1.055747e-05, 0.1031524, 0.07233626, -0.007980347, 0 (Max error: 0.0184169) (D-gap: 5.51399e-05) (f(1) = 0.992008)
 bTRC : 16-bit table with 1024 entries
-  ~= : 1.508441, 1.110535, -0.05764122, 0.09840215, 0.07722384, 0.003158569, 0 (Max error: 0.0494118) (D-gap: 0.000133727) (f(1) = 1.08383)
-Best : 1.439447, 1.07946, -0.07423442, 0.1001471, 0.07526882, 0.006874084, 0 (D-gap: 0.00012941) (f(1) = 1.01437)
-Inv  : 0.6947112, 0.8958664, -0.006158261, 9.985308, 0.007537957, 0.06882095, -0 (D-gap: -0.000705704) (f(1) = 0.990749)
-Best Error: | 0.0193188 0.0178842 0.0199659 |
+  ~= : 1.444059, 1.080429, -0.06959254, 0.09840215, 0.07722384, 0.005664825, 0 (Max error: 0.0213387) (D-gap: 0.000134651) (f(1) = 1.0213)
+Best : 1.444059, 1.080429, -0.06959254, 0.09840215, 0.07722384, 0.005664825, 0 (D-gap: 0.000134651) (f(1) = 1.0213)
+Inv  : 0.6924927, 0.8943901, -0.005066564, 10.16238, 0.007598992, 0.06447601, -0 (D-gap: -0.000520892) (f(1) = 0.986366)
+Best Error: | 0.0190027 0.01756 0.0213387 |
  XYZ : | 0.512558 0.29548645 0.15614319 |
        | 0.24029541 0.7005768 0.059127808 |
        | -0.0010375977 0.042297363 0.7836609 |
diff --git a/profiles/misc/sRGB_Calibrated_Heterogeneous.icc.txt b/profiles/misc/sRGB_Calibrated_Heterogeneous.icc.txt
index cba6c58..3893e0e 100644
--- a/profiles/misc/sRGB_Calibrated_Heterogeneous.icc.txt
+++ b/profiles/misc/sRGB_Calibrated_Heterogeneous.icc.txt
@@ -16,14 +16,14 @@
  'cprt' : 'mluc' :     60 : 1944
 
 rTRC : 16-bit table with 256 entries
-  ~= : 2.232039, 1.004654, -0.004092941, 0.01206226, 0.03921569, -7.629395e-05, 0 (Max error: 0.00611324) (D-gap: 2.42817e-05) (f(1) = 1.00117)
+  ~= : 2.231967, 1.004677, -0.00411076, 0.01206226, 0.03921569, -9.918213e-05, 0 (Max error: 0.00580043) (D-gap: 9.16654e-07) (f(1) = 1.00115)
 gTRC : 16-bit table with 256 entries
-  ~= : 2.197513, 1.010475, -0.009469209, 0.009727627, 0.02352941, 0.0001678467, 0 (Max error: 0.00431907) (D-gap: 2.74072e-05) (f(1) = 1.00237)
+  ~= : 2.198234, 1.010315, -0.008928984, 0.009727627, 0.02352941, 0.000164032, 0 (Max error: 0.00394905) (D-gap: 3.07562e-05) (f(1) = 1.00321)
 bTRC : 16-bit table with 256 entries
-  ~= : 2.261958, 1.004646, -0.004023268, 0.0077821, 0.01960785, 6.103516e-05, 0 (Max error: 0.00378567) (D-gap: -8.82382e-06) (f(1) = 1.00146)
-Best : 2.232039, 1.004654, -0.004092941, 0.01206226, 0.03921569, -7.629395e-05, 0 (D-gap: 2.42817e-05) (f(1) = 1.00117)
-Inv  : 0.4480209, 0.9897156, 7.550931e-05, 82.90323, 0.0004730297, 0.004066467, -0 (D-gap: -0.000688914) (f(1) = 0.999474)
-Best Error: | 0.00611324 0.0057922 0.00695762 |
+  ~= : 2.261967, 1.004639, -0.00400671, 0.0077821, 0.01960785, 8.010864e-05, 0 (Max error: 0.00375134) (D-gap: 1.04425e-05) (f(1) = 1.0015)
+Best : 2.231967, 1.004677, -0.00411076, 0.01206226, 0.03921569, -9.918213e-05, 0 (D-gap: 9.16654e-07) (f(1) = 1.00115)
+Inv  : 0.4480354, 0.989666, 9.815718e-05, 82.90323, 0.0004730297, 0.004089355, -0 (D-gap: -3.39784e-05) (f(1) = 0.999481)
+Best Error: | 0.00580043 0.00582463 0.00695762 |
  XYZ : | 0.4492798 0.38258362 0.13233948 |
        | 0.22447205 0.7223511 0.05317688 |
        | 0.0011291504 0.05355835 0.7702179 |
diff --git a/profiles/sRGB_Facebook.icc.txt b/profiles/sRGB_Facebook.icc.txt
index 89af818..538878f 100644
--- a/profiles/sRGB_Facebook.icc.txt
+++ b/profiles/sRGB_Facebook.icc.txt
@@ -17,15 +17,15 @@
  'bTRC' : 'curv' :     64 : 460
 
 rTRC : 16-bit table with 26 entries (~sRGB)
-  ~= : 2.38273, 0.9532852, 0.04522569, 0.07743954, 0.04, 0.0005531311, 0 (Max error: 0.00213668) (D-gap: 0.000140188) (f(1) = 0.997005) (~sRGB)
+  ~= : 2.387424, 0.9516296, 0.04789746, 0.07743954, 0.04, 0.0003929138, 0 (Max error: 0.00184847) (D-gap: 0.000151274) (f(1) = 0.999268) (~sRGB)
 gTRC : 16-bit table with 26 entries (~sRGB)
-  ~= : 2.38273, 0.9532852, 0.04522569, 0.07743954, 0.04, 0.0005531311, 0 (Max error: 0.00213668) (D-gap: 0.000140188) (f(1) = 0.997005) (~sRGB)
+  ~= : 2.387424, 0.9516296, 0.04789746, 0.07743954, 0.04, 0.0003929138, 0 (Max error: 0.00184847) (D-gap: 0.000151274) (f(1) = 0.999268) (~sRGB)
 bTRC : 16-bit table with 26 entries (~sRGB)
-  ~= : 2.38273, 0.9532852, 0.04522569, 0.07743954, 0.04, 0.0005531311, 0 (Max error: 0.00213668) (D-gap: 0.000140188) (f(1) = 0.997005) (~sRGB)
+  ~= : 2.387424, 0.9516296, 0.04789746, 0.07743954, 0.04, 0.0003929138, 0 (Max error: 0.00184847) (D-gap: 0.000151274) (f(1) = 0.999268) (~sRGB)
 TRCs ≈ sRGB
-Best : 2.38273, 0.9532852, 0.04522569, 0.07743954, 0.04, 0.0005531311, 0 (D-gap: 0.000140188) (f(1) = 0.997005) (~sRGB)
-Inv  : 0.4196866, 1.120888, -0.0006199979, 12.9133, 0.003097581, -0.04740906, -0 (D-gap: -0.00190929) (f(1) = 1.00132)
-Best Error: | 0.00213668 0.00213668 0.00213668 |
+Best : 2.387424, 0.9516296, 0.04789746, 0.07743954, 0.04, 0.0003929138, 0 (D-gap: 0.000151274) (f(1) = 0.999268) (~sRGB)
+Inv  : 0.4188614, 1.125809, -0.0004423458, 12.9133, 0.003097581, -0.05030823, -0 (D-gap: -0.00200752) (f(1) = 1.00032)
+Best Error: | 0.00184847 0.00184847 0.00184847 |
  XYZ : | 0.43606567 0.3851471 0.1430664 |
        | 0.2224884 0.71687317 0.06060791 |
        | 0.013916016 0.097076416 0.71409607 |
diff --git a/skcms.cc b/skcms.cc
index c54acb6..cc5738d 100644
--- a/skcms.cc
+++ b/skcms.cc
@@ -1656,11 +1656,10 @@
 static float rg_nonlinear(float x,
                           const skcms_Curve* curve,
                           const skcms_TransferFunction* tf,
-                          const float P[3],
                           float dfdP[3]) {
     const float y = eval_curve(curve, x);
 
-    const float g = P[0],  a = P[1],  b = P[2],
+    const float g = tf->g, a = tf->a, b = tf->b,
                 c = tf->c, d = tf->d, f = tf->f;
 
     const float Y = fmaxf_(a*y + b, 0.0f),
@@ -1683,11 +1682,12 @@
 }
 
 static bool gauss_newton_step(const skcms_Curve* curve,
-                              const skcms_TransferFunction* tf,
-                              float P[3],
+                                    skcms_TransferFunction* tf,
                               float x0, float dx, int N) {
     // We'll sample x from the range [x0,x1] (both inclusive) N times with even spacing.
     //
+    // Let P = [ tf->g, tf->a, tf->b ] (the three terms that we're adjusting).
+    //
     // We want to do P' = P + (Jf^T Jf)^-1 Jf^T r(P),
     //   where r(P) is the residual vector
     //   and Jf is the Jacobian matrix of f(), ∂r/∂P.
@@ -1729,7 +1729,7 @@
         float x = x0 + i*dx;
 
         float dfdP[3] = {0,0,0};
-        float resid = rg_nonlinear(x,curve,tf,P, dfdP);
+        float resid = rg_nonlinear(x,curve,tf, dfdP);
 
         for (int r = 0; r < 3; r++) {
             for (int c = 0; c < 3; c++) {
@@ -1756,58 +1756,85 @@
 
     // 4) multiply inverse lhs by rhs
     skcms_Vector3 dP = mv_mul(&lhs_inv, &rhs);
-    P[0] += dP.vals[0];
-    P[1] += dP.vals[1];
-    P[2] += dP.vals[2];
-    return isfinitef_(P[0]) && isfinitef_(P[1]) && isfinitef_(P[2]);
+    tf->g += dP.vals[0];
+    tf->a += dP.vals[1];
+    tf->b += dP.vals[2];
+    return isfinitef_(tf->g) && isfinitef_(tf->a) && isfinitef_(tf->b);
 }
 
+static float max_roundtrip_error_checked(const skcms_Curve* curve,
+                                         const skcms_TransferFunction* tf_inv) {
+    skcms_TransferFunction tf;
+    if (!skcms_TransferFunction_invert(tf_inv, &tf) || sRGBish != classify(tf)) {
+        return INFINITY_;
+    }
+
+    skcms_TransferFunction tf_inv_again;
+    if (!skcms_TransferFunction_invert(&tf, &tf_inv_again)) {
+        return INFINITY_;
+    }
+
+    return skcms_MaxRoundtripError(curve, &tf_inv_again);
+}
 
 // Fit the points in [L,N) to the non-linear piece of tf, or return false if we can't.
 static bool fit_nonlinear(const skcms_Curve* curve, int L, int N, skcms_TransferFunction* tf) {
-    float P[3] = { tf->g, tf->a, tf->b };
+    // This enforces a few constraints that are not modeled in gauss_newton_step()'s optimization.
+    auto fixup_tf = [tf]() {
+        // a must be non-negative. That ensures the function is monotonically increasing.
+        // We don't really know how to fix up a if it goes negative.
+        if (tf->a < 0) {
+            return false;
+        }
+        // ad+b must be non-negative. That ensures we don't end up with complex numbers in powf.
+        // We feel just barely not uneasy enough to tweak b so ad+b is zero in this case.
+        if (tf->a * tf->d + tf->b < 0) {
+            tf->b = -tf->a * tf->d;
+        }
+        assert (tf->a >= 0 &&
+                tf->a * tf->d + tf->b >= 0);
+
+        // cd+f must be ~= (ad+b)^g+e. That ensures the function is continuous. We keep e as a free
+        // parameter so we can guarantee this.
+        tf->e =   tf->c*tf->d + tf->f
+          - powf_(tf->a*tf->d + tf->b, tf->g);
+
+        return true;
+    };
+
+    if (!fixup_tf()) {
+        return false;
+    }
 
     // No matter where we start, dx should always represent N even steps from 0 to 1.
     const float dx = 1.0f / (N-1);
 
+    skcms_TransferFunction best_tf = *tf;
+    float best_max_error = INFINITY_;
+
+    // Need this or several curves get worse... *sigh*
+    float init_error = max_roundtrip_error_checked(curve, tf);
+    if (init_error < best_max_error) {
+        best_max_error = init_error;
+        best_tf = *tf;
+    }
+
     // As far as we can tell, 1 Gauss-Newton step won't converge, and 3 steps is no better than 2.
-    for (int j = 0; j < 2; j++) {
-        // These extra constraints a >= 0 and ad+b >= 0 are not modeled in the optimization.
-        // We don't really know how to fix up a if it goes negative.
-        if (P[1] < 0) {
-            return false;
+    for (int j = 0; j < 8; j++) {
+        if (!gauss_newton_step(curve, tf, L*dx, dx, N-L) || !fixup_tf()) {
+            *tf = best_tf;
+            return isfinitef_(best_max_error);
         }
-        // If ad+b goes negative, we feel just barely not uneasy enough to tweak b so ad+b is zero.
-        if (P[1] * tf->d + P[2] < 0) {
-            P[2] = -P[1] * tf->d;
-        }
-        assert (P[1] >= 0 &&
-                P[1] * tf->d + P[2] >= 0);
 
-        if (!gauss_newton_step(curve, tf,
-                               P,
-                               L*dx, dx, N-L)) {
-            return false;
+        float max_error = max_roundtrip_error_checked(curve, tf);
+        if (max_error < best_max_error) {
+            best_max_error = max_error;
+            best_tf = *tf;
         }
     }
 
-    // We need to apply our fixups one last time
-    if (P[1] < 0) {
-        return false;
-    }
-    if (P[1] * tf->d + P[2] < 0) {
-        P[2] = -P[1] * tf->d;
-    }
-
-    assert (P[1] >= 0 &&
-            P[1] * tf->d + P[2] >= 0);
-
-    tf->g = P[0];
-    tf->a = P[1];
-    tf->b = P[2];
-    tf->e =   tf->c*tf->d + tf->f
-      - powf_(tf->a*tf->d + tf->b, tf->g);
-    return true;
+    *tf = best_tf;
+    return isfinitef_(best_max_error);
 }
 
 bool skcms_ApproximateCurve(const skcms_Curve* curve,
@@ -1874,7 +1901,9 @@
             }
 
             // We fit tf_inv, so calculate tf to keep in sync.
+            // fit_nonlinear() should guarantee invertibility.
             if (!skcms_TransferFunction_invert(&tf_inv, &tf)) {
+                assert(false);
                 continue;
             }
         }
@@ -1882,7 +1911,9 @@
         // We'd better have a sane, sRGB-ish TF by now.
         // Other non-Bad TFs would be fine, but we know we've only ever tried to fit sRGBish;
         // anything else is just some accident of math and the way we pun tf.g as a type flag.
+        // fit_nonlinear() should guarantee this.
         if (sRGBish != classify(tf)) {
+            assert(false);
             continue;
         }
 
@@ -1893,7 +1924,9 @@
         //
         // We've kept tf and tf_inv in sync above, but we can't guarantee that tf is
         // invertible, so re-verify that here (and use the new inverse for testing).
+        // fit_nonlinear() should guarantee this.
         if (!skcms_TransferFunction_invert(&tf, &tf_inv)) {
+            assert(false);
             continue;
         }