Extract common code out into kdm_for_screen()
[dcpomatic.git] / src / lib / video_content_scale.h
1 /*
2     Copyright (C) 2013-2018 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 #ifndef DCPOMATIC_VIDEO_CONTENT_SCALE_H
22 #define DCPOMATIC_VIDEO_CONTENT_SCALE_H
23
24 #include <dcp/util.h>
25 #include <boost/shared_ptr.hpp>
26 #include <vector>
27
28 namespace cxml {
29         class Node;
30 }
31
32 namespace xmlpp {
33         class Node;
34 }
35
36 class Ratio;
37 class VideoContent;
38
39 class VideoContentScale
40 {
41 public:
42         VideoContentScale ();
43         explicit VideoContentScale (Ratio const *);
44         explicit VideoContentScale (bool);
45         explicit VideoContentScale (boost::shared_ptr<cxml::Node>);
46
47         dcp::Size size (boost::shared_ptr<const VideoContent>, dcp::Size display_container, dcp::Size film_container) const;
48         std::string id () const;
49         std::string name () const;
50         void as_xml (xmlpp::Node *) const;
51
52         Ratio const * ratio () const {
53                 return _ratio;
54         }
55
56         bool scale () const {
57                 return _scale;
58         }
59
60         static void setup_scales ();
61         static std::vector<VideoContentScale> all () {
62                 return _scales;
63         }
64
65 private:
66         /** a ratio to stretch the content to, or 0 for no stretch */
67         Ratio const * _ratio;
68         /** true if we want to change the size of the content in any way */
69         bool _scale;
70
71         /* If _ratio is 0 and _scale is false there is no scale at all (i.e.
72            the content is used at its original size)
73         */
74
75         static std::vector<VideoContentScale> _scales;
76 };
77
78 bool operator== (VideoContentScale const & a, VideoContentScale const & b);
79 bool operator!= (VideoContentScale const & a, VideoContentScale const & b);
80
81 #endif