blob: 86516b18759c2182271306a25510a015134eb72b [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
mtklein3d4c4a52015-03-26 12:32:29 -070021inline SkPMColor SkPMFloat::trunc() const {
22 return SkPackARGB32(this->a(), this->r(), this->g(), this->b());
23}
24
mtkleina2f4be72015-02-23 10:04:34 -080025inline SkPMColor SkPMFloat::get() const {
26 SkASSERT(this->isValid());
mtklein0aebf5d2015-03-03 08:57:07 -080027 return SkPackARGB32(this->a()+0.5f, this->r()+0.5f, this->g()+0.5f, this->b()+0.5f);
mtkleina2f4be72015-02-23 10:04:34 -080028}
29
30inline SkPMColor SkPMFloat::clamped() const {
31 float a = this->a(),
32 r = this->r(),
33 g = this->g(),
34 b = this->b();
mtklein60d2a322015-03-03 07:46:15 -080035 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);
mtklein0aebf5d2015-03-03 08:57:07 -080039 return SkPackARGB32(a+0.5f, r+0.5f, g+0.5f, b+0.5f);
mtkleina2f4be72015-02-23 10:04:34 -080040}
mtklein91fd7372015-03-06 06:15:44 -080041
mtklein15391ee2015-03-25 13:43:34 -070042inline 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]);
mtklein91fd7372015-03-06 06:15:44 -080048}
49
mtklein15391ee2015-03-25 13:43:34 -070050inline 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();
mtklein91fd7372015-03-06 06:15:44 -080057}
58
mtklein15391ee2015-03-25 13:43:34 -070059inline 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();
mtklein91fd7372015-03-06 06:15:44 -080066}