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

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

Issue 137053003: Apply the CTM to filter parameters for 4 pixel-moving filters. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Revert changes to SkBlurImageFilter.h, SkDropShadowImageFilter.h; use local SkVector var instead 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
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 if (!src.getPixels()) { 187 if (!src.getPixels()) {
188 return false; 188 return false;
189 } 189 }
190 190
191 dst->setConfig(src.config(), bounds.width(), bounds.height()); 191 dst->setConfig(src.config(), bounds.width(), bounds.height());
192 dst->allocPixels(); 192 dst->allocPixels();
193 if (!dst->getPixels()) { 193 if (!dst->getPixels()) {
194 return false; 194 return false;
195 } 195 }
196 196
197 int width = radius().width(); 197 SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()),
198 int height = radius().height(); 198 SkIntToScalar(this->radius().height()));
199 ctm.mapVectors(&radius, 1);
200 int width = SkScalarFloorToInt(radius.fX);
201 int height = SkScalarFloorToInt(radius.fY);
199 202
200 if (width < 0 || height < 0) { 203 if (width < 0 || height < 0) {
201 return false; 204 return false;
202 } 205 }
203 206
207 SkIRect srcBounds = bounds;
208 srcBounds.offset(-srcOffset);
209
204 if (width == 0 && height == 0) { 210 if (width == 0 && height == 0) {
205 src.extractSubset(dst, bounds); 211 src.extractSubset(dst, srcBounds);
206 offset->fX = bounds.left(); 212 offset->fX = bounds.left();
207 offset->fY = bounds.top(); 213 offset->fY = bounds.top();
208 return true; 214 return true;
209 } 215 }
210 216
211 SkBitmap temp; 217 SkBitmap temp;
212 temp.setConfig(dst->config(), dst->width(), dst->height()); 218 temp.setConfig(dst->config(), dst->width(), dst->height());
213 if (!temp.allocPixels()) { 219 if (!temp.allocPixels()) {
214 return false; 220 return false;
215 } 221 }
216 222
223 if (width > 0 && height > 0) {
224 erodeX(src, &temp, width, srcBounds);
225 SkIRect tmpBounds = SkIRect::MakeWH(srcBounds.width(), srcBounds.height( ));
226 erodeY(temp, dst, height, tmpBounds);
227 } else if (width > 0) {
228 erodeX(src, dst, width, srcBounds);
229 } else if (height > 0) {
230 erodeY(src, dst, height, srcBounds);
231 }
217 offset->fX = bounds.left(); 232 offset->fX = bounds.left();
218 offset->fY = bounds.top(); 233 offset->fY = bounds.top();
219 bounds.offset(-srcOffset);
220 if (width > 0 && height > 0) {
221 erodeX(src, &temp, width, bounds);
222 SkIRect tmpBounds = SkIRect::MakeWH(bounds.width(), bounds.height());
223 erodeY(temp, dst, height, tmpBounds);
224 } else if (width > 0) {
225 erodeX(src, dst, width, bounds);
226 } else if (height > 0) {
227 erodeY(src, dst, height, bounds);
228 }
229 return true; 234 return true;
230 } 235 }
231 236
232 bool SkDilateImageFilter::onFilterImage(Proxy* proxy, 237 bool SkDilateImageFilter::onFilterImage(Proxy* proxy,
233 const SkBitmap& source, const SkMatrix& ctm, 238 const SkBitmap& source, const SkMatrix& ctm,
234 SkBitmap* dst, SkIPoint* offset) { 239 SkBitmap* dst, SkIPoint* offset) {
235 SkBitmap src = source; 240 SkBitmap src = source;
236 SkIPoint srcOffset = SkIPoint::Make(0, 0); 241 SkIPoint srcOffset = SkIPoint::Make(0, 0);
237 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, &srcO ffset)) { 242 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, &srcO ffset)) {
238 return false; 243 return false;
(...skipping 13 matching lines...) Expand all
252 if (!src.getPixels()) { 257 if (!src.getPixels()) {
253 return false; 258 return false;
254 } 259 }
255 260
256 dst->setConfig(src.config(), bounds.width(), bounds.height()); 261 dst->setConfig(src.config(), bounds.width(), bounds.height());
257 dst->allocPixels(); 262 dst->allocPixels();
258 if (!dst->getPixels()) { 263 if (!dst->getPixels()) {
259 return false; 264 return false;
260 } 265 }
261 266
262 int width = radius().width(); 267 SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()),
263 int height = radius().height(); 268 SkIntToScalar(this->radius().height()));
269 ctm.mapVectors(&radius, 1);
270 int width = SkScalarFloorToInt(radius.fX);
271 int height = SkScalarFloorToInt(radius.fY);
264 272
265 if (width < 0 || height < 0) { 273 if (width < 0 || height < 0) {
266 return false; 274 return false;
267 } 275 }
268 276
277 SkIRect srcBounds = bounds;
278 srcBounds.offset(-srcOffset);
279
269 if (width == 0 && height == 0) { 280 if (width == 0 && height == 0) {
270 src.extractSubset(dst, bounds); 281 src.extractSubset(dst, srcBounds);
271 offset->fX = bounds.left(); 282 offset->fX = bounds.left();
272 offset->fY = bounds.top(); 283 offset->fY = bounds.top();
273 return true; 284 return true;
274 } 285 }
275 286
276 SkBitmap temp; 287 SkBitmap temp;
277 temp.setConfig(dst->config(), dst->width(), dst->height()); 288 temp.setConfig(dst->config(), dst->width(), dst->height());
278 if (!temp.allocPixels()) { 289 if (!temp.allocPixels()) {
279 return false; 290 return false;
280 } 291 }
281 292
293 if (width > 0 && height > 0) {
294 dilateX(src, &temp, width, srcBounds);
295 SkIRect tmpBounds = SkIRect::MakeWH(srcBounds.width(), srcBounds.height( ));
296 dilateY(temp, dst, height, tmpBounds);
297 } else if (width > 0) {
298 dilateX(src, dst, width, srcBounds);
299 } else if (height > 0) {
300 dilateY(src, dst, height, srcBounds);
301 }
282 offset->fX = bounds.left(); 302 offset->fX = bounds.left();
283 offset->fY = bounds.top(); 303 offset->fY = bounds.top();
284 bounds.offset(-srcOffset);
285 if (width > 0 && height > 0) {
286 dilateX(src, &temp, width, bounds);
287 SkIRect tmpBounds = SkIRect::MakeWH(bounds.width(), bounds.height());
288 dilateY(temp, dst, height, tmpBounds);
289 } else if (width > 0) {
290 dilateX(src, dst, width, bounds);
291 } else if (height > 0) {
292 dilateY(src, dst, height, bounds);
293 }
294 return true; 304 return true;
295 } 305 }
296 306
297 #if SK_SUPPORT_GPU 307 #if SK_SUPPORT_GPU
298 308
299 /////////////////////////////////////////////////////////////////////////////// 309 ///////////////////////////////////////////////////////////////////////////////
300 310
301 class GrGLMorphologyEffect; 311 class GrGLMorphologyEffect;
302 312
303 /** 313 /**
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 src.reset(ast.detach()); 572 src.reset(ast.detach());
563 } 573 }
564 return SkImageFilterUtils::WrapTexture(src, rect.width(), rect.height(), dst ); 574 return SkImageFilterUtils::WrapTexture(src, rect.width(), rect.height(), dst );
565 } 575 }
566 576
567 }; 577 };
568 578
569 bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, cons t SkMatrix& ctm, 579 bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, cons t SkMatrix& ctm,
570 SkBitmap* result, SkIPoint* offset) { 580 SkBitmap* result, SkIPoint* offset) {
571 SkBitmap input; 581 SkBitmap input;
572 if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &in put, offset)) { 582 SkIPoint srcOffset = SkIPoint::Make(0, 0);
583 if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &in put, &srcOffset)) {
573 return false; 584 return false;
574 } 585 }
575 SkIRect bounds; 586 SkIRect bounds;
576 src.getBounds(&bounds); 587 input.getBounds(&bounds);
588 bounds.offset(srcOffset);
577 if (!this->applyCropRect(&bounds, ctm)) { 589 if (!this->applyCropRect(&bounds, ctm)) {
578 return false; 590 return false;
579 } 591 }
580 int width = radius().width(); 592 SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()),
581 int height = radius().height(); 593 SkIntToScalar(this->radius().height()));
594 ctm.mapVectors(&radius, 1);
595 int width = SkScalarFloorToInt(radius.fX);
596 int height = SkScalarFloorToInt(radius.fY);
582 597
583 if (width < 0 || height < 0) { 598 if (width < 0 || height < 0) {
584 return false; 599 return false;
585 } 600 }
586 601
602 SkIRect srcBounds = bounds;
603 srcBounds.offset(-srcOffset);
587 if (width == 0 && height == 0) { 604 if (width == 0 && height == 0) {
588 src.extractSubset(result, bounds); 605 input.extractSubset(result, srcBounds);
589 offset->fX = bounds.left(); 606 offset->fX = bounds.left();
590 offset->fY = bounds.top(); 607 offset->fY = bounds.top();
591 return true; 608 return true;
592 } 609 }
593 610
594 if (!apply_morphology(input, bounds, GrMorphologyEffect::kDilate_MorphologyT ype, radius(), result)) { 611 if (!apply_morphology(input, srcBounds, GrMorphologyEffect::kDilate_Morpholo gyType, SkISize::Make(width, height), result)) {
sugoi 2014/01/20 19:36:57 Exceeds 100 chars.
Stephen White 2014/01/20 19:46:01 Fixed.
595 return false; 612 return false;
596 } 613 }
597 offset->fX = bounds.left(); 614 offset->fX = bounds.left();
598 offset->fY = bounds.top(); 615 offset->fY = bounds.top();
599 return true; 616 return true;
600 } 617 }
601 618
602 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, 619 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
603 SkBitmap* result, SkIPoint* offset) { 620 SkBitmap* result, SkIPoint* offset) {
604 SkBitmap input; 621 SkBitmap input;
605 if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &in put, offset)) { 622 SkIPoint srcOffset = SkIPoint::Make(0, 0);
623 if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &in put, &srcOffset)) {
606 return false; 624 return false;
607 } 625 }
608 SkIRect bounds; 626 SkIRect bounds;
609 src.getBounds(&bounds); 627 input.getBounds(&bounds);
628 bounds.offset(srcOffset);
610 if (!this->applyCropRect(&bounds, ctm)) { 629 if (!this->applyCropRect(&bounds, ctm)) {
611 return false; 630 return false;
612 } 631 }
613 int width = radius().width(); 632 SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()),
614 int height = radius().height(); 633 SkIntToScalar(this->radius().height()));
634 ctm.mapVectors(&radius, 1);
635 int width = SkScalarFloorToInt(radius.fX);
636 int height = SkScalarFloorToInt(radius.fY);
615 637
616 if (width < 0 || height < 0) { 638 if (width < 0 || height < 0) {
617 return false; 639 return false;
618 } 640 }
619 641
642 SkIRect srcBounds = bounds;
643 srcBounds.offset(-srcOffset);
644
620 if (width == 0 && height == 0) { 645 if (width == 0 && height == 0) {
621 src.extractSubset(result, bounds); 646 input.extractSubset(result, srcBounds);
622 offset->fX = bounds.left(); 647 offset->fX = bounds.left();
623 offset->fY = bounds.top(); 648 offset->fY = bounds.top();
624 return true; 649 return true;
625 } 650 }
626 651
627 if (!apply_morphology(input, bounds, GrMorphologyEffect::kErode_MorphologyTy pe, radius(), result)) { 652 if (!apply_morphology(input, srcBounds, GrMorphologyEffect::kErode_Morpholog yType, SkISize::Make(width, height), result)) {
sugoi 2014/01/20 19:36:57 Exceeds 100 chars.
Stephen White 2014/01/20 19:46:01 Fixed.
628 return false; 653 return false;
629 } 654 }
630 offset->fX = bounds.left(); 655 offset->fX = bounds.left();
631 offset->fY = bounds.top(); 656 offset->fY = bounds.top();
632 return true; 657 return true;
633 } 658 }
634 659
635 #endif 660 #endif
OLDNEW
« gm/imagefiltersscaled.cpp ('K') | « src/effects/SkDropShadowImageFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698