1 /* === S Y N F I G ========================================================= */ 2 /*! \file synfig/rendering/software/function/blur.h 3 ** \brief Blur Header 4 ** 5 ** $Id$ 6 ** 7 ** \legal 8 ** ......... ... 2015 Ivan Mahonin 9 ** 10 ** This package is free software; you can redistribute it and/or 11 ** modify it under the terms of the GNU General Public License as 12 ** published by the Free Software Foundation; either version 2 of 13 ** the License, or (at your option) any later version. 14 ** 15 ** This package is distributed in the hope that it will be useful, 16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 ** General Public License for more details. 19 ** \endlegal 20 */ 21 /* ========================================================================= */ 22 23 /* === S T A R T =========================================================== */ 24 25 #ifndef __SYNFIG_RENDERING_SOFTWARE_BLUR_H 26 #define __SYNFIG_RENDERING_SOFTWARE_BLUR_H 27 28 /* === H E A D E R S ======================================================= */ 29 30 #include <vector> 31 32 #include "../../primitive/blur.h" 33 34 #include <synfig/vector.h> 35 #include <synfig/complex.h> 36 #include <synfig/surface.h> 37 38 /* === M A C R O S ========================================================= */ 39 40 /* === T Y P E D E F S ===================================================== */ 41 42 /* === C L A S S E S & S T R U C T S ======================================= */ 43 44 namespace synfig 45 { 46 namespace rendering 47 { 48 namespace software 49 { 50 51 class Blur 52 { 53 public: 54 class Params { 55 public: 56 synfig::Surface *dest; 57 RectInt dest_rect; 58 const synfig::Surface *src; 59 VectorInt src_offset; 60 RectInt src_rect; 61 rendering::Blur::Type type; 62 Vector size; 63 Vector amplified_size; 64 VectorInt extra_size; 65 VectorInt offset; 66 bool blend; 67 Color::BlendMethod blend_method; 68 ColorReal amount; 69 Params()70 Params(): dest(), src(), blend(), blend_method(), amount() { } Params(synfig::Surface & dest,const RectInt & dest_rect,const synfig::Surface & src,const VectorInt src_offset,rendering::Blur::Type type,const Vector & size,bool blend,Color::BlendMethod blend_method,ColorReal amount)71 Params( 72 synfig::Surface &dest, 73 const RectInt &dest_rect, 74 const synfig::Surface &src, 75 const VectorInt src_offset, 76 rendering::Blur::Type type, 77 const Vector &size, 78 bool blend, 79 Color::BlendMethod blend_method, 80 ColorReal amount 81 ): 82 dest(&dest), 83 dest_rect(dest_rect), 84 src(&src), 85 src_offset(src_offset), 86 type(type), 87 size(size), 88 blend(blend), 89 blend_method(blend_method), 90 amount(amount) 91 { } 92 93 bool validate(); 94 }; 95 96 class IIRCoefficients 97 { 98 public: 99 union { 100 struct { Real k0, k1, k2, k3; }; 101 struct { Real k[4]; }; 102 }; IIRCoefficients()103 IIRCoefficients(): k0(), k1(), k2(), k3() { } 104 }; 105 106 static Real get_size_amplifier(rendering::Blur::Type type); 107 static Real get_extra_size(rendering::Blur::Type type); 108 static VectorInt get_extra_size(rendering::Blur::Type type, const Vector &size); 109 110 private: 111 static const Real iir_min_radius; 112 static const Real iir_max_radius; 113 static const Real iir_radius_step; 114 static const Real iir_coefficients_unprepared[][3]; 115 116 static IIRCoefficients get_iir_coefficients(Real radius); 117 118 //! Simple blur by pattern 119 static void blur_pattern(const Params ¶ms); 120 121 //! Full-size blur using Furier transform 122 static void blur_fft(const Params ¶ms); 123 124 //! Fast box-blur 125 static void blur_box(const Params ¶ms); 126 127 //! Blur using infinite impulse response filter (gaussian only) 128 static void blur_iir(const Params ¶ms); 129 130 public: 131 //! Generic blur function 132 static void blur(Params params); 133 }; 134 135 } /* end namespace software */ 136 } /* end namespace rendering */ 137 } /* end namespace synfig */ 138 139 /* -- E N D ----------------------------------------------------------------- */ 140 141 #endif 142