2 * Copyright 2012 The Android Open Source Project
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkMatrixConvolutionImageFilter_DEFINED
9 #define SkMatrixConvolutionImageFilter_DEFINED
11 #include "SkImageFilter.h"
16 /*! \class SkMatrixConvolutionImageFilter
17 Matrix convolution image filter. This filter applies an NxM image
18 processing kernel to a given input image. This can be used to produce
19 effects such as sharpening, blurring, edge detection, etc.
22 class SK_API SkMatrixConvolutionImageFilter : public SkImageFilter {
26 kClamp_TileMode, /*!< Clamp to the image's edge pixels. */
27 kRepeat_TileMode, /*!< Wrap around to the image's opposite edge. */
28 kClampToBlack_TileMode, /*!< Fill with transparent black. */
31 /** Construct a matrix convolution image filter.
32 @param kernelSize The kernel size in pixels, in each dimension (N by M).
33 @param kernel The image processing kernel. Must contain N * M
34 elements, in row order.
35 @param gain A scale factor applied to each pixel after
36 convolution. This can be used to normalize the
37 kernel, if it does not sum to 1.
38 @param bias A bias factor added to each pixel after convolution.
39 @param target An offset applied to each pixel coordinate before
40 convolution. This can be used to center the kernel
41 over the image (e.g., a 3x3 kernel should have a
43 @param tileMode How accesses outside the image are treated. (@see
45 @param convolveAlpha If true, all channels are convolved. If false,
46 only the RGB channels are convolved, and
47 alpha is copied from the source image.
48 @param input The input image filter. If NULL, the src bitmap
49 passed to filterImage() is used instead.
50 @param cropRect The rectangle to which the output processing will be limited.
53 SkMatrixConvolutionImageFilter(const SkISize& kernelSize,
54 const SkScalar* kernel,
57 const SkIPoint& target,
60 SkImageFilter* input = NULL,
61 const CropRect* cropRect = NULL);
62 virtual ~SkMatrixConvolutionImageFilter();
64 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMatrixConvolutionImageFilter)
67 SkMatrixConvolutionImageFilter(SkReadBuffer& buffer);
68 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
70 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
71 SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE;
74 virtual bool asNewEffect(GrEffectRef** effect,
76 const SkMatrix& matrix,
77 const SkIRect& bounds) const SK_OVERRIDE;
88 typedef SkImageFilter INHERITED;
90 template <class PixelFetcher, bool convolveAlpha>
91 void filterPixels(const SkBitmap& src,
94 const SkIRect& bounds) const;
95 template <class PixelFetcher>
96 void filterPixels(const SkBitmap& src,
99 const SkIRect& bounds) const;
100 void filterInteriorPixels(const SkBitmap& src,
103 const SkIRect& bounds) const;
104 void filterBorderPixels(const SkBitmap& src,
107 const SkIRect& bounds) const;