Primitive auto-crop (#1477).
[dcpomatic.git] / src / wx / simple_video_view.cc
index e54c8390e78ea9cd56483c159c214c21a16d536d..f866bd4a895a6789df53f5ba4d4da1bb04a3ac4e 100644 (file)
 #include "lib/dcpomatic_log.h"
 #include "lib/image.h"
 #include <dcp/util.h>
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
 #include <wx/wx.h>
+LIBDCP_ENABLE_WARNINGS
 #include <boost/bind/bind.hpp>
 
 
@@ -65,6 +68,8 @@ SimpleVideoView::paint ()
 {
         _state_timer.set("paint-panel");
        wxPaintDC dc (_panel);
+       auto scale = 1 / dpi_scale_factor (_panel);
+       dc.SetLogicalScale (scale, scale);
 
        auto const panel_size = _panel->GetSize ();
 
@@ -72,6 +77,7 @@ SimpleVideoView::paint ()
        if (!_image) {
                dc.Clear ();
        } else {
+               DCPOMATIC_ASSERT (_image->alignment() == Image::Alignment::COMPACT);
                out_size = _image->size();
                wxImage frame (out_size.width, out_size.height, _image->data()[0], true);
                wxBitmap frame_bitmap (frame);
@@ -113,6 +119,19 @@ SimpleVideoView::paint ()
                dc.DrawRectangle (subs->x * out_size.width, subs->y * out_size.height, subs->width * out_size.width, subs->height * out_size.height);
        }
 
+       if (_viewer->crop_guess()) {
+               wxPen p (crop_guess_colour(), 2);
+               dc.SetPen (p);
+               dc.SetBrush (*wxTRANSPARENT_BRUSH);
+               auto const crop_guess = _viewer->crop_guess().get();
+               dc.DrawRectangle (
+                       _inter_position.x + _inter_size.width * crop_guess.x,
+                       _inter_position.y + _inter_size.height * crop_guess.y,
+                       _inter_size.width * crop_guess.width,
+                       _inter_size.height * crop_guess.height
+                       );
+       }
+
         _state_timer.unset();
 }
 
@@ -188,7 +207,7 @@ void
 SimpleVideoView::update ()
 {
        if (!player_video().first) {
-               set_image (shared_ptr<Image>());
+               _image.reset ();
                refresh_panel ();
                return;
        }
@@ -221,9 +240,7 @@ SimpleVideoView::update ()
 
        _state_timer.set ("get image");
 
-       set_image (
-               player_video().first->image(bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::COMPACT, true)
-               );
+       _image = player_video().first->image(boost::bind(&PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, true);
 
        _state_timer.set ("ImageChanged");
        _viewer->image_changed (player_video().first);