| 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 #include "SkUtils.h" | 8 #include "SkUtils.h" |
| 9 | 9 |
| 10 namespace { // See Sk4px.h | 10 namespace { // See Sk4px.h |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 Sk4px px1 = Sk16b(); | 33 Sk4px px1 = Sk16b(); |
| 34 memcpy(&px1, px, 4); | 34 memcpy(&px1, px, 4); |
| 35 return px1; | 35 return px1; |
| 36 } | 36 } |
| 37 | 37 |
| 38 inline void Sk4px::store4(SkPMColor px[4]) const { memcpy(px, this, 16); } | 38 inline void Sk4px::store4(SkPMColor px[4]) const { memcpy(px, this, 16); } |
| 39 inline void Sk4px::store2(SkPMColor px[2]) const { memcpy(px, this, 8); } | 39 inline void Sk4px::store2(SkPMColor px[2]) const { memcpy(px, this, 8); } |
| 40 inline void Sk4px::store1(SkPMColor px[1]) const { memcpy(px, this, 4); } | 40 inline void Sk4px::store1(SkPMColor px[1]) const { memcpy(px, this, 4); } |
| 41 | 41 |
| 42 inline Sk4px::Wide Sk4px::widenLo() const { | 42 inline Sk4px::Wide Sk4px::widenLo() const { |
| 43 return Sk16h(this->kth< 0>(), this->kth< 1>(), this->kth< 2>(), this->kth< 3
>(), | 43 return Sk16h((*this)[ 0], (*this)[ 1], (*this)[ 2], (*this)[ 3], |
| 44 this->kth< 4>(), this->kth< 5>(), this->kth< 6>(), this->kth< 7
>(), | 44 (*this)[ 4], (*this)[ 5], (*this)[ 6], (*this)[ 7], |
| 45 this->kth< 8>(), this->kth< 9>(), this->kth<10>(), this->kth<11
>(), | 45 (*this)[ 8], (*this)[ 9], (*this)[10], (*this)[11], |
| 46 this->kth<12>(), this->kth<13>(), this->kth<14>(), this->kth<15
>()); | 46 (*this)[12], (*this)[13], (*this)[14], (*this)[15]); |
| 47 } | 47 } |
| 48 | 48 |
| 49 inline Sk4px::Wide Sk4px::widenHi() const { return this->widenLo() << 8; } | 49 inline Sk4px::Wide Sk4px::widenHi() const { return this->widenLo() << 8; } |
| 50 | 50 |
| 51 inline Sk4px::Wide Sk4px::widenLoHi() const { return this->widenLo() + this->wid
enHi(); } | 51 inline Sk4px::Wide Sk4px::widenLoHi() const { return this->widenLo() + this->wid
enHi(); } |
| 52 | 52 |
| 53 inline Sk4px::Wide Sk4px::mulWiden(const Sk16b& other) const { | 53 inline Sk4px::Wide Sk4px::mulWiden(const Sk16b& other) const { |
| 54 return this->widenLo() * Sk4px(other).widenLo(); | 54 return this->widenLo() * Sk4px(other).widenLo(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 inline Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const { | 57 inline Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const { |
| 58 Sk4px::Wide r = (*this + other) >> 8; | 58 Sk4px::Wide r = (*this + other) >> 8; |
| 59 return Sk16b(r.kth< 0>(), r.kth< 1>(), r.kth< 2>(), r.kth< 3>(), | 59 return Sk16b(r[ 0], r[ 1], r[ 2], r[ 3], |
| 60 r.kth< 4>(), r.kth< 5>(), r.kth< 6>(), r.kth< 7>(), | 60 r[ 4], r[ 5], r[ 6], r[ 7], |
| 61 r.kth< 8>(), r.kth< 9>(), r.kth<10>(), r.kth<11>(), | 61 r[ 8], r[ 9], r[10], r[11], |
| 62 r.kth<12>(), r.kth<13>(), r.kth<14>(), r.kth<15>()); | 62 r[12], r[13], r[14], r[15]); |
| 63 } | 63 } |
| 64 | 64 |
| 65 inline Sk4px Sk4px::Wide::div255() const { | 65 inline Sk4px Sk4px::Wide::div255() const { |
| 66 // Calculated as ((x+128) + ((x+128)>>8)) >> 8. | 66 // Calculated as ((x+128) + ((x+128)>>8)) >> 8. |
| 67 auto v = *this + Sk16h(128); | 67 auto v = *this + Sk16h(128); |
| 68 return v.addNarrowHi(v>>8); | 68 return v.addNarrowHi(v>>8); |
| 69 } | 69 } |
| 70 | 70 |
| 71 inline Sk4px Sk4px::alphas() const { | 71 inline Sk4px Sk4px::alphas() const { |
| 72 static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian."); | 72 static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian."); |
| 73 return Sk16b(this->kth< 3>(), this->kth< 3>(), this->kth< 3>(), this->kth< 3
>(), | 73 return Sk16b((*this)[ 3], (*this)[ 3], (*this)[ 3], (*this)[ 3], |
| 74 this->kth< 7>(), this->kth< 7>(), this->kth< 7>(), this->kth< 7
>(), | 74 (*this)[ 7], (*this)[ 7], (*this)[ 7], (*this)[ 7], |
| 75 this->kth<11>(), this->kth<11>(), this->kth<11>(), this->kth<11
>(), | 75 (*this)[11], (*this)[11], (*this)[11], (*this)[11], |
| 76 this->kth<15>(), this->kth<15>(), this->kth<15>(), this->kth<15
>()); | 76 (*this)[15], (*this)[15], (*this)[15], (*this)[15]); |
| 77 } | 77 } |
| 78 | 78 |
| 79 inline Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) { | 79 inline Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) { |
| 80 return Sk16b(a[0], a[0], a[0], a[0], | 80 return Sk16b(a[0], a[0], a[0], a[0], |
| 81 a[1], a[1], a[1], a[1], | 81 a[1], a[1], a[1], a[1], |
| 82 a[2], a[2], a[2], a[2], | 82 a[2], a[2], a[2], a[2], |
| 83 a[3], a[3], a[3], a[3]); | 83 a[3], a[3], a[3], a[3]); |
| 84 } | 84 } |
| 85 | 85 |
| 86 inline Sk4px Sk4px::Load2Alphas(const SkAlpha a[2]) { | 86 inline Sk4px Sk4px::Load2Alphas(const SkAlpha a[2]) { |
| 87 return Sk16b(a[0], a[0], a[0], a[0], | 87 return Sk16b(a[0], a[0], a[0], a[0], |
| 88 a[1], a[1], a[1], a[1], | 88 a[1], a[1], a[1], a[1], |
| 89 0,0,0,0, | 89 0,0,0,0, |
| 90 0,0,0,0); | 90 0,0,0,0); |
| 91 } | 91 } |
| 92 | 92 |
| 93 inline Sk4px Sk4px::zeroAlphas() const { | 93 inline Sk4px Sk4px::zeroAlphas() const { |
| 94 static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian."); | 94 static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian."); |
| 95 return Sk16b(this->kth< 0>(), this->kth< 1>(), this->kth< 2>(), 0, | 95 return Sk16b((*this)[ 0], (*this)[ 1], (*this)[ 2], 0, |
| 96 this->kth< 4>(), this->kth< 5>(), this->kth< 6>(), 0, | 96 (*this)[ 4], (*this)[ 5], (*this)[ 6], 0, |
| 97 this->kth< 8>(), this->kth< 9>(), this->kth<10>(), 0, | 97 (*this)[ 8], (*this)[ 9], (*this)[10], 0, |
| 98 this->kth<12>(), this->kth<13>(), this->kth<14>(), 0); | 98 (*this)[12], (*this)[13], (*this)[14], 0); |
| 99 } | 99 } |
| 100 | 100 |
| 101 inline Sk4px Sk4px::zeroColors() const { | 101 inline Sk4px Sk4px::zeroColors() const { |
| 102 static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian."); | 102 static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian."); |
| 103 return Sk16b(0,0,0, this->kth< 3>(), | 103 return Sk16b(0,0,0, (*this)[ 3], |
| 104 0,0,0, this->kth< 7>(), | 104 0,0,0, (*this)[ 7], |
| 105 0,0,0, this->kth<11>(), | 105 0,0,0, (*this)[11], |
| 106 0,0,0, this->kth<15>()); | 106 0,0,0, (*this)[15]); |
| 107 } | 107 } |
| 108 | 108 |
| 109 } // namespace | 109 } // namespace |
| OLD | NEW |