From: Carl Hetherington Date: Tue, 30 Sep 2014 08:33:33 +0000 (+0100) Subject: Basic video fade support. X-Git-Tag: v2.0.48~574 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=a4d8e5d24beddb719180e75f1047ae317bef85a4 Basic video fade support. --- diff --git a/src/lib/image.cc b/src/lib/image.cc index 0b06d39b1..0da2d1e48 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -717,3 +717,110 @@ operator== (Image const & a, Image const & b) return true; } + +void +Image::fade (float f) +{ + switch (_pixel_format) { + case PIX_FMT_YUV420P: + case PIX_FMT_YUV422P: + case PIX_FMT_YUV444P: + case PIX_FMT_YUV411P: + case PIX_FMT_YUVJ420P: + case PIX_FMT_YUVJ422P: + case PIX_FMT_YUVJ444P: + case PIX_FMT_RGB24: + case PIX_FMT_ARGB: + case PIX_FMT_RGBA: + case PIX_FMT_ABGR: + case PIX_FMT_BGRA: + case PIX_FMT_RGB555LE: + /* 8-bit */ + for (int c = 0; c < 3; ++c) { + uint8_t* p = data()[c]; + for (int y = 0; y < lines(c); ++y) { + uint8_t* q = p; + for (int x = 0; x < line_size()[c]; ++x) { + *q = int (float (*q) * f); + ++q; + } + p += stride()[c]; + } + } + break; + + case PIX_FMT_YUV422P9LE: + case PIX_FMT_YUV444P9LE: + case PIX_FMT_YUV422P10LE: + case PIX_FMT_YUV444P10LE: + case PIX_FMT_YUV422P16LE: + case PIX_FMT_YUV444P16LE: + case AV_PIX_FMT_YUVA420P9LE: + case AV_PIX_FMT_YUVA422P9LE: + case AV_PIX_FMT_YUVA444P9LE: + case AV_PIX_FMT_YUVA420P10LE: + case AV_PIX_FMT_YUVA422P10LE: + case AV_PIX_FMT_YUVA444P10LE: + /* 16-bit little-endian */ + for (int c = 0; c < 3; ++c) { + int const stride_pixels = stride()[c] / 2; + int const line_size_pixels = line_size()[c] / 2; + uint16_t* p = reinterpret_cast (data()[c]); + for (int y = 0; y < lines(c); ++y) { + uint16_t* q = p; + for (int x = 0; x < line_size_pixels; ++x) { + *q = int (float (*q) * f); + ++q; + } + p += stride_pixels; + } + } + break; + + case PIX_FMT_YUV422P9BE: + case PIX_FMT_YUV444P9BE: + case PIX_FMT_YUV444P10BE: + case PIX_FMT_YUV422P10BE: + case AV_PIX_FMT_YUVA420P9BE: + case AV_PIX_FMT_YUVA422P9BE: + case AV_PIX_FMT_YUVA444P9BE: + case AV_PIX_FMT_YUVA420P10BE: + case AV_PIX_FMT_YUVA422P10BE: + case AV_PIX_FMT_YUVA444P10BE: + case AV_PIX_FMT_YUVA420P16BE: + case AV_PIX_FMT_YUVA422P16BE: + case AV_PIX_FMT_YUVA444P16BE: + /* 16-bit big-endian */ + for (int c = 0; c < 3; ++c) { + int const stride_pixels = stride()[c] / 2; + int const line_size_pixels = line_size()[c] / 2; + uint16_t* p = reinterpret_cast (data()[c]); + for (int y = 0; y < lines(c); ++y) { + uint16_t* q = p; + for (int x = 0; x < line_size_pixels; ++x) { + *q = swap_16 (int (float (swap_16 (*q)) * f)); + ++q; + } + p += stride_pixels; + } + } + break; + + case PIX_FMT_UYVY422: + { + int const Y = lines(0); + int const X = line_size()[0]; + uint8_t* p = data()[0]; + for (int y = 0; y < Y; ++y) { + for (int x = 0; x < X; ++x) { + *p = int (float (*p) * f); + ++p; + } + } + break; + } + + default: + throw PixelFormatError ("fade()", _pixel_format); + } +} diff --git a/src/lib/image.h b/src/lib/image.h index e1f8d0ddd..172250eb1 100644 --- a/src/lib/image.h +++ b/src/lib/image.h @@ -67,6 +67,7 @@ public: void make_transparent (); void alpha_blend (boost::shared_ptr image, Position pos); void copy (boost::shared_ptr image, Position pos); + void fade (float); void read_from_socket (boost::shared_ptr); void write_to_socket (boost::shared_ptr) const; diff --git a/src/lib/magick_image_proxy.cc b/src/lib/magick_image_proxy.cc index c3cfc422c..e5265187f 100644 --- a/src/lib/magick_image_proxy.cc +++ b/src/lib/magick_image_proxy.cc @@ -119,7 +119,7 @@ MagickImageProxy::image () const delete magick_image; LOG_TIMING ("[%1] MagickImageProxy completes decode and convert of %2 bytes", boost::this_thread::get_id(), _blob.length()); - + return _image; } diff --git a/src/lib/player.cc b/src/lib/player.cc index f83c9563b..5961292ca 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -300,6 +300,7 @@ Player::black_player_video_frame (DCPTime time) const shared_ptr (new RawImageProxy (_black_image, _film->log ())), time, Crop (), + optional (), _video_container_size, _video_container_size, Scaler::from_id ("bicubic"), @@ -356,6 +357,7 @@ Player::get_video (DCPTime time, bool accurate) i->image, content_video_to_dcp (piece, i->frame), content->crop (), + content->fade (i->frame), image_size, _video_container_size, _film->scaler(), diff --git a/src/lib/player_video.cc b/src/lib/player_video.cc index aab90a806..2feb52f42 100644 --- a/src/lib/player_video.cc +++ b/src/lib/player_video.cc @@ -34,6 +34,7 @@ PlayerVideo::PlayerVideo ( shared_ptr in, DCPTime time, Crop crop, + boost::optional fade, dcp::Size inter_size, dcp::Size out_size, Scaler const * scaler, @@ -44,6 +45,7 @@ PlayerVideo::PlayerVideo ( : _in (in) , _time (time) , _crop (crop) + , _fade (fade) , _inter_size (inter_size) , _out_size (out_size) , _scaler (scaler) @@ -58,6 +60,7 @@ PlayerVideo::PlayerVideo (shared_ptr node, shared_ptr socket { _time = DCPTime (node->number_child ("Time")); _crop = Crop (node); + _fade = node->optional_number_child ("Fade"); _inter_size = dcp::Size (node->number_child ("InterWidth"), node->number_child ("InterHeight")); _out_size = dcp::Size (node->number_child ("OutWidth"), node->number_child ("OutHeight")); @@ -115,6 +118,10 @@ PlayerVideo::image (bool burn_subtitle) const out->alpha_blend (_subtitle.image, _subtitle.position); } + if (_fade) { + out->fade (_fade.get ()); + } + return out; } @@ -123,6 +130,9 @@ PlayerVideo::add_metadata (xmlpp::Node* node, bool send_subtitles) const { node->add_child("Time")->add_child_text (raw_convert (_time.get ())); _crop.as_xml (node); + if (_fade) { + node->add_child("Fade")->add_child_text (raw_convert (_fade.get ())); + } _in->add_metadata (node->add_child ("In")); node->add_child("InterWidth")->add_child_text (raw_convert (_inter_size.width)); node->add_child("InterHeight")->add_child_text (raw_convert (_inter_size.height)); @@ -184,6 +194,7 @@ PlayerVideo::same (shared_ptr other) const { if (_in != other->_in || _crop != other->_crop || + _fade.get_value_or(0) != other->_fade.get_value_or(0) || _inter_size != other->_inter_size || _out_size != other->_out_size || _scaler != other->_scaler || diff --git a/src/lib/player_video.h b/src/lib/player_video.h index 59894a227..0f5e83b10 100644 --- a/src/lib/player_video.h +++ b/src/lib/player_video.h @@ -37,7 +37,19 @@ class EncodedData; class PlayerVideo { public: - PlayerVideo (boost::shared_ptr, DCPTime, Crop, dcp::Size, dcp::Size, Scaler const *, Eyes, Part, ColourConversion); + PlayerVideo ( + boost::shared_ptr, + DCPTime, + Crop, + boost::optional, + dcp::Size, + dcp::Size, + Scaler const *, + Eyes, + Part, + ColourConversion + ); + PlayerVideo (boost::shared_ptr, boost::shared_ptr, boost::shared_ptr); void set_subtitle (PositionImage); @@ -76,6 +88,7 @@ private: boost::shared_ptr _in; DCPTime _time; Crop _crop; + boost::optional _fade; dcp::Size _inter_size; dcp::Size _out_size; Scaler const * _scaler; diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index b5097b355..ba656e4c2 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -44,6 +44,8 @@ int const VideoContentProperty::VIDEO_FRAME_TYPE = 2; int const VideoContentProperty::VIDEO_CROP = 3; int const VideoContentProperty::VIDEO_SCALE = 4; int const VideoContentProperty::COLOUR_CONVERSION = 5; +int const VideoContentProperty::VIDEO_FADE_IN = 6; +int const VideoContentProperty::VIDEO_FADE_OUT = 7; using std::string; using std::setprecision; @@ -116,6 +118,10 @@ VideoContent::VideoContent (shared_ptr f, cxml::ConstNodePtr node, i } _colour_conversion = ColourConversion (node->node_child ("ColourConversion")); + if (version >= 32) { + _fade_in = ContentTime (node->number_child ("FadeIn")); + _fade_out = ContentTime (node->number_child ("FadeOut")); + } } VideoContent::VideoContent (shared_ptr f, vector > c) @@ -152,6 +158,10 @@ VideoContent::VideoContent (shared_ptr f, vector throw JoinError (_("Content to be joined must have the same colour conversion.")); } + if (vc->fade_in() != ref->fade_in() || vc->fade_out() != ref->fade_out()) { + throw JoinError (_("Content to be joined must have the same fades.")); + } + _video_length += vc->video_length (); } @@ -161,6 +171,8 @@ VideoContent::VideoContent (shared_ptr f, vector _crop = ref->crop (); _scale = ref->scale (); _colour_conversion = ref->colour_conversion (); + _fade_in = ref->fade_in (); + _fade_out = ref->fade_out (); } void @@ -175,6 +187,8 @@ VideoContent::as_xml (xmlpp::Node* node) const _crop.as_xml (node); _scale.as_xml (node->add_child("Scale")); _colour_conversion.as_xml (node->add_child("ColourConversion")); + node->add_child("FadeIn")->add_child_text (raw_convert (_fade_in.get ())); + node->add_child("FadeOut")->add_child_text (raw_convert (_fade_out.get ())); } void @@ -372,6 +386,28 @@ VideoContent::set_colour_conversion (ColourConversion c) signal_changed (VideoContentProperty::COLOUR_CONVERSION); } +void +VideoContent::set_fade_in (ContentTime t) +{ + { + boost::mutex::scoped_lock lm (_mutex); + _fade_in = t; + } + + signal_changed (VideoContentProperty::VIDEO_FADE_IN); +} + +void +VideoContent::set_fade_out (ContentTime t) +{ + { + boost::mutex::scoped_lock lm (_mutex); + _fade_out = t; + } + + signal_changed (VideoContentProperty::VIDEO_FADE_OUT); +} + /** @return Video size after 3D split and crop */ dcp::Size VideoContent::video_size_after_crop () const @@ -431,3 +467,19 @@ VideoContent::set_video_frame_rate (float r) signal_changed (VideoContentProperty::VIDEO_FRAME_RATE); } +optional +VideoContent::fade (VideoFrame f) const +{ + assert (f >= 0); + + if (f < fade_in().frames (video_frame_rate ())) { + return float (f) / _fade_in.frames (video_frame_rate ()); + } + + VideoFrame fade_out_start = ContentTime (video_length() - fade_out()).frames (video_frame_rate ()); + if (f >= fade_out_start) { + return 1 - float (f - fade_out_start) / fade_out().frames (video_frame_rate ()); + } + + return optional (); +} diff --git a/src/lib/video_content.h b/src/lib/video_content.h index b3c81d9c3..e88fb0227 100644 --- a/src/lib/video_content.h +++ b/src/lib/video_content.h @@ -36,6 +36,8 @@ public: static int const VIDEO_CROP; static int const VIDEO_SCALE; static int const COLOUR_CONVERSION; + static int const VIDEO_FADE_IN; + static int const VIDEO_FADE_OUT; }; class VideoContent : public virtual Content @@ -88,6 +90,9 @@ public: void set_scale (VideoContentScale); void set_colour_conversion (ColourConversion); + + void set_fade_in (ContentTime); + void set_fade_out (ContentTime); VideoFrameType video_frame_type () const { boost::mutex::scoped_lock lm (_mutex); @@ -130,11 +135,23 @@ public: return _colour_conversion; } + ContentTime fade_in () const { + boost::mutex::scoped_lock lm (_mutex); + return _fade_in; + } + + ContentTime fade_out () const { + boost::mutex::scoped_lock lm (_mutex); + return _fade_out; + } + dcp::Size video_size_after_3d_split () const; dcp::Size video_size_after_crop () const; ContentTime dcp_time_to_content_time (DCPTime) const; + boost::optional fade (VideoFrame) const; + void scale_and_crop_to_fit_width (); void scale_and_crop_to_fit_height (); @@ -157,6 +174,8 @@ private: Crop _crop; VideoContentScale _scale; ColourConversion _colour_conversion; + ContentTime _fade_in; + ContentTime _fade_out; }; #endif diff --git a/src/lib/video_decoder.cc b/src/lib/video_decoder.cc index 5dd078553..64c66ea55 100644 --- a/src/lib/video_decoder.cc +++ b/src/lib/video_decoder.cc @@ -19,12 +19,14 @@ #include "video_decoder.h" #include "image.h" +#include "image_proxy.h" #include "content_video.h" #include "i18n.h" using std::cout; using std::list; +using std::max; using boost::shared_ptr; using boost::optional; diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index 01aa0158b..d08a11ea9 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -191,12 +191,6 @@ public: Bind (wxEVT_CLOSE_WINDOW, boost::bind (&Frame::close, this, _1)); - wxAcceleratorEntry accel[1]; - accel[0].Set (wxACCEL_CTRL, static_cast('A'), ID_add_file); - Bind (wxEVT_MENU, boost::bind (&ContentPanel::add_file_clicked, _film_editor->content_panel()), ID_add_file); - wxAcceleratorTable accel_table (1, accel); - SetAcceleratorTable (accel_table); - /* Use a panel as the only child of the Frame so that we avoid the dark-grey background on Windows. */ @@ -222,6 +216,12 @@ public: JobManager::instance()->ActiveJobsChanged.connect (boost::bind (&Frame::set_menu_sensitivity, this)); overall_panel->SetSizer (main_sizer); + + wxAcceleratorEntry accel[1]; + accel[0].Set (wxACCEL_CTRL, static_cast('A'), ID_add_file); + Bind (wxEVT_MENU, boost::bind (&ContentPanel::add_file_clicked, _film_editor->content_panel()), ID_add_file); + wxAcceleratorTable accel_table (1, accel); + SetAcceleratorTable (accel_table); } void new_film (boost::filesystem::path path) diff --git a/src/wx/content_widget.h b/src/wx/content_widget.h index bbe160399..b4d06286e 100644 --- a/src/wx/content_widget.h +++ b/src/wx/content_widget.h @@ -103,11 +103,12 @@ public: } /** Add this widget to a wxGridBagSizer */ - void add (wxGridBagSizer* sizer, wxGBPosition position) + void add (wxGridBagSizer* sizer, wxGBPosition position, wxGBSpan span = wxDefaultSpan) { _sizer = sizer; _position = position; - _sizer->Add (_wrapped, _position); + _span = span; + _sizer->Add (_wrapped, _position, _span); } /** Update the view from the model */ @@ -151,7 +152,7 @@ private: _sizer->Detach (_button); _button->Hide (); - _sizer->Add (_wrapped, _position); + _sizer->Add (_wrapped, _position, _span); _wrapped->Show (); _sizer->Layout (); } @@ -165,7 +166,7 @@ private: _wrapped->Hide (); _sizer->Detach (_wrapped); _button->Show (); - _sizer->Add (_button, _position); + _sizer->Add (_button, _position, _span); _sizer->Layout (); } @@ -187,6 +188,7 @@ private: T* _wrapped; wxGridBagSizer* _sizer; wxGBPosition _position; + wxGBSpan _span; wxButton* _button; List _content; int _property; diff --git a/src/wx/timecode.cc b/src/wx/timecode.cc index 07cb0be65..bd0a182c2 100644 --- a/src/wx/timecode.cc +++ b/src/wx/timecode.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington + Copyright (C) 2013-2014 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,16 +17,16 @@ */ -#include #include "lib/util.h" #include "timecode.h" #include "wx_util.h" +#include using std::string; using std::cout; using boost::lexical_cast; -Timecode::Timecode (wxWindow* parent) +TimecodeBase::TimecodeBase (wxWindow* parent) : wxPanel (parent) { wxClientDC dc (parent); @@ -69,11 +69,11 @@ Timecode::Timecode (wxWindow* parent) _fixed = add_label_to_sizer (_sizer, this, wxT ("42"), false); - _hours->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&Timecode::changed, this)); - _minutes->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&Timecode::changed, this)); - _seconds->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&Timecode::changed, this)); - _frames->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&Timecode::changed, this)); - _set_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&Timecode::set_clicked, this)); + _hours->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimecodeBase::changed, this)); + _minutes->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimecodeBase::changed, this)); + _seconds->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimecodeBase::changed, this)); + _frames->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimecodeBase::changed, this)); + _set_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimecodeBase::set_clicked, this)); _set_button->Enable (false); @@ -83,40 +83,7 @@ Timecode::Timecode (wxWindow* parent) } void -Timecode::set (DCPTime t, int fps) -{ - int h; - int m; - int s; - int f; - t.split (fps, h, m, s, f); - - checked_set (_hours, lexical_cast (h)); - checked_set (_minutes, lexical_cast (m)); - checked_set (_seconds, lexical_cast (s)); - checked_set (_frames, lexical_cast (f)); - - _fixed->SetLabel (std_to_wx (t.timecode (fps))); -} - -DCPTime -Timecode::get (int fps) const -{ - DCPTime t; - string const h = wx_to_std (_hours->GetValue ()); - t += DCPTime::from_seconds (lexical_cast (h.empty() ? "0" : h) * 3600); - string const m = wx_to_std (_minutes->GetValue()); - t += DCPTime::from_seconds (lexical_cast (m.empty() ? "0" : m) * 60); - string const s = wx_to_std (_seconds->GetValue()); - t += DCPTime::from_seconds (lexical_cast (s.empty() ? "0" : s)); - string const f = wx_to_std (_frames->GetValue()); - t += DCPTime::from_seconds (lexical_cast (f.empty() ? "0" : f) / fps); - - return t; -} - -void -Timecode::clear () +TimecodeBase::clear () { checked_set (_hours, ""); checked_set (_minutes, ""); @@ -126,20 +93,20 @@ Timecode::clear () } void -Timecode::changed () +TimecodeBase::changed () { _set_button->Enable (true); } void -Timecode::set_clicked () +TimecodeBase::set_clicked () { Changed (); _set_button->Enable (false); } void -Timecode::set_editable (bool e) +TimecodeBase::set_editable (bool e) { _editable->Show (e); _fixed->Show (!e); diff --git a/src/wx/timecode.h b/src/wx/timecode.h index 72b00ddeb..7a34b80fe 100644 --- a/src/wx/timecode.h +++ b/src/wx/timecode.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington + Copyright (C) 2013-2014 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,24 +17,27 @@ */ -#include -#include +#ifndef DCPOMATIC_WX_TIMECODE_H +#define DCPOMATIC_WX_TIMECODE_H + +#include "wx_util.h" #include "lib/types.h" +#include +#include +#include -class Timecode : public wxPanel +class TimecodeBase : public wxPanel { public: - Timecode (wxWindow *); + TimecodeBase (wxWindow *); - void set (DCPTime, int); - DCPTime get (int) const; void clear (); void set_editable (bool); boost::signals2::signal Changed; -private: +protected: void changed (); void set_clicked (); @@ -48,3 +51,46 @@ private: wxStaticText* _fixed; }; +template +class Timecode : public TimecodeBase +{ +public: + Timecode (wxWindow* parent) + : TimecodeBase (parent) + { + + } + + void set (T t, int fps) + { + int h; + int m; + int s; + int f; + t.split (fps, h, m, s, f); + + checked_set (_hours, boost::lexical_cast (h)); + checked_set (_minutes, boost::lexical_cast (m)); + checked_set (_seconds, boost::lexical_cast (s)); + checked_set (_frames, boost::lexical_cast (f)); + + _fixed->SetLabel (std_to_wx (t.timecode (fps))); + } + + T get (int fps) const + { + T t; + std::string const h = wx_to_std (_hours->GetValue ()); + t += T::from_seconds (boost::lexical_cast (h.empty() ? "0" : h) * 3600); + std::string const m = wx_to_std (_minutes->GetValue()); + t += T::from_seconds (boost::lexical_cast (m.empty() ? "0" : m) * 60); + std::string const s = wx_to_std (_seconds->GetValue()); + t += T::from_seconds (boost::lexical_cast (s.empty() ? "0" : s)); + std::string const f = wx_to_std (_frames->GetValue()); + t += T::from_seconds (boost::lexical_cast (f.empty() ? "0" : f) / fps); + + return t; + } +}; + +#endif diff --git a/src/wx/timing_panel.cc b/src/wx/timing_panel.cc index 27d5b9cd3..0f86a3f3f 100644 --- a/src/wx/timing_panel.cc +++ b/src/wx/timing_panel.cc @@ -40,19 +40,19 @@ TimingPanel::TimingPanel (ContentPanel* p) _sizer->Add (grid, 0, wxALL, 8); add_label_to_sizer (grid, this, _("Position"), true); - _position = new Timecode (this); + _position = new Timecode (this); grid->Add (_position); add_label_to_sizer (grid, this, _("Full length"), true); - _full_length = new Timecode (this); + _full_length = new Timecode (this); grid->Add (_full_length); add_label_to_sizer (grid, this, _("Trim from start"), true); - _trim_start = new Timecode (this); + _trim_start = new Timecode (this); grid->Add (_trim_start); add_label_to_sizer (grid, this, _("Trim from end"), true); - _trim_end = new Timecode (this); + _trim_end = new Timecode (this); grid->Add (_trim_end); add_label_to_sizer (grid, this, _("Play length"), true); - _play_length = new Timecode (this); + _play_length = new Timecode (this); grid->Add (_play_length); { diff --git a/src/wx/timing_panel.h b/src/wx/timing_panel.h index b531db551..00b7f84e7 100644 --- a/src/wx/timing_panel.h +++ b/src/wx/timing_panel.h @@ -18,8 +18,7 @@ */ #include "content_sub_panel.h" - -class Timecode; +#include "timecode.h" class TimingPanel : public ContentSubPanel { @@ -38,11 +37,11 @@ private: void video_frame_rate_changed (); void set_video_frame_rate (); - Timecode* _position; - Timecode* _full_length; - Timecode* _trim_start; - Timecode* _trim_end; - Timecode* _play_length; + Timecode* _position; + Timecode* _full_length; + Timecode* _trim_start; + Timecode* _trim_end; + Timecode* _play_length; wxTextCtrl* _video_frame_rate; wxButton* _set_video_frame_rate; }; diff --git a/src/wx/video_panel.cc b/src/wx/video_panel.cc index a5d197c2a..a8510cbba 100644 --- a/src/wx/video_panel.cc +++ b/src/wx/video_panel.cc @@ -37,6 +37,7 @@ using std::string; using std::pair; using std::cout; using std::list; +using std::set; using boost::shared_ptr; using boost::dynamic_pointer_cast; using boost::bind; @@ -82,7 +83,7 @@ VideoPanel::VideoPanel (ContentPanel* p) &caster, &caster ); - _frame_type->add (grid, wxGBPosition (r, 1)); + _frame_type->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2)); ++r; add_label_to_grid_bag_sizer (grid, this, _("Left crop"), true, wxGBPosition (r, 0)); @@ -94,9 +95,8 @@ VideoPanel::VideoPanel (ContentPanel* p) boost::mem_fn (&VideoContent::set_left_crop) ); _left_crop->add (grid, wxGBPosition (r, 1)); - ++r; - add_label_to_grid_bag_sizer (grid, this, _("Right crop"), true, wxGBPosition (r, 0)); + add_label_to_grid_bag_sizer (grid, this, _("Right crop"), true, wxGBPosition (r, 2)); _right_crop = new ContentSpinCtrl ( this, new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)), @@ -104,7 +104,8 @@ VideoPanel::VideoPanel (ContentPanel* p) boost::mem_fn (&VideoContent::right_crop), boost::mem_fn (&VideoContent::set_right_crop) ); - _right_crop->add (grid, wxGBPosition (r, 1)); + _right_crop->add (grid, wxGBPosition (r, 3)); + ++r; add_label_to_grid_bag_sizer (grid, this, _("Top crop"), true, wxGBPosition (r, 0)); @@ -115,10 +116,9 @@ VideoPanel::VideoPanel (ContentPanel* p) boost::mem_fn (&VideoContent::top_crop), boost::mem_fn (&VideoContent::set_top_crop) ); - _top_crop->add (grid, wxGBPosition (r,1 )); - ++r; + _top_crop->add (grid, wxGBPosition (r, 1)); - add_label_to_grid_bag_sizer (grid, this, _("Bottom crop"), true, wxGBPosition (r, 0)); + add_label_to_grid_bag_sizer (grid, this, _("Bottom crop"), true, wxGBPosition (r, 2)); _bottom_crop = new ContentSpinCtrl ( this, new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)), @@ -126,9 +126,20 @@ VideoPanel::VideoPanel (ContentPanel* p) boost::mem_fn (&VideoContent::bottom_crop), boost::mem_fn (&VideoContent::set_bottom_crop) ); - _bottom_crop->add (grid, wxGBPosition (r, 1)); + _bottom_crop->add (grid, wxGBPosition (r, 3)); + ++r; + add_label_to_grid_bag_sizer (grid, this, _("Fade in"), true, wxGBPosition (r, 0)); + _fade_in = new Timecode (this); + grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3)); + ++r; + + add_label_to_grid_bag_sizer (grid, this, _("Fade out"), true, wxGBPosition (r, 0)); + _fade_out = new Timecode (this); + grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3)); + ++r; + add_label_to_grid_bag_sizer (grid, this, _("Scale to"), true, wxGBPosition (r, 0)); _scale = new ContentChoice ( this, @@ -139,44 +150,29 @@ VideoPanel::VideoPanel (ContentPanel* p) &index_to_scale, &scale_to_index ); - _scale->add (grid, wxGBPosition (r, 1)); + _scale->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2)); ++r; - { - add_label_to_grid_bag_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0)); - wxSizer* s = new wxBoxSizer (wxHORIZONTAL); - - 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); - } + wxClientDC dc (this); + wxSize size = dc.GetTextExtent (wxT ("A quite long name")); + size.SetHeight (-1); + + add_label_to_grid_bag_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0)); + _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size); + grid->Add (_filters, wxGBPosition (r, 1), wxGBSpan (1, 2), wxALIGN_CENTER_VERTICAL); + _filters_button = new wxButton (this, wxID_ANY, _("Edit...")); + grid->Add (_filters_button, wxGBPosition (r, 3), 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); - } + add_label_to_grid_bag_sizer (grid, this, _("Colour conversion"), true, wxGBPosition (r, 0)); + _colour_conversion = new wxStaticText (this, wxID_ANY, wxT (""), wxDefaultPosition, size); + grid->Add (_colour_conversion, wxGBPosition (r, 1), wxGBSpan (1, 2), wxALIGN_CENTER_VERTICAL); + _colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit...")); + grid->Add (_colour_conversion_button, wxGBPosition (r, 3), 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); + grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6); wxFont font = _description->GetFont(); font.SetStyle(wxFONTSTYLE_ITALIC); font.SetPointSize(font.GetPointSize() - 1); @@ -201,6 +197,9 @@ VideoPanel::VideoPanel (ContentPanel* p) _frame_type->wrapped()->Append (_("3D left only")); _frame_type->wrapped()->Append (_("3D right only")); + _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this)); + _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_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)); } @@ -251,6 +250,28 @@ VideoPanel::film_content_changed (int property) _filters->SetLabel (std_to_wx (p)); } } + } else if (property == VideoContentProperty::VIDEO_FADE_IN) { + set check; + for (VideoContentList::const_iterator i = vc.begin (); i != vc.end(); ++i) { + check.insert ((*i)->fade_in ()); + } + + if (check.size() == 1) { + _fade_in->set (vc.front()->fade_in (), vc.front()->video_frame_rate ()); + } else { + _fade_in->clear (); + } + } else if (property == VideoContentProperty::VIDEO_FADE_OUT) { + set check; + for (VideoContentList::const_iterator i = vc.begin (); i != vc.end(); ++i) { + check.insert ((*i)->fade_out ()); + } + + if (check.size() == 1) { + _fade_out->set (vc.front()->fade_out (), vc.front()->video_frame_rate ()); + } else { + _fade_out->clear (); + } } } @@ -381,5 +402,25 @@ VideoPanel::content_selection_changed () film_content_changed (VideoContentProperty::VIDEO_CROP); film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE); film_content_changed (VideoContentProperty::COLOUR_CONVERSION); + film_content_changed (VideoContentProperty::VIDEO_FADE_IN); + film_content_changed (VideoContentProperty::VIDEO_FADE_OUT); film_content_changed (FFmpegContentProperty::FILTERS); } + +void +VideoPanel::fade_in_changed () +{ + VideoContentList vc = _parent->selected_video (); + for (VideoContentList::const_iterator i = vc.begin(); i != vc.end(); ++i) { + (*i)->set_fade_in (_fade_in->get (_parent->film()->video_frame_rate ())); + } +} + +void +VideoPanel::fade_out_changed () +{ + VideoContentList vc = _parent->selected_video (); + for (VideoContentList::const_iterator i = vc.begin(); i != vc.end(); ++i) { + (*i)->set_fade_out (_fade_out->get (_parent->film()->video_frame_rate ())); + } +} diff --git a/src/wx/video_panel.h b/src/wx/video_panel.h index e17541cd3..aa0c6ed53 100644 --- a/src/wx/video_panel.h +++ b/src/wx/video_panel.h @@ -21,9 +21,10 @@ * @brief VideoPanel class. */ -#include "lib/film.h" #include "content_sub_panel.h" #include "content_widget.h" +#include "timecode.h" +#include "lib/film.h" class wxChoice; class wxStaticText; @@ -45,6 +46,8 @@ public: private: void edit_filters_clicked (); void edit_colour_conversion_clicked (); + void fade_in_changed (); + void fade_out_changed (); void setup_description (); @@ -53,6 +56,8 @@ private: ContentSpinCtrl* _right_crop; ContentSpinCtrl* _top_crop; ContentSpinCtrl* _bottom_crop; + Timecode* _fade_in; + Timecode* _fade_out; ContentChoice* _scale; wxStaticText* _description; wxStaticText* _filters; diff --git a/test/client_server_test.cc b/test/client_server_test.cc index 4e3ecc983..0154200ad 100644 --- a/test/client_server_test.cc +++ b/test/client_server_test.cc @@ -39,6 +39,7 @@ using std::list; using boost::shared_ptr; using boost::thread; +using boost::optional; void do_remote_encode (shared_ptr frame, ServerDescription description, shared_ptr locally_encoded) @@ -86,6 +87,7 @@ BOOST_AUTO_TEST_CASE (client_server_test_rgb) shared_ptr (new RawImageProxy (image, log)), DCPTime (), Crop (), + optional (), dcp::Size (1998, 1080), dcp::Size (1998, 1080), Scaler::from_id ("bicubic"), @@ -169,6 +171,7 @@ BOOST_AUTO_TEST_CASE (client_server_test_yuv) shared_ptr (new RawImageProxy (image, log)), DCPTime (), Crop (), + optional (), dcp::Size (1998, 1080), dcp::Size (1998, 1080), Scaler::from_id ("bicubic"),