summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-07-27 22:30:35 +0100
committerCarl Hetherington <cth@carlh.net>2012-07-27 22:30:35 +0100
commit6427e9dcb2cd239dcd5a392aac847df47f9875d9 (patch)
treeeb69053b6b103db808bfeaf1d07fc9c729fa533f /src/lib
parent423928e4a0c9294f7e7da30030f00e3fc09cdf14 (diff)
Use a Crop struct and use it to speed up cropping a bit.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/decoder.cc2
-rw-r--r--src/lib/film.cc26
-rw-r--r--src/lib/film.h26
-rw-r--r--src/lib/film_state.cc20
-rw-r--r--src/lib/film_state.h13
-rw-r--r--src/lib/util.cc10
-rw-r--r--src/lib/util.h13
7 files changed, 52 insertions, 58 deletions
diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc
index abdaa59d9..c6982ef46 100644
--- a/src/lib/decoder.cc
+++ b/src/lib/decoder.cc
@@ -401,7 +401,7 @@ Decoder::setup_video_filters ()
if (_opt->apply_crop) {
size_after_crop = _fs->cropped_size (native_size ());
- fs << crop_string (Position (_fs->left_crop, _fs->top_crop), size_after_crop);
+ fs << crop_string (Position (_fs->crop.left, _fs->crop.top), size_after_crop);
} else {
size_after_crop = native_size ();
fs << crop_string (Position (0, 0), size_after_crop);
diff --git a/src/lib/film.cc b/src/lib/film.cc
index a9d6e8f99..cb0a44a45 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -223,48 +223,48 @@ Film::set_dcp_content_type (DCPContentType const * t)
void
Film::set_left_crop (int c)
{
- if (c == _state.left_crop) {
+ if (c == _state.crop.left) {
return;
}
- _state.left_crop = c;
- signal_changed (LEFT_CROP);
+ _state.crop.left = c;
+ signal_changed (CROP);
}
/** Set the number of pixels by which to crop the right of the source video */
void
Film::set_right_crop (int c)
{
- if (c == _state.right_crop) {
+ if (c == _state.crop.right) {
return;
}
- _state.right_crop = c;
- signal_changed (RIGHT_CROP);
+ _state.crop.right = c;
+ signal_changed (CROP);
}
/** Set the number of pixels by which to crop the top of the source video */
void
Film::set_top_crop (int c)
{
- if (c == _state.top_crop) {
+ if (c == _state.crop.top) {
return;
}
- _state.top_crop = c;
- signal_changed (TOP_CROP);
+ _state.crop.top = c;
+ signal_changed (CROP);
}
/** Set the number of pixels by which to crop the bottom of the source video */
void
Film::set_bottom_crop (int c)
{
- if (c == _state.bottom_crop) {
+ if (c == _state.crop.bottom) {
return;
}
- _state.bottom_crop = c;
- signal_changed (BOTTOM_CROP);
+ _state.crop.bottom = c;
+ signal_changed (CROP);
}
/** Set the filters to apply to the image when generating thumbnails
@@ -425,7 +425,7 @@ Film::j2k_dir () const
stringstream s;
s << _state.format->id()
<< "_" << _state.content_digest
- << "_" << left_crop() << "_" << right_crop() << "_" << top_crop() << "_" << bottom_crop()
+ << "_" << crop().left << "_" << crop().right << "_" << crop().top << "_" << crop().bottom
<< "_" << f.first << "_" << f.second
<< "_" << _state.scaler->id();
diff --git a/src/lib/film.h b/src/lib/film.h
index f214d411f..dc766252d 100644
--- a/src/lib/film.h
+++ b/src/lib/film.h
@@ -70,24 +70,9 @@ public:
return _state.name;
}
- /** @return number of pixels to crop from the top of the original picture */
- int top_crop () const {
- return _state.top_crop;
- }
-
- /** @return number of pixels to crop from the bottom of the original picture */
- int bottom_crop () const {
- return _state.bottom_crop;
- }
-
- /** @return number of pixels to crop from the left-hand side of the original picture */
- int left_crop () const {
- return _state.left_crop;
- }
-
- /** @return number of pixels to crop from the right-hand side of the original picture */
- int right_crop () const {
- return _state.right_crop;
+ /** @return number of pixels to crop from the sides of the original picture */
+ Crop crop () const {
+ return _state.crop;
}
/** @return the format to present this film in (flat, scope, etc.) */
@@ -219,10 +204,7 @@ public:
CONTENT,
DCP_CONTENT_TYPE,
FORMAT,
- LEFT_CROP,
- RIGHT_CROP,
- TOP_CROP,
- BOTTOM_CROP,
+ CROP,
FILTERS,
SCALER,
DCP_FRAMES,
diff --git a/src/lib/film_state.cc b/src/lib/film_state.cc
index 29bf71db3..e23bf9148 100644
--- a/src/lib/film_state.cc
+++ b/src/lib/film_state.cc
@@ -55,10 +55,10 @@ FilmState::write_metadata (ofstream& f) const
if (format) {
f << "format " << format->as_metadata () << "\n";
}
- f << "left_crop " << left_crop << "\n";
- f << "right_crop " << right_crop << "\n";
- f << "top_crop " << top_crop << "\n";
- f << "bottom_crop " << bottom_crop << "\n";
+ f << "left_crop " << crop.left << "\n";
+ f << "right_crop " << crop.right << "\n";
+ f << "top_crop " << crop.top << "\n";
+ f << "bottom_crop " << crop.bottom << "\n";
for (vector<Filter const *>::const_iterator i = filters.begin(); i != filters.end(); ++i) {
f << "filter " << (*i)->id () << "\n";
}
@@ -114,13 +114,13 @@ FilmState::read_metadata (string k, string v)
} else if (k == "format") {
format = Format::from_metadata (v);
} else if (k == "left_crop") {
- left_crop = atoi (v.c_str ());
+ crop.left = atoi (v.c_str ());
} else if (k == "right_crop") {
- right_crop = atoi (v.c_str ());
+ crop.right = atoi (v.c_str ());
} else if (k == "top_crop") {
- top_crop = atoi (v.c_str ());
+ crop.top = atoi (v.c_str ());
} else if (k == "bottom_crop") {
- bottom_crop = atoi (v.c_str ());
+ crop.bottom = atoi (v.c_str ());
} else if (k == "filter") {
filters.push_back (Filter::from_id (v));
} else if (k == "scaler") {
@@ -214,8 +214,8 @@ FilmState::thumb_frame (int n) const
Size
FilmState::cropped_size (Size s) const
{
- s.width -= left_crop + right_crop;
- s.height -= top_crop + bottom_crop;
+ s.width -= crop.left + crop.right;
+ s.height -= crop.top + crop.bottom;
return s;
}
diff --git a/src/lib/film_state.h b/src/lib/film_state.h
index 1df2dc95d..12d44cdce 100644
--- a/src/lib/film_state.h
+++ b/src/lib/film_state.h
@@ -55,10 +55,6 @@ public:
: dcp_content_type (0)
, frames_per_second (0)
, format (0)
- , left_crop (0)
- , right_crop (0)
- , top_crop (0)
- , bottom_crop (0)
, scaler (Scaler::from_id ("bicubic"))
, dcp_frames (0)
, dcp_trim_action (CUT)
@@ -106,14 +102,7 @@ public:
float frames_per_second;
/** The format to present this Film in (flat, scope, etc.) */
Format const * format;
- /** Number of pixels to crop from the left-hand side of the original picture */
- int left_crop;
- /** Number of pixels to crop from the right-hand side of the original picture */
- int right_crop;
- /** Number of pixels to crop from the top of the original picture */
- int top_crop;
- /** Number of pixels to crop from the bottom of the original picture */
- int bottom_crop;
+ Crop crop;
/** Video filters that should be used when generating DCPs */
std::vector<Filter const *> filters;
/** Scaler algorithm to use */
diff --git a/src/lib/util.cc b/src/lib/util.cc
index c15433953..5106f3182 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -491,3 +491,13 @@ dcp_audio_sample_rate (int fs)
return 96000;
}
+
+bool operator== (Crop const & a, Crop const & b)
+{
+ return (a.left == b.left && a.right == b.right && a.top == b.top && a.bottom == b.bottom);
+}
+
+bool operator!= (Crop const & a, Crop const & b)
+{
+ return !(a == b);
+}
diff --git a/src/lib/util.h b/src/lib/util.h
index 1faef0cd3..16afb7bb6 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -103,6 +103,19 @@ struct Size
int height;
};
+struct Crop
+{
+ Crop () : left (0), right (0), top (0), bottom (0) {}
+
+ int left;
+ int right;
+ int top;
+ int bottom;
+};
+
+extern bool operator== (Crop const & a, Crop const & b);
+extern bool operator!= (Crop const & a, Crop const & b);
+
struct Position
{
Position ()