annotate libass/ass_utils.c @ 35044:99ac85950277

Support decoding teletext in the format that WTV uses.
author reimar
date Sat, 01 Sep 2012 14:53:05 +0000
parents 88eebbbbd6a0
children 49fc594fda43
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: 19405
diff changeset
1 /*
26723
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
0f892cd714b2 Use standard license header.
diego
parents: 26036
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: 26036
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: 26036
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: 26036
diff changeset
17 */
20008
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19405
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 <stdlib.h>
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
22 #include <stdio.h>
19405
0797e1b4a4be Replace stdint.h with inttypes.h.
eugeni
parents: 19003
diff changeset
23 #include <inttypes.h>
26034
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
24 #include <ft2build.h>
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
25 #include FT_GLYPH_H
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 30200
diff changeset
26 #include <strings.h>
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
27
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
28 #include "ass_library.h"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
29 #include "ass.h"
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
30 #include "ass_utils.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
31
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
32 int mystrtoi(char **p, int *res)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
33 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
34 double temp_res;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
35 char *start = *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
36 temp_res = ass_strtod(*p, p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
37 *res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
38 if (*p != start)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
39 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
40 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
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
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
44 int mystrtoll(char **p, long long *res)
28717
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
45 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
46 double temp_res;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
47 char *start = *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
48 temp_res = ass_strtod(*p, p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
49 *res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
50 if (*p != start)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
51 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
52 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
53 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
54 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
55
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
56 int mystrtou32(char **p, int base, uint32_t *res)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
57 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
58 char *start = *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
59 *res = strtoll(*p, p, base);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
60 if (*p != start)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
61 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
62 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
63 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
64 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
65
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
66 int mystrtod(char **p, double *res)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
67 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
68 char *start = *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
69 *res = ass_strtod(*p, p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
70 if (*p != start)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
71 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
72 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
73 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
74 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
75
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
76 int strtocolor(ASS_Library *library, char **q, uint32_t *res, int hex)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
77 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
78 uint32_t color = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
79 int result;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
80 char *p = *q;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
81 int base = hex ? 16 : 10;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28785
diff changeset
82
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
83 if (*p == '&')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
84 ++p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
85 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
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
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
88 if (*p == 'H' || *p == 'h') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
89 ++p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
90 result = mystrtou32(&p, 16, &color);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
91 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
92 result = mystrtou32(&p, base, &color);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
93 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28785
diff changeset
94
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
95 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
96 unsigned char *tmp = (unsigned char *) (&color);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
97 unsigned char b;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
98 b = tmp[0];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
99 tmp[0] = tmp[3];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
100 tmp[3] = b;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
101 b = tmp[1];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
102 tmp[1] = tmp[2];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
103 tmp[2] = b;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
104 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
105 if (*p == '&')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
106 ++p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
107 *q = p;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
108
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
109 *res = color;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
110 return result;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
111 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
112
28785
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
113 // Return a boolean value for a string
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
114 char parse_bool(char *str)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
115 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
116 while (*str == ' ' || *str == '\t')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
117 str++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
118 if (!strncasecmp(str, "yes", 3))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
119 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
120 else if (strtol(str, NULL, 10) > 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
121 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
122 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
123 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
124
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
125 void ass_msg(ASS_Library *priv, int lvl, char *fmt, ...)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
126 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
127 va_list va;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
128 va_start(va, fmt);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
129 priv->msg_callback(lvl, fmt, va, priv->msg_callback_data);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
130 va_end(va);
28785
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
131 }
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
132
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
133 unsigned ass_utf8_get_char(char **str)
26034
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
134 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
135 uint8_t *strp = (uint8_t *) * str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
136 unsigned c = *strp++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
137 unsigned mask = 0x80;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
138 int len = -1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
139 while (c & mask) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
140 mask >>= 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
141 len++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
142 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
143 if (len <= 0 || len > 4)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
144 goto no_utf8;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
145 c &= mask - 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
146 while ((*strp & 0xc0) == 0x80) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
147 if (len-- <= 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
148 goto no_utf8;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
149 c = (c << 6) | (*strp++ & 0x3f);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
150 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
151 if (len)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
152 goto no_utf8;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
153 *str = (char *) strp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
154 return c;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
155
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
156 no_utf8:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
157 strp = (uint8_t *) * str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
158 c = *strp++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
159 *str = (char *) strp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
160 return c;
26034
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
161 }
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
162
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
163 #ifdef CONFIG_ENCA
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
164 void *ass_guess_buffer_cp(ASS_Library *library, unsigned char *buffer,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
165 int buflen, char *preferred_language,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
166 char *fallback)
26034
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
167 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
168 const char **languages;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
169 size_t langcnt;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
170 EncaAnalyser analyser;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
171 EncaEncoding encoding;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
172 char *detected_sub_cp = NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
173 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
174
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
175 languages = enca_get_languages(&langcnt);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
176 ass_msg(library, MSGL_V, "ENCA supported languages");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
177 for (i = 0; i < langcnt; i++) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
178 ass_msg(library, MSGL_V, "lang %s", languages[i]);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
179 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
180
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
181 for (i = 0; i < langcnt; i++) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
182 const char *tmp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
183
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
184 if (strcasecmp(languages[i], preferred_language) != 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
185 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
186 analyser = enca_analyser_alloc(languages[i]);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
187 encoding = enca_analyse_const(analyser, buffer, buflen);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
188 tmp = enca_charset_name(encoding.charset, ENCA_NAME_STYLE_ICONV);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
189 if (tmp && encoding.charset != ENCA_CS_UNKNOWN) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
190 detected_sub_cp = strdup(tmp);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
191 ass_msg(library, MSGL_INFO, "ENCA detected charset: %s", tmp);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
192 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
193 enca_analyser_free(analyser);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
194 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
195
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
196 free(languages);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
197
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
198 if (!detected_sub_cp) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
199 detected_sub_cp = strdup(fallback);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
200 ass_msg(library, MSGL_INFO,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
201 "ENCA detection failed: fallback to %s", fallback);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
202 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
203
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
204 return detected_sub_cp;
26034
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
205 }
26036
8d8c52a169ad Comment out dump_glyph(): it is unused and, as it is now, breaks compilation.
eugeni
parents: 26034
diff changeset
206 #endif