aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-03-30 10:50:27 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-03-30 10:50:27 -0700
commitc9adb05b64fa0bfadf9d1a782afcda470da68c9e (patch)
tree6413cc149b70ae36181e9f0789246b9db24447f0 /src/effects
parent23ac62c83a49d675a38f1c20462b5537f3c8af01 (diff)
Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T>
The primary feature this delivers is SkNf and SkNd for arbitrary power-of-two N. Non-specialized types or types larger than 128 bits should now Just Work (and we can drop in a specialization to make them faster). Sk4s is now just a typedef for SkNf<4, SkScalar>; Sk4d is SkNf<4, double>, Sk2f SkNf<2, float>, etc. This also makes implementing new specializations easier and more encapsulated. We're now using template specialization, which means the specialized versions don't have to leak out so much from SkNx_sse.h and SkNx_neon.h. This design leaves us room to grow up, e.g to SkNf<8, SkScalar> == Sk8s, and to grown down too, to things like SkNi<8, uint16_t> == Sk8h. To simplify things, I've stripped away most APIs (swizzles, casts, reinterpret_casts) that no one's using yet. I will happily add them back if they seem useful. You shouldn't feel bad about using any of the typedef Sk4s, Sk4f, Sk4d, Sk2s, Sk2f, Sk2d, Sk4i, etc. Here's how you should feel: - Sk4f, Sk4s, Sk2d: feel awesome - Sk2f, Sk2s, Sk4d: feel pretty good No public API changes. TBR=reed@google.com BUG=skia:3592 Review URL: https://codereview.chromium.org/1048593002
Diffstat (limited to 'src/effects')
-rw-r--r--src/effects/SkColorMatrixFilter.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp
index a406eda564..7c86e2e046 100644
--- a/src/effects/SkColorMatrixFilter.cpp
+++ b/src/effects/SkColorMatrixFilter.cpp
@@ -255,9 +255,9 @@ uint32_t SkColorMatrixFilter::getFlags() const {
*/
static const float gInv255 = 0.0039215683f; // (1.0f / 255) - ULP == SkBits2Float(0x3B808080)
-static Sk4f premul(const Sk4f& x) {
+static Sk4s premul(const Sk4s& x) {
float scale = SkPMFloat(x).a() * gInv255;
- Sk4f pm = x * Sk4f(scale, scale, scale, 1);
+ Sk4s pm = x * Sk4s(scale, scale, scale, 1);
#ifdef SK_DEBUG
SkPMFloat pmf(pm);
@@ -267,9 +267,9 @@ static Sk4f premul(const Sk4f& x) {
return pm;
}
-static Sk4f unpremul(const SkPMFloat& pm) {
+static Sk4s unpremul(const SkPMFloat& pm) {
float scale = 255 / pm.a(); // candidate for fast/approx invert?
- return Sk4f(pm) * Sk4f(scale, scale, scale, 1);
+ return Sk4s(pm) * Sk4s(scale, scale, scale, 1);
}
void SkColorMatrixFilter::filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const {
@@ -288,11 +288,11 @@ void SkColorMatrixFilter::filterSpan(const SkPMColor src[], int count, SkPMColor
#endif
if (use_floats) {
- const Sk4f c0 = Sk4f::Load(fTranspose + 0);
- const Sk4f c1 = Sk4f::Load(fTranspose + 4);
- const Sk4f c2 = Sk4f::Load(fTranspose + 8);
- const Sk4f c3 = Sk4f::Load(fTranspose + 12);
- const Sk4f c4 = Sk4f::Load(fTranspose + 16); // translates
+ const Sk4s c0 = Sk4s::Load(fTranspose + 0);
+ const Sk4s c1 = Sk4s::Load(fTranspose + 4);
+ const Sk4s c2 = Sk4s::Load(fTranspose + 8);
+ const Sk4s c3 = Sk4s::Load(fTranspose + 12);
+ const Sk4s c4 = Sk4s::Load(fTranspose + 16); // translates
SkPMColor matrix_translate_pmcolor = SkPMFloat(premul(c4)).clamped();
@@ -309,16 +309,16 @@ void SkColorMatrixFilter::filterSpan(const SkPMColor src[], int count, SkPMColor
srcf = unpremul(srcf);
}
- Sk4f r4 = Sk4f(srcf.r());
- Sk4f g4 = Sk4f(srcf.g());
- Sk4f b4 = Sk4f(srcf.b());
- Sk4f a4 = Sk4f(srcf.a());
+ Sk4s r4 = Sk4s(srcf.r());
+ Sk4s g4 = Sk4s(srcf.g());
+ Sk4s b4 = Sk4s(srcf.b());
+ Sk4s a4 = Sk4s(srcf.a());
// apply matrix
- Sk4f dst4 = c0 * r4 + c1 * g4 + c2 * b4 + c3 * a4 + c4;
+ Sk4s dst4 = c0 * r4 + c1 * g4 + c2 * b4 + c3 * a4 + c4;
// pin before re-premul (convention for color-matrix???)
- dst4 = Sk4f::Max(Sk4f(0), Sk4f::Min(Sk4f(255), dst4));
+ dst4 = Sk4s::Max(Sk4s(0), Sk4s::Min(Sk4s(255), dst4));
// re-premul and write
dst[i] = SkPMFloat(premul(dst4)).get();