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/smpte_subtitle_asset.h>
30 #include <dcp/language_tag.h>
31 #include <boost/test/unit_test.hpp>
37 using std::shared_ptr;
40 BOOST_AUTO_TEST_CASE(interop_correctly_placed_in_interop)
42 string const name = "interop_in_interop_position_test";
43 auto fr = content_factory("test/data/dcp_sub.xml");
44 auto film = new_test_film2(name, fr);
46 film->set_interop(true);
51 dcp::VerificationNote::Code::INVALID_STANDARD,
52 dcp::VerificationNote::Code::INVALID_SUBTITLE_SPACING,
53 dcp::VerificationNote::Code::INVALID_SUBTITLE_DURATION
56 auto output = subtitle_file(film);
57 dcp::InteropSubtitleAsset asset(output);
58 auto output_subs = asset.subtitles();
59 BOOST_REQUIRE_EQUAL(output_subs.size(), 1U);
61 /* The input subtitle should have been left alone */
62 BOOST_CHECK(output_subs[0]->v_align() == dcp::VAlign::BOTTOM);
63 BOOST_CHECK_CLOSE(output_subs[0]->v_position(), 0.08, 1e-3);
67 BOOST_AUTO_TEST_CASE(interop_correctly_placed_in_smpte)
69 string const name = "interop_in_smpte_position_test";
70 auto fr = content_factory("test/data/dcp_sub.xml");
71 auto film = new_test_film2(name, fr);
73 film->set_interop(false);
78 dcp::VerificationNote::Code::INVALID_SUBTITLE_SPACING,
79 dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
80 dcp::VerificationNote::Code::MISSING_CPL_METADATA,
81 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME
84 auto output = subtitle_file(film);
85 dcp::SMPTESubtitleAsset asset(output);
86 auto output_subs = asset.subtitles();
87 BOOST_REQUIRE_EQUAL(output_subs.size(), 1U);
89 BOOST_CHECK(output_subs[0]->v_align() == dcp::VAlign::BOTTOM);
90 BOOST_CHECK_CLOSE(output_subs[0]->v_position(), 0.07074, 2);
94 BOOST_AUTO_TEST_CASE(smpte_correctly_placed_in_interop)
96 string const name = "smpte_in_interop_position_test";
97 auto fr = content_factory("test/data/short.srt");
98 auto film = new_test_film2(name, fr);
100 film->set_interop(true);
102 make_and_verify_dcp (
105 dcp::VerificationNote::Code::INVALID_STANDARD,
106 dcp::VerificationNote::Code::INVALID_SUBTITLE_SPACING,
107 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME
110 auto output = subtitle_file(film);
111 dcp::InteropSubtitleAsset asset(output);
112 auto output_subs = asset.subtitles();
113 BOOST_REQUIRE_EQUAL(output_subs.size(), 1U);
115 BOOST_CHECK(output_subs[0]->v_align() == dcp::VAlign::TOP);
116 BOOST_CHECK_CLOSE(output_subs[0]->v_position(), 0.87079, 1e-3);
122 vpos_test(dcp::VAlign reference, float position, dcp::Standard from, dcp::Standard to)
124 string standard = from == dcp::Standard::INTEROP ? "interop" : "smpte";
125 auto name = String::compose("vpos_test_%1_%2", standard, valign_to_string(reference));
126 auto in = content_factory(String::compose("test/data/%1.xml", name));
127 auto film = new_test_film2(name, in);
129 film->set_interop(to == dcp::Standard::INTEROP);
131 film->write_metadata();
132 make_dcp(film, TranscodeJob::ChangedBehaviour::IGNORE);
133 BOOST_REQUIRE(!wait_for_jobs());
135 auto out = subtitle_file(film);
136 vector<shared_ptr<const dcp::Subtitle>> subtitles;
137 if (to == dcp::Standard::INTEROP) {
138 dcp::InteropSubtitleAsset asset(out);
139 subtitles = asset.subtitles();
141 dcp::SMPTESubtitleAsset asset(out);
142 subtitles = asset.subtitles();
145 BOOST_REQUIRE_EQUAL(subtitles.size(), 1U);
147 BOOST_CHECK(subtitles[0]->v_align() == reference);
148 BOOST_CHECK_CLOSE(subtitles[0]->v_position(), position, 2);
152 BOOST_AUTO_TEST_CASE(subtitles_correctly_placed_with_all_references)
154 constexpr auto baseline_to_bottom = 0.00925926;
155 constexpr auto height = 0.0462963;
157 vpos_test(dcp::VAlign::TOP, 0.2 - height + baseline_to_bottom, dcp::Standard::INTEROP, dcp::Standard::SMPTE);
158 vpos_test(dcp::VAlign::CENTER, 0.11 - (height / 2) + baseline_to_bottom, dcp::Standard::INTEROP, dcp::Standard::SMPTE);
159 vpos_test(dcp::VAlign::BOTTOM, 0.08 - baseline_to_bottom, dcp::Standard::INTEROP, dcp::Standard::SMPTE);
160 vpos_test(dcp::VAlign::TOP, 0.1 + height - baseline_to_bottom, dcp::Standard::SMPTE, dcp::Standard::INTEROP);
161 vpos_test(dcp::VAlign::CENTER, 0.15 + (height / 2) - baseline_to_bottom, dcp::Standard::SMPTE, dcp::Standard::INTEROP);
162 vpos_test(dcp::VAlign::BOTTOM, 0.10 + baseline_to_bottom, dcp::Standard::SMPTE, dcp::Standard::INTEROP);