Sk4px_none.h 1.9 KB

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