Commit e496c45d authored by Andrey Utkin's avatar Andrey Utkin Committed by Anton Khirnov

drawtext: add 'fix_bounds' option on coords fixing

Before, drawtext filter deliberately altered given text coordinates if
text didn't fully fit on the picture. This breaks the use case of
scrolling large text, e.g. movie closing credits.
Add 'fix_bounds', to make it usable in such cases (by setting its value to 0).
Default behavior is not changed, and non-fitting text coords are fixed.
Signed-off-by: 's avatarAnton Khirnov <anton@khirnov.net>
parent 2b43dfce
......@@ -598,6 +598,9 @@ libfreetype flags.
@item tabsize
The size in number of spaces to use for rendering the tab.
Default value is 4.
@item fix_bounds
If true, check and fix text coords to avoid clipping.
@end table
For example the command:
......
......@@ -122,6 +122,7 @@ typedef struct {
short int draw_box; ///< draw box around text - true or false
int use_kerning; ///< font kerning is used - true/false
int tabsize; ///< tab size
int fix_bounds; ///< do we let it go out of frame bounds - t/f
FT_Library library; ///< freetype font library handle
FT_Face face; ///< freetype font face handle
......@@ -157,6 +158,8 @@ static const AVOption drawtext_options[]= {
{"shadowy", "set y", OFFSET(shadowy), AV_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX },
{"tabsize", "set tab size", OFFSET(tabsize), AV_OPT_TYPE_INT, {.dbl=4}, 0, INT_MAX },
{"draw", "if false do not draw", OFFSET(d_expr), AV_OPT_TYPE_STRING, {.str="1"}, CHAR_MIN, CHAR_MAX },
{"fix_bounds", "if true, check and fix text coords to avoid clipping",
OFFSET(fix_bounds), AV_OPT_TYPE_INT, {.dbl=1}, 0, 1 },
/* FT_LOAD_* flags */
{"ft_load_flags", "set font loading flags for libfreetype", OFFSET(ft_load_flags), AV_OPT_TYPE_FLAGS, {.dbl=FT_LOAD_DEFAULT|FT_LOAD_RENDER}, 0, INT_MAX, 0, "ft_load_flags" },
......@@ -828,12 +831,14 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
normalize_double(&dtext->x, dtext->var_values[VAR_X]);
normalize_double(&dtext->y, dtext->var_values[VAR_Y]);
if (dtext->x < 0) dtext->x = 0;
if (dtext->y < 0) dtext->y = 0;
if ((unsigned)dtext->x + (unsigned)dtext->w > inlink->w)
dtext->x = inlink->w - dtext->w;
if ((unsigned)dtext->y + (unsigned)dtext->h > inlink->h)
dtext->y = inlink->h - dtext->h;
if (dtext->fix_bounds) {
if (dtext->x < 0) dtext->x = 0;
if (dtext->y < 0) dtext->y = 0;
if ((unsigned)dtext->x + (unsigned)dtext->w > inlink->w)
dtext->x = inlink->w - dtext->w;
if ((unsigned)dtext->y + (unsigned)dtext->h > inlink->h)
dtext->y = inlink->h - dtext->h;
}
dtext->x &= ~((1 << dtext->hsub) - 1);
dtext->y &= ~((1 << dtext->vsub) - 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment