Revision c5420f10 libavfilter/vf_drawtext.c

View differences:

libavfilter/vf_drawtext.c
55 55
    char *textfile;                 ///< file with text to be drawn
56 56
    unsigned int x;                 ///< x position to start drawing text
57 57
    unsigned int y;                 ///< y position to start drawing text
58
    int shadowx, shadowy;
58 59
    unsigned int fontsize;          ///< font size to use
59 60
    char *fontcolor_string;         ///< font color as string
60 61
    char *boxcolor_string;          ///< box color as string
62
    char *shadowcolor_string;       ///< shadow color as string
61 63
    uint8_t fontcolor[4];           ///< foreground color
62 64
    uint8_t boxcolor[4];            ///< background color
65
    uint8_t shadowcolor[4];         ///< shadow color
63 66
    uint8_t fontcolor_rgba[4];      ///< foreground color in RGBA
64 67
    uint8_t boxcolor_rgba[4];       ///< background color in RGBA
68
    uint8_t shadowcolor_rgba[4];    ///< shadow color in RGBA
65 69

  
66 70
    short int draw_box;             ///< draw box around text - true or false
67 71
    int use_kerning;                ///< font kerning is used - true/false
......
85 89
{"textfile", "set text file",        OFFSET(textfile),         FF_OPT_TYPE_STRING, 0,  CHAR_MIN, CHAR_MAX },
86 90
{"fontcolor","set foreground color", OFFSET(fontcolor_string), FF_OPT_TYPE_STRING, 0,  CHAR_MIN, CHAR_MAX },
87 91
{"boxcolor", "set box color",        OFFSET(boxcolor_string),  FF_OPT_TYPE_STRING, 0,  CHAR_MIN, CHAR_MAX },
92
{"shadowcolor", "set shadow color",  OFFSET(shadowcolor_string),  FF_OPT_TYPE_STRING, 0,  CHAR_MIN, CHAR_MAX },
88 93
{"box",      "set box",              OFFSET(draw_box),         FF_OPT_TYPE_INT,    0,         0,        1 },
89 94
{"fontsize", "set font size",        OFFSET(fontsize),         FF_OPT_TYPE_INT,   16,         1,       72 },
90 95
{"x",        "set x",                OFFSET(x),                FF_OPT_TYPE_INT,    0,         0,  INT_MAX },
91 96
{"y",        "set y",                OFFSET(y),                FF_OPT_TYPE_INT,    0,         0,  INT_MAX },
97
{"shadowx",  "set x",                OFFSET(shadowx),          FF_OPT_TYPE_INT,    0,   INT_MIN,  INT_MAX },
98
{"shadowy",  "set y",                OFFSET(shadowy),          FF_OPT_TYPE_INT,    0,   INT_MIN,  INT_MAX },
92 99
{"tabsize",  "set tab size",         OFFSET(tabsize),          FF_OPT_TYPE_INT,    4,         0,  INT_MAX },
93 100

  
94 101
/* FT_LOAD_* flags */
......
217 224
    av_opt_set_defaults2(dtext, 0, 0);
218 225
    dtext->fontcolor_string = av_strdup("black");
219 226
    dtext->boxcolor_string = av_strdup("white");
227
    dtext->shadowcolor_string = av_strdup("black");
220 228

  
221 229
    if ((err = (av_set_options_string(dtext, args, "=", ":"))) < 0) {
222 230
        av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
......
269 277
        return err;
270 278
    }
271 279

  
280
    if ((err = av_parse_color(dtext->shadowcolor_rgba, dtext->shadowcolor_string, -1, ctx))) {
281
        av_log(ctx, AV_LOG_ERROR,
282
               "Invalid shadow color '%s'\n", dtext->shadowcolor_string);
283
        return err;
284
    }
285

  
272 286
    if ((err = FT_Init_FreeType(&(dtext->library)))) {
273 287
        av_log(ctx, AV_LOG_ERROR,
274 288
               "Could not load FreeType: %s\n", FT_ERRMSG(err));
......
338 352
    av_freep(&dtext->fontcolor_string);
339 353
    av_freep(&dtext->boxcolor_string);
340 354
    av_freep(&dtext->positions);
355
    av_freep(&dtext->shadowcolor_string);
341 356
    av_tree_enumerate(dtext->glyphs, NULL, NULL, glyph_enu_free);
342 357
    av_tree_destroy(dtext->glyphs);
343 358
    dtext->glyphs = 0;
......
373 388
        dtext->fontcolor[1] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0);
374 389
        dtext->fontcolor[2] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0);
375 390
        dtext->fontcolor[3] = rgba[3];
391
        rgba = dtext->shadowcolor_rgba;
392
        dtext->shadowcolor[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]);
393
        dtext->shadowcolor[1] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0);
394
        dtext->shadowcolor[2] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0);
395
        dtext->shadowcolor[3] = rgba[3];
376 396
    }
377 397

  
378 398
    return 0;
......
495 515
}
496 516

  
497 517
static int draw_glyphs(DrawTextContext *dtext, AVFilterBufferRef *picref,
498
                        int width, int height)
518
                       int width, int height, const uint8_t rgbcolor[4], const uint8_t yuvcolor[4], int x, int y)
499 519
{
500 520
    char *text = dtext->text;
501 521
    uint32_t code = 0;
......
520 540

  
521 541
        if (dtext->is_packed_rgb) {
522 542
            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);
543
                           dtext->positions[i].x+x, dtext->positions[i].y+y, width, height,
544
                           dtext->pixel_step[0], rgbcolor, dtext->rgba_map);
525 545
        } else {
526 546
            draw_glyph_yuv(picref, &glyph->bitmap,
527
                           dtext->positions[i].x, dtext->positions[i].y, width, height,
528
                           dtext->fontcolor, dtext->hsub, dtext->vsub);
547
                           dtext->positions[i].x+x, dtext->positions[i].y+y, width, height,
548
                           yuvcolor, dtext->hsub, dtext->vsub);
529 549
        }
530 550
    }
531 551

  
......
643 663
                dtext->box_line, dtext->pixel_step, dtext->boxcolor,
644 664
                dtext->hsub, dtext->vsub, dtext->is_packed_rgb, dtext->rgba_map);
645 665

  
646
    if ((ret = draw_glyphs(dtext, picref, width, height)) < 0)
666
    if (dtext->shadowx || dtext->shadowy) {
667
        if ((ret = draw_glyphs(dtext, picref, width, height, dtext->shadowcolor_rgba,
668
                               dtext->shadowcolor, dtext->shadowx, dtext->shadowy)) < 0)
669
            return ret;
670
    }
671

  
672
    if ((ret = draw_glyphs(dtext, picref, width, height, dtext->fontcolor_rgba,
673
                           dtext->fontcolor, 0, 0)) < 0)
647 674
        return ret;
648 675

  
649 676
    return 0;

Also available in: Unified diff