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

Side by Side Diff: src/opts/SkMorphology_opts_SSE2.cpp

Issue 52603004: Implement SSE2-based implementations of the morphology filters (dilate & (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Tweak Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/opts/SkMorphology_opts_SSE2.h ('k') | src/opts/SkMorphology_opts_none.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 The Android Open Source Project
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
9 #include "SkColorPriv.h"
10
11 #include <emmintrin.h>
12
13 /* SSE2 version of dilateX, dilateY, erodeX, erodeY.
14 * portable versions are in src/effects/SkMorphologyImageFilter.cpp.
15 */
16
17 enum MorphType {
18 kDilate, kErode
19 };
20
21 enum MorphDirection {
22 kX, kY
23 };
24
25 template<MorphType type, MorphDirection direction>
26 static void SkMorph_SSE2(const SkPMColor* src, SkPMColor* dst, int radius,
27 int width, int height, int srcStride, int dstStride)
28 {
29 const int srcStrideX = direction == kX ? 1 : srcStride;
30 const int dstStrideX = direction == kX ? 1 : dstStride;
31 const int srcStrideY = direction == kX ? srcStride : 1;
32 const int dstStrideY = direction == kX ? dstStride : 1;
33 radius = SkMin32(radius, width - 1);
34 const SkPMColor* upperSrc = src + radius * srcStrideX;
35 for (int x = 0; x < width; ++x) {
36 const SkPMColor* lp = src;
37 const SkPMColor* up = upperSrc;
38 SkPMColor* dptr = dst;
39 for (int y = 0; y < height; ++y) {
40 __m128i max = type == kDilate ? _mm_setzero_si128() : _mm_set1_epi32 (0xFFFFFFFF);
41 for (const SkPMColor* p = lp; p <= up; p += srcStrideX) {
42 __m128i src_pixel = _mm_cvtsi32_si128(*p);
43 max = type == kDilate ? _mm_max_epu8(src_pixel, max) : _mm_min_e pu8(src_pixel, max);
44 }
45 *dptr = _mm_cvtsi128_si32(max);
46 dptr += dstStrideY;
47 lp += srcStrideY;
48 up += srcStrideY;
49 }
50 if (x >= radius) src += srcStrideX;
51 if (x + radius < width - 1) upperSrc += srcStrideX;
52 dst += dstStrideX;
53 }
54 }
55
56 void SkDilateX_SSE2(const SkPMColor* src, SkPMColor* dst, int radius,
57 int width, int height, int srcStride, int dstStride)
58 {
59 SkMorph_SSE2<kDilate, kX>(src, dst, radius, width, height, srcStride, dstStr ide);
60 }
61
62 void SkErodeX_SSE2(const SkPMColor* src, SkPMColor* dst, int radius,
63 int width, int height, int srcStride, int dstStride)
64 {
65 SkMorph_SSE2<kErode, kX>(src, dst, radius, width, height, srcStride, dstStri de);
66 }
67
68 void SkDilateY_SSE2(const SkPMColor* src, SkPMColor* dst, int radius,
69 int width, int height, int srcStride, int dstStride)
70 {
71 SkMorph_SSE2<kDilate, kY>(src, dst, radius, width, height, srcStride, dstStr ide);
72 }
73
74 void SkErodeY_SSE2(const SkPMColor* src, SkPMColor* dst, int radius,
75 int width, int height, int srcStride, int dstStride)
76 {
77 SkMorph_SSE2<kErode, kY>(src, dst, radius, width, height, srcStride, dstStri de);
78 }
OLDNEW
« no previous file with comments | « src/opts/SkMorphology_opts_SSE2.h ('k') | src/opts/SkMorphology_opts_none.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698