Mercurial > mplayer.hg
annotate libass/ass_library.c @ 34040:02ffd25c7733
configure: drop extra standard compiler/linker flags for *BSD systems
Adding the standard library locations to the search path is doubtful
behavior and unnecessary at least on FreeBSD.
author | diego |
---|---|
date | Fri, 23 Sep 2011 16:08:15 +0000 |
parents | 88eebbbbd6a0 |
children | 6e7f60f6f9d4 |
rev | line source |
---|---|
20477 | 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:
26724
diff
changeset
|
4 * This file is part of libass. |
26723 | 5 * |
34011 | 6 * Permission to use, copy, modify, and distribute this software for any |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
26723 | 9 * |
34011 | 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
26723 | 17 */ |
20477 | 18 |
31875 | 19 #include "config.h" |
20 | |
20477 | 21 #include <inttypes.h> |
22 #include <stdio.h> | |
23 #include <stdlib.h> | |
24 #include <string.h> | |
30200 | 25 #include <stdarg.h> |
20477 | 26 |
27 #include "ass.h" | |
28 #include "ass_library.h" | |
30200 | 29 #include "ass_utils.h" |
20477 | 30 |
30200 | 31 static void ass_msg_handler(int level, const char *fmt, va_list va, void *data) |
20477 | 32 { |
30200 | 33 if (level > MSGL_INFO) |
34 return; | |
35 fprintf(stderr, "[ass] "); | |
36 vfprintf(stderr, fmt, va); | |
37 fprintf(stderr, "\n"); | |
20477 | 38 } |
39 | |
30200 | 40 ASS_Library *ass_library_init(void) |
20477 | 41 { |
30200 | 42 ASS_Library* lib = calloc(1, sizeof(*lib)); |
43 lib->msg_callback = ass_msg_handler; | |
44 | |
45 return lib; | |
20477 | 46 } |
47 | |
30200 | 48 void ass_library_done(ASS_Library *priv) |
20477 | 49 { |
30200 | 50 if (priv) { |
51 ass_set_fonts_dir(priv, NULL); | |
52 ass_set_style_overrides(priv, NULL); | |
53 ass_clear_fonts(priv); | |
54 free(priv); | |
55 } | |
20477 | 56 } |
57 | |
30200 | 58 void ass_set_fonts_dir(ASS_Library *priv, const char *fonts_dir) |
20477 | 59 { |
31875 | 60 free(priv->fonts_dir); |
30200 | 61 |
62 priv->fonts_dir = fonts_dir ? strdup(fonts_dir) : 0; | |
63 } | |
64 | |
65 void ass_set_extract_fonts(ASS_Library *priv, int extract) | |
66 { | |
67 priv->extract_fonts = !!extract; | |
20477 | 68 } |
69 | |
30200 | 70 void ass_set_style_overrides(ASS_Library *priv, char **list) |
20477 | 71 { |
30200 | 72 char **p; |
73 char **q; | |
74 int cnt; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26738
diff
changeset
|
75 |
30200 | 76 if (priv->style_overrides) { |
77 for (p = priv->style_overrides; *p; ++p) | |
78 free(*p); | |
79 } | |
31875 | 80 free(priv->style_overrides); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26738
diff
changeset
|
81 |
30200 | 82 if (!list) |
83 return; | |
20477 | 84 |
30200 | 85 for (p = list, cnt = 0; *p; ++p, ++cnt) { |
86 } | |
87 | |
88 priv->style_overrides = malloc((cnt + 1) * sizeof(char *)); | |
89 for (p = list, q = priv->style_overrides; *p; ++p, ++q) | |
90 *q = strdup(*p); | |
91 priv->style_overrides[cnt] = NULL; | |
20477 | 92 } |
21458
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
93 |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
94 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
|
95 { |
30200 | 96 if (!(nelem & 31)) |
97 *array = realloc(*array, (nelem + 32) * elsize); | |
98 } | |
99 | |
100 void ass_add_font(ASS_Library *priv, char *name, char *data, int size) | |
101 { | |
102 int idx = priv->num_fontdata; | |
103 if (!name || !data || !size) | |
104 return; | |
105 grow_array((void **) &priv->fontdata, priv->num_fontdata, | |
106 sizeof(*priv->fontdata)); | |
107 | |
108 priv->fontdata[idx].name = strdup(name); | |
109 | |
110 priv->fontdata[idx].data = malloc(size); | |
111 memcpy(priv->fontdata[idx].data, data, size); | |
112 | |
113 priv->fontdata[idx].size = size; | |
114 | |
115 priv->num_fontdata++; | |
21458
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
116 } |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
117 |
30200 | 118 void ass_clear_fonts(ASS_Library *priv) |
21458
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
119 { |
30200 | 120 int i; |
121 for (i = 0; i < priv->num_fontdata; ++i) { | |
122 free(priv->fontdata[i].name); | |
123 free(priv->fontdata[i].data); | |
124 } | |
125 free(priv->fontdata); | |
126 priv->fontdata = NULL; | |
127 priv->num_fontdata = 0; | |
21458
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
128 } |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
129 |
30200 | 130 /* |
131 * Register a message callback function with libass. Without setting one, | |
132 * a default handler is used which prints everything with MSGL_INFO or | |
133 * higher to the standard output. | |
134 * | |
135 * \param msg_cb the callback function | |
136 * \param data additional data that will be passed to the callback | |
137 */ | |
138 void ass_set_message_cb(ASS_Library *priv, | |
139 void (*msg_cb)(int, const char *, va_list, void *), | |
140 void *data) | |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
141 { |
30200 | 142 if (msg_cb) { |
143 priv->msg_callback = msg_cb; | |
144 priv->msg_callback_data = data; | |
145 } | |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
146 } |