2007-04-09 04:02:40 +02:00
|
|
|
/*
|
2008-12-28 09:09:59 +01:00
|
|
|
* Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
|
|
|
|
*
|
|
|
|
* This file is part of libass.
|
|
|
|
*
|
|
|
|
* libass is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* libass is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with libass; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2007-04-09 04:02:40 +02:00
|
|
|
|
2008-03-21 06:32:23 +01:00
|
|
|
#ifndef LIBASS_CACHE_H
|
|
|
|
#define LIBASS_CACHE_H
|
|
|
|
|
|
|
|
#include "ass.h"
|
|
|
|
#include "ass_font.h"
|
|
|
|
#include "ass_bitmap.h"
|
2007-04-09 04:02:40 +02:00
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
typedef void (*hashmap_item_dtor_t) (void *key, size_t key_size,
|
|
|
|
void *value, size_t value_size);
|
|
|
|
typedef int (*hashmap_key_compare_t) (void *key1, void *key2,
|
|
|
|
size_t key_size);
|
|
|
|
typedef unsigned (*hashmap_hash_t) (void *key, size_t key_size);
|
|
|
|
|
|
|
|
typedef struct hashmap_item_s {
|
|
|
|
void *key;
|
|
|
|
void *value;
|
|
|
|
struct hashmap_item_s *next;
|
|
|
|
} hashmap_item_t;
|
|
|
|
typedef hashmap_item_t *hashmap_item_p;
|
|
|
|
|
|
|
|
typedef struct hashmap_s {
|
|
|
|
int nbuckets;
|
|
|
|
size_t key_size, value_size;
|
|
|
|
hashmap_item_p *root;
|
|
|
|
hashmap_item_dtor_t item_dtor; // a destructor for hashmap key/value pairs
|
|
|
|
hashmap_key_compare_t key_compare;
|
|
|
|
hashmap_hash_t hash;
|
|
|
|
// stats
|
|
|
|
int hit_count;
|
|
|
|
int miss_count;
|
|
|
|
int count;
|
2009-07-14 00:43:25 +02:00
|
|
|
ass_library_t *library;
|
2009-07-11 17:48:50 +02:00
|
|
|
} hashmap_t;
|
|
|
|
|
2009-07-14 00:43:25 +02:00
|
|
|
hashmap_t *hashmap_init(ass_library_t *library, size_t key_size,
|
|
|
|
size_t value_size, int nbuckets,
|
2009-07-11 17:48:50 +02:00
|
|
|
hashmap_item_dtor_t item_dtor,
|
|
|
|
hashmap_key_compare_t key_compare,
|
|
|
|
hashmap_hash_t hash);
|
|
|
|
void hashmap_done(hashmap_t *map);
|
|
|
|
void *hashmap_insert(hashmap_t *map, void *key, void *value);
|
|
|
|
void *hashmap_find(hashmap_t *map, void *key);
|
|
|
|
|
2009-07-14 00:43:25 +02:00
|
|
|
hashmap_t *ass_font_cache_init(ass_library_t *library);
|
2009-07-11 17:48:50 +02:00
|
|
|
ass_font_t *ass_font_cache_find(hashmap_t *, ass_font_desc_t *desc);
|
|
|
|
void *ass_font_cache_add(hashmap_t *, ass_font_t *font);
|
|
|
|
void ass_font_cache_done(hashmap_t *);
|
2007-04-09 04:02:40 +02:00
|
|
|
|
2009-05-04 08:48:21 +02:00
|
|
|
// Create definitions for bitmap_hash_key and glyph_hash_key
|
|
|
|
#define CREATE_STRUCT_DEFINITIONS
|
2009-07-14 00:43:25 +02:00
|
|
|
#include "ass_cache_template.h"
|
2007-04-09 04:02:40 +02:00
|
|
|
|
2008-01-17 17:50:19 +01:00
|
|
|
typedef struct bitmap_hash_val_s {
|
2009-07-11 17:48:50 +02:00
|
|
|
bitmap_t *bm; // the actual bitmaps
|
|
|
|
bitmap_t *bm_o;
|
|
|
|
bitmap_t *bm_s;
|
2008-01-17 17:50:19 +01:00
|
|
|
} bitmap_hash_val_t;
|
|
|
|
|
2009-07-14 00:43:25 +02:00
|
|
|
hashmap_t *ass_bitmap_cache_init(ass_library_t *library);
|
2009-07-11 17:48:50 +02:00
|
|
|
void *cache_add_bitmap(hashmap_t *, bitmap_hash_key_t *key,
|
|
|
|
bitmap_hash_val_t *val);
|
|
|
|
bitmap_hash_val_t *cache_find_bitmap(hashmap_t *bitmap_cache,
|
|
|
|
bitmap_hash_key_t *key);
|
|
|
|
hashmap_t *ass_bitmap_cache_reset(hashmap_t *bitmap_cache);
|
|
|
|
void ass_bitmap_cache_done(hashmap_t *bitmap_cache);
|
2009-03-12 04:46:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct composite_hash_val_s {
|
2009-07-11 17:48:50 +02:00
|
|
|
unsigned char *a;
|
|
|
|
unsigned char *b;
|
2009-03-12 04:46:44 +01:00
|
|
|
} composite_hash_val_t;
|
|
|
|
|
2009-07-14 00:43:25 +02:00
|
|
|
hashmap_t *ass_composite_cache_init(ass_library_t *library);
|
2009-07-11 17:48:50 +02:00
|
|
|
void *cache_add_composite(hashmap_t *, composite_hash_key_t *key,
|
|
|
|
composite_hash_val_t *val);
|
|
|
|
composite_hash_val_t *cache_find_composite(hashmap_t *composite_cache,
|
|
|
|
composite_hash_key_t *key);
|
|
|
|
hashmap_t *ass_composite_cache_reset(hashmap_t *composite_cache);
|
|
|
|
void ass_composite_cache_done(hashmap_t *composite_cache);
|
2009-03-12 04:46:44 +01:00
|
|
|
|
|
|
|
|
2008-01-17 17:50:19 +01:00
|
|
|
typedef struct glyph_hash_val_s {
|
2009-07-11 17:48:50 +02:00
|
|
|
FT_Glyph glyph;
|
|
|
|
FT_Glyph outline_glyph;
|
|
|
|
FT_BBox bbox_scaled; // bbox after scaling, but before rotation
|
|
|
|
FT_Vector advance; // 26.6, advance distance to the next bitmap in line
|
|
|
|
int asc, desc; // ascender/descender of a drawing
|
2007-04-09 04:02:40 +02:00
|
|
|
} glyph_hash_val_t;
|
|
|
|
|
2009-07-14 00:43:25 +02:00
|
|
|
hashmap_t *ass_glyph_cache_init(ass_library_t *library);
|
2009-07-11 17:48:50 +02:00
|
|
|
void *cache_add_glyph(hashmap_t *, glyph_hash_key_t *key,
|
|
|
|
glyph_hash_val_t *val);
|
|
|
|
glyph_hash_val_t *cache_find_glyph(hashmap_t *glyph_cache,
|
|
|
|
glyph_hash_key_t *key);
|
|
|
|
hashmap_t *ass_glyph_cache_reset(hashmap_t *glyph_cache);
|
|
|
|
void ass_glyph_cache_done(hashmap_t *glyph_cache);
|
|
|
|
|
|
|
|
#endif /* LIBASS_CACHE_H */
|