diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-01-15 17:31:58 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-01-15 17:31:58 +0400 |
commit | f37d1b7b4e90c280a345b9cc7d1ab1fc02c2780e (patch) | |
tree | d20ce6207aac2679ced51ab5fdcd0c26b09d807c /source/blender/blenkernel | |
parent | 58601362b7f80bfdd19d3a429a9f3bc83aaf8135 (diff) |
Color channels now can be disabled for the whole frame in clip editor
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_movieclip.h | 11 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_tracking.h | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/movieclip.c | 61 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/tracking.c | 28 |
4 files changed, 77 insertions, 29 deletions
diff --git a/source/blender/blenkernel/BKE_movieclip.h b/source/blender/blenkernel/BKE_movieclip.h index b41f038941d..6f404bf5fee 100644 --- a/source/blender/blenkernel/BKE_movieclip.h +++ b/source/blender/blenkernel/BKE_movieclip.h @@ -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 diff --git a/source/blender/blenkernel/BKE_tracking.h b/source/blender/blenkernel/BKE_tracking.h index bd5790e1319..d3f297ece86 100644 --- a/source/blender/blenkernel/BKE_tracking.h +++ b/source/blender/blenkernel/BKE_tracking.h @@ -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 diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 1b6c6ba518b..3b1dc2973ad 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -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; diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 8831d7e73b2..428e6ebf6ca 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -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]) { |