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 8 #include "SkUtils.h" 9 10 namespace { // NOLINT(google-build-namespaces) 11 12 inline Sk4px::Wide Sk4px::widen() const { 13 return Sk16h((*this)[ 0], (*this)[ 1], (*this)[ 2], (*this)[ 3], 14 (*this)[ 4], (*this)[ 5], (*this)[ 6], (*this)[ 7], 15 (*this)[ 8], (*this)[ 9], (*this)[10], (*this)[11], 16 (*this)[12], (*this)[13], (*this)[14], (*this)[15]); 17 } 18 19 inline Sk4px::Wide Sk4px::mulWiden(const Sk16b& other) const { 20 return this->widen() * Sk4px(other).widen(); 21 } 22 23 inline Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const { 24 Sk4px::Wide r = (*this + other) >> 8; 25 return Sk16b(r[ 0], r[ 1], r[ 2], r[ 3], 26 r[ 4], r[ 5], r[ 6], r[ 7], 27 r[ 8], r[ 9], r[10], r[11], 28 r[12], r[13], r[14], r[15]); 29 } 30 31 inline Sk4px Sk4px::Wide::div255() const { 32 // Calculated as ((x+128) + ((x+128)>>8)) >> 8. 33 auto v = *this + Sk16h(128); 34 return v.addNarrowHi(v>>8); 35 } 36 37 inline Sk4px Sk4px::alphas() const { 38 static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian."); 39 return Sk16b((*this)[ 3], (*this)[ 3], (*this)[ 3], (*this)[ 3], 40 (*this)[ 7], (*this)[ 7], (*this)[ 7], (*this)[ 7], 41 (*this)[11], (*this)[11], (*this)[11], (*this)[11], 42 (*this)[15], (*this)[15], (*this)[15], (*this)[15]); 43 } 44 45 inline Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) { 46 return Sk16b(a[0], a[0], a[0], a[0], 47 a[1], a[1], a[1], a[1], 48 a[2], a[2], a[2], a[2], 49 a[3], a[3], a[3], a[3]); 50 } 51 52 inline Sk4px Sk4px::Load2Alphas(const SkAlpha a[2]) { 53 return Sk16b(a[0], a[0], a[0], a[0], 54 a[1], a[1], a[1], a[1], 55 0,0,0,0, 56 0,0,0,0); 57 } 58 59 } // namespace 60