More player debugging for butler video-full states.
[dcpomatic.git] / src / lib / types.cc
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 #include "types.h"
22 #include "compose.hpp"
23 #include "dcpomatic_assert.h"
24 #include <dcp/raw_convert.h>
25 #include <libxml++/libxml++.h>
26 #include <libcxml/cxml.h>
27
28 #include "i18n.h"
29
30 using std::max;
31 using std::min;
32 using std::string;
33 using boost::shared_ptr;
34 using dcp::raw_convert;
35
36 bool operator== (Crop const & a, Crop const & b)
37 {
38         return (a.left == b.left && a.right == b.right && a.top == b.top && a.bottom == b.bottom);
39 }
40
41 bool operator!= (Crop const & a, Crop const & b)
42 {
43         return !(a == b);
44 }
45
46 /** @param r Resolution.
47  *  @return Untranslated string representation.
48  */
49 string
50 resolution_to_string (Resolution r)
51 {
52         switch (r) {
53         case RESOLUTION_2K:
54                 return "2K";
55         case RESOLUTION_4K:
56                 return "4K";
57         }
58
59         DCPOMATIC_ASSERT (false);
60         return "";
61 }
62
63
64 Resolution
65 string_to_resolution (string s)
66 {
67         if (s == "2K") {
68                 return RESOLUTION_2K;
69         }
70
71         if (s == "4K") {
72                 return RESOLUTION_4K;
73         }
74
75         DCPOMATIC_ASSERT (false);
76         return RESOLUTION_2K;
77 }
78
79 Crop::Crop (shared_ptr<cxml::Node> node)
80 {
81         left = node->number_child<int> ("LeftCrop");
82         right = node->number_child<int> ("RightCrop");
83         top = node->number_child<int> ("TopCrop");
84         bottom = node->number_child<int> ("BottomCrop");
85 }
86
87 void
88 Crop::as_xml (xmlpp::Node* node) const
89 {
90         node->add_child("LeftCrop")->add_child_text (raw_convert<string> (left));
91         node->add_child("RightCrop")->add_child_text (raw_convert<string> (right));
92         node->add_child("TopCrop")->add_child_text (raw_convert<string> (top));
93         node->add_child("BottomCrop")->add_child_text (raw_convert<string> (bottom));
94 }
95
96 TextType
97 string_to_text_type (string s)
98 {
99         if (s == "unknown") {
100                 return TEXT_UNKNOWN;
101         } else if (s == "open-subtitle") {
102                 return TEXT_OPEN_SUBTITLE;
103         } else if (s == "closed-caption") {
104                 return TEXT_CLOSED_CAPTION;
105         } else {
106                 throw MetadataError (String::compose ("Unknown text type %1", s));
107         }
108 }
109
110 string
111 text_type_to_string (TextType t)
112 {
113         switch (t) {
114         case TEXT_UNKNOWN:
115                 return "unknown";
116         case TEXT_OPEN_SUBTITLE:
117                 return "open-subtitle";
118         case TEXT_CLOSED_CAPTION:
119                 return "closed-caption";
120         default:
121                 DCPOMATIC_ASSERT (false);
122         }
123 }
124
125 string
126 text_type_to_name (TextType t)
127 {
128         switch (t) {
129         case TEXT_UNKNOWN:
130                 return _("Timed text");
131         case TEXT_OPEN_SUBTITLE:
132                 return _("Open subtitles");
133         case TEXT_CLOSED_CAPTION:
134                 return _("Closed captions");
135         default:
136                 DCPOMATIC_ASSERT (false);
137         }
138 }
139
140 string
141 video_frame_type_to_string (VideoFrameType t)
142 {
143         switch (t) {
144         case VIDEO_FRAME_TYPE_2D:
145                 return "2d";
146         case VIDEO_FRAME_TYPE_3D:
147                 return "3d";
148         case VIDEO_FRAME_TYPE_3D_LEFT_RIGHT:
149                 return "3d-left-right";
150         case VIDEO_FRAME_TYPE_3D_TOP_BOTTOM:
151                 return "3d-top-bottom";
152         case VIDEO_FRAME_TYPE_3D_ALTERNATE:
153                 return "3d-alternate";
154         case VIDEO_FRAME_TYPE_3D_LEFT:
155                 return "3d-left";
156         case VIDEO_FRAME_TYPE_3D_RIGHT:
157                 return "3d-right";
158         default:
159                 DCPOMATIC_ASSERT (false);
160         }
161
162         DCPOMATIC_ASSERT (false);
163 }
164
165 VideoFrameType
166 string_to_video_frame_type (string s)
167 {
168         if (s == "2d") {
169                 return VIDEO_FRAME_TYPE_2D;
170         } else if (s == "3d") {
171                 return VIDEO_FRAME_TYPE_3D;
172         } else if (s == "3d-left-right") {
173                 return VIDEO_FRAME_TYPE_3D_LEFT_RIGHT;
174         } else if (s == "3d-top-bottom") {
175                 return VIDEO_FRAME_TYPE_3D_TOP_BOTTOM;
176         } else if (s == "3d-alternate") {
177                 return VIDEO_FRAME_TYPE_3D_ALTERNATE;
178         } else if (s == "3d-left") {
179                 return VIDEO_FRAME_TYPE_3D_LEFT;
180         } else if (s == "3d-right") {
181                 return VIDEO_FRAME_TYPE_3D_RIGHT;
182         }
183
184         DCPOMATIC_ASSERT (false);
185 }