2 Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp 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 libdcp 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 libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
35 /** @file src/subtitle_image.cc
36 * @brief SubtitleImage class
40 #include "equality_options.h"
41 #include "filesystem.h"
42 #include "subtitle_image.h"
46 using std::dynamic_pointer_cast;
48 using std::shared_ptr;
53 SubtitleImage::SubtitleImage (
65 : Subtitle(in, out, h_position, h_align, v_position, v_align, z_position, fade_up_time, fade_down_time)
66 , _png_image (png_image)
73 SubtitleImage::SubtitleImage (
86 : Subtitle(in, out, h_position, h_align, v_position, v_align, z_position, fade_up_time, fade_down_time)
87 , _png_image (png_image)
95 SubtitleImage::read_png_file (boost::filesystem::path file)
98 _png_image = ArrayData (file);
103 SubtitleImage::write_png_file (boost::filesystem::path file) const
106 png_image().write (file);
111 dcp::operator== (SubtitleImage const & a, SubtitleImage const & b)
114 a.png_image() == b.png_image() &&
117 a.out() == b.out() &&
118 a.h_position() == b.h_position() &&
119 a.h_align() == b.h_align() &&
120 a.v_position() == b.v_position() &&
121 a.v_align() == b.v_align() &&
122 a.z_position() == b.z_position() &&
123 a.fade_up_time() == b.fade_up_time() &&
124 a.fade_down_time() == b.fade_down_time()
130 dcp::operator!= (SubtitleImage const & a, SubtitleImage const & b)
137 SubtitleImage::equals(shared_ptr<const Subtitle> other_sub, EqualityOptions const& options, NoteHandler note) const
139 if (!Subtitle::equals(other_sub, options, note)) {
143 auto other = dynamic_pointer_cast<const SubtitleImage>(other_sub);
145 note(NoteType::ERROR, "Subtitle types differ: string vs image");
149 if (png_image() != other->png_image()) {
150 note (NoteType::ERROR, "subtitle image PNG data differs");
151 if (options.export_differing_subtitles) {
152 string const base = "dcpdiff_subtitle_";
153 if (filesystem::exists(base + "A.png")) {
154 note (NoteType::ERROR, "could not export subtitle as " + base + "A.png already exists");
156 png_image().write(base + "A.png");
158 if (filesystem::exists(base + "B.png")) {
159 note (NoteType::ERROR, "could not export subtitle as " + base + "B.png already exists");
161 other->png_image().write(base + "B.png");
172 dcp::operator<< (ostream& s, SubtitleImage const & sub)
174 s << "\n[IMAGE] from " << sub.in() << " to " << sub.out() << ";\n"
175 << "fade up " << sub.fade_up_time() << ", fade down " << sub.fade_down_time() << ";\n"
176 << "v pos " << sub.v_position() << ", valign " << ((int) sub.v_align())
177 << ", hpos " << sub.h_position() << ", halign " << ((int) sub.h_align())
178 << ", zpos " << sub.z_position() << "\n";