aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/opts/SkPMFloat_none.h
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-06-25 08:56:28 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-06-25 08:56:28 -0700
commite9a3e3c17a313942042d6cfb9f4f0361a900d9e7 (patch)
tree913d6d293e2578f223ec82f2bbac69fbf43b711b /src/opts/SkPMFloat_none.h
parent538bacb4bb3ceac7786108cd68b04ed58b1c29c7 (diff)
Convert SkPMFloat to [0,1] range and prune its API.
Now that Sk4px exists, there's a lot less sense in eeking out every cycle of speed from SkPMFloat: if we need to go _really_ fast, we should use Sk4px. SkPMFloat's going to be used for things that are already slow: large-range intermediates, divides, sqrts, etc. A [0,1] range is easier to work with, and can even be faster if we eliminate enough *255 and *1/255 steps. This is particularly true on ARM, where NEON can do the *255 and /255 steps for us while converting float<->int. We have lots of experimental SkPMFloat <-> SkPMColor APIs that I'm now removing. Of the existing APIs, roundClamp() is the sanest, so I've kept only that, now called round(). The 4-at-a-time APIs never panned out, so they're gone. There will be small diffs on: colormatrix coloremoji colorfilterimagefilter fadefilter imagefilters_xfermodes imagefilterscropexpand imagefiltersgraph tileimagefilter BUG=skia: Review URL: https://codereview.chromium.org/1201343004
Diffstat (limited to 'src/opts/SkPMFloat_none.h')
-rw-r--r--src/opts/SkPMFloat_none.h55
1 files changed, 10 insertions, 45 deletions
diff --git a/src/opts/SkPMFloat_none.h b/src/opts/SkPMFloat_none.h
index 9bb584ed86..ba773564d6 100644
--- a/src/opts/SkPMFloat_none.h
+++ b/src/opts/SkPMFloat_none.h
@@ -8,61 +8,26 @@
namespace { // See SkPMFloat.h
inline SkPMFloat::SkPMFloat(SkPMColor c) {
- *this = SkPMFloat::FromARGB(SkGetPackedA32(c),
- SkGetPackedR32(c),
- SkGetPackedG32(c),
- SkGetPackedB32(c));
+ float inv255 = 1.0f/255;
+ *this = SkPMFloat::FromARGB(SkGetPackedA32(c) * inv255,
+ SkGetPackedR32(c) * inv255,
+ SkGetPackedG32(c) * inv255,
+ SkGetPackedB32(c) * inv255);
SkASSERT(this->isValid());
}
-inline SkPMColor SkPMFloat::trunc() const {
- return SkPackARGB32(this->a(), this->r(), this->g(), this->b());
-}
-
inline SkPMColor SkPMFloat::round() const {
- SkPMColor c = SkPackARGB32(this->a()+0.5f, this->r()+0.5f, this->g()+0.5f, this->b()+0.5f);
- SkPMColorAssert(c);
- return c;
-}
-
-inline SkPMColor SkPMFloat::roundClamp() const {
float a = this->a(),
r = this->r(),
g = this->g(),
b = this->b();
- a = a < 0 ? 0 : (a > 255 ? 255 : a);
- r = r < 0 ? 0 : (r > 255 ? 255 : r);
- g = g < 0 ? 0 : (g > 255 ? 255 : g);
- b = b < 0 ? 0 : (b > 255 ? 255 : b);
- SkPMColor c = SkPackARGB32(a+0.5f, r+0.5f, g+0.5f, b+0.5f);
+ 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);
+ SkPMColor c = SkPackARGB32(255*a+0.5f, 255*r+0.5f, 255*g+0.5f, 255*b+0.5f);
SkPMColorAssert(c);
return c;
}
-inline void SkPMFloat::From4PMColors(const SkPMColor colors[4],
- SkPMFloat* a, SkPMFloat* b, SkPMFloat* c, SkPMFloat* d) {
- *a = FromPMColor(colors[0]);
- *b = FromPMColor(colors[1]);
- *c = FromPMColor(colors[2]);
- *d = FromPMColor(colors[3]);
-}
-
-inline void SkPMFloat::RoundTo4PMColors(
- const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFloat& d,
- SkPMColor colors[4]) {
- colors[0] = a.round();
- colors[1] = b.round();
- colors[2] = c.round();
- colors[3] = d.round();
-}
-
-inline void SkPMFloat::RoundClampTo4PMColors(
- const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFloat& d,
- SkPMColor colors[4]) {
- colors[0] = a.roundClamp();
- colors[1] = b.roundClamp();
- colors[2] = c.roundClamp();
- colors[3] = d.roundClamp();
-}
-
} // namespace