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 SkPM4f_DEFINED | 8 #ifndef SkPM4f_DEFINED |
9 #define SkPM4f_DEFINED | 9 #define SkPM4f_DEFINED |
10 | 10 |
11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
12 #include "SkNx.h" | |
13 | |
14 static inline Sk4f swizzle_rb(const Sk4f& x) { | |
15 return Sk4f(x[2], x[1], x[0], x[3]); | |
mtklein
2016/03/07 18:01:14
You're killing me...
return SkNx_shuffle<2,1,
| |
16 } | |
17 | |
18 static inline Sk4f swizzle_rgba_to_pmorder(const Sk4f& x) { | |
19 #ifdef SK_PMCOLOR_IS_BGRA | |
20 return swizzle_rb(x); | |
21 #else | |
22 return x; | |
23 #endif | |
24 } | |
25 | |
26 static inline Sk4f swizzle_pmorder_to_rgba(const Sk4f& x) { | |
27 #ifdef SK_PMCOLOR_IS_BGRA | |
28 return swizzle_rb(x); | |
29 #else | |
30 return x; | |
31 #endif | |
32 } | |
12 | 33 |
13 /* | 34 /* |
14 * The float values are 0...1 premultiplied | 35 * The float values are 0...1 premultiplied in RGBA order (regardless of SkPMCo lor order) |
15 */ | 36 */ |
16 struct SkPM4f { | 37 struct SkPM4f { |
17 enum { | 38 enum { |
18 A = SK_A32_SHIFT/8, | 39 R, G, B, A, |
19 R = SK_R32_SHIFT/8, | |
20 G = SK_G32_SHIFT/8, | |
21 B = SK_B32_SHIFT/8, | |
22 }; | 40 }; |
23 float fVec[4]; | 41 float fVec[4]; |
24 | 42 |
43 float r() const { return fVec[R]; } | |
44 float g() const { return fVec[G]; } | |
45 float b() const { return fVec[B]; } | |
25 float a() const { return fVec[A]; } | 46 float a() const { return fVec[A]; } |
26 | 47 |
48 static SkPM4f From4f(const Sk4f& x) { | |
49 SkPM4f pm; | |
50 x.store(pm.fVec); | |
51 return pm; | |
52 } | |
53 static SkPM4f FromF16(const uint16_t[4]); | |
54 static SkPM4f FromPMColor(SkPMColor); | |
55 | |
56 Sk4f to4f() const { return Sk4f::Load(fVec); } | |
mtklein
2016/03/07 18:01:14
Looks great to me now. Thanks.
| |
57 Sk4f to4f_rgba() const { return this->to4f(); } | |
58 Sk4f to4f_bgra() const { return swizzle_rb(this->to4f()); } | |
59 Sk4f to4f_pmorder() const { return swizzle_rgba_to_pmorder(this->to4f()); } | |
60 | |
61 void toF16(uint16_t[4]) const; | |
62 uint64_t toF16() const; // 4 float16 values packed into uint64_t | |
63 | |
27 SkColor4f unpremul() const; | 64 SkColor4f unpremul() const; |
28 | 65 |
29 static SkPM4f FromPMColor(SkPMColor); | |
30 | |
31 // half-float routines | |
32 void toF16(uint16_t[4]) const; | |
33 uint64_t toF16() const; // 4 float16 values packed into uint64_t | |
34 static SkPM4f FromF16(const uint16_t[4]); | |
35 | |
36 #ifdef SK_DEBUG | 66 #ifdef SK_DEBUG |
37 void assertIsUnit() const; | 67 void assertIsUnit() const; |
38 #else | 68 #else |
39 void assertIsUnit() const {} | 69 void assertIsUnit() const {} |
40 #endif | 70 #endif |
41 }; | 71 }; |
42 | 72 |
43 typedef SkPM4f (*SkXfermodeProc4f)(const SkPM4f& src, const SkPM4f& dst); | 73 typedef SkPM4f (*SkXfermodeProc4f)(const SkPM4f& src, const SkPM4f& dst); |
44 | 74 |
45 | |
46 #endif | 75 #endif |
OLD | NEW |