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

Unified Diff: src/opts/SkPMFloat_none.h

Issue 936633002: Sketch SkPMFloat (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: explicit casts Created 5 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 | « src/opts/SkPMFloat_neon.h ('k') | tests/PMFloatTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/opts/SkPMFloat_none.h
diff --git a/src/opts/SkPMFloat_none.h b/src/opts/SkPMFloat_none.h
new file mode 100644
index 0000000000000000000000000000000000000000..dee7ce6862f8c9593a545aff2514893200eec0fc
--- /dev/null
+++ b/src/opts/SkPMFloat_none.h
@@ -0,0 +1,28 @@
+#include "SkColorPriv.h"
+#include "SkPMFloat.h"
+
+inline void SkPMFloat::set(SkPMColor c) {
+ float scale = 1.0f / 255.0f;
+ this->setA(SkGetPackedA32(c) * scale);
+ this->setR(SkGetPackedR32(c) * scale);
+ this->setG(SkGetPackedG32(c) * scale);
+ this->setB(SkGetPackedB32(c) * scale);
+ SkASSERT(this->isValid());
+}
+
+inline SkPMColor SkPMFloat::get() const {
+ SkASSERT(this->isValid());
+ return SkPackARGB32(this->a() * 255, this->r() * 255, this->g() * 255, this->b() * 255);
+}
+
+inline SkPMColor SkPMFloat::clamped() const {
+ float a = this->a(),
+ r = this->r(),
+ g = this->g(),
+ b = this->b();
+ a = a < 0 ? 0 : (a > 1 ? 1 : a);
+ r = r < 0 ? 0 : (r > 1 ? 1 : r);
+ g = g < 0 ? 0 : (g > 1 ? 1 : g);
+ b = b < 0 ? 0 : (b > 1 ? 1 : b);
+ return SkPackARGB32(a * 255, r * 255, g * 255, b * 255);
+}
« no previous file with comments | « src/opts/SkPMFloat_neon.h ('k') | tests/PMFloatTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698