[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49578] trunk/blender/source/blender: code cleanup: minor edit - replace memset() with zero initialization, remove unneeded NULL check in ibuf_sample()

Campbell Barton ideasman42 at gmail.com
Sun Aug 5 17:04:11 CEST 2012


Revision: 49578
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49578
Author:   campbellbarton
Date:     2012-08-05 15:04:10 +0000 (Sun, 05 Aug 2012)
Log Message:
-----------
code cleanup: minor edit - replace memset() with zero initialization, remove unneeded NULL check in ibuf_sample()

Modified Paths:
--------------
    trunk/blender/source/blender/editors/sculpt_paint/paint_utils.c
    trunk/blender/source/blender/render/extern/include/RE_render_ext.h
    trunk/blender/source/blender/render/intern/include/texture.h
    trunk/blender/source/blender/render/intern/source/imagetexture.c

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_utils.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_utils.c	2012-08-05 14:22:44 UTC (rev 49577)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_utils.c	2012-08-05 15:04:10 UTC (rev 49578)
@@ -13,7 +13,7 @@
  *
  * 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.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  * All rights reserved.
@@ -177,15 +177,10 @@
 
 float paint_get_tex_pixel(Brush *br, float u, float v)
 {
-	TexResult texres;
-	float co[3];
+	TexResult texres = {0};
+	float co[3] = {u, v, 0.0f};
 	int hasrgb;
 
-	co[0] = u;
-	co[1] = v;
-	co[2] = 0;
-
-	memset(&texres, 0, sizeof(TexResult));
 	hasrgb = multitex_ext(br->mtex.tex, co, NULL, NULL, 0, &texres);
 
 	if (hasrgb & TEX_RGB)

Modified: trunk/blender/source/blender/render/extern/include/RE_render_ext.h
===================================================================
--- trunk/blender/source/blender/render/extern/include/RE_render_ext.h	2012-08-05 14:22:44 UTC (rev 49577)
+++ trunk/blender/source/blender/render/extern/include/RE_render_ext.h	2012-08-05 15:04:10 UTC (rev 49578)
@@ -58,7 +58,7 @@
 float texture_value_blend(float tex, float out, float fact, float facg, int blendtype);
 
 /* node_composite.c */
-void ibuf_sample(struct ImBuf *ibuf, float fx, float fy, float dx, float dy, float *result);
+void ibuf_sample(struct ImBuf *ibuf, float fx, float fy, float dx, float dy, float result[4]);
 void antialias_tagbuf(int xsize, int ysize, char *rectmove);
 
 /* dynamicpaint.c */

Modified: trunk/blender/source/blender/render/intern/include/texture.h
===================================================================
--- trunk/blender/source/blender/render/intern/include/texture.h	2012-08-05 14:22:44 UTC (rev 49577)
+++ trunk/blender/source/blender/render/intern/include/texture.h	2012-08-05 15:04:10 UTC (rev 49578)
@@ -78,7 +78,7 @@
 
 int imagewraposa(struct Tex *tex, struct Image *ima, struct ImBuf *ibuf, const float texvec[3], const float dxt[3], const float dyt[3], struct TexResult *texres);
 int imagewrap(struct Tex *tex, struct Image *ima, struct ImBuf *ibuf, const float texvec[3], struct TexResult *texres);
-void image_sample(struct Image *ima, float fx, float fy, float dx, float dy, float *result);
+void image_sample(struct Image *ima, float fx, float fy, float dx, float dy, float result[4]);
 
 #endif /* __TEXTURE_H__ */
 

Modified: trunk/blender/source/blender/render/intern/source/imagetexture.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/imagetexture.c	2012-08-05 14:22:44 UTC (rev 49577)
+++ trunk/blender/source/blender/render/intern/source/imagetexture.c	2012-08-05 15:04:10 UTC (rev 49578)
@@ -1779,11 +1779,8 @@
 	}
 
 	/* de-premul, this is being premulled in shade_input_do_shade() */
-	if (texres->ta!=1.0f && texres->ta>1e-4f) {
-		fx= 1.0f/texres->ta;
-		texres->tr*= fx;
-		texres->tg*= fx;
-		texres->tb*= fx;
+	if (texres->ta != 1.0f && texres->ta > 1e-4f) {
+		mul_v3_fl(&texres->tr, 1.0f / texres->ta);
 	}
 
 	BRICONTRGB;
@@ -1791,25 +1788,22 @@
 	return retval;
 }
 
-void image_sample(Image *ima, float fx, float fy, float dx, float dy, float *result)
+void image_sample(Image *ima, float fx, float fy, float dx, float dy, float result[4])
 {
 	TexResult texres;
 	ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
 	
-	if (ibuf==NULL) {
-		result[0]= result[1]= result[2]= result[3]= 0.0f;
+	if (UNLIKELY(ibuf == NULL)) {
+		zero_v4(result);
 		return;
 	}
 	
 	if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) )
 		ibuf->rect+= (ibuf->x*ibuf->y);
 
-	texres.talpha= 1; /* boxsample expects to be initialized */
-	boxsample(ibuf, fx, fy, fx+dx, fy+dy, &texres, 0, 1);
-	result[0]= texres.tr;
-	result[1]= texres.tg;
-	result[2]= texres.tb;
-	result[3]= texres.ta;
+	texres.talpha = TRUE; /* boxsample expects to be initialized */
+	boxsample(ibuf, fx, fy, fx + dx, fy + dy, &texres, 0, 1);
+	copy_v4_v4(result, &texres.tr);
 	
 	if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) )
 		ibuf->rect-= (ibuf->x*ibuf->y);
@@ -1817,15 +1811,11 @@
 	ima->flag|= IMA_USED_FOR_RENDER;
 }
 
-void ibuf_sample(ImBuf *ibuf, float fx, float fy, float dx, float dy, float *result)
+void ibuf_sample(ImBuf *ibuf, float fx, float fy, float dx, float dy, float result[4])
 {
-	TexResult texres;
+	TexResult texres = {0};
 	afdata_t AFD;
-	
-	if (ibuf==NULL) {
-		return;
-	}
-	
+
 	AFD.dxt[0] = dx; AFD.dxt[1] = dx;
 	AFD.dyt[0] = dy; AFD.dyt[1] = dy;
 	//copy_v2_v2(AFD.dxt, dx);
@@ -1833,13 +1823,8 @@
 	
 	AFD.intpol = 1;
 	AFD.extflag = TXC_EXTD;
-	
-	memset(&texres, 0, sizeof(texres));
+
 	ewa_eval(&texres, ibuf, fx, fy, &AFD);
 	
-	
-	result[0]= texres.tr;
-	result[1]= texres.tg;
-	result[2]= texres.tb;
-	result[3]= texres.ta;
+	copy_v4_v4(result, &texres.tr);
 }




More information about the Bf-blender-cvs mailing list