[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56517] trunk/blender/source/blender: Fix for crash when using 2D stabilization for float movie clips

Sergey Sharybin sergey.vfx at gmail.com
Mon May 6 19:59:03 CEST 2013


Revision: 56517
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56517
Author:   nazgul
Date:     2013-05-06 17:59:02 +0000 (Mon, 06 May 2013)
Log Message:
-----------
Fix for crash when using 2D stabilization for float movie clips

Also removed unneeded image buffer scaling, it was only needed
for "early output" if there was no rotation. That is no longer
supported since it used to pixelate result a lot and interpolation
is always used now.

Saves quite a few of memory and CPU cycles.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/tracking.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/makesdna/DNA_tracking_types.h

Modified: trunk/blender/source/blender/blenkernel/intern/tracking.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/tracking.c	2013-05-06 17:24:30 UTC (rev 56516)
+++ trunk/blender/source/blender/blenkernel/intern/tracking.c	2013-05-06 17:59:02 UTC (rev 56517)
@@ -154,9 +154,6 @@
 	tracking_reconstruction_free(&tracking->reconstruction);
 	tracking_objects_free(&tracking->objects);
 
-	if (tracking->stabilization.scaleibuf)
-		IMB_freeImBuf(tracking->stabilization.scaleibuf);
-
 	if (tracking->camera.intrinsics)
 		BKE_tracking_distortion_free(tracking->camera.intrinsics);
 
@@ -3488,34 +3485,6 @@
 	return stab->scale;
 }
 
-static ImBuf *stabilization_allocate_ibuf(ImBuf *cacheibuf, ImBuf *srcibuf, int fill)
-{
-	int flags;
-
-	if (cacheibuf && (cacheibuf->x != srcibuf->x || cacheibuf->y != srcibuf->y)) {
-		IMB_freeImBuf(cacheibuf);
-		cacheibuf = NULL;
-	}
-
-	flags = IB_rect;
-
-	if (srcibuf->rect_float)
-		flags |= IB_rectfloat;
-
-	if (cacheibuf) {
-		if (fill) {
-			float col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
-
-			IMB_rectfill(cacheibuf, col);
-		}
-	}
-	else {
-		cacheibuf = IMB_allocImBuf(srcibuf->x, srcibuf->y, srcibuf->planes, flags);
-	}
-
-	return cacheibuf;
-}
-
 /* NOTE: frame number should be in clip space, not scene space */
 void BKE_tracking_stabilization_data_get(MovieTracking *tracking, int framenr, int width, int height,
                                          float loc[2], float *scale, float *angle)
@@ -3568,6 +3537,7 @@
 	float mat[4][4];
 	int j, filter = tracking->stabilization.filter;
 	void (*interpolation)(struct ImBuf *, struct ImBuf *, float, float, int, int) = NULL;
+	int ibuf_flags;
 
 	if (loc)
 		copy_v2_v2(tloc, loc);
@@ -3575,6 +3545,7 @@
 	if (scale)
 		tscale = *scale;
 
+	/* Perform early output if no stabilization is used. */
 	if ((stab->flag & TRACKING_2D_STABILIZATION) == 0) {
 		if (loc)
 			zero_v2(loc);
@@ -3588,25 +3559,17 @@
 		return ibuf;
 	}
 
-	BKE_tracking_stabilization_data_get(tracking, framenr, width, height, tloc, &tscale, &tangle);
+	/* Allocate frame for stabilization result. */
+	ibuf_flags = 0;
+	if (ibuf->rect)
+		ibuf_flags |= IB_rect;
+	if (ibuf->rect_float)
+		ibuf_flags |= IB_rectfloat;
 
-	tmpibuf = stabilization_allocate_ibuf(NULL, ibuf, TRUE);
+	tmpibuf = IMB_allocImBuf(ibuf->x, ibuf->y, ibuf->planes, ibuf_flags);
 
-	/* scale would be handled by matrix transformation when angle is non-zero */
-	if (tscale != 1.0f && tangle == 0.0f) {
-		ImBuf *scaleibuf;
-
-		stabilization_calculate_autoscale_factor(tracking, width, height);
-
-		scaleibuf = stabilization_allocate_ibuf(stab->scaleibuf, ibuf, 0);
-		stab->scaleibuf = scaleibuf;
-
-		IMB_rectcpy(scaleibuf, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y);
-		IMB_scalefastImBuf(scaleibuf, ibuf->x * tscale, ibuf->y * tscale);
-
-		ibuf = scaleibuf;
-	}
-
+	/* Calculate stabilization matrix. */
+	BKE_tracking_stabilization_data_get(tracking, framenr, width, height, tloc, &tscale, &tangle);
 	BKE_tracking_stabilization_data_to_mat4(ibuf->x, ibuf->y, aspect, tloc, tscale, tangle, mat);
 	invert_m4(mat);
 
@@ -3627,7 +3590,7 @@
 	 * But need to keep an eye on this if the function will be
 	 * used in other cases.
 	 */
-    #pragma omp parallel for if(tmpibuf->y > 128)
+	#pragma omp parallel for if(tmpibuf->y > 128)
 	for (j = 0; j < tmpibuf->y; j++) {
 		int i;
 		for (i = 0; i < tmpibuf->x; i++) {
@@ -3639,6 +3602,7 @@
 		}
 	}
 
+	/* TODO(sergey): we've got no mipmaps actually? */
 	tmpibuf->userflags |= IB_MIPMAP_INVALID;
 
 	if (tmpibuf->rect_float)

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2013-05-06 17:24:30 UTC (rev 56516)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2013-05-06 17:59:02 UTC (rev 56517)
@@ -6633,7 +6633,6 @@
 	clip->tracking.stats = NULL;
 
 	clip->tracking.stabilization.ok = 0;
-	clip->tracking.stabilization.scaleibuf = NULL;
 	clip->tracking.stabilization.rot_track = newdataadr(fd, clip->tracking.stabilization.rot_track);
 
 	clip->tracking.dopesheet.ok = 0;

Modified: trunk/blender/source/blender/makesdna/DNA_tracking_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_tracking_types.h	2013-05-06 17:24:30 UTC (rev 56516)
+++ trunk/blender/source/blender/makesdna/DNA_tracking_types.h	2013-05-06 17:59:02 UTC (rev 56517)
@@ -205,8 +205,6 @@
 	/* some pre-computing run-time variables */
 	int ok;                     /* are precomputed values and scaled buf relevant? */
 	float scale;                /* autoscale factor */
-
-	struct ImBuf *scaleibuf;    /* currently scaled ibuf */
 } MovieTrackingStabilization;
 
 typedef struct MovieTrackingReconstruction {




More information about the Bf-blender-cvs mailing list