2 Copyright (C) 2014-2021 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 /** @file test/burnt_subtitle_test.cc
23 * @brief Test the burning of subtitles into the DCP.
28 #include "lib/config.h"
29 #include "lib/content_factory.h"
30 #include "lib/dcp_content.h"
31 #include "lib/dcp_content_type.h"
32 #include "lib/dcp_text_content.h"
34 #include "lib/log_entry.h"
35 #include "lib/plain_text_content.h"
36 #include "lib/ratio.h"
37 #include "lib/text_content.h"
42 #include <dcp/j2k_transcode.h>
43 #include <dcp/mono_picture_asset.h>
44 #include <dcp/mono_picture_asset_reader.h>
45 #include <dcp/mono_picture_frame.h>
46 #include <dcp/openjpeg_image.h>
47 #include <dcp/reel_picture_asset.h>
48 #include <dcp/reel_mono_picture_asset.h>
49 #include <boost/test/unit_test.hpp>
52 using std::dynamic_pointer_cast;
53 using std::make_shared;
55 using namespace dcpomatic;
58 /** Build a small DCP with no picture and a single subtitle overlaid onto it from a SubRip file */
59 BOOST_AUTO_TEST_CASE (burnt_subtitle_test_subrip)
61 auto film = new_test_film ("burnt_subtitle_test_subrip");
62 film->set_container (Ratio::from_id ("185"));
63 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
64 film->set_name ("frobozz");
65 auto content = make_shared<StringText>(film, "test/data/subrip2.srt");
66 content->subtitle->set_use (true);
67 content->subtitle->set_burn (true);
68 film->examine_and_add_content (content);
69 BOOST_REQUIRE (!wait_for_jobs());
70 make_and_verify_dcp (film);
72 check_dcp ("test/data/burnt_subtitle_test_subrip", film->dir (film->dcp_name ()));
75 /** Build a small DCP with no picture and a single subtitle overlaid onto it from a DCP XML file */
76 BOOST_AUTO_TEST_CASE (burnt_subtitle_test_dcp)
78 auto film = new_test_film ("burnt_subtitle_test_dcp");
79 film->set_container (Ratio::from_id ("185"));
80 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
81 film->set_name ("frobozz");
82 auto content = make_shared<DCPTextContent>(film, "test/data/dcp_sub.xml");
83 content->subtitle->set_use (true);
84 film->examine_and_add_content (content);
85 BOOST_REQUIRE (!wait_for_jobs());
86 make_and_verify_dcp (film);
88 check_dcp ("test/data/burnt_subtitle_test_dcp", film->dir (film->dcp_name ()));
91 /** Burn some subtitles into an existing DCP to check the colour conversion */
92 BOOST_AUTO_TEST_CASE (burnt_subtitle_test_onto_dcp)
94 auto film = new_test_film ("burnt_subtitle_test_onto_dcp");
95 film->set_container (Ratio::from_id ("185"));
96 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
97 film->set_name ("frobozz");
98 film->examine_and_add_content (content_factory(film, "test/data/flat_black.png")[0]);
99 BOOST_REQUIRE (!wait_for_jobs());
100 make_and_verify_dcp (film);
102 Config::instance()->set_log_types (Config::instance()->log_types() | LogEntry::TYPE_DEBUG_ENCODE);
103 auto film2 = new_test_film ("burnt_subtitle_test_onto_dcp2");
104 film2->set_container (Ratio::from_id ("185"));
105 film2->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
106 film2->set_name ("frobozz");
107 auto background_dcp = make_shared<DCPContent>(film2, film->dir(film->dcp_name()));
108 film2->examine_and_add_content (background_dcp);
109 auto sub = dynamic_pointer_cast<StringText> (
110 content_factory(film2, "test/data/subrip2.srt")[0]
112 sub->subtitle->set_burn (true);
113 sub->subtitle->set_outline (true);
114 film2->examine_and_add_content (sub);
115 BOOST_REQUIRE (!wait_for_jobs());
116 make_and_verify_dcp (film2);
118 BOOST_CHECK (background_dcp->position() == DCPTime());
119 BOOST_CHECK (sub->position() == DCPTime());
121 dcp::DCP dcp (film2->dir (film2->dcp_name ()));
123 BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1);
124 BOOST_REQUIRE_EQUAL (dcp.cpls().front()->reels().size(), 1);
125 BOOST_REQUIRE (dcp.cpls().front()->reels().front()->main_picture());
126 BOOST_REQUIRE (dcp.cpls().front()->reels().front()->main_picture()->asset());
127 auto pic = dynamic_pointer_cast<dcp::ReelMonoPictureAsset> (
128 dcp.cpls().front()->reels().front()->main_picture()
131 auto frame = pic->start_read()->get_frame(12);
132 auto xyz = frame->xyz_image ();
133 BOOST_CHECK_EQUAL (xyz->size().width, 1998);
134 BOOST_CHECK_EQUAL (xyz->size().height, 1080);
136 check_dcp ("test/data/burnt_subtitle_test_onto_dcp", film->dir(film->dcp_name()));