| 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 #ifndef SkMorphologyImageFilter_DEFINED | 8 #ifndef SkMorphologyImageFilter_DEFINED |
| 9 #define SkMorphologyImageFilter_DEFINED | 9 #define SkMorphologyImageFilter_DEFINED |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * All morphology procs have the same signature: src is the source buffer, d
st the | 22 * All morphology procs have the same signature: src is the source buffer, d
st the |
| 23 * destination buffer, radius is the morphology radius, width and height are
the bounds | 23 * destination buffer, radius is the morphology radius, width and height are
the bounds |
| 24 * of the destination buffer (in pixels), and srcStride and dstStride are th
e | 24 * of the destination buffer (in pixels), and srcStride and dstStride are th
e |
| 25 * number of pixels per row in each buffer. All buffers are 8888. | 25 * number of pixels per row in each buffer. All buffers are 8888. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 typedef void (*Proc)(const SkPMColor* src, SkPMColor* dst, int radius, | 28 typedef void (*Proc)(const SkPMColor* src, SkPMColor* dst, int radius, |
| 29 int width, int height, int srcStride, int dstStride); | 29 int width, int height, int srcStride, int dstStride); |
| 30 | 30 |
| 31 protected: | 31 protected: |
| 32 enum Op { |
| 33 kErode_Op, |
| 34 kDilate_Op, |
| 35 }; |
| 36 |
| 37 virtual Op op() const = 0; |
| 38 |
| 32 SkMorphologyImageFilter(int radiusX, int radiusY, SkImageFilter* input, | 39 SkMorphologyImageFilter(int radiusX, int radiusY, SkImageFilter* input, |
| 33 const CropRect* cropRect); | 40 const CropRect* cropRect); |
| 34 sk_sp<SkSpecialImage> filterImageGeneric(bool dilate, | 41 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, |
| 35 SkSpecialImage* source, | 42 const Context&, |
| 36 const Context&, | 43 SkIPoint* offset) const override; |
| 37 SkIPoint* offset) const; | |
| 38 void flatten(SkWriteBuffer&) const override; | 44 void flatten(SkWriteBuffer&) const override; |
| 39 | 45 |
| 40 SkISize radius() const { return fRadius; } | 46 SkISize radius() const { return fRadius; } |
| 41 | 47 |
| 42 private: | 48 private: |
| 43 SkISize fRadius; | 49 SkISize fRadius; |
| 50 |
| 44 typedef SkImageFilter INHERITED; | 51 typedef SkImageFilter INHERITED; |
| 45 }; | 52 }; |
| 46 | 53 |
| 47 /////////////////////////////////////////////////////////////////////////////// | 54 /////////////////////////////////////////////////////////////////////////////// |
| 48 class SK_API SkDilateImageFilter : public SkMorphologyImageFilter { | 55 class SK_API SkDilateImageFilter : public SkMorphologyImageFilter { |
| 49 public: | 56 public: |
| 50 static SkImageFilter* Create(int radiusX, int radiusY, | 57 static SkImageFilter* Create(int radiusX, int radiusY, |
| 51 SkImageFilter* input = nullptr, | 58 SkImageFilter* input = nullptr, |
| 52 const CropRect* cropRect = nullptr) { | 59 const CropRect* cropRect = nullptr) { |
| 53 if (radiusX < 0 || radiusY < 0) { | 60 if (radiusX < 0 || radiusY < 0) { |
| 54 return nullptr; | 61 return nullptr; |
| 55 } | 62 } |
| 56 return new SkDilateImageFilter(radiusX, radiusY, input, cropRect); | 63 return new SkDilateImageFilter(radiusX, radiusY, input, cropRect); |
| 57 } | 64 } |
| 58 | 65 |
| 59 SK_TO_STRING_OVERRIDE() | 66 SK_TO_STRING_OVERRIDE() |
| 60 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDilateImageFilter) | 67 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDilateImageFilter) |
| 61 | 68 |
| 62 protected: | 69 protected: |
| 63 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, | 70 Op op() const override { return kDilate_Op; } |
| 64 SkIPoint* offset) const override; | |
| 65 | 71 |
| 66 private: | 72 private: |
| 67 SkDilateImageFilter(int radiusX, int radiusY, SkImageFilter* input, const Cr
opRect* cropRect) | 73 SkDilateImageFilter(int radiusX, int radiusY, SkImageFilter* input, const Cr
opRect* cropRect) |
| 68 : INHERITED(radiusX, radiusY, input, cropRect) {} | 74 : INHERITED(radiusX, radiusY, input, cropRect) {} |
| 69 | 75 |
| 70 typedef SkMorphologyImageFilter INHERITED; | 76 typedef SkMorphologyImageFilter INHERITED; |
| 71 }; | 77 }; |
| 72 | 78 |
| 73 /////////////////////////////////////////////////////////////////////////////// | 79 /////////////////////////////////////////////////////////////////////////////// |
| 74 class SK_API SkErodeImageFilter : public SkMorphologyImageFilter { | 80 class SK_API SkErodeImageFilter : public SkMorphologyImageFilter { |
| 75 public: | 81 public: |
| 76 static SkImageFilter* Create(int radiusX, int radiusY, | 82 static SkImageFilter* Create(int radiusX, int radiusY, |
| 77 SkImageFilter* input = nullptr, | 83 SkImageFilter* input = nullptr, |
| 78 const CropRect* cropRect = nullptr) { | 84 const CropRect* cropRect = nullptr) { |
| 79 if (radiusX < 0 || radiusY < 0) { | 85 if (radiusX < 0 || radiusY < 0) { |
| 80 return nullptr; | 86 return nullptr; |
| 81 } | 87 } |
| 82 return new SkErodeImageFilter(radiusX, radiusY, input, cropRect); | 88 return new SkErodeImageFilter(radiusX, radiusY, input, cropRect); |
| 83 } | 89 } |
| 84 | 90 |
| 85 SK_TO_STRING_OVERRIDE() | 91 SK_TO_STRING_OVERRIDE() |
| 86 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkErodeImageFilter) | 92 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkErodeImageFilter) |
| 87 | 93 |
| 88 protected: | 94 protected: |
| 89 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, | 95 Op op() const override { return kErode_Op; } |
| 90 SkIPoint* offset) const override; | |
| 91 | 96 |
| 92 private: | 97 private: |
| 93 SkErodeImageFilter(int radiusX, int radiusY, SkImageFilter* input, const Cro
pRect* cropRect) | 98 SkErodeImageFilter(int radiusX, int radiusY, SkImageFilter* input, const Cro
pRect* cropRect) |
| 94 : INHERITED(radiusX, radiusY, input, cropRect) {} | 99 : INHERITED(radiusX, radiusY, input, cropRect) {} |
| 95 | 100 |
| 96 typedef SkMorphologyImageFilter INHERITED; | 101 typedef SkMorphologyImageFilter INHERITED; |
| 97 }; | 102 }; |
| 98 | 103 |
| 99 #endif | 104 #endif |
| OLD | NEW |