X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Ffilm_viewer.cc;h=5262338332e7073884b37bbc398c9d007eb057ca;hb=c0e04acd1e9875fa67800a7861bd8a370157b49f;hp=bf082adc2e534824eb6d769cc32fa5c43cb2be85;hpb=13511ed2fcc23f4d5f9c507c775c3c5cfd82d155;p=dcpomatic.git diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index bf082adc2..526233833 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -26,7 +26,6 @@ #include "lib/film.h" #include "lib/format.h" #include "lib/util.h" -#include "lib/thumbs_job.h" #include "lib/job_manager.h" #include "lib/film_state.h" #include "lib/options.h" @@ -50,7 +49,7 @@ public: /** Handle a paint event */ void paint_event (wxPaintEvent& ev) { - if (!_film || _film->num_thumbs() == 0) { + if (!_film || _film->thumbs().size() == 0) { wxPaintDC dc (this); return; } @@ -58,21 +57,18 @@ public: if (_frame_rebuild_needed) { _image.reset (new wxImage (std_to_wx (_film->thumb_file (_index)))); - _subtitles.clear (); - list > s = _film->thumb_subtitles (_index); - for (list >::iterator i = s.begin(); i != s.end(); ++i) { - _subtitles.push_back (SubtitleView (i->first, std_to_wx (i->second))); + _subtitle.reset (); + pair s = _film->thumb_subtitle (_index); + if (!s.second.empty ()) { + _subtitle.reset (new SubtitleView (s.first, std_to_wx (s.second))); } _frame_rebuild_needed = false; - compose (); - _composition_needed = false; } if (_composition_needed) { compose (); - _composition_needed = false; } wxPaintDC dc (this); @@ -80,10 +76,8 @@ public: dc.DrawBitmap (*_bitmap, 0, 0, false); } - if (_film->with_subtitles ()) { - for (list::iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { - dc.DrawBitmap (*i->bitmap, i->transformed_area.x, i->transformed_area.y, true); - } + if (_film->with_subtitles() && _subtitle) { + dc.DrawBitmap (*_subtitle->bitmap, _subtitle->transformed_area.x, _subtitle->transformed_area.y, true); } } @@ -123,7 +117,7 @@ public: { _bitmap.reset (); _image.reset (); - _subtitles.clear (); + _subtitle.reset (); } void recompose () @@ -138,6 +132,8 @@ private: void compose () { + _composition_needed = false; + if (!_film || !_image) { return; } @@ -146,18 +142,20 @@ private: int vw, vh; GetSize (&vw, &vh); + Crop const fc = _film->crop (); + /* Cropped rectangle */ - Rectangle cropped_area ( - _film->crop().left, - _film->crop().top, - _image->GetWidth() - (_film->crop().left + _film->crop().right), - _image->GetHeight() - (_film->crop().top + _film->crop().bottom) + Rect cropped_area ( + fc.left, + fc.top, + _image->GetWidth() - (fc.left + fc.right), + _image->GetHeight() - (fc.top + fc.bottom) ); /* Target ratio */ float const target = _film->format() ? _film->format()->ratio_as_float (_film) : 1.78; - _transformed_image = _image->GetSubImage (wxRect (cropped_area.x, cropped_area.y, cropped_area.w, cropped_area.h)); + _transformed_image = _image->GetSubImage (wxRect (cropped_area.x, cropped_area.y, cropped_area.width, cropped_area.height)); float x_scale = 1; float y_scale = 1; @@ -165,28 +163,28 @@ private: if ((float (vw) / vh) > target) { /* view is longer (horizontally) than the ratio; fit height */ _transformed_image.Rescale (vh * target, vh, wxIMAGE_QUALITY_HIGH); - x_scale = vh * target / cropped_area.w; - y_scale = float (vh) / cropped_area.h; + x_scale = vh * target / cropped_area.width; + y_scale = float (vh) / cropped_area.height; } else { /* view is shorter (horizontally) than the ratio; fit width */ _transformed_image.Rescale (vw, vw / target, wxIMAGE_QUALITY_HIGH); - x_scale = float (vw) / cropped_area.w; - y_scale = (vw / target) / cropped_area.h; + x_scale = float (vw) / cropped_area.width; + y_scale = (vw / target) / cropped_area.height; } _bitmap.reset (new wxBitmap (_transformed_image)); - for (list::iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { + if (_subtitle) { - i->transformed_area = transformed_subtitle_area ( - x_scale, y_scale, i->base_area, _film->subtitle_offset(), _film->subtitle_scale() + _subtitle->transformed_area = subtitle_transformed_area ( + x_scale, y_scale, _subtitle->base_area, _film->subtitle_offset(), _film->subtitle_scale() ); - i->transformed_image = i->base_image; - i->transformed_image.Rescale (i->transformed_area.w, i->transformed_area.h, wxIMAGE_QUALITY_HIGH); - i->transformed_area.x -= _film->crop().left; - i->transformed_area.y -= _film->crop().top; - i->bitmap.reset (new wxBitmap (i->transformed_image)); + _subtitle->transformed_image = _subtitle->base_image; + _subtitle->transformed_image.Rescale (_subtitle->transformed_area.width, _subtitle->transformed_area.height, wxIMAGE_QUALITY_HIGH); + _subtitle->transformed_area.x -= rint (_film->crop().left * x_scale); + _subtitle->transformed_area.y -= rint (_film->crop().top * y_scale); + _subtitle->bitmap.reset (new wxBitmap (_subtitle->transformed_image)); } } @@ -206,18 +204,18 @@ private: { base_area.x = p.x; base_area.y = p.y; - base_area.w = base_image.GetWidth (); - base_area.h = base_image.GetHeight (); + base_area.width = base_image.GetWidth (); + base_area.height = base_image.GetHeight (); } - Rectangle base_area; - Rectangle transformed_area; + Rect base_area; + Rect transformed_area; wxImage base_image; wxImage transformed_image; shared_ptr bitmap; }; - list _subtitles; + shared_ptr _subtitle; }; BEGIN_EVENT_TABLE (ThumbPanel, wxPanel) @@ -235,8 +233,8 @@ FilmViewer::FilmViewer (Film* f, wxWindow* p) _thumb_panel = new ThumbPanel (this, f); _sizer->Add (_thumb_panel, 1, wxEXPAND); - int const max = f ? f->num_thumbs() - 1 : 0; - _slider = new wxSlider (this, wxID_ANY, 0, 0, max); + int const m = max ((size_t) 1, f ? f->thumbs().size() - 1 : 0); + _slider = new wxSlider (this, wxID_ANY, 0, 0, m); _sizer->Add (_slider, 0, wxEXPAND | wxLEFT | wxRIGHT); set_thumbnail (0); @@ -248,7 +246,7 @@ FilmViewer::FilmViewer (Film* f, wxWindow* p) void FilmViewer::set_thumbnail (int n) { - if (_film == 0 || _film->num_thumbs() <= n) { + if (_film == 0 || int (_film->thumbs().size()) <= n) { return; } @@ -262,12 +260,14 @@ FilmViewer::slider_changed (wxCommandEvent &) } void -FilmViewer::film_changed (Film::Property p) +FilmViewer::film_changed (FilmState::Property p) { + ensure_ui_thread (); + switch (p) { - case Film::THUMBS: - if (_film && _film->num_thumbs() > 1) { - _slider->SetRange (0, _film->num_thumbs () - 1); + case FilmState::THUMBS: + if (_film && _film->thumbs().size() > 1) { + _slider->SetRange (0, _film->thumbs().size() - 1); } else { _thumb_panel->clear (); _slider->SetRange (0, 1); @@ -276,16 +276,14 @@ FilmViewer::film_changed (Film::Property p) _slider->SetValue (0); set_thumbnail (0); break; - case Film::CONTENT: + case FilmState::CONTENT: setup_visibility (); - _film->examine_content (); - update_thumbs (); break; - case Film::CROP: - case Film::FORMAT: - case Film::WITH_SUBTITLES: - case Film::SUBTITLE_OFFSET: - case Film::SUBTITLE_SCALE: + case FilmState::CROP: + case FilmState::FORMAT: + case FilmState::WITH_SUBTITLES: + case FilmState::SUBTITLE_OFFSET: + case FilmState::SUBTITLE_SCALE: _thumb_panel->recompose (); break; default: @@ -313,28 +311,6 @@ FilmViewer::set_film (Film* f) setup_visibility (); } -void -FilmViewer::update_thumbs () -{ - if (!_film) { - return; - } - - _film->update_thumbs_pre_gui (); - - shared_ptr s = _film->state_copy (); - shared_ptr o (new Options (s->dir ("thumbs"), ".png", "")); - o->out_size = _film->size (); - o->apply_crop = false; - o->decode_audio = false; - o->decode_video_frequency = 128; - o->decode_subtitles = true; - - shared_ptr j (new ThumbsJob (s, o, _film->log(), shared_ptr ())); - j->Finished.connect (sigc::mem_fun (_film, &Film::update_thumbs_post_gui)); - JobManager::instance()->add (j); -} - void FilmViewer::setup_visibility () {