Rename Subtitle -> Text
[dcpomatic.git] / test / burnt_subtitle_test.cc
1 /*
2     Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 /** @file  test/burnt_subtitle_test.cc
22  *  @brief Test the burning of subtitles into the DCP.
23  *  @ingroup specific
24  */
25
26 #include "lib/text_text_content.h"
27 #include "lib/dcp_text_content.h"
28 #include "lib/film.h"
29 #include "lib/ratio.h"
30 #include "lib/dcp_content_type.h"
31 #include "lib/text_content.h"
32 #include "lib/dcp_content.h"
33 #include "lib/content_factory.h"
34 #include "lib/config.h"
35 #include "lib/log_entry.h"
36 #include "test.h"
37 #include <dcp/dcp.h>
38 #include <dcp/cpl.h>
39 #include <dcp/reel.h>
40 #include <dcp/j2k.h>
41 #include <dcp/mono_picture_asset.h>
42 #include <dcp/mono_picture_asset_reader.h>
43 #include <dcp/mono_picture_frame.h>
44 #include <dcp/openjpeg_image.h>
45 #include <dcp/reel_picture_asset.h>
46 #include <dcp/reel_mono_picture_asset.h>
47 #include <boost/test/unit_test.hpp>
48 #include <iostream>
49
50 using std::cout;
51 using std::map;
52 using boost::shared_ptr;
53 using boost::dynamic_pointer_cast;
54
55 /** Build a small DCP with no picture and a single subtitle overlaid onto it from a SubRip file */
56 BOOST_AUTO_TEST_CASE (burnt_subtitle_test_subrip)
57 {
58         shared_ptr<Film> film = new_test_film ("burnt_subtitle_test_subrip");
59         film->set_container (Ratio::from_id ("185"));
60         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
61         film->set_name ("frobozz");
62         shared_ptr<TextTextContent> content (new TextTextContent (film, "test/data/subrip2.srt"));
63         content->subtitle->set_use (true);
64         content->subtitle->set_burn (true);
65         film->examine_and_add_content (content);
66         wait_for_jobs ();
67         film->make_dcp ();
68         wait_for_jobs ();
69
70         check_dcp ("test/data/burnt_subtitle_test_subrip", film->dir (film->dcp_name ()));
71 }
72
73 /** Build a small DCP with no picture and a single subtitle overlaid onto it from a DCP XML file */
74 BOOST_AUTO_TEST_CASE (burnt_subtitle_test_dcp)
75 {
76         shared_ptr<Film> film = new_test_film ("burnt_subtitle_test_dcp");
77         film->set_container (Ratio::from_id ("185"));
78         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
79         film->set_name ("frobozz");
80         shared_ptr<DCPTextContent> content (new DCPTextContent (film, "test/data/dcp_sub.xml"));
81         content->subtitle->set_use (true);
82         film->examine_and_add_content (content);
83         wait_for_jobs ();
84         film->make_dcp ();
85         wait_for_jobs ();
86
87         check_dcp ("test/data/burnt_subtitle_test_dcp", film->dir (film->dcp_name ()));
88 }
89
90 /** Burn some subtitles into an existing DCP to check the colour conversion */
91 BOOST_AUTO_TEST_CASE (burnt_subtitle_test_onto_dcp)
92 {
93         shared_ptr<Film> film = new_test_film ("burnt_subtitle_test_onto_dcp");
94         film->set_container (Ratio::from_id ("185"));
95         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
96         film->set_name ("frobozz");
97         film->examine_and_add_content (content_factory(film, "test/data/flat_black.png").front());
98         BOOST_REQUIRE (!wait_for_jobs());
99         film->make_dcp ();
100         BOOST_REQUIRE (!wait_for_jobs());
101
102         Config::instance()->set_log_types (Config::instance()->log_types() | LogEntry::TYPE_DEBUG_ENCODE);
103         shared_ptr<Film> 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         shared_ptr<DCPContent> background_dcp (new DCPContent(film2, film->dir(film->dcp_name())));
108         film2->examine_and_add_content (background_dcp);
109         shared_ptr<TextTextContent> sub = dynamic_pointer_cast<TextTextContent> (
110                 content_factory(film2, "test/data/subrip2.srt").front()
111                 );
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         film2->make_dcp ();
117         BOOST_REQUIRE (!wait_for_jobs());
118
119         BOOST_CHECK (background_dcp->position() == DCPTime());
120         BOOST_CHECK (sub->position() == DCPTime());
121
122         dcp::DCP dcp (film2->dir (film2->dcp_name ()));
123         dcp.read ();
124         BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1);
125         BOOST_REQUIRE_EQUAL (dcp.cpls().front()->reels().size(), 1);
126         BOOST_REQUIRE (dcp.cpls().front()->reels().front()->main_picture());
127         BOOST_REQUIRE (dcp.cpls().front()->reels().front()->main_picture()->asset());
128         shared_ptr<const dcp::MonoPictureAsset> pic = dynamic_pointer_cast<dcp::ReelMonoPictureAsset> (
129                 dcp.cpls().front()->reels().front()->main_picture()
130                 )->mono_asset();
131         BOOST_REQUIRE (pic);
132         shared_ptr<const dcp::MonoPictureFrame> frame = pic->start_read()->get_frame (12);
133         shared_ptr<dcp::OpenJPEGImage> xyz = frame->xyz_image ();
134         BOOST_CHECK_EQUAL (xyz->size().width, 1998);
135         BOOST_CHECK_EQUAL (xyz->size().height, 1080);
136
137         check_dcp ("test/data/burnt_subtitle_test_onto_dcp", film->dir(film->dcp_name()));
138 }