| 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 SK_ALWAYS_INLINE SkPMFloat::SkPMFloat(SkPMColor c) { |
| 9 | |
| 10 inline SkPMFloat::SkPMFloat(SkPMColor c) { | |
| 11 float inv255 = 1.0f/255; | 9 float inv255 = 1.0f/255; |
| 12 *this = SkPMFloat::FromARGB(SkGetPackedA32(c) * inv255, | 10 *this = SkPMFloat::FromARGB(SkGetPackedA32(c) * inv255, |
| 13 SkGetPackedR32(c) * inv255, | 11 SkGetPackedR32(c) * inv255, |
| 14 SkGetPackedG32(c) * inv255, | 12 SkGetPackedG32(c) * inv255, |
| 15 SkGetPackedB32(c) * inv255); | 13 SkGetPackedB32(c) * inv255); |
| 16 SkASSERT(this->isValid()); | 14 SkASSERT(this->isValid()); |
| 17 } | 15 } |
| 18 | 16 |
| 19 inline SkPMColor SkPMFloat::round() const { | 17 SK_ALWAYS_INLINE SkPMColor SkPMFloat::round() const { |
| 20 float a = this->a(), | 18 float a = this->a(), |
| 21 r = this->r(), | 19 r = this->r(), |
| 22 g = this->g(), | 20 g = this->g(), |
| 23 b = this->b(); | 21 b = this->b(); |
| 24 a = a < 0 ? 0 : (a > 1 ? 1 : a); | 22 a = a < 0 ? 0 : (a > 1 ? 1 : a); |
| 25 r = r < 0 ? 0 : (r > 1 ? 1 : r); | 23 r = r < 0 ? 0 : (r > 1 ? 1 : r); |
| 26 g = g < 0 ? 0 : (g > 1 ? 1 : g); | 24 g = g < 0 ? 0 : (g > 1 ? 1 : g); |
| 27 b = b < 0 ? 0 : (b > 1 ? 1 : b); | 25 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); | 26 SkPMColor c = SkPackARGB32(255*a+0.5f, 255*r+0.5f, 255*g+0.5f, 255*b+0.5f); |
| 29 SkPMColorAssert(c); | 27 SkPMColorAssert(c); |
| 30 return c; | 28 return c; |
| 31 } | 29 } |
| 32 | 30 |
| 33 inline Sk4f SkPMFloat::alphas() const { | 31 SK_ALWAYS_INLINE Sk4f SkPMFloat::alphas() const { |
| 34 return Sk4f(this->a()); | 32 return Sk4f(this->a()); |
| 35 } | 33 } |
| 36 | |
| 37 } // namespace | |
| OLD | NEW |