OLD | NEW |
---|---|
1 #ifndef SkPM_DEFINED | 1 #ifndef SkPM_DEFINED |
2 #define SkPM_DEFINED | 2 #define SkPM_DEFINED |
3 | 3 |
4 #include "SkTypes.h" | 4 #include "SkTypes.h" |
5 #include "SkColor.h" | 5 #include "SkColor.h" |
6 #include "Sk4x.h" | 6 #include "Sk4x.h" |
7 | 7 |
8 // A pre-multiplied color storing each component as a float in the range [0, 255 ]. | 8 // A pre-multiplied color storing each component in the same order as SkPMColor, |
9 // but as a float in the range [0, 255]. | |
9 class SK_STRUCT_ALIGN(16) SkPMFloat { | 10 class SK_STRUCT_ALIGN(16) SkPMFloat { |
10 public: | 11 public: |
12 explicit SkPMFloat(SkPMColor); | |
reed1
2015/03/04 16:00:38
I'm not sure if constructors are "safer" than fact
mtklein
2015/03/04 18:16:00
Done.
| |
13 SkPMFloat(float a, float r, float g, float b) { | |
14 // TODO: faster when specialized? | |
15 fColor[SK_A32_SHIFT / 8] = a; | |
16 fColor[SK_R32_SHIFT / 8] = r; | |
17 fColor[SK_G32_SHIFT / 8] = g; | |
18 fColor[SK_B32_SHIFT / 8] = b; | |
19 SkASSERT(this->isValid()); | |
20 } | |
21 | |
11 // Normal POD copies and do-nothing initialization. | 22 // Normal POD copies and do-nothing initialization. |
12 SkPMFloat() = default; | 23 SkPMFloat() = default; |
13 SkPMFloat(const SkPMFloat&) = default; | 24 SkPMFloat(const SkPMFloat&) = default; |
14 SkPMFloat& operator=(const SkPMFloat&) = default; | 25 SkPMFloat& operator=(const SkPMFloat&) = default; |
15 | 26 |
16 // Freely autoconvert between SkPMFloat and Sk4f. | 27 // Freely autoconvert between SkPMFloat and Sk4f. |
17 /*implicit*/ SkPMFloat(const Sk4f& fs) { fs.storeAligned(fColor); } | 28 /*implicit*/ SkPMFloat(const Sk4f& fs) { fs.storeAligned(fColor); } |
18 /*implicit*/ operator Sk4f() const { return Sk4f::LoadAligned(fColor); } | 29 /*implicit*/ operator Sk4f() const { return Sk4f::LoadAligned(fColor); } |
19 | 30 |
20 float a() const { return fColor[SK_A32_SHIFT / 8]; } | 31 float a() const { return fColor[SK_A32_SHIFT / 8]; } |
21 float r() const { return fColor[SK_R32_SHIFT / 8]; } | 32 float r() const { return fColor[SK_R32_SHIFT / 8]; } |
22 float g() const { return fColor[SK_G32_SHIFT / 8]; } | 33 float g() const { return fColor[SK_G32_SHIFT / 8]; } |
23 float b() const { return fColor[SK_B32_SHIFT / 8]; } | 34 float b() const { return fColor[SK_B32_SHIFT / 8]; } |
24 | 35 |
25 void setA(float val) { fColor[SK_A32_SHIFT / 8] = val; } | |
26 void setR(float val) { fColor[SK_R32_SHIFT / 8] = val; } | |
27 void setG(float val) { fColor[SK_G32_SHIFT / 8] = val; } | |
28 void setB(float val) { fColor[SK_B32_SHIFT / 8] = val; } | |
29 | |
30 void set(SkPMColor); | |
31 | |
32 // get() and clamped() round component values to the nearest integer. | 36 // get() and clamped() round component values to the nearest integer. |
33 SkPMColor get() const; // May SkASSERT(this->isValid()). Some implemen tations may clamp. | 37 SkPMColor get() const; // May SkASSERT(this->isValid()). Some implemen tations may clamp. |
34 SkPMColor clamped() const; // Will clamp all values to [0, 255]. Then may assert isValid(). | 38 SkPMColor clamped() const; // Will clamp all values to [0, 255]. Then may assert isValid(). |
35 | 39 |
36 bool isValid() const { | 40 bool isValid() const { |
37 return this->a() >= 0 && this->a() <= 255 | 41 return this->a() >= 0 && this->a() <= 255 |
38 && this->r() >= 0 && this->r() <= this->a() | 42 && this->r() >= 0 && this->r() <= this->a() |
39 && this->g() >= 0 && this->g() <= this->a() | 43 && this->g() >= 0 && this->g() <= this->a() |
40 && this->b() >= 0 && this->b() <= this->a(); | 44 && this->b() >= 0 && this->b() <= this->a(); |
41 } | 45 } |
42 | 46 |
43 private: | 47 private: |
44 // We mirror SkPMColor order only to make set()/get()/clamped() as fast as p ossible. | |
45 float fColor[4]; | 48 float fColor[4]; |
46 }; | 49 }; |
47 | 50 |
48 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 | 51 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 |
49 #include "../opts/SkPMFloat_SSE2.h" | 52 #include "../opts/SkPMFloat_SSE2.h" |
50 #elif defined(__ARM_NEON__) | 53 #elif defined(__ARM_NEON__) |
51 #include "../opts/SkPMFloat_neon.h" | 54 #include "../opts/SkPMFloat_neon.h" |
52 #else | 55 #else |
53 #include "../opts/SkPMFloat_none.h" | 56 #include "../opts/SkPMFloat_none.h" |
54 #endif | 57 #endif |
55 | 58 |
56 #endif//SkPM_DEFINED | 59 #endif//SkPM_DEFINED |
OLD | NEW |