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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright 2013 The Android Open Source Project
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8
michael@0 9 #include "SkColorPriv.h"
michael@0 10 #include "SkMorphology_opts_SSE2.h"
michael@0 11
michael@0 12 #include <emmintrin.h>
michael@0 13
michael@0 14 /* SSE2 version of dilateX, dilateY, erodeX, erodeY.
michael@0 15 * portable versions are in src/effects/SkMorphologyImageFilter.cpp.
michael@0 16 */
michael@0 17
michael@0 18 enum MorphType {
michael@0 19 kDilate, kErode
michael@0 20 };
michael@0 21
michael@0 22 enum MorphDirection {
michael@0 23 kX, kY
michael@0 24 };
michael@0 25
michael@0 26 template<MorphType type, MorphDirection direction>
michael@0 27 static void SkMorph_SSE2(const SkPMColor* src, SkPMColor* dst, int radius,
michael@0 28 int width, int height, int srcStride, int dstStride)
michael@0 29 {
michael@0 30 const int srcStrideX = direction == kX ? 1 : srcStride;
michael@0 31 const int dstStrideX = direction == kX ? 1 : dstStride;
michael@0 32 const int srcStrideY = direction == kX ? srcStride : 1;
michael@0 33 const int dstStrideY = direction == kX ? dstStride : 1;
michael@0 34 radius = SkMin32(radius, width - 1);
michael@0 35 const SkPMColor* upperSrc = src + radius * srcStrideX;
michael@0 36 for (int x = 0; x < width; ++x) {
michael@0 37 const SkPMColor* lp = src;
michael@0 38 const SkPMColor* up = upperSrc;
michael@0 39 SkPMColor* dptr = dst;
michael@0 40 for (int y = 0; y < height; ++y) {
michael@0 41 __m128i max = type == kDilate ? _mm_setzero_si128() : _mm_set1_epi32(0xFFFFFFFF);
michael@0 42 for (const SkPMColor* p = lp; p <= up; p += srcStrideX) {
michael@0 43 __m128i src_pixel = _mm_cvtsi32_si128(*p);
michael@0 44 max = type == kDilate ? _mm_max_epu8(src_pixel, max) : _mm_min_epu8(src_pixel, max);
michael@0 45 }
michael@0 46 *dptr = _mm_cvtsi128_si32(max);
michael@0 47 dptr += dstStrideY;
michael@0 48 lp += srcStrideY;
michael@0 49 up += srcStrideY;
michael@0 50 }
michael@0 51 if (x >= radius) src += srcStrideX;
michael@0 52 if (x + radius < width - 1) upperSrc += srcStrideX;
michael@0 53 dst += dstStrideX;
michael@0 54 }
michael@0 55 }
michael@0 56
michael@0 57 void SkDilateX_SSE2(const SkPMColor* src, SkPMColor* dst, int radius,
michael@0 58 int width, int height, int srcStride, int dstStride)
michael@0 59 {
michael@0 60 SkMorph_SSE2<kDilate, kX>(src, dst, radius, width, height, srcStride, dstStride);
michael@0 61 }
michael@0 62
michael@0 63 void SkErodeX_SSE2(const SkPMColor* src, SkPMColor* dst, int radius,
michael@0 64 int width, int height, int srcStride, int dstStride)
michael@0 65 {
michael@0 66 SkMorph_SSE2<kErode, kX>(src, dst, radius, width, height, srcStride, dstStride);
michael@0 67 }
michael@0 68
michael@0 69 void SkDilateY_SSE2(const SkPMColor* src, SkPMColor* dst, int radius,
michael@0 70 int width, int height, int srcStride, int dstStride)
michael@0 71 {
michael@0 72 SkMorph_SSE2<kDilate, kY>(src, dst, radius, width, height, srcStride, dstStride);
michael@0 73 }
michael@0 74
michael@0 75 void SkErodeY_SSE2(const SkPMColor* src, SkPMColor* dst, int radius,
michael@0 76 int width, int height, int srcStride, int dstStride)
michael@0 77 {
michael@0 78 SkMorph_SSE2<kErode, kY>(src, dst, radius, width, height, srcStride, dstStride);
michael@0 79 }

mercurial