aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/skcms/src/Curve.c
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/skcms/src/Curve.c')
-rw-r--r--third_party/skcms/src/Curve.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/third_party/skcms/src/Curve.c b/third_party/skcms/src/Curve.c
new file mode 100644
index 0000000000..1e48d65799
--- /dev/null
+++ b/third_party/skcms/src/Curve.c
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Curve.h"
+#include "TransferFunction.h"
+
+float skcms_eval_curve(const skcms_Curve* curve, float x) {
+ if (curve->table_entries == 0) {
+ return skcms_TransferFunction_eval(&curve->parametric, x);
+ }
+
+ // TODO: today we should always hit an entry exactly, but if that changes, lerp?
+ // (We add half to account for slight int -> float -> int round tripping issues.)
+ int ix = (int)( x*(curve->table_entries - 1) + 0.5f );
+
+ if (curve->table_8) {
+ return curve->table_8[ix] * (1/255.0f);
+ } else {
+ uint16_t be;
+ memcpy(&be, curve->table_16 + 2*ix, 2);
+
+ uint16_t le = ((be << 8) | (be >> 8)) & 0xffff;
+ return le * (1/65535.0f);
+ }
+}