annotate libass/ass_library.c @ 29012:8273eda1388c

Fix some places where "non-alpha to YUVA420P" do not fill the alpha plane
author sdrik
date Tue, 24 Mar 2009 07:10:19 +0000
parents 588ce97b44f2
children 0f1b5b68af32
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
1 // -*- c-basic-offset: 8; indent-tabs-mode: t -*-
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
2 // vim:ts=8:sw=8:noet:ai:
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
3 /*
26723
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
4 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
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
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
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
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
9 * it under the terms of the GNU General Public License as published by
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
11 * (at your option) any later version.
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
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
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
16 * GNU General Public License for more details.
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
17 *
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
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
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
21 */
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
22
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
23 #include <inttypes.h>
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
24 #include <stdio.h>
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
25 #include <stdlib.h>
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
26 #include <string.h>
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
27
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
28 #include "ass.h"
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
29 #include "ass_library.h"
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
30
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
31
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
32 ass_library_t* ass_library_init(void)
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
33 {
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
34 return calloc(1, sizeof(ass_library_t));
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
35 }
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
36
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
37 void ass_library_done(ass_library_t* priv)
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
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
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
45 }
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
46
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
47 void ass_set_fonts_dir(ass_library_t* priv, const char* fonts_dir)
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
48 {
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
49 if (priv->fonts_dir)
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
50 free(priv->fonts_dir);
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
51
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
52 priv->fonts_dir = fonts_dir ? strdup(fonts_dir) : 0;
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
53 }
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
54
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
55 void ass_set_extract_fonts(ass_library_t* priv, int extract)
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
56 {
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
57 priv->extract_fonts = !!extract;
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
58 }
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
59
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
60 void ass_set_style_overrides(ass_library_t* priv, char** list)
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
61 {
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
62 char** p;
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
63 char** q;
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
64 int cnt;
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
65
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
66 if (priv->style_overrides) {
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
67 for (p = priv->style_overrides; *p; ++p)
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
68 free(*p);
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
69 free(priv->style_overrides);
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
70 }
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
71
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
72 if (!list) return;
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
73
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
74 for (p = list, cnt = 0; *p; ++p, ++cnt) {}
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
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
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
77 for (p = list, q = priv->style_overrides; *p; ++p, ++q)
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
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
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
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
042b545d588e No need to reinvent strdup...
eugeni
parents: 25613
diff changeset
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
a09381e1a325 Fix ass_clear_fonts not deallocating fontdata.
eugeni
parents: 25616
diff changeset
112 free(priv->fontdata);
a09381e1a325 Fix ass_clear_fonts not deallocating fontdata.
eugeni
parents: 25616
diff changeset
113 priv->fontdata = NULL;
a09381e1a325 Fix ass_clear_fonts not deallocating fontdata.
eugeni
parents: 25616
diff changeset
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 }