5e48269189d43b8e7658ecf02be2c1c561874b16
[dcpomatic.git] / src / lib / types.h
1 /*
2     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef DCPOMATIC_TYPES_H
21 #define DCPOMATIC_TYPES_H
22
23 #include <vector>
24 #include <boost/shared_ptr.hpp>
25 #include <libdcp/util.h>
26
27 class Content;
28
29 typedef std::vector<boost::shared_ptr<Content> > ContentList;
30 typedef int64_t ContentAudioFrame;
31 typedef int ContentVideoFrame;
32 typedef double Time;
33
34 /** @struct Crop
35  *  @brief A description of the crop of an image or video.
36  */
37 struct Crop
38 {
39         Crop () : left (0), right (0), top (0), bottom (0) {}
40
41         /** Number of pixels to remove from the left-hand side */
42         int left;
43         /** Number of pixels to remove from the right-hand side */
44         int right;
45         /** Number of pixels to remove from the top */
46         int top;
47         /** Number of pixels to remove from the bottom */
48         int bottom;
49 };
50
51 extern bool operator== (Crop const & a, Crop const & b);
52 extern bool operator!= (Crop const & a, Crop const & b);
53
54 /** @struct Position
55  *  @brief A position.
56  */
57 struct Position
58 {
59         Position ()
60                 : x (0)
61                 , y (0)
62         {}
63
64         Position (int x_, int y_)
65                 : x (x_)
66                 , y (y_)
67         {}
68
69         /** x coordinate */
70         int x;
71         /** y coordinate */
72         int y;
73 };
74
75 /** @struct Rect
76  *  @brief A rectangle.
77  */
78 struct Rect
79 {
80         Rect ()
81                 : x (0)
82                 , y (0)
83                 , width (0)
84                 , height (0)
85         {}
86
87         Rect (int x_, int y_, int w_, int h_)
88                 : x (x_)
89                 , y (y_)
90                 , width (w_)
91                 , height (h_)
92         {}
93
94         int x;
95         int y;
96         int width;
97         int height;
98
99         Position position () const {
100                 return Position (x, y);
101         }
102
103         libdcp::Size size () const {
104                 return libdcp::Size (width, height);
105         }
106
107         Rect intersection (Rect const & other) const;
108
109         bool contains (Position) const;
110 };
111
112 #endif