Merge branch 'master' of ssh://git.carlh.net/home/carl/git/dcpomatic
authorCarl Hetherington <cth@carlh.net>
Tue, 16 Aug 2016 13:10:54 +0000 (14:10 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 16 Aug 2016 13:10:54 +0000 (14:10 +0100)
ChangeLog
src/tools/dcpomatic.cc
src/wx/video_waveform_dialog.cc
src/wx/video_waveform_dialog.h
src/wx/video_waveform_plot.cc
src/wx/video_waveform_plot.h

index 2ba295fd12de9abf7d5243c4f00012de465d899e..2440e7b90b9aba7836ff466aea089c45bf1bb5b5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2016-08-16  c.hetherington  <cth@carlh.net>
+
+       * Simple information on mouse position in the video waveform (part of #932).
+
 2016-08-15  Carl Hetherington  <cth@carlh.net>
 
        * Version 2.9.12 released.
index 1f320f088ec57be6c0aba504b78ae2b995d044a5..d4695f1fa08b04475dd4210a3ff7ee40c5b02601 100644 (file)
@@ -317,6 +317,8 @@ public:
                _film = film;
                _film_viewer->set_film (_film);
                _film_editor->set_film (_film);
+               delete _video_waveform_dialog;
+               _video_waveform_dialog = 0;
                set_menu_sensitivity ();
                Config::instance()->add_to_history (_film->directory ());
        }
@@ -649,7 +651,7 @@ private:
        void tools_video_waveform ()
        {
                if (!_video_waveform_dialog) {
-                       _video_waveform_dialog = new VideoWaveformDialog (this, _film_viewer);
+                       _video_waveform_dialog = new VideoWaveformDialog (this, _film, _film_viewer);
                }
 
                _video_waveform_dialog->Show ();
index e4b09b8eec0b2f9ecb24ddf012fbf3e0d143f81b..412ebf8bb7482a67625ae084a256220ee10fb706 100644 (file)
@@ -27,8 +27,9 @@
 
 using std::cout;
 using boost::bind;
+using boost::weak_ptr;
 
-VideoWaveformDialog::VideoWaveformDialog (wxWindow* parent, FilmViewer* viewer)
+VideoWaveformDialog::VideoWaveformDialog (wxWindow* parent, weak_ptr<const Film> film, FilmViewer* viewer)
        : wxDialog (
                parent,
                wxID_ANY,
@@ -56,7 +57,18 @@ VideoWaveformDialog::VideoWaveformDialog (wxWindow* parent, FilmViewer* viewer)
 
        overall_sizer->Add (controls, 0, wxALL | wxEXPAND, DCPOMATIC_SIZER_X_GAP);
 
-       _plot = new VideoWaveformPlot (this, _viewer);
+       wxBoxSizer* position = new wxBoxSizer (wxHORIZONTAL);
+       add_label_to_sizer (position, this, _("Image X position"), true);
+       _x_position = new wxStaticText (this, wxID_ANY, "");
+       _x_position->SetMinSize (wxSize (64, -1));
+       position->Add (_x_position, 0, wxALL, DCPOMATIC_SIZER_X_GAP);
+       add_label_to_sizer (position, this, _("component value"), true);
+       _value = new wxStaticText (this, wxID_ANY, "");
+       _value->SetMinSize (wxSize (64, -1));
+       position->Add (_value, 0, wxALL, DCPOMATIC_SIZER_X_GAP);
+       overall_sizer->Add (position, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP);
+
+       _plot = new VideoWaveformPlot (this, film, _viewer);
        overall_sizer->Add (_plot, 1, wxALL | wxEXPAND, 12);
 
 #ifdef DCPOMATIC_LINUX
@@ -71,8 +83,9 @@ VideoWaveformDialog::VideoWaveformDialog (wxWindow* parent, FilmViewer* viewer)
        overall_sizer->SetSizeHints (this);
 
        Bind (wxEVT_SHOW, bind (&VideoWaveformDialog::shown, this, _1));
-       _component->Bind  (wxEVT_COMMAND_CHOICE_SELECTED, bind (&VideoWaveformDialog::component_changed, this));
+       _component->Bind (wxEVT_COMMAND_CHOICE_SELECTED, bind (&VideoWaveformDialog::component_changed, this));
        _contrast->Bind (wxEVT_SCROLL_THUMBTRACK, bind (&VideoWaveformDialog::contrast_changed, this));
+       _plot->MouseMoved.connect (bind (&VideoWaveformDialog::mouse_moved, this, _1, _2, _3, _4));
 
        _component->SetSelection (0);
        _contrast->SetValue (32);
@@ -101,3 +114,19 @@ VideoWaveformDialog::contrast_changed ()
 {
        _plot->set_contrast (_contrast->GetValue ());
 }
+
+void
+VideoWaveformDialog::mouse_moved (int x1, int x2, int y1, int y2)
+{
+       if (x1 != x2) {
+               _x_position->SetLabel (wxString::Format ("%d-%d", x1, x2));
+       } else {
+               _x_position->SetLabel (wxString::Format ("%d", x1));
+       }
+
+       if (y1 != y2) {
+               _value->SetLabel (wxString::Format ("%d-%d", y1, y2));
+       } else {
+               _value->SetLabel (wxString::Format ("%d", y1));
+       }
+}
index c853d0cda0945012172abe2fead3bdf8e6c19436..aa134f7a5f9ad236cd7a48697914dd895dcd98a0 100644 (file)
 */
 
 #include <wx/wx.h>
+#include <boost/weak_ptr.hpp>
 
 class VideoWaveformPlot;
 class FilmViewer;
+class Film;
 
 class VideoWaveformDialog : public wxDialog
 {
 public:
-       VideoWaveformDialog (wxWindow* parent, FilmViewer* viewer);
+       VideoWaveformDialog (wxWindow* parent, boost::weak_ptr<const Film> film, FilmViewer* viewer);
 
 private:
        void shown (wxShowEvent &);
        void component_changed ();
        void contrast_changed ();
+       void mouse_moved (int x1, int x2, int y1, int y2);
 
        FilmViewer* _viewer;
        VideoWaveformPlot* _plot;
        wxChoice* _component;
        wxSlider* _contrast;
+       wxStaticText* _x_position;
+       wxStaticText* _value;
 };
index 794922bff190fcfff2c3cb244f13029efab1a278..ad0498057b8a0c5296a598316b41aa1e58610358 100644 (file)
 
 using std::cout;
 using std::min;
+using std::max;
 using std::string;
 using boost::weak_ptr;
 using boost::shared_ptr;
 using dcp::locale_convert;
 
 int const VideoWaveformPlot::_vertical_margin = 8;
+int const VideoWaveformPlot::_pixel_values = 4096;
+int const VideoWaveformPlot::_x_axis_width = 52;
 
-VideoWaveformPlot::VideoWaveformPlot (wxWindow* parent, FilmViewer* viewer)
+VideoWaveformPlot::VideoWaveformPlot (wxWindow* parent, weak_ptr<const Film> film, FilmViewer* viewer)
        : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)
+       , _film (film)
        , _dirty (true)
        , _enabled (false)
        , _component (0)
@@ -54,6 +58,7 @@ VideoWaveformPlot::VideoWaveformPlot (wxWindow* parent, FilmViewer* viewer)
 
        Bind (wxEVT_PAINT, boost::bind (&VideoWaveformPlot::paint, this));
        Bind (wxEVT_SIZE,  boost::bind (&VideoWaveformPlot::sized, this, _1));
+       Bind (wxEVT_MOTION, boost::bind (&VideoWaveformPlot::mouse_moved, this, _1));
 
        SetMinSize (wxSize (640, 512));
        SetBackgroundColour (wxColour (0, 0, 0));
@@ -78,7 +83,6 @@ VideoWaveformPlot::paint ()
                return;
        }
 
-       int const axis_x = 48;
        int const height = _waveform->size().height;
 
        gc->SetPen (wxPen (wxColour (255, 255, 255), 1, wxPENSTYLE_SOLID));
@@ -108,10 +112,10 @@ VideoWaveformPlot::paint ()
                wxGraphicsPath p = gc->CreatePath ();
                int const y = _vertical_margin + height - (i * height / label_gaps) - 1;
                p.MoveToPoint (label_width + 8, y);
-               p.AddLineToPoint (axis_x, y);
+               p.AddLineToPoint (_x_axis_width - 4, y);
                gc->StrokePath (p);
                int x = 4;
-               int const n = i * 4096 / label_gaps;
+               int const n = i * _pixel_values / label_gaps;
                if (n < 10) {
                        x += extra[0];
                } else if (n < 100) {
@@ -124,7 +128,7 @@ VideoWaveformPlot::paint ()
 
        wxImage waveform (_waveform->size().width, height, _waveform->data()[0], true);
        wxBitmap bitmap (waveform);
-       gc->DrawBitmap (bitmap, axis_x + 4, _vertical_margin, _waveform->size().width, height);
+       gc->DrawBitmap (bitmap, _x_axis_width, _vertical_margin, _waveform->size().width, height);
 
        delete gc;
 }
@@ -138,37 +142,36 @@ VideoWaveformPlot::create_waveform ()
                return;
        }
 
-       dcp::Size const size = _image->size();
-       _waveform.reset (new Image (AV_PIX_FMT_RGB24, dcp::Size (size.width, size.height), true));
+       dcp::Size const image_size = _image->size();
+       int const waveform_height = GetSize().GetHeight() - _vertical_margin * 2;
+       _waveform.reset (new Image (AV_PIX_FMT_RGB24, dcp::Size (image_size.width, waveform_height), true));
 
-       for (int x = 0; x < size.width; ++x) {
+       for (int x = 0; x < image_size.width; ++x) {
 
                /* Work out one vertical `slice' of waveform pixels.  Each value in
                   strip is the number of samples in image with the corresponding group of
                   values.
                */
-               int strip[size.height];
-               for (int i = 0; i < size.height; ++i) {
-                       strip[i] = 0;
-               }
+               int strip[waveform_height];
+               memset (strip, 0, waveform_height * sizeof(int));
 
                int* ip = _image->data (_component) + x;
-               for (int y = 0; y < size.height; ++y) {
-                       strip[*ip * size.height / 4096]++;
-                       ip += size.width;
+               for (int y = 0; y < image_size.height; ++y) {
+                       strip[*ip * waveform_height / _pixel_values]++;
+                       ip += image_size.width;
                }
 
                /* Copy slice into the waveform */
                uint8_t* wp = _waveform->data()[0] + x * 3;
-               for (int y = size.height - 1; y >= 0; --y) {
-                       wp[0] = wp[1] = wp[2] = min (255, (strip[y] * 255 / size.height) * _contrast);
+               for (int y = waveform_height - 1; y >= 0; --y) {
+                       wp[0] = wp[1] = wp[2] = min (255, (strip[y] * 255 / waveform_height) * _contrast);
                        wp += _waveform->stride()[0];
                }
        }
 
        _waveform = _waveform->scale (
-               dcp::Size (GetSize().GetWidth() - 32, GetSize().GetHeight() - _vertical_margin * 2),
-               dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB24, false, true
+               dcp::Size (GetSize().GetWidth() - _x_axis_width, waveform_height),
+               dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB24, false, false
                );
 }
 
@@ -221,3 +224,34 @@ VideoWaveformPlot::set_contrast (int b)
        _dirty = true;
        Refresh ();
 }
+
+void
+VideoWaveformPlot::mouse_moved (wxMouseEvent& ev)
+{
+       if (!_image) {
+               return;
+       }
+
+       if (_dirty) {
+               create_waveform ();
+               _dirty = false;
+       }
+
+       shared_ptr<const Film> film = _film.lock ();
+       if (!film) {
+               return;
+       }
+
+       dcp::Size const full = film->frame_size ();
+
+       double const xs = static_cast<double> (full.width) / _waveform->size().width;
+       int const x1 = max (0, min (full.width - 1, int (floor (ev.GetPosition().x - _x_axis_width - 0.5) * xs)));
+       int const x2 = max (0, min (full.width - 1, int (floor (ev.GetPosition().x - _x_axis_width + 0.5) * xs)));
+
+       double const ys = static_cast<double> (_pixel_values) / _waveform->size().height;
+       int const fy = _waveform->size().height - (ev.GetPosition().y - _vertical_margin);
+       int const y1 = max (0, min (_pixel_values - 1, int (floor (fy - 0.5) * ys)));
+       int const y2 = max (0, min (_pixel_values - 1, int (floor (fy + 0.5) * ys)));
+
+       MouseMoved (x1, x2, y1, y2);
+}
index c5cc498f6273a07bcf3e1482b258ee620762180f..7e9dbf70999691da6ca2ee793a2bae1c8814d3cc 100644 (file)
@@ -29,23 +29,33 @@ namespace dcp {
 
 class PlayerVideo;
 class Image;
+class Film;
 class FilmViewer;
 
 class VideoWaveformPlot : public wxPanel
 {
 public:
-       VideoWaveformPlot (wxWindow* parent, FilmViewer* viewer);
+       VideoWaveformPlot (wxWindow* parent, boost::weak_ptr<const Film> film, FilmViewer* viewer);
 
        void set_enabled (bool e);
        void set_component (int c);
        void set_contrast (int b);
 
+       /** Emitted when the mouse is moved over the waveform.  The parameters
+           are:
+           - (int, int): image x range
+           - (int, int): component value range
+       */
+       boost::signals2::signal<void (int, int, int, int)> MouseMoved;
+
 private:
        void paint ();
        void sized (wxSizeEvent &);
        void create_waveform ();
        void set_image (boost::weak_ptr<PlayerVideo>);
+       void mouse_moved (wxMouseEvent &);
 
+       boost::weak_ptr<const Film> _film;
        boost::shared_ptr<dcp::OpenJPEGImage> _image;
        boost::shared_ptr<const Image> _waveform;
        bool _dirty;
@@ -54,6 +64,8 @@ private:
        int _contrast;
 
        static int const _vertical_margin;
+       static int const _pixel_values;
+       static int const _x_axis_width;
 
        boost::signals2::connection _viewer_connection;
 };