2 * Copyright (C) 2011 University of Szeged
3 * Copyright (C) 2011 Zoltan Herczeg
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef FEGaussianBlurNEON_h
28 #define FEGaussianBlurNEON_h
30 #include <wtf/Platform.h>
32 #if CPU(ARM_NEON) && COMPILER(GCC)
34 #include "FEGaussianBlur.h"
35 #include "NEONHelpers.h"
39 inline void boxBlurNEON(Uint8ClampedArray* srcPixelArray, Uint8ClampedArray* dstPixelArray,
40 unsigned dx, int dxLeft, int dxRight, int stride, int strideLine, int effectWidth, int effectHeight)
42 uint32_t* sourcePixel = reinterpret_cast<uint32_t*>(srcPixelArray->data());
43 uint32_t* destinationPixel = reinterpret_cast<uint32_t*>(dstPixelArray->data());
45 float32x4_t deltaX = vdupq_n_f32(1.0 / dx);
46 int pixelLine = strideLine / 4;
48 for (int y = 0; y < effectHeight; ++y) {
49 int line = y * pixelLine;
50 float32x4_t sum = vdupq_n_f32(0);
52 int maxKernelSize = std::min(dxRight, effectWidth);
53 for (int i = 0; i < maxKernelSize; ++i) {
54 float32x4_t sourcePixelAsFloat = loadRGBA8AsFloat(sourcePixel + line + i);
55 sum = vaddq_f32(sum, sourcePixelAsFloat);
59 for (int x = 0; x < effectWidth; ++x) {
60 int pixelOffset = line + x;
61 float32x4_t result = vmulq_f32(sum, deltaX);
62 storeFloatAsRGBA8(result, destinationPixel+pixelOffset);
64 float32x4_t sourcePixelAsFloat = loadRGBA8AsFloat(sourcePixel + pixelOffset - dxLeft);
65 sum = vsubq_f32(sum, sourcePixelAsFloat);
67 if (x + dxRight < effectWidth) {
68 float32x4_t sourcePixelAsFloat = loadRGBA8AsFloat(sourcePixel + pixelOffset + dxRight);
69 sum = vaddq_f32(sum, sourcePixelAsFloat);
75 } // namespace WebCore
77 #endif // CPU(ARM_NEON) && COMPILER(GCC)
79 #endif // FEGaussianBlurNEON_h