Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: src/effects/SkMorphologyImageFilter.cpp

Issue 52603004: Implement SSE2-based implementations of the morphology filters (dilate & (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Tweak Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gyp/opts.gyp ('k') | src/opts/SkMorphology_opts.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The Android Open Source Project 2 * Copyright 2012 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkMorphologyImageFilter.h" 8 #include "SkMorphologyImageFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 #include "SkFlattenableBuffers.h" 11 #include "SkFlattenableBuffers.h"
12 #include "SkRect.h" 12 #include "SkRect.h"
13 #include "SkMorphology_opts.h"
13 #if SK_SUPPORT_GPU 14 #if SK_SUPPORT_GPU
14 #include "GrContext.h" 15 #include "GrContext.h"
15 #include "GrTexture.h" 16 #include "GrTexture.h"
16 #include "GrTBackendEffectFactory.h" 17 #include "GrTBackendEffectFactory.h"
17 #include "gl/GrGLEffect.h" 18 #include "gl/GrGLEffect.h"
18 #include "effects/Gr1DKernelEffect.h" 19 #include "effects/Gr1DKernelEffect.h"
19 #include "SkImageFilterUtils.h" 20 #include "SkImageFilterUtils.h"
20 #endif 21 #endif
21 22
22 SkMorphologyImageFilter::SkMorphologyImageFilter(SkFlattenableReadBuffer& buffer ) 23 SkMorphologyImageFilter::SkMorphologyImageFilter(SkFlattenableReadBuffer& buffer )
23 : INHERITED(buffer) { 24 : INHERITED(buffer) {
24 fRadius.fWidth = buffer.readInt(); 25 fRadius.fWidth = buffer.readInt();
25 fRadius.fHeight = buffer.readInt(); 26 fRadius.fHeight = buffer.readInt();
26 buffer.validate((fRadius.fWidth >= 0) && 27 buffer.validate((fRadius.fWidth >= 0) &&
27 (fRadius.fHeight >= 0)); 28 (fRadius.fHeight >= 0));
28 } 29 }
29 30
30 SkMorphologyImageFilter::SkMorphologyImageFilter(int radiusX, int radiusY, SkIma geFilter* input, const CropRect* cropRect) 31 SkMorphologyImageFilter::SkMorphologyImageFilter(int radiusX, int radiusY, SkIma geFilter* input, const CropRect* cropRect)
31 : INHERITED(input, cropRect), fRadius(SkISize::Make(radiusX, radiusY)) { 32 : INHERITED(input, cropRect), fRadius(SkISize::Make(radiusX, radiusY)) {
32 } 33 }
33 34
34 35
35 void SkMorphologyImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { 36 void SkMorphologyImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
36 this->INHERITED::flatten(buffer); 37 this->INHERITED::flatten(buffer);
37 buffer.writeInt(fRadius.fWidth); 38 buffer.writeInt(fRadius.fWidth);
38 buffer.writeInt(fRadius.fHeight); 39 buffer.writeInt(fRadius.fHeight);
39 } 40 }
40 41
42 enum MorphDirection {
43 kX, kY
44 };
45
46 template<MorphDirection direction>
41 static void erode(const SkPMColor* src, SkPMColor* dst, 47 static void erode(const SkPMColor* src, SkPMColor* dst,
42 int radius, int width, int height, 48 int radius, int width, int height,
43 int srcStrideX, int srcStrideY, 49 int srcStride, int dstStride)
44 int dstStrideX, int dstStrideY)
45 { 50 {
51 const int srcStrideX = direction == kX ? 1 : srcStride;
52 const int dstStrideX = direction == kX ? 1 : dstStride;
53 const int srcStrideY = direction == kX ? srcStride : 1;
54 const int dstStrideY = direction == kX ? dstStride : 1;
46 radius = SkMin32(radius, width - 1); 55 radius = SkMin32(radius, width - 1);
47 const SkPMColor* upperSrc = src + radius * srcStrideX; 56 const SkPMColor* upperSrc = src + radius * srcStrideX;
48 for (int x = 0; x < width; ++x) { 57 for (int x = 0; x < width; ++x) {
49 const SkPMColor* lp = src; 58 const SkPMColor* lp = src;
50 const SkPMColor* up = upperSrc; 59 const SkPMColor* up = upperSrc;
51 SkPMColor* dptr = dst; 60 SkPMColor* dptr = dst;
52 for (int y = 0; y < height; ++y) { 61 for (int y = 0; y < height; ++y) {
53 int minB = 255, minG = 255, minR = 255, minA = 255; 62 int minB = 255, minG = 255, minR = 255, minA = 255;
54 for (const SkPMColor* p = lp; p <= up; p += srcStrideX) { 63 for (const SkPMColor* p = lp; p <= up; p += srcStrideX) {
55 int b = SkGetPackedB32(*p); 64 int b = SkGetPackedB32(*p);
(...skipping 11 matching lines...) Expand all
67 up += srcStrideY; 76 up += srcStrideY;
68 } 77 }
69 if (x >= radius) src += srcStrideX; 78 if (x >= radius) src += srcStrideX;
70 if (x + radius < width - 1) upperSrc += srcStrideX; 79 if (x + radius < width - 1) upperSrc += srcStrideX;
71 dst += dstStrideX; 80 dst += dstStrideX;
72 } 81 }
73 } 82 }
74 83
75 static void erodeX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRec t& bounds) 84 static void erodeX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRec t& bounds)
76 { 85 {
77 erode(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), 86 SkMorphologyProc erodeXProc = SkMorphologyGetPlatformProc(kErodeX_SkMorpholo gyProcType);
78 radiusX, bounds.width(), bounds.height(), 87 if (!erodeXProc) {
79 1, src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels()); 88 erodeXProc = erode<kX>;
89 }
90 erodeXProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
91 radiusX, bounds.width(), bounds.height(),
92 src.rowBytesAsPixels(), dst->rowBytesAsPixels());
80 } 93 }
81 94
82 static void erodeY(const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRec t& bounds) 95 static void erodeY(const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRec t& bounds)
83 { 96 {
84 erode(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), 97 SkMorphologyProc erodeYProc = SkMorphologyGetPlatformProc(kErodeY_SkMorpholo gyProcType);
85 radiusY, bounds.height(), bounds.width(), 98 if (!erodeYProc) {
86 src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels(), 1); 99 erodeYProc = erode<kY>;
100 }
101 erodeYProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
102 radiusY, bounds.height(), bounds.width(),
103 src.rowBytesAsPixels(), dst->rowBytesAsPixels());
87 } 104 }
88 105
106 template<MorphDirection direction>
89 static void dilate(const SkPMColor* src, SkPMColor* dst, 107 static void dilate(const SkPMColor* src, SkPMColor* dst,
90 int radius, int width, int height, 108 int radius, int width, int height,
91 int srcStrideX, int srcStrideY, 109 int srcStride, int dstStride)
92 int dstStrideX, int dstStrideY)
93 { 110 {
111 const int srcStrideX = direction == kX ? 1 : srcStride;
112 const int dstStrideX = direction == kX ? 1 : dstStride;
113 const int srcStrideY = direction == kX ? srcStride : 1;
114 const int dstStrideY = direction == kX ? dstStride : 1;
94 radius = SkMin32(radius, width - 1); 115 radius = SkMin32(radius, width - 1);
95 const SkPMColor* upperSrc = src + radius * srcStrideX; 116 const SkPMColor* upperSrc = src + radius * srcStrideX;
96 for (int x = 0; x < width; ++x) { 117 for (int x = 0; x < width; ++x) {
97 const SkPMColor* lp = src; 118 const SkPMColor* lp = src;
98 const SkPMColor* up = upperSrc; 119 const SkPMColor* up = upperSrc;
99 SkPMColor* dptr = dst; 120 SkPMColor* dptr = dst;
100 for (int y = 0; y < height; ++y) { 121 for (int y = 0; y < height; ++y) {
101 int maxB = 0, maxG = 0, maxR = 0, maxA = 0; 122 int maxB = 0, maxG = 0, maxR = 0, maxA = 0;
102 for (const SkPMColor* p = lp; p <= up; p += srcStrideX) { 123 for (const SkPMColor* p = lp; p <= up; p += srcStrideX) {
103 int b = SkGetPackedB32(*p); 124 int b = SkGetPackedB32(*p);
(...skipping 11 matching lines...) Expand all
115 up += srcStrideY; 136 up += srcStrideY;
116 } 137 }
117 if (x >= radius) src += srcStrideX; 138 if (x >= radius) src += srcStrideX;
118 if (x + radius < width - 1) upperSrc += srcStrideX; 139 if (x + radius < width - 1) upperSrc += srcStrideX;
119 dst += dstStrideX; 140 dst += dstStrideX;
120 } 141 }
121 } 142 }
122 143
123 static void dilateX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRe ct& bounds) 144 static void dilateX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRe ct& bounds)
124 { 145 {
125 dilate(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), 146 SkMorphologyProc dilateXProc = SkMorphologyGetPlatformProc(kDilateX_SkMorpho logyProcType);
126 radiusX, bounds.width(), bounds.height(), 147 if (!dilateXProc) {
127 1, src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels()); 148 dilateXProc = dilate<kX>;
149 }
150 dilateXProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0) ,
151 radiusX, bounds.width(), bounds.height(),
152 src.rowBytesAsPixels(), dst->rowBytesAsPixels());
128 } 153 }
129 154
130 static void dilateY(const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRe ct& bounds) 155 static void dilateY(const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRe ct& bounds)
131 { 156 {
132 dilate(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), 157 SkMorphologyProc dilateYProc = SkMorphologyGetPlatformProc(kDilateY_SkMorpho logyProcType);
133 radiusY, bounds.height(), bounds.width(), 158 if (!dilateYProc) {
134 src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels(), 1); 159 dilateYProc = dilate<kY>;
160 }
161 dilateYProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0) ,
162 radiusY, bounds.height(), bounds.width(),
163 src.rowBytesAsPixels(), dst->rowBytesAsPixels());
135 } 164 }
136 165
137 bool SkErodeImageFilter::onFilterImage(Proxy* proxy, 166 bool SkErodeImageFilter::onFilterImage(Proxy* proxy,
138 const SkBitmap& source, const SkMatrix& c tm, 167 const SkBitmap& source, const SkMatrix& c tm,
139 SkBitmap* dst, SkIPoint* offset) { 168 SkBitmap* dst, SkIPoint* offset) {
140 SkBitmap src = source; 169 SkBitmap src = source;
141 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, offse t)) { 170 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, offse t)) {
142 return false; 171 return false;
143 } 172 }
144 173
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 614
586 if (!apply_morphology(input, bounds, GrMorphologyEffect::kErode_MorphologyTy pe, radius(), result)) { 615 if (!apply_morphology(input, bounds, GrMorphologyEffect::kErode_MorphologyTy pe, radius(), result)) {
587 return false; 616 return false;
588 } 617 }
589 offset->fX += bounds.left(); 618 offset->fX += bounds.left();
590 offset->fY += bounds.top(); 619 offset->fY += bounds.top();
591 return true; 620 return true;
592 } 621 }
593 622
594 #endif 623 #endif
OLDNEW
« no previous file with comments | « gyp/opts.gyp ('k') | src/opts/SkMorphology_opts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698