Don't scale chroma subsampled images to sizes that don't align with the subsampling...
[dcpomatic.git] / src / lib / pixel_quanta.h
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 #ifndef DCPOMATIC_PIXEL_QUANTA_H
23 #define DCPOMATIC_PIXEL_QUANTA_H
24
25
26 #include "warnings.h"
27
28 #include <libcxml/cxml.h>
29 #include <dcp/types.h>
30 DCPOMATIC_DISABLE_WARNINGS
31 #include <libxml++/libxml++.h>
32 DCPOMATIC_ENABLE_WARNINGS
33
34
35 class PixelQuanta
36 {
37 public:
38         PixelQuanta ()
39                 : x(1)
40                 , y(1)
41         {}
42
43         /** @param x number of pixels that must not be split in the x direction; e.g. if x=2 scale should
44          *  only happen to multiples of 2 width, and x crop should only happen at multiples of 2 position.
45          *  @param y similar value for y / height.
46          */
47         PixelQuanta (int x_, int y_)
48                 : x(x_)
49                 , y(y_)
50         {}
51
52         PixelQuanta (cxml::ConstNodePtr node);
53
54         void as_xml (xmlpp::Element* node) const;
55
56         int round_x (int x_) const;
57         int round_y (int y_) const;
58         dcp::Size round (dcp::Size size) const;
59
60         int x;
61         int y;
62 };
63
64
65 PixelQuanta max (PixelQuanta const& a, PixelQuanta const& b);
66
67 #endif
68