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.
26 #include "lib/text_subtitle_content.h"
27 #include "lib/dcp_subtitle_content.h"
29 #include "lib/ratio.h"
30 #include "lib/dcp_content_type.h"
31 #include "lib/subtitle_content.h"
32 #include "lib/content_factory.h"
38 #include <dcp/mono_picture_asset.h>
39 #include <dcp/mono_picture_asset_reader.h>
40 #include <dcp/mono_picture_frame.h>
41 #include <dcp/openjpeg_image.h>
42 #include <dcp/reel_picture_asset.h>
43 #include <dcp/reel_mono_picture_asset.h>
44 #include <boost/test/unit_test.hpp>
49 using boost::shared_ptr;
50 using boost::dynamic_pointer_cast;
52 /** Build a small DCP with no picture and a single subtitle overlaid onto it from a SubRip file */
53 BOOST_AUTO_TEST_CASE (burnt_subtitle_test_subrip)
55 shared_ptr<Film> film = new_test_film ("burnt_subtitle_test_subrip");
56 film->set_container (Ratio::from_id ("185"));
57 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
58 film->set_name ("frobozz");
59 shared_ptr<TextSubtitleContent> content (new TextSubtitleContent (film, "test/data/subrip2.srt"));
60 content->set_use_subtitles (true);
61 content->set_burn_subtitles (true);
62 film->examine_and_add_content (content, true);
67 check_dcp ("test/data/burnt_subtitle_test_subrip", film->dir (film->dcp_name ()));
70 /** Build a small DCP with no picture and a single subtitle overlaid onto it from a DCP XML file */
71 BOOST_AUTO_TEST_CASE (burnt_subtitle_test_dcp)
73 shared_ptr<Film> film = new_test_film ("burnt_subtitle_test_dcp");
74 film->set_container (Ratio::from_id ("185"));
75 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
76 film->set_name ("frobozz");
77 film->set_burn_subtitles (true);
78 shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent (film, "test/data/dcp_sub.xml"));
79 content->set_use_subtitles (true);
80 film->examine_and_add_content (content, true);
85 check_dcp ("test/data/burnt_subtitle_test_dcp", film->dir (film->dcp_name ()));
88 /** Burn some subtitles into an existing DCP to check the colour conversion */
89 BOOST_AUTO_TEST_CASE (burnt_subtitle_test_onto_dcp)
91 shared_ptr<Film> film = new_test_film ("burnt_subtitle_test_onto_dcp");
92 film->set_container (Ratio::from_id ("185"));
93 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
94 film->set_name ("frobozz");
95 film->examine_and_add_content (content_factory(film, "test/data/flat_white.png").front());
100 shared_ptr<Film> film2 = new_test_film ("burnt_subtitle_test_onto_dcp2");
101 film2->set_container (Ratio::from_id ("185"));
102 film2->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
103 film2->set_name ("frobozz");
104 film2->examine_and_add_content (content_factory(film2, film->dir (film->dcp_name ())).front());
105 shared_ptr<TextSubtitleContent> sub = dynamic_pointer_cast<TextSubtitleContent> (
106 content_factory (film2, "test/data/subrip2.srt")
108 sub->subtitle->set_burn (true);
109 sub->subtitle->set_outline (true);
110 film2->examine_and_add_content (sub);
115 dcp::DCP dcp (film2->dir (film2->dcp_name ()));
117 BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1);
118 BOOST_REQUIRE_EQUAL (dcp.cpls().front()->reels().size(), 1);
119 BOOST_REQUIRE (dcp.cpls().front()->reels().front()->main_picture());
120 BOOST_REQUIRE (dcp.cpls().front()->reels().front()->main_picture()->asset());
121 shared_ptr<const dcp::MonoPictureAsset> pic = dynamic_pointer_cast<dcp::ReelMonoPictureAsset> (
122 dcp.cpls().front()->reels().front()->main_picture()
125 shared_ptr<const dcp::MonoPictureFrame> frame = pic->start_read()->get_frame (12);
126 shared_ptr<dcp::OpenJPEGImage> xyz = frame->xyz_image ();
127 BOOST_CHECK_EQUAL (xyz->size().width, 1998);
128 BOOST_CHECK_EQUAL (xyz->size().height, 1080);
130 /* XXX: check the output ... */