blob: 00705aa582bdca2dfc09222b5100fd543fe3ce11 [file] [log] [blame]
mtklein15391ee2015-03-25 13:43:34 -07001/*
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
mtkleinf94fa712015-03-18 09:51:23 -07008inline SkPMFloat& SkPMFloat::operator=(const SkPMFloat& that) {
9 for (int i = 0; i < 4; i++) { fColor[i] = that.fColor[i]; }
10 return *this;
11}
mtkleina2f4be72015-02-23 10:04:34 -080012
mtklein4e644f52015-03-04 11:25:27 -080013inline SkPMFloat::SkPMFloat(SkPMColor c) {
14 *this = SkPMFloat::FromARGB(SkGetPackedA32(c),
15 SkGetPackedR32(c),
16 SkGetPackedG32(c),
17 SkGetPackedB32(c));
mtkleina2f4be72015-02-23 10:04:34 -080018 SkASSERT(this->isValid());
19}
20
21inline SkPMColor SkPMFloat::get() const {
22 SkASSERT(this->isValid());
mtklein0aebf5d2015-03-03 08:57:07 -080023 return SkPackARGB32(this->a()+0.5f, this->r()+0.5f, this->g()+0.5f, this->b()+0.5f);
mtkleina2f4be72015-02-23 10:04:34 -080024}
25
26inline SkPMColor SkPMFloat::clamped() const {
27 float a = this->a(),
28 r = this->r(),
29 g = this->g(),
30 b = this->b();
mtklein60d2a322015-03-03 07:46:15 -080031 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);
mtklein0aebf5d2015-03-03 08:57:07 -080035 return SkPackARGB32(a+0.5f, r+0.5f, g+0.5f, b+0.5f);
mtkleina2f4be72015-02-23 10:04:34 -080036}
mtklein91fd7372015-03-06 06:15:44 -080037
mtklein15391ee2015-03-25 13:43:34 -070038inline 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]);
mtklein91fd7372015-03-06 06:15:44 -080044}
45
mtklein15391ee2015-03-25 13:43:34 -070046inline 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();
mtklein91fd7372015-03-06 06:15:44 -080053}
54
mtklein15391ee2015-03-25 13:43:34 -070055inline 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();
mtklein91fd7372015-03-06 06:15:44 -080062}