Basic and slightly inaccurate support for <Space> in subtitles (#2103).
[dcpomatic.git] / src / lib / pixel_quanta.cc
1 /*
2     Copyright (C) 2021 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
22 #include "pixel_quanta.h"
23 #include <dcp/raw_convert.h>
24
25
26 PixelQuanta::PixelQuanta (cxml::ConstNodePtr node)
27         : x(node->number_child<int>("X"))
28         , y(node->number_child<int>("Y"))
29 {
30
31 }
32
33
34 void
35 PixelQuanta::as_xml (xmlpp::Element* node) const
36 {
37         node->add_child("X")->add_child_text(dcp::raw_convert<std::string>(x));
38         node->add_child("Y")->add_child_text(dcp::raw_convert<std::string>(y));
39 }
40
41
42 int
43 PixelQuanta::round_x (int x_) const
44 {
45         return x_ - (x_ % x);
46 }
47
48
49 int
50 PixelQuanta::round_y (int y_) const
51 {
52         return y_ - (y_ % y);
53 }
54
55
56 dcp::Size
57 PixelQuanta::round (dcp::Size size) const
58 {
59         return dcp::Size (round_x(size.width), round_y(size.height));
60 }
61
62
63 PixelQuanta
64 max (PixelQuanta const& a, PixelQuanta const& b)
65 {
66         return { std::max(a.x, b.x), std::max(a.y, b.y) };
67 }
68