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 |
| 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 template<bool dilate, bool inX> |
| 18 static void SkMorph_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, |
| 19 int width, int height, int srcStride, int dstStride) |
| 20 { |
| 21 const int srcStrideX = inX ? 1 : srcStride; |
| 22 const int dstStrideX = inX ? 1 : dstStride; |
| 23 const int srcStrideY = inX ? srcStride : 1; |
| 24 const int dstStrideY = inX ? dstStride : 1; |
| 25 radius = SkMin32(radius, width - 1); |
| 26 const SkPMColor* upperSrc = src + radius * srcStrideX; |
| 27 for (int x = 0; x < width; ++x) { |
| 28 const SkPMColor* lp = src; |
| 29 const SkPMColor* up = upperSrc; |
| 30 SkPMColor* dptr = dst; |
| 31 for (int y = 0; y < height; ++y) { |
| 32 __m128i max = dilate ? _mm_setzero_si128() : _mm_set1_epi32(0xFFFFFF
FF); |
| 33 for (const SkPMColor* p = lp; p <= up; p += srcStrideX) { |
| 34 __m128i src_pixel = _mm_cvtsi32_si128(*p); |
| 35 max = dilate ? _mm_max_epu8(src_pixel, max) : _mm_min_epu8(src_p
ixel, max); |
| 36 } |
| 37 *dptr = _mm_cvtsi128_si32(max); |
| 38 dptr += dstStrideY; |
| 39 lp += srcStrideY; |
| 40 up += srcStrideY; |
| 41 } |
| 42 if (x >= radius) src += srcStrideX; |
| 43 if (x + radius < width - 1) upperSrc += srcStrideX; |
| 44 dst += dstStrideX; |
| 45 } |
| 46 } |
| 47 |
| 48 void SkDilateX_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, |
| 49 int width, int height, int srcStride, int dstStride) |
| 50 { |
| 51 SkMorph_SSE2<true, true>(src, dst, radius, width, height, srcStride, dstStri
de); |
| 52 } |
| 53 |
| 54 void SkErodeX_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, |
| 55 int width, int height, int srcStride, int dstStride) |
| 56 { |
| 57 SkMorph_SSE2<false, true>(src, dst, radius, width, height, srcStride, dstStr
ide); |
| 58 } |
| 59 |
| 60 void SkDilateY_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, |
| 61 int width, int height, int srcStride, int dstStride) |
| 62 { |
| 63 SkMorph_SSE2<true, false>(src, dst, radius, width, height, srcStride, dstStr
ide); |
| 64 } |
| 65 |
| 66 void SkErodeY_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, |
| 67 int width, int height, int srcStride, int dstStride) |
| 68 { |
| 69 SkMorph_SSE2<false, false>(src, dst, radius, width, height, srcStride, dstSt
ride); |
| 70 } |
OLD | NEW |