Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkMatrixConvolutionImageFilter.h
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 "SkImageFilter.h"
12 #include "SkScalar.h"
13 #include "SkSize.h"
14 #include "SkPoint.h"
15 
16 class SkBitmap;
17 
25 public:
27  enum TileMode {
28  kClamp_TileMode = 0,
31  kMax_TileMode = kClampToBlack_TileMode
32  };
33 
35 
57  static sk_sp<SkImageFilter> Make(const SkISize& kernelSize,
58  const SkScalar* kernel,
59  SkScalar gain,
60  SkScalar bias,
61  const SkIPoint& kernelOffset,
62  TileMode tileMode,
63  bool convolveAlpha,
65  const CropRect* cropRect = nullptr);
66 
67  SK_TO_STRING_OVERRIDE()
68  SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMatrixConvolutionImageFilter)
69 
70 #ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
71  static SkImageFilter* Create(const SkISize& kernelSize,
72  const SkScalar* kernel,
73  SkScalar gain,
74  SkScalar bias,
75  const SkIPoint& kernelOffset,
76  TileMode tileMode,
77  bool convolveAlpha,
78  SkImageFilter* input = NULL,
79  const CropRect* cropRect = NULL) {
80  return Make(kernelSize, kernel, gain, bias, kernelOffset, tileMode, convolveAlpha,
81  sk_ref_sp<SkImageFilter>(input), cropRect).release();
82  }
83 #endif
84 
85 protected:
86  SkMatrixConvolutionImageFilter(const SkISize& kernelSize,
87  const SkScalar* kernel,
88  SkScalar gain,
89  SkScalar bias,
90  const SkIPoint& kernelOffset,
91  TileMode tileMode,
92  bool convolveAlpha,
94  const CropRect* cropRect);
95  void flatten(SkWriteBuffer&) const override;
96 
97  sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
98  SkIPoint* offset) const override;
99  SkIRect onFilterNodeBounds(const SkIRect&, const SkMatrix&, MapDirection) const override;
100  bool affectsTransparentBlack() const override;
101 
102 private:
103  SkISize fKernelSize;
104  SkScalar* fKernel;
105  SkScalar fGain;
106  SkScalar fBias;
107  SkIPoint fKernelOffset;
108  TileMode fTileMode;
109  bool fConvolveAlpha;
110 
111  template <class PixelFetcher, bool convolveAlpha>
112  void filterPixels(const SkBitmap& src,
113  SkBitmap* result,
114  const SkIRect& rect,
115  const SkIRect& bounds) const;
116  template <class PixelFetcher>
117  void filterPixels(const SkBitmap& src,
118  SkBitmap* result,
119  const SkIRect& rect,
120  const SkIRect& bounds) const;
121  void filterInteriorPixels(const SkBitmap& src,
122  SkBitmap* result,
123  const SkIRect& rect,
124  const SkIRect& bounds) const;
125  void filterBorderPixels(const SkBitmap& src,
126  SkBitmap* result,
127  const SkIRect& rect,
128  const SkIRect& bounds) const;
129 
130  typedef SkImageFilter INHERITED;
131 };
132 
133 #endif
void flatten(SkWriteBuffer &) const override
Override this if your subclass needs to record data that it will need to recreate itself from its Cre...
TileMode
Definition: SkMatrixConvolutionImageFilter.h:27
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:26
virtual sk_sp< SkSpecialImage > onFilterImage(SkSpecialImage *src, const Context &, SkIPoint *offset) const =0
This is the virtual which should be overridden by the derived class to perform image filtering...
Definition: SkMatrixConvolutionImageFilter.h:24
The SkBitmap class specifies a raster bitmap.
Definition: SkBitmap.h:41
Base class for image filters.
Definition: SkImageFilter.h:35
Definition: SkWriteBuffer.h:26
virtual SkIRect onFilterNodeBounds(const SkIRect &, const SkMatrix &, MapDirection) const
Performs a forwards or reverse mapping of the given rect to accommodate this filter's margin requirem...
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20
Definition: SkMatrixConvolutionImageFilter.h:30
SkIPoint holds two 32 bit integer coordinates.
Definition: SkPoint.h:40
Definition: SkMatrixConvolutionImageFilter.h:29