Color channels now can be disabled for the whole frame in clip editor

This commit is contained in:
Sergey Sharybin 2012-01-15 13:31:58 +00:00
parent 58601362b7
commit f37d1b7b4e
8 changed files with 120 additions and 31 deletions

@ -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")

@ -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

@ -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

@ -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;

@ -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])
{

@ -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;

@ -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 */

@ -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);
}