annotate libass/ass_cache.c @ 22442:56a0b0f8a66e

Add code to detect and convert to console codepage on Windows. Patch by Zuxy Meng [zuxy.meng at gmail com]
author reimar
date Sun, 04 Mar 2007 19:04:08 +0000
parents 2f3f27a014ef
children a1ced37f2ee5
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 // -*- c-basic-offset: 8; indent-tabs-mode: t -*-
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
2 // vim:ts=8:sw=8:noet:ai:
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
3 /*
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
4 Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
5
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
6 This program is free software; you can redistribute it and/or modify
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
7 it under the terms of the GNU General Public License as published by
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
8 the Free Software Foundation; either version 2 of the License, or
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
9 (at your option) any later version.
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
10
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
11 This program is distributed in the hope that it will be useful,
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
14 GNU General Public License for more details.
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
15
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
16 You should have received a copy of the GNU General Public License
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
17 along with this program; if not, write to the Free Software
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
19 */
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19965
diff changeset
20
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
21 #include "config.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
22
22292
2f3f27a014ef Add some missing includes.
eugeni
parents: 22215
diff changeset
23 #include <inttypes.h>
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
24 #include <ft2build.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
25 #include FT_FREETYPE_H
19846
bcc792bfa431 Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents: 19545
diff changeset
26 #include FT_GLYPH_H
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
27
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
28 #include <assert.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
29
21026
d138463e820b Collect all includes of mplayer headers in libass in a single file (mputils.h).
eugeni
parents: 20637
diff changeset
30 #include "mputils.h"
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21348
diff changeset
31 #include "ass.h"
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
32 #include "ass_fontconfig.h"
21322
bb55f4f7b3cb Fix compilation broken in previous commit.
eugeni
parents: 21317
diff changeset
33 #include "ass_font.h"
19846
bcc792bfa431 Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents: 19545
diff changeset
34 #include "ass_bitmap.h"
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
35 #include "ass_cache.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
36
21265
4e7a7dea3e1f Rename:
eugeni
parents: 21066
diff changeset
37 #define MAX_FONT_CACHE_SIZE 100
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
38
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
39 static ass_font_t** font_cache;
21265
4e7a7dea3e1f Rename:
eugeni
parents: 21066
diff changeset
40 static int font_cache_size;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
41
21265
4e7a7dea3e1f Rename:
eugeni
parents: 21066
diff changeset
42 static int font_compare(ass_font_desc_t* a, ass_font_desc_t* b) {
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
43 if (strcmp(a->family, b->family) != 0)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
44 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
45 if (a->bold != b->bold)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
46 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
47 if (a->italic != b->italic)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
48 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
49 return 1;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
50 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
51
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
52 /**
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
53 * \brief Get a face struct from cache.
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
54 * \param desc required face description
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
55 * \return font struct
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
56 */
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
57 ass_font_t* ass_font_cache_find(ass_font_desc_t* desc)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
58 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
59 int i;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
60
21265
4e7a7dea3e1f Rename:
eugeni
parents: 21066
diff changeset
61 for (i=0; i<font_cache_size; ++i)
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
62 if (font_compare(desc, &(font_cache[i]->desc)))
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
63 return font_cache[i];
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
64
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
65 return 0;
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
66 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
67
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
68 /**
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
69 * \brief Add a face struct to cache.
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
70 * \param font font struct
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
71 */
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
72 void ass_font_cache_add(ass_font_t* font)
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
73 {
21265
4e7a7dea3e1f Rename:
eugeni
parents: 21066
diff changeset
74 if (font_cache_size == MAX_FONT_CACHE_SIZE) {
21066
6196ba31e97e MSGTRs for libass
kraymer
parents: 21026
diff changeset
75 mp_msg(MSGT_ASS, MSGL_FATAL, MSGTR_LIBASS_TooManyFonts);
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
76 // FIXME: possible memory leak
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
77 return;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
78 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
79
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
80 font_cache[font_cache_size] = font;
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents: 21267
diff changeset
81 font_cache_size++;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
82 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
83
21265
4e7a7dea3e1f Rename:
eugeni
parents: 21066
diff changeset
84 void ass_font_cache_init(void)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
85 {
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
86 font_cache = calloc(MAX_FONT_CACHE_SIZE, sizeof(ass_font_t*));
21265
4e7a7dea3e1f Rename:
eugeni
parents: 21066
diff changeset
87 font_cache_size = 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
88 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
89
21265
4e7a7dea3e1f Rename:
eugeni
parents: 21066
diff changeset
90 void ass_font_cache_done(void)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
91 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
92 int i;
21265
4e7a7dea3e1f Rename:
eugeni
parents: 21066
diff changeset
93 for (i = 0; i < font_cache_size; ++i) {
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21279
diff changeset
94 ass_font_t* item = font_cache[i];
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents: 21267
diff changeset
95 ass_font_free(item);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
96 }
21265
4e7a7dea3e1f Rename:
eugeni
parents: 21066
diff changeset
97 free(font_cache);
4e7a7dea3e1f Rename:
eugeni
parents: 21066
diff changeset
98 font_cache_size = 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
99 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
100
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
101 //---------------------------------
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
102 // glyph cache
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
103
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
104 #define GLYPH_HASH_SIZE (0xFFFF + 13)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
105
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
106 typedef struct glyph_hash_item_s {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
107 glyph_hash_key_t key;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
108 glyph_hash_val_t val;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
109 struct glyph_hash_item_s* next;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
110 } glyph_hash_item_t;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
111
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
112 typedef glyph_hash_item_t* glyph_hash_item_p;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
113
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
114 static glyph_hash_item_p* glyph_hash_root;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
115 static int glyph_hash_size;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
116
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
117 static int glyph_compare(glyph_hash_key_t* a, glyph_hash_key_t* b) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
118 if (memcmp(a, b, sizeof(glyph_hash_key_t)) == 0)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
119 return 1;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
120 else
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
121 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
122 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
123
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
124 static unsigned glyph_hash(glyph_hash_key_t* key) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
125 unsigned val = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
126 unsigned i;
21348
d7920b488fa2 Use (ass_font_t, char code) instead of (FT_Face, glyph index) to identify
eugeni
parents: 21322
diff changeset
127 for (i = 0; i < sizeof(key->font); ++i)
d7920b488fa2 Use (ass_font_t, char code) instead of (FT_Face, glyph index) to identify
eugeni
parents: 21322
diff changeset
128 val += *(unsigned char *)(&(key->font) + i);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
129 val <<= 21;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
130
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
131 if (key->bitmap) val &= 0x80000000;
19848
07be98a5dd5f Add \be (blur edges) support to libass.
eugeni
parents: 19846
diff changeset
132 if (key->be) val &= 0x40000000;
21348
d7920b488fa2 Use (ass_font_t, char code) instead of (FT_Face, glyph index) to identify
eugeni
parents: 21322
diff changeset
133 val += key->ch;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
134 val += key->size << 8;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
135 val += key->outline << 3;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
136 val += key->advance.x << 10;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
137 val += key->advance.y << 16;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
138 val += key->bold << 1;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
139 val += key->italic << 20;
22215
fb365c2b3d05 Implement \frx and \fry (and reimplement \frz) as 3d rotations.
eugeni
parents: 21458
diff changeset
140 val += key->frx;
fb365c2b3d05 Implement \frx and \fry (and reimplement \frz) as 3d rotations.
eugeni
parents: 21458
diff changeset
141 val += key->fry << 1;
fb365c2b3d05 Implement \frx and \fry (and reimplement \frz) as 3d rotations.
eugeni
parents: 21458
diff changeset
142 val += key->frz << 2;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
143 return val;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
144 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
145
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
146 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
147 * \brief Add a glyph to glyph cache.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
148 * \param key hash key
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
149 * \param val hash val: 2 bitmap glyphs + some additional info
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
150 */
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
151 void cache_add_glyph(glyph_hash_key_t* key, glyph_hash_val_t* val)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
152 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
153 unsigned hash = glyph_hash(key);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
154 glyph_hash_item_t** next = glyph_hash_root + (hash % GLYPH_HASH_SIZE);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
155 while (*next) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
156 if (glyph_compare(key, &((*next)->key)))
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
157 return;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
158 next = &((*next)->next);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
159 assert(next);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
160 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
161 (*next) = malloc(sizeof(glyph_hash_item_t));
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
162 // (*next)->desc = glyph_key_copy(key, &((*next)->key));
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
163 memcpy(&((*next)->key), key, sizeof(glyph_hash_key_t));
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
164 memcpy(&((*next)->val), val, sizeof(glyph_hash_val_t));
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
165 (*next)->next = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
166
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
167 glyph_hash_size ++;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
168 /* if (glyph_hash_size && (glyph_hash_size % 25 == 0)) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
169 printf("\nGlyph cache: %d entries, %d bytes\n", glyph_hash_size, glyph_hash_size * sizeof(glyph_hash_item_t));
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
170 } */
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
171 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
172
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
173 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
174 * \brief Get a glyph from glyph cache.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
175 * \param key hash key
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
176 * \return requested hash val or 0 if not found
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
177 */
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
178 glyph_hash_val_t* cache_find_glyph(glyph_hash_key_t* key)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
179 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
180 unsigned hash = glyph_hash(key);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
181 glyph_hash_item_t* item = glyph_hash_root[hash % GLYPH_HASH_SIZE];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
182 while (item) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
183 if (glyph_compare(key, &(item->key))) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
184 return &(item->val);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
185 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
186 item = item->next;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
187 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
188 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
189 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
190
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
191 void ass_glyph_cache_init(void)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
192 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
193 glyph_hash_root = calloc(GLYPH_HASH_SIZE, sizeof(glyph_hash_item_p));
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
194 glyph_hash_size = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
195 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
196
19545
8f46b547db39 Simplify ass_glyph_cache_reset().
eugeni
parents: 19539
diff changeset
197 void ass_glyph_cache_done(void)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
198 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
199 int i;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
200 for (i = 0; i < GLYPH_HASH_SIZE; ++i) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
201 glyph_hash_item_t* item = glyph_hash_root[i];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
202 while (item) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
203 glyph_hash_item_t* next = item->next;
19846
bcc792bfa431 Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents: 19545
diff changeset
204 if (item->val.bm) ass_free_bitmap(item->val.bm);
bcc792bfa431 Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents: 19545
diff changeset
205 if (item->val.bm_o) ass_free_bitmap(item->val.bm_o);
19965
70352570e9ae Shadow support in libass.
eugeni
parents: 19848
diff changeset
206 if (item->val.bm_s) ass_free_bitmap(item->val.bm_s);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
207 free(item);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
208 item = next;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
209 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
210 }
19545
8f46b547db39 Simplify ass_glyph_cache_reset().
eugeni
parents: 19539
diff changeset
211 free(glyph_hash_root);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
212 glyph_hash_size = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
213 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
214
19545
8f46b547db39 Simplify ass_glyph_cache_reset().
eugeni
parents: 19539
diff changeset
215 void ass_glyph_cache_reset(void)
19539
64009ae411fb Reset glyph cache on reconfigure.
eugeni
parents: 18937
diff changeset
216 {
19545
8f46b547db39 Simplify ass_glyph_cache_reset().
eugeni
parents: 19539
diff changeset
217 ass_glyph_cache_done();
8f46b547db39 Simplify ass_glyph_cache_reset().
eugeni
parents: 19539
diff changeset
218 ass_glyph_cache_init();
19539
64009ae411fb Reset glyph cache on reconfigure.
eugeni
parents: 18937
diff changeset
219 }
64009ae411fb Reset glyph cache on reconfigure.
eugeni
parents: 18937
diff changeset
220