• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SkFlattenable.h"
13 #include "SkImageFilter.h"
14 #include "SkSize.h"
15 
16 ///////////////////////////////////////////////////////////////////////////////
17 class SK_API SkMorphologyImageFilter : public SkImageFilter {
18 public:
19     SkRect computeFastBounds(const SkRect& src) const override;
20     SkIRect onFilterNodeBounds(const SkIRect& src, const SkMatrix& ctm,
21                                MapDirection, const SkIRect* inputRect) const override;
22 
23     /**
24      * All morphology procs have the same signature: src is the source buffer, dst the
25      * destination buffer, radius is the morphology radius, width and height are the bounds
26      * of the destination buffer (in pixels), and srcStride and dstStride are the
27      * number of pixels per row in each buffer. All buffers are 8888.
28      */
29 
30     typedef void (*Proc)(const SkPMColor* src, SkPMColor* dst, int radius,
31                          int width, int height, int srcStride, int dstStride);
32 
33 protected:
34     enum Op {
35         kErode_Op,
36         kDilate_Op,
37     };
38 
39     virtual Op op() const = 0;
40 
41     SkMorphologyImageFilter(int radiusX, int radiusY,
42                             sk_sp<SkImageFilter> input,
43                             const CropRect* cropRect);
44     sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source,
45                                         const Context&,
46                                         SkIPoint* offset) const override;
47     sk_sp<SkImageFilter> onMakeColorSpace(SkColorSpaceXformer*) const override;
48     void flatten(SkWriteBuffer&) const override;
49 
radius()50     SkISize radius() const { return fRadius; }
51 
52 private:
53     SkISize  fRadius;
54 
55     typedef SkImageFilter INHERITED;
56 };
57 
58 ///////////////////////////////////////////////////////////////////////////////
59 class SK_API SkDilateImageFilter : public SkMorphologyImageFilter {
60 public:
61     static sk_sp<SkImageFilter> Make(int radiusX, int radiusY,
62                                      sk_sp<SkImageFilter> input,
63                                      const CropRect* cropRect = nullptr);
64 
65 protected:
op()66     Op op() const override { return kDilate_Op; }
67 
68 private:
SK_FLATTENABLE_HOOKS(SkDilateImageFilter)69     SK_FLATTENABLE_HOOKS(SkDilateImageFilter)
70 
71     SkDilateImageFilter(int radiusX, int radiusY,
72                         sk_sp<SkImageFilter> input,
73                         const CropRect* cropRect)
74         : INHERITED(radiusX, radiusY, input, cropRect) {}
75 
76     typedef SkMorphologyImageFilter INHERITED;
77 };
78 
79 ///////////////////////////////////////////////////////////////////////////////
80 class SK_API SkErodeImageFilter : public SkMorphologyImageFilter {
81 public:
82     static sk_sp<SkImageFilter> Make(int radiusX, int radiusY,
83                                      sk_sp<SkImageFilter> input,
84                                      const CropRect* cropRect = nullptr);
85 
86 protected:
op()87     Op op() const override { return kErode_Op; }
88 
89 private:
SK_FLATTENABLE_HOOKS(SkErodeImageFilter)90     SK_FLATTENABLE_HOOKS(SkErodeImageFilter)
91 
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