| 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 SkPx_none_DEFINED | 8 #ifndef SkPx_none_DEFINED |
| 9 #define SkPx_none_DEFINED | 9 #define SkPx_none_DEFINED |
| 10 | 10 |
| 11 // Nothing fancy here. We're the backup _none case after all. | 11 // Nothing fancy here. We're the backup _none case after all. |
| 12 // Our declared sweet spot is simply a single pixel at a time. | 12 // Our declared sweet spot is simply a single pixel at a time. |
| 13 | 13 |
| 14 struct SkPx_none { | 14 namespace none { |
| 15 |
| 16 struct SkPx { |
| 15 static const int N = 1; | 17 static const int N = 1; |
| 16 uint8_t f8[4]; | 18 uint8_t f8[4]; |
| 17 | 19 |
| 18 SkPx_none(uint32_t px) { memcpy(f8, &px, 4); } | 20 SkPx(uint32_t px) { memcpy(f8, &px, 4); } |
| 19 SkPx_none(uint8_t x, uint8_t y, uint8_t z, uint8_t a) { | 21 SkPx(uint8_t x, uint8_t y, uint8_t z, uint8_t a) { |
| 20 f8[0] = x; f8[1] = y; f8[2] = z; f8[3] = a; | 22 f8[0] = x; f8[1] = y; f8[2] = z; f8[3] = a; |
| 21 } | 23 } |
| 22 | 24 |
| 23 static SkPx_none Dup(uint32_t px) { return px; } | 25 static SkPx Dup(uint32_t px) { return px; } |
| 24 static SkPx_none Load(const uint32_t* px) { return *px; } | 26 static SkPx Load(const uint32_t* px) { return *px; } |
| 25 static SkPx_none Load(const uint32_t* px, int n) { | 27 static SkPx Load(const uint32_t* px, int n) { |
| 26 SkASSERT(false); // There are no 0<n<1. | 28 SkASSERT(false); // There are no 0<n<1. |
| 27 return 0; | 29 return 0; |
| 28 } | 30 } |
| 29 | 31 |
| 30 void store(uint32_t* px) const { memcpy(px, f8, 4); } | 32 void store(uint32_t* px) const { memcpy(px, f8, 4); } |
| 31 void store(uint32_t* px, int n) const { | 33 void store(uint32_t* px, int n) const { |
| 32 SkASSERT(false); // There are no 0<n<1. | 34 SkASSERT(false); // There are no 0<n<1. |
| 33 } | 35 } |
| 34 | 36 |
| 35 struct Alpha { | 37 struct Alpha { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 58 Wide operator-(const Wide& o) const { | 60 Wide operator-(const Wide& o) const { |
| 59 return Wide(f16[0]-o.f16[0], f16[1]-o.f16[1], f16[2]-o.f16[2], f16[3
]-o.f16[3]); | 61 return Wide(f16[0]-o.f16[0], f16[1]-o.f16[1], f16[2]-o.f16[2], f16[3
]-o.f16[3]); |
| 60 } | 62 } |
| 61 template <int bits> Wide shl() const { | 63 template <int bits> Wide shl() const { |
| 62 return Wide(f16[0]<<bits, f16[1]<<bits, f16[2]<<bits, f16[3]<<bits); | 64 return Wide(f16[0]<<bits, f16[1]<<bits, f16[2]<<bits, f16[3]<<bits); |
| 63 } | 65 } |
| 64 template <int bits> Wide shr() const { | 66 template <int bits> Wide shr() const { |
| 65 return Wide(f16[0]>>bits, f16[1]>>bits, f16[2]>>bits, f16[3]>>bits); | 67 return Wide(f16[0]>>bits, f16[1]>>bits, f16[2]>>bits, f16[3]>>bits); |
| 66 } | 68 } |
| 67 | 69 |
| 68 SkPx_none addNarrowHi(const SkPx_none& o) const { | 70 SkPx addNarrowHi(const SkPx& o) const { |
| 69 Wide sum = (*this + o.widenLo()).shr<8>(); | 71 Wide sum = (*this + o.widenLo()).shr<8>(); |
| 70 return SkPx_none(sum.f16[0], sum.f16[1], sum.f16[2], sum.f16[3]); | 72 return SkPx(sum.f16[0], sum.f16[1], sum.f16[2], sum.f16[3]); |
| 71 } | 73 } |
| 72 }; | 74 }; |
| 73 | 75 |
| 74 Alpha alpha() const { return f8[3]; } | 76 Alpha alpha() const { return f8[3]; } |
| 75 | 77 |
| 76 Wide widenLo() const { return Wide(f8[0], f8[1], f8[2], f8[3]); } | 78 Wide widenLo() const { return Wide(f8[0], f8[1], f8[2], f8[3]); } |
| 77 Wide widenHi() const { return this->widenLo().shl<8>(); } | 79 Wide widenHi() const { return this->widenLo().shl<8>(); } |
| 78 Wide widenLoHi() const { return this->widenLo() + this->widenHi(); } | 80 Wide widenLoHi() const { return this->widenLo() + this->widenHi(); } |
| 79 | 81 |
| 80 SkPx_none operator+(const SkPx_none& o) const { | 82 SkPx operator+(const SkPx& o) const { |
| 81 return SkPx_none(f8[0]+o.f8[0], f8[1]+o.f8[1], f8[2]+o.f8[2], f8[3]+o.f8
[3]); | 83 return SkPx(f8[0]+o.f8[0], f8[1]+o.f8[1], f8[2]+o.f8[2], f8[3]+o.f8[3]); |
| 82 } | 84 } |
| 83 SkPx_none operator-(const SkPx_none& o) const { | 85 SkPx operator-(const SkPx& o) const { |
| 84 return SkPx_none(f8[0]-o.f8[0], f8[1]-o.f8[1], f8[2]-o.f8[2], f8[3]-o.f8
[3]); | 86 return SkPx(f8[0]-o.f8[0], f8[1]-o.f8[1], f8[2]-o.f8[2], f8[3]-o.f8[3]); |
| 85 } | 87 } |
| 86 SkPx_none saturatedAdd(const SkPx_none& o) const { | 88 SkPx saturatedAdd(const SkPx& o) const { |
| 87 return SkPx_none(SkTMax(0, SkTMin(255, f8[0]+o.f8[0])), | 89 return SkPx(SkTMax(0, SkTMin(255, f8[0]+o.f8[0])), |
| 88 SkTMax(0, SkTMin(255, f8[1]+o.f8[1])), | 90 SkTMax(0, SkTMin(255, f8[1]+o.f8[1])), |
| 89 SkTMax(0, SkTMin(255, f8[2]+o.f8[2])), | 91 SkTMax(0, SkTMin(255, f8[2]+o.f8[2])), |
| 90 SkTMax(0, SkTMin(255, f8[3]+o.f8[3]))); | 92 SkTMax(0, SkTMin(255, f8[3]+o.f8[3]))); |
| 91 } | 93 } |
| 92 | 94 |
| 93 Wide operator*(const Alpha& a) const { | 95 Wide operator*(const Alpha& a) const { |
| 94 return Wide(f8[0]*a.fA, f8[1]*a.fA, f8[2]*a.fA, f8[3]*a.fA); | 96 return Wide(f8[0]*a.fA, f8[1]*a.fA, f8[2]*a.fA, f8[3]*a.fA); |
| 95 } | 97 } |
| 96 SkPx_none approxMulDiv255(const Alpha& a) const { | 98 SkPx approxMulDiv255(const Alpha& a) const { |
| 97 return (*this * a).addNarrowHi(*this); | 99 return (*this * a).addNarrowHi(*this); |
| 98 } | 100 } |
| 99 | 101 |
| 100 SkPx_none addAlpha(const Alpha& a) const { | 102 SkPx addAlpha(const Alpha& a) const { |
| 101 return SkPx_none(f8[0], f8[1], f8[2], f8[3]+a.fA); | 103 return SkPx(f8[0], f8[1], f8[2], f8[3]+a.fA); |
| 102 } | 104 } |
| 103 }; | 105 }; |
| 104 typedef SkPx_none SkPx; | 106 |
| 107 } // namespace none |
| 108 |
| 109 typedef none::SkPx SkPx; |
| 105 | 110 |
| 106 #endif//SkPx_none_DEFINED | 111 #endif//SkPx_none_DEFINED |
| OLD | NEW |