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 SkMatrixConvolutionImageFilter_DEFINED |
9 | #define SkMatrixConvolutionImageFilter_DEFINED |
10 | |
11 | #include "include/core/SkImageFilter.h" |
12 | #include "include/core/SkPoint.h" |
13 | #include "include/core/SkScalar.h" |
14 | #include "include/core/SkSize.h" |
15 | |
16 | class SkBitmap; |
17 | enum class SkTileMode; |
18 | |
19 | /*! \class SkMatrixConvolutionImageFilter |
20 | Matrix convolution image filter. This filter applies an NxM image |
21 | processing kernel to a given input image. This can be used to produce |
22 | effects such as sharpening, blurring, edge detection, etc. |
23 | |
24 | DEPRECATED: Use include/effects/SkImageFilters::MatrixConvolution |
25 | */ |
26 | |
27 | class SK_API SkMatrixConvolutionImageFilter { |
28 | public: |
29 | /*! \enum TileMode |
30 | * DEPRECATED: Use SkTileMode instead. */ |
31 | enum TileMode { |
32 | kClamp_TileMode = 0, /*!< Clamp to the image's edge pixels. */ |
33 | kRepeat_TileMode, /*!< Wrap around to the image's opposite edge. */ |
34 | kClampToBlack_TileMode, /*!< Fill with transparent black. */ |
35 | kLast_TileMode = kClampToBlack_TileMode, |
36 | |
37 | // TODO: remove kMax - it is non-standard but used by Chromium! |
38 | kMax_TileMode = kClampToBlack_TileMode |
39 | }; |
40 | |
41 | static sk_sp<SkImageFilter> Make(const SkISize& kernelSize, |
42 | const SkScalar* kernel, |
43 | SkScalar gain, |
44 | SkScalar bias, |
45 | const SkIPoint& kernelOffset, |
46 | TileMode tileMode, |
47 | bool convolveAlpha, |
48 | sk_sp<SkImageFilter> input, |
49 | const SkImageFilter::CropRect* cropRect = nullptr); |
50 | |
51 | /** Construct a matrix convolution image filter. |
52 | @param kernelSize The kernel size in pixels, in each dimension (N by M). |
53 | @param kernel The image processing kernel. Must contain N * M |
54 | elements, in row order. |
55 | @param gain A scale factor applied to each pixel after |
56 | convolution. This can be used to normalize the |
57 | kernel, if it does not sum to 1. |
58 | @param bias A bias factor added to each pixel after convolution. |
59 | @param kernelOffset An offset applied to each pixel coordinate before |
60 | convolution. This can be used to center the kernel |
61 | over the image (e.g., a 3x3 kernel should have an |
62 | offset of {1, 1}). |
63 | @param tileMode How accesses outside the image are treated. (@see |
64 | TileMode). EXPERIMENTAL: kMirror not supported yet. |
65 | @param convolveAlpha If true, all channels are convolved. If false, |
66 | only the RGB channels are convolved, and |
67 | alpha is copied from the source image. |
68 | @param input The input image filter. If NULL, the src bitmap |
69 | passed to filterImage() is used instead. |
70 | @param cropRect The rectangle to which the output processing will be limited. |
71 | */ |
72 | static sk_sp<SkImageFilter> Make(const SkISize& kernelSize, |
73 | const SkScalar* kernel, |
74 | SkScalar gain, |
75 | SkScalar bias, |
76 | const SkIPoint& kernelOffset, |
77 | SkTileMode tileMode, |
78 | bool convolveAlpha, |
79 | sk_sp<SkImageFilter> input, |
80 | const SkImageFilter::CropRect* cropRect = nullptr); |
81 | |
82 | static void RegisterFlattenables(); |
83 | |
84 | private: |
85 | SkMatrixConvolutionImageFilter() = delete; |
86 | }; |
87 | |
88 | #endif |
89 | |