blob: a11fe241cfa1fe0a5de20d6f535cd44b2ccf80fe [file] [log] [blame]
mtkleina2f4be72015-02-23 10:04:34 -08001#include "SkColorPriv.h"
mtkleina2f4be72015-02-23 10:04:34 -08002
3inline void SkPMFloat::set(SkPMColor c) {
4 float scale = 1.0f / 255.0f;
5 this->setA(SkGetPackedA32(c) * scale);
6 this->setR(SkGetPackedR32(c) * scale);
7 this->setG(SkGetPackedG32(c) * scale);
8 this->setB(SkGetPackedB32(c) * scale);
9 SkASSERT(this->isValid());
10}
11
12inline SkPMColor SkPMFloat::get() const {
13 SkASSERT(this->isValid());
14 return SkPackARGB32(this->a() * 255, this->r() * 255, this->g() * 255, this->b() * 255);
15}
16
17inline SkPMColor SkPMFloat::clamped() const {
18 float a = this->a(),
19 r = this->r(),
20 g = this->g(),
21 b = this->b();
22 a = a < 0 ? 0 : (a > 1 ? 1 : a);
23 r = r < 0 ? 0 : (r > 1 ? 1 : r);
24 g = g < 0 ? 0 : (g > 1 ? 1 : g);
25 b = b < 0 ? 0 : (b > 1 ? 1 : b);
26 return SkPackARGB32(a * 255, r * 255, g * 255, b * 255);
27}