[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47316] branches/soc-2011-tomato/source/ blender: Cleanup in spline diffirintiation code - encapsulate max segment length

Sergey Sharybin sergey.vfx at gmail.com
Fri Jun 1 14:25:20 CEST 2012


Revision: 47316
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47316
Author:   nazgul
Date:     2012-06-01 12:25:18 +0000 (Fri, 01 Jun 2012)
Log Message:
-----------
Cleanup in spline diffirintiation code - encapsulate max segment length
to resolution calculation functions rather than doing this from callee.

Also switch mask drawing code do the same spline resolution calculation
as used for compositor (which takes frame dimensions into account).

Modified Paths:
--------------
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c
    branches/soc-2011-tomato/source/blender/editors/mask/mask_draw.c
    branches/soc-2011-tomato/source/blender/editors/mask/mask_ops.c

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h	2012-06-01 11:50:32 UTC (rev 47315)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h	2012-06-01 12:25:18 UTC (rev 47316)
@@ -57,10 +57,14 @@
 
 /* splines */
 struct MaskSpline *BKE_mask_spline_add(struct MaskLayer *masklay);
-int BKE_mask_spline_resolution(struct MaskSpline *spline, float max_seg_len);
 
-float (*BKE_mask_spline_differentiate(struct MaskSpline *spline, int *tot_diff_point, int dynamic_res, float max_dseg_len))[2];
-float (*BKE_mask_spline_feather_differentiated_points(struct MaskSpline *spline, int *tot_feather_point, int dynamic_res, float max_dseg_len))[2];
+float (*BKE_mask_spline_differentiate(struct MaskSpline *spline, int *tot_diff_point))[2];
+float (*BKE_mask_spline_feather_differentiated_points(struct MaskSpline *spline, int *tot_feather_point))[2];
+
+float (*BKE_mask_spline_differentiate_with_resolution(struct MaskSpline *spline, int width, int height, int *tot_diff_point))[2];
+float (*BKE_mask_spline_feather_differentiated_points_with_resolution(struct MaskSpline *spline,
+			 int width, int height, int *tot_feather_point))[2];
+
 float (*BKE_mask_spline_feather_points(struct MaskSpline *spline, int *tot_feather_point))[2];
 
 /* point */
@@ -68,9 +72,18 @@
 void BKE_mask_point_handle(struct MaskSplinePoint *point, float handle[2]);
 void BKE_mask_point_set_handle(struct MaskSplinePoint *point, float loc[2], int keep_direction,
                                float orig_handle[2], float orig_vec[3][3]);
+
 float *BKE_mask_point_segment_diff(struct MaskSpline *spline, struct MaskSplinePoint *point, int *tot_diff_point);
 float *BKE_mask_point_segment_feather_diff(struct MaskSpline *spline, struct MaskSplinePoint *point,
                                            int *tot_feather_point);
+
+float *BKE_mask_point_segment_diff_with_resolution(struct MaskSpline *spline, struct MaskSplinePoint *point,
+                                                   int width, int height, int *tot_diff_point);
+
+float *BKE_mask_point_segment_feather_diff_with_resolution(struct MaskSpline *spline, struct MaskSplinePoint *point,
+                                                           int width, int height,
+                                                           int *tot_feather_point);
+
 void BKE_mask_point_segment_co(struct MaskSpline *spline, struct MaskSplinePoint *point, float u, float co[2]);
 void BKE_mask_point_normal(struct MaskSpline *spline, struct MaskSplinePoint *point,
                            float u, float n[2]);

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c	2012-06-01 11:50:32 UTC (rev 47315)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c	2012-06-01 12:25:18 UTC (rev 47316)
@@ -149,11 +149,18 @@
 	return spline;
 }
 
-int BKE_mask_spline_resolution(MaskSpline *spline, float max_seg_len)
+static int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height)
 {
-	const float max_segment = max_seg_len;
+	float max_segment = 0.01f;
 	int i, resol = 1;
 
+	if (width != 0 && height != 0) {
+		if (width >= height)
+			max_segment = 1.0f / (float) width;
+		else
+			max_segment = 1.0f / (float) height;
+	}
+
 	for (i = 0; i < spline->tot_point; i++) {
 		MaskSplinePoint *point = &spline->points[i];
 		MaskSplinePoint *next_point;
@@ -186,10 +193,10 @@
 	return resol;
 }
 
-int BKE_mask_spline_feather_resolution(MaskSpline *spline, float max_seg_len)
+static int BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, int height)
 {
 	const float max_segment = 0.005;
-	int resol = BKE_mask_spline_resolution(spline, max_seg_len);
+	int resol = BKE_mask_spline_resolution(spline, width, height);
 	float max_jump = 0.0f;
 	int i;
 
@@ -216,19 +223,14 @@
 	return resol;
 }
 
-float (*BKE_mask_spline_differentiate(MaskSpline *spline, int *tot_diff_point, int dynamic_res, float max_dseg_len))[2]
+float (*BKE_mask_spline_differentiate_with_resolution(MaskSpline *spline, int width, int height, int *tot_diff_point))[2]
 {
 	MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
 
 	MaskSplinePoint *point, *prev;
 	float (*diff_points)[2], (*fp)[2];
-	int a, len, resol;
-	if (!dynamic_res) {
-		max_dseg_len = 0.01f;
-	}	
-	resol = BKE_mask_spline_resolution(spline, max_dseg_len);
+	int a, len, resol = BKE_mask_spline_resolution(spline, width, height);
 
-
 	if (spline->tot_point <= 1) {
 		/* nothing to differentiate */
 		*tot_diff_point = 0;
@@ -284,16 +286,18 @@
 	return diff_points;
 }
 
-float (*BKE_mask_spline_feather_differentiated_points(MaskSpline * spline, int *tot_feather_point, int dynamic_res, float max_dseg_len))[2]
+float (*BKE_mask_spline_differentiate(MaskSpline *spline, int *tot_diff_point))[2]
 {
+	return BKE_mask_spline_differentiate_with_resolution(spline, 0, 0, tot_diff_point);
+}
+
+float (*BKE_mask_spline_feather_differentiated_points_with_resolution(MaskSpline *spline, int width, int height,
+                                                                      int *tot_feather_point))[2]
+{
 	MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
 
 	float (*feather)[2], (*fp)[2];
-	int i, j, tot, resol;
-	if (!dynamic_res) {
-		max_dseg_len = 0.005f;
-	}
-	resol = BKE_mask_spline_feather_resolution(spline, max_dseg_len);
+	int i, j, tot, resol = BKE_mask_spline_feather_resolution(spline, width, height);
 
 	tot = resol * spline->tot_point;
 	feather = fp = MEM_mallocN(tot * sizeof(*feather), "mask spline feather diff points");
@@ -320,6 +324,11 @@
 	return feather;
 }
 
+float (*BKE_mask_spline_feather_differentiated_points(MaskSpline * spline, int *tot_feather_point))[2]
+{
+	return BKE_mask_spline_feather_differentiated_points_with_resolution(spline, 0, 0, tot_feather_point);
+}
+
 float (*BKE_mask_spline_feather_points(MaskSpline * spline, int *tot_feather_point))[2]
 {
 	MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
@@ -424,10 +433,12 @@
 	}
 }
 
-float *BKE_mask_point_segment_feather_diff(MaskSpline *spline, MaskSplinePoint *point, int *tot_feather_point)
+float *BKE_mask_point_segment_feather_diff_with_resolution(MaskSpline *spline, MaskSplinePoint *point,
+                                                           int width, int height,
+                                                           int *tot_feather_point)
 {
 	float *feather, *fp;
-	int i, resol = BKE_mask_spline_feather_resolution(spline, 0.005f);
+	int i, resol = BKE_mask_spline_feather_resolution(spline, width, height);
 
 	feather = fp = MEM_callocN(2 * resol * sizeof(float), "mask point spline feather diff points");
 
@@ -448,13 +459,18 @@
 	return feather;
 }
 
-float *BKE_mask_point_segment_diff(MaskSpline *spline, MaskSplinePoint *point, int *tot_diff_point)
+float *BKE_mask_point_segment_feather_diff(MaskSpline *spline, MaskSplinePoint *point, int *tot_feather_point)
 {
+	return BKE_mask_point_segment_feather_diff_with_resolution(spline, point, 0, 0, tot_feather_point);
+}
+
+float *BKE_mask_point_segment_diff_with_resolution(MaskSpline *spline, MaskSplinePoint *point, int width, int height, int *tot_diff_point)
+{
 	MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point);
 
 	BezTriple *bezt, *next;
 	float *diff_points, *fp;
-	int j, resol = BKE_mask_spline_resolution(spline, 0.01f);
+	int j, resol = BKE_mask_spline_resolution(spline, width, height);
 
 	bezt = &point->bezt;
 
@@ -484,6 +500,11 @@
 	return diff_points;
 }
 
+float *BKE_mask_point_segment_diff(MaskSpline *spline, MaskSplinePoint *point, int *tot_diff_point)
+{
+	return BKE_mask_point_segment_diff_with_resolution(spline, point, 0, 0, tot_diff_point);
+}
+
 void BKE_mask_point_segment_co(MaskSpline *spline, MaskSplinePoint *point, float u, float co[2])
 {
 	MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point);
@@ -1816,9 +1837,11 @@
 			float (*diff_feather_points)[2];
 			int tot_diff_feather_points;
 
-			diff_points = BKE_mask_spline_differentiate(spline, &tot_diff_point, 1, max_dseg_len);
+			diff_points = BKE_mask_spline_differentiate_with_resolution(spline, width, height, &tot_diff_point);
 			if (tot_diff_point) {
-				diff_feather_points = BKE_mask_spline_feather_differentiated_points(spline, &tot_diff_feather_points, 1, max_dseg_len);
+				diff_feather_points =
+					BKE_mask_spline_feather_differentiated_points_with_resolution(spline, width, height,
+					                                                              &tot_diff_feather_points);
 			}
 
 			/* TODO, make this optional! */

Modified: branches/soc-2011-tomato/source/blender/editors/mask/mask_draw.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/mask/mask_draw.c	2012-06-01 11:50:32 UTC (rev 47315)
+++ branches/soc-2011-tomato/source/blender/editors/mask/mask_draw.c	2012-06-01 12:25:18 UTC (rev 47316)
@@ -323,7 +323,8 @@
 }
 
 static void draw_spline_curve(MaskLayer *masklay, MaskSpline *spline,
-                              const char draw_flag, const char draw_type)
+                              const char draw_flag, const char draw_type,
+                              int width, int height)
 {
 	unsigned char rgb_tmp[4];
 
@@ -336,7 +337,7 @@
 	int tot_feather_point;
 	float (*feather_points)[2];
 
-	diff_points = BKE_mask_spline_differentiate(spline, &tot_diff_point, 0, 0.0f);
+	diff_points = BKE_mask_spline_differentiate_with_resolution(spline, width, height, &tot_diff_point);
 
 	if (!diff_points)
 		return;
@@ -347,7 +348,7 @@
 		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 	}
 
-	feather_points = BKE_mask_spline_feather_differentiated_points(spline, &tot_feather_point, 0, 0.0f);
+	feather_points = BKE_mask_spline_feather_differentiated_points_with_resolution(spline, width, height, &tot_feather_point);
 
 	/* draw feather */
 	mask_spline_feather_color_get(masklay, spline, is_spline_sel, rgb_tmp);
@@ -371,8 +372,8 @@
 	(void)draw_type;
 }
 
-static void draw_masklays(Mask *mask,
-                          const char draw_flag, const char draw_type)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list