diff options
author | 2012-09-18 20:32:34 +0000 | |
---|---|---|
committer | 2012-09-18 20:32:34 +0000 | |
commit | 5faa2dc266ec933b3961f985e5718236f1ecbe47 (patch) | |
tree | c8c50ad2e8667e89aacadb5f8d0f242ba888097b /include/effects/SkMatrixConvolutionImageFilter.h | |
parent | d1688744d537d928699b6069f99c4470a0f6e772 (diff) |
Implements a matrix convolution filter (raster path only). The filtering loop
is templated on the tiling mode for speed: interior pixels are unconditionally
fetched; border pixels apply the appropriate tiling mode before fetching. It
handles target, bias, divisor (as gain), and edge modes (named to be more
skia-like). It does not handle the "preserveAlpha" semantics of
feConvolveMatrix, nor "kernelUnitLength".
git-svn-id: http://skia.googlecode.com/svn/trunk@5592 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/effects/SkMatrixConvolutionImageFilter.h')
-rw-r--r-- | include/effects/SkMatrixConvolutionImageFilter.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/include/effects/SkMatrixConvolutionImageFilter.h b/include/effects/SkMatrixConvolutionImageFilter.h new file mode 100644 index 0000000000..4409ebd40e --- /dev/null +++ b/include/effects/SkMatrixConvolutionImageFilter.h @@ -0,0 +1,76 @@ +/* + * Copyright 2012 The Android Open Source Project + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkMatrixConvolutionImageFilter_DEFINED +#define SkMatrixConvolutionImageFilter_DEFINED + +#include "SkSingleInputImageFilter.h" +#include "SkScalar.h" +#include "SkSize.h" +#include "SkPoint.h" + +/*! \class SkMatrixConvolutionImageFilter + Matrix convolution image filter. This filter applies an NxM image + processing kernel to a given input image. This can be used to produce + effects such as sharpening, blurring, edge detection, etc. + */ + +class SkMatrixConvolutionImageFilter : public SkSingleInputImageFilter { +public: + /*! \enum TileMode */ + enum TileMode { + kClamp_TileMode, /*!< Clamp to the image's edge pixels. */ + kRepeat_TileMode, /*!< Wrap around to the image's opposite edge. */ + kClampToBlack_TileMode, /*!< Fill with transparent black. */ + }; + + /** Construct a matrix convolution image filter. + @param kernelSize The kernel size in pixels, in each dimension (N by M). + @param kernel The image processing kernel. Must contain N * M + elements, in row order. + @param gain A scale factor applied to each pixel after + convolution. This can be used to normalize the + kernel, if it does not sum to 1. + @param bias A bias factor added to each pixel after convolution. + @param target An offset applied to each pixel coordinate before + convolution. This can be used to center the kernel + over the image (e.g., a 3x3 kernel should have a + target of {1, 1}). + @param tileMode How accesses outside the image are treated. (@see + TileMode). + @param input The input image filter. If NULL, the src bitmap + passed to filterImage() is used instead. + */ + + SkMatrixConvolutionImageFilter(const SkISize& kernelSize, const SkScalar* kernel, SkScalar gain, SkScalar bias, const SkIPoint& target, TileMode tileMode, SkImageFilter* input = NULL); + virtual ~SkMatrixConvolutionImageFilter(); + + SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMatrixConvolutionImageFilter) + +protected: + SkMatrixConvolutionImageFilter(SkFlattenableReadBuffer& buffer); + virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; + + virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, + SkBitmap* result, SkIPoint* loc) SK_OVERRIDE; + +private: + SkISize fKernelSize; + SkScalar* fKernel; + SkScalar fGain; + SkScalar fBias; + SkIPoint fTarget; + TileMode fTileMode; + typedef SkSingleInputImageFilter INHERITED; + + template <class PixelFetcher> + void filterPixels(const SkBitmap& src, SkBitmap* result, const SkIRect& rect); + void filterInteriorPixels(const SkBitmap& src, SkBitmap* result, const SkIRect& rect); + void filterBorderPixels(const SkBitmap& src, SkBitmap* result, const SkIRect& rect); +}; + +#endif |