gfx/skia/trunk/src/opts/SkMorphology_opts_SSE2.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/opts/SkMorphology_opts_SSE2.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,79 @@
     1.4 +/*
     1.5 + * Copyright 2013 The Android Open Source Project
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +
    1.12 +#include "SkColorPriv.h"
    1.13 +#include "SkMorphology_opts_SSE2.h"
    1.14 +
    1.15 +#include <emmintrin.h>
    1.16 +
    1.17 +/* SSE2 version of dilateX, dilateY, erodeX, erodeY.
    1.18 + * portable versions are in src/effects/SkMorphologyImageFilter.cpp.
    1.19 + */
    1.20 +
    1.21 +enum MorphType {
    1.22 +    kDilate, kErode
    1.23 +};
    1.24 +
    1.25 +enum MorphDirection {
    1.26 +    kX, kY
    1.27 +};
    1.28 +
    1.29 +template<MorphType type, MorphDirection direction>
    1.30 +static void SkMorph_SSE2(const SkPMColor* src, SkPMColor* dst, int radius,
    1.31 +                         int width, int height, int srcStride, int dstStride)
    1.32 +{
    1.33 +    const int srcStrideX = direction == kX ? 1 : srcStride;
    1.34 +    const int dstStrideX = direction == kX ? 1 : dstStride;
    1.35 +    const int srcStrideY = direction == kX ? srcStride : 1;
    1.36 +    const int dstStrideY = direction == kX ? dstStride : 1;
    1.37 +    radius = SkMin32(radius, width - 1);
    1.38 +    const SkPMColor* upperSrc = src + radius * srcStrideX;
    1.39 +    for (int x = 0; x < width; ++x) {
    1.40 +        const SkPMColor* lp = src;
    1.41 +        const SkPMColor* up = upperSrc;
    1.42 +        SkPMColor* dptr = dst;
    1.43 +        for (int y = 0; y < height; ++y) {
    1.44 +            __m128i max = type == kDilate ? _mm_setzero_si128() : _mm_set1_epi32(0xFFFFFFFF);
    1.45 +            for (const SkPMColor* p = lp; p <= up; p += srcStrideX) {
    1.46 +                __m128i src_pixel = _mm_cvtsi32_si128(*p);
    1.47 +                max = type == kDilate ? _mm_max_epu8(src_pixel, max) : _mm_min_epu8(src_pixel, max);
    1.48 +            }
    1.49 +            *dptr = _mm_cvtsi128_si32(max);
    1.50 +            dptr += dstStrideY;
    1.51 +            lp += srcStrideY;
    1.52 +            up += srcStrideY;
    1.53 +        }
    1.54 +        if (x >= radius) src += srcStrideX;
    1.55 +        if (x + radius < width - 1) upperSrc += srcStrideX;
    1.56 +        dst += dstStrideX;
    1.57 +    }
    1.58 +}
    1.59 +
    1.60 +void SkDilateX_SSE2(const SkPMColor* src, SkPMColor* dst, int radius,
    1.61 +                    int width, int height, int srcStride, int dstStride)
    1.62 +{
    1.63 +    SkMorph_SSE2<kDilate, kX>(src, dst, radius, width, height, srcStride, dstStride);
    1.64 +}
    1.65 +
    1.66 +void SkErodeX_SSE2(const SkPMColor* src, SkPMColor* dst, int radius,
    1.67 +                   int width, int height, int srcStride, int dstStride)
    1.68 +{
    1.69 +    SkMorph_SSE2<kErode, kX>(src, dst, radius, width, height, srcStride, dstStride);
    1.70 +}
    1.71 +
    1.72 +void SkDilateY_SSE2(const SkPMColor* src, SkPMColor* dst, int radius,
    1.73 +                    int width, int height, int srcStride, int dstStride)
    1.74 +{
    1.75 +    SkMorph_SSE2<kDilate, kY>(src, dst, radius, width, height, srcStride, dstStride);
    1.76 +}
    1.77 +
    1.78 +void SkErodeY_SSE2(const SkPMColor* src, SkPMColor* dst, int radius,
    1.79 +                   int width, int height, int srcStride, int dstStride)
    1.80 +{
    1.81 +    SkMorph_SSE2<kErode, kY>(src, dst, radius, width, height, srcStride, dstStride);
    1.82 +}

mercurial