Index: src/effects/SkMorphologyImageFilter.cpp |
diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp |
index df015cac7356fb2cf4d9b1c67612cf9c155fb7aa..8adeb38a2bd6a6f9da685f0197725347d9357327 100644 |
--- a/src/effects/SkMorphologyImageFilter.cpp |
+++ b/src/effects/SkMorphologyImageFilter.cpp |
@@ -10,6 +10,7 @@ |
#include "SkColorPriv.h" |
#include "SkFlattenableBuffers.h" |
#include "SkRect.h" |
+#include "SkMorphology_opts.h" |
#if SK_SUPPORT_GPU |
#include "GrContext.h" |
#include "GrTexture.h" |
@@ -38,11 +39,15 @@ void SkMorphologyImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { |
buffer.writeInt(fRadius.fHeight); |
} |
+template<bool inX> |
reed1
2013/10/30 20:14:28
very nice code sharing!
bike shed : seeing erode<
Stephen White
2013/10/30 20:48:06
Done.
|
static void erode(const SkPMColor* src, SkPMColor* dst, |
int radius, int width, int height, |
- int srcStrideX, int srcStrideY, |
- int dstStrideX, int dstStrideY) |
+ int srcStride, int dstStride) |
{ |
+ const int srcStrideX = inX ? 1 : srcStride; |
+ const int dstStrideX = inX ? 1 : dstStride; |
+ const int srcStrideY = inX ? srcStride : 1; |
+ const int dstStrideY = inX ? dstStride : 1; |
radius = SkMin32(radius, width - 1); |
const SkPMColor* upperSrc = src + radius * srcStrideX; |
for (int x = 0; x < width; ++x) { |
@@ -74,23 +79,35 @@ static void erode(const SkPMColor* src, SkPMColor* dst, |
static void erodeX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRect& bounds) |
{ |
- erode(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), |
- radiusX, bounds.width(), bounds.height(), |
- 1, src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels()); |
+ SkMorphologyProc erodeXProc = SkMorphologyGetPlatformProc(SkMorphologyErodeX_Type); |
+ if (!erodeXProc) { |
+ erodeXProc = erode<true>; |
+ } |
+ erodeXProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), |
+ radiusX, bounds.width(), bounds.height(), |
+ src.rowBytesAsPixels(), dst->rowBytesAsPixels()); |
} |
static void erodeY(const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRect& bounds) |
{ |
- erode(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), |
- radiusY, bounds.height(), bounds.width(), |
- src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels(), 1); |
+ SkMorphologyProc erodeYProc = SkMorphologyGetPlatformProc(SkMorphologyErodeY_Type); |
+ if (!erodeYProc) { |
+ erodeYProc = erode<false>; |
+ } |
+ erodeYProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), |
+ radiusY, bounds.height(), bounds.width(), |
+ src.rowBytesAsPixels(), dst->rowBytesAsPixels()); |
} |
+template<bool inX> |
static void dilate(const SkPMColor* src, SkPMColor* dst, |
int radius, int width, int height, |
- int srcStrideX, int srcStrideY, |
- int dstStrideX, int dstStrideY) |
+ int srcStride, int dstStride) |
{ |
+ const int srcStrideX = inX ? 1 : srcStride; |
+ const int dstStrideX = inX ? 1 : dstStride; |
+ const int srcStrideY = inX ? srcStride : 1; |
+ const int dstStrideY = inX ? dstStride : 1; |
radius = SkMin32(radius, width - 1); |
const SkPMColor* upperSrc = src + radius * srcStrideX; |
for (int x = 0; x < width; ++x) { |
@@ -122,16 +139,24 @@ static void dilate(const SkPMColor* src, SkPMColor* dst, |
static void dilateX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRect& bounds) |
{ |
- dilate(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), |
- radiusX, bounds.width(), bounds.height(), |
- 1, src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels()); |
+ SkMorphologyProc dilateXProc = SkMorphologyGetPlatformProc(SkMorphologyDilateX_Type); |
+ if (!dilateXProc) { |
+ dilateXProc = dilate<true>; |
+ } |
+ dilateXProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), |
+ radiusX, bounds.width(), bounds.height(), |
+ src.rowBytesAsPixels(), dst->rowBytesAsPixels()); |
} |
static void dilateY(const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRect& bounds) |
{ |
- dilate(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), |
- radiusY, bounds.height(), bounds.width(), |
- src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels(), 1); |
+ SkMorphologyProc dilateYProc = SkMorphologyGetPlatformProc(SkMorphologyDilateY_Type); |
+ if (!dilateYProc) { |
+ dilateYProc = dilate<false>; |
+ } |
+ dilateYProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), |
+ radiusY, bounds.height(), bounds.width(), |
+ src.rowBytesAsPixels(), dst->rowBytesAsPixels()); |
} |
bool SkErodeImageFilter::onFilterImage(Proxy* proxy, |