| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 (value * Sk4f(1.0f / 255)).store(&c4); | 113 (value * Sk4f(1.0f / 255)).store(&c4); |
| 114 return c4; | 114 return c4; |
| 115 } | 115 } |
| 116 | 116 |
| 117 SkColor4f SkPM4f::unpremul() const { | 117 SkColor4f SkPM4f::unpremul() const { |
| 118 float alpha = fVec[A]; | 118 float alpha = fVec[A]; |
| 119 if (0 == alpha) { | 119 if (0 == alpha) { |
| 120 return { 0, 0, 0, 0 }; | 120 return { 0, 0, 0, 0 }; |
| 121 } else { | 121 } else { |
| 122 float invAlpha = 1 / alpha; | 122 float invAlpha = 1 / alpha; |
| 123 return { alpha, fVec[R] * invAlpha, fVec[G] * invAlpha, fVec[B] * invAlp
ha }; | 123 return { fVec[R] * invAlpha, fVec[G] * invAlpha, fVec[B] * invAlpha, alp
ha }; |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 void SkPM4f::toF16(uint16_t half[4]) const { | 127 void SkPM4f::toF16(uint16_t half[4]) const { |
| 128 for (int i = 0; i < 4; ++i) { | 128 for (int i = 0; i < 4; ++i) { |
| 129 half[i] = SkFloatToHalf(fVec[i]); | 129 half[i] = SkFloatToHalf(fVec[i]); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 uint64_t SkPM4f::toF16() const { | 133 uint64_t SkPM4f::toF16() const { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 148 #ifdef SK_DEBUG | 148 #ifdef SK_DEBUG |
| 149 void SkPM4f::assertIsUnit() const { | 149 void SkPM4f::assertIsUnit() const { |
| 150 auto c4 = Sk4f::Load(fVec); | 150 auto c4 = Sk4f::Load(fVec); |
| 151 SkASSERT((c4 >= Sk4f(0)).allTrue() && (c4 <= Sk4f(1)).allTrue()); | 151 SkASSERT((c4 >= Sk4f(0)).allTrue() && (c4 <= Sk4f(1)).allTrue()); |
| 152 } | 152 } |
| 153 #endif | 153 #endif |
| 154 | 154 |
| 155 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 155 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 156 | 156 |
| 157 SkColor4f SkColor4f::FromColor(SkColor c) { | 157 SkColor4f SkColor4f::FromColor(SkColor c) { |
| 158 Sk4f value = SkNx_shuffle<3,2,1,0>(SkNx_cast<float>(Sk4b::Load(&c))); | 158 Sk4f value = SkNx_shuffle<2,1,0,3>(SkNx_cast<float>(Sk4b::Load(&c))); |
| 159 SkColor4f c4; | 159 SkColor4f c4; |
| 160 (value * Sk4f(1.0f / 255)).store(&c4); | 160 (value * Sk4f(1.0f / 255)).store(&c4); |
| 161 if (gTreatSkColorAsSRGB) { | 161 if (gTreatSkColorAsSRGB) { |
| 162 c4.fR = srgb_to_linear(c4.fR); | 162 c4.fR = srgb_to_linear(c4.fR); |
| 163 c4.fG = srgb_to_linear(c4.fG); | 163 c4.fG = srgb_to_linear(c4.fG); |
| 164 c4.fB = srgb_to_linear(c4.fB); | 164 c4.fB = srgb_to_linear(c4.fB); |
| 165 } | 165 } |
| 166 return c4; | 166 return c4; |
| 167 } | 167 } |
| 168 | 168 |
| 169 SkColor4f SkColor4f::Pin(float a, float r, float g, float b) { | 169 SkColor SkColor4f::toSkColor() const { |
| 170 SkColor result; |
| 171 Sk4f value = SkNx_shuffle<2, 1, 0, 3>(Sk4f::Load(this->vec())); |
| 172 SkNx_cast<uint8_t>(value * Sk4f(255) + Sk4f(0.5f)).store(&result); |
| 173 return result; |
| 174 } |
| 175 |
| 176 SkColor4f SkColor4f::Pin(float r, float g, float b, float a) { |
| 170 SkColor4f c4; | 177 SkColor4f c4; |
| 171 Sk4f::Min(Sk4f::Max(Sk4f(a, r, g, b), Sk4f(0)), Sk4f(1)).store(c4.vec()); | 178 Sk4f::Min(Sk4f::Max(Sk4f(r, g, b, a), Sk4f(0)), Sk4f(1)).store(c4.vec()); |
| 172 return c4; | 179 return c4; |
| 173 } | 180 } |
| 174 | 181 |
| 175 SkPM4f SkColor4f::premul() const { | 182 SkPM4f SkColor4f::premul() const { |
| 176 auto src = Sk4f::Load(this->pin().vec()); | 183 auto src = Sk4f::Load(this->pin().vec()); |
| 177 float srcAlpha = src[0]; // need the pinned version of our alpha | 184 float srcAlpha = src[3]; // need the pinned version of our alpha |
| 178 src = src * Sk4f(1, srcAlpha, srcAlpha, srcAlpha); | 185 src = src * Sk4f(srcAlpha, srcAlpha, srcAlpha, 1); |
| 179 | 186 |
| 180 // ARGB -> RGBA | 187 return SkPM4f::From4f(src); |
| 181 Sk4f dst = SkNx_shuffle<1,2,3,0>(src); | |
| 182 | |
| 183 return SkPM4f::From4f(dst); | |
| 184 } | 188 } |
| OLD | NEW |