Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/freestyle/intern/image/GaussianFilter.h')
-rwxr-xr-xsource/blender/freestyle/intern/image/GaussianFilter.h146
1 files changed, 146 insertions, 0 deletions
diff --git a/source/blender/freestyle/intern/image/GaussianFilter.h b/source/blender/freestyle/intern/image/GaussianFilter.h
new file mode 100755
index 00000000000..be0e3e2bada
--- /dev/null
+++ b/source/blender/freestyle/intern/image/GaussianFilter.h
@@ -0,0 +1,146 @@
+//
+// Filename : Image.h
+// Author(s) : Stephane Grabli
+// Purpose : Class to perform gaussian filtering operations on an image
+// Date of creation : 20/05/2003
+//
+///////////////////////////////////////////////////////////////////////////////
+
+
+//
+// Copyright (C) : Please refer to the COPYRIGHT file distributed
+// with this source distribution.
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef GAUSSIANFILTER_H
+# define GAUSSIANFILTER_H
+
+#include <string.h> // for memcpy
+#include <cstdlib> // for abs
+#include "../system/FreestyleConfig.h"
+
+class LIB_IMAGE_EXPORT GaussianFilter{
+protected:
+ /* the mask is a symetrical 2d array (with respect
+ to the middle point).
+ Thus, M(i,j) = M(-i,j) = M(i,-j) = M(-i,-j).
+ For this reason, to represent a NxN array (N odd), we only store
+ a ((N+1)/2)x((N+1)/2) array.
+ */
+ float _sigma;
+ float *_mask;
+ int _bound;
+ int _maskSize; // the real mask size (must be odd)(the size of the mask we store is ((_maskSize+1)/2)*((_maskSize+1)/2))
+ int _storedMaskSize; //(_maskSize+1)/2)
+
+public:
+ GaussianFilter(float iSigma = 1.f) ;
+ GaussianFilter(const GaussianFilter&) ;
+ GaussianFilter& operator= (const GaussianFilter&) ;
+ virtual ~GaussianFilter() ;
+
+ /*! Returns the value for pixel x,y of image "map" after a gaussian blur,
+ * made using the sigma value.
+ * The sigma value determines the mask size (~ 2 x sigma).
+ * \param map
+ * The image we wish to work on. The Map template must implement the
+ * foloowing methods:
+ * - float pixel(unsigned int x,unsigned int y) const;
+ * - unsigned width() const;
+ * - unsigned height() const;
+ * \param x
+ * The abscissa of the pixel where we want to evaluate the gaussian blur.
+ * \param y
+ * The ordinate of the pixel where we want to evaluate the gaussian blur.
+ * \param sigma
+ * The sigma value of the gaussian function.
+ */
+ template<class Map>
+ float getSmoothedPixel(Map * map, int x, int y) ;
+
+ /*! Compute the mask size and returns the REAL mask size ((2*_maskSize)-1)
+ * This method is provided for convenience.
+ */
+ static int computeMaskSize(float sigma) ;
+
+ /*! accessors */
+ inline float sigma() const {return _sigma;}
+ inline int maskSize() const {return _maskSize;}
+ inline int getBound() {return _bound;}
+
+ /*! modifiers */
+ void setSigma(float sigma) ;
+ // void SetMaskSize(int size) {_maskSize = size;_storedMaskSize=(_maskSize+1)>>1;}
+
+
+protected:
+ void computeMask();
+};
+
+/*
+
+ #############################################
+ #############################################
+ #############################################
+ ###### ######
+ ###### I M P L E M E N T A T I O N ######
+ ###### ######
+ #############################################
+ #############################################
+ #############################################
+
+*/
+
+
+#include <math.h>
+
+#ifdef __MACH__
+#define sqrtf(x) (sqrt(x))
+#endif
+
+template<class Map>
+float GaussianFilter::getSmoothedPixel(Map * map, int x, int y)
+{
+ float sum = 0.f;
+ float L=0.f;
+ int w = (int)map->width(); //soc
+ int h = (int)map->height(); //soc
+
+ // Current pixel is x,y
+ // Sum surrounding pixels L value:
+ for(int i=-_bound; i<=_bound; ++i)
+ {
+ if((y+i < 0) || (y+i >= h))
+ continue;
+ for(int j=-_bound; j<=_bound; ++j)
+ {
+ if((x+j < 0) || (x+j >= w))
+ continue;
+
+ float tmpL = map->pixel(x+j,y+i);
+ float m = _mask[abs(i)*_storedMaskSize+abs(j)];
+ L += m*tmpL;
+ sum += m;
+ }
+ }
+ //L /= sum;
+ return L;
+}
+
+
+#endif // GAUSSIANFILTER