| 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 #include "SkMorphology_opts.h" | |
| 11 #include "SkMorphology_opts_neon.h" | |
| 12 | |
| 13 #include <arm_neon.h> | |
| 14 | |
| 15 /* neon version of dilateX, dilateY, erodeX, erodeY. | |
| 16 * portable versions are in src/effects/SkMorphologyImageFilter.cpp. | |
| 17 */ | |
| 18 | |
| 19 enum MorphType { | |
| 20 kDilate, kErode | |
| 21 }; | |
| 22 | |
| 23 enum MorphDirection { | |
| 24 kX, kY | |
| 25 }; | |
| 26 | |
| 27 template<MorphType type, MorphDirection direction> | |
| 28 static void SkMorph_neon(const SkPMColor* src, SkPMColor* dst, int radius, | |
| 29 int width, int height, int srcStride, int dstStride) | |
| 30 { | |
| 31 const int srcStrideX = direction == kX ? 1 : srcStride; | |
| 32 const int dstStrideX = direction == kX ? 1 : dstStride; | |
| 33 const int srcStrideY = direction == kX ? srcStride : 1; | |
| 34 const int dstStrideY = direction == kX ? dstStride : 1; | |
| 35 radius = SkMin32(radius, width - 1); | |
| 36 const SkPMColor* upperSrc = src + radius * srcStrideX; | |
| 37 for (int x = 0; x < width; ++x) { | |
| 38 const SkPMColor* lp = src; | |
| 39 const SkPMColor* up = upperSrc; | |
| 40 SkPMColor* dptr = dst; | |
| 41 for (int y = 0; y < height; ++y) { | |
| 42 uint8x8_t max = vdup_n_u8(type == kDilate ? 0 : 255); | |
| 43 for (const SkPMColor* p = lp; p <= up; p += srcStrideX) { | |
| 44 uint8x8_t src_pixel = vreinterpret_u8_u32(vdup_n_u32(*p)); | |
| 45 max = type == kDilate ? vmax_u8(src_pixel, max) : vmin_u8(src_pi
xel, max); | |
| 46 } | |
| 47 *dptr = vget_lane_u32(vreinterpret_u32_u8(max), 0); | |
| 48 dptr += dstStrideY; | |
| 49 lp += srcStrideY; | |
| 50 up += srcStrideY; | |
| 51 } | |
| 52 if (x >= radius) src += srcStrideX; | |
| 53 if (x + radius < width - 1) upperSrc += srcStrideX; | |
| 54 dst += dstStrideX; | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 void SkDilateX_neon(const SkPMColor* src, SkPMColor* dst, int radius, | |
| 59 int width, int height, int srcStride, int dstStride) | |
| 60 { | |
| 61 SkMorph_neon<kDilate, kX>(src, dst, radius, width, height, srcStride, dstStr
ide); | |
| 62 } | |
| 63 | |
| 64 void SkErodeX_neon(const SkPMColor* src, SkPMColor* dst, int radius, | |
| 65 int width, int height, int srcStride, int dstStride) | |
| 66 { | |
| 67 SkMorph_neon<kErode, kX>(src, dst, radius, width, height, srcStride, dstStri
de); | |
| 68 } | |
| 69 | |
| 70 void SkDilateY_neon(const SkPMColor* src, SkPMColor* dst, int radius, | |
| 71 int width, int height, int srcStride, int dstStride) | |
| 72 { | |
| 73 SkMorph_neon<kDilate, kY>(src, dst, radius, width, height, srcStride, dstStr
ide); | |
| 74 } | |
| 75 | |
| 76 void SkErodeY_neon(const SkPMColor* src, SkPMColor* dst, int radius, | |
| 77 int width, int height, int srcStride, int dstStride) | |
| 78 { | |
| 79 SkMorph_neon<kErode, kY>(src, dst, radius, width, height, srcStride, dstStri
de); | |
| 80 } | |
| OLD | NEW |