2 Copyright (C) 2015 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/>.
21 #include <boost/test/unit_test.hpp>
22 #include "lib/ffmpeg_content.h"
23 #include "lib/ratio.h"
24 #include "lib/video_content.h"
29 using boost::shared_ptr;
30 using boost::optional;
34 test (dcp::Size content_size, dcp::Size display_size, dcp::Size film_size, Crop crop, Ratio const * ratio, bool scale, dcp::Size correct)
36 shared_ptr<Film> film;
37 string s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
40 "<Path>/home/c.hetherington/DCP/prophet_clip.mkv</Path>"
41 "<Digest>f3f23663da5bef6d2cbaa0db066f3351314142710</Digest>"
42 "<Position>0</Position>"
43 "<TrimStart>0</TrimStart>"
44 "<TrimEnd>0</TrimEnd>"
45 "<VideoLength>2879</VideoLength>"
46 "<VideoWidth>" + raw_convert<string>(content_size.width) + "</VideoWidth>"
47 "<VideoHeight>" + raw_convert<string>(content_size.height) + "</VideoHeight>"
48 "<VideoFrameRate>23.97602462768555</VideoFrameRate>"
49 "<OriginalVideoFrameRate>23.97602462768555</OriginalVideoFrameRate>"
50 "<VideoFrameType>0</VideoFrameType>"
51 "<SampleAspectRatio>1</SampleAspectRatio>"
52 "<BitsPerPixel>12</BitsPerPixel>"
53 "<LeftCrop>" + raw_convert<string>(crop.left) + "</LeftCrop>"
54 "<RightCrop>" + raw_convert<string>(crop.right) + "</RightCrop>"
55 "<TopCrop>" + raw_convert<string>(crop.top) + "</TopCrop>"
56 "<BottomCrop>" + raw_convert<string>(crop.bottom) + "</BottomCrop>"
60 s += "<Ratio>" + ratio->id() + "</Ratio>";
62 s += "<Scale>" + string(scale ? "1" : "0") + "</Scale>";
67 "<InputGamma>2.4</InputGamma>"
68 "<InputGammaLinearised>1</InputGammaLinearised>"
69 "<Matrix i=\"0\" j=\"0\">0.4124564</Matrix>"
70 "<Matrix i=\"0\" j=\"1\">0.3575761</Matrix>"
71 "<Matrix i=\"0\" j=\"2\">0.1804375</Matrix>"
72 "<Matrix i=\"1\" j=\"0\">0.2126729</Matrix>"
73 "<Matrix i=\"1\" j=\"1\">0.7151522</Matrix>"
74 "<Matrix i=\"1\" j=\"2\">0.072175</Matrix>"
75 "<Matrix i=\"2\" j=\"0\">0.0193339</Matrix>"
76 "<Matrix i=\"2\" j=\"1\">0.119192</Matrix>"
77 "<Matrix i=\"2\" j=\"2\">0.9503041</Matrix>"
78 "<OutputGamma>2.6</OutputGamma>"
80 "<AudioGain>0</AudioGain>"
81 "<AudioDelay>0</AudioDelay>"
82 "<SubtitleXOffset>0</SubtitleXOffset>"
83 "<SubtitleYOffset>0</SubtitleYOffset>"
84 "<SubtitleXScale>0</SubtitleXScale>"
85 "<SubtitleYScale>0</SubtitleYScale>"
88 shared_ptr<cxml::Document> doc (new cxml::Document ());
92 shared_ptr<FFmpegContent> vc (new FFmpegContent (film, doc, 10, notes));
94 optional<VideoContentScale> sc;
96 sc = VideoContentScale (ratio);
98 sc = VideoContentScale (scale);
101 dcp::Size answer = sc.get().size (vc->video, display_size, film_size);
102 if (answer != correct) {
103 cerr << "Testing " << vc->video->size().width << "x" << vc->video->size().height << "\n";
104 cerr << "Testing " << display_size.width << "x" << display_size.height << "\n";
105 cerr << answer.width << "x" << answer.height << " instead of " << correct.width << "x" << correct.height << "\n";
107 BOOST_CHECK (answer == correct);
110 /* Test scale and stretch to specified ratio */
111 BOOST_AUTO_TEST_CASE (video_content_scale_test_to_ratio)
115 // Flat in flat container
117 dcp::Size (400, 200),
118 dcp::Size (1998, 1080),
119 dcp::Size (1998, 1080),
121 Ratio::from_id ("185"),
123 dcp::Size (1998, 1080)
126 // Scope in flat container
128 dcp::Size (400, 200),
129 dcp::Size (1998, 1080),
130 dcp::Size (1998, 1080),
132 Ratio::from_id ("239"),
134 dcp::Size (1998, 837)
137 // Flat in scope container
139 dcp::Size (400, 200),
140 dcp::Size (2048, 858),
141 dcp::Size (2048, 858),
143 Ratio::from_id ("185"),
145 dcp::Size (1587, 858)
151 // Flat in flat container
153 dcp::Size (400, 200),
154 dcp::Size (185, 100),
155 dcp::Size (1998, 1080),
157 Ratio::from_id ("185"),
162 // Scope in flat container
164 dcp::Size (400, 200),
165 dcp::Size (185, 100),
166 dcp::Size (1998, 1080),
168 Ratio::from_id ("239"),
173 // Flat in scope container
175 dcp::Size (400, 200),
176 dcp::Size (239, 100),
177 dcp::Size (2048, 858),
179 Ratio::from_id ("185"),
186 BOOST_AUTO_TEST_CASE (video_content_scale_no_scale)
188 /* No scale where the content is bigger than even the film container */
190 dcp::Size (1920, 1080),
191 dcp::Size (887, 371),
192 dcp::Size (2048, 858),