Fix errors when a custom size is given which is larger than the container (#2404).
[dcpomatic.git] / test / scaling_test.cc
1 /*
2     Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 /** @file test/scaling_test.cc
23  *  @brief Test scaling and black-padding of images from a still-image source.
24  *  @ingroup feature
25  */
26
27
28 #include "lib/content_factory.h"
29 #include "lib/dcp_content_type.h"
30 #include "lib/film.h"
31 #include "lib/image_content.h"
32 #include "lib/ratio.h"
33 #include "lib/video_content.h"
34 #include "test.h"
35 #include <boost/test/unit_test.hpp>
36
37
38 using std::string;
39 using std::shared_ptr;
40 using std::make_shared;
41
42
43 static void scaling_test_for (shared_ptr<Film> film, shared_ptr<Content> content, float ratio, std::string image, string container)
44 {
45         content->video->set_custom_ratio (ratio);
46         film->set_container (Ratio::from_id (container));
47         film->set_interop (false);
48         make_and_verify_dcp (
49                 film,
50                 {
51                         dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
52                         dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
53                 });
54
55         boost::filesystem::path ref;
56         ref = "test";
57         ref /= "data";
58         ref /= "scaling_test_" + image + "_" + container;
59
60         boost::filesystem::path check;
61         check = "build";
62         check /= "test";
63         check /= "scaling_test";
64         check /= film->dcp_name();
65
66         check_dcp (ref.string(), check.string());
67 }
68
69
70 BOOST_AUTO_TEST_CASE (scaling_test)
71 {
72         auto film = new_test_film ("scaling_test");
73         film->set_dcp_content_type (DCPContentType::from_isdcf_name("FTR"));
74         film->set_name ("scaling_test");
75         auto imc = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
76
77         film->examine_and_add_content (imc);
78
79         BOOST_REQUIRE (!wait_for_jobs());
80
81         imc->video->set_length (1);
82
83         /* F-133: 133 image in a flat container */
84         scaling_test_for (film, imc, 4.0 / 3, "133", "185");
85         /* F: flat image in a flat container */
86         scaling_test_for (film, imc, 1.85, "185", "185");
87         /* F-S: scope image in a flat container */
88         scaling_test_for (film, imc, 2.38695, "239", "185");
89
90         /* S-133: 133 image in a scope container */
91         scaling_test_for (film, imc, 4.0 / 3, "133", "239");
92         /* S-F: flat image in a scope container */
93         scaling_test_for (film, imc, 1.85, "185", "239");
94         /* S: scope image in a scope container */
95         scaling_test_for (film, imc, 2.38695, "239", "239");
96 }
97
98
99 BOOST_AUTO_TEST_CASE(assertion_failure_when_scaling)
100 {
101         auto content = content_factory("test/data/flat_red.png");
102         auto film = new_test_film2("assertion_failure_when_scaling", content);
103
104         content[0]->video->set_custom_size(dcp::Size{3996, 2180});
105         film->set_resolution(Resolution::FOUR_K);
106
107         make_and_verify_dcp (
108                 film,
109                 {
110                         dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
111                         dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
112                 });
113 }
114