Add a toggle button to display motion tracker previews in grayscale.
authorKeir Mierle <mierle@gmail.com>
Sun, 4 Dec 2011 12:58:31 +0000 (12:58 +0000)
committerKeir Mierle <mierle@gmail.com>
Sun, 4 Dec 2011 12:58:31 +0000 (12:58 +0000)
release/scripts/startup/bl_ui/space_clip.py
source/blender/blenkernel/intern/tracking.c
source/blender/makesdna/DNA_tracking_types.h
source/blender/makesrna/intern/rna_tracking.c

index 5cdd1de547f4874c1165ee62243f74941f93868b..3acf87f7776f3e14168044e286e11b4e65c71fb9 100644 (file)
@@ -353,9 +353,15 @@ class CLIP_PT_track(Panel):
         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, "preview_grayscale", text="B/W", toggle=True)
 
         layout.separator()
 
index 361a6d50961aa0afe7fd4cf69861667949e0e490..80cd95d8a64c51fbe383d1061a2afdf988dc9463 100644 (file)
@@ -865,12 +865,12 @@ void BKE_tracking_context_free(MovieTrackingContext *context)
 /* 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)
+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
@@ -888,15 +888,27 @@ static void disable_imbuf_channels(ImBuf *ibuf, MovieTrackingTrack *track)
                                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];
-                               float gray = (0.2126f*r + 0.7152f*g + 0.0722f*b) / scale;
-                               rrgbf[0] = rrgbf[1] = rrgbf[2] = gray;
+                               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;
                                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];
-                               float gray = (0.2126f*r + 0.7152f*g + 0.0722f*b) / scale;
-                               rrgb[0] = rrgb[1] = rrgb[2] = gray;
+                               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;
+                               }
                        }
                }
        }
@@ -938,7 +950,9 @@ static ImBuf *get_area_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTracki
                origin[1]= y1-margin;
        }
 
-       disable_imbuf_channels(tmpibuf, track);
+       if (track->flag & TRACK_PREVIEW_GRAYSCALE) {
+               disable_imbuf_channels(tmpibuf, track, 1 /* grayscale */);
+       }
 
        return tmpibuf;
 }
@@ -967,7 +981,7 @@ static float *get_search_floatbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieT
        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;
@@ -979,22 +993,11 @@ static float *get_search_floatbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieT
 
                        if(tmpibuf->rect_float) {
                                float *rrgbf= tmpibuf->rect_float + pixel*4;
-
-                               if ((track->flag&(TRACK_DISABLE_RED|TRACK_DISABLE_GREEN|TRACK_DISABLE_BLUE))==0)
-                                       *fp= 0.2126*rrgbf[0] + 0.7152*rrgbf[1] + 0.0722*rrgbf[2];
-                               else
-                                       /* disable_imbuf_channels already did the grayscale conversion */
-                                       *fp= *rrgbf;
+                               *fp= 0.2126*rrgbf[0] + 0.7152*rrgbf[1] + 0.0722*rrgbf[2];
                        } else {
                                unsigned char *rrgb= (unsigned char*)tmpibuf->rect + pixel*4;
-
-                               if ((track->flag&(TRACK_DISABLE_RED|TRACK_DISABLE_GREEN|TRACK_DISABLE_BLUE))==0)
-                                       *fp= (0.2126*rrgb[0] + 0.7152*rrgb[1] + 0.0722*rrgb[2])/255.0f;
-                               else
-                                       /* disable_imbuf_channels already did the grayscale conversion */
-                                       *fp= *rrgb / 255.0;
+                               *fp= (0.2126*rrgb[0] + 0.7152*rrgb[1] + 0.0722*rrgb[2])/255.0f;
                        }
-
                        fp++;
                }
        }
@@ -1016,22 +1019,11 @@ static unsigned char *get_ucharbuf(ImBuf *ibuf, int flags)
 
                        if(ibuf->rect_float) {
                                float *rrgbf= ibuf->rect_float + pixel*4;
-
-                               if ((flags&(TRACK_DISABLE_RED|TRACK_DISABLE_GREEN|TRACK_DISABLE_BLUE))==0)
-                                       *cp= FTOCHAR(0.2126f*rrgbf[0] + 0.7152f*rrgbf[1] + 0.0722f*rrgbf[2]);
-                               else
-                                       /* disable_imbuf_channels already did the grayscale conversion */
-                                       *cp= FTOCHAR(*rrgbf);
+                               *cp= FTOCHAR(0.2126f*rrgbf[0] + 0.7152f*rrgbf[1] + 0.0722f*rrgbf[2]);
                        } else {
                                unsigned char *rrgb= (unsigned char*)ibuf->rect + pixel*4;
-
-                               if ((flags&(TRACK_DISABLE_RED|TRACK_DISABLE_GREEN|TRACK_DISABLE_BLUE))==0)
-                                       *cp= 0.2126f*rrgb[0] + 0.7152f*rrgb[1] + 0.0722f*rrgb[2];
-                               else
-                                       /* disable_imbuf_channels already did the grayscale conversion */
-                                       *cp= *rrgb;
+                               *cp= 0.2126f*rrgb[0] + 0.7152f*rrgb[1] + 0.0722f*rrgb[2];
                        }
-
                        cp++;
                }
        }
@@ -1046,7 +1038,7 @@ static unsigned char *get_search_bytebuf(ImBuf *ibuf, MovieTrackingTrack *track,
        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;
index 82ccbf87c0b5508875332b6da78e6d3e9ca56727..9058e82b36722a2b3cf8cc2607c36285b78b3ff6 100644 (file)
@@ -207,6 +207,7 @@ enum {
 #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
index 5a2ef54cfc1ef8b1d28486b67e4f678650246a49..7e8e7ba3a6b7799c06f27d5aaea06dad83441e04 100644 (file)
@@ -673,6 +673,12 @@ static void rna_def_trackingTrack(BlenderRNA *brna)
        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, "preview_grayscale", 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);