| 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 | |
| 21 | inline SkPMColor SkPMFloat::get() const { |
| 22 | SkASSERT(this->isValid()); |
| mtklein | 0aebf5d | 2015-03-03 08:57:07 -0800 | [diff] [blame] | 23 | 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] | 24 | } |
| 25 | |
| 26 | inline SkPMColor SkPMFloat::clamped() const { |
| 27 | float a = this->a(), |
| 28 | r = this->r(), |
| 29 | g = this->g(), |
| 30 | b = this->b(); |
| mtklein | 60d2a32 | 2015-03-03 07:46:15 -0800 | [diff] [blame] | 31 | a = a < 0 ? 0 : (a > 255 ? 255 : a); |
| 32 | r = r < 0 ? 0 : (r > 255 ? 255 : r); |
| 33 | g = g < 0 ? 0 : (g > 255 ? 255 : g); |
| 34 | b = b < 0 ? 0 : (b > 255 ? 255 : b); |
| mtklein | 0aebf5d | 2015-03-03 08:57:07 -0800 | [diff] [blame] | 35 | 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] | 36 | } |
| mtklein | 91fd737 | 2015-03-06 06:15:44 -0800 | [diff] [blame] | 37 | |
| mtklein | 15391ee | 2015-03-25 13:43:34 -0700 | [diff] [blame^] | 38 | inline void SkPMFloat::From4PMColors(const SkPMColor colors[4], |
| 39 | SkPMFloat* a, SkPMFloat* b, SkPMFloat* c, SkPMFloat* d) { |
| 40 | *a = FromPMColor(colors[0]); |
| 41 | *b = FromPMColor(colors[1]); |
| 42 | *c = FromPMColor(colors[2]); |
| 43 | *d = FromPMColor(colors[3]); |
| mtklein | 91fd737 | 2015-03-06 06:15:44 -0800 | [diff] [blame] | 44 | } |
| 45 | |
| mtklein | 15391ee | 2015-03-25 13:43:34 -0700 | [diff] [blame^] | 46 | inline void SkPMFloat::To4PMColors( |
| 47 | const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFloat& d, |
| 48 | SkPMColor colors[4]) { |
| 49 | colors[0] = a.get(); |
| 50 | colors[1] = b.get(); |
| 51 | colors[2] = c.get(); |
| 52 | colors[3] = d.get(); |
| mtklein | 91fd737 | 2015-03-06 06:15:44 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| mtklein | 15391ee | 2015-03-25 13:43:34 -0700 | [diff] [blame^] | 55 | inline void SkPMFloat::ClampTo4PMColors( |
| 56 | const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFloat& d, |
| 57 | SkPMColor colors[4]) { |
| 58 | colors[0] = a.clamped(); |
| 59 | colors[1] = b.clamped(); |
| 60 | colors[2] = c.clamped(); |
| 61 | colors[3] = d.clamped(); |
| mtklein | 91fd737 | 2015-03-06 06:15:44 -0800 | [diff] [blame] | 62 | } |