| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkMatrixConvolutionImageFilter_DEFINED | 8 #ifndef SkMatrixConvolutionImageFilter_DEFINED |
| 9 #define SkMatrixConvolutionImageFilter_DEFINED | 9 #define SkMatrixConvolutionImageFilter_DEFINED |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 class SK_API SkMatrixConvolutionImageFilter : public SkImageFilter { | 22 class SK_API SkMatrixConvolutionImageFilter : public SkImageFilter { |
| 23 public: | 23 public: |
| 24 /*! \enum TileMode */ | 24 /*! \enum TileMode */ |
| 25 enum TileMode { | 25 enum TileMode { |
| 26 kClamp_TileMode, /*!< Clamp to the image's edge pixels. */ | 26 kClamp_TileMode, /*!< Clamp to the image's edge pixels. */ |
| 27 kRepeat_TileMode, /*!< Wrap around to the image's opposite edge. */ | 27 kRepeat_TileMode, /*!< Wrap around to the image's opposite edge. */ |
| 28 kClampToBlack_TileMode, /*!< Fill with transparent black. */ | 28 kClampToBlack_TileMode, /*!< Fill with transparent black. */ |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 virtual ~SkMatrixConvolutionImageFilter(); |
| 32 |
| 31 /** Construct a matrix convolution image filter. | 33 /** Construct a matrix convolution image filter. |
| 32 @param kernelSize The kernel size in pixels, in each dimension (N by M)
. | 34 @param kernelSize The kernel size in pixels, in each dimension (N by
M). |
| 33 @param kernel The image processing kernel. Must contain N * M | 35 @param kernel The image processing kernel. Must contain N * M |
| 34 elements, in row order. | 36 elements, in row order. |
| 35 @param gain A scale factor applied to each pixel after | 37 @param gain A scale factor applied to each pixel after |
| 36 convolution. This can be used to normalize the | 38 convolution. This can be used to normalize the |
| 37 kernel, if it does not sum to 1. | 39 kernel, if it does not sum to 1. |
| 38 @param bias A bias factor added to each pixel after convolution. | 40 @param bias A bias factor added to each pixel after convolutio
n. |
| 39 @param target An offset applied to each pixel coordinate before | 41 @param kernelOffset An offset applied to each pixel coordinate before |
| 40 convolution. This can be used to center the kernel | 42 convolution. This can be used to center the kerne
l |
| 41 over the image (e.g., a 3x3 kernel should have a | 43 over the image (e.g., a 3x3 kernel should have an |
| 42 target of {1, 1}). | 44 offset of {1, 1}). |
| 43 @param tileMode How accesses outside the image are treated. (@see | 45 @param tileMode How accesses outside the image are treated. (@see |
| 44 TileMode). | 46 TileMode). |
| 45 @param convolveAlpha If true, all channels are convolved. If false, | 47 @param convolveAlpha If true, all channels are convolved. If false, |
| 46 only the RGB channels are convolved, and | 48 only the RGB channels are convolved, and |
| 47 alpha is copied from the source image. | 49 alpha is copied from the source image. |
| 48 @param input The input image filter. If NULL, the src bitmap | 50 @param input The input image filter. If NULL, the src bitmap |
| 49 passed to filterImage() is used instead. | 51 passed to filterImage() is used instead. |
| 50 @param cropRect The rectangle to which the output processing will be
limited. | 52 @param cropRect The rectangle to which the output processing will
be limited. |
| 51 */ | 53 */ |
| 52 | 54 static SkMatrixConvolutionImageFilter* Create(const SkISize& kernelSize, |
| 53 SkMatrixConvolutionImageFilter(const SkISize& kernelSize, | 55 const SkScalar* kernel, |
| 54 const SkScalar* kernel, | 56 SkScalar gain, |
| 55 SkScalar gain, | 57 SkScalar bias, |
| 56 SkScalar bias, | 58 const SkIPoint& kernelOffset, |
| 57 const SkIPoint& target, | 59 TileMode tileMode, |
| 58 TileMode tileMode, | 60 bool convolveAlpha, |
| 59 bool convolveAlpha, | 61 SkImageFilter* input = NULL, |
| 60 SkImageFilter* input = NULL, | 62 const CropRect* cropRect = NUL
L) { |
| 61 const CropRect* cropRect = NULL); | 63 return SkNEW_ARGS(SkMatrixConvolutionImageFilter, (kernelSize, kernel, g
ain, bias, |
| 62 virtual ~SkMatrixConvolutionImageFilter(); | 64 kernelOffset, tileMod
e, convolveAlpha, |
| 65 input, cropRect)); |
| 66 } |
| 63 | 67 |
| 64 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMatrixConvolutionImage
Filter) | 68 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMatrixConvolutionImage
Filter) |
| 65 | 69 |
| 66 protected: | 70 protected: |
| 67 SkMatrixConvolutionImageFilter(SkReadBuffer& buffer); | 71 SkMatrixConvolutionImageFilter(SkReadBuffer& buffer); |
| 68 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | 72 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
| 69 | 73 |
| 70 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, | 74 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, |
| 71 SkBitmap* result, SkIPoint* loc) const SK_OVERRID
E; | 75 SkBitmap* result, SkIPoint* loc) const SK_OVERRID
E; |
| 72 | 76 |
| 73 #if SK_SUPPORT_GPU | 77 #if SK_SUPPORT_GPU |
| 74 virtual bool asNewEffect(GrEffectRef** effect, | 78 virtual bool asNewEffect(GrEffectRef** effect, |
| 75 GrTexture*, | 79 GrTexture*, |
| 76 const SkMatrix& matrix, | 80 const SkMatrix& matrix, |
| 77 const SkIRect& bounds) const SK_OVERRIDE; | 81 const SkIRect& bounds) const SK_OVERRIDE; |
| 78 #endif | 82 #endif |
| 79 | 83 |
| 84 #ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS |
| 85 public: |
| 86 #endif |
| 87 SkMatrixConvolutionImageFilter(const SkISize& kernelSize, |
| 88 const SkScalar* kernel, |
| 89 SkScalar gain, |
| 90 SkScalar bias, |
| 91 const SkIPoint& kernelOffset, |
| 92 TileMode tileMode, |
| 93 bool convolveAlpha, |
| 94 SkImageFilter* input = NULL, |
| 95 const CropRect* cropRect = NULL); |
| 96 |
| 80 private: | 97 private: |
| 81 SkISize fKernelSize; | 98 SkISize fKernelSize; |
| 82 SkScalar* fKernel; | 99 SkScalar* fKernel; |
| 83 SkScalar fGain; | 100 SkScalar fGain; |
| 84 SkScalar fBias; | 101 SkScalar fBias; |
| 85 SkIPoint fTarget; | 102 SkIPoint fKernelOffset; |
| 86 TileMode fTileMode; | 103 TileMode fTileMode; |
| 87 bool fConvolveAlpha; | 104 bool fConvolveAlpha; |
| 88 typedef SkImageFilter INHERITED; | 105 typedef SkImageFilter INHERITED; |
| 89 | 106 |
| 90 template <class PixelFetcher, bool convolveAlpha> | 107 template <class PixelFetcher, bool convolveAlpha> |
| 91 void filterPixels(const SkBitmap& src, | 108 void filterPixels(const SkBitmap& src, |
| 92 SkBitmap* result, | 109 SkBitmap* result, |
| 93 const SkIRect& rect, | 110 const SkIRect& rect, |
| 94 const SkIRect& bounds) const; | 111 const SkIRect& bounds) const; |
| 95 template <class PixelFetcher> | 112 template <class PixelFetcher> |
| 96 void filterPixels(const SkBitmap& src, | 113 void filterPixels(const SkBitmap& src, |
| 97 SkBitmap* result, | 114 SkBitmap* result, |
| 98 const SkIRect& rect, | 115 const SkIRect& rect, |
| 99 const SkIRect& bounds) const; | 116 const SkIRect& bounds) const; |
| 100 void filterInteriorPixels(const SkBitmap& src, | 117 void filterInteriorPixels(const SkBitmap& src, |
| 101 SkBitmap* result, | 118 SkBitmap* result, |
| 102 const SkIRect& rect, | 119 const SkIRect& rect, |
| 103 const SkIRect& bounds) const; | 120 const SkIRect& bounds) const; |
| 104 void filterBorderPixels(const SkBitmap& src, | 121 void filterBorderPixels(const SkBitmap& src, |
| 105 SkBitmap* result, | 122 SkBitmap* result, |
| 106 const SkIRect& rect, | 123 const SkIRect& rect, |
| 107 const SkIRect& bounds) const; | 124 const SkIRect& bounds) const; |
| 108 }; | 125 }; |
| 109 | 126 |
| 110 #endif | 127 #endif |
| OLD | NEW |