2 Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
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.
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.
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.
23 #include "stl_binary_writer.h"
24 #include "compose.hpp"
32 put_string (char* p, string s)
34 memcpy (p, s.c_str (), s.length ());
38 put_string (char* p, int n, string s)
40 memcpy (p, s.c_str (), s.length ());
41 memset (p + s.length(), ' ', s.length () - n);
44 /** @param language ISO 3-character country code for the language of the subtitles */
46 sub::write_stl_binary (
47 list<Subtitle> subtitles,
48 float frames_per_second,
50 string original_programme_title,
51 string original_episode_title,
52 string translated_programme_title,
53 string translated_episode_title,
54 string translator_name,
55 string translator_contact_details,
59 string country_of_origin,
62 string editor_contact_details,
63 boost::filesystem::path file_name
66 assert (language.size() == 3);
67 assert (original_programme_title.size() <= 32);
68 assert (original_episode_title.size() <= 32);
69 assert (translated_programme_title.size() <= 32);
70 assert (translated_episode_title.size() <= 32);
71 assert (translator_name.size() <= 32);
72 assert (translator_contact_details.size() <= 32);
73 assert (creation_date.size() == 6);
74 assert (revision_date.size() == 6);
75 assert (revision_number <= 99);
76 assert (country_of_origin.size() == 3);
77 assert (publisher.size() <= 32);
78 assert (editor_name.size() <= 32);
79 assert (editor_contact_details.size() <= 32);
81 char* buffer = new char[1024];
82 ofstream output (file_name.string().c_str ());
85 put_string (buffer + 0, "850");
86 /* Disk format code */
87 put_string (buffer + 3, String::compose ("STL%1.01", rint (frames_per_second)));
88 /* Display standard code: open subtitling */
89 put_string (buffer + 11, "0");
90 /* Character code table: Latin (ISO 6937) */
91 put_string (buffer + 12, "00");
92 put_string (buffer + 14, language);
93 put_string (buffer + 16, 32, original_programme_title);
94 put_string (buffer + 48, 32, original_episode_title);
95 put_string (buffer + 80, 32, translated_programme_title);
96 put_string (buffer + 112, 32, translated_episode_title);
97 put_string (buffer + 144, 32, translator_name);
98 put_string (buffer + 176, 32, translator_contact_details);
99 /* Subtitle list reference code */
100 put_string (buffer + 208, "0000000000000000");
101 put_string (buffer + 224, creation_date);
102 put_string (buffer + 230, revision_date);
103 put_string (buffer + 236, String::compose ("%02d", revision_number));
105 put_string (buffer + 238, String::compose ("%05d", subtitles.size ()));
106 /* Total number of subtitles */
107 put_string (buffer + 243, String::compose ("%05d", subtitles.size ()));
108 /* Total number of subtitle groups */
109 put_string (buffer + 248, "000");
110 /* Maximum number of displayable characters in any text row */
112 put_string (buffer + 251, "99");
113 /* Maximum number of displayable rows */
115 put_string (buffer + 253, "99");
116 /* Time code status */
117 put_string (buffer + 255, "1");
118 /* Start-of-programme time code */
119 put_string (buffer + 256, "00000000");
120 /* First-in-cue time code */
121 put_string (buffer + 264, "00000000");
122 /* Total number of disks */
123 put_string (buffer + 272, "1");
124 /* Disk sequence number */
125 put_string (buffer + 273, "1");
126 put_string (buffer + 274, country_of_origin);
127 put_string (buffer + 277, publisher);
128 put_string (buffer + 309, editor_name);
129 put_string (buffer + 341, editor_contact_details);
131 output.write (buffer, 1024);