Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: src/core/Sk4px.h

Issue 1141213002: Sk4px: Difference and Exclusion (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: back to 8-bit Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/core/SkXfermode.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef Sk4px_DEFINED 8 #ifndef Sk4px_DEFINED
9 #define Sk4px_DEFINED 9 #define Sk4px_DEFINED
10 10
11 #include "SkNx.h" 11 #include "SkNx.h"
12 #include "SkColor.h" 12 #include "SkColor.h"
13 13
14 // 1, 2 or 4 SkPMColors, generally vectorized. 14 // 1, 2 or 4 SkPMColors, generally vectorized.
15 class Sk4px : public Sk16b { 15 class Sk4px : public Sk16b {
16 public: 16 public:
17 Sk4px(SkAlpha a) : INHERITED(a) {} // Duplicate 16x: a -> aaaa aaaa aaaa aaaa 17 Sk4px(SkAlpha a) : INHERITED(a) {} // Duplicate 16x: a -> aaaa aaaa aaaa aaaa
18 Sk4px(SkPMColor); // Duplicate 4x: argb -> argb argb argb argb 18 Sk4px(SkPMColor); // Duplicate 4x: argb -> argb argb argb argb
19 Sk4px(const Sk16b& v) : INHERITED(v) {} 19 Sk4px(const Sk16b& v) : INHERITED(v) {}
20 20
21 Sk4px alphas() const; // ARGB argb XYZW xyzw -> AAAA aaaa XXXX xxxx 21 Sk4px alphas() const; // ARGB argb XYZW xyzw -> AAAA aaaa XXXX xxxx
22 22
23 // Mask away color or alpha lanes.
24 Sk4px zeroColors() const; // ARGB argb XYZW xyzw -> A000 a000 X000 x000
25 Sk4px zeroAlphas() const; // ARGB argb XYZW xyzw -> 0RGB 0rgb 0YZW 0yzw
26
23 Sk4px inv() const { return Sk16b(255) - *this; } 27 Sk4px inv() const { return Sk16b(255) - *this; }
24 28
25 // When loading or storing fewer than 4 SkPMColors, we use the low lanes. 29 // When loading or storing fewer than 4 SkPMColors, we use the low lanes.
26 static Sk4px Load4(const SkPMColor[4]); // PMColor[4] -> ARGB argb XYZW xyz w 30 static Sk4px Load4(const SkPMColor[4]); // PMColor[4] -> ARGB argb XYZW xyz w
27 static Sk4px Load2(const SkPMColor[2]); // PMColor[2] -> ARGB argb ???? ??? ? 31 static Sk4px Load2(const SkPMColor[2]); // PMColor[2] -> ARGB argb ???? ??? ?
28 static Sk4px Load1(const SkPMColor[1]); // PMColor[1] -> ARGB ???? ???? ??? ? 32 static Sk4px Load1(const SkPMColor[1]); // PMColor[1] -> ARGB ???? ???? ??? ?
29 33
30 // Ditto for Alphas... Load2Alphas fills the low two lanes of Sk4px. 34 // Ditto for Alphas... Load2Alphas fills the low two lanes of Sk4px.
31 static Sk4px Load4Alphas(const SkAlpha[4]); // AaXx -> AAAA aaaa XXXX xxxx 35 static Sk4px Load4Alphas(const SkAlpha[4]); // AaXx -> AAAA aaaa XXXX xxxx
32 static Sk4px Load2Alphas(const SkAlpha[2]); // Aa -> AAAA aaaa ???? ???? 36 static Sk4px Load2Alphas(const SkAlpha[2]); // Aa -> AAAA aaaa ???? ????
(...skipping 16 matching lines...) Expand all
49 return Sk4px::Wide(*this + Sk16h(128)).div255TruncNarrow(); 53 return Sk4px::Wide(*this + Sk16h(128)).div255TruncNarrow();
50 } 54 }
51 55
52 private: 56 private:
53 typedef Sk16h INHERITED; 57 typedef Sk16h INHERITED;
54 }; 58 };
55 59
56 Wide widenLo() const; // ARGB -> 0A 0R 0G 0B 60 Wide widenLo() const; // ARGB -> 0A 0R 0G 0B
57 Wide widenHi() const; // ARGB -> A0 R0 G0 B0 61 Wide widenHi() const; // ARGB -> A0 R0 G0 B0
58 Wide mulWiden(const Sk16b&) const; // 8-bit x 8-bit -> 16-bit components. 62 Wide mulWiden(const Sk16b&) const; // 8-bit x 8-bit -> 16-bit components.
63 Wide mul255Widen() const {
64 // TODO: x*255 = x*256-x, so something like this->widenHi() - this->wide nLo()?
65 return this->mulWiden(Sk16b(255));
66 }
59 67
60 // A generic driver that maps fn over a src array into a dst array. 68 // A generic driver that maps fn over a src array into a dst array.
61 // fn should take an Sk4px (4 src pixels) and return an Sk4px (4 dst pixels) . 69 // fn should take an Sk4px (4 src pixels) and return an Sk4px (4 dst pixels) .
62 template <typename Fn> 70 template <typename Fn>
63 static void MapSrc(int count, SkPMColor* dst, const SkPMColor* src, Fn fn) { 71 static void MapSrc(int count, SkPMColor* dst, const SkPMColor* src, Fn fn) {
64 // This looks a bit odd, but it helps loop-invariant hoisting across dif ferent calls to fn. 72 // This looks a bit odd, but it helps loop-invariant hoisting across dif ferent calls to fn.
65 // Basically, we need to make sure we keep things inside a single loop. 73 // Basically, we need to make sure we keep things inside a single loop.
66 while (count > 0) { 74 while (count > 0) {
67 if (count >= 8) { 75 if (count >= 8) {
68 Sk4px dst0 = fn(Load4(src+0)), 76 Sk4px dst0 = fn(Load4(src+0)),
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 168 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
161 #include "../opts/Sk4px_SSE2.h" 169 #include "../opts/Sk4px_SSE2.h"
162 #elif defined(SK_ARM_HAS_NEON) 170 #elif defined(SK_ARM_HAS_NEON)
163 #include "../opts/Sk4px_NEON.h" 171 #include "../opts/Sk4px_NEON.h"
164 #else 172 #else
165 #include "../opts/Sk4px_none.h" 173 #include "../opts/Sk4px_none.h"
166 #endif 174 #endif
167 #endif 175 #endif
168 176
169 #endif//Sk4px_DEFINED 177 #endif//Sk4px_DEFINED
OLDNEW
« no previous file with comments | « no previous file | src/core/SkXfermode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698