Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/movieclip.c')
-rw-r--r--source/blender/blenkernel/intern/movieclip.c543
1 files changed, 308 insertions, 235 deletions
diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c
index 0cecc09a9d7..e375262c045 100644
--- a/source/blender/blenkernel/intern/movieclip.c
+++ b/source/blender/blenkernel/intern/movieclip.c
@@ -82,19 +82,19 @@
static int sequence_guess_offset(const char *full_name, int head_len, int numlen)
{
- char num[FILE_MAX]= {0};
+ char num[FILE_MAX] = {0};
- BLI_strncpy(num, full_name+head_len, numlen+1);
+ BLI_strncpy(num, full_name + head_len, numlen + 1);
return atoi(num);
}
static int rendersize_to_proxy(MovieClipUser *user, int flag)
{
- if ((flag&MCLIP_USE_PROXY)==0)
+ if ((flag & MCLIP_USE_PROXY) == 0)
return IMB_PROXY_NONE;
- switch(user->render_size) {
+ switch (user->render_size) {
case MCLIP_PROXY_RENDER_SIZE_25:
return IMB_PROXY_25;
@@ -116,7 +116,7 @@ static int rendersize_to_proxy(MovieClipUser *user, int flag)
static int rendersize_to_number(int render_size)
{
- switch(render_size) {
+ switch (render_size) {
case MCLIP_PROXY_RENDER_SIZE_25:
return 25;
@@ -138,7 +138,7 @@ static int rendersize_to_number(int render_size)
static int get_timecode(MovieClip *clip, int flag)
{
- if ((flag&MCLIP_USE_PROXY)==0)
+ if ((flag & MCLIP_USE_PROXY) == 0)
return IMB_TC_NONE;
return clip->proxy.tc;
@@ -157,8 +157,10 @@ static void get_sequence_fname(MovieClip *clip, int framenr, char *name)
* autoguess offset for now. could be something smarter in the future */
offset= sequence_guess_offset(clip->name, strlen(head), numlen);
- if (numlen) BLI_stringenc(name, head, tail, numlen, offset+framenr-1);
- else BLI_strncpy(name, clip->name, sizeof(clip->name));
+ if (numlen)
+ BLI_stringenc(name, head, tail, numlen, offset + framenr - 1);
+ else
+ BLI_strncpy(name, clip->name, sizeof(clip->name));
BLI_path_abs(name, ID_BLEND_PATH(G.main, &clip->id));
}
@@ -166,12 +168,12 @@ static void get_sequence_fname(MovieClip *clip, int framenr, char *name)
/* supposed to work with sequences only */
static void get_proxy_fname(MovieClip *clip, int proxy_render_size, int undistorted, int framenr, char *name)
{
- int size= rendersize_to_number(proxy_render_size);
+ int size = rendersize_to_number(proxy_render_size);
char dir[FILE_MAX], clipdir[FILE_MAX], clipfile[FILE_MAX];
BLI_split_dirfile(clip->name, clipdir, clipfile, FILE_MAX, FILE_MAX);
- if (clip->flag&MCLIP_USE_PROXY_CUSTOM_DIR) {
+ if (clip->flag & MCLIP_USE_PROXY_CUSTOM_DIR) {
BLI_strncpy(dir, clip->proxy.dir, sizeof(dir));
}
else {
@@ -195,27 +197,24 @@ static ImBuf *movieclip_load_sequence_file(MovieClip *clip, MovieClipUser *user,
char name[FILE_MAX];
int loadflag, use_proxy= 0;
- use_proxy= (flag&MCLIP_USE_PROXY) && user->render_size != MCLIP_PROXY_RENDER_SIZE_FULL;
+ use_proxy = (flag & MCLIP_USE_PROXY) && user->render_size != MCLIP_PROXY_RENDER_SIZE_FULL;
if (use_proxy) {
- int undistort= user->render_flag&MCLIP_PROXY_RENDER_UNDISTORT;
+ int undistort = user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT;
get_proxy_fname(clip, user->render_size, undistort, framenr, name);
}
else
get_sequence_fname(clip, framenr, name);
- loadflag= IB_rect|IB_multilayer;
+ loadflag = IB_rect|IB_multilayer;
/* read ibuf */
- ibuf= IMB_loadiffname(name, loadflag);
+ ibuf = IMB_loadiffname(name, loadflag);
return ibuf;
}
-static ImBuf *movieclip_load_movie_file(MovieClip *clip, MovieClipUser *user, int framenr, int flag)
+static void movieclip_open_anim_file(MovieClip *clip)
{
- ImBuf *ibuf= NULL;
- int tc= get_timecode(clip, flag);
- int proxy= rendersize_to_proxy(user, flag);
char str[FILE_MAX];
if (!clip->anim) {
@@ -223,10 +222,10 @@ static ImBuf *movieclip_load_movie_file(MovieClip *clip, MovieClipUser *user, in
BLI_path_abs(str, ID_BLEND_PATH(G.main, &clip->id));
/* FIXME: make several stream accessible in image editor, too */
- clip->anim= openanim(str, IB_rect, 0);
+ clip->anim = openanim(str, IB_rect, 0);
if (clip->anim) {
- if (clip->flag&MCLIP_USE_PROXY_CUSTOM_DIR) {
+ if (clip->flag & MCLIP_USE_PROXY_CUSTOM_DIR) {
char dir[FILE_MAX];
BLI_strncpy(dir, clip->proxy.dir, sizeof(dir));
BLI_path_abs(dir, G.main->name);
@@ -234,26 +233,61 @@ static ImBuf *movieclip_load_movie_file(MovieClip *clip, MovieClipUser *user, in
}
}
}
+}
+
+static ImBuf *movieclip_load_movie_file(MovieClip *clip, MovieClipUser *user, int framenr, int flag)
+{
+ ImBuf *ibuf = NULL;
+ int tc = get_timecode(clip, flag);
+ int proxy = rendersize_to_proxy(user, flag);
+
+ movieclip_open_anim_file(clip);
if (clip->anim) {
int dur;
int fra;
- dur= IMB_anim_get_duration(clip->anim, tc);
- fra= framenr-1;
+ dur = IMB_anim_get_duration(clip->anim, tc);
+ fra = framenr - 1;
if (fra<0)
- fra= 0;
+ fra = 0;
- if (fra>(dur-1))
- fra= dur-1;
+ if (fra > (dur - 1))
+ fra = dur - 1;
- ibuf= IMB_anim_absolute(clip->anim, fra, tc, proxy);
+ ibuf = IMB_anim_absolute(clip->anim, fra, tc, proxy);
}
return ibuf;
}
+static void movieclip_calc_length(MovieClip *clip)
+{
+ if (clip->source == MCLIP_SRC_MOVIE) {
+ movieclip_open_anim_file(clip);
+
+ if (clip->anim) {
+ clip->len = IMB_anim_get_duration(clip->anim, clip->proxy.tc);
+ }
+ }
+ else if (clip->source == MCLIP_SRC_SEQUENCE) {
+ int framenr = 1;
+ char name[FILE_MAX];
+
+ for (;;) {
+ get_sequence_fname(clip, framenr, name);
+
+ if (!BLI_exists(name)) {
+ clip->len = framenr + 1;
+ break;
+ }
+
+ framenr++;
+ }
+ }
+}
+
/*********************** image buffer cache *************************/
typedef struct MovieClipCache {
@@ -295,34 +329,40 @@ typedef struct MovieClipImBufCacheKey {
static void moviecache_keydata(void *userkey, int *framenr, int *proxy, int *render_flags)
{
- MovieClipImBufCacheKey *key= (MovieClipImBufCacheKey*)userkey;
+ MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey*)userkey;
- *framenr= key->framenr;
- *proxy= key->proxy;
- *render_flags= key->render_flag;
+ *framenr = key->framenr;
+ *proxy = key->proxy;
+ *render_flags = key->render_flag;
}
static unsigned int moviecache_hashhash(const void *keyv)
{
- MovieClipImBufCacheKey *key= (MovieClipImBufCacheKey*)keyv;
- int rval= key->framenr;
+ MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey*)keyv;
+ int rval = key->framenr;
return rval;
}
static int moviecache_hashcmp(const void *av, const void *bv)
{
- const MovieClipImBufCacheKey *a= (MovieClipImBufCacheKey*)av;
- const MovieClipImBufCacheKey *b= (MovieClipImBufCacheKey*)bv;
+ const MovieClipImBufCacheKey *a = (MovieClipImBufCacheKey*)av;
+ const MovieClipImBufCacheKey *b = (MovieClipImBufCacheKey*)bv;
- if (a->framenr<b->framenr) return -1;
- else if (a->framenr>b->framenr) return 1;
+ if (a->framenr < b->framenr)
+ return -1;
+ else if (a->framenr > b->framenr)
+ return 1;
- if (a->proxy<b->proxy) return -1;
- else if (a->proxy>b->proxy) return 1;
+ if (a->proxy < b->proxy)
+ return -1;
+ else if (a->proxy > b->proxy)
+ return 1;
- if (a->render_flag<b->render_flag) return -1;
- else if (a->render_flag>b->render_flag) return 1;
+ if (a->render_flag < b->render_flag)
+ return -1;
+ else if (a->render_flag > b->render_flag)
+ return 1;
return 0;
}
@@ -332,15 +372,15 @@ static ImBuf *get_imbuf_cache(MovieClip *clip, MovieClipUser *user, int flag)
if (clip->cache) {
MovieClipImBufCacheKey key;
- key.framenr= user->framenr;
+ key.framenr = user->framenr;
- if (flag&MCLIP_USE_PROXY) {
- key.proxy= rendersize_to_proxy(user, flag);
- key.render_flag= user->render_flag;
+ if (flag & MCLIP_USE_PROXY) {
+ key.proxy = rendersize_to_proxy(user, flag);
+ key.render_flag = user->render_flag;
}
else {
- key.proxy= IMB_PROXY_NONE;
- key.render_flag= 0;
+ key.proxy = IMB_PROXY_NONE;
+ key.render_flag = 0;
}
return IMB_moviecache_get(clip->cache->moviecache, &key);
@@ -354,21 +394,21 @@ static void put_imbuf_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, i
MovieClipImBufCacheKey key;
if (!clip->cache) {
- clip->cache= MEM_callocN(sizeof(MovieClipCache), "movieClipCache");
+ clip->cache = MEM_callocN(sizeof(MovieClipCache), "movieClipCache");
- clip->cache->moviecache= IMB_moviecache_create(sizeof(MovieClipImBufCacheKey), moviecache_hashhash,
+ clip->cache->moviecache = IMB_moviecache_create(sizeof(MovieClipImBufCacheKey), moviecache_hashhash,
moviecache_hashcmp, moviecache_keydata);
}
- key.framenr= user->framenr;
+ key.framenr = user->framenr;
- if (flag&MCLIP_USE_PROXY) {
- key.proxy= rendersize_to_proxy(user, flag);
- key.render_flag= user->render_flag;
+ if (flag & MCLIP_USE_PROXY) {
+ key.proxy = rendersize_to_proxy(user, flag);
+ key.render_flag = user->render_flag;
}
else {
- key.proxy= IMB_PROXY_NONE;
- key.render_flag= 0;
+ key.proxy = IMB_PROXY_NONE;
+ key.render_flag = 0;
}
IMB_moviecache_put(clip->cache->moviecache, &key, ibuf);
@@ -381,18 +421,18 @@ static MovieClip *movieclip_alloc(const char *name)
{
MovieClip *clip;
- clip= alloc_libblock(&G.main->movieclip, ID_MC, name);
+ clip = alloc_libblock(&G.main->movieclip, ID_MC, name);
- clip->aspx= clip->aspy= 1.0f;
+ clip->aspx = clip->aspy= 1.0f;
BKE_tracking_init_settings(&clip->tracking);
- clip->proxy.build_size_flag= IMB_PROXY_25;
- clip->proxy.build_tc_flag= IMB_TC_RECORD_RUN |
- IMB_TC_FREE_RUN |
- IMB_TC_INTERPOLATED_REC_DATE_FREE_RUN |
- IMB_TC_RECORD_RUN_NO_GAPS;
- clip->proxy.quality= 90;
+ clip->proxy.build_size_flag = IMB_PROXY_25;
+ clip->proxy.build_tc_flag = IMB_TC_RECORD_RUN |
+ IMB_TC_FREE_RUN |
+ IMB_TC_INTERPOLATED_REC_DATE_FREE_RUN |
+ IMB_TC_RECORD_RUN_NO_GAPS;
+ clip->proxy.quality = 90;
return clip;
}
@@ -413,16 +453,17 @@ MovieClip *BKE_add_movieclip_file(const char *name)
BLI_path_abs(str, G.main->name);
/* exists? */
- file= BLI_open(str, O_BINARY|O_RDONLY,0);
- if (file== -1) return NULL;
+ file = BLI_open(str, O_BINARY|O_RDONLY,0);
+ if (file == -1)
+ return NULL;
close(file);
/* ** first search an identical clip ** */
- for (clip= G.main->movieclip.first; clip; clip= clip->id.next) {
+ for (clip = G.main->movieclip.first; clip; clip = clip->id.next) {
BLI_strncpy(strtest, clip->name, sizeof(clip->name));
BLI_path_abs(strtest, G.main->name);
- if (strcmp(strtest, str)==0) {
+ if (strcmp(strtest, str) == 0) {
BLI_strncpy(clip->name, name, sizeof(clip->name)); /* for stringcode */
clip->id.us++; /* officially should not, it doesn't link here! */
@@ -433,49 +474,54 @@ MovieClip *BKE_add_movieclip_file(const char *name)
/* ** add new movieclip ** */
/* create a short library name */
- len= strlen(name);
+ len = strlen(name);
- while (len > 0 && name[len - 1] != '/' && name[len - 1] != '\\') len--;
- libname= name+len;
+ while (len > 0 && name[len - 1] != '/' && name[len - 1] != '\\')
+ len--;
+ libname = name + len;
- clip= movieclip_alloc(libname);
+ clip = movieclip_alloc(libname);
BLI_strncpy(clip->name, name, sizeof(clip->name));
- if (BLI_testextensie_array(name, imb_ext_movie)) clip->source= MCLIP_SRC_MOVIE;
- else clip->source= MCLIP_SRC_SEQUENCE;
+ if (BLI_testextensie_array(name, imb_ext_movie))
+ clip->source = MCLIP_SRC_MOVIE;
+ else
+ clip->source = MCLIP_SRC_SEQUENCE;
- user.framenr= 1;
+ user.framenr = 1;
BKE_movieclip_get_size(clip, &user, &width, &height);
if (width && height) {
- clip->tracking.camera.principal[0]= ((float)width)/2;
- clip->tracking.camera.principal[1]= ((float)height)/2;
+ clip->tracking.camera.principal[0] = ((float)width) / 2.0f;
+ clip->tracking.camera.principal[1] = ((float)height) / 2.0f;
- clip->tracking.camera.focal= 24.0f*width/clip->tracking.camera.sensor_width;
+ clip->tracking.camera.focal = 24.0f * width / clip->tracking.camera.sensor_width;
}
+ movieclip_calc_length(clip);
+
return clip;
}
static void real_ibuf_size(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, int *width, int *height)
{
- *width= ibuf->x;
- *height= ibuf->y;
+ *width = ibuf->x;
+ *height = ibuf->y;
- if (clip->flag&MCLIP_USE_PROXY) {
+ if (clip->flag & MCLIP_USE_PROXY) {
switch(user->render_size) {
case MCLIP_PROXY_RENDER_SIZE_25:
- (*width)*= 4;
- (*height)*= 4;
+ (*width) *= 4;
+ (*height) *= 4;
break;
case MCLIP_PROXY_RENDER_SIZE_50:
- (*width)*= 2.0f;
- (*height)*= 2.0f;
+ (*width) *= 2.0f;
+ (*height) *= 2.0f;
break;
case MCLIP_PROXY_RENDER_SIZE_75:
- *width= ((float)*width)*4.0f/3.0f;
- *height= ((float)*height)*4.0f/3.0f;
+ *width = ((float)*width)*4.0f/3.0f;
+ *height = ((float)*height)*4.0f/3.0f;
break;
}
}
@@ -490,12 +536,12 @@ static ImBuf *get_undistorted_ibuf(MovieClip *clip, struct MovieDistortion *dist
imb_freerectfloatImBuf(ibuf);
if (distortion)
- undistibuf= BKE_tracking_distortion_exec(distortion, &clip->tracking, ibuf, ibuf->x, ibuf->y, 0.0f, 1);
+ undistibuf = BKE_tracking_distortion_exec(distortion, &clip->tracking, ibuf, ibuf->x, ibuf->y, 0.0f, 1);
else
- undistibuf= BKE_tracking_undistort(&clip->tracking, ibuf, ibuf->x, ibuf->y, 0.0f);
+ undistibuf = BKE_tracking_undistort(&clip->tracking, ibuf, ibuf->x, ibuf->y, 0.0f);
- if (undistibuf->userflags&IB_RECT_INVALID) {
- ibuf->userflags&= ~IB_RECT_INVALID;
+ if (undistibuf->userflags & IB_RECT_INVALID) {
+ ibuf->userflags &= ~IB_RECT_INVALID;
IMB_rect_from_float(undistibuf);
}
@@ -528,29 +574,29 @@ static int need_postprocessed_frame(MovieClipUser *user, int flag, int postproce
static int check_undistortion_cache_flags(MovieClip *clip)
{
- MovieClipCache *cache= clip->cache;
- MovieTrackingCamera *camera= &clip->tracking.camera;
+ MovieClipCache *cache = clip->cache;
+ MovieTrackingCamera *camera = &clip->tracking.camera;
/* check for distortion model changes */
if (!equals_v2v2(camera->principal, cache->postprocessed.principal))
- return 0;
+ return FALSE;
if (!equals_v3v3(&camera->k1, &cache->postprocessed.k1))
- return 0;
+ return FALSE;
- return 1;
+ return TRUE;
}
static ImBuf *get_postprocessed_cached_frame(MovieClip *clip, MovieClipUser *user, int flag, int postprocess_flag)
{
- MovieClipCache *cache= clip->cache;
- int framenr= user->framenr;
- short proxy= IMB_PROXY_NONE;
- int render_flag= 0;
-
- if (flag&MCLIP_USE_PROXY) {
- proxy= rendersize_to_proxy(user, flag);
- render_flag= user->render_flag;
+ MovieClipCache *cache = clip->cache;
+ int framenr = user->framenr;
+ short proxy = IMB_PROXY_NONE;
+ int render_flag = 0;
+
+ if (flag & MCLIP_USE_PROXY) {
+ proxy = rendersize_to_proxy(user, flag);
+ render_flag = user->render_flag;
}
/* no cache or no cached postprocessed image */
@@ -582,19 +628,19 @@ static ImBuf *get_postprocessed_cached_frame(MovieClip *clip, MovieClipUser *use
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;
+ MovieClipCache *cache = clip->cache;
+ MovieTrackingCamera *camera = &clip->tracking.camera;
ImBuf *postproc_ibuf = NULL;
if (cache->postprocessed.ibuf)
IMB_freeImBuf(cache->postprocessed.ibuf);
- cache->postprocessed.framenr= user->framenr;
+ cache->postprocessed.framenr = user->framenr;
cache->postprocessed.flag = postprocess_flag;
- if (flag&MCLIP_USE_PROXY) {
- cache->postprocessed.proxy= rendersize_to_proxy(user, flag);
- cache->postprocessed.render_flag= user->render_flag;
+ if (flag & MCLIP_USE_PROXY) {
+ cache->postprocessed.proxy = rendersize_to_proxy(user, flag);
+ cache->postprocessed.render_flag = user->render_flag;
}
else {
cache->postprocessed.proxy = IMB_PROXY_NONE;
@@ -604,10 +650,12 @@ 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;
+ cache->postprocessed.undistoriton_used = TRUE;
postproc_ibuf= get_undistorted_ibuf(clip, NULL, ibuf);
}
- else cache->postprocessed.undistoriton_used = 0;
+ else {
+ cache->postprocessed.undistoriton_used = FALSE;
+ }
if (postprocess_flag) {
int disable_red = postprocess_flag & MOVIECLIP_DISABLE_RED,
@@ -624,12 +672,12 @@ static ImBuf *put_postprocessed_frame_to_cache(MovieClip *clip, MovieClipUser *u
IMB_refImBuf(postproc_ibuf);
- cache->postprocessed.ibuf= 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;
+ cache->stabilized.ibuf = NULL;
}
return postproc_ibuf;
@@ -638,8 +686,8 @@ static ImBuf *put_postprocessed_frame_to_cache(MovieClip *clip, MovieClipUser *u
static ImBuf *movieclip_get_postprocessed_ibuf(MovieClip *clip, MovieClipUser *user, int flag,
int postprocess_flag, int cache_flag)
{
- ImBuf *ibuf= NULL;
- int framenr= user->framenr, need_postprocess= 0;
+ ImBuf *ibuf = NULL;
+ int framenr = user->framenr, need_postprocess = FALSE;
/* cache isn't threadsafe itself and also loading of movies
* can't happen from concurent threads that's why we use lock here */
@@ -650,23 +698,24 @@ static ImBuf *movieclip_get_postprocessed_ibuf(MovieClip *clip, MovieClipUser *u
ibuf= get_postprocessed_cached_frame(clip, user, flag, postprocess_flag);
if (!ibuf)
- need_postprocess= 1;
+ need_postprocess = TRUE;
}
if (!ibuf)
ibuf= get_imbuf_cache(clip, user, flag);
if (!ibuf) {
- int use_sequence= 0;
+ int use_sequence = FALSE;
/* undistorted proxies for movies should be read as image sequence */
- use_sequence= (user->render_flag&MCLIP_PROXY_RENDER_UNDISTORT) &&
- (user->render_size!=MCLIP_PROXY_RENDER_SIZE_FULL);
+ use_sequence = (user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT) &&
+ (user->render_size != MCLIP_PROXY_RENDER_SIZE_FULL);
- if (clip->source==MCLIP_SRC_SEQUENCE || use_sequence)
- ibuf= movieclip_load_sequence_file(clip, user, framenr, flag);
+ if (clip->source == MCLIP_SRC_SEQUENCE || use_sequence) {
+ ibuf = movieclip_load_sequence_file(clip, user, framenr, flag);
+ }
else {
- ibuf= movieclip_load_movie_file(clip, user, framenr, flag);
+ ibuf = movieclip_load_movie_file(clip, user, framenr, flag);
}
if (ibuf && (cache_flag & MOVIECLIP_CACHE_SKIP) == 0)
@@ -674,13 +723,13 @@ static ImBuf *movieclip_get_postprocessed_ibuf(MovieClip *clip, MovieClipUser *u
}
if (ibuf) {
- clip->lastframe= framenr;
+ clip->lastframe = framenr;
real_ibuf_size(clip, user, ibuf, &clip->lastsize[0], &clip->lastsize[1]);
/* postprocess frame and put to cache */
if (need_postprocess) {
- ImBuf *tmpibuf= ibuf;
- ibuf= put_postprocessed_frame_to_cache(clip, user, tmpibuf, flag, postprocess_flag);
+ ImBuf *tmpibuf = ibuf;
+ ibuf = put_postprocessed_frame_to_cache(clip, user, tmpibuf, flag, postprocess_flag);
IMB_freeImBuf(tmpibuf);
}
}
@@ -714,7 +763,7 @@ static ImBuf *get_stable_cached_frame(MovieClip *clip, MovieClipUser *user, int
short proxy = IMB_PROXY_NONE;
int render_flag = 0;
- if (clip->flag&MCLIP_USE_PROXY) {
+ if (clip->flag & MCLIP_USE_PROXY) {
proxy = rendersize_to_proxy(user, clip->flag);
render_flag = user->render_flag;
}
@@ -724,7 +773,7 @@ static ImBuf *get_stable_cached_frame(MovieClip *clip, MovieClipUser *user, int
return NULL;
/* cached ibuf used different proxy settings */
- if (cache->stabilized.render_flag!=render_flag || cache->stabilized.proxy!=proxy)
+ if (cache->stabilized.render_flag != render_flag || cache->stabilized.proxy != proxy)
return NULL;
if (cache->stabilized.postprocess_flag != postprocess_flag)
@@ -777,9 +826,9 @@ static ImBuf *put_stabilized_frame_to_cache(MovieClip *clip, MovieClipUser *user
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);
- cache->stabilized.render_flag= user->render_flag;
+ if (clip->flag & MCLIP_USE_PROXY) {
+ cache->stabilized.proxy = rendersize_to_proxy(user, clip->flag);
+ cache->stabilized.render_flag = user->render_flag;
}
else {
cache->stabilized.proxy = IMB_PROXY_NONE;
@@ -795,37 +844,47 @@ static ImBuf *put_stabilized_frame_to_cache(MovieClip *clip, MovieClipUser *user
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;
+ ImBuf *ibuf, *stableibuf = NULL;
+ int framenr = user->framenr;
- ibuf= BKE_movieclip_get_postprocessed_ibuf(clip, user, postprocess_flag);
+ ibuf = BKE_movieclip_get_postprocessed_ibuf(clip, user, postprocess_flag);
if (!ibuf)
return NULL;
- if (clip->tracking.stabilization.flag&TRACKING_2D_STABILIZATION) {
+ if (clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) {
MovieClipCache *cache= clip->cache;
- stableibuf= get_stable_cached_frame(clip, user, framenr, postprocess_flag);
+ stableibuf = get_stable_cached_frame(clip, user, framenr, postprocess_flag);
if (!stableibuf)
- stableibuf= put_stabilized_frame_to_cache(clip, user, ibuf, framenr, postprocess_flag);
+ stableibuf = put_stabilized_frame_to_cache(clip, user, ibuf, framenr, postprocess_flag);
+
+ if (loc)
+ copy_v2_v2(loc, cache->stabilized.loc);
- if (loc) copy_v2_v2(loc, cache->stabilized.loc);
- if (scale) *scale= cache->stabilized.scale;
- if (angle) *angle= cache->stabilized.angle;
+ if (scale)
+ *scale= cache->stabilized.scale;
+
+ if (angle)
+ *angle= cache->stabilized.angle;
}
else {
- if (loc) zero_v2(loc);
- if (scale) *scale= 1.0f;
- if (angle) *angle= 0.0f;
+ if (loc)
+ zero_v2(loc);
+
+ if (scale)
+ *scale= 1.0f;
- stableibuf= ibuf;
+ if (angle)
+ *angle= 0.0f;
+
+ stableibuf = ibuf;
}
- if (stableibuf!=ibuf) {
+ if (stableibuf != ibuf) {
IMB_freeImBuf(ibuf);
- ibuf= stableibuf;
+ ibuf = stableibuf;
}
return ibuf;
@@ -834,31 +893,31 @@ ImBuf *BKE_movieclip_get_stable_ibuf(MovieClip *clip, MovieClipUser *user, float
int BKE_movieclip_has_frame(MovieClip *clip, MovieClipUser *user)
{
- ImBuf *ibuf= BKE_movieclip_get_ibuf(clip, user);
+ ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, user);
if (ibuf) {
IMB_freeImBuf(ibuf);
- return 1;
+ return TRUE;
}
- return 0;
+ return FALSE;
}
void BKE_movieclip_get_size(MovieClip *clip, MovieClipUser *user, int *width, int *height)
{
- if (user->framenr==clip->lastframe) {
- *width= clip->lastsize[0];
- *height= clip->lastsize[1];
+ if (user->framenr == clip->lastframe) {
+ *width = clip->lastsize[0];
+ *height = clip->lastsize[1];
}
else {
- ImBuf *ibuf= BKE_movieclip_get_ibuf(clip, user);
+ ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, user);
if (ibuf && ibuf->x && ibuf->y) {
real_ibuf_size(clip, user, ibuf, width, height);
}
else {
- *width= 0;
- *height= 0;
+ *width = 0;
+ *height = 0;
}
if (ibuf)
@@ -866,27 +925,31 @@ void BKE_movieclip_get_size(MovieClip *clip, MovieClipUser *user, int *width, in
}
}
-int BKE_movieclip_get_duration(struct MovieClip *clip)
+int BKE_movieclip_get_duration(MovieClip *clip)
{
- return IMB_anim_get_duration(clip->anim, clip->proxy.tc);
+ if (!clip->len) {
+ movieclip_calc_length(clip);
+ }
+
+ return clip->len;
}
void BKE_movieclip_aspect(MovieClip *clip, float *aspx, float *aspy)
{
- *aspx= *aspy= 1.0;
+ *aspx = *aspy = 1.0;
/* x is always 1 */
- *aspy = clip->aspy/clip->aspx/clip->tracking.camera.pixel_aspect;
+ *aspy = clip->aspy / clip->aspx / clip->tracking.camera.pixel_aspect;
}
/* get segments of cached frames. useful for debugging cache policies */
void BKE_movieclip_get_cache_segments(MovieClip *clip, MovieClipUser *user, int *totseg_r, int **points_r)
{
- *totseg_r= 0;
- *points_r= NULL;
+ *totseg_r = 0;
+ *points_r = NULL;
if (clip->cache) {
- int proxy= rendersize_to_proxy(user, clip->flag);
+ int proxy = rendersize_to_proxy(user, clip->flag);
IMB_moviecache_get_cache_segments(clip->cache->moviecache, proxy, user->render_flag, totseg_r, points_r);
}
@@ -896,7 +959,7 @@ void BKE_movieclip_user_set_frame(MovieClipUser *iuser, int framenr)
{
/* TODO: clamp framenr here? */
- iuser->framenr= framenr;
+ iuser->framenr = framenr;
}
static void free_buffers(MovieClip *clip)
@@ -911,12 +974,12 @@ static void free_buffers(MovieClip *clip)
IMB_freeImBuf(clip->cache->stabilized.ibuf);
MEM_freeN(clip->cache);
- clip->cache= NULL;
+ clip->cache = NULL;
}
if (clip->anim) {
IMB_free_anim(clip->anim);
- clip->anim= FALSE;
+ clip->anim = NULL;
}
BKE_free_animdata((ID *) clip);
@@ -927,11 +990,15 @@ void BKE_movieclip_reload(MovieClip *clip)
/* clear cache */
free_buffers(clip);
- clip->tracking.stabilization.ok= 0;
+ clip->tracking.stabilization.ok = FALSE;
/* update clip source */
- if (BLI_testextensie_array(clip->name, imb_ext_movie)) clip->source= MCLIP_SRC_MOVIE;
- else clip->source= MCLIP_SRC_SEQUENCE;
+ if (BLI_testextensie_array(clip->name, imb_ext_movie))
+ clip->source = MCLIP_SRC_MOVIE;
+ else
+ clip->source = MCLIP_SRC_SEQUENCE;
+
+ movieclip_calc_length(clip);
}
void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClipScopes *scopes)
@@ -941,44 +1008,44 @@ void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClip
if (scopes->track_preview) {
IMB_freeImBuf(scopes->track_preview);
- scopes->track_preview= NULL;
+ scopes->track_preview = NULL;
}
- scopes->marker= NULL;
- scopes->track= NULL;
+ scopes->marker = NULL;
+ scopes->track = NULL;
if (clip) {
- MovieTrackingTrack *act_track= BKE_tracking_active_track(&clip->tracking);
+ MovieTrackingTrack *act_track = BKE_tracking_active_track(&clip->tracking);
if (act_track) {
- MovieTrackingTrack *track= act_track;
- MovieTrackingMarker *marker= BKE_tracking_get_marker(track, user->framenr);
+ MovieTrackingTrack *track = act_track;
+ MovieTrackingMarker *marker = BKE_tracking_get_marker(track, user->framenr);
- if (marker->flag&MARKER_DISABLED) {
- scopes->track_disabled= 1;
+ if (marker->flag & MARKER_DISABLED) {
+ scopes->track_disabled = TRUE;
}
else {
- ImBuf *ibuf= BKE_movieclip_get_ibuf(clip, user);
+ ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, user);
- scopes->track_disabled= 0;
+ scopes->track_disabled = FALSE;
if (ibuf && ibuf->rect) {
ImBuf *tmpibuf;
- MovieTrackingMarker undist_marker= *marker;
+ MovieTrackingMarker undist_marker = *marker;
- if (user->render_flag&MCLIP_PROXY_RENDER_UNDISTORT) {
+ if (user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT) {
int width, height;
- float aspy= 1.0f/clip->tracking.camera.pixel_aspect;
+ float aspy= 1.0f / clip->tracking.camera.pixel_aspect;
BKE_movieclip_get_size(clip, user, &width, &height);
- undist_marker.pos[0]*= width;
- undist_marker.pos[1]*= height*aspy;
+ undist_marker.pos[0] *= width;
+ undist_marker.pos[1] *= height*aspy;
BKE_tracking_invert_intrinsics(&clip->tracking, undist_marker.pos, undist_marker.pos);
- undist_marker.pos[0]/= width;
- undist_marker.pos[1]/= height*aspy;
+ undist_marker.pos[0] /= width;
+ undist_marker.pos[1] /= height*aspy;
}
/* NOTE: margin should be kept in sync with value from ui_draw_but_TRACKPREVIEW */
@@ -997,46 +1064,46 @@ void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClip
IMB_freeImBuf(ibuf);
}
- if ((track->flag&TRACK_LOCKED)==0) {
- scopes->marker= marker;
- scopes->track= track;
- scopes->slide_scale[0]= track->pat_max[0]-track->pat_min[0];
- scopes->slide_scale[1]= track->pat_max[1]-track->pat_min[1];
+ if ((track->flag & TRACK_LOCKED)==0) {
+ scopes->marker = marker;
+ scopes->track = track;
+ scopes->slide_scale[0] = track->pat_max[0]-track->pat_min[0];
+ scopes->slide_scale[1] = track->pat_max[1]-track->pat_min[1];
}
}
}
- scopes->framenr= user->framenr;
- scopes->ok= 1;
+ scopes->framenr = user->framenr;
+ scopes->ok = TRUE;
}
static void movieclip_build_proxy_ibuf(MovieClip *clip, ImBuf *ibuf, int cfra, int proxy_render_size, int undistorted)
{
char name[FILE_MAX];
int quality, rectx, recty;
- int size= rendersize_to_number(proxy_render_size);
+ int size = rendersize_to_number(proxy_render_size);
ImBuf *scaleibuf;
get_proxy_fname(clip, proxy_render_size, undistorted, cfra, name);
- rectx= ibuf->x*size/100.0f;
- recty= ibuf->y*size/100.0f;
+ rectx = ibuf->x * size / 100.0f;
+ recty = ibuf->y * size / 100.0f;
- scaleibuf= IMB_dupImBuf(ibuf);
+ scaleibuf = IMB_dupImBuf(ibuf);
IMB_scaleImBuf(scaleibuf, (short)rectx, (short)recty);
- quality= clip->proxy.quality;
- scaleibuf->ftype= JPG | quality;
+ quality = clip->proxy.quality;
+ scaleibuf->ftype = JPG | quality;
/* unsupported feature only confuses other s/w */
- if (scaleibuf->planes==32)
- scaleibuf->planes= 24;
+ if (scaleibuf->planes == 32)
+ scaleibuf->planes = 24;
BLI_lock_thread(LOCK_MOVIECLIP);
BLI_make_existing_file(name);
- if (IMB_saveiff(scaleibuf, name, IB_rect)==0)
+ if (IMB_saveiff(scaleibuf, name, IB_rect) == 0)
perror(name);
BLI_unlock_thread(LOCK_MOVIECLIP);
@@ -1045,30 +1112,30 @@ static void movieclip_build_proxy_ibuf(MovieClip *clip, ImBuf *ibuf, int cfra, i
}
void BKE_movieclip_build_proxy_frame(MovieClip *clip, int clip_flag, struct MovieDistortion *distortion,
- int cfra, int *build_sizes, int build_count, int undistorted)
+ int cfra, int *build_sizes, int build_count, int undistorted)
{
ImBuf *ibuf;
MovieClipUser user;
- user.framenr= cfra;
- user.render_flag= 0;
- user.render_size= MCLIP_PROXY_RENDER_SIZE_FULL;
+ user.framenr = cfra;
+ user.render_flag = 0;
+ user.render_size = MCLIP_PROXY_RENDER_SIZE_FULL;
- ibuf= BKE_movieclip_get_ibuf_flag(clip, &user, clip_flag, MOVIECLIP_CACHE_SKIP);
+ ibuf = BKE_movieclip_get_ibuf_flag(clip, &user, clip_flag, MOVIECLIP_CACHE_SKIP);
if (ibuf) {
- ImBuf *tmpibuf= ibuf;
+ ImBuf *tmpibuf = ibuf;
int i;
if (undistorted)
- tmpibuf= get_undistorted_ibuf(clip, distortion, ibuf);
+ tmpibuf = get_undistorted_ibuf(clip, distortion, ibuf);
- for (i= 0; i<build_count; i++)
+ for (i = 0; i < build_count; i++)
movieclip_build_proxy_ibuf(clip, tmpibuf, cfra, build_sizes[i], undistorted);
IMB_freeImBuf(ibuf);
- if (tmpibuf!=ibuf)
+ if (tmpibuf != ibuf)
IMB_freeImBuf(tmpibuf);
}
}
@@ -1088,53 +1155,59 @@ void unlink_movieclip(Main *bmain, MovieClip *clip)
Scene *sce;
Object *ob;
- for (scr= bmain->screen.first; scr; scr= scr->id.next) {
- for (area= scr->areabase.first; area; area= area->next) {
- for (sl= area->spacedata.first; sl; sl= sl->next) {
- if (sl->spacetype==SPACE_CLIP) {
- SpaceClip *sc= (SpaceClip *) sl;
+ for (scr = bmain->screen.first; scr; scr = scr->id.next) {
+ for (area = scr->areabase.first; area; area = area->next) {
+ for (sl = area->spacedata.first; sl; sl = sl->next) {
+ if (sl->spacetype == SPACE_CLIP) {
+ SpaceClip *sc = (SpaceClip *) sl;
- if (sc->clip==clip)
- sc->clip= NULL;
+ if (sc->clip == clip)
+ sc->clip = NULL;
}
- else if (sl->spacetype==SPACE_VIEW3D) {
- View3D *v3d= (View3D *) sl;
+ else if (sl->spacetype == SPACE_VIEW3D) {
+ View3D *v3d = (View3D *) sl;
BGpic *bgpic;
- for (bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) {
- if (bgpic->clip==clip)
- bgpic->clip= NULL;
+ for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
+ if (bgpic->clip == clip)
+ bgpic->clip = NULL;
}
}
}
}
}
- for (sce= bmain->scene.first; sce; sce= sce->id.next) {
- if (sce->clip==clip)
- sce->clip= NULL;
+ for (sce = bmain->scene.first; sce; sce = sce->id.next) {
+ if (sce->clip == clip)
+ sce->clip = NULL;
}
- for (ob= bmain->object.first; ob; ob= ob->id.next) {
+ for (ob = bmain->object.first; ob; ob = ob->id.next) {
bConstraint *con;
- for (con= ob->constraints.first; con; con= con->next) {
- bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
+ for (con = ob->constraints.first; con; con = con->next) {
+ bConstraintTypeInfo *cti = constraint_get_typeinfo(con);
+
+ if (cti->type == CONSTRAINT_TYPE_FOLLOWTRACK) {
+ bFollowTrackConstraint *data = (bFollowTrackConstraint *) con->data;
- if (cti->type==CONSTRAINT_TYPE_FOLLOWTRACK) {
- bFollowTrackConstraint *data= (bFollowTrackConstraint *) con->data;
+ if (data->clip == clip)
+ data->clip = NULL;
+ }
+ else if (cti->type == CONSTRAINT_TYPE_CAMERASOLVER) {
+ bCameraSolverConstraint *data = (bCameraSolverConstraint *) con->data;
- if (data->clip==clip)
- data->clip= NULL;
+ if (data->clip == clip)
+ data->clip = NULL;
}
- else if (cti->type==CONSTRAINT_TYPE_CAMERASOLVER) {
- bCameraSolverConstraint *data= (bCameraSolverConstraint *) con->data;
+ else if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
+ bObjectSolverConstraint *data = (bObjectSolverConstraint *) con->data;
- if (data->clip==clip)
- data->clip= NULL;
+ if (data->clip == clip)
+ data->clip = NULL;
}
}
}
- clip->id.us= 0;
+ clip->id.us = 0;
}