Revision f9c61974 libavfilter/vf_drawtext.c

View differences:

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

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

  
98 105
/* FT_LOAD_* flags */
......
205 212
    av_opt_set_defaults2(dtext, 0, 0);
206 213
    dtext->fontcolor_string = av_strdup("black");
207 214
    dtext->boxcolor_string = av_strdup("white");
215
    dtext->shadowcolor_string = av_strdup("black");
208 216

  
209 217
    if ((err = (av_set_options_string(dtext, args, "=", ":"))) < 0) {
210 218
        av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
......
257 265
        return err;
258 266
    }
259 267

  
268
    if ((err = av_parse_color(dtext->shadowcolor_rgba, dtext->shadowcolor_string, -1, ctx))) {
269
        av_log(ctx, AV_LOG_ERROR,
270
               "Invalid shadow color '%s'\n", dtext->shadowcolor_string);
271
        return err;
272
    }
273

  
260 274
    if ((err = FT_Init_FreeType(&(dtext->library)))) {
261 275
        av_log(ctx, AV_LOG_ERROR,
262 276
               "Could not load FreeType: %s\n", FT_ERRMSG(err));
......
324 338
    av_freep(&dtext->text);
325 339
    av_freep(&dtext->fontcolor_string);
326 340
    av_freep(&dtext->boxcolor_string);
341
    av_freep(&dtext->shadowcolor_string);
327 342
    av_tree_enumerate(dtext->glyphs, NULL, NULL, glyph_enu_free);
328 343
    av_tree_destroy(dtext->glyphs);
329 344
    dtext->glyphs = 0;
......
359 374
        dtext->fontcolor[1] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0);
360 375
        dtext->fontcolor[2] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0);
361 376
        dtext->fontcolor[3] = rgba[3];
377
        rgba = dtext->shadowcolor_rgba;
378
        dtext->shadowcolor[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]);
379
        dtext->shadowcolor[1] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0);
380
        dtext->shadowcolor[2] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0);
381
        dtext->shadowcolor[3] = rgba[3];
362 382
    }
363 383

  
364 384
    return 0;
......
476 496
}
477 497

  
478 498
static int draw_glyphs(DrawTextContext *dtext, AVFilterBufferRef *picref,
479
                        int width, int height)
499
                       int width, int height, const uint8_t rgbcolor[4], const uint8_t yuvcolor[4], int x, int y)
480 500
{
481 501
    char *text = dtext->text;
482 502
    uint32_t code = 0;
......
501 521

  
502 522
        if (dtext->is_packed_rgb) {
503 523
            draw_glyph_rgb(picref, &glyph->bitmap,
504
                           dtext->positions[i].x, dtext->positions[i].y, width, height,
505
                           dtext->pixel_step[0], dtext->fontcolor_rgba, dtext->rgba_map);
524
                           dtext->positions[i].x+x, dtext->positions[i].y+y, width, height,
525
                           dtext->pixel_step[0], rgbcolor, dtext->rgba_map);
506 526
        } else {
507 527
            draw_glyph_yuv(picref, &glyph->bitmap,
508
                           dtext->positions[i].x, dtext->positions[i].y, width, height,
509
                           dtext->fontcolor, dtext->hsub, dtext->vsub);
528
                           dtext->positions[i].x+x, dtext->positions[i].y+y, width, height,
529
                           yuvcolor, dtext->hsub, dtext->vsub);
510 530
        }
511 531
    }
512 532

  
......
621 641
                dtext->hsub, dtext->vsub, dtext->is_packed_rgb, dtext->rgba_map);
622 642
    }
623 643

  
624
    if((ret=draw_glyphs(dtext, picref, width, height))<0)
644
    if(dtext->shadowx || dtext->shadowy){
645
        if((ret=draw_glyphs(dtext, picref, width, height, dtext->shadowcolor_rgba, dtext->shadowcolor, dtext->shadowx, dtext->shadowy))<0)
646
            return ret;
647
    }
648

  
649
    if((ret=draw_glyphs(dtext, picref, width, height, dtext->fontcolor_rgba, dtext->fontcolor, 0, 0))<0)
625 650
        return ret;
626 651

  
627 652
    return 0;

Also available in: Unified diff