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 in the same order as SkPMColor, | 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 // but as a float in the range [0, 255]. |
10 class SK_STRUCT_ALIGN(16) SkPMFloat { | 10 class SK_STRUCT_ALIGN(16) SkPMFloat { |
11 public: | 11 public: |
12 static SkPMFloat FromPMColor(SkPMColor c) { return SkPMFloat(c); } | 12 static SkPMFloat FromPMColor(SkPMColor c) { return SkPMFloat(c); } |
13 static SkPMFloat FromARGB(float a, float r, float g, float b) { return SkPMF
loat(a,r,g,b); } | 13 static SkPMFloat FromARGB(float a, float r, float g, float b) { return SkPMF
loat(a,r,g,b); } |
14 | 14 |
| 15 // May be more efficient than one at a time. No special alignment assumed f
or SkPMColors. |
| 16 static void From4PMColors(SkPMFloat floats[4], const SkPMColor colors[4]) { |
| 17 // TODO: specialize |
| 18 for (int i = 0; i < 4; i++) { floats[i] = FromPMColor(colors[i]); } |
| 19 } |
| 20 |
15 explicit SkPMFloat(SkPMColor); | 21 explicit SkPMFloat(SkPMColor); |
16 SkPMFloat(float a, float r, float g, float b) { | 22 SkPMFloat(float a, float r, float g, float b) { |
17 // TODO: faster when specialized? | 23 // TODO: faster when specialized? |
18 fColor[SK_A32_SHIFT / 8] = a; | 24 fColor[SK_A32_SHIFT / 8] = a; |
19 fColor[SK_R32_SHIFT / 8] = r; | 25 fColor[SK_R32_SHIFT / 8] = r; |
20 fColor[SK_G32_SHIFT / 8] = g; | 26 fColor[SK_G32_SHIFT / 8] = g; |
21 fColor[SK_B32_SHIFT / 8] = b; | 27 fColor[SK_B32_SHIFT / 8] = b; |
22 } | 28 } |
23 | 29 |
24 // Uninitialized. | 30 // Uninitialized. |
(...skipping 12 matching lines...) Expand all Loading... |
37 | 43 |
38 float a() const { return fColor[SK_A32_SHIFT / 8]; } | 44 float a() const { return fColor[SK_A32_SHIFT / 8]; } |
39 float r() const { return fColor[SK_R32_SHIFT / 8]; } | 45 float r() const { return fColor[SK_R32_SHIFT / 8]; } |
40 float g() const { return fColor[SK_G32_SHIFT / 8]; } | 46 float g() const { return fColor[SK_G32_SHIFT / 8]; } |
41 float b() const { return fColor[SK_B32_SHIFT / 8]; } | 47 float b() const { return fColor[SK_B32_SHIFT / 8]; } |
42 | 48 |
43 // get() and clamped() round component values to the nearest integer. | 49 // get() and clamped() round component values to the nearest integer. |
44 SkPMColor get() const; // May SkASSERT(this->isValid()). Some implemen
tations may clamp. | 50 SkPMColor get() const; // May SkASSERT(this->isValid()). Some implemen
tations may clamp. |
45 SkPMColor clamped() const; // Will clamp all values to [0, 255]. Then may
assert isValid(). | 51 SkPMColor clamped() const; // Will clamp all values to [0, 255]. Then may
assert isValid(). |
46 | 52 |
| 53 // 4-at-a-time versions of get() and clamped(). Like From4PMColors(), no al
ignment assumed. |
| 54 static void To4PMColors(SkPMColor colors[4], const SkPMFloat floats[4]) { |
| 55 // TODO: specialize |
| 56 for (int i = 0; i < 4; i++) { colors[i] = floats[i].get(); } |
| 57 } |
| 58 static void ClampTo4PMColors(SkPMColor colors[4], const SkPMFloat floats[4])
{ |
| 59 // TODO: specialize |
| 60 for (int i = 0; i < 4; i++) { colors[i] = floats[i].clamped(); } |
| 61 } |
| 62 |
47 bool isValid() const { | 63 bool isValid() const { |
48 return this->a() >= 0 && this->a() <= 255 | 64 return this->a() >= 0 && this->a() <= 255 |
49 && this->r() >= 0 && this->r() <= this->a() | 65 && this->r() >= 0 && this->r() <= this->a() |
50 && this->g() >= 0 && this->g() <= this->a() | 66 && this->g() >= 0 && this->g() <= this->a() |
51 && this->b() >= 0 && this->b() <= this->a(); | 67 && this->b() >= 0 && this->b() <= this->a(); |
52 } | 68 } |
53 | 69 |
54 private: | 70 private: |
55 float fColor[4]; | 71 float fColor[4]; |
56 }; | 72 }; |
57 | 73 |
58 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 | 74 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 |
59 #include "../opts/SkPMFloat_SSSE3.h" | 75 #include "../opts/SkPMFloat_SSSE3.h" |
60 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 | 76 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 |
61 #include "../opts/SkPMFloat_SSE2.h" | 77 #include "../opts/SkPMFloat_SSE2.h" |
62 #elif defined(__ARM_NEON__) | 78 #elif defined(__ARM_NEON__) |
63 #include "../opts/SkPMFloat_neon.h" | 79 #include "../opts/SkPMFloat_neon.h" |
64 #else | 80 #else |
65 #include "../opts/SkPMFloat_none.h" | 81 #include "../opts/SkPMFloat_none.h" |
66 #endif | 82 #endif |
67 | 83 |
68 #endif//SkPM_DEFINED | 84 #endif//SkPM_DEFINED |
OLD | NEW |