2 Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp 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 libdcp 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 libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
35 #include "smpte_load_font_node.h"
36 #include "smpte_subtitle_asset.h"
37 #include "subtitle_image.h"
40 #include <boost/optional/optional_io.hpp>
41 #include <boost/test/unit_test.hpp>
47 using boost::dynamic_pointer_cast;
48 using boost::optional;
49 using boost::shared_ptr;
52 BOOST_AUTO_TEST_CASE (smpte_subtitle_id_test)
54 dcp::SMPTESubtitleAsset subs;
56 shared_ptr<dcp::Subtitle> (
57 new dcp::SubtitleString(
63 dcp::Time(0, 1, 2, 3, 24),
64 dcp::Time(0, 2, 2, 3, 24),
73 dcp::Time(0, 0, 0, 0, 24),
74 dcp::Time(0, 0, 0, 0, 24)
78 subs.write("build/test/smpte_subtitle_id_test.mxf");
80 dcp::SMPTESubtitleAsset check("build/test/smpte_subtitle_id_test.mxf");
81 BOOST_CHECK(check.id() != check.xml_id());
85 /** Check reading of a SMPTE subtitle file */
86 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test)
88 dcp::SMPTESubtitleAsset sc (
91 "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV" /
92 "8b48f6ae-c74b-4b80-b994-a8236bbbad74_sub.mxf"
95 BOOST_CHECK_EQUAL (sc.id(), "8b48f6ae-c74b-4b80-b994-a8236bbbad74");
96 BOOST_CHECK_EQUAL (sc.content_title_text(), "Journey to Jah");
97 BOOST_REQUIRE (sc.annotation_text());
98 BOOST_CHECK_EQUAL (sc.annotation_text().get(), "Journey to Jah");
99 BOOST_CHECK_EQUAL (sc.issue_date(), dcp::LocalTime ("2014-02-25T11:22:48.000-00:00"));
100 BOOST_REQUIRE (sc.reel_number());
101 BOOST_CHECK_EQUAL (sc.reel_number().get(), 1);
102 BOOST_REQUIRE (sc.language ());
103 BOOST_CHECK_EQUAL (sc.language().get (), "de");
104 BOOST_CHECK_EQUAL (sc.edit_rate(), dcp::Fraction (25, 1));
105 BOOST_CHECK_EQUAL (sc.time_code_rate(), 25);
106 BOOST_CHECK_EQUAL (sc.start_time(), dcp::Time (0, 0, 0, 0, 25));
107 auto lfn = sc.load_font_nodes ();
108 BOOST_REQUIRE_EQUAL (lfn.size(), 1);
109 shared_ptr<dcp::SMPTELoadFontNode> smpte_lfn = dynamic_pointer_cast<dcp::SMPTELoadFontNode> (lfn.front ());
110 BOOST_REQUIRE (smpte_lfn);
111 BOOST_CHECK_EQUAL (smpte_lfn->id, "theFontId");
112 BOOST_CHECK_EQUAL (smpte_lfn->urn, "9118bbce-4105-4a05-b37c-a5a6f75e1fea");
113 BOOST_REQUIRE_EQUAL (sc.subtitles().size(), 63);
114 BOOST_REQUIRE (dynamic_pointer_cast<const dcp::SubtitleString>(sc.subtitles().front()));
115 BOOST_CHECK_EQUAL (dynamic_pointer_cast<const dcp::SubtitleString>(sc.subtitles().front())->text(), "Noch mal.");
116 BOOST_CHECK_EQUAL (sc.subtitles().front()->in(), dcp::Time (0, 0, 25, 12, 25));
117 BOOST_CHECK_EQUAL (sc.subtitles().front()->out(), dcp::Time (0, 0, 26, 4, 25));
118 BOOST_REQUIRE (dynamic_pointer_cast<const dcp::SubtitleString>(sc.subtitles().back()));
119 BOOST_CHECK_EQUAL (dynamic_pointer_cast<const dcp::SubtitleString>(sc.subtitles().back())->text(), "Prochainement");
120 BOOST_CHECK_EQUAL (sc.subtitles().back()->in(), dcp::Time (0, 1, 57, 17, 25));
121 BOOST_CHECK_EQUAL (sc.subtitles().back()->out(), dcp::Time (0, 1, 58, 12, 25));
125 /** And another one featuring <Font> within <Text> */
126 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test2)
128 dcp::SMPTESubtitleAsset sc (private_test / "olsson.xml");
130 auto subs = sc.subtitles();
131 BOOST_REQUIRE_EQUAL (subs.size(), 6);
132 auto i = subs.begin();
133 auto is = dynamic_pointer_cast<const dcp::SubtitleString>(*i);
135 BOOST_CHECK_EQUAL (is->text(), "Testing is ");
136 BOOST_CHECK (!is->italic());
138 is = dynamic_pointer_cast<const dcp::SubtitleString>(*i);
140 BOOST_CHECK_EQUAL (is->text(), "really");
141 BOOST_CHECK (is->italic());
143 is = dynamic_pointer_cast<const dcp::SubtitleString>(*i);
145 BOOST_CHECK_EQUAL (is->text(), " fun!");
146 BOOST_CHECK (!is->italic());
148 is = dynamic_pointer_cast<const dcp::SubtitleString>(*i);
150 BOOST_CHECK_EQUAL (is->text(), "This is the ");
151 BOOST_CHECK (!is->italic());
153 is = dynamic_pointer_cast<const dcp::SubtitleString>(*i);
155 BOOST_CHECK_EQUAL (is->text(), "second");
156 BOOST_CHECK (is->italic());
158 is = dynamic_pointer_cast<const dcp::SubtitleString>(*i);
160 BOOST_CHECK_EQUAL (is->text(), " line!");
161 BOOST_CHECK (!is->italic());
165 /** And another one featuring image subtitles */
166 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test3)
168 dcp::SMPTESubtitleAsset subs ("test/data/subs.mxf");
170 BOOST_REQUIRE_EQUAL (subs.subtitles().size(), 1);
171 auto si = dynamic_pointer_cast<const dcp::SubtitleImage>(subs.subtitles().front());
173 BOOST_CHECK (si->png_image() == dcp::Data("test/data/sub.png"));
177 /* Write some subtitle content as SMPTE XML and check that it is right */
178 BOOST_AUTO_TEST_CASE (write_smpte_subtitle_test)
180 dcp::SMPTESubtitleAsset c;
181 c.set_reel_number (1);
182 c.set_language ("en");
183 c.set_content_title_text ("Test");
184 c.set_issue_date (dcp::LocalTime ("2016-04-01T03:52:00+00:00"));
187 shared_ptr<dcp::SubtitleString> (
188 new dcp::SubtitleString(
193 dcp::Colour (255, 255, 255),
196 dcp::Time (0, 4, 9, 22, 24),
197 dcp::Time (0, 4, 11, 22, 24),
205 dcp::Colour (0, 0, 0),
206 dcp::Time (0, 0, 0, 0, 24),
207 dcp::Time (0, 0, 0, 0, 24)
213 shared_ptr<dcp::SubtitleString>(
214 new dcp::SubtitleString(
215 boost::optional<string> (),
219 dcp::Colour (128, 0, 64),
222 dcp::Time (5, 41, 0, 21, 24),
223 dcp::Time (6, 12, 15, 21, 24),
231 dcp::Colour (1, 2, 3),
232 dcp::Time (1, 2, 3, 4, 24),
233 dcp::Time (5, 6, 7, 8, 24)
238 c._xml_id = "a6c58cff-3e1e-4b38-acec-a42224475ef6";
241 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
242 "<dcst:SubtitleReel xmlns:dcst=\"http://www.smpte-ra.org/schemas/428-7/2010/DCST\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
243 "<dcst:Id>urn:uuid:a6c58cff-3e1e-4b38-acec-a42224475ef6</dcst:Id>"
244 "<dcst:ContentTitleText>Test</dcst:ContentTitleText>"
245 "<dcst:IssueDate>2016-04-01T03:52:00.000+00:00</dcst:IssueDate>"
246 "<dcst:ReelNumber>1</dcst:ReelNumber>"
247 "<dcst:Language>en</dcst:Language>"
248 "<dcst:EditRate>24 1</dcst:EditRate>"
249 "<dcst:TimeCodeRate>24</dcst:TimeCodeRate>"
250 "<dcst:SubtitleList>"
251 "<dcst:Font AspectAdjust=\"1.0\" Color=\"FFFFFFFF\" Effect=\"none\" EffectColor=\"FF000000\" ID=\"Frutiger\" Italic=\"no\" Script=\"normal\" Size=\"48\" Underline=\"no\" Weight=\"normal\">"
252 "<dcst:Subtitle SpotNumber=\"1\" TimeIn=\"00:04:09:22\" TimeOut=\"00:04:11:22\" FadeUpTime=\"00:00:00:00\" FadeDownTime=\"00:00:00:00\">"
253 "<dcst:Text Valign=\"top\" Vposition=\"80\">Hello world</dcst:Text>"
256 "<dcst:Font AspectAdjust=\"1.0\" Color=\"FF800040\" Effect=\"border\" EffectColor=\"FF010203\" Italic=\"yes\" Script=\"normal\" Size=\"91\" Underline=\"yes\" Weight=\"bold\">"
257 "<dcst:Subtitle SpotNumber=\"2\" TimeIn=\"05:41:00:21\" TimeOut=\"06:12:15:21\" FadeUpTime=\"01:02:03:04\" FadeDownTime=\"05:06:07:08\">"
258 "<dcst:Text Valign=\"bottom\" Vposition=\"40\" Direction=\"rtl\">What's going on</dcst:Text>"
261 "</dcst:SubtitleList>"
262 "</dcst:SubtitleReel>",
268 /* Write some subtitle content as SMPTE XML and check that it is right.
269 This includes in-line font changes.
271 BOOST_AUTO_TEST_CASE (write_smpte_subtitle_test2)
273 dcp::SMPTESubtitleAsset c;
274 c.set_reel_number (1);
275 c.set_language ("en");
276 c.set_content_title_text ("Test");
277 c.set_issue_date (dcp::LocalTime ("2016-04-01T03:52:00+00:00"));
280 shared_ptr<dcp::SubtitleString>(
281 new dcp::SubtitleString(
286 dcp::Colour (255, 255, 255),
289 dcp::Time (0, 0, 1, 0, 24),
290 dcp::Time (0, 0, 9, 0, 24),
298 dcp::Colour (0, 0, 0),
299 dcp::Time (0, 0, 0, 0, 24),
300 dcp::Time (0, 0, 0, 0, 24)
306 shared_ptr<dcp::SubtitleString>(
307 new dcp::SubtitleString(
312 dcp::Colour (255, 255, 255),
315 dcp::Time (0, 0, 1, 0, 24),
316 dcp::Time (0, 0, 9, 0, 24),
324 dcp::Colour (0, 0, 0),
325 dcp::Time (0, 0, 0, 0, 24),
326 dcp::Time (0, 0, 0, 0, 24)
332 shared_ptr<dcp::SubtitleString>(
333 new dcp::SubtitleString(
338 dcp::Colour (255, 255, 255),
341 dcp::Time (0, 0, 1, 0, 24),
342 dcp::Time (0, 0, 9, 0, 24),
350 dcp::Colour (0, 0, 0),
351 dcp::Time (0, 0, 0, 0, 24),
352 dcp::Time (0, 0, 0, 0, 24)
358 shared_ptr<dcp::SubtitleString>(
359 new dcp::SubtitleString(
364 dcp::Colour (255, 255, 255),
367 dcp::Time (0, 0, 1, 0, 24),
368 dcp::Time (0, 0, 9, 0, 24),
376 dcp::Colour (0, 0, 0),
377 dcp::Time (0, 0, 0, 0, 24),
378 dcp::Time (0, 0, 0, 0, 24)
384 shared_ptr<dcp::SubtitleString>(
385 new dcp::SubtitleString(
390 dcp::Colour (255, 255, 255),
393 dcp::Time (0, 0, 1, 0, 24),
394 dcp::Time (0, 0, 9, 0, 24),
402 dcp::Colour (0, 0, 0),
403 dcp::Time (0, 0, 0, 0, 24),
404 dcp::Time (0, 0, 0, 0, 24)
410 shared_ptr<dcp::SubtitleString>(
411 new dcp::SubtitleString(
416 dcp::Colour (255, 255, 255),
419 dcp::Time (0, 0, 1, 0, 24),
420 dcp::Time (0, 0, 9, 0, 24),
428 dcp::Colour (0, 0, 0),
429 dcp::Time (0, 0, 0, 0, 24),
430 dcp::Time (0, 0, 0, 0, 24)
435 c._xml_id = "a6c58cff-3e1e-4b38-acec-a42224475ef6";
439 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
440 "<dcst:SubtitleReel xmlns:dcst=\"http://www.smpte-ra.org/schemas/428-7/2010/DCST\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
441 "<dcst:Id>urn:uuid:a6c58cff-3e1e-4b38-acec-a42224475ef6</dcst:Id>"
442 "<dcst:ContentTitleText>Test</dcst:ContentTitleText>"
443 "<dcst:IssueDate>2016-04-01T03:52:00.000+00:00</dcst:IssueDate>"
444 "<dcst:ReelNumber>1</dcst:ReelNumber>"
445 "<dcst:Language>en</dcst:Language>"
446 "<dcst:EditRate>24 1</dcst:EditRate>"
447 "<dcst:TimeCodeRate>24</dcst:TimeCodeRate>"
448 "<dcst:SubtitleList>"
449 "<dcst:Font AspectAdjust=\"1.0\" Color=\"FFFFFFFF\" Effect=\"none\" EffectColor=\"FF000000\" ID=\"Arial\" Script=\"normal\" Size=\"48\" Underline=\"no\" Weight=\"normal\">"
450 "<dcst:Subtitle SpotNumber=\"1\" TimeIn=\"00:00:01:00\" TimeOut=\"00:00:09:00\" FadeUpTime=\"00:00:00:00\" FadeDownTime=\"00:00:00:00\">"
451 "<dcst:Text Valign=\"top\" Vposition=\"80\">"
452 "<dcst:Font Italic=\"no\">Testing is </dcst:Font>"
453 "<dcst:Font Italic=\"yes\">really</dcst:Font>"
454 "<dcst:Font Italic=\"no\"> fun</dcst:Font>"
456 "<dcst:Text Valign=\"top\" Vposition=\"90\">"
457 "<dcst:Font Italic=\"no\">This is the </dcst:Font>"
458 "<dcst:Font Italic=\"yes\">second</dcst:Font>"
459 "<dcst:Font Italic=\"no\"> line</dcst:Font>"
463 "</dcst:SubtitleList>"
464 "</dcst:SubtitleReel>",
469 /* Write some subtitle content as SMPTE using bitmaps and check that it is right */
470 BOOST_AUTO_TEST_CASE (write_smpte_subtitle_test3)
472 dcp::SMPTESubtitleAsset c;
473 c.set_reel_number (1);
474 c.set_language ("en");
475 c.set_content_title_text ("Test");
478 shared_ptr<dcp::SubtitleImage>(
479 new dcp::SubtitleImage(
480 dcp::Data ("test/data/sub.png"),
481 dcp::Time (0, 4, 9, 22, 24),
482 dcp::Time (0, 4, 11, 22, 24),
487 dcp::Time (0, 0, 0, 0, 24),
488 dcp::Time (0, 0, 0, 0, 24)
493 c._id = "a6c58cff-3e1e-4b38-acec-a42224475ef6";
495 boost::filesystem::create_directories ("build/test/write_smpte_subtitle_test3");
496 c.write ("build/test/write_smpte_subtitle_test3/subs.mxf");
498 /* XXX: check this result when we can read them back in again */