| mtklein | 15391ee | 2015-03-25 13:43:34 -0700 | [diff] [blame] | 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 | |
| mtklein | f94fa71 | 2015-03-18 09:51:23 -0700 | [diff] [blame] | 8 | inline SkPMFloat& SkPMFloat::operator=(const SkPMFloat& that) { |
| 9 | for (int i = 0; i < 4; i++) { fColor[i] = that.fColor[i]; } |
| 10 | return *this; |
| 11 | } |
| mtklein | a2f4be7 | 2015-02-23 10:04:34 -0800 | [diff] [blame] | 12 | |
| mtklein | 4e644f5 | 2015-03-04 11:25:27 -0800 | [diff] [blame] | 13 | inline SkPMFloat::SkPMFloat(SkPMColor c) { |
| 14 | *this = SkPMFloat::FromARGB(SkGetPackedA32(c), |
| 15 | SkGetPackedR32(c), |
| 16 | SkGetPackedG32(c), |
| 17 | SkGetPackedB32(c)); |
| mtklein | a2f4be7 | 2015-02-23 10:04:34 -0800 | [diff] [blame] | 18 | SkASSERT(this->isValid()); |
| 19 | } |
| 20 | |
| mtklein | 3d4c4a5 | 2015-03-26 12:32:29 -0700 | [diff] [blame] | 21 | inline SkPMColor SkPMFloat::trunc() const { |
| 22 | return SkPackARGB32(this->a(), this->r(), this->g(), this->b()); |
| 23 | } |
| 24 | |
| mtklein | a2f4be7 | 2015-02-23 10:04:34 -0800 | [diff] [blame] | 25 | inline SkPMColor SkPMFloat::get() const { |
| 26 | SkASSERT(this->isValid()); |
| mtklein | 0aebf5d | 2015-03-03 08:57:07 -0800 | [diff] [blame] | 27 | 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] | 28 | } |
| 29 | |
| 30 | inline SkPMColor SkPMFloat::clamped() const { |
| 31 | float a = this->a(), |
| 32 | r = this->r(), |
| 33 | g = this->g(), |
| 34 | b = this->b(); |
| mtklein | 60d2a32 | 2015-03-03 07:46:15 -0800 | [diff] [blame] | 35 | a = a < 0 ? 0 : (a > 255 ? 255 : a); |
| 36 | r = r < 0 ? 0 : (r > 255 ? 255 : r); |
| 37 | g = g < 0 ? 0 : (g > 255 ? 255 : g); |
| 38 | b = b < 0 ? 0 : (b > 255 ? 255 : b); |
| mtklein | 0aebf5d | 2015-03-03 08:57:07 -0800 | [diff] [blame] | 39 | 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] | 40 | } |
| mtklein | 91fd737 | 2015-03-06 06:15:44 -0800 | [diff] [blame] | 41 | |
| mtklein | 15391ee | 2015-03-25 13:43:34 -0700 | [diff] [blame] | 42 | inline void SkPMFloat::From4PMColors(const SkPMColor colors[4], |
| 43 | SkPMFloat* a, SkPMFloat* b, SkPMFloat* c, SkPMFloat* d) { |
| 44 | *a = FromPMColor(colors[0]); |
| 45 | *b = FromPMColor(colors[1]); |
| 46 | *c = FromPMColor(colors[2]); |
| 47 | *d = FromPMColor(colors[3]); |
| mtklein | 91fd737 | 2015-03-06 06:15:44 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| mtklein | 15391ee | 2015-03-25 13:43:34 -0700 | [diff] [blame] | 50 | inline void SkPMFloat::To4PMColors( |
| 51 | const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFloat& d, |
| 52 | SkPMColor colors[4]) { |
| 53 | colors[0] = a.get(); |
| 54 | colors[1] = b.get(); |
| 55 | colors[2] = c.get(); |
| 56 | colors[3] = d.get(); |
| mtklein | 91fd737 | 2015-03-06 06:15:44 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| mtklein | 15391ee | 2015-03-25 13:43:34 -0700 | [diff] [blame] | 59 | inline void SkPMFloat::ClampTo4PMColors( |
| 60 | const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFloat& d, |
| 61 | SkPMColor colors[4]) { |
| 62 | colors[0] = a.clamped(); |
| 63 | colors[1] = b.clamped(); |
| 64 | colors[2] = c.clamped(); |
| 65 | colors[3] = d.clamped(); |
| mtklein | 91fd737 | 2015-03-06 06:15:44 -0800 | [diff] [blame] | 66 | } |