summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Utkin <andrey.krieger.utkin@gmail.com>2012-02-05 14:41:01 +0200
committerAnton Khirnov <anton@khirnov.net>2012-02-06 07:57:40 +0100
commite496c45d9ba58586b3826c0bd9e4be155b8fd1df (patch)
tree98129dc205c70a4b85b7a102ad5179f0d5b678f1
parent2b43dfce3651bc517c66365a30f30b708d6b79af (diff)
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: Anton Khirnov <anton@khirnov.net>
-rw-r--r--doc/filters.texi3
-rw-r--r--libavfilter/vf_drawtext.c17
2 files changed, 14 insertions, 6 deletions
diff --git a/doc/filters.texi b/doc/filters.texi
index 4e7ede23a4..16059fd41d 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -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:
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index f6ce1243e6..5b794dc545 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -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);