aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2018-04-18 12:59:38 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-18 17:34:44 +0000
commit1ccaa6e056296db61eb1af2668a23995fe98e6b3 (patch)
tree7a5f8f19b43e78db31f8f38b063b8a488433ecd4 /third_party
parentbef83531c7287697eeeb950ea32bdf3b102de8b9 (diff)
skcms→b4e167a stricter TF13 matching
Change-Id: If731fa84b20857f8795ba6f5dec3c6dd677dedc1 Reviewed-on: https://skia-review.googlesource.com/122040 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'third_party')
-rw-r--r--third_party/skcms/src/TF13.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/third_party/skcms/src/TF13.c b/third_party/skcms/src/TF13.c
index 281718f431..de8e61a7d3 100644
--- a/third_party/skcms/src/TF13.c
+++ b/third_party/skcms/src/TF13.c
@@ -9,6 +9,7 @@
#include "GaussNewton.h"
#include "PortableMath.h"
#include <limits.h>
+#include <stdlib.h>
// Evaluating skcms_TF13{A,B} at x:
// f(x) = Ax^3 + Bx^2 + (1-A-B)x
@@ -55,11 +56,28 @@ bool skcms_ApproximateCurve13(const skcms_Curve* curve, skcms_TF13* approx, floa
for (int i = 0; i < N; i++) {
float x = i * (1.0f / (N-1));
- float err = fabsf_( skcms_eval_curve(x, curve) - eval_13(x,NULL,P) );
+ const float got = eval_13(x,NULL,P),
+ want = skcms_eval_curve(x, curve);
+
+ const float err = fabsf_(got - want);
if (err > *max_error) {
*max_error = err;
}
+
+ // Compare what bytes we'd choose for these floats, rounded, and scaled by 255,
+ // but intentionally not clamped... if this goes negative, we want it to hurt.
+
+ const int gbyte = (int)(255.0f * got + 0.5f),
+ wbyte = (int)(255.0f * want + 0.5f);
+
+ // Allow no more than 1/256 error, and no error at all at the beginning or end.
+ const int tol = (i == 0 || i == N-1) ? 0
+ : 1;
+ if (abs(gbyte - wbyte) > tol) {
+ return false;
+ }
}
+
approx->A = P[0];
approx->B = P[1];
return true;