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.h" michael@0: #include "SkMorphology_opts_neon.h" michael@0: michael@0: #include michael@0: michael@0: /* neon 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_neon(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: uint8x8_t max = vdup_n_u8(type == kDilate ? 0 : 255); michael@0: for (const SkPMColor* p = lp; p <= up; p += srcStrideX) { michael@0: uint8x8_t src_pixel = vreinterpret_u8_u32(vdup_n_u32(*p)); michael@0: max = type == kDilate ? vmax_u8(src_pixel, max) : vmin_u8(src_pixel, max); michael@0: } michael@0: *dptr = vget_lane_u32(vreinterpret_u32_u8(max), 0); 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_neon(const SkPMColor* src, SkPMColor* dst, int radius, michael@0: int width, int height, int srcStride, int dstStride) michael@0: { michael@0: SkMorph_neon(src, dst, radius, width, height, srcStride, dstStride); michael@0: } michael@0: michael@0: void SkErodeX_neon(const SkPMColor* src, SkPMColor* dst, int radius, michael@0: int width, int height, int srcStride, int dstStride) michael@0: { michael@0: SkMorph_neon(src, dst, radius, width, height, srcStride, dstStride); michael@0: } michael@0: michael@0: void SkDilateY_neon(const SkPMColor* src, SkPMColor* dst, int radius, michael@0: int width, int height, int srcStride, int dstStride) michael@0: { michael@0: SkMorph_neon(src, dst, radius, width, height, srcStride, dstStride); michael@0: } michael@0: michael@0: void SkErodeY_neon(const SkPMColor* src, SkPMColor* dst, int radius, michael@0: int width, int height, int srcStride, int dstStride) michael@0: { michael@0: SkMorph_neon(src, dst, radius, width, height, srcStride, dstStride); michael@0: }