OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2013 The Android Open Source Project | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 | |
9 #include "SkBitmap.h" | |
10 #include "SkColorPriv.h" | |
11 #include "SkBlurImage_opts.h" | |
12 #include "SkRect.h" | |
13 | |
14 #include <arm_neon.h> | |
15 | |
16 namespace { | |
17 | |
18 enum BlurDirection { | |
19 kX, kY | |
20 }; | |
21 | |
22 /** | |
23 * Helper function to spread the components of a 32-bit integer into the | |
24 * lower 8 bits of each 32-bit element of an SSE register. | |
25 */ | |
26 | |
27 inline uint32x4_t expand(uint32_t a) { | |
28 uint8x8_t v8 = vreinterpret_u8_u32(vdup_n_u32(a)); | |
mtklein
2013/12/03 20:22:13
Do you mind adding in comment crutches for me agai
Stephen White
2013/12/04 15:18:41
Done. I put in some brackets to indicate the lengt
| |
29 const uint16x4_t v16 = vget_low_u16(vmovl_u8(v8)); | |
30 return vmovl_u16(v16); | |
31 } | |
32 | |
33 template<BlurDirection srcDirection, BlurDirection dstDirection> | |
34 void SkBoxBlur_SSE2(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker nelSize, | |
mtklein
2013/12/03 20:22:13
Given that we're clearly copying and pasting here
Stephen White
2013/12/04 15:18:41
Whoops, busted. :) Fixed.
mtklein
2013/12/04 16:52:23
SGTM
| |
35 int leftOffset, int rightOffset, int width, int height) | |
36 { | |
37 const int rightBorder = SkMin32(rightOffset + 1, width); | |
38 const int srcStrideX = srcDirection == kX ? 1 : srcStride; | |
39 const int dstStrideX = dstDirection == kX ? 1 : height; | |
40 const int srcStrideY = srcDirection == kX ? srcStride : 1; | |
41 const int dstStrideY = dstDirection == kX ? width : 1; | |
42 const uint32x4_t scale = vdupq_n_u32((1 << 24) / kernelSize); | |
43 const uint32x4_t half = vdupq_n_u32(1 << 23); | |
44 for (int y = 0; y < height; ++y) { | |
45 uint32x4_t sum = vdupq_n_u32(0); | |
46 const SkPMColor* p = src; | |
47 for (int i = 0; i < rightBorder; ++i) { | |
48 sum = vaddq_u32(sum, expand(*p)); | |
49 p += srcStrideX; | |
50 } | |
51 | |
52 const SkPMColor* sptr = src; | |
53 SkColor* dptr = dst; | |
54 for (int x = 0; x < width; ++x) { | |
55 // half+sumA*scale, half+sumR*scale, half+sumG*scale, half+sumB*scal e | |
56 uint32x4_t result = vmlaq_u32(half, sum, scale); | |
57 | |
58 // Shift down to lower 8 bits of each element. | |
59 result = vshrq_n_u32(result, 24); | |
60 | |
61 // A R G B | |
62 uint16x4_t result16 = vqmovn_u32(result); | |
63 | |
64 // A R G B A R G B | |
65 uint8x8_t result8 = vqmovn_u16(vcombine_u16(result16, result16)); | |
66 | |
67 vst1_lane_u32(dptr, vreinterpret_u32_u8(result8), 0); | |
68 if (x >= leftOffset) { | |
69 const SkPMColor* l = sptr - leftOffset * srcStrideX; | |
mtklein
2013/12/03 20:22:13
I've only just noticed, we used SkColor here in th
Stephen White
2013/12/04 15:18:41
Thanks, done.
| |
70 sum = vsubq_u32(sum, expand(*l)); | |
71 } | |
72 if (x + rightOffset + 1 < width) { | |
73 const SkPMColor* r = sptr + (rightOffset + 1) * srcStrideX; | |
74 sum = vaddq_u32(sum, expand(*r)); | |
75 } | |
76 sptr += srcStrideX; | |
77 if (srcDirection == kY) { | |
78 SK_PREFETCH(sptr + (rightOffset + 1) * srcStrideX); | |
79 } | |
80 dptr += dstStrideX; | |
81 } | |
82 src += srcStrideY; | |
83 dst += dstStrideY; | |
84 } | |
85 } | |
86 | |
87 } // namespace | |
88 | |
89 bool SkBoxBlurGetPlatformProcs(SkBoxBlurProc* boxBlurX, | |
90 SkBoxBlurProc* boxBlurY, | |
91 SkBoxBlurProc* boxBlurXY, | |
92 SkBoxBlurProc* boxBlurYX) { | |
93 *boxBlurX = SkBoxBlur_SSE2<kX, kX>; | |
mtklein
2013/12/03 20:22:13
_SSE2 here too
Stephen White
2013/12/04 15:18:41
Fixed.
| |
94 *boxBlurY = SkBoxBlur_SSE2<kY, kY>; | |
95 *boxBlurXY = SkBoxBlur_SSE2<kX, kY>; | |
96 *boxBlurYX = SkBoxBlur_SSE2<kY, kX>; | |
97 return true; | |
98 } | |
OLD | NEW |