diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-04-08 14:56:50 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-04-08 14:56:50 +0400 |
commit | 51a937039e42b50c232661c53bf9621ce44c6b94 (patch) | |
tree | 5f682f4656da3d6392cc804d309b242f085e1d08 /source | |
parent | 97a6965da9a671987df50570f8206c39569bac78 (diff) |
Camera stabilization fixes and improvements
- Nearest interpolation was always used when there's
no rotation for stabilization. Was a failure of
optimization heuristic.
- Made 2d stabilization frame acquiring threaded.
This function is only used for display and sequencer
which will only benefit of threads here.
- Fixed bug introduced in r48749 which lead to
re-making stable frame on every redraw.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/movieclip.c | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/tracking.c | 61 |
2 files changed, 30 insertions, 32 deletions
diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index c8f3399665c..a83ee548054 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -973,6 +973,7 @@ static ImBuf *put_stabilized_frame_to_cache(MovieClip *clip, MovieClipUser *user copy_v2_v2(cache->stabilized.loc, tloc); + cache->stabilized.reference_ibuf = ibuf; cache->stabilized.scale = tscale; cache->stabilized.angle = tangle; cache->stabilized.framenr = framenr; diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 9723e65e401..6a7fce4a0a3 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -3564,6 +3564,9 @@ ImBuf *BKE_tracking_stabilize_frame(MovieTracking *tracking, int framenr, ImBuf ImBuf *tmpibuf; float width = ibuf->x, height = ibuf->y; float aspect = tracking->camera.pixel_aspect; + float mat[4][4]; + int j, filter = tracking->stabilization.filter; + void (*interpolation)(struct ImBuf *, struct ImBuf *, float, float, int, int) = NULL; if (loc) copy_v2_v2(tloc, loc); @@ -3600,41 +3603,35 @@ ImBuf *BKE_tracking_stabilize_frame(MovieTracking *tracking, int framenr, ImBuf ibuf = scaleibuf; } - 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); - } - else { - float mat[4][4]; - int i, j, filter = tracking->stabilization.filter; - void (*interpolation)(struct ImBuf *, struct ImBuf *, float, float, int, int) = NULL; - - BKE_tracking_stabilization_data_to_mat4(ibuf->x, ibuf->y, aspect, tloc, tscale, tangle, mat); - invert_m4(mat); - - if (filter == TRACKING_FILTER_NEAREST) - interpolation = nearest_interpolation; - else if (filter == TRACKING_FILTER_BILINEAR) - interpolation = bilinear_interpolation; - else if (filter == TRACKING_FILTER_BICUBIC) - interpolation = bicubic_interpolation; - else - /* fallback to default interpolation method */ - interpolation = nearest_interpolation; + BKE_tracking_stabilization_data_to_mat4(ibuf->x, ibuf->y, aspect, tloc, tscale, tangle, mat); + invert_m4(mat); - for (j = 0; j < tmpibuf->y; j++) { - for (i = 0; i < tmpibuf->x; i++) { - float vec[3] = {i, j, 0}; + if (filter == TRACKING_FILTER_NEAREST) + interpolation = nearest_interpolation; + else if (filter == TRACKING_FILTER_BILINEAR) + interpolation = bilinear_interpolation; + else if (filter == TRACKING_FILTER_BICUBIC) + interpolation = bicubic_interpolation; + else + /* fallback to default interpolation method */ + interpolation = nearest_interpolation; - mul_v3_m4v3(vec, mat, vec); + /* This function is only used for display in clip editor and + * sequencer only, which would only benefit of using threads + * here. + * + * But need to keep an eye on this if the function will be + * used in other cases. + */ + #pragma omp parallel for if(tmpibuf->y > 128) + for (j = 0; j < tmpibuf->y; j++) { + int i; + for (i = 0; i < tmpibuf->x; i++) { + float vec[3] = {i, j, 0}; - interpolation(ibuf, tmpibuf, vec[0], vec[1], i, j); - } + mul_v3_m4v3(vec, mat, vec); + + interpolation(ibuf, tmpibuf, vec[0], vec[1], i, j); } } |