OLD | NEW |
| (Empty) |
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 | |
8 #ifndef SkPx_none_DEFINED | |
9 #define SkPx_none_DEFINED | |
10 | |
11 // Nothing fancy here. We're the backup _none case after all. | |
12 // Our declared sweet spot is simply a single pixel at a time. | |
13 | |
14 struct SkPx_none { | |
15 static const int N = 1; | |
16 uint8_t f8[4]; | |
17 | |
18 SkPx_none(uint32_t px) { memcpy(f8, &px, 4); } | |
19 SkPx_none(uint8_t x, uint8_t y, uint8_t z, uint8_t a) { | |
20 f8[0] = x; f8[1] = y; f8[2] = z; f8[3] = a; | |
21 } | |
22 | |
23 static SkPx_none Dup(uint32_t px) { return px; } | |
24 static SkPx_none Load(const uint32_t* px) { return *px; } | |
25 static SkPx_none Load(const uint32_t* px, int n) { | |
26 SkASSERT(false); // There are no 0<n<1. | |
27 return 0; | |
28 } | |
29 | |
30 void store(uint32_t* px) const { memcpy(px, f8, 4); } | |
31 void store(uint32_t* px, int n) const { | |
32 SkASSERT(false); // There are no 0<n<1. | |
33 } | |
34 | |
35 struct Alpha { | |
36 uint8_t fA; | |
37 Alpha(uint8_t a) : fA(a) {} | |
38 | |
39 static Alpha Dup(uint8_t a) { return a; } | |
40 static Alpha Load(const uint8_t* a) { return *a; } | |
41 static Alpha Load(const uint8_t* a, int n) { | |
42 SkASSERT(false); // There are no 0<n<1. | |
43 return 0; | |
44 } | |
45 Alpha inv() const { return 255 - fA; } | |
46 }; | |
47 | |
48 struct Wide { | |
49 uint16_t f16[4]; | |
50 | |
51 Wide(uint16_t x, uint16_t y, uint16_t z, uint16_t a) { | |
52 f16[0] = x; f16[1] = y; f16[2] = z; f16[3] = a; | |
53 } | |
54 | |
55 Wide operator+(const Wide& o) const { | |
56 return Wide(f16[0]+o.f16[0], f16[1]+o.f16[1], f16[2]+o.f16[2], f16[3
]+o.f16[3]); | |
57 } | |
58 Wide operator-(const Wide& o) const { | |
59 return Wide(f16[0]-o.f16[0], f16[1]-o.f16[1], f16[2]-o.f16[2], f16[3
]-o.f16[3]); | |
60 } | |
61 Wide operator<<(int bits) const { | |
62 return Wide(f16[0]<<bits, f16[1]<<bits, f16[2]<<bits, f16[3]<<bits); | |
63 } | |
64 Wide operator>>(int bits) const { | |
65 return Wide(f16[0]>>bits, f16[1]>>bits, f16[2]>>bits, f16[3]>>bits); | |
66 } | |
67 | |
68 SkPx_none addNarrowHi(const SkPx_none& o) const { | |
69 Wide sum = (*this + o.widenLo()) >> 8; | |
70 return SkPx_none(sum.f16[0], sum.f16[1], sum.f16[2], sum.f16[3]); | |
71 } | |
72 }; | |
73 | |
74 Alpha alpha() const { return f8[3]; } | |
75 | |
76 Wide widenLo() const { return Wide(f8[0], f8[1], f8[2], f8[3]); } | |
77 Wide widenHi() const { return this->widenLo() << 8; } | |
78 Wide widenLoHi() const { return this->widenLo() + this->widenHi(); } | |
79 | |
80 SkPx_none operator+(const SkPx_none& o) const { | |
81 return SkPx_none(f8[0]+o.f8[0], f8[1]+o.f8[1], f8[2]+o.f8[2], f8[3]+o.f8
[3]); | |
82 } | |
83 SkPx_none operator-(const SkPx_none& o) const { | |
84 return SkPx_none(f8[0]-o.f8[0], f8[1]-o.f8[1], f8[2]-o.f8[2], f8[3]-o.f8
[3]); | |
85 } | |
86 SkPx_none saturatedAdd(const SkPx_none& o) const { | |
87 return SkPx_none(SkTMax(0, SkTMin(255, f8[0]+o.f8[0])), | |
88 SkTMax(0, SkTMin(255, f8[1]+o.f8[1])), | |
89 SkTMax(0, SkTMin(255, f8[2]+o.f8[2])), | |
90 SkTMax(0, SkTMin(255, f8[3]+o.f8[3]))); | |
91 } | |
92 | |
93 Wide operator*(const Alpha& a) const { | |
94 return Wide(f8[0]*a.fA, f8[1]*a.fA, f8[2]*a.fA, f8[3]*a.fA); | |
95 } | |
96 SkPx_none approxMulDiv255(const Alpha& a) const { | |
97 return (*this * a).addNarrowHi(*this); | |
98 } | |
99 | |
100 SkPx_none addAlpha(const Alpha& a) const { | |
101 return SkPx_none(f8[0], f8[1], f8[2], f8[3]+a.fA); | |
102 } | |
103 }; | |
104 typedef SkPx_none SkPx; | |
105 | |
106 #endif//SkPx_none_DEFINED | |
OLD | NEW |