Index: src/core/SkPM4f.h |
diff --git a/src/core/SkPM4f.h b/src/core/SkPM4f.h |
index fb22783dcc44203a8c3931982f645e3de7dde956..e99ddccd8effac93898897df523042ac38a7ccba 100644 |
--- a/src/core/SkPM4f.h |
+++ b/src/core/SkPM4f.h |
@@ -9,29 +9,51 @@ |
#define SkPM4f_DEFINED |
#include "SkColorPriv.h" |
+#include "SkNx.h" |
+ |
+static inline Sk4f swizzle_rb(const Sk4f& x) { |
+ return SkNx_shuffle<2, 1, 0, 3>(x); |
+} |
+ |
+static inline Sk4f swizzle_rb_if_bgra(const Sk4f& x) { |
+#ifdef SK_PMCOLOR_IS_BGRA |
+ return swizzle_rb(x); |
+#else |
+ return x; |
+#endif |
+} |
/* |
- * The float values are 0...1 premultiplied |
+ * The float values are 0...1 premultiplied in RGBA order (regardless of SkPMColor order) |
*/ |
struct SkPM4f { |
enum { |
- A = SK_A32_SHIFT/8, |
- R = SK_R32_SHIFT/8, |
- G = SK_G32_SHIFT/8, |
- B = SK_B32_SHIFT/8, |
+ R, G, B, A, |
}; |
float fVec[4]; |
+ float r() const { return fVec[R]; } |
+ float g() const { return fVec[G]; } |
+ float b() const { return fVec[B]; } |
float a() const { return fVec[A]; } |
- SkColor4f unpremul() const; |
- |
+ static SkPM4f From4f(const Sk4f& x) { |
+ SkPM4f pm; |
+ x.store(pm.fVec); |
+ return pm; |
+ } |
+ static SkPM4f FromF16(const uint16_t[4]); |
static SkPM4f FromPMColor(SkPMColor); |
- // half-float routines |
+ Sk4f to4f() const { return Sk4f::Load(fVec); } |
+ Sk4f to4f_rgba() const { return this->to4f(); } |
+ Sk4f to4f_bgra() const { return swizzle_rb(this->to4f()); } |
+ Sk4f to4f_pmorder() const { return swizzle_rb_if_bgra(this->to4f()); } |
+ |
void toF16(uint16_t[4]) const; |
uint64_t toF16() const; // 4 float16 values packed into uint64_t |
- static SkPM4f FromF16(const uint16_t[4]); |
+ |
+ SkColor4f unpremul() const; |
#ifdef SK_DEBUG |
void assertIsUnit() const; |
@@ -42,5 +64,4 @@ struct SkPM4f { |
typedef SkPM4f (*SkXfermodeProc4f)(const SkPM4f& src, const SkPM4f& dst); |
- |
#endif |