| 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. | 8 // A pre-multiplied color storing each component as a float in the range [0, 255
]. |
| 9 class SK_STRUCT_ALIGN(16) SkPMFloat { | 9 class SK_STRUCT_ALIGN(16) SkPMFloat { |
| 10 public: | 10 public: |
| 11 // Normal POD copies and do-nothing initialization. | 11 // Normal POD copies and do-nothing initialization. |
| 12 SkPMFloat() = default; | 12 SkPMFloat() = default; |
| 13 SkPMFloat(const SkPMFloat&) = default; | 13 SkPMFloat(const SkPMFloat&) = default; |
| 14 SkPMFloat& operator=(const SkPMFloat&) = default; | 14 SkPMFloat& operator=(const SkPMFloat&) = default; |
| 15 | 15 |
| 16 // Freely autoconvert between SkPMFloat and Sk4f. | 16 // Freely autoconvert between SkPMFloat and Sk4f. |
| 17 /*implicit*/ SkPMFloat(const Sk4f& fs) { fs.storeAligned(fColor); } | 17 /*implicit*/ SkPMFloat(const Sk4f& fs) { fs.storeAligned(fColor); } |
| 18 /*implicit*/ operator Sk4f() const { return Sk4f::LoadAligned(fColor); } | 18 /*implicit*/ operator Sk4f() const { return Sk4f::LoadAligned(fColor); } |
| 19 | 19 |
| 20 float a() const { return fColor[SK_A32_SHIFT / 8]; } | 20 float a() const { return fColor[SK_A32_SHIFT / 8]; } |
| 21 float r() const { return fColor[SK_R32_SHIFT / 8]; } | 21 float r() const { return fColor[SK_R32_SHIFT / 8]; } |
| 22 float g() const { return fColor[SK_G32_SHIFT / 8]; } | 22 float g() const { return fColor[SK_G32_SHIFT / 8]; } |
| 23 float b() const { return fColor[SK_B32_SHIFT / 8]; } | 23 float b() const { return fColor[SK_B32_SHIFT / 8]; } |
| 24 | 24 |
| 25 void setA(float val) { fColor[SK_A32_SHIFT / 8] = val; } | 25 void setA(float val) { fColor[SK_A32_SHIFT / 8] = val; } |
| 26 void setR(float val) { fColor[SK_R32_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; } | 27 void setG(float val) { fColor[SK_G32_SHIFT / 8] = val; } |
| 28 void setB(float val) { fColor[SK_B32_SHIFT / 8] = val; } | 28 void setB(float val) { fColor[SK_B32_SHIFT / 8] = val; } |
| 29 | 29 |
| 30 void set(SkPMColor); | 30 void set(SkPMColor); |
| 31 | 31 |
| 32 SkPMColor get() const; // May SkASSERT(this->isValid()). Some implemen
tations may clamp. | 32 SkPMColor get() const; // May SkASSERT(this->isValid()). Some implemen
tations may clamp. |
| 33 SkPMColor clamped() const; // Will clamp all values to [0,1], then SkASSERT
(this->isValid()). | 33 SkPMColor clamped() const; // Will clamp all values to [0, 255]. Then may
assert isValid(). |
| 34 | 34 |
| 35 bool isValid() const { | 35 bool isValid() const { |
| 36 return this->a() >= 0 && this->a() <= 1 | 36 return this->a() >= 0 && this->a() <= 255 |
| 37 && this->r() >= 0 && this->r() <= this->a() | 37 && this->r() >= 0 && this->r() <= this->a() |
| 38 && this->g() >= 0 && this->g() <= this->a() | 38 && this->g() >= 0 && this->g() <= this->a() |
| 39 && this->b() >= 0 && this->b() <= this->a(); | 39 && this->b() >= 0 && this->b() <= this->a(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 // We mirror SkPMColor order only to make set()/get()/clamped() as fast as p
ossible. | 43 // We mirror SkPMColor order only to make set()/get()/clamped() as fast as p
ossible. |
| 44 float fColor[4]; | 44 float fColor[4]; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 | 47 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 |
| 48 #include "../opts/SkPMFloat_SSE2.h" | 48 #include "../opts/SkPMFloat_SSE2.h" |
| 49 #elif defined(__ARM_NEON__) | 49 #elif defined(__ARM_NEON__) |
| 50 #include "../opts/SkPMFloat_neon.h" | 50 #include "../opts/SkPMFloat_neon.h" |
| 51 #else | 51 #else |
| 52 #include "../opts/SkPMFloat_none.h" | 52 #include "../opts/SkPMFloat_none.h" |
| 53 #endif | 53 #endif |
| 54 | 54 |
| 55 #endif//SkPM_DEFINED | 55 #endif//SkPM_DEFINED |
| OLD | NEW |