[FFmpeg-cvslog] drawbox: Respect thickness parameter

Jean Delvare git at videolan.org
Fri Jun 14 04:05:48 CEST 2013


ffmpeg | branch: master | Jean Delvare <khali at linux-fr.org> | Wed Jun 12 10:48:57 2013 +0200| [cef42ded8dd099bfc8de6cfcf75c579d13e582ad] | committer: Michael Niedermayer

drawbox: Respect thickness parameter

The drawbox video filter is drawing lines one pixel thinner than
requested. The default thickness is 4 pixel but in fact the lines
drawn by default are only 3 pixel wide.

Change the comparisons in the code to fix this off-by-one bug. Also
change the default thickness from 4 to 3 to minimize the unexpected
changes from the user's perspective.

As I was already touching these lines, I also removed the "maximum" in
the thickness parameter description, as I don't think it was adding
any value and I even found it confusing.

Reviewed-by: Andrey Utkin <andrey.krieger.utkin at gmail.com>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cef42ded8dd099bfc8de6cfcf75c579d13e582ad
---

 doc/filters.texi         |    2 +-
 libavfilter/vf_drawbox.c |   12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 0381c6a..6e616b2 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2900,7 +2900,7 @@ value @code{invert} is used, the box edge color is the same as the
 video with inverted luma.
 
 @item thickness, t
-Set the thickness of the box edge. Default value is @code{4}.
+Set the thickness of the box edge. Default value is @code{3}.
 @end table
 
 @subsection Examples
diff --git a/libavfilter/vf_drawbox.c b/libavfilter/vf_drawbox.c
index 0cddda4..0148761 100644
--- a/libavfilter/vf_drawbox.c
+++ b/libavfilter/vf_drawbox.c
@@ -114,15 +114,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
 
         if (s->invert_color) {
             for (x = FFMAX(xb, 0); x < xb + s->w && x < frame->width; x++)
-                if ((y - yb < s->thickness-1) || (yb + s->h - y < s->thickness) ||
-                    (x - xb < s->thickness-1) || (xb + s->w - x < s->thickness))
+                if ((y - yb < s->thickness) || (yb + s->h - 1 - y < s->thickness) ||
+                    (x - xb < s->thickness) || (xb + s->w - 1 - x < s->thickness))
                     row[0][x] = 0xff - row[0][x];
         } else {
             for (x = FFMAX(xb, 0); x < xb + s->w && x < frame->width; x++) {
                 double alpha = (double)s->yuv_color[A] / 255;
 
-                if ((y - yb < s->thickness-1) || (yb + s->h - y < s->thickness) ||
-                    (x - xb < s->thickness-1) || (xb + s->w - x < s->thickness)) {
+                if ((y - yb < s->thickness) || (yb + s->h - 1 - y < s->thickness) ||
+                    (x - xb < s->thickness) || (xb + s->w - 1 - x < s->thickness)) {
                     row[0][x                 ] = (1 - alpha) * row[0][x                 ] + alpha * s->yuv_color[Y];
                     row[1][x >> s->hsub] = (1 - alpha) * row[1][x >> s->hsub] + alpha * s->yuv_color[U];
                     row[2][x >> s->hsub] = (1 - alpha) * row[2][x >> s->hsub] + alpha * s->yuv_color[V];
@@ -148,8 +148,8 @@ static const AVOption drawbox_options[] = {
     { "h",         "set height of the box",                        OFFSET(h_opt),     AV_OPT_TYPE_INT, { .i64 = 0 }, 0,       INT_MAX, FLAGS },
     { "color",     "set color of the box",                         OFFSET(color_str), AV_OPT_TYPE_STRING, { .str = "black" }, CHAR_MIN, CHAR_MAX, FLAGS },
     { "c",         "set color of the box",                         OFFSET(color_str), AV_OPT_TYPE_STRING, { .str = "black" }, CHAR_MIN, CHAR_MAX, FLAGS },
-    { "thickness", "set the box maximum thickness",                OFFSET(thickness), AV_OPT_TYPE_INT, {.i64=4}, 0, INT_MAX, FLAGS },
-    { "t",         "set the box maximum thickness",                OFFSET(thickness), AV_OPT_TYPE_INT, {.i64=4}, 0, INT_MAX, FLAGS },
+    { "thickness", "set the box thickness",                        OFFSET(thickness), AV_OPT_TYPE_INT, { .i64 = 3 }, 0,       INT_MAX, FLAGS },
+    { "t",         "set the box thickness",                        OFFSET(thickness), AV_OPT_TYPE_INT, { .i64 = 3 }, 0,       INT_MAX, FLAGS },
     { NULL }
 };
 



More information about the ffmpeg-cvslog mailing list