+2016-03-16 Carl Hetherington <cth@carlh.net>
+
+ * Optimise image scaling for the preview.
+
2016-05-11 Carl Hetherington <cth@carlh.net>
* Hopefully improve strange colour fringing on
/*
- Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
- Taken from code Copyright (C) 2010-2011 Terrence Meiczinger
+ Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
{
shared_ptr<dcp::OpenJPEGImage> xyz;
- shared_ptr<Image> image = frame->image (note);
+ shared_ptr<Image> image = frame->image (note, bind (&PlayerVideo::keep_xyz_or_rgb, _1), true, false);
if (frame->colour_conversion()) {
xyz = dcp::rgb_to_xyz (
image->data()[0],
/*
- Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
- Taken from code Copyright (C) 2010-2011 Terrence Meiczinger
+ Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
/*
- Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
return d->nb_components;
}
-/** Crop this image, scale it to `inter_size' and then place it in a black frame of `out_size' */
+/** Crop this image, scale it to `inter_size' and then place it in a black frame of `out_size'.
+ * @param fast Try to be fast at the possible expense of quality; at present this means using
+ * fast bilinear rather than bicubic scaling.
+ */
shared_ptr<Image>
Image::crop_scale_window (
- Crop crop, dcp::Size inter_size, dcp::Size out_size, dcp::YUVToRGB yuv_to_rgb, AVPixelFormat out_format, bool out_aligned
+ Crop crop, dcp::Size inter_size, dcp::Size out_size, dcp::YUVToRGB yuv_to_rgb, AVPixelFormat out_format, bool out_aligned, bool fast
) const
{
/* Empirical testing suggests that sws_scale() will crash if
struct SwsContext* scale_context = sws_getContext (
cropped_size.width, cropped_size.height, pixel_format(),
inter_size.width, inter_size.height, out_format,
- SWS_BICUBIC, 0, 0, 0
+ fast ? SWS_FAST_BILINEAR : SWS_BICUBIC, 0, 0, 0
);
if (!scale_context) {
return out;
}
+/** @param fast Try to be fast at the possible expense of quality; at present this means using
+ * fast bilinear rather than bicubic scaling.
+ */
shared_ptr<Image>
-Image::scale (dcp::Size out_size, dcp::YUVToRGB yuv_to_rgb, AVPixelFormat out_format, bool out_aligned) const
+Image::scale (dcp::Size out_size, dcp::YUVToRGB yuv_to_rgb, AVPixelFormat out_format, bool out_aligned, bool fast) const
{
/* Empirical testing suggests that sws_scale() will crash if
the input image is not aligned.
struct SwsContext* scale_context = sws_getContext (
size().width, size().height, pixel_format(),
out_size.width, out_size.height, out_format,
- SWS_BICUBIC, 0, 0, 0
+ fast ? SWS_FAST_BILINEAR : SWS_BICUBIC, 0, 0, 0
);
DCPOMATIC_ASSERT (yuv_to_rgb < dcp::YUV_TO_RGB_COUNT);
/*
- Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
int line_factor (int) const;
dcp::Size sample_size (int) const;
- boost::shared_ptr<Image> scale (dcp::Size, dcp::YUVToRGB yuv_to_rgb, AVPixelFormat, bool aligned) const;
- boost::shared_ptr<Image> crop_scale_window (Crop c, dcp::Size, dcp::Size, dcp::YUVToRGB yuv_to_rgb, AVPixelFormat, bool aligned) const;
+ boost::shared_ptr<Image> scale (dcp::Size, dcp::YUVToRGB yuv_to_rgb, AVPixelFormat, bool aligned, bool fast) const;
+ boost::shared_ptr<Image> crop_scale_window (
+ Crop c, dcp::Size, dcp::Size, dcp::YUVToRGB yuv_to_rgb, AVPixelFormat, bool aligned, bool fast)
+ const;
void make_black ();
void make_transparent ();
scaled_size,
dcp::YUV_TO_RGB_REC601,
i->image->pixel_format (),
- true
+ true,
+ _fast
),
Position<int> (
lrint (_video_container_size.width * i->rectangle.x),
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
using boost::optional;
+using boost::function;
using dcp::Data;
PlayerVideo::PlayerVideo (
_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));
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);
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;
+}
void set_subtitle (PositionImage);
- boost::shared_ptr<Image> image (dcp::NoteHandler note) const;
+ boost::shared_ptr<Image> image (dcp::NoteHandler note, boost::function<AVPixelFormat (AVPixelFormat)> pixel_format, bool aligned, bool fast) const;
+
+ static AVPixelFormat always_rgb (AVPixelFormat);
+ static AVPixelFormat keep_xyz_or_rgb (AVPixelFormat);
void add_metadata (xmlpp::Node* node) const;
void send_binary (boost::shared_ptr<Socket> socket) const;
try {
_player.reset (new Player (_film, _film->playlist ()));
+ _player->set_fast ();
} catch (bad_alloc) {
error_dialog (this, _("There is not enough free memory to do that."));
_film.reset ();
pv = all_pv.front ();
}
- /* XXX: this could now give us a 48-bit image, which is a bit wasteful,
- or a XYZ image, which the code below will currently rely on FFmpeg
- to colourspace-convert.
- */
- _frame = pv->image (boost::bind (&Log::dcp_log, _film->log().get(), _1, _2));
- ImageChanged (pv);
+ _frame = pv->image (
+ bind (&Log::dcp_log, _film->log().get(), _1, _2), bind (&PlayerVideo::always_rgb, _1), false, true
+ );
- dcp::YUVToRGB yuv_to_rgb = dcp::YUV_TO_RGB_REC601;
- if (pv->colour_conversion()) {
- yuv_to_rgb = pv->colour_conversion().get().yuv_to_rgb();
- }
+ ImageChanged (pv);
- _frame = _frame->scale (_frame->size(), yuv_to_rgb, AV_PIX_FMT_RGB24, false);
_position = pv->time ();
_inter_position = pv->inter_position ();
_inter_size = pv->inter_size ();
_waveform = _waveform->scale (
dcp::Size (GetSize().GetWidth() - 32, GetSize().GetHeight() - _vertical_margin * 2),
- dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB24, false
+ dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB24, false, true
);
}
for (list<AVPixelFormat>::const_iterator i = pix_fmts.begin(); i != pix_fmts.end(); ++i) {
boost::shared_ptr<Image> foo (new Image (*i, in_size, true));
foo->make_black ();
- boost::shared_ptr<Image> bar = foo->scale (out_size, dcp::YUV_TO_RGB_REC601, AV_PIX_FMT_RGB24, true);
+ boost::shared_ptr<Image> bar = foo->scale (out_size, dcp::YUV_TO_RGB_REC601, AV_PIX_FMT_RGB24, true, false);
uint8_t* p = bar->data()[0];
for (int y = 0; y < bar->size().height; ++y) {