Various bits mostly related to colour conversions.
[dcpomatic.git] / src / wx / video_panel.cc
index 47e32c5e812b03fcee4454d7536f5c2207c36bea..bb8476d63b7bbdf1d39624ac28f38b9f29ed887b 100644 (file)
 #include <wx/spinctrl.h>
 #include "lib/ratio.h"
 #include "lib/filter.h"
+#include "lib/ffmpeg_content.h"
+#include "lib/colour_conversion.h"
+#include "lib/config.h"
 #include "filter_dialog.h"
 #include "video_panel.h"
 #include "wx_util.h"
 #include "film_editor.h"
+#include "content_colour_conversion_dialog.h"
 
 using std::vector;
 using std::string;
 using std::pair;
+using std::cout;
+using std::list;
 using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
+using boost::bind;
+using boost::optional;
 
 VideoPanel::VideoPanel (FilmEditor* e)
        : FilmEditorPanel (e, _("Video"))
@@ -38,6 +46,12 @@ VideoPanel::VideoPanel (FilmEditor* e)
        _sizer->Add (grid, 0, wxALL, 8);
 
        int r = 0;
+
+       add_label_to_grid_bag_sizer (grid, this, _("Type"), true, wxGBPosition (r, 0));
+       _frame_type = new wxChoice (this, wxID_ANY);
+       grid->Add (_frame_type, wxGBPosition (r, 1));
+       ++r;
+       
        add_label_to_grid_bag_sizer (grid, this, _("Left crop"), true, wxGBPosition (r, 0));
        _left_crop = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
        grid->Add (_left_crop, wxGBPosition (r, 1));
@@ -63,24 +77,46 @@ VideoPanel::VideoPanel (FilmEditor* e)
        grid->Add (_ratio, wxGBPosition (r, 1));
        ++r;
 
-       _scaling_description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n"), wxDefaultPosition, wxDefaultSize);
-       grid->Add (_scaling_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
-       wxFont font = _scaling_description->GetFont();
-       font.SetStyle(wxFONTSTYLE_ITALIC);
-       font.SetPointSize(font.GetPointSize() - 1);
-       _scaling_description->SetFont(font);
-       ++r;
-
        {
                add_label_to_grid_bag_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0));
                wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
-               _filters = new wxStaticText (this, wxID_ANY, _("None"));
+
+               wxClientDC dc (this);
+               wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
+               size.SetHeight (-1);
+               
+               _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
                s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
                _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
                s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
                grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
        }
        ++r;
+       
+       {
+               add_label_to_grid_bag_sizer (grid, this, _("Colour conversion"), true, wxGBPosition (r, 0));
+               wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
+
+               wxClientDC dc (this);
+               wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
+               size.SetHeight (-1);
+               
+               _colour_conversion = new wxStaticText (this, wxID_ANY, wxT (""), wxDefaultPosition, size);
+
+               s->Add (_colour_conversion, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
+               _colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
+               s->Add (_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
+               grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
+       }
+       ++r;
+
+       _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
+       grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
+       wxFont font = _description->GetFont();
+       font.SetStyle(wxFONTSTYLE_ITALIC);
+       font.SetPointSize(font.GetPointSize() - 1);
+       _description->SetFont(font);
+       ++r;
 
        _left_crop->SetRange (0, 1024);
        _top_crop->SetRange (0, 1024);
@@ -93,18 +129,23 @@ VideoPanel::VideoPanel (FilmEditor* e)
                _ratio->Append (std_to_wx ((*i)->nickname ()));
        }
 
-       _ratio->Connect          (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED,  wxCommandEventHandler (VideoPanel::ratio_changed), 0, this);
-       _left_crop->Connect      (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (VideoPanel::left_crop_changed), 0, this);
-       _right_crop->Connect     (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (VideoPanel::right_crop_changed), 0, this);
-       _top_crop->Connect       (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (VideoPanel::top_crop_changed), 0, this);
-       _bottom_crop->Connect    (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (VideoPanel::bottom_crop_changed), 0, this);
-       _filters_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,   wxCommandEventHandler (VideoPanel::edit_filters_clicked), 0, this);
+       _frame_type->Append (_("2D"));
+       _frame_type->Append (_("3D left/right"));
+
+       _frame_type->Bind               (wxEVT_COMMAND_CHOICE_SELECTED,  boost::bind (&VideoPanel::frame_type_changed, this));
+       _left_crop->Bind                (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&VideoPanel::left_crop_changed, this));
+       _right_crop->Bind               (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&VideoPanel::right_crop_changed, this));
+       _top_crop->Bind                 (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&VideoPanel::top_crop_changed, this));
+       _bottom_crop->Bind              (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&VideoPanel::bottom_crop_changed, this));
+       _ratio->Bind                    (wxEVT_COMMAND_CHOICE_SELECTED,  boost::bind (&VideoPanel::ratio_changed, this));
+       _filters_button->Bind           (wxEVT_COMMAND_BUTTON_CLICKED,   boost::bind (&VideoPanel::edit_filters_clicked, this));
+       _colour_conversion_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED,   boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
 }
 
 
 /** Called when the left crop widget has been changed */
 void
-VideoPanel::left_crop_changed (wxCommandEvent &)
+VideoPanel::left_crop_changed ()
 {
        shared_ptr<VideoContent> c = _editor->selected_video_content ();
        if (!c) {
@@ -116,7 +157,7 @@ VideoPanel::left_crop_changed (wxCommandEvent &)
 
 /** Called when the right crop widget has been changed */
 void
-VideoPanel::right_crop_changed (wxCommandEvent &)
+VideoPanel::right_crop_changed ()
 {
        shared_ptr<VideoContent> c = _editor->selected_video_content ();
        if (!c) {
@@ -128,7 +169,7 @@ VideoPanel::right_crop_changed (wxCommandEvent &)
 
 /** Called when the top crop widget has been changed */
 void
-VideoPanel::top_crop_changed (wxCommandEvent &)
+VideoPanel::top_crop_changed ()
 {
        shared_ptr<VideoContent> c = _editor->selected_video_content ();
        if (!c) {
@@ -140,7 +181,7 @@ VideoPanel::top_crop_changed (wxCommandEvent &)
 
 /** Called when the bottom crop value has been changed */
 void
-VideoPanel::bottom_crop_changed (wxCommandEvent &)
+VideoPanel::bottom_crop_changed ()
 {
        shared_ptr<VideoContent> c = _editor->selected_video_content ();
        if (!c) {
@@ -155,7 +196,8 @@ VideoPanel::film_changed (Film::Property property)
 {
        switch (property) {
        case Film::CONTAINER:
-               setup_scaling_description ();
+       case Film::VIDEO_FRAME_RATE:
+               setup_description ();
                break;
        default:
                break;
@@ -167,13 +209,16 @@ VideoPanel::film_content_changed (shared_ptr<Content> c, int property)
 {
        shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (c);
        shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
-       
-       if (property == VideoContentProperty::VIDEO_CROP) {
+
+       if (property == VideoContentProperty::VIDEO_FRAME_TYPE) {
+               checked_set (_frame_type, vc ? vc->video_frame_type () : VIDEO_FRAME_TYPE_2D);
+               setup_description ();
+       } else if (property == VideoContentProperty::VIDEO_CROP) {
                checked_set (_left_crop,   vc ? vc->crop().left : 0);
                checked_set (_right_crop,  vc ? vc->crop().right        : 0);
                checked_set (_top_crop,    vc ? vc->crop().top  : 0);
                checked_set (_bottom_crop, vc ? vc->crop().bottom : 0);
-               setup_scaling_description ();
+               setup_description ();
        } else if (property == VideoContentProperty::VIDEO_RATIO) {
                if (vc) {
                        int n = 0;
@@ -192,7 +237,13 @@ VideoPanel::film_content_changed (shared_ptr<Content> c, int property)
                } else {
                        checked_set (_ratio, -1);
                }
-               setup_scaling_description ();
+               setup_description ();
+       } else if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
+               setup_description ();
+       } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
+               optional<size_t> preset = vc ? vc->colour_conversion().preset () : optional<size_t> ();
+               vector<PresetColourConversion> cc = Config::instance()->colour_conversions ();
+               _colour_conversion->SetLabel (preset ? std_to_wx (cc[preset.get()].name) : _("Custom"));
        } else if (property == FFmpegContentProperty::FILTERS) {
                if (fc) {
                        pair<string, string> p = Filter::ffmpeg_strings (fc->filters ());
@@ -208,7 +259,7 @@ VideoPanel::film_content_changed (shared_ptr<Content> c, int property)
 
 /** Called when the `Edit filters' button has been clicked */
 void
-VideoPanel::edit_filters_clicked (wxCommandEvent &)
+VideoPanel::edit_filters_clicked ()
 {
        shared_ptr<Content> c = _editor->selected_content ();
        if (!c) {
@@ -227,11 +278,11 @@ VideoPanel::edit_filters_clicked (wxCommandEvent &)
 }
 
 void
-VideoPanel::setup_scaling_description ()
+VideoPanel::setup_description ()
 {
        shared_ptr<VideoContent> vc = _editor->selected_video_content ();
        if (!vc) {
-               _scaling_description->SetLabel ("");
+               _description->SetLabel ("");
                return;
        }
 
@@ -241,16 +292,16 @@ VideoPanel::setup_scaling_description ()
 
        if (vc->video_size().width && vc->video_size().height) {
                d << wxString::Format (
-                       _("Original video is %dx%d (%.2f:1)\n"),
-                       vc->video_size().width, vc->video_size().height,
-                       float (vc->video_size().width) / vc->video_size().height
+                       _("Content video is %dx%d (%.2f:1)\n"),
+                       vc->video_size_after_3d_split().width, vc->video_size_after_3d_split().height,
+                       float (vc->video_size_after_3d_split().width) / vc->video_size_after_3d_split().height
                        );
                ++lines;
        }
 
        Crop const crop = vc->crop ();
        if ((crop.left || crop.right || crop.top || crop.bottom) && vc->video_size() != libdcp::Size (0, 0)) {
-               libdcp::Size cropped = vc->video_size ();
+               libdcp::Size cropped = vc->video_size_after_3d_split ();
                cropped.width -= crop.left + crop.right;
                cropped.height -= crop.top + crop.bottom;
                d << wxString::Format (
@@ -283,16 +334,23 @@ VideoPanel::setup_scaling_description ()
                }
        }
 
-       for (int i = lines; i < 4; ++i) {
+       d << wxString::Format (_("Content frame rate %.4f\n"), vc->video_frame_rate ());
+       ++lines;
+       FrameRateConversion frc (vc->video_frame_rate(), _editor->film()->video_frame_rate ());
+       d << frc.description << "\n";
+       ++lines;
+
+       for (int i = lines; i < 6; ++i) {
                d << wxT ("\n ");
        }
 
-       _scaling_description->SetLabel (d);
+       _description->SetLabel (d);
+       _sizer->Layout ();
 }
 
 
 void
-VideoPanel::ratio_changed (wxCommandEvent &)
+VideoPanel::ratio_changed ()
 {
        if (!_editor->film ()) {
                return;
@@ -307,3 +365,29 @@ VideoPanel::ratio_changed (wxCommandEvent &)
                vc->set_ratio (ratios[n]);
        }
 }
+
+void
+VideoPanel::frame_type_changed ()
+{
+       shared_ptr<VideoContent> vc = _editor->selected_video_content ();
+       if (vc) {
+               vc->set_video_frame_type (static_cast<VideoFrameType> (_frame_type->GetSelection ()));
+       }
+}
+
+void
+VideoPanel::edit_colour_conversion_clicked ()
+{
+       shared_ptr<VideoContent> vc = _editor->selected_video_content ();
+       if (!vc) {
+               return;
+       }
+
+       ColourConversion conversion = vc->colour_conversion ();
+       ContentColourConversionDialog* d = new ContentColourConversionDialog (this);
+       d->set (conversion);
+       d->ShowModal ();
+
+       vc->set_colour_conversion (d->get ());
+       d->Destroy ();
+}