Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Unified Diff: src/core/SkPMFloat.h

Issue 1308903003: Templatize SkPMFloat to support both 1 and 255 biases. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: pump the loops for Android Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkPMFloat.h
diff --git a/src/core/SkPMFloat.h b/src/core/SkPMFloat.h
index 4a5621f5b3cc62cf6ae11b5173d8f449fcce10ef..46288323071b5032e05c805cfba45aafb07e2145 100644
--- a/src/core/SkPMFloat.h
+++ b/src/core/SkPMFloat.h
@@ -21,8 +21,11 @@
namespace {
// A pre-multiplied color storing each component in the same order as SkPMColor,
-// but as a float in the range [0, 1].
+// but as a float in the range [0, kBias],
+// where kBias is either 1 (easier to work with) or 255 (sometimes a little faster).
+template <int kBias>
class SkPMFloat : public Sk4f {
+ static_assert(kBias == 1 || kBias == 255, "");
public:
static SkPMFloat FromPMColor(SkPMColor c) { return SkPMFloat(c); }
static SkPMFloat FromARGB(float a, float r, float g, float b) { return SkPMFloat(a,r,g,b); }
@@ -47,10 +50,10 @@ public:
float g() const { return this->kth<SK_G32_SHIFT / 8>(); }
float b() const { return this->kth<SK_B32_SHIFT / 8>(); }
- SkPMColor round() const; // Rounds from [0.0f, 1.0f] to [0, 255], clamping if out of range.
+ SkPMColor round() const; // Rounds from [0, kBias] to [0, 255], clamping if out of range.
bool isValid() const {
- return this->a() >= 0 && this->a() <= 1
+ return this->a() >= 0 && this->a() <= kBias
&& this->r() >= 0 && this->r() <= this->a()
&& this->g() >= 0 && this->g() <= this->a()
&& this->b() >= 0 && this->b() <= this->a();

Powered by Google App Engine
This is Rietveld 408576698