Mercurial > mplayer.hg
annotate libass/ass_library.c @ 27651:f445847b8ec1
fix FAQ about compiling 32 bit mplayer on x86_64
Suggested by Wolfgang Knauf
author | gpoirier |
---|---|
date | Thu, 02 Oct 2008 22:15:45 +0000 |
parents | 588ce97b44f2 |
children | 0f1b5b68af32 |
rev | line source |
---|---|
20477 | 1 // -*- c-basic-offset: 8; indent-tabs-mode: t -*- |
2 // vim:ts=8:sw=8:noet:ai: | |
3 /* | |
26723 | 4 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com> |
5 * | |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26724
diff
changeset
|
6 * This file is part of libass. |
26723 | 7 * |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26724
diff
changeset
|
8 * libass is free software; you can redistribute it and/or modify |
26723 | 9 * it under the terms of the GNU General Public License as published by |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26724
diff
changeset
|
13 * libass is distributed in the hope that it will be useful, |
26723 | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * 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:
26724
diff
changeset
|
19 * with libass; if not, write to the Free Software Foundation, Inc., |
26724
980ec8f69c58
Fix one more license header wording detail for consistency.
diego
parents:
26723
diff
changeset
|
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
26723 | 21 */ |
20477 | 22 |
23 #include <inttypes.h> | |
24 #include <stdio.h> | |
25 #include <stdlib.h> | |
26 #include <string.h> | |
27 | |
28 #include "ass.h" | |
29 #include "ass_library.h" | |
30 | |
31 | |
32 ass_library_t* ass_library_init(void) | |
33 { | |
34 return calloc(1, sizeof(ass_library_t)); | |
35 } | |
36 | |
37 void ass_library_done(ass_library_t* priv) | |
38 { | |
21497
4a4af5271542
Also free ass_library_t members in ass_library_done
reimar
parents:
21458
diff
changeset
|
39 if (priv) { |
4a4af5271542
Also free ass_library_t members in ass_library_done
reimar
parents:
21458
diff
changeset
|
40 ass_set_fonts_dir(priv, NULL); |
4a4af5271542
Also free ass_library_t members in ass_library_done
reimar
parents:
21458
diff
changeset
|
41 ass_set_style_overrides(priv, NULL); |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
42 ass_clear_fonts(priv); |
21497
4a4af5271542
Also free ass_library_t members in ass_library_done
reimar
parents:
21458
diff
changeset
|
43 free(priv); |
4a4af5271542
Also free ass_library_t members in ass_library_done
reimar
parents:
21458
diff
changeset
|
44 } |
20477 | 45 } |
46 | |
47 void ass_set_fonts_dir(ass_library_t* priv, const char* fonts_dir) | |
48 { | |
49 if (priv->fonts_dir) | |
50 free(priv->fonts_dir); | |
51 | |
52 priv->fonts_dir = fonts_dir ? strdup(fonts_dir) : 0; | |
53 } | |
54 | |
55 void ass_set_extract_fonts(ass_library_t* priv, int extract) | |
56 { | |
57 priv->extract_fonts = !!extract; | |
58 } | |
59 | |
60 void ass_set_style_overrides(ass_library_t* priv, char** list) | |
61 { | |
62 char** p; | |
63 char** q; | |
64 int cnt; | |
65 | |
66 if (priv->style_overrides) { | |
67 for (p = priv->style_overrides; *p; ++p) | |
68 free(*p); | |
69 free(priv->style_overrides); | |
70 } | |
71 | |
72 if (!list) return; | |
73 | |
74 for (p = list, cnt = 0; *p; ++p, ++cnt) {} | |
75 | |
20722
2edba6772316
Bugfix: when copying ass_force_style_list, ending 0 was left out.
eugeni
parents:
20477
diff
changeset
|
76 priv->style_overrides = malloc((cnt + 1) * sizeof(char*)); |
20477 | 77 for (p = list, q = priv->style_overrides; *p; ++p, ++q) |
78 *q = strdup(*p); | |
20722
2edba6772316
Bugfix: when copying ass_force_style_list, ending 0 was left out.
eugeni
parents:
20477
diff
changeset
|
79 priv->style_overrides[cnt] = NULL; |
20477 | 80 } |
21458
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
81 |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
82 static void grow_array(void **array, int nelem, size_t elsize) |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
83 { |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
84 if (!(nelem & 31)) |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
85 *array = realloc(*array, (nelem + 32) * elsize); |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
86 } |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
87 |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
88 void ass_add_font(ass_library_t* priv, char* name, char* data, int size) |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
89 { |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
90 int idx = priv->num_fontdata; |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
91 if (!name || !data || !size) |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
92 return; |
21458
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
93 grow_array((void**)&priv->fontdata, priv->num_fontdata, sizeof(*priv->fontdata)); |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
94 |
25616 | 95 priv->fontdata[idx].name = strdup(name); |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
96 |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
97 priv->fontdata[idx].data = malloc(size); |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
98 memcpy(priv->fontdata[idx].data, data, size); |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
99 |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
100 priv->fontdata[idx].size = size; |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
101 |
21458
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
102 priv->num_fontdata ++; |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
103 } |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
104 |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
105 void ass_clear_fonts(ass_library_t* priv) |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
106 { |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
107 int i; |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
108 for (i = 0; i < priv->num_fontdata; ++i) { |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
109 free(priv->fontdata[i].name); |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
110 free(priv->fontdata[i].data); |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
111 } |
25621 | 112 free(priv->fontdata); |
113 priv->fontdata = NULL; | |
114 priv->num_fontdata = 0; | |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
115 } |