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 Sk4fGradientPriv_DEFINED | 8 #ifndef Sk4fGradientPriv_DEFINED |
9 #define Sk4fGradientPriv_DEFINED | 9 #define Sk4fGradientPriv_DEFINED |
10 | 10 |
11 #include "SkColor.h" | 11 #include "SkColor.h" |
12 #include "SkHalf.h" | |
13 #include "SkImageInfo.h" | |
12 #include "SkNx.h" | 14 #include "SkNx.h" |
13 #include "SkPM4f.h" | 15 #include "SkPM4f.h" |
16 #include "SkPM4fPriv.h" | |
14 | 17 |
15 // Templates shared by various 4f gradient flavors. | 18 // Templates shared by various 4f gradient flavors. |
16 | 19 |
17 namespace { | 20 namespace { |
18 | 21 |
19 inline Sk4f premul_4f(const Sk4f& c) { | 22 inline Sk4f premul_4f(const Sk4f& c) { |
20 const float alpha = c[SkPM4f::A]; | 23 const float alpha = c[SkPM4f::A]; |
21 // FIXME: portable swizzle? | 24 // FIXME: portable swizzle? |
22 return c * Sk4f(alpha, alpha, alpha, 1); | 25 return c * Sk4f(alpha, alpha, alpha, 1); |
23 } | 26 } |
24 | 27 |
25 template <bool do_premul> | 28 template <bool do_premul> |
26 inline SkPMColor trunc_from_255(const Sk4f& c) { | 29 inline SkPMColor trunc_from_255(const Sk4f& c) { |
27 SkPMColor pmc; | 30 SkPMColor pmc; |
28 SkNx_cast<uint8_t>(c).store(&pmc); | 31 SkNx_cast<uint8_t>(c).store(&pmc); |
29 if (do_premul) { | 32 if (do_premul) { |
30 pmc = SkPreMultiplyARGB(SkGetPackedA32(pmc), SkGetPackedR32(pmc), | 33 pmc = SkPreMultiplyARGB(SkGetPackedA32(pmc), SkGetPackedR32(pmc), |
31 SkGetPackedG32(pmc), SkGetPackedB32(pmc)); | 34 SkGetPackedG32(pmc), SkGetPackedB32(pmc)); |
32 } | 35 } |
33 return pmc; | 36 return pmc; |
34 } | 37 } |
35 | 38 |
36 template<typename DstType, bool do_premul> | 39 template<typename DstType, SkColorProfileType, bool do_premul> |
37 void store(const Sk4f& color, DstType* dst); | 40 void store(const Sk4f& color, DstType* dst); |
38 | 41 |
39 template<> | 42 template<> |
40 inline void store<SkPM4f, false>(const Sk4f& c, SkPM4f* dst) { | 43 inline void store<SkPM4f, kLinear_SkColorProfileType, false>(const Sk4f& c, SkPM 4f* dst) { |
reed1
2016/03/18 14:28:59
Getting hard to remember what true and false mean
f(malita)
2016/03/18 16:54:11
Done.
| |
41 c.store(dst); | 44 c.store(dst); |
42 } | 45 } |
43 | 46 |
44 template<> | 47 template<> |
45 inline void store<SkPM4f, true>(const Sk4f& c, SkPM4f* dst) { | 48 inline void store<SkPM4f, kLinear_SkColorProfileType, true>(const Sk4f& c, SkPM4 f* dst) { |
46 store<SkPM4f, false>(premul_4f(c), dst); | 49 store<SkPM4f, kLinear_SkColorProfileType, false>(premul_4f(c), dst); |
47 } | 50 } |
48 | 51 |
49 template<> | 52 template<> |
50 inline void store<SkPMColor, false>(const Sk4f& c, SkPMColor* dst) { | 53 inline void store<SkPMColor, kLinear_SkColorProfileType, false>(const Sk4f& c, S kPMColor* dst) { |
51 *dst = trunc_from_255<false>(c); | 54 *dst = trunc_from_255<false>(c); |
52 } | 55 } |
53 | 56 |
54 template<> | 57 template<> |
55 inline void store<SkPMColor, true>(const Sk4f& c, SkPMColor* dst) { | 58 inline void store<SkPMColor, kLinear_SkColorProfileType, true>(const Sk4f& c, Sk PMColor* dst) { |
56 *dst = trunc_from_255<true>(c); | 59 *dst = trunc_from_255<true>(c); |
57 } | 60 } |
58 | 61 |
59 template<typename DstType, bool do_premul> | 62 template<> |
63 inline void store<SkPMColor, kSRGB_SkColorProfileType, false>(const Sk4f& c, SkP MColor* dst) { | |
64 // FIXME: this assumes opaque colors. Handle unpremultiplication. | |
65 *dst = Sk4f_toS32(c); | |
66 } | |
67 | |
68 template<> | |
69 inline void store<SkPMColor, kSRGB_SkColorProfileType, true>(const Sk4f& c, SkPM Color* dst) { | |
70 const SkPMColor s32 = Sk4f_toS32(c); | |
71 *dst = SkPreMultiplyARGB(SkGetPackedA32(s32), SkGetPackedR32(s32), | |
reed1
2016/03/18 14:28:59
why not Sk4f_toS32(premul_4f(c)) ?
f(malita)
2016/03/18 16:54:11
Done.
| |
72 SkGetPackedG32(s32), SkGetPackedB32(s32)); | |
73 } | |
74 | |
75 template<> | |
76 inline void store<uint64_t, kLinear_SkColorProfileType, false>(const Sk4f& c, ui nt64_t* dst) { | |
77 *dst = SkFloatToHalf_01(c); | |
78 } | |
79 | |
80 template<> | |
81 inline void store<uint64_t, kLinear_SkColorProfileType, true>(const Sk4f& c, uin t64_t* dst) { | |
82 store<uint64_t, kLinear_SkColorProfileType, false>(premul_4f(c), dst); | |
83 } | |
84 | |
85 template<typename DstType, SkColorProfileType profile, bool do_premul> | |
60 inline void store4x(const Sk4f& c0, | 86 inline void store4x(const Sk4f& c0, |
61 const Sk4f& c1, | 87 const Sk4f& c1, |
62 const Sk4f& c2, | 88 const Sk4f& c2, |
63 const Sk4f& c3, | 89 const Sk4f& c3, |
64 DstType* dst) { | 90 DstType* dst) { |
65 store<DstType, do_premul>(c0, dst++); | 91 store<DstType, profile, do_premul>(c0, dst++); |
66 store<DstType, do_premul>(c1, dst++); | 92 store<DstType, profile, do_premul>(c1, dst++); |
67 store<DstType, do_premul>(c2, dst++); | 93 store<DstType, profile, do_premul>(c2, dst++); |
68 store<DstType, do_premul>(c3, dst++); | 94 store<DstType, profile, do_premul>(c3, dst++); |
69 } | 95 } |
70 | 96 |
71 template<> | 97 template<> |
72 inline void store4x<SkPMColor, false>(const Sk4f& c0, | 98 inline void store4x<SkPMColor, kLinear_SkColorProfileType, false>(const Sk4f& c0 , |
73 const Sk4f& c1, | 99 const Sk4f& c1 , |
74 const Sk4f& c2, | 100 const Sk4f& c2 , |
75 const Sk4f& c3, | 101 const Sk4f& c3 , |
76 SkPMColor* dst) { | 102 SkPMColor* dst ) { |
77 Sk4f_ToBytes((uint8_t*)dst, c0, c1, c2, c3); | 103 Sk4f_ToBytes((uint8_t*)dst, c0, c1, c2, c3); |
78 } | 104 } |
79 | 105 |
80 template<typename DstType> | 106 template<typename DstType, SkColorProfileType> |
81 float dst_component_scale(); | 107 Sk4f scale_for_dest(const Sk4f& c) { |
82 | 108 return c; |
83 template<> | |
84 inline float dst_component_scale<SkPM4f>() { | |
85 return 1; | |
86 } | 109 } |
87 | 110 |
88 template<> | 111 template<> |
89 inline float dst_component_scale<SkPMColor>() { | 112 inline Sk4f scale_for_dest<SkPMColor, kLinear_SkColorProfileType>(const Sk4f& c) { |
90 return 255; | 113 return c * 255; |
91 } | 114 } |
92 | 115 |
93 template<typename DstType> | 116 template<typename DstType> |
94 Sk4f dst_swizzle(const SkPM4f&); | 117 Sk4f dst_swizzle(const SkPM4f&); |
95 | 118 |
96 template<> | 119 template<> |
97 inline Sk4f dst_swizzle<SkPM4f>(const SkPM4f& c) { | 120 inline Sk4f dst_swizzle<SkPM4f>(const SkPM4f& c) { |
98 return c.to4f(); | 121 return c.to4f(); |
99 } | 122 } |
100 | 123 |
101 template<> | 124 template<> |
102 inline Sk4f dst_swizzle<SkPMColor>(const SkPM4f& c) { | 125 inline Sk4f dst_swizzle<SkPMColor>(const SkPM4f& c) { |
103 return c.to4f_pmorder(); | 126 return c.to4f_pmorder(); |
104 } | 127 } |
105 | 128 |
129 template<> | |
130 inline Sk4f dst_swizzle<uint64_t>(const SkPM4f& c) { | |
131 return c.to4f(); | |
132 } | |
133 | |
106 } | 134 } |
107 | 135 |
108 #endif // Sk4fGradientPriv_DEFINED | 136 #endif // Sk4fGradientPriv_DEFINED |
OLD | NEW |