diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-03-26 03:19:21 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-03-26 03:19:21 +0400 |
commit | 1ce2c73816be97f72484ffa40a3187b24968c6b3 (patch) | |
tree | ea78a78c854a20a6a959ba979c29a6f3823f1955 /source/blender/blenkernel/intern | |
parent | 4457e85442eea30bc6166e15da040188e77b5be7 (diff) |
Code style cleaup for motion-tracking modules.
Should be no functional changes.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 126 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/movieclip.c | 491 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/tracking.c | 1629 |
3 files changed, 1176 insertions, 1070 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 449376a3960..0126f1dc416 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -3927,28 +3927,28 @@ static bConstraintTypeInfo CTI_PIVOT = { /* ----------- Follow Track ------------- */ -static void followtrack_new_data (void *cdata) +static void followtrack_new_data(void *cdata) { - bFollowTrackConstraint *data= (bFollowTrackConstraint *)cdata; - - data->clip= NULL; + bFollowTrackConstraint *data = (bFollowTrackConstraint *)cdata; + + data->clip = NULL; data->flag |= FOLLOWTRACK_ACTIVECLIP; } -static void followtrack_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void followtrack_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bFollowTrackConstraint *data= con->data; - + bFollowTrackConstraint *data = con->data; + func(con, (ID**)&data->clip, userdata); func(con, (ID**)&data->camera, userdata); func(con, (ID**)&data->depth_ob, userdata); } -static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) +static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) { - Scene *scene= cob->scene; - bFollowTrackConstraint *data= con->data; - MovieClip *clip= data->clip; + Scene *scene = cob->scene; + bFollowTrackConstraint *data = con->data; + MovieClip *clip = data->clip; MovieTracking *tracking; MovieTrackingTrack *track; MovieTrackingObject *tracking_object; @@ -3960,17 +3960,17 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase if (!clip || !data->track[0] || !camob) return; - tracking= &clip->tracking; + tracking = &clip->tracking; if (data->object[0]) - tracking_object= BKE_tracking_named_object(tracking, data->object); + tracking_object = BKE_tracking_named_object(tracking, data->object); else - tracking_object= BKE_tracking_get_camera_object(tracking); + tracking_object = BKE_tracking_get_camera_object(tracking); if (!tracking_object) return; - track= BKE_tracking_named_track(tracking, tracking_object, data->track); + track = BKE_tracking_named_track(tracking, tracking_object, data->track); if (!track) return; @@ -3981,7 +3981,7 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase copy_m4_m4(obmat, cob->matrix); - if ((tracking_object->flag&TRACKING_OBJECT_CAMERA)==0) { + if ((tracking_object->flag & TRACKING_OBJECT_CAMERA)==0) { float imat[4][4]; copy_m4_m4(mat, camob->obmat); @@ -4003,15 +4003,15 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase else { MovieTrackingMarker *marker; float vec[3], disp[3], axis[3], mat[4][4]; - float aspect= (scene->r.xsch*scene->r.xasp) / (scene->r.ysch*scene->r.yasp); + float aspect= (scene->r.xsch * scene->r.xasp) / (scene->r.ysch * scene->r.yasp); float len, d; where_is_object_mat(scene, camob, mat); /* camera axis */ - vec[0]= 0.0f; - vec[1]= 0.0f; - vec[2]= 1.0f; + vec[0] = 0.0f; + vec[1] = 0.0f; + vec[2] = 1.0f; mul_v3_m4v3(axis, mat, vec); /* distance to projection plane */ @@ -4019,13 +4019,13 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase sub_v3_v3(vec, mat[3]); project_v3_v3v3(disp, vec, axis); - len= len_v3(disp); + len = len_v3(disp); if (len > FLT_EPSILON) { CameraParams params; float pos[2], rmat[4][4]; - marker= BKE_tracking_get_marker(track, scene->r.cfra); + marker = BKE_tracking_get_marker(track, scene->r.cfra); add_v2_v2v2(pos, marker->pos, track->offset); @@ -4033,12 +4033,14 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase camera_params_from_object(¶ms, camob); if (params.is_ortho) { - vec[0]= params.ortho_scale * (pos[0]-0.5f+params.shiftx); - vec[1]= params.ortho_scale * (pos[1]-0.5f+params.shifty); - vec[2]= -len; + vec[0] = params.ortho_scale * (pos[0] - 0.5f + params.shiftx); + vec[1] = params.ortho_scale * (pos[1] - 0.5f + params.shifty); + vec[2] = -len; - if (aspect > 1.0f) vec[1] /= aspect; - else vec[0] *= aspect; + if (aspect > 1.0f) + vec[1] /= aspect; + else + vec[0] *= aspect; mul_v3_m4v3(disp, camob->obmat, vec); @@ -4049,14 +4051,16 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase copy_v3_v3(cob->matrix[3], disp); } else { - d= (len*params.sensor_x) / (2.0f*params.lens); + d= (len * params.sensor_x) / (2.0f * params.lens); - vec[0]= d*(2.0f*(pos[0]+params.shiftx)-1.0f); - vec[1]= d*(2.0f*(pos[1]+params.shifty)-1.0f); - vec[2]= -len; + vec[0] = d * (2.0f * (pos[0] + params.shiftx) - 1.0f); + vec[1] = d * (2.0f * (pos[1] + params.shifty) - 1.0f); + vec[2] = -len; - if (aspect > 1.0f) vec[1] /= aspect; - else vec[0] *= aspect; + if (aspect > 1.0f) + vec[1] /= aspect; + else + vec[0] *= aspect; mul_v3_m4v3(disp, camob->obmat, vec); @@ -4069,8 +4073,8 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase } if (data->depth_ob && data->depth_ob->derivedFinal) { - Object *depth_ob= data->depth_ob; - BVHTreeFromMesh treeData= NULL_BVHTreeFromMesh; + Object *depth_ob = data->depth_ob; + BVHTreeFromMesh treeData = NULL_BVHTreeFromMesh; BVHTreeRayHit hit; float ray_start[3], ray_end[3], ray_nor[3], imat[4][4]; int result; @@ -4084,10 +4088,10 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase bvhtree_from_mesh_faces(&treeData, depth_ob->derivedFinal, 0.0f, 4, 6); - hit.dist= FLT_MAX; - hit.index= -1; + hit.dist = FLT_MAX; + hit.index = -1; - result= BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_nor, 0.0f, &hit, treeData.raycast_callback, &treeData); + result = BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_nor, 0.0f, &hit, treeData.raycast_callback, &treeData); if (result != -1) { mul_v3_m4v3(cob->matrix[3], depth_ob->obmat, hit.co); @@ -4117,34 +4121,34 @@ static bConstraintTypeInfo CTI_FOLLOWTRACK = { /* ----------- Camre Solver ------------- */ -static void camerasolver_new_data (void *cdata) +static void camerasolver_new_data(void *cdata) { - bCameraSolverConstraint *data= (bCameraSolverConstraint *)cdata; - + bCameraSolverConstraint *data = (bCameraSolverConstraint *)cdata; + data->clip = NULL; data->flag |= CAMERASOLVER_ACTIVECLIP; } -static void camerasolver_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void camerasolver_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { - bCameraSolverConstraint *data= con->data; - + bCameraSolverConstraint *data = con->data; + func(con, (ID**)&data->clip, userdata); } -static void camerasolver_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) +static void camerasolver_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) { - Scene *scene= cob->scene; - bCameraSolverConstraint *data= con->data; - MovieClip *clip= data->clip; + Scene *scene = cob->scene; + bCameraSolverConstraint *data = con->data; + MovieClip *clip = data->clip; if (data->flag & CAMERASOLVER_ACTIVECLIP) - clip= scene->clip; + clip = scene->clip; if (clip) { float mat[4][4], obmat[4][4]; - MovieTracking *tracking= &clip->tracking; - MovieTrackingObject *object= BKE_tracking_get_camera_object(tracking); + MovieTracking *tracking = &clip->tracking; + MovieTrackingObject *object = BKE_tracking_get_camera_object(tracking); BKE_tracking_get_interpolated_camera(tracking, object, scene->r.cfra, mat); @@ -4172,16 +4176,16 @@ static bConstraintTypeInfo CTI_CAMERASOLVER = { /* ----------- Object Solver ------------- */ -static void objectsolver_new_data (void *cdata) +static void objectsolver_new_data(void *cdata) { - bObjectSolverConstraint *data= (bObjectSolverConstraint *)cdata; + bObjectSolverConstraint *data = (bObjectSolverConstraint *)cdata; data->clip = NULL; data->flag |= OBJECTSOLVER_ACTIVECLIP; unit_m4(data->invmat); } -static void objectsolver_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +static void objectsolver_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata) { bObjectSolverConstraint *data= con->data; @@ -4189,12 +4193,12 @@ static void objectsolver_id_looper (bConstraint *con, ConstraintIDFunc func, voi func(con, (ID**)&data->camera, userdata); } -static void objectsolver_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) +static void objectsolver_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) { - Scene *scene= cob->scene; - bObjectSolverConstraint *data= con->data; - MovieClip *clip= data->clip; - Object *camob= data->camera ? data->camera : scene->camera; + Scene *scene = cob->scene; + bObjectSolverConstraint *data = con->data; + MovieClip *clip = data->clip; + Object *camob = data->camera ? data->camera : scene->camera; if (data->flag & OBJECTSOLVER_ACTIVECLIP) clip= scene->clip; @@ -4203,10 +4207,10 @@ static void objectsolver_evaluate (bConstraint *con, bConstraintOb *cob, ListBas return; if (clip) { - MovieTracking *tracking= &clip->tracking; + MovieTracking *tracking = &clip->tracking; MovieTrackingObject *object; - object= BKE_tracking_named_object(tracking, data->object); + object = BKE_tracking_named_object(tracking, data->object); if (object) { float mat[4][4], obmat[4][4], imat[4][4], cammat[4][4], camimat[4][4], parmat[4][4]; diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 0cecc09a9d7..bc147c52094 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,27 @@ 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) { - ImBuf *ibuf= NULL; - int tc= get_timecode(clip, flag); - int proxy= rendersize_to_proxy(user, flag); + 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 +225,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); @@ -239,16 +241,16 @@ static ImBuf *movieclip_load_movie_file(MovieClip *clip, MovieClipUser *user, in 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; @@ -295,34 +297,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 +340,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 +362,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 +389,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 +421,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,24 +442,27 @@ 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; } return clip; @@ -458,24 +470,24 @@ MovieClip *BKE_add_movieclip_file(const char *name) 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 +502,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 +540,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 +594,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 +616,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 +638,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 +652,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 +664,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 +689,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 +729,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 +739,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 +792,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 +810,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; + + if (angle) + *angle= 0.0f; - stableibuf= ibuf; + stableibuf = ibuf; } - if (stableibuf!=ibuf) { + if (stableibuf != ibuf) { IMB_freeImBuf(ibuf); - ibuf= stableibuf; + ibuf = stableibuf; } return ibuf; @@ -834,31 +859,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) @@ -873,20 +898,20 @@ int BKE_movieclip_get_duration(struct MovieClip *clip) 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 +921,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 +936,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 +952,13 @@ 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; } void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClipScopes *scopes) @@ -941,44 +968,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 +1024,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 +1072,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 +1115,53 @@ 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; + 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_CAMERASOLVER) { + bCameraSolverConstraint *data = (bCameraSolverConstraint *) con->data; - if (data->clip==clip) - data->clip= NULL; + if (data->clip == clip) + data->clip = NULL; } } } - clip->id.us= 0; + clip->id.us = 0; } diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index bdecc6884ea..b35b654a55b 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -55,7 +55,6 @@ #include "BKE_movieclip.h" #include "BKE_object.h" #include "BKE_scene.h" -#include "BKE_main.h" // XXX: ... #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" @@ -78,24 +77,24 @@ static struct { void BKE_tracking_init_settings(MovieTracking *tracking) { - tracking->camera.sensor_width= 35.0f; - tracking->camera.pixel_aspect= 1.0f; - tracking->camera.units= CAMERA_UNITS_MM; - - tracking->settings.default_tracker= TRACKER_HYBRID; - tracking->settings.default_minimum_correlation= 0.75; - tracking->settings.default_pattern_size= 11; - tracking->settings.default_search_size= 51; - tracking->settings.default_pyramid_levels= 2; - tracking->settings.keyframe1= 1; - tracking->settings.keyframe2= 30; - tracking->settings.dist= 1; - tracking->settings.object_distance= 1; - - tracking->stabilization.scaleinf= 1.0f; - tracking->stabilization.locinf= 1.0f; - tracking->stabilization.rotinf= 1.0f; - tracking->stabilization.maxscale= 2.0f; + tracking->camera.sensor_width = 35.0f; + tracking->camera.pixel_aspect = 1.0f; + tracking->camera.units = CAMERA_UNITS_MM; + + tracking->settings.default_tracker = TRACKER_HYBRID; + tracking->settings.default_minimum_correlation = 0.75; + tracking->settings.default_pattern_size = 11; + tracking->settings.default_search_size = 51; + tracking->settings.default_pyramid_levels = 2; + tracking->settings.keyframe1 = 1; + tracking->settings.keyframe2 = 30; + tracking->settings.dist = 1; + tracking->settings.object_distance = 1; + + tracking->stabilization.scaleinf = 1.0f; + tracking->stabilization.locinf = 1.0f; + tracking->stabilization.rotinf = 1.0f; + tracking->stabilization.maxscale = 2.0f; BKE_tracking_new_object(tracking, "Camera"); } @@ -112,143 +111,152 @@ void BKE_tracking_clamp_track(MovieTrackingTrack *track, int event) } /* sort */ - for (a= 0; a<2; a++) { - if (track->pat_min[a]>track->pat_max[a]) + for (a = 0; a < 2; a++) { + if (track->pat_min[a] > track->pat_max[a]) SWAP(float, track->pat_min[a], track->pat_max[a]); - if (track->search_min[a]>track->search_max[a]) + if (track->search_min[a] > track->search_max[a]) SWAP(float, track->search_min[a], track->search_max[a]); } /* compute the effective pattern size, which differs from the fine resolution * pattern size for the pyramid KLT tracker */ - for (a= 0; a<2; a++) { + for (a = 0; a < 2; a++) { pat_min[a] = max_pyramid_level_factor * track->pat_min[a]; pat_max[a] = max_pyramid_level_factor * track->pat_max[a]; } - if (event==CLAMP_PAT_DIM) { - for (a= 0; a<2; a++) { + if (event == CLAMP_PAT_DIM) { + for (a = 0; a < 2; a++) { /* search shouldn't be resized smaller than pattern */ - track->search_min[a]= MIN2(pat_min[a], track->search_min[a]); - track->search_max[a]= MAX2(pat_max[a], track->search_max[a]); + track->search_min[a] = MIN2(pat_min[a], track->search_min[a]); + track->search_max[a] = MAX2(pat_max[a], track->search_max[a]); } } - else if (event==CLAMP_PAT_POS) { + else if (event == CLAMP_PAT_POS) { float dim[2]; + sub_v2_v2v2(dim, track->pat_max, track->pat_min); - for (a= 0; a<2; a++) { + for (a = 0; a < 2; a++) { /* pattern shouldn't be moved outside of search */ if (pat_min[a] < track->search_min[a]) { - track->pat_min[a]= track->search_min[a] - (pat_min[a] - track->pat_min[a]); - track->pat_max[a]= track->pat_min[a] + dim[a]; + track->pat_min[a] = track->search_min[a] - (pat_min[a] - track->pat_min[a]); + track->pat_max[a] = track->pat_min[a] + dim[a]; } if (track->pat_max[a] > track->search_max[a]) { - track->pat_max[a]= track->search_max[a] - (pat_max[a] - track->pat_max[a]); - track->pat_min[a]= track->pat_max[a] - dim[a]; + track->pat_max[a] = track->search_max[a] - (pat_max[a] - track->pat_max[a]); + track->pat_min[a] = track->pat_max[a] - dim[a]; } } } - else if (event==CLAMP_SEARCH_DIM) { - for (a= 0; a<2; a++) { + else if (event == CLAMP_SEARCH_DIM) { + for (a = 0; a < 2; a++) { /* search shouldn't be resized smaller than pattern */ - track->search_min[a]= MIN2(pat_min[a], track->search_min[a]); - track->search_max[a]= MAX2(pat_max[a], track->search_max[a]); + track->search_min[a] = MIN2(pat_min[a], track->search_min[a]); + track->search_max[a] = MAX2(pat_max[a], track->search_max[a]); } } - else if (event==CLAMP_SEARCH_POS) { + else if (event == CLAMP_SEARCH_POS) { float dim[2]; + sub_v2_v2v2(dim, track->search_max, track->search_min); - for (a= 0; a<2; a++) { + for (a = 0; a < 2; a++) { /* search shouldn't be moved inside pattern */ if (track->search_min[a] > pat_min[a]) { - track->search_min[a]= pat_min[a]; - track->search_max[a]= track->search_min[a]+dim[a]; + track->search_min[a] = pat_min[a]; + track->search_max[a] = track->search_min[a]+dim[a]; } if (track->search_max[a] < pat_max[a]) { - track->search_max[a]= pat_max[a]; - track->search_min[a]= track->search_max[a]-dim[a]; + track->search_max[a] = pat_max[a]; + track->search_min[a] = track->search_max[a]-dim[a]; } } } - else if (event==CLAMP_PYRAMID_LEVELS || (event==CLAMP_SEARCH_DIM && track->tracker == TRACKER_KLT)) { + else if (event == CLAMP_PYRAMID_LEVELS || (event == CLAMP_SEARCH_DIM && track->tracker == TRACKER_KLT)) { float dim[2]; sub_v2_v2v2(dim, track->pat_max, track->pat_min); { - float search_ratio= 2.3f * max_pyramid_level_factor; + float search_ratio = 2.3f * max_pyramid_level_factor; /* resize the search area to something sensible based * on the number of pyramid levels */ - for (a= 0; a<2; a++) { - track->search_min[a]= search_ratio * track->pat_min[a]; - track->search_max[a]= search_ratio * track->pat_max[a]; + for (a = 0; a < 2; a++) { + track->search_min[a] = search_ratio * track->pat_min[a]; + track->search_max[a] = search_ratio * track->pat_max[a]; } } } /* marker's center should be in center of pattern */ - if (event==CLAMP_PAT_DIM || event==CLAMP_PAT_POS) { + if (event == CLAMP_PAT_DIM || event == CLAMP_PAT_POS) { float dim[2]; + sub_v2_v2v2(dim, track->pat_max, track->pat_min); - for (a= 0; a<2; a++) { - track->pat_min[a]= -dim[a]/2.0f; - track->pat_max[a]= dim[a]/2.0f; + for (a = 0; a < 2; a++) { + track->pat_min[a] = -dim[a]/2.0f; + track->pat_max[a] = dim[a]/2.0f; } } } void BKE_tracking_track_flag(MovieTrackingTrack *track, int area, int flag, int clear) { - if (area==TRACK_AREA_NONE) + if (area == TRACK_AREA_NONE) return; if (clear) { - if (area&TRACK_AREA_POINT) track->flag&= ~flag; - if (area&TRACK_AREA_PAT) track->pat_flag&= ~flag; - if (area&TRACK_AREA_SEARCH) track->search_flag&= ~flag; + if (area & TRACK_AREA_POINT) + track->flag &= ~flag; + if (area & TRACK_AREA_PAT) + track->pat_flag &= ~flag; + if (area & TRACK_AREA_SEARCH) + track->search_flag &= ~flag; } else { - if (area&TRACK_AREA_POINT) track->flag|= flag; - if (area&TRACK_AREA_PAT) track->pat_flag|= flag; - if (area&TRACK_AREA_SEARCH) track->search_flag|= flag; + if (area & TRACK_AREA_POINT) + track->flag |= flag; + if (area & TRACK_AREA_PAT) + track->pat_flag |= flag; + if (area & TRACK_AREA_SEARCH) + track->search_flag |= flag; } } MovieTrackingTrack *BKE_tracking_add_track(MovieTracking *tracking, ListBase *tracksbase, float x, float y, - int framenr, int width, int height) + int framenr, int width, int height) { MovieTrackingTrack *track; MovieTrackingMarker marker; - MovieTrackingSettings *settings= &tracking->settings; + MovieTrackingSettings *settings = &tracking->settings; - float half_pattern= (float)settings->default_pattern_size/2.0f; - float half_search= (float)settings->default_search_size/2.0f; + float half_pattern = (float)settings->default_pattern_size / 2.0f; + float half_search = (float)settings->default_search_size / 2.0f; float pat[2], search[2]; - pat[0]= half_pattern/(float)width; - pat[1]= half_pattern/(float)height; + pat[0] = half_pattern / (float)width; + pat[1] = half_pattern / (float)height; - search[0]= half_search/(float)width; - search[1]= half_search/(float)height; + search[0] = half_search / (float)width; + search[1] = half_search / (float)height; - track= MEM_callocN(sizeof(MovieTrackingTrack), "add_marker_exec track"); + track = MEM_callocN(sizeof(MovieTrackingTrack), "add_marker_exec track"); strcpy(track->name, "Track"); - track->tracker= settings->default_tracker; - track->pyramid_levels= settings->default_pyramid_levels; - track->minimum_correlation= settings->default_minimum_correlation; - track->margin= settings->default_margin; - track->pattern_match= settings->default_pattern_match; - track->frames_limit= settings->default_frames_limit; - track->flag= settings->default_flag; + track->tracker = settings->default_tracker; + track->pyramid_levels = settings->default_pyramid_levels; + track->minimum_correlation = settings->default_minimum_correlation; + track->margin = settings->default_margin; + track->pattern_match = settings->default_pattern_match; + track->frames_limit = settings->default_frames_limit; + track->flag = settings->default_flag; memset(&marker, 0, sizeof(marker)); - marker.pos[0]= x; - marker.pos[1]= y; - marker.framenr= framenr; + marker.pos[0] = x; + marker.pos[1] = y; + marker.framenr = framenr; copy_v2_v2(track->pat_max, pat); negate_v2_v2(track->pat_min, pat); @@ -272,32 +280,34 @@ MovieTrackingMarker *BKE_tracking_insert_marker(MovieTrackingTrack *track, Movie MovieTrackingMarker *old_marker= NULL; if (track->markersnr) - old_marker= BKE_tracking_exact_marker(track, marker->framenr); + old_marker = BKE_tracking_exact_marker(track, marker->framenr); if (old_marker) { - *old_marker= *marker; + *old_marker = *marker; return old_marker; } else { - int a= track->markersnr; + int a = track->markersnr; while (a--) { - if (track->markers[a].framenr<marker->framenr) + if (track->markers[a].framenr < marker->framenr) break; } track->markersnr++; - if (track->markers) track->markers= MEM_reallocN(track->markers, sizeof(MovieTrackingMarker)*track->markersnr); - else track->markers= MEM_callocN(sizeof(MovieTrackingMarker), "MovieTracking markers"); + if (track->markers) + track->markers = MEM_reallocN(track->markers, sizeof(MovieTrackingMarker)*track->markersnr); + else + track->markers = MEM_callocN(sizeof(MovieTrackingMarker), "MovieTracking markers"); memmove(track->markers+a+2, track->markers+a+1, (track->markersnr-a-2)*sizeof(MovieTrackingMarker)); - track->markers[a+1]= *marker; + track->markers[a+1] = *marker; - track->last_marker= a+1; + track->last_marker = a + 1; - return &track->markers[a+1]; + return &track->markers[a + 1]; } } @@ -306,16 +316,16 @@ void BKE_tracking_delete_marker(MovieTrackingTrack *track, int framenr) int a= 0; while (a<track->markersnr) { - if (track->markers[a].framenr==framenr) { - if (track->markersnr>1) { + if (track->markers[a].framenr == framenr) { + if (track->markersnr > 1) { memmove(track->markers+a, track->markers+a+1, (track->markersnr-a-1)*sizeof(MovieTrackingMarker)); track->markersnr--; - track->markers= MEM_reallocN(track->markers, sizeof(MovieTrackingMarker)*track->markersnr); + track->markers = MEM_reallocN(track->markers, sizeof(MovieTrackingMarker)*track->markersnr); } else { MEM_freeN(track->markers); - track->markers= NULL; - track->markersnr= 0; + track->markers = NULL; + track->markersnr = 0; } break; @@ -327,22 +337,23 @@ void BKE_tracking_delete_marker(MovieTrackingTrack *track, int framenr) MovieTrackingMarker *BKE_tracking_get_marker(MovieTrackingTrack *track, int framenr) { - int a= track->markersnr-1; + int a = track->markersnr-1; if (!track->markersnr) return NULL; /* approximate pre-first framenr marker with first marker */ - if (framenr<track->markers[0].framenr) + if (framenr < track->markers[0].framenr) return &track->markers[0]; - if (track->last_marker<track->markersnr) - a= track->last_marker; + if (track->last_marker < track->markersnr) + a = track->last_marker; + + if (track->markers[a].framenr <= framenr) { + while (a < track->markersnr && track->markers[a].framenr <= framenr) { + if (track->markers[a].framenr == framenr) { + track->last_marker = a; - if (track->markers[a].framenr<=framenr) { - while (a<track->markersnr && track->markers[a].framenr<=framenr) { - if (track->markers[a].framenr==framenr) { - track->last_marker= a; return &track->markers[a]; } a++; @@ -352,9 +363,10 @@ MovieTrackingMarker *BKE_tracking_get_marker(MovieTrackingTrack *track, int fram return &track->markers[a-1]; } else { - while (a>=0 && track->markers[a].framenr>=framenr) { - if (track->markers[a].framenr==framenr) { - track->last_marker= a; + while (a >= 0 && track->markers[a].framenr >= framenr) { + if (track->markers[a].framenr == framenr) { + track->last_marker = a; + return &track->markers[a]; } @@ -370,16 +382,16 @@ MovieTrackingMarker *BKE_tracking_get_marker(MovieTrackingTrack *track, int fram MovieTrackingMarker *BKE_tracking_ensure_marker(MovieTrackingTrack *track, int framenr) { - MovieTrackingMarker *marker= BKE_tracking_get_marker(track, framenr); + MovieTrackingMarker *marker = BKE_tracking_get_marker(track, framenr); - if (marker->framenr!=framenr) { + if (marker->framenr != framenr) { MovieTrackingMarker marker_new; - marker_new= *marker; - marker_new.framenr= framenr; + marker_new = *marker; + marker_new.framenr = framenr; BKE_tracking_insert_marker(track, &marker_new); - marker= BKE_tracking_get_marker(track, framenr); + marker = BKE_tracking_get_marker(track, framenr); } return marker; @@ -387,9 +399,9 @@ MovieTrackingMarker *BKE_tracking_ensure_marker(MovieTrackingTrack *track, int f MovieTrackingMarker *BKE_tracking_exact_marker(MovieTrackingTrack *track, int framenr) { - MovieTrackingMarker *marker= BKE_tracking_get_marker(track, framenr); + MovieTrackingMarker *marker = BKE_tracking_get_marker(track, framenr); - if (marker->framenr!=framenr) + if (marker->framenr != framenr) return NULL; return marker; @@ -409,19 +421,22 @@ int BKE_tracking_has_enabled_marker(MovieTrackingTrack *track, int framenr) void BKE_tracking_free_track(MovieTrackingTrack *track) { - if (track->markers) MEM_freeN(track->markers); + if (track->markers) + MEM_freeN(track->markers); } static void put_disabled_marker(MovieTrackingTrack *track, MovieTrackingMarker *ref_marker, int before, int overwrite) { MovieTrackingMarker marker_new; - marker_new= *ref_marker; - marker_new.flag&= ~MARKER_TRACKED; - marker_new.flag|= MARKER_DISABLED; + marker_new = *ref_marker; + marker_new.flag &= ~MARKER_TRACKED; + marker_new.flag |= MARKER_DISABLED; - if (before) marker_new.framenr--; - else marker_new.framenr++; + if (before) + marker_new.framenr--; + else + marker_new.framenr++; if (!BKE_tracking_has_marker(track, marker_new.framenr) || overwrite) BKE_tracking_insert_marker(track, &marker_new); @@ -431,12 +446,13 @@ void BKE_tracking_clear_path(MovieTrackingTrack *track, int ref_frame, int actio { int a; - if (action==TRACK_CLEAR_REMAINED) { - a= 1; - while (a<track->markersnr) { - if (track->markers[a].framenr>ref_frame) { - track->markersnr= a; - track->markers= MEM_reallocN(track->markers, sizeof(MovieTrackingMarker)*track->markersnr); + if (action == TRACK_CLEAR_REMAINED) { + a = 1; + + while (a < track->markersnr) { + if (track->markers[a].framenr > ref_frame) { + track->markersnr = a; + track->markers = MEM_reallocN(track->markers, sizeof(MovieTrackingMarker)*track->markersnr); break; } @@ -447,14 +463,15 @@ void BKE_tracking_clear_path(MovieTrackingTrack *track, int ref_frame, int actio if (track->markersnr) put_disabled_marker(track, &track->markers[track->markersnr-1], 0, 1); } - else if (action==TRACK_CLEAR_UPTO) { + else if (action == TRACK_CLEAR_UPTO) { a= track->markersnr-1; - while (a>=0) { - if (track->markers[a].framenr<=ref_frame) { + + while (a >= 0) { + if (track->markers[a].framenr <= ref_frame) { memmove(track->markers, track->markers+a, (track->markersnr-a)*sizeof(MovieTrackingMarker)); - track->markersnr= track->markersnr-a; - track->markers= MEM_reallocN(track->markers, sizeof(MovieTrackingMarker)*track->markersnr); + track->markersnr = track->markersnr-a; + track->markers = MEM_reallocN(track->markers, sizeof(MovieTrackingMarker)*track->markersnr); break; } @@ -465,15 +482,15 @@ void BKE_tracking_clear_path(MovieTrackingTrack *track, int ref_frame, int actio if (track->markersnr) put_disabled_marker(track, &track->markers[0], 1, 1); } - else if (action==TRACK_CLEAR_ALL) { + else if (action == TRACK_CLEAR_ALL) { MovieTrackingMarker *marker, marker_new; - marker= BKE_tracking_get_marker(track, ref_frame); - marker_new= *marker; + marker = BKE_tracking_get_marker(track, ref_frame); + marker_new = *marker; MEM_freeN(track->markers); - track->markers= NULL; - track->markersnr= 0; + track->markers = NULL; + track->markersnr = 0; BKE_tracking_insert_marker(track, &marker_new); @@ -484,27 +501,28 @@ void BKE_tracking_clear_path(MovieTrackingTrack *track, int ref_frame, int actio void BKE_tracking_join_tracks(MovieTrackingTrack *dst_track, MovieTrackingTrack *src_track) { - int i= 0, a= 0, b= 0; + int i = 0, a = 0, b = 0, tot; MovieTrackingMarker *markers; - markers= MEM_callocN((dst_track->markersnr+src_track->markersnr)*sizeof(MovieTrackingMarker), "tmp tracking joined tracks"); + tot = dst_track->markersnr + src_track->markersnr; + markers = MEM_callocN(tot * sizeof(MovieTrackingMarker), "tmp tracking joined tracks"); while (a < src_track->markersnr || b < dst_track->markersnr) { - if (b>=dst_track->markersnr) { - markers[i]= src_track->markers[a++]; + if (b >= dst_track->markersnr) { + markers[i] = src_track->markers[a++]; } - else if (a>=src_track->markersnr) { - markers[i]= dst_track->markers[b++]; + else if (a >= src_track->markersnr) { + markers[i] = dst_track->markers[b++]; } - else if (src_track->markers[a].framenr<dst_track->markers[b].framenr) { - markers[i]= src_track->markers[a++]; + else if (src_track->markers[a].framenr < dst_track->markers[b].framenr) { + markers[i] = src_track->markers[a++]; } - else if (src_track->markers[a].framenr>dst_track->markers[b].framenr) { - markers[i]= dst_track->markers[b++]; + else if (src_track->markers[a].framenr > dst_track->markers[b].framenr) { + markers[i] = dst_track->markers[b++]; } else { - if ((src_track->markers[a].flag&MARKER_DISABLED)==0) { - if ((dst_track->markers[b].flag&MARKER_DISABLED)==0) { + if ((src_track->markers[a].flag & MARKER_DISABLED)==0) { + if ((dst_track->markers[b].flag & MARKER_DISABLED)==0) { /* both tracks are enabled on this frame, so find the whole segment * on which tracks are intersecting and blend tracks using linear * interpolation to prevent jumps */ @@ -517,6 +535,7 @@ void BKE_tracking_join_tracks(MovieTrackingTrack *dst_track, MovieTrackingTrack (dst_track->markers[b-1].flag & MARKER_DISABLED) || (dst_track->markers[b-1].framenr != frame - 1); + /* find length of intersection */ while (a < src_track->markersnr && b < dst_track->markersnr) { marker_a = &src_track->markers[a]; marker_b = &dst_track->markers[b]; @@ -536,6 +555,7 @@ void BKE_tracking_join_tracks(MovieTrackingTrack *dst_track, MovieTrackingTrack a = start_a; b = start_b; + /* linear interpolation for intersecting frames */ for (j = 0; j < len; j++) { float fac = 0.5f; @@ -548,7 +568,7 @@ void BKE_tracking_join_tracks(MovieTrackingTrack *dst_track, MovieTrackingTrack marker_a = &src_track->markers[a]; marker_b = &dst_track->markers[b]; - markers[i]= dst_track->markers[b]; + markers[i] = dst_track->markers[b]; interp_v2_v2v2(markers[i].pos, marker_b->pos, marker_a->pos, fac); a++; b++; @@ -558,9 +578,9 @@ void BKE_tracking_join_tracks(MovieTrackingTrack *dst_track, MovieTrackingTrack /* this values will be incremented at the end of the loop cycle */ a--; b--; i--; } - else markers[i]= src_track->markers[a]; + else markers[i] = src_track->markers[a]; } - else markers[i]= dst_track->markers[b]; + else markers[i] = dst_track->markers[b]; a++; b++; @@ -571,10 +591,10 @@ void BKE_tracking_join_tracks(MovieTrackingTrack *dst_track, MovieTrackingTrack MEM_freeN(dst_track->markers); - dst_track->markers= MEM_callocN(i*sizeof(MovieTrackingMarker), "tracking joined tracks"); + dst_track->markers = MEM_callocN(i*sizeof(MovieTrackingMarker), "tracking joined tracks"); memcpy(dst_track->markers, markers, i*sizeof(MovieTrackingMarker)); - dst_track->markersnr= i; + dst_track->markersnr = i; MEM_freeN(markers); } @@ -583,7 +603,7 @@ static void tracking_tracks_free(ListBase *tracks) { MovieTrackingTrack *track; - for (track= tracks->first; track; track= track->next) { + for (track = tracks->first; track; track = track->next) { BKE_tracking_free_track(track); } @@ -606,7 +626,7 @@ static void tracking_objects_free(ListBase *objects) { MovieTrackingObject *object; - for (object= objects->first; object; object= object->next) + for (object = objects->first; object; object = object->next) tracking_object_free(object); BLI_freelistN(objects); @@ -631,7 +651,7 @@ static MovieTrackingTrack *duplicate_track(MovieTrackingTrack *track) new_track = MEM_callocN(sizeof(MovieTrackingTrack), "tracksMapMerge new_track"); - *new_track= *track; + *new_track = *track; new_track->next = new_track->prev = NULL; new_track->markers = MEM_dupallocN(new_track->markers); @@ -710,20 +730,20 @@ typedef struct TracksMap { static TracksMap *tracks_map_new(const char *object_name, int is_camera, int num_tracks, int customdata_size) { - TracksMap *map= MEM_callocN(sizeof(TracksMap), "TrackingsMap"); + TracksMap *map = MEM_callocN(sizeof(TracksMap), "TrackingsMap"); BLI_strncpy(map->object_name, object_name, sizeof(map->object_name)); - map->is_camera= is_camera; + map->is_camera = is_camera; - map->num_tracks= num_tracks; - map->customdata_size= customdata_size; + map->num_tracks = num_tracks; + map->customdata_size = customdata_size; - map->tracks= MEM_callocN(sizeof(MovieTrackingTrack)*num_tracks, "TrackingsMap tracks"); + map->tracks = MEM_callocN(sizeof(MovieTrackingTrack)*num_tracks, "TrackingsMap tracks"); if (customdata_size) - map->customdata= MEM_callocN(customdata_size*num_tracks, "TracksMap customdata"); + map->customdata = MEM_callocN(customdata_size*num_tracks, "TracksMap customdata"); - map->hash= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "TracksMap hash"); + map->hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "TracksMap hash"); return map; } @@ -735,19 +755,19 @@ static int tracks_map_size(TracksMap *map) static void tracks_map_get(TracksMap *map, int index, MovieTrackingTrack **track, void **customdata) { - *track= &map->tracks[index]; + *track = &map->tracks[index]; if (map->customdata) - *customdata= &map->customdata[index*map->customdata_size]; + *customdata = &map->customdata[index*map->customdata_size]; } static void tracks_map_insert(TracksMap *map, MovieTrackingTrack *track, void *customdata) { MovieTrackingTrack new_track= *track; - new_track.markers= MEM_dupallocN(new_track.markers); + new_track.markers = MEM_dupallocN(new_track.markers); - map->tracks[map->ptr]= new_track; + map->tracks[map->ptr] = new_track; if (customdata) memcpy(&map->customdata[map->ptr*map->customdata_size], customdata, map->customdata_size); @@ -760,64 +780,64 @@ static void tracks_map_insert(TracksMap *map, MovieTrackingTrack *track, void *c static void tracks_map_merge(TracksMap *map, MovieTracking *tracking) { MovieTrackingTrack *track; - MovieTrackingTrack *act_track= BKE_tracking_active_track(tracking); - MovieTrackingTrack *rot_track= tracking->stabilization.rot_track; - ListBase tracks= {NULL, NULL}, new_tracks= {NULL, NULL}; + MovieTrackingTrack *act_track = BKE_tracking_active_track(tracking); + MovieTrackingTrack *rot_track = tracking->stabilization.rot_track; + ListBase tracks = {NULL, NULL}, new_tracks = {NULL, NULL}; ListBase *old_tracks; int a; if (map->is_camera) { - old_tracks= &tracking->tracks; + old_tracks = &tracking->tracks; } else { - MovieTrackingObject *object= BKE_tracking_named_object(tracking, map->object_name); + MovieTrackingObject *object = BKE_tracking_named_object(tracking, map->object_name); if (!object) { /* object was deleted by user, create new one */ - object= BKE_tracking_new_object(tracking, map->object_name); + object = BKE_tracking_new_object(tracking, map->object_name); } - old_tracks= &object->tracks; + old_tracks = &object->tracks; } /* duplicate currently operating tracks to temporary list. * this is needed to keep names in unique state and it's faster to change names * of currently operating tracks (if needed) */ - for (a= 0; a<map->num_tracks; a++) { - int replace_sel= 0, replace_rot= 0; + for (a = 0; a < map->num_tracks; a++) { + int replace_sel = 0, replace_rot = 0; MovieTrackingTrack *new_track, *old; - track= &map->tracks[a]; + track = &map->tracks[a]; /* find original of operating track in list of previously displayed tracks */ - old= BLI_ghash_lookup(map->hash, track); + old = BLI_ghash_lookup(map->hash, track); if (old) { - MovieTrackingTrack *cur= old_tracks->first; + MovieTrackingTrack *cur = old_tracks->first; while (cur) { - if (cur==old) + if (cur == old) break; - cur= cur->next; + cur = cur->next; } /* original track was found, re-use flags and remove this track */ if (cur) { - if (cur==act_track) - replace_sel= 1; - if (cur==rot_track) - replace_rot= 1; + if (cur == act_track) + replace_sel = 1; + if (cur == rot_track) + replace_rot = 1; - track->flag= cur->flag; - track->pat_flag= cur->pat_flag; - track->search_flag= cur->search_flag; + track->flag = cur->flag; + track->pat_flag = cur->pat_flag; + track->search_flag = cur->search_flag; BKE_tracking_free_track(cur); BLI_freelinkN(old_tracks, cur); } } - new_track= duplicate_track(track); + new_track = duplicate_track(track); BLI_ghash_remove(map->hash, track, NULL, NULL); /* XXX: are we actually need this */ BLI_ghash_insert(map->hash, track, new_track); @@ -832,24 +852,24 @@ static void tracks_map_merge(TracksMap *map, MovieTracking *tracking) } /* move all tracks, which aren't operating */ - track= old_tracks->first; + track = old_tracks->first; while (track) { - MovieTrackingTrack *next= track->next; + MovieTrackingTrack *next = track->next; - track->next= track->prev= NULL; + track->next = track->prev = NULL; BLI_addtail(&new_tracks, track); track= next; } /* now move all tracks which are currently operating and keep their names unique */ - track= tracks.first; + track = tracks.first; while (track) { - MovieTrackingTrack *next= track->next; + MovieTrackingTrack *next = track->next; BLI_remlink(&tracks, track); - track->next= track->prev= NULL; + track->next = track->prev = NULL; BLI_addtail(&new_tracks, track); BLI_uniquename(&new_tracks, track, "Track", '.', offsetof(MovieTrackingTrack, name), sizeof(track->name)); @@ -866,7 +886,7 @@ static void tracks_map_free(TracksMap *map, void (*customdata_free) (void *custo BLI_ghash_free(map->hash, NULL, NULL); - for (i= 0; i<map->num_tracks; i++) { + for (i = 0; i < map->num_tracks; i++) { if (map->customdata && customdata_free) customdata_free(&map->customdata[i*map->customdata_size]); @@ -915,48 +935,48 @@ typedef struct MovieTrackingContext { MovieTrackingContext *BKE_tracking_context_new(MovieClip *clip, MovieClipUser *user, short backwards, short sequence) { - MovieTrackingContext *context= MEM_callocN(sizeof(MovieTrackingContext), "trackingContext"); - MovieTracking *tracking= &clip->tracking; - MovieTrackingSettings *settings= &tracking->settings; - ListBase *tracksbase= BKE_tracking_get_tracks(tracking); + MovieTrackingContext *context = MEM_callocN(sizeof(MovieTrackingContext), "trackingContext"); + MovieTracking *tracking = &clip->tracking; + MovieTrackingSettings *settings = &tracking->settings; + ListBase *tracksbase = BKE_tracking_get_tracks(tracking); MovieTrackingTrack *track; - MovieTrackingObject *object= BKE_tracking_active_object(tracking); - int num_tracks= 0; + MovieTrackingObject *object = BKE_tracking_active_object(tracking); + int num_tracks = 0; - context->settings= *settings; - context->backwards= backwards; - context->sync_frame= user->framenr; - context->first_time= 1; - context->sequence= sequence; + context->settings = *settings; + context->backwards = backwards; + context->sync_frame = user->framenr; + context->first_time = TRUE; + context->sequence = sequence; /* count */ - track= tracksbase->first; + track = tracksbase->first; while (track) { if (TRACK_SELECTED(track) && (track->flag & (TRACK_LOCKED | TRACK_HIDDEN))==0) { - MovieTrackingMarker *marker= BKE_tracking_get_marker(track, user->framenr); + MovieTrackingMarker *marker = BKE_tracking_get_marker(track, user->framenr); - if ((marker->flag&MARKER_DISABLED)==0) + if ((marker->flag & MARKER_DISABLED) == 0) num_tracks++; } - track= track->next; + track = track->next; } if (num_tracks) { int width, height; - context->tracks_map= tracks_map_new(object->name, object->flag & TRACKING_OBJECT_CAMERA, - num_tracks, sizeof(TrackContext)); + context->tracks_map = tracks_map_new(object->name, object->flag & TRACKING_OBJECT_CAMERA, + num_tracks, sizeof(TrackContext)); BKE_movieclip_get_size(clip, user, &width, &height); /* create tracking data */ - track= tracksbase->first; + track = tracksbase->first; while (track) { - if (TRACK_SELECTED(track) && (track->flag & (TRACK_HIDDEN | TRACK_LOCKED))==0) { - MovieTrackingMarker *marker= BKE_tracking_get_marker(track, user->framenr); + if (TRACK_SELECTED(track) && (track->flag & (TRACK_HIDDEN | TRACK_LOCKED)) == 0) { + MovieTrackingMarker *marker = BKE_tracking_get_marker(track, user->framenr); - if ((marker->flag&MARKER_DISABLED)==0) { + if ((marker->flag & MARKER_DISABLED) == 0) { TrackContext track_context; memset(&track_context, 0, sizeof(TrackContext)); @@ -964,34 +984,39 @@ MovieTrackingContext *BKE_tracking_context_new(MovieClip *clip, MovieClipUser *u #ifdef WITH_LIBMV { float patx, paty; - patx= (int)((track->pat_max[0]-track->pat_min[0])*width); - paty= (int)((track->pat_max[1]-track->pat_min[1])*height); + patx = (int)((track->pat_max[0]-track->pat_min[0])*width); + paty = (int)((track->pat_max[1]-track->pat_min[1])*height); if (ELEM(track->tracker, TRACKER_KLT, TRACKER_HYBRID)) { - float search_size_x= (track->search_max[0]-track->search_min[0])*width; - float search_size_y= (track->search_max[1]-track->search_min[1])*height; - float pattern_size_x= (track->pat_max[0]-track->pat_min[0])*width; - float pattern_size_y= (track->pat_max[1]-track->pat_min[1])*height; - int wndx= (int)patx/2, wndy= (int)paty/2; + float search_size_x = (track->search_max[0]-track->search_min[0])*width; + float search_size_y = (track->search_max[1]-track->search_min[1])*height; + float pattern_size_x = (track->pat_max[0]-track->pat_min[0])*width; + float pattern_size_y = (track->pat_max[1]-track->pat_min[1])*height; + int wndx = (int)patx / 2, wndy = (int)paty / 2; + int half_wnd = MAX2(wndx, wndy); /* compute the maximum pyramid size */ - float search_to_pattern_ratio= MIN2(search_size_x, search_size_y) + float search_to_pattern_ratio = MIN2(search_size_x, search_size_y) / MAX2(pattern_size_x, pattern_size_y); float log2_search_to_pattern_ratio = log(floor(search_to_pattern_ratio)) / M_LN2; - int max_pyramid_levels= floor(log2_search_to_pattern_ratio + 1); + int max_pyramid_levels = floor(log2_search_to_pattern_ratio + 1); /* try to accommodate the user's choice of pyramid level in a way * that doesn't cause the coarsest pyramid pattern to be larger * than the search size */ - int level= MIN2(track->pyramid_levels, max_pyramid_levels); - - if (track->tracker==TRACKER_KLT) - track_context.region_tracker= libmv_pyramidRegionTrackerNew(100, level, MAX2(wndx, wndy), track->minimum_correlation); - else - track_context.region_tracker= libmv_hybridRegionTrackerNew(100, MAX2(wndx, wndy), track->minimum_correlation); + int level = MIN2(track->pyramid_levels, max_pyramid_levels); + + if (track->tracker==TRACKER_KLT) { + track_context.region_tracker = + libmv_pyramidRegionTrackerNew(100, level, half_wnd, track->minimum_correlation); + } + else { + track_context.region_tracker = + libmv_hybridRegionTrackerNew(100, half_wnd, track->minimum_correlation); + } } - else if (track->tracker==TRACKER_SAD) { - track_context.pattern_size= MAX2(patx, paty); + else if (track->tracker == TRACKER_SAD) { + track_context.pattern_size = MAX2(patx, paty); } } #endif @@ -1000,11 +1025,11 @@ MovieTrackingContext *BKE_tracking_context_new(MovieClip *clip, MovieClipUser *u } } - track= track->next; + track = track->next; } } - context->clip= clip; + context->clip = clip; /* store needed clip flags passing to get_buffer functions * - MCLIP_USE_PROXY is needed to because timecode affects on movie clip @@ -1014,11 +1039,11 @@ MovieTrackingContext *BKE_tracking_context_new(MovieClip *clip, MovieClipUser *u * - MCLIP_USE_PROXY_CUSTOM_DIR is needed because proxy/timecode files might * be stored in a different location * ignore all the rest possible flags for now */ - context->clip_flag= clip->flag&MCLIP_TIMECODE_FLAGS; + context->clip_flag = clip->flag&MCLIP_TIMECODE_FLAGS; - context->user= *user; - context->user.render_size= MCLIP_PROXY_RENDER_SIZE_FULL; - context->user.render_flag= 0; + context->user = *user; + context->user.render_size = MCLIP_PROXY_RENDER_SIZE_FULL; + context->user.render_flag = 0; if (!sequence) BLI_begin_threaded_malloc(); @@ -1028,7 +1053,7 @@ MovieTrackingContext *BKE_tracking_context_new(MovieClip *clip, MovieClipUser *u static void track_context_free(void *customdata) { - TrackContext *track_context= (TrackContext *)customdata; + TrackContext *track_context = (TrackContext *)customdata; #if WITH_LIBMV if (track_context->region_tracker) @@ -1074,17 +1099,19 @@ void BKE_tracking_disable_imbuf_channels(ImBuf *ibuf, int disable_red, int disab (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++) { - int pixel= ibuf->x*y + x; + for (y = 0; y < ibuf->y; y++) { + for (x = 0; x < ibuf->x; x++) { + int pixel = ibuf->x*y + x; if (ibuf->rect_float) { - float *rrgbf= ibuf->rect_float + pixel*4; + float *rrgbf = ibuf->rect_float + pixel*4; 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; } else { @@ -1094,12 +1121,14 @@ void BKE_tracking_disable_imbuf_channels(ImBuf *ibuf, int disable_red, int disab } } else { - char *rrgb= (char*)ibuf->rect + pixel*4; + char *rrgb = (char*)ibuf->rect + pixel*4; 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; } else { @@ -1114,12 +1143,12 @@ void BKE_tracking_disable_imbuf_channels(ImBuf *ibuf, int disable_red, int disab 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_BLUE, grayscale); + BKE_tracking_disable_imbuf_channels(ibuf, track->flag & TRACK_DISABLE_RED, + track->flag & TRACK_DISABLE_GREEN, track->flag & TRACK_DISABLE_BLUE, 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]) + float min[2], float max[2], int margin, int anchored, float pos[2], int origin[2]) { ImBuf *tmpibuf; int x, y; @@ -1133,30 +1162,30 @@ static ImBuf *get_area_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTracki if (pos) zero_v2(pos); - x= mpos[0]*ibuf->x; - y= mpos[1]*ibuf->y; + x = mpos[0]*ibuf->x; + y = mpos[1]*ibuf->y; - w= (max[0]-min[0])*ibuf->x; - h= (max[1]-min[1])*ibuf->y; + w = (max[0] - min[0]) * ibuf->x; + h = (max[1] - min[1]) * ibuf->y; /* dimensions should be odd */ - w= w|1; - h= h|1; + w = w|1; + h = h|1; - x1= x-(int)(w * (-min[0] / (max[0] - min[0]))); - y1= y-(int)(h * (-min[1] / (max[1] - min[1]))); + x1 = x-(int)(w * (-min[0] / (max[0] - min[0]))); + y1 = y-(int)(h * (-min[1] / (max[1] - min[1]))); - tmpibuf= IMB_allocImBuf(w+margin*2, h+margin*2, 32, IB_rect); - IMB_rectcpy(tmpibuf, ibuf, 0, 0, x1-margin, y1-margin, w+margin*2, h+margin*2); + tmpibuf = IMB_allocImBuf(w+margin*2, h+margin*2, 32, IB_rect); + IMB_rectcpy(tmpibuf, ibuf, 0, 0, x1 - margin, y1 - margin, w + margin * 2, h + margin * 2); if (pos != NULL) { - pos[0]= mpos[0]*ibuf->x-x1+margin; - pos[1]= mpos[1]*ibuf->y-y1+margin; + pos[0] = mpos[0] * ibuf->x - x1 + margin; + pos[1] = mpos[1] * ibuf->y - y1 + margin; } if (origin != NULL) { - origin[0]= x1-margin; - origin[1]= y1-margin; + origin[0] = x1 - margin; + origin[1] = y1 - margin; } if ((track->flag & TRACK_PREVIEW_GRAYSCALE) || @@ -1164,54 +1193,57 @@ static ImBuf *get_area_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTracki (track->flag & TRACK_DISABLE_GREEN) || (track->flag & TRACK_DISABLE_BLUE)) { - disable_imbuf_channels(tmpibuf, track, 1 /* grayscale */); + disable_imbuf_channels(tmpibuf, track, TRUE /* grayscale */); } return tmpibuf; } ImBuf *BKE_tracking_get_pattern_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker, - int margin, int anchored, float pos[2], int origin[2]) + int margin, int anchored, float pos[2], int origin[2]) { return get_area_imbuf(ibuf, track, marker, track->pat_min, track->pat_max, margin, anchored, pos, origin); } ImBuf *BKE_tracking_get_search_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker, - int margin, int anchored, float pos[2], int origin[2]) + int margin, int anchored, float pos[2], int origin[2]) { return get_area_imbuf(ibuf, track, marker, track->search_min, track->search_max, margin, anchored, pos, origin); } #ifdef WITH_LIBMV static float *get_search_floatbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker, - int *width_r, int *height_r, float pos[2], int origin[2]) + int *width_r, int *height_r, float pos[2], int origin[2]) { ImBuf *tmpibuf; float *pixels, *fp; int x, y, width, height; - width= (track->search_max[0]-track->search_min[0])*ibuf->x; - height= (track->search_max[1]-track->search_min[1])*ibuf->y; + width = (track->search_max[0] - track->search_min[0]) * ibuf->x; + height = (track->search_max[1] - track->search_min[1]) * ibuf->y; - tmpibuf= BKE_tracking_get_search_imbuf(ibuf, track, marker, 0, 0, pos, origin); - disable_imbuf_channels(tmpibuf, track, 0 /* don't grayscale */); + tmpibuf = BKE_tracking_get_search_imbuf(ibuf, track, marker, 0, 0, pos, origin); + disable_imbuf_channels(tmpibuf, track, FALSE /* don't grayscale */); - *width_r= width; - *height_r= height; + *width_r = width; + *height_r = height; - fp= pixels= MEM_callocN(width*height*sizeof(float), "tracking floatBuf"); - for (y= 0; y<(int)height; y++) { - for (x= 0; x<(int)width; x++) { - int pixel= tmpibuf->x*y + x; + fp = pixels = MEM_callocN(width * height * sizeof(float), "tracking floatBuf"); + for (y = 0; y < (int)height; y++) { + for (x = 0; x < (int)width; x++) { + int pixel = tmpibuf->x * y + x; if (tmpibuf->rect_float) { - float *rrgbf= tmpibuf->rect_float + pixel*4; - *fp= 0.2126*rrgbf[0] + 0.7152*rrgbf[1] + 0.0722*rrgbf[2]; + float *rrgbf = tmpibuf->rect_float + pixel * 4; + + *fp = 0.2126 * rrgbf[0] + 0.7152 * rrgbf[1] + 0.0722 * rrgbf[2]; } else { - unsigned char *rrgb= (unsigned char*)tmpibuf->rect + pixel*4; - *fp= (0.2126*rrgb[0] + 0.7152*rrgb[1] + 0.0722*rrgb[2])/255.0f; + unsigned char *rrgb = (unsigned char*)tmpibuf->rect + pixel * 4; + + *fp = (0.2126 * rrgb[0] + 0.7152 * rrgb[1] + 0.0722 * rrgb[2]) / 255.0f; } + fp++; } } @@ -1226,20 +1258,23 @@ static unsigned char *get_ucharbuf(ImBuf *ibuf) int x, y; unsigned char *pixels, *cp; - cp= pixels= MEM_callocN(ibuf->x*ibuf->y*sizeof(unsigned char), "tracking ucharBuf"); - for (y= 0; y<ibuf->y; y++) { - for (x= 0; x<ibuf->x; x++) { - int pixel= ibuf->x*y + x; + cp = pixels = MEM_callocN(ibuf->x * ibuf->y * sizeof(unsigned char), "tracking ucharBuf"); + for (y = 0; y < ibuf->y; y++) { + for (x = 0; x < ibuf->x; x++) { + int pixel = ibuf->x * y + x; if (ibuf->rect_float) { - const float *rrgbf= ibuf->rect_float + pixel*4; - const float grey_f= 0.2126f*rrgbf[0] + 0.7152f*rrgbf[1] + 0.0722f*rrgbf[2]; - *cp= FTOCHAR(grey_f); + const float *rrgbf = ibuf->rect_float + pixel*4; + const float grey_f = 0.2126f * rrgbf[0] + 0.7152f * rrgbf[1] + 0.0722f * rrgbf[2]; + + *cp = FTOCHAR(grey_f); } else { - const unsigned char *rrgb= (unsigned char*)ibuf->rect + pixel*4; - *cp= 0.2126f*rrgb[0] + 0.7152f*rrgb[1] + 0.0722f*rrgb[2]; + const unsigned char *rrgb = (unsigned char*)ibuf->rect + pixel * 4; + + *cp = 0.2126f * rrgb[0] + 0.7152f * rrgb[1] + 0.0722f * rrgb[2]; } + cp++; } } @@ -1248,18 +1283,18 @@ static unsigned char *get_ucharbuf(ImBuf *ibuf) } static unsigned char *get_search_bytebuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker, - int *width_r, int *height_r, float pos[2], int origin[2]) + int *width_r, int *height_r, float pos[2], int origin[2]) { ImBuf *tmpibuf; unsigned char *pixels; - tmpibuf= BKE_tracking_get_search_imbuf(ibuf, track, marker, 0, 0, pos, origin); - disable_imbuf_channels(tmpibuf, track, 0 /* don't grayscale */); + tmpibuf = BKE_tracking_get_search_imbuf(ibuf, track, marker, 0, 0, pos, origin); + disable_imbuf_channels(tmpibuf, track, FALSE /* don't grayscale */); - *width_r= tmpibuf->x; - *height_r= tmpibuf->y; + *width_r = tmpibuf->x; + *height_r = tmpibuf->y; - pixels= get_ucharbuf(tmpibuf); + pixels = get_ucharbuf(tmpibuf); IMB_freeImBuf(tmpibuf); @@ -1269,63 +1304,64 @@ static unsigned char *get_search_bytebuf(ImBuf *ibuf, MovieTrackingTrack *track, static ImBuf *get_frame_ibuf(MovieTrackingContext *context, int framenr) { ImBuf *ibuf; - MovieClipUser user= context->user; + MovieClipUser user = context->user; - user.framenr= framenr; + user.framenr = framenr; - ibuf= BKE_movieclip_get_ibuf_flag(context->clip, &user, context->clip_flag, MOVIECLIP_CACHE_SKIP); + ibuf = BKE_movieclip_get_ibuf_flag(context->clip, &user, context->clip_flag, MOVIECLIP_CACHE_SKIP); return ibuf; } static ImBuf *get_keyframed_ibuf(MovieTrackingContext *context, MovieTrackingTrack *track, - MovieTrackingMarker *marker, MovieTrackingMarker **marker_keyed) + MovieTrackingMarker *marker, MovieTrackingMarker **marker_keyed) { - int framenr= marker->framenr; - int a= marker-track->markers; + int framenr = marker->framenr; + int a = marker-track->markers; - *marker_keyed= marker; + *marker_keyed = marker; - while (a>=0 && a<track->markersnr) { - int next= (context->backwards) ? a+1 : a-1; - int is_keyframed= 0; - MovieTrackingMarker *cur_marker= &track->markers[a]; - MovieTrackingMarker *next_marker= NULL; + while (a >= 0 && a < track->markersnr) { + int next = (context->backwards) ? a+1 : a-1; + int is_keyframed = FALSE; + MovieTrackingMarker *cur_marker = &track->markers[a]; + MovieTrackingMarker *next_marker = NULL; if (next>=0 && next<track->markersnr) next_marker= &track->markers[next]; /* if next mrker is disabled, stop searching keyframe and use current frame as keyframe */ - if (next_marker && next_marker->flag&MARKER_DISABLED) - is_keyframed= 1; + if (next_marker && next_marker->flag & MARKER_DISABLED) + is_keyframed = TRUE; - is_keyframed|= (cur_marker->flag&MARKER_TRACKED)==0; + is_keyframed |= (cur_marker->flag & MARKER_TRACKED) == 0; if (is_keyframed) { - framenr= cur_marker->framenr; - *marker_keyed= cur_marker; + framenr = cur_marker->framenr; + *marker_keyed = cur_marker; + break; } - a= next; + a = next; } return get_frame_ibuf(context, framenr); } static ImBuf *get_adjust_ibuf(MovieTrackingContext *context, MovieTrackingTrack *track, MovieTrackingMarker *marker, - int curfra, MovieTrackingMarker **marker_keyed) + int curfra, MovieTrackingMarker **marker_keyed) { - ImBuf *ibuf= NULL; + ImBuf *ibuf = NULL; if (track->pattern_match == TRACK_MATCH_KEYFRAME) { - ibuf= get_keyframed_ibuf(context, track, marker, marker_keyed); + ibuf = get_keyframed_ibuf(context, track, marker, marker_keyed); } else { - ibuf= get_frame_ibuf(context, curfra); + ibuf = get_frame_ibuf(context, curfra); /* use current marker as keyframed position */ - *marker_keyed= marker; + *marker_keyed = marker; } return ibuf; @@ -1335,10 +1371,10 @@ static void get_warped(TrackContext *track_context, int x, int y, int width, uns { int i, j; - for (i=0; i<track_context->pattern_size; i++) { - for (j=0; j<track_context->pattern_size; j++) { - track_context->warped[i*track_context->pattern_size+j]= - image[(y+i-track_context->pattern_size/2)*width+x+j-track_context->pattern_size/2]; + for (i = 0; i < track_context->pattern_size; i++) { + for (j = 0; j < track_context->pattern_size; j++) { + track_context->warped[i * track_context->pattern_size + j] = + image[(y + i - track_context->pattern_size / 2) * width + x + j - track_context->pattern_size / 2]; } } } @@ -1347,130 +1383,139 @@ static void get_warped(TrackContext *track_context, int x, int y, int width, uns void BKE_tracking_sync(MovieTrackingContext *context) { - MovieTracking *tracking= &context->clip->tracking; + MovieTracking *tracking = &context->clip->tracking; int newframe; tracks_map_merge(context->tracks_map, tracking); - if (context->backwards) newframe= context->user.framenr+1; - else newframe= context->user.framenr-1; + if (context->backwards) + newframe = context->user.framenr + 1; + else + newframe = context->user.framenr - 1; - context->sync_frame= newframe; + context->sync_frame = newframe; } void BKE_tracking_sync_user(MovieClipUser *user, MovieTrackingContext *context) { - user->framenr= context->sync_frame; + user->framenr = context->sync_frame; } int BKE_tracking_next(MovieTrackingContext *context) { ImBuf *ibuf_new; - int curfra= context->user.framenr; - int a, ok= 0, map_size; + int curfra = context->user.framenr; + int a, ok = FALSE, map_size; - map_size= tracks_map_size(context->tracks_map); + map_size = tracks_map_size(context->tracks_map); /* nothing to track, avoid unneeded frames reading to save time and memory */ if (!map_size) - return 0; + return FALSE; - if (context->backwards) context->user.framenr--; - else context->user.framenr++; + if (context->backwards) + context->user.framenr--; + else + context->user.framenr++; - ibuf_new= BKE_movieclip_get_ibuf_flag(context->clip, &context->user, context->clip_flag, MOVIECLIP_CACHE_SKIP); + ibuf_new = BKE_movieclip_get_ibuf_flag(context->clip, &context->user, context->clip_flag, MOVIECLIP_CACHE_SKIP); if (!ibuf_new) - return 0; + return FALSE; #pragma omp parallel for private(a) shared(ibuf_new, ok) if (map_size>1) - for (a= 0; a<map_size; a++) { + for (a = 0; a < map_size; a++) { TrackContext *track_context = NULL; MovieTrackingTrack *track; MovieTrackingMarker *marker; tracks_map_get(context->tracks_map, a, &track, (void**)&track_context); - marker= BKE_tracking_exact_marker(track, curfra); + marker = BKE_tracking_exact_marker(track, curfra); - if (marker && (marker->flag&MARKER_DISABLED)==0) { + if (marker && (marker->flag & MARKER_DISABLED) == 0) { #ifdef WITH_LIBMV - int width, height, origin[2], tracked= 0, need_readjust= 0; + int width, height, origin[2], tracked = 0, need_readjust = 0; float pos[2], margin[2], dim[2]; double x1, y1, x2, y2; - ImBuf *ibuf= NULL; + ImBuf *ibuf = NULL; MovieTrackingMarker marker_new, *marker_keyed; - int onbound= 0, nextfra; + int onbound = FALSE, nextfra; - if (track->pattern_match==TRACK_MATCH_KEYFRAME) - need_readjust= context->first_time; + if (track->pattern_match == TRACK_MATCH_KEYFRAME) + need_readjust = context->first_time; else - need_readjust= 1; + need_readjust = TRUE; - if (context->backwards) nextfra= curfra-1; - else nextfra= curfra+1; + if (context->backwards) + nextfra = curfra - 1; + else + nextfra = curfra + 1; /* margin from frame boundaries */ sub_v2_v2v2(dim, track->pat_max, track->pat_min); - margin[0]= margin[1]= MAX2(dim[0], dim[1]) / 2.0f; + margin[0] = margin[1] = MAX2(dim[0], dim[1]) / 2.0f; - margin[0]= MAX2(margin[0], (float)track->margin / ibuf_new->x); - margin[1]= MAX2(margin[1], (float)track->margin / ibuf_new->y); + margin[0] = MAX2(margin[0], (float)track->margin / ibuf_new->x); + margin[1] = MAX2(margin[1], (float)track->margin / ibuf_new->y); /* do not track markers which are too close to boundary */ if (marker->pos[0]<margin[0] || marker->pos[0]>1.0f-margin[0] || - marker->pos[1]<margin[1] || marker->pos[1]>1.0f-margin[1]) { - onbound= 1; + marker->pos[1]<margin[1] || marker->pos[1]>1.0f-margin[1]) + { + onbound = TRUE; } else if (ELEM(track->tracker, TRACKER_KLT, TRACKER_HYBRID)) { float *patch_new; if (need_readjust) { /* calculate patch for keyframed position */ - ibuf= get_adjust_ibuf(context, track, marker, curfra, &marker_keyed); + ibuf = get_adjust_ibuf(context, track, marker, curfra, &marker_keyed); if (track_context->patch) MEM_freeN(track_context->patch); - track_context->patch= get_search_floatbuf(ibuf, track, marker_keyed, &width, &height, track_context->keyframed_pos, origin); + track_context->patch = get_search_floatbuf(ibuf, track, marker_keyed, &width, &height, + track_context->keyframed_pos, origin); IMB_freeImBuf(ibuf); } - patch_new= get_search_floatbuf(ibuf_new, track, marker, &width, &height, pos, origin); + patch_new = get_search_floatbuf(ibuf_new, track, marker, &width, &height, pos, origin); - x1= track_context->keyframed_pos[0]; - y1= track_context->keyframed_pos[1]; + x1 = track_context->keyframed_pos[0]; + y1 = track_context->keyframed_pos[1]; - x2= pos[0]; - y2= pos[1]; + x2 = pos[0]; + y2 = pos[1]; - tracked= libmv_regionTrackerTrack(track_context->region_tracker, track_context->patch, patch_new, + tracked = libmv_regionTrackerTrack(track_context->region_tracker, track_context->patch, patch_new, width, height, x1, y1, &x2, &y2); MEM_freeN(patch_new); } - else if (track->tracker==TRACKER_SAD) { + else if (track->tracker == TRACKER_SAD) { unsigned char *image_new; float correlation; - float warp[3][2]={{0}}; + float warp[3][2] = {{0}}; if (need_readjust) { unsigned char *image; /* calculate pattern for keyframed position */ - ibuf= get_adjust_ibuf(context, track, marker, curfra, &marker_keyed); + ibuf = get_adjust_ibuf(context, track, marker, curfra, &marker_keyed); - image= get_search_bytebuf(ibuf, track, marker_keyed, &width, &height, pos, origin); + image = get_search_bytebuf(ibuf, track, marker_keyed, &width, &height, pos, origin); memset(warp, 0, sizeof(warp)); - warp[0][0]= 1; - warp[1][1]= 1; - warp[2][0]= pos[0]; - warp[2][1]= pos[1]; + warp[0][0] = 1; + warp[1][1] = 1; + warp[2][0] = pos[0]; + warp[2][1] = pos[1]; if (!track_context->pattern) { - int square= track_context->pattern_size*track_context->pattern_size; - track_context->pattern= MEM_callocN(sizeof(unsigned char)*square, "trackking pattern"); + int square = track_context->pattern_size*track_context->pattern_size; + + track_context->pattern = MEM_callocN(sizeof(unsigned char) * square, "trackking pattern"); } libmv_SADSamplePattern(image, width, warp, track_context->pattern, track_context->pattern_size); @@ -1479,37 +1524,39 @@ int BKE_tracking_next(MovieTrackingContext *context) IMB_freeImBuf(ibuf); } - image_new= get_search_bytebuf(ibuf_new, track, marker, &width, &height, pos, origin); + image_new = get_search_bytebuf(ibuf_new, track, marker, &width, &height, pos, origin); - if (track_context->warped==NULL) { + if (track_context->warped == NULL) { unsigned char *image_old; - ibuf= get_frame_ibuf(context, curfra); + ibuf = get_frame_ibuf(context, curfra); - if (track_context->warped==NULL) { - int square= track_context->pattern_size*track_context->pattern_size; - track_context->warped= MEM_callocN(sizeof(unsigned char)*square, "trackking warped"); + if (track_context->warped == NULL) { + int square = track_context->pattern_size * track_context->pattern_size; + + track_context->warped = MEM_callocN(sizeof(unsigned char)*square, "trackking warped"); } - image_old= get_search_bytebuf(ibuf, track, marker, &width, &height, pos, origin); + image_old = get_search_bytebuf(ibuf, track, marker, &width, &height, pos, origin); get_warped(track_context, pos[0], pos[1], width, image_old); IMB_freeImBuf(ibuf); MEM_freeN(image_old); } memset(warp, 0, sizeof(warp)); - warp[0][0]= 1; - warp[1][1]= 1; - warp[2][0]= pos[0]; - warp[2][1]= pos[1]; + warp[0][0] = 1; + warp[1][1] = 1; + warp[2][0] = pos[0]; + warp[2][1] = pos[1]; - correlation= libmv_SADTrackerTrack(track_context->pattern, track_context->warped, - track_context->pattern_size, image_new, width, width, height, warp); + correlation = libmv_SADTrackerTrack(track_context->pattern, track_context->warped, + track_context->pattern_size, image_new, + width, width, height, warp); - x2= warp[2][0]; - y2= warp[2][1]; + x2 = warp[2][0]; + y2 = warp[2][1]; - tracked= track->minimum_correlation < correlation; + tracked = track->minimum_correlation < correlation; if (tracked) get_warped(track_context, x2, y2, width, image_new); @@ -1530,14 +1577,14 @@ int BKE_tracking_next(MovieTrackingContext *context) memset(&marker_new, 0, sizeof(marker_new)); if (!onbound) { - marker_new.pos[0]= (origin[0]+x2)/ibuf_new->x; - marker_new.pos[1]= (origin[1]+y2)/ibuf_new->y; + marker_new.pos[0] = (origin[0] + x2) / ibuf_new->x; + marker_new.pos[1] = (origin[1] + y2) / ibuf_new->y; } else { copy_v2_v2(marker_new.pos, marker->pos); } - marker_new.flag|= MARKER_TRACKED; + marker_new.flag |= MARKER_TRACKED; marker_new.framenr= nextfra; #pragma omp critical @@ -1552,10 +1599,10 @@ int BKE_tracking_next(MovieTrackingContext *context) } } else { - marker_new= *marker; + marker_new = *marker; - marker_new.framenr= nextfra; - marker_new.flag|= MARKER_DISABLED; + marker_new.framenr = nextfra; + marker_new.flag |= MARKER_DISABLED; #pragma omp critical { @@ -1563,14 +1610,14 @@ int BKE_tracking_next(MovieTrackingContext *context) } } - ok= 1; + ok = TRUE; #endif } } IMB_freeImBuf(ibuf_new); - context->first_time= 0; + context->first_time = FALSE; context->frames++; return ok; @@ -1611,23 +1658,24 @@ typedef struct ReconstructProgressData { #if WITH_LIBMV static struct libmv_Tracks *create_libmv_tracks(ListBase *tracksbase, int width, int height) { - int tracknr= 0; + int tracknr = 0; MovieTrackingTrack *track; - struct libmv_Tracks *tracks= libmv_tracksNew(); + struct libmv_Tracks *tracks = libmv_tracksNew(); - track= tracksbase->first; + track = tracksbase->first; while (track) { - int a= 0; + int a = 0; - for (a= 0; a<track->markersnr; a++) { - MovieTrackingMarker *marker= &track->markers[a]; + for (a = 0; a < track->markersnr; a++) { + MovieTrackingMarker *marker = &track->markers[a]; - if ((marker->flag&MARKER_DISABLED)==0) + if ((marker->flag & MARKER_DISABLED) == 0) { libmv_tracksInsert(tracks, marker->framenr, tracknr, - marker->pos[0]*width, marker->pos[1]*height); + marker->pos[0] * width, marker->pos[1] * height); + } } - track= track->next; + track = track->next; tracknr++; } @@ -1636,124 +1684,123 @@ static struct libmv_Tracks *create_libmv_tracks(ListBase *tracksbase, int width, static void retrieve_libmv_reconstruct_intrinscis(MovieReconstructContext *context, MovieTracking *tracking) { - struct libmv_Reconstruction *libmv_reconstruction= context->reconstruction; + struct libmv_Reconstruction *libmv_reconstruction = context->reconstruction; struct libmv_CameraIntrinsics *libmv_intrinsics = libmv_ReconstructionExtractIntrinsics(libmv_reconstruction); - float aspy= 1.0f/tracking->camera.pixel_aspect; + float aspy = 1.0f / tracking->camera.pixel_aspect; double focal_length, principal_x, principal_y, k1, k2, k3; int width, height; libmv_CameraIntrinsicsExtract(libmv_intrinsics, &focal_length, &principal_x, &principal_y, - &k1, &k2, &k3, &width, &height); + &k1, &k2, &k3, &width, &height); - tracking->camera.focal= focal_length; - tracking->camera.principal[0]= principal_x; + tracking->camera.focal = focal_length; + tracking->camera.principal[0] = principal_x; - /* todo: verify divide by aspy is correct */ - tracking->camera.principal[1]= principal_y / aspy; - tracking->camera.k1= k1; - tracking->camera.k2= k2; + tracking->camera.principal[1] = principal_y / aspy; + tracking->camera.k1 = k1; + tracking->camera.k2 = k2; } static int retrieve_libmv_reconstruct_tracks(MovieReconstructContext *context, MovieTracking *tracking) { - struct libmv_Reconstruction *libmv_reconstruction= context->reconstruction; - MovieTrackingReconstruction *reconstruction= NULL; + struct libmv_Reconstruction *libmv_reconstruction = context->reconstruction; + MovieTrackingReconstruction *reconstruction = NULL; MovieReconstructedCamera *reconstructed; MovieTrackingTrack *track; - ListBase *tracksbase= NULL; - int ok= 1, tracknr= 0, a, origin_set= 0; - int sfra= context->sfra, efra= context->efra; + ListBase *tracksbase = NULL; + int ok = TRUE, tracknr = 0, a, origin_set = FALSE; + int sfra = context->sfra, efra = context->efra; float imat[4][4]; if (context->is_camera) { - tracksbase= &tracking->tracks; - reconstruction= &tracking->reconstruction; + tracksbase = &tracking->tracks; + reconstruction = &tracking->reconstruction; } else { - MovieTrackingObject *object= BKE_tracking_named_object(tracking, context->object_name); + MovieTrackingObject *object = BKE_tracking_named_object(tracking, context->object_name); - tracksbase= &object->tracks; - reconstruction= &object->reconstruction; + tracksbase = &object->tracks; + reconstruction = &object->reconstruction; } unit_m4(imat); - track= tracksbase->first; + track = tracksbase->first; while (track) { double pos[3]; if (libmv_reporojectionPointForTrack(libmv_reconstruction, tracknr, pos)) { - track->bundle_pos[0]= pos[0]; - track->bundle_pos[1]= pos[1]; - track->bundle_pos[2]= pos[2]; + track->bundle_pos[0] = pos[0]; + track->bundle_pos[1] = pos[1]; + track->bundle_pos[2] = pos[2]; - track->flag|= TRACK_HAS_BUNDLE; - track->error= libmv_reporojectionErrorForTrack(libmv_reconstruction, tracknr); + track->flag |= TRACK_HAS_BUNDLE; + track->error = libmv_reporojectionErrorForTrack(libmv_reconstruction, tracknr); } else { - track->flag&= ~TRACK_HAS_BUNDLE; - ok= 0; + track->flag &= ~TRACK_HAS_BUNDLE; + ok = FALSE; printf("No bundle for track #%d '%s'\n", tracknr, track->name); } - track= track->next; + track = track->next; tracknr++; } if (reconstruction->cameras) MEM_freeN(reconstruction->cameras); - reconstruction->camnr= 0; - reconstruction->cameras= NULL; - reconstructed= MEM_callocN((efra-sfra+1)*sizeof(MovieReconstructedCamera), "temp reconstructed camera"); + reconstruction->camnr = 0; + reconstruction->cameras = NULL; + reconstructed = MEM_callocN((efra-sfra+1)*sizeof(MovieReconstructedCamera), "temp reconstructed camera"); - for (a= sfra; a<=efra; a++) { + for (a = sfra; a <= efra; a++) { double matd[4][4]; if (libmv_reporojectionCameraForImage(libmv_reconstruction, a, matd)) { int i, j; float mat[4][4]; - float error= libmv_reporojectionErrorForImage(libmv_reconstruction, a); + float error = libmv_reporojectionErrorForImage(libmv_reconstruction, a); - for (i=0; i<4; i++) - for (j= 0; j<4; j++) - mat[i][j]= matd[i][j]; + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + mat[i][j] = matd[i][j]; if (!origin_set) { copy_m4_m4(imat, mat); invert_m4(imat); - origin_set= 1; + origin_set = TRUE; } if (origin_set) mult_m4_m4m4(mat, imat, mat); copy_m4_m4(reconstructed[reconstruction->camnr].mat, mat); - reconstructed[reconstruction->camnr].framenr= a; - reconstructed[reconstruction->camnr].error= error; + reconstructed[reconstruction->camnr].framenr = a; + reconstructed[reconstruction->camnr].error = error; reconstruction->camnr++; } else { - ok= 0; + ok = FALSE; printf("No camera for frame %d\n", a); } } if (reconstruction->camnr) { - reconstruction->cameras= MEM_callocN(reconstruction->camnr*sizeof(MovieReconstructedCamera), "reconstructed camera"); - memcpy(reconstruction->cameras, reconstructed, reconstruction->camnr*sizeof(MovieReconstructedCamera)); + reconstruction->cameras = MEM_callocN(reconstruction->camnr * sizeof(MovieReconstructedCamera), "reconstructed camera"); + memcpy(reconstruction->cameras, reconstructed, reconstruction->camnr * sizeof(MovieReconstructedCamera)); } if (origin_set) { - track= tracksbase->first; + track = tracksbase->first; while (track) { - if (track->flag&TRACK_HAS_BUNDLE) + if (track->flag & TRACK_HAS_BUNDLE) mul_v3_m4v3(track->bundle_pos, imat, track->bundle_pos); - track= track->next; + track = track->next; } } @@ -1772,40 +1819,40 @@ static int retrieve_libmv_reconstruct(MovieReconstructContext *context, MovieTra static int get_refine_intrinsics_flags(MovieTracking *tracking, MovieTrackingObject *object) { - int refine= tracking->settings.refine_camera_intrinsics; - int flags= 0; + int refine = tracking->settings.refine_camera_intrinsics; + int flags = 0; - if ((object->flag&TRACKING_OBJECT_CAMERA)==0) + if ((object->flag & TRACKING_OBJECT_CAMERA) == 0) return 0; - if (refine&REFINE_FOCAL_LENGTH) - flags|= LIBMV_REFINE_FOCAL_LENGTH; + if (refine & REFINE_FOCAL_LENGTH) + flags |= LIBMV_REFINE_FOCAL_LENGTH; - if (refine&REFINE_PRINCIPAL_POINT) - flags|= LIBMV_REFINE_PRINCIPAL_POINT; + if (refine & REFINE_PRINCIPAL_POINT) + flags |= LIBMV_REFINE_PRINCIPAL_POINT; - if (refine&REFINE_RADIAL_DISTORTION_K1) - flags|= REFINE_RADIAL_DISTORTION_K1; + if (refine & REFINE_RADIAL_DISTORTION_K1) + flags |= REFINE_RADIAL_DISTORTION_K1; - if (refine&REFINE_RADIAL_DISTORTION_K2) - flags|= REFINE_RADIAL_DISTORTION_K2; + if (refine & REFINE_RADIAL_DISTORTION_K2) + flags |= REFINE_RADIAL_DISTORTION_K2; return flags; } static int count_tracks_on_both_keyframes(MovieTracking *tracking, ListBase *tracksbase) { - int tot= 0; - int frame1= tracking->settings.keyframe1, frame2= tracking->settings.keyframe2; + int tot = 0; + int frame1 = tracking->settings.keyframe1, frame2= tracking->settings.keyframe2; MovieTrackingTrack *track; - track= tracksbase->first; + track = tracksbase->first; while (track) { if (BKE_tracking_has_enabled_marker(track, frame1)) if (BKE_tracking_has_enabled_marker(track, frame2)) tot++; - track= track->next; + track = track->next; } return tot; @@ -1815,76 +1862,78 @@ static int count_tracks_on_both_keyframes(MovieTracking *tracking, ListBase *tra int BKE_tracking_can_reconstruct(MovieTracking *tracking, MovieTrackingObject *object, char *error_msg, int error_size) { #if WITH_LIBMV - ListBase *tracksbase= BKE_tracking_object_tracks(tracking, object); + ListBase *tracksbase = BKE_tracking_object_tracks(tracking, object); if (count_tracks_on_both_keyframes(tracking, tracksbase)<8) { BLI_strncpy(error_msg, "At least 8 common tracks on both of keyframes are needed for reconstruction", error_size); - return 0; + + return FALSE; } - return 1; + return TRUE; #else BLI_strncpy(error_msg, "Blender is compiled without motion tracking library", error_size); - (void)tracking; - (void)object; + + (void) tracking; + (void) object; return 0; #endif } -MovieReconstructContext* BKE_tracking_reconstruction_context_new(MovieTracking *tracking, - MovieTrackingObject *object, int keyframe1, int keyframe2, int width, int height) +MovieReconstructContext* BKE_tracking_reconstruction_context_new(MovieTracking *tracking, MovieTrackingObject *object, + int keyframe1, int keyframe2, int width, int height) { - MovieReconstructContext *context= MEM_callocN(sizeof(MovieReconstructContext), "MovieReconstructContext data"); - MovieTrackingCamera *camera= &tracking->camera; - ListBase *tracksbase= BKE_tracking_object_tracks(tracking, object); - float aspy= 1.0f/tracking->camera.pixel_aspect; - int num_tracks= BLI_countlist(tracksbase); - int sfra= INT_MAX, efra= INT_MIN; + MovieReconstructContext *context = MEM_callocN(sizeof(MovieReconstructContext), "MovieReconstructContext data"); + MovieTrackingCamera *camera = &tracking->camera; + ListBase *tracksbase = BKE_tracking_object_tracks(tracking, object); + float aspy = 1.0f / tracking->camera.pixel_aspect; + int num_tracks = BLI_countlist(tracksbase); + int sfra = INT_MAX, efra = INT_MIN; MovieTrackingTrack *track; BLI_strncpy(context->object_name, object->name, sizeof(context->object_name)); context->is_camera = object->flag&TRACKING_OBJECT_CAMERA; - context->tracks_map= tracks_map_new(context->object_name, context->is_camera, num_tracks, 0); + context->tracks_map = tracks_map_new(context->object_name, context->is_camera, num_tracks, 0); - track= tracksbase->first; + track = tracksbase->first; while (track) { - int first= 0, last= track->markersnr-1; - MovieTrackingMarker *first_marker= &track->markers[0]; - MovieTrackingMarker *last_marker= &track->markers[track->markersnr-1]; + int first = 0, last = track->markersnr-1; + MovieTrackingMarker *first_marker = &track->markers[0]; + MovieTrackingMarker *last_marker = &track->markers[track->markersnr - 1]; /* find first not-disabled marker */ - while (first<=track->markersnr-1 && first_marker->flag&MARKER_DISABLED) { + while (first <= track->markersnr - 1 && first_marker->flag & MARKER_DISABLED) { first++; first_marker++; } /* find last not-disabled marker */ - while (last>=0 && last_marker->flag&MARKER_DISABLED) { + while (last >= 0 && last_marker->flag & MARKER_DISABLED) { last--; last_marker--; } - if (first<track->markersnr-1) - sfra= MIN2(sfra, first_marker->framenr); + if (first<track->markersnr - 1) + sfra = MIN2(sfra, first_marker->framenr); - if (last>=0) - efra= MAX2(efra, last_marker->framenr); + if (last >= 0) + efra = MAX2(efra, last_marker->framenr); tracks_map_insert(context->tracks_map, track, NULL); - track= track->next; + track = track->next; } - context->sfra= sfra; - context->efra= efra; + context->sfra = sfra; + context->efra = efra; #ifdef WITH_LIBMV - context->tracks= create_libmv_tracks(tracksbase, width, height*aspy); - context->keyframe1= keyframe1; - context->keyframe2= keyframe2; - context->refine_flags= get_refine_intrinsics_flags(tracking, object); + context->tracks = create_libmv_tracks(tracksbase, width, height*aspy); + context->keyframe1 = keyframe1; + context->keyframe2 = keyframe2; + context->refine_flags = get_refine_intrinsics_flags(tracking, object); #else (void) width; (void) height; @@ -1892,13 +1941,13 @@ MovieReconstructContext* BKE_tracking_reconstruction_context_new(MovieTracking * (void) keyframe2; #endif - context->focal_length= camera->focal; - context->principal_point[0]= camera->principal[0]; - context->principal_point[1]= camera->principal[1]*aspy; + context->focal_length = camera->focal; + context->principal_point[0] = camera->principal[0]; + context->principal_point[1] = camera->principal[1] * aspy; - context->k1= camera->k1; - context->k2= camera->k2; - context->k3= camera->k3; + context->k1 = camera->k1; + context->k2 = camera->k2; + context->k3 = camera->k3; return context; } @@ -1923,40 +1972,39 @@ static void solve_reconstruction_update_cb(void *customdata, double progress, co ReconstructProgressData *progressdata= customdata; if (progressdata->progress) { - *progressdata->progress= progress; - *progressdata->do_update= 1; + *progressdata->progress = progress; + *progressdata->do_update = TRUE; } - BLI_snprintf(progressdata->stats_message, progressdata->message_size, - "Solving camera | %s", message); + BLI_snprintf(progressdata->stats_message, progressdata->message_size, "Solving camera | %s", message); } #endif #if 0 static int solve_reconstruction_testbreak_cb(void *customdata) { - ReconstructProgressData *progressdata= customdata; + ReconstructProgressData *progressdata = customdata; if (progressdata->stop && *progressdata->stop) - return 1; + return TRUE; return G.afbreek; } #endif -void BKE_tracking_solve_reconstruction(MovieReconstructContext *context, short *stop, - short *do_update, float *progress, char *stats_message, int message_size) +void BKE_tracking_solve_reconstruction(MovieReconstructContext *context, short *stop, short *do_update, + float *progress, char *stats_message, int message_size) { #ifdef WITH_LIBMV float error; ReconstructProgressData progressdata; - progressdata.stop= stop; - progressdata.do_update= do_update; - progressdata.progress= progress; - progressdata.stats_message= stats_message; - progressdata.message_size= message_size; + progressdata.stop = stop; + progressdata.do_update = do_update; + progressdata.progress = progress; + progressdata.stats_message = stats_message; + progressdata.message_size = message_size; context->reconstruction = libmv_solveReconstruction(context->tracks, context->keyframe1, context->keyframe2, @@ -1966,9 +2014,9 @@ void BKE_tracking_solve_reconstruction(MovieReconstructContext *context, short * context->k1, context->k2, context->k3, solve_reconstruction_update_cb, &progressdata); - error= libmv_reprojectionError(context->reconstruction); + error = libmv_reprojectionError(context->reconstruction); - context->reprojection_error= error; + context->reprojection_error = error; #else (void) context; (void) stop; @@ -1986,24 +2034,24 @@ int BKE_tracking_finish_reconstruction(MovieReconstructContext *context, MovieTr tracks_map_merge(context->tracks_map, tracking); if (context->is_camera) { - reconstruction= &tracking->reconstruction; + reconstruction = &tracking->reconstruction; } else { MovieTrackingObject *object; - object= BKE_tracking_named_object(tracking, context->object_name); - reconstruction= &object->reconstruction; + object = BKE_tracking_named_object(tracking, context->object_name); + reconstruction = &object->reconstruction; } - reconstruction->error= context->reprojection_error; - reconstruction->flag|= TRACKING_RECONSTRUCTED; + reconstruction->error = context->reprojection_error; + reconstruction->flag |= TRACKING_RECONSTRUCTED; #ifdef WITH_LIBMV if (!retrieve_libmv_reconstruct(context, tracking)) - return 0; + return FALSE; #endif - return 1; + return TRUE; } void BKE_track_unique_name(ListBase *tracksbase, MovieTrackingTrack *track) @@ -2013,14 +2061,14 @@ void BKE_track_unique_name(ListBase *tracksbase, MovieTrackingTrack *track) MovieTrackingTrack *BKE_tracking_named_track(MovieTracking *tracking, MovieTrackingObject *object, const char *name) { - ListBase *tracksbase= BKE_tracking_object_tracks(tracking, object); - MovieTrackingTrack *track= tracksbase->first; + ListBase *tracksbase = BKE_tracking_object_tracks(tracking, object); + MovieTrackingTrack *track = tracksbase->first; while (track) { if (!strcmp(track->name, name)) return track; - track= track->next; + track = track->next; } return NULL; @@ -2029,51 +2077,59 @@ MovieTrackingTrack *BKE_tracking_named_track(MovieTracking *tracking, MovieTrack static int reconstruction_camera_index(MovieTrackingReconstruction *reconstruction, int framenr, int nearest) { MovieReconstructedCamera *cameras= reconstruction->cameras; - int a= 0, d= 1; + int a = 0, d = 1; if (!reconstruction->camnr) return -1; if (framenr<cameras[0].framenr) { - if (nearest) return 0; - else return -1; + if (nearest) + return 0; + else + return -1; } - if (framenr>cameras[reconstruction->camnr-1].framenr) { - if (nearest) return reconstruction->camnr-1; - else return -1; + if (framenr>cameras[reconstruction->camnr - 1].framenr) { + if (nearest) + return reconstruction->camnr - 1; + else + return -1; } if (reconstruction->last_camera<reconstruction->camnr) - a= reconstruction->last_camera; + a = reconstruction->last_camera; - if (cameras[a].framenr>=framenr) - d= -1; + if (cameras[a].framenr >= framenr) + d = -1; - while (a>=0 && a<reconstruction->camnr) { - int cfra= cameras[a].framenr; + while (a >= 0 && a < reconstruction->camnr) { + int cfra = cameras[a].framenr; /* check if needed framenr was "skipped" -- no data for requested frame */ - if (d>0 && cfra>framenr) { + if (d > 0 && cfra > framenr) { /* interpolate with previous position */ - if (nearest) return a-1; - else break; + if (nearest) + return a - 1; + else + break; } - if (d<0 && cfra<framenr) { + if (d < 0 && cfra < framenr) { /* interpolate with next position */ - if (nearest) return a; - else break; + if (nearest) + return a; + else + break; } - if (cfra==framenr) { - reconstruction->last_camera= a; + if (cfra == framenr) { + reconstruction->last_camera = a; return a; } - a+= d; + a += d; } return -1; @@ -2081,47 +2137,48 @@ static int reconstruction_camera_index(MovieTrackingReconstruction *reconstructi static void scale_reconstructed_camera(MovieTrackingObject *object, float mat[4][4]) { - if ((object->flag&TRACKING_OBJECT_CAMERA)==0) { + if ((object->flag & TRACKING_OBJECT_CAMERA) == 0) { float smat[4][4]; - scale_m4_fl(smat, 1.0f/object->scale); + scale_m4_fl(smat, 1.0f / object->scale); mult_m4_m4m4(mat, mat, smat); } } MovieReconstructedCamera *BKE_tracking_get_reconstructed_camera(MovieTracking *tracking, - MovieTrackingObject *object, int framenr) + MovieTrackingObject *object, int framenr) { MovieTrackingReconstruction *reconstruction; int a; - reconstruction= BKE_tracking_object_reconstruction(tracking, object); - a= reconstruction_camera_index(reconstruction, framenr, 0); + reconstruction = BKE_tracking_object_reconstruction(tracking, object); + a = reconstruction_camera_index(reconstruction, framenr, FALSE); - if (a==-1) + if (a ==-1) return NULL; return &reconstruction->cameras[a]; } void BKE_tracking_get_interpolated_camera(MovieTracking *tracking, MovieTrackingObject *object, - int framenr, float mat[4][4]) + int framenr, float mat[4][4]) { MovieTrackingReconstruction *reconstruction; MovieReconstructedCamera *cameras; int a; - reconstruction= BKE_tracking_object_reconstruction(tracking, object); - cameras= reconstruction->cameras; - a= reconstruction_camera_index(reconstruction, framenr, 1); + reconstruction = BKE_tracking_object_reconstruction(tracking, object); + cameras = reconstruction->cameras; + a = reconstruction_camera_index(reconstruction, framenr, 1); - if (a==-1) { + if (a == -1) { unit_m4(mat); + return; } - if (cameras[a].framenr!=framenr && a>0 && a<reconstruction->camnr-1) { - float t= ((float)framenr-cameras[a].framenr) / (cameras[a+1].framenr-cameras[a].framenr); + if (cameras[a].framenr != framenr && a > 0 && a < reconstruction->camnr - 1) { + float t = ((float)framenr-cameras[a].framenr) / (cameras[a + 1].framenr-cameras[a].framenr); blend_m4_m4m4(mat, cameras[a].mat, cameras[a+1].mat, t); } @@ -2135,8 +2192,10 @@ void BKE_tracking_get_interpolated_camera(MovieTracking *tracking, MovieTracking void BKE_get_tracking_mat(Scene *scene, Object *ob, float mat[4][4]) { if (!ob) { - if (scene->camera) ob= scene->camera; - else ob= scene_find_camera(scene); + if (scene->camera) + ob = scene->camera; + else + ob = scene_find_camera(scene); } if (ob) @@ -2147,53 +2206,54 @@ void BKE_get_tracking_mat(Scene *scene, Object *ob, float mat[4][4]) void BKE_tracking_camera_shift(MovieTracking *tracking, int winx, int winy, float *shiftx, float *shifty) { - *shiftx= (0.5f*winx-tracking->camera.principal[0]) / winx; - *shifty= (0.5f*winy-tracking->camera.principal[1]) / winx; + /* indeed in both of cases it should be winx -- it's just how camera shift works for blender's camera */ + *shiftx = (0.5f * winx-tracking->camera.principal[0]) / winx; + *shifty = (0.5f * winy-tracking->camera.principal[1]) / winx; } void BKE_tracking_camera_to_blender(MovieTracking *tracking, Scene *scene, Camera *camera, int width, int height) { - float focal= tracking->camera.focal; + float focal = tracking->camera.focal; - camera->sensor_x= tracking->camera.sensor_width; - camera->sensor_fit= CAMERA_SENSOR_FIT_AUTO; - camera->lens= focal*camera->sensor_x/width; + camera->sensor_x = tracking->camera.sensor_width; + camera->sensor_fit = CAMERA_SENSOR_FIT_AUTO; + camera->lens = focal*camera->sensor_x/width; - scene->r.xsch= width*tracking->camera.pixel_aspect; - scene->r.ysch= height; + scene->r.xsch = width*tracking->camera.pixel_aspect; + scene->r.ysch = height; - scene->r.xasp= 1.0f; - scene->r.yasp= 1.0f; + scene->r.xasp = 1.0f; + scene->r.yasp = 1.0f; BKE_tracking_camera_shift(tracking, width, height, &camera->shiftx, &camera->shifty); } void BKE_tracking_projection_matrix(MovieTracking *tracking, MovieTrackingObject *object, - int framenr, int winx, int winy, float mat[4][4]) + int framenr, int winx, int winy, float mat[4][4]) { MovieReconstructedCamera *camera; - float lens= tracking->camera.focal*tracking->camera.sensor_width/(float)winx; + float lens = tracking->camera.focal*tracking->camera.sensor_width/(float)winx; float viewfac, pixsize, left, right, bottom, top, clipsta, clipend; float winmat[4][4]; - float ycor= 1.0f/tracking->camera.pixel_aspect; - float shiftx, shifty, winside= MAX2(winx, winy); + float ycor = 1.0f / tracking->camera.pixel_aspect; + float shiftx, shifty, winside = MAX2(winx, winy); BKE_tracking_camera_shift(tracking, winx, winy, &shiftx, &shifty); - clipsta= 0.1f; - clipend= 1000.0f; + clipsta = 0.1f; + clipend = 1000.0f; if (winx >= winy) - viewfac= (lens*winx)/tracking->camera.sensor_width; + viewfac = (lens*winx)/tracking->camera.sensor_width; else - viewfac= (ycor*lens*winy)/tracking->camera.sensor_width; + viewfac = (ycor*lens*winy)/tracking->camera.sensor_width; - pixsize= clipsta/viewfac; + pixsize = clipsta/viewfac; - left= -0.5f*(float)winx + shiftx*winside; - bottom= -0.5f*(ycor)*(float)winy + shifty*winside; - right= 0.5f*(float)winx + shiftx*winside; - top= 0.5f*(ycor)*(float)winy + shifty*winside; + left = -0.5f * (float)winx + shiftx * winside; + bottom = -0.5f * (ycor) * (float)winy + shifty * winside; + right = 0.5f * (float)winx + shiftx * winside; + top = 0.5f * (ycor) * (float)winy + shifty * winside; left *= pixsize; right *= pixsize; @@ -2202,7 +2262,7 @@ void BKE_tracking_projection_matrix(MovieTracking *tracking, MovieTrackingObject perspective_m4(winmat, left, right, bottom, top, clipsta, clipend); - camera= BKE_tracking_get_reconstructed_camera(tracking, object, framenr); + camera = BKE_tracking_get_reconstructed_camera(tracking, object, framenr); if (camera) { float imat[4][4]; @@ -2215,7 +2275,7 @@ void BKE_tracking_projection_matrix(MovieTracking *tracking, MovieTrackingObject ListBase *BKE_tracking_get_tracks(MovieTracking *tracking) { - MovieTrackingObject *object= BKE_tracking_active_object(tracking); + MovieTrackingObject *object = BKE_tracking_active_object(tracking); if (object && (object->flag & TRACKING_OBJECT_CAMERA) == 0) { return &object->tracks; @@ -2231,7 +2291,7 @@ MovieTrackingTrack *BKE_tracking_active_track(MovieTracking *tracking) if (!tracking->act_track) return NULL; - tracksbase= BKE_tracking_get_tracks(tracking); + tracksbase = BKE_tracking_get_tracks(tracking); /* check that active track is in current tracks list */ if (BLI_findindex(tracksbase, tracking->act_track) >= 0) @@ -2247,7 +2307,7 @@ MovieTrackingObject *BKE_tracking_active_object(MovieTracking *tracking) MovieTrackingObject *BKE_tracking_get_camera_object(MovieTracking *tracking) { - MovieTrackingObject *object= tracking->objects.first; + MovieTrackingObject *object = tracking->objects.first; while (object) { if (object->flag & TRACKING_OBJECT_CAMERA) @@ -2279,7 +2339,7 @@ MovieTrackingReconstruction *BKE_tracking_object_reconstruction(MovieTracking *t MovieTrackingReconstruction *BKE_tracking_get_reconstruction(MovieTracking *tracking) { - MovieTrackingObject *object= BKE_tracking_active_object(tracking); + MovieTrackingObject *object = BKE_tracking_active_object(tracking); return BKE_tracking_object_reconstruction(tracking, object); } @@ -2290,42 +2350,42 @@ void BKE_tracking_apply_intrinsics(MovieTracking *tracking, float co[2], float n #ifdef WITH_LIBMV double x, y; - float aspy= 1.0f/tracking->camera.pixel_aspect; + float aspy = 1.0f/tracking->camera.pixel_aspect; /* normalize coords */ - x= (co[0]-camera->principal[0]) / camera->focal; - y= (co[1]-camera->principal[1] * aspy) / camera->focal; + x = (co[0] - camera->principal[0]) / camera->focal; + y = (co[1] - camera->principal[1] * aspy) / camera->focal; libmv_applyCameraIntrinsics(camera->focal, camera->principal[0], camera->principal[1] * aspy, - camera->k1, camera->k2, camera->k3, x, y, &x, &y); + camera->k1, camera->k2, camera->k3, x, y, &x, &y); /* result is in image coords already */ - nco[0]= x; - nco[1]= y; + nco[0] = x; + nco[1] = y; #else - (void)camera; - (void)co; - (void)nco; + (void) camera; + (void) co; + (void) nco; #endif } void BKE_tracking_invert_intrinsics(MovieTracking *tracking, float co[2], float nco[2]) { - MovieTrackingCamera *camera= &tracking->camera; + MovieTrackingCamera *camera = &tracking->camera; #ifdef WITH_LIBMV - double x= co[0], y= co[1]; - float aspy= 1.0f/tracking->camera.pixel_aspect; + double x = co[0], y = co[1]; + float aspy = 1.0f / tracking->camera.pixel_aspect; libmv_InvertIntrinsics(camera->focal, camera->principal[0], camera->principal[1] * aspy, - camera->k1, camera->k2, camera->k3, x, y, &x, &y); + camera->k1, camera->k2, camera->k3, x, y, &x, &y); - nco[0]= x * camera->focal + camera->principal[0]; - nco[1]= y * camera->focal + camera->principal[1] * aspy; + nco[0] = x * camera->focal + camera->principal[0]; + nco[1] = y * camera->focal + camera->principal[1] * aspy; #else - (void)camera; - (void)co; - (void)nco; + (void) camera; + (void) co; + (void) nco; #endif } @@ -2333,125 +2393,126 @@ void BKE_tracking_invert_intrinsics(MovieTracking *tracking, float co[2], float static int point_in_stroke(bGPDstroke *stroke, float x, float y) { int i, prev; - int count= 0; - bGPDspoint *points= stroke->points; + int count = 0; + bGPDspoint *points = stroke->points; - prev= stroke->totpoints-1; + prev = stroke->totpoints - 1; - for (i= 0; i<stroke->totpoints; i++) { - if ((points[i].y<y && points[prev].y>=y) || (points[prev].y<y && points[i].y>=y)) { - float fac= (y-points[i].y)/(points[prev].y-points[i].y); + for (i = 0; i<stroke->totpoints; i++) { + if ((points[i].y < y && points[prev].y >= y) || (points[prev].y < y && points[i].y >= y)) { + float fac = (y - points[i].y) / (points[prev].y - points[i].y); - if (points[i].x+fac*(points[prev].x-points[i].x)<x) + if (points[i].x + fac * (points[prev].x - points[i].x) < x) count++; } prev= i; } - return count%2; + return count % 2; } static int point_in_layer(bGPDlayer *layer, float x, float y) { - bGPDframe *frame= layer->frames.first; + bGPDframe *frame = layer->frames.first; while (frame) { - bGPDstroke *stroke= frame->strokes.first; + bGPDstroke *stroke = frame->strokes.first; + while (stroke) { if (point_in_stroke(stroke, x, y)) - return 1; + return TRUE; - stroke= stroke->next; + stroke = stroke->next; } - frame= frame->next; + frame = frame->next; } - return 0; + return FALSE; } static void retrieve_libmv_features(MovieTracking *tracking, ListBase *tracksbase, - struct libmv_Features *features, int framenr, int width, int height, - bGPDlayer *layer, int place_outside_layer) + struct libmv_Features *features, int framenr, int width, int height, + bGPDlayer *layer, int place_outside_layer) { int a; - a= libmv_countFeatures(features); + a = libmv_countFeatures(features); while (a--) { MovieTrackingTrack *track; double x, y, size, score; - int ok= 1; + int ok = TRUE; float xu, yu; libmv_getFeature(features, a, &x, &y, &score, &size); - xu= x/width; - yu= y/height; + xu = x / width; + yu = y / height; if (layer) - ok= point_in_layer(layer, xu, yu)!=place_outside_layer; + ok = point_in_layer(layer, xu, yu) != place_outside_layer; if (ok) { - track= BKE_tracking_add_track(tracking, tracksbase, xu, yu, framenr, width, height); - track->flag|= SELECT; - track->pat_flag|= SELECT; - track->search_flag|= SELECT; + track = BKE_tracking_add_track(tracking, tracksbase, xu, yu, framenr, width, height); + track->flag |= SELECT; + track->pat_flag |= SELECT; + track->search_flag |= SELECT; } } } #endif void BKE_tracking_detect_fast(MovieTracking *tracking, ListBase *tracksbase, ImBuf *ibuf, - int framenr, int margin, int min_trackness, int min_distance, bGPDlayer *layer, - int place_outside_layer) + int framenr, int margin, int min_trackness, int min_distance, bGPDlayer *layer, + int place_outside_layer) { #ifdef WITH_LIBMV struct libmv_Features *features; - unsigned char *pixels= get_ucharbuf(ibuf); + unsigned char *pixels = get_ucharbuf(ibuf); - features= libmv_detectFeaturesFAST(pixels, ibuf->x, ibuf->y, ibuf->x, - margin, min_trackness, min_distance); + features = libmv_detectFeaturesFAST(pixels, ibuf->x, ibuf->y, ibuf->x, + margin, min_trackness, min_distance); MEM_freeN(pixels); retrieve_libmv_features(tracking, tracksbase, features, framenr, - ibuf->x, ibuf->y, layer, place_outside_layer); + ibuf->x, ibuf->y, layer, place_outside_layer); libmv_destroyFeatures(features); #else - (void)tracking; - (void)tracksbase; - (void)ibuf; - (void)framenr; - (void)margin; - (void)min_trackness; - (void)min_distance; - (void)layer; - (void)place_outside_layer; + (void) tracking; + (void) tracksbase; + (void) ibuf; + (void) framenr; + (void) margin; + (void) min_trackness; + (void) min_distance; + (void) layer; + (void) place_outside_layer; #endif } MovieTrackingTrack *BKE_tracking_indexed_track(MovieTracking *tracking, int tracknr, ListBase **tracksbase_r) { MovieTrackingObject *object; - int cur= 1; + int cur = 1; - object= tracking->objects.first; + object = tracking->objects.first; while (object) { - ListBase *tracksbase= BKE_tracking_object_tracks(tracking, object); - MovieTrackingTrack *track= tracksbase->first; + ListBase *tracksbase = BKE_tracking_object_tracks(tracking, object); + MovieTrackingTrack *track = tracksbase->first; while (track) { - if (track->flag&TRACK_HAS_BUNDLE) { - if (cur==tracknr) { - *tracksbase_r= tracksbase; + if (track->flag & TRACK_HAS_BUNDLE) { + if (cur == tracknr) { + *tracksbase_r = tracksbase; return track; } cur++; } - track= track->next; + track = track->next; } object= object->next; @@ -2464,104 +2525,103 @@ MovieTrackingTrack *BKE_tracking_indexed_track(MovieTracking *tracking, int trac static int stabilization_median_point(MovieTracking *tracking, int framenr, float median[2]) { - int ok= 0; + int ok = FALSE; float min[2], max[2]; MovieTrackingTrack *track; INIT_MINMAX2(min, max); - (void) tracking; - - track= tracking->tracks.first; + track = tracking->tracks.first; while (track) { - if (track->flag&TRACK_USE_2D_STAB) { - MovieTrackingMarker *marker= BKE_tracking_get_marker(track, framenr); + if (track->flag & TRACK_USE_2D_STAB) { + MovieTrackingMarker *marker = BKE_tracking_get_marker(track, framenr); DO_MINMAX2(marker->pos, min, max); - ok= 1; + ok = TRUE; } - track= track->next; + track = track->next; } - median[0]= (max[0]+min[0])/2.0f; - median[1]= (max[1]+min[1])/2.0f; + median[0] = (max[0] + min[0]) / 2.0f; + median[1] = (max[1] + min[1]) / 2.0f; return ok; } static void calculate_stabdata(MovieTracking *tracking, int framenr, float width, float height, - float firstmedian[2], float median[2], float loc[2], float *scale, float *angle) + float firstmedian[2], float median[2], float loc[2], float *scale, float *angle) { - MovieTrackingStabilization *stab= &tracking->stabilization; + MovieTrackingStabilization *stab = &tracking->stabilization; - *scale= (stab->scale-1.0f)*stab->scaleinf+1.0f; - *angle= 0.0f; + *scale = (stab->scale - 1.0f) * stab->scaleinf + 1.0f; + *angle = 0.0f; - loc[0]= (firstmedian[0]-median[0])*width*(*scale); - loc[1]= (firstmedian[1]-median[1])*height*(*scale); + loc[0] = (firstmedian[0] - median[0]) *width * (*scale); + loc[1] = (firstmedian[1] - median[1]) *height * (*scale); mul_v2_fl(loc, stab->locinf); - if ((stab->flag&TRACKING_STABILIZE_ROTATION) && stab->rot_track && stab->rotinf) { + if ((stab->flag & TRACKING_STABILIZE_ROTATION) && stab->rot_track && stab->rotinf) { MovieTrackingMarker *marker; float a[2], b[2]; - float x0= (float)width/2.0f, y0= (float)height/2.0f; - float x= median[0]*width, y= median[1]*height; + float x0 = (float)width / 2.0f, y0 = (float)height / 2.0f; + float x = median[0] * width, y = median[1] * height; - marker= BKE_tracking_get_marker(stab->rot_track, 1); + marker = BKE_tracking_get_marker(stab->rot_track, 1); sub_v2_v2v2(a, marker->pos, firstmedian); - a[0]*= width; - a[1]*= height; + a[0] *= width; + a[1] *= height; - marker= BKE_tracking_get_marker(stab->rot_track, framenr); + marker = BKE_tracking_get_marker(stab->rot_track, framenr); sub_v2_v2v2(b, marker->pos, median); - b[0]*= width; - b[1]*= height; + b[0] *= width; + b[1] *= height; - *angle= -atan2(a[0]*b[1]-a[1]*b[0], a[0]*b[0]+a[1]*b[1]); - *angle*= stab->rotinf; + *angle = -atan2(a[0]*b[1]-a[1]*b[0], a[0]*b[0]+a[1]*b[1]); + *angle *= stab->rotinf; /* convert to rotation around image center */ - loc[0]-= (x0 + (x-x0)*cosf(*angle)-(y-y0)*sinf(*angle) - x)*(*scale); - loc[1]-= (y0 + (x-x0)*sinf(*angle)+(y-y0)*cosf(*angle) - y)*(*scale); + loc[0] -= (x0 + (x - x0) * cosf(*angle) - (y - y0) * sinf(*angle) - x) * (*scale); + loc[1] -= (y0 + (x - x0) * sinf(*angle) + (y - y0) * cosf(*angle) - y) * (*scale); } } static float stabilization_auto_scale_factor(MovieTracking *tracking, int width, int height) { float firstmedian[2]; - MovieTrackingStabilization *stab= &tracking->stabilization; - float aspect= tracking->camera.pixel_aspect; + MovieTrackingStabilization *stab = &tracking->stabilization; + float aspect = tracking->camera.pixel_aspect; if (stab->ok) return stab->scale; if (stabilization_median_point(tracking, 1, firstmedian)) { - int sfra= INT_MAX, efra= INT_MIN, cfra; - float scale= 1.0f; + int sfra = INT_MAX, efra = INT_MIN, cfra; + float scale = 1.0f; MovieTrackingTrack *track; - stab->scale= 1.0f; + stab->scale = 1.0f; - track= tracking->tracks.first; + track = tracking->tracks.first; while (track) { - if (track->flag&TRACK_USE_2D_STAB || - ((stab->flag&TRACKING_STABILIZE_ROTATION) && track==stab->rot_track)) { - sfra= MIN2(sfra, track->markers[0].framenr); - efra= MAX2(efra, track->markers[track->markersnr-1].framenr); + if (track->flag & TRACK_USE_2D_STAB || + ((stab->flag & TRACKING_STABILIZE_ROTATION) && track == stab->rot_track)) + { + sfra = MIN2(sfra, track->markers[0].framenr); + efra = MAX2(efra, track->markers[track->markersnr - 1].framenr); } - track= track->next; + track = track->next; } - for (cfra=sfra; cfra<=efra; cfra++) { + for (cfra = sfra; cfra <= efra; cfra++) { float median[2]; float loc[2], angle, tmp_scale; int i; float mat[4][4]; - float points[4][2]={{0.0f, 0.0f}, {0.0f, height}, {width, height}, {width, 0.0f}}; + float points[4][2] = {{0.0f, 0.0f}, {0.0f, height}, {width, height}, {width, 0.0f}}; float si, co; stabilization_median_point(tracking, cfra, median); @@ -2573,9 +2633,9 @@ static float stabilization_auto_scale_factor(MovieTracking *tracking, int width, si = sin(angle); co = cos(angle); - for (i= 0; i<4; i++) { + for (i = 0; i < 4; i++) { int j; - float a[3]= {0.0f, 0.0f, 0.0f}, b[3]= {0.0f, 0.0f, 0.0f}; + float a[3] = {0.0f, 0.0f, 0.0f}, b[3]= {0.0f, 0.0f, 0.0f}; copy_v3_v3(a, points[i]); copy_v3_v3(b, points[(i+1)%4]); @@ -2583,8 +2643,8 @@ static float stabilization_auto_scale_factor(MovieTracking *tracking, int width, mul_m4_v3(mat, a); mul_m4_v3(mat, b); - for (j= 0; j<4; j++) { - float point[3]= {points[j][0], points[j][1], 0.0f}; + for (j = 0; j < 4; j++) { + float point[3] = {points[j][0], points[j][1], 0.0f}; float v1[3], v2[3]; sub_v3_v3v3(v1, b, a); @@ -2632,16 +2692,16 @@ static float stabilization_auto_scale_factor(MovieTracking *tracking, int width, } } - stab->scale= scale; + stab->scale = scale; if (stab->maxscale>0.0f) - stab->scale= MIN2(stab->scale, stab->maxscale); + stab->scale = MIN2(stab->scale, stab->maxscale); } else { - stab->scale= 1.0f; + stab->scale = 1.0f; } - stab->ok= 1; + stab->ok = TRUE; return stab->scale; } @@ -2652,23 +2712,24 @@ static ImBuf* stabilize_alloc_ibuf(ImBuf *cacheibuf, ImBuf *srcibuf, int fill) if (cacheibuf && (cacheibuf->x != srcibuf->x || cacheibuf->y != srcibuf->y)) { IMB_freeImBuf(cacheibuf); - cacheibuf= NULL; + cacheibuf = NULL; } - flags= IB_rect; + flags = IB_rect; if (srcibuf->rect_float) - flags|= IB_rectfloat; + flags |= IB_rectfloat; if (cacheibuf) { if (fill) { - float col[4]= {0.0f, 0.0f, 0.0f, 0.0f}; + float col[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + IMB_rectfill(cacheibuf, col); } } else { - cacheibuf= IMB_allocImBuf(srcibuf->x, srcibuf->y, srcibuf->planes, flags); - cacheibuf->profile= srcibuf->profile; + cacheibuf = IMB_allocImBuf(srcibuf->x, srcibuf->y, srcibuf->planes, flags); + cacheibuf->profile = srcibuf->profile; } return cacheibuf; @@ -2677,9 +2738,9 @@ static ImBuf* stabilize_alloc_ibuf(ImBuf *cacheibuf, ImBuf *srcibuf, int fill) void BKE_tracking_stabilization_data(MovieTracking *tracking, int framenr, int width, int height, float loc[2], float *scale, float *angle) { float firstmedian[2], median[2]; - MovieTrackingStabilization *stab= &tracking->stabilization; + MovieTrackingStabilization *stab = &tracking->stabilization; - if ((stab->flag&TRACKING_2D_STABILIZATION)==0) { + if ((stab->flag & TRACKING_2D_STABILIZATION) == 0) { zero_v2(loc); *scale= 1.0f; *angle= 0.0f; @@ -2690,16 +2751,16 @@ void BKE_tracking_stabilization_data(MovieTracking *tracking, int framenr, int w if (stabilization_median_point(tracking, 1, firstmedian)) { stabilization_median_point(tracking, framenr, median); - if ((stab->flag&TRACKING_AUTOSCALE)==0) - stab->scale= 1.0f; + if ((stab->flag & TRACKING_AUTOSCALE) == 0) + stab->scale = 1.0f; if (!stab->ok) { - if (stab->flag&TRACKING_AUTOSCALE) + if (stab->flag & TRACKING_AUTOSCALE) stabilization_auto_scale_factor(tracking, width, height); calculate_stabdata(tracking, framenr, width, height, firstmedian, median, loc, scale, angle); - stab->ok= 1; + stab->ok = TRUE; } else { calculate_stabdata(tracking, framenr, width, height, firstmedian, median, loc, scale, angle); @@ -2707,56 +2768,65 @@ void BKE_tracking_stabilization_data(MovieTracking *tracking, int framenr, int w } else { zero_v2(loc); - *scale= 1.0f; - *angle= 0.0f; + *scale = 1.0f; + *angle = 0.0f; } } ImBuf *BKE_tracking_stabilize(MovieTracking *tracking, int framenr, ImBuf *ibuf, float loc[2], float *scale, float *angle) { float tloc[2], tscale, tangle; - MovieTrackingStabilization *stab= &tracking->stabilization; + MovieTrackingStabilization *stab = &tracking->stabilization; ImBuf *tmpibuf; - float width= ibuf->x, height= ibuf->y; - float aspect= tracking->camera.pixel_aspect; + float width = ibuf->x, height = ibuf->y; + float aspect = tracking->camera.pixel_aspect; - if (loc) copy_v2_v2(tloc, loc); - if (scale) tscale= *scale; + if (loc) + copy_v2_v2(tloc, loc); - if ((stab->flag&TRACKING_2D_STABILIZATION)==0) { - if (loc) zero_v2(loc); - if (scale) *scale= 1.0f; + if (scale) + tscale = *scale; + + if ((stab->flag & TRACKING_2D_STABILIZATION) == 0) { + if (loc) + zero_v2(loc); + + if (scale) + *scale = 1.0f; return ibuf; } BKE_tracking_stabilization_data(tracking, framenr, width, height, tloc, &tscale, &tangle); - tmpibuf= stabilize_alloc_ibuf(NULL, ibuf, 1); + tmpibuf = stabilize_alloc_ibuf(NULL, ibuf, TRUE); /* scale would be handled by matrix transformation when angle is non-zero */ - if (tscale!=1.0f && tangle==0.0f) { + if (tscale != 1.0f && tangle == 0.0f) { ImBuf *scaleibuf; stabilization_auto_scale_factor(tracking, width, height); - scaleibuf= stabilize_alloc_ibuf(stab->scaleibuf, ibuf, 0); - stab->scaleibuf= scaleibuf; + scaleibuf = stabilize_alloc_ibuf(stab->scaleibuf, ibuf, 0); + stab->scaleibuf = scaleibuf; IMB_rectcpy(scaleibuf, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y); IMB_scalefastImBuf(scaleibuf, ibuf->x*tscale, ibuf->y*tscale); - ibuf= scaleibuf; + ibuf = scaleibuf; } - if (tangle==0.0f) { + if (tangle == 0.0f) { /* if angle is zero, then it's much faster to use rect copy * but could be issues with subpixel precisions */ - 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); + 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, filter= tracking->stabilization.filter; + 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); @@ -2772,9 +2842,9 @@ ImBuf *BKE_tracking_stabilize(MovieTracking *tracking, int framenr, ImBuf *ibuf, /* fallback to default interpolation method */ interpolation = neareast_interpolation; - for (j=0; j<tmpibuf->y; j++) { - for (i=0; i<tmpibuf->x;i++) { - float vec[3]= {i, j, 0}; + 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); @@ -2783,14 +2853,19 @@ ImBuf *BKE_tracking_stabilize(MovieTracking *tracking, int framenr, ImBuf *ibuf, } } - tmpibuf->userflags|= IB_MIPMAP_INVALID; + tmpibuf->userflags |= IB_MIPMAP_INVALID; if (tmpibuf->rect_float) - tmpibuf->userflags|= IB_RECT_INVALID; + tmpibuf->userflags |= IB_RECT_INVALID; + + if (loc) + copy_v2_v2(loc, tloc); - if (loc) copy_v2_v2(loc, tloc); - if (scale) *scale= tscale; - if (angle) *angle= tangle; + if (scale) + *scale= tscale; + + if (angle) + *angle= tangle; return tmpibuf; } @@ -2811,8 +2886,8 @@ void BKE_tracking_stabdata_to_mat4(int width, int height, float aspect, float lo invert_m4_m4(iamat, amat); /* image center as rotation center */ - cmat[3][0]= (float)width/2.0f; - cmat[3][1]= (float)height/2.0f; + cmat[3][0] = (float)width / 2.0f; + cmat[3][1] = (float)height / 2.0f; invert_m4_m4(icmat, cmat); size_to_mat4(smat, svec); /* scale matrix */ @@ -2827,7 +2902,7 @@ MovieDistortion *BKE_tracking_distortion_create(void) { MovieDistortion *distortion; - distortion= MEM_callocN(sizeof(MovieDistortion), "BKE_tracking_distortion_create"); + distortion = MEM_callocN(sizeof(MovieDistortion), "BKE_tracking_distortion_create"); return distortion; } @@ -2836,12 +2911,12 @@ MovieDistortion *BKE_tracking_distortion_copy(MovieDistortion *distortion) { MovieDistortion *new_distortion; - new_distortion= MEM_callocN(sizeof(MovieDistortion), "BKE_tracking_distortion_create"); + new_distortion = MEM_callocN(sizeof(MovieDistortion), "BKE_tracking_distortion_create"); #ifdef WITH_LIBMV - new_distortion->intrinsics= libmv_CameraIntrinsicsCopy(distortion->intrinsics); + new_distortion->intrinsics = libmv_CameraIntrinsicsCopy(distortion->intrinsics); #else - (void)distortion; + (void) distortion; #endif return new_distortion; @@ -2849,12 +2924,12 @@ MovieDistortion *BKE_tracking_distortion_copy(MovieDistortion *distortion) void BKE_tracking_distortion_update(MovieDistortion *distortion, MovieTracking *tracking, int width, int height) { - MovieTrackingCamera *camera= &tracking->camera; - float aspy= 1.0f/tracking->camera.pixel_aspect; + MovieTrackingCamera *camera = &tracking->camera; + float aspy = 1.0f / tracking->camera.pixel_aspect; #ifdef WITH_LIBMV if (!distortion->intrinsics) { - distortion->intrinsics= libmv_CameraIntrinsicsNew(camera->focal, + distortion->intrinsics = libmv_CameraIntrinsicsNew(camera->focal, camera->principal[0], camera->principal[1] * aspy, camera->k1, camera->k2, camera->k3, width, height * aspy); } @@ -2864,22 +2939,22 @@ void BKE_tracking_distortion_update(MovieDistortion *distortion, MovieTracking * camera->k1, camera->k2, camera->k3, width, height * aspy); } #else - (void)distortion; - (void)width; - (void)height; - (void)camera; - (void)aspy; + (void) distortion; + (void) width; + (void) height; + (void) camera; + (void) aspy; #endif } ImBuf *BKE_tracking_distortion_exec(MovieDistortion *distortion, MovieTracking *tracking, - ImBuf *ibuf, int width, int height, float overscan, int undistort) + ImBuf *ibuf, int width, int height, float overscan, int undistort) { ImBuf *resibuf; BKE_tracking_distortion_update(distortion, tracking, width, height); - resibuf= IMB_dupImBuf(ibuf); + resibuf = IMB_dupImBuf(ibuf); if (ibuf->rect_float) { #ifdef WITH_LIBMV @@ -2895,7 +2970,7 @@ ImBuf *BKE_tracking_distortion_exec(MovieDistortion *distortion, MovieTracking * } #endif - ibuf->userflags|= IB_RECT_INVALID; + ibuf->userflags |= IB_RECT_INVALID; } else { #ifdef WITH_LIBMV @@ -2913,8 +2988,8 @@ ImBuf *BKE_tracking_distortion_exec(MovieDistortion *distortion, MovieTracking * } #ifndef WITH_LIBMV - (void)overscan; - (void)undistort; + (void) overscan; + (void) undistort; #endif return resibuf; @@ -2931,20 +3006,20 @@ void BKE_tracking_distortion_destroy(MovieDistortion *distortion) ImBuf *BKE_tracking_undistort(MovieTracking *tracking, ImBuf *ibuf, int width, int height, float overscan) { - MovieTrackingCamera *camera= &tracking->camera; + MovieTrackingCamera *camera = &tracking->camera; if (camera->intrinsics == NULL) - camera->intrinsics= BKE_tracking_distortion_create(); + camera->intrinsics = BKE_tracking_distortion_create(); return BKE_tracking_distortion_exec(camera->intrinsics, tracking, ibuf, width, height, overscan, 1); } ImBuf *BKE_tracking_distort(MovieTracking *tracking, ImBuf *ibuf, int width, int height, float overscan) { - MovieTrackingCamera *camera= &tracking->camera; + MovieTrackingCamera *camera = &tracking->camera; if (camera->intrinsics == NULL) - camera->intrinsics= BKE_tracking_distortion_create(); + camera->intrinsics = BKE_tracking_distortion_create(); return BKE_tracking_distortion_exec(camera->intrinsics, tracking, ibuf, width, height, overscan, 0); } @@ -2956,11 +3031,11 @@ void BKE_tracking_select_track(ListBase *tracksbase, MovieTrackingTrack *track, BKE_tracking_track_flag(track, area, SELECT, 0); } else { - MovieTrackingTrack *cur= tracksbase->first; + MovieTrackingTrack *cur = tracksbase->first; while (cur) { if ((cur->flag & TRACK_HIDDEN) == 0) { - if (cur==track) { + if (cur == track) { BKE_tracking_track_flag(cur, TRACK_AREA_ALL, SELECT, 1); BKE_tracking_track_flag(cur, area, SELECT, 0); } @@ -2969,7 +3044,7 @@ void BKE_tracking_select_track(ListBase *tracksbase, MovieTrackingTrack *track, } } - cur= cur->next; + cur = cur->next; } } } @@ -2981,13 +3056,13 @@ void BKE_tracking_deselect_track(MovieTrackingTrack *track, int area) MovieTrackingObject *BKE_tracking_new_object(MovieTracking *tracking, const char *name) { - MovieTrackingObject *object= MEM_callocN(sizeof(MovieTrackingObject), "tracking object"); + MovieTrackingObject *object = MEM_callocN(sizeof(MovieTrackingObject), "tracking object"); - if (tracking->tot_object==0) { + if (tracking->tot_object == 0) { /* first object is always camera */ BLI_strncpy(object->name, "Camera", sizeof(object->name)); - object->flag|= TRACKING_OBJECT_CAMERA; + object->flag |= TRACKING_OBJECT_CAMERA; } else { BLI_strncpy(object->name, name, sizeof(object->name)); @@ -2996,9 +3071,9 @@ MovieTrackingObject *BKE_tracking_new_object(MovieTracking *tracking, const char BLI_addtail(&tracking->objects, object); tracking->tot_object++; - tracking->objectnr= BLI_countlist(&tracking->objects) - 1; + tracking->objectnr = BLI_countlist(&tracking->objects) - 1; - object->scale= 1.0f; + object->scale = 1.0f; BKE_tracking_object_unique_name(tracking, object); @@ -3008,7 +3083,7 @@ MovieTrackingObject *BKE_tracking_new_object(MovieTracking *tracking, const char void BKE_tracking_remove_object(MovieTracking *tracking, MovieTrackingObject *object) { MovieTrackingTrack *track; - int index= BLI_findindex(&tracking->objects, object); + int index = BLI_findindex(&tracking->objects, object); if (index<0) return; @@ -3018,10 +3093,10 @@ void BKE_tracking_remove_object(MovieTracking *tracking, MovieTrackingObject *ob return; } - track= object->tracks.first; + track = object->tracks.first; while (track) { - if (track==tracking->act_track) - tracking->act_track= NULL; + if (track == tracking->act_track) + tracking->act_track = NULL; track= track->next; } @@ -3032,9 +3107,9 @@ void BKE_tracking_remove_object(MovieTracking *tracking, MovieTrackingObject *ob tracking->tot_object--; if (index>0) - tracking->objectnr= index-1; + tracking->objectnr = index - 1; else - tracking->objectnr= 0; + tracking->objectnr = 0; } void BKE_tracking_object_unique_name(MovieTracking *tracking, MovieTrackingObject *object) @@ -3044,13 +3119,13 @@ void BKE_tracking_object_unique_name(MovieTracking *tracking, MovieTrackingObjec MovieTrackingObject *BKE_tracking_named_object(MovieTracking *tracking, const char *name) { - MovieTrackingObject *object= tracking->objects.first; + MovieTrackingObject *object = tracking->objects.first; while (object) { if (!strcmp(object->name, name)) return object; - object= object->next; + object = object->next; } return NULL; |