History

avfilter/vf_drawtext: add options for size of the background box

yethie committed 3 years ago

Commit fac7bb01 parent 79e39972 files · +24 −6Browse files

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/vf_drawtext.c+16−6
@@ -262,6 +262,8 @@ typedef struct DrawTextContext { · 261 unmodified lines
262262 int bb_right; ///< the size of the right box border
263263 int bb_bottom; ///< the size of the bottom box border
264264 int bb_left; ///< the size of the left box border
265+ int box_width; ///< the width of box
266+ int box_height; ///< the height of box
265267 int tabsize; ///< tab size
266268 int fix_bounds; ///< do we let it go out of frame bounds - t/f
267269
@@ -297,6 +299,9 @@ typedef struct DrawTextContext { · 29 unmodified lines
297299 #endif
298300 AVDictionary *metadata;
299301
302+ int boxw; ///< the value of the boxw parameter
303+ int boxh; ///< the value of the boxh parameter
304+
300305 TextLine *lines; ///< computed information about text lines
301306 int line_count; ///< the number of text lines
302307 uint32_t *tab_clusters; ///< the position of tab characters in the text
@@ -322,6 +327,8 @@ static const AVOption drawtext_options[]= { · 19 unmodified lines
322327 {"fontsize", "set font size", OFFSET(fontsize_expr), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS},
323328 {"x", "set x expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS},
324329 {"y", "set y expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS},
330+ {"boxw", "set box width", OFFSET(boxw), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS},
331+ {"boxh", "set box height", OFFSET(boxh), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS},
325332 {"shadowx", "set shadow x offset", OFFSET(shadowx), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS},
326333 {"shadowy", "set shadow y offset", OFFSET(shadowy), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS},
327334 {"borderw", "set border width", OFFSET(borderw), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS},
@@ -1473,8 +1480,8 @@ static int draw_glyphs(DrawTextContext *s, AVFrame *frame, · 1145 unmodified lines
14731480 FT_BitmapGlyph b_glyph;
14741481 int clip_x = 0, clip_y = 0;
14751482
1476− clip_x = FFMIN(metrics->rect_x + metrics->width + s->bb_right, frame->width);
1477− clip_y = FFMIN(metrics->rect_y + metrics->height + s->bb_bottom, frame->height);
1483+ clip_x = FFMIN(metrics->rect_x + s->box_width + s->bb_right, frame->width);
1484+ clip_y = FFMIN(metrics->rect_y + s->box_height + s->bb_bottom, frame->height);
14781485
14791486 for (l = 0; l < s->line_count; ++l) {
14801487 TextLine *line = &s->lines[l];
@@ -1907,6 +1914,9 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame) · 426 unmodified lines
19071914 metrics.rect_x = s->x;
19081915 metrics.rect_y = s->y;
19091916
1917+ s->box_width = s->boxw == 0 ? metrics.width : s->boxw;
1918+ s->box_height = s->boxh == 0 ? metrics.height : s->boxh;
1919+
19101920 if (!s->draw_box) {
19111921 // Create a border for the clipping region to take into account subpixel
19121922 // errors in text measurement and effects.
@@ -1920,16 +1930,16 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame) · 7 unmodified lines
19201930 /* Check if the whole box is out of the frame */
19211931 is_outside = metrics.rect_x - s->bb_left >= width ||
19221932 metrics.rect_y - s->bb_top >= height ||
1923− metrics.rect_x + metrics.width + s->bb_right <= 0 ||
1924− metrics.rect_y + metrics.height + s->bb_bottom <= 0;
1933+ metrics.rect_x + s->box_width + s->bb_right <= 0 ||
1934+ metrics.rect_y + s->box_height + s->bb_bottom <= 0;
19251935
19261936 if (!is_outside) {
19271937 /* draw box */
19281938 if (s->draw_box) {
19291939 rec_x = metrics.rect_x - s->bb_left;
19301940 rec_y = metrics.rect_y - s->bb_top;
1931− rec_width = metrics.width + s->bb_right + s->bb_left;
1932− rec_height = metrics.height + s->bb_bottom + s->bb_top;
1941+ rec_width = s->box_width + s->bb_right + s->bb_left;
1942+ rec_height = s->box_height + s->bb_bottom + s->bb_top;
19331943 ff_blend_rectangle(&s->dc, &boxcolor,
19341944 frame->data, frame->linesize, width, height,
19351945 rec_x, rec_y, rec_width, rec_height);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t