senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 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 | |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 8 | #ifndef SkMorphologyImageFilter_DEFINED |
| 9 | #define SkMorphologyImageFilter_DEFINED |
| 10 | |
senorblanco@chromium.org | 0ded88d | 2014-01-24 15:43:50 +0000 | [diff] [blame] | 11 | #include "SkColor.h" |
senorblanco@chromium.org | 377c14a | 2013-02-04 22:57:21 +0000 | [diff] [blame] | 12 | #include "SkImageFilter.h" |
senorblanco@chromium.org | bf2768b | 2012-08-20 15:43:14 +0000 | [diff] [blame] | 13 | #include "SkSize.h" |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 14 | |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 15 | /////////////////////////////////////////////////////////////////////////////// |
schenney | 95376a0 | 2015-10-06 12:59:55 -0700 | [diff] [blame] | 16 | class SK_API SkMorphologyImageFilter : public SkImageFilter { |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 17 | public: |
senorblanco | e5e7984 | 2016-03-21 14:51:59 -0700 | [diff] [blame] | 18 | SkRect computeFastBounds(const SkRect& src) const override; |
| 19 | SkIRect onFilterNodeBounds(const SkIRect& src, const SkMatrix&, MapDirection) const override; |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 20 | |
senorblanco@chromium.org | 0ded88d | 2014-01-24 15:43:50 +0000 | [diff] [blame] | 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 | |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 31 | protected: |
robertphillips | 40d8d62 | 2016-03-30 08:09:56 -0700 | [diff] [blame] | 32 | enum Op { |
| 33 | kErode_Op, |
| 34 | kDilate_Op, |
| 35 | }; |
| 36 | |
| 37 | virtual Op op() const = 0; |
| 38 | |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 39 | SkMorphologyImageFilter(int radiusX, int radiusY, |
| 40 | sk_sp<SkImageFilter> input, |
senorblanco | 24e06d5 | 2015-03-18 12:11:33 -0700 | [diff] [blame] | 41 | const CropRect* cropRect); |
robertphillips | 40d8d62 | 2016-03-30 08:09:56 -0700 | [diff] [blame] | 42 | sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, |
| 43 | const Context&, |
| 44 | SkIPoint* offset) const override; |
Matt Sarett | 6d72ed9 | 2017-04-10 16:35:33 -0400 | [diff] [blame^] | 45 | sk_sp<SkImageFilter> onMakeColorSpace(SkColorSpaceXformer*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 46 | void flatten(SkWriteBuffer&) const override; |
djsollen@google.com | 5492424 | 2012-03-29 15:18:04 +0000 | [diff] [blame] | 47 | |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 48 | SkISize radius() const { return fRadius; } |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 49 | |
| 50 | private: |
robertphillips | 40d8d62 | 2016-03-30 08:09:56 -0700 | [diff] [blame] | 51 | SkISize fRadius; |
| 52 | |
senorblanco@chromium.org | 377c14a | 2013-02-04 22:57:21 +0000 | [diff] [blame] | 53 | typedef SkImageFilter INHERITED; |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 56 | /////////////////////////////////////////////////////////////////////////////// |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 57 | class SK_API SkDilateImageFilter : public SkMorphologyImageFilter { |
| 58 | public: |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 59 | static sk_sp<SkImageFilter> Make(int radiusX, int radiusY, |
| 60 | sk_sp<SkImageFilter> input, |
robertphillips | 225db44 | 2016-04-17 14:27:05 -0700 | [diff] [blame] | 61 | const CropRect* cropRect = nullptr); |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 62 | |
robertphillips | f3f5bad | 2014-12-19 13:49:15 -0800 | [diff] [blame] | 63 | SK_TO_STRING_OVERRIDE() |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 64 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDilateImageFilter) |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 65 | |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 66 | protected: |
robertphillips | 40d8d62 | 2016-03-30 08:09:56 -0700 | [diff] [blame] | 67 | Op op() const override { return kDilate_Op; } |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 68 | |
reed | 5ea95df | 2015-10-06 14:05:32 -0700 | [diff] [blame] | 69 | private: |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 70 | SkDilateImageFilter(int radiusX, int radiusY, |
| 71 | sk_sp<SkImageFilter> input, |
| 72 | const CropRect* cropRect) |
senorblanco | 24e06d5 | 2015-03-18 12:11:33 -0700 | [diff] [blame] | 73 | : INHERITED(radiusX, radiusY, input, cropRect) {} |
reed | 5ea95df | 2015-10-06 14:05:32 -0700 | [diff] [blame] | 74 | |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 75 | typedef SkMorphologyImageFilter INHERITED; |
| 76 | }; |
| 77 | |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 78 | /////////////////////////////////////////////////////////////////////////////// |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 79 | class SK_API SkErodeImageFilter : public SkMorphologyImageFilter { |
| 80 | public: |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 81 | static sk_sp<SkImageFilter> Make(int radiusX, int radiusY, |
| 82 | sk_sp<SkImageFilter> input, |
robertphillips | 225db44 | 2016-04-17 14:27:05 -0700 | [diff] [blame] | 83 | const CropRect* cropRect = nullptr); |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 84 | |
robertphillips | f3f5bad | 2014-12-19 13:49:15 -0800 | [diff] [blame] | 85 | SK_TO_STRING_OVERRIDE() |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 86 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkErodeImageFilter) |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 87 | |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 88 | protected: |
robertphillips | 40d8d62 | 2016-03-30 08:09:56 -0700 | [diff] [blame] | 89 | Op op() const override { return kErode_Op; } |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 90 | |
reed | 5ea95df | 2015-10-06 14:05:32 -0700 | [diff] [blame] | 91 | private: |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 92 | SkErodeImageFilter(int radiusX, int radiusY, |
| 93 | sk_sp<SkImageFilter> input, const CropRect* cropRect) |
senorblanco | 24e06d5 | 2015-03-18 12:11:33 -0700 | [diff] [blame] | 94 | : INHERITED(radiusX, radiusY, input, cropRect) {} |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 95 | |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 96 | typedef SkMorphologyImageFilter INHERITED; |
| 97 | }; |
| 98 | |
| 99 | #endif |