[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46759] branches/soc-2011-tomato/source/ blender: mask editor now stores points/handles in 1:1 aspect, makes tool code _much_ more logical/easier.

Campbell Barton ideasman42 at gmail.com
Fri May 18 10:59:07 CEST 2012


Revision: 46759
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46759
Author:   campbellbarton
Date:     2012-05-18 08:59:05 +0000 (Fri, 18 May 2012)
Log Message:
-----------
mask editor now stores points/handles in 1:1 aspect, makes tool code _much_ more logical/easier.

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_editor.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_dopesheet_ops.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_editor.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c
    branches/soc-2011-tomato/source/blender/editors/transform/transform.c
    branches/soc-2011-tomato/source/blender/editors/transform/transform_conversions.c
    branches/soc-2011-tomato/source/blender/nodes/composite/nodes/node_composite_mask.c

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h	2012-05-18 08:24:31 UTC (rev 46758)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h	2012-05-18 08:59:05 UTC (rev 46759)
@@ -34,6 +34,8 @@
 struct MaskSpline;
 struct MaskSplinePoint;
 struct MaskSplinePointUW;
+struct MovieClip;
+struct MovieClipUser;
 struct Scene;
 
 /* shapes */
@@ -77,6 +79,9 @@
 void BKE_mask_free(struct Mask *mask);
 void BKE_mask_unlink(struct Main *bmain, struct Mask *mask);
 
+void BKE_mask_coord_from_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]);
+void BKE_mask_coord_to_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]);
+
 /* parenting */
 
 void BKE_mask_evaluate_all_masks(struct Main *bmain, float ctime);

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c	2012-05-18 08:24:31 UTC (rev 46758)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c	2012-05-18 08:59:05 UTC (rev 46759)
@@ -52,6 +52,7 @@
 #include "BKE_main.h"
 #include "BKE_mask.h"
 #include "BKE_tracking.h"
+#include "BKE_movieclip.h"
 #include "BKE_utildefines.h"
 
 /* shapes */
@@ -727,6 +728,49 @@
 	mask->id.us = 0;
 }
 
+void BKE_mask_coord_from_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2])
+{
+	int width, height;
+
+	/* scaling for the clip */
+	BKE_movieclip_get_size(clip, user, &width, &height);
+
+	if (width == height) {
+		r_co[0] = co[0];
+		r_co[1] = co[1];
+	}
+	else if (width < height) {
+		r_co[0] = ((co[0] - 0.5f) * ((float)width / (float)height)) + 0.5f;
+		r_co[1] = co[1];
+	}
+	else { /* (width > height) */
+		r_co[0] = co[0];
+		r_co[1] = ((co[1] - 0.5f) * ((float)height / (float)width)) + 0.5f;
+	}
+}
+
+/* as above but divide */
+void BKE_mask_coord_to_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2])
+{
+	int width, height;
+
+	/* scaling for the clip */
+	BKE_movieclip_get_size(clip, user, &width, &height);
+
+	if (width == height) {
+		r_co[0] = co[0];
+		r_co[1] = co[1];
+	}
+	else if (width < height) {
+		r_co[0] = ((co[0] - 0.5f) / ((float)width / (float)height)) + 0.5f;
+		r_co[1] = co[1];
+	}
+	else { /* (width > height) */
+		r_co[0] = co[0];
+		r_co[1] = ((co[1] - 0.5f) / ((float)height / (float)width)) + 0.5f;
+	}
+}
+
 static void evaluate_mask_parent(MaskParent *parent, float ctime, float co[2])
 {
 	if (!parent)
@@ -744,10 +788,12 @@
 			if (ob) {
 				MovieTrackingTrack *track = BKE_tracking_named_track(tracking, ob, parent->sub_parent);
 
+				MovieClipUser user = {0};
+				user.framenr = ctime;
+
 				if (track) {
 					MovieTrackingMarker *marker = BKE_tracking_get_marker(track, ctime);
-
-					copy_v2_v2(co, marker->pos);
+					BKE_mask_coord_from_movieclip(clip, &user, co, marker->pos);
 				}
 			}
 		}

Modified: branches/soc-2011-tomato/source/blender/editors/mask/mask_editor.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/mask/mask_editor.c	2012-05-18 08:24:31 UTC (rev 46758)
+++ branches/soc-2011-tomato/source/blender/editors/mask/mask_editor.c	2012-05-18 08:59:05 UTC (rev 46759)
@@ -81,6 +81,7 @@
 
 	if (sc) {
 		ED_clip_mouse_pos(C, event, co);
+		BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co);
 	}
 	else {
 		/* possible other spaces from which mask editing is available */

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/clip_dopesheet_ops.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/clip_dopesheet_ops.c	2012-05-18 08:24:31 UTC (rev 46758)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/clip_dopesheet_ops.c	2012-05-18 08:59:05 UTC (rev 46759)
@@ -59,6 +59,7 @@
 
 #include "clip_intern.h"	// own include
 
+#if 0
 static int ED_space_clip_dopesheet_poll(bContext *C)
 {
 	SpaceClip *sc = CTX_wm_space_clip(C);
@@ -73,6 +74,7 @@
 
 	return FALSE;
 }
+#endif
 
 /********************** select channel operator *********************/
 

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/clip_editor.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/clip_editor.c	2012-05-18 08:24:31 UTC (rev 46758)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/clip_editor.c	2012-05-18 08:59:05 UTC (rev 46759)
@@ -268,10 +268,13 @@
 	int w, h;
 
 	ED_space_clip_aspect(sc, aspx, aspy);
-        ED_space_clip_size(sc, &w, &h);
+	ED_space_clip_size(sc, &w, &h);
 
+	/* now this is not accounted for! */
+#if 0
 	*aspx *= (float)w;
 	*aspy *= (float)h;
+#endif
 
 	if(*aspx < *aspy) {
 		*aspy= *aspy / *aspx;

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c	2012-05-18 08:24:31 UTC (rev 46758)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c	2012-05-18 08:59:05 UTC (rev 46759)
@@ -1101,6 +1101,10 @@
 		int width, height;
 		float zoomx, zoomy, aspx, aspy;
 
+		/* frame image */
+		float maxdim;
+		float xofs, yofs;
+
 		/* find window pixel coordinates of origin */
 		UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y);
 
@@ -1108,10 +1112,24 @@
 		ED_space_clip_zoom(sc, ar, &zoomx, &zoomy);
 		ED_space_clip_aspect(sc, &aspx, &aspy);
 
+		/* frame the image */
+		maxdim = maxf(width, height);
+		if (width == height) {
+			xofs = yofs = 0;
+		}
+		else if (width < height) {
+			xofs = ((height - width) / -2.0f) * zoomx;
+			yofs = 0.0f;
+		}
+		else { /* (width > height) */
+			xofs = 0.0f;
+			yofs = ((width - height) / -2.0f) * zoomy;
+		}
+
 		/* apply transformation so mask editing tools will assume drawing from the origin in normalized space */
 		glPushMatrix();
-		glTranslatef(x, y, 0);
-		glScalef(width*zoomx, height*zoomy, 0);
+		glTranslatef(x + xofs, y + yofs, 0);
+		glScalef(maxdim * zoomx, maxdim * zoomy, 0);
 		glMultMatrixf(sc->stabmat);
 
 		ED_mask_draw((bContext *)C, width*aspx, height*aspy, zoomx, zoomy);

Modified: branches/soc-2011-tomato/source/blender/editors/transform/transform.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/transform/transform.c	2012-05-18 08:24:31 UTC (rev 46758)
+++ branches/soc-2011-tomato/source/blender/editors/transform/transform.c	2012-05-18 08:59:05 UTC (rev 46759)
@@ -163,12 +163,22 @@
 	else if (t->spacetype==SPACE_CLIP) {
 		View2D *v2d = t->view;
 		float divx, divy;
+		float mulx, muly;
 
 		divx = v2d->mask.xmax-v2d->mask.xmin;
 		divy = v2d->mask.ymax-v2d->mask.ymin;
 
-		r_vec[0] = (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
-		r_vec[1] = (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
+		mulx = (v2d->cur.xmax-v2d->cur.xmin);
+		muly = (v2d->cur.ymax-v2d->cur.ymin);
+
+		if (t->options & CTX_MASK) {
+			/* clamp w/h, mask only */
+			divx = divy = minf(divx, divy);
+			mulx = muly = minf(mulx, muly);
+		}
+
+		r_vec[0] = mulx * (dx) / divx;
+		r_vec[1] = muly * (dy) / divy;
 		r_vec[2] = 0.0f;
 
 		if (t->options & CTX_MASK) {
@@ -303,17 +313,22 @@
 		if (t->options & (CTX_MOVIECLIP | CTX_MASK)) {
 			SpaceClip *sc = t->sa->spacedata.first;
 			float aspx, aspy;
-			int width, height;
 
-			ED_space_clip_size(sc, &width, &height);
 
-			if (t->options & CTX_MOVIECLIP)
+			if (t->options & CTX_MOVIECLIP) {
+				int width, height;
+				ED_space_clip_size(sc, &width, &height);
 				ED_space_clip_aspect(sc, &aspx, &aspy);
-			else if (t->options & CTX_MASK)
+
+				vec[0] *= width / aspx;
+				vec[1] *= height / aspy;
+			}
+			else if (t->options & CTX_MASK) {
 				ED_space_clip_mask_aspect(sc, &aspx, &aspy);
 
-			vec[0] *= width / aspx;
-			vec[1] *= height / aspy;
+				vec[0] /= aspx;
+				vec[1] /= aspy;
+			}
 		}
 	}
 }
@@ -340,15 +355,22 @@
 		if (t->options & (CTX_MOVIECLIP | CTX_MASK)) {
 			SpaceClip *sc = t->sa->spacedata.first;
 			float aspx, aspy;
-			int width, height;
 
-			if (t->options & CTX_MOVIECLIP)
+			if (t->options & CTX_MOVIECLIP) {
+				int width, height;
 				ED_space_clip_size(sc, &width, &height);
-			else if (t->options & CTX_MASK)
 				ED_space_clip_aspect(sc, &aspx, &aspy);
 
-			vec[0] *= aspx / width;
-			vec[1] *= aspy / height;
+				vec[0] *= aspx / width;
+				vec[1] *= aspy / height;
+			}
+			else if (t->options & CTX_MASK) {
+				ED_space_clip_aspect(sc, &aspx, &aspy);
+				ED_space_clip_mask_aspect(sc, &aspx, &aspy);
+
+				vec[0] *= aspx;
+				vec[1] *= aspy;
+			}
 		}
 	}
 }

Modified: branches/soc-2011-tomato/source/blender/editors/transform/transform_conversions.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/transform/transform_conversions.c	2012-05-18 08:24:31 UTC (rev 46758)
+++ branches/soc-2011-tomato/source/blender/editors/transform/transform_conversions.c	2012-05-18 08:59:05 UTC (rev 46759)
@@ -5875,12 +5875,9 @@
 		}
 	}
 	else {
-		int width, height;
-
 		tdm->is_handle = TRUE;
 
-		ED_space_clip_mask_size(sc, &width, &height);
-		BKE_mask_point_handle(point, width, height, tdm->handle);
+		BKE_mask_point_handle(point, aspx, aspy, tdm->handle);
 
 		copy_v2_v2(tdm->orig_handle, tdm->handle);
 

Modified: branches/soc-2011-tomato/source/blender/nodes/composite/nodes/node_composite_mask.c
===================================================================
--- branches/soc-2011-tomato/source/blender/nodes/composite/nodes/node_composite_mask.c	2012-05-18 08:24:31 UTC (rev 46758)
+++ branches/soc-2011-tomato/source/blender/nodes/composite/nodes/node_composite_mask.c	2012-05-18 08:59:05 UTC (rev 46759)
@@ -94,6 +94,26 @@
 
 				diff_points = BKE_mask_spline_differentiate(spline, &tot_diff_point);
 
+				/* TODO, make this optional! */
+				if (sx != sy) {
+					float *fp;
+					int i;
+					float asp;
+
+					if (sx < sy) {
+						fp = &diff_points[0];
+						asp = (float)sx / (float)sy;
+					}
+					else {
+						fp = &diff_points[1];
+						asp = (float)sy / (float)sx;
+					}
+
+					for (i = 0; i < tot_diff_point; i++, fp += 2) {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list