diff options
author | Grigori Goronzy <greg@blackbox> | 2011-06-27 02:17:10 +0200 |
---|---|---|
committer | Grigori Goronzy <greg@blackbox> | 2011-06-27 02:17:10 +0200 |
commit | d14f08365d9ecd16e8c762d852b6a22d7cc2307d (patch) | |
tree | f1957f459b64213d3dd380007b5b8864599db9d7 /libass/ass_cache.c | |
parent | 308f4193c6b8d9f3ab8c70f7a9e083e7e2ad867d (diff) | |
download | libass-d14f08365d9ecd16e8c762d852b6a22d7cc2307d.tar.bz2 libass-d14f08365d9ecd16e8c762d852b6a22d7cc2307d.tar.xz |
cache: unified outline cache for glyphs/drawings
Glyphs and drawings have wildly different hash keys. Subclass the hash
keys of glyphs and drawings in a new, unified outline cache. This also
fixes some issues with drawings in the glyph cache. Now, the textual
description of the drawing is included in the key (the hash value isn't
really good enough, especially not fnv32) and the baseline offset is
saved as well.
Diffstat (limited to 'libass/ass_cache.c')
-rw-r--r-- | libass/ass_cache.c | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/libass/ass_cache.c b/libass/ass_cache.c index 5ea4f1d..15f7376 100644 --- a/libass/ass_cache.c +++ b/libass/ass_cache.c @@ -29,7 +29,7 @@ #include "ass_cache.h" // type-specific functions -// create hash/compare functions for bitmap, glyph and composite cache +// create hash/compare functions for bitmap, outline and composite cache #define CREATE_HASH_FUNCTIONS #include "ass_cache_template.h" #define CREATE_COMPARISON_FUNCTIONS @@ -96,41 +96,56 @@ static size_t bitmap_size(void *value, size_t value_size) return 0; } -// glyph cache -static void glyph_destruct(void *key, void *value) +// composite cache +static void composite_destruct(void *key, void *value) { - GlyphHashValue *v = value; - if (v->outline) - outline_free(v->lib, v->outline); - if (v->border) - outline_free(v->lib, v->border); + CompositeHashValue *v = value; + free(v->a); + free(v->b); free(key); free(value); } -static size_t glyph_size(void *value, size_t value_size) +// outline cache + +static unsigned outline_hash(void *key, size_t key_size) { -#if 0 - GlyphHashValue *val = value; - if (val->glyph && val->glyph->format == FT_GLYPH_FORMAT_BITMAP) { - FT_Bitmap *bitmap = &((FT_BitmapGlyph) val->glyph)->bitmap; - return bitmap->rows * bitmap->pitch; + OutlineHashKey *k = key; + switch (k->type) { + case OUTLINE_GLYPH: return glyph_hash(&k->u, key_size); + case OUTLINE_DRAWING: return drawing_hash(&k->u, key_size); + default: return 0; } -#endif - return 0; } -// composite cache -static void composite_destruct(void *key, void *value) +static unsigned outline_compare(void *a, void *b, size_t key_size) { - CompositeHashValue *v = value; - free(v->a); - free(v->b); + OutlineHashKey *ak = a; + OutlineHashKey *bk = b; + if (ak->type != bk->type) return 0; + switch (ak->type) { + case OUTLINE_GLYPH: return glyph_compare(&ak->u, &bk->u, key_size); + case OUTLINE_DRAWING: return drawing_compare(&ak->u, &bk->u, key_size); + default: return 0; + } +} + +static void outline_destruct(void *key, void *value) +{ + OutlineHashValue *v = value; + OutlineHashKey *k = key; + if (v->outline) + outline_free(v->lib, v->outline); + if (v->border) + outline_free(v->lib, v->border); + if (k->type == OUTLINE_DRAWING) + free(k->u.drawing.text); free(key); free(value); } + // Cache data typedef struct cache_item { void *key; @@ -279,10 +294,10 @@ Cache *ass_font_cache_create(void) (ItemSize)NULL, sizeof(ASS_FontDesc), sizeof(ASS_Font)); } -Cache *ass_glyph_cache_create(void) +Cache *ass_outline_cache_create(void) { - return ass_cache_create(glyph_hash, glyph_compare, glyph_destruct, - glyph_size, sizeof(GlyphHashKey), sizeof(GlyphHashValue)); + return ass_cache_create(outline_hash, outline_compare, outline_destruct, + NULL, sizeof(OutlineHashKey), sizeof(OutlineHashValue)); } Cache *ass_bitmap_cache_create(void) |