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
diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp
index e2d4d30..f285668 100644
--- a/src/core/SkPixmap.cpp
+++ b/src/core/SkPixmap.cpp
@@ -207,6 +207,41 @@
return true;
}
+#include "SkNx.h"
+#include "SkHalf.h"
+
+static void sk_memset64(uint64_t dst[], uint64_t value, int count) {
+ for (int i = 0; i < count; ++i) {
+ dst[i] = value;
+ }
+}
+
+bool SkPixmap::erase(const SkColor4f& origColor, const SkIRect* subset) const {
+ SkPixmap pm;
+ if (subset) {
+ if (!this->extractSubset(&pm, *subset)) {
+ return false;
+ }
+ } else {
+ pm = *this;
+ }
+
+ const SkColor4f color = origColor.pin();
+
+ if (kRGBA_F16_SkColorType != pm.colorType()) {
+ Sk4f c4 = Sk4f::Load(color.vec());
+ SkColor c;
+ (c4 * Sk4f(255) + Sk4f(0.5f)).store(&c);
+ return pm.erase(c);
+ }
+
+ const uint64_t half4 = color.premul().toF16();
+ for (int y = 0; y < pm.height(); ++y) {
+ sk_memset64(pm.writable_addr64(0, y), half4, pm.width());
+ }
+ return true;
+}
+
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkSurface.h"