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

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

Issue 112803004: Make SkImageFilter crop rects relative to the primitive origin, instead of relative to their parent (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Updated to ToT Created 6 years, 11 months 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 | « src/effects/SkBitmapSource.cpp ('k') | src/effects/SkColorFilterImageFilter.cpp » ('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 2011 The Android Open Source Project 2 * Copyright 2011 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBlurImageFilter.h" 9 #include "SkBlurImageFilter.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 *highOffset = d / 2; 130 *highOffset = d / 2;
131 *lowOffset = *highOffset - 1; 131 *lowOffset = *highOffset - 1;
132 *kernelSize3 = d + 1; 132 *kernelSize3 = d + 1;
133 } 133 }
134 } 134 }
135 135
136 bool SkBlurImageFilter::onFilterImage(Proxy* proxy, 136 bool SkBlurImageFilter::onFilterImage(Proxy* proxy,
137 const SkBitmap& source, const SkMatrix& ct m, 137 const SkBitmap& source, const SkMatrix& ct m,
138 SkBitmap* dst, SkIPoint* offset) { 138 SkBitmap* dst, SkIPoint* offset) {
139 SkBitmap src = source; 139 SkBitmap src = source;
140 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, offse t)) { 140 SkIPoint srcOffset = SkIPoint::Make(0, 0);
141 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, &srcO ffset)) {
141 return false; 142 return false;
142 } 143 }
143 144
144 if (src.config() != SkBitmap::kARGB_8888_Config) { 145 if (src.config() != SkBitmap::kARGB_8888_Config) {
145 return false; 146 return false;
146 } 147 }
147 148
148 SkAutoLockPixels alp(src); 149 SkAutoLockPixels alp(src);
149 if (!src.getPixels()) { 150 if (!src.getPixels()) {
150 return false; 151 return false;
151 } 152 }
152 153
153 SkIRect srcBounds, dstBounds; 154 SkIRect srcBounds, dstBounds;
154 src.getBounds(&srcBounds); 155 src.getBounds(&srcBounds);
156 srcBounds.offset(srcOffset);
155 if (!this->applyCropRect(&srcBounds, ctm)) { 157 if (!this->applyCropRect(&srcBounds, ctm)) {
156 return false; 158 return false;
157 } 159 }
158 160
159 dst->setConfig(src.config(), srcBounds.width(), srcBounds.height()); 161 dst->setConfig(src.config(), srcBounds.width(), srcBounds.height());
160 dst->getBounds(&dstBounds); 162 dst->getBounds(&dstBounds);
161 dst->allocPixels(); 163 dst->allocPixels();
162 if (!dst->getPixels()) { 164 if (!dst->getPixels()) {
163 return false; 165 return false;
164 } 166 }
165 167
166 int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX; 168 int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX;
167 int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY; 169 int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY;
168 getBox3Params(fSigma.width(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &hig hOffsetX); 170 getBox3Params(fSigma.width(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &hig hOffsetX);
169 getBox3Params(fSigma.height(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &hi ghOffsetY); 171 getBox3Params(fSigma.height(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &hi ghOffsetY);
170 172
171 if (kernelSizeX < 0 || kernelSizeY < 0) { 173 if (kernelSizeX < 0 || kernelSizeY < 0) {
172 return false; 174 return false;
173 } 175 }
174 176
175 if (kernelSizeX == 0 && kernelSizeY == 0) { 177 if (kernelSizeX == 0 && kernelSizeY == 0) {
176 src.copyTo(dst, dst->config()); 178 src.copyTo(dst, dst->config());
179 offset->fX = srcBounds.fLeft;
180 offset->fY = srcBounds.fTop;
177 return true; 181 return true;
178 } 182 }
179 183
180 SkBitmap temp; 184 SkBitmap temp;
181 temp.setConfig(dst->config(), dst->width(), dst->height()); 185 temp.setConfig(dst->config(), dst->width(), dst->height());
182 if (!temp.allocPixels()) { 186 if (!temp.allocPixels()) {
183 return false; 187 return false;
184 } 188 }
185 189
190 offset->fX = srcBounds.fLeft;
191 offset->fY = srcBounds.fTop;
192 srcBounds.offset(-srcOffset);
186 const SkPMColor* s = src.getAddr32(srcBounds.left(), srcBounds.top()); 193 const SkPMColor* s = src.getAddr32(srcBounds.left(), srcBounds.top());
187 SkPMColor* t = temp.getAddr32(0, 0); 194 SkPMColor* t = temp.getAddr32(0, 0);
188 SkPMColor* d = dst->getAddr32(0, 0); 195 SkPMColor* d = dst->getAddr32(0, 0);
189 int w = dstBounds.width(), h = dstBounds.height(); 196 int w = dstBounds.width(), h = dstBounds.height();
190 int sw = src.rowBytesAsPixels(); 197 int sw = src.rowBytesAsPixels();
191 SkBoxBlurProc boxBlurX, boxBlurY, boxBlurXY, boxBlurYX; 198 SkBoxBlurProc boxBlurX, boxBlurY, boxBlurXY, boxBlurYX;
192 if (!SkBoxBlurGetPlatformProcs(&boxBlurX, &boxBlurY, &boxBlurXY, &boxBlurYX) ) { 199 if (!SkBoxBlurGetPlatformProcs(&boxBlurX, &boxBlurY, &boxBlurXY, &boxBlurYX) ) {
193 boxBlurX = boxBlur<kX, kX>; 200 boxBlurX = boxBlur<kX, kX>;
194 boxBlurY = boxBlur<kY, kY>; 201 boxBlurY = boxBlur<kY, kY>;
195 boxBlurXY = boxBlur<kX, kY>; 202 boxBlurXY = boxBlur<kX, kY>;
196 boxBlurYX = boxBlur<kY, kX>; 203 boxBlurYX = boxBlur<kY, kX>;
197 } 204 }
198 205
199 if (kernelSizeX > 0 && kernelSizeY > 0) { 206 if (kernelSizeX > 0 && kernelSizeY > 0) {
200 boxBlurX(s, sw, t, kernelSizeX, lowOffsetX, highOffsetX, w, h); 207 boxBlurX(s, sw, t, kernelSizeX, lowOffsetX, highOffsetX, w, h);
201 boxBlurX(t, w, d, kernelSizeX, highOffsetX, lowOffsetX, w, h); 208 boxBlurX(t, w, d, kernelSizeX, highOffsetX, lowOffsetX, w, h);
202 boxBlurXY(d, w, t, kernelSizeX3, highOffsetX, highOffsetX, w, h); 209 boxBlurXY(d, w, t, kernelSizeX3, highOffsetX, highOffsetX, w, h);
203 boxBlurX(t, h, d, kernelSizeY, lowOffsetY, highOffsetY, h, w); 210 boxBlurX(t, h, d, kernelSizeY, lowOffsetY, highOffsetY, h, w);
204 boxBlurX(d, h, t, kernelSizeY, highOffsetY, lowOffsetY, h, w); 211 boxBlurX(d, h, t, kernelSizeY, highOffsetY, lowOffsetY, h, w);
205 boxBlurXY(t, h, d, kernelSizeY3, highOffsetY, highOffsetY, h, w); 212 boxBlurXY(t, h, d, kernelSizeY3, highOffsetY, highOffsetY, h, w);
206 } else if (kernelSizeX > 0) { 213 } else if (kernelSizeX > 0) {
207 boxBlurX(s, sw, d, kernelSizeX, lowOffsetX, highOffsetX, w, h); 214 boxBlurX(s, sw, d, kernelSizeX, lowOffsetX, highOffsetX, w, h);
208 boxBlurX(d, w, t, kernelSizeX, highOffsetX, lowOffsetX, w, h); 215 boxBlurX(d, w, t, kernelSizeX, highOffsetX, lowOffsetX, w, h);
209 boxBlurX(t, w, d, kernelSizeX3, highOffsetX, highOffsetX, w, h); 216 boxBlurX(t, w, d, kernelSizeX3, highOffsetX, highOffsetX, w, h);
210 } else if (kernelSizeY > 0) { 217 } else if (kernelSizeY > 0) {
211 boxBlurYX(s, sw, d, kernelSizeY, lowOffsetY, highOffsetY, h, w); 218 boxBlurYX(s, sw, d, kernelSizeY, lowOffsetY, highOffsetY, h, w);
212 boxBlurX(d, h, t, kernelSizeY, highOffsetY, lowOffsetY, h, w); 219 boxBlurX(d, h, t, kernelSizeY, highOffsetY, lowOffsetY, h, w);
213 boxBlurXY(t, h, d, kernelSizeY3, highOffsetY, highOffsetY, h, w); 220 boxBlurXY(t, h, d, kernelSizeY3, highOffsetY, highOffsetY, h, w);
214 } 221 }
215 offset->fX += srcBounds.fLeft;
216 offset->fY += srcBounds.fTop;
217 return true; 222 return true;
218 } 223 }
219 224
220 bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, 225 bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
221 SkBitmap* result, SkIPoint* offset) { 226 SkBitmap* result, SkIPoint* offset) {
222 #if SK_SUPPORT_GPU 227 #if SK_SUPPORT_GPU
223 SkBitmap input; 228 SkBitmap input;
224 if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &in put, offset)) { 229 if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &in put, offset)) {
225 return false; 230 return false;
226 } 231 }
227 GrTexture* source = input.getTexture(); 232 GrTexture* source = input.getTexture();
228 SkIRect rect; 233 SkIRect rect;
229 src.getBounds(&rect); 234 src.getBounds(&rect);
230 if (!this->applyCropRect(&rect, ctm)) { 235 if (!this->applyCropRect(&rect, ctm)) {
231 return false; 236 return false;
232 } 237 }
233 SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(source->getContext( ), 238 SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(source->getContext( ),
234 source, 239 source,
235 false, 240 false,
236 SkRect::Make(rect), 241 SkRect::Make(rect),
237 true, 242 true,
238 fSigma.width(), 243 fSigma.width(),
239 fSigma.height())); 244 fSigma.height()));
240 offset->fX += rect.fLeft; 245 offset->fX = rect.fLeft;
241 offset->fY += rect.fTop; 246 offset->fY = rect.fTop;
242 return SkImageFilterUtils::WrapTexture(tex, rect.width(), rect.height(), res ult); 247 return SkImageFilterUtils::WrapTexture(tex, rect.width(), rect.height(), res ult);
243 #else 248 #else
244 SkDEBUGFAIL("Should not call in GPU-less build"); 249 SkDEBUGFAIL("Should not call in GPU-less build");
245 return false; 250 return false;
246 #endif 251 #endif
247 } 252 }
OLDNEW
« no previous file with comments | « src/effects/SkBitmapSource.cpp ('k') | src/effects/SkColorFilterImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698