Color channels now can be disabled for the whole frame in clip editor
authorSergey Sharybin <sergey.vfx@gmail.com>
Sun, 15 Jan 2012 13:31:58 +0000 (13:31 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sun, 15 Jan 2012 13:31:58 +0000 (13:31 +0000)
release/scripts/startup/bl_ui/space_clip.py
source/blender/blenkernel/BKE_movieclip.h
source/blender/blenkernel/BKE_tracking.h
source/blender/blenkernel/intern/movieclip.c
source/blender/blenkernel/intern/tracking.c
source/blender/editors/space_clip/clip_editor.c
source/blender/makesdna/DNA_space_types.h
source/blender/makesrna/intern/rna_space.c

index aef6e317e776f8db847a049a77244350286dbe7e..0cf3a9211670e080dd295e5e529082af74019435 100644 (file)
@@ -515,6 +515,17 @@ class CLIP_PT_display(Panel):
         layout = self.layout
         sc = context.space_data
 
+        row = layout.row(align=True)
+        sub = row.row()
+        sub.prop(sc, "show_red_channel", text="R", toggle=True)
+        sub.prop(sc, "show_green_channel", text="G", toggle=True)
+        sub.prop(sc, "show_blue_channel", text="B", toggle=True)
+
+        row.separator()
+
+        sub = row.row()
+        sub.prop(sc, "use_grayscale_preview", text="B/W", toggle=True)
+
         col = layout.column(align=True)
 
         col.prop(sc, "show_marker_pattern", text="Pattern")
index b41f038941de40e1fcc984e664974e52b2c48057..6f404bf5feec32694d25a2576c1f7a08af968e47 100644 (file)
@@ -47,7 +47,8 @@ struct MovieClip *BKE_add_movieclip_file(const char *name);
 void BKE_movieclip_reload(struct MovieClip *clip);
 
 struct ImBuf *BKE_movieclip_get_ibuf(struct MovieClip *clip, struct MovieClipUser *user);
-struct ImBuf *BKE_movieclip_get_stable_ibuf(struct MovieClip *clip, struct MovieClipUser *user, float loc[2], float *scale, float *angle);
+struct ImBuf *BKE_movieclip_get_postprocessed_ibuf(struct MovieClip *clip, struct MovieClipUser *user, int postprocess_flag);
+struct ImBuf *BKE_movieclip_get_stable_ibuf(struct MovieClip *clip, struct MovieClipUser *user, float loc[2], float *scale, float *angle, int postprocess_flag);
 struct ImBuf *BKE_movieclip_get_ibuf_flag(struct MovieClip *clip, struct MovieClipUser *user, int flag);
 void BKE_movieclip_get_size(struct MovieClip *clip, struct MovieClipUser *user, int *width, int *height);
 void BKE_movieclip_aspect(struct MovieClip *clip, float *aspx, float *aspy);
@@ -63,8 +64,10 @@ void BKE_movieclip_get_cache_segments(struct MovieClip *clip, struct MovieClipUs
 void BKE_movieclip_build_proxy_frame(struct MovieClip *clip, int clip_flag, struct MovieDistortion *distortion,
                        int cfra, int *build_sizes, int build_count, int undistorted);
 
-#define TRACK_CLEAR_UPTO               0
-#define TRACK_CLEAR_REMAINED   1
-#define TRACK_CLEAR_ALL                        2
+/* postprocessing flags */
+#define MOVIECLIP_DISABLE_RED       (1<<0)
+#define MOVIECLIP_DISABLE_GREEN     (1<<1)
+#define MOVIECLIP_DISABLE_BLUE      (1<<2)
+#define MOVIECLIP_PREVIEW_GRAYSCALE (1<<3)
 
 #endif
index bd5790e1319064e979e3f6f6042ac2fc7e3622b3..d3f297ece8638f8db4a84331d7df8d99fa410ede 100644 (file)
@@ -97,6 +97,8 @@ struct ListBase *BKE_tracking_object_tracks(struct MovieTracking *tracking, stru
 struct MovieTrackingReconstruction *BKE_tracking_object_reconstruction(struct MovieTracking *tracking,
                        struct MovieTrackingObject *object);
 
+void BKE_tracking_disable_imbuf_channels(struct ImBuf *ibuf, int disable_red, int disable_green, int disable_blue, int grayscale);
+
 /* clipboard */
 void BKE_tracking_free_clipboard(void);
 void BKE_tracking_clipboard_copy_tracks(struct MovieTracking *tracking, struct MovieTrackingObject *object);
@@ -166,6 +168,10 @@ void BKE_tracking_deselect_track(struct MovieTrackingTrack *track, int area);
 
 #define MARKER_VISIBLE(sc, marker)                     (((marker)->flag&MARKER_DISABLED)==0 || ((sc)->flag&SC_HIDE_DISABLED)==0)
 
+#define TRACK_CLEAR_UPTO               0
+#define TRACK_CLEAR_REMAINED   1
+#define TRACK_CLEAR_ALL                        2
+
 #define CLAMP_PAT_DIM          1
 #define CLAMP_PAT_POS          2
 #define CLAMP_SEARCH_DIM       3
index 1b6c6ba518b1929883416d42ce146a145782d4a1..3b1dc2973ad7fadd7cb54666121e0c9fed5214d9 100644 (file)
@@ -261,10 +261,12 @@ typedef struct MovieClipCache {
        struct {
                ImBuf *ibuf;
                int framenr;
+               int flag;
 
                /* cache for undistorted shot */
                float principal[2];
                float k1, k2, k3;
+               short undistoriton_used;
 
                int proxy;
                short render_flag;
@@ -511,9 +513,9 @@ static int need_undistortion_postprocess(MovieClipUser *user, int flag)
        return result;
 }
 
-static int need_postprocessed_frame(MovieClipUser *user, int flag)
+static int need_postprocessed_frame(MovieClipUser *user, int flag, int postprocess_flag)
 {
-       int result = 0;
+       int result = postprocess_flag;
 
        result |= need_undistortion_postprocess(user, flag);
 
@@ -535,7 +537,7 @@ static int check_undistortion_cache_flags(MovieClip *clip)
        return 1;
 }
 
-static ImBuf *get_postprocessed_cached_frame(MovieClip *clip, MovieClipUser *user, int flag)
+static ImBuf *get_postprocessed_cached_frame(MovieClip *clip, MovieClipUser *user, int flag, int postprocess_flag)
 {
        MovieClipCache *cache= clip->cache;
        int framenr= user->framenr;
@@ -556,29 +558,35 @@ static ImBuf *get_postprocessed_cached_frame(MovieClip *clip, MovieClipUser *use
                return NULL;
 
        /* cached ibuf used different proxy settings */
-       if(cache->postprocessed.render_flag!=render_flag || cache->postprocessed.proxy!=proxy)
+       if(cache->postprocessed.render_flag != render_flag || cache->postprocessed.proxy != proxy)
+               return NULL;
+
+       if(cache->postprocessed.flag != postprocess_flag)
                return NULL;
 
        if(need_undistortion_postprocess(user, flag)) {
                if(!check_undistortion_cache_flags(clip))
                        return NULL;
        }
+       else if(cache->postprocessed.undistoriton_used)
+               return NULL;
 
        IMB_refImBuf(cache->postprocessed.ibuf);
 
        return cache->postprocessed.ibuf;
 }
 
-static ImBuf *put_postprocessed_frame_to_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, int flag)
+static ImBuf *put_postprocessed_frame_to_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, int flag, int postprocess_flag)
 {
        MovieClipCache *cache= clip->cache;
        MovieTrackingCamera *camera= &clip->tracking.camera;
-       ImBuf *postproc_ibuf;
+       ImBuf *postproc_ibuf = NULL;
 
        if(cache->postprocessed.ibuf)
                IMB_freeImBuf(cache->postprocessed.ibuf);
 
        cache->postprocessed.framenr= user->framenr;
+       cache->postprocessed.flag = postprocess_flag;
 
        if(flag&MCLIP_USE_PROXY) {
                cache->postprocessed.proxy= rendersize_to_proxy(user, flag);
@@ -592,18 +600,38 @@ static ImBuf *put_postprocessed_frame_to_cache(MovieClip *clip, MovieClipUser *u
        if(need_undistortion_postprocess(user, flag)) {
                copy_v2_v2(cache->postprocessed.principal, camera->principal);
                copy_v3_v3(&cache->postprocessed.k1, &camera->k1);
+               cache->postprocessed.undistoriton_used = 1;
+               postproc_ibuf= get_undistorted_ibuf(clip, NULL, ibuf);
        }
+       else cache->postprocessed.undistoriton_used = 0;
 
-       postproc_ibuf= get_undistorted_ibuf(clip, NULL, ibuf);
+       if(postprocess_flag) {
+               int disable_red   = postprocess_flag & MOVIECLIP_DISABLE_RED,
+                   disable_green = postprocess_flag & MOVIECLIP_DISABLE_GREEN,
+                       disable_blue  = postprocess_flag & MOVIECLIP_DISABLE_BLUE,
+                       grayscale     = postprocess_flag & MOVIECLIP_PREVIEW_GRAYSCALE;
+
+               if(!postproc_ibuf)
+                       postproc_ibuf = IMB_dupImBuf(ibuf);
+
+               if(disable_red || disable_green || disable_blue || grayscale)
+                       BKE_tracking_disable_imbuf_channels(postproc_ibuf, disable_red, disable_green, disable_blue, 1);
+       }
 
        IMB_refImBuf(postproc_ibuf);
 
        cache->postprocessed.ibuf= postproc_ibuf;
 
+       if(cache->stabilized.ibuf) {
+               /* force stable buffer be re-calculated */
+               IMB_freeImBuf(cache->stabilized.ibuf);
+               cache->stabilized.ibuf= NULL;
+       }
+
        return postproc_ibuf;
 }
 
-static ImBuf *movieclip_get_postprocessed_ibuf(MovieClip *clip, MovieClipUser *user, int flag)
+static ImBuf *movieclip_get_postprocessed_ibuf(MovieClip *clip, MovieClipUser *user, int flag, int postprocess_flag)
 {
        ImBuf *ibuf= NULL;
        int framenr= user->framenr, need_postprocess= 0;
@@ -613,8 +641,8 @@ static ImBuf *movieclip_get_postprocessed_ibuf(MovieClip *clip, MovieClipUser *u
        BLI_lock_thread(LOCK_MOVIECLIP);
 
        /* try to obtain cached postprocessed frame first */
-       if(need_postprocessed_frame(user, flag)) {
-               ibuf= get_postprocessed_cached_frame(clip, user, flag);
+       if(need_postprocessed_frame(user, flag, postprocess_flag)) {
+               ibuf= get_postprocessed_cached_frame(clip, user, flag, postprocess_flag);
 
                if(!ibuf)
                        need_postprocess= 1;
@@ -647,7 +675,7 @@ static ImBuf *movieclip_get_postprocessed_ibuf(MovieClip *clip, MovieClipUser *u
                /* postprocess frame and put to cache */
                if(need_postprocess) {
                        ImBuf *tmpibuf= ibuf;
-                       ibuf= put_postprocessed_frame_to_cache(clip, user, tmpibuf, flag);
+                       ibuf= put_postprocessed_frame_to_cache(clip, user, tmpibuf, flag, postprocess_flag);
                        IMB_freeImBuf(tmpibuf);
                }
        }
@@ -664,7 +692,12 @@ ImBuf *BKE_movieclip_get_ibuf(MovieClip *clip, MovieClipUser *user)
 
 ImBuf *BKE_movieclip_get_ibuf_flag(MovieClip *clip, MovieClipUser *user, int flag)
 {
-       return movieclip_get_postprocessed_ibuf(clip, user, flag);
+       return movieclip_get_postprocessed_ibuf(clip, user, flag, 0);
+}
+
+ImBuf *BKE_movieclip_get_postprocessed_ibuf(MovieClip *clip, MovieClipUser *user, int postprocess_flag)
+{
+       return movieclip_get_postprocessed_ibuf(clip, user, clip->flag, postprocess_flag);
 }
 
 static ImBuf *get_stable_cached_frame(MovieClip *clip, MovieClipUser *user, int framenr)
@@ -738,12 +771,12 @@ static ImBuf *put_stabilized_frame_to_cache(MovieClip *clip, MovieClipUser *user
        return stableibuf;
 }
 
-ImBuf *BKE_movieclip_get_stable_ibuf(MovieClip *clip, MovieClipUser *user, float loc[2], float *scale, float *angle)
+ImBuf *BKE_movieclip_get_stable_ibuf(MovieClip *clip, MovieClipUser *user, float loc[2], float *scale, float *angle, int postprocess_flag)
 {
        ImBuf *ibuf, *stableibuf= NULL;
        int framenr= user->framenr;
 
-       ibuf= BKE_movieclip_get_ibuf(clip, user);
+       ibuf= BKE_movieclip_get_postprocessed_ibuf(clip, user, postprocess_flag);
 
        if(!ibuf)
                return NULL;
index 8831d7e73b2cb971780be3cfd89785efb18b5105..428e6ebf6ca82dcb8039191b97086caebb05d7d5 100644 (file)
@@ -1010,19 +1010,19 @@ 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, int grayscale)
+void BKE_tracking_disable_imbuf_channels(ImBuf *ibuf, int disable_red, int disable_green, int disable_blue, int grayscale)
 {
        int x, y;
        float scale;
 
-       if((track->flag&(TRACK_DISABLE_RED|TRACK_DISABLE_GREEN|TRACK_DISABLE_BLUE))==0 && !grayscale)
+       if(!disable_red && !disable_green && !disable_blue && !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);
+       scale = (disable_red   ? 0.0f : 0.2126f) +
+               (disable_green ? 0.0f : 0.7152f) +
+               (disable_blue  ? 0.0f : 0.0722f);
 
        for(y= 0; y<ibuf->y; y++) {
                for (x= 0; x<ibuf->x; x++) {
@@ -1030,9 +1030,9 @@ static void disable_imbuf_channels(ImBuf *ibuf, MovieTrackingTrack *track, int g
 
                        if(ibuf->rect_float) {
                                float *rrgbf= ibuf->rect_float + pixel*4;
-                               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 r = disable_red   ? 0.0f : rrgbf[0];
+                               float g = disable_green ? 0.0f : rrgbf[1];
+                               float b = 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;
@@ -1043,9 +1043,9 @@ static void disable_imbuf_channels(ImBuf *ibuf, MovieTrackingTrack *track, int g
                                }
                        } 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];
+                               char r = disable_red   ? 0 : rrgb[0];
+                               char g = disable_green ? 0 : rrgb[1];
+                               char b = 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;
@@ -1059,6 +1059,12 @@ static void disable_imbuf_channels(ImBuf *ibuf, MovieTrackingTrack *track, int g
        }
 }
 
+static void disable_imbuf_channels(ImBuf *ibuf, MovieTrackingTrack *track, int grayscale)
+{
+       BKE_tracking_disable_imbuf_channels(ibuf, track->flag&TRACK_DISABLE_RED,
+                       track->flag&TRACK_DISABLE_GREEN, track->flag&TRACK_DISABLE_RED, grayscale);
+}
+
 static ImBuf *get_area_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker,
                        float min[2], float max[2], int margin, int anchored, float pos[2], int origin[2])
 {
index d75df0ab51e579ca48f5dde694ebbfdcee6c2630..35d870022a48f10ea54a5febd148b08e4f28a0cc 100644 (file)
@@ -86,7 +86,7 @@ ImBuf *ED_space_clip_get_buffer(SpaceClip *sc)
        if(sc->clip) {
                ImBuf *ibuf;
 
-               ibuf= BKE_movieclip_get_ibuf(sc->clip, &sc->user);
+               ibuf= BKE_movieclip_get_postprocessed_ibuf(sc->clip, &sc->user, sc->postproc_flag);
 
                if(ibuf && (ibuf->rect || ibuf->rect_float))
                        return ibuf;
@@ -103,7 +103,7 @@ ImBuf *ED_space_clip_get_stable_buffer(SpaceClip *sc, float loc[2], float *scale
        if(sc->clip) {
                ImBuf *ibuf;
 
-               ibuf= BKE_movieclip_get_stable_ibuf(sc->clip, &sc->user, loc, scale, angle);
+               ibuf= BKE_movieclip_get_stable_ibuf(sc->clip, &sc->user, loc, scale, angle, sc->postproc_flag);
 
                if(ibuf && (ibuf->rect || ibuf->rect_float))
                        return ibuf;
index 16df71e0f544a2343979866146e192569992b9b9..aa7a84c577b9723a09e2ddb82f7e0915054edcec 100644 (file)
@@ -516,6 +516,9 @@ typedef struct SpaceClip {
        int pad;
        float stabmat[4][4], unistabmat[4][4];          /* current stabilization matrix and the same matrix in unified space,
                                                                                                   defined when drawing and used for mouse position calculation */
+
+       /* movie postprocessing */
+       int postproc_flag, pad2;
 } SpaceClip;
 
 /* view3d  Now in DNA_view3d_types.h */
index 5b0b97d19be05a473d05b41f69f2ba34ee3d5ddd..d7f1c375a2162632faa672562b1da379b5072b6c 100644 (file)
@@ -35,6 +35,7 @@
 #include "rna_internal.h"
 
 #include "BKE_key.h"
+#include "BKE_movieclip.h"
 
 #include "DNA_action_types.h"
 #include "DNA_key_types.h"
@@ -2984,6 +2985,32 @@ static void rna_def_space_clip(BlenderRNA *brna)
        RNA_def_property_boolean_sdna(prop, NULL, "flag", SC_SHOW_GRAPH_TRACKS);
        RNA_def_property_ui_text(prop, "Show Tracks", "Display the speed curves (in \"x\" direction red, in \"y\" direction green) for the selected tracks");
        RNA_def_property_update(prop, NC_SPACE|ND_SPACE_CLIP, NULL);
+
+       /* ** channels ** */
+
+       /* show_red_channel */
+       prop= RNA_def_property(srna, "show_red_channel", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_negative_sdna(prop, NULL, "postproc_flag", MOVIECLIP_DISABLE_RED);
+       RNA_def_property_ui_text(prop, "Show Red Channel", "Show red channel in the frame");
+       RNA_def_property_update(prop, NC_SPACE|ND_SPACE_CLIP, NULL);
+
+       /* show_green_channel */
+       prop= RNA_def_property(srna, "show_green_channel", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_negative_sdna(prop, NULL, "postproc_flag", MOVIECLIP_DISABLE_GREEN);
+       RNA_def_property_ui_text(prop, "Show Green Channel", "Show green channel in the frame");
+       RNA_def_property_update(prop, NC_SPACE|ND_SPACE_CLIP, NULL);
+
+       /* show_blue_channel */
+       prop= RNA_def_property(srna, "show_blue_channel", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_negative_sdna(prop, NULL, "postproc_flag", MOVIECLIP_DISABLE_BLUE);
+       RNA_def_property_ui_text(prop, "Show Blue Channel", "Show blue channel in the frame");
+       RNA_def_property_update(prop, NC_SPACE|ND_SPACE_CLIP, NULL);
+
+       /* preview_grayscale */
+       prop= RNA_def_property(srna, "use_grayscale_preview", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "postproc_flag", MOVIECLIP_PREVIEW_GRAYSCALE);
+       RNA_def_property_ui_text(prop, "Grayscale", "Display frame in grayscale mode");
+       RNA_def_property_update(prop, NC_MOVIECLIP|ND_DISPLAY, NULL);
 }