2 Copyright (C) 2022 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/content.h"
23 #include "lib/content_factory.h"
25 #include "lib/make_dcp.h"
26 #include "lib/text_content.h"
28 #include <dcp/interop_subtitle_asset.h>
29 #include <dcp/language_tag.h>
30 #include <dcp/smpte_subtitle_asset.h>
31 #include <boost/test/unit_test.hpp>
35 using std::shared_ptr;
40 BOOST_AUTO_TEST_CASE(srt_correctly_placed_in_interop)
42 string const name = "srt_in_interop_position_test";
43 auto fr = content_factory("test/data/short.srt");
44 auto film = new_test_film2(name, fr);
45 fr[0]->only_text()->set_language(dcp::LanguageTag("de"));
47 film->set_interop(true);
52 dcp::VerificationNote::Code::INVALID_STANDARD,
53 dcp::VerificationNote::Code::INVALID_SUBTITLE_SPACING,
54 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME
57 auto output = subtitle_file(film);
59 dcp::InteropSubtitleAsset asset(output);
60 auto output_subs = asset.subtitles();
61 BOOST_REQUIRE_EQUAL(output_subs.size(), 1U);
63 BOOST_CHECK(output_subs[0]->v_align() == dcp::VAlign::BOTTOM);
64 BOOST_CHECK_CLOSE(output_subs[0]->v_position(), 0.172726989, 1e-3);
68 BOOST_AUTO_TEST_CASE(srt_correctly_placed_in_smpte)
70 string const name = "srt_in_smpte_position_test";
71 auto fr = content_factory("test/data/short.srt");
72 auto film = new_test_film2(name, fr);
74 fr[0]->text[0]->set_language(dcp::LanguageTag("en"));
75 film->set_interop(false);
80 dcp::VerificationNote::Code::MISSING_CPL_METADATA,
81 dcp::VerificationNote::Code::INVALID_SUBTITLE_SPACING,
82 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME
85 auto output = subtitle_file(film);
87 dcp::SMPTESubtitleAsset asset(output);
88 auto output_subs = asset.subtitles();
89 BOOST_REQUIRE_EQUAL(output_subs.size(), 1U);
91 BOOST_CHECK(output_subs[0]->v_align() == dcp::VAlign::BOTTOM);
92 BOOST_CHECK_CLOSE(output_subs[0]->v_position(), 0.172726989, 1e-3);
96 /** Make a DCP from some DCP subtitles and check the vertical alignment */
99 vpos_test(dcp::VAlign reference, float position, dcp::SubtitleStandard from, dcp::Standard to)
103 case dcp::SubtitleStandard::SMPTE_2007:
104 case dcp::SubtitleStandard::SMPTE_2010:
105 standard = "smpte_2010";
107 case dcp::SubtitleStandard::INTEROP:
108 standard = "interop";
110 case dcp::SubtitleStandard::SMPTE_2014:
111 standard = "smpte_2014";
115 auto name = String::compose("vpos_test_%1_%2", standard, valign_to_string(reference));
116 auto in = content_factory(String::compose("test/data/%1.xml", name));
117 auto film = new_test_film2(name, in);
119 film->set_interop(to == dcp::Standard::INTEROP);
121 film->write_metadata();
122 make_dcp(film, TranscodeJob::ChangedBehaviour::IGNORE);
123 BOOST_REQUIRE(!wait_for_jobs());
125 auto out = subtitle_file(film);
126 vector<shared_ptr<const dcp::Subtitle>> subtitles;
127 if (to == dcp::Standard::INTEROP) {
128 dcp::InteropSubtitleAsset asset(out);
129 subtitles = asset.subtitles();
131 dcp::SMPTESubtitleAsset asset(out);
132 subtitles = asset.subtitles();
135 BOOST_REQUIRE_EQUAL(subtitles.size(), 1U);
137 BOOST_CHECK(subtitles[0]->v_align() == reference);
138 BOOST_CHECK_CLOSE(subtitles[0]->v_position(), position, 2);
142 BOOST_AUTO_TEST_CASE(subtitles_correctly_placed_with_all_references)
144 constexpr auto baseline_to_bottom = 0.00925926;
145 constexpr auto height = 0.0462963;
148 auto from = dcp::SubtitleStandard::INTEROP;
151 vpos_test(dcp::VAlign::TOP, 0.2, from, dcp::Standard::INTEROP);
152 vpos_test(dcp::VAlign::CENTER, 0.11, from, dcp::Standard::INTEROP);
153 vpos_test(dcp::VAlign::BOTTOM, 0.08, from, dcp::Standard::INTEROP);
156 vpos_test(dcp::VAlign::TOP, 0.2, from, dcp::Standard::SMPTE);
157 vpos_test(dcp::VAlign::CENTER, 0.11, from, dcp::Standard::SMPTE);
158 vpos_test(dcp::VAlign::BOTTOM, 0.08, from, dcp::Standard::SMPTE);
160 /* SMPTE 2010 source */
161 from = dcp::SubtitleStandard::SMPTE_2010;
164 vpos_test(dcp::VAlign::TOP, 0.1 + height - baseline_to_bottom, from, dcp::Standard::INTEROP);
165 vpos_test(dcp::VAlign::CENTER, 0.15 + (height / 2) - baseline_to_bottom, from, dcp::Standard::INTEROP);
166 vpos_test(dcp::VAlign::BOTTOM, 0.10 + baseline_to_bottom, from, dcp::Standard::INTEROP);
169 vpos_test(dcp::VAlign::TOP, 0.1 + height - baseline_to_bottom, from, dcp::Standard::SMPTE);
170 vpos_test(dcp::VAlign::CENTER, 0.15 + (height / 2) - baseline_to_bottom, from, dcp::Standard::SMPTE);
171 vpos_test(dcp::VAlign::BOTTOM, 0.10 + baseline_to_bottom, from, dcp::Standard::SMPTE);
173 /* SMPTE 2014 source */
174 from = dcp::SubtitleStandard::SMPTE_2014;
177 vpos_test(dcp::VAlign::TOP, 0.2, from, dcp::Standard::INTEROP);
178 vpos_test(dcp::VAlign::CENTER, 0.11, from, dcp::Standard::INTEROP);
179 vpos_test(dcp::VAlign::BOTTOM, 0.08, from, dcp::Standard::INTEROP);
182 vpos_test(dcp::VAlign::TOP, 0.2, from, dcp::Standard::SMPTE);
183 vpos_test(dcp::VAlign::CENTER, 0.11, from, dcp::Standard::SMPTE);
184 vpos_test(dcp::VAlign::BOTTOM, 0.08, from, dcp::Standard::SMPTE);