[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43372] trunk/blender/source/blender: ensure functions are not used within FTOCHAR macro since they run 2-3 times .

Campbell Barton ideasman42 at gmail.com
Sat Jan 14 11:33:29 CET 2012


Revision: 43372
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43372
Author:   campbellbarton
Date:     2012-01-14 10:33:16 +0000 (Sat, 14 Jan 2012)
Log Message:
-----------
ensure functions are not used within FTOCHAR macro since they run 2-3 times.

brushes were doing curve lookups within this macro for example.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_brush.h
    trunk/blender/source/blender/blenkernel/intern/brush.c
    trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c
    trunk/blender/source/blender/blenlib/BLI_math_color.h
    trunk/blender/source/blender/blenlib/intern/math_color.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image.c

Modified: trunk/blender/source/blender/blenkernel/BKE_brush.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_brush.h	2012-01-14 10:12:24 UTC (rev 43371)
+++ trunk/blender/source/blender/blenkernel/BKE_brush.h	2012-01-14 10:33:16 UTC (rev 43372)
@@ -67,7 +67,7 @@
 float brush_curve_strength(struct Brush *br, float p, const float len); /* used for sculpt */
 
 /* sampling */
-void brush_sample_tex(struct Brush *brush, float *xy, float *rgba, const int thread);
+void brush_sample_tex(struct Brush *brush, const float xy[2], float rgba[4], const int thread);
 void brush_imbuf_new(struct Brush *brush, short flt, short texfalloff, int size,
 	struct ImBuf **imbuf, int use_color_correction);
 

Modified: trunk/blender/source/blender/blenkernel/intern/brush.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/brush.c	2012-01-14 10:12:24 UTC (rev 43371)
+++ trunk/blender/source/blender/blenkernel/intern/brush.c	2012-01-14 10:33:16 UTC (rev 43372)
@@ -487,7 +487,7 @@
 }
 
 /* Brush Sampling */
-void brush_sample_tex(Brush *brush, float *xy, float *rgba, const int thread)
+void brush_sample_tex(Brush *brush, const float xy[2], float rgba[4], const int thread)
 {
 	MTex *mtex= &brush->mtex;
 
@@ -515,15 +515,16 @@
 			rgba[3]= 1.0f;
 		}
 	}
-	else if (rgba)
+	else {
 		rgba[0]= rgba[1]= rgba[2]= rgba[3]= 1.0f;
+	}
 }
 
-
+/* TODO, use define for 'texfall' arg */
 void brush_imbuf_new(Brush *brush, short flt, short texfall, int bufsize, ImBuf **outbuf, int use_color_correction)
 {
 	ImBuf *ibuf;
-	float xy[2], dist, rgba[4], *dstf;
+	float xy[2], rgba[4], *dstf;
 	int x, y, rowbytes, xoff, yoff, imbflag;
 	const int radius= brush_size(brush);
 	char *dst, crgb[3];
@@ -554,28 +555,23 @@
 				xy[1] = y + yoff;
 
 				if (texfall == 0) {
-					dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
-
 					copy_v3_v3(dstf, brush_rgb);
-					dstf[3]= alpha*brush_curve_strength_clamp(brush, dist, radius);
+					dstf[3]= alpha*brush_curve_strength_clamp(brush, len_v2(xy), radius);
 				}
 				else if (texfall == 1) {
 					brush_sample_tex(brush, xy, dstf, 0);
 				}
 				else {
-					dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
-
 					brush_sample_tex(brush, xy, rgba, 0);
 					mul_v3_v3v3(dstf, rgba, brush_rgb);
-					dstf[3] = rgba[3]*alpha*brush_curve_strength_clamp(brush, dist, radius);
+					dstf[3] = rgba[3]*alpha*brush_curve_strength_clamp(brush, len_v2(xy), radius);
 				}
 			}
 		}
 	}
 	else {
-		crgb[0]= FTOCHAR(brush->rgb[0]);
-		crgb[1]= FTOCHAR(brush->rgb[1]);
-		crgb[2]= FTOCHAR(brush->rgb[2]);
+		float alpha_f; /* final float alpha to convert to char */
+		F3TOCHAR3(brush->rgb, crgb);
 
 		for (y=0; y < ibuf->y; y++) {
 			dst = (char*)ibuf->rect + y*rowbytes;
@@ -585,36 +581,38 @@
 				xy[1] = y + yoff;
 
 				if (texfall == 0) {
-					dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
+					alpha_f = alpha * brush_curve_strength(brush, len_v2(xy), radius);
 
-					dst[0]= crgb[0];
-					dst[1]= crgb[1];
-					dst[2]= crgb[2];
-					dst[3]= FTOCHAR(alpha*brush_curve_strength(brush, dist, radius));
+					dst[0] = crgb[0];
+					dst[1] = crgb[1];
+					dst[2] = crgb[2];
+					dst[3] = FTOCHAR(alpha_f);
 				}
 				else if (texfall == 1) {
 					brush_sample_tex(brush, xy, rgba, 0);
-					dst[0]= FTOCHAR(rgba[0]);
-					dst[1]= FTOCHAR(rgba[1]);
-					dst[2]= FTOCHAR(rgba[2]);
-					dst[3]= FTOCHAR(rgba[3]);
+					dst[0] = FTOCHAR(rgba[0]);
+					dst[1] = FTOCHAR(rgba[1]);
+					dst[2] = FTOCHAR(rgba[2]);
+					dst[3] = FTOCHAR(rgba[3]);
 				}
 				else if (texfall == 2) {
-					dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
-
 					brush_sample_tex(brush, xy, rgba, 0);
-					dst[0] = FTOCHAR(rgba[0]*brush->rgb[0]);
-					dst[1] = FTOCHAR(rgba[1]*brush->rgb[1]);
-					dst[2] = FTOCHAR(rgba[2]*brush->rgb[2]);
-					dst[3] = FTOCHAR(rgba[3]*alpha*brush_curve_strength_clamp(brush, dist, radius));
-				} else {
-					dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
+					mul_v3_v3(rgba, brush->rgb);
+					alpha_f = rgba[3] * alpha * brush_curve_strength_clamp(brush, len_v2(xy), radius);
 
+					dst[0] = FTOCHAR(rgba[0]);
+					dst[1] = FTOCHAR(rgba[1]);
+					dst[2] = FTOCHAR(rgba[2]);
+					dst[3] = FTOCHAR(alpha_f);
+				}
+				else {
 					brush_sample_tex(brush, xy, rgba, 0);
-					dst[0]= crgb[0];
-					dst[1]= crgb[1];
-					dst[2]= crgb[2];
-					dst[3] = FTOCHAR(rgba[3]*alpha*brush_curve_strength_clamp(brush, dist, radius));
+					alpha_f = rgba[3] * alpha * brush_curve_strength_clamp(brush, len_v2(xy), radius);
+
+					dst[0] = crgb[0];
+					dst[1] = crgb[1];
+					dst[2] = crgb[2];
+					dst[3] = FTOCHAR(alpha_f);
 				}
 			}
 		}

Modified: trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c	2012-01-14 10:12:24 UTC (rev 43371)
+++ trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c	2012-01-14 10:33:16 UTC (rev 43372)
@@ -1620,8 +1620,8 @@
 										}
 										else {
 											col[i*4+j].a = 255;
-											col[i*4+j].r = FTOCHAR(pPoint[index].wetness);
-											col[i*4+j].g = FTOCHAR(pPoint[index].wetness);
+											col[i*4+j].r =
+											col[i*4+j].g =
 											col[i*4+j].b = FTOCHAR(pPoint[index].wetness);
 										}
 									}
@@ -1671,8 +1671,8 @@
 								for (; j<((mface[i].v4)?4:3); j++) {
 									int index = (j==0)?mface[i].v1: (j==1)?mface[i].v2: (j==2)?mface[i].v3: mface[i].v4;
 									col[i*4+j].a = 255;
-									col[i*4+j].r = FTOCHAR(pPoint[index].wetness);
-									col[i*4+j].g = FTOCHAR(pPoint[index].wetness);
+									col[i*4+j].r =
+									col[i*4+j].g =
 									col[i*4+j].b = FTOCHAR(pPoint[index].wetness);
 								}
 							}

Modified: trunk/blender/source/blender/blenlib/BLI_math_color.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_color.h	2012-01-14 10:12:24 UTC (rev 43371)
+++ trunk/blender/source/blender/blenlib/BLI_math_color.h	2012-01-14 10:33:16 UTC (rev 43372)
@@ -99,8 +99,8 @@
 void rgb_float_set_hue_float_offset(float * rgb, float hue_offset);
 void rgb_byte_set_hue_float_offset(unsigned char * rgb, float hue_offset);
 
-void rgb_byte_to_float(const unsigned char *in, float *out);
-void rgb_float_to_byte(const float *in, unsigned char *out);
+void rgb_byte_to_float(const unsigned char in[3], float out[3]);
+void rgb_float_to_byte(const float in[3], unsigned char out[3]);
 
 /***************** lift/gamma/gain / ASC-CDL conversion *****************/
 

Modified: trunk/blender/source/blender/blenlib/intern/math_color.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_color.c	2012-01-14 10:12:24 UTC (rev 43371)
+++ trunk/blender/source/blender/blenlib/intern/math_color.c	2012-01-14 10:33:16 UTC (rev 43372)
@@ -337,14 +337,14 @@
 	*b /= 255.0f;
 }
 
-void rgb_byte_to_float(const unsigned char *in, float *out)
+void rgb_byte_to_float(const unsigned char in[3], float out[3])
 {
 	out[0]= ((float)in[0]) / 255.0f;
 	out[1]= ((float)in[1]) / 255.0f;
 	out[2]= ((float)in[2]) / 255.0f;
 }
 
-void rgb_float_to_byte(const float *in, unsigned char *out)
+void rgb_float_to_byte(const float in[3], unsigned char out[3])
 {
 	int r, g, b;
 	

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2012-01-14 10:12:24 UTC (rev 43371)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2012-01-14 10:33:16 UTC (rev 43372)
@@ -1784,25 +1784,16 @@
 }
 #endif //PROJ_DEBUG_NOSEAMBLEED
 
-static float Vec2Lenf_nosqrt(const float *v1, const float *v2)
+static float len_squared_v2v2_alt(const float *v1, const float v2_1, const float v2_2)
 {
 	float x, y;
 
-	x = v1[0]-v2[0];
-	y = v1[1]-v2[1];
-	return x*x+y*y;
-}
-
-static float Vec2Lenf_nosqrt_other(const float *v1, const float v2_1, const float v2_2)
-{
-	float x, y;
-
 	x = v1[0]-v2_1;
 	y = v1[1]-v2_2;
 	return x*x+y*y;
 }
 
-/* note, use a squared value so we can use Vec2Lenf_nosqrt
+/* note, use a squared value so we can use len_squared_v2v2
  * be sure that you have done a bounds check first or this may fail */
 /* only give bucket_bounds as an arg because we need it elsewhere */
 static int project_bucket_isect_circle(const float cent[2], const float radius_squared, rctf *bucket_bounds)
@@ -1826,21 +1817,21 @@
 	if (cent[0] < bucket_bounds->xmin) {
 		/* lower left out of radius test */
 		if (cent[1] < bucket_bounds->ymin) {
-			return (Vec2Lenf_nosqrt_other(cent, bucket_bounds->xmin, bucket_bounds->ymin) < radius_squared) ? 1 : 0;
+			return (len_squared_v2v2_alt(cent, bucket_bounds->xmin, bucket_bounds->ymin) < radius_squared) ? 1 : 0;
 		} 
 		/* top left test */
 		else if (cent[1] > bucket_bounds->ymax) {
-			return (Vec2Lenf_nosqrt_other(cent, bucket_bounds->xmin, bucket_bounds->ymax) < radius_squared) ? 1 : 0;
+			return (len_squared_v2v2_alt(cent, bucket_bounds->xmin, bucket_bounds->ymax) < radius_squared) ? 1 : 0;
 		}
 	}
 	else if (cent[0] > bucket_bounds->xmax) {
 		/* lower right out of radius test */
 		if (cent[1] < bucket_bounds->ymin) {
-			return (Vec2Lenf_nosqrt_other(cent, bucket_bounds->xmax, bucket_bounds->ymin) < radius_squared) ? 1 : 0;
+			return (len_squared_v2v2_alt(cent, bucket_bounds->xmax, bucket_bounds->ymin) < radius_squared) ? 1 : 0;
 		} 
 		/* top right test */
 		else if (cent[1] > bucket_bounds->ymax) {
-			return (Vec2Lenf_nosqrt_other(cent, bucket_bounds->xmax, bucket_bounds->ymax) < radius_squared) ? 1 : 0;
+			return (len_squared_v2v2_alt(cent, bucket_bounds->xmax, bucket_bounds->ymax) < radius_squared) ? 1 : 0;
 		}
 	}
 	
@@ -3901,8 +3892,7 @@
 
 				projPixel = (ProjPixel *)node->link;
 
-				/*dist = len_v2v2(projPixel->projCoSS, pos);*/ /* correct but uses a sqrtf */
-				dist_nosqrt = Vec2Lenf_nosqrt(projPixel->projCoSS, pos);
+				dist_nosqrt = len_squared_v2v2(projPixel->projCoSS, pos);
 
 				/*if (dist < radius) {*/ /* correct but uses a sqrtf */
 				if (dist_nosqrt <= radius_squared) {



More information about the Bf-blender-cvs mailing list