[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42996] trunk/blender: Camera tracking: improvements of track preview widget

Sergey Sharybin sergey.vfx at gmail.com
Fri Dec 30 11:20:33 CET 2011


Revision: 42996
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42996
Author:   nazgul
Date:     2011-12-30 10:20:29 +0000 (Fri, 30 Dec 2011)
Log Message:
-----------
Camera tracking: improvements of track preview widget

- Enable bicybic filtering fir image displayed in track preview
- Option to show grayscale content of track preview
- When some channels are disabled, display exactly the same
  content of preview image which is sending to tracker library.

Merged from tomato branch using command:
    svn merge -r42382:42383 -r42384:42385 -r42394:42395 \
	    -r42397:42398 -r42398:42399 -r42406:42407 \
		-r42410:42411 -r42417:42418 -r42471:42472 \
		^/branches/soc-2011-tomato
  

Revision Links:
--------------
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42382
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42384
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42394
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42397
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42398
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42406
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42410
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42417
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42471

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_clip.py
    trunk/blender/source/blender/blenkernel/intern/tracking.c
    trunk/blender/source/blender/editors/interface/interface_draw.c
    trunk/blender/source/blender/makesdna/DNA_tracking_types.h
    trunk/blender/source/blender/makesrna/intern/rna_tracking.c

Property Changed:
----------------
    trunk/blender/
    trunk/blender/source/blender/editors/space_outliner/


Property changes on: trunk/blender
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/soc-2011-cucumber:37517
/branches/soc-2011-tomato:42376,42378-42379,42397,42400
   + /branches/soc-2011-cucumber:37517
/branches/soc-2011-tomato:42376,42378-42379,42383,42385,42395,42397-42400,42407,42411,42418,42472

Modified: trunk/blender/release/scripts/startup/bl_ui/space_clip.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_clip.py	2011-12-30 09:23:06 UTC (rev 42995)
+++ trunk/blender/release/scripts/startup/bl_ui/space_clip.py	2011-12-30 10:20:29 UTC (rev 42996)
@@ -352,10 +352,16 @@
         layout.template_track(sc, "scopes")
 
         row = layout.row(align=True)
-        row.prop(act_track, "use_red_channel", text="R", toggle=True)
-        row.prop(act_track, "use_green_channel", text="G", toggle=True)
-        row.prop(act_track, "use_blue_channel", text="B", toggle=True)
+        sub = row.row()
+        sub.prop(act_track, "use_red_channel", text="R", toggle=True)
+        sub.prop(act_track, "use_green_channel", text="G", toggle=True)
+        sub.prop(act_track, "use_blue_channel", text="B", toggle=True)
 
+        row.separator()
+
+        sub = row.row()
+        sub.prop(act_track, "use_grayscale_preview", text="B/W", toggle=True)
+
         layout.separator()
 
         row = layout.row(align=True)

Modified: trunk/blender/source/blender/blenkernel/intern/tracking.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/tracking.c	2011-12-30 09:23:06 UTC (rev 42995)
+++ trunk/blender/source/blender/blenkernel/intern/tracking.c	2011-12-30 10:20:29 UTC (rev 42996)
@@ -883,29 +883,53 @@
 	MEM_freeN(context);
 }
 
-static void disable_imbuf_channels(ImBuf *ibuf, MovieTrackingTrack *track)
+/* zap channels from the imbuf that are disabled by the user. this can lead to
+ * better tracks sometimes. however, instead of simply zeroing the channels
+ * out, do a partial grayscale conversion so the display is better. */
+static void disable_imbuf_channels(ImBuf *ibuf, MovieTrackingTrack *track, int grayscale)
 {
 	int x, y;
+	float scale;
 
-	if((track->flag&(TRACK_DISABLE_RED|TRACK_DISABLE_GREEN|TRACK_DISABLE_BLUE))==0)
+	if((track->flag&(TRACK_DISABLE_RED|TRACK_DISABLE_GREEN|TRACK_DISABLE_BLUE))==0 && !grayscale)
 		return;
 
+	/* If only some components are selected, it's important to rescale the result
+	 * appropriately so that e.g. if only blue is selected, it's not zeroed out. */
+	scale = ((track->flag&TRACK_DISABLE_RED  ) ? 0.0f : 0.2126f) +
+	        ((track->flag&TRACK_DISABLE_GREEN) ? 0.0f : 0.7152f) +
+	        ((track->flag&TRACK_DISABLE_BLUE)  ? 0.0f : 0.0722f);
+
 	for(y= 0; y<ibuf->y; y++) {
 		for (x= 0; x<ibuf->x; x++) {
 			int pixel= ibuf->x*y + x;
 
 			if(ibuf->rect_float) {
 				float *rrgbf= ibuf->rect_float + pixel*4;
-
-				if(track->flag&TRACK_DISABLE_RED)	rrgbf[0]= 0;
-				if(track->flag&TRACK_DISABLE_GREEN)	rrgbf[1]= 0;
-				if(track->flag&TRACK_DISABLE_BLUE)	rrgbf[2]= 0;
+				float r = (track->flag&TRACK_DISABLE_RED)   ? 0.0f : rrgbf[0];
+				float g = (track->flag&TRACK_DISABLE_GREEN) ? 0.0f : rrgbf[1];
+				float b = (track->flag&TRACK_DISABLE_BLUE)  ? 0.0f : rrgbf[2];
+				if (grayscale) {
+					float gray = (0.2126f*r + 0.7152f*g + 0.0722f*b) / scale;
+					rrgbf[0] = rrgbf[1] = rrgbf[2] = gray;
+				} else {
+					rrgbf[0] = r;
+					rrgbf[1] = g;
+					rrgbf[2] = b;
+				}
 			} else {
 				char *rrgb= (char*)ibuf->rect + pixel*4;
-
-				if(track->flag&TRACK_DISABLE_RED)	rrgb[0]= 0;
-				if(track->flag&TRACK_DISABLE_GREEN)	rrgb[1]= 0;
-				if(track->flag&TRACK_DISABLE_BLUE)	rrgb[2]= 0;
+				char r = (track->flag&TRACK_DISABLE_RED)   ? 0 : rrgb[0];
+				char g = (track->flag&TRACK_DISABLE_GREEN) ? 0 : rrgb[1];
+				char b = (track->flag&TRACK_DISABLE_BLUE)  ? 0 : rrgb[2];
+				if (grayscale) {
+					float gray = (0.2126f*r + 0.7152f*g + 0.0722f*b) / scale;
+					rrgb[0] = rrgb[1] = rrgb[2] = gray;
+				} else {
+					rrgb[0] = r;
+					rrgb[1] = g;
+					rrgb[2] = b;
+				}
 			}
 		}
 	}
@@ -947,7 +971,12 @@
 		origin[1]= y1-margin;
 	}
 
-	disable_imbuf_channels(tmpibuf, track);
+	if ((track->flag & TRACK_PREVIEW_GRAYSCALE) ||
+			(track->flag & TRACK_DISABLE_RED)       ||
+			(track->flag & TRACK_DISABLE_GREEN)     ||
+			(track->flag & TRACK_DISABLE_BLUE) ) {
+		disable_imbuf_channels(tmpibuf, track, 1 /* grayscale */);
+	}
 
 	return tmpibuf;
 }
@@ -976,7 +1005,7 @@
 	height= (track->search_max[1]-track->search_min[1])*ibuf->y;
 
 	tmpibuf= BKE_tracking_get_search_imbuf(ibuf, track, marker, 0, 0, pos, origin);
-	disable_imbuf_channels(tmpibuf, track);
+	disable_imbuf_channels(tmpibuf, track, 0 /* don't grayscale */);
 
 	*width_r= width;
 	*height_r= height;
@@ -988,14 +1017,11 @@
 
 			if(tmpibuf->rect_float) {
 				float *rrgbf= tmpibuf->rect_float + pixel*4;
-
 				*fp= 0.2126*rrgbf[0] + 0.7152*rrgbf[1] + 0.0722*rrgbf[2];
 			} else {
 				unsigned char *rrgb= (unsigned char*)tmpibuf->rect + pixel*4;
-
 				*fp= (0.2126*rrgb[0] + 0.7152*rrgb[1] + 0.0722*rrgb[2])/255.0f;
 			}
-
 			fp++;
 		}
 	}
@@ -1017,14 +1043,11 @@
 
 			if(ibuf->rect_float) {
 				float *rrgbf= ibuf->rect_float + pixel*4;
-
 				*cp= FTOCHAR(0.2126f*rrgbf[0] + 0.7152f*rrgbf[1] + 0.0722f*rrgbf[2]);
 			} else {
 				unsigned char *rrgb= (unsigned char*)ibuf->rect + pixel*4;
-
 				*cp= 0.2126f*rrgb[0] + 0.7152f*rrgb[1] + 0.0722f*rrgb[2];
 			}
-
 			cp++;
 		}
 	}
@@ -1039,7 +1062,7 @@
 	unsigned char *pixels;
 
 	tmpibuf= BKE_tracking_get_search_imbuf(ibuf, track, marker, 0, 0, pos, origin);
-	disable_imbuf_channels(tmpibuf, track);
+	disable_imbuf_channels(tmpibuf, track, 0 /* don't grayscale */);
 
 	*width_r= tmpibuf->x;
 	*height_r= tmpibuf->y;

Modified: trunk/blender/source/blender/editors/interface/interface_draw.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_draw.c	2011-12-30 09:23:06 UTC (rev 42995)
+++ trunk/blender/source/blender/editors/interface/interface_draw.c	2011-12-30 10:20:29 UTC (rev 42996)
@@ -1465,6 +1465,8 @@
 {
 	ImBuf *scaleibuf;
 	int x, y, w= ibuf->x*zoomx, h= ibuf->y*zoomy;
+	const float max_x= ibuf->x-1.0f;
+	const float max_y= ibuf->y-1.0f;
 	const float scalex= 1.0f/zoomx;
 	const float scaley= 1.0f/zoomy;
 
@@ -1472,15 +1474,13 @@
 
 	for(y= 0; y<scaleibuf->y; y++) {
 		for (x= 0; x<scaleibuf->x; x++) {
-			int pixel= scaleibuf->x*y + x;
-			int orig_pixel= ibuf->x*(int)(scaley*(float)y) + (int)(scalex*(float)x);
-			char *rrgb= (char*)scaleibuf->rect + pixel*4;
-			char *orig_rrgb= (char*)ibuf->rect + orig_pixel*4;
+			float src_x= scalex*x;
+			float src_y= scaley*y;
 
-			rrgb[0]= orig_rrgb[0];
-			rrgb[1]= orig_rrgb[1];
-			rrgb[2]= orig_rrgb[2];
-			rrgb[3]= orig_rrgb[3];
+			CLAMP(src_x, 0, max_x);
+			CLAMP(src_y, 0, max_y);
+
+			bicubic_interpolation(ibuf, scaleibuf, src_x, src_y, x, y);
 		}
 	}
 


Property changes on: trunk/blender/source/blender/editors/space_outliner
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/soc-2011-pepper/source/blender/editors/space_outliner:36831-38987
/branches/soc-2011-tomato/source/blender/editors/space_outliner:42376,42378-42379,42397,42400
   + /branches/soc-2011-pepper/source/blender/editors/space_outliner:36831-38987
/branches/soc-2011-tomato/source/blender/editors/space_outliner:42376,42378-42379,42383,42385,42395,42397-42400,42407,42411,42418,42472

Modified: trunk/blender/source/blender/makesdna/DNA_tracking_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_tracking_types.h	2011-12-30 09:23:06 UTC (rev 42995)
+++ trunk/blender/source/blender/makesdna/DNA_tracking_types.h	2011-12-30 10:20:29 UTC (rev 42996)
@@ -207,6 +207,7 @@
 #define TRACK_LOCKED		(1<<6)
 #define TRACK_CUSTOMCOLOR	(1<<7)
 #define TRACK_USE_2D_STAB	(1<<8)
+#define TRACK_PREVIEW_GRAYSCALE	(1<<9)
 
 /* MovieTrackingTrack->tracker */
 #define TRACKER_KLT		0

Modified: trunk/blender/source/blender/makesrna/intern/rna_tracking.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_tracking.c	2011-12-30 09:23:06 UTC (rev 42995)
+++ trunk/blender/source/blender/makesrna/intern/rna_tracking.c	2011-12-30 10:20:29 UTC (rev 42996)
@@ -673,6 +673,12 @@
 	RNA_def_property_ui_text(prop, "Use Blue Channel", "Use blue channel from footage for tracking");
 	RNA_def_property_update(prop, NC_MOVIECLIP|ND_DISPLAY, NULL);
 
+	/* preview_grayscale */
+	prop= RNA_def_property(srna, "use_grayscale_preview", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACK_PREVIEW_GRAYSCALE);
+	RNA_def_property_ui_text(prop, "Grayscale", "Display what the tracking algorithm sees in the preview");
+	RNA_def_property_update(prop, NC_MOVIECLIP|ND_DISPLAY, NULL);
+
 	/* has bundle */
 	prop= RNA_def_property(srna, "has_bundle", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACK_HAS_BUNDLE);




More information about the Bf-blender-cvs mailing list