back to Sk4f for SkPMColor

#floats

BUG=skia:
BUG=skia:3592

Review URL: https://codereview.chromium.org/1047823002
This commit is contained in:
mtklein 2015-03-31 08:17:00 -07:00 committed by Commit bot
parent 39383a1946
commit 0340df5b36
6 changed files with 26 additions and 26 deletions

View File

@ -103,7 +103,7 @@ struct PMFloatGradientBench : public Benchmark {
SkPMColor fDevice[100];
void onDraw(const int loops, SkCanvas*) override {
Sk4s c0 = SkPMFloat::FromARGB(255, 255, 0, 0),
Sk4f c0 = SkPMFloat::FromARGB(255, 255, 0, 0),
c1 = SkPMFloat::FromARGB(255, 0, 0, 255),
dc = c1 - c0,
fx(0.1f),
@ -112,7 +112,7 @@ struct PMFloatGradientBench : public Benchmark {
dcdx4(dcdx+dcdx+dcdx+dcdx);
for (int n = 0; n < loops; n++) {
Sk4s a = c0 + dc*fx + Sk4s(0.5f), // The +0.5f lets us call trunc() instead of get().
Sk4f a = c0 + dc*fx + Sk4f(0.5f), // The +0.5f lets us call trunc() instead of get().
b = a + dcdx,
c = b + dcdx,
d = c + dcdx;

View File

@ -34,9 +34,9 @@ public:
#endif
// Freely autoconvert between SkPMFloat and Sk4s.
/*implicit*/ SkPMFloat(const Sk4s& fs) { fColors = fs; }
/*implicit*/ operator Sk4s() const { return fColors; }
// Freely autoconvert between SkPMFloat and Sk4f.
/*implicit*/ SkPMFloat(const Sk4f& fs) { fColors = fs; }
/*implicit*/ operator Sk4f() const { return fColors; }
float a() const { return fColors[SK_A32_SHIFT / 8]; }
float r() const { return fColors[SK_R32_SHIFT / 8]; }
@ -65,11 +65,11 @@ public:
}
private:
Sk4s fColors;
Sk4f fColors;
};
#ifdef SKNX_NO_SIMD
// Platform implementations of SkPMFloat assume Sk4s uses SSE or NEON. _none is generic.
// Platform implementations of SkPMFloat assume Sk4f uses SSE or NEON. _none is generic.
#include "../opts/SkPMFloat_none.h"
#else
#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3

View File

@ -255,9 +255,9 @@ uint32_t SkColorMatrixFilter::getFlags() const {
*/
static const float gInv255 = 0.0039215683f; // (1.0f / 255) - ULP == SkBits2Float(0x3B808080)
static Sk4s premul(const Sk4s& x) {
static Sk4f premul(const Sk4f& x) {
float scale = SkPMFloat(x).a() * gInv255;
Sk4s pm = x * Sk4s(scale, scale, scale, 1);
Sk4f pm = x * Sk4f(scale, scale, scale, 1);
#ifdef SK_DEBUG
SkPMFloat pmf(pm);
@ -267,9 +267,9 @@ static Sk4s premul(const Sk4s& x) {
return pm;
}
static Sk4s unpremul(const SkPMFloat& pm) {
static Sk4f unpremul(const SkPMFloat& pm) {
float scale = 255 / pm.a(); // candidate for fast/approx invert?
return Sk4s(pm) * Sk4s(scale, scale, scale, 1);
return Sk4f(pm) * Sk4f(scale, scale, scale, 1);
}
static Sk4f clamp_0_255(const Sk4f& value) {
@ -292,11 +292,11 @@ void SkColorMatrixFilter::filterSpan(const SkPMColor src[], int count, SkPMColor
#endif
if (use_floats) {
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
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
// todo: we could cache this in the constructor...
SkPMColor matrix_translate_pmcolor = SkPMFloat(premul(clamp_0_255(c4))).clamped();
@ -314,13 +314,13 @@ void SkColorMatrixFilter::filterSpan(const SkPMColor src[], int count, SkPMColor
srcf = unpremul(srcf);
}
Sk4s r4 = Sk4s(srcf.r());
Sk4s g4 = Sk4s(srcf.g());
Sk4s b4 = Sk4s(srcf.b());
Sk4s a4 = Sk4s(srcf.a());
Sk4f r4 = Sk4f(srcf.r());
Sk4f g4 = Sk4f(srcf.g());
Sk4f b4 = Sk4f(srcf.b());
Sk4f a4 = Sk4f(srcf.a());
// apply matrix
Sk4s dst4 = c0 * r4 + c1 * g4 + c2 * b4 + c3 * a4 + c4;
Sk4f dst4 = c0 * r4 + c1 * g4 + c2 * b4 + c3 * a4 + c4;
// clamp, re-premul, and write
dst[i] = SkPMFloat(premul(clamp_0_255(dst4))).get();

View File

@ -33,7 +33,7 @@ inline SkPMColor SkPMFloat::trunc() const {
inline SkPMColor SkPMFloat::get() const {
SkASSERT(this->isValid());
return SkPMFloat(Sk4s(0.5f) + *this).trunc();
return SkPMFloat(Sk4f(0.5f) + *this).trunc();
}
inline SkPMColor SkPMFloat::clamped() const {

View File

@ -32,7 +32,7 @@ inline SkPMColor SkPMFloat::trunc() const {
inline SkPMColor SkPMFloat::get() const {
SkASSERT(this->isValid());
return SkPMFloat(Sk4s(0.5f) + *this).trunc();
return SkPMFloat(Sk4f(0.5f) + *this).trunc();
}
inline SkPMColor SkPMFloat::clamped() const {

View File

@ -32,9 +32,9 @@ DEF_TEST(SkPMFloat, r) {
REPORTER_ASSERT(r, SkScalarNearlyEqual( 1.0f, clamped.g()));
REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.0f, clamped.b()));
// Test SkPMFloat <-> Sk4s conversion.
Sk4s fs = clamped;
SkPMFloat scaled = fs * Sk4s(0.25f);
// Test SkPMFloat <-> Sk4f conversion.
Sk4f fs = clamped;
SkPMFloat scaled = fs * Sk4f(0.25f);
REPORTER_ASSERT(r, SkScalarNearlyEqual(63.75f, scaled.a()));
REPORTER_ASSERT(r, SkScalarNearlyEqual(38.25f, scaled.r()));
REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.25f, scaled.g()));