Mercurial > mplayer.hg
annotate libass/ass_utils.c @ 31882:ef30e1505969
Do not call *_aid_from_lang when audio_lang is NULL.
author | reimar |
---|---|
date | Mon, 16 Aug 2010 10:33:33 +0000 |
parents | ac6e48baa03d |
children | 88eebbbbd6a0 |
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 * |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26723
diff
changeset
|
6 * libass is free software; you can redistribute it and/or modify |
26723 | 7 * it under the terms of the GNU General Public License as published by |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26723
diff
changeset
|
11 * libass is distributed in the hope that it will be useful, |
26723 | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License along | |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26723
diff
changeset
|
17 * with libass; if not, write to the Free Software Foundation, Inc., |
26723 | 18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 */ | |
20008
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
20 |
18937 | 21 #include "config.h" |
22 | |
23 #include <stdlib.h> | |
30200 | 24 #include <stdio.h> |
19405 | 25 #include <inttypes.h> |
26034 | 26 #include <ft2build.h> |
27 #include FT_GLYPH_H | |
31875 | 28 #include <strings.h> |
18937 | 29 |
30200 | 30 #include "ass_library.h" |
31 #include "ass.h" | |
18937 | 32 #include "ass_utils.h" |
33 | |
30200 | 34 int mystrtoi(char **p, int *res) |
18937 | 35 { |
30200 | 36 double temp_res; |
37 char *start = *p; | |
38 temp_res = ass_strtod(*p, p); | |
39 *res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5)); | |
40 if (*p != start) | |
41 return 1; | |
42 else | |
43 return 0; | |
28717
7bbe6626f0e0
Support fractional arguments for some override tags.
eugeni
parents:
26738
diff
changeset
|
44 } |
7bbe6626f0e0
Support fractional arguments for some override tags.
eugeni
parents:
26738
diff
changeset
|
45 |
30200 | 46 int mystrtoll(char **p, long long *res) |
28717
7bbe6626f0e0
Support fractional arguments for some override tags.
eugeni
parents:
26738
diff
changeset
|
47 { |
30200 | 48 double temp_res; |
49 char *start = *p; | |
50 temp_res = ass_strtod(*p, p); | |
51 *res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5)); | |
52 if (*p != start) | |
53 return 1; | |
54 else | |
55 return 0; | |
18937 | 56 } |
57 | |
30200 | 58 int mystrtou32(char **p, int base, uint32_t *res) |
18937 | 59 { |
30200 | 60 char *start = *p; |
61 *res = strtoll(*p, p, base); | |
62 if (*p != start) | |
63 return 1; | |
64 else | |
65 return 0; | |
18937 | 66 } |
67 | |
30200 | 68 int mystrtod(char **p, double *res) |
18937 | 69 { |
30200 | 70 char *start = *p; |
71 *res = ass_strtod(*p, p); | |
72 if (*p != start) | |
73 return 1; | |
74 else | |
75 return 0; | |
18937 | 76 } |
77 | |
30200 | 78 int strtocolor(ASS_Library *library, char **q, uint32_t *res, int hex) |
18937 | 79 { |
30200 | 80 uint32_t color = 0; |
81 int result; | |
82 char *p = *q; | |
83 int base = hex ? 16 : 10; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28785
diff
changeset
|
84 |
30200 | 85 if (*p == '&') |
86 ++p; | |
87 else | |
88 ass_msg(library, MSGL_DBG2, "suspicious color format: \"%s\"\n", p); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28785
diff
changeset
|
89 |
30200 | 90 if (*p == 'H' || *p == 'h') { |
91 ++p; | |
92 result = mystrtou32(&p, 16, &color); | |
93 } else { | |
94 result = mystrtou32(&p, base, &color); | |
95 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28785
diff
changeset
|
96 |
30200 | 97 { |
98 unsigned char *tmp = (unsigned char *) (&color); | |
99 unsigned char b; | |
100 b = tmp[0]; | |
101 tmp[0] = tmp[3]; | |
102 tmp[3] = b; | |
103 b = tmp[1]; | |
104 tmp[1] = tmp[2]; | |
105 tmp[2] = b; | |
106 } | |
107 if (*p == '&') | |
108 ++p; | |
109 *q = p; | |
18937 | 110 |
30200 | 111 *res = color; |
112 return result; | |
18937 | 113 } |
114 | |
28785 | 115 // Return a boolean value for a string |
30200 | 116 char parse_bool(char *str) |
117 { | |
118 while (*str == ' ' || *str == '\t') | |
119 str++; | |
120 if (!strncasecmp(str, "yes", 3)) | |
121 return 1; | |
122 else if (strtol(str, NULL, 10) > 0) | |
123 return 1; | |
124 return 0; | |
125 } | |
126 | |
127 void ass_msg(ASS_Library *priv, int lvl, char *fmt, ...) | |
128 { | |
129 va_list va; | |
130 va_start(va, fmt); | |
131 priv->msg_callback(lvl, fmt, va, priv->msg_callback_data); | |
132 va_end(va); | |
28785 | 133 } |
134 | |
30200 | 135 unsigned ass_utf8_get_char(char **str) |
26034 | 136 { |
30200 | 137 uint8_t *strp = (uint8_t *) * str; |
138 unsigned c = *strp++; | |
139 unsigned mask = 0x80; | |
140 int len = -1; | |
141 while (c & mask) { | |
142 mask >>= 1; | |
143 len++; | |
144 } | |
145 if (len <= 0 || len > 4) | |
146 goto no_utf8; | |
147 c &= mask - 1; | |
148 while ((*strp & 0xc0) == 0x80) { | |
149 if (len-- <= 0) | |
150 goto no_utf8; | |
151 c = (c << 6) | (*strp++ & 0x3f); | |
152 } | |
153 if (len) | |
154 goto no_utf8; | |
155 *str = (char *) strp; | |
156 return c; | |
157 | |
158 no_utf8: | |
159 strp = (uint8_t *) * str; | |
160 c = *strp++; | |
161 *str = (char *) strp; | |
162 return c; | |
26034 | 163 } |
164 | |
30200 | 165 #ifdef CONFIG_ENCA |
166 void *ass_guess_buffer_cp(ASS_Library *library, unsigned char *buffer, | |
167 int buflen, char *preferred_language, | |
168 char *fallback) | |
26034 | 169 { |
30200 | 170 const char **languages; |
171 size_t langcnt; | |
172 EncaAnalyser analyser; | |
173 EncaEncoding encoding; | |
174 char *detected_sub_cp = NULL; | |
175 int i; | |
176 | |
177 languages = enca_get_languages(&langcnt); | |
178 ass_msg(library, MSGL_V, "ENCA supported languages"); | |
179 for (i = 0; i < langcnt; i++) { | |
180 ass_msg(library, MSGL_V, "lang %s", languages[i]); | |
181 } | |
182 | |
183 for (i = 0; i < langcnt; i++) { | |
184 const char *tmp; | |
185 | |
186 if (strcasecmp(languages[i], preferred_language) != 0) | |
187 continue; | |
188 analyser = enca_analyser_alloc(languages[i]); | |
189 encoding = enca_analyse_const(analyser, buffer, buflen); | |
190 tmp = enca_charset_name(encoding.charset, ENCA_NAME_STYLE_ICONV); | |
191 if (tmp && encoding.charset != ENCA_CS_UNKNOWN) { | |
192 detected_sub_cp = strdup(tmp); | |
193 ass_msg(library, MSGL_INFO, "ENCA detected charset: %s", tmp); | |
194 } | |
195 enca_analyser_free(analyser); | |
196 } | |
197 | |
198 free(languages); | |
199 | |
200 if (!detected_sub_cp) { | |
201 detected_sub_cp = strdup(fallback); | |
202 ass_msg(library, MSGL_INFO, | |
203 "ENCA detection failed: fallback to %s", fallback); | |
204 } | |
205 | |
206 return detected_sub_cp; | |
26034 | 207 } |
26036
8d8c52a169ad
Comment out dump_glyph(): it is unused and, as it is now, breaks compilation.
eugeni
parents:
26034
diff
changeset
|
208 #endif |