diff options
author | Mike Klein <mtklein@google.com> | 2018-10-26 10:24:26 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-10-26 15:44:49 +0000 |
commit | d99bd00b2459aea336402f5d2e1af8f11f37f400 (patch) | |
tree | 60d8175f21c12935822ca419a10597c81aa23ee2 /src/effects | |
parent | 86776076ee1a0ea8c471458aff6537b084e24950 (diff) | |
download | skqp-d99bd00b2459aea336402f5d2e1af8f11f37f400.tar.gz |
move unspecialized routines out of SkOpts
No src/opts/SkOpts_foo.cpp ever replaces these function pointers with
a specialized version, so there's no value to the indirection.
I kind of want to rewrite most of this, but I've not done that here.
It's all just the same code moved around.
Change-Id: Iecb81a64aff3e9ed18c1a3c6d2eb1a6e94e966de
Reviewed-on: https://skia-review.googlesource.com/c/165400
Auto-Submit: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
Diffstat (limited to 'src/effects')
-rw-r--r-- | src/effects/imagefilters/SkMorphologyImageFilter.cpp | 126 |
1 files changed, 121 insertions, 5 deletions
diff --git a/src/effects/imagefilters/SkMorphologyImageFilter.cpp b/src/effects/imagefilters/SkMorphologyImageFilter.cpp index 5b823f165a..9c270407b9 100644 --- a/src/effects/imagefilters/SkMorphologyImageFilter.cpp +++ b/src/effects/imagefilters/SkMorphologyImageFilter.cpp @@ -11,7 +11,6 @@ #include "SkColorData.h" #include "SkColorSpaceXformer.h" #include "SkImageFilterPriv.h" -#include "SkOpts.h" #include "SkReadBuffer.h" #include "SkRect.h" #include "SkSpecialImage.h" @@ -518,6 +517,123 @@ static sk_sp<SkSpecialImage> apply_morphology( } #endif +namespace { + enum MorphType { kDilate, kErode }; + enum class MorphDirection { kX, kY }; + +#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 + template<MorphType type, MorphDirection direction> + static void morph(const SkPMColor* src, SkPMColor* dst, + int radius, int width, int height, int srcStride, int dstStride) { + const int srcStrideX = direction == MorphDirection::kX ? 1 : srcStride; + const int dstStrideX = direction == MorphDirection::kX ? 1 : dstStride; + const int srcStrideY = direction == MorphDirection::kX ? srcStride : 1; + const int dstStrideY = direction == MorphDirection::kX ? dstStride : 1; + radius = SkMin32(radius, width - 1); + const SkPMColor* upperSrc = src + radius * srcStrideX; + 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 extreme = (type == kDilate) ? _mm_setzero_si128() + : _mm_set1_epi32(0xFFFFFFFF); + for (const SkPMColor* p = lp; p <= up; p += srcStrideX) { + __m128i src_pixel = _mm_cvtsi32_si128(*p); + extreme = (type == kDilate) ? _mm_max_epu8(src_pixel, extreme) + : _mm_min_epu8(src_pixel, extreme); + } + *dptr = _mm_cvtsi128_si32(extreme); + dptr += dstStrideY; + lp += srcStrideY; + up += srcStrideY; + } + if (x >= radius) { src += srcStrideX; } + if (x + radius < width - 1) { upperSrc += srcStrideX; } + dst += dstStrideX; + } + } + +#elif defined(SK_ARM_HAS_NEON) + template<MorphType type, MorphDirection direction> + static void morph(const SkPMColor* src, SkPMColor* dst, + int radius, int width, int height, int srcStride, int dstStride) { + const int srcStrideX = direction == MorphDirection::kX ? 1 : srcStride; + const int dstStrideX = direction == MorphDirection::kX ? 1 : dstStride; + const int srcStrideY = direction == MorphDirection::kX ? srcStride : 1; + const int dstStrideY = direction == MorphDirection::kX ? dstStride : 1; + radius = SkMin32(radius, width - 1); + const SkPMColor* upperSrc = src + radius * srcStrideX; + 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) { + uint8x8_t extreme = vdup_n_u8(type == kDilate ? 0 : 255); + for (const SkPMColor* p = lp; p <= up; p += srcStrideX) { + uint8x8_t src_pixel = vreinterpret_u8_u32(vdup_n_u32(*p)); + extreme = (type == kDilate) ? vmax_u8(src_pixel, extreme) + : vmin_u8(src_pixel, extreme); + } + *dptr = vget_lane_u32(vreinterpret_u32_u8(extreme), 0); + dptr += dstStrideY; + lp += srcStrideY; + up += srcStrideY; + } + if (x >= radius) src += srcStrideX; + if (x + radius < width - 1) upperSrc += srcStrideX; + dst += dstStrideX; + } + } + +#else + template<MorphType type, MorphDirection direction> + static void morph(const SkPMColor* src, SkPMColor* dst, + int radius, int width, int height, int srcStride, int dstStride) { + const int srcStrideX = direction == MorphDirection::kX ? 1 : srcStride; + const int dstStrideX = direction == MorphDirection::kX ? 1 : dstStride; + const int srcStrideY = direction == MorphDirection::kX ? srcStride : 1; + const int dstStrideY = direction == MorphDirection::kX ? dstStride : 1; + radius = SkMin32(radius, width - 1); + const SkPMColor* upperSrc = src + radius * srcStrideX; + 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) { + // If we're maxing (dilate), start from 0; if minning (erode), start from 255. + const int start = (type == kDilate) ? 0 : 255; + int B = start, G = start, R = start, A = start; + for (const SkPMColor* p = lp; p <= up; p += srcStrideX) { + int b = SkGetPackedB32(*p), + g = SkGetPackedG32(*p), + r = SkGetPackedR32(*p), + a = SkGetPackedA32(*p); + if (type == kDilate) { + B = SkTMax(b, B); + G = SkTMax(g, G); + R = SkTMax(r, R); + A = SkTMax(a, A); + } else { + B = SkTMin(b, B); + G = SkTMin(g, G); + R = SkTMin(r, R); + A = SkTMin(a, A); + } + } + *dptr = SkPackARGB32(A, R, G, B); + dptr += dstStrideY; + lp += srcStrideY; + up += srcStrideY; + } + if (x >= radius) { src += srcStrideX; } + if (x + radius < width - 1) { upperSrc += srcStrideX; } + dst += dstStrideX; + } + } +#endif +} // namespace + sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* source, const Context& ctx, SkIPoint* offset) const { @@ -596,11 +712,11 @@ sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* sou SkMorphologyImageFilter::Proc procX, procY; if (kDilate_Op == this->op()) { - procX = SkOpts::dilate_x; - procY = SkOpts::dilate_y; + procX = &morph<kDilate, MorphDirection::kX>; + procY = &morph<kDilate, MorphDirection::kY>; } else { - procX = SkOpts::erode_x; - procY = SkOpts::erode_y; + procX = &morph<kErode, MorphDirection::kX>; + procY = &morph<kErode, MorphDirection::kY>; } if (width > 0 && height > 0) { |