michael@0: /* michael@0: * Copyright 2013 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "SkColorPriv.h" michael@0: #include "SkMorphology_opts_SSE2.h" michael@0: michael@0: #include michael@0: michael@0: /* SSE2 version of dilateX, dilateY, erodeX, erodeY. michael@0: * portable versions are in src/effects/SkMorphologyImageFilter.cpp. michael@0: */ michael@0: michael@0: enum MorphType { michael@0: kDilate, kErode michael@0: }; michael@0: michael@0: enum MorphDirection { michael@0: kX, kY michael@0: }; michael@0: michael@0: template michael@0: static void SkMorph_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, michael@0: int width, int height, int srcStride, int dstStride) michael@0: { michael@0: const int srcStrideX = direction == kX ? 1 : srcStride; michael@0: const int dstStrideX = direction == kX ? 1 : dstStride; michael@0: const int srcStrideY = direction == kX ? srcStride : 1; michael@0: const int dstStrideY = direction == kX ? dstStride : 1; michael@0: radius = SkMin32(radius, width - 1); michael@0: const SkPMColor* upperSrc = src + radius * srcStrideX; michael@0: for (int x = 0; x < width; ++x) { michael@0: const SkPMColor* lp = src; michael@0: const SkPMColor* up = upperSrc; michael@0: SkPMColor* dptr = dst; michael@0: for (int y = 0; y < height; ++y) { michael@0: __m128i max = type == kDilate ? _mm_setzero_si128() : _mm_set1_epi32(0xFFFFFFFF); michael@0: for (const SkPMColor* p = lp; p <= up; p += srcStrideX) { michael@0: __m128i src_pixel = _mm_cvtsi32_si128(*p); michael@0: max = type == kDilate ? _mm_max_epu8(src_pixel, max) : _mm_min_epu8(src_pixel, max); michael@0: } michael@0: *dptr = _mm_cvtsi128_si32(max); michael@0: dptr += dstStrideY; michael@0: lp += srcStrideY; michael@0: up += srcStrideY; michael@0: } michael@0: if (x >= radius) src += srcStrideX; michael@0: if (x + radius < width - 1) upperSrc += srcStrideX; michael@0: dst += dstStrideX; michael@0: } michael@0: } michael@0: michael@0: void SkDilateX_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, michael@0: int width, int height, int srcStride, int dstStride) michael@0: { michael@0: SkMorph_SSE2(src, dst, radius, width, height, srcStride, dstStride); michael@0: } michael@0: michael@0: void SkErodeX_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, michael@0: int width, int height, int srcStride, int dstStride) michael@0: { michael@0: SkMorph_SSE2(src, dst, radius, width, height, srcStride, dstStride); michael@0: } michael@0: michael@0: void SkDilateY_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, michael@0: int width, int height, int srcStride, int dstStride) michael@0: { michael@0: SkMorph_SSE2(src, dst, radius, width, height, srcStride, dstStride); michael@0: } michael@0: michael@0: void SkErodeY_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, michael@0: int width, int height, int srcStride, int dstStride) michael@0: { michael@0: SkMorph_SSE2(src, dst, radius, width, height, srcStride, dstStride); michael@0: }