diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-10-10 20:35:05 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-10-10 20:35:05 +0100 |
| commit | ed70b4faf0f53b106aebd4b9195ccc81da97880e (patch) | |
| tree | 03ccbe558fbcc4165115e89212692ebcc0fda019 /src/lib | |
| parent | cc4a67b7eb8ecaed076e261960848f70e3e741af (diff) | |
Thumbs sort of have subs.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/film.cc | 45 | ||||
| -rw-r--r-- | src/lib/film.h | 1 | ||||
| -rw-r--r-- | src/lib/film_state.cc | 14 | ||||
| -rw-r--r-- | src/lib/film_state.h | 2 | ||||
| -rw-r--r-- | src/lib/util.cc | 13 | ||||
| -rw-r--r-- | src/lib/util.h | 25 |
6 files changed, 99 insertions, 1 deletions
diff --git a/src/lib/film.cc b/src/lib/film.cc index 95dc7b825..1e23c4d6b 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -27,6 +27,7 @@ #include <unistd.h> #include <boost/filesystem.hpp> #include <boost/algorithm/string.hpp> +#include <boost/lexical_cast.hpp> #include "film.h" #include "format.h" #include "tiff_encoder.h" @@ -668,3 +669,47 @@ Film::set_with_subtitles (bool w) _state.with_subtitles = w; signal_changed (WITH_SUBTITLES); } + +list<pair<Position, string> > +Film::thumb_subtitles (int n) const +{ + string sub_file = _state.thumb_base(n) + ".sub"; + if (!filesystem::exists (sub_file)) { + return list<pair<Position, string> > (); + } + + ifstream f (sub_file.c_str ()); + string line; + + int sub_number; + int sub_x; + list<pair<Position, string> > subs; + + while (getline (f, line)) { + if (line.empty ()) { + continue; + } + + if (line[line.size() - 1] == '\r') { + line = line.substr (0, line.size() - 1); + } + + size_t const s = line.find (' '); + if (s == string::npos) { + continue; + } + + string const k = line.substr (0, s); + int const v = lexical_cast<int> (line.substr(s + 1)); + + if (k == "image") { + sub_number = v; + } else if (k == "x") { + sub_x = v; + } else if (k == "y") { + subs.push_back (make_pair (Position (sub_x, v), String::compose ("%1.sub.%2.tiff", _state.thumb_base(n), sub_number))); + } + } + + return subs; +} diff --git a/src/lib/film.h b/src/lib/film.h index 919cecc22..1e01747a2 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -193,6 +193,7 @@ public: int num_thumbs () const; int thumb_frame (int) const; std::string thumb_file (int) const; + std::list<std::pair<Position, std::string> > thumb_subtitles (int) const; void copy_from_dvd_post_gui (); void examine_content (); diff --git a/src/lib/film_state.cc b/src/lib/film_state.cc index 03d4cae83..2847ea513 100644 --- a/src/lib/film_state.cc +++ b/src/lib/film_state.cc @@ -191,9 +191,21 @@ FilmState::thumb_file (int n) const string FilmState::thumb_file_for_frame (int n) const { + return thumb_base_for_frame(n) + ".tiff"; +} + +string +FilmState::thumb_base (int n) const +{ + return thumb_base_for_frame (thumb_frame (n)); +} + +string +FilmState::thumb_base_for_frame (int n) const +{ stringstream s; s.width (8); - s << setfill('0') << n << ".tiff"; + s << setfill('0') << n; filesystem::path p; p /= dir ("thumbs"); diff --git a/src/lib/film_state.h b/src/lib/film_state.h index 2b792694c..5b3ef8367 100644 --- a/src/lib/film_state.h +++ b/src/lib/film_state.h @@ -79,6 +79,7 @@ public: bool content_is_dvd () const; std::string thumb_file (int) const; + std::string thumb_base (int) const; int thumb_frame (int) const; int bytes_per_sample () const; @@ -151,6 +152,7 @@ public: private: std::string thumb_file_for_frame (int) const; + std::string thumb_base_for_frame (int) const; }; #endif diff --git a/src/lib/util.cc b/src/lib/util.cc index 935566440..82aaf8ff5 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -600,3 +600,16 @@ Socket::read_indefinite (uint8_t* data, int size, int timeout) assert (size >= _buffer_data); memcpy (data, _buffer, size); } + +Rectangle +Rectangle::intersection (Rectangle const & other) const +{ + int const tx = max (x, other.x); + int const ty = max (y, other.y); + + return Rectangle ( + tx, ty, + min (x + w, other.x + other.w) - tx, + min (y + h, other.y + other.h) - ty + ); +} diff --git a/src/lib/util.h b/src/lib/util.h index ed13cd43c..e1ad7fd64 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -121,6 +121,31 @@ struct Position int y; }; +/** A rectangle */ +struct Rectangle +{ + Rectangle () + : x (0) + , y (0) + , w (0) + , h (0) + {} + + Rectangle (int x_, int y_, int w_, int h_) + : x (x_) + , y (y_) + , w (w_) + , h (h_) + {} + + int x; + int y; + int w; + int h; + + Rectangle intersection (Rectangle const & other) const; +}; + extern std::string crop_string (Position, Size); extern int dcp_audio_sample_rate (int); extern std::string colour_lut_index_to_name (int index); |
