diff --git a/src/zm_stream.cpp b/src/zm_stream.cpp index 33619cfe48..b08587386f 100644 --- a/src/zm_stream.cpp +++ b/src/zm_stream.cpp @@ -306,8 +306,9 @@ Image *StreamBase::prepareImage(Image *image, int pre_scaled_by) { } Debug(3, "Cropping to %d,%d -> %d,%d %dx%din blown up image", lo_x, lo_y, hi_x, hi_y, hi_x-lo_x, hi_y-lo_y); - // Scaled back to base_image dimensions - last_crop = Box({lo_x*ZM_SCALE_BASE/cur_zoom, lo_y*ZM_SCALE_BASE/cur_zoom}, {hi_x*ZM_SCALE_BASE/cur_zoom, hi_y*ZM_SCALE_BASE/cur_zoom}); + // Scaled back to base_image dimensions; kept while the view is unchanged, since redoing it rounds towards 0,0. + if ((cur_zoom != last_zoom) || (cur_x != last_x) || (cur_y != last_y)) + last_crop = Box({lo_x*ZM_SCALE_BASE/cur_zoom, lo_y*ZM_SCALE_BASE/cur_zoom}, {hi_x*ZM_SCALE_BASE/cur_zoom, hi_y*ZM_SCALE_BASE/cur_zoom}); last_crop_width = base_image_width; last_crop_height = base_image_height; diff --git a/tests/zm_stream.cpp b/tests/zm_stream.cpp index 76fbc34d77..a72df021b8 100644 --- a/tests/zm_stream.cpp +++ b/tests/zm_stream.cpp @@ -372,6 +372,23 @@ TEST_CASE("StreamBase::prepareImage starts a new zoom from the whole frame", "[S CHECK(used.crop().Hi().y_ == expected.Hi().y_); } +TEST_CASE("StreamBase::prepareImage keeps a zoomed view still from frame to frame", "[StreamBase]") { + EnsureImageInit(); + Image frame(640, 480, ZM_COLOUR_RGB32, ZM_SUBPIX_ORDER_RGBA); + TestStream stream; + stream.setView(ZM_SCALE_BASE, 150); + stream.setClick(100, 100); + stream.prepare(&frame); + const Box first = stream.crop(); + + for (int i = 0; i < 30; i++) stream.prepare(&frame); + + CHECK(stream.crop().Lo().x_ == first.Lo().x_); + CHECK(stream.crop().Lo().y_ == first.Lo().y_); + CHECK(stream.crop().Hi().x_ == first.Hi().x_); + CHECK(stream.crop().Hi().y_ == first.Hi().y_); +} + TEST_CASE("StreamBase::preScaleDimensions") { const int kWidth = 640; const int kHeight = 480;