gfx/skia/trunk/src/opts/SkMorphology_opts_neon.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_neon.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,80 @@
     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.h"
    1.14 +#include "SkMorphology_opts_neon.h"
    1.15 +
    1.16 +#include <arm_neon.h>
    1.17 +
    1.18 +/* neon version of dilateX, dilateY, erodeX, erodeY.
    1.19 + * portable versions are in src/effects/SkMorphologyImageFilter.cpp.
    1.20 + */
    1.21 +
    1.22 +enum MorphType {
    1.23 +    kDilate, kErode
    1.24 +};
    1.25 +
    1.26 +enum MorphDirection {
    1.27 +    kX, kY
    1.28 +};
    1.29 +
    1.30 +template<MorphType type, MorphDirection direction>
    1.31 +static void SkMorph_neon(const SkPMColor* src, SkPMColor* dst, int radius,
    1.32 +                         int width, int height, int srcStride, int dstStride)
    1.33 +{
    1.34 +    const int srcStrideX = direction == kX ? 1 : srcStride;
    1.35 +    const int dstStrideX = direction == kX ? 1 : dstStride;
    1.36 +    const int srcStrideY = direction == kX ? srcStride : 1;
    1.37 +    const int dstStrideY = direction == kX ? dstStride : 1;
    1.38 +    radius = SkMin32(radius, width - 1);
    1.39 +    const SkPMColor* upperSrc = src + radius * srcStrideX;
    1.40 +    for (int x = 0; x < width; ++x) {
    1.41 +        const SkPMColor* lp = src;
    1.42 +        const SkPMColor* up = upperSrc;
    1.43 +        SkPMColor* dptr = dst;
    1.44 +        for (int y = 0; y < height; ++y) {
    1.45 +            uint8x8_t max = vdup_n_u8(type == kDilate ? 0 : 255);
    1.46 +            for (const SkPMColor* p = lp; p <= up; p += srcStrideX) {
    1.47 +                uint8x8_t src_pixel = vreinterpret_u8_u32(vdup_n_u32(*p));
    1.48 +                max = type == kDilate ? vmax_u8(src_pixel, max) : vmin_u8(src_pixel, max);
    1.49 +            }
    1.50 +            *dptr = vget_lane_u32(vreinterpret_u32_u8(max), 0);
    1.51 +            dptr += dstStrideY;
    1.52 +            lp += srcStrideY;
    1.53 +            up += srcStrideY;
    1.54 +        }
    1.55 +        if (x >= radius) src += srcStrideX;
    1.56 +        if (x + radius < width - 1) upperSrc += srcStrideX;
    1.57 +        dst += dstStrideX;
    1.58 +    }
    1.59 +}
    1.60 +
    1.61 +void SkDilateX_neon(const SkPMColor* src, SkPMColor* dst, int radius,
    1.62 +                    int width, int height, int srcStride, int dstStride)
    1.63 +{
    1.64 +    SkMorph_neon<kDilate, kX>(src, dst, radius, width, height, srcStride, dstStride);
    1.65 +}
    1.66 +
    1.67 +void SkErodeX_neon(const SkPMColor* src, SkPMColor* dst, int radius,
    1.68 +                   int width, int height, int srcStride, int dstStride)
    1.69 +{
    1.70 +    SkMorph_neon<kErode, kX>(src, dst, radius, width, height, srcStride, dstStride);
    1.71 +}
    1.72 +
    1.73 +void SkDilateY_neon(const SkPMColor* src, SkPMColor* dst, int radius,
    1.74 +                    int width, int height, int srcStride, int dstStride)
    1.75 +{
    1.76 +    SkMorph_neon<kDilate, kY>(src, dst, radius, width, height, srcStride, dstStride);
    1.77 +}
    1.78 +
    1.79 +void SkErodeY_neon(const SkPMColor* src, SkPMColor* dst, int radius,
    1.80 +                   int width, int height, int srcStride, int dstStride)
    1.81 +{
    1.82 +    SkMorph_neon<kErode, kY>(src, dst, radius, width, height, srcStride, dstStride);
    1.83 +}

mercurial