Hi again,

Am 19.03.19 um 17:31 schrieb Carl Eugen Hoyos:
> One run is not good.
> Either use the loop option to filter the same frame again and
> again or feed a video to ffmpeg.

I have new patches.

Patch 1 is just a little renaming and a preparation for the benchmark
timer code.

Patch 2 is a slight enhancement in performance for cases, where only top
and bottom borders are filled.

Patch 3 beautifies the code an really enhances the performance. See the
results included in the benchmark patch

-Ulf

>From d78d496c0ed7ba83bf113d3f9cf5d68ce62ce4eb Mon Sep 17 00:00:00 2001
From: Ulf Zibis <ulf.zi...@cosoco.de>
Date: 14.03.2019, 19:34:03

avfilter/fillborders: added comments; named more descriptive; corrected indentations;
moved fillborders_options[] more up, needed for STOP_TIMER(testcase);

diff --git a/libavfilter/vf_fillborders.c b/libavfilter/vf_fillborders.c
index 1344587..ce768d4 100644
--- a/libavfilter/vf_fillborders.c
+++ b/libavfilter/vf_fillborders.c
@@ -19,14 +19,16 @@
  */
 
 #include "libavutil/colorspace.h"
-#include "libavutil/common.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
-#include "avfilter.h"
 #include "drawutils.h"
-#include "formats.h"
 #include "internal.h"
+/*
+#include "libavutil/common.h"
+#include "avfilter.h"
+#include "formats.h"
 #include "video.h"
+*/
 
 enum { Y, U, V, A };
 enum { R, G, B };
@@ -53,6 +55,22 @@
 
     void (*fillborders)(struct FillBordersContext *s, AVFrame *frame);
 } FillBordersContext;
+
+#define OFFSET(x) offsetof(FillBordersContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+
+static const AVOption fillborders_options[] = {
+    { "left",   "set the left fill border",   OFFSET(left),   AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,    FLAGS },
+    { "right",  "set the right fill border",  OFFSET(right),  AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,    FLAGS },
+    { "top",    "set the top fill border",    OFFSET(top),    AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,    FLAGS },
+    { "bottom", "set the bottom fill border", OFFSET(bottom), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,    FLAGS },
+    { "mode",   "set the fill borders mode",  OFFSET(mode),   AV_OPT_TYPE_INT, {.i64=FM_SMEAR}, 0, FM_NB_MODES-1, FLAGS, "mode" },
+        { "smear",  NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_SMEAR},  0, 0, FLAGS, "mode" },
+        { "mirror", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_MIRROR}, 0, 0, FLAGS, "mode" },
+        { "fixed",  NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_FIXED},  0, 0, FLAGS, "mode" },
+    { "color",  "set the color for the fixed mode", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS },
+    { NULL }
+};
 
 static int query_formats(AVFilterContext *ctx)
 {
@@ -87,27 +105,28 @@
     int p, y;
 
     for (p = 0; p < s->nb_planes; p++) {
-        uint8_t *ptr = frame->data[p];
+        uint8_t *data = frame->data[p];
         int linesize = frame->linesize[p];
 
+        /* fill left and right borders from top to bottom border */
         for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-            memset(ptr + y * linesize,
-                   *(ptr + y * linesize + s->borders[p].left),
-                   s->borders[p].left);
-            memset(ptr + y * linesize + s->planewidth[p] - s->borders[p].right,
-                   *(ptr + y * linesize + s->planewidth[p] - s->borders[p].right - 1),
-                   s->borders[p].right);
+            memset(data + y * linesize,
+                    *(data + y * linesize + s->borders[p].left),
+                    s->borders[p].left);
+            memset(data + y * linesize + s->planewidth[p] - s->borders[p].right,
+                    *(data + y * linesize + s->planewidth[p] - s->borders[p].right - 1),
+                    s->borders[p].right);
         }
 
+        /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
-            memcpy(ptr + y * linesize,
-                   ptr + s->borders[p].top * linesize, s->planewidth[p]);
+            memcpy(data + y * linesize,
+                    data + s->borders[p].top * linesize, s->planewidth[p]);
         }
-
         for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
-            memcpy(ptr + y * linesize,
-                   ptr + (s->planeheight[p] - s->borders[p].bottom - 1) * linesize,
-                   s->planewidth[p]);
+            memcpy(data + y * linesize,
+                    data + (s->planeheight[p] - s->borders[p].bottom - 1) * linesize,
+                    s->planewidth[p]);
         }
     }
 }
@@ -117,29 +136,29 @@
     int p, y, x;
 
     for (p = 0; p < s->nb_planes; p++) {
-        uint16_t *ptr = (uint16_t *)frame->data[p];
-        int linesize = frame->linesize[p] / 2;
+        uint16_t *data = (uint16_t *)frame->data[p];
+        int linesize = frame->linesize[p] / sizeof(uint16_t);
 
+        /* fill left and right borders from top to bottom border */
         for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
             for (x = 0; x < s->borders[p].left; x++) {
-                ptr[y * linesize + x] =  *(ptr + y * linesize + s->borders[p].left);
+                data[y * linesize + x] = *(data + y * linesize + s->borders[p].left);
             }
-
             for (x = 0; x < s->borders[p].right; x++) {
-                ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                   *(ptr + y * linesize + s->planewidth[p] - s->borders[p].right - 1);
+                data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
+                    *(data + y * linesize + s->planewidth[p] - s->borders[p].right - 1);
             }
         }
 
+        /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
-            memcpy(ptr + y * linesize,
-                   ptr + s->borders[p].top * linesize, s->planewidth[p] * 2);
+            memcpy(data + y * linesize,
+                    data + s->borders[p].top * linesize, s->planewidth[p] * sizeof(uint16_t));
         }
-
         for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
-            memcpy(ptr + y * linesize,
-                   ptr + (s->planeheight[p] - s->borders[p].bottom - 1) * linesize,
-                   s->planewidth[p] * 2);
+            memcpy(data + y * linesize,
+                    data + (s->planeheight[p] - s->borders[p].bottom - 1) * linesize,
+                    s->planewidth[p] * sizeof(uint16_t));
         }
     }
 }
@@ -149,30 +168,30 @@
     int p, y, x;
 
     for (p = 0; p < s->nb_planes; p++) {
-        uint8_t *ptr = frame->data[p];
+        uint8_t *data = frame->data[p];
         int linesize = frame->linesize[p];
 
+        /* fill left and right borders from top to bottom border */
         for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
             for (x = 0; x < s->borders[p].left; x++) {
-                ptr[y * linesize + x] = ptr[y * linesize + s->borders[p].left * 2 - 1 - x];
+                data[y * linesize + x] = data[y * linesize + s->borders[p].left * 2 - 1 - x];
             }
-
             for (x = 0; x < s->borders[p].right; x++) {
-                ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                    ptr[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
+                data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
+                    data[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
             }
         }
 
+        /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
-            memcpy(ptr + y * linesize,
-                   ptr + (s->borders[p].top * 2 - 1 - y) * linesize,
-                   s->planewidth[p]);
+            memcpy(data + y * linesize,
+                    data + (s->borders[p].top * 2 - 1 - y) * linesize,
+                    s->planewidth[p]);
         }
-
         for (y = 0; y < s->borders[p].bottom; y++) {
-            memcpy(ptr + (s->planeheight[p] - s->borders[p].bottom + y) * linesize,
-                   ptr + (s->planeheight[p] - s->borders[p].bottom - 1 - y) * linesize,
-                   s->planewidth[p]);
+            memcpy(data + (s->planeheight[p] - s->borders[p].bottom + y) * linesize,
+                    data + (s->planeheight[p] - s->borders[p].bottom - 1 - y) * linesize,
+                    s->planewidth[p]);
         }
     }
 }
@@ -182,30 +201,31 @@
     int p, y, x;
 
     for (p = 0; p < s->nb_planes; p++) {
-        uint16_t *ptr = (uint16_t *)frame->data[p];
-        int linesize = frame->linesize[p] / 2;
+        uint16_t *data = (uint16_t *)frame->data[p];
+        int linesize = frame->linesize[p] / sizeof(uint16_t);
 
+        /* fill left and right borders from top to bottom border */
         for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
             for (x = 0; x < s->borders[p].left; x++) {
-                ptr[y * linesize + x] = ptr[y * linesize + s->borders[p].left * 2 - 1 - x];
+                data[y * linesize + x] = data[y * linesize + s->borders[p].left * 2 - 1 - x];
             }
 
             for (x = 0; x < s->borders[p].right; x++) {
-                ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                    ptr[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
+                data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
+                    data[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
             }
         }
 
+        /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
-            memcpy(ptr + y * linesize,
-                   ptr + (s->borders[p].top * 2 - 1 - y) * linesize,
-                   s->planewidth[p] * 2);
+            memcpy(data + y * linesize,
+                    data + (s->borders[p].top * 2 - 1 - y) * linesize,
+                    s->planewidth[p] * sizeof(uint16_t));
         }
-
         for (y = 0; y < s->borders[p].bottom; y++) {
-            memcpy(ptr + (s->planeheight[p] - s->borders[p].bottom + y) * linesize,
-                   ptr + (s->planeheight[p] - s->borders[p].bottom - 1 - y) * linesize,
-                   s->planewidth[p] * 2);
+            memcpy(data + (s->planeheight[p] - s->borders[p].bottom + y) * linesize,
+                    data + (s->planeheight[p] - s->borders[p].bottom - 1 - y) * linesize,
+                    s->planewidth[p] * sizeof(uint16_t));
         }
     }
 }
@@ -215,22 +235,23 @@
     int p, y;
 
     for (p = 0; p < s->nb_planes; p++) {
-        uint8_t *ptr = frame->data[p];
+        uint8_t *data = frame->data[p];
         uint8_t fill = s->fill[p];
         int linesize = frame->linesize[p];
 
+        /* fill left and right borders from top to bottom border */
         for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-            memset(ptr + y * linesize, fill, s->borders[p].left);
-            memset(ptr + y * linesize + s->planewidth[p] - s->borders[p].right, fill,
-                   s->borders[p].right);
+            memset(data + y * linesize, fill, s->borders[p].left);
+            memset(data + y * linesize + s->planewidth[p] - s->borders[p].right, fill,
+                    s->borders[p].right);
         }
 
+        /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
-            memset(ptr + y * linesize, fill, s->planewidth[p]);
+            memset(data + y * linesize, fill, s->planewidth[p]);
         }
-
         for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
-            memset(ptr + y * linesize, fill, s->planewidth[p]);
+            memset(data + y * linesize, fill, s->planewidth[p]);
         }
     }
 }
@@ -240,41 +261,32 @@
     int p, y, x;
 
     for (p = 0; p < s->nb_planes; p++) {
-        uint16_t *ptr = (uint16_t *)frame->data[p];
+        uint16_t *data = (uint16_t *)frame->data[p];
         uint16_t fill = s->fill[p] << (s->depth - 8);
-        int linesize = frame->linesize[p] / 2;
+        int linesize = frame->linesize[p] / sizeof(uint16_t);
 
+        /* fill left and right borders from top to bottom border */
         for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
             for (x = 0; x < s->borders[p].left; x++) {
-                ptr[y * linesize + x] = fill;
+                data[y * linesize + x] = fill;
             }
-
             for (x = 0; x < s->borders[p].right; x++) {
-                ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] = fill;
+                data[y * linesize + s->planewidth[p] - s->borders[p].right + x] = fill;
             }
         }
 
+        /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
             for (x = 0; x < s->planewidth[p]; x++) {
-                ptr[y * linesize + x] = fill;
+                data[y * linesize + x] = fill;
             }
         }
-
         for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
             for (x = 0; x < s->planewidth[p]; x++) {
-                ptr[y * linesize + x] = fill;
+                data[y * linesize + x] = fill;
             }
         }
     }
-}
-
-static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
-{
-    FillBordersContext *s = inlink->dst->priv;
-
-    s->fillborders(s, frame);
-
-    return ff_filter_frame(inlink->dst->outputs[0], frame);
 }
 
 static int config_input(AVFilterLink *inlink)
@@ -345,21 +357,14 @@
     return 0;
 }
 
-#define OFFSET(x) offsetof(FillBordersContext, x)
-#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
+{
+    FillBordersContext *s = inlink->dst->priv;
 
-static const AVOption fillborders_options[] = {
-    { "left",   "set the left fill border",   OFFSET(left),   AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,    FLAGS },
-    { "right",  "set the right fill border",  OFFSET(right),  AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,    FLAGS },
-    { "top",    "set the top fill border",    OFFSET(top),    AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,    FLAGS },
-    { "bottom", "set the bottom fill border", OFFSET(bottom), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,    FLAGS },
-    { "mode",   "set the fill borders mode",  OFFSET(mode),   AV_OPT_TYPE_INT, {.i64=FM_SMEAR}, 0, FM_NB_MODES-1, FLAGS, "mode" },
-        { "smear",  NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_SMEAR},  0, 0, FLAGS, "mode" },
-        { "mirror", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_MIRROR}, 0, 0, FLAGS, "mode" },
-        { "fixed",  NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_FIXED},  0, 0, FLAGS, "mode" },
-    { "color",  "set the color for the fixed mode", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS },
-    { NULL }
-};
+    s->fillborders(s, frame);
+
+    return ff_filter_frame(inlink->dst->outputs[0], frame);
+}
 
 AVFILTER_DEFINE_CLASS(fillborders);
 
>From 0e5acdd89a5d7ac3dc501e9ebe7a7b4fda727cf1 Mon Sep 17 00:00:00 2001
From: Ulf Zibis <ulf.zi...@cosoco.de>
Date: 23.03.2019, 17:06:57

avfilter/fillborders: added benchmark timer and samples

diff --git a/debug/16.jpg b/debug/16.jpg
new file mode 100644
index 0000000..a4feeb1
--- /dev/null
+++ b/debug/16.jpg
Binary files differ
diff --git a/debug/8.jpg b/debug/8.jpg
new file mode 100644
index 0000000..d6226ec
--- /dev/null
+++ b/debug/8.jpg
Binary files differ
diff --git a/debug/CYD_1.5m_x264.mp4 b/debug/CYD_1.5m_x264.mp4
new file mode 100755
index 0000000..414f2c6
--- /dev/null
+++ b/debug/CYD_1.5m_x264.mp4
Binary files differ
diff --git a/debug/CYD_1005.jpg b/debug/CYD_1005.jpg
new file mode 100755
index 0000000..89058a3
--- /dev/null
+++ b/debug/CYD_1005.jpg
Binary files differ
diff --git a/debug/fillborders.sh b/debug/fillborders.sh
new file mode 100755
index 0000000..ec33bb5
--- /dev/null
+++ b/debug/fillborders.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+i=0
+test[i++]="3-plane 8-bit  YUV-420:   CYD_1.5m_x264.mp4"
+#test[i++]="3-plane 8-bit  YUV-420:   CYD_1005.jpg"
+#test[i++]="1-plane 8-bit  Y-400:     8.jpg"
+test[i++]="1-plane 16-bit Y-400:     16.jpg"
+#test[i++]="4-plane 16-bit RGB-444:   rgba64le-lzw.tif"
+
+for ((i=0;i<${#test[@]};i++))
+do
+    echo "Test[$i] ======> ${test[i]} <======"
+    file=${test[i]##* }
+#    file="CYD_6m_H.264 (Kopie).mp4"
+    mode="mirror"
+    #mode="fixed:green"
+    for borders in "0:0:5:5" "5:5:0:0" "5:5:5:5"
+    do
+        input="debug/${file}"
+        output="debug/ZZ_${file%.*}_${mode%:*}-${borders//:/-}.${file##*.}"
+        for patch in "ffmpeg" "./ffmpeg-p1"
+        do
+            echo "${patch} : ${input} --> ${output}"
+            if [ $(ffprobe -v error -of default=nk=1:nw=1 -show_entries format=format_name "${input}") == "image2" ]
+                then
+                    ${patch} -y -v error -i "${input}" -vf loop=loop=1024:size=1:start=0,fillborders=${borders}:${mode} -f null -
+                else
+                    ${patch} -y -v error -i "${input}" -vf fillborders=${borders}:${mode} -f null -
+#                    ${patch} -y -v error -i "${input}" -vf fillborders=${borders}:${mode} "${output}"
+            fi
+        done
+    done
+done
diff --git a/debug/rgba64le-lzw.tif b/debug/rgba64le-lzw.tif
new file mode 100644
index 0000000..265ca9d
--- /dev/null
+++ b/debug/rgba64le-lzw.tif
Binary files differ
diff --git a/libavfilter/vf_fillborders.c b/libavfilter/vf_fillborders.c
index ce768d4..00c1888 100644
--- a/libavfilter/vf_fillborders.c
+++ b/libavfilter/vf_fillborders.c
@@ -289,6 +289,8 @@
     }
 }
 
+static char testcase[128];
+
 static int config_input(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
@@ -354,6 +356,10 @@
         memcpy(s->fill, s->yuv_color, sizeof(s->yuv_color));
     }
 
+    sprintf(testcase, "fillborders=%d:%d:%d:%d:%s %dp-%dbit-%dx%d",
+            s->left, s->right, s->top, s->bottom, fillborders_options[5 + s->mode].name,
+            s->nb_planes, s->depth, desc->log2_chroma_w, desc->log2_chroma_h);
+
     return 0;
 }
 
@@ -361,8 +367,12 @@
 {
     FillBordersContext *s = inlink->dst->priv;
 
+    START_TIMER
+
     s->fillborders(s, frame);
 
+    STOP_TIMER(testcase)
+
     return ff_filter_frame(inlink->dst->outputs[0], frame);
 }
 
>From 6a8759efffe79ebddc05e767f799749331664e2c Mon Sep 17 00:00:00 2001
From: Ulf Zibis <ulf.zi...@cosoco.de>
Date: 23.03.2019, 17:12:21

avfilter/fillborders: avoid needless calculations for performance

diff --git a/debug/Benchmark_P1-P2.log b/debug/Benchmark_P1-P2.log
new file mode 100644
index 0000000..62bc3bb
--- /dev/null
+++ b/debug/Benchmark_P1-P2.log
@@ -0,0 +1,153 @@
+Test[0] ======> 3-plane 8-bit  YUV-420:   CYD_1.5m_x264.mp4 <======
+./ffmpeg-p1 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-0-0-5-5.mp4
+ 140220 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1 runs,      0 skips
+ 129195 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       2 runs,      0 skips
+ 130095 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       4 runs,      0 skips
+ 130432 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       8 runs,      0 skips
+ 134617 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      16 runs,      0 skips
+ 132586 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      32 runs,      0 skips
+ 134611 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      64 runs,      0 skips
+ 133402 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     128 runs,      0 skips
+ 133068 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     255 runs,      1 skips
+ 132042 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     511 runs,      1 skips
+ 132217 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,    1023 runs,      1 skips
+ 132853 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,    2047 runs,      1 skips
+./ffmpeg-p2 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-0-0-5-5.mp4
+ 121860 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1 runs,      0 skips
+ 119430 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       2 runs,      0 skips
+ 123840 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       4 runs,      0 skips
+ 124818 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       8 runs,      0 skips
+ 127125 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      16 runs,      0 skips
+ 128950 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      32 runs,      0 skips
+ 129653 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      64 runs,      0 skips
+ 129835 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     128 runs,      0 skips
+ 128759 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     256 runs,      0 skips
+ 128895 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     512 runs,      0 skips
+ 127821 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,    1024 runs,      0 skips
+ 128850 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,    2047 runs,      1 skips
+./ffmpeg-p1 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-5-5-0-0.mp4
+ 565920 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1 runs,      0 skips
+ 572175 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       2 runs,      0 skips
+ 626490 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       3 runs,      1 skips
+ 818254 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       7 runs,      1 skips
+ 736338 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      15 runs,      1 skips
+ 716899 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      31 runs,      1 skips
+ 731955 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      63 runs,      1 skips
+ 749510 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     127 runs,      1 skips
+ 735916 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     255 runs,      1 skips
+ 733472 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     510 runs,      2 skips
+ 728824 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,    1021 runs,      3 skips
+ 728497 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,    2042 runs,      6 skips
+./ffmpeg-p2 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-5-5-0-0.mp4
+ 494820 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1 runs,      0 skips
+ 552330 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       2 runs,      0 skips
+ 613845 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       4 runs,      0 skips
+ 646110 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       8 runs,      0 skips
+ 661494 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      16 runs,      0 skips
+ 668376 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      32 runs,      0 skips
+ 673538 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      64 runs,      0 skips
+ 696244 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     128 runs,      0 skips
+ 706868 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     254 runs,      2 skips
+ 703372 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     510 runs,      2 skips
+ 699808 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,    1021 runs,      3 skips
+ 696951 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,    2040 runs,      8 skips
+./ffmpeg-p1 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-5-5-5-5.mp4
+ 676710 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1 runs,      0 skips
+ 667440 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       2 runs,      0 skips
+ 720990 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       4 runs,      0 skips
+ 736335 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       8 runs,      0 skips
+ 724578 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      16 runs,      0 skips
+ 754832 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      31 runs,      1 skips
+ 770582 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      63 runs,      1 skips
+ 749747 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     127 runs,      1 skips
+ 771069 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     255 runs,      1 skips
+ 755564 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     509 runs,      3 skips
+ 758909 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,    1021 runs,      3 skips
+ 755436 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,    2040 runs,      8 skips
+./ffmpeg-p2 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-5-5-5-5.mp4
+ 785790 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1 runs,      0 skips
+ 693135 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       2 runs,      0 skips
+ 796117 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       4 runs,      0 skips
+ 796410 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       8 runs,      0 skips
+ 797518 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      16 runs,      0 skips
+ 785742 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      32 runs,      0 skips
+ 793428 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      64 runs,      0 skips
+ 770551 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     128 runs,      0 skips
+ 773889 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     256 runs,      0 skips
+ 778019 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     511 runs,      1 skips
+ 775368 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,    1020 runs,      4 skips
+ 771539 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,    2041 runs,      7 skips
+Test[1] ======> 1-plane 16-bit Y-400:     16.jpg <======
+./ffmpeg-p1 : debug/16.jpg --> debug/ZZ_16_mirror-0-0-5-5.jpg
+  56160 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       1 runs,      0 skips
+  67275 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       2 runs,      0 skips
+  64012 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       4 runs,      0 skips
+  63427 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       8 runs,      0 skips
+  61003 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      16 runs,      0 skips
+  59037 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      32 runs,      0 skips
+  63504 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      64 runs,      0 skips
+  62137 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     128 runs,      0 skips
+  63069 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     256 runs,      0 skips
+  62824 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     512 runs,      0 skips
+  61802 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,    1024 runs,      0 skips
+./ffmpeg-p2 : debug/16.jpg --> debug/ZZ_16_mirror-0-0-5-5.jpg
+  80460 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       1 runs,      0 skips
+  86400 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       2 runs,      0 skips
+  77760 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       4 runs,      0 skips
+  66701 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       8 runs,      0 skips
+  60508 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      16 runs,      0 skips
+  59760 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      32 runs,      0 skips
+  59035 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      64 runs,      0 skips
+  63789 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     128 runs,      0 skips
+  62669 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     255 runs,      1 skips
+  60977 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     511 runs,      1 skips
+  60445 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,    1023 runs,      1 skips
+./ffmpeg-p1 : debug/16.jpg --> debug/ZZ_16_mirror-5-5-0-0.jpg
+ 252990 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       1 runs,      0 skips
+ 256545 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       2 runs,      0 skips
+ 275197 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       4 runs,      0 skips
+ 369360 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       8 runs,      0 skips
+ 316586 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      16 runs,      0 skips
+ 288225 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      32 runs,      0 skips
+ 273805 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      63 runs,      1 skips
+ 265709 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     127 runs,      1 skips
+ 256600 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     255 runs,      1 skips
+ 254463 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     509 runs,      3 skips
+ 249649 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,    1020 runs,      4 skips
+./ffmpeg-p2 : debug/16.jpg --> debug/ZZ_16_mirror-5-5-0-0.jpg
+ 283050 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       1 runs,      0 skips
+ 257985 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       2 runs,      0 skips
+ 261022 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       4 runs,      0 skips
+ 251313 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       8 runs,      0 skips
+ 251814 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      16 runs,      0 skips
+ 251817 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      32 runs,      0 skips
+ 254266 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      64 runs,      0 skips
+ 255410 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     128 runs,      0 skips
+ 268811 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     256 runs,      0 skips
+ 267155 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     512 runs,      0 skips
+ 264171 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,    1023 runs,      1 skips
+./ffmpeg-p1 : debug/16.jpg --> debug/ZZ_16_mirror-5-5-5-5.jpg
+ 264330 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       1 runs,      0 skips
+ 276345 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       2 runs,      0 skips
+ 314370 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       4 runs,      0 skips
+ 304256 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       8 runs,      0 skips
+ 292376 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      16 runs,      0 skips
+ 280825 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      32 runs,      0 skips
+ 293401 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      64 runs,      0 skips
+ 295573 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     128 runs,      0 skips
+ 292719 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     255 runs,      1 skips
+ 277691 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     510 runs,      2 skips
+ 281630 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,    1020 runs,      4 skips
+./ffmpeg-p2 : debug/16.jpg --> debug/ZZ_16_mirror-5-5-5-5.jpg
+ 342810 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       1 runs,      0 skips
+ 289125 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       2 runs,      0 skips
+ 284130 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       4 runs,      0 skips
+ 280552 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       8 runs,      0 skips
+ 269426 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      16 runs,      0 skips
+ 272778 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      32 runs,      0 skips
+ 273436 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      64 runs,      0 skips
+ 279547 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     128 runs,      0 skips
+ 290456 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     256 runs,      0 skips
+ 290597 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     512 runs,      0 skips
+ 285697 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,    1023 runs,      1 skips
+
diff --git a/debug/fillborders.sh b/debug/fillborders.sh
index ec33bb5..aa8fd79 100755
--- a/debug/fillborders.sh
+++ b/debug/fillborders.sh
@@ -17,7 +17,7 @@
     do
         input="debug/${file}"
         output="debug/ZZ_${file%.*}_${mode%:*}-${borders//:/-}.${file##*.}"
-        for patch in "ffmpeg" "./ffmpeg-p1"
+        for patch in "./ffmpeg-p1" "./ffmpeg-p2"
         do
             echo "${patch} : ${input} --> ${output}"
             if [ $(ffprobe -v error -of default=nk=1:nw=1 -show_entries format=format_name "${input}") == "image2" ]
diff --git a/ffmpeg-p1 b/ffmpeg-p1
new file mode 100755
index 0000000..5f24a65
--- /dev/null
+++ b/ffmpeg-p1
Binary files differ
diff --git a/ffmpeg-p2 b/ffmpeg-p2
new file mode 100755
index 0000000..bf6d107
--- /dev/null
+++ b/ffmpeg-p2
Binary files differ
diff --git a/libavfilter/vf_fillborders.c b/libavfilter/vf_fillborders.c
index 00c1888..b447320 100644
--- a/libavfilter/vf_fillborders.c
+++ b/libavfilter/vf_fillborders.c
@@ -18,17 +18,11 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "drawutils.h"
+#include "internal.h"
 #include "libavutil/colorspace.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
-#include "drawutils.h"
-#include "internal.h"
-/*
-#include "libavutil/common.h"
-#include "avfilter.h"
-#include "formats.h"
-#include "video.h"
-*/
 
 enum { Y, U, V, A };
 enum { R, G, B };
@@ -109,14 +103,16 @@
         int linesize = frame->linesize[p];
 
         /* fill left and right borders from top to bottom border */
-        for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-            memset(data + y * linesize,
-                    *(data + y * linesize + s->borders[p].left),
-                    s->borders[p].left);
-            memset(data + y * linesize + s->planewidth[p] - s->borders[p].right,
-                    *(data + y * linesize + s->planewidth[p] - s->borders[p].right - 1),
-                    s->borders[p].right);
-        }
+        if (s->borders[p].left != 0 ||
+                s->borders[p].right != s->planewidth[p]) // in case skip for performance
+            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
+                memset(data + y * linesize,
+                        *(data + y * linesize + s->borders[p].left),
+                        s->borders[p].left);
+                memset(data + y * linesize + s->planewidth[p] - s->borders[p].right,
+                        *(data + y * linesize + s->planewidth[p] - s->borders[p].right - 1),
+                        s->borders[p].right);
+            }
 
         /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
@@ -140,15 +136,17 @@
         int linesize = frame->linesize[p] / sizeof(uint16_t);
 
         /* fill left and right borders from top to bottom border */
-        for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-            for (x = 0; x < s->borders[p].left; x++) {
-                data[y * linesize + x] = *(data + y * linesize + s->borders[p].left);
+        if (s->borders[p].left != 0 ||
+                s->borders[p].right != s->planewidth[p]) // in case skip for performance
+            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
+                for (x = 0; x < s->borders[p].left; x++) {
+                    data[y * linesize + x] = *(data + y * linesize + s->borders[p].left);
+                }
+                for (x = 0; x < s->borders[p].right; x++) {
+                    data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
+                            *(data + y * linesize + s->planewidth[p] - s->borders[p].right - 1);
+                }
             }
-            for (x = 0; x < s->borders[p].right; x++) {
-                data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                    *(data + y * linesize + s->planewidth[p] - s->borders[p].right - 1);
-            }
-        }
 
         /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
@@ -172,15 +170,17 @@
         int linesize = frame->linesize[p];
 
         /* fill left and right borders from top to bottom border */
-        for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-            for (x = 0; x < s->borders[p].left; x++) {
-                data[y * linesize + x] = data[y * linesize + s->borders[p].left * 2 - 1 - x];
+        if (s->borders[p].left != 0 ||
+                s->borders[p].right != s->planewidth[p]) // in case skip for performance
+            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
+                for (x = 0; x < s->borders[p].left; x++) {
+                    data[y * linesize + x] = data[y * linesize + s->borders[p].left * 2 - 1 - x];
+                }
+                for (x = 0; x < s->borders[p].right; x++) {
+                    data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
+                            data[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
+                }
             }
-            for (x = 0; x < s->borders[p].right; x++) {
-                data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                    data[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
-            }
-        }
 
         /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
@@ -205,16 +205,18 @@
         int linesize = frame->linesize[p] / sizeof(uint16_t);
 
         /* fill left and right borders from top to bottom border */
-        for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-            for (x = 0; x < s->borders[p].left; x++) {
-                data[y * linesize + x] = data[y * linesize + s->borders[p].left * 2 - 1 - x];
-            }
+        if (s->borders[p].left != 0 ||
+                s->borders[p].right != s->planewidth[p]) // in case skip for performance
+            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
+                for (x = 0; x < s->borders[p].left; x++) {
+                    data[y * linesize + x] = data[y * linesize + s->borders[p].left * 2 - 1 - x];
+                }
 
-            for (x = 0; x < s->borders[p].right; x++) {
-                data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                    data[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
+                for (x = 0; x < s->borders[p].right; x++) {
+                    data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
+                            data[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
+                }
             }
-        }
 
         /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
@@ -240,11 +242,13 @@
         int linesize = frame->linesize[p];
 
         /* fill left and right borders from top to bottom border */
-        for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-            memset(data + y * linesize, fill, s->borders[p].left);
-            memset(data + y * linesize + s->planewidth[p] - s->borders[p].right, fill,
-                    s->borders[p].right);
-        }
+        if (s->borders[p].left != 0 ||
+                s->borders[p].right != s->planewidth[p]) // in case skip for performance
+            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
+                memset(data + y * linesize, fill, s->borders[p].left);
+                memset(data + y * linesize + s->planewidth[p] - s->borders[p].right, fill,
+                        s->borders[p].right);
+            }
 
         /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
@@ -266,14 +270,16 @@
         int linesize = frame->linesize[p] / sizeof(uint16_t);
 
         /* fill left and right borders from top to bottom border */
-        for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-            for (x = 0; x < s->borders[p].left; x++) {
-                data[y * linesize + x] = fill;
+        if (s->borders[p].left != 0 ||
+                s->borders[p].right != s->planewidth[p]) // in case skip for performance
+            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
+                for (x = 0; x < s->borders[p].left; x++) {
+                    data[y * linesize + x] = fill;
+                }
+                for (x = 0; x < s->borders[p].right; x++) {
+                    data[y * linesize + s->planewidth[p] - s->borders[p].right + x] = fill;
+                }
             }
-            for (x = 0; x < s->borders[p].right; x++) {
-                data[y * linesize + s->planewidth[p] - s->borders[p].right + x] = fill;
-            }
-        }
 
         /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
@@ -296,6 +302,20 @@
     AVFilterContext *ctx = inlink->dst;
     FillBordersContext *s = ctx->priv;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+
+    if (inlink->w < s->left + s->right ||
+            inlink->w <= s->left ||
+            inlink->w <= s->right ||
+            inlink->h < s->top + s->bottom ||
+            inlink->h <= s->top ||
+            inlink->h <= s->bottom ||
+            inlink->w < s->left * 2 ||
+            inlink->w < s->right * 2 ||
+            inlink->h < s->top * 2 ||
+            inlink->h < s->bottom * 2) {
+        av_log(ctx, AV_LOG_ERROR, "Borders are bigger than input frame size.\n");
+        return AVERROR(EINVAL);
+    }
 
     s->nb_planes = desc->nb_components;
     s->depth = desc->comp[0].depth;
@@ -320,40 +340,23 @@
     s->borders[2].top    = s->top >> desc->log2_chroma_h;
     s->borders[2].bottom = s->bottom >> desc->log2_chroma_h;
 
-    if (inlink->w < s->left + s->right ||
-        inlink->w <= s->left ||
-        inlink->w <= s->right ||
-        inlink->h < s->top + s->bottom ||
-        inlink->h <= s->top ||
-        inlink->h <= s->bottom ||
-        inlink->w < s->left * 2 ||
-        inlink->w < s->right * 2 ||
-        inlink->h < s->top * 2 ||
-        inlink->h < s->bottom * 2) {
-        av_log(ctx, AV_LOG_ERROR, "Borders are bigger than input frame size.\n");
-        return AVERROR(EINVAL);
-    }
-
     switch (s->mode) {
-    case FM_SMEAR:  s->fillborders = s->depth <= 8 ? smear_borders8  : smear_borders16;  break;
-    case FM_MIRROR: s->fillborders = s->depth <= 8 ? mirror_borders8 : mirror_borders16; break;
-    case FM_FIXED:  s->fillborders = s->depth <= 8 ? fixed_borders8  : fixed_borders16;  break;
-    }
-
-    s->yuv_color[Y] = RGB_TO_Y_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B]);
-    s->yuv_color[U] = RGB_TO_U_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B], 0);
-    s->yuv_color[V] = RGB_TO_V_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B], 0);
-    s->yuv_color[A] = s->rgba_color[A];
-
-    if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
-        uint8_t rgba_map[4];
-        int i;
-
-        ff_fill_rgba_map(rgba_map, inlink->format);
-        for (i = 0; i < 4; i++)
-            s->fill[rgba_map[i]] = s->rgba_color[i];
-    } else {
-        memcpy(s->fill, s->yuv_color, sizeof(s->yuv_color));
+        case FM_SMEAR:  s->fillborders = s->depth <= 8 ? smear_borders8  : smear_borders16;  break;
+        case FM_MIRROR: s->fillborders = s->depth <= 8 ? mirror_borders8 : mirror_borders16; break;
+        case FM_FIXED:  s->fillborders = s->depth <= 8 ? fixed_borders8  : fixed_borders16;
+            if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
+                uint8_t rgba_map[4];
+                int i;
+                ff_fill_rgba_map(rgba_map, inlink->format);
+                for (i = 0; i < sizeof(rgba_map); i++)
+                    s->fill[rgba_map[i]] = s->rgba_color[i];
+            } else {
+                s->yuv_color[Y] = RGB_TO_Y_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B]);
+                s->yuv_color[U] = RGB_TO_U_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B], 0);
+                s->yuv_color[V] = RGB_TO_V_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B], 0);
+                s->yuv_color[A] = s->rgba_color[A];
+                memcpy(s->fill, s->yuv_color, sizeof(s->yuv_color));
+            } break;
     }
 
     sprintf(testcase, "fillborders=%d:%d:%d:%d:%s %dp-%dbit-%dx%d",
>From e7345783a28a20ed06b1fcfa87f9fc8229cae3b0 Mon Sep 17 00:00:00 2001
From: Ulf Zibis <ulf.zi...@cosoco.de>
Date: 23.03.2019, 20:45:33

avfilter/fillborders: enhanced readability;
side effect: better performance by less indirections in for loops

diff --git a/debug/Benchmark_P1-P3.log b/debug/Benchmark_P1-P3.log
new file mode 100644
index 0000000..791b6af
--- /dev/null
+++ b/debug/Benchmark_P1-P3.log
@@ -0,0 +1,152 @@
+Test[0] ======> 3-plane 8-bit  YUV-420:   CYD_1.5m_x264.mp4 <======
+./ffmpeg-p1 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-0-0-5-5.mp4
+ 152910 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1 runs,      0 skips
+ 137655 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       2 runs,      0 skips
+ 136665 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       4 runs,      0 skips
+ 134898 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       8 runs,      0 skips
+ 132564 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      16 runs,      0 skips
+ 134170 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      32 runs,      0 skips
+ 135137 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      64 runs,      0 skips
+ 133850 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     128 runs,      0 skips
+ 132160 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     256 runs,      0 skips
+ 132530 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     512 runs,      0 skips
+ 132204 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,    1023 runs,      1 skips
+ 131111 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,    2045 runs,      3 skips
+./ffmpeg-p3 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-0-0-5-5.mp4
+  90450 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1 runs,      0 skips
+  93240 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       2 runs,      0 skips
+ 100710 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       4 runs,      0 skips
+  98775 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       8 runs,      0 skips
+  96969 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      16 runs,      0 skips
+  95765 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      32 runs,      0 skips
+  95322 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      64 runs,      0 skips
+  95523 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     128 runs,      0 skips
+  96034 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     256 runs,      0 skips
+  95269 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     511 runs,      1 skips
+  95172 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,    1023 runs,      1 skips
+  95172 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,    2046 runs,      2 skips
+./ffmpeg-p1 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-5-5-0-0.mp4
+ 497790 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1 runs,      0 skips
+ 577395 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       2 runs,      0 skips
+ 658530 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       4 runs,      0 skips
+ 692820 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       8 runs,      0 skips
+ 649102 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      16 runs,      0 skips
+ 619278 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      32 runs,      0 skips
+ 638354 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      63 runs,      1 skips
+ 663901 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     126 runs,      2 skips
+ 641847 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     253 runs,      3 skips
+ 626153 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     509 runs,      3 skips
+ 617921 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,    1019 runs,      5 skips
+ 614453 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,    2036 runs,     12 skips
+./ffmpeg-p3 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-5-5-0-0.mp4
+ 371610 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1 runs,      0 skips
+ 415620 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       2 runs,      0 skips
+ 587430 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       4 runs,      0 skips
+ 700875 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       8 runs,      0 skips
+ 584606 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      16 runs,      0 skips
+ 705810 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      32 runs,      0 skips
+ 621233 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      64 runs,      0 skips
+ 558663 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     128 runs,      0 skips
+ 544978 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     256 runs,      0 skips
+ 518520 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     509 runs,      3 skips
+ 510660 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,    1020 runs,      4 skips
+ 508549 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,    2037 runs,     11 skips
+./ffmpeg-p1 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-5-5-5-5.mp4
+ 734130 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1 runs,      0 skips
+ 722025 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       2 runs,      0 skips
+ 735547 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       4 runs,      0 skips
+ 729371 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       8 runs,      0 skips
+ 661246 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      16 runs,      0 skips
+ 677356 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      32 runs,      0 skips
+ 650588 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      64 runs,      0 skips
+ 653702 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     128 runs,      0 skips
+ 649521 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     256 runs,      0 skips
+ 649270 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     512 runs,      0 skips
+ 641965 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,    1024 runs,      0 skips
+ 640856 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,    2045 runs,      3 skips
+./ffmpeg-p3 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-5-5-5-5.mp4
+ 514350 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1 runs,      0 skips
+ 508455 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       2 runs,      0 skips
+ 530055 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       4 runs,      0 skips
+ 564401 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       8 runs,      0 skips
+ 564845 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      16 runs,      0 skips
+ 546238 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      32 runs,      0 skips
+ 561036 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      64 runs,      0 skips
+ 561433 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     128 runs,      0 skips
+ 559685 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     256 runs,      0 skips
+ 555065 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     511 runs,      1 skips
+ 541722 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,    1023 runs,      1 skips
+ 540713 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,    2043 runs,      5 skips
+Test[1] ======> 1-plane 16-bit Y-400:     16.jpg <======
+./ffmpeg-p1 : debug/16.jpg --> debug/ZZ_16_mirror-0-0-5-5.jpg
+  53730 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       1 runs,      0 skips
+  56745 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       2 runs,      0 skips
+  63967 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       4 runs,      0 skips
+  62797 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       8 runs,      0 skips
+  60997 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      16 runs,      0 skips
+  59661 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      32 runs,      0 skips
+  59876 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      64 runs,      0 skips
+  60731 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     128 runs,      0 skips
+  59818 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     256 runs,      0 skips
+  58054 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     512 runs,      0 skips
+  54689 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,    1024 runs,      0 skips
+./ffmpeg-p3 : debug/16.jpg --> debug/ZZ_16_mirror-0-0-5-5.jpg
+  62460 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       1 runs,      0 skips
+  61785 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       2 runs,      0 skips
+  65677 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       4 runs,      0 skips
+  63258 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       8 runs,      0 skips
+  64670 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      16 runs,      0 skips
+  62198 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      32 runs,      0 skips
+  62280 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      64 runs,      0 skips
+  62189 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     128 runs,      0 skips
+  61690 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     255 runs,      1 skips
+  58162 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     510 runs,      2 skips
+  55087 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,    1022 runs,      2 skips
+./ffmpeg-p1 : debug/16.jpg --> debug/ZZ_16_mirror-5-5-0-0.jpg
+ 196470 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       1 runs,      0 skips
+ 227070 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       2 runs,      0 skips
+ 264577 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       4 runs,      0 skips
+ 262338 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       8 runs,      0 skips
+ 272430 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      16 runs,      0 skips
+ 290224 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      32 runs,      0 skips
+ 275519 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      64 runs,      0 skips
+ 247729 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     128 runs,      0 skips
+ 239989 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     255 runs,      1 skips
+ 236435 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     511 runs,      1 skips
+ 223386 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,    1022 runs,      2 skips
+./ffmpeg-p3 : debug/16.jpg --> debug/ZZ_16_mirror-5-5-0-0.jpg
+ 186570 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       1 runs,      0 skips
+ 217215 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       2 runs,      0 skips
+ 240502 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       4 runs,      0 skips
+ 248377 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       8 runs,      0 skips
+ 235366 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      16 runs,      0 skips
+ 227151 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      32 runs,      0 skips
+ 239397 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      64 runs,      0 skips
+ 232529 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     128 runs,      0 skips
+ 229997 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     256 runs,      0 skips
+ 215414 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     512 runs,      0 skips
+ 201998 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,    1024 runs,      0 skips
+./ffmpeg-p1 : debug/16.jpg --> debug/ZZ_16_mirror-5-5-5-5.jpg
+ 321210 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       1 runs,      0 skips
+ 325215 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       2 runs,      0 skips
+ 321570 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       4 runs,      0 skips
+ 315112 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       8 runs,      0 skips
+ 302236 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      16 runs,      0 skips
+ 292986 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      32 runs,      0 skips
+ 285664 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      64 runs,      0 skips
+ 291649 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     128 runs,      0 skips
+ 284839 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     256 runs,      0 skips
+ 273345 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     512 runs,      0 skips
+ 256928 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,    1024 runs,      0 skips
+./ffmpeg-p3 : debug/16.jpg --> debug/ZZ_16_mirror-5-5-5-5.jpg
+ 207270 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       1 runs,      0 skips
+ 242955 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       2 runs,      0 skips
+ 284962 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       4 runs,      0 skips
+ 276896 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       8 runs,      0 skips
+ 262113 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      16 runs,      0 skips
+ 257903 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      32 runs,      0 skips
+ 266698 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      64 runs,      0 skips
+ 261421 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     128 runs,      0 skips
+ 254113 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     256 runs,      0 skips
+ 238678 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     512 runs,      0 skips
+ 230192 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,    1024 runs,      0 skips
diff --git a/debug/Benchmark_P2-P3.log b/debug/Benchmark_P2-P3.log
new file mode 100644
index 0000000..6a1c279
--- /dev/null
+++ b/debug/Benchmark_P2-P3.log
@@ -0,0 +1,152 @@
+Test[0] ======> 3-plane 8-bit  YUV-420:   CYD_1.5m_x264.mp4 <======
+./ffmpeg-p2 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-0-0-5-5.mp4
+ 131220 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1 runs,      0 skips
+ 123885 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       2 runs,      0 skips
+ 131040 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       4 runs,      0 skips
+ 134100 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       8 runs,      0 skips
+ 132975 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      16 runs,      0 skips
+ 141457 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      32 runs,      0 skips
+ 140007 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      64 runs,      0 skips
+ 137624 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     128 runs,      0 skips
+ 134992 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     256 runs,      0 skips
+ 133704 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     512 runs,      0 skips
+ 131721 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,    1022 runs,      2 skips
+ 131461 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,    2045 runs,      3 skips
+./ffmpeg-p3 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-0-0-5-5.mp4
+  93420 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1 runs,      0 skips
+  92925 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       2 runs,      0 skips
+  99112 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       4 runs,      0 skips
+  98932 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       8 runs,      0 skips
+  99326 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      16 runs,      0 skips
+  99059 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      32 runs,      0 skips
+ 102242 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,      64 runs,      0 skips
+ 101072 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     128 runs,      0 skips
+  99430 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     256 runs,      0 skips
+  98442 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,     511 runs,      1 skips
+  97970 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,    1022 runs,      2 skips
+  97760 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,    2043 runs,      5 skips
+./ffmpeg-p2 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-5-5-0-0.mp4
+ 539100 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1 runs,      0 skips
+ 610065 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       2 runs,      0 skips
+ 664020 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       4 runs,      0 skips
+ 647055 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       8 runs,      0 skips
+ 593971 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      16 runs,      0 skips
+ 622575 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      32 runs,      0 skips
+ 656157 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      64 runs,      0 skips
+ 637149 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     128 runs,      0 skips
+ 634275 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     254 runs,      2 skips
+ 624818 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     507 runs,      5 skips
+ 626980 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,    1013 runs,     11 skips
+ 614364 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,    2033 runs,     15 skips
+./ffmpeg-p3 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-5-5-0-0.mp4
+ 470430 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1 runs,      0 skips
+ 475200 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       2 runs,      0 skips
+ 564367 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       4 runs,      0 skips
+ 578542 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       8 runs,      0 skips
+ 540540 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      16 runs,      0 skips
+ 537795 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      32 runs,      0 skips
+ 565540 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,      64 runs,      0 skips
+ 543585 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     128 runs,      0 skips
+ 525647 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     256 runs,      0 skips
+ 512596 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,     511 runs,      1 skips
+ 506673 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,    1021 runs,      3 skips
+ 501811 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,    2043 runs,      5 skips
+./ffmpeg-p2 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-5-5-5-5.mp4
+ 511470 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1 runs,      0 skips
+ 591345 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       2 runs,      0 skips
+1048612 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       4 runs,      0 skips
+1166265 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       8 runs,      0 skips
+ 960058 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      16 runs,      0 skips
+ 833582 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      32 runs,      0 skips
+ 838518 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      64 runs,      0 skips
+ 817359 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     128 runs,      0 skips
+ 760786 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     256 runs,      0 skips
+ 736783 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     511 runs,      1 skips
+ 703944 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,    1021 runs,      3 skips
+ 698058 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,    2043 runs,      5 skips
+./ffmpeg-p3 : debug/CYD_1.5m_x264.mp4 --> debug/ZZ_CYD_1.5m_x264_mirror-5-5-5-5.mp4
+ 504450 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1 runs,      0 skips
+ 578610 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       2 runs,      0 skips
+ 608895 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       4 runs,      0 skips
+ 607893 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       8 runs,      0 skips
+ 657151 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      16 runs,      0 skips
+ 621914 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      32 runs,      0 skips
+ 573044 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,      64 runs,      0 skips
+ 528410 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     128 runs,      0 skips
+ 511207 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     255 runs,      1 skips
+ 504752 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,     510 runs,      2 skips
+ 503153 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,    1019 runs,      5 skips
+ 500910 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,    2038 runs,     10 skips
+Test[1] ======> 1-plane 16-bit Y-400:     16.jpg <======
+./ffmpeg-p2 : debug/16.jpg --> debug/ZZ_16_mirror-0-0-5-5.jpg
+  50490 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       1 runs,      0 skips
+  51480 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       2 runs,      0 skips
+  52290 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       4 runs,      0 skips
+  50220 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       8 runs,      0 skips
+  57026 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      16 runs,      0 skips
+  52740 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      32 runs,      0 skips
+  49712 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      64 runs,      0 skips
+  54687 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     128 runs,      0 skips
+  55327 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     256 runs,      0 skips
+  56639 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     511 runs,      1 skips
+  56471 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,    1023 runs,      1 skips
+./ffmpeg-p3 : debug/16.jpg --> debug/ZZ_16_mirror-0-0-5-5.jpg
+  61110 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       1 runs,      0 skips
+  66195 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       2 runs,      0 skips
+  69120 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       4 runs,      0 skips
+  67972 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,       8 runs,      0 skips
+  63258 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      16 runs,      0 skips
+  66549 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      32 runs,      0 skips
+  63562 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,      64 runs,      0 skips
+  56940 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     128 runs,      0 skips
+  58699 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     256 runs,      0 skips
+  56193 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,     512 runs,      0 skips
+  57922 decicycles in fillborders=0:0:5:5:mirror 1p-16bit-0x0,    1023 runs,      1 skips
+./ffmpeg-p2 : debug/16.jpg --> debug/ZZ_16_mirror-5-5-0-0.jpg
+ 284130 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       1 runs,      0 skips
+ 262665 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       2 runs,      0 skips
+ 276367 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       4 runs,      0 skips
+ 256736 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       8 runs,      0 skips
+ 237071 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      16 runs,      0 skips
+ 237445 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      32 runs,      0 skips
+ 253331 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      64 runs,      0 skips
+ 251007 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     128 runs,      0 skips
+ 241606 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     256 runs,      0 skips
+ 240309 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     511 runs,      1 skips
+ 235028 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,    1022 runs,      2 skips
+./ffmpeg-p3 : debug/16.jpg --> debug/ZZ_16_mirror-5-5-0-0.jpg
+ 215640 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       1 runs,      0 skips
+ 226350 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       2 runs,      0 skips
+ 247590 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       4 runs,      0 skips
+ 235608 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,       8 runs,      0 skips
+ 212130 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      16 runs,      0 skips
+ 214360 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      32 runs,      0 skips
+ 210808 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,      64 runs,      0 skips
+ 205201 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     128 runs,      0 skips
+ 205582 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     255 runs,      1 skips
+ 211508 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,     510 runs,      2 skips
+ 210541 decicycles in fillborders=5:5:0:0:mirror 1p-16bit-0x0,    1020 runs,      4 skips
+./ffmpeg-p2 : debug/16.jpg --> debug/ZZ_16_mirror-5-5-5-5.jpg
+ 350100 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       1 runs,      0 skips
+ 346320 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       2 runs,      0 skips
+ 549090 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       4 runs,      0 skips
+ 401388 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       8 runs,      0 skips
+ 336031 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      16 runs,      0 skips
+ 308171 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      32 runs,      0 skips
+ 288490 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      64 runs,      0 skips
+ 294166 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     127 runs,      1 skips
+ 274391 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     255 runs,      1 skips
+ 274900 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     511 runs,      1 skips
+ 274431 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,    1023 runs,      1 skips
+./ffmpeg-p3 : debug/16.jpg --> debug/ZZ_16_mirror-5-5-5-5.jpg
+ 264690 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       1 runs,      0 skips
+ 319320 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       2 runs,      0 skips
+ 291352 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       4 runs,      0 skips
+ 274770 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,       8 runs,      0 skips
+ 259149 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      16 runs,      0 skips
+ 247702 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      32 runs,      0 skips
+ 255941 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,      64 runs,      0 skips
+ 259472 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     128 runs,      0 skips
+ 251605 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     255 runs,      1 skips
+ 251474 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,     510 runs,      2 skips
+ 250625 decicycles in fillborders=5:5:5:5:mirror 1p-16bit-0x0,    1022 runs,      2 skips
diff --git a/debug/fillborders.sh b/debug/fillborders.sh
index aa8fd79..23d82d2 100755
--- a/debug/fillborders.sh
+++ b/debug/fillborders.sh
@@ -17,12 +17,13 @@
     do
         input="debug/${file}"
         output="debug/ZZ_${file%.*}_${mode%:*}-${borders//:/-}.${file##*.}"
-        for patch in "./ffmpeg-p1" "./ffmpeg-p2"
+        for patch in "./ffmpeg-p2" "./ffmpeg-p3"
         do
             echo "${patch} : ${input} --> ${output}"
             if [ $(ffprobe -v error -of default=nk=1:nw=1 -show_entries format=format_name "${input}") == "image2" ]
                 then
                     ${patch} -y -v error -i "${input}" -vf loop=loop=1024:size=1:start=0,fillborders=${borders}:${mode} -f null -
+#                    ${patch} -y -v error -i "${input}" -vf loop=loop=1024:size=1:start=0,fillborders=${borders}:${mode} -update 1 "${output}"
                 else
                     ${patch} -y -v error -i "${input}" -vf fillborders=${borders}:${mode} -f null -
 #                    ${patch} -y -v error -i "${input}" -vf fillborders=${borders}:${mode} "${output}"
diff --git a/ffmpeg-p3 b/ffmpeg-p3
new file mode 100755
index 0000000..1f771c2
--- /dev/null
+++ b/ffmpeg-p3
Binary files differ
diff --git a/libavfilter/vf_fillborders.c b/libavfilter/vf_fillborders.c
index b447320..25f6fe3 100644
--- a/libavfilter/vf_fillborders.c
+++ b/libavfilter/vf_fillborders.c
@@ -101,28 +101,30 @@
     for (p = 0; p < s->nb_planes; p++) {
         uint8_t *data = frame->data[p];
         int linesize = frame->linesize[p];
+        int width = s->planewidth[p];
+        int height = s->planeheight[p];
+        int left = s->borders[p].left;
+        int right = s->borders[p].right;
+        int top = s->borders[p].top;
+        int bottom = s->borders[p].bottom;
 
         /* fill left and right borders from top to bottom border */
-        if (s->borders[p].left != 0 ||
-                s->borders[p].right != s->planewidth[p]) // in case skip for performance
-            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
+        if (left != 0 || right != width) // in case skip for performance
+            for (y = top; y < height - bottom; y++) {
                 memset(data + y * linesize,
-                        *(data + y * linesize + s->borders[p].left),
-                        s->borders[p].left);
-                memset(data + y * linesize + s->planewidth[p] - s->borders[p].right,
-                        *(data + y * linesize + s->planewidth[p] - s->borders[p].right - 1),
-                        s->borders[p].right);
+                        *(data + y * linesize + left), left);
+                memset(data + y * linesize + width - right,
+                        *(data + y * linesize + width - right - 1), right);
             }
 
         /* fill top and bottom borders */
-        for (y = 0; y < s->borders[p].top; y++) {
+        for (y = 0; y < top; y++) {
             memcpy(data + y * linesize,
-                    data + s->borders[p].top * linesize, s->planewidth[p]);
+                    data + top * linesize, width);
         }
-        for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
+        for (y = height - bottom; y < height; y++) {
             memcpy(data + y * linesize,
-                    data + (s->planeheight[p] - s->borders[p].bottom - 1) * linesize,
-                    s->planewidth[p]);
+                    data + (height - bottom - 1) * linesize, width);
         }
     }
 }
@@ -134,29 +136,33 @@
     for (p = 0; p < s->nb_planes; p++) {
         uint16_t *data = (uint16_t *)frame->data[p];
         int linesize = frame->linesize[p] / sizeof(uint16_t);
+        int width = s->planewidth[p];
+        int height = s->planeheight[p];
+        int left = s->borders[p].left;
+        int right = s->borders[p].right;
+        int top = s->borders[p].top;
+        int bottom = s->borders[p].bottom;
 
         /* fill left and right borders from top to bottom border */
-        if (s->borders[p].left != 0 ||
-                s->borders[p].right != s->planewidth[p]) // in case skip for performance
-            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-                for (x = 0; x < s->borders[p].left; x++) {
-                    data[y * linesize + x] = *(data + y * linesize + s->borders[p].left);
+        if (left != 0 || right != width) // in case skip for performance
+            for (y = top; y < height - bottom; y++) {
+                for (x = 0; x < left; x++) {
+                    data[y * linesize + x] = data[y * linesize + left];
                 }
-                for (x = 0; x < s->borders[p].right; x++) {
-                    data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                            *(data + y * linesize + s->planewidth[p] - s->borders[p].right - 1);
+                for (x = 0; x < right; x++) {
+                    data[y * linesize + width - right + x] =
+                            data[y * linesize + width - right - 1];
                 }
             }
 
         /* fill top and bottom borders */
-        for (y = 0; y < s->borders[p].top; y++) {
+        for (y = 0; y < top; y++) {
             memcpy(data + y * linesize,
-                    data + s->borders[p].top * linesize, s->planewidth[p] * sizeof(uint16_t));
+                    data + top * linesize, width * sizeof(uint16_t));
         }
-        for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
+        for (y = height - bottom; y < height; y++) {
             memcpy(data + y * linesize,
-                    data + (s->planeheight[p] - s->borders[p].bottom - 1) * linesize,
-                    s->planewidth[p] * sizeof(uint16_t));
+                    data + (height - bottom - 1) * linesize, width * sizeof(uint16_t));
         }
     }
 }
@@ -168,30 +174,33 @@
     for (p = 0; p < s->nb_planes; p++) {
         uint8_t *data = frame->data[p];
         int linesize = frame->linesize[p];
+        int width = s->planewidth[p];
+        int height = s->planeheight[p];
+        int left = s->borders[p].left;
+        int right = s->borders[p].right;
+        int top = s->borders[p].top;
+        int bottom = s->borders[p].bottom;
 
         /* fill left and right borders from top to bottom border */
-        if (s->borders[p].left != 0 ||
-                s->borders[p].right != s->planewidth[p]) // in case skip for performance
-            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-                for (x = 0; x < s->borders[p].left; x++) {
-                    data[y * linesize + x] = data[y * linesize + s->borders[p].left * 2 - 1 - x];
+        if (left != 0 || right != width) // in case skip for performance
+            for (y = top; y < height - bottom; y++) {
+                for (x = 0; x < left; x++) {
+                    data[y * linesize + x] = data[y * linesize + left * 2 - 1 - x];
                 }
-                for (x = 0; x < s->borders[p].right; x++) {
-                    data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                            data[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
+                for (x = 0; x < right; x++) {
+                    data[y * linesize + width - right + x] =
+                            data[y * linesize + width - right - 1 - x];
                 }
             }
 
         /* fill top and bottom borders */
-        for (y = 0; y < s->borders[p].top; y++) {
+        for (y = 0; y < top; y++) {
             memcpy(data + y * linesize,
-                    data + (s->borders[p].top * 2 - 1 - y) * linesize,
-                    s->planewidth[p]);
+                    data + (top * 2 - 1 - y) * linesize, width);
         }
-        for (y = 0; y < s->borders[p].bottom; y++) {
-            memcpy(data + (s->planeheight[p] - s->borders[p].bottom + y) * linesize,
-                    data + (s->planeheight[p] - s->borders[p].bottom - 1 - y) * linesize,
-                    s->planewidth[p]);
+        for (y = 0; y < bottom; y++) {
+            memcpy(data + (height - bottom + y) * linesize,
+                    data + (height - bottom - 1 - y) * linesize, width);
         }
     }
 }
@@ -203,31 +212,34 @@
     for (p = 0; p < s->nb_planes; p++) {
         uint16_t *data = (uint16_t *)frame->data[p];
         int linesize = frame->linesize[p] / sizeof(uint16_t);
+        int width = s->planewidth[p];
+        int height = s->planeheight[p];
+        int left = s->borders[p].left;
+        int right = s->borders[p].right;
+        int top = s->borders[p].top;
+        int bottom = s->borders[p].bottom;
 
         /* fill left and right borders from top to bottom border */
-        if (s->borders[p].left != 0 ||
-                s->borders[p].right != s->planewidth[p]) // in case skip for performance
-            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-                for (x = 0; x < s->borders[p].left; x++) {
-                    data[y * linesize + x] = data[y * linesize + s->borders[p].left * 2 - 1 - x];
+        if (left != 0 || right != width) // in case skip for performance
+            for (y = top; y < height - bottom; y++) {
+                for (x = 0; x < left; x++) {
+                    data[y * linesize + x] = data[y * linesize + left * 2 - 1 - x];
                 }
 
-                for (x = 0; x < s->borders[p].right; x++) {
-                    data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                            data[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
+                for (x = 0; x < right; x++) {
+                    data[y * linesize + width - right + x] =
+                            data[y * linesize + width - right - 1 - x];
                 }
             }
 
         /* fill top and bottom borders */
-        for (y = 0; y < s->borders[p].top; y++) {
+        for (y = 0; y < top; y++) {
             memcpy(data + y * linesize,
-                    data + (s->borders[p].top * 2 - 1 - y) * linesize,
-                    s->planewidth[p] * sizeof(uint16_t));
+                    data + (top * 2 - 1 - y) * linesize, width * sizeof(uint16_t));
         }
-        for (y = 0; y < s->borders[p].bottom; y++) {
-            memcpy(data + (s->planeheight[p] - s->borders[p].bottom + y) * linesize,
-                    data + (s->planeheight[p] - s->borders[p].bottom - 1 - y) * linesize,
-                    s->planewidth[p] * sizeof(uint16_t));
+        for (y = 0; y < bottom; y++) {
+            memcpy(data + (height - bottom + y) * linesize,
+                    data + (height - bottom - 1 - y) * linesize, width * sizeof(uint16_t));
         }
     }
 }
@@ -238,24 +250,28 @@
 
     for (p = 0; p < s->nb_planes; p++) {
         uint8_t *data = frame->data[p];
-        uint8_t fill = s->fill[p];
         int linesize = frame->linesize[p];
+        int width = s->planewidth[p];
+        int height = s->planeheight[p];
+        int left = s->borders[p].left;
+        int right = s->borders[p].right;
+        int top = s->borders[p].top;
+        int bottom = s->borders[p].bottom;
+        uint8_t fill = s->fill[p];
 
         /* fill left and right borders from top to bottom border */
-        if (s->borders[p].left != 0 ||
-                s->borders[p].right != s->planewidth[p]) // in case skip for performance
-            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-                memset(data + y * linesize, fill, s->borders[p].left);
-                memset(data + y * linesize + s->planewidth[p] - s->borders[p].right, fill,
-                        s->borders[p].right);
+        if (left != 0 || right != width) // in case skip for performance
+            for (y = top; y < height - bottom; y++) {
+                memset(data + y * linesize, fill, left);
+                memset(data + y * linesize + width - right, fill, right);
             }
 
         /* fill top and bottom borders */
-        for (y = 0; y < s->borders[p].top; y++) {
-            memset(data + y * linesize, fill, s->planewidth[p]);
+        for (y = 0; y < top; y++) {
+            memset(data + y * linesize, fill, width);
         }
-        for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
-            memset(data + y * linesize, fill, s->planewidth[p]);
+        for (y = height - bottom; y < height; y++) {
+            memset(data + y * linesize, fill, width);
         }
     }
 }
@@ -266,29 +282,34 @@
 
     for (p = 0; p < s->nb_planes; p++) {
         uint16_t *data = (uint16_t *)frame->data[p];
-        uint16_t fill = s->fill[p] << (s->depth - 8);
         int linesize = frame->linesize[p] / sizeof(uint16_t);
+        int width = s->planewidth[p];
+        int height = s->planeheight[p];
+        int left = s->borders[p].left;
+        int right = s->borders[p].right;
+        int top = s->borders[p].top;
+        int bottom = s->borders[p].bottom;
+        uint16_t fill = s->fill[p] << (s->depth - 8);
 
         /* fill left and right borders from top to bottom border */
-        if (s->borders[p].left != 0 ||
-                s->borders[p].right != s->planewidth[p]) // in case skip for performance
-            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-                for (x = 0; x < s->borders[p].left; x++) {
+        if (left != 0 || right != width) // in case skip for performance
+            for (y = top; y < height - bottom; y++) {
+                for (x = 0; x < left; x++) {
                     data[y * linesize + x] = fill;
                 }
-                for (x = 0; x < s->borders[p].right; x++) {
-                    data[y * linesize + s->planewidth[p] - s->borders[p].right + x] = fill;
+                for (x = 0; x < right; x++) {
+                    data[y * linesize + width - right + x] = fill;
                 }
             }
 
         /* fill top and bottom borders */
-        for (y = 0; y < s->borders[p].top; y++) {
-            for (x = 0; x < s->planewidth[p]; x++) {
+        for (y = 0; y < top; y++) {
+            for (x = 0; x < width; x++) {
                 data[y * linesize + x] = fill;
             }
         }
-        for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
-            for (x = 0; x < s->planewidth[p]; x++) {
+        for (y = height - bottom; y < height; y++) {
+            for (x = 0; x < width; x++) {
                 data[y * linesize + x] = fill;
             }
         }
>From f2ca2c2353fef093713451fd808eb7fa4702b3a0 Mon Sep 17 00:00:00 2001
From: Ulf Zibis <ulf.zi...@cosoco.de>
Date: 14.03.2019, 19:34:03

avfilter/fillborders: added comments; named more descriptive; corrected indentations;
moved fillborders_options[] more up, needed for STOP_TIMER(testcase);

diff --git a/libavfilter/vf_fillborders.c b/libavfilter/vf_fillborders.c
index 1344587..3d63e88 100644
--- a/libavfilter/vf_fillborders.c
+++ b/libavfilter/vf_fillborders.c
@@ -19,14 +19,16 @@
  */
 
 #include "libavutil/colorspace.h"
-#include "libavutil/common.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
-#include "avfilter.h"
 #include "drawutils.h"
-#include "formats.h"
 #include "internal.h"
+/*
+#include "libavutil/common.h"
+#include "avfilter.h"
+#include "formats.h"
 #include "video.h"
+*/
 
 enum { Y, U, V, A };
 enum { R, G, B };
@@ -53,6 +55,22 @@
 
     void (*fillborders)(struct FillBordersContext *s, AVFrame *frame);
 } FillBordersContext;
+
+#define OFFSET(x) offsetof(FillBordersContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+
+static const AVOption fillborders_options[] = {
+    { "left",   "set the left fill border",   OFFSET(left),   AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,    FLAGS },
+    { "right",  "set the right fill border",  OFFSET(right),  AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,    FLAGS },
+    { "top",    "set the top fill border",    OFFSET(top),    AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,    FLAGS },
+    { "bottom", "set the bottom fill border", OFFSET(bottom), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,    FLAGS },
+    { "mode",   "set the fill borders mode",  OFFSET(mode),   AV_OPT_TYPE_INT, {.i64=FM_SMEAR}, 0, FM_NB_MODES-1, FLAGS, "mode" },
+        { "smear",  NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_SMEAR},  0, 0, FLAGS, "mode" },
+        { "mirror", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_MIRROR}, 0, 0, FLAGS, "mode" },
+        { "fixed",  NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_FIXED},  0, 0, FLAGS, "mode" },
+    { "color",  "set the color for the fixed mode", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS },
+    { NULL }
+};
 
 static int query_formats(AVFilterContext *ctx)
 {
@@ -87,27 +105,28 @@
     int p, y;
 
     for (p = 0; p < s->nb_planes; p++) {
-        uint8_t *ptr = frame->data[p];
+        uint8_t *data = frame->data[p];
         int linesize = frame->linesize[p];
 
+        /* fill left and right borders from top to bottom border */
         for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-            memset(ptr + y * linesize,
-                   *(ptr + y * linesize + s->borders[p].left),
-                   s->borders[p].left);
-            memset(ptr + y * linesize + s->planewidth[p] - s->borders[p].right,
-                   *(ptr + y * linesize + s->planewidth[p] - s->borders[p].right - 1),
-                   s->borders[p].right);
+            memset(data + y * linesize,
+                    *(data + y * linesize + s->borders[p].left),
+                    s->borders[p].left);
+            memset(data + y * linesize + s->planewidth[p] - s->borders[p].right,
+                    *(data + y * linesize + s->planewidth[p] - s->borders[p].right - 1),
+                    s->borders[p].right);
         }
 
+        /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
-            memcpy(ptr + y * linesize,
-                   ptr + s->borders[p].top * linesize, s->planewidth[p]);
+            memcpy(data + y * linesize,
+                    data + s->borders[p].top * linesize, s->planewidth[p]);
         }
-
         for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
-            memcpy(ptr + y * linesize,
-                   ptr + (s->planeheight[p] - s->borders[p].bottom - 1) * linesize,
-                   s->planewidth[p]);
+            memcpy(data + y * linesize,
+                    data + (s->planeheight[p] - s->borders[p].bottom - 1) * linesize,
+                    s->planewidth[p]);
         }
     }
 }
@@ -117,29 +136,29 @@
     int p, y, x;
 
     for (p = 0; p < s->nb_planes; p++) {
-        uint16_t *ptr = (uint16_t *)frame->data[p];
-        int linesize = frame->linesize[p] / 2;
+        uint16_t *data = (uint16_t *)frame->data[p];
+        int linesize = frame->linesize[p] / sizeof(uint16_t);
 
+        /* fill left and right borders from top to bottom border */
         for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
             for (x = 0; x < s->borders[p].left; x++) {
-                ptr[y * linesize + x] =  *(ptr + y * linesize + s->borders[p].left);
+                data[y * linesize + x] = *(data + y * linesize + s->borders[p].left);
             }
-
             for (x = 0; x < s->borders[p].right; x++) {
-                ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                   *(ptr + y * linesize + s->planewidth[p] - s->borders[p].right - 1);
+                data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
+                    *(data + y * linesize + s->planewidth[p] - s->borders[p].right - 1);
             }
         }
 
+        /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
-            memcpy(ptr + y * linesize,
-                   ptr + s->borders[p].top * linesize, s->planewidth[p] * 2);
+            memcpy(data + y * linesize,
+                    data + s->borders[p].top * linesize, s->planewidth[p] * sizeof(uint16_t));
         }
-
         for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
-            memcpy(ptr + y * linesize,
-                   ptr + (s->planeheight[p] - s->borders[p].bottom - 1) * linesize,
-                   s->planewidth[p] * 2);
+            memcpy(data + y * linesize,
+                    data + (s->planeheight[p] - s->borders[p].bottom - 1) * linesize,
+                    s->planewidth[p] * sizeof(uint16_t));
         }
     }
 }
@@ -149,30 +168,30 @@
     int p, y, x;
 
     for (p = 0; p < s->nb_planes; p++) {
-        uint8_t *ptr = frame->data[p];
+        uint8_t *data = frame->data[p];
         int linesize = frame->linesize[p];
 
+        /* fill left and right borders from top to bottom border */
         for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
             for (x = 0; x < s->borders[p].left; x++) {
-                ptr[y * linesize + x] = ptr[y * linesize + s->borders[p].left * 2 - 1 - x];
+                data[y * linesize + x] = data[y * linesize + s->borders[p].left * 2 - 1 - x];
             }
-
             for (x = 0; x < s->borders[p].right; x++) {
-                ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                    ptr[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
+                data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
+                    data[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
             }
         }
 
+        /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
-            memcpy(ptr + y * linesize,
-                   ptr + (s->borders[p].top * 2 - 1 - y) * linesize,
-                   s->planewidth[p]);
+            memcpy(data + y * linesize,
+                    data + (s->borders[p].top * 2 - 1 - y) * linesize,
+                    s->planewidth[p]);
         }
-
         for (y = 0; y < s->borders[p].bottom; y++) {
-            memcpy(ptr + (s->planeheight[p] - s->borders[p].bottom + y) * linesize,
-                   ptr + (s->planeheight[p] - s->borders[p].bottom - 1 - y) * linesize,
-                   s->planewidth[p]);
+            memcpy(data + (s->planeheight[p] - s->borders[p].bottom + y) * linesize,
+                    data + (s->planeheight[p] - s->borders[p].bottom - 1 - y) * linesize,
+                    s->planewidth[p]);
         }
     }
 }
@@ -182,30 +201,31 @@
     int p, y, x;
 
     for (p = 0; p < s->nb_planes; p++) {
-        uint16_t *ptr = (uint16_t *)frame->data[p];
-        int linesize = frame->linesize[p] / 2;
+        uint16_t *data = (uint16_t *)frame->data[p];
+        int linesize = frame->linesize[p] / sizeof(uint16_t);
 
+        /* fill left and right borders from top to bottom border */
         for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
             for (x = 0; x < s->borders[p].left; x++) {
-                ptr[y * linesize + x] = ptr[y * linesize + s->borders[p].left * 2 - 1 - x];
+                data[y * linesize + x] = data[y * linesize + s->borders[p].left * 2 - 1 - x];
             }
 
             for (x = 0; x < s->borders[p].right; x++) {
-                ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                    ptr[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
+                data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
+                    data[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
             }
         }
 
+        /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
-            memcpy(ptr + y * linesize,
-                   ptr + (s->borders[p].top * 2 - 1 - y) * linesize,
-                   s->planewidth[p] * 2);
+            memcpy(data + y * linesize,
+                    data + (s->borders[p].top * 2 - 1 - y) * linesize,
+                    s->planewidth[p] * sizeof(uint16_t));
         }
-
         for (y = 0; y < s->borders[p].bottom; y++) {
-            memcpy(ptr + (s->planeheight[p] - s->borders[p].bottom + y) * linesize,
-                   ptr + (s->planeheight[p] - s->borders[p].bottom - 1 - y) * linesize,
-                   s->planewidth[p] * 2);
+            memcpy(data + (s->planeheight[p] - s->borders[p].bottom + y) * linesize,
+                    data + (s->planeheight[p] - s->borders[p].bottom - 1 - y) * linesize,
+                    s->planewidth[p] * sizeof(uint16_t));
         }
     }
 }
@@ -215,22 +235,23 @@
     int p, y;
 
     for (p = 0; p < s->nb_planes; p++) {
-        uint8_t *ptr = frame->data[p];
+        uint8_t *data = frame->data[p];
         uint8_t fill = s->fill[p];
         int linesize = frame->linesize[p];
 
+        /* fill left and right borders from top to bottom border */
         for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-            memset(ptr + y * linesize, fill, s->borders[p].left);
-            memset(ptr + y * linesize + s->planewidth[p] - s->borders[p].right, fill,
-                   s->borders[p].right);
+            memset(data + y * linesize, fill, s->borders[p].left);
+            memset(data + y * linesize + s->planewidth[p] - s->borders[p].right, fill,
+                    s->borders[p].right);
         }
 
+        /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
-            memset(ptr + y * linesize, fill, s->planewidth[p]);
+            memset(data + y * linesize, fill, s->planewidth[p]);
         }
-
         for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
-            memset(ptr + y * linesize, fill, s->planewidth[p]);
+            memset(data + y * linesize, fill, s->planewidth[p]);
         }
     }
 }
@@ -240,41 +261,32 @@
     int p, y, x;
 
     for (p = 0; p < s->nb_planes; p++) {
-        uint16_t *ptr = (uint16_t *)frame->data[p];
+        uint16_t *data = (uint16_t *)frame->data[p];
         uint16_t fill = s->fill[p] << (s->depth - 8);
-        int linesize = frame->linesize[p] / 2;
+        int linesize = frame->linesize[p] / sizeof(uint16_t);
 
+        /* fill left and right borders from top to bottom border */
         for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
             for (x = 0; x < s->borders[p].left; x++) {
-                ptr[y * linesize + x] = fill;
+                data[y * linesize + x] = fill;
             }
-
             for (x = 0; x < s->borders[p].right; x++) {
-                ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] = fill;
+                data[y * linesize + s->planewidth[p] - s->borders[p].right + x] = fill;
             }
         }
 
+        /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
             for (x = 0; x < s->planewidth[p]; x++) {
-                ptr[y * linesize + x] = fill;
+                data[y * linesize + x] = fill;
             }
         }
-
         for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
             for (x = 0; x < s->planewidth[p]; x++) {
-                ptr[y * linesize + x] = fill;
+                data[y * linesize + x] = fill;
             }
         }
     }
-}
-
-static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
-{
-    FillBordersContext *s = inlink->dst->priv;
-
-    s->fillborders(s, frame);
-
-    return ff_filter_frame(inlink->dst->outputs[0], frame);
 }
 
 static int config_input(AVFilterLink *inlink)
@@ -307,23 +319,23 @@
     s->borders[2].bottom = s->bottom >> desc->log2_chroma_h;
 
     if (inlink->w < s->left + s->right ||
-        inlink->w <= s->left ||
-        inlink->w <= s->right ||
-        inlink->h < s->top + s->bottom ||
-        inlink->h <= s->top ||
-        inlink->h <= s->bottom ||
-        inlink->w < s->left * 2 ||
-        inlink->w < s->right * 2 ||
-        inlink->h < s->top * 2 ||
-        inlink->h < s->bottom * 2) {
+            inlink->w <= s->left ||
+            inlink->w <= s->right ||
+            inlink->h < s->top + s->bottom ||
+            inlink->h <= s->top ||
+            inlink->h <= s->bottom ||
+            inlink->w < s->left * 2 ||
+            inlink->w < s->right * 2 ||
+            inlink->h < s->top * 2 ||
+            inlink->h < s->bottom * 2) {
         av_log(ctx, AV_LOG_ERROR, "Borders are bigger than input frame size.\n");
         return AVERROR(EINVAL);
     }
 
     switch (s->mode) {
-    case FM_SMEAR:  s->fillborders = s->depth <= 8 ? smear_borders8  : smear_borders16;  break;
-    case FM_MIRROR: s->fillborders = s->depth <= 8 ? mirror_borders8 : mirror_borders16; break;
-    case FM_FIXED:  s->fillborders = s->depth <= 8 ? fixed_borders8  : fixed_borders16;  break;
+        case FM_SMEAR:  s->fillborders = s->depth <= 8 ? smear_borders8  : smear_borders16;  break;
+        case FM_MIRROR: s->fillborders = s->depth <= 8 ? mirror_borders8 : mirror_borders16; break;
+        case FM_FIXED:  s->fillborders = s->depth <= 8 ? fixed_borders8  : fixed_borders16;  break;
     }
 
     s->yuv_color[Y] = RGB_TO_Y_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B]);
@@ -336,7 +348,7 @@
         int i;
 
         ff_fill_rgba_map(rgba_map, inlink->format);
-        for (i = 0; i < 4; i++)
+        for (i = 0; i < sizeof(rgba_map); i++)
             s->fill[rgba_map[i]] = s->rgba_color[i];
     } else {
         memcpy(s->fill, s->yuv_color, sizeof(s->yuv_color));
@@ -345,21 +357,14 @@
     return 0;
 }
 
-#define OFFSET(x) offsetof(FillBordersContext, x)
-#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
+{
+    FillBordersContext *s = inlink->dst->priv;
 
-static const AVOption fillborders_options[] = {
-    { "left",   "set the left fill border",   OFFSET(left),   AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,    FLAGS },
-    { "right",  "set the right fill border",  OFFSET(right),  AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,    FLAGS },
-    { "top",    "set the top fill border",    OFFSET(top),    AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,    FLAGS },
-    { "bottom", "set the bottom fill border", OFFSET(bottom), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX,    FLAGS },
-    { "mode",   "set the fill borders mode",  OFFSET(mode),   AV_OPT_TYPE_INT, {.i64=FM_SMEAR}, 0, FM_NB_MODES-1, FLAGS, "mode" },
-        { "smear",  NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_SMEAR},  0, 0, FLAGS, "mode" },
-        { "mirror", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_MIRROR}, 0, 0, FLAGS, "mode" },
-        { "fixed",  NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_FIXED},  0, 0, FLAGS, "mode" },
-    { "color",  "set the color for the fixed mode", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS },
-    { NULL }
-};
+    s->fillborders(s, frame);
+
+    return ff_filter_frame(inlink->dst->outputs[0], frame);
+}
 
 AVFILTER_DEFINE_CLASS(fillborders);
 
>From 792124ba566a9316f754ab6801f8b5d82e6377e3 Mon Sep 17 00:00:00 2001
From: Ulf Zibis <ulf.zi...@cosoco.de>
Date: 22.03.2019, 22:06:29

avfilter/fillborders: avoid needless calculations for performance

diff --git a/libavfilter/vf_fillborders.c b/libavfilter/vf_fillborders.c
index 3d63e88..43de099 100644
--- a/libavfilter/vf_fillborders.c
+++ b/libavfilter/vf_fillborders.c
@@ -18,17 +18,11 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "drawutils.h"
+#include "internal.h"
 #include "libavutil/colorspace.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
-#include "drawutils.h"
-#include "internal.h"
-/*
-#include "libavutil/common.h"
-#include "avfilter.h"
-#include "formats.h"
-#include "video.h"
-*/
 
 enum { Y, U, V, A };
 enum { R, G, B };
@@ -109,14 +103,16 @@
         int linesize = frame->linesize[p];
 
         /* fill left and right borders from top to bottom border */
-        for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-            memset(data + y * linesize,
-                    *(data + y * linesize + s->borders[p].left),
-                    s->borders[p].left);
-            memset(data + y * linesize + s->planewidth[p] - s->borders[p].right,
-                    *(data + y * linesize + s->planewidth[p] - s->borders[p].right - 1),
-                    s->borders[p].right);
-        }
+        if (s->borders[p].left != 0 ||
+                s->borders[p].right != s->planewidth[p]) // in case skip for performance
+            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
+                memset(data + y * linesize,
+                        *(data + y * linesize + s->borders[p].left),
+                        s->borders[p].left);
+                memset(data + y * linesize + s->planewidth[p] - s->borders[p].right,
+                        *(data + y * linesize + s->planewidth[p] - s->borders[p].right - 1),
+                        s->borders[p].right);
+            }
 
         /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
@@ -140,15 +136,17 @@
         int linesize = frame->linesize[p] / sizeof(uint16_t);
 
         /* fill left and right borders from top to bottom border */
-        for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-            for (x = 0; x < s->borders[p].left; x++) {
-                data[y * linesize + x] = *(data + y * linesize + s->borders[p].left);
+        if (s->borders[p].left != 0 ||
+                s->borders[p].right != s->planewidth[p]) // in case skip for performance
+            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
+                for (x = 0; x < s->borders[p].left; x++) {
+                    data[y * linesize + x] = *(data + y * linesize + s->borders[p].left);
+                }
+                for (x = 0; x < s->borders[p].right; x++) {
+                    data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
+                            *(data + y * linesize + s->planewidth[p] - s->borders[p].right - 1);
+                }
             }
-            for (x = 0; x < s->borders[p].right; x++) {
-                data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                    *(data + y * linesize + s->planewidth[p] - s->borders[p].right - 1);
-            }
-        }
 
         /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
@@ -172,15 +170,17 @@
         int linesize = frame->linesize[p];
 
         /* fill left and right borders from top to bottom border */
-        for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-            for (x = 0; x < s->borders[p].left; x++) {
-                data[y * linesize + x] = data[y * linesize + s->borders[p].left * 2 - 1 - x];
+        if (s->borders[p].left != 0 ||
+                s->borders[p].right != s->planewidth[p]) // in case skip for performance
+            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
+                for (x = 0; x < s->borders[p].left; x++) {
+                    data[y * linesize + x] = data[y * linesize + s->borders[p].left * 2 - 1 - x];
+                }
+                for (x = 0; x < s->borders[p].right; x++) {
+                    data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
+                            data[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
+                }
             }
-            for (x = 0; x < s->borders[p].right; x++) {
-                data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                    data[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
-            }
-        }
 
         /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
@@ -205,16 +205,18 @@
         int linesize = frame->linesize[p] / sizeof(uint16_t);
 
         /* fill left and right borders from top to bottom border */
-        for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-            for (x = 0; x < s->borders[p].left; x++) {
-                data[y * linesize + x] = data[y * linesize + s->borders[p].left * 2 - 1 - x];
-            }
+        if (s->borders[p].left != 0 ||
+                s->borders[p].right != s->planewidth[p]) // in case skip for performance
+            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
+                for (x = 0; x < s->borders[p].left; x++) {
+                    data[y * linesize + x] = data[y * linesize + s->borders[p].left * 2 - 1 - x];
+                }
 
-            for (x = 0; x < s->borders[p].right; x++) {
-                data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                    data[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
+                for (x = 0; x < s->borders[p].right; x++) {
+                    data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
+                            data[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
+                }
             }
-        }
 
         /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
@@ -240,11 +242,13 @@
         int linesize = frame->linesize[p];
 
         /* fill left and right borders from top to bottom border */
-        for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-            memset(data + y * linesize, fill, s->borders[p].left);
-            memset(data + y * linesize + s->planewidth[p] - s->borders[p].right, fill,
-                    s->borders[p].right);
-        }
+        if (s->borders[p].left != 0 ||
+                s->borders[p].right != s->planewidth[p]) // in case skip for performance
+            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
+                memset(data + y * linesize, fill, s->borders[p].left);
+                memset(data + y * linesize + s->planewidth[p] - s->borders[p].right, fill,
+                        s->borders[p].right);
+            }
 
         /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
@@ -266,14 +270,16 @@
         int linesize = frame->linesize[p] / sizeof(uint16_t);
 
         /* fill left and right borders from top to bottom border */
-        for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-            for (x = 0; x < s->borders[p].left; x++) {
-                data[y * linesize + x] = fill;
+        if (s->borders[p].left != 0 ||
+                s->borders[p].right != s->planewidth[p]) // in case skip for performance
+            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
+                for (x = 0; x < s->borders[p].left; x++) {
+                    data[y * linesize + x] = fill;
+                }
+                for (x = 0; x < s->borders[p].right; x++) {
+                    data[y * linesize + s->planewidth[p] - s->borders[p].right + x] = fill;
+                }
             }
-            for (x = 0; x < s->borders[p].right; x++) {
-                data[y * linesize + s->planewidth[p] - s->borders[p].right + x] = fill;
-            }
-        }
 
         /* fill top and bottom borders */
         for (y = 0; y < s->borders[p].top; y++) {
@@ -294,6 +300,20 @@
     AVFilterContext *ctx = inlink->dst;
     FillBordersContext *s = ctx->priv;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+
+    if (inlink->w < s->left + s->right ||
+            inlink->w <= s->left ||
+            inlink->w <= s->right ||
+            inlink->h < s->top + s->bottom ||
+            inlink->h <= s->top ||
+            inlink->h <= s->bottom ||
+            inlink->w < s->left * 2 ||
+            inlink->w < s->right * 2 ||
+            inlink->h < s->top * 2 ||
+            inlink->h < s->bottom * 2) {
+        av_log(ctx, AV_LOG_ERROR, "Borders are bigger than input frame size.\n");
+        return AVERROR(EINVAL);
+    }
 
     s->nb_planes = desc->nb_components;
     s->depth = desc->comp[0].depth;
@@ -318,40 +338,23 @@
     s->borders[2].top    = s->top >> desc->log2_chroma_h;
     s->borders[2].bottom = s->bottom >> desc->log2_chroma_h;
 
-    if (inlink->w < s->left + s->right ||
-            inlink->w <= s->left ||
-            inlink->w <= s->right ||
-            inlink->h < s->top + s->bottom ||
-            inlink->h <= s->top ||
-            inlink->h <= s->bottom ||
-            inlink->w < s->left * 2 ||
-            inlink->w < s->right * 2 ||
-            inlink->h < s->top * 2 ||
-            inlink->h < s->bottom * 2) {
-        av_log(ctx, AV_LOG_ERROR, "Borders are bigger than input frame size.\n");
-        return AVERROR(EINVAL);
-    }
-
     switch (s->mode) {
         case FM_SMEAR:  s->fillborders = s->depth <= 8 ? smear_borders8  : smear_borders16;  break;
         case FM_MIRROR: s->fillborders = s->depth <= 8 ? mirror_borders8 : mirror_borders16; break;
-        case FM_FIXED:  s->fillborders = s->depth <= 8 ? fixed_borders8  : fixed_borders16;  break;
-    }
-
-    s->yuv_color[Y] = RGB_TO_Y_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B]);
-    s->yuv_color[U] = RGB_TO_U_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B], 0);
-    s->yuv_color[V] = RGB_TO_V_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B], 0);
-    s->yuv_color[A] = s->rgba_color[A];
-
-    if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
-        uint8_t rgba_map[4];
-        int i;
-
-        ff_fill_rgba_map(rgba_map, inlink->format);
-        for (i = 0; i < sizeof(rgba_map); i++)
-            s->fill[rgba_map[i]] = s->rgba_color[i];
-    } else {
-        memcpy(s->fill, s->yuv_color, sizeof(s->yuv_color));
+        case FM_FIXED:  s->fillborders = s->depth <= 8 ? fixed_borders8  : fixed_borders16;
+            if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
+                uint8_t rgba_map[4];
+                int i;
+                ff_fill_rgba_map(rgba_map, inlink->format);
+                for (i = 0; i < sizeof(rgba_map); i++)
+                    s->fill[rgba_map[i]] = s->rgba_color[i];
+            } else {
+                s->yuv_color[Y] = RGB_TO_Y_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B]);
+                s->yuv_color[U] = RGB_TO_U_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B], 0);
+                s->yuv_color[V] = RGB_TO_V_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B], 0);
+                s->yuv_color[A] = s->rgba_color[A];
+                memcpy(s->fill, s->yuv_color, sizeof(s->yuv_color));
+            } break;
     }
 
     return 0;
>From 727ead94327e04b9f1128af97dc8607b5276d739 Mon Sep 17 00:00:00 2001
From: Ulf Zibis <ulf.zi...@cosoco.de>
Date: 24.03.2019, 00:02:09

avfilter/fillborders: enhanced readability;
side effect: better performance by less indirections in for loops

diff --git a/libavfilter/vf_fillborders.c b/libavfilter/vf_fillborders.c
index 43de099..f6631c3 100644
--- a/libavfilter/vf_fillborders.c
+++ b/libavfilter/vf_fillborders.c
@@ -101,28 +101,30 @@
     for (p = 0; p < s->nb_planes; p++) {
         uint8_t *data = frame->data[p];
         int linesize = frame->linesize[p];
+        int width = s->planewidth[p];
+        int height = s->planeheight[p];
+        int left = s->borders[p].left;
+        int right = s->borders[p].right;
+        int top = s->borders[p].top;
+        int bottom = s->borders[p].bottom;
 
         /* fill left and right borders from top to bottom border */
-        if (s->borders[p].left != 0 ||
-                s->borders[p].right != s->planewidth[p]) // in case skip for performance
-            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
+        if (left != 0 || right != width) // in case skip for performance
+            for (y = top; y < height - bottom; y++) {
                 memset(data + y * linesize,
-                        *(data + y * linesize + s->borders[p].left),
-                        s->borders[p].left);
-                memset(data + y * linesize + s->planewidth[p] - s->borders[p].right,
-                        *(data + y * linesize + s->planewidth[p] - s->borders[p].right - 1),
-                        s->borders[p].right);
+                        *(data + y * linesize + left), left);
+                memset(data + y * linesize + width - right,
+                        *(data + y * linesize + width - right - 1), right);
             }
 
         /* fill top and bottom borders */
-        for (y = 0; y < s->borders[p].top; y++) {
+        for (y = 0; y < top; y++) {
             memcpy(data + y * linesize,
-                    data + s->borders[p].top * linesize, s->planewidth[p]);
+                    data + top * linesize, width);
         }
-        for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
+        for (y = height - bottom; y < height; y++) {
             memcpy(data + y * linesize,
-                    data + (s->planeheight[p] - s->borders[p].bottom - 1) * linesize,
-                    s->planewidth[p]);
+                    data + (height - bottom - 1) * linesize, width);
         }
     }
 }
@@ -134,29 +136,33 @@
     for (p = 0; p < s->nb_planes; p++) {
         uint16_t *data = (uint16_t *)frame->data[p];
         int linesize = frame->linesize[p] / sizeof(uint16_t);
+        int width = s->planewidth[p];
+        int height = s->planeheight[p];
+        int left = s->borders[p].left;
+        int right = s->borders[p].right;
+        int top = s->borders[p].top;
+        int bottom = s->borders[p].bottom;
 
         /* fill left and right borders from top to bottom border */
-        if (s->borders[p].left != 0 ||
-                s->borders[p].right != s->planewidth[p]) // in case skip for performance
-            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-                for (x = 0; x < s->borders[p].left; x++) {
-                    data[y * linesize + x] = *(data + y * linesize + s->borders[p].left);
+        if (left != 0 || right != width) // in case skip for performance
+            for (y = top; y < height - bottom; y++) {
+                for (x = 0; x < left; x++) {
+                    data[y * linesize + x] = data[y * linesize + left];
                 }
-                for (x = 0; x < s->borders[p].right; x++) {
-                    data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                            *(data + y * linesize + s->planewidth[p] - s->borders[p].right - 1);
+                for (x = 0; x < right; x++) {
+                    data[y * linesize + width - right + x] =
+                            data[y * linesize + width - right - 1];
                 }
             }
 
         /* fill top and bottom borders */
-        for (y = 0; y < s->borders[p].top; y++) {
+        for (y = 0; y < top; y++) {
             memcpy(data + y * linesize,
-                    data + s->borders[p].top * linesize, s->planewidth[p] * sizeof(uint16_t));
+                    data + top * linesize, width * sizeof(uint16_t));
         }
-        for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
+        for (y = height - bottom; y < height; y++) {
             memcpy(data + y * linesize,
-                    data + (s->planeheight[p] - s->borders[p].bottom - 1) * linesize,
-                    s->planewidth[p] * sizeof(uint16_t));
+                    data + (height - bottom - 1) * linesize, width * sizeof(uint16_t));
         }
     }
 }
@@ -168,30 +174,33 @@
     for (p = 0; p < s->nb_planes; p++) {
         uint8_t *data = frame->data[p];
         int linesize = frame->linesize[p];
+        int width = s->planewidth[p];
+        int height = s->planeheight[p];
+        int left = s->borders[p].left;
+        int right = s->borders[p].right;
+        int top = s->borders[p].top;
+        int bottom = s->borders[p].bottom;
 
         /* fill left and right borders from top to bottom border */
-        if (s->borders[p].left != 0 ||
-                s->borders[p].right != s->planewidth[p]) // in case skip for performance
-            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-                for (x = 0; x < s->borders[p].left; x++) {
-                    data[y * linesize + x] = data[y * linesize + s->borders[p].left * 2 - 1 - x];
+        if (left != 0 || right != width) // in case skip for performance
+            for (y = top; y < height - bottom; y++) {
+                for (x = 0; x < left; x++) {
+                    data[y * linesize + x] = data[y * linesize + left * 2 - 1 - x];
                 }
-                for (x = 0; x < s->borders[p].right; x++) {
-                    data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                            data[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
+                for (x = 0; x < right; x++) {
+                    data[y * linesize + width - right + x] =
+                            data[y * linesize + width - right - 1 - x];
                 }
             }
 
         /* fill top and bottom borders */
-        for (y = 0; y < s->borders[p].top; y++) {
+        for (y = 0; y < top; y++) {
             memcpy(data + y * linesize,
-                    data + (s->borders[p].top * 2 - 1 - y) * linesize,
-                    s->planewidth[p]);
+                    data + (top * 2 - 1 - y) * linesize, width);
         }
-        for (y = 0; y < s->borders[p].bottom; y++) {
-            memcpy(data + (s->planeheight[p] - s->borders[p].bottom + y) * linesize,
-                    data + (s->planeheight[p] - s->borders[p].bottom - 1 - y) * linesize,
-                    s->planewidth[p]);
+        for (y = 0; y < bottom; y++) {
+            memcpy(data + (height - bottom + y) * linesize,
+                    data + (height - bottom - 1 - y) * linesize, width);
         }
     }
 }
@@ -203,31 +212,34 @@
     for (p = 0; p < s->nb_planes; p++) {
         uint16_t *data = (uint16_t *)frame->data[p];
         int linesize = frame->linesize[p] / sizeof(uint16_t);
+        int width = s->planewidth[p];
+        int height = s->planeheight[p];
+        int left = s->borders[p].left;
+        int right = s->borders[p].right;
+        int top = s->borders[p].top;
+        int bottom = s->borders[p].bottom;
 
         /* fill left and right borders from top to bottom border */
-        if (s->borders[p].left != 0 ||
-                s->borders[p].right != s->planewidth[p]) // in case skip for performance
-            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-                for (x = 0; x < s->borders[p].left; x++) {
-                    data[y * linesize + x] = data[y * linesize + s->borders[p].left * 2 - 1 - x];
+        if (left != 0 || right != width) // in case skip for performance
+            for (y = top; y < height - bottom; y++) {
+                for (x = 0; x < left; x++) {
+                    data[y * linesize + x] = data[y * linesize + left * 2 - 1 - x];
                 }
 
-                for (x = 0; x < s->borders[p].right; x++) {
-                    data[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-                            data[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
+                for (x = 0; x < right; x++) {
+                    data[y * linesize + width - right + x] =
+                            data[y * linesize + width - right - 1 - x];
                 }
             }
 
         /* fill top and bottom borders */
-        for (y = 0; y < s->borders[p].top; y++) {
+        for (y = 0; y < top; y++) {
             memcpy(data + y * linesize,
-                    data + (s->borders[p].top * 2 - 1 - y) * linesize,
-                    s->planewidth[p] * sizeof(uint16_t));
+                    data + (top * 2 - 1 - y) * linesize, width * sizeof(uint16_t));
         }
-        for (y = 0; y < s->borders[p].bottom; y++) {
-            memcpy(data + (s->planeheight[p] - s->borders[p].bottom + y) * linesize,
-                    data + (s->planeheight[p] - s->borders[p].bottom - 1 - y) * linesize,
-                    s->planewidth[p] * sizeof(uint16_t));
+        for (y = 0; y < bottom; y++) {
+            memcpy(data + (height - bottom + y) * linesize,
+                    data + (height - bottom - 1 - y) * linesize, width * sizeof(uint16_t));
         }
     }
 }
@@ -238,24 +250,28 @@
 
     for (p = 0; p < s->nb_planes; p++) {
         uint8_t *data = frame->data[p];
-        uint8_t fill = s->fill[p];
         int linesize = frame->linesize[p];
+        int width = s->planewidth[p];
+        int height = s->planeheight[p];
+        int left = s->borders[p].left;
+        int right = s->borders[p].right;
+        int top = s->borders[p].top;
+        int bottom = s->borders[p].bottom;
+        uint8_t fill = s->fill[p];
 
         /* fill left and right borders from top to bottom border */
-        if (s->borders[p].left != 0 ||
-                s->borders[p].right != s->planewidth[p]) // in case skip for performance
-            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-                memset(data + y * linesize, fill, s->borders[p].left);
-                memset(data + y * linesize + s->planewidth[p] - s->borders[p].right, fill,
-                        s->borders[p].right);
+        if (left != 0 || right != width) // in case skip for performance
+            for (y = top; y < height - bottom; y++) {
+                memset(data + y * linesize, fill, left);
+                memset(data + y * linesize + width - right, fill, right);
             }
 
         /* fill top and bottom borders */
-        for (y = 0; y < s->borders[p].top; y++) {
-            memset(data + y * linesize, fill, s->planewidth[p]);
+        for (y = 0; y < top; y++) {
+            memset(data + y * linesize, fill, width);
         }
-        for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
-            memset(data + y * linesize, fill, s->planewidth[p]);
+        for (y = height - bottom; y < height; y++) {
+            memset(data + y * linesize, fill, width);
         }
     }
 }
@@ -266,29 +282,34 @@
 
     for (p = 0; p < s->nb_planes; p++) {
         uint16_t *data = (uint16_t *)frame->data[p];
-        uint16_t fill = s->fill[p] << (s->depth - 8);
         int linesize = frame->linesize[p] / sizeof(uint16_t);
+        int width = s->planewidth[p];
+        int height = s->planeheight[p];
+        int left = s->borders[p].left;
+        int right = s->borders[p].right;
+        int top = s->borders[p].top;
+        int bottom = s->borders[p].bottom;
+        uint16_t fill = s->fill[p] << (s->depth - 8);
 
         /* fill left and right borders from top to bottom border */
-        if (s->borders[p].left != 0 ||
-                s->borders[p].right != s->planewidth[p]) // in case skip for performance
-            for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
-                for (x = 0; x < s->borders[p].left; x++) {
+        if (left != 0 || right != width) // in case skip for performance
+            for (y = top; y < height - bottom; y++) {
+                for (x = 0; x < left; x++) {
                     data[y * linesize + x] = fill;
                 }
-                for (x = 0; x < s->borders[p].right; x++) {
-                    data[y * linesize + s->planewidth[p] - s->borders[p].right + x] = fill;
+                for (x = 0; x < right; x++) {
+                    data[y * linesize + width - right + x] = fill;
                 }
             }
 
         /* fill top and bottom borders */
-        for (y = 0; y < s->borders[p].top; y++) {
-            for (x = 0; x < s->planewidth[p]; x++) {
+        for (y = 0; y < top; y++) {
+            for (x = 0; x < width; x++) {
                 data[y * linesize + x] = fill;
             }
         }
-        for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
-            for (x = 0; x < s->planewidth[p]; x++) {
+        for (y = height - bottom; y < height; y++) {
+            for (x = 0; x < width; x++) {
                 data[y * linesize + x] = fill;
             }
         }
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to