| 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 | |
| 11 | |
| 12 static_assert(sizeof(Sk4px) == 16, "This file uses memcpy / sk_memset32, so exac
t size matters."); | 10 static_assert(sizeof(Sk4px) == 16, "This file uses memcpy / sk_memset32, so exac
t size matters."); |
| 13 | 11 |
| 14 inline Sk4px Sk4px::DupPMColor(SkPMColor px) { | 12 SK_ALWAYS_INLINE Sk4px Sk4px::DupPMColor(SkPMColor px) { |
| 15 Sk4px px4 = Sk16b(); | 13 Sk4px px4 = Sk16b(); |
| 16 sk_memset32((uint32_t*)&px4, px, 4); | 14 sk_memset32((uint32_t*)&px4, px, 4); |
| 17 return px4; | 15 return px4; |
| 18 } | 16 } |
| 19 | 17 |
| 20 inline Sk4px Sk4px::Load4(const SkPMColor px[4]) { | 18 SK_ALWAYS_INLINE Sk4px Sk4px::Load4(const SkPMColor px[4]) { |
| 21 Sk4px px4 = Sk16b(); | 19 Sk4px px4 = Sk16b(); |
| 22 memcpy(&px4, px, 16); | 20 memcpy(&px4, px, 16); |
| 23 return px4; | 21 return px4; |
| 24 } | 22 } |
| 25 | 23 |
| 26 inline Sk4px Sk4px::Load2(const SkPMColor px[2]) { | 24 SK_ALWAYS_INLINE Sk4px Sk4px::Load2(const SkPMColor px[2]) { |
| 27 Sk4px px2 = Sk16b(); | 25 Sk4px px2 = Sk16b(); |
| 28 memcpy(&px2, px, 8); | 26 memcpy(&px2, px, 8); |
| 29 return px2; | 27 return px2; |
| 30 } | 28 } |
| 31 | 29 |
| 32 inline Sk4px Sk4px::Load1(const SkPMColor px[1]) { | 30 SK_ALWAYS_INLINE Sk4px Sk4px::Load1(const SkPMColor px[1]) { |
| 33 Sk4px px1 = Sk16b(); | 31 Sk4px px1 = Sk16b(); |
| 34 memcpy(&px1, px, 4); | 32 memcpy(&px1, px, 4); |
| 35 return px1; | 33 return px1; |
| 36 } | 34 } |
| 37 | 35 |
| 38 inline void Sk4px::store4(SkPMColor px[4]) const { memcpy(px, this, 16); } | 36 SK_ALWAYS_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); } | 37 SK_ALWAYS_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); } | 38 SK_ALWAYS_INLINE void Sk4px::store1(SkPMColor px[1]) const { memcpy(px, this, 4
); } |
| 41 | 39 |
| 42 inline Sk4px::Wide Sk4px::widenLo() const { | 40 SK_ALWAYS_INLINE Sk4px::Wide Sk4px::widenLo() const { |
| 43 return Sk16h(this->kth< 0>(), this->kth< 1>(), this->kth< 2>(), this->kth< 3
>(), | 41 return Sk16h(this->kth< 0>(), this->kth< 1>(), this->kth< 2>(), this->kth< 3
>(), |
| 44 this->kth< 4>(), this->kth< 5>(), this->kth< 6>(), this->kth< 7
>(), | 42 this->kth< 4>(), this->kth< 5>(), this->kth< 6>(), this->kth< 7
>(), |
| 45 this->kth< 8>(), this->kth< 9>(), this->kth<10>(), this->kth<11
>(), | 43 this->kth< 8>(), this->kth< 9>(), this->kth<10>(), this->kth<11
>(), |
| 46 this->kth<12>(), this->kth<13>(), this->kth<14>(), this->kth<15
>()); | 44 this->kth<12>(), this->kth<13>(), this->kth<14>(), this->kth<15
>()); |
| 47 } | 45 } |
| 48 | 46 |
| 49 inline Sk4px::Wide Sk4px::widenHi() const { return this->widenLo() << 8; } | 47 SK_ALWAYS_INLINE Sk4px::Wide Sk4px::widenHi() const { return this->widenLo() <<
8; } |
| 50 | 48 |
| 51 inline Sk4px::Wide Sk4px::widenLoHi() const { return this->widenLo() + this->wid
enHi(); } | 49 SK_ALWAYS_INLINE Sk4px::Wide Sk4px::widenLoHi() const { return this->widenLo() +
this->widenHi(); } |
| 52 | 50 |
| 53 inline Sk4px::Wide Sk4px::mulWiden(const Sk16b& other) const { | 51 SK_ALWAYS_INLINE Sk4px::Wide Sk4px::mulWiden(const Sk16b& other) const { |
| 54 return this->widenLo() * Sk4px(other).widenLo(); | 52 return this->widenLo() * Sk4px(other).widenLo(); |
| 55 } | 53 } |
| 56 | 54 |
| 57 inline Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const { | 55 SK_ALWAYS_INLINE Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const { |
| 58 Sk4px::Wide r = (*this + other) >> 8; | 56 Sk4px::Wide r = (*this + other) >> 8; |
| 59 return Sk16b(r.kth< 0>(), r.kth< 1>(), r.kth< 2>(), r.kth< 3>(), | 57 return Sk16b(r.kth< 0>(), r.kth< 1>(), r.kth< 2>(), r.kth< 3>(), |
| 60 r.kth< 4>(), r.kth< 5>(), r.kth< 6>(), r.kth< 7>(), | 58 r.kth< 4>(), r.kth< 5>(), r.kth< 6>(), r.kth< 7>(), |
| 61 r.kth< 8>(), r.kth< 9>(), r.kth<10>(), r.kth<11>(), | 59 r.kth< 8>(), r.kth< 9>(), r.kth<10>(), r.kth<11>(), |
| 62 r.kth<12>(), r.kth<13>(), r.kth<14>(), r.kth<15>()); | 60 r.kth<12>(), r.kth<13>(), r.kth<14>(), r.kth<15>()); |
| 63 } | 61 } |
| 64 | 62 |
| 65 inline Sk4px Sk4px::alphas() const { | 63 SK_ALWAYS_INLINE Sk4px Sk4px::alphas() const { |
| 66 static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian."); | 64 static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian."); |
| 67 return Sk16b(this->kth< 3>(), this->kth< 3>(), this->kth< 3>(), this->kth< 3
>(), | 65 return Sk16b(this->kth< 3>(), this->kth< 3>(), this->kth< 3>(), this->kth< 3
>(), |
| 68 this->kth< 7>(), this->kth< 7>(), this->kth< 7>(), this->kth< 7
>(), | 66 this->kth< 7>(), this->kth< 7>(), this->kth< 7>(), this->kth< 7
>(), |
| 69 this->kth<11>(), this->kth<11>(), this->kth<11>(), this->kth<11
>(), | 67 this->kth<11>(), this->kth<11>(), this->kth<11>(), this->kth<11
>(), |
| 70 this->kth<15>(), this->kth<15>(), this->kth<15>(), this->kth<15
>()); | 68 this->kth<15>(), this->kth<15>(), this->kth<15>(), this->kth<15
>()); |
| 71 } | 69 } |
| 72 | 70 |
| 73 inline Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) { | 71 SK_ALWAYS_INLINE Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) { |
| 74 return Sk16b(a[0], a[0], a[0], a[0], | 72 return Sk16b(a[0], a[0], a[0], a[0], |
| 75 a[1], a[1], a[1], a[1], | 73 a[1], a[1], a[1], a[1], |
| 76 a[2], a[2], a[2], a[2], | 74 a[2], a[2], a[2], a[2], |
| 77 a[3], a[3], a[3], a[3]); | 75 a[3], a[3], a[3], a[3]); |
| 78 } | 76 } |
| 79 | 77 |
| 80 inline Sk4px Sk4px::Load2Alphas(const SkAlpha a[2]) { | 78 SK_ALWAYS_INLINE Sk4px Sk4px::Load2Alphas(const SkAlpha a[2]) { |
| 81 return Sk16b(a[0], a[0], a[0], a[0], | 79 return Sk16b(a[0], a[0], a[0], a[0], |
| 82 a[1], a[1], a[1], a[1], | 80 a[1], a[1], a[1], a[1], |
| 83 0,0,0,0, | 81 0,0,0,0, |
| 84 0,0,0,0); | 82 0,0,0,0); |
| 85 } | 83 } |
| 86 | 84 |
| 87 inline Sk4px Sk4px::zeroAlphas() const { | 85 SK_ALWAYS_INLINE Sk4px Sk4px::zeroAlphas() const { |
| 88 static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian."); | 86 static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian."); |
| 89 return Sk16b(this->kth< 0>(), this->kth< 1>(), this->kth< 2>(), 0, | 87 return Sk16b(this->kth< 0>(), this->kth< 1>(), this->kth< 2>(), 0, |
| 90 this->kth< 4>(), this->kth< 5>(), this->kth< 6>(), 0, | 88 this->kth< 4>(), this->kth< 5>(), this->kth< 6>(), 0, |
| 91 this->kth< 8>(), this->kth< 9>(), this->kth<10>(), 0, | 89 this->kth< 8>(), this->kth< 9>(), this->kth<10>(), 0, |
| 92 this->kth<12>(), this->kth<13>(), this->kth<14>(), 0); | 90 this->kth<12>(), this->kth<13>(), this->kth<14>(), 0); |
| 93 } | 91 } |
| 94 | 92 |
| 95 inline Sk4px Sk4px::zeroColors() const { | 93 SK_ALWAYS_INLINE Sk4px Sk4px::zeroColors() const { |
| 96 static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian."); | 94 static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian."); |
| 97 return Sk16b(0,0,0, this->kth< 3>(), | 95 return Sk16b(0,0,0, this->kth< 3>(), |
| 98 0,0,0, this->kth< 7>(), | 96 0,0,0, this->kth< 7>(), |
| 99 0,0,0, this->kth<11>(), | 97 0,0,0, this->kth<11>(), |
| 100 0,0,0, this->kth<15>()); | 98 0,0,0, this->kth<15>()); |
| 101 } | 99 } |
| 102 | 100 |
| 103 inline Sk4px Sk4px::Load4(const SkPMColor16 src[4]) { | 101 SK_ALWAYS_INLINE Sk4px Sk4px::Load4(const SkPMColor16 src[4]) { |
| 104 SkPMColor src32[4]; | 102 SkPMColor src32[4]; |
| 105 for (int i = 0; i < 4; i++) { src32[i] = SkPixel16ToPixel32(src[i]); } | 103 for (int i = 0; i < 4; i++) { src32[i] = SkPixel16ToPixel32(src[i]); } |
| 106 return Load4(src32); | 104 return Load4(src32); |
| 107 } | 105 } |
| 108 inline Sk4px Sk4px::Load2(const SkPMColor16 src[2]) { | 106 SK_ALWAYS_INLINE Sk4px Sk4px::Load2(const SkPMColor16 src[2]) { |
| 109 SkPMColor src32[2]; | 107 SkPMColor src32[2]; |
| 110 for (int i = 0; i < 2; i++) { src32[i] = SkPixel16ToPixel32(src[i]); } | 108 for (int i = 0; i < 2; i++) { src32[i] = SkPixel16ToPixel32(src[i]); } |
| 111 return Load2(src32); | 109 return Load2(src32); |
| 112 } | 110 } |
| 113 inline Sk4px Sk4px::Load1(const SkPMColor16 src[1]) { | 111 SK_ALWAYS_INLINE Sk4px Sk4px::Load1(const SkPMColor16 src[1]) { |
| 114 SkPMColor src32 = SkPixel16ToPixel32(src[0]); | 112 SkPMColor src32 = SkPixel16ToPixel32(src[0]); |
| 115 return Load1(&src32); | 113 return Load1(&src32); |
| 116 } | 114 } |
| 117 | 115 |
| 118 inline void Sk4px::store4(SkPMColor16 dst[4]) const { | 116 SK_ALWAYS_INLINE void Sk4px::store4(SkPMColor16 dst[4]) const { |
| 119 SkPMColor dst32[4]; | 117 SkPMColor dst32[4]; |
| 120 this->store4(dst32); | 118 this->store4(dst32); |
| 121 for (int i = 0; i < 4; i++) { dst[i] = SkPixel32ToPixel16(dst32[i]); } | 119 for (int i = 0; i < 4; i++) { dst[i] = SkPixel32ToPixel16(dst32[i]); } |
| 122 } | 120 } |
| 123 inline void Sk4px::store2(SkPMColor16 dst[2]) const { | 121 SK_ALWAYS_INLINE void Sk4px::store2(SkPMColor16 dst[2]) const { |
| 124 SkPMColor dst32[2]; | 122 SkPMColor dst32[2]; |
| 125 this->store2(dst32); | 123 this->store2(dst32); |
| 126 for (int i = 0; i < 2; i++) { dst[i] = SkPixel32ToPixel16(dst32[i]); } | 124 for (int i = 0; i < 2; i++) { dst[i] = SkPixel32ToPixel16(dst32[i]); } |
| 127 } | 125 } |
| 128 inline void Sk4px::store1(SkPMColor16 dst[1]) const { | 126 SK_ALWAYS_INLINE void Sk4px::store1(SkPMColor16 dst[1]) const { |
| 129 SkPMColor dst32; | 127 SkPMColor dst32; |
| 130 this->store1(&dst32); | 128 this->store1(&dst32); |
| 131 dst[0] = SkPixel32ToPixel16(dst32); | 129 dst[0] = SkPixel32ToPixel16(dst32); |
| 132 } | 130 } |
| 133 | |
| 134 } // namespace | |
| OLD | NEW |