OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 "SkColor.h" | 8 #include "SkColor.h" |
9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
10 #include "SkFixed.h" | 10 #include "SkFixed.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 case 1: r = q; g = v; b = p; break; | 95 case 1: r = q; g = v; b = p; break; |
96 case 2: r = p; g = v; b = t; break; | 96 case 2: r = p; g = v; b = t; break; |
97 case 3: r = p; g = q; b = v; break; | 97 case 3: r = p; g = q; b = v; break; |
98 case 4: r = t; g = p; b = v; break; | 98 case 4: r = t; g = p; b = v; break; |
99 default: r = v; g = p; b = q; break; | 99 default: r = v; g = p; b = q; break; |
100 } | 100 } |
101 return SkColorSetARGB(a, r, g, b); | 101 return SkColorSetARGB(a, r, g, b); |
102 } | 102 } |
103 | 103 |
104 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 104 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
105 #include "SkPM4f.h" | 105 #include "SkPM4fPriv.h" |
106 #include "SkNx.h" | |
107 #include "SkHalf.h" | 106 #include "SkHalf.h" |
108 | 107 |
109 SkPM4f SkPM4f::FromPMColor(SkPMColor c) { | 108 SkPM4f SkPM4f::FromPMColor(SkPMColor c) { |
110 Sk4f value = SkNx_cast<float>(Sk4b::Load(&c)); | 109 Sk4f value = to_4f_rgba(c); |
111 SkPM4f c4; | 110 SkPM4f c4; |
112 (value * Sk4f(1.0f / 255)).store(&c4); | 111 (value * Sk4f(1.0f / 255)).store(&c4); |
113 return c4; | 112 return c4; |
114 } | 113 } |
115 | 114 |
116 SkColor4f SkPM4f::unpremul() const { | 115 SkColor4f SkPM4f::unpremul() const { |
117 float alpha = fVec[A]; | 116 float alpha = fVec[A]; |
118 if (0 == alpha) { | 117 if (0 == alpha) { |
119 return { 0, 0, 0, 0 }; | 118 return { 0, 0, 0, 0 }; |
120 } else { | 119 } else { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 SkColor4f c4; | 163 SkColor4f c4; |
165 Sk4f::Min(Sk4f::Max(Sk4f(a, r, g, b), Sk4f(0)), Sk4f(1)).store(c4.vec()); | 164 Sk4f::Min(Sk4f::Max(Sk4f(a, r, g, b), Sk4f(0)), Sk4f(1)).store(c4.vec()); |
166 return c4; | 165 return c4; |
167 } | 166 } |
168 | 167 |
169 SkPM4f SkColor4f::premul() const { | 168 SkPM4f SkColor4f::premul() const { |
170 auto src = Sk4f::Load(this->pin().vec()); | 169 auto src = Sk4f::Load(this->pin().vec()); |
171 float srcAlpha = src[0]; // need the pinned version of our alpha | 170 float srcAlpha = src[0]; // need the pinned version of our alpha |
172 src = src * Sk4f(1, srcAlpha, srcAlpha, srcAlpha); | 171 src = src * Sk4f(1, srcAlpha, srcAlpha, srcAlpha); |
173 | 172 |
174 #ifdef SK_PMCOLOR_IS_BGRA | |
175 // ARGB -> BGRA | |
176 Sk4f dst = SkNx_shuffle<3,2,1,0>(src); | |
177 #else | |
178 // ARGB -> RGBA | 173 // ARGB -> RGBA |
179 Sk4f dst = SkNx_shuffle<1,2,3,0>(src); | 174 Sk4f dst = SkNx_shuffle<1,2,3,0>(src); |
180 #endif | |
181 | 175 |
182 SkPM4f pm4; | 176 return SkPM4f::From4f(dst); |
183 dst.store(&pm4); | |
184 return pm4; | |
185 } | 177 } |
OLD | NEW |