Try to add basic decryption support to dcpdiff.
[libdcp.git] / src / types.h
1 /*
2     Copyright (C) 2012-2014 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 /** @file  src/types.h
21  *  @brief Miscellaneous types.
22  */
23
24 #ifndef LIBDCP_TYPES_H
25 #define LIBDCP_TYPES_H
26
27 #include <boost/shared_ptr.hpp>
28 #include <boost/function.hpp>
29 #include <string>
30
31 namespace dcp
32 {
33
34 namespace parse {
35         class AssetMap;
36 }
37
38 /** @struct Size
39  *  @brief The integer, two-dimensional size of something.
40  */
41 struct Size
42 {
43         Size ()
44                 : width (0)
45                 , height (0)
46         {}
47
48         Size (int w, int h)
49                 : width (w)
50                 , height (h)
51         {}
52
53         float ratio () const {
54                 return float (width) / height;
55         }
56         
57         int width;
58         int height;
59 };
60
61 /** Identifier for a sound channel */
62 enum Channel {
63         LEFT = 0,      ///< left
64         RIGHT = 1,     ///< right
65         CENTRE = 2,    ///< centre
66         LFE = 3,       ///< low-frequency effects (sub)
67         LS = 4,        ///< left surround
68         RS = 5,        ///< right surround
69         CHANNEL_7 = 6, ///< channel 7; not sure what this should be called
70         CHANNEL_8 = 7  ///< channel 8; not sure what this should be called
71 };
72
73 enum ContentKind
74 {
75         FEATURE,
76         SHORT,
77         TRAILER,
78         TEST,
79         TRANSITIONAL,
80         RATING,
81         TEASER,
82         POLICY,
83         PUBLIC_SERVICE_ANNOUNCEMENT,
84         ADVERTISEMENT
85 };
86
87 enum Effect
88 {
89         NONE,
90         BORDER,
91         SHADOW
92 };
93
94 extern std::string effect_to_string (Effect e);
95 extern Effect string_to_effect (std::string s);
96
97 enum VAlign
98 {
99         TOP,
100         CENTER,
101         BOTTOM
102 };
103
104 extern std::string valign_to_string (VAlign a);
105 extern VAlign string_to_valign (std::string s);
106
107 enum Eye
108 {
109         EYE_LEFT,
110         EYE_RIGHT
111 };
112
113 /** @class Fraction
114  *  @brief A fraction (i.e. a thing with an integer numerator and an integer denominator).
115  */
116 class Fraction
117 {
118 public:
119         /** Construct a fraction of 0/0 */
120         Fraction () : numerator (0), denominator (0) {}
121         Fraction (std::string s);
122         /** Construct a fraction with a specified numerator and denominator.
123          *  @param n Numerator.
124          *  @param d Denominator.
125          */
126         Fraction (int n, int d) : numerator (n), denominator (d) {}
127
128         float as_float () const {
129                 return float (numerator) / denominator;
130         }
131
132         int numerator;
133         int denominator;
134 };
135
136 extern bool operator== (Fraction const & a, Fraction const & b);
137 extern bool operator!= (Fraction const & a, Fraction const & b);
138
139 /** @struct EqualityOptions
140  *  @brief  A class to describe what "equality" means for a particular test.
141  *
142  *  When comparing things, we want to be able to ignore some differences;
143  *  this class expresses those differences.
144  */
145 struct EqualityOptions
146 {
147         /** Construct an EqualityOptions where nothing at all can differ */
148         EqualityOptions () 
149                 : max_mean_pixel_error (0)
150                 , max_std_dev_pixel_error (0)
151                 , max_audio_sample_error (0)
152                 , cpl_annotation_texts_can_differ (false)
153                 , mxf_filenames_can_differ (false)
154                 , reel_hashes_can_differ (false)
155         {}
156
157         /** The maximum allowable mean difference in pixel value between two images */
158         double max_mean_pixel_error;
159         /** The maximum standard deviation of the differences in pixel value between two images */
160         double max_std_dev_pixel_error;
161         /** The maximum difference in audio sample value between two soundtracks */
162         int max_audio_sample_error;
163         /** true if the <AnnotationText> nodes of CPLs are allowed to differ */
164         bool cpl_annotation_texts_can_differ;
165         /** true if MXF file leafnames are allowed to differ */
166         bool mxf_filenames_can_differ;
167         /** true if <Hash>es in Reels can differ */
168         bool reel_hashes_can_differ;
169 };
170
171 /* I've been unable to make mingw happy with ERROR as a symbol, so
172    I'm using a DCP_ prefix here.
173 */
174 enum NoteType {
175         DCP_PROGRESS,
176         DCP_ERROR,
177         DCP_NOTE
178 };
179
180 enum Standard {
181         INTEROP,
182         SMPTE
183 };
184
185 enum Formulation {
186         MODIFIED_TRANSITIONAL_1,
187         DCI_ANY,
188         DCI_SPECIFIC
189 };
190
191 /** @class Colour
192  *  @brief An RGB colour.
193  */
194 class Colour
195 {
196 public:
197         Colour ();
198         Colour (int r_, int g_, int b_);
199         Colour (std::string argb_hex);
200
201         int r; ///< red component, from 0 to 255
202         int g; ///< green component, from 0 to 255
203         int b; ///< blue component, from 0 to 255
204
205         std::string to_argb_string () const;
206 };
207
208 extern bool operator== (Colour const & a, Colour const & b);
209 extern bool operator!= (Colour const & a, Colour const & b);
210 extern std::ostream & operator<< (std::ostream & s, Colour const & c);
211
212 typedef std::pair<std::string, boost::shared_ptr<const parse::AssetMap> > PathAssetMap;
213
214 typedef boost::function<void (NoteType, std::string)> NoteHandler;
215
216
217 }
218
219 #endif