Tomato: configurable filter type for 2d stabilization
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 16 Feb 2012 15:03:37 +0000 (15:03 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 16 Feb 2012 15:03:37 +0000 (15:03 +0000)
release/scripts/startup/bl_ui/space_clip.py
source/blender/blenkernel/intern/movieclip.c
source/blender/blenkernel/intern/tracking.c
source/blender/makesdna/DNA_tracking_types.h
source/blender/makesrna/intern/rna_tracking.c

index bb5c60f..d911616 100644 (file)
@@ -686,6 +686,8 @@ class CLIP_PT_stabilization(Panel):
         row.active = stab.rotation_track is not None
         row.prop(stab, "influence_rotation")
 
+        layout.prop(stab, "filter_type")
+
 
 class CLIP_PT_marker(Panel):
     bl_space_type = 'CLIP_EDITOR'
index ce0d169..69b32ce 100644 (file)
@@ -280,7 +280,7 @@ typedef struct MovieClipCache {
                int postprocess_flag;
 
                float loc[2], scale, angle, aspect;
-               int proxy;
+               int proxy, filter;
                short render_flag;
        } stabilized;
 } MovieClipCache;
@@ -706,6 +706,7 @@ ImBuf *BKE_movieclip_get_postprocessed_ibuf(MovieClip *clip, MovieClipUser *user
 static ImBuf *get_stable_cached_frame(MovieClip *clip, MovieClipUser *user, int framenr, int postprocess_flag)
 {
        MovieClipCache *cache = clip->cache;
+       MovieTracking *tracking = &clip->tracking;
        ImBuf *stableibuf;
        float tloc[2], tscale, tangle;
        short proxy = IMB_PROXY_NONE;
@@ -728,7 +729,10 @@ static ImBuf *get_stable_cached_frame(MovieClip *clip, MovieClipUser *user, int
                return NULL;
 
        /* stabilization also depends on pixel aspect ratio */
-       if(cache->stabilized.aspect != clip->tracking.camera.pixel_aspect)
+       if(cache->stabilized.aspect != tracking->camera.pixel_aspect)
+               return NULL;
+
+       if(cache->stabilized.filter != tracking->stabilization.filter)
                return NULL;
 
        stableibuf = cache->stabilized.ibuf;
@@ -752,6 +756,7 @@ static ImBuf *put_stabilized_frame_to_cache(MovieClip *clip, MovieClipUser *user
                                             int framenr, int postprocess_flag)
 {
        MovieClipCache *cache = clip->cache;
+       MovieTracking *tracking = &clip->tracking;
        ImBuf *stableibuf;
        float tloc[2], tscale, tangle;
 
@@ -767,7 +772,8 @@ static ImBuf *put_stabilized_frame_to_cache(MovieClip *clip, MovieClipUser *user
        cache->stabilized.scale = tscale;
        cache->stabilized.angle = tangle;
        cache->stabilized.framenr = framenr;
-       cache->stabilized.aspect = clip->tracking.camera.pixel_aspect;
+       cache->stabilized.aspect = tracking->camera.pixel_aspect;
+       cache->stabilized.filter = tracking->stabilization.filter;
 
        if(clip->flag&MCLIP_USE_PROXY) {
                cache->stabilized.proxy= rendersize_to_proxy(user, clip->flag);
index 0476691..7461e05 100644 (file)
@@ -2688,19 +2688,26 @@ ImBuf *BKE_tracking_stabilize(MovieTracking *tracking, int framenr, ImBuf *ibuf,
                IMB_rectcpy(tmpibuf, ibuf, tloc[0]-(tscale-1.0f)*width/2.0f, tloc[1]-(tscale-1.0f)*height/2.0f, 0, 0, ibuf->x, ibuf->y);
        } else {
                float mat[4][4];
-               int i, j;
+               int i, j, filter= tracking->stabilization.filter;
+               void (*interpolation) (struct ImBuf*, struct ImBuf*, float, float, int, int) = NULL;
 
                BKE_tracking_stabdata_to_mat4(ibuf->x, ibuf->y, aspect, tloc, tscale, tangle, mat);
                invert_m4(mat);
 
+               if(filter == TRACKING_FILTER_NEAREAST)
+                       interpolation = neareast_interpolation;
+               else if(filter == TRACKING_FILTER_BILINEAR)
+                       interpolation = bilinear_interpolation;
+               else if(filter == TRACKING_FILTER_BICUBIC)
+                       interpolation = bicubic_interpolation;
+
                for(j=0; j<tmpibuf->y; j++) {
                        for(i=0; i<tmpibuf->x;i++) {
                                float vec[3]= {i, j, 0};
 
                                mul_v3_m4v3(vec, mat, vec);
 
-                               /* TODO: add selector for interpolation method */
-                               neareast_interpolation(ibuf, tmpibuf, vec[0], vec[1], i, j);
+                               interpolation(ibuf, tmpibuf, vec[0], vec[1], i, j);
                        }
                }
        }
index 1b41131..e81344d 100644 (file)
@@ -159,8 +159,10 @@ typedef struct MovieTrackingStabilization {
 
        float locinf, scaleinf, rotinf; /* influence on location, scale and rotation */
 
+       int filter;             /* filter used for pixel interpolation */
+
        /* some pre-computing run-time variables */
-       int ok, pad;                            /* are precomputed values and scaled buf relevant? */
+       int ok;                                         /* are precomputed values and scaled buf relevant? */
        float scale;                            /* autoscale factor */
 
        struct ImBuf *scaleibuf;        /* currently scaled ibuf */
@@ -258,6 +260,11 @@ enum {
 #define TRACKING_AUTOSCALE                     (1<<1)
 #define TRACKING_STABILIZE_ROTATION    (1<<2)
 
+/* MovieTrackingStrabilization->filter */
+#define TRACKING_FILTER_NEAREAST       0
+#define TRACKING_FILTER_BILINEAR       1
+#define TRACKING_FILTER_BICUBIC                2
+
 /* MovieTrackingReconstruction->flag */
 #define TRACKING_RECONSTRUCTED (1<<0)
 
index 2d6a568..e4ce730 100644 (file)
@@ -1064,6 +1064,12 @@ static void rna_def_trackingStabilization(BlenderRNA *brna)
        StructRNA *srna;
        PropertyRNA *prop;
 
+       static EnumPropertyItem filter_items[] = {
+               {TRACKING_FILTER_NEAREAST, "NEAREST",   0, "Nearest",   ""},
+               {TRACKING_FILTER_BILINEAR, "BILINEAR",   0, "Bilinear",   ""},
+               {TRACKING_FILTER_BICUBIC, "BICUBIC", 0, "Bicubic", ""},
+               {0, NULL, 0, NULL, NULL}};
+
        srna= RNA_def_struct(brna, "MovieTrackingStabilization", NULL);
        RNA_def_struct_path_func(srna, "rna_trackingStabilization_path");
        RNA_def_struct_ui_text(srna, "Movie tracking stabilization data", "Match-moving stabilization data for tracking");
@@ -1137,6 +1143,13 @@ static void rna_def_trackingStabilization(BlenderRNA *brna)
        RNA_def_property_range(prop, 0.0f, 1.0f);
        RNA_def_property_ui_text(prop, "Rotation Influence", "Influence of stabilization algorithm on footage rotation");
        RNA_def_property_update(prop, NC_MOVIECLIP|ND_DISPLAY, "rna_tracking_flushUpdate");
+
+       /* filter */
+       prop = RNA_def_property(srna, "filter_type", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "filter");
+       RNA_def_property_enum_items(prop, filter_items);
+       RNA_def_property_ui_text(prop, "Filter", "Method to use to filter stabilization");
+       RNA_def_property_update(prop, NC_MOVIECLIP|ND_DISPLAY, "rna_tracking_flushUpdate");
 }
 
 static void rna_def_reconstructedCamera(BlenderRNA *brna)