blob: a33fa7a28d91e6d2068ee4ab77c427d90bcafc30 [file] [log] [blame]
mtkleina2f4be72015-02-23 10:04:34 -08001#include "SkColorPriv.h"
mtkleina2f4be72015-02-23 10:04:34 -08002
mtklein4e644f52015-03-04 11:25:27 -08003inline SkPMFloat::SkPMFloat(SkPMColor c) {
4 *this = SkPMFloat::FromARGB(SkGetPackedA32(c),
5 SkGetPackedR32(c),
6 SkGetPackedG32(c),
7 SkGetPackedB32(c));
mtkleina2f4be72015-02-23 10:04:34 -08008 SkASSERT(this->isValid());
9}
10
11inline SkPMColor SkPMFloat::get() const {
12 SkASSERT(this->isValid());
mtklein0aebf5d2015-03-03 08:57:07 -080013 return SkPackARGB32(this->a()+0.5f, this->r()+0.5f, this->g()+0.5f, this->b()+0.5f);
mtkleina2f4be72015-02-23 10:04:34 -080014}
15
16inline SkPMColor SkPMFloat::clamped() const {
17 float a = this->a(),
18 r = this->r(),
19 g = this->g(),
20 b = this->b();
mtklein60d2a322015-03-03 07:46:15 -080021 a = a < 0 ? 0 : (a > 255 ? 255 : a);
22 r = r < 0 ? 0 : (r > 255 ? 255 : r);
23 g = g < 0 ? 0 : (g > 255 ? 255 : g);
24 b = b < 0 ? 0 : (b > 255 ? 255 : b);
mtklein0aebf5d2015-03-03 08:57:07 -080025 return SkPackARGB32(a+0.5f, r+0.5f, g+0.5f, b+0.5f);
mtkleina2f4be72015-02-23 10:04:34 -080026}
mtklein91fd7372015-03-06 06:15:44 -080027
28inline void SkPMFloat::From4PMColors(SkPMFloat floats[4], const SkPMColor colors[4]) {
29 for (int i = 0; i < 4; i++) { floats[i] = FromPMColor(colors[i]); }
30}
31
32inline void SkPMFloat::To4PMColors(SkPMColor colors[4], const SkPMFloat floats[4]) {
33 for (int i = 0; i < 4; i++) { colors[i] = floats[i].get(); }
34}
35
36inline void SkPMFloat::ClampTo4PMColors(SkPMColor colors[4], const SkPMFloat floats[4]) {
37 for (int i = 0; i < 4; i++) { colors[i] = floats[i].clamped(); }
38}