summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-10-03 20:53:44 +0200
committerCarl Hetherington <cth@carlh.net>2021-10-03 23:41:02 +0200
commit70b72b53eab0f247eb4dc605a2d669d4adb4e469 (patch)
treeaf117017f084fc2fedf0e2eaad667cda7d832b64 /src/lib
parentc2a17a87868eba87072fc369102b2b3cd8905e5a (diff)
Differentiate requested and actual crop.
This is so we limit cropping to what is possible considering chroma subsampling.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/pixel_quanta.cc14
-rw-r--r--src/lib/pixel_quanta.h3
-rw-r--r--src/lib/player.cc2
-rw-r--r--src/lib/player_video.cc2
-rw-r--r--src/lib/video_content.cc34
-rw-r--r--src/lib/video_content.h12
6 files changed, 51 insertions, 16 deletions
diff --git a/src/lib/pixel_quanta.cc b/src/lib/pixel_quanta.cc
index 12eea5031..09e684064 100644
--- a/src/lib/pixel_quanta.cc
+++ b/src/lib/pixel_quanta.cc
@@ -39,6 +39,20 @@ PixelQuanta::as_xml (xmlpp::Element* node) const
}
+int
+PixelQuanta::round_x (int x_) const
+{
+ return x_ - (x_ % x);
+}
+
+
+int
+PixelQuanta::round_y (int y_) const
+{
+ return y_ - (y_ % y);
+}
+
+
PixelQuanta
max (PixelQuanta const& a, PixelQuanta const& b)
{
diff --git a/src/lib/pixel_quanta.h b/src/lib/pixel_quanta.h
index e4a03c9d2..c37ba189b 100644
--- a/src/lib/pixel_quanta.h
+++ b/src/lib/pixel_quanta.h
@@ -52,6 +52,9 @@ public:
void as_xml (xmlpp::Element* node) const;
+ int round_x (int x_) const;
+ int round_y (int y_) const;
+
int x;
int y;
};
diff --git a/src/lib/player.cc b/src/lib/player.cc
index 7951926e6..285126ced 100644
--- a/src/lib/player.cc
+++ b/src/lib/player.cc
@@ -922,7 +922,7 @@ Player::video (weak_ptr<Piece> wp, ContentVideo video)
_last_video[wp] = std::make_shared<PlayerVideo>(
video.image,
- piece->content->video->crop (),
+ piece->content->video->actual_crop(),
piece->content->video->fade (_film, video.frame),
scale_for_display(piece->content->video->scaled_size(_film->frame_size()), _video_container_size, _film->frame_size()),
_video_container_size,
diff --git a/src/lib/player_video.cc b/src/lib/player_video.cc
index 7c36af31b..c9bc2dcde 100644
--- a/src/lib/player_video.cc
+++ b/src/lib/player_video.cc
@@ -343,7 +343,7 @@ PlayerVideo::reset_metadata (shared_ptr<const Film> film, dcp::Size player_video
return false;
}
- _crop = content->video->crop();
+ _crop = content->video->actual_crop();
_fade = content->video->fade(film, _video_frame.get());
_inter_size = scale_for_display(content->video->scaled_size(film->frame_size()), player_video_container_size, film->frame_size());
_out_size = player_video_container_size;
diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc
index bffe2e322..0ef102116 100644
--- a/src/lib/video_content.cc
+++ b/src/lib/video_content.cc
@@ -218,7 +218,7 @@ VideoContent::VideoContent (Content* parent, vector<shared_ptr<Content> > c)
throw JoinError (_("Content to be joined must have the same video frame type."));
}
- if (c[i]->video->crop() != ref->crop()) {
+ if (c[i]->video->requested_crop() != ref->requested_crop()) {
throw JoinError (_("Content to be joined must have the same crop."));
}
@@ -254,7 +254,7 @@ VideoContent::VideoContent (Content* parent, vector<shared_ptr<Content> > c)
_use = ref->use ();
_size = ref->size ();
_frame_type = ref->frame_type ();
- _crop = ref->crop ();
+ _crop = ref->requested_crop ();
_custom_ratio = ref->custom_ratio ();
_colour_conversion = ref->colour_conversion ();
_fade_in = ref->fade_in ();
@@ -334,13 +334,14 @@ string
VideoContent::identifier () const
{
char buffer[256];
+ auto const crop = actual_crop();
snprintf (
buffer, sizeof(buffer), "%d_%d_%d_%d_%d_%f_%d_%d%" PRId64 "_%" PRId64 "_%d",
(_use ? 1 : 0),
- crop().left,
- crop().right,
- crop().top,
- crop().bottom,
+ crop.left,
+ crop.right,
+ crop.top,
+ crop.bottom,
_custom_ratio.get_value_or(0),
_custom_size ? _custom_size->width : 0,
_custom_size ? _custom_size->height : 0,
@@ -399,7 +400,7 @@ VideoContent::size_after_3d_split () const
dcp::Size
VideoContent::size_after_crop () const
{
- return crop().apply (size_after_3d_split ());
+ return actual_crop().apply(size_after_3d_split());
}
@@ -452,8 +453,10 @@ VideoContent::processing_description (shared_ptr<const Film> film)
d += buffer;
}
- if ((crop().left || crop().right || crop().top || crop().bottom) && size() != dcp::Size (0, 0)) {
- dcp::Size cropped = size_after_crop ();
+ auto const crop = actual_crop();
+
+ if ((crop.left || crop.right || crop.top || crop.bottom) && size() != dcp::Size(0, 0)) {
+ auto const cropped = size_after_crop ();
d += String::compose (
_("\nCropped to %1x%2"),
cropped.width, cropped.height
@@ -668,3 +671,16 @@ VideoContent::set_custom_size (optional<dcp::Size> size)
{
maybe_set (_custom_size, size, VideoContentProperty::CUSTOM_SIZE);
}
+
+
+Crop
+VideoContent::actual_crop () const
+{
+ return Crop(
+ _pixel_quanta.round_x(_crop.left),
+ _pixel_quanta.round_x(_crop.right),
+ _pixel_quanta.round_y(_crop.top),
+ _pixel_quanta.round_y(_crop.bottom)
+ );
+}
+
diff --git a/src/lib/video_content.h b/src/lib/video_content.h
index de151e145..ce645bb41 100644
--- a/src/lib/video_content.h
+++ b/src/lib/video_content.h
@@ -113,27 +113,29 @@ public:
return _frame_type;
}
- Crop crop () const {
+ Crop actual_crop () const;
+
+ Crop requested_crop () const {
boost::mutex::scoped_lock lm (_mutex);
return _crop;
}
- int left_crop () const {
+ int requested_left_crop () const {
boost::mutex::scoped_lock lm (_mutex);
return _crop.left;
}
- int right_crop () const {
+ int requested_right_crop () const {
boost::mutex::scoped_lock lm (_mutex);
return _crop.right;
}
- int top_crop () const {
+ int requested_top_crop () const {
boost::mutex::scoped_lock lm (_mutex);
return _crop.top;
}
- int bottom_crop () const {
+ int requested_bottom_crop () const {
boost::mutex::scoped_lock lm (_mutex);
return _crop.bottom;
}