Index: src/effects/SkColorMatrixFilter.cpp |
diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp |
index 92b26ebdf91ec901d1dc8bb44baff073288edb1c..d7f0a742955575aeff5399765c03a5a5e4a2ef46 100644 |
--- a/src/effects/SkColorMatrixFilter.cpp |
+++ b/src/effects/SkColorMatrixFilter.cpp |
@@ -8,7 +8,7 @@ |
#include "SkColorMatrixFilter.h" |
#include "SkColorMatrix.h" |
#include "SkColorPriv.h" |
-#include "SkPMFloat.h" |
+#include "SkNx.h" |
#include "SkReadBuffer.h" |
#include "SkWriteBuffer.h" |
#include "SkUnPreMultiply.h" |
@@ -239,25 +239,27 @@ uint32_t SkColorMatrixFilter::getFlags() const { |
return this->INHERITED::getFlags() | fFlags; |
} |
-static Sk4f premul(const Sk4f& x) { |
- float scale = SkPMFloat(x).a(); |
- Sk4f pm = x * SkPMFloat(1, scale, scale, scale); |
+static Sk4f scale_rgb(float scale) { |
+ static_assert(SK_A32_SHIFT == 24, "Alpha is lane 3"); |
+ return Sk4f(scale, scale, scale, 1); |
+} |
-#ifdef SK_DEBUG |
- SkPMFloat pmf(pm); |
- SkASSERT(pmf.isValid()); |
-#endif |
+static Sk4f premul(const Sk4f& x) { |
+ return x * scale_rgb(x.kth<SK_A32_SHIFT/8>()); |
+} |
- return pm; |
+static Sk4f unpremul(const Sk4f& x) { |
+ return x * scale_rgb(1 / x.kth<SK_A32_SHIFT/8>()); // TODO: fast/approx invert? |
} |
-static Sk4f unpremul(const SkPMFloat& pm) { |
- float scale = 1 / pm.a(); // candidate for fast/approx invert? |
- return pm * SkPMFloat(1, scale, scale, scale); |
+static Sk4f clamp_0_1(const Sk4f& x) { |
+ return Sk4f::Max(Sk4f::Min(x, Sk4f(1)), Sk4f(0)); |
} |
-static Sk4f clamp_0_1(const Sk4f& value) { |
- return Sk4f::Max(Sk4f::Min(value, Sk4f(1)), Sk4f(0)); |
+static SkPMColor round(const Sk4f& x) { |
+ SkPMColor c; |
+ (x * Sk4f(255) + Sk4f(0.5f)).toBytes((uint8_t*)&c); |
+ return c; |
} |
void SkColorMatrixFilter::filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const { |
@@ -285,7 +287,7 @@ void SkColorMatrixFilter::filterSpan(const SkPMColor src[], int count, SkPMColor |
const Sk4f c4 = Sk4f::Load(fTranspose + 16)*Sk4f(1.0f/255); |
// todo: we could cache this in the constructor... |
- SkPMColor matrix_translate_pmcolor = SkPMFloat(premul(clamp_0_1(c4))).round(); |
+ SkPMColor matrix_translate_pmcolor = round(premul(clamp_0_1(c4))); |
for (int i = 0; i < count; i++) { |
const SkPMColor src_c = src[i]; |
@@ -294,22 +296,22 @@ void SkColorMatrixFilter::filterSpan(const SkPMColor src[], int count, SkPMColor |
continue; |
} |
- SkPMFloat srcf(src_c); |
+ Sk4f srcf = Sk4f::FromBytes((const uint8_t*)&src_c) * Sk4f(1.0f/255); |
if (0xFF != SkGetPackedA32(src_c)) { |
srcf = unpremul(srcf); |
} |
- Sk4f r4 = Sk4f(srcf.r()); |
- Sk4f g4 = Sk4f(srcf.g()); |
- Sk4f b4 = Sk4f(srcf.b()); |
- Sk4f a4 = Sk4f(srcf.a()); |
+ Sk4f r4 = Sk4f(srcf.kth<SK_R32_SHIFT/8>()); |
+ Sk4f g4 = Sk4f(srcf.kth<SK_G32_SHIFT/8>()); |
+ Sk4f b4 = Sk4f(srcf.kth<SK_B32_SHIFT/8>()); |
+ Sk4f a4 = Sk4f(srcf.kth<SK_A32_SHIFT/8>()); |
// apply matrix |
Sk4f dst4 = c0 * r4 + c1 * g4 + c2 * b4 + c3 * a4 + c4; |
// clamp, re-premul, and write |
- dst[i] = SkPMFloat(premul(clamp_0_1(dst4))).round(); |
+ dst[i] = round(premul(clamp_0_1(dst4))); |
} |
} else { |
const State& state = fState; |