Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Unified Diff: src/core/SkColorSpaceXformPriv.h

Issue 2449243003: Initial implementation of a SkColorSpace_A2B xform (Closed)
Patch Set: fixed compile error on certain trybots related to RVO move-elision Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkColorSpaceXform.cpp ('k') | src/core/SkColorSpaceXform_A2B.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkColorSpaceXformPriv.h
diff --git a/src/core/SkColorSpaceXformPriv.h b/src/core/SkColorSpaceXformPriv.h
new file mode 100644
index 0000000000000000000000000000000000000000..c2418a93b6d8e8c1f99bb10dcbfed5d65fcdf23e
--- /dev/null
+++ b/src/core/SkColorSpaceXformPriv.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkColorSpaceXformPriv_DEFINED
+#define SkColorSpaceXformPriv_DEFINED
+
+#include "SkColorSpace_Base.h"
+#include "SkHalf.h"
+#include "SkSRGB.h"
+
+#define AI SK_ALWAYS_INLINE
+
+#define SkCSXformPrintfDefined 0
+#define SkCSXformPrintf(...)
+
+// Interpolating lookup in a variably sized table.
+static AI float interp_lut(float input, const float* table, int tableSize) {
+ float index = input * (tableSize - 1);
+ float diff = index - sk_float_floor2int(index);
+ return table[(int) sk_float_floor2int(index)] * (1.0f - diff) +
+ table[(int) sk_float_ceil2int(index)] * diff;
+}
+
+// Inverse table lookup. Ex: what index corresponds to the input value? This will
+// have strange results when the table is non-increasing. But any sane gamma
+// function will be increasing.
+static float inverse_interp_lut(float input, const float* table, int tableSize) {
+ if (input <= table[0]) {
+ return table[0];
+ } else if (input >= table[tableSize - 1]) {
+ return 1.0f;
+ }
+
+ for (int i = 1; i < tableSize; i++) {
+ if (table[i] >= input) {
+ // We are guaranteed that input is greater than table[i - 1].
+ float diff = input - table[i - 1];
+ float distance = table[i] - table[i - 1];
+ float index = (i - 1) + diff / distance;
+ return index / (tableSize - 1);
+ }
+ }
+
+ // Should be unreachable, since we'll return before the loop if input is
+ // larger than the last entry.
+ SkASSERT(false);
+ return 0.0f;
+}
+
+#undef AI
+
+#endif
« no previous file with comments | « src/core/SkColorSpaceXform.cpp ('k') | src/core/SkColorSpaceXform_A2B.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698