annotate libass/ass.c @ 35818:0728f9dcb4ac

configure: Remove redundant double variable initialization
author diego
date Fri, 15 Feb 2013 02:40:33 +0000
parents d0004e3bcbbc
children c3aaaf17c721
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
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
194 static uint32_t string2color(ASS_Library *library, char *p)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
195 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
196 uint32_t tmp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
197 (void) strtocolor(library, &p, &tmp, 0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
198 return tmp;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
199 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
200
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
201 static long long string2timecode(ASS_Library *library, char *p)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
202 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
203 unsigned h, m, s, ms;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
204 long long tm;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
205 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
206 if (res < 4) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
207 ass_msg(library, MSGL_WARN, "Bad timestamp");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
208 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
209 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
210 tm = ((h * 60 + m) * 60 + s) * 1000 + ms * 10;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
211 return tm;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
212 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
213
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
214 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
215 * \brief converts numpad-style align to align.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
216 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
217 static int numpad2align(int val)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
218 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
219 int res, v;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
220 v = (val - 1) / 3; // 0, 1 or 2 for vertical alignment
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
221 if (v != 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
222 v = 3 - v;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
223 res = ((val - 1) % 3) + 1; // horizontal alignment
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
224 res += v * 4;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
225 return res;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
226 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
227
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
228 #define NEXT(str,token) \
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
229 token = next_token(&str); \
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
230 if (!token) break;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
231
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
232 #define ANYVAL(name,func) \
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
233 } else if (strcasecmp(tname, #name) == 0) { \
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
234 target->name = func(token); \
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
235 ass_msg(track->library, MSGL_DBG2, "%s = %s", #name, token);
19495
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
236
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
237 #define STRVAL(name) \
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
238 } else if (strcasecmp(tname, #name) == 0) { \
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
239 if (target->name != NULL) free(target->name); \
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
240 target->name = strdup(token); \
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
241 ass_msg(track->library, MSGL_DBG2, "%s = %s", #name, token);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
242
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
243 #define COLORVAL(name) \
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
244 } else if (strcasecmp(tname, #name) == 0) { \
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
245 target->name = string2color(track->library, token); \
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
246 ass_msg(track->library, MSGL_DBG2, "%s = %s", #name, token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
247
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
248 #define INTVAL(name) ANYVAL(name,atoi)
31853
e64df5862cea Import libass 0.9.10
greg
parents: 31227
diff changeset
249 #define FPVAL(name) ANYVAL(name,ass_atof)
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
250 #define TIMEVAL(name) \
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
251 } else if (strcasecmp(tname, #name) == 0) { \
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
252 target->name = string2timecode(track->library, token); \
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
253 ass_msg(track->library, MSGL_DBG2, "%s = %s", #name, token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
254
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
255 #define STYLEVAL(name) \
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
256 } else if (strcasecmp(tname, #name) == 0) { \
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
257 target->name = lookup_style(track, token); \
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
258 ass_msg(track->library, MSGL_DBG2, "%s = %s", #name, token);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
259
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
260 #define ALIAS(alias,name) \
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
261 if (strcasecmp(tname, #alias) == 0) {tname = #name;}
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
262
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
263 static char *next_token(char **str)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
264 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
265 char *p = *str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
266 char *start;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
267 skip_spaces(&p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
268 if (*p == '\0') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
269 *str = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
270 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
271 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
272 start = p; // start of the token
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
273 for (; (*p != '\0') && (*p != ','); ++p) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
274 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
275 if (*p == '\0') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
276 *str = p; // eos found, str will point to '\0' at exit
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
277 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
278 *p = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
279 *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
280 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
281 --p; // end of current token
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
282 rskip_spaces(&p, start);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
283 if (p < start)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
284 p = start; // empty token
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
285 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
286 ++p; // the first space character, or '\0'
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
287 *p = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
288 return start;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
289 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
290
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
291 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
292 * \brief Parse the tail of Dialogue line
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
293 * \param track track
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
294 * \param event parsed data goes here
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
295 * \param str string to parse, zero-terminated
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
296 * \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
297 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
298 static int process_event_tail(ASS_Track *track, ASS_Event *event,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
299 char *str, int n_ignored)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
300 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
301 char *token;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
302 char *tname;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
303 char *p = str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
304 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
305 ASS_Event *target = event;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
306
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
307 char *format = strdup(track->event_format);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
308 char *q = format; // format scanning pointer
29472
ce53e67e8633 Fix crash when event format is not specified
greg
parents: 29263
diff changeset
309
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
310 if (track->n_styles == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
311 // add "Default" style to the end
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
312 // 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
313 int sid = ass_alloc_style(track);
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
314 set_default_style(&track->styles[sid]);
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
315 track->default_style = sid;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
316 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
317
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
318 for (i = 0; i < n_ignored; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
319 NEXT(q, tname);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
320 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
321
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
322 while (1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
323 NEXT(q, tname);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
324 if (strcasecmp(tname, "Text") == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
325 char *last;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
326 event->Text = strdup(p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
327 if (*event->Text != 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
328 last = event->Text + strlen(event->Text) - 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
329 if (last >= event->Text && *last == '\r')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
330 *last = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
331 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
332 ass_msg(track->library, MSGL_DBG2, "Text = %s", event->Text);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
333 event->Duration -= event->Start;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
334 free(format);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
335 return 0; // "Text" is always the last
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
336 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
337 NEXT(p, token);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
338
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
339 ALIAS(End, Duration) // temporarily store end timecode in event->Duration
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
340 if (0) { // cool ;)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
341 INTVAL(Layer)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
342 STYLEVAL(Style)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
343 STRVAL(Name)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
344 STRVAL(Effect)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
345 INTVAL(MarginL)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
346 INTVAL(MarginR)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
347 INTVAL(MarginV)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
348 TIMEVAL(Start)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
349 TIMEVAL(Duration)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
350 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
351 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
352 free(format);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
353 return 1;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
354 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
355
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
356 /**
19495
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
357 * \brief Parse command line style overrides (--ass-force-style option)
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
358 * \param track track to apply overrides to
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
359 * The format for overrides is [StyleName.]Field=Value
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
360 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
361 void ass_process_force_style(ASS_Track *track)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
362 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
363 char **fs, *eq, *dt, *style, *tname, *token;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
364 ASS_Style *target;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
365 int sid;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
366 char **list = track->library->style_overrides;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
367
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
368 if (!list)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
369 return;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
370
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
371 for (fs = list; *fs; ++fs) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
372 eq = strrchr(*fs, '=');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
373 if (!eq)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
374 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
375 *eq = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
376 token = eq + 1;
19495
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
377
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
378 if (!strcasecmp(*fs, "PlayResX"))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
379 track->PlayResX = atoi(token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
380 else if (!strcasecmp(*fs, "PlayResY"))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
381 track->PlayResY = atoi(token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
382 else if (!strcasecmp(*fs, "Timer"))
31853
e64df5862cea Import libass 0.9.10
greg
parents: 31227
diff changeset
383 track->Timer = ass_atof(token);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
384 else if (!strcasecmp(*fs, "WrapStyle"))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
385 track->WrapStyle = atoi(token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
386 else if (!strcasecmp(*fs, "ScaledBorderAndShadow"))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
387 track->ScaledBorderAndShadow = parse_bool(token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
388 else if (!strcasecmp(*fs, "Kerning"))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
389 track->Kerning = parse_bool(token);
25582
6b1d7568ae3d Allow overriding [Script Info] parameters with -ass-force-style option.
eugeni
parents: 25515
diff changeset
390
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
391 dt = strrchr(*fs, '.');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
392 if (dt) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
393 *dt = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
394 style = *fs;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
395 tname = dt + 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
396 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
397 style = NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
398 tname = *fs;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
399 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
400 for (sid = 0; sid < track->n_styles; ++sid) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
401 if (style == NULL
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
402 || strcasecmp(track->styles[sid].Name, style) == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
403 target = track->styles + sid;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
404 if (0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
405 STRVAL(FontName)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
406 COLORVAL(PrimaryColour)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
407 COLORVAL(SecondaryColour)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
408 COLORVAL(OutlineColour)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
409 COLORVAL(BackColour)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
410 FPVAL(FontSize)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
411 INTVAL(Bold)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
412 INTVAL(Italic)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
413 INTVAL(Underline)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
414 INTVAL(StrikeOut)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
415 FPVAL(Spacing)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
416 INTVAL(Angle)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
417 INTVAL(BorderStyle)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
418 INTVAL(Alignment)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
419 INTVAL(MarginL)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
420 INTVAL(MarginR)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
421 INTVAL(MarginV)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
422 INTVAL(Encoding)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
423 FPVAL(ScaleX)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
424 FPVAL(ScaleY)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
425 FPVAL(Outline)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
426 FPVAL(Shadow)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
427 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
428 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
429 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
430 *eq = '=';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
431 if (dt)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
432 *dt = '.';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
433 }
19495
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
434 }
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
435
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
436 /**
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
437 * \brief Parse the Style line
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
438 * \param track track
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
439 * \param str string to parse, zero-terminated
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
440 * Allocates a new style struct.
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
441 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
442 static int process_style(ASS_Track *track, char *str)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
443 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
444
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
445 char *token;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
446 char *tname;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
447 char *p = str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
448 char *format;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
449 char *q; // format scanning pointer
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
450 int sid;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
451 ASS_Style *style;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
452 ASS_Style *target;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
453
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
454 if (!track->style_format) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
455 // no style format header
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
456 // probably an ancient script version
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
457 if (track->track_type == TRACK_TYPE_SSA)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
458 track->style_format =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
459 strdup
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
460 ("Name, Fontname, Fontsize, PrimaryColour, SecondaryColour,"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
461 "TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline,"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
462 "Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
463 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
464 track->style_format =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
465 strdup
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
466 ("Name, Fontname, Fontsize, PrimaryColour, SecondaryColour,"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
467 "OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut,"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
468 "ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow,"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
469 "Alignment, MarginL, MarginR, MarginV, Encoding");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
470 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
471
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
472 q = format = strdup(track->style_format);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
473
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
474 // Add default style first
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
475 if (track->n_styles == 0) {
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
476 // 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
477 int sid = ass_alloc_style(track);
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
478 set_default_style(&track->styles[sid]);
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
479 track->default_style = sid;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
480 }
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
481
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
482 ass_msg(track->library, MSGL_V, "[%p] Style: %s", track, str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
483
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
484 sid = ass_alloc_style(track);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
485
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
486 style = track->styles + sid;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
487 target = style;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
488
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
489 // fill style with some default values
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
490 style->ScaleX = 100.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
491 style->ScaleY = 100.;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
492
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
493 while (1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
494 NEXT(q, tname);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
495 NEXT(p, token);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
496
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
497 if (0) { // cool ;)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
498 STRVAL(Name)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
499 if ((strcmp(target->Name, "Default") == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
500 || (strcmp(target->Name, "*Default") == 0))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
501 track->default_style = sid;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
502 STRVAL(FontName)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
503 COLORVAL(PrimaryColour)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
504 COLORVAL(SecondaryColour)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
505 COLORVAL(OutlineColour) // TertiaryColor
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
506 COLORVAL(BackColour)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
507 // SSA uses BackColour for both outline and shadow
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
508 // 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
509 if (track->track_type == TRACK_TYPE_SSA)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
510 target->OutlineColour = target->BackColour;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
511 FPVAL(FontSize)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
512 INTVAL(Bold)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
513 INTVAL(Italic)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
514 INTVAL(Underline)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
515 INTVAL(StrikeOut)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
516 FPVAL(Spacing)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
517 INTVAL(Angle)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
518 INTVAL(BorderStyle)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
519 INTVAL(Alignment)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
520 if (track->track_type == TRACK_TYPE_ASS)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
521 target->Alignment = numpad2align(target->Alignment);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
522 INTVAL(MarginL)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
523 INTVAL(MarginR)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
524 INTVAL(MarginV)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
525 INTVAL(Encoding)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
526 FPVAL(ScaleX)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
527 FPVAL(ScaleY)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
528 FPVAL(Outline)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
529 FPVAL(Shadow)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
530 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
531 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
532 style->ScaleX /= 100.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
533 style->ScaleY /= 100.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
534 style->Bold = !!style->Bold;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
535 style->Italic = !!style->Italic;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
536 style->Underline = !!style->Underline;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
537 if (!style->Name)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
538 style->Name = strdup("Default");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
539 if (!style->FontName)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
540 style->FontName = strdup("Arial");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
541 free(format);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
542 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
543
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
544 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
545
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
546 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
547 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
548 if (!strncmp(str, "Format:", 7)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
549 char *p = str + 7;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
550 skip_spaces(&p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
551 track->style_format = strdup(p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
552 ass_msg(track->library, MSGL_DBG2, "Style format: %s",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
553 track->style_format);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
554 } else if (!strncmp(str, "Style:", 6)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
555 char *p = str + 6;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
556 skip_spaces(&p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
557 process_style(track, p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
558 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
559 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
560 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
561
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
562 static int process_info_line(ASS_Track *track, char *str)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
563 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
564 if (!strncmp(str, "PlayResX:", 9)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
565 track->PlayResX = atoi(str + 9);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
566 } else if (!strncmp(str, "PlayResY:", 9)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
567 track->PlayResY = atoi(str + 9);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
568 } else if (!strncmp(str, "Timer:", 6)) {
31853
e64df5862cea Import libass 0.9.10
greg
parents: 31227
diff changeset
569 track->Timer = ass_atof(str + 6);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
570 } else if (!strncmp(str, "WrapStyle:", 10)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
571 track->WrapStyle = atoi(str + 10);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
572 } else if (!strncmp(str, "ScaledBorderAndShadow:", 22)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
573 track->ScaledBorderAndShadow = parse_bool(str + 22);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
574 } else if (!strncmp(str, "Kerning:", 8)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
575 track->Kerning = parse_bool(str + 8);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
576 } else if (!strncmp(str, "Language:", 9)) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
577 char *p = str + 9;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
578 while (*p && isspace(*p)) p++;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
579 track->Language = malloc(3);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
580 strncpy(track->Language, p, 2);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
581 track->Language[2] = 0;
30200
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;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
584 }
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
585
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
586 static void event_format_fallback(ASS_Track *track)
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
587 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
588 track->parser_priv->state = PST_EVENTS;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
589 if (track->track_type == TRACK_TYPE_SSA)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
590 track->event_format = strdup("Format: Marked, Start, End, Style, "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
591 "Name, MarginL, MarginR, MarginV, Effect, Text");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
592 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
593 track->event_format = strdup("Format: Layer, Start, End, Style, "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
594 "Actor, MarginL, MarginR, MarginV, Effect, Text");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
595 ass_msg(track->library, MSGL_V,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
596 "No event format found, using fallback");
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
597 }
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
598
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
599 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
600 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
601 if (!strncmp(str, "Format:", 7)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
602 char *p = str + 7;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
603 skip_spaces(&p);
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
604 free(track->event_format);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
605 track->event_format = strdup(p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
606 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
607 } else if (!strncmp(str, "Dialogue:", 9)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
608 // This should never be reached for embedded subtitles.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
609 // 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
610 // called directly from demuxer
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
611 int eid;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
612 ASS_Event *event;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
613
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
614 str += 9;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
615 skip_spaces(&str);
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
616
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
617 eid = ass_alloc_event(track);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
618 event = track->events + eid;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
619
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
620 // We can't parse events with event_format
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
621 if (!track->event_format)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
622 event_format_fallback(track);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
623
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
624 process_event_tail(track, event, str, 0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
625 } else {
31853
e64df5862cea Import libass 0.9.10
greg
parents: 31227
diff changeset
626 ass_msg(track->library, MSGL_V, "Not understood: '%.30s'", str);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
627 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
628 return 0;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
629 }
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
630
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
631 // Copied from mkvtoolnix
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
632 static unsigned char *decode_chars(unsigned char c1, unsigned char c2,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
633 unsigned char c3, unsigned char c4,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
634 unsigned char *dst, int cnt)
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
635 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
636 uint32_t value;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
637 unsigned char bytes[3];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
638 int i;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
639
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
640 value =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
641 ((c1 - 33) << 18) + ((c2 - 33) << 12) + ((c3 - 33) << 6) + (c4 -
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
642 33);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
643 bytes[2] = value & 0xff;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
644 bytes[1] = (value & 0xff00) >> 8;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
645 bytes[0] = (value & 0xff0000) >> 16;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
646
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
647 for (i = 0; i < cnt; ++i)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
648 *dst++ = bytes[i];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
649 return dst;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
650 }
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
651
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
652 static int decode_font(ASS_Track *track)
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
653 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
654 unsigned char *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
655 unsigned char *q;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
656 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
657 int size; // original size
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
658 int dsize; // decoded size
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
659 unsigned char *buf = 0;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
660
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
661 ass_msg(track->library, MSGL_V, "Font: %d bytes encoded data",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
662 track->parser_priv->fontdata_used);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
663 size = track->parser_priv->fontdata_used;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
664 if (size % 4 == 1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
665 ass_msg(track->library, MSGL_ERR, "Bad encoded data size");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
666 goto error_decode_font;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
667 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
668 buf = malloc(size / 4 * 3 + 2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
669 q = buf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
670 for (i = 0, p = (unsigned char *) track->parser_priv->fontdata;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
671 i < size / 4; i++, p += 4) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
672 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
673 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
674 if (size % 4 == 2) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
675 q = decode_chars(p[0], p[1], 0, 0, q, 1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
676 } else if (size % 4 == 3) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
677 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
678 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
679 dsize = q - buf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
680 assert(dsize <= size / 4 * 3 + 2);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
681
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
682 if (track->library->extract_fonts) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
683 ass_add_font(track->library, track->parser_priv->fontname,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
684 (char *) buf, dsize);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
685 }
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
686
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
687 error_decode_font:
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
688 free(buf);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
689 free(track->parser_priv->fontname);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
690 free(track->parser_priv->fontdata);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
691 track->parser_priv->fontname = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
692 track->parser_priv->fontdata = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
693 track->parser_priv->fontdata_size = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
694 track->parser_priv->fontdata_used = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
695 return 0;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
696 }
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
697
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
698 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
699 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
700 int len;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
701
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
702 if (!strncmp(str, "fontname:", 9)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
703 char *p = str + 9;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
704 skip_spaces(&p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
705 if (track->parser_priv->fontname) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
706 decode_font(track);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
707 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
708 track->parser_priv->fontname = strdup(p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
709 ass_msg(track->library, MSGL_V, "Fontname: %s",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
710 track->parser_priv->fontname);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
711 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
712 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
713
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
714 if (!track->parser_priv->fontname) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
715 ass_msg(track->library, MSGL_V, "Not understood: '%s'", str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
716 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
717 }
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
718
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
719 len = strlen(str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
720 if (len > 80) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
721 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
722 len, str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
723 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
724 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
725 if (track->parser_priv->fontdata_used + len >
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
726 track->parser_priv->fontdata_size) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
727 track->parser_priv->fontdata_size += 100 * 1024;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
728 track->parser_priv->fontdata =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
729 realloc(track->parser_priv->fontdata,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
730 track->parser_priv->fontdata_size);
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 memcpy(track->parser_priv->fontdata + track->parser_priv->fontdata_used,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
733 str, len);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
734 track->parser_priv->fontdata_used += len;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
735
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
736 return 0;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
737 }
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
738
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
739 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
740 * \brief Parse a header line
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
741 * \param track track
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
742 * \param str string to parse, zero-terminated
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
743 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
744 static int process_line(ASS_Track *track, char *str)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
745 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
746 if (!strncasecmp(str, "[Script Info]", 13)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
747 track->parser_priv->state = PST_INFO;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
748 } else if (!strncasecmp(str, "[V4 Styles]", 11)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
749 track->parser_priv->state = PST_STYLES;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
750 track->track_type = TRACK_TYPE_SSA;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
751 } else if (!strncasecmp(str, "[V4+ Styles]", 12)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
752 track->parser_priv->state = PST_STYLES;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
753 track->track_type = TRACK_TYPE_ASS;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
754 } else if (!strncasecmp(str, "[Events]", 8)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
755 track->parser_priv->state = PST_EVENTS;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
756 } else if (!strncasecmp(str, "[Fonts]", 7)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
757 track->parser_priv->state = PST_FONTS;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
758 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
759 switch (track->parser_priv->state) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
760 case PST_INFO:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
761 process_info_line(track, str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
762 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
763 case PST_STYLES:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
764 process_styles_line(track, str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
765 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
766 case PST_EVENTS:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
767 process_events_line(track, str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
768 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
769 case PST_FONTS:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
770 process_fonts_line(track, str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
771 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
772 default:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
773 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
774 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
775 }
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
776
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
777 // there is no explicit end-of-font marker in ssa/ass
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
778 if ((track->parser_priv->state != PST_FONTS)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
779 && (track->parser_priv->fontname))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
780 decode_font(track);
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
781
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
782 return 0;
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
783 }
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
784
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
785 static int process_text(ASS_Track *track, char *str)
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
786 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
787 char *p = str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
788 while (1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
789 char *q;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
790 while (1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
791 if ((*p == '\r') || (*p == '\n'))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
792 ++p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
793 else if (p[0] == '\xef' && p[1] == '\xbb' && p[2] == '\xbf')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
794 p += 3; // U+FFFE (BOM)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
795 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
796 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
797 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
798 for (q = p; ((*q != '\0') && (*q != '\r') && (*q != '\n')); ++q) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
799 };
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
800 if (q == p)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
801 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
802 if (*q != '\0')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
803 *(q++) = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
804 process_line(track, p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
805 if (*q == '\0')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
806 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
807 p = q;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
808 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
809 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
810 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
811
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
812 /**
27498
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
813 * \brief Process a chunk of subtitle stream data.
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
814 * \param track track
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
815 * \param data string to parse
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
816 * \param size length of data
27498
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
817 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
818 void ass_process_data(ASS_Track *track, char *data, int size)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
819 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
820 char *str = malloc(size + 1);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
821
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
822 memcpy(str, data, size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
823 str[size] = '\0';
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
824
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
825 ass_msg(track->library, MSGL_V, "Event: %s", str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
826 process_text(track, str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
827 free(str);
27498
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
828 }
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
829
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
830 /**
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
831 * \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
832 * \param track track
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
833 * \param data string to parse
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
834 * \param size length of data
d895515b366d libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents: 27393
diff changeset
835 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
836 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
837 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
838 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
839 ass_process_data(track, data, size);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
840
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
841 // probably an mkv produced by ancient mkvtoolnix
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
842 // such files don't have [Events] and Format: headers
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
843 if (!track->event_format)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
844 event_format_fallback(track);
19495
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
845
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
846 ass_process_force_style(track);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
847 }
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 static int check_duplicate_event(ASS_Track *track, int ReadOrder)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
850 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
851 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
852 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
853 if (track->events[i].ReadOrder == ReadOrder)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
854 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
855 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
856 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
857
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
858 /**
25515
diego
parents: 24851
diff changeset
859 * \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
860 * \param track track
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
861 * \param data string to parse
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
862 * \param size length of data
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
863 * \param timecode starting time of the event (milliseconds)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
864 * \param duration duration of the event (milliseconds)
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
865 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
866 void ass_process_chunk(ASS_Track *track, char *data, int size,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
867 long long timecode, long long duration)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
868 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
869 char *str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
870 int eid;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
871 char *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
872 char *token;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
873 ASS_Event *event;
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 if (!track->event_format) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
876 ass_msg(track->library, MSGL_WARN, "Event format header missing");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
877 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
878 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
879
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
880 str = malloc(size + 1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
881 memcpy(str, data, size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
882 str[size] = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
883 ass_msg(track->library, MSGL_V, "Event at %" PRId64 ", +%" PRId64 ": %s",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
884 (int64_t) timecode, (int64_t) duration, str);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
885
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
886 eid = ass_alloc_event(track);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
887 event = track->events + eid;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
888
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
889 p = str;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
890
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
891 do {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
892 NEXT(p, token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
893 event->ReadOrder = atoi(token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
894 if (check_duplicate_event(track, event->ReadOrder))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
895 break;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
896
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
897 NEXT(p, token);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
898 event->Layer = atoi(token);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
899
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
900 process_event_tail(track, event, p, 3);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
901
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
902 event->Start = timecode;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
903 event->Duration = duration;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
904
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
905 free(str);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
906 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
907 // dump_events(tid);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
908 } while (0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
909 // some error
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
910 ass_free_event(track, eid);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
911 track->n_events--;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
912 free(str);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
913 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
914
31227
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
915 /**
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
916 * \brief Flush buffered events.
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
917 * \param track track
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
918 */
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
919 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
920 {
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
921 if (track->events) {
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
922 int eid;
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
923 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
924 ass_free_event(track, eid);
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
925 track->n_events = 0;
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
926 }
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
927 }
ee7beb1a3a6e backport ass_flush_events() from upstream libass and make use of it
aurel
parents: 30200
diff changeset
928
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
929 #ifdef CONFIG_ICONV
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
930 /** \brief recode buffer to utf-8
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents: 20008
diff changeset
931 * constraint: codepage != 0
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
932 * \param data pointer to text buffer
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
933 * \param size buffer size
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
934 * \return a pointer to recoded buffer, caller is responsible for freeing it
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
935 **/
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
936 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
937 char *codepage)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
938 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
939 iconv_t icdsc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
940 char *tocp = "UTF-8";
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
941 char *outbuf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
942 assert(codepage);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
943
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
944 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
945 const char *cp_tmp = codepage;
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
946 #ifdef CONFIG_ENCA
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
947 char enca_lang[3], enca_fallback[100];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
948 if (sscanf(codepage, "enca:%2s:%99s", enca_lang, enca_fallback) == 2
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
949 || sscanf(codepage, "ENCA:%2s:%99s", enca_lang,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
950 enca_fallback) == 2) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
951 cp_tmp =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
952 ass_guess_buffer_cp(library, (unsigned char *) data, size,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
953 enca_lang, enca_fallback);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
954 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
955 #endif
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
956 if ((icdsc = iconv_open(tocp, cp_tmp)) != (iconv_t) (-1)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
957 ass_msg(library, MSGL_V, "Opened iconv descriptor");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
958 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
959 ass_msg(library, MSGL_ERR, "Error opening iconv descriptor");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
960 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
961
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
962 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
963 size_t osize = size;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
964 size_t ileft = size;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
965 size_t oleft = size - 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
966 char *ip;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
967 char *op;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
968 size_t rc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
969 int clear = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
970
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
971 outbuf = malloc(osize);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
972 ip = data;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
973 op = outbuf;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
974
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
975 while (1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
976 if (ileft)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
977 rc = iconv(icdsc, &ip, &ileft, &op, &oleft);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
978 else { // clear the conversion state and leave
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
979 clear = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
980 rc = iconv(icdsc, NULL, NULL, &op, &oleft);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
981 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
982 if (rc == (size_t) (-1)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
983 if (errno == E2BIG) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
984 size_t offset = op - outbuf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
985 outbuf = (char *) realloc(outbuf, osize + size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
986 op = outbuf + offset;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
987 osize += size;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
988 oleft += size;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
989 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
990 ass_msg(library, MSGL_WARN, "Error recoding file");
35701
c7866af24567 Updated libass to 7e45532
SubJunk
parents: 35262
diff changeset
991 free(outbuf);
35716
d0004e3bcbbc Formatting
SubJunk
parents: 35701
diff changeset
992 outbuf = NULL;
d0004e3bcbbc Formatting
SubJunk
parents: 35701
diff changeset
993 goto out;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
994 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
995 } else if (clear)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
996 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
997 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
998 outbuf[osize - oleft - 1] = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
999 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1000
35701
c7866af24567 Updated libass to 7e45532
SubJunk
parents: 35262
diff changeset
1001 out:
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1002 if (icdsc != (iconv_t) (-1)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1003 (void) iconv_close(icdsc);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1004 icdsc = (iconv_t) (-1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1005 ass_msg(library, MSGL_V, "Closed iconv descriptor");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1006 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1007
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1008 return outbuf;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1009 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1010 #endif // ICONV
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1011
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1012 /**
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1013 * \brief read file contents into newly allocated buffer
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1014 * \param fname file name
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1015 * \param bufsize out: file size
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1016 * \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
1017 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1018 static char *read_file(ASS_Library *library, char *fname, size_t *bufsize)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1019 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1020 int res;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1021 long sz;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1022 long bytes_read;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1023 char *buf;
19652
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1024
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1025 FILE *fp = fopen(fname, "rb");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1026 if (!fp) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1027 ass_msg(library, MSGL_WARN,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1028 "ass_read_file(%s): fopen failed", fname);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1029 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1030 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1031 res = fseek(fp, 0, SEEK_END);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1032 if (res == -1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1033 ass_msg(library, MSGL_WARN,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1034 "ass_read_file(%s): fseek failed", fname);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1035 fclose(fp);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1036 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1037 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1038
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1039 sz = ftell(fp);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1040 rewind(fp);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1041
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1042 ass_msg(library, MSGL_V, "File size: %ld", sz);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1043
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1044 buf = malloc(sz + 1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1045 assert(buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1046 bytes_read = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1047 do {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1048 res = fread(buf + bytes_read, 1, sz - bytes_read, fp);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1049 if (res <= 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1050 ass_msg(library, MSGL_INFO, "Read failed, %d: %s", errno,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1051 strerror(errno));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1052 fclose(fp);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1053 free(buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1054 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1055 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1056 bytes_read += res;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1057 } while (sz - bytes_read > 0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1058 buf[sz] = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1059 fclose(fp);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1060
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1061 if (bufsize)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1062 *bufsize = sz;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1063 return buf;
19652
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1064 }
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1065
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1066 /*
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1067 * \param buf pointer to subtitle text in utf-8
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1068 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1069 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
1070 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1071 ASS_Track *track;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1072 int i;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1073
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1074 track = ass_new_track(library);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1075
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1076 // process header
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1077 process_text(track, buf);
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
1078
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1079 // external SSA/ASS subs does not have ReadOrder field
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1080 for (i = 0; i < track->n_events; ++i)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1081 track->events[i].ReadOrder = i;
19905
5a24682d9dd5 Set ReadOrder values for external subtitles.
eugeni
parents: 19652
diff changeset
1082
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1083 // there is no explicit end-of-font marker in ssa/ass
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1084 if (track->parser_priv->fontname)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1085 decode_font(track);
19492
c8daf3471201 SSA/ASS parser reworked, with 2 main results:
eugeni
parents: 19474
diff changeset
1086
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1087 if (track->track_type == TRACK_TYPE_UNKNOWN) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1088 ass_free_track(track);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1089 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1090 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1091
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1092 ass_process_force_style(track);
19495
31ac2e1a5695 New cmdline option: -ass-force-style.
eugeni
parents: 19492
diff changeset
1093
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1094 return track;
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1095 }
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1096
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1097 /**
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1098 * \brief Read subtitles from memory.
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1099 * \param library libass library object
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1100 * \param buf pointer to subtitles text
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1101 * \param bufsize size of buffer
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1102 * \param codepage recode buffer contents from given codepage
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1103 * \return newly allocated track
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1104 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1105 ASS_Track *ass_read_memory(ASS_Library *library, char *buf,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1106 size_t bufsize, char *codepage)
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1107 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1108 ASS_Track *track;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1109 int need_free = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1110
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1111 if (!buf)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1112 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1113
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
1114 #ifdef CONFIG_ICONV
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1115 if (codepage) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1116 buf = sub_recode(library, buf, bufsize, codepage);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1117 if (!buf)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1118 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1119 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1120 need_free = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1121 }
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1122 #endif
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1123 track = parse_memory(library, buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1124 if (need_free)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1125 free(buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1126 if (!track)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1127 return 0;
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_msg(library, MSGL_INFO, "Added subtitle file: "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1130 "<memory> (%d styles, %d events)",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1131 track->n_styles, track->n_events);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1132 return track;
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1133 }
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1134
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1135 static char *read_file_recode(ASS_Library *library, char *fname,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1136 char *codepage, size_t *size)
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1137 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1138 char *buf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1139 size_t bufsize;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1140
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1141 buf = read_file(library, fname, &bufsize);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1142 if (!buf)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1143 return 0;
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
1144 #ifdef CONFIG_ICONV
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1145 if (codepage) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1146 char *tmpbuf = sub_recode(library, buf, bufsize, codepage);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1147 free(buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1148 buf = tmpbuf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1149 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1150 if (!buf)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1151 return 0;
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1152 #endif
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1153 *size = bufsize;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1154 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
1155 }
7286d245bf33 Move code for reading a file and recoding it to utf-8 to a separate function.
eugeni
parents: 23300
diff changeset
1156
7286d245bf33 Move code for reading a file and recoding it to utf-8 to a separate function.
eugeni
parents: 23300
diff changeset
1157 /**
7286d245bf33 Move code for reading a file and recoding it to utf-8 to a separate function.
eugeni
parents: 23300
diff changeset
1158 * \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
1159 * \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
1160 * \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
1161 * \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
1162 * \return newly allocated track
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1163 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1164 ASS_Track *ass_read_file(ASS_Library *library, char *fname,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1165 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
1166 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1167 char *buf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1168 ASS_Track *track;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1169 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
1170
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1171 buf = read_file_recode(library, fname, codepage, &bufsize);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1172 if (!buf)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1173 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1174 track = parse_memory(library, buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1175 free(buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1176 if (!track)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1177 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1178
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1179 track->name = strdup(fname);
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1180
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1181 ass_msg(library, MSGL_INFO,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1182 "Added subtitle file: '%s' (%d styles, %d events)",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1183 fname, track->n_styles, track->n_events);
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 return track;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1186 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1187
19652
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1188 /**
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1189 * \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
1190 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1191 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
1192 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1193 char *buf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1194 ParserState old_state;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1195 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
1196
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1197 buf = read_file(track->library, fname, &sz);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1198 if (!buf)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1199 return 1;
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27359
diff changeset
1200 #ifdef CONFIG_ICONV
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1201 if (codepage) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1202 char *tmpbuf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1203 tmpbuf = sub_recode(track->library, buf, sz, codepage);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1204 free(buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1205 buf = tmpbuf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1206 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1207 if (!buf)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1208 return 0;
20603
b0814eba65ec Implement loading subtitles from memory.
eugeni
parents: 20602
diff changeset
1209 #endif
19652
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1210
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1211 old_state = track->parser_priv->state;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1212 track->parser_priv->state = PST_STYLES;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1213 process_text(track, buf);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1214 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
1215
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1216 return 0;
19652
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1217 }
2c016957360a Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents: 19639
diff changeset
1218
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1219 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
1220 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1221 int i;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1222
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1223 if (movement == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1224 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1225 if (track->n_events == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1226 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1227
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1228 if (movement < 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1229 for (i = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1230 (i < track->n_events)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1231 &&
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1232 ((long long) (track->events[i].Start +
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1233 track->events[i].Duration) <= now); ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1234 } else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1235 for (i = track->n_events - 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1236 (i >= 0) && ((long long) (track->events[i].Start) > now);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1237 --i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1238 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28900
diff changeset
1239
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1240 // -1 and n_events are ok
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1241 assert(i >= -1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1242 assert(i <= track->n_events);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1243 i += movement;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1244 if (i < 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1245 i = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1246 if (i >= track->n_events)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1247 i = track->n_events - 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1248 return ((long long) track->events[i].Start) - now;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1249 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1250
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1251 ASS_Track *ass_new_track(ASS_Library *library)
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 ASS_Track *track = calloc(1, sizeof(ASS_Track));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1254 track->library = library;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1255 track->ScaledBorderAndShadow = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1256 track->parser_priv = calloc(1, sizeof(ASS_ParserPriv));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 30066
diff changeset
1257 return track;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1258 }
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1259
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1260 /**
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1261 * \brief Prepare track for rendering
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1262 */
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1263 void ass_lazy_track_init(ASS_Library *lib, ASS_Track *track)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1264 {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1265 if (track->PlayResX && track->PlayResY)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1266 return;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1267 if (!track->PlayResX && !track->PlayResY) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1268 ass_msg(lib, MSGL_WARN,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1269 "Neither PlayResX nor PlayResY defined. Assuming 384x288");
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1270 track->PlayResX = 384;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1271 track->PlayResY = 288;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1272 } else {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1273 if (!track->PlayResY && track->PlayResX == 1280) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1274 track->PlayResY = 1024;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1275 ass_msg(lib, MSGL_WARN,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1276 "PlayResY undefined, setting to %d", track->PlayResY);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1277 } else if (!track->PlayResY) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1278 track->PlayResY = track->PlayResX * 3 / 4;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1279 ass_msg(lib, MSGL_WARN,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1280 "PlayResY undefined, setting to %d", track->PlayResY);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1281 } else if (!track->PlayResX && track->PlayResY == 1024) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1282 track->PlayResX = 1280;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1283 ass_msg(lib, MSGL_WARN,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1284 "PlayResX undefined, setting to %d", track->PlayResX);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1285 } else if (!track->PlayResX) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1286 track->PlayResX = track->PlayResY * 4 / 3;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1287 ass_msg(lib, MSGL_WARN,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1288 "PlayResX undefined, setting to %d", track->PlayResX);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1289 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1290 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
1291 }