+2013-10-15 Carl Hetherington <cth@carlh.net>
+
+ * Allow no-stretch scaling like in DVD-o-matic.
+
2013-10-14 Carl Hetherington <cth@carlh.net>
* Add Rec. 709 colour conversion preset using
shared_ptr<Image>
Image::crop (Crop crop, bool aligned) const
{
- libdcp::Size cropped_size = size ();
- cropped_size.width -= crop.left + crop.right;
- cropped_size.height -= crop.top + crop.bottom;
-
+ libdcp::Size cropped_size = crop.apply (size ());
shared_ptr<Image> out (new Image (pixel_format(), cropped_size, aligned));
for (int c = 0; c < components(); ++c) {
_playlist_changed_connection = _playlist->Changed.connect (bind (&Player::playlist_changed, this));
_playlist_content_changed_connection = _playlist->ContentChanged.connect (bind (&Player::content_changed, this, _1, _2, _3));
_film_changed_connection = _film->Changed.connect (bind (&Player::film_changed, this, _1));
- set_video_container_size (_film->container()->size (_film->full_frame ()));
+ set_video_container_size (fit_ratio_within (_film->container()->ratio (), _film->full_frame ()));
}
void
work_image = work_image->crop (content->crop(), true);
- libdcp::Size const image_size = content->ratio()->size (_video_container_size);
+ float const ratio = content->ratio() ? content->ratio()->ratio() : content->video_size_after_crop().ratio();
+ libdcp::Size image_size = fit_ratio_within (ratio, _video_container_size);
work_image = work_image->scale (image_size, _film->scaler(), PIX_FMT_RGB24, true);
#include <libdcp/types.h>
#include "ratio.h"
+#include "util.h"
#include "i18n.h"
vector<Ratio const *> Ratio::_ratios;
-libdcp::Size
-Ratio::size (libdcp::Size full_frame) const
-{
- if (_ratio < static_cast<float>(full_frame.width) / full_frame.height) {
- return libdcp::Size (full_frame.height * _ratio, full_frame.height);
- } else {
- return libdcp::Size (full_frame.width, full_frame.width / _ratio);
- }
-
- return libdcp::Size ();
-}
-
-
void
Ratio::setup_ratios ()
{
, _dci_name (d)
{}
- libdcp::Size size (libdcp::Size) const;
-
std::string id () const {
return _id;
}
int top;
/** Number of pixels to remove from the bottom */
int bottom;
+
+ libdcp::Size apply (libdcp::Size s, int minimum = 4) const {
+ s.width -= left + right;
+ s.height -= top + bottom;
+
+ if (s.width < minimum) {
+ s.width = minimum;
+ }
+
+ if (s.height < minimum) {
+ s.height = minimum;
+ }
+
+ return s;
+ }
};
extern bool operator== (Crop const & a, Crop const & b);
return shared_ptr<const libdcp::Signer> (new libdcp::Signer (chain, signer_key));
}
+libdcp::Size
+fit_ratio_within (float ratio, libdcp::Size full_frame)
+{
+ if (ratio < full_frame.ratio ()) {
+ return libdcp::Size (full_frame.height * ratio, full_frame.height);
+ }
+
+ return libdcp::Size (full_frame.width, full_frame.width / ratio);
+}
extern boost::filesystem::path mo_path ();
#endif
extern std::string tidy_for_filename (std::string);
-boost::shared_ptr<const libdcp::Signer> make_signer ();
+extern boost::shared_ptr<const libdcp::Signer> make_signer ();
+extern libdcp::Size fit_ratio_within (float ratio, libdcp::Size);
struct FrameRateConversion
{
VideoContent::VideoContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node)
: Content (f, node)
+ , _ratio (0)
{
_video_length = node->number_child<VideoContent::Frame> ("VideoLength");
_video_size.width = node->number_child<int> ("VideoWidth");
_("%1x%2 pixels (%3:1)"),
video_size().width,
video_size().height,
- setprecision (3), float (video_size().width) / video_size().height
+ setprecision (3), video_size().ratio ()
);
return s.str ();
signal_changed (VideoContentProperty::COLOUR_CONVERSION);
}
+
+/** @return Video size after 3D split and crop */
+libdcp::Size
+VideoContent::video_size_after_crop () const
+{
+ return crop().apply (video_size_after_3d_split ());
+}
void set_ratio (Ratio const *);
+ /** @return ratio to scale to, or 0 if the content's own ratio should be preserved. */
Ratio const * ratio () const {
boost::mutex::scoped_lock lm (_mutex);
return _ratio;
}
libdcp::Size video_size_after_3d_split () const;
+ libdcp::Size video_size_after_crop () const;
protected:
void take_from_video_examiner (boost::shared_ptr<VideoExaminer>);
}
_picture_asset->set_edit_rate (_film->video_frame_rate ());
- _picture_asset->set_size (_film->container()->size (_film->full_frame ()));
+ _picture_asset->set_size (fit_ratio_within (_film->container()->ratio(), _film->full_frame ()));
if (_film->encrypted ()) {
_picture_asset->set_key (_film->key ());
Ratio const * container = _film->container ();
- float const panel_ratio = static_cast<float> (_panel_size.width) / _panel_size.height;
+ float const panel_ratio = _panel_size.ratio ();
float const film_ratio = container ? container->ratio () : 1.78;
if (panel_ratio < film_ratio) {
#include "lib/ffmpeg_content.h"
#include "lib/colour_conversion.h"
#include "lib/config.h"
+#include "lib/util.h"
#include "filter_dialog.h"
#include "video_panel.h"
#include "wx_util.h"
for (vector<Ratio const *>::iterator i = ratios.begin(); i != ratios.end(); ++i) {
_ratio->Append (std_to_wx ((*i)->nickname ()));
}
+ _ratio->Append (_("No stretch"));
_frame_type->Append (_("2D"));
_frame_type->Append (_("3D left/right"));
}
if (i == ratios.end()) {
- checked_set (_ratio, -1);
+ checked_set (_ratio, ratios.size ());
} else {
checked_set (_ratio, n);
}
if (vc->video_size().width && vc->video_size().height) {
d << wxString::Format (
_("Content video is %dx%d (%.2f:1)\n"),
- vc->video_size_after_3d_split().width, vc->video_size_after_3d_split().height,
- float (vc->video_size_after_3d_split().width) / vc->video_size_after_3d_split().height
+ vc->video_size_after_3d_split().width,
+ vc->video_size_after_3d_split().height,
+ vc->video_size_after_3d_split().ratio ()
);
++lines;
}
Crop const crop = vc->crop ();
if ((crop.left || crop.right || crop.top || crop.bottom) && vc->video_size() != libdcp::Size (0, 0)) {
- libdcp::Size cropped = vc->video_size_after_3d_split ();
- cropped.width -= crop.left + crop.right;
- cropped.height -= crop.top + crop.bottom;
+ libdcp::Size cropped = vc->video_size_after_crop ();
d << wxString::Format (
_("Cropped to %dx%d (%.2f:1)\n"),
cropped.width, cropped.height,
- float (cropped.width) / cropped.height
+ cropped.ratio ()
);
++lines;
}
Ratio const * ratio = vc->ratio ();
- if (ratio) {
- libdcp::Size container_size = _editor->film()->container()->size (_editor->film()->full_frame ());
-
- libdcp::Size const scaled = ratio->size (container_size);
+ libdcp::Size container_size = fit_ratio_within (_editor->film()->container()->ratio (), _editor->film()->full_frame ());
+ float const ratio_value = ratio ? ratio->ratio() : vc->video_size_after_crop().ratio ();
+
+ /* We have a specified ratio to scale to */
+ libdcp::Size const scaled = fit_ratio_within (ratio_value, container_size);
+
+ d << wxString::Format (
+ _("Scaled to %dx%d (%.2f:1)\n"),
+ scaled.width, scaled.height,
+ scaled.ratio ()
+ );
+ ++lines;
+
+ if (scaled != container_size) {
d << wxString::Format (
- _("Scaled to %dx%d (%.2f:1)\n"),
- scaled.width, scaled.height,
- float (scaled.width) / scaled.height
+ _("Padded with black to %dx%d (%.2f:1)\n"),
+ container_size.width, container_size.height,
+ container_size.ratio ()
);
++lines;
-
- if (scaled != container_size) {
- d << wxString::Format (
- _("Padded with black to %dx%d (%.2f:1)\n"),
- container_size.width, container_size.height,
- float (container_size.width) / container_size.height
- );
- ++lines;
- }
}
d << wxString::Format (_("Content frame rate %.4f\n"), vc->video_frame_rate ());
int const n = _ratio->GetSelection ();
if (n >= 0) {
vector<Ratio const *> ratios = Ratio::all ();
- assert (n < int (ratios.size()));
- vc->set_ratio (ratios[n]);
+ if (n < int (ratios.size ())) {
+ vc->set_ratio (ratios[n]);
+ } else {
+ vc->set_ratio (0);
+ }
}
}
#include <boost/test/unit_test.hpp>
#include <libdcp/util.h>
#include "lib/ratio.h"
+#include "lib/util.h"
using std::ostream;
Ratio const * r = Ratio::from_id ("119");
BOOST_CHECK (r);
- BOOST_CHECK_EQUAL (r->size(libdcp::Size (2048, 1080)), libdcp::Size (1285, 1080));
+ BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1285, 1080));
r = Ratio::from_id ("133");
BOOST_CHECK (r);
- BOOST_CHECK_EQUAL (r->size(libdcp::Size (2048, 1080)), libdcp::Size (1436, 1080));
+ BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1436, 1080));
r = Ratio::from_id ("137");
BOOST_CHECK (r);
- BOOST_CHECK_EQUAL (r->size(libdcp::Size (2048, 1080)), libdcp::Size (1480, 1080));
+ BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1480, 1080));
r = Ratio::from_id ("138");
BOOST_CHECK (r);
- BOOST_CHECK_EQUAL (r->size(libdcp::Size (2048, 1080)), libdcp::Size (1485, 1080));
+ BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1485, 1080));
r = Ratio::from_id ("166");
BOOST_CHECK (r);
- BOOST_CHECK_EQUAL (r->size(libdcp::Size (2048, 1080)), libdcp::Size (1793, 1080));
+ BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1793, 1080));
r = Ratio::from_id ("178");
BOOST_CHECK (r);
- BOOST_CHECK_EQUAL (r->size(libdcp::Size (2048, 1080)), libdcp::Size (1920, 1080));
+ BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1920, 1080));
r = Ratio::from_id ("185");
BOOST_CHECK (r);
- BOOST_CHECK_EQUAL (r->size(libdcp::Size (2048, 1080)), libdcp::Size (1998, 1080));
+ BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1998, 1080));
r = Ratio::from_id ("239");
BOOST_CHECK (r);
- BOOST_CHECK_EQUAL (r->size(libdcp::Size (2048, 1080)), libdcp::Size (2048, 858));
+ BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (2048, 858));
r = Ratio::from_id ("full-frame");
BOOST_CHECK (r);
- BOOST_CHECK_EQUAL (r->size(libdcp::Size (2048, 1080)), libdcp::Size (2048, 1080));
+ BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (2048, 1080));
}