[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48854] trunk/blender/source/blender/ blenkernel/intern/mask.c: feather points now align with mask outline when called with same resolution .

Campbell Barton ideasman42 at gmail.com
Thu Jul 12 11:03:45 CEST 2012


Revision: 48854
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48854
Author:   campbellbarton
Date:     2012-07-12 09:03:45 +0000 (Thu, 12 Jul 2012)
Log Message:
-----------
feather points now align with mask outline when called with same resolution.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/mask.c

Modified: trunk/blender/source/blender/blenkernel/intern/mask.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mask.c	2012-07-12 08:34:59 UTC (rev 48853)
+++ trunk/blender/source/blender/blenkernel/intern/mask.c	2012-07-12 09:03:45 UTC (rev 48854)
@@ -314,6 +314,23 @@
 	return resol;
 }
 
+static int mask_spline_points_calc_tot(const MaskSpline *spline, const int resol)
+{
+	int len;
+
+	/* count */
+	len = (spline->tot_point - 1) * resol;
+
+	if (spline->flag & MASK_SPLINE_CYCLIC) {
+		len += resol;
+	}
+	else {
+		len++;
+	}
+
+	return len;
+}
+
 float (*BKE_mask_spline_differentiate_with_resolution_ex(MaskSpline *spline, const int resol,
                                                          int *tot_diff_point))[2]
 {
@@ -321,7 +338,8 @@
 
 	MaskSplinePoint *point, *prev;
 	float (*diff_points)[2], (*fp)[2];
-	int a, len;
+	const int tot = mask_spline_points_calc_tot(spline, resol);
+	int a;
 
 	if (spline->tot_point <= 1) {
 		/* nothing to differentiate */
@@ -329,17 +347,9 @@
 		return NULL;
 	}
 
-	/* count */
-	len = (spline->tot_point - 1) * resol;
-
-	if (spline->flag & MASK_SPLINE_CYCLIC)
-		len += resol;
-	else
-		len++;
-
 	/* len+1 because of 'forward_diff_bezier' function */
-	*tot_diff_point = len;
-	diff_points = fp = MEM_mallocN((len + 1) * sizeof(*diff_points), "mask spline vets");
+	*tot_diff_point = tot;
+	diff_points = fp = MEM_mallocN((tot + 1) * sizeof(*diff_points), "mask spline vets");
 
 	a = spline->tot_point - 1;
 	if (spline->flag & MASK_SPLINE_CYCLIC)
@@ -391,32 +401,68 @@
 	return BKE_mask_spline_differentiate_with_resolution(spline, 0, 0, tot_diff_point);
 }
 
+/**
+ * values align with #BKE_mask_spline_differentiate_with_resolution_ex
+ * when \a resol arguments match.
+ */
 float (*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(MaskSpline *spline, const int resol,
                                                                          int *tot_feather_point))[2]
 {
 	MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
-
+	MaskSplinePoint *point, *prev;
 	float (*feather)[2], (*fp)[2];
-	int i, j, tot;
 
-	tot = resol * spline->tot_point;
-	feather = fp = MEM_mallocN(tot * sizeof(*feather), "mask spline feather diff points");
+	const int tot = mask_spline_points_calc_tot(spline, resol);
+	int a;
 
-	for (i = 0; i < spline->tot_point; i++) {
-		MaskSplinePoint *point = &points_array[i];
+	/* tot+1 because of 'forward_diff_bezier' function */
+	feather = fp = MEM_mallocN((tot + 1) * sizeof(*feather), "mask spline feather diff points");
 
+	a = spline->tot_point - 1;
+	if (spline->flag & MASK_SPLINE_CYCLIC)
+		a++;
+
+	prev = points_array;
+	point = prev + 1;
+
+	while (a--) {
+		/* BezTriple *prevbezt; */  /* UNUSED */
+		/* BezTriple *bezt; */      /* UNUSED */
+		int j;
+
+		if (a == 0 && (spline->flag & MASK_SPLINE_CYCLIC))
+			point = points_array;
+
+
+		/* prevbezt = &prev->bezt; */
+		/* bezt = &point->bezt; */
+
 		for (j = 0; j < resol; j++, fp++) {
 			float u = (float) j / resol, weight;
 			float co[2], n[2];
 
 			/* TODO - these calls all calculate similar things
 			 * could be unified for some speed */
-			BKE_mask_point_segment_co(spline, point, u, co);
-			BKE_mask_point_normal(spline, point, u, n);
-			weight = BKE_mask_point_weight(spline, point, u);
+			BKE_mask_point_segment_co(spline, prev, u, co);
+			BKE_mask_point_normal(spline, prev, u, n);
+			weight = BKE_mask_point_weight(spline, prev, u);
 
 			madd_v2_v2v2fl(*fp, co, n, weight);
 		}
+
+		if (a == 0 && (spline->flag & MASK_SPLINE_CYCLIC) == 0) {
+			float u = 1.0f, weight;
+			float co[2], n[2];
+
+			BKE_mask_point_segment_co(spline, prev, u, co);
+			BKE_mask_point_normal(spline, prev, u, n);
+			weight = BKE_mask_point_weight(spline, prev, u);
+
+			madd_v2_v2v2fl(*fp, co, n, weight);
+		}
+
+		prev = point;
+		point++;
 	}
 
 	*tot_feather_point = tot;




More information about the Bf-blender-cvs mailing list