2 Copyright (C) 2014-2016 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/burnt_subtitle_test.cc
22 * @brief Test the burning of subtitles into the DCP.
25 #include "lib/text_subtitle_content.h"
26 #include "lib/dcp_subtitle_content.h"
28 #include "lib/ratio.h"
29 #include "lib/dcp_content_type.h"
30 #include "lib/subtitle_content.h"
31 #include "lib/content_factory.h"
37 #include <dcp/mono_picture_asset.h>
38 #include <dcp/mono_picture_asset_reader.h>
39 #include <dcp/mono_picture_frame.h>
40 #include <dcp/openjpeg_image.h>
41 #include <dcp/reel_picture_asset.h>
42 #include <dcp/reel_mono_picture_asset.h>
43 #include <boost/test/unit_test.hpp>
48 using boost::shared_ptr;
49 using boost::dynamic_pointer_cast;
51 /** Build a small DCP with no picture and a single subtitle overlaid onto it from a SubRip file */
52 BOOST_AUTO_TEST_CASE (burnt_subtitle_test_subrip)
54 shared_ptr<Film> film = new_test_film ("burnt_subtitle_test_subrip");
55 film->set_container (Ratio::from_id ("185"));
56 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
57 film->set_name ("frobozz");
58 shared_ptr<TextSubtitleContent> content (new TextSubtitleContent (film, "test/data/subrip2.srt"));
59 content->set_use_subtitles (true);
60 content->set_burn_subtitles (true);
61 film->examine_and_add_content (content, true);
66 check_dcp ("test/data/burnt_subtitle_test_subrip", film->dir (film->dcp_name ()));
69 /** Build a small DCP with no picture and a single subtitle overlaid onto it from a DCP XML file */
70 BOOST_AUTO_TEST_CASE (burnt_subtitle_test_dcp)
72 shared_ptr<Film> film = new_test_film ("burnt_subtitle_test_dcp");
73 film->set_container (Ratio::from_id ("185"));
74 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
75 film->set_name ("frobozz");
76 film->set_burn_subtitles (true);
77 shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent (film, "test/data/dcp_sub.xml"));
78 content->set_use_subtitles (true);
79 film->examine_and_add_content (content, true);
84 check_dcp ("test/data/burnt_subtitle_test_dcp", film->dir (film->dcp_name ()));
87 /** Burn some subtitles into an existing DCP to check the colour conversion */
88 BOOST_AUTO_TEST_CASE (burnt_subtitle_test_onto_dcp)
90 shared_ptr<Film> film = new_test_film ("burnt_subtitle_test_onto_dcp");
91 film->set_container (Ratio::from_id ("185"));
92 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
93 film->set_name ("frobozz");
94 film->examine_and_add_content (content_factory (film, "test/data/flat_white.png"));
99 shared_ptr<Film> film2 = new_test_film ("burnt_subtitle_test_onto_dcp2");
100 film2->set_container (Ratio::from_id ("185"));
101 film2->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
102 film2->set_name ("frobozz");
103 film2->examine_and_add_content (content_factory (film2, film->dir (film->dcp_name ())));
104 shared_ptr<TextSubtitleContent> sub = dynamic_pointer_cast<TextSubtitleContent> (
105 content_factory (film2, "test/data/subrip2.srt")
107 sub->subtitle->set_burn (true);
108 sub->subtitle->set_outline (true);
109 film2->examine_and_add_content (sub);
114 dcp::DCP dcp (film2->dir (film2->dcp_name ()));
116 BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1);
117 BOOST_REQUIRE_EQUAL (dcp.cpls().front()->reels().size(), 1);
118 BOOST_REQUIRE (dcp.cpls().front()->reels().front()->main_picture());
119 BOOST_REQUIRE (dcp.cpls().front()->reels().front()->main_picture()->asset());
120 shared_ptr<const dcp::MonoPictureAsset> pic = dynamic_pointer_cast<dcp::ReelMonoPictureAsset> (
121 dcp.cpls().front()->reels().front()->main_picture()
124 shared_ptr<const dcp::MonoPictureFrame> frame = pic->start_read()->get_frame (12);
125 shared_ptr<dcp::OpenJPEGImage> xyz = frame->xyz_image ();
126 BOOST_CHECK_EQUAL (xyz->size().width, 1998);
127 BOOST_CHECK_EQUAL (xyz->size().height, 1080);
129 /* XXX: check the output ... */