Index: src/core/SkColor.cpp |
diff --git a/src/core/SkColor.cpp b/src/core/SkColor.cpp |
index 87e3a9d60e2f18dfa449bd16f2033036a34ba1d0..c0a3895bbe5ffb4ce4807332aa2029fc7fe4a448 100644 |
--- a/src/core/SkColor.cpp |
+++ b/src/core/SkColor.cpp |
@@ -103,6 +103,7 @@ SkColor SkHSVToColor(U8CPU a, const SkScalar hsv[3]) { |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
#include "SkNx.h" |
+#include "SkHalf.h" |
SkPM4f SkPM4f::FromPMColor(SkPMColor c) { |
Sk4f value = SkNx_cast<float>(Sk4b::Load(&c)); |
@@ -121,6 +122,36 @@ SkColor4f SkPM4f::unpremul() const { |
} |
} |
+void SkPM4f::toF16(uint16_t half[4]) const { |
+ for (int i = 0; i < 4; ++i) { |
+ half[i] = SkFloatToHalf(fVec[i]); |
+ } |
+} |
+ |
+uint64_t SkPM4f::toF16() const { |
+ uint64_t value; |
+ this->toF16(reinterpret_cast<uint16_t*>(&value)); |
+ return value; |
+} |
+ |
+SkPM4f SkPM4f::FromF16(const uint16_t half[4]) { |
+ return {{ |
+ SkHalfToFloat(half[0]), |
+ SkHalfToFloat(half[1]), |
+ SkHalfToFloat(half[2]), |
+ SkHalfToFloat(half[3]) |
+ }}; |
+} |
+ |
+#ifdef SK_DEBUG |
+void SkPM4f::assertIsUnit() const { |
+ auto c4 = Sk4f::Load(fVec); |
+ SkASSERT((c4 >= Sk4f(0)).allTrue() && (c4 <= Sk4f(1)).allTrue()); |
+} |
+#endif |
+ |
+/////////////////////////////////////////////////////////////////////////////////////////////////// |
+ |
SkColor4f SkColor4f::FromColor(SkColor c) { |
Sk4f value = SkNx_shuffle<3,2,1,0>(SkNx_cast<float>(Sk4b::Load(&c))); |
SkColor4f c4; |
@@ -151,10 +182,3 @@ SkPM4f SkColor4f::premul() const { |
dst.store(&pm4); |
return pm4; |
} |
- |
-#ifdef SK_DEBUG |
-void SkPM4f::assertIsUnit() const { |
- auto c4 = Sk4f::Load(fVec); |
- SkASSERT((c4 >= Sk4f(0)).allTrue() && (c4 <= Sk4f(1)).allTrue()); |
-} |
-#endif |