1 /* 2 * Copyright 2012 The Android Open Source Project 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkMorphologyImageFilter_DEFINED 9 #define SkMorphologyImageFilter_DEFINED 10 11 #include "SkColor.h" 12 #include "SkImageFilter.h" 13 #include "SkSize.h" 14 15 /////////////////////////////////////////////////////////////////////////////// 16 class SK_API SkMorphologyImageFilter : public SkImageFilter { 17 public: 18 SkRect computeFastBounds(const SkRect& src) const override; 19 SkIRect onFilterNodeBounds(const SkIRect& src, const SkMatrix&, MapDirection) const override; 20 21 /** 22 * All morphology procs have the same signature: src is the source buffer, dst the 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 the 25 * number of pixels per row in each buffer. All buffers are 8888. 26 */ 27 28 typedef void (*Proc)(const SkPMColor* src, SkPMColor* dst, int radius, 29 int width, int height, int srcStride, int dstStride); 30 31 protected: 32 enum Op { 33 kErode_Op, 34 kDilate_Op, 35 }; 36 37 virtual Op op() const = 0; 38 39 SkMorphologyImageFilter(int radiusX, int radiusY, 40 sk_sp<SkImageFilter> input, 41 const CropRect* cropRect); 42 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, 43 const Context&, 44 SkIPoint* offset) const override; 45 sk_sp<SkImageFilter> onMakeColorSpace(SkColorSpaceXformer*) const override; 46 void flatten(SkWriteBuffer&) const override; 47 48 SkISize radius() const { return fRadius; } 49 50 private: 51 SkISize fRadius; 52 53 typedef SkImageFilter INHERITED; 54 }; 55 56 /////////////////////////////////////////////////////////////////////////////// 57 class SK_API SkDilateImageFilter : public SkMorphologyImageFilter { 58 public: 59 static sk_sp<SkImageFilter> Make(int radiusX, int radiusY, 60 sk_sp<SkImageFilter> input, 61 const CropRect* cropRect = nullptr); 62 63 SK_TO_STRING_OVERRIDE() 64 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDilateImageFilter) 65 66 protected: 67 Op op() const override { return kDilate_Op; } 68 69 private: 70 SkDilateImageFilter(int radiusX, int radiusY, 71 sk_sp<SkImageFilter> input, 72 const CropRect* cropRect) 73 : INHERITED(radiusX, radiusY, input, cropRect) {} 74 75 typedef SkMorphologyImageFilter INHERITED; 76 }; 77 78 /////////////////////////////////////////////////////////////////////////////// 79 class SK_API SkErodeImageFilter : public SkMorphologyImageFilter { 80 public: 81 static sk_sp<SkImageFilter> Make(int radiusX, int radiusY, 82 sk_sp<SkImageFilter> input, 83 const CropRect* cropRect = nullptr); 84 85 SK_TO_STRING_OVERRIDE() 86 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkErodeImageFilter) 87 88 protected: 89 Op op() const override { return kErode_Op; } 90 91 private: 92 SkErodeImageFilter(int radiusX, int radiusY, 93 sk_sp<SkImageFilter> input, const CropRect* cropRect) 94 : INHERITED(radiusX, radiusY, input, cropRect) {} 95 96 typedef SkMorphologyImageFilter INHERITED; 97 }; 98 99 #endif 100