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