Fix compilation after r31173.
[mplayer/glamo.git] / libass / ass_cache.h
blob5c9749f87092978f64c08878b210776ee1afb1f9
1 /*
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
4 * This file is part of libass.
6 * libass is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * libass is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with libass; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #ifndef LIBASS_CACHE_H
22 #define LIBASS_CACHE_H
24 #include "ass.h"
25 #include "ass_font.h"
26 #include "ass_bitmap.h"
28 typedef void (*HashmapItemDtor) (void *key, size_t key_size,
29 void *value, size_t value_size);
30 typedef int (*HashmapKeyCompare) (void *key1, void *key2,
31 size_t key_size);
32 typedef unsigned (*HashmapHash) (void *key, size_t key_size);
34 typedef struct hashmap_item {
35 void *key;
36 void *value;
37 struct hashmap_item *next;
38 } HashmapItem;
39 typedef HashmapItem *hashmap_item_p;
41 typedef struct {
42 int nbuckets;
43 size_t key_size, value_size;
44 hashmap_item_p *root;
45 HashmapItemDtor item_dtor; // a destructor for hashmap key/value pairs
46 HashmapKeyCompare key_compare;
47 HashmapHash hash;
48 size_t cache_size;
49 // stats
50 int hit_count;
51 int miss_count;
52 int count;
53 ASS_Library *library;
54 } Hashmap;
56 Hashmap *hashmap_init(ASS_Library *library, size_t key_size,
57 size_t value_size, int nbuckets,
58 HashmapItemDtor item_dtor,
59 HashmapKeyCompare key_compare,
60 HashmapHash hash);
61 void hashmap_done(Hashmap *map);
62 void *hashmap_insert(Hashmap *map, void *key, void *value);
63 void *hashmap_find(Hashmap *map, void *key);
65 Hashmap *ass_font_cache_init(ASS_Library *library);
66 ASS_Font *ass_font_cache_find(Hashmap *, ASS_FontDesc *desc);
67 void *ass_font_cache_add(Hashmap *, ASS_Font *font);
68 void ass_font_cache_done(Hashmap *);
70 // Create definitions for bitmap_hash_key and glyph_hash_key
71 #define CREATE_STRUCT_DEFINITIONS
72 #include "ass_cache_template.h"
74 typedef struct {
75 Bitmap *bm; // the actual bitmaps
76 Bitmap *bm_o;
77 Bitmap *bm_s;
78 } BitmapHashValue;
80 Hashmap *ass_bitmap_cache_init(ASS_Library *library);
81 void *cache_add_bitmap(Hashmap *, BitmapHashKey *key,
82 BitmapHashValue *val);
83 BitmapHashValue *cache_find_bitmap(Hashmap *bitmap_cache,
84 BitmapHashKey *key);
85 Hashmap *ass_bitmap_cache_reset(Hashmap *bitmap_cache);
86 void ass_bitmap_cache_done(Hashmap *bitmap_cache);
89 typedef struct {
90 unsigned char *a;
91 unsigned char *b;
92 } CompositeHashValue;
94 Hashmap *ass_composite_cache_init(ASS_Library *library);
95 void *cache_add_composite(Hashmap *, CompositeHashKey *key,
96 CompositeHashValue *val);
97 CompositeHashValue *cache_find_composite(Hashmap *composite_cache,
98 CompositeHashKey *key);
99 Hashmap *ass_composite_cache_reset(Hashmap *composite_cache);
100 void ass_composite_cache_done(Hashmap *composite_cache);
103 typedef struct {
104 FT_Glyph glyph;
105 FT_Glyph outline_glyph;
106 FT_BBox bbox_scaled; // bbox after scaling, but before rotation
107 FT_Vector advance; // 26.6, advance distance to the next bitmap in line
108 int asc, desc; // ascender/descender of a drawing
109 } GlyphHashValue;
111 Hashmap *ass_glyph_cache_init(ASS_Library *library);
112 void *cache_add_glyph(Hashmap *, GlyphHashKey *key,
113 GlyphHashValue *val);
114 GlyphHashValue *cache_find_glyph(Hashmap *glyph_cache,
115 GlyphHashKey *key);
116 Hashmap *ass_glyph_cache_reset(Hashmap *glyph_cache);
117 void ass_glyph_cache_done(Hashmap *glyph_cache);
119 #endif /* LIBASS_CACHE_H */