annotate libass/ass.c @ 34790:89c7cd996a36

codecs.conf: add some isom/fourcc to dts decoders
author compn
date Wed, 25 Apr 2012 01:07:11 +0000
parents 6e7f60f6f9d4
children 49fc594fda43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20008
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19905
diff changeset
1 /*
26723
0f892cd714b2 Use standard license header.
diego
parents: 26593
diff changeset
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
0f892cd714b2 Use standard license header.
diego
parents: 26593
diff changeset
3 *
26738
588ce97b44f2 Speak of libass instead of MPlayer in the libass license headers.
diego
parents: 26723
diff changeset
4 * This file is part of libass.
26723
0f892cd714b2 Use standard license header.
diego
parents: 26593
diff changeset
5 *
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
6 * Permission to use, copy, modify, and distribute this software for any
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
7 * purpose with or without fee is hereby granted, provided that the above
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
8 * copyright notice and this permission notice appear in all copies.
26723
0f892cd714b2 Use standard license header.
diego
parents: 26593
diff changeset
9 *
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26723
0f892cd714b2 Use standard license header.
diego
parents: 26593
diff changeset
17 */
20008
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19905
diff changeset
18
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
19 #include "config.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
20
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
21 #include <stdio.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
22 #include <stdlib.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
23 #include <string.h>
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
24 #include <strings.h>
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
25 #include <assert.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
26 #include <errno.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
27 #include <sys/types.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
28 #include <sys/stat.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
29 #include <unistd.h>
19374
acb26d9717da MinGW treats %lld as %d. Replace it with PRId64.
eugeni
parents: 18937
diff changeset
30 #include <inttypes.h>
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
31 #include <ctype.h>
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
32
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
33 #ifdef CONFIG_ICONV
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
34 #include <iconv.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
35 #endif
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
36
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
37 #include "ass.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
38 #include "ass_utils.h"
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents: 20008
diff changeset
39 #include "ass_library.h"
19652
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
40
31853
e64df5862cea Import libass 0.9.10
greg
parents: 31227
diff changeset
41 #define ass_atof(STR) (ass_strtod((STR),NULL))
e64df5862cea Import libass 0.9.10
greg
parents: 31227
diff changeset
42
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
43 typedef enum {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
44 PST_UNKNOWN = 0,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
45 PST_INFO,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
46 PST_STYLES,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
47 PST_EVENTS,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
48 PST_FONTS
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
49 } ParserState;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
50
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
51 struct parser_priv {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
52 ParserState state;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
53 char *fontname;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
54 char *fontdata;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
55 int fontdata_size;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
56 int fontdata_used;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
57 };
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
58
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
59 #define ASS_STYLES_ALLOC 20
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
60 #define ASS_EVENTS_ALLOC 200
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
61
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
62 void ass_free_track(ASS_Track *track)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
63 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
64 int i;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
65
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
66 if (track->parser_priv) {
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
67 free(track->parser_priv->fontname);
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
68 free(track->parser_priv->fontdata);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
69 free(track->parser_priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
70 }
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
71 free(track->style_format);
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
72 free(track->event_format);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
73 free(track->Language);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
74 if (track->styles) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
75 for (i = 0; i < track->n_styles; ++i)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
76 ass_free_style(track, i);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
77 }
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
78 free(track->styles);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
79 if (track->events) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
80 for (i = 0; i < track->n_events; ++i)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
81 ass_free_event(track, i);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
82 }
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
83 free(track->events);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
84 free(track->name);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
85 free(track);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
86 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
87
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
88 /// \brief Allocate a new style struct
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
89 /// \param track track
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
90 /// \return style id
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
91 int ass_alloc_style(ASS_Track *track)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
92 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
93 int sid;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
94
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
95 assert(track->n_styles <= track->max_styles);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
96
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
97 if (track->n_styles == track->max_styles) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
98 track->max_styles += ASS_STYLES_ALLOC;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
99 track->styles =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
100 (ASS_Style *) realloc(track->styles,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
101 sizeof(ASS_Style) *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
102 track->max_styles);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
103 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
104
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
105 sid = track->n_styles++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
106 memset(track->styles + sid, 0, sizeof(ASS_Style));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
107 return sid;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
108 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
109
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
110 /// \brief Allocate a new event struct
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
111 /// \param track track
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
112 /// \return event id
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
113 int ass_alloc_event(ASS_Track *track)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
114 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
115 int eid;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
116
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
117 assert(track->n_events <= track->max_events);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
118
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
119 if (track->n_events == track->max_events) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
120 track->max_events += ASS_EVENTS_ALLOC;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
121 track->events =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
122 (ASS_Event *) realloc(track->events,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
123 sizeof(ASS_Event) *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
124 track->max_events);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
125 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
126
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
127 eid = track->n_events++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
128 memset(track->events + eid, 0, sizeof(ASS_Event));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
129 return eid;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
130 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
131
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
132 void ass_free_event(ASS_Track *track, int eid)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
133 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
134 ASS_Event *event = track->events + eid;
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
135
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
136 free(event->Name);
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
137 free(event->Effect);
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
138 free(event->Text);
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
139 free(event->render_priv);
19474
07209f48e527 Add public functions for removal of styles and events.
eugeni
parents: 19405
diff changeset
140 }
07209f48e527 Add public functions for removal of styles and events.
eugeni
parents: 19405
diff changeset
141
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
142 void ass_free_style(ASS_Track *track, int sid)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
143 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
144 ASS_Style *style = track->styles + sid;
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
145
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
146 free(style->Name);
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
147 free(style->FontName);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
148 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
149
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
150 // ==============================================================================================
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
151
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
152 static void skip_spaces(char **str)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
153 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
154 char *p = *str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
155 while ((*p == ' ') || (*p == '\t'))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
156 ++p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
157 *str = p;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
158 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
159
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
160 static void rskip_spaces(char **str, char *limit)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
161 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
162 char *p = *str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
163 while ((p >= limit) && ((*p == ' ') || (*p == '\t')))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
164 --p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
165 *str = p;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
166 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
167
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
168 /**
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
169 * \brief Set up default style
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
170 * \param style style to edit to defaults
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
171 * The parameters are mostly taken directly from VSFilter source for
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
172 * best compatibility.
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
173 */
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
174 static void set_default_style(ASS_Style *style)
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
175 {
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
176 style->Name = strdup("Default");
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
177 style->FontName = strdup("Arial");
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
178 style->FontSize = 18;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
179 style->PrimaryColour = 0xffffff00;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
180 style->SecondaryColour = 0x00ffff00;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
181 style->OutlineColour = 0x00000000;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
182 style->BackColour = 0x00000080;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
183 style->Bold = 200;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
184 style->ScaleX = 1.0;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
185 style->ScaleY = 1.0;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
186 style->Spacing = 0;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
187 style->BorderStyle = 1;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
188 style->Outline = 2;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
189 style->Shadow = 3;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
190 style->Alignment = 2;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
191 style->MarginL = style->MarginR = style->MarginV = 20;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
192 }
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
193
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
194 /**
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
195 * \brief find style by name
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
196 * \param track track
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
197 * \param name style name
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
198 * \return index in track->styles
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
199 * Returnes 0 if no styles found => expects at least 1 style.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
200 * Parsing code always adds "Default" style in the end.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
201 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
202 static int lookup_style(ASS_Track *track, char *name)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
203 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
204 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
205 if (*name == '*')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
206 ++name; // FIXME: what does '*' really mean ?
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
207 for (i = track->n_styles - 1; i >= 0; --i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
208 if (strcmp(track->styles[i].Name, name) == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
209 return i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
210 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
211 i = track->default_style;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
212 ass_msg(track->library, MSGL_WARN,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
213 "[%p]: Warning: no style named '%s' found, using '%s'",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
214 track, name, track->styles[i].Name);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
215 return i; // use the first style
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
216 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
217
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
218 static uint32_t string2color(ASS_Library *library, char *p)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
219 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
220 uint32_t tmp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
221 (void) strtocolor(library, &p, &tmp, 0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
222 return tmp;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
223 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
224
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
225 static long long string2timecode(ASS_Library *library, char *p)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
226 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
227 unsigned h, m, s, ms;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
228 long long tm;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
229 int res = sscanf(p, "%1d:%2d:%2d.%2d", &h, &m, &s, &ms);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
230 if (res < 4) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
231 ass_msg(library, MSGL_WARN, "Bad timestamp");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
232 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
233 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
234 tm = ((h * 60 + m) * 60 + s) * 1000 + ms * 10;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
235 return tm;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
236 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
237
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
238 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
239 * \brief converts numpad-style align to align.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
240 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
241 static int numpad2align(int val)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
242 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
243 int res, v;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
244 v = (val - 1) / 3; // 0, 1 or 2 for vertical alignment
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
245 if (v != 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
246 v = 3 - v;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
247 res = ((val - 1) % 3) + 1; // horizontal alignment
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
248 res += v * 4;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
249 return res;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
250 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
251
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
252 #define NEXT(str,token) \
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
253 token = next_token(&str); \
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
254 if (!token) break;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
255
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
256 #define ANYVAL(name,func) \
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
257 } else if (strcasecmp(tname, #name) == 0) { \
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
258 target->name = func(token); \
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
259 ass_msg(track->library, MSGL_DBG2, "%s = %s", #name, token);
19495
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
260
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
261 #define STRVAL(name) \
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
262 } else if (strcasecmp(tname, #name) == 0) { \
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
263 if (target->name != NULL) free(target->name); \
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
264 target->name = strdup(token); \
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
265 ass_msg(track->library, MSGL_DBG2, "%s = %s", #name, token);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
266
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
267 #define COLORVAL(name) \
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
268 } else if (strcasecmp(tname, #name) == 0) { \
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
269 target->name = string2color(track->library, token); \
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
270 ass_msg(track->library, MSGL_DBG2, "%s = %s", #name, token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
271
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
272 #define INTVAL(name) ANYVAL(name,atoi)
31853
e64df5862cea Import libass 0.9.10
greg
parents: 31227
diff changeset
273 #define FPVAL(name) ANYVAL(name,ass_atof)
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
274 #define TIMEVAL(name) \
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
275 } else if (strcasecmp(tname, #name) == 0) { \
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
276 target->name = string2timecode(track->library, token); \
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
277 ass_msg(track->library, MSGL_DBG2, "%s = %s", #name, token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
278
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
279 #define STYLEVAL(name) \
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
280 } else if (strcasecmp(tname, #name) == 0) { \
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
281 target->name = lookup_style(track, token); \
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
282 ass_msg(track->library, MSGL_DBG2, "%s = %s", #name, token);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
283
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
284 #define ALIAS(alias,name) \
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
285 if (strcasecmp(tname, #alias) == 0) {tname = #name;}
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
286
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
287 static char *next_token(char **str)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
288 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
289 char *p = *str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
290 char *start;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
291 skip_spaces(&p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
292 if (*p == '\0') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
293 *str = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
294 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
295 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
296 start = p; // start of the token
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
297 for (; (*p != '\0') && (*p != ','); ++p) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
298 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
299 if (*p == '\0') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
300 *str = p; // eos found, str will point to '\0' at exit
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
301 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
302 *p = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
303 *str = p + 1; // ',' found, str will point to the next char (beginning of the next token)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
304 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
305 --p; // end of current token
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
306 rskip_spaces(&p, start);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
307 if (p < start)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
308 p = start; // empty token
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
309 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
310 ++p; // the first space character, or '\0'
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
311 *p = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
312 return start;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
313 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
314
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
315 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
316 * \brief Parse the tail of Dialogue line
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
317 * \param track track
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
318 * \param event parsed data goes here
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
319 * \param str string to parse, zero-terminated
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
320 * \param n_ignored number of format options to skip at the beginning
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
321 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
322 static int process_event_tail(ASS_Track *track, ASS_Event *event,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
323 char *str, int n_ignored)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
324 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
325 char *token;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
326 char *tname;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
327 char *p = str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
328 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
329 ASS_Event *target = event;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
330
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
331 char *format = strdup(track->event_format);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
332 char *q = format; // format scanning pointer
29472
ce53e67e8633 Fix crash when event format is not specified
greg
parents: 29263
diff changeset
333
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
334 if (track->n_styles == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
335 // add "Default" style to the end
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
336 // will be used if track does not contain a default style (or even does not contain styles at all)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
337 int sid = ass_alloc_style(track);
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
338 set_default_style(&track->styles[sid]);
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
339 track->default_style = sid;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
340 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
341
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
342 for (i = 0; i < n_ignored; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
343 NEXT(q, tname);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
344 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
345
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
346 while (1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
347 NEXT(q, tname);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
348 if (strcasecmp(tname, "Text") == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
349 char *last;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
350 event->Text = strdup(p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
351 if (*event->Text != 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
352 last = event->Text + strlen(event->Text) - 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
353 if (last >= event->Text && *last == '\r')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
354 *last = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
355 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
356 ass_msg(track->library, MSGL_DBG2, "Text = %s", event->Text);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
357 event->Duration -= event->Start;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
358 free(format);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
359 return 0; // "Text" is always the last
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
360 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
361 NEXT(p, token);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
362
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
363 ALIAS(End, Duration) // temporarily store end timecode in event->Duration
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
364 if (0) { // cool ;)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
365 INTVAL(Layer)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
366 STYLEVAL(Style)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
367 STRVAL(Name)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
368 STRVAL(Effect)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
369 INTVAL(MarginL)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
370 INTVAL(MarginR)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
371 INTVAL(MarginV)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
372 TIMEVAL(Start)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
373 TIMEVAL(Duration)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
374 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
375 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
376 free(format);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
377 return 1;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
378 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
379
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
380 /**
19495
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
381 * \brief Parse command line style overrides (--ass-force-style option)
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
382 * \param track track to apply overrides to
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
383 * The format for overrides is [StyleName.]Field=Value
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
384 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
385 void ass_process_force_style(ASS_Track *track)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
386 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
387 char **fs, *eq, *dt, *style, *tname, *token;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
388 ASS_Style *target;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
389 int sid;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
390 char **list = track->library->style_overrides;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
391
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
392 if (!list)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
393 return;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
394
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
395 for (fs = list; *fs; ++fs) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
396 eq = strrchr(*fs, '=');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
397 if (!eq)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
398 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
399 *eq = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
400 token = eq + 1;
19495
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
401
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
402 if (!strcasecmp(*fs, "PlayResX"))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
403 track->PlayResX = atoi(token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
404 else if (!strcasecmp(*fs, "PlayResY"))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
405 track->PlayResY = atoi(token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
406 else if (!strcasecmp(*fs, "Timer"))
31853
e64df5862cea Import libass 0.9.10
greg
parents: 31227
diff changeset
407 track->Timer = ass_atof(token);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
408 else if (!strcasecmp(*fs, "WrapStyle"))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
409 track->WrapStyle = atoi(token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
410 else if (!strcasecmp(*fs, "ScaledBorderAndShadow"))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
411 track->ScaledBorderAndShadow = parse_bool(token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
412 else if (!strcasecmp(*fs, "Kerning"))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
413 track->Kerning = parse_bool(token);
25582
6b1d7568ae3d Allow overriding [Script Info] parameters with -ass-force-style option.
eugeni
parents: 25515
diff changeset
414
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
415 dt = strrchr(*fs, '.');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
416 if (dt) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
417 *dt = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
418 style = *fs;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
419 tname = dt + 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
420 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
421 style = NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
422 tname = *fs;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
423 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
424 for (sid = 0; sid < track->n_styles; ++sid) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
425 if (style == NULL
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
426 || strcasecmp(track->styles[sid].Name, style) == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
427 target = track->styles + sid;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
428 if (0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
429 STRVAL(FontName)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
430 COLORVAL(PrimaryColour)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
431 COLORVAL(SecondaryColour)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
432 COLORVAL(OutlineColour)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
433 COLORVAL(BackColour)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
434 FPVAL(FontSize)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
435 INTVAL(Bold)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
436 INTVAL(Italic)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
437 INTVAL(Underline)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
438 INTVAL(StrikeOut)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
439 FPVAL(Spacing)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
440 INTVAL(Angle)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
441 INTVAL(BorderStyle)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
442 INTVAL(Alignment)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
443 INTVAL(MarginL)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
444 INTVAL(MarginR)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
445 INTVAL(MarginV)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
446 INTVAL(Encoding)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
447 FPVAL(ScaleX)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
448 FPVAL(ScaleY)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
449 FPVAL(Outline)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
450 FPVAL(Shadow)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
451 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
452 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
453 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
454 *eq = '=';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
455 if (dt)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
456 *dt = '.';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
457 }
19495
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
458 }
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
459
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
460 /**
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
461 * \brief Parse the Style line
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
462 * \param track track
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
463 * \param str string to parse, zero-terminated
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
464 * Allocates a new style struct.
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
465 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
466 static int process_style(ASS_Track *track, char *str)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
467 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
468
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
469 char *token;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
470 char *tname;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
471 char *p = str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
472 char *format;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
473 char *q; // format scanning pointer
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
474 int sid;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
475 ASS_Style *style;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
476 ASS_Style *target;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
477
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
478 if (!track->style_format) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
479 // no style format header
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
480 // probably an ancient script version
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
481 if (track->track_type == TRACK_TYPE_SSA)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
482 track->style_format =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
483 strdup
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
484 ("Name, Fontname, Fontsize, PrimaryColour, SecondaryColour,"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
485 "TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline,"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
486 "Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
487 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
488 track->style_format =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
489 strdup
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
490 ("Name, Fontname, Fontsize, PrimaryColour, SecondaryColour,"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
491 "OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut,"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
492 "ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow,"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
493 "Alignment, MarginL, MarginR, MarginV, Encoding");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
494 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
495
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
496 q = format = strdup(track->style_format);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
497
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
498 // Add default style first
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
499 if (track->n_styles == 0) {
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
500 // will be used if track does not contain a default style (or even does not contain styles at all)
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
501 int sid = ass_alloc_style(track);
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
502 set_default_style(&track->styles[sid]);
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
503 track->default_style = sid;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
504 }
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
505
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
506 ass_msg(track->library, MSGL_V, "[%p] Style: %s", track, str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
507
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
508 sid = ass_alloc_style(track);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
509
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
510 style = track->styles + sid;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
511 target = style;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
512
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
513 // fill style with some default values
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
514 style->ScaleX = 100.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
515 style->ScaleY = 100.;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
516
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
517 while (1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
518 NEXT(q, tname);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
519 NEXT(p, token);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
520
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
521 if (0) { // cool ;)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
522 STRVAL(Name)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
523 if ((strcmp(target->Name, "Default") == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
524 || (strcmp(target->Name, "*Default") == 0))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
525 track->default_style = sid;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
526 STRVAL(FontName)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
527 COLORVAL(PrimaryColour)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
528 COLORVAL(SecondaryColour)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
529 COLORVAL(OutlineColour) // TertiaryColor
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
530 COLORVAL(BackColour)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
531 // SSA uses BackColour for both outline and shadow
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
532 // this will destroy SSA's TertiaryColour, but i'm not going to use it anyway
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
533 if (track->track_type == TRACK_TYPE_SSA)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
534 target->OutlineColour = target->BackColour;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
535 FPVAL(FontSize)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
536 INTVAL(Bold)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
537 INTVAL(Italic)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
538 INTVAL(Underline)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
539 INTVAL(StrikeOut)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
540 FPVAL(Spacing)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
541 INTVAL(Angle)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
542 INTVAL(BorderStyle)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
543 INTVAL(Alignment)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
544 if (track->track_type == TRACK_TYPE_ASS)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
545 target->Alignment = numpad2align(target->Alignment);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
546 INTVAL(MarginL)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
547 INTVAL(MarginR)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
548 INTVAL(MarginV)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
549 INTVAL(Encoding)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
550 FPVAL(ScaleX)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
551 FPVAL(ScaleY)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
552 FPVAL(Outline)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
553 FPVAL(Shadow)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
554 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
555 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
556 style->ScaleX /= 100.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
557 style->ScaleY /= 100.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
558 style->Bold = !!style->Bold;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
559 style->Italic = !!style->Italic;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
560 style->Underline = !!style->Underline;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
561 if (!style->Name)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
562 style->Name = strdup("Default");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
563 if (!style->FontName)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
564 style->FontName = strdup("Arial");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
565 free(format);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
566 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
567
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
568 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
569
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
570 static int process_styles_line(ASS_Track *track, char *str)
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
571 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
572 if (!strncmp(str, "Format:", 7)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
573 char *p = str + 7;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
574 skip_spaces(&p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
575 track->style_format = strdup(p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
576 ass_msg(track->library, MSGL_DBG2, "Style format: %s",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
577 track->style_format);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
578 } else if (!strncmp(str, "Style:", 6)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
579 char *p = str + 6;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
580 skip_spaces(&p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
581 process_style(track, p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
582 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
583 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
584 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
585
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
586 static int process_info_line(ASS_Track *track, char *str)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
587 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
588 if (!strncmp(str, "PlayResX:", 9)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
589 track->PlayResX = atoi(str + 9);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
590 } else if (!strncmp(str, "PlayResY:", 9)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
591 track->PlayResY = atoi(str + 9);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
592 } else if (!strncmp(str, "Timer:", 6)) {
31853
e64df5862cea Import libass 0.9.10
greg
parents: 31227
diff changeset
593 track->Timer = ass_atof(str + 6);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
594 } else if (!strncmp(str, "WrapStyle:", 10)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
595 track->WrapStyle = atoi(str + 10);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
596 } else if (!strncmp(str, "ScaledBorderAndShadow:", 22)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
597 track->ScaledBorderAndShadow = parse_bool(str + 22);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
598 } else if (!strncmp(str, "Kerning:", 8)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
599 track->Kerning = parse_bool(str + 8);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
600 } else if (!strncmp(str, "Language:", 9)) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
601 char *p = str + 9;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
602 while (*p && isspace(*p)) p++;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
603 track->Language = malloc(3);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
604 strncpy(track->Language, p, 2);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
605 track->Language[2] = 0;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
606 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
607 return 0;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
608 }
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
609
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
610 static void event_format_fallback(ASS_Track *track)
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
611 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
612 track->parser_priv->state = PST_EVENTS;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
613 if (track->track_type == TRACK_TYPE_SSA)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
614 track->event_format = strdup("Format: Marked, Start, End, Style, "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
615 "Name, MarginL, MarginR, MarginV, Effect, Text");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
616 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
617 track->event_format = strdup("Format: Layer, Start, End, Style, "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
618 "Actor, MarginL, MarginR, MarginV, Effect, Text");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
619 ass_msg(track->library, MSGL_V,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
620 "No event format found, using fallback");
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
621 }
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
622
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
623 static int process_events_line(ASS_Track *track, char *str)
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
624 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
625 if (!strncmp(str, "Format:", 7)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
626 char *p = str + 7;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
627 skip_spaces(&p);
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
628 free(track->event_format);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
629 track->event_format = strdup(p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
630 ass_msg(track->library, MSGL_DBG2, "Event format: %s", track->event_format);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
631 } else if (!strncmp(str, "Dialogue:", 9)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
632 // This should never be reached for embedded subtitles.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
633 // They have slightly different format and are parsed in ass_process_chunk,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
634 // called directly from demuxer
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
635 int eid;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
636 ASS_Event *event;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
637
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
638 str += 9;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
639 skip_spaces(&str);
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
640
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
641 eid = ass_alloc_event(track);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
642 event = track->events + eid;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
643
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
644 // We can't parse events with event_format
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
645 if (!track->event_format)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
646 event_format_fallback(track);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
647
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
648 process_event_tail(track, event, str, 0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
649 } else {
31853
e64df5862cea Import libass 0.9.10
greg
parents: 31227
diff changeset
650 ass_msg(track->library, MSGL_V, "Not understood: '%.30s'", str);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
651 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
652 return 0;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
653 }
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
654
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
655 // Copied from mkvtoolnix
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
656 static unsigned char *decode_chars(unsigned char c1, unsigned char c2,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
657 unsigned char c3, unsigned char c4,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
658 unsigned char *dst, int cnt)
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
659 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
660 uint32_t value;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
661 unsigned char bytes[3];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
662 int i;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
663
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
664 value =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
665 ((c1 - 33) << 18) + ((c2 - 33) << 12) + ((c3 - 33) << 6) + (c4 -
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
666 33);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
667 bytes[2] = value & 0xff;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
668 bytes[1] = (value & 0xff00) >> 8;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
669 bytes[0] = (value & 0xff0000) >> 16;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
670
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
671 for (i = 0; i < cnt; ++i)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
672 *dst++ = bytes[i];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
673 return dst;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
674 }
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
675
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
676 static int decode_font(ASS_Track *track)
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
677 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
678 unsigned char *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
679 unsigned char *q;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
680 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
681 int size; // original size
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
682 int dsize; // decoded size
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
683 unsigned char *buf = 0;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
684
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
685 ass_msg(track->library, MSGL_V, "Font: %d bytes encoded data",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
686 track->parser_priv->fontdata_used);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
687 size = track->parser_priv->fontdata_used;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
688 if (size % 4 == 1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
689 ass_msg(track->library, MSGL_ERR, "Bad encoded data size");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
690 goto error_decode_font;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
691 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
692 buf = malloc(size / 4 * 3 + 2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
693 q = buf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
694 for (i = 0, p = (unsigned char *) track->parser_priv->fontdata;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
695 i < size / 4; i++, p += 4) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
696 q = decode_chars(p[0], p[1], p[2], p[3], q, 3);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
697 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
698 if (size % 4 == 2) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
699 q = decode_chars(p[0], p[1], 0, 0, q, 1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
700 } else if (size % 4 == 3) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
701 q = decode_chars(p[0], p[1], p[2], 0, q, 2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
702 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
703 dsize = q - buf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
704 assert(dsize <= size / 4 * 3 + 2);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
705
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
706 if (track->library->extract_fonts) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
707 ass_add_font(track->library, track->parser_priv->fontname,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
708 (char *) buf, dsize);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
709 }
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
710
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
711 error_decode_font:
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
712 free(buf);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
713 free(track->parser_priv->fontname);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
714 free(track->parser_priv->fontdata);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
715 track->parser_priv->fontname = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
716 track->parser_priv->fontdata = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
717 track->parser_priv->fontdata_size = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
718 track->parser_priv->fontdata_used = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
719 return 0;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
720 }
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
721
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
722 static int process_fonts_line(ASS_Track *track, char *str)
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
723 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
724 int len;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
725
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
726 if (!strncmp(str, "fontname:", 9)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
727 char *p = str + 9;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
728 skip_spaces(&p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
729 if (track->parser_priv->fontname) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
730 decode_font(track);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
731 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
732 track->parser_priv->fontname = strdup(p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
733 ass_msg(track->library, MSGL_V, "Fontname: %s",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
734 track->parser_priv->fontname);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
735 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
736 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
737
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
738 if (!track->parser_priv->fontname) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
739 ass_msg(track->library, MSGL_V, "Not understood: '%s'", str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
740 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
741 }
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
742
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
743 len = strlen(str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
744 if (len > 80) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
745 ass_msg(track->library, MSGL_WARN, "Font line too long: %d, %s",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
746 len, str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
747 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
748 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
749 if (track->parser_priv->fontdata_used + len >
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
750 track->parser_priv->fontdata_size) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
751 track->parser_priv->fontdata_size += 100 * 1024;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
752 track->parser_priv->fontdata =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
753 realloc(track->parser_priv->fontdata,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
754 track->parser_priv->fontdata_size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
755 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
756 memcpy(track->parser_priv->fontdata + track->parser_priv->fontdata_used,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
757 str, len);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
758 track->parser_priv->fontdata_used += len;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
759
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
760 return 0;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
761 }
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
762
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
763 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
764 * \brief Parse a header line
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
765 * \param track track
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
766 * \param str string to parse, zero-terminated
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
767 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
768 static int process_line(ASS_Track *track, char *str)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
769 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
770 if (!strncasecmp(str, "[Script Info]", 13)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
771 track->parser_priv->state = PST_INFO;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
772 } else if (!strncasecmp(str, "[V4 Styles]", 11)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
773 track->parser_priv->state = PST_STYLES;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
774 track->track_type = TRACK_TYPE_SSA;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
775 } else if (!strncasecmp(str, "[V4+ Styles]", 12)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
776 track->parser_priv->state = PST_STYLES;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
777 track->track_type = TRACK_TYPE_ASS;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
778 } else if (!strncasecmp(str, "[Events]", 8)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
779 track->parser_priv->state = PST_EVENTS;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
780 } else if (!strncasecmp(str, "[Fonts]", 7)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
781 track->parser_priv->state = PST_FONTS;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
782 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
783 switch (track->parser_priv->state) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
784 case PST_INFO:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
785 process_info_line(track, str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
786 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
787 case PST_STYLES:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
788 process_styles_line(track, str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
789 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
790 case PST_EVENTS:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
791 process_events_line(track, str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
792 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
793 case PST_FONTS:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
794 process_fonts_line(track, str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
795 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
796 default:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
797 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
798 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
799 }
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
800
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
801 // there is no explicit end-of-font marker in ssa/ass
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
802 if ((track->parser_priv->state != PST_FONTS)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
803 && (track->parser_priv->fontname))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
804 decode_font(track);
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
805
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
806 return 0;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
807 }
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
808
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
809 static int process_text(ASS_Track *track, char *str)
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
810 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
811 char *p = str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
812 while (1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
813 char *q;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
814 while (1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
815 if ((*p == '\r') || (*p == '\n'))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
816 ++p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
817 else if (p[0] == '\xef' && p[1] == '\xbb' && p[2] == '\xbf')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
818 p += 3; // U+FFFE (BOM)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
819 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
820 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
821 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
822 for (q = p; ((*q != '\0') && (*q != '\r') && (*q != '\n')); ++q) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
823 };
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
824 if (q == p)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
825 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
826 if (*q != '\0')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
827 *(q++) = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
828 process_line(track, p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
829 if (*q == '\0')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
830 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
831 p = q;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
832 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
833 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
834 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
835
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
836 /**
27498
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
837 * \brief Process a chunk of subtitle stream data.
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
838 * \param track track
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
839 * \param data string to parse
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
840 * \param size length of data
27498
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
841 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
842 void ass_process_data(ASS_Track *track, char *data, int size)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
843 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
844 char *str = malloc(size + 1);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
845
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
846 memcpy(str, data, size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
847 str[size] = '\0';
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
848
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
849 ass_msg(track->library, MSGL_V, "Event: %s", str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
850 process_text(track, str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
851 free(str);
27498
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
852 }
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
853
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
854 /**
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
855 * \brief Process CodecPrivate section of subtitle stream
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
856 * \param track track
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
857 * \param data string to parse
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
858 * \param size length of data
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
859 CodecPrivate section contains [Stream Info] and [V4+ Styles] ([V4 Styles] for SSA) sections
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
860 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
861 void ass_process_codec_private(ASS_Track *track, char *data, int size)
27498
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
862 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
863 ass_process_data(track, data, size);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
864
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
865 // probably an mkv produced by ancient mkvtoolnix
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
866 // such files don't have [Events] and Format: headers
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
867 if (!track->event_format)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
868 event_format_fallback(track);
19495
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
869
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
870 ass_process_force_style(track);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
871 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
872
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
873 static int check_duplicate_event(ASS_Track *track, int ReadOrder)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
874 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
875 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
876 for (i = 0; i < track->n_events - 1; ++i) // ignoring last event, it is the one we are comparing with
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
877 if (track->events[i].ReadOrder == ReadOrder)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
878 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
879 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
880 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
881
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
882 /**
25515
diego
parents: 24851
diff changeset
883 * \brief Process a chunk of subtitle stream data. In Matroska, this contains exactly 1 event (or a commentary).
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
884 * \param track track
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
885 * \param data string to parse
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
886 * \param size length of data
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
887 * \param timecode starting time of the event (milliseconds)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
888 * \param duration duration of the event (milliseconds)
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
889 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
890 void ass_process_chunk(ASS_Track *track, char *data, int size,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
891 long long timecode, long long duration)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
892 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
893 char *str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
894 int eid;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
895 char *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
896 char *token;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
897 ASS_Event *event;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
898
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
899 if (!track->event_format) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
900 ass_msg(track->library, MSGL_WARN, "Event format header missing");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
901 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
902 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
903
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
904 str = malloc(size + 1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
905 memcpy(str, data, size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
906 str[size] = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
907 ass_msg(track->library, MSGL_V, "Event at %" PRId64 ", +%" PRId64 ": %s",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
908 (int64_t) timecode, (int64_t) duration, str);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
909
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
910 eid = ass_alloc_event(track);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
911 event = track->events + eid;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
912
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
913 p = str;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
914
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
915 do {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
916 NEXT(p, token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
917 event->ReadOrder = atoi(token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
918 if (check_duplicate_event(track, event->ReadOrder))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
919 break;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
920
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
921 NEXT(p, token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
922 event->Layer = atoi(token);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
923
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
924 process_event_tail(track, event, p, 3);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
925
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
926 event->Start = timecode;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
927 event->Duration = duration;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
928
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
929 free(str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
930 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
931 // dump_events(tid);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
932 } while (0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
933 // some error
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
934 ass_free_event(track, eid);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
935 track->n_events--;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
936 free(str);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
937 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
938
31227
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
939 /**
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
940 * \brief Flush buffered events.
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
941 * \param track track
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
942 */
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
943 void ass_flush_events(ASS_Track *track)
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
944 {
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
945 if (track->events) {
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
946 int eid;
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
947 for (eid = 0; eid < track->n_events; eid++)
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
948 ass_free_event(track, eid);
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
949 track->n_events = 0;
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
950 }
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
951 }
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
952
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
953 #ifdef CONFIG_ICONV
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
954 /** \brief recode buffer to utf-8
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents: 20008
diff changeset
955 * constraint: codepage != 0
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
956 * \param data pointer to text buffer
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
957 * \param size buffer size
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
958 * \return a pointer to recoded buffer, caller is responsible for freeing it
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
959 **/
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
960 static char *sub_recode(ASS_Library *library, char *data, size_t size,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
961 char *codepage)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
962 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
963 iconv_t icdsc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
964 char *tocp = "UTF-8";
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
965 char *outbuf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
966 assert(codepage);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
967
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
968 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
969 const char *cp_tmp = codepage;
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
970 #ifdef CONFIG_ENCA
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
971 char enca_lang[3], enca_fallback[100];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
972 if (sscanf(codepage, "enca:%2s:%99s", enca_lang, enca_fallback) == 2
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
973 || sscanf(codepage, "ENCA:%2s:%99s", enca_lang,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
974 enca_fallback) == 2) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
975 cp_tmp =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
976 ass_guess_buffer_cp(library, (unsigned char *) data, size,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
977 enca_lang, enca_fallback);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
978 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
979 #endif
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
980 if ((icdsc = iconv_open(tocp, cp_tmp)) != (iconv_t) (-1)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
981 ass_msg(library, MSGL_V, "Opened iconv descriptor");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
982 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
983 ass_msg(library, MSGL_ERR, "Error opening iconv descriptor");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
984 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
985
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
986 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
987 size_t osize = size;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
988 size_t ileft = size;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
989 size_t oleft = size - 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
990 char *ip;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
991 char *op;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
992 size_t rc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
993 int clear = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
994
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
995 outbuf = malloc(osize);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
996 ip = data;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
997 op = outbuf;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
998
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
999 while (1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1000 if (ileft)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1001 rc = iconv(icdsc, &ip, &ileft, &op, &oleft);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1002 else { // clear the conversion state and leave
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1003 clear = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1004 rc = iconv(icdsc, NULL, NULL, &op, &oleft);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1005 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1006 if (rc == (size_t) (-1)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1007 if (errno == E2BIG) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1008 size_t offset = op - outbuf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1009 outbuf = (char *) realloc(outbuf, osize + size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1010 op = outbuf + offset;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1011 osize += size;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1012 oleft += size;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1013 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1014 ass_msg(library, MSGL_WARN, "Error recoding file");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1015 return NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1016 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1017 } else if (clear)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1018 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1019 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1020 outbuf[osize - oleft - 1] = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1021 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1022
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1023 if (icdsc != (iconv_t) (-1)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1024 (void) iconv_close(icdsc);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1025 icdsc = (iconv_t) (-1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1026 ass_msg(library, MSGL_V, "Closed iconv descriptor");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1027 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1028
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1029 return outbuf;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1030 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1031 #endif // ICONV
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1032
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1033 /**
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1034 * \brief read file contents into newly allocated buffer
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1035 * \param fname file name
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1036 * \param bufsize out: file size
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1037 * \return pointer to file contents. Caller is responsible for its deallocation.
19652
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1038 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1039 static char *read_file(ASS_Library *library, char *fname, size_t *bufsize)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1040 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1041 int res;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1042 long sz;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1043 long bytes_read;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1044 char *buf;
19652
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1045
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1046 FILE *fp = fopen(fname, "rb");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1047 if (!fp) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1048 ass_msg(library, MSGL_WARN,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1049 "ass_read_file(%s): fopen failed", fname);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1050 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1051 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1052 res = fseek(fp, 0, SEEK_END);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1053 if (res == -1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1054 ass_msg(library, MSGL_WARN,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1055 "ass_read_file(%s): fseek failed", fname);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1056 fclose(fp);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1057 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1058 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1059
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1060 sz = ftell(fp);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1061 rewind(fp);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1062
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1063 ass_msg(library, MSGL_V, "File size: %ld", sz);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1064
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1065 buf = malloc(sz + 1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1066 assert(buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1067 bytes_read = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1068 do {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1069 res = fread(buf + bytes_read, 1, sz - bytes_read, fp);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1070 if (res <= 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1071 ass_msg(library, MSGL_INFO, "Read failed, %d: %s", errno,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1072 strerror(errno));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1073 fclose(fp);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1074 free(buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1075 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1076 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1077 bytes_read += res;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1078 } while (sz - bytes_read > 0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1079 buf[sz] = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1080 fclose(fp);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1081
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1082 if (bufsize)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1083 *bufsize = sz;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1084 return buf;
19652
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1085 }
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1086
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1087 /*
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1088 * \param buf pointer to subtitle text in utf-8
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1089 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1090 static ASS_Track *parse_memory(ASS_Library *library, char *buf)
19652
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1091 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1092 ASS_Track *track;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1093 int i;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1094
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1095 track = ass_new_track(library);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1096
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1097 // process header
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1098 process_text(track, buf);
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
1099
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1100 // external SSA/ASS subs does not have ReadOrder field
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1101 for (i = 0; i < track->n_events; ++i)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1102 track->events[i].ReadOrder = i;
19905
5a24682d9dd5 Set ReadOrder values for external subtitles.
eugeni
parents: 19652
diff changeset
1103
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1104 // there is no explicit end-of-font marker in ssa/ass
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1105 if (track->parser_priv->fontname)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1106 decode_font(track);
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
1107
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1108 if (track->track_type == TRACK_TYPE_UNKNOWN) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1109 ass_free_track(track);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1110 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1111 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1112
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1113 ass_process_force_style(track);
19495
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
1114
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1115 return track;
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1116 }
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1117
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1118 /**
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1119 * \brief Read subtitles from memory.
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1120 * \param library libass library object
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1121 * \param buf pointer to subtitles text
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1122 * \param bufsize size of buffer
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1123 * \param codepage recode buffer contents from given codepage
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1124 * \return newly allocated track
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1125 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1126 ASS_Track *ass_read_memory(ASS_Library *library, char *buf,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1127 size_t bufsize, char *codepage)
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1128 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1129 ASS_Track *track;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1130 int need_free = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1131
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1132 if (!buf)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1133 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1134
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
1135 #ifdef CONFIG_ICONV
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1136 if (codepage) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1137 buf = sub_recode(library, buf, bufsize, codepage);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1138 if (!buf)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1139 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1140 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1141 need_free = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1142 }
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1143 #endif
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1144 track = parse_memory(library, buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1145 if (need_free)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1146 free(buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1147 if (!track)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1148 return 0;
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1149
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1150 ass_msg(library, MSGL_INFO, "Added subtitle file: "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1151 "<memory> (%d styles, %d events)",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1152 track->n_styles, track->n_events);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1153 return track;
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1154 }
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1155
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1156 static char *read_file_recode(ASS_Library *library, char *fname,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1157 char *codepage, size_t *size)
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1158 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1159 char *buf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1160 size_t bufsize;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1161
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1162 buf = read_file(library, fname, &bufsize);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1163 if (!buf)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1164 return 0;
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
1165 #ifdef CONFIG_ICONV
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1166 if (codepage) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1167 char *tmpbuf = sub_recode(library, buf, bufsize, codepage);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1168 free(buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1169 buf = tmpbuf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1170 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1171 if (!buf)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1172 return 0;
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1173 #endif
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1174 *size = bufsize;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1175 return buf;
23424
7286d245bf33 Move code for reading a file and recoding it to utf-8 to a separate function.
eugeni
parents: 23300
diff changeset
1176 }
7286d245bf33 Move code for reading a file and recoding it to utf-8 to a separate function.
eugeni
parents: 23300
diff changeset
1177
7286d245bf33 Move code for reading a file and recoding it to utf-8 to a separate function.
eugeni
parents: 23300
diff changeset
1178 /**
7286d245bf33 Move code for reading a file and recoding it to utf-8 to a separate function.
eugeni
parents: 23300
diff changeset
1179 * \brief Read subtitles from file.
7286d245bf33 Move code for reading a file and recoding it to utf-8 to a separate function.
eugeni
parents: 23300
diff changeset
1180 * \param library libass library object
7286d245bf33 Move code for reading a file and recoding it to utf-8 to a separate function.
eugeni
parents: 23300
diff changeset
1181 * \param fname file name
7286d245bf33 Move code for reading a file and recoding it to utf-8 to a separate function.
eugeni
parents: 23300
diff changeset
1182 * \param codepage recode buffer contents from given codepage
7286d245bf33 Move code for reading a file and recoding it to utf-8 to a separate function.
eugeni
parents: 23300
diff changeset
1183 * \return newly allocated track
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1184 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1185 ASS_Track *ass_read_file(ASS_Library *library, char *fname,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1186 char *codepage)
23424
7286d245bf33 Move code for reading a file and recoding it to utf-8 to a separate function.
eugeni
parents: 23300
diff changeset
1187 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1188 char *buf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1189 ASS_Track *track;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1190 size_t bufsize;
23424
7286d245bf33 Move code for reading a file and recoding it to utf-8 to a separate function.
eugeni
parents: 23300
diff changeset
1191
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1192 buf = read_file_recode(library, fname, codepage, &bufsize);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1193 if (!buf)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1194 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1195 track = parse_memory(library, buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1196 free(buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1197 if (!track)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1198 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1199
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1200 track->name = strdup(fname);
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1201
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1202 ass_msg(library, MSGL_INFO,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1203 "Added subtitle file: '%s' (%d styles, %d events)",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1204 fname, track->n_styles, track->n_events);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1205
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1206 return track;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1207 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1208
19652
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1209 /**
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1210 * \brief read styles from file into already initialized track
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1211 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1212 int ass_read_styles(ASS_Track *track, char *fname, char *codepage)
19652
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1213 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1214 char *buf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1215 ParserState old_state;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1216 size_t sz;
19652
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1217
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1218 buf = read_file(track->library, fname, &sz);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1219 if (!buf)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1220 return 1;
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
1221 #ifdef CONFIG_ICONV
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1222 if (codepage) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1223 char *tmpbuf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1224 tmpbuf = sub_recode(track->library, buf, sz, codepage);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1225 free(buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1226 buf = tmpbuf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1227 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1228 if (!buf)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1229 return 0;
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1230 #endif
19652
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1231
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1232 old_state = track->parser_priv->state;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1233 track->parser_priv->state = PST_STYLES;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1234 process_text(track, buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1235 track->parser_priv->state = old_state;
19652
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1236
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1237 return 0;
19652
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1238 }
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1239
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1240 long long ass_step_sub(ASS_Track *track, long long now, int movement)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1241 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1242 int i;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1243
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1244 if (movement == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1245 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1246 if (track->n_events == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1247 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1248
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1249 if (movement < 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1250 for (i = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1251 (i < track->n_events)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1252 &&
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1253 ((long long) (track->events[i].Start +
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1254 track->events[i].Duration) <= now); ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1255 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1256 for (i = track->n_events - 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1257 (i >= 0) && ((long long) (track->events[i].Start) > now);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1258 --i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1259 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1260
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1261 // -1 and n_events are ok
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1262 assert(i >= -1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1263 assert(i <= track->n_events);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1264 i += movement;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1265 if (i < 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1266 i = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1267 if (i >= track->n_events)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1268 i = track->n_events - 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1269 return ((long long) track->events[i].Start) - now;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1270 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1271
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1272 ASS_Track *ass_new_track(ASS_Library *library)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1273 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1274 ASS_Track *track = calloc(1, sizeof(ASS_Track));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1275 track->library = library;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1276 track->ScaledBorderAndShadow = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1277 track->parser_priv = calloc(1, sizeof(ASS_ParserPriv));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1278 return track;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1279 }
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1280
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1281 /**
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1282 * \brief Prepare track for rendering
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1283 */
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1284 void ass_lazy_track_init(ASS_Library *lib, ASS_Track *track)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1285 {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1286 if (track->PlayResX && track->PlayResY)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1287 return;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1288 if (!track->PlayResX && !track->PlayResY) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1289 ass_msg(lib, MSGL_WARN,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1290 "Neither PlayResX nor PlayResY defined. Assuming 384x288");
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1291 track->PlayResX = 384;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1292 track->PlayResY = 288;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1293 } else {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1294 if (!track->PlayResY && track->PlayResX == 1280) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1295 track->PlayResY = 1024;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1296 ass_msg(lib, MSGL_WARN,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1297 "PlayResY undefined, setting to %d", track->PlayResY);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1298 } else if (!track->PlayResY) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1299 track->PlayResY = track->PlayResX * 3 / 4;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1300 ass_msg(lib, MSGL_WARN,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1301 "PlayResY undefined, setting to %d", track->PlayResY);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1302 } else if (!track->PlayResX && track->PlayResY == 1024) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1303 track->PlayResX = 1280;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1304 ass_msg(lib, MSGL_WARN,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1305 "PlayResX undefined, setting to %d", track->PlayResX);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1306 } else if (!track->PlayResX) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1307 track->PlayResX = track->PlayResY * 4 / 3;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1308 ass_msg(lib, MSGL_WARN,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1309 "PlayResX undefined, setting to %d", track->PlayResX);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1310 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1311 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1312 }