Mercurial > mplayer.hg
annotate libass/ass_utils.c @ 20502:81a92ae66d78
Move ass_library initialization code to ass_mp.c.
author | eugeni |
---|---|
date | Sun, 29 Oct 2006 15:26:13 +0000 |
parents | 30df9a64618a |
children | 5cbf1c33a668 |
rev | line source |
---|---|
20008
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
1 // -*- c-basic-offset: 8; indent-tabs-mode: t -*- |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
2 // vim:ts=8:sw=8:noet:ai: |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
3 /* |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
4 Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com> |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
5 |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
6 This program is free software; you can redistribute it and/or modify |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
7 it under the terms of the GNU General Public License as published by |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
8 the Free Software Foundation; either version 2 of the License, or |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
9 (at your option) any later version. |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
10 |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
11 This program is distributed in the hope that it will be useful, |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
14 GNU General Public License for more details. |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
15 |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
16 You should have received a copy of the GNU General Public License |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
17 along with this program; if not, write to the Free Software |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
19 */ |
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> | |
19405 | 24 #include <inttypes.h> |
20501
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
25 #include <string.h> |
18937 | 26 #include <sys/time.h> |
27 #include <time.h> | |
28 | |
20501
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
29 #ifdef HAVE_ENCA |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
30 #include <enca.h> |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
31 #endif |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
32 |
18937 | 33 #include "mp_msg.h" |
34 #include "ass_utils.h" | |
35 | |
36 int mystrtoi(char** p, int base, int* res) | |
37 { | |
38 char* start = *p; | |
39 *res = strtol(*p, p, base); | |
40 if (*p != start) return 1; | |
41 else return 0; | |
42 } | |
43 | |
44 int mystrtou32(char** p, int base, uint32_t* res) | |
45 { | |
46 char* start = *p; | |
47 *res = strtoll(*p, p, base); | |
48 if (*p != start) return 1; | |
49 else return 0; | |
50 } | |
51 | |
52 int mystrtod(char** p, double* res) | |
53 { | |
54 char* start = *p; | |
55 *res = strtod(*p, p); | |
56 if (*p != start) return 1; | |
57 else return 0; | |
58 } | |
59 | |
60 int strtocolor(char** q, uint32_t* res) | |
61 { | |
62 uint32_t color = 0; | |
63 int result; | |
64 char* p = *q; | |
65 | |
66 if (*p == '&') ++p; | |
19003 | 67 else mp_msg(MSGT_GLOBAL, MSGL_DBG2, "suspicious color format: \"%s\"\n", p); |
18937 | 68 |
19003 | 69 if (*p == 'H' || *p == 'h') { |
18937 | 70 ++p; |
71 result = mystrtou32(&p, 16, &color); | |
72 } else { | |
19003 | 73 result = mystrtou32(&p, 0, &color); |
18937 | 74 } |
75 | |
76 { | |
77 unsigned char* tmp = (unsigned char*)(&color); | |
78 unsigned char b; | |
79 b = tmp[0]; tmp[0] = tmp[3]; tmp[3] = b; | |
80 b = tmp[1]; tmp[1] = tmp[2]; tmp[2] = b; | |
81 } | |
82 if (*p == '&') ++p; | |
83 *q = p; | |
84 | |
85 *res = color; | |
86 return result; | |
87 } | |
88 | |
20501
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
89 unsigned ass_utf8_get_char(char **str) |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
90 { |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
91 uint8_t *strp = (uint8_t *)*str; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
92 unsigned c = *strp++; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
93 unsigned mask = 0x80; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
94 int len = -1; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
95 while (c & mask) { |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
96 mask >>= 1; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
97 len++; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
98 } |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
99 if (len <= 0 || len > 4) |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
100 goto no_utf8; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
101 c &= mask - 1; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
102 while ((*strp & 0xc0) == 0x80) { |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
103 if (len-- <= 0) |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
104 goto no_utf8; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
105 c = (c << 6) | (*strp++ & 0x3f); |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
106 } |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
107 if (len) |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
108 goto no_utf8; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
109 *str = (char *)strp; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
110 return c; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
111 |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
112 no_utf8: |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
113 strp = (uint8_t *)*str; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
114 c = *strp++; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
115 *str = (char *)strp; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
116 return c; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
117 } |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
118 |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
119 #ifdef HAVE_ENCA |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
120 void* ass_guess_buffer_cp(unsigned char* buffer, int buflen, char *preferred_language, char *fallback) |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
121 { |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
122 const char **languages; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
123 size_t langcnt; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
124 EncaAnalyser analyser; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
125 EncaEncoding encoding; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
126 char *detected_sub_cp = NULL; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
127 int i; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
128 |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
129 languages = enca_get_languages(&langcnt); |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
130 mp_msg(MSGT_SUBREADER, MSGL_V, "ENCA supported languages: "); |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
131 for (i = 0; i < langcnt; i++) { |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
132 mp_msg(MSGT_SUBREADER, MSGL_V, "%s ", languages[i]); |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
133 } |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
134 mp_msg(MSGT_SUBREADER, MSGL_V, "\n"); |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
135 |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
136 for (i = 0; i < langcnt; i++) { |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
137 const char *tmp; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
138 |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
139 if (strcasecmp(languages[i], preferred_language) != 0) continue; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
140 analyser = enca_analyser_alloc(languages[i]); |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
141 encoding = enca_analyse_const(analyser, buffer, buflen); |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
142 tmp = enca_charset_name(encoding.charset, ENCA_NAME_STYLE_ICONV); |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
143 if (tmp && encoding.charset != ENCA_CS_UNKNOWN) { |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
144 detected_sub_cp = strdup(tmp); |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
145 mp_msg(MSGT_SUBREADER, MSGL_INFO, "ENCA detected charset: %s\n", tmp); |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
146 } |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
147 enca_analyser_free(analyser); |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
148 } |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
149 |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
150 free(languages); |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
151 |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
152 if (!detected_sub_cp) { |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
153 detected_sub_cp = strdup(fallback); |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
154 mp_msg(MSGT_SUBREADER, MSGL_INFO, "ENCA detection failed: fallback to %s\n", fallback); |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
155 } |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
156 |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
157 return detected_sub_cp; |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
158 } |
30df9a64618a
Copy the following functions to libass to avoid dependency on the rest of mplayer:
eugeni
parents:
20008
diff
changeset
|
159 #endif |