Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright 2017 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 SkGaussFilter_DEFINED
      9 #define SkGaussFilter_DEFINED
     10 
     11 #include <cstddef>
     12 
     13 // Define gaussian filters for values of sigma < 2. Produce values good to 1 part in 1,000,000.
     14 // Gaussian produces values as defined in the SVG 1.1 spec:
     15 // https://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement
     16 // Bessel produces values as defined in "Scale-Space for Discrete Signals" by Tony Lindeberg
     17 class SkGaussFilter {
     18 public:
     19     static constexpr int kGaussArrayMax = 6;
     20     enum class Type : bool {
     21         Gaussian,
     22         Bessel
     23     };
     24 
     25     // Type selects which method is used to calculate the gaussian factors.
     26     SkGaussFilter(double sigma, Type type);
     27 
     28     size_t size()   const { return fN; }
     29     int radius() const { return fN - 1; }
     30     int width()  const { return 2 * this->radius() + 1; }
     31 
     32     // Allow a filter to be used in a C++ ranged-for loop.
     33     const double* begin() const { return &fBasis[0];  }
     34     const double* end()   const { return &fBasis[fN]; }
     35 
     36 private:
     37     double fBasis[kGaussArrayMax];
     38     int    fN;
     39 };
     40 
     41 #endif  // SkGaussFilter_DEFINED
     42