annotate libass/ass_cache.c @ 34168:55abe5125482

Make include recursion depth actually have some effect. Not working yet though, needs another change to really work properly.
author reimar
date Tue, 25 Oct 2011 19:22:10 +0000
parents 88eebbbbd6a0
children 6e7f60f6f9d4
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: 19965
diff changeset
1 /*
26723
0f892cd714b2 Use standard license header.
diego
parents: 23214
diff changeset
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
0f892cd714b2 Use standard license header.
diego
parents: 23214
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: 23214
diff changeset
5 *
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
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: 31853
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: 31853
diff changeset
8 * copyright notice and this permission notice appear in all copies.
26723
0f892cd714b2 Use standard license header.
diego
parents: 23214
diff changeset
9 *
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
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: 31853
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: 31853
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: 31853
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: 31853
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: 31853
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: 31853
diff changeset
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26723
0f892cd714b2 Use standard license header.
diego
parents: 23214
diff changeset
17 */
20008
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
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
22292
2f3f27a014ef Add some missing includes.
eugeni
parents: 22215
diff changeset
21 #include <inttypes.h>
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
22 #include <ft2build.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
23 #include FT_FREETYPE_H
19846
bcc792bfa431 Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents: 19545
diff changeset
24 #include FT_GLYPH_H
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
25
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
26 #include <assert.h>
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_utils.h"
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21348
diff changeset
29 #include "ass.h"
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
30 #include "ass_fontconfig.h"
21322
bb55f4f7b3cb Fix compilation broken in previous commit.
eugeni
parents: 21317
diff changeset
31 #include "ass_font.h"
19846
bcc792bfa431 Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents: 19545
diff changeset
32 #include "ass_bitmap.h"
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
33 #include "ass_cache.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
34
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
35 static unsigned hashmap_hash(void *buf, size_t len)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
36 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
37 return fnv_32a_buf(buf, len, FNV1_32A_INIT);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
38 }
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
39
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
40 static int hashmap_key_compare(void *a, void *b, size_t size)
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
41 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
42 return memcmp(a, b, size) == 0;
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
43 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
44
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
45 static void hashmap_item_dtor(void *key, size_t key_size, void *value,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
46 size_t value_size)
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
47 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
48 free(key);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
49 free(value);
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
50 }
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
51
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
52 Hashmap *hashmap_init(ASS_Library *library, size_t key_size,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
53 size_t value_size, int nbuckets,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
54 HashmapItemDtor item_dtor,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
55 HashmapKeyCompare key_compare,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
56 HashmapHash hash)
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
57 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
58 Hashmap *map = calloc(1, sizeof(Hashmap));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
59 map->library = library;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
60 map->nbuckets = nbuckets;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
61 map->key_size = key_size;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
62 map->value_size = value_size;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
63 map->root = calloc(nbuckets, sizeof(hashmap_item_p));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
64 map->item_dtor = item_dtor ? item_dtor : hashmap_item_dtor;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
65 map->key_compare = key_compare ? key_compare : hashmap_key_compare;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
66 map->hash = hash ? hash : hashmap_hash;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
67 return map;
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
68 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
69
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
70 void hashmap_done(Hashmap *map)
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
71 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
72 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
73 // print stats
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
74 if (map->count > 0 || map->hit_count + map->miss_count > 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
75 ass_msg(map->library, MSGL_V,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
76 "cache statistics: \n total accesses: %d\n hits: %d\n "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
77 "misses: %d\n object count: %d",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
78 map->hit_count + map->miss_count, map->hit_count,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
79 map->miss_count, map->count);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28860
diff changeset
80
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
81 for (i = 0; i < map->nbuckets; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
82 HashmapItem *item = map->root[i];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
83 while (item) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
84 HashmapItem *next = item->next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
85 map->item_dtor(item->key, map->key_size, item->value,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
86 map->value_size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
87 free(item);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
88 item = next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
89 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
90 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
91 free(map->root);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
92 free(map);
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
93 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
94
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
95 // does nothing if key already exists
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
96 void *hashmap_insert(Hashmap *map, void *key, void *value)
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
97 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
98 unsigned hash = map->hash(key, map->key_size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
99 HashmapItem **next = map->root + (hash % map->nbuckets);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
100 while (*next) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
101 if (map->key_compare(key, (*next)->key, map->key_size))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
102 return (*next)->value;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
103 next = &((*next)->next);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
104 assert(next);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
105 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
106 (*next) = malloc(sizeof(HashmapItem));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
107 (*next)->key = malloc(map->key_size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
108 (*next)->value = malloc(map->value_size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
109 memcpy((*next)->key, key, map->key_size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
110 memcpy((*next)->value, value, map->value_size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
111 (*next)->next = 0;
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
112
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
113 map->count++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
114 return (*next)->value;
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
115 }
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
116
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
117 void *hashmap_find(Hashmap *map, void *key)
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
118 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
119 unsigned hash = map->hash(key, map->key_size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
120 HashmapItem *item = map->root[hash % map->nbuckets];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
121 while (item) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
122 if (map->key_compare(key, item->key, map->key_size)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
123 map->hit_count++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
124 return item->value;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
125 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
126 item = item->next;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
127 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
128 map->miss_count++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
129 return 0;
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
130 }
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
131
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
132 //---------------------------------
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
133 // font cache
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
134
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
135 static unsigned font_desc_hash(void *buf, size_t len)
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
136 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
137 ASS_FontDesc *desc = buf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
138 unsigned hval;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
139 hval = fnv_32a_str(desc->family, FNV1_32A_INIT);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
140 hval = fnv_32a_buf(&desc->bold, sizeof(desc->bold), hval);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
141 hval = fnv_32a_buf(&desc->italic, sizeof(desc->italic), hval);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
142 return hval;
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
143 }
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
144
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
145 static int font_compare(void *key1, void *key2, size_t key_size)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
146 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
147 ASS_FontDesc *a = key1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
148 ASS_FontDesc *b = key2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
149 if (strcmp(a->family, b->family) != 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
150 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
151 if (a->bold != b->bold)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
152 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
153 if (a->italic != b->italic)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
154 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
155 if (a->treat_family_as_pattern != b->treat_family_as_pattern)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
156 return 0;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
157 if (a->vertical != b->vertical)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
158 return 0;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
159 return 1;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
160 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
161
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
162 static void font_hash_dtor(void *key, size_t key_size, void *value,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
163 size_t value_size)
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
164 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
165 ass_font_free(value);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
166 free(key);
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
167 }
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
168
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
169 ASS_Font *ass_font_cache_find(Hashmap *font_cache,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
170 ASS_FontDesc *desc)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
171 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
172 return hashmap_find(font_cache, desc);
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
173 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
174
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
175 /**
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
176 * \brief Add a face struct to cache.
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
177 * \param font font struct
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
178 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
179 void *ass_font_cache_add(Hashmap *font_cache, ASS_Font *font)
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
180 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
181 return hashmap_insert(font_cache, &(font->desc), font);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
182 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
183
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
184 Hashmap *ass_font_cache_init(ASS_Library *library)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
185 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
186 Hashmap *font_cache;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
187 font_cache = hashmap_init(library, sizeof(ASS_FontDesc),
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
188 sizeof(ASS_Font),
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
189 1000,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
190 font_hash_dtor, font_compare, font_desc_hash);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
191 return font_cache;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
192 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
193
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
194 void ass_font_cache_done(Hashmap *font_cache)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
195 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
196 hashmap_done(font_cache);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
197 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
198
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
199
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
200 // Create hash/compare functions for bitmap and glyph
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
201 #define CREATE_HASH_FUNCTIONS
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
202 #include "ass_cache_template.h"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
203 #define CREATE_COMPARISON_FUNCTIONS
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
204 #include "ass_cache_template.h"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
205
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
206 //---------------------------------
23017
f3b04984b0da Rename glyph cache to bitmap cache.
eugeni
parents: 23016
diff changeset
207 // bitmap cache
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
208
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
209 static void bitmap_hash_dtor(void *key, size_t key_size, void *value,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
210 size_t value_size)
23016
a1ced37f2ee5 Add generic hash map implementation.
eugeni
parents: 22292
diff changeset
211 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
212 BitmapHashValue *v = value;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
213 if (v->bm)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
214 ass_free_bitmap(v->bm);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
215 if (v->bm_o)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
216 ass_free_bitmap(v->bm_o);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
217 if (v->bm_s)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
218 ass_free_bitmap(v->bm_s);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
219 free(key);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
220 free(value);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
221 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
222
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
223 void *cache_add_bitmap(Hashmap *bitmap_cache, BitmapHashKey *key,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
224 BitmapHashValue *val)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
225 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
226 // Note: this is only an approximation
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
227 if (val->bm_o)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
228 bitmap_cache->cache_size += val->bm_o->w * val->bm_o->h * 3;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
229 else if (val->bm)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
230 bitmap_cache->cache_size += val->bm->w * val->bm->h * 3;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
231
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
232 return hashmap_insert(bitmap_cache, key, val);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
233 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
234
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
235 /**
23017
f3b04984b0da Rename glyph cache to bitmap cache.
eugeni
parents: 23016
diff changeset
236 * \brief Get a bitmap from bitmap cache.
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
237 * \param key hash key
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
238 * \return requested hash val or 0 if not found
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28860
diff changeset
239 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
240 BitmapHashValue *cache_find_bitmap(Hashmap *bitmap_cache,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
241 BitmapHashKey *key)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
242 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
243 return hashmap_find(bitmap_cache, key);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
244 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
245
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
246 Hashmap *ass_bitmap_cache_init(ASS_Library *library)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
247 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
248 Hashmap *bitmap_cache;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
249 bitmap_cache = hashmap_init(library,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
250 sizeof(BitmapHashKey),
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
251 sizeof(BitmapHashValue),
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
252 0xFFFF + 13,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
253 bitmap_hash_dtor, bitmap_compare,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
254 bitmap_hash);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
255 return bitmap_cache;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
256 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
257
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
258 void ass_bitmap_cache_done(Hashmap *bitmap_cache)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
259 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
260 hashmap_done(bitmap_cache);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
261 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
262
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
263 Hashmap *ass_bitmap_cache_reset(Hashmap *bitmap_cache)
19539
64009ae411fb Reset glyph cache on reconfigure.
eugeni
parents: 18937
diff changeset
264 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
265 ASS_Library *lib = bitmap_cache->library;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
266
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
267 ass_bitmap_cache_done(bitmap_cache);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
268 return ass_bitmap_cache_init(lib);
19539
64009ae411fb Reset glyph cache on reconfigure.
eugeni
parents: 18937
diff changeset
269 }
64009ae411fb Reset glyph cache on reconfigure.
eugeni
parents: 18937
diff changeset
270
23018
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
271 //---------------------------------
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
272 // glyph cache
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
273
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
274 static void glyph_hash_dtor(void *key, size_t key_size, void *value,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
275 size_t value_size)
23018
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
276 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
277 GlyphHashValue *v = value;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
278 if (v->glyph)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
279 FT_Done_Glyph(v->glyph);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
280 if (v->outline_glyph)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
281 FT_Done_Glyph(v->outline_glyph);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
282 free(key);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
283 free(value);
23018
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
284 }
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
285
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
286 void *cache_add_glyph(Hashmap *glyph_cache, GlyphHashKey *key,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
287 GlyphHashValue *val)
23018
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
288 {
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
289 if (val->glyph && val->glyph->format == FT_GLYPH_FORMAT_BITMAP) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
290 FT_Bitmap *bitmap = &((FT_BitmapGlyph) val->glyph)->bitmap;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
291 glyph_cache->cache_size += bitmap->rows * bitmap->pitch;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
292 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
293
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
294 return hashmap_insert(glyph_cache, key, val);
23018
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
295 }
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
296
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
297 /**
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
298 * \brief Get a glyph from glyph cache.
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
299 * \param key hash key
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
300 * \return requested hash val or 0 if not found
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28860
diff changeset
301 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
302 GlyphHashValue *cache_find_glyph(Hashmap *glyph_cache,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
303 GlyphHashKey *key)
23018
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
304 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
305 return hashmap_find(glyph_cache, key);
23018
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
306 }
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
307
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
308 Hashmap *ass_glyph_cache_init(ASS_Library *library)
23018
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
309 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
310 Hashmap *glyph_cache;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
311 glyph_cache = hashmap_init(library, sizeof(GlyphHashKey),
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
312 sizeof(GlyphHashValue),
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
313 0xFFFF + 13,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
314 glyph_hash_dtor, glyph_compare, glyph_hash);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
315 return glyph_cache;
23018
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
316 }
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
317
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
318 void ass_glyph_cache_done(Hashmap *glyph_cache)
23018
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
319 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
320 hashmap_done(glyph_cache);
23018
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
321 }
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
322
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
323 Hashmap *ass_glyph_cache_reset(Hashmap *glyph_cache)
23018
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
324 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
325 ASS_Library *lib = glyph_cache->library;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
326
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
327 ass_glyph_cache_done(glyph_cache);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
328 return ass_glyph_cache_init(lib);
23018
a4517aa83565 Add outline glyph cache (unused yet).
eugeni
parents: 23017
diff changeset
329 }
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
330
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
331
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
332 //---------------------------------
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
333 // composite cache
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
334
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
335 static void composite_hash_dtor(void *key, size_t key_size, void *value,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
336 size_t value_size)
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
337 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
338 CompositeHashValue *v = value;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
339 free(v->a);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
340 free(v->b);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
341 free(key);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
342 free(value);
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
343 }
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
344
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
345 void *cache_add_composite(Hashmap *composite_cache,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
346 CompositeHashKey *key,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
347 CompositeHashValue *val)
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
348 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
349 return hashmap_insert(composite_cache, key, val);
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
350 }
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
351
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
352 /**
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
353 * \brief Get a composite bitmap from composite cache.
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
354 * \param key hash key
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
355 * \return requested hash val or 0 if not found
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
356 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
357 CompositeHashValue *cache_find_composite(Hashmap *composite_cache,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
358 CompositeHashKey *key)
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
359 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
360 return hashmap_find(composite_cache, key);
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
361 }
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
362
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
363 Hashmap *ass_composite_cache_init(ASS_Library *library)
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
364 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
365 Hashmap *composite_cache;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
366 composite_cache = hashmap_init(library, sizeof(CompositeHashKey),
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
367 sizeof(CompositeHashValue),
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
368 0xFFFF + 13,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
369 composite_hash_dtor, composite_compare,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
370 composite_hash);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
371 return composite_cache;
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
372 }
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
373
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
374 void ass_composite_cache_done(Hashmap *composite_cache)
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
375 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
376 hashmap_done(composite_cache);
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
377 }
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
378
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
379 Hashmap *ass_composite_cache_reset(Hashmap *composite_cache)
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
380 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
381 ASS_Library *lib = composite_cache->library;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
382
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
383 ass_composite_cache_done(composite_cache);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
384 return ass_composite_cache_init(lib);
28789
a0ce88ba2557 Combine adjacent overlapping, translucent glyph borders and shadows to
greg
parents: 26759
diff changeset
385 }