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

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: Fix typo in dilateY() 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
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 )
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 up += srcStrideY; 68 up += srcStrideY;
68 } 69 }
69 if (x >= radius) src += srcStrideX; 70 if (x >= radius) src += srcStrideX;
70 if (x + radius < width - 1) upperSrc += srcStrideX; 71 if (x + radius < width - 1) upperSrc += srcStrideX;
71 dst += dstStrideX; 72 dst += dstStrideX;
72 } 73 }
73 } 74 }
74 75
75 static void erodeX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRec t& bounds) 76 static void erodeX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRec t& bounds)
76 { 77 {
77 erode(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), 78 if (SkMorphologyProc erodeXProc = SkErodeXGetPlatformProc()) {
reed1 2013/10/30 15:15:04 can we change either the platformproc or your erod
Stephen White 2013/10/30 19:47:17 Done.
78 radiusX, bounds.width(), bounds.height(), 79 (*erodeXProc)(src.getAddr32(bounds.left(), bounds.top()),
79 1, src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels()); 80 dst->getAddr32(0, 0), radiusX,
81 bounds.width(), bounds.height(),
82 src.rowBytesAsPixels(),
83 dst->rowBytesAsPixels());
84 } else {
85 erode(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
86 radiusX, bounds.width(), bounds.height(),
87 1, src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels());
88 }
80 } 89 }
81 90
82 static void erodeY(const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRec t& bounds) 91 static void erodeY(const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRec t& bounds)
83 { 92 {
84 erode(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), 93 if (SkMorphologyProc erodeYProc = SkErodeYGetPlatformProc()) {
85 radiusY, bounds.height(), bounds.width(), 94 (*erodeYProc)(src.getAddr32(bounds.left(), bounds.top()),
86 src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels(), 1); 95 dst->getAddr32(0, 0),
96 radiusY,
97 bounds.width(), bounds.height(),
98 src.rowBytesAsPixels(),
99 dst->rowBytesAsPixels());
100 } else {
101 erode(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
102 radiusY, bounds.height(), bounds.width(),
103 src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels(), 1);
104 }
87 } 105 }
88 106
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 srcStrideX, int srcStrideY,
92 int dstStrideX, int dstStrideY) 110 int dstStrideX, int dstStrideY)
93 { 111 {
94 radius = SkMin32(radius, width - 1); 112 radius = SkMin32(radius, width - 1);
95 const SkPMColor* upperSrc = src + radius * srcStrideX; 113 const SkPMColor* upperSrc = src + radius * srcStrideX;
96 for (int x = 0; x < width; ++x) { 114 for (int x = 0; x < width; ++x) {
(...skipping 18 matching lines...) Expand all
115 up += srcStrideY; 133 up += srcStrideY;
116 } 134 }
117 if (x >= radius) src += srcStrideX; 135 if (x >= radius) src += srcStrideX;
118 if (x + radius < width - 1) upperSrc += srcStrideX; 136 if (x + radius < width - 1) upperSrc += srcStrideX;
119 dst += dstStrideX; 137 dst += dstStrideX;
120 } 138 }
121 } 139 }
122 140
123 static void dilateX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRe ct& bounds) 141 static void dilateX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRe ct& bounds)
124 { 142 {
125 dilate(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), 143 if (SkMorphologyProc erodeYProc = SkDilateXGetPlatformProc()) {
126 radiusX, bounds.width(), bounds.height(), 144 (*erodeYProc)(src.getAddr32(bounds.left(), bounds.top()),
127 1, src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels()); 145 dst->getAddr32(0, 0), radiusX,
146 bounds.width(), bounds.height(),
147 src.rowBytesAsPixels(),
148 dst->rowBytesAsPixels());
149 } else {
150 dilate(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
151 radiusX, bounds.width(), bounds.height(),
152 1, src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels());
153 }
128 } 154 }
129 155
130 static void dilateY(const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRe ct& bounds) 156 static void dilateY(const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRe ct& bounds)
131 { 157 {
132 dilate(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), 158 if (SkMorphologyProc dilateYProc = SkDilateYGetPlatformProc()) {
133 radiusY, bounds.height(), bounds.width(), 159 (*dilateYProc)(src.getAddr32(bounds.left(), bounds.top()),
134 src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels(), 1); 160 dst->getAddr32(0, 0),
161 radiusY,
162 bounds.width(), bounds.height(),
163 src.rowBytesAsPixels(),
164 dst->rowBytesAsPixels());
165 } else {
166 dilate(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
167 radiusY, bounds.height(), bounds.width(),
168 src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels(), 1);
169 }
135 } 170 }
136 171
137 bool SkErodeImageFilter::onFilterImage(Proxy* proxy, 172 bool SkErodeImageFilter::onFilterImage(Proxy* proxy,
138 const SkBitmap& source, const SkMatrix& c tm, 173 const SkBitmap& source, const SkMatrix& c tm,
139 SkBitmap* dst, SkIPoint* offset) { 174 SkBitmap* dst, SkIPoint* offset) {
140 SkBitmap src = source; 175 SkBitmap src = source;
141 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, offse t)) { 176 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, offse t)) {
142 return false; 177 return false;
143 } 178 }
144 179
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 620
586 if (!apply_morphology(input, bounds, GrMorphologyEffect::kErode_MorphologyTy pe, radius(), result)) { 621 if (!apply_morphology(input, bounds, GrMorphologyEffect::kErode_MorphologyTy pe, radius(), result)) {
587 return false; 622 return false;
588 } 623 }
589 offset->fX += bounds.left(); 624 offset->fX += bounds.left();
590 offset->fY += bounds.top(); 625 offset->fY += bounds.top();
591 return true; 626 return true;
592 } 627 }
593 628
594 #endif 629 #endif
OLDNEW
« no previous file with comments | « gyp/opts.gyp ('k') | src/opts/SkMorphology_opts.h » ('j') | src/opts/SkMorphology_opts.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698