| mtklein | f94fa71 | 2015-03-18 09:51:23 -0700 | [diff] [blame^] | 1 | inline SkPMFloat& SkPMFloat::operator=(const SkPMFloat& that) { |
| 2 | for (int i = 0; i < 4; i++) { fColor[i] = that.fColor[i]; } |
| 3 | return *this; |
| 4 | } |
| mtklein | a2f4be7 | 2015-02-23 10:04:34 -0800 | [diff] [blame] | 5 | |
| mtklein | 4e644f5 | 2015-03-04 11:25:27 -0800 | [diff] [blame] | 6 | inline SkPMFloat::SkPMFloat(SkPMColor c) { |
| 7 | *this = SkPMFloat::FromARGB(SkGetPackedA32(c), |
| 8 | SkGetPackedR32(c), |
| 9 | SkGetPackedG32(c), |
| 10 | SkGetPackedB32(c)); |
| mtklein | a2f4be7 | 2015-02-23 10:04:34 -0800 | [diff] [blame] | 11 | SkASSERT(this->isValid()); |
| 12 | } |
| 13 | |
| 14 | inline SkPMColor SkPMFloat::get() const { |
| 15 | SkASSERT(this->isValid()); |
| mtklein | 0aebf5d | 2015-03-03 08:57:07 -0800 | [diff] [blame] | 16 | return SkPackARGB32(this->a()+0.5f, this->r()+0.5f, this->g()+0.5f, this->b()+0.5f); |
| mtklein | a2f4be7 | 2015-02-23 10:04:34 -0800 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | inline SkPMColor SkPMFloat::clamped() const { |
| 20 | float a = this->a(), |
| 21 | r = this->r(), |
| 22 | g = this->g(), |
| 23 | b = this->b(); |
| mtklein | 60d2a32 | 2015-03-03 07:46:15 -0800 | [diff] [blame] | 24 | a = a < 0 ? 0 : (a > 255 ? 255 : a); |
| 25 | r = r < 0 ? 0 : (r > 255 ? 255 : r); |
| 26 | g = g < 0 ? 0 : (g > 255 ? 255 : g); |
| 27 | b = b < 0 ? 0 : (b > 255 ? 255 : b); |
| mtklein | 0aebf5d | 2015-03-03 08:57:07 -0800 | [diff] [blame] | 28 | return SkPackARGB32(a+0.5f, r+0.5f, g+0.5f, b+0.5f); |
| mtklein | a2f4be7 | 2015-02-23 10:04:34 -0800 | [diff] [blame] | 29 | } |
| mtklein | 91fd737 | 2015-03-06 06:15:44 -0800 | [diff] [blame] | 30 | |
| 31 | inline void SkPMFloat::From4PMColors(SkPMFloat floats[4], const SkPMColor colors[4]) { |
| 32 | for (int i = 0; i < 4; i++) { floats[i] = FromPMColor(colors[i]); } |
| 33 | } |
| 34 | |
| 35 | inline void SkPMFloat::To4PMColors(SkPMColor colors[4], const SkPMFloat floats[4]) { |
| 36 | for (int i = 0; i < 4; i++) { colors[i] = floats[i].get(); } |
| 37 | } |
| 38 | |
| 39 | inline void SkPMFloat::ClampTo4PMColors(SkPMColor colors[4], const SkPMFloat floats[4]) { |
| 40 | for (int i = 0; i < 4; i++) { colors[i] = floats[i].clamped(); } |
| 41 | } |