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