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

Side by Side Diff: src/effects/SkMorphologyImageFilter.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/SkMergeImageFilter.cpp ('k') | src/effects/SkOffsetImageFilter.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 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"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 160 }
161 dilateYProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0) , 161 dilateYProc(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0) ,
162 radiusY, bounds.height(), bounds.width(), 162 radiusY, bounds.height(), bounds.width(),
163 src.rowBytesAsPixels(), dst->rowBytesAsPixels()); 163 src.rowBytesAsPixels(), dst->rowBytesAsPixels());
164 } 164 }
165 165
166 bool SkErodeImageFilter::onFilterImage(Proxy* proxy, 166 bool SkErodeImageFilter::onFilterImage(Proxy* proxy,
167 const SkBitmap& source, const SkMatrix& c tm, 167 const SkBitmap& source, const SkMatrix& c tm,
168 SkBitmap* dst, SkIPoint* offset) { 168 SkBitmap* dst, SkIPoint* offset) {
169 SkBitmap src = source; 169 SkBitmap src = source;
170 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, offse t)) { 170 SkIPoint srcOffset = SkIPoint::Make(0, 0);
171 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, &srcO ffset)) {
171 return false; 172 return false;
172 } 173 }
173 174
174 if (src.config() != SkBitmap::kARGB_8888_Config) { 175 if (src.config() != SkBitmap::kARGB_8888_Config) {
175 return false; 176 return false;
176 } 177 }
177 178
178 SkIRect bounds; 179 SkIRect bounds;
179 src.getBounds(&bounds); 180 src.getBounds(&bounds);
181 bounds.offset(srcOffset);
180 if (!this->applyCropRect(&bounds, ctm)) { 182 if (!this->applyCropRect(&bounds, ctm)) {
181 return false; 183 return false;
182 } 184 }
183 185
184 SkAutoLockPixels alp(src); 186 SkAutoLockPixels alp(src);
185 if (!src.getPixels()) { 187 if (!src.getPixels()) {
186 return false; 188 return false;
187 } 189 }
188 190
189 dst->setConfig(src.config(), bounds.width(), bounds.height()); 191 dst->setConfig(src.config(), bounds.width(), bounds.height());
190 dst->allocPixels(); 192 dst->allocPixels();
191 if (!dst->getPixels()) { 193 if (!dst->getPixels()) {
192 return false; 194 return false;
193 } 195 }
194 196
195 int width = radius().width(); 197 int width = radius().width();
196 int height = radius().height(); 198 int height = radius().height();
197 199
198 if (width < 0 || height < 0) { 200 if (width < 0 || height < 0) {
199 return false; 201 return false;
200 } 202 }
201 203
202 if (width == 0 && height == 0) { 204 if (width == 0 && height == 0) {
203 src.extractSubset(dst, bounds); 205 src.extractSubset(dst, bounds);
204 offset->fX += bounds.left(); 206 offset->fX = bounds.left();
205 offset->fY += bounds.top(); 207 offset->fY = bounds.top();
206 return true; 208 return true;
207 } 209 }
208 210
209 SkBitmap temp; 211 SkBitmap temp;
210 temp.setConfig(dst->config(), dst->width(), dst->height()); 212 temp.setConfig(dst->config(), dst->width(), dst->height());
211 if (!temp.allocPixels()) { 213 if (!temp.allocPixels()) {
212 return false; 214 return false;
213 } 215 }
214 216
217 offset->fX = bounds.left();
218 offset->fY = bounds.top();
219 bounds.offset(-srcOffset);
215 if (width > 0 && height > 0) { 220 if (width > 0 && height > 0) {
216 erodeX(src, &temp, width, bounds); 221 erodeX(src, &temp, width, bounds);
217 SkIRect tmpBounds = SkIRect::MakeWH(bounds.width(), bounds.height()); 222 SkIRect tmpBounds = SkIRect::MakeWH(bounds.width(), bounds.height());
218 erodeY(temp, dst, height, tmpBounds); 223 erodeY(temp, dst, height, tmpBounds);
219 } else if (width > 0) { 224 } else if (width > 0) {
220 erodeX(src, dst, width, bounds); 225 erodeX(src, dst, width, bounds);
221 } else if (height > 0) { 226 } else if (height > 0) {
222 erodeY(src, dst, height, bounds); 227 erodeY(src, dst, height, bounds);
223 } 228 }
224 offset->fX += bounds.left();
225 offset->fY += bounds.top();
226 return true; 229 return true;
227 } 230 }
228 231
229 bool SkDilateImageFilter::onFilterImage(Proxy* proxy, 232 bool SkDilateImageFilter::onFilterImage(Proxy* proxy,
230 const SkBitmap& source, const SkMatrix& ctm, 233 const SkBitmap& source, const SkMatrix& ctm,
231 SkBitmap* dst, SkIPoint* offset) { 234 SkBitmap* dst, SkIPoint* offset) {
232 SkBitmap src = source; 235 SkBitmap src = source;
233 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, offse t)) { 236 SkIPoint srcOffset = SkIPoint::Make(0, 0);
237 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, &srcO ffset)) {
234 return false; 238 return false;
235 } 239 }
236 if (src.config() != SkBitmap::kARGB_8888_Config) { 240 if (src.config() != SkBitmap::kARGB_8888_Config) {
237 return false; 241 return false;
238 } 242 }
239 243
240 SkIRect bounds; 244 SkIRect bounds;
241 src.getBounds(&bounds); 245 src.getBounds(&bounds);
246 bounds.offset(srcOffset);
242 if (!this->applyCropRect(&bounds, ctm)) { 247 if (!this->applyCropRect(&bounds, ctm)) {
243 return false; 248 return false;
244 } 249 }
245 250
246 SkAutoLockPixels alp(src); 251 SkAutoLockPixels alp(src);
247 if (!src.getPixels()) { 252 if (!src.getPixels()) {
248 return false; 253 return false;
249 } 254 }
250 255
251 dst->setConfig(src.config(), bounds.width(), bounds.height()); 256 dst->setConfig(src.config(), bounds.width(), bounds.height());
252 dst->allocPixels(); 257 dst->allocPixels();
253 if (!dst->getPixels()) { 258 if (!dst->getPixels()) {
254 return false; 259 return false;
255 } 260 }
256 261
257 int width = radius().width(); 262 int width = radius().width();
258 int height = radius().height(); 263 int height = radius().height();
259 264
260 if (width < 0 || height < 0) { 265 if (width < 0 || height < 0) {
261 return false; 266 return false;
262 } 267 }
263 268
264 if (width == 0 && height == 0) { 269 if (width == 0 && height == 0) {
265 src.extractSubset(dst, bounds); 270 src.extractSubset(dst, bounds);
266 offset->fX += bounds.left(); 271 offset->fX = bounds.left();
267 offset->fY += bounds.top(); 272 offset->fY = bounds.top();
268 return true; 273 return true;
269 } 274 }
270 275
271 SkBitmap temp; 276 SkBitmap temp;
272 temp.setConfig(dst->config(), dst->width(), dst->height()); 277 temp.setConfig(dst->config(), dst->width(), dst->height());
273 if (!temp.allocPixels()) { 278 if (!temp.allocPixels()) {
274 return false; 279 return false;
275 } 280 }
276 281
282 offset->fX = bounds.left();
283 offset->fY = bounds.top();
284 bounds.offset(-srcOffset);
277 if (width > 0 && height > 0) { 285 if (width > 0 && height > 0) {
278 dilateX(src, &temp, width, bounds); 286 dilateX(src, &temp, width, bounds);
279 SkIRect tmpBounds = SkIRect::MakeWH(bounds.width(), bounds.height()); 287 SkIRect tmpBounds = SkIRect::MakeWH(bounds.width(), bounds.height());
280 dilateY(temp, dst, height, tmpBounds); 288 dilateY(temp, dst, height, tmpBounds);
281 } else if (width > 0) { 289 } else if (width > 0) {
282 dilateX(src, dst, width, bounds); 290 dilateX(src, dst, width, bounds);
283 } else if (height > 0) { 291 } else if (height > 0) {
284 dilateY(src, dst, height, bounds); 292 dilateY(src, dst, height, bounds);
285 } 293 }
286 offset->fX += bounds.left();
287 offset->fY += bounds.top();
288 return true; 294 return true;
289 } 295 }
290 296
291 #if SK_SUPPORT_GPU 297 #if SK_SUPPORT_GPU
292 298
293 /////////////////////////////////////////////////////////////////////////////// 299 ///////////////////////////////////////////////////////////////////////////////
294 300
295 class GrGLMorphologyEffect; 301 class GrGLMorphologyEffect;
296 302
297 /** 303 /**
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 } 579 }
574 int width = radius().width(); 580 int width = radius().width();
575 int height = radius().height(); 581 int height = radius().height();
576 582
577 if (width < 0 || height < 0) { 583 if (width < 0 || height < 0) {
578 return false; 584 return false;
579 } 585 }
580 586
581 if (width == 0 && height == 0) { 587 if (width == 0 && height == 0) {
582 src.extractSubset(result, bounds); 588 src.extractSubset(result, bounds);
583 offset->fX += bounds.left(); 589 offset->fX = bounds.left();
584 offset->fY += bounds.top(); 590 offset->fY = bounds.top();
585 return true; 591 return true;
586 } 592 }
587 593
588 if (!apply_morphology(input, bounds, GrMorphologyEffect::kDilate_MorphologyT ype, radius(), result)) { 594 if (!apply_morphology(input, bounds, GrMorphologyEffect::kDilate_MorphologyT ype, radius(), result)) {
589 return false; 595 return false;
590 } 596 }
591 offset->fX += bounds.left(); 597 offset->fX = bounds.left();
592 offset->fY += bounds.top(); 598 offset->fY = bounds.top();
593 return true; 599 return true;
594 } 600 }
595 601
596 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, 602 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
597 SkBitmap* result, SkIPoint* offset) { 603 SkBitmap* result, SkIPoint* offset) {
598 SkBitmap input; 604 SkBitmap input;
599 if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &in put, offset)) { 605 if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &in put, offset)) {
600 return false; 606 return false;
601 } 607 }
602 SkIRect bounds; 608 SkIRect bounds;
603 src.getBounds(&bounds); 609 src.getBounds(&bounds);
604 if (!this->applyCropRect(&bounds, ctm)) { 610 if (!this->applyCropRect(&bounds, ctm)) {
605 return false; 611 return false;
606 } 612 }
607 int width = radius().width(); 613 int width = radius().width();
608 int height = radius().height(); 614 int height = radius().height();
609 615
610 if (width < 0 || height < 0) { 616 if (width < 0 || height < 0) {
611 return false; 617 return false;
612 } 618 }
613 619
614 if (width == 0 && height == 0) { 620 if (width == 0 && height == 0) {
615 src.extractSubset(result, bounds); 621 src.extractSubset(result, bounds);
616 offset->fX += bounds.left(); 622 offset->fX = bounds.left();
617 offset->fY += bounds.top(); 623 offset->fY = bounds.top();
618 return true; 624 return true;
619 } 625 }
620 626
621 if (!apply_morphology(input, bounds, GrMorphologyEffect::kErode_MorphologyTy pe, radius(), result)) { 627 if (!apply_morphology(input, bounds, GrMorphologyEffect::kErode_MorphologyTy pe, radius(), result)) {
622 return false; 628 return false;
623 } 629 }
624 offset->fX += bounds.left(); 630 offset->fX = bounds.left();
625 offset->fY += bounds.top(); 631 offset->fY = bounds.top();
626 return true; 632 return true;
627 } 633 }
628 634
629 #endif 635 #endif
OLDNEW
« no previous file with comments | « src/effects/SkMergeImageFilter.cpp ('k') | src/effects/SkOffsetImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698