1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
SkPMFloat(SkPMColor c)8 inline SkPMFloat::SkPMFloat(SkPMColor c) {
9 *this = SkPMFloat::FromARGB(SkGetPackedA32(c),
10 SkGetPackedR32(c),
11 SkGetPackedG32(c),
12 SkGetPackedB32(c));
13 SkASSERT(this->isValid());
14 }
15
trunc()16 inline SkPMColor SkPMFloat::trunc() const {
17 return SkPackARGB32(this->a(), this->r(), this->g(), this->b());
18 }
19
round()20 inline SkPMColor SkPMFloat::round() const {
21 SkPMColor c = SkPackARGB32(this->a()+0.5f, this->r()+0.5f, this->g()+0.5f, this->b()+0.5f);
22 SkPMColorAssert(c);
23 return c;
24 }
25
roundClamp()26 inline SkPMColor SkPMFloat::roundClamp() const {
27 float a = this->a(),
28 r = this->r(),
29 g = this->g(),
30 b = this->b();
31 a = a < 0 ? 0 : (a > 255 ? 255 : a);
32 r = r < 0 ? 0 : (r > 255 ? 255 : r);
33 g = g < 0 ? 0 : (g > 255 ? 255 : g);
34 b = b < 0 ? 0 : (b > 255 ? 255 : b);
35 SkPMColor c = SkPackARGB32(a+0.5f, r+0.5f, g+0.5f, b+0.5f);
36 SkPMColorAssert(c);
37 return c;
38 }
39
From4PMColors(const SkPMColor colors[4],SkPMFloat * a,SkPMFloat * b,SkPMFloat * c,SkPMFloat * d)40 inline void SkPMFloat::From4PMColors(const SkPMColor colors[4],
41 SkPMFloat* a, SkPMFloat* b, SkPMFloat* c, SkPMFloat* d) {
42 *a = FromPMColor(colors[0]);
43 *b = FromPMColor(colors[1]);
44 *c = FromPMColor(colors[2]);
45 *d = FromPMColor(colors[3]);
46 }
47
RoundTo4PMColors(const SkPMFloat & a,const SkPMFloat & b,const SkPMFloat & c,const SkPMFloat & d,SkPMColor colors[4])48 inline void SkPMFloat::RoundTo4PMColors(
49 const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFloat& d,
50 SkPMColor colors[4]) {
51 colors[0] = a.round();
52 colors[1] = b.round();
53 colors[2] = c.round();
54 colors[3] = d.round();
55 }
56
RoundClampTo4PMColors(const SkPMFloat & a,const SkPMFloat & b,const SkPMFloat & c,const SkPMFloat & d,SkPMColor colors[4])57 inline void SkPMFloat::RoundClampTo4PMColors(
58 const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFloat& d,
59 SkPMColor colors[4]) {
60 colors[0] = a.roundClamp();
61 colors[1] = b.roundClamp();
62 colors[2] = c.roundClamp();
63 colors[3] = d.roundClamp();
64 }
65