Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
| ... | ... |
@@ -494,12 +494,50 @@ static inline int is_newline(uint32_t c) |
| 494 | 494 |
return (c == '\n' || c == '\r' || c == '\f' || c == '\v'); |
| 495 | 495 |
} |
| 496 | 496 |
|
| 497 |
+static int draw_glyphs(DrawTextContext *dtext, AVFilterBufferRef *picref, |
|
| 498 |
+ int width, int height) |
|
| 499 |
+{
|
|
| 500 |
+ char *text = dtext->text; |
|
| 501 |
+ uint32_t code = 0; |
|
| 502 |
+ int i; |
|
| 503 |
+ uint8_t *p; |
|
| 504 |
+ Glyph *glyph = NULL; |
|
| 505 |
+ |
|
| 506 |
+ for (i = 0, p = text; *p; i++) {
|
|
| 507 |
+ Glyph dummy = { 0 };
|
|
| 508 |
+ GET_UTF8(code, *p++, continue;); |
|
| 509 |
+ |
|
| 510 |
+ /* skip new line chars, just go to new line */ |
|
| 511 |
+ if (code == '\n' || code == '\r' || code == '\t') |
|
| 512 |
+ continue; |
|
| 513 |
+ |
|
| 514 |
+ dummy.code = code; |
|
| 515 |
+ glyph = av_tree_find(dtext->glyphs, &dummy, (void *)glyph_cmp, NULL); |
|
| 516 |
+ |
|
| 517 |
+ if (glyph->bitmap.pixel_mode != FT_PIXEL_MODE_MONO && |
|
| 518 |
+ glyph->bitmap.pixel_mode != FT_PIXEL_MODE_GRAY) |
|
| 519 |
+ return AVERROR(EINVAL); |
|
| 520 |
+ |
|
| 521 |
+ if (dtext->is_packed_rgb) {
|
|
| 522 |
+ draw_glyph_rgb(picref, &glyph->bitmap, |
|
| 523 |
+ dtext->positions[i].x, dtext->positions[i].y, width, height, |
|
| 524 |
+ dtext->pixel_step[0], dtext->fontcolor_rgba, dtext->rgba_map); |
|
| 525 |
+ } else {
|
|
| 526 |
+ draw_glyph_yuv(picref, &glyph->bitmap, |
|
| 527 |
+ dtext->positions[i].x, dtext->positions[i].y, width, height, |
|
| 528 |
+ dtext->fontcolor, dtext->hsub, dtext->vsub); |
|
| 529 |
+ } |
|
| 530 |
+ } |
|
| 531 |
+ |
|
| 532 |
+ return 0; |
|
| 533 |
+} |
|
| 534 |
+ |
|
| 497 | 535 |
static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref, |
| 498 | 536 |
int width, int height) |
| 499 | 537 |
{
|
| 500 | 538 |
DrawTextContext *dtext = ctx->priv; |
| 501 | 539 |
uint32_t code = 0, prev_code = 0; |
| 502 |
- int x = 0, y = 0, i = 0; |
|
| 540 |
+ int x = 0, y = 0, i = 0, ret; |
|
| 503 | 541 |
int text_height, baseline; |
| 504 | 542 |
uint8_t *p; |
| 505 | 543 |
int str_w = 0; |
| ... | ... |
@@ -605,32 +643,8 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref, |
| 605 | 605 |
dtext->box_line, dtext->pixel_step, dtext->boxcolor, |
| 606 | 606 |
dtext->hsub, dtext->vsub, dtext->is_packed_rgb, dtext->rgba_map); |
| 607 | 607 |
|
| 608 |
- /* draw glyphs */ |
|
| 609 |
- for (i = 0, p = dtext->text; *p; i++) {
|
|
| 610 |
- Glyph dummy = { 0 };
|
|
| 611 |
- GET_UTF8(code, *p++, continue;); |
|
| 612 |
- |
|
| 613 |
- /* skip new line chars, just go to new line */ |
|
| 614 |
- if (is_newline(code) || code == ' ' || code == '\t') |
|
| 615 |
- continue; |
|
| 616 |
- |
|
| 617 |
- dummy.code = code; |
|
| 618 |
- glyph = av_tree_find(dtext->glyphs, &dummy, glyph_cmp, NULL); |
|
| 619 |
- |
|
| 620 |
- if (glyph->bitmap.pixel_mode != FT_PIXEL_MODE_MONO && |
|
| 621 |
- glyph->bitmap.pixel_mode != FT_PIXEL_MODE_GRAY) |
|
| 622 |
- return AVERROR(EINVAL); |
|
| 623 |
- |
|
| 624 |
- if (dtext->is_packed_rgb) {
|
|
| 625 |
- draw_glyph_rgb(picref, &glyph->bitmap, |
|
| 626 |
- dtext->positions[i].x, dtext->positions[i].y, width, height, |
|
| 627 |
- dtext->pixel_step[0], dtext->fontcolor_rgba, dtext->rgba_map); |
|
| 628 |
- } else {
|
|
| 629 |
- draw_glyph_yuv(picref, &glyph->bitmap, |
|
| 630 |
- dtext->positions[i].x, dtext->positions[i].y, width, height, |
|
| 631 |
- dtext->fontcolor, dtext->hsub, dtext->vsub); |
|
| 632 |
- } |
|
| 633 |
- } |
|
| 608 |
+ if ((ret = draw_glyphs(dtext, picref, width, height)) < 0) |
|
| 609 |
+ return ret; |
|
| 634 | 610 |
|
| 635 | 611 |
return 0; |
| 636 | 612 |
} |