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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 "SkNx.h" | 105 #include "SkNx.h" |
106 | 106 |
107 SkPM4f SkPM4f::FromPMColor(SkPMColor c) { | 107 SkColor4f SkColor4f::Pin(float a, float r, float g, float b) { |
108 Sk4f value = SkNx_cast<float>(Sk4b::Load((const uint8_t*)&c)); | 108 SkColor4f c4; |
109 SkPM4f c4; | 109 Sk4f::Min(Sk4f::Max(Sk4f(a, r, g, b), Sk4f(0)), Sk4f(1)).store(c4.vec()); |
110 (value * Sk4f(1.0f / 255)).store(c4.fVec); | |
111 return c4; | 110 return c4; |
112 } | 111 } |
113 | 112 |
114 SkColor4f SkColor4f::FromColor(SkColor c) { | 113 SkColor4f SkColor4f::FromColor(SkColor c) { |
115 Sk4f value = SkNx_shuffle<3,2,1,0>(SkNx_cast<float>(Sk4b::Load((const uint8_
t*)&c))); | 114 Sk4f value = SkNx_shuffle<3,2,1,0>(SkNx_cast<float>(Sk4b::Load((const uint8_
t*)&c))); |
116 SkColor4f c4; | 115 SkColor4f c4; |
117 (value * Sk4f(1.0f / 255)).store(c4.vec()); | 116 (value * Sk4f(1.0f / 255)).store(c4.vec()); |
118 return c4; | 117 return c4; |
119 } | 118 } |
120 | 119 |
121 SkColor4f SkColor4f::Pin(float a, float r, float g, float b) { | |
122 SkColor4f c4; | |
123 Sk4f::Min(Sk4f::Max(Sk4f(a, r, g, b), Sk4f(0)), Sk4f(1)).store(c4.vec()); | |
124 return c4; | |
125 } | |
126 | |
127 SkPM4f SkColor4f::premul() const { | 120 SkPM4f SkColor4f::premul() const { |
128 auto src = Sk4f::Load(this->pin().vec()); | 121 auto src = Sk4f::Load(this->pin().vec()); |
129 float srcAlpha = src.kth<0>(); // need the pinned version of our alpha | 122 float srcAlpha = src.kth<0>(); // need the pinned version of our alpha |
130 src = src * Sk4f(1, srcAlpha, srcAlpha, srcAlpha); | 123 src = src * Sk4f(1, srcAlpha, srcAlpha, srcAlpha); |
131 | 124 |
132 #ifdef SK_PMCOLOR_IS_BGRA | 125 #ifdef SK_PMCOLOR_IS_BGRA |
133 // ARGB -> BGRA | 126 // ARGB -> BGRA |
134 Sk4f dst = SkNx_shuffle<3,2,1,0>(src); | 127 Sk4f dst = SkNx_shuffle<3,2,1,0>(src); |
135 #else | 128 #else |
136 // ARGB -> RGBA | 129 // ARGB -> RGBA |
137 Sk4f dst = SkNx_shuffle<1,2,3,0>(src); | 130 Sk4f dst = SkNx_shuffle<1,2,3,0>(src); |
138 #endif | 131 #endif |
139 | 132 |
140 SkPM4f pm4; | 133 SkPM4f pm4; |
141 dst.store(pm4.fVec); | 134 dst.store(pm4.fVec); |
142 return pm4; | 135 return pm4; |
143 } | 136 } |
OLD | NEW |