| OLD | NEW |
| 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 Loading... |
| 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 |
| 215 if (width > 0 && height > 0) { | 217 if (width > 0 && height > 0) { |
| 216 erodeX(src, &temp, width, bounds); | 218 erodeX(src, &temp, width, bounds); |
| 217 SkIRect tmpBounds = SkIRect::MakeWH(bounds.width(), bounds.height()); | 219 SkIRect tmpBounds = SkIRect::MakeWH(bounds.width(), bounds.height()); |
| 218 erodeY(temp, dst, height, tmpBounds); | 220 erodeY(temp, dst, height, tmpBounds); |
| 219 } else if (width > 0) { | 221 } else if (width > 0) { |
| 220 erodeX(src, dst, width, bounds); | 222 erodeX(src, dst, width, bounds); |
| 221 } else if (height > 0) { | 223 } else if (height > 0) { |
| 222 erodeY(src, dst, height, bounds); | 224 erodeY(src, dst, height, bounds); |
| 223 } | 225 } |
| 224 offset->fX += bounds.left(); | 226 offset->fX = bounds.left(); |
| 225 offset->fY += bounds.top(); | 227 offset->fY = bounds.top(); |
| 226 return true; | 228 return true; |
| 227 } | 229 } |
| 228 | 230 |
| 229 bool SkDilateImageFilter::onFilterImage(Proxy* proxy, | 231 bool SkDilateImageFilter::onFilterImage(Proxy* proxy, |
| 230 const SkBitmap& source, const SkMatrix&
ctm, | 232 const SkBitmap& source, const SkMatrix&
ctm, |
| 231 SkBitmap* dst, SkIPoint* offset) { | 233 SkBitmap* dst, SkIPoint* offset) { |
| 232 SkBitmap src = source; | 234 SkBitmap src = source; |
| 233 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, offse
t)) { | 235 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| 236 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, &srcO
ffset)) { |
| 234 return false; | 237 return false; |
| 235 } | 238 } |
| 236 if (src.config() != SkBitmap::kARGB_8888_Config) { | 239 if (src.config() != SkBitmap::kARGB_8888_Config) { |
| 237 return false; | 240 return false; |
| 238 } | 241 } |
| 239 | 242 |
| 240 SkIRect bounds; | 243 SkIRect bounds; |
| 241 src.getBounds(&bounds); | 244 src.getBounds(&bounds); |
| 245 bounds.offset(srcOffset); |
| 242 if (!this->applyCropRect(&bounds, ctm)) { | 246 if (!this->applyCropRect(&bounds, ctm)) { |
| 243 return false; | 247 return false; |
| 244 } | 248 } |
| 245 | 249 |
| 246 SkAutoLockPixels alp(src); | 250 SkAutoLockPixels alp(src); |
| 247 if (!src.getPixels()) { | 251 if (!src.getPixels()) { |
| 248 return false; | 252 return false; |
| 249 } | 253 } |
| 250 | 254 |
| 251 dst->setConfig(src.config(), bounds.width(), bounds.height()); | 255 dst->setConfig(src.config(), bounds.width(), bounds.height()); |
| 252 dst->allocPixels(); | 256 dst->allocPixels(); |
| 253 if (!dst->getPixels()) { | 257 if (!dst->getPixels()) { |
| 254 return false; | 258 return false; |
| 255 } | 259 } |
| 256 | 260 |
| 257 int width = radius().width(); | 261 int width = radius().width(); |
| 258 int height = radius().height(); | 262 int height = radius().height(); |
| 259 | 263 |
| 260 if (width < 0 || height < 0) { | 264 if (width < 0 || height < 0) { |
| 261 return false; | 265 return false; |
| 262 } | 266 } |
| 263 | 267 |
| 264 if (width == 0 && height == 0) { | 268 if (width == 0 && height == 0) { |
| 265 src.extractSubset(dst, bounds); | 269 src.extractSubset(dst, bounds); |
| 266 offset->fX += bounds.left(); | 270 offset->fX = bounds.left(); |
| 267 offset->fY += bounds.top(); | 271 offset->fY = bounds.top(); |
| 268 return true; | 272 return true; |
| 269 } | 273 } |
| 270 | 274 |
| 271 SkBitmap temp; | 275 SkBitmap temp; |
| 272 temp.setConfig(dst->config(), dst->width(), dst->height()); | 276 temp.setConfig(dst->config(), dst->width(), dst->height()); |
| 273 if (!temp.allocPixels()) { | 277 if (!temp.allocPixels()) { |
| 274 return false; | 278 return false; |
| 275 } | 279 } |
| 276 | 280 |
| 277 if (width > 0 && height > 0) { | 281 if (width > 0 && height > 0) { |
| 278 dilateX(src, &temp, width, bounds); | 282 dilateX(src, &temp, width, bounds); |
| 279 SkIRect tmpBounds = SkIRect::MakeWH(bounds.width(), bounds.height()); | 283 SkIRect tmpBounds = SkIRect::MakeWH(bounds.width(), bounds.height()); |
| 280 dilateY(temp, dst, height, tmpBounds); | 284 dilateY(temp, dst, height, tmpBounds); |
| 281 } else if (width > 0) { | 285 } else if (width > 0) { |
| 282 dilateX(src, dst, width, bounds); | 286 dilateX(src, dst, width, bounds); |
| 283 } else if (height > 0) { | 287 } else if (height > 0) { |
| 284 dilateY(src, dst, height, bounds); | 288 dilateY(src, dst, height, bounds); |
| 285 } | 289 } |
| 286 offset->fX += bounds.left(); | 290 offset->fX = bounds.left(); |
| 287 offset->fY += bounds.top(); | 291 offset->fY = bounds.top(); |
| 288 return true; | 292 return true; |
| 289 } | 293 } |
| 290 | 294 |
| 291 #if SK_SUPPORT_GPU | 295 #if SK_SUPPORT_GPU |
| 292 | 296 |
| 293 /////////////////////////////////////////////////////////////////////////////// | 297 /////////////////////////////////////////////////////////////////////////////// |
| 294 | 298 |
| 295 class GrGLMorphologyEffect; | 299 class GrGLMorphologyEffect; |
| 296 | 300 |
| 297 /** | 301 /** |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 } | 577 } |
| 574 int width = radius().width(); | 578 int width = radius().width(); |
| 575 int height = radius().height(); | 579 int height = radius().height(); |
| 576 | 580 |
| 577 if (width < 0 || height < 0) { | 581 if (width < 0 || height < 0) { |
| 578 return false; | 582 return false; |
| 579 } | 583 } |
| 580 | 584 |
| 581 if (width == 0 && height == 0) { | 585 if (width == 0 && height == 0) { |
| 582 src.extractSubset(result, bounds); | 586 src.extractSubset(result, bounds); |
| 583 offset->fX += bounds.left(); | 587 offset->fX = bounds.left(); |
| 584 offset->fY += bounds.top(); | 588 offset->fY = bounds.top(); |
| 585 return true; | 589 return true; |
| 586 } | 590 } |
| 587 | 591 |
| 588 if (!apply_morphology(input, bounds, GrMorphologyEffect::kDilate_MorphologyT
ype, radius(), result)) { | 592 if (!apply_morphology(input, bounds, GrMorphologyEffect::kDilate_MorphologyT
ype, radius(), result)) { |
| 589 return false; | 593 return false; |
| 590 } | 594 } |
| 591 offset->fX += bounds.left(); | 595 offset->fX = bounds.left(); |
| 592 offset->fY += bounds.top(); | 596 offset->fY = bounds.top(); |
| 593 return true; | 597 return true; |
| 594 } | 598 } |
| 595 | 599 |
| 596 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
SkMatrix& ctm, | 600 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
SkMatrix& ctm, |
| 597 SkBitmap* result, SkIPoint* offset) { | 601 SkBitmap* result, SkIPoint* offset) { |
| 598 SkBitmap input; | 602 SkBitmap input; |
| 599 if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &in
put, offset)) { | 603 if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &in
put, offset)) { |
| 600 return false; | 604 return false; |
| 601 } | 605 } |
| 602 SkIRect bounds; | 606 SkIRect bounds; |
| 603 src.getBounds(&bounds); | 607 src.getBounds(&bounds); |
| 604 if (!this->applyCropRect(&bounds, ctm)) { | 608 if (!this->applyCropRect(&bounds, ctm)) { |
| 605 return false; | 609 return false; |
| 606 } | 610 } |
| 607 int width = radius().width(); | 611 int width = radius().width(); |
| 608 int height = radius().height(); | 612 int height = radius().height(); |
| 609 | 613 |
| 610 if (width < 0 || height < 0) { | 614 if (width < 0 || height < 0) { |
| 611 return false; | 615 return false; |
| 612 } | 616 } |
| 613 | 617 |
| 614 if (width == 0 && height == 0) { | 618 if (width == 0 && height == 0) { |
| 615 src.extractSubset(result, bounds); | 619 src.extractSubset(result, bounds); |
| 616 offset->fX += bounds.left(); | 620 offset->fX = bounds.left(); |
| 617 offset->fY += bounds.top(); | 621 offset->fY = bounds.top(); |
| 618 return true; | 622 return true; |
| 619 } | 623 } |
| 620 | 624 |
| 621 if (!apply_morphology(input, bounds, GrMorphologyEffect::kErode_MorphologyTy
pe, radius(), result)) { | 625 if (!apply_morphology(input, bounds, GrMorphologyEffect::kErode_MorphologyTy
pe, radius(), result)) { |
| 622 return false; | 626 return false; |
| 623 } | 627 } |
| 624 offset->fX += bounds.left(); | 628 offset->fX = bounds.left(); |
| 625 offset->fY += bounds.top(); | 629 offset->fY = bounds.top(); |
| 626 return true; | 630 return true; |
| 627 } | 631 } |
| 628 | 632 |
| 629 #endif | 633 #endif |
| OLD | NEW |