OLD | NEW |
| (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 #include <emmintrin.h> | |
9 #include "SkColorPriv.h" | |
10 #include "SkMorphology_opts_SSE2.h" | |
11 | |
12 /* SSE2 version of dilateX, dilateY, erodeX, erodeY. | |
13 * portable versions are in src/effects/SkMorphologyImageFilter.cpp. | |
14 */ | |
15 | |
16 enum MorphType { | |
17 kDilate, kErode | |
18 }; | |
19 | |
20 enum MorphDirection { | |
21 kX, kY | |
22 }; | |
23 | |
24 template<MorphType type, MorphDirection direction> | |
25 static void SkMorph_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, | |
26 int width, int height, int srcStride, int dstStride) | |
27 { | |
28 const int srcStrideX = direction == kX ? 1 : srcStride; | |
29 const int dstStrideX = direction == kX ? 1 : dstStride; | |
30 const int srcStrideY = direction == kX ? srcStride : 1; | |
31 const int dstStrideY = direction == kX ? dstStride : 1; | |
32 radius = SkMin32(radius, width - 1); | |
33 const SkPMColor* upperSrc = src + radius * srcStrideX; | |
34 for (int x = 0; x < width; ++x) { | |
35 const SkPMColor* lp = src; | |
36 const SkPMColor* up = upperSrc; | |
37 SkPMColor* dptr = dst; | |
38 for (int y = 0; y < height; ++y) { | |
39 __m128i max = type == kDilate ? _mm_setzero_si128() : _mm_set1_epi32
(0xFFFFFFFF); | |
40 for (const SkPMColor* p = lp; p <= up; p += srcStrideX) { | |
41 __m128i src_pixel = _mm_cvtsi32_si128(*p); | |
42 max = type == kDilate ? _mm_max_epu8(src_pixel, max) : _mm_min_e
pu8(src_pixel, max); | |
43 } | |
44 *dptr = _mm_cvtsi128_si32(max); | |
45 dptr += dstStrideY; | |
46 lp += srcStrideY; | |
47 up += srcStrideY; | |
48 } | |
49 if (x >= radius) { | |
50 src += srcStrideX; | |
51 } | |
52 if (x + radius < width - 1) { | |
53 upperSrc += srcStrideX; | |
54 } | |
55 dst += dstStrideX; | |
56 } | |
57 } | |
58 | |
59 void SkDilateX_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, | |
60 int width, int height, int srcStride, int dstStride) | |
61 { | |
62 SkMorph_SSE2<kDilate, kX>(src, dst, radius, width, height, srcStride, dstStr
ide); | |
63 } | |
64 | |
65 void SkErodeX_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, | |
66 int width, int height, int srcStride, int dstStride) | |
67 { | |
68 SkMorph_SSE2<kErode, kX>(src, dst, radius, width, height, srcStride, dstStri
de); | |
69 } | |
70 | |
71 void SkDilateY_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, | |
72 int width, int height, int srcStride, int dstStride) | |
73 { | |
74 SkMorph_SSE2<kDilate, kY>(src, dst, radius, width, height, srcStride, dstStr
ide); | |
75 } | |
76 | |
77 void SkErodeY_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, | |
78 int width, int height, int srcStride, int dstStride) | |
79 { | |
80 SkMorph_SSE2<kErode, kY>(src, dst, radius, width, height, srcStride, dstStri
de); | |
81 } | |
OLD | NEW |