Various Doxygen fixes.
[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_subtitle_content.h"
27 #include "lib/dcp_subtitle_content.h"
28 #include "lib/film.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"
33 #include "test.h"
34 #include <dcp/dcp.h>
35 #include <dcp/cpl.h>
36 #include <dcp/reel.h>
37 #include <dcp/j2k.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>
45 #include <iostream>
46
47 using std::cout;
48 using std::map;
49 using boost::shared_ptr;
50 using boost::dynamic_pointer_cast;
51
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)
54 {
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);
63         wait_for_jobs ();
64         film->make_dcp ();
65         wait_for_jobs ();
66
67         check_dcp ("test/data/burnt_subtitle_test_subrip", film->dir (film->dcp_name ()));
68 }
69
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)
72 {
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);
81         wait_for_jobs ();
82         film->make_dcp ();
83         wait_for_jobs ();
84
85         check_dcp ("test/data/burnt_subtitle_test_dcp", film->dir (film->dcp_name ()));
86 }
87
88 /** Burn some subtitles into an existing DCP to check the colour conversion */
89 BOOST_AUTO_TEST_CASE (burnt_subtitle_test_onto_dcp)
90 {
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());
96         wait_for_jobs ();
97         film->make_dcp ();
98         wait_for_jobs ();
99
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")
107                 );
108         sub->subtitle->set_burn (true);
109         sub->subtitle->set_outline (true);
110         film2->examine_and_add_content (sub);
111         wait_for_jobs ();
112         film2->make_dcp ();
113         wait_for_jobs ();
114
115         dcp::DCP dcp (film2->dir (film2->dcp_name ()));
116         dcp.read ();
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()
123                 )->mono_asset();
124         BOOST_REQUIRE (pic);
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);
129
130         /* XXX: check the output ... */
131 }