2 Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 #include "lib/ratio.h"
23 #include "lib/video_content.h"
24 #include <boost/test/unit_test.hpp>
27 static dcp::Size const FOUR_TO_THREE(1436, 1080);
28 static dcp::Size const FLAT(1998, 1080);
29 static dcp::Size const SCOPE(2048, 858);
32 /* Test VideoContent::scaled_size() without any legacy stuff */
33 BOOST_AUTO_TEST_CASE (scaled_size_test1)
37 /* Images at full size and in DCP-approved sizes that will not be scaled */
38 // Flat/scope content into flat/scope container
40 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FLAT);
42 BOOST_CHECK_EQUAL (vc.scaled_size(SCOPE), SCOPE);
43 // 1.33:1 into flat container
44 vc._size = FOUR_TO_THREE;
45 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(FOUR_TO_THREE));
46 // Scope into flat container
48 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 837));
50 /* Smaller images but in the same ratios */
51 vc._size = dcp::Size(185, 100);
52 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FLAT);
53 vc._size = dcp::Size(955, 400);
54 BOOST_CHECK_EQUAL (vc.scaled_size(SCOPE), SCOPE);
55 // 1.33:1 into flat container
56 vc._size = dcp::Size(133, 100);
57 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(FOUR_TO_THREE));
58 // Scope into flat container
59 vc._size = dcp::Size(239, 100);
60 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 836));
62 /* Images at full size that are not DCP-approved but will still remain unscaled */
63 vc._size = dcp::Size(600, 1080);
64 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(600, 1080));
65 vc._size = dcp::Size(1700, 1080);
66 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1700, 1080));
68 /* Image at full size that is too big for the container and will be shrunk */
69 vc._size = dcp::Size(3000, 1080);
70 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 719));
74 /* Same as scaled_size_test1 but with a non-unity sample aspect ratio */
75 BOOST_AUTO_TEST_CASE (scaled_size_test2)
79 vc._sample_aspect_ratio = 2;
81 /* Images at full size and in DCP-approved sizes that will not be scaled */
82 // Flat/scope content into flat/scope container
83 vc._size = dcp::Size (1998 / 2, 1080);
84 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FLAT);
85 vc._size = dcp::Size (2048 / 2, 858);
86 BOOST_CHECK_EQUAL (vc.scaled_size(SCOPE), SCOPE);
87 // 1.33:1 into flat container
88 vc._size = dcp::Size (1436 / 2, 1080);
89 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(FOUR_TO_THREE));
90 // Scope into flat container
91 vc._size = dcp::Size (2048 / 2, 858);
92 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 837));
94 /* Smaller images but in the same ratios */
95 vc._size = dcp::Size(185, 200);
96 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FLAT);
97 vc._size = dcp::Size(955, 800);
98 BOOST_CHECK_EQUAL (vc.scaled_size(SCOPE), SCOPE);
99 // 4:3 into flat container
100 vc._size = dcp::Size(133, 200);
101 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(FOUR_TO_THREE));
102 // Scope into flat container
103 vc._size = dcp::Size(239, 200);
104 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 836));
106 /* Images at full size that are not DCP-approved but will still remain unscaled */
107 vc._size = dcp::Size(600 / 2, 1080);
108 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(600, 1080));
109 vc._size = dcp::Size(1700 / 2, 1080);
110 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1700, 1080));
112 /* Image at full size that is too big for the container and will be shrunk */
113 vc._size = dcp::Size(3000 / 2, 1080);
114 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 719));
118 /* Test VideoContent::scaled_size() with some legacy stuff */
119 BOOST_AUTO_TEST_CASE (scaled_size_legacy_test)
122 /* 640x480 content that the user had asked to be stretched to 1.85:1 */
124 vc._size = dcp::Size(640, 480);
125 vc._legacy_ratio = Ratio::from_id("185")->ratio();
126 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FLAT);
130 /* 640x480 content that the user had asked to be scaled to fit the container, without stretch */
132 vc._size = dcp::Size(640, 480);
133 vc._legacy_ratio = 1.33;
134 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FOUR_TO_THREE);
138 /* 640x480 content that the user had asked to be kept the same size */
140 vc._size = dcp::Size(640, 480);
141 vc._custom_size = dcp::Size(640, 480);
142 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(640, 480));