| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 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 "SkAlphaThresholdFilter.h" | 8 #include "SkAlphaThresholdFilter.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
| 11 #include "SkWriteBuffer.h" | 11 #include "SkWriteBuffer.h" |
| 12 #include "SkRegion.h" | 12 #include "SkRegion.h" |
| 13 | 13 |
| 14 class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter { | 14 class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter { |
| 15 public: | 15 public: |
| 16 SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold,
SkScalar outerThreshold); | 16 SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold,
SkScalar outerThreshold); |
| 17 | 17 |
| 18 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterIm
pl) | 18 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterIm
pl) |
| 19 | 19 |
| 20 protected: | 20 protected: |
| 21 explicit SkAlphaThresholdFilterImpl(SkReadBuffer& buffer); | 21 explicit SkAlphaThresholdFilterImpl(SkReadBuffer& buffer); |
| 22 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | 22 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
| 23 | 23 |
| 24 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, | 24 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
| 25 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; | 25 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; |
| 26 #if SK_SUPPORT_GPU | 26 #if SK_SUPPORT_GPU |
| 27 virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture, | 27 virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture, |
| 28 const SkMatrix& matrix, const SkIRect& bounds) cons
t SK_OVERRIDE; | 28 const SkMatrix& matrix, const SkIRect& bounds) cons
t SK_OVERRIDE; |
| 29 #endif | 29 #endif |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 SkRegion fRegion; | 32 SkRegion fRegion; |
| 33 SkScalar fInnerThreshold; | 33 SkScalar fInnerThreshold; |
| 34 SkScalar fOuterThreshold; | 34 SkScalar fOuterThreshold; |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 #endif | 297 #endif |
| 298 | 298 |
| 299 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { | 299 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { |
| 300 this->INHERITED::flatten(buffer); | 300 this->INHERITED::flatten(buffer); |
| 301 buffer.writeScalar(fInnerThreshold); | 301 buffer.writeScalar(fInnerThreshold); |
| 302 buffer.writeScalar(fOuterThreshold); | 302 buffer.writeScalar(fOuterThreshold); |
| 303 buffer.writeRegion(fRegion); | 303 buffer.writeRegion(fRegion); |
| 304 } | 304 } |
| 305 | 305 |
| 306 bool SkAlphaThresholdFilterImpl::onFilterImage(Proxy*, const SkBitmap& src, | 306 bool SkAlphaThresholdFilterImpl::onFilterImage(Proxy*, const SkBitmap& src, |
| 307 const SkMatrix& matrix, SkBitmap*
dst, | 307 const Context& ctx, SkBitmap* dst
, |
| 308 SkIPoint* offset) const { | 308 SkIPoint* offset) const { |
| 309 SkASSERT(src.colorType() == kPMColor_SkColorType); | 309 SkASSERT(src.colorType() == kPMColor_SkColorType); |
| 310 | 310 |
| 311 if (src.colorType() != kPMColor_SkColorType) { | 311 if (src.colorType() != kPMColor_SkColorType) { |
| 312 return false; | 312 return false; |
| 313 } | 313 } |
| 314 | 314 |
| 315 SkMatrix localInverse; | 315 SkMatrix localInverse; |
| 316 if (!matrix.invert(&localInverse)) { | 316 if (!ctx.ctm().invert(&localInverse)) { |
| 317 return false; | 317 return false; |
| 318 } | 318 } |
| 319 | 319 |
| 320 SkAutoLockPixels alp(src); | 320 SkAutoLockPixels alp(src); |
| 321 SkASSERT(src.getPixels()); | 321 SkASSERT(src.getPixels()); |
| 322 if (!src.getPixels() || src.width() <= 0 || src.height() <= 0) { | 322 if (!src.getPixels() || src.width() <= 0 || src.height() <= 0) { |
| 323 return false; | 323 return false; |
| 324 } | 324 } |
| 325 | 325 |
| 326 dst->setConfig(src.config(), src.width(), src.height()); | 326 dst->setConfig(src.config(), src.width(), src.height()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 (U8CPU)(SkColorGetG(source) *
scale), | 358 (U8CPU)(SkColorGetG(source) *
scale), |
| 359 (U8CPU)(SkColorGetB(source) *
scale)); | 359 (U8CPU)(SkColorGetB(source) *
scale)); |
| 360 } | 360 } |
| 361 } | 361 } |
| 362 dptr[y * dst->width() + x] = output_color; | 362 dptr[y * dst->width() + x] = output_color; |
| 363 } | 363 } |
| 364 } | 364 } |
| 365 | 365 |
| 366 return true; | 366 return true; |
| 367 } | 367 } |
| OLD | NEW |