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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 104 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
105 #include "SkNx.h" | 105 #include "SkNx.h" |
106 | 106 |
107 SkPM4f SkPM4f::FromPMColor(SkPMColor c) { | 107 SkPM4f SkPM4f::FromPMColor(SkPMColor c) { |
108 Sk4f value = SkNx_cast<float>(Sk4b::Load(&c)); | 108 Sk4f value = SkNx_cast<float>(Sk4b::Load(&c)); |
109 SkPM4f c4; | 109 SkPM4f c4; |
110 (value * Sk4f(1.0f / 255)).store(&c4); | 110 (value * Sk4f(1.0f / 255)).store(&c4); |
111 return c4; | 111 return c4; |
112 } | 112 } |
113 | 113 |
| 114 SkColor4f SkPM4f::unpremul() const { |
| 115 float alpha = fVec[A]; |
| 116 if (0 == alpha) { |
| 117 return { 0, 0, 0, 0 }; |
| 118 } else { |
| 119 float invAlpha = 1 / alpha; |
| 120 return { alpha, fVec[R] * invAlpha, fVec[G] * invAlpha, fVec[B] * invAlp
ha }; |
| 121 } |
| 122 } |
| 123 |
114 SkColor4f SkColor4f::FromColor(SkColor c) { | 124 SkColor4f SkColor4f::FromColor(SkColor c) { |
115 Sk4f value = SkNx_shuffle<3,2,1,0>(SkNx_cast<float>(Sk4b::Load(&c))); | 125 Sk4f value = SkNx_shuffle<3,2,1,0>(SkNx_cast<float>(Sk4b::Load(&c))); |
116 SkColor4f c4; | 126 SkColor4f c4; |
117 (value * Sk4f(1.0f / 255)).store(&c4); | 127 (value * Sk4f(1.0f / 255)).store(&c4); |
118 return c4; | 128 return c4; |
119 } | 129 } |
120 | 130 |
121 SkColor4f SkColor4f::Pin(float a, float r, float g, float b) { | 131 SkColor4f SkColor4f::Pin(float a, float r, float g, float b) { |
122 SkColor4f c4; | 132 SkColor4f c4; |
123 Sk4f::Min(Sk4f::Max(Sk4f(a, r, g, b), Sk4f(0)), Sk4f(1)).store(c4.vec()); | 133 Sk4f::Min(Sk4f::Max(Sk4f(a, r, g, b), Sk4f(0)), Sk4f(1)).store(c4.vec()); |
(...skipping 17 matching lines...) Expand all Loading... |
141 dst.store(&pm4); | 151 dst.store(&pm4); |
142 return pm4; | 152 return pm4; |
143 } | 153 } |
144 | 154 |
145 #ifdef SK_DEBUG | 155 #ifdef SK_DEBUG |
146 void SkPM4f::assertIsUnit() const { | 156 void SkPM4f::assertIsUnit() const { |
147 auto c4 = Sk4f::Load(fVec); | 157 auto c4 = Sk4f::Load(fVec); |
148 SkASSERT((c4 >= Sk4f(0)).allTrue() && (c4 <= Sk4f(1)).allTrue()); | 158 SkASSERT((c4 >= Sk4f(0)).allTrue() && (c4 <= Sk4f(1)).allTrue()); |
149 } | 159 } |
150 #endif | 160 #endif |
OLD | NEW |