OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkPM4fPriv_DEFINED | 8 #ifndef SkPM4fPriv_DEFINED |
9 #define SkPM4fPriv_DEFINED | 9 #define SkPM4fPriv_DEFINED |
10 | 10 |
11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
12 #include "SkPM4f.h" | 12 #include "SkPM4f.h" |
13 | 13 |
| 14 extern bool gTreatSkColorAsSRGB; |
| 15 |
14 static inline float get_alpha(const Sk4f& f4) { | 16 static inline float get_alpha(const Sk4f& f4) { |
15 return f4[SkPM4f::A]; | 17 return f4[SkPM4f::A]; |
16 } | 18 } |
17 | 19 |
18 static inline Sk4f set_alpha(const Sk4f& f4, float alpha) { | 20 static inline Sk4f set_alpha(const Sk4f& f4, float alpha) { |
19 static_assert(3 == SkPM4f::A, ""); | 21 static_assert(3 == SkPM4f::A, ""); |
20 return Sk4f(f4[0], f4[1], f4[2], alpha); | 22 return Sk4f(f4[0], f4[1], f4[2], alpha); |
21 } | 23 } |
22 | 24 |
23 static inline uint32_t to_4b(const Sk4f& f4) { | 25 static inline uint32_t to_4b(const Sk4f& f4) { |
(...skipping 11 matching lines...) Expand all Loading... |
35 } | 37 } |
36 | 38 |
37 static inline Sk4f srgb_to_linear(const Sk4f& s4) { | 39 static inline Sk4f srgb_to_linear(const Sk4f& s4) { |
38 return set_alpha(s4 * s4, get_alpha(s4)); | 40 return set_alpha(s4 * s4, get_alpha(s4)); |
39 } | 41 } |
40 | 42 |
41 static inline Sk4f linear_to_srgb(const Sk4f& l4) { | 43 static inline Sk4f linear_to_srgb(const Sk4f& l4) { |
42 return set_alpha(l4.sqrt(), get_alpha(l4)); | 44 return set_alpha(l4.sqrt(), get_alpha(l4)); |
43 } | 45 } |
44 | 46 |
| 47 static inline float srgb_to_linear(float x) { |
| 48 return x * x; |
| 49 } |
| 50 |
| 51 static inline float linear_to_srgb(float x) { |
| 52 return sqrtf(x); |
| 53 } |
| 54 |
45 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 55 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
46 | 56 |
47 static inline Sk4f Sk4f_fromL32(uint32_t src) { | 57 static inline Sk4f Sk4f_fromL32(uint32_t src) { |
48 return to_4f(src) * Sk4f(1.0f/255); | 58 return to_4f(src) * Sk4f(1.0f/255); |
49 } | 59 } |
50 | 60 |
51 static inline Sk4f Sk4f_fromS32(uint32_t src) { | 61 static inline Sk4f Sk4f_fromS32(uint32_t src) { |
52 return srgb_to_linear(to_4f(src) * Sk4f(1.0f/255)); | 62 return srgb_to_linear(to_4f(src) * Sk4f(1.0f/255)); |
53 } | 63 } |
54 | 64 |
55 static inline uint32_t Sk4f_toL32(const Sk4f& x4) { | 65 static inline uint32_t Sk4f_toL32(const Sk4f& x4) { |
56 return to_4b(x4 * Sk4f(255) + Sk4f(0.5f)); | 66 return to_4b(x4 * Sk4f(255) + Sk4f(0.5f)); |
57 } | 67 } |
58 | 68 |
59 static inline uint32_t Sk4f_toS32(const Sk4f& x4) { | 69 static inline uint32_t Sk4f_toS32(const Sk4f& x4) { |
60 return to_4b(linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f)); | 70 return to_4b(linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f)); |
61 } | 71 } |
62 | 72 |
63 #endif | 73 #endif |
OLD | NEW |