tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 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 GrConvolutionEffect_DEFINED |
| 9 | #define GrConvolutionEffect_DEFINED |
| 10 | |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 11 | #include "Gr1DKernelEffect.h" |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 12 | |
bsalomon@google.com | ae4f96a | 2012-05-18 19:54:48 +0000 | [diff] [blame] | 13 | class GrGLConvolutionEffect; |
| 14 | |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 15 | /** |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 16 | * A convolution effect. The kernel is specified as an array of 2 * half-width |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 17 | * + 1 weights. Each texel is multiplied by it's weight and summed to determine |
| 18 | * the output color. The output color is modulated by the input color. |
| 19 | */ |
| 20 | class GrConvolutionEffect : public Gr1DKernelEffect { |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 21 | |
| 22 | public: |
| 23 | |
tomhudson@google.com | fde2c0a | 2012-07-16 12:23:32 +0000 | [diff] [blame] | 24 | /// Convolve with an arbitrary user-specified kernel |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 25 | GrConvolutionEffect(GrTexture*, Direction, |
| 26 | int halfWidth, const float* kernel = NULL); |
tomhudson@google.com | fde2c0a | 2012-07-16 12:23:32 +0000 | [diff] [blame] | 27 | |
| 28 | /// Convolve with a gaussian kernel |
| 29 | GrConvolutionEffect(GrTexture*, Direction, |
| 30 | int halfWidth, float gaussianSigma); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 31 | virtual ~GrConvolutionEffect(); |
| 32 | |
bsalomon@google.com | ae4f96a | 2012-05-18 19:54:48 +0000 | [diff] [blame] | 33 | const float* kernel() const { return fKernel; } |
bsalomon@google.com | 289efe0 | 2012-05-21 20:57:59 +0000 | [diff] [blame] | 34 | |
bsalomon@google.com | ae4f96a | 2012-05-18 19:54:48 +0000 | [diff] [blame] | 35 | static const char* Name() { return "Convolution"; } |
| 36 | |
bsalomon@google.com | 422e81a | 2012-10-25 14:11:03 +0000 | [diff] [blame] | 37 | typedef GrGLConvolutionEffect GLEffect; |
bsalomon@google.com | 289efe0 | 2012-05-21 20:57:59 +0000 | [diff] [blame] | 38 | |
bsalomon@google.com | 396e61f | 2012-10-25 19:00:29 +0000 | [diff] [blame^] | 39 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 40 | virtual bool isEqual(const GrEffect&) const SK_OVERRIDE; |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 41 | |
| 42 | enum { |
| 43 | // This was decided based on the min allowed value for the max texture |
| 44 | // samples per fragment program run in DX9SM2 (32). A sigma param of 4.0 |
| 45 | // on a blur filter gives a kernel width of 25 while a sigma of 5.0 |
| 46 | // would exceed a 32 wide kernel. |
| 47 | kMaxKernelRadius = 12, |
| 48 | // With a C++11 we could have a constexpr version of WidthFromRadius() |
| 49 | // and not have to duplicate this calculation. |
| 50 | kMaxKernelWidth = 2 * kMaxKernelRadius + 1, |
| 51 | }; |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 52 | |
| 53 | protected: |
| 54 | |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 55 | float fKernel[kMaxKernelWidth]; |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 56 | |
| 57 | private: |
bsalomon@google.com | f271cc7 | 2012-10-24 19:35:13 +0000 | [diff] [blame] | 58 | GR_DECLARE_EFFECT_TEST; |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 59 | |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 60 | typedef Gr1DKernelEffect INHERITED; |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | #endif |