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 /** @file test/video_content_scale_test.cc
22 * @brief Test VideoContentScale
23 * @ingroup selfcontained
26 #include "lib/ffmpeg_content.h"
27 #include "lib/ratio.h"
28 #include "lib/video_content.h"
29 #include <dcp/raw_convert.h>
30 #include <boost/test/unit_test.hpp>
35 using boost::shared_ptr;
36 using boost::optional;
37 using dcp::raw_convert;
41 test (dcp::Size content_size, dcp::Size display_size, dcp::Size film_size, Crop crop, Ratio const * ratio, bool scale, dcp::Size correct)
43 shared_ptr<Film> film;
44 string s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
47 "<Path>/home/c.hetherington/DCP/prophet_long_clip.mkv</Path>"
48 "<Digest>f3f23663da5bef6d2cbaa0db066f3351314142710</Digest>"
49 "<Position>0</Position>"
50 "<TrimStart>0</TrimStart>"
51 "<TrimEnd>0</TrimEnd>"
52 "<VideoLength>2879</VideoLength>"
53 "<VideoWidth>" + raw_convert<string>(content_size.width) + "</VideoWidth>"
54 "<VideoHeight>" + raw_convert<string>(content_size.height) + "</VideoHeight>"
55 "<VideoFrameRate>23.97602462768555</VideoFrameRate>"
56 "<OriginalVideoFrameRate>23.97602462768555</OriginalVideoFrameRate>"
57 "<VideoFrameType>0</VideoFrameType>"
58 "<SampleAspectRatio>1</SampleAspectRatio>"
59 "<BitsPerPixel>12</BitsPerPixel>"
60 "<LeftCrop>" + raw_convert<string>(crop.left) + "</LeftCrop>"
61 "<RightCrop>" + raw_convert<string>(crop.right) + "</RightCrop>"
62 "<TopCrop>" + raw_convert<string>(crop.top) + "</TopCrop>"
63 "<BottomCrop>" + raw_convert<string>(crop.bottom) + "</BottomCrop>"
67 s += "<Ratio>" + ratio->id() + "</Ratio>";
69 s += "<Scale>" + string(scale ? "1" : "0") + "</Scale>";
74 "<InputGamma>2.4</InputGamma>"
75 "<InputGammaLinearised>1</InputGammaLinearised>"
76 "<Matrix i=\"0\" j=\"0\">0.4124564</Matrix>"
77 "<Matrix i=\"0\" j=\"1\">0.3575761</Matrix>"
78 "<Matrix i=\"0\" j=\"2\">0.1804375</Matrix>"
79 "<Matrix i=\"1\" j=\"0\">0.2126729</Matrix>"
80 "<Matrix i=\"1\" j=\"1\">0.7151522</Matrix>"
81 "<Matrix i=\"1\" j=\"2\">0.072175</Matrix>"
82 "<Matrix i=\"2\" j=\"0\">0.0193339</Matrix>"
83 "<Matrix i=\"2\" j=\"1\">0.119192</Matrix>"
84 "<Matrix i=\"2\" j=\"2\">0.9503041</Matrix>"
85 "<OutputGamma>2.6</OutputGamma>"
87 "<AudioGain>0</AudioGain>"
88 "<AudioDelay>0</AudioDelay>"
89 "<SubtitleXOffset>0</SubtitleXOffset>"
90 "<SubtitleYOffset>0</SubtitleYOffset>"
91 "<SubtitleXScale>0</SubtitleXScale>"
92 "<SubtitleYScale>0</SubtitleYScale>"
95 shared_ptr<cxml::Document> doc (new cxml::Document ());
99 shared_ptr<FFmpegContent> vc (new FFmpegContent (doc, 10, notes));
101 optional<VideoContentScale> sc;
103 sc = VideoContentScale (ratio);
105 sc = VideoContentScale (scale);
108 dcp::Size answer = sc.get().size (vc->video, display_size, film_size);
109 if (answer != correct) {
110 cerr << "Testing " << vc->video->size().width << "x" << vc->video->size().height << "\n";
111 cerr << "Testing " << display_size.width << "x" << display_size.height << "\n";
112 cerr << answer.width << "x" << answer.height << " instead of " << correct.width << "x" << correct.height << "\n";
114 BOOST_CHECK (answer == correct);
117 /* Test scale and stretch to specified ratio */
118 BOOST_AUTO_TEST_CASE (video_content_scale_test_to_ratio)
122 // Flat in flat container
124 dcp::Size (400, 200),
125 dcp::Size (1998, 1080),
126 dcp::Size (1998, 1080),
128 Ratio::from_id ("185"),
130 dcp::Size (1998, 1080)
133 // Scope in flat container
135 dcp::Size (400, 200),
136 dcp::Size (1998, 1080),
137 dcp::Size (1998, 1080),
139 Ratio::from_id ("239"),
141 dcp::Size (1998, 837)
144 // Flat in scope container
146 dcp::Size (400, 200),
147 dcp::Size (2048, 858),
148 dcp::Size (2048, 858),
150 Ratio::from_id ("185"),
152 dcp::Size (1587, 858)
158 // Flat in flat container
160 dcp::Size (400, 200),
161 dcp::Size (185, 100),
162 dcp::Size (1998, 1080),
164 Ratio::from_id ("185"),
169 // Scope in flat container
171 dcp::Size (400, 200),
172 dcp::Size (185, 100),
173 dcp::Size (1998, 1080),
175 Ratio::from_id ("239"),
180 // Flat in scope container
182 dcp::Size (400, 200),
183 dcp::Size (239, 100),
184 dcp::Size (2048, 858),
186 Ratio::from_id ("185"),
193 BOOST_AUTO_TEST_CASE (video_content_scale_no_scale)
195 /* No scale where the content is bigger than even the film container */
197 dcp::Size (1920, 1080),
198 dcp::Size (887, 371),
199 dcp::Size (2048, 858),