Mercurial > mplayer.hg
annotate libass/ass_utils.c @ 35549:463d8e512c38
Free guiInfo when GUI ends.
author | ib |
---|---|
date | Mon, 10 Dec 2012 01:45:44 +0000 |
parents | 49fc594fda43 |
children | c3aaaf17c721 |
rev | line source |
---|---|
20008
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
1 /* |
26723 | 2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com> |
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 | 5 * |
34011 | 6 * Permission to use, copy, modify, and distribute this software for any |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
26723 | 9 * |
34011 | 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
26723 | 17 */ |
20008
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
18 |
18937 | 19 #include "config.h" |
20 | |
21 #include <stdlib.h> | |
30200 | 22 #include <stdio.h> |
19405 | 23 #include <inttypes.h> |
26034 | 24 #include <ft2build.h> |
25 #include FT_GLYPH_H | |
31875 | 26 #include <strings.h> |
18937 | 27 |
30200 | 28 #include "ass_library.h" |
29 #include "ass.h" | |
18937 | 30 #include "ass_utils.h" |
31 | |
30200 | 32 int mystrtoi(char **p, int *res) |
18937 | 33 { |
30200 | 34 double temp_res; |
35 char *start = *p; | |
36 temp_res = ass_strtod(*p, p); | |
37 *res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5)); | |
38 if (*p != start) | |
39 return 1; | |
40 else | |
41 return 0; | |
28717
7bbe6626f0e0
Support fractional arguments for some override tags.
eugeni
parents:
26738
diff
changeset
|
42 } |
7bbe6626f0e0
Support fractional arguments for some override tags.
eugeni
parents:
26738
diff
changeset
|
43 |
30200 | 44 int mystrtoll(char **p, long long *res) |
28717
7bbe6626f0e0
Support fractional arguments for some override tags.
eugeni
parents:
26738
diff
changeset
|
45 { |
30200 | 46 double temp_res; |
47 char *start = *p; | |
48 temp_res = ass_strtod(*p, p); | |
49 *res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5)); | |
50 if (*p != start) | |
51 return 1; | |
52 else | |
53 return 0; | |
18937 | 54 } |
55 | |
30200 | 56 int mystrtou32(char **p, int base, uint32_t *res) |
18937 | 57 { |
30200 | 58 char *start = *p; |
59 *res = strtoll(*p, p, base); | |
60 if (*p != start) | |
61 return 1; | |
62 else | |
63 return 0; | |
18937 | 64 } |
65 | |
30200 | 66 int mystrtod(char **p, double *res) |
18937 | 67 { |
30200 | 68 char *start = *p; |
69 *res = ass_strtod(*p, p); | |
70 if (*p != start) | |
71 return 1; | |
72 else | |
73 return 0; | |
18937 | 74 } |
75 | |
30200 | 76 int strtocolor(ASS_Library *library, char **q, uint32_t *res, int hex) |
18937 | 77 { |
30200 | 78 uint32_t color = 0; |
79 int result; | |
80 char *p = *q; | |
81 int base = hex ? 16 : 10; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28785
diff
changeset
|
82 |
30200 | 83 if (*p == '&') |
84 ++p; | |
85 else | |
86 ass_msg(library, MSGL_DBG2, "suspicious color format: \"%s\"\n", p); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28785
diff
changeset
|
87 |
30200 | 88 if (*p == 'H' || *p == 'h') { |
89 ++p; | |
90 result = mystrtou32(&p, 16, &color); | |
91 } else { | |
92 result = mystrtou32(&p, base, &color); | |
93 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28785
diff
changeset
|
94 |
30200 | 95 { |
96 unsigned char *tmp = (unsigned char *) (&color); | |
97 unsigned char b; | |
98 b = tmp[0]; | |
99 tmp[0] = tmp[3]; | |
100 tmp[3] = b; | |
101 b = tmp[1]; | |
102 tmp[1] = tmp[2]; | |
103 tmp[2] = b; | |
104 } | |
105 if (*p == '&') | |
106 ++p; | |
107 *q = p; | |
18937 | 108 |
30200 | 109 *res = color; |
110 return result; | |
18937 | 111 } |
112 | |
28785 | 113 // Return a boolean value for a string |
30200 | 114 char parse_bool(char *str) |
115 { | |
116 while (*str == ' ' || *str == '\t') | |
117 str++; | |
118 if (!strncasecmp(str, "yes", 3)) | |
119 return 1; | |
120 else if (strtol(str, NULL, 10) > 0) | |
121 return 1; | |
122 return 0; | |
123 } | |
124 | |
125 void ass_msg(ASS_Library *priv, int lvl, char *fmt, ...) | |
126 { | |
127 va_list va; | |
128 va_start(va, fmt); | |
129 priv->msg_callback(lvl, fmt, va, priv->msg_callback_data); | |
130 va_end(va); | |
28785 | 131 } |
132 | |
30200 | 133 unsigned ass_utf8_get_char(char **str) |
26034 | 134 { |
30200 | 135 uint8_t *strp = (uint8_t *) * str; |
136 unsigned c = *strp++; | |
137 unsigned mask = 0x80; | |
138 int len = -1; | |
139 while (c & mask) { | |
140 mask >>= 1; | |
141 len++; | |
142 } | |
143 if (len <= 0 || len > 4) | |
144 goto no_utf8; | |
145 c &= mask - 1; | |
146 while ((*strp & 0xc0) == 0x80) { | |
147 if (len-- <= 0) | |
148 goto no_utf8; | |
149 c = (c << 6) | (*strp++ & 0x3f); | |
150 } | |
151 if (len) | |
152 goto no_utf8; | |
153 *str = (char *) strp; | |
154 return c; | |
155 | |
156 no_utf8: | |
157 strp = (uint8_t *) * str; | |
158 c = *strp++; | |
159 *str = (char *) strp; | |
160 return c; | |
26034 | 161 } |
162 | |
35262 | 163 /** |
164 * \brief find style by name | |
165 * \param track track | |
166 * \param name style name | |
167 * \return index in track->styles | |
168 * Returnes 0 if no styles found => expects at least 1 style. | |
169 * Parsing code always adds "Default" style in the end. | |
170 */ | |
171 int lookup_style(ASS_Track *track, char *name) | |
172 { | |
173 int i; | |
174 if (*name == '*') | |
175 ++name; // FIXME: what does '*' really mean ? | |
176 for (i = track->n_styles - 1; i >= 0; --i) { | |
177 if (strcmp(track->styles[i].Name, name) == 0) | |
178 return i; | |
179 } | |
180 i = track->default_style; | |
181 ass_msg(track->library, MSGL_WARN, | |
182 "[%p]: Warning: no style named '%s' found, using '%s'", | |
183 track, name, track->styles[i].Name); | |
184 return i; // use the first style | |
185 } | |
186 | |
30200 | 187 #ifdef CONFIG_ENCA |
188 void *ass_guess_buffer_cp(ASS_Library *library, unsigned char *buffer, | |
189 int buflen, char *preferred_language, | |
190 char *fallback) | |
26034 | 191 { |
30200 | 192 const char **languages; |
193 size_t langcnt; | |
194 EncaAnalyser analyser; | |
195 EncaEncoding encoding; | |
196 char *detected_sub_cp = NULL; | |
197 int i; | |
198 | |
199 languages = enca_get_languages(&langcnt); | |
200 ass_msg(library, MSGL_V, "ENCA supported languages"); | |
201 for (i = 0; i < langcnt; i++) { | |
202 ass_msg(library, MSGL_V, "lang %s", languages[i]); | |
203 } | |
204 | |
205 for (i = 0; i < langcnt; i++) { | |
206 const char *tmp; | |
207 | |
208 if (strcasecmp(languages[i], preferred_language) != 0) | |
209 continue; | |
210 analyser = enca_analyser_alloc(languages[i]); | |
211 encoding = enca_analyse_const(analyser, buffer, buflen); | |
212 tmp = enca_charset_name(encoding.charset, ENCA_NAME_STYLE_ICONV); | |
213 if (tmp && encoding.charset != ENCA_CS_UNKNOWN) { | |
214 detected_sub_cp = strdup(tmp); | |
215 ass_msg(library, MSGL_INFO, "ENCA detected charset: %s", tmp); | |
216 } | |
217 enca_analyser_free(analyser); | |
218 } | |
219 | |
220 free(languages); | |
221 | |
222 if (!detected_sub_cp) { | |
223 detected_sub_cp = strdup(fallback); | |
224 ass_msg(library, MSGL_INFO, | |
225 "ENCA detection failed: fallback to %s", fallback); | |
226 } | |
227 | |
228 return detected_sub_cp; | |
26034 | 229 } |
26036
8d8c52a169ad
Comment out dump_glyph(): it is unused and, as it is now, breaks compilation.
eugeni
parents:
26034
diff
changeset
|
230 #endif |