Remove previous blur image implementation. Try 2
The last version had a problem with the no simd compilation. TBR=mtklein@google.com Change-Id: I139388cf3bf1b55cb4a49133a98be129fd9711c6 Reviewed-on: https://skia-review.googlesource.com/80983 Reviewed-by: Herb Derby <herb@google.com> Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
parent
c382384848
commit
d8e2b13ad4
@ -65,11 +65,6 @@ private:
|
||||
SkIRect inputBounds, SkIRect dstBounds, const OutputProperties& outProps) const;
|
||||
#endif
|
||||
|
||||
sk_sp<SkSpecialImage> cpuFilter(
|
||||
SkSpecialImage *source,
|
||||
SkVector sigma, const sk_sp<SkSpecialImage> &input,
|
||||
SkIRect inputBounds, SkIRect dstBounds) const;
|
||||
|
||||
SkSize fSigma;
|
||||
SkBlurImageFilter::TileMode fTileMode;
|
||||
};
|
||||
@ -158,23 +153,6 @@ static GrTextureDomain::Mode to_texture_domain_mode(SkBlurImageFilter::TileMode
|
||||
}
|
||||
#endif
|
||||
|
||||
static void get_box3_params(SkScalar s, int *kernelSize, int* kernelSize3, int *lowOffset,
|
||||
int *highOffset) {
|
||||
float pi = SkScalarToFloat(SK_ScalarPI);
|
||||
int d = static_cast<int>(floorf(SkScalarToFloat(s) * 3.0f * sqrtf(2.0f * pi) / 4.0f + 0.5f));
|
||||
*kernelSize = d;
|
||||
if (d % 2 == 1) {
|
||||
*lowOffset = *highOffset = (d - 1) / 2;
|
||||
*kernelSize3 = d;
|
||||
} else {
|
||||
*highOffset = d / 2;
|
||||
*lowOffset = *highOffset - 1;
|
||||
*kernelSize3 = d + 1;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(SK_SUPPORT_LEGACY_BLUR_IMAGE)
|
||||
|
||||
// This is defined by the SVG spec:
|
||||
// https://drafts.fxtf.org/filter-effects/#feGaussianBlurElement
|
||||
static int calculate_window(double sigma) {
|
||||
@ -415,9 +393,10 @@ static void blur_one_direction(Sk4u* buffer, int window,
|
||||
}
|
||||
}
|
||||
|
||||
static sk_sp<SkSpecialImage> combined_pass_blur(
|
||||
// TODO: Implement CPU backend for different fTileMode.
|
||||
static sk_sp<SkSpecialImage> cpu_blur(
|
||||
SkVector sigma,
|
||||
SkSpecialImage* source, const sk_sp<SkSpecialImage>& input,
|
||||
SkSpecialImage *source, const sk_sp<SkSpecialImage> &input,
|
||||
SkIRect srcBounds, SkIRect dstBounds) {
|
||||
SkBitmap inputBM;
|
||||
|
||||
@ -533,7 +512,6 @@ static sk_sp<SkSpecialImage> combined_pass_blur(
|
||||
dstBounds.height()),
|
||||
dst, &source->props());
|
||||
}
|
||||
#endif
|
||||
|
||||
sk_sp<SkSpecialImage> SkBlurImageFilterImpl::onFilterImage(SkSpecialImage* source,
|
||||
const Context& ctx,
|
||||
@ -585,11 +563,7 @@ sk_sp<SkSpecialImage> SkBlurImageFilterImpl::onFilterImage(SkSpecialImage* sourc
|
||||
if (sigma.x() < kZeroWindow && sigma.y() < kZeroWindow) {
|
||||
result = input->makeSubset(inputBounds);
|
||||
} else {
|
||||
#if defined(SK_SUPPORT_LEGACY_BLUR_IMAGE)
|
||||
result = this->cpuFilter(source, sigma, input, inputBounds, dstBounds);
|
||||
#else
|
||||
result = combined_pass_blur(sigma, source, input, inputBounds, dstBounds);
|
||||
#endif
|
||||
result = cpu_blur(sigma, source, input, inputBounds, dstBounds);
|
||||
}
|
||||
}
|
||||
|
||||
@ -659,87 +633,6 @@ sk_sp<SkSpecialImage> SkBlurImageFilterImpl::gpuFilter(
|
||||
}
|
||||
#endif
|
||||
|
||||
// TODO: Implement CPU backend for different fTileMode.
|
||||
sk_sp<SkSpecialImage> SkBlurImageFilterImpl::cpuFilter(
|
||||
SkSpecialImage *source,
|
||||
SkVector sigma, const sk_sp<SkSpecialImage> &input,
|
||||
SkIRect inputBounds, SkIRect dstBounds) const
|
||||
{
|
||||
int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX;
|
||||
int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY;
|
||||
get_box3_params(sigma.x(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &highOffsetX);
|
||||
get_box3_params(sigma.y(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &highOffsetY);
|
||||
|
||||
SkBitmap inputBM;
|
||||
|
||||
if (!input->getROPixels(&inputBM) && inputBM.colorType() != kN32_SkColorType) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkImageInfo info = SkImageInfo::Make(dstBounds.width(), dstBounds.height(),
|
||||
inputBM.colorType(), inputBM.alphaType());
|
||||
|
||||
SkBitmap tmp, dst;
|
||||
if (!tmp.tryAllocPixels(info) || !dst.tryAllocPixels(info)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Get ready to blur.
|
||||
const SkPMColor* s = inputBM.getAddr32(inputBounds.x(), inputBounds.y());
|
||||
SkPMColor* t = tmp.getAddr32(0, 0);
|
||||
SkPMColor* d = dst.getAddr32(0, 0);
|
||||
|
||||
// Shift everything from being relative to the orignal input bounds to the destination bounds.
|
||||
inputBounds.offset(-dstBounds.x(), -dstBounds.y());
|
||||
dstBounds.offset(-dstBounds.x(), -dstBounds.y());
|
||||
|
||||
int w = dstBounds.width(),
|
||||
h = dstBounds.height(),
|
||||
sw = inputBM.rowBytesAsPixels();
|
||||
|
||||
SkIRect inputBoundsT = SkIRect::MakeLTRB(inputBounds.top(), inputBounds.left(),
|
||||
inputBounds.bottom(), inputBounds.right());
|
||||
SkIRect dstBoundsT = SkIRect::MakeWH(dstBounds.height(), dstBounds.width());
|
||||
|
||||
/**
|
||||
*
|
||||
* In order to make memory accesses cache-friendly, we reorder the passes to
|
||||
* use contiguous memory reads wherever possible.
|
||||
*
|
||||
* For example, the 6 passes of the X-and-Y blur case are rewritten as
|
||||
* follows. Instead of 3 passes in X and 3 passes in Y, we perform
|
||||
* 2 passes in X, 1 pass in X transposed to Y on write, 2 passes in X,
|
||||
* then 1 pass in X transposed to Y on write.
|
||||
*
|
||||
* +----+ +----+ +----+ +---+ +---+ +---+ +----+
|
||||
* + AB + ----> | AB | ----> | AB | -----> | A | ----> | A | ----> | A | -----> | AB |
|
||||
* +----+ blurX +----+ blurX +----+ blurXY | B | blurX | B | blurX | B | blurXY +----+
|
||||
* +---+ +---+ +---+
|
||||
*
|
||||
* In this way, two of the y-blurs become x-blurs applied to transposed
|
||||
* images, and all memory reads are contiguous.
|
||||
*/
|
||||
if (kernelSizeX > 0 && kernelSizeY > 0) {
|
||||
SkOpts::box_blur_xx(s, sw, inputBounds, t, kernelSizeX, lowOffsetX, highOffsetX, w, h);
|
||||
SkOpts::box_blur_xx(t, w, dstBounds, d, kernelSizeX, highOffsetX, lowOffsetX, w, h);
|
||||
SkOpts::box_blur_xy(d, w, dstBounds, t, kernelSizeX3, highOffsetX, highOffsetX, w, h);
|
||||
SkOpts::box_blur_xx(t, h, dstBoundsT, d, kernelSizeY, lowOffsetY, highOffsetY, h, w);
|
||||
SkOpts::box_blur_xx(d, h, dstBoundsT, t, kernelSizeY, highOffsetY, lowOffsetY, h, w);
|
||||
SkOpts::box_blur_xy(t, h, dstBoundsT, d, kernelSizeY3, highOffsetY, highOffsetY, h, w);
|
||||
} else if (kernelSizeX > 0) {
|
||||
SkOpts::box_blur_xx(s, sw, inputBounds, d, kernelSizeX, lowOffsetX, highOffsetX, w, h);
|
||||
SkOpts::box_blur_xx(d, w, dstBounds, t, kernelSizeX, highOffsetX, lowOffsetX, w, h);
|
||||
SkOpts::box_blur_xx(t, w, dstBounds, d, kernelSizeX3, highOffsetX, highOffsetX, w, h);
|
||||
} else if (kernelSizeY > 0) {
|
||||
SkOpts::box_blur_yx(s, sw, inputBoundsT, d, kernelSizeY, lowOffsetY, highOffsetY, h, w);
|
||||
SkOpts::box_blur_xx(d, h, dstBoundsT, t, kernelSizeY, highOffsetY, lowOffsetY, h, w);
|
||||
SkOpts::box_blur_xy(t, h, dstBoundsT, d, kernelSizeY3, highOffsetY, highOffsetY, h, w);
|
||||
}
|
||||
|
||||
return SkSpecialImage::MakeFromRaster(SkIRect::MakeSize(dstBounds.size()),
|
||||
dst, &source->props());
|
||||
}
|
||||
|
||||
sk_sp<SkImageFilter> SkBlurImageFilterImpl::onMakeColorSpace(SkColorSpaceXformer* xformer)
|
||||
const {
|
||||
SkASSERT(1 == this->countInputs());
|
||||
|
@ -38,7 +38,6 @@
|
||||
|
||||
#include "SkBlitMask_opts.h"
|
||||
#include "SkBlitRow_opts.h"
|
||||
#include "SkBlurImageFilter_opts.h"
|
||||
#include "SkChecksum_opts.h"
|
||||
#include "SkMorphologyImageFilter_opts.h"
|
||||
#include "SkSwizzler_opts.h"
|
||||
@ -53,10 +52,6 @@ namespace SkOpts {
|
||||
#define DEFINE_DEFAULT(name) decltype(name) name = SK_OPTS_NS::name
|
||||
DEFINE_DEFAULT(create_xfermode);
|
||||
|
||||
DEFINE_DEFAULT(box_blur_xx);
|
||||
DEFINE_DEFAULT(box_blur_xy);
|
||||
DEFINE_DEFAULT(box_blur_yx);
|
||||
|
||||
DEFINE_DEFAULT(dilate_x);
|
||||
DEFINE_DEFAULT(dilate_y);
|
||||
DEFINE_DEFAULT( erode_x);
|
||||
|
@ -25,9 +25,6 @@ namespace SkOpts {
|
||||
// May return nullptr if we haven't specialized the given Mode.
|
||||
extern SkXfermode* (*create_xfermode)(SkBlendMode);
|
||||
|
||||
typedef void (*BoxBlur)(const SkPMColor*, int, const SkIRect& srcBounds, SkPMColor*, int, int, int, int, int);
|
||||
extern BoxBlur box_blur_xx, box_blur_xy, box_blur_yx;
|
||||
|
||||
typedef void (*Morph)(const SkPMColor*, SkPMColor*, int, int, int, int, int);
|
||||
extern Morph dilate_x, dilate_y, erode_x, erode_y;
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
|
||||
#include "SkColor_opts_SSE2.h"
|
||||
#include <immintrin.h>
|
||||
#endif
|
||||
|
||||
namespace SK_OPTS_NS {
|
||||
|
@ -1,322 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkBlurImageFilter_opts_DEFINED
|
||||
#define SkBlurImageFilter_opts_DEFINED
|
||||
|
||||
#include "SkColorData.h"
|
||||
#include "SkRect.h"
|
||||
|
||||
#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
|
||||
#include <immintrin.h>
|
||||
#endif
|
||||
|
||||
namespace SK_OPTS_NS {
|
||||
|
||||
enum class BlurDirection { kX, kY };
|
||||
|
||||
#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
|
||||
#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE41
|
||||
// RGBA -> R000 G000 B000 A000
|
||||
static inline __m128i expand(SkPMColor p) {
|
||||
return _mm_cvtepu8_epi32(_mm_cvtsi32_si128(p));
|
||||
};
|
||||
// 000R 000G 000B 000A -> RGBA
|
||||
static inline SkPMColor repack(__m128i p) {
|
||||
const char _ = ~0; // Don't care what ends up in these bytes. This zeros them.
|
||||
p = _mm_shuffle_epi8(p, _mm_setr_epi8(3,7,11,15, _,_,_,_, _,_,_,_, _,_,_,_));
|
||||
return _mm_cvtsi128_si32(p);
|
||||
};
|
||||
#define mullo_epi32 _mm_mullo_epi32
|
||||
|
||||
#else
|
||||
static inline __m128i expand(int p) {
|
||||
auto result = _mm_cvtsi32_si128(p);
|
||||
result = _mm_unpacklo_epi8 (result, _mm_setzero_si128());
|
||||
result = _mm_unpacklo_epi16(result, _mm_setzero_si128());
|
||||
return result;
|
||||
};
|
||||
static inline SkPMColor repack(__m128i p) {
|
||||
p = _mm_srli_epi32(p, 24); // R000 G000 B000 A000
|
||||
p = _mm_packs_epi32(p, p); // R0G0 B0A0 xxxx xxxx
|
||||
p = _mm_packus_epi16(p, p); // RGBA xxxx xxxx xxxx
|
||||
return _mm_cvtsi128_si32(p);
|
||||
};
|
||||
|
||||
// _mm_mullo_epi32 is not available, so use the standard trick to emulate it.
|
||||
static inline __m128i mullo_epi32(__m128i a, __m128i b) {
|
||||
__m128i p02 = _mm_mul_epu32(a, b),
|
||||
p13 = _mm_mul_epu32(_mm_srli_si128(a, 4),
|
||||
_mm_srli_si128(b, 4));
|
||||
return _mm_unpacklo_epi32(_mm_shuffle_epi32(p02, _MM_SHUFFLE(0,0,2,0)),
|
||||
_mm_shuffle_epi32(p13, _MM_SHUFFLE(0,0,2,0)));
|
||||
};
|
||||
#endif
|
||||
|
||||
#define INIT_SCALE const __m128i scale = _mm_set1_epi32((1 << 24) / kernelSize);
|
||||
#define INIT_HALF const __m128i half = _mm_set1_epi32(1 << 23);
|
||||
#define INIT_SUMS __m128i sum = _mm_setzero_si128();
|
||||
#define INCREMENT_SUMS(c) sum = _mm_add_epi32(sum, expand(c))
|
||||
#define DECREMENT_SUMS(c) sum = _mm_sub_epi32(sum, expand(c))
|
||||
#define STORE_SUMS *dptr = repack(_mm_add_epi32(mullo_epi32(sum, scale), half));
|
||||
#define DOUBLE_ROW_OPTIMIZATION /*none*/
|
||||
|
||||
#elif defined(SK_ARM_HAS_NEON)
|
||||
|
||||
// val = (sum * scale * 2 + 0x8000) >> 16
|
||||
#define STORE_SUMS_DOUBLE \
|
||||
uint16x8_t resultPixels = vreinterpretq_u16_s16(vqrdmulhq_s16( \
|
||||
vreinterpretq_s16_u16(sum), vreinterpretq_s16_u16(scale))); \
|
||||
if (dstDirection == BlurDirection::kX) { \
|
||||
uint32x2_t px2 = vreinterpret_u32_u8(vmovn_u16(resultPixels)); \
|
||||
vst1_lane_u32(dptr + 0, px2, 0); \
|
||||
vst1_lane_u32(dptr + width, px2, 1); \
|
||||
} else { \
|
||||
vst1_u8((uint8_t*)dptr, vmovn_u16(resultPixels)); \
|
||||
}
|
||||
|
||||
#define INCREMENT_SUMS_DOUBLE(p) sum = vaddw_u8(sum, load_2_pixels(p))
|
||||
#define DECREMENT_SUMS_DOUBLE(p) sum = vsubw_u8(sum, load_2_pixels(p))
|
||||
|
||||
// Fast path for kernel sizes between 2 and 127, working on two rows at a time.
|
||||
template<BlurDirection srcDirection, BlurDirection dstDirection>
|
||||
static int box_blur_double(const SkPMColor** src, int srcStride, const SkIRect& srcBounds,
|
||||
SkPMColor** dst, int kernelSize,
|
||||
int leftOffset, int rightOffset, int width, int height) {
|
||||
// Load 2 pixels from adjacent rows.
|
||||
auto load_2_pixels = [&](const SkPMColor* s) {
|
||||
if (srcDirection == BlurDirection::kX) {
|
||||
// 10% faster by adding these 2 prefetches
|
||||
SK_PREFETCH(s + 16);
|
||||
SK_PREFETCH(s + 16 + srcStride);
|
||||
auto one = vld1_lane_u32(s + 0, vdup_n_u32(0), 0),
|
||||
two = vld1_lane_u32(s + srcStride, one, 1);
|
||||
return vreinterpret_u8_u32(two);
|
||||
} else {
|
||||
return vld1_u8((uint8_t*)s);
|
||||
}
|
||||
};
|
||||
int left = srcBounds.left();
|
||||
int right = srcBounds.right();
|
||||
int top = srcBounds.top();
|
||||
int bottom = srcBounds.bottom();
|
||||
int incrementStart = SkMax32(left - rightOffset - 1, left - right);
|
||||
int incrementEnd = SkMax32(right - rightOffset - 1, 0);
|
||||
int decrementStart = SkMin32(left + leftOffset, width);
|
||||
int decrementEnd = SkMin32(right + leftOffset, width);
|
||||
const int srcStrideX = srcDirection == BlurDirection::kX ? 1 : srcStride;
|
||||
const int dstStrideX = dstDirection == BlurDirection::kX ? 1 : height;
|
||||
const int srcStrideY = srcDirection == BlurDirection::kX ? srcStride : 1;
|
||||
const int dstStrideY = dstDirection == BlurDirection::kX ? width : 1;
|
||||
const uint16x8_t scale = vdupq_n_u16((1 << 15) / kernelSize);
|
||||
|
||||
for (; bottom - top >= 2; top += 2) {
|
||||
uint16x8_t sum = vdupq_n_u16(0);
|
||||
const SkPMColor* lptr = *src;
|
||||
const SkPMColor* rptr = *src;
|
||||
SkPMColor* dptr = *dst;
|
||||
int x;
|
||||
for (x = incrementStart; x < 0; ++x) {
|
||||
INCREMENT_SUMS_DOUBLE(rptr);
|
||||
rptr += srcStrideX;
|
||||
}
|
||||
// Clear to zero when sampling to the left our domain. "sum" is zero here because we
|
||||
// initialized it above, and the preceeding loop has no effect in this case.
|
||||
for (x = 0; x < incrementStart; ++x) {
|
||||
STORE_SUMS_DOUBLE
|
||||
dptr += dstStrideX;
|
||||
}
|
||||
for (; x < decrementStart && x < incrementEnd; ++x) {
|
||||
STORE_SUMS_DOUBLE
|
||||
dptr += dstStrideX;
|
||||
INCREMENT_SUMS_DOUBLE(rptr);
|
||||
rptr += srcStrideX;
|
||||
}
|
||||
for (x = decrementStart; x < incrementEnd; ++x) {
|
||||
STORE_SUMS_DOUBLE
|
||||
dptr += dstStrideX;
|
||||
INCREMENT_SUMS_DOUBLE(rptr);
|
||||
rptr += srcStrideX;
|
||||
DECREMENT_SUMS_DOUBLE(lptr);
|
||||
lptr += srcStrideX;
|
||||
}
|
||||
for (x = incrementEnd; x < decrementStart; ++x) {
|
||||
STORE_SUMS_DOUBLE
|
||||
dptr += dstStrideX;
|
||||
}
|
||||
for (; x < decrementEnd; ++x) {
|
||||
STORE_SUMS_DOUBLE
|
||||
dptr += dstStrideX;
|
||||
DECREMENT_SUMS_DOUBLE(lptr);
|
||||
lptr += srcStrideX;
|
||||
}
|
||||
// Clear to zero when sampling to the right of our domain. "sum" is
|
||||
// zero here because we added on then subtracted off all of the pixels, leaving zero.
|
||||
for (; x < width; ++x) {
|
||||
STORE_SUMS_DOUBLE
|
||||
dptr += dstStrideX;
|
||||
}
|
||||
*src += srcStrideY * 2;
|
||||
*dst += dstStrideY * 2;
|
||||
}
|
||||
return top;
|
||||
}
|
||||
|
||||
// RGBA -> R0G0 B0A0
|
||||
static inline uint16x4_t expand(SkPMColor p) {
|
||||
return vget_low_u16(vmovl_u8(vreinterpret_u8_u32(vdup_n_u32(p))));
|
||||
};
|
||||
|
||||
#define INIT_SCALE const uint32x4_t scale = vdupq_n_u32((1 << 24) / kernelSize);
|
||||
#define INIT_HALF const uint32x4_t half = vdupq_n_u32(1 << 23);
|
||||
#define INIT_SUMS uint32x4_t sum = vdupq_n_u32(0);
|
||||
#define INCREMENT_SUMS(c) sum = vaddw_u16(sum, expand(c));
|
||||
#define DECREMENT_SUMS(c) sum = vsubw_u16(sum, expand(c));
|
||||
|
||||
#define STORE_SUMS \
|
||||
uint32x4_t result = vmlaq_u32(half, sum, scale); \
|
||||
uint16x4_t result16 = vqshrn_n_u32(result, 16); \
|
||||
uint8x8_t result8 = vqshrn_n_u16(vcombine_u16(result16, result16), 8); \
|
||||
vst1_lane_u32(dptr, vreinterpret_u32_u8(result8), 0);
|
||||
|
||||
#define DOUBLE_ROW_OPTIMIZATION \
|
||||
if (1 < kernelSize && kernelSize < 128) { \
|
||||
top = box_blur_double<srcDirection, dstDirection>(&src, srcStride, srcBounds, &dst, \
|
||||
kernelSize, \
|
||||
leftOffset, rightOffset, \
|
||||
width, height); \
|
||||
}
|
||||
|
||||
#else // Neither NEON nor >=SSE2.
|
||||
|
||||
#define INIT_SCALE uint32_t scale = (1 << 24) / kernelSize;
|
||||
#define INIT_HALF uint32_t half = 1 << 23;
|
||||
#define INIT_SUMS int sumA = 0, sumR = 0, sumG = 0, sumB = 0;
|
||||
#define INCREMENT_SUMS(c) \
|
||||
sumA += SkGetPackedA32(c); \
|
||||
sumR += SkGetPackedR32(c); \
|
||||
sumG += SkGetPackedG32(c); \
|
||||
sumB += SkGetPackedB32(c)
|
||||
#define DECREMENT_SUMS(c) \
|
||||
sumA -= SkGetPackedA32(c); \
|
||||
sumR -= SkGetPackedR32(c); \
|
||||
sumG -= SkGetPackedG32(c); \
|
||||
sumB -= SkGetPackedB32(c)
|
||||
#define STORE_SUMS \
|
||||
*dptr = SkPackARGB32((sumA * scale + half) >> 24, \
|
||||
(sumR * scale + half) >> 24, \
|
||||
(sumG * scale + half) >> 24, \
|
||||
(sumB * scale + half) >> 24);
|
||||
#define DOUBLE_ROW_OPTIMIZATION
|
||||
|
||||
#endif
|
||||
|
||||
template<BlurDirection srcDirection, BlurDirection dstDirection>
|
||||
/*not static*/ inline
|
||||
void box_blur(const SkPMColor* src, int srcStride, const SkIRect& srcBounds, SkPMColor* dst,
|
||||
int kernelSize, int leftOffset, int rightOffset, int width, int height) {
|
||||
int left = srcBounds.left();
|
||||
int right = srcBounds.right();
|
||||
int top = srcBounds.top();
|
||||
int bottom = srcBounds.bottom();
|
||||
int incrementStart = SkMax32(left - rightOffset - 1, left - right);
|
||||
int incrementEnd = SkMax32(right - rightOffset - 1, 0);
|
||||
int decrementStart = SkMin32(left + leftOffset, width);
|
||||
int decrementEnd = SkMin32(right + leftOffset, width);
|
||||
int srcStrideX = srcDirection == BlurDirection::kX ? 1 : srcStride;
|
||||
int dstStrideX = dstDirection == BlurDirection::kX ? 1 : height;
|
||||
int srcStrideY = srcDirection == BlurDirection::kX ? srcStride : 1;
|
||||
int dstStrideY = dstDirection == BlurDirection::kX ? width : 1;
|
||||
INIT_SCALE
|
||||
INIT_HALF
|
||||
|
||||
// Clear to zero when sampling above our domain.
|
||||
for (int y = 0; y < top; y++) {
|
||||
SkColor* dptr = dst;
|
||||
for (int x = 0; x < width; ++x) {
|
||||
*dptr = 0;
|
||||
dptr += dstStrideX;
|
||||
}
|
||||
dst += dstStrideY;
|
||||
}
|
||||
|
||||
DOUBLE_ROW_OPTIMIZATION
|
||||
|
||||
for (int y = top; y < bottom; ++y) {
|
||||
INIT_SUMS
|
||||
const SkPMColor* lptr = src;
|
||||
const SkPMColor* rptr = src;
|
||||
SkColor* dptr = dst;
|
||||
int x;
|
||||
for (x = incrementStart; x < 0; ++x) {
|
||||
INCREMENT_SUMS(*rptr);
|
||||
rptr += srcStrideX;
|
||||
if (srcDirection == BlurDirection::kY) {
|
||||
SK_PREFETCH(rptr);
|
||||
}
|
||||
}
|
||||
// Clear to zero when sampling to the left of our domain.
|
||||
for (x = 0; x < incrementStart; ++x) {
|
||||
*dptr = 0;
|
||||
dptr += dstStrideX;
|
||||
}
|
||||
for (; x < decrementStart && x < incrementEnd; ++x) {
|
||||
STORE_SUMS
|
||||
dptr += dstStrideX;
|
||||
INCREMENT_SUMS(*rptr);
|
||||
rptr += srcStrideX;
|
||||
if (srcDirection == BlurDirection::kY) {
|
||||
SK_PREFETCH(rptr);
|
||||
}
|
||||
}
|
||||
for (x = decrementStart; x < incrementEnd; ++x) {
|
||||
STORE_SUMS
|
||||
dptr += dstStrideX;
|
||||
INCREMENT_SUMS(*rptr);
|
||||
rptr += srcStrideX;
|
||||
if (srcDirection == BlurDirection::kY) {
|
||||
SK_PREFETCH(rptr);
|
||||
}
|
||||
DECREMENT_SUMS(*lptr);
|
||||
lptr += srcStrideX;
|
||||
}
|
||||
for (x = incrementEnd; x < decrementStart; ++x) {
|
||||
STORE_SUMS
|
||||
dptr += dstStrideX;
|
||||
}
|
||||
for (; x < decrementEnd; ++x) {
|
||||
STORE_SUMS
|
||||
dptr += dstStrideX;
|
||||
DECREMENT_SUMS(*lptr);
|
||||
lptr += srcStrideX;
|
||||
}
|
||||
// Clear to zero when sampling to the right of our domain.
|
||||
for (; x < width; ++x) {
|
||||
*dptr = 0;
|
||||
dptr += dstStrideX;
|
||||
}
|
||||
src += srcStrideY;
|
||||
dst += dstStrideY;
|
||||
}
|
||||
// Clear to zero when sampling below our domain.
|
||||
for (int y = bottom; y < height; ++y) {
|
||||
SkColor* dptr = dst;
|
||||
for (int x = 0; x < width; ++x) {
|
||||
*dptr = 0;
|
||||
dptr += dstStrideX;
|
||||
}
|
||||
dst += dstStrideY;
|
||||
}
|
||||
}
|
||||
|
||||
static auto box_blur_xx = &box_blur<BlurDirection::kX, BlurDirection::kX>,
|
||||
box_blur_xy = &box_blur<BlurDirection::kX, BlurDirection::kY>,
|
||||
box_blur_yx = &box_blur<BlurDirection::kY, BlurDirection::kX>;
|
||||
|
||||
} // namespace SK_OPTS_NS
|
||||
|
||||
#endif
|
@ -8,14 +8,10 @@
|
||||
#include "SkOpts.h"
|
||||
|
||||
#define SK_OPTS_NS sse41
|
||||
#include "SkBlurImageFilter_opts.h"
|
||||
#include "SkBlitRow_opts.h"
|
||||
|
||||
namespace SkOpts {
|
||||
void Init_sse41() {
|
||||
box_blur_xx = sse41::box_blur_xx;
|
||||
box_blur_xy = sse41::box_blur_xy;
|
||||
box_blur_yx = sse41::box_blur_yx;
|
||||
blit_row_s32a_opaque = sse41::blit_row_s32a_opaque;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user