Start of STL binary reader; start of dumpsubs.
[libsub.git] / src / stl_binary_reader.h
1 /*
2     Copyright (C) 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 #include <map>
21 #include "reader.h"
22
23 namespace sub {
24
25 template<class T>
26 class STLCode
27 {
28 public:
29         STLCode ()
30                 : value ((T) 0)
31         {}
32
33         STLCode (T v, std::string d)
34                 : value (v)
35                 , description (d)
36         {}
37         
38         T value;
39         std::string description;
40 };
41
42 class STLBinaryReader : public Reader
43 {
44 public:
45         STLBinaryReader (std::istream &);
46         ~STLBinaryReader ();
47
48         std::map<std::string, std::string> metadata () const;
49
50         enum DisplayStandard {
51                 DISPLAY_STANDARD_UNDEFINED,
52                 DISPLAY_STANDARD_OPEN_SUBTITLING,
53                 DISPLAY_STANDARD_LEVEL_1_TELETEXT,
54                 DISPLAY_STANDARD_LEVEL_2_TELETEXT
55         };
56
57         enum LanguageGroup {
58                 LANGUAGE_GROUP_LATIN,
59                 LANGUAGE_GROUP_LATIN_CYRILLIC,
60                 LANGUAGE_GROUP_LATIN_ARABIC,
61                 LANGUAGE_GROUP_LATIN_GREEK,
62                 LANGUAGE_GROUP_LATIN_HEBREW
63         };
64
65         enum Language {
66                 LANGUAGE_UNKNOWN,
67                 LANGUAGE_ALBANIAN,
68                 LANGUAGE_BRETON,
69                 LANGUAGE_CATALAN,
70                 LANGUAGE_CROATIAN,
71                 LANGUAGE_WELSH,
72                 LANGUAGE_CZECH,
73                 LANGUAGE_DANISH,
74                 LANGUAGE_GERMAN,
75                 LANGUAGE_ENGLISH,
76                 LANGUAGE_SPANISH,
77                 LANGUAGE_ESPERANTO,
78                 LANGUAGE_ESTONIAN,
79                 LANGUAGE_BASQUE,
80                 LANGUAGE_FAROESE,
81                 LANGUAGE_FRENCH,
82                 LANGUAGE_FRISIAN,
83                 LANGUAGE_IRISH,
84                 LANGUAGE_GAELIC,
85                 LANGUAGE_GALACIAN,
86                 LANGUAGE_ICELANDIC,
87                 LANGUAGE_ITALIAN,
88                 LANGUAGE_LAPPISH,
89                 LANGUAGE_LATIN,
90                 LANGUAGE_LATVIAN,
91                 LANGUAGE_LUXEMBORGIAN,
92                 LANGUAGE_LITHUANIAN,
93                 LANGUAGE_HUNGARIAN,
94                 LANGUAGE_MALTESE,
95                 LANGUAGE_DUTCH,
96                 LANGUAGE_NORWEGIAN,
97                 LANGUAGE_OCCITAN,
98                 LANGUAGE_POLISH,
99                 LANGUAGE_PORTUGESE,
100                 LANGUAGE_ROMANIAN,
101                 LANGUAGE_ROMANSH,
102                 LANGUAGE_SERBIAN,
103                 LANGUAGE_SLOVAK,
104                 LANGUAGE_SLOVENIAN,
105                 LANGUAGE_FINNISH,
106                 LANGUAGE_SWEDISH,
107                 LANGUAGE_TURKISH,
108                 LANGUAGE_FLEMISH,
109                 LANGUAGE_WALLON,
110                 LANGUAGE_AMHARIC,
111                 LANGUAGE_ARABIC,
112                 LANGUAGE_ARMENIAN,
113                 LANGUAGE_ASSAMESE,
114                 LANGUAGE_AZERBAIJANI,
115                 LANGUAGE_BAMBORA,
116                 LANGUAGE_BIELORUSSIAN,
117                 LANGUAGE_BENGALI,
118                 LANGUAGE_BULGARIAN,
119                 LANGUAGE_BURMESE,
120                 LANGUAGE_CHINESE,
121                 LANGUAGE_CHURASH,
122                 LANGUAGE_DARI,
123                 LANGUAGE_FULANI,
124                 LANGUAGE_GEORGIAN,
125                 LANGUAGE_GREEK,
126                 LANGUAGE_GUJURATI,
127                 LANGUAGE_GURANI,
128                 LANGUAGE_HAUSA,
129                 LANGUAGE_HEBREW,
130                 LANGUAGE_HINDI,
131                 LANGUAGE_INDONESIAN,
132                 LANGUAGE_JAPANESE,
133                 LANGUAGE_KANNADA,
134                 LANGUAGE_KAZAKH,
135                 LANGUAGE_KHMER,
136                 LANGUAGE_KOREAN,
137                 LANGUAGE_LAOTIAN,
138                 LANGUAGE_MACEDONIAN,
139                 LANGUAGE_MALAGASAY,
140                 LANGUAGE_MALAYSIAN,
141                 LANGUAGE_MOLDAVIAN,
142                 LANGUAGE_MARATHI,
143                 LANGUAGE_NDEBELE,
144                 LANGUAGE_NEPALI,
145                 LANGUAGE_ORIYA,
146                 LANGUAGE_PAPAMIENTO,
147                 LANGUAGE_PERSIAN,
148                 LANGUAGE_PUNJABI,
149                 LANGUAGE_PUSHTU,
150                 LANGUAGE_QUECHUA,
151                 LANGUAGE_RUSSIAN,
152                 LANGUAGE_RUTHENIAN,
153                 LANGUAGE_SERBO_CROAT,
154                 LANGUAGE_SHONA,
155                 LANGUAGE_SINHALESE,
156                 LANGUAGE_SOMALI,
157                 LANGUAGE_SRANAN_TONGO,
158                 LANGUAGE_SWAHILI,
159                 LANGUAGE_TADZHIK,
160                 LANGUAGE_TAMIL,
161                 LANGUAGE_TATAR,
162                 LANGUAGE_TELUGU,
163                 LANGUAGE_THAI,
164                 LANGUAGE_UKRANIAN,
165                 LANGUAGE_URDU,
166                 LANGUAGE_UZBEK,
167                 LANGUAGE_VIETNAMESE,
168                 LANGUAGE_ZULU
169         };
170
171         enum TimecodeStatus {
172                 TIMECODE_STATUS_NOT_INTENDED_FOR_USE,
173                 TIMECODE_STATUS_INTENDED_FOR_USE
174         };
175
176         int code_page_number;
177         int frame_rate;
178         DisplayStandard display_standard;
179         LanguageGroup language_group;
180         Language language;
181         std::string original_programme_title;
182         std::string original_episode_title;
183         std::string translated_programme_title;
184         std::string translated_episode_title;
185         std::string translator_name;
186         std::string translator_contact_details;
187         std::string subtitle_list_reference_code;
188         std::string creation_date;
189         std::string revision_date;
190         std::string revision_number;
191         int tti_blocks;
192         int number_of_subtitles;
193         int subtitle_groups;
194         int maximum_characters;
195         int maximum_rows;
196         TimecodeStatus timecode_status;
197         std::string start_of_programme;
198         std::string first_in_cue;
199         int disks;
200         int disk_sequence_number;
201         std::string country_of_origin;
202         std::string publisher;
203         std::string editor_name;
204         std::string editor_contact_details;
205
206 private:
207         std::string fixed_string (int, int) const;
208         void create_maps ();
209         
210         std::map<std::string, STLCode<DisplayStandard> > _display_standard_map;
211         std::map<std::string, STLCode<LanguageGroup> > _language_group_map;
212         std::map<std::string, STLCode<Language> > _language_map;
213         std::map<std::string, STLCode<TimecodeStatus> > _timecode_status_map;
214
215         unsigned char* _buffer;
216 };
217
218 }