Index: src/opts/SkMorphology_opts_SSE2.cpp |
diff --git a/src/opts/SkMorphology_opts_SSE2.cpp b/src/opts/SkMorphology_opts_SSE2.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8d94edd5b95a94e18b285f698b03aa392876a0a7 |
--- /dev/null |
+++ b/src/opts/SkMorphology_opts_SSE2.cpp |
@@ -0,0 +1,117 @@ |
+/* |
+ * Copyright 2013 The Android Open Source Project |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+ |
+#include "SkColorPriv.h" |
+ |
+#include <emmintrin.h> |
+ |
+/* SSE2 version of dilateX, dilateY, erodeX, erodeY. |
+ * portable versions are in src/effects/SkMorphologyImageFilter.cpp. |
+ */ |
+ |
+void SkDilateX_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, |
mtklein
2013/10/30 15:44:47
Do you see any value in sharing the structure of a
Stephen White
2013/10/30 19:47:17
OK, I've templated across type and direction. No e
|
+ int width, int height, int srcStride, int dstStride) |
+{ |
+ radius = SkMin32(radius, width - 1); |
+ const SkPMColor* upperSrc = src + radius; |
+ for (int x = 0; x < width; ++x) { |
+ const SkPMColor* lp = src; |
+ const SkPMColor* up = upperSrc; |
+ SkPMColor* dptr = dst; |
+ for (int y = 0; y < height; ++y) { |
+ __m128i max = _mm_setzero_si128(); |
+ for (const SkPMColor* p = lp; p <= up; ++p) { |
+ __m128i src_pixel = _mm_cvtsi32_si128(*p); |
+ max = _mm_max_epu8(src_pixel, max); |
+ } |
+ *dptr = _mm_cvtsi128_si32(max); |
+ dptr += dstStride; |
+ lp += srcStride; |
+ up += srcStride; |
+ } |
+ if (x >= radius) ++src; |
+ if (x + radius < width - 1) ++upperSrc; |
+ ++dst; |
+ } |
+} |
+ |
+void SkDilateY_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, |
+ int width, int height, int srcStride, int dstStride) |
+{ |
+ radius = SkMin32(radius, height - 1); |
+ const SkPMColor* upperSrc = src + radius * srcStride; |
+ for (int y = 0; y < height; ++y) { |
+ const SkPMColor* lp = src; |
+ const SkPMColor* up = upperSrc; |
+ SkPMColor* dptr = dst; |
+ for (int x = 0; x < width; ++x) { |
+ __m128i max = _mm_setzero_si128(); |
+ for (const SkPMColor* p = lp; p <= up; p += srcStride) { |
+ __m128i src_pixel = _mm_cvtsi32_si128(*p); |
+ max = _mm_max_epu8(src_pixel, max); |
+ } |
+ *dptr++ = _mm_cvtsi128_si32(max); |
+ lp++; |
+ up++; |
+ } |
+ if (y >= radius) src += srcStride; |
+ if (y + radius < height - 1) upperSrc += srcStride; |
+ dst += dstStride; |
+ } |
+} |
+ |
+void SkErodeX_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, |
+ int width, int height, int srcStride, int dstStride) |
+{ |
+ radius = SkMin32(radius, width - 1); |
+ const SkPMColor* upperSrc = src + radius; |
+ for (int x = 0; x < width; ++x) { |
+ const SkPMColor* lp = src; |
+ const SkPMColor* up = upperSrc; |
+ SkPMColor* dptr = dst; |
+ for (int y = 0; y < height; ++y) { |
+ __m128i min = _mm_set1_epi32(0xFFFFFFFF); |
+ for (const SkPMColor* p = lp; p <= up; ++p) { |
+ __m128i src_pixel = _mm_cvtsi32_si128(*p); |
+ min = _mm_min_epu8(src_pixel, min); |
+ } |
+ *dptr = _mm_cvtsi128_si32(min); |
+ dptr += dstStride; |
+ lp += srcStride; |
+ up += srcStride; |
+ } |
+ if (x >= radius) ++src; |
+ if (x + radius < width - 1) ++upperSrc; |
+ ++dst; |
+ } |
+} |
+ |
+void SkErodeY_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, |
+ int width, int height, int srcStride, int dstStride) |
+{ |
+ radius = SkMin32(radius, height - 1); |
+ const SkPMColor* upperSrc = src + radius * srcStride; |
+ for (int y = 0; y < height; ++y) { |
+ const SkPMColor* lp = src; |
+ const SkPMColor* up = upperSrc; |
+ SkPMColor* dptr = dst; |
+ for (int x = 0; x < width; ++x) { |
+ __m128i min = _mm_set1_epi32(0xFFFFFFFF); |
+ for (const SkPMColor* p = lp; p <= up; p += srcStride) { |
+ __m128i src_pixel = _mm_cvtsi32_si128(*p); |
+ min = _mm_min_epu8(src_pixel, min); |
+ } |
+ *dptr++ = _mm_cvtsi128_si32(min); |
+ lp++; |
+ up++; |
+ } |
+ if (y >= radius) src += srcStride; |
+ if (y + radius < height - 1) upperSrc += srcStride; |
+ dst += dstStride; |
+ } |
+} |