Libmv: Fix wrong search area clamping in frame accessor
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 23 Oct 2014 09:39:55 +0000 (11:39 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 23 Oct 2014 09:39:55 +0000 (11:39 +0200)
Not sure who was that smart to make it wrong :)

Hopefully it'll fix the "magnetic" borders reported by Sebastian,
when the marker gets "attracted" by the frame bounds.

source/blender/blenkernel/intern/tracking_util.c

index 8b2e45fa09819aeff028bd26a44a7183d76b5bc7..f64840f25432f0adab7dd00ee93eda2523604544 100644 (file)
@@ -694,16 +694,18 @@ static ImBuf *accessor_get_ibuf(TrackingImageAccessor *accessor,
                 * the data we can.
                 */
                int clamped_origin_x = max_ii((int)region->min[0], 0),
-                       clamped_origin_y = max_ii((int)region->min[1], 0);
-               int clamped_width = min_ii(width, orig_ibuf->x - region->min[0] - 1),
-                       clamped_height = min_ii(height, orig_ibuf->y - region->min[1] - 1);
+                   clamped_origin_y = max_ii((int)region->min[1], 0);
+               int dst_offset_x = clamped_origin_x - (int)region->min[0],
+                   dst_offset_y = clamped_origin_y - (int)region->min[1];
+               int clamped_width = width - dst_offset_x,
+                   clamped_height = height - dst_offset_y;
 
                final_ibuf = IMB_allocImBuf(width, height, 32, IB_rectfloat);
 
                if (orig_ibuf->rect_float != NULL) {
                        IMB_rectcpy(final_ibuf, orig_ibuf,
-                                   0, 0,
-                                   region->min[0], region->min[1],
+                                   dst_offset_x, dst_offset_y,
+                                   clamped_origin_x, clamped_origin_y,
                                    clamped_width, clamped_height);
                }
                else {
@@ -717,8 +719,10 @@ static ImBuf *accessor_get_ibuf(TrackingImageAccessor *accessor,
                                for (x = 0; x < clamped_width; ++x) {
                                        int src_x = x + clamped_origin_x,
                                            src_y = y + clamped_origin_y;
-                                       int dst_index = (y * width + x) * 4,
-                                               src_index = (src_y * orig_ibuf->x + src_x) * 4;
+                                       int dst_x = x + dst_offset_x,
+                                           dst_y = y + dst_offset_y;
+                                       int dst_index = (dst_y * width + dst_x) * 4,
+                                           src_index = (src_y * orig_ibuf->x + src_x) * 4;
                                        rgba_uchar_to_float(final_ibuf->rect_float + dst_index,
                                                            (unsigned char *)orig_ibuf->rect +
                                                                             src_index);