summaryrefslogtreecommitdiff
path: root/src/lib/player_video.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2016-05-12 00:18:18 +0100
committerCarl Hetherington <cth@carlh.net>2016-05-12 00:18:18 +0100
commit631f905234537d2b0a24e9b3ff40f08a17c0fd8b (patch)
treedc60d31714e5201028d679b41bef6c5658681a02 /src/lib/player_video.cc
parent396cddb7c112aedc80a106a785083aea05b8b741 (diff)
Optimise image scaling for the preview.
Diffstat (limited to 'src/lib/player_video.cc')
-rw-r--r--src/lib/player_video.cc28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/lib/player_video.cc b/src/lib/player_video.cc
index ba4503d8e..3129a1717 100644
--- a/src/lib/player_video.cc
+++ b/src/lib/player_video.cc
@@ -34,6 +34,7 @@ using std::cout;
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
using boost::optional;
+using boost::function;
using dcp::Data;
PlayerVideo::PlayerVideo (
@@ -94,8 +95,14 @@ PlayerVideo::set_subtitle (PositionImage image)
_subtitle = image;
}
+/** Create an image for this frame.
+ * @param note Handler for any notes that are made during the process.
+ * @param pixel_format Function which is called to decide what pixel format the output image should be;
+ * it is passed the pixel format of the input image from the ImageProxy, and should return the desired
+ * output pixel format. Two functions always_rgb and keep_xyz_or_rgb are provided for use here.
+ */
shared_ptr<Image>
-PlayerVideo::image (dcp::NoteHandler note) const
+PlayerVideo::image (dcp::NoteHandler note, function<AVPixelFormat (AVPixelFormat)> pixel_format, bool aligned, bool fast) const
{
shared_ptr<Image> im = _in->image (optional<dcp::NoteHandler> (note));
@@ -122,10 +129,9 @@ PlayerVideo::image (dcp::NoteHandler note) const
yuv_to_rgb = _colour_conversion.get().yuv_to_rgb();
}
- /* If the input is XYZ, keep it otherwise convert to RGB */
- AVPixelFormat const p = _in->pixel_format() == AV_PIX_FMT_XYZ12LE ? AV_PIX_FMT_XYZ12LE : AV_PIX_FMT_RGB48LE;
-
- shared_ptr<Image> out = im->crop_scale_window (total_crop, _inter_size, _out_size, yuv_to_rgb, p, true);
+ shared_ptr<Image> out = im->crop_scale_window (
+ total_crop, _inter_size, _out_size, yuv_to_rgb, pixel_format (_in->pixel_format()), aligned, fast
+ );
if (_subtitle) {
out->alpha_blend (_subtitle->image, _subtitle->position);
@@ -230,3 +236,15 @@ PlayerVideo::same (shared_ptr<const PlayerVideo> other) const
return _in->same (other->_in);
}
+
+AVPixelFormat
+PlayerVideo::always_rgb (AVPixelFormat)
+{
+ return AV_PIX_FMT_RGB24;
+}
+
+AVPixelFormat
+PlayerVideo::keep_xyz_or_rgb (AVPixelFormat p)
+{
+ return p == AV_PIX_FMT_XYZ12LE ? AV_PIX_FMT_XYZ12LE : AV_PIX_FMT_RGB48LE;
+}