Mercurial > mplayer.hg
annotate libass/ass_utils.c @ 31284:c02ae498fb2e
remove libmpcodecs/vf_rgb2bgr.c
Its functionality has been superseeded by sws by quite some time, and
the "swap" functionality is now provided by vf_format.
see http://comments.gmane.org/gmane.comp.video.mplayer.devel/55804 for
a full discussion.
author | siretart |
---|---|
date | Wed, 09 Jun 2010 07:26:54 +0000 |
parents | 48d020c5ceca |
children | ac6e48baa03d |
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 | |
18937 | 28 |
30200 | 29 #include "ass_library.h" |
30 #include "ass.h" | |
18937 | 31 #include "ass_utils.h" |
32 | |
30200 | 33 int mystrtoi(char **p, int *res) |
18937 | 34 { |
30200 | 35 double temp_res; |
36 char *start = *p; | |
37 temp_res = ass_strtod(*p, p); | |
38 *res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5)); | |
39 if (*p != start) | |
40 return 1; | |
41 else | |
42 return 0; | |
28717
7bbe6626f0e0
Support fractional arguments for some override tags.
eugeni
parents:
26738
diff
changeset
|
43 } |
7bbe6626f0e0
Support fractional arguments for some override tags.
eugeni
parents:
26738
diff
changeset
|
44 |
30200 | 45 int mystrtoll(char **p, long long *res) |
28717
7bbe6626f0e0
Support fractional arguments for some override tags.
eugeni
parents:
26738
diff
changeset
|
46 { |
30200 | 47 double temp_res; |
48 char *start = *p; | |
49 temp_res = ass_strtod(*p, p); | |
50 *res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5)); | |
51 if (*p != start) | |
52 return 1; | |
53 else | |
54 return 0; | |
18937 | 55 } |
56 | |
30200 | 57 int mystrtou32(char **p, int base, uint32_t *res) |
18937 | 58 { |
30200 | 59 char *start = *p; |
60 *res = strtoll(*p, p, base); | |
61 if (*p != start) | |
62 return 1; | |
63 else | |
64 return 0; | |
18937 | 65 } |
66 | |
30200 | 67 int mystrtod(char **p, double *res) |
18937 | 68 { |
30200 | 69 char *start = *p; |
70 *res = ass_strtod(*p, p); | |
71 if (*p != start) | |
72 return 1; | |
73 else | |
74 return 0; | |
18937 | 75 } |
76 | |
30200 | 77 int strtocolor(ASS_Library *library, char **q, uint32_t *res, int hex) |
18937 | 78 { |
30200 | 79 uint32_t color = 0; |
80 int result; | |
81 char *p = *q; | |
82 int base = hex ? 16 : 10; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28785
diff
changeset
|
83 |
30200 | 84 if (*p == '&') |
85 ++p; | |
86 else | |
87 ass_msg(library, MSGL_DBG2, "suspicious color format: \"%s\"\n", p); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28785
diff
changeset
|
88 |
30200 | 89 if (*p == 'H' || *p == 'h') { |
90 ++p; | |
91 result = mystrtou32(&p, 16, &color); | |
92 } else { | |
93 result = mystrtou32(&p, base, &color); | |
94 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28785
diff
changeset
|
95 |
30200 | 96 { |
97 unsigned char *tmp = (unsigned char *) (&color); | |
98 unsigned char b; | |
99 b = tmp[0]; | |
100 tmp[0] = tmp[3]; | |
101 tmp[3] = b; | |
102 b = tmp[1]; | |
103 tmp[1] = tmp[2]; | |
104 tmp[2] = b; | |
105 } | |
106 if (*p == '&') | |
107 ++p; | |
108 *q = p; | |
18937 | 109 |
30200 | 110 *res = color; |
111 return result; | |
18937 | 112 } |
113 | |
28785 | 114 // Return a boolean value for a string |
30200 | 115 char parse_bool(char *str) |
116 { | |
117 while (*str == ' ' || *str == '\t') | |
118 str++; | |
119 if (!strncasecmp(str, "yes", 3)) | |
120 return 1; | |
121 else if (strtol(str, NULL, 10) > 0) | |
122 return 1; | |
123 return 0; | |
124 } | |
125 | |
126 void ass_msg(ASS_Library *priv, int lvl, char *fmt, ...) | |
127 { | |
128 va_list va; | |
129 va_start(va, fmt); | |
130 priv->msg_callback(lvl, fmt, va, priv->msg_callback_data); | |
131 va_end(va); | |
28785 | 132 } |
133 | |
30200 | 134 unsigned ass_utf8_get_char(char **str) |
26034 | 135 { |
30200 | 136 uint8_t *strp = (uint8_t *) * str; |
137 unsigned c = *strp++; | |
138 unsigned mask = 0x80; | |
139 int len = -1; | |
140 while (c & mask) { | |
141 mask >>= 1; | |
142 len++; | |
143 } | |
144 if (len <= 0 || len > 4) | |
145 goto no_utf8; | |
146 c &= mask - 1; | |
147 while ((*strp & 0xc0) == 0x80) { | |
148 if (len-- <= 0) | |
149 goto no_utf8; | |
150 c = (c << 6) | (*strp++ & 0x3f); | |
151 } | |
152 if (len) | |
153 goto no_utf8; | |
154 *str = (char *) strp; | |
155 return c; | |
156 | |
157 no_utf8: | |
158 strp = (uint8_t *) * str; | |
159 c = *strp++; | |
160 *str = (char *) strp; | |
161 return c; | |
26034 | 162 } |
163 | |
30200 | 164 #ifdef CONFIG_ENCA |
165 void *ass_guess_buffer_cp(ASS_Library *library, unsigned char *buffer, | |
166 int buflen, char *preferred_language, | |
167 char *fallback) | |
26034 | 168 { |
30200 | 169 const char **languages; |
170 size_t langcnt; | |
171 EncaAnalyser analyser; | |
172 EncaEncoding encoding; | |
173 char *detected_sub_cp = NULL; | |
174 int i; | |
175 | |
176 languages = enca_get_languages(&langcnt); | |
177 ass_msg(library, MSGL_V, "ENCA supported languages"); | |
178 for (i = 0; i < langcnt; i++) { | |
179 ass_msg(library, MSGL_V, "lang %s", languages[i]); | |
180 } | |
181 | |
182 for (i = 0; i < langcnt; i++) { | |
183 const char *tmp; | |
184 | |
185 if (strcasecmp(languages[i], preferred_language) != 0) | |
186 continue; | |
187 analyser = enca_analyser_alloc(languages[i]); | |
188 encoding = enca_analyse_const(analyser, buffer, buflen); | |
189 tmp = enca_charset_name(encoding.charset, ENCA_NAME_STYLE_ICONV); | |
190 if (tmp && encoding.charset != ENCA_CS_UNKNOWN) { | |
191 detected_sub_cp = strdup(tmp); | |
192 ass_msg(library, MSGL_INFO, "ENCA detected charset: %s", tmp); | |
193 } | |
194 enca_analyser_free(analyser); | |
195 } | |
196 | |
197 free(languages); | |
198 | |
199 if (!detected_sub_cp) { | |
200 detected_sub_cp = strdup(fallback); | |
201 ass_msg(library, MSGL_INFO, | |
202 "ENCA detection failed: fallback to %s", fallback); | |
203 } | |
204 | |
205 return detected_sub_cp; | |
26034 | 206 } |
26036
8d8c52a169ad
Comment out dump_glyph(): it is unused and, as it is now, breaks compilation.
eugeni
parents:
26034
diff
changeset
|
207 #endif |