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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/core/SkColorSpaceXform.cpp ('k') | src/core/SkColorSpaceXform_A2B.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkColorSpaceXformPriv_DEFINED
9 #define SkColorSpaceXformPriv_DEFINED
10
11 #include "SkColorSpace_Base.h"
12 #include "SkHalf.h"
13 #include "SkSRGB.h"
14
15 #define AI SK_ALWAYS_INLINE
16
17 #define SkCSXformPrintfDefined 0
18 #define SkCSXformPrintf(...)
19
20 // Interpolating lookup in a variably sized table.
21 static AI float interp_lut(float input, const float* table, int tableSize) {
22 float index = input * (tableSize - 1);
23 float diff = index - sk_float_floor2int(index);
24 return table[(int) sk_float_floor2int(index)] * (1.0f - diff) +
25 table[(int) sk_float_ceil2int(index)] * diff;
26 }
27
28 // Inverse table lookup. Ex: what index corresponds to the input value? This w ill
29 // have strange results when the table is non-increasing. But any sane gamma
30 // function will be increasing.
31 static float inverse_interp_lut(float input, const float* table, int tableSize) {
32 if (input <= table[0]) {
33 return table[0];
34 } else if (input >= table[tableSize - 1]) {
35 return 1.0f;
36 }
37
38 for (int i = 1; i < tableSize; i++) {
39 if (table[i] >= input) {
40 // We are guaranteed that input is greater than table[i - 1].
41 float diff = input - table[i - 1];
42 float distance = table[i] - table[i - 1];
43 float index = (i - 1) + diff / distance;
44 return index / (tableSize - 1);
45 }
46 }
47
48 // Should be unreachable, since we'll return before the loop if input is
49 // larger than the last entry.
50 SkASSERT(false);
51 return 0.0f;
52 }
53
54 #undef AI
55
56 #endif
OLDNEW
« 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