diff options
author | greg <greg@blackbox> | 2009-06-18 14:12:32 +0200 |
---|---|---|
committer | greg <greg@blackbox> | 2009-06-19 05:17:22 +0200 |
commit | 3fcd2a5c6225edcd83d3f7e154592735dc8c6536 (patch) | |
tree | 1590694893490f9dcabc66e35169a106f32bdf00 /libass | |
parent | 2f59cd0e21b3f4a953b67525fa56b133d4d6b352 (diff) | |
download | libass-3fcd2a5c6225edcd83d3f7e154592735dc8c6536.tar.bz2 libass-3fcd2a5c6225edcd83d3f7e154592735dc8c6536.tar.xz |
Remove MAX_GLYPHS and MAX_LINES limits. Instead, dynamically allocate
memory and use reasonable initial sizes.
Diffstat (limited to 'libass')
-rw-r--r-- | libass/ass_render.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/libass/ass_render.c b/libass/ass_render.c index 8c2af83c..66b513e2 100644 --- a/libass/ass_render.c +++ b/libass/ass_render.c @@ -41,8 +41,8 @@ #include "ass_fontconfig.h" #include "ass_library.h" -#define MAX_GLYPHS 3000 -#define MAX_LINES 300 +#define MAX_GLYPHS_INITIAL 1024 +#define MAX_LINES_INITIAL 64 #define BLUR_MAX_RADIUS 50.0 #define MAX_BE 100 #define ROUND(x) ((int) ((x) + .5)) @@ -115,9 +115,11 @@ typedef struct line_info_s { typedef struct text_info_s { glyph_info_t* glyphs; int length; - line_info_t lines[MAX_LINES]; + line_info_t* lines; int n_lines; int height; + int max_glyphs; + int max_lines; } text_info_t; @@ -282,7 +284,10 @@ ass_renderer_t* ass_renderer_init(ass_library_t* library) priv->cache.composite_cache = ass_composite_cache_init(); priv->cache.glyph_cache = ass_glyph_cache_init(); - priv->text_info.glyphs = calloc(MAX_GLYPHS, sizeof(glyph_info_t)); + priv->text_info.max_glyphs = MAX_GLYPHS_INITIAL; + priv->text_info.max_lines = MAX_LINES_INITIAL; + priv->text_info.glyphs = calloc(MAX_GLYPHS_INITIAL, sizeof(glyph_info_t)); + priv->text_info.lines = calloc(MAX_LINES_INITIAL, sizeof(line_info_t)); ass_init_exit: if (priv) mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_LIBASS_Init); @@ -306,7 +311,8 @@ void ass_renderer_done(ass_renderer_t* render_priv) if (render_priv && render_priv->synth_priv) ass_synth_done(render_priv->synth_priv); if (render_priv && render_priv->eimg) free(render_priv->eimg); free(render_priv); - if (render_priv->text_info.glyphs) free(render_priv->text_info.glyphs); + free(render_priv->text_info.glyphs); + free(render_priv->text_info.lines); } /** @@ -1623,12 +1629,11 @@ static void wrap_lines_smart(ass_renderer_t* render_priv, int max_text_width) // need to use one more line // marking break_at+1 as start of a new line int lead = break_at + 1; // the first symbol of the new line - if (text_info->n_lines >= MAX_LINES) { - // to many lines ! - // no more linebreaks - for (j = lead; j < text_info->length; ++j) - text_info->glyphs[j].linebreak = 0; - break; + if (text_info->n_lines >= text_info->max_lines) { + // Raise maximum number of lines + text_info->max_lines *= 2; + text_info->lines = realloc(text_info->lines, + sizeof(line_info_t) * text_info->max_lines); } if (lead < text_info->length) text_info->glyphs[lead].linebreak = break_type; @@ -1934,10 +1939,10 @@ static int ass_render_event(ass_renderer_t* render_priv, ass_event_t* event, eve if (code == 0) break; - if (text_info->length >= MAX_GLYPHS) { - mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_MAX_GLYPHS_Reached, - (int)(event - render_priv->track->events), event->Start, event->Duration, event->Text); - break; + if (text_info->length >= text_info->max_glyphs) { + // Raise maximum number of glyphs + text_info->max_glyphs *= 2; + text_info->glyphs = realloc(text_info->glyphs, sizeof(glyph_info_t) * text_info->max_glyphs); } if ( previous && code ) { |