>From 9c79b787f828e0335f511fef9d7ec7b5a3fc7a4d Mon Sep 17 00:00:00 2001
From: Andrey Utkin <[email protected]>
Date: Fri, 3 Feb 2012 21:39:52 +0200
Subject: [PATCH 1/4] drawtext: Fix if block

---
 libavfilter/vf_drawtext.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index 060c3a4..4c4ad5e 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -493,8 +493,10 @@ static int dtext_prepare_text(AVFilterContext *ctx)
         dummy.code = code;
         glyph = av_tree_find(dtext->glyphs, &dummy, glyph_cmp, NULL);
         if (!glyph)
+        {
             ret = load_glyph(ctx, &glyph, code);
-        if (ret) return ret;
+            if (ret) return ret;
+        }

         y_min = FFMIN(glyph->bbox.yMin, y_min);
         y_max = FFMAX(glyph->bbox.yMax, y_max);
-- 
1.7.3.4

>From 222e439340802d3b595eabffdf839c3c419e9744 Mon Sep 17 00:00:00 2001
From: Andrey Utkin <[email protected]>
Date: Sat, 4 Feb 2012 18:35:28 +0200
Subject: [PATCH 2/4] 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 4c4ad5e..6373129 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.3.4

>From 91f6c10703123464ec4df3a500c5927b43dd16af Mon Sep 17 00:00:00 2001
From: Andrey Utkin <[email protected]>
Date: Sat, 4 Feb 2012 18:49:28 +0200
Subject: [PATCH 3/4] 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 6373129..66ffc13 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 (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);
-- 
1.7.3.4

>From 77b283c1f044881866f54ea767602d688b603538 Mon Sep 17 00:00:00 2001
From: Andrey Utkin <[email protected]>
Date: Sat, 4 Feb 2012 18:54:07 +0200
Subject: [PATCH 4/4] 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 66ffc13..106405a 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 (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;
+        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.3.4



-- 
Andrey Utkin
From 9c79b787f828e0335f511fef9d7ec7b5a3fc7a4d Mon Sep 17 00:00:00 2001
From: Andrey Utkin <[email protected]>
Date: Fri, 3 Feb 2012 21:39:52 +0200
Subject: [PATCH 1/4] drawtext: Fix if block

---
 libavfilter/vf_drawtext.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index 060c3a4..4c4ad5e 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -493,8 +493,10 @@ static int dtext_prepare_text(AVFilterContext *ctx)
         dummy.code = code;
         glyph = av_tree_find(dtext->glyphs, &dummy, glyph_cmp, NULL);
         if (!glyph)
+        {
             ret = load_glyph(ctx, &glyph, code);
-        if (ret) return ret;
+            if (ret) return ret;
+        }
 
         y_min = FFMIN(glyph->bbox.yMin, y_min);
         y_max = FFMAX(glyph->bbox.yMax, y_max);
-- 
1.7.3.4

From 222e439340802d3b595eabffdf839c3c419e9744 Mon Sep 17 00:00:00 2001
From: Andrey Utkin <[email protected]>
Date: Sat, 4 Feb 2012 18:35:28 +0200
Subject: [PATCH 2/4] 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 4c4ad5e..6373129 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.3.4

From 91f6c10703123464ec4df3a500c5927b43dd16af Mon Sep 17 00:00:00 2001
From: Andrey Utkin <[email protected]>
Date: Sat, 4 Feb 2012 18:49:28 +0200
Subject: [PATCH 3/4] 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 6373129..66ffc13 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 (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);
-- 
1.7.3.4

From 77b283c1f044881866f54ea767602d688b603538 Mon Sep 17 00:00:00 2001
From: Andrey Utkin <[email protected]>
Date: Sat, 4 Feb 2012 18:54:07 +0200
Subject: [PATCH 4/4] 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 66ffc13..106405a 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 (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;
+        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.3.4

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to