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

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 the non-SSE2 build. 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 )
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 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.
41 static void erode(const SkPMColor* src, SkPMColor* dst, 43 static void erode(const SkPMColor* src, SkPMColor* dst,
42 int radius, int width, int height, 44 int radius, int width, int height,
43 int srcStrideX, int srcStrideY, 45 int srcStride, int dstStride)
44 int dstStrideX, int dstStrideY)
45 { 46 {
47 const int srcStrideX = inX ? 1 : srcStride;
48 const int dstStrideX = inX ? 1 : dstStride;
49 const int srcStrideY = inX ? srcStride : 1;
50 const int dstStrideY = inX ? dstStride : 1;
46 radius = SkMin32(radius, width - 1); 51 radius = SkMin32(radius, width - 1);
47 const SkPMColor* upperSrc = src + radius * srcStrideX; 52 const SkPMColor* upperSrc = src + radius * srcStrideX;
48 for (int x = 0; x < width; ++x) { 53 for (int x = 0; x < width; ++x) {
49 const SkPMColor* lp = src; 54 const SkPMColor* lp = src;
50 const SkPMColor* up = upperSrc; 55 const SkPMColor* up = upperSrc;
51 SkPMColor* dptr = dst; 56 SkPMColor* dptr = dst;
52 for (int y = 0; y < height; ++y) { 57 for (int y = 0; y < height; ++y) {
53 int minB = 255, minG = 255, minR = 255, minA = 255; 58 int minB = 255, minG = 255, minR = 255, minA = 255;
54 for (const SkPMColor* p = lp; p <= up; p += srcStrideX) { 59 for (const SkPMColor* p = lp; p <= up; p += srcStrideX) {
55 int b = SkGetPackedB32(*p); 60 int b = SkGetPackedB32(*p);
(...skipping 11 matching lines...) Expand all
67 up += srcStrideY; 72 up += srcStrideY;
68 } 73 }
69 if (x >= radius) src += srcStrideX; 74 if (x >= radius) src += srcStrideX;
70 if (x + radius < width - 1) upperSrc += srcStrideX; 75 if (x + radius < width - 1) upperSrc += srcStrideX;
71 dst += dstStrideX; 76 dst += dstStrideX;
72 } 77 }
73 } 78 }
74 79
75 static void erodeX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRec t& bounds) 80 static void erodeX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRec t& bounds)
76 { 81 {
77 erode(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), 82 SkMorphologyProc erodeXProc = SkMorphologyGetPlatformProc(SkMorphologyErodeX _Type);
78 radiusX, bounds.width(), bounds.height(), 83 if (!erodeXProc) {
79 1, src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels()); 84 erodeXProc = erode<true>;
85 }
86 erodeXProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
87 radiusX, bounds.width(), bounds.height(),
88 src.rowBytesAsPixels(), dst->rowBytesAsPixels());
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 SkMorphologyProc erodeYProc = SkMorphologyGetPlatformProc(SkMorphologyErodeY _Type);
85 radiusY, bounds.height(), bounds.width(), 94 if (!erodeYProc) {
86 src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels(), 1); 95 erodeYProc = erode<false>;
96 }
97 erodeYProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
98 radiusY, bounds.height(), bounds.width(),
99 src.rowBytesAsPixels(), dst->rowBytesAsPixels());
87 } 100 }
88 101
102 template<bool inX>
89 static void dilate(const SkPMColor* src, SkPMColor* dst, 103 static void dilate(const SkPMColor* src, SkPMColor* dst,
90 int radius, int width, int height, 104 int radius, int width, int height,
91 int srcStrideX, int srcStrideY, 105 int srcStride, int dstStride)
92 int dstStrideX, int dstStrideY)
93 { 106 {
107 const int srcStrideX = inX ? 1 : srcStride;
108 const int dstStrideX = inX ? 1 : dstStride;
109 const int srcStrideY = inX ? srcStride : 1;
110 const int dstStrideY = inX ? dstStride : 1;
94 radius = SkMin32(radius, width - 1); 111 radius = SkMin32(radius, width - 1);
95 const SkPMColor* upperSrc = src + radius * srcStrideX; 112 const SkPMColor* upperSrc = src + radius * srcStrideX;
96 for (int x = 0; x < width; ++x) { 113 for (int x = 0; x < width; ++x) {
97 const SkPMColor* lp = src; 114 const SkPMColor* lp = src;
98 const SkPMColor* up = upperSrc; 115 const SkPMColor* up = upperSrc;
99 SkPMColor* dptr = dst; 116 SkPMColor* dptr = dst;
100 for (int y = 0; y < height; ++y) { 117 for (int y = 0; y < height; ++y) {
101 int maxB = 0, maxG = 0, maxR = 0, maxA = 0; 118 int maxB = 0, maxG = 0, maxR = 0, maxA = 0;
102 for (const SkPMColor* p = lp; p <= up; p += srcStrideX) { 119 for (const SkPMColor* p = lp; p <= up; p += srcStrideX) {
103 int b = SkGetPackedB32(*p); 120 int b = SkGetPackedB32(*p);
(...skipping 11 matching lines...) Expand all
115 up += srcStrideY; 132 up += srcStrideY;
116 } 133 }
117 if (x >= radius) src += srcStrideX; 134 if (x >= radius) src += srcStrideX;
118 if (x + radius < width - 1) upperSrc += srcStrideX; 135 if (x + radius < width - 1) upperSrc += srcStrideX;
119 dst += dstStrideX; 136 dst += dstStrideX;
120 } 137 }
121 } 138 }
122 139
123 static void dilateX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRe ct& bounds) 140 static void dilateX(const SkBitmap& src, SkBitmap* dst, int radiusX, const SkIRe ct& bounds)
124 { 141 {
125 dilate(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), 142 SkMorphologyProc dilateXProc = SkMorphologyGetPlatformProc(SkMorphologyDilat eX_Type);
126 radiusX, bounds.width(), bounds.height(), 143 if (!dilateXProc) {
127 1, src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels()); 144 dilateXProc = dilate<true>;
145 }
146 dilateXProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0) ,
147 radiusX, bounds.width(), bounds.height(),
148 src.rowBytesAsPixels(), dst->rowBytesAsPixels());
128 } 149 }
129 150
130 static void dilateY(const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRe ct& bounds) 151 static void dilateY(const SkBitmap& src, SkBitmap* dst, int radiusY, const SkIRe ct& bounds)
131 { 152 {
132 dilate(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), 153 SkMorphologyProc dilateYProc = SkMorphologyGetPlatformProc(SkMorphologyDilat eY_Type);
133 radiusY, bounds.height(), bounds.width(), 154 if (!dilateYProc) {
134 src.rowBytesAsPixels(), 1, dst->rowBytesAsPixels(), 1); 155 dilateYProc = dilate<false>;
156 }
157 dilateYProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0) ,
158 radiusY, bounds.height(), bounds.width(),
159 src.rowBytesAsPixels(), dst->rowBytesAsPixels());
135 } 160 }
136 161
137 bool SkErodeImageFilter::onFilterImage(Proxy* proxy, 162 bool SkErodeImageFilter::onFilterImage(Proxy* proxy,
138 const SkBitmap& source, const SkMatrix& c tm, 163 const SkBitmap& source, const SkMatrix& c tm,
139 SkBitmap* dst, SkIPoint* offset) { 164 SkBitmap* dst, SkIPoint* offset) {
140 SkBitmap src = source; 165 SkBitmap src = source;
141 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, offse t)) { 166 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, offse t)) {
142 return false; 167 return false;
143 } 168 }
144 169
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 610
586 if (!apply_morphology(input, bounds, GrMorphologyEffect::kErode_MorphologyTy pe, radius(), result)) { 611 if (!apply_morphology(input, bounds, GrMorphologyEffect::kErode_MorphologyTy pe, radius(), result)) {
587 return false; 612 return false;
588 } 613 }
589 offset->fX += bounds.left(); 614 offset->fX += bounds.left();
590 offset->fY += bounds.top(); 615 offset->fY += bounds.top();
591 return true; 616 return true;
592 } 617 }
593 618
594 #endif 619 #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