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
262 int bb_right; ///< the size of the right box border262 int bb_right; ///< the size of the right box border
263 int bb_bottom; ///< the size of the bottom box border263 int bb_bottom; ///< the size of the bottom box border
264 int bb_left; ///< the size of the left box border264 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
265 int tabsize; ///< tab size267 int tabsize; ///< tab size
266 int fix_bounds; ///< do we let it go out of frame bounds - t/f268 int fix_bounds; ///< do we let it go out of frame bounds - t/f
267 269
@@ -297,6 +299,9 @@ typedef struct DrawTextContext { · 29 unmodified lines
297#endif299#endif
298 AVDictionary *metadata;300 AVDictionary *metadata;
299 301
302 int boxw; ///< the value of the boxw parameter
303 int boxh; ///< the value of the boxh parameter
304
300 TextLine *lines; ///< computed information about text lines305 TextLine *lines; ///< computed information about text lines
301 int line_count; ///< the number of text lines306 int line_count; ///< the number of text lines
302 uint32_t *tab_clusters; ///< the position of tab characters in the text307 uint32_t *tab_clusters; ///< the position of tab characters in the text
@@ -322,6 +327,8 @@ static const AVOption drawtext_options[]= { · 19 unmodified lines
322 {"fontsize", "set font size", OFFSET(fontsize_expr), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS},327 {"fontsize", "set font size", OFFSET(fontsize_expr), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS},
323 {"x", "set x expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS},328 {"x", "set x expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS},
324 {"y", "set y expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS},329 {"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},
325 {"shadowx", "set shadow x offset", OFFSET(shadowx), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS},332 {"shadowx", "set shadow x offset", OFFSET(shadowx), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS},
326 {"shadowy", "set shadow y offset", OFFSET(shadowy), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS},333 {"shadowy", "set shadow y offset", OFFSET(shadowy), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS},
327 {"borderw", "set border width", OFFSET(borderw), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS},334 {"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
1473 FT_BitmapGlyph b_glyph;1480 FT_BitmapGlyph b_glyph;
1474 int clip_x = 0, clip_y = 0;1481 int clip_x = 0, clip_y = 0;
1475 1482
1476 clip_x = FFMIN(metrics->rect_x + metrics->width + s->bb_right, frame->width);1483 clip_x = FFMIN(metrics->rect_x + s->box_width + s->bb_right, frame->width);
1477 clip_y = FFMIN(metrics->rect_y + metrics->height + s->bb_bottom, frame->height);1484 clip_y = FFMIN(metrics->rect_y + s->box_height + s->bb_bottom, frame->height);
1478 1485
1479 for (l = 0; l < s->line_count; ++l) {1486 for (l = 0; l < s->line_count; ++l) {
1480 TextLine *line = &s->lines[l];1487 TextLine *line = &s->lines[l];
@@ -1907,6 +1914,9 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame) · 426 unmodified lines
1907 metrics.rect_x = s->x;1914 metrics.rect_x = s->x;
1908 metrics.rect_y = s->y;1915 metrics.rect_y = s->y;
1909 1916
1917 s->box_width = s->boxw == 0 ? metrics.width : s->boxw;
1918 s->box_height = s->boxh == 0 ? metrics.height : s->boxh;
1919
1910 if (!s->draw_box) {1920 if (!s->draw_box) {
1911 // Create a border for the clipping region to take into account subpixel1921 // Create a border for the clipping region to take into account subpixel
1912 // errors in text measurement and effects.1922 // errors in text measurement and effects.
@@ -1920,16 +1930,16 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame) · 7 unmodified lines
1920 /* Check if the whole box is out of the frame */1930 /* Check if the whole box is out of the frame */
1921 is_outside = metrics.rect_x - s->bb_left >= width ||1931 is_outside = metrics.rect_x - s->bb_left >= width ||
1922 metrics.rect_y - s->bb_top >= height ||1932 metrics.rect_y - s->bb_top >= height ||
1923 metrics.rect_x + metrics.width + s->bb_right <= 0 ||1933 metrics.rect_x + s->box_width + s->bb_right <= 0 ||
1924 metrics.rect_y + metrics.height + s->bb_bottom <= 0;1934 metrics.rect_y + s->box_height + s->bb_bottom <= 0;
1925 1935
1926 if (!is_outside) {1936 if (!is_outside) {
1927 /* draw box */1937 /* draw box */
1928 if (s->draw_box) {1938 if (s->draw_box) {
1929 rec_x = metrics.rect_x - s->bb_left;1939 rec_x = metrics.rect_x - s->bb_left;
1930 rec_y = metrics.rect_y - s->bb_top;1940 rec_y = metrics.rect_y - s->bb_top;
1931 rec_width = metrics.width + s->bb_right + s->bb_left;1941 rec_width = s->box_width + s->bb_right + s->bb_left;
1932 rec_height = metrics.height + s->bb_bottom + s->bb_top;1942 rec_height = s->box_height + s->bb_bottom + s->bb_top;
1933 ff_blend_rectangle(&s->dc, &boxcolor,1943 ff_blend_rectangle(&s->dc, &boxcolor,
1934 frame->data, frame->linesize, width, height,1944 frame->data, frame->linesize, width, height,
1935 rec_x, rec_y, rec_width, rec_height);1945 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