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 #include "SkColorPriv.h" |
8 #include "SkPM4f.h" | 9 #include "SkPM4f.h" |
9 #include "SkColorPriv.h" | |
10 #include "SkNx.h" | |
11 | 10 |
12 static inline float get_alpha(const Sk4f& f4) { | 11 static inline float get_alpha(const Sk4f& f4) { |
13 return f4[SkPM4f::A]; | 12 return f4[SkPM4f::A]; |
14 } | 13 } |
15 | 14 |
16 static inline Sk4f set_alpha(const Sk4f& f4, float alpha) { | 15 static inline Sk4f set_alpha(const Sk4f& f4, float alpha) { |
17 static_assert(3 == SkPM4f::A, ""); | 16 static_assert(3 == SkPM4f::A, ""); |
18 return Sk4f(f4[0], f4[1], f4[2], alpha); | 17 return Sk4f(f4[0], f4[1], f4[2], alpha); |
19 } | 18 } |
20 | 19 |
21 static inline uint32_t to_4b(const Sk4f& f4) { | 20 static inline uint32_t to_4b(const Sk4f& f4) { |
22 uint32_t b4; | 21 uint32_t b4; |
23 SkNx_cast<uint8_t>(f4).store((uint8_t*)&b4); | 22 SkNx_cast<uint8_t>(f4).store((uint8_t*)&b4); |
24 return b4; | 23 return b4; |
25 } | 24 } |
26 | 25 |
27 static inline Sk4f to_4f(uint32_t b4) { | 26 static inline Sk4f to_4f(uint32_t b4) { |
28 return SkNx_cast<float>(Sk4b::Load((const uint8_t*)&b4)); | 27 return SkNx_cast<float>(Sk4b::Load((const uint8_t*)&b4)); |
29 } | 28 } |
30 | 29 |
| 30 static inline Sk4f to_4f_rgba(uint32_t b4) { |
| 31 return swizzle_rb_if_bgra(to_4f(b4)); |
| 32 } |
| 33 |
31 static inline Sk4f srgb_to_linear(const Sk4f& s4) { | 34 static inline Sk4f srgb_to_linear(const Sk4f& s4) { |
32 return set_alpha(s4 * s4, get_alpha(s4)); | 35 return set_alpha(s4 * s4, get_alpha(s4)); |
33 } | 36 } |
34 | 37 |
35 static inline Sk4f linear_to_srgb(const Sk4f& l4) { | 38 static inline Sk4f linear_to_srgb(const Sk4f& l4) { |
36 return set_alpha(l4.sqrt(), get_alpha(l4)); | 39 return set_alpha(l4.sqrt(), get_alpha(l4)); |
37 } | 40 } |
38 | 41 |
39 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 42 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
40 | 43 |
41 static inline Sk4f Sk4f_fromL32(uint32_t src) { | 44 static inline Sk4f Sk4f_fromL32(uint32_t src) { |
42 return to_4f(src) * Sk4f(1.0f/255); | 45 return to_4f(src) * Sk4f(1.0f/255); |
43 } | 46 } |
44 | 47 |
45 static inline Sk4f Sk4f_fromS32(uint32_t src) { | 48 static inline Sk4f Sk4f_fromS32(uint32_t src) { |
46 return srgb_to_linear(to_4f(src) * Sk4f(1.0f/255)); | 49 return srgb_to_linear(to_4f(src) * Sk4f(1.0f/255)); |
47 } | 50 } |
48 | 51 |
49 static inline uint32_t Sk4f_toL32(const Sk4f& x4) { | 52 static inline uint32_t Sk4f_toL32(const Sk4f& x4) { |
50 return to_4b(x4 * Sk4f(255) + Sk4f(0.5f)); | 53 return to_4b(x4 * Sk4f(255) + Sk4f(0.5f)); |
51 } | 54 } |
52 | 55 |
53 static inline uint32_t Sk4f_toS32(const Sk4f& x4) { | 56 static inline uint32_t Sk4f_toS32(const Sk4f& x4) { |
54 return to_4b(linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f)); | 57 return to_4b(linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f)); |
55 } | 58 } |
OLD | NEW |