| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkPM_DEFINED | 8 #ifndef SkPM_DEFINED |
| 9 #define SkPM_DEFINED | 9 #define SkPM_DEFINED |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 SkPMFloat() {} | 27 SkPMFloat() {} |
| 28 explicit SkPMFloat(SkPMColor); | 28 explicit SkPMFloat(SkPMColor); |
| 29 SkPMFloat(float a, float r, float g, float b) | 29 SkPMFloat(float a, float r, float g, float b) |
| 30 #ifdef SK_PMCOLOR_IS_RGBA | 30 #ifdef SK_PMCOLOR_IS_RGBA |
| 31 : fColors(r,g,b,a) {} | 31 : fColors(r,g,b,a) {} |
| 32 #else | 32 #else |
| 33 : fColors(b,g,r,a) {} | 33 : fColors(b,g,r,a) {} |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 | 36 |
| 37 // Freely autoconvert between SkPMFloat and Sk4s. | 37 // Freely autoconvert between SkPMFloat and Sk4f. |
| 38 /*implicit*/ SkPMFloat(const Sk4s& fs) { fColors = fs; } | 38 /*implicit*/ SkPMFloat(const Sk4f& fs) { fColors = fs; } |
| 39 /*implicit*/ operator Sk4s() const { return fColors; } | 39 /*implicit*/ operator Sk4f() const { return fColors; } |
| 40 | 40 |
| 41 float a() const { return fColors[SK_A32_SHIFT / 8]; } | 41 float a() const { return fColors[SK_A32_SHIFT / 8]; } |
| 42 float r() const { return fColors[SK_R32_SHIFT / 8]; } | 42 float r() const { return fColors[SK_R32_SHIFT / 8]; } |
| 43 float g() const { return fColors[SK_G32_SHIFT / 8]; } | 43 float g() const { return fColors[SK_G32_SHIFT / 8]; } |
| 44 float b() const { return fColors[SK_B32_SHIFT / 8]; } | 44 float b() const { return fColors[SK_B32_SHIFT / 8]; } |
| 45 | 45 |
| 46 // get() and clamped() round component values to the nearest integer. | 46 // get() and clamped() round component values to the nearest integer. |
| 47 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. |
| 48 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(). |
| 49 | 49 |
| 50 // Like get(), but truncates instead of rounding. | 50 // Like get(), but truncates instead of rounding. |
| 51 // The domain of this function is (-1.0f, 256.0f). Values in (-1.0f, 0.0f]
trunc to a zero. | 51 // The domain of this function is (-1.0f, 256.0f). Values in (-1.0f, 0.0f]
trunc to a zero. |
| 52 SkPMColor trunc() const; | 52 SkPMColor trunc() const; |
| 53 | 53 |
| 54 // 4-at-a-time versions of get() and clamped(). Like From4PMColors(), no al
ignment assumed. | 54 // 4-at-a-time versions of get() and clamped(). Like From4PMColors(), no al
ignment assumed. |
| 55 static void To4PMColors( | 55 static void To4PMColors( |
| 56 const SkPMFloat&, const SkPMFloat&, const SkPMFloat&, const SkPMFloa
t&, SkPMColor[4]); | 56 const SkPMFloat&, const SkPMFloat&, const SkPMFloat&, const SkPMFloa
t&, SkPMColor[4]); |
| 57 static void ClampTo4PMColors( | 57 static void ClampTo4PMColors( |
| 58 const SkPMFloat&, const SkPMFloat&, const SkPMFloat&, const SkPMFloa
t&, SkPMColor[4]); | 58 const SkPMFloat&, const SkPMFloat&, const SkPMFloat&, const SkPMFloa
t&, SkPMColor[4]); |
| 59 | 59 |
| 60 bool isValid() const { | 60 bool isValid() const { |
| 61 return this->a() >= 0 && this->a() <= 255 | 61 return this->a() >= 0 && this->a() <= 255 |
| 62 && this->r() >= 0 && this->r() <= this->a() | 62 && this->r() >= 0 && this->r() <= this->a() |
| 63 && this->g() >= 0 && this->g() <= this->a() | 63 && this->g() >= 0 && this->g() <= this->a() |
| 64 && this->b() >= 0 && this->b() <= this->a(); | 64 && this->b() >= 0 && this->b() <= this->a(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 Sk4s fColors; | 68 Sk4f fColors; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 #ifdef SKNX_NO_SIMD | 71 #ifdef SKNX_NO_SIMD |
| 72 // Platform implementations of SkPMFloat assume Sk4s uses SSE or NEON. _non
e is generic. | 72 // Platform implementations of SkPMFloat assume Sk4f uses SSE or NEON. _non
e is generic. |
| 73 #include "../opts/SkPMFloat_none.h" | 73 #include "../opts/SkPMFloat_none.h" |
| 74 #else | 74 #else |
| 75 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 | 75 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 |
| 76 #include "../opts/SkPMFloat_SSSE3.h" | 76 #include "../opts/SkPMFloat_SSSE3.h" |
| 77 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 | 77 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 |
| 78 #include "../opts/SkPMFloat_SSE2.h" | 78 #include "../opts/SkPMFloat_SSE2.h" |
| 79 #elif defined(SK_ARM_HAS_NEON) | 79 #elif defined(SK_ARM_HAS_NEON) |
| 80 #include "../opts/SkPMFloat_neon.h" | 80 #include "../opts/SkPMFloat_neon.h" |
| 81 #else | 81 #else |
| 82 #include "../opts/SkPMFloat_none.h" | 82 #include "../opts/SkPMFloat_none.h" |
| 83 #endif | 83 #endif |
| 84 #endif | 84 #endif |
| 85 | 85 |
| 86 #endif//SkPM_DEFINED | 86 #endif//SkPM_DEFINED |
| OLD | NEW |