Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Unified Diff: src/core/SkColor.cpp

Issue 1666343002: add kRGBA_F16_SkColorType (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add unittest Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkPixmap.h ('k') | src/core/SkPixmap.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « include/core/SkPixmap.h ('k') | src/core/SkPixmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698