drawtext: factor draw_glyphs.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> Signed-off-by: Anton Khirnov <anton@khirnov.net>
This commit is contained in:
committed by
Anton Khirnov
parent
a5b81c317e
commit
e73127a443
@@ -494,12 +494,50 @@ static inline int is_newline(uint32_t c)
|
|||||||
return (c == '\n' || c == '\r' || c == '\f' || c == '\v');
|
return (c == '\n' || c == '\r' || c == '\f' || c == '\v');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref,
|
||||||
int width, int height)
|
int width, int height)
|
||||||
{
|
{
|
||||||
DrawTextContext *dtext = ctx->priv;
|
DrawTextContext *dtext = ctx->priv;
|
||||||
uint32_t code = 0, prev_code = 0;
|
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;
|
int text_height, baseline;
|
||||||
uint8_t *p;
|
uint8_t *p;
|
||||||
int str_w = 0;
|
int str_w = 0;
|
||||||
@@ -605,32 +643,8 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref,
|
|||||||
dtext->box_line, dtext->pixel_step, dtext->boxcolor,
|
dtext->box_line, dtext->pixel_step, dtext->boxcolor,
|
||||||
dtext->hsub, dtext->vsub, dtext->is_packed_rgb, dtext->rgba_map);
|
dtext->hsub, dtext->vsub, dtext->is_packed_rgb, dtext->rgba_map);
|
||||||
|
|
||||||
/* draw glyphs */
|
if ((ret = draw_glyphs(dtext, picref, width, height)) < 0)
|
||||||
for (i = 0, p = dtext->text; *p; i++) {
|
return ret;
|
||||||
Glyph dummy = { 0 };
|
|
||||||
GET_UTF8(code, *p++, continue;);
|
|
||||||
|
|
||||||
/* skip new line chars, just go to new line */
|
|
||||||
if (is_newline(code) || code == ' ' || code == '\t')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
dummy.code = code;
|
|
||||||
glyph = av_tree_find(dtext->glyphs, &dummy, 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user