| 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 namespace { // See SkPMFloat.h | 8 namespace { // See SkPMFloat.h |
| 9 | 9 |
| 10 inline SkPMFloat::SkPMFloat(SkPMColor c) { | 10 inline SkPMFloat::SkPMFloat(SkPMColor c) { |
| 11 *this = SkPMFloat::FromARGB(SkGetPackedA32(c), | 11 float inv255 = 1.0f/255; |
| 12 SkGetPackedR32(c), | 12 *this = SkPMFloat::FromARGB(SkGetPackedA32(c) * inv255, |
| 13 SkGetPackedG32(c), | 13 SkGetPackedR32(c) * inv255, |
| 14 SkGetPackedB32(c)); | 14 SkGetPackedG32(c) * inv255, |
| 15 SkGetPackedB32(c) * inv255); |
| 15 SkASSERT(this->isValid()); | 16 SkASSERT(this->isValid()); |
| 16 } | 17 } |
| 17 | 18 |
| 18 inline SkPMColor SkPMFloat::trunc() const { | |
| 19 return SkPackARGB32(this->a(), this->r(), this->g(), this->b()); | |
| 20 } | |
| 21 | |
| 22 inline SkPMColor SkPMFloat::round() const { | 19 inline SkPMColor SkPMFloat::round() const { |
| 23 SkPMColor c = SkPackARGB32(this->a()+0.5f, this->r()+0.5f, this->g()+0.5f, t
his->b()+0.5f); | 20 float a = this->a(), |
| 21 r = this->r(), |
| 22 g = this->g(), |
| 23 b = this->b(); |
| 24 a = a < 0 ? 0 : (a > 1 ? 1 : a); |
| 25 r = r < 0 ? 0 : (r > 1 ? 1 : r); |
| 26 g = g < 0 ? 0 : (g > 1 ? 1 : g); |
| 27 b = b < 0 ? 0 : (b > 1 ? 1 : b); |
| 28 SkPMColor c = SkPackARGB32(255*a+0.5f, 255*r+0.5f, 255*g+0.5f, 255*b+0.5f); |
| 24 SkPMColorAssert(c); | 29 SkPMColorAssert(c); |
| 25 return c; | 30 return c; |
| 26 } | 31 } |
| 27 | 32 |
| 28 inline SkPMColor SkPMFloat::roundClamp() const { | |
| 29 float a = this->a(), | |
| 30 r = this->r(), | |
| 31 g = this->g(), | |
| 32 b = this->b(); | |
| 33 a = a < 0 ? 0 : (a > 255 ? 255 : a); | |
| 34 r = r < 0 ? 0 : (r > 255 ? 255 : r); | |
| 35 g = g < 0 ? 0 : (g > 255 ? 255 : g); | |
| 36 b = b < 0 ? 0 : (b > 255 ? 255 : b); | |
| 37 SkPMColor c = SkPackARGB32(a+0.5f, r+0.5f, g+0.5f, b+0.5f); | |
| 38 SkPMColorAssert(c); | |
| 39 return c; | |
| 40 } | |
| 41 | |
| 42 inline void SkPMFloat::From4PMColors(const SkPMColor colors[4], | |
| 43 SkPMFloat* a, SkPMFloat* b, SkPMFloat* c, S
kPMFloat* d) { | |
| 44 *a = FromPMColor(colors[0]); | |
| 45 *b = FromPMColor(colors[1]); | |
| 46 *c = FromPMColor(colors[2]); | |
| 47 *d = FromPMColor(colors[3]); | |
| 48 } | |
| 49 | |
| 50 inline void SkPMFloat::RoundTo4PMColors( | |
| 51 const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFlo
at& d, | |
| 52 SkPMColor colors[4]) { | |
| 53 colors[0] = a.round(); | |
| 54 colors[1] = b.round(); | |
| 55 colors[2] = c.round(); | |
| 56 colors[3] = d.round(); | |
| 57 } | |
| 58 | |
| 59 inline void SkPMFloat::RoundClampTo4PMColors( | |
| 60 const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFlo
at& d, | |
| 61 SkPMColor colors[4]) { | |
| 62 colors[0] = a.roundClamp(); | |
| 63 colors[1] = b.roundClamp(); | |
| 64 colors[2] = c.roundClamp(); | |
| 65 colors[3] = d.roundClamp(); | |
| 66 } | |
| 67 | |
| 68 } // namespace | 33 } // namespace |
| OLD | NEW |