Sorry, i don't know ATM how to send git patches in a way other people do (i use gmail thru browser). Advices are appreciated.
Rationale for patch 2 is the use case of scrolling "credits" file, like in movies. >From 2b45d4026fe5263126d8ca36417300fa8d5955f1 Mon Sep 17 00:00:00 2001 From: Andrey Utkin <[email protected]> Date: Sat, 4 Feb 2012 18:35:28 +0200 Subject: [PATCH 1/3] drawtext: fix text_{w,h} expression vars Before, {text_,}{w,h} vars hadn't got initialized --- libavfilter/vf_drawtext.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 760981b..6edd123 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -550,7 +550,9 @@ static int dtext_prepare_text(AVFilterContext *ctx) y = FFMIN(y + text_height, height - 1); dtext->w = str_w; + dtext->var_values[VAR_TEXT_W] = dtext->var_values[VAR_TW] = dtext->w; dtext->h = y; + dtext->var_values[VAR_TEXT_H] = dtext->var_values[VAR_TH] = dtext->h; return 0; } -- 1.7.7 >From a89386126e3879ad05bfeed9a551d923fe2273cd Mon Sep 17 00:00:00 2001 From: Andrey Utkin <[email protected]> Date: Sat, 4 Feb 2012 18:49:28 +0200 Subject: [PATCH 2/3] drawtext: optionize behavior on coords fixing --- libavfilter/vf_drawtext.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 6edd123..8a2b9a3 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 }, +{"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 (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); -- 1.7.7 >From bb70363d01582226ad78be1ac218f152504d52c0 Mon Sep 17 00:00:00 2001 From: Andrey Utkin <[email protected]> Date: Sat, 4 Feb 2012 18:54:07 +0200 Subject: [PATCH 3/3] drawtext: cosmetics: indentation for previous commit --- libavfilter/vf_drawtext.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 8a2b9a3..fea28c5 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -832,12 +832,12 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) normalize_double(&dtext->y, dtext->var_values[VAR_Y]); if (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; + 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); -- 1.7.7 -- Andrey Utkin
From 2b45d4026fe5263126d8ca36417300fa8d5955f1 Mon Sep 17 00:00:00 2001 From: Andrey Utkin <[email protected]> Date: Sat, 4 Feb 2012 18:35:28 +0200 Subject: [PATCH 1/3] drawtext: fix text_{w,h} expression vars Before, {text_,}{w,h} vars hadn't got initialized --- libavfilter/vf_drawtext.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 760981b..6edd123 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -550,7 +550,9 @@ static int dtext_prepare_text(AVFilterContext *ctx) y = FFMIN(y + text_height, height - 1); dtext->w = str_w; + dtext->var_values[VAR_TEXT_W] = dtext->var_values[VAR_TW] = dtext->w; dtext->h = y; + dtext->var_values[VAR_TEXT_H] = dtext->var_values[VAR_TH] = dtext->h; return 0; } -- 1.7.7
From a89386126e3879ad05bfeed9a551d923fe2273cd Mon Sep 17 00:00:00 2001 From: Andrey Utkin <[email protected]> Date: Sat, 4 Feb 2012 18:49:28 +0200 Subject: [PATCH 2/3] drawtext: optionize behavior on coords fixing --- libavfilter/vf_drawtext.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 6edd123..8a2b9a3 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 }, +{"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 (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); -- 1.7.7
From bb70363d01582226ad78be1ac218f152504d52c0 Mon Sep 17 00:00:00 2001 From: Andrey Utkin <[email protected]> Date: Sat, 4 Feb 2012 18:54:07 +0200 Subject: [PATCH 3/3] drawtext: cosmetics: indentation for previous commit --- libavfilter/vf_drawtext.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 8a2b9a3..fea28c5 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -832,12 +832,12 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) normalize_double(&dtext->y, dtext->var_values[VAR_Y]); if (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; + 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); -- 1.7.7
_______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
