[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17566] branches/projection-paint/source/ blender/src/imagepaint.c: use const where possible and removed some unneeded args (4.3% speedup)

Campbell Barton ideasman42 at gmail.com
Tue Nov 25 04:39:31 CET 2008


Revision: 17566
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17566
Author:   campbellbarton
Date:     2008-11-25 04:39:30 +0100 (Tue, 25 Nov 2008)

Log Message:
-----------
use const where possible and removed some unneeded args (4.3% speedup)

Modified Paths:
--------------
    branches/projection-paint/source/blender/src/imagepaint.c

Modified: branches/projection-paint/source/blender/src/imagepaint.c
===================================================================
--- branches/projection-paint/source/blender/src/imagepaint.c	2008-11-25 01:19:09 UTC (rev 17565)
+++ branches/projection-paint/source/blender/src/imagepaint.c	2008-11-25 03:39:30 UTC (rev 17566)
@@ -482,7 +482,7 @@
 }
 
 /* fast projection bucket array lookup, use the safe version for bound checking  */
-static int project_bucket_offset(ProjPaintState *ps, float projCoSS[2])
+static int project_bucket_offset(const ProjPaintState *ps, const float projCoSS[2])
 {
 	/* If we were not dealing with screenspace 2D coords we could simple do...
 	 * ps->bucketRect[x + (y*ps->buckets_y)] */
@@ -498,7 +498,7 @@
 		(	(	(int)(( (projCoSS[1] - ps->screen_min[1])  / ps->screen_height) * ps->buckets_y)) * ps->buckets_x );
 }
 
-static int project_bucket_offset_safe(ProjPaintState *ps, float projCoSS[2])
+static int project_bucket_offset_safe(const ProjPaintState *ps, const float projCoSS[2])
 {
 	int bucket_index = project_bucket_offset(ps, projCoSS);
 	
@@ -510,7 +510,7 @@
 }
 
 /* The point must be inside the triangle */
-static void BarycentricWeightsSimple2f(float v1[2], float v2[2], float v3[2], float pt[2], float w[3]) {
+static void BarycentricWeightsSimple2f(const float v1[2], const float v2[2], const float v3[2], const float pt[2], float w[3]) {
 	float wtot, wtot_inv;
 	w[0] = AreaF2Dfl(v2, v3, pt);
 	w[1] = AreaF2Dfl(v3, v1, pt);
@@ -528,7 +528,7 @@
 
 /* also works for points outside the triangle */
 #define SIDE_OF_LINE(pa,pb,pp)	((pa[0]-pp[0])*(pb[1]-pp[1]))-((pb[0]-pp[0])*(pa[1]-pp[1]))
-static void BarycentricWeights2f(float v1[2], float v2[2], float v3[2], float pt[2], float w[3]) {
+static void BarycentricWeights2f(const float v1[2], const float v2[2], const float v3[2], const float pt[2], float w[3]) {
 	float wtot_inv, wtot = AreaF2Dfl(v1, v2, v3);
 	if (wtot > 0.0f) {
 		wtot_inv = 1.0f / wtot;
@@ -552,7 +552,7 @@
 
 /* still use 2D X,Y space but this works for verts transformed by a perspective matrix, using their 4th component as a weight */
 
-static void BarycentricWeightsPersp2f(float v1[4], float v2[4], float v3[4], float pt[2], float w[3]) {
+static void BarycentricWeightsPersp2f(const float v1[4], const float v2[4], const float v3[4], const float pt[2], float w[3]) {
 	float persp_tot, persp_tot_inv;
 	BarycentricWeights2f(v1,v2,v3,pt,w);
 	
@@ -571,7 +571,7 @@
 	}
 }
 
-static void BarycentricWeightsSimplePersp2f(float v1[4], float v2[4], float v3[4], float pt[2], float w[3])
+static void BarycentricWeightsSimplePersp2f(const float v1[4], const float v2[4], const float v3[4], const float pt[2], float w[3])
 {
 	float persp_tot_inv, persp_tot;
 	BarycentricWeightsSimple2f(v1,v2,v3,pt,w);
@@ -591,20 +591,20 @@
 	}
 }
 
-static void VecWeightf(float p[3], float v1[3], float v2[3], float v3[3], float w[3])
+static void VecWeightf(float p[3], const float v1[3], const float v2[3], const float v3[3], const float w[3])
 {
 	p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2];
 	p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2];
 	p[2] = v1[2]*w[0] + v2[2]*w[1] + v3[2]*w[2];
 }
 
-static void Vec2Weightf(float p[3], float v1[3], float v2[3], float v3[3], float w[3])
+static void Vec2Weightf(float p[2], const float v1[2], const float v2[2], const float v3[2], const float w[3])
 {
 	p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2];
 	p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2];
 }
 
-static float tri_depth_2d(float v1[3], float v2[3], float v3[3], float pt[2], float w[3])
+static float tri_depth_2d(const float v1[3], const float v2[3], const float v3[3], const float pt[2], float w[3])
 {
 	BarycentricWeightsSimple2f(v1,v2,v3,pt,w);
 	return (v1[2]*w[0]) + (v2[2]*w[1]) + (v3[2]*w[2]);
@@ -612,7 +612,7 @@
 
 
 /* Return the top-most face index that the screen space coord 'pt' touches (or -1) */
-static int project_paint_PickFace(ProjPaintState *ps, float pt[2], float w[3], int *side) {
+static int project_paint_PickFace(const ProjPaintState *ps, const float pt[2], float w[3], int *side) {
 	LinkNode *node;
 	float w_tmp[3];
 	float *v1, *v2, *v3, *v4;
@@ -670,7 +670,7 @@
 }
 
 /* Set the top-most face color that the screen space coord 'pt' touches (or return 0 if none touch) */
-static int project_paint_PickColor(ProjPaintState *ps, float pt[2], float *rgba_fp, unsigned char *rgba, int interp)
+static int project_paint_PickColor(const ProjPaintState *ps, const float pt[2], float *rgba_fp, unsigned char *rgba, const int interp)
 {
 	float w[3], uv[2];
 	int side;
@@ -764,7 +764,7 @@
  * -1	: no occlusion but 2D intersection is true (avoid testing the other half of a quad)
  *  1	: occluded */
 
-static int project_paint_occlude_ptv(float pt[3], float v1[3], float v2[3], float v3[3])
+static int project_paint_occlude_ptv(const float pt[3], const float v1[3], const float v2[3], const float v3[3])
 {
 	/* if all are behind us, return false */
 	if(v1[2] > pt[2] && v2[2] > pt[2] && v3[2] > pt[2])
@@ -790,8 +790,12 @@
 }
 
 
-static int project_paint_occlude_ptv_clip(ProjPaintState *ps, MFace *mf, float pt[3], float v1[3], float v2[3], float v3[3], int side)
-{
+static int project_paint_occlude_ptv_clip(
+		const ProjPaintState *ps, const MFace *mf,
+		const float pt[3],
+		const float v1[3], const float v2[3], const float v3[3],
+		const int side
+) {
 	float w[3], wco[3];
 	
 	/* if all are behind us, return false */
@@ -821,7 +825,7 @@
 /* Check if a screenspace location is occluded by any other faces
  * check, pixelScreenCo must be in screenspace, its Z-Depth only needs to be used for comparison
  * and dosn't need to be correct in relation to X and Y coords (this is the case in perspective view) */
-static int project_bucket_point_occluded(ProjPaintState *ps, LinkNode *bucketFace, int orig_face, float pixelScreenCo[4])
+static int project_bucket_point_occluded(const ProjPaintState *ps, LinkNode *bucketFace, const int orig_face, const float pixelScreenCo[4])
 {
 	MFace *mf;
 	int face_index;
@@ -879,7 +883,7 @@
 #define ISECT_TRUE 1
 #define ISECT_TRUE_P1 2
 #define ISECT_TRUE_P2 3
-static int line_isect_y(float p1[2], float p2[2], float y_level, float *x_isect)
+static int line_isect_y(const float p1[2], const float p2[2], const float y_level, float *x_isect)
 {
 	if (y_level==p1[1]) {
 		*x_isect = p1[0];
@@ -901,7 +905,7 @@
 	}
 }
 
-static int line_isect_x(float p1[2], float p2[2], float x_level, float *y_isect)
+static int line_isect_x(const float p1[2], const float p2[2], const float x_level, float *y_isect)
 {
 	if (x_level==p1[0]) {
 		*y_isect = p1[1];
@@ -924,7 +928,7 @@
 }
 
 /* simple func use for comparing UV locations to check if there are seams */
-static int cmp_uv(float vec2a[2], float vec2b[2])
+static int cmp_uv(const float vec2a[2], const float vec2b[2])
 {
 	return ((fabs(vec2a[0]-vec2b[0]) < 0.0001f) && (fabs(vec2a[1]-vec2b[1]) < 0.0001f)) ? 1:0;
 }
@@ -932,8 +936,12 @@
 
 /* set min_px and max_px to the image space bounds of the UV coords 
  * return zero if there is no area in the returned rectangle */
-static int pixel_bounds_uv(float uv1[2], float uv2[2], float uv3[2], float uv4[2], int min_px[2], int max_px[2], int ibuf_x, int ibuf_y, int is_quad)
-{
+static int pixel_bounds_uv(
+		const float uv1[2], const float uv2[2], const float uv3[2], const float uv4[2],
+		int min_px[2], int max_px[2],
+		const int ibuf_x, const int ibuf_y,
+		int is_quad
+) {
 	float min_uv[2], max_uv[2]; /* UV bounds */
 	
 	INIT_MINMAX2(min_uv, max_uv);
@@ -956,7 +964,7 @@
 	return (min_px[0] == max_px[0] || min_px[1] == max_px[1]) ? 0 : 1;
 }
 
-static int pixel_bounds_array(float (* uv)[2], int min_px[2], int max_px[2], int ibuf_x, int ibuf_y, int tot)
+static int pixel_bounds_array(float (* uv)[2], int min_px[2], int max_px[2], const int ibuf_x, const int ibuf_y, int tot)
 {
 	float min_uv[2], max_uv[2]; /* UV bounds */
 	
@@ -987,18 +995,17 @@
 
 /* This function returns 1 if this face has a seam along the 2 face-vert indicies
  * 'orig_i1_fidx' and 'orig_i2_fidx' */
-static int check_seam(ProjPaintState *ps, int orig_face, int orig_i1_fidx, int orig_i2_fidx, int *other_face, int *orig_fidx)
+static int check_seam(const ProjPaintState *ps, const int orig_face, const int orig_i1_fidx, const int orig_i2_fidx, int *other_face, int *orig_fidx)
 {
 	LinkNode *node;
 	int face_index;
 	int i, i1, i2;
 	int i1_fidx = -1, i2_fidx = -1; /* indexi in face */
-	MFace *orig_mf, *mf;
-	MTFace *orig_tf, *tf;
+	MFace *mf;
+	MTFace *tf;
+	const MFace *orig_mf = ps->dm_mface + orig_face;  
+	const MTFace *orig_tf = ps->dm_mtface + orig_face;
 	
-	orig_mf = ps->dm_mface + orig_face;
-	orig_tf = ps->dm_mtface + orig_face;
-	
 	/* vert indicies from face vert order indicies */
 	i1 = (*(&orig_mf->v1 + orig_i1_fidx));
 	i2 = (*(&orig_mf->v1 + orig_i2_fidx));
@@ -1074,28 +1081,28 @@
 /* Calculate outset UV's, this is not the same as simply scaling the UVs,
  * since the outset coords are a margin that keep an even distance from the original UV's,
  * note that the image aspect is taken into account */
-static void uv_image_outset(float (*orig_uv)[2], float (*outset_uv)[2], float scaler, int ima_x, int ima_y, int is_quad)
+static void uv_image_outset(float (*orig_uv)[2], float (*outset_uv)[2], const float scaler, const int ibuf_x, const int ibuf_y, const int is_quad)
 {
 	float a1,a2,a3,a4=0.0f;
 	float puv[4][2]; /* pixelspace uv's */
 	float no1[2], no2[2], no3[2], no4[2]; /* normals */
 	float dir1[2], dir2[2], dir3[2], dir4[2];
-	float ima_x_inv = 1.0f / (float)ima_x; 
-	float ima_y_inv = 1.0f / (float)ima_y; 
+	float ibuf_x_inv = 1.0f / (float)ibuf_x; 
+	float ibuf_y_inv = 1.0f / (float)ibuf_y; 
 	
 	/* make UV's in pixel space so we can */
-	puv[0][0] = orig_uv[0][0] * ima_x;
-	puv[0][1] = orig_uv[0][1] * ima_y;
+	puv[0][0] = orig_uv[0][0] * ibuf_x;
+	puv[0][1] = orig_uv[0][1] * ibuf_y;
 	
-	puv[1][0] = orig_uv[1][0] * ima_x;
-	puv[1][1] = orig_uv[1][1] * ima_y;
+	puv[1][0] = orig_uv[1][0] * ibuf_x;
+	puv[1][1] = orig_uv[1][1] * ibuf_y;
 	
-	puv[2][0] = orig_uv[2][0] * ima_x;
-	puv[2][1] = orig_uv[2][1] * ima_y;
+	puv[2][0] = orig_uv[2][0] * ibuf_x;
+	puv[2][1] = orig_uv[2][1] * ibuf_y;
 	
 	if (is_quad) {
-		puv[3][0] = orig_uv[3][0] * ima_x;
-		puv[3][1] = orig_uv[3][1] * ima_y;
+		puv[3][0] = orig_uv[3][0] * ibuf_x;
+		puv[3][1] = orig_uv[3][1] * ibuf_y;
 	}
 	
 	/* face edge directions */
@@ -1142,17 +1149,17 @@
 		Vec2Addf(outset_uv[1], puv[1], no2);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list