diff options
-rw-r--r-- | third_party/skcms/src/PolyTF.c | 23 | ||||
-rw-r--r-- | third_party/skcms/src/TransferFunction.c | 6 | ||||
-rwxr-xr-x | third_party/skcms/version.sha1 | 2 |
3 files changed, 20 insertions, 11 deletions
diff --git a/third_party/skcms/src/PolyTF.c b/third_party/skcms/src/PolyTF.c index b7b34c3d36..89e0cc40ca 100644 --- a/third_party/skcms/src/PolyTF.c +++ b/third_party/skcms/src/PolyTF.c @@ -94,13 +94,18 @@ static bool fit_poly_tf(const skcms_Curve* curve, skcms_PolyTF* tf) { } // Detect linear baseline: (ax + b)^g + e --> ax ~~> Cx - if (baseline.g == 1 && baseline.d == 0 && baseline.b + baseline.e == 0) { - tf->A = 0; - tf->B = 0; - tf->C = baseline.a; - tf->D = INFINITY_; // Always use Cx, never Ax^3+Bx^2+(1-A-B) - return true; + if (baseline.g == 1 && baseline.d == 0) { + if (baseline.b + baseline.e == 0) { + tf->A = 0; + tf->B = 0; + tf->C = baseline.a; + tf->D = INFINITY_; // Always use Cx, never Ax^3+Bx^2+(1-A-B) + return true; + } else { + return false; // Just like baseline.f != 0 above, can't represent this offset. + } } + // This case is less likely, but also guards against divide by zero below. if (tf->D == 1) { tf->A = 0; @@ -112,7 +117,11 @@ static bool fit_poly_tf(const skcms_Curve* curve, skcms_PolyTF* tf) { // If the curve isn't parametric and we approximated instead, this should be exact. const int L = (int)(tf->D * (N-1)) + 1; - // TODO: handle special case of L == N-1 to avoid /0 in Gauss-Newton. + if (L == N-1) { + // All points but one fit the linear section. + // We could connect the last point with a quadratic, but let's just be lazy. + return false; + } skcms_TransferFunction inv; if (!skcms_TransferFunction_invert(&baseline, &inv)) { diff --git a/third_party/skcms/src/TransferFunction.c b/third_party/skcms/src/TransferFunction.c index b9bbf0b59b..14a7898f00 100644 --- a/third_party/skcms/src/TransferFunction.c +++ b/third_party/skcms/src/TransferFunction.c @@ -295,9 +295,9 @@ bool skcms_ApproximateCurve(const skcms_Curve* curve, // Degenerate case with only two points in the nonlinear segment. Solve directly. tf.g = 1; tf.a = (skcms_eval_curve((N-1)*x_scale, curve) - skcms_eval_curve((N-2)*x_scale, curve)) - * (N-1); - tf.b = skcms_eval_curve((N-1)*x_scale, curve) - - tf.a * (N-2) * x_scale; + / x_scale; + tf.b = skcms_eval_curve((N-2)*x_scale, curve) + - tf.a * (N-2)*x_scale; tf.e = 0; } else { // Start by guessing a gamma-only curve through the midpoint. diff --git a/third_party/skcms/version.sha1 b/third_party/skcms/version.sha1 index 91b45a81ee..db34bce1c4 100755 --- a/third_party/skcms/version.sha1 +++ b/third_party/skcms/version.sha1 @@ -1 +1 @@ -03457e177feaa237d742a795a7c050c0476c2cb5
\ No newline at end of file +42c27486c1ffb16339be984eb6dde03e714a2c65
\ No newline at end of file |