Fill test disk partitions with random noise to expose more bugs.
[dcpomatic.git] / test / video_content_scale_test.cc
1 /*
2     Copyright (C) 2020 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 #include "lib/ratio.h"
23 #include "lib/video_content.h"
24 #include "test.h"
25 #include <boost/test/unit_test.hpp>
26
27
28 static dcp::Size const FOUR_TO_THREE(1436, 1080);
29 static dcp::Size const FLAT(1998, 1080);
30 static dcp::Size const SCOPE(2048, 858);
31
32
33 /* Test VideoContent::scaled_size() without any legacy stuff */
34 BOOST_AUTO_TEST_CASE (scaled_size_test1)
35 {
36         VideoContent vc (0);
37
38         /* Images at full size and in DCP-approved sizes that will not be scaled */
39         // Flat/scope content into flat/scope container
40         vc._size = FLAT;
41         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FLAT);
42         vc._size = SCOPE;
43         BOOST_CHECK_EQUAL (vc.scaled_size(SCOPE), SCOPE);
44         // 1.33:1 into flat container
45         vc._size = FOUR_TO_THREE;
46         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(FOUR_TO_THREE));
47         // Scope into flat container
48         vc._size = SCOPE;
49         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 837));
50
51         /* Smaller images but in the same ratios */
52         vc._size = dcp::Size(185, 100);
53         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FLAT);
54         vc._size = dcp::Size(955, 400);
55         BOOST_CHECK_EQUAL (vc.scaled_size(SCOPE), SCOPE);
56         // 1.33:1 into flat container
57         vc._size = dcp::Size(133, 100);
58         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(FOUR_TO_THREE));
59         // Scope into flat container
60         vc._size = dcp::Size(239, 100);
61         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 836));
62
63         /* Images at full size that are not DCP-approved but will still remain unscaled */
64         vc._size = dcp::Size(600, 1080);
65         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(600, 1080));
66         vc._size = dcp::Size(1700, 1080);
67         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1700, 1080));
68
69         /* Image at full size that is too big for the container and will be shrunk */
70         vc._size = dcp::Size(3000, 1080);
71         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 719));
72 }
73
74
75 /* Same as scaled_size_test1 but with a non-unity sample aspect ratio */
76 BOOST_AUTO_TEST_CASE (scaled_size_test2)
77 {
78         VideoContent vc (0);
79
80         vc._sample_aspect_ratio = 2;
81
82         /* Images at full size and in DCP-approved sizes that will not be scaled */
83         // Flat/scope content into flat/scope container
84         vc._size = dcp::Size (1998 / 2, 1080);
85         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FLAT);
86         vc._size = dcp::Size (2048 / 2, 858);
87         BOOST_CHECK_EQUAL (vc.scaled_size(SCOPE), SCOPE);
88         // 1.33:1 into flat container
89         vc._size = dcp::Size (1436 / 2, 1080);
90         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(FOUR_TO_THREE));
91         // Scope into flat container
92         vc._size = dcp::Size (2048 / 2, 858);
93         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 837));
94
95         /* Smaller images but in the same ratios */
96         vc._size = dcp::Size(185, 200);
97         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FLAT);
98         vc._size = dcp::Size(955, 800);
99         BOOST_CHECK_EQUAL (vc.scaled_size(SCOPE), SCOPE);
100         // 4:3 into flat container
101         vc._size = dcp::Size(133, 200);
102         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(FOUR_TO_THREE));
103         // Scope into flat container
104         vc._size = dcp::Size(239, 200);
105         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 836));
106
107         /* Images at full size that are not DCP-approved but will still remain unscaled */
108         vc._size = dcp::Size(600 / 2, 1080);
109         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(600, 1080));
110         vc._size = dcp::Size(1700 / 2, 1080);
111         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1700, 1080));
112
113         /* Image at full size that is too big for the container and will be shrunk */
114         vc._size = dcp::Size(3000 / 2, 1080);
115         BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(1998, 719));
116 }
117
118
119 /* Test VideoContent::scaled_size() with some legacy stuff */
120 BOOST_AUTO_TEST_CASE (scaled_size_legacy_test)
121 {
122         {
123                 /* 640x480 content that the user had asked to be stretched to 1.85:1 */
124                 VideoContent vc (0);
125                 vc._size = dcp::Size(640, 480);
126                 vc._legacy_ratio = Ratio::from_id("185")->ratio();
127                 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FLAT);
128         }
129
130         {
131                 /* 640x480 content that the user had asked to be scaled to fit the container, without stretch */
132                 VideoContent vc (0);
133                 vc._size = dcp::Size(640, 480);
134                 vc._legacy_ratio = 1.33;
135                 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), FOUR_TO_THREE);
136         }
137
138         {
139                 /* 640x480 content that the user had asked to be kept the same size */
140                 VideoContent vc (0);
141                 vc._size = dcp::Size(640, 480);
142                 vc._custom_size = dcp::Size(640, 480);
143                 BOOST_CHECK_EQUAL (vc.scaled_size(FLAT), dcp::Size(640, 480));
144         }
145 }
146