[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55444] trunk/blender/source/blender/ compositor/operations/COM_GaussianBokehBlurOperation.cpp: Fix #34694. This was actually a bug in the compositor's Bokeh Blur operation. It was writing outside of allocated memory in case of (0, 0) size buffers, with the usual unpredictable results.

Lukas Toenne lukas.toenne at googlemail.com
Wed Mar 20 16:54:17 CET 2013


Revision: 55444
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55444
Author:   lukastoenne
Date:     2013-03-20 15:54:16 +0000 (Wed, 20 Mar 2013)
Log Message:
-----------
Fix #34694. This was actually a bug in the compositor's Bokeh Blur operation. It was writing outside of allocated memory in case of (0, 0) size buffers, with the usual unpredictable results.

Modified Paths:
--------------
    trunk/blender/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp

Modified: trunk/blender/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp	2013-03-20 15:01:15 UTC (rev 55443)
+++ trunk/blender/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp	2013-03-20 15:54:16 UTC (rev 55444)
@@ -62,7 +62,6 @@
 		int n;
 		float *dgauss;
 		float *ddgauss;
-		float val;
 		int j, i;
 		const float width = this->getWidth();
 		const float height = this->getHeight();
@@ -84,13 +83,15 @@
 	
 		this->m_radx = ceil(radxf);
 		this->m_rady = ceil(radyf);
+		
+		int ddwidth = 2 * this->m_radx + 1;
+		int ddheight = 2 * this->m_rady + 1;
+		n = ddwidth * ddheight;
 	
-		n = (2 * this->m_radx + 1) * (2 * this->m_rady + 1);
-	
 		/* create a full filter image */
 		ddgauss = (float *)MEM_mallocN(sizeof(float) * n, __func__);
 		dgauss = ddgauss;
-		val = 0.0f;
+		float sum = 0.0f;
 		for (j = -this->m_rady; j <= this->m_rady; j++) {
 			for (i = -this->m_radx; i <= this->m_radx; i++, dgauss++) {
 				float fj = (float)j / radyf;
@@ -98,16 +99,19 @@
 				float dist = sqrt(fj * fj + fi * fi);
 				*dgauss = RE_filter_value(this->m_data->filtertype, dist);
 				
-				val += *dgauss;
+				sum += *dgauss;
 			}
 		}
-		if (val != 0.0f) {
-			val = 1.0f / val;
-			for (j = n - 1; j >= 0; j--) {
-				ddgauss[j] *= val;
-			}
+		if (sum > 0.0f) {
+			/* normalize */
+			float norm = 1.0f / sum;
+			for (j = n - 1; j >= 0; j--)
+				ddgauss[j] *= norm;
 		}
-		else ddgauss[4] = 1.0f;
+		else {
+			int center = m_rady * ddwidth + m_radx;
+			ddgauss[center] = 1.0f;
+		}
 		
 		this->m_gausstab = ddgauss;
 	}




More information about the Bf-blender-cvs mailing list