SkMorphologyImageFilter.h revision 0ded88d431a1872e21986984f009db2e84f52738
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
9#ifndef SkMorphologyImageFilter_DEFINED
10#define SkMorphologyImageFilter_DEFINED
11
12#include "SkColor.h"
13#include "SkImageFilter.h"
14#include "SkSize.h"
15
16class SK_API SkMorphologyImageFilter : public SkImageFilter {
17public:
18    SkMorphologyImageFilter(int radiusX, int radiusY, SkImageFilter* input, const CropRect* cropRect);
19
20    /**
21     * All morphology procs have the same signature: src is the source buffer, dst the
22     * destination buffer, radius is the morphology radius, width and height are the bounds
23     * of the destination buffer (in pixels), and srcStride and dstStride are the
24     * number of pixels per row in each buffer. All buffers are 8888.
25     */
26
27    typedef void (*Proc)(const SkPMColor* src, SkPMColor* dst, int radius,
28                         int width, int height, int srcStride, int dstStride);
29
30protected:
31    bool filterImageGeneric(Proc procX, Proc procY,
32                            Proxy*, const SkBitmap& src, const SkMatrix&,
33                            SkBitmap* result, SkIPoint* offset);
34    SkMorphologyImageFilter(SkFlattenableReadBuffer& buffer);
35    virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
36#if SK_SUPPORT_GPU
37    virtual bool canFilterImageGPU() const SK_OVERRIDE { return true; }
38    bool filterImageGPUGeneric(bool dilate, Proxy* proxy, const SkBitmap& src,
39                               const SkMatrix& ctm, SkBitmap* result,
40                               SkIPoint* offset);
41#endif
42
43    SkISize    radius() const { return fRadius; }
44
45private:
46    SkISize    fRadius;
47    typedef SkImageFilter INHERITED;
48};
49
50class SK_API SkDilateImageFilter : public SkMorphologyImageFilter {
51public:
52    SkDilateImageFilter(int radiusX, int radiusY,
53                        SkImageFilter* input = NULL,
54                        const CropRect* cropRect = NULL)
55    : INHERITED(radiusX, radiusY, input, cropRect) {}
56
57    virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
58                               SkBitmap* result, SkIPoint* offset) SK_OVERRIDE;
59#if SK_SUPPORT_GPU
60    virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
61                                SkBitmap* result, SkIPoint* offset) SK_OVERRIDE;
62#endif
63
64    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDilateImageFilter)
65
66protected:
67    SkDilateImageFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
68
69private:
70    typedef SkMorphologyImageFilter INHERITED;
71};
72
73class SK_API SkErodeImageFilter : public SkMorphologyImageFilter {
74public:
75    SkErodeImageFilter(int radiusX, int radiusY,
76                       SkImageFilter* input = NULL,
77                       const CropRect* cropRect = NULL)
78    : INHERITED(radiusX, radiusY, input, cropRect) {}
79
80    virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
81                               SkBitmap* result, SkIPoint* offset) SK_OVERRIDE;
82#if SK_SUPPORT_GPU
83    virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
84                                SkBitmap* result, SkIPoint* offset) SK_OVERRIDE;
85#endif
86
87    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkErodeImageFilter)
88
89protected:
90    SkErodeImageFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
91
92private:
93    typedef SkMorphologyImageFilter INHERITED;
94};
95
96#endif
97