diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-02-22 01:11:35 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-02-22 01:49:54 +0100 |
commit | a64a2c5f98d3e2bdc75ac3f30db6d3fe84260436 (patch) | |
tree | 364923c2790044fad0edd0bcb6117d0609763b10 /libavfilter | |
parent | bccea08836ad3e92b43a9770e5156e569103226a (diff) | |
download | ffmpeg-streaming-a64a2c5f98d3e2bdc75ac3f30db6d3fe84260436.zip ffmpeg-streaming-a64a2c5f98d3e2bdc75ac3f30db6d3fe84260436.tar.gz |
factor draw_glyphs out of drawtext filter
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavfilter')
-rw-r--r-- | libavfilter/vf_drawtext.c | 68 |
1 files changed, 41 insertions, 27 deletions
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 95ee5e8..7802208 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -475,13 +475,51 @@ static inline void drawbox(AVFilterBufferRef *picref, unsigned int x, unsigned i } } +static int draw_glyphs(DrawTextContext *dtext, AVFilterBufferRef *picref, + int width, int height) +{ + char *text = dtext->text; + uint32_t code = 0; + int i; + uint8_t *p; + Glyph *glyph = NULL; + + for (i = 0, p = text; *p; i++) { + Glyph dummy = { 0 }; + GET_UTF8(code, *p++, continue;); + + /* skip new line chars, just go to new line */ + if (code == '\n' || code == '\r' || code == '\t') + continue; + + dummy.code = code; + glyph = av_tree_find(dtext->glyphs, &dummy, (void *)glyph_cmp, NULL); + + if (glyph->bitmap.pixel_mode != FT_PIXEL_MODE_MONO && + glyph->bitmap.pixel_mode != FT_PIXEL_MODE_GRAY) + return AVERROR(EINVAL); + + if (dtext->is_packed_rgb) { + draw_glyph_rgb(picref, &glyph->bitmap, + dtext->positions[i].x, dtext->positions[i].y, width, height, + dtext->pixel_step[0], dtext->fontcolor_rgba, dtext->rgba_map); + } else { + draw_glyph_yuv(picref, &glyph->bitmap, + dtext->positions[i].x, dtext->positions[i].y, width, height, + dtext->fontcolor, dtext->hsub, dtext->vsub); + } + } + + return 0; +} + static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref, int width, int height) { DrawTextContext *dtext = ctx->priv; char *text = dtext->text; uint32_t code = 0, prev_code = 0; - int x = 0, y = 0, i = 0; + int x = 0, y = 0, i = 0, ret; int text_height, baseline; uint8_t *p; int str_w, str_w_max; @@ -583,32 +621,8 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref, dtext->hsub, dtext->vsub, dtext->is_packed_rgb, dtext->rgba_map); } - /* draw glyphs */ - for (i = 0, p = text; *p; i++) { - Glyph dummy = { 0 }; - GET_UTF8(code, *p++, continue;); - - /* skip new line chars, just go to new line */ - if (code == '\n' || code == '\r' || code == '\t') - continue; - - dummy.code = code; - glyph = av_tree_find(dtext->glyphs, &dummy, (void *)glyph_cmp, NULL); - - if (glyph->bitmap.pixel_mode != FT_PIXEL_MODE_MONO && - glyph->bitmap.pixel_mode != FT_PIXEL_MODE_GRAY) - return AVERROR(EINVAL); - - if (dtext->is_packed_rgb) { - draw_glyph_rgb(picref, &glyph->bitmap, - dtext->positions[i].x, dtext->positions[i].y, width, height, - dtext->pixel_step[0], dtext->fontcolor_rgba, dtext->rgba_map); - } else { - draw_glyph_yuv(picref, &glyph->bitmap, - dtext->positions[i].x, dtext->positions[i].y, width, height, - dtext->fontcolor, dtext->hsub, dtext->vsub); - } - } + if((ret=draw_glyphs(dtext, picref, width, height))<0) + return ret; return 0; } |