blob: edd16099980d85772b8c6a0b8d7aad1ba566d51a [file] [log] [blame]
mtkleind2ffd362015-05-12 06:11:21 -07001/*
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
Mike Kleinc33d6142018-12-12 08:47:54 -050010namespace { // NOLINT(google-build-namespaces)
mtklein082e3292015-08-12 11:56:43 -070011
Mike Klein7dfe6d92018-12-18 14:53:37 -050012inline Sk4px::Wide Sk4px::widen() const {
mtklein7c249e52016-02-21 10:54:19 -080013 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]);
mtkleind2ffd362015-05-12 06:11:21 -070017}
18
mtklein082e3292015-08-12 11:56:43 -070019inline Sk4px::Wide Sk4px::mulWiden(const Sk16b& other) const {
Mike Klein7dfe6d92018-12-18 14:53:37 -050020 return this->widen() * Sk4px(other).widen();
mtkleind2ffd362015-05-12 06:11:21 -070021}
22
mtklein082e3292015-08-12 11:56:43 -070023inline Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const {
mtkleind2ffd362015-05-12 06:11:21 -070024 Sk4px::Wide r = (*this + other) >> 8;
mtklein7c249e52016-02-21 10:54:19 -080025 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]);
mtkleind2ffd362015-05-12 06:11:21 -070029}
mtklein8a90edc2015-05-13 12:19:42 -070030
mtkleincbf4fba2015-11-17 14:19:52 -080031inline 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
mtklein082e3292015-08-12 11:56:43 -070037inline Sk4px Sk4px::alphas() const {
mtklein8a90edc2015-05-13 12:19:42 -070038 static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian.");
mtklein7c249e52016-02-21 10:54:19 -080039 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]);
mtklein8a90edc2015-05-13 12:19:42 -070043}
44
mtklein082e3292015-08-12 11:56:43 -070045inline Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) {
mtklein8a90edc2015-05-13 12:19:42 -070046 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
mtklein082e3292015-08-12 11:56:43 -070052inline Sk4px Sk4px::Load2Alphas(const SkAlpha a[2]) {
mtklein8a90edc2015-05-13 12:19:42 -070053 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}
mtklein0135a412015-05-15 10:36:21 -070058
mtklein082e3292015-08-12 11:56:43 -070059} // namespace