| OLD | NEW |
| 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 |
| 1 #ifndef SkPM_DEFINED | 8 #ifndef SkPM_DEFINED |
| 2 #define SkPM_DEFINED | 9 #define SkPM_DEFINED |
| 3 | 10 |
| 4 #include "SkTypes.h" | 11 #include "SkTypes.h" |
| 5 #include "SkColor.h" | 12 #include "SkColor.h" |
| 6 #include "SkColorPriv.h" | 13 #include "SkColorPriv.h" |
| 7 #include "Sk4x.h" | 14 #include "Sk4x.h" |
| 8 | 15 |
| 9 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 | 16 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 |
| 10 #include <immintrin.h> | 17 #include <immintrin.h> |
| 11 #elif defined(SK_ARM_HAS_NEON) | 18 #elif defined(SK_ARM_HAS_NEON) |
| 12 #include <arm_neon.h> | 19 #include <arm_neon.h> |
| 13 #endif | 20 #endif |
| 14 | 21 |
| 15 // A pre-multiplied color storing each component in the same order as SkPMColor, | 22 // A pre-multiplied color storing each component in the same order as SkPMColor, |
| 16 // but as a float in the range [0, 255]. | 23 // but as a float in the range [0, 255]. |
| 17 class SK_STRUCT_ALIGN(16) SkPMFloat { | 24 class SK_STRUCT_ALIGN(16) SkPMFloat { |
| 18 public: | 25 public: |
| 19 static SkPMFloat FromPMColor(SkPMColor c) { return SkPMFloat(c); } | 26 static SkPMFloat FromPMColor(SkPMColor c) { return SkPMFloat(c); } |
| 20 static SkPMFloat FromARGB(float a, float r, float g, float b) { return SkPMF
loat(a,r,g,b); } | 27 static SkPMFloat FromARGB(float a, float r, float g, float b) { return SkPMF
loat(a,r,g,b); } |
| 21 | 28 |
| 22 // May be more efficient than one at a time. No special alignment assumed f
or SkPMColors. | 29 // May be more efficient than one at a time. No special alignment assumed f
or SkPMColors. |
| 23 static void From4PMColors(SkPMFloat[4], const SkPMColor[4]); | 30 static void From4PMColors(const SkPMColor[4], SkPMFloat*, SkPMFloat*, SkPMFl
oat*, SkPMFloat*); |
| 24 | 31 |
| 25 explicit SkPMFloat(SkPMColor); | 32 explicit SkPMFloat(SkPMColor); |
| 26 SkPMFloat(float a, float r, float g, float b) { | 33 SkPMFloat(float a, float r, float g, float b) { |
| 27 // TODO: faster when specialized? | 34 // TODO: faster when specialized? |
| 28 fColor[SK_A32_SHIFT / 8] = a; | 35 fColor[SK_A32_SHIFT / 8] = a; |
| 29 fColor[SK_R32_SHIFT / 8] = r; | 36 fColor[SK_R32_SHIFT / 8] = r; |
| 30 fColor[SK_G32_SHIFT / 8] = g; | 37 fColor[SK_G32_SHIFT / 8] = g; |
| 31 fColor[SK_B32_SHIFT / 8] = b; | 38 fColor[SK_B32_SHIFT / 8] = b; |
| 32 } | 39 } |
| 33 | 40 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 44 float a() const { return fColor[SK_A32_SHIFT / 8]; } | 51 float a() const { return fColor[SK_A32_SHIFT / 8]; } |
| 45 float r() const { return fColor[SK_R32_SHIFT / 8]; } | 52 float r() const { return fColor[SK_R32_SHIFT / 8]; } |
| 46 float g() const { return fColor[SK_G32_SHIFT / 8]; } | 53 float g() const { return fColor[SK_G32_SHIFT / 8]; } |
| 47 float b() const { return fColor[SK_B32_SHIFT / 8]; } | 54 float b() const { return fColor[SK_B32_SHIFT / 8]; } |
| 48 | 55 |
| 49 // get() and clamped() round component values to the nearest integer. | 56 // get() and clamped() round component values to the nearest integer. |
| 50 SkPMColor get() const; // May SkASSERT(this->isValid()). Some implemen
tations may clamp. | 57 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(). | 58 SkPMColor clamped() const; // Will clamp all values to [0, 255]. Then may
assert isValid(). |
| 52 | 59 |
| 53 // 4-at-a-time versions of get() and clamped(). Like From4PMColors(), no al
ignment assumed. | 60 // 4-at-a-time versions of get() and clamped(). Like From4PMColors(), no al
ignment assumed. |
| 54 static void To4PMColors(SkPMColor[4], const SkPMFloat[4]); | 61 static void To4PMColors( |
| 55 static void ClampTo4PMColors(SkPMColor[4], const SkPMFloat[4]); | 62 const SkPMFloat&, const SkPMFloat&, const SkPMFloat&, const SkPMFloa
t&, SkPMColor[4]); |
| 63 static void ClampTo4PMColors( |
| 64 const SkPMFloat&, const SkPMFloat&, const SkPMFloat&, const SkPMFloa
t&, SkPMColor[4]); |
| 56 | 65 |
| 57 bool isValid() const { | 66 bool isValid() const { |
| 58 return this->a() >= 0 && this->a() <= 255 | 67 return this->a() >= 0 && this->a() <= 255 |
| 59 && this->r() >= 0 && this->r() <= this->a() | 68 && this->r() >= 0 && this->r() <= this->a() |
| 60 && this->g() >= 0 && this->g() <= this->a() | 69 && this->g() >= 0 && this->g() <= this->a() |
| 61 && this->b() >= 0 && this->b() <= this->a(); | 70 && this->b() >= 0 && this->b() <= this->a(); |
| 62 } | 71 } |
| 63 | 72 |
| 64 private: | 73 private: |
| 65 union { | 74 union { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 76 #include "../opts/SkPMFloat_SSSE3.h" | 85 #include "../opts/SkPMFloat_SSSE3.h" |
| 77 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 | 86 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 |
| 78 #include "../opts/SkPMFloat_SSE2.h" | 87 #include "../opts/SkPMFloat_SSE2.h" |
| 79 #elif defined(SK_ARM_HAS_NEON) | 88 #elif defined(SK_ARM_HAS_NEON) |
| 80 #include "../opts/SkPMFloat_neon.h" | 89 #include "../opts/SkPMFloat_neon.h" |
| 81 #else | 90 #else |
| 82 #include "../opts/SkPMFloat_none.h" | 91 #include "../opts/SkPMFloat_none.h" |
| 83 #endif | 92 #endif |
| 84 | 93 |
| 85 #endif//SkPM_DEFINED | 94 #endif//SkPM_DEFINED |
| OLD | NEW |