diff --git a/source/blender/blenkernel/BKE_tracking.h b/source/blender/blenkernel/BKE_tracking.h index f720050f59c..ebbba7de7c7 100644 --- a/source/blender/blenkernel/BKE_tracking.h +++ b/source/blender/blenkernel/BKE_tracking.h @@ -138,7 +138,7 @@ void BKE_tracking_detect_fast(struct MovieTracking *tracking, struct ListBase *t /* 2D stabilization */ void BKE_tracking_stabilization_data(struct MovieTracking *tracking, int framenr, int width, int height, float loc[2], float *scale, float *angle); struct ImBuf *BKE_tracking_stabilize(struct MovieTracking *tracking, int framenr, struct ImBuf *ibuf, float loc[2], float *scale, float *angle); -void BKE_tracking_stabdata_to_mat4(int width, int height, float loc[2], float scale, float angle, float mat[4][4]); +void BKE_tracking_stabdata_to_mat4(int width, int height, float aspect, float loc[2], float scale, float angle, float mat[4][4]); /* Distortion/Undistortion */ void BKE_tracking_apply_intrinsics(struct MovieTracking *tracking, float co[2], float nco[2]); diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index c93c03a4424..ce0d169557d 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -279,7 +279,7 @@ typedef struct MovieClipCache { int framenr; int postprocess_flag; - float loc[2], scale, angle; + float loc[2], scale, angle, aspect; int proxy; short render_flag; } stabilized; @@ -727,6 +727,10 @@ static ImBuf *get_stable_cached_frame(MovieClip *clip, MovieClipUser *user, int if(cache->stabilized.postprocess_flag != postprocess_flag) return NULL; + /* stabilization also depends on pixel aspect ratio */ + if(cache->stabilized.aspect != clip->tracking.camera.pixel_aspect) + return NULL; + stableibuf = cache->stabilized.ibuf; BKE_tracking_stabilization_data(&clip->tracking, framenr, stableibuf->x, stableibuf->y, tloc, &tscale, &tangle); @@ -763,6 +767,7 @@ static ImBuf *put_stabilized_frame_to_cache(MovieClip *clip, MovieClipUser *user cache->stabilized.scale = tscale; cache->stabilized.angle = tangle; cache->stabilized.framenr = framenr; + cache->stabilized.aspect = clip->tracking.camera.pixel_aspect; if(clip->flag&MCLIP_USE_PROXY) { cache->stabilized.proxy= rendersize_to_proxy(user, clip->flag); diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index c9e6ecf6394..04766910df6 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -2485,6 +2485,7 @@ static float stabilization_auto_scale_factor(MovieTracking *tracking, int width, { float firstmedian[2]; MovieTrackingStabilization *stab= &tracking->stabilization; + float aspect= tracking->camera.pixel_aspect; if(stab->ok) return stab->scale; @@ -2535,7 +2536,7 @@ static float stabilization_auto_scale_factor(MovieTracking *tracking, int width, float mat[4][4]; float points[4][2]={{0.0f, 0.0f}, {0.0f, height}, {width, height}, {width, 0.0f}}; - BKE_tracking_stabdata_to_mat4(width, height, loc, scale, angle, mat); + BKE_tracking_stabdata_to_mat4(width, height, aspect, loc, scale, angle, mat); for(i= 0; i<4; i++) { int j; @@ -2650,6 +2651,7 @@ ImBuf *BKE_tracking_stabilize(MovieTracking *tracking, int framenr, ImBuf *ibuf, MovieTrackingStabilization *stab= &tracking->stabilization; ImBuf *tmpibuf; float width= ibuf->x, height= ibuf->y; + float aspect= tracking->camera.pixel_aspect; if(loc) copy_v2_v2(tloc, loc); if(scale) tscale= *scale; @@ -2688,7 +2690,7 @@ ImBuf *BKE_tracking_stabilize(MovieTracking *tracking, int framenr, ImBuf *ibuf, float mat[4][4]; int i, j; - BKE_tracking_stabdata_to_mat4(ibuf->x, ibuf->y, tloc, tscale, tangle, mat); + BKE_tracking_stabdata_to_mat4(ibuf->x, ibuf->y, aspect, tloc, tscale, tangle, mat); invert_m4(mat); for(j=0; jy; j++) { @@ -2715,15 +2717,20 @@ ImBuf *BKE_tracking_stabilize(MovieTracking *tracking, int framenr, ImBuf *ibuf, return tmpibuf; } -void BKE_tracking_stabdata_to_mat4(int width, int height, float loc[2], float scale, float angle, float mat[4][4]) +void BKE_tracking_stabdata_to_mat4(int width, int height, float aspect, float loc[2], float scale, float angle, float mat[4][4]) { - float lmat[4][4], rmat[4][4], smat[4][4], cmat[4][4], icmat[4][4]; + float lmat[4][4], rmat[4][4], smat[4][4], cmat[4][4], icmat[4][4], amat[4][4], iamat[4][4]; float svec[3]= {scale, scale, scale}; unit_m4(rmat); unit_m4(lmat); unit_m4(smat); unit_m4(cmat); + unit_m4(amat); + + /* aspect ratio correction matrix */ + amat[0][0] = 1.0f / aspect; + invert_m4_m4(iamat, amat); /* image center as rotation center */ cmat[3][0]= (float)width/2.0f; @@ -2735,7 +2742,7 @@ void BKE_tracking_stabdata_to_mat4(int width, int height, float loc[2], float sc rotate_m4(rmat, 'Z', angle); /* rotation matrix */ /* compose transformation matrix */ - mul_serie_m4(mat, lmat, cmat, rmat, smat, icmat, NULL, NULL, NULL); + mul_serie_m4(mat, amat, lmat, cmat, rmat, smat, icmat, iamat, NULL); } MovieDistortion *BKE_tracking_distortion_create(void) diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index 49fa7837de6..6dda09a1451 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -1269,13 +1269,14 @@ void clip_draw_main(SpaceClip *sc, ARegion *ar, Scene *scene) if(ibuf) { float loc[2]; + float aspect= clip->tracking.camera.pixel_aspect; if(width != ibuf->x) mul_v2_v2fl(loc, sc->loc, (float)width / ibuf->x); else copy_v2_v2(loc, sc->loc); - BKE_tracking_stabdata_to_mat4(width, height, loc, sc->scale, sc->angle, sc->stabmat); + BKE_tracking_stabdata_to_mat4(width, height, aspect, loc, sc->scale, sc->angle, sc->stabmat); unit_m4(smat); smat[0][0]= 1.0f/width;