Chromium Code Reviews| 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 SkMorphologyImageFilter(int radiusX, int radiusY, SkImageFilter* input, | 32 enum Op { |
| 33 kErode_Op, | |
| 34 kDilate_Op, | |
| 35 }; | |
| 36 | |
| 37 SkMorphologyImageFilter(Op op, int radiusX, int radiusY, SkImageFilter* inpu t, | |
| 33 const CropRect* cropRect); | 38 const CropRect* cropRect); |
| 34 sk_sp<SkSpecialImage> filterImageGeneric(bool dilate, | 39 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, |
| 35 SkSpecialImage* source, | 40 const Context&, |
| 36 const Context&, | 41 SkIPoint* offset) const override; |
| 37 SkIPoint* offset) const; | |
| 38 void flatten(SkWriteBuffer&) const override; | 42 void flatten(SkWriteBuffer&) const override; |
| 39 | 43 |
| 40 SkISize radius() const { return fRadius; } | 44 SkISize radius() const { return fRadius; } |
| 41 | 45 |
| 42 private: | 46 private: |
| 43 SkISize fRadius; | 47 const Op fOp; |
|
Stephen White
2016/03/29 14:42:04
Could we just provide a virtual op() function, ove
robertphillips
2016/03/29 20:27:45
Done.
| |
| 48 SkISize fRadius; | |
| 49 | |
| 44 typedef SkImageFilter INHERITED; | 50 typedef SkImageFilter INHERITED; |
| 45 }; | 51 }; |
| 46 | 52 |
| 47 /////////////////////////////////////////////////////////////////////////////// | 53 /////////////////////////////////////////////////////////////////////////////// |
| 48 class SK_API SkDilateImageFilter : public SkMorphologyImageFilter { | 54 class SK_API SkDilateImageFilter : public SkMorphologyImageFilter { |
| 49 public: | 55 public: |
| 50 static SkImageFilter* Create(int radiusX, int radiusY, | 56 static SkImageFilter* Create(int radiusX, int radiusY, |
| 51 SkImageFilter* input = nullptr, | 57 SkImageFilter* input = nullptr, |
| 52 const CropRect* cropRect = nullptr) { | 58 const CropRect* cropRect = nullptr) { |
| 53 if (radiusX < 0 || radiusY < 0) { | 59 if (radiusX < 0 || radiusY < 0) { |
| 54 return nullptr; | 60 return nullptr; |
| 55 } | 61 } |
| 56 return new SkDilateImageFilter(radiusX, radiusY, input, cropRect); | 62 return new SkDilateImageFilter(radiusX, radiusY, input, cropRect); |
| 57 } | 63 } |
| 58 | 64 |
| 59 SK_TO_STRING_OVERRIDE() | 65 SK_TO_STRING_OVERRIDE() |
| 60 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDilateImageFilter) | 66 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDilateImageFilter) |
| 61 | 67 |
| 62 protected: | |
| 63 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, | |
| 64 SkIPoint* offset) const override; | |
| 65 | |
| 66 private: | 68 private: |
| 67 SkDilateImageFilter(int radiusX, int radiusY, SkImageFilter* input, const Cr opRect* cropRect) | 69 SkDilateImageFilter(int radiusX, int radiusY, SkImageFilter* input, const Cr opRect* cropRect) |
| 68 : INHERITED(radiusX, radiusY, input, cropRect) {} | 70 : INHERITED(kDilate_Op, radiusX, radiusY, input, cropRect) {} |
| 69 | 71 |
| 70 typedef SkMorphologyImageFilter INHERITED; | 72 typedef SkMorphologyImageFilter INHERITED; |
| 71 }; | 73 }; |
| 72 | 74 |
| 73 /////////////////////////////////////////////////////////////////////////////// | 75 /////////////////////////////////////////////////////////////////////////////// |
| 74 class SK_API SkErodeImageFilter : public SkMorphologyImageFilter { | 76 class SK_API SkErodeImageFilter : public SkMorphologyImageFilter { |
| 75 public: | 77 public: |
| 76 static SkImageFilter* Create(int radiusX, int radiusY, | 78 static SkImageFilter* Create(int radiusX, int radiusY, |
| 77 SkImageFilter* input = nullptr, | 79 SkImageFilter* input = nullptr, |
| 78 const CropRect* cropRect = nullptr) { | 80 const CropRect* cropRect = nullptr) { |
| 79 if (radiusX < 0 || radiusY < 0) { | 81 if (radiusX < 0 || radiusY < 0) { |
| 80 return nullptr; | 82 return nullptr; |
| 81 } | 83 } |
| 82 return new SkErodeImageFilter(radiusX, radiusY, input, cropRect); | 84 return new SkErodeImageFilter(radiusX, radiusY, input, cropRect); |
| 83 } | 85 } |
| 84 | 86 |
| 85 SK_TO_STRING_OVERRIDE() | 87 SK_TO_STRING_OVERRIDE() |
| 86 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkErodeImageFilter) | 88 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkErodeImageFilter) |
| 87 | 89 |
| 88 protected: | |
| 89 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, | |
| 90 SkIPoint* offset) const override; | |
| 91 | |
| 92 private: | 90 private: |
| 93 SkErodeImageFilter(int radiusX, int radiusY, SkImageFilter* input, const Cro pRect* cropRect) | 91 SkErodeImageFilter(int radiusX, int radiusY, SkImageFilter* input, const Cro pRect* cropRect) |
| 94 : INHERITED(radiusX, radiusY, input, cropRect) {} | 92 : INHERITED(kErode_Op, radiusX, radiusY, input, cropRect) {} |
| 95 | 93 |
| 96 typedef SkMorphologyImageFilter INHERITED; | 94 typedef SkMorphologyImageFilter INHERITED; |
| 97 }; | 95 }; |
| 98 | 96 |
| 99 #endif | 97 #endif |
| OLD | NEW |