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