add kRGBA_F16_SkColorType
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1666343002
Review URL: https://codereview.chromium.org/1666343002
diff --git a/src/core/SkColor.cpp b/src/core/SkColor.cpp
index 87e3a9d..c0a3895 100644
--- a/src/core/SkColor.cpp
+++ b/src/core/SkColor.cpp
@@ -103,6 +103,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "SkNx.h"
+#include "SkHalf.h"
SkPM4f SkPM4f::FromPMColor(SkPMColor c) {
Sk4f value = SkNx_cast<float>(Sk4b::Load(&c));
@@ -121,6 +122,36 @@
}
}
+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 @@
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