Hi again,

Am 12.03.19 um 00:37 schrieb Carl Eugen Hoyos:
> 2019-03-12 0:25 GMT+01:00, Moritz Barsnick <barsn...@gmx.net>:
>> Ideally, you use the START_TIMER/STOP_TIMER macros to
>> profile the actual functions you changed. (Check this mailing list's
>> archives for some examples, and play with the code.)
> But this should not be needed if time (the command) and / or
> benchmark (the FFmpeg option) show clear improvements.

With the benchmark option I can not see the time for the filter, just
for the de/encoding, and as I assume, that this filter is much faster
than the de/encoding around it, I suspect, the overall time will be helpful.

So I have "played" with the START_TIMER/STOP_TIMER macros.

Now I'm kind of helpless, as the numbers I get are varying in wide
range. It seems, that my changes help a little for e.g. "-vf
fillborders:0:0:5:5:mirror". This is what I expected by bypassing the
code loops for the right/left borders, when there is nothing to do, but
the timer results are "noisy".

I attach the patches for the first 2 chunks again, and too the patches
for my timed version. Hopefully you have the time to play a little with
that and can give me hints, how I could get more reliable numbers. (I
just had closed all other applications like Firefox, Transmission etc.
before running the benchmarks)

-Ulf

==========================================================================
$ debug/fillborders.sh
Test[0] ======> 3-plane 8-bit YUV-colour:    CYD_1005.jpg <======
./ffmpeg-p1 : CYD_1005.jpg --> ZZ_CYD_1005_mirror-0-0-5-5.jpg
 122670 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 133020 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,       1
runs,      0 skips
 118350 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 124740 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 122130 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
./ffmpeg-p2 : CYD_1005.jpg --> ZZ_CYD_1005_mirror-0-0-5-5.jpg
 118800 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 123840 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 121500 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 135090 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 126270 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 125730 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
./ffmpeg-p1 : CYD_1005.jpg --> ZZ_CYD_1005_mirror-5-5-0-0.jpg
 557730 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 614880 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 598410 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 545940 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 591030 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 566910 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
./ffmpeg-p2 : CYD_1005.jpg --> ZZ_CYD_1005_mirror-5-5-0-0.jpg
 542430 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 567900 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 490050 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 579330 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 521370 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 890370 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
./ffmpeg-p1 : CYD_1005.jpg --> ZZ_CYD_1005_mirror-5-5-5-5.jpg
 576540 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 597060 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 599940 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 621900 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 588870 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 606600 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
./ffmpeg-p2 : CYD_1005.jpg --> ZZ_CYD_1005_mirror-5-5-5-5.jpg
 522090 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 655650 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 609660 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 600300 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 561510 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 630090 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
=====================================================================================
$ debug/fillborders.sh
Test[0] ======> 3-plane 8-bit YUV-colour:    CYD_1005.jpg <======
./ffmpeg-p1 : CYD_1005.jpg --> ZZ_CYD_1005_mirror-0-0-5-5.jpg
 131220 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 141030 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 135900 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 133380 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 148230 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 119880 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
./ffmpeg-p2 : CYD_1005.jpg --> ZZ_CYD_1005_mirror-0-0-5-5.jpg
 165870 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 120960 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 126450 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 122310 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 132660 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 122940 decicycles in fillborders=0:0:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
./ffmpeg-p1 : CYD_1005.jpg --> ZZ_CYD_1005_mirror-5-5-0-0.jpg
 578160 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 571140 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 652320 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 571500 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 756810 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 515880 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
./ffmpeg-p2 : CYD_1005.jpg --> ZZ_CYD_1005_mirror-5-5-0-0.jpg
 625140 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 595260 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 552600 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 636390 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 687960 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
 648900 decicycles in fillborders=5:5:0:0:mirror 3p-8bit-1x1,       1
runs,      0 skips
./ffmpeg-p1 : CYD_1005.jpg --> ZZ_CYD_1005_mirror-5-5-5-5.jpg
 578610 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 552060 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 604980 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 486900 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 498780 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 549900 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
./ffmpeg-p2 : CYD_1005.jpg --> ZZ_CYD_1005_mirror-5-5-5-5.jpg
 642240 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 658710 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
1701630 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 676350 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 622350 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
 693630 decicycles in fillborders=5:5:5:5:mirror 3p-8bit-1x1,       1
runs,      0 skips
==============================================================================


>From b07ff408d579c49fef93041bedb3b894d914f2b8 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;

diff --git a/libavfilter/vf_fillborders.c b/libavfilter/vf_fillborders.c
index 1344587..8b7ad18 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 };
@@ -87,27 +89,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 +120,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 +152,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 +185,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 +219,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,29 +245,29 @@
     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;
             }
         }
     }
@@ -307,23 +312,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 +341,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));
>From 3c8b9762468e3fdafca5e9634855222e855176de Mon Sep 17 00:00:00 2001
From: Ulf Zibis <ulf.zi...@cosoco.de>
Date: 19.03.2019, 02:52:44

avfilter/fillborders: avoid needless calculations for performance

diff --git a/libavfilter/vf_fillborders.c b/libavfilter/vf_fillborders.c
index 8b7ad18..401200f 100644
--- a/libavfilter/vf_fillborders.c
+++ b/libavfilter/vf_fillborders.c
@@ -93,14 +93,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++) {
@@ -124,15 +126,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++) {
@@ -156,15 +160,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++) {
@@ -189,16 +195,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++) {
@@ -224,11 +232,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++) {
@@ -250,14 +260,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++) {
@@ -288,6 +300,20 @@
     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;
 
@@ -311,40 +337,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 1cb5bd2705cc4d6d16e7b48b8fe6d934c963f64a Mon Sep 17 00:00:00 2001
From: Ulf Zibis <ulf.zi...@cosoco.de>
Date: 18.03.2019, 17:53:08

avfilter/fillborders: added benchmark timer

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..671032b
--- /dev/null
+++ b/debug/fillborders.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+i=0
+test[i++]="3-plane 8-bit YUV-colour:    CYD_1005.jpg"
+test[i++]="4-plane 8-bit RGB-colour:    8.jpg"
+test[i++]="4-plane 16-bit RGB-colour:   16.jpg"
+
+for ((i=0;i<${#test[@]};i++))
+do
+    echo "Test[$i] ======> ${test[i]} <======"
+    input=${test[i]##* }
+    mode="mirror"
+    #mode="fixed:green"
+    for borders in "0:0:5:5" "5:5:0:0" "5:5:5:5"
+    do
+        output="ZZ_${input%.*}_${mode%:*}-${borders//:/-}.${input##*.}"
+        for patch in "ffmpeg     " "./ffmpeg-p1"
+        do
+            echo "${patch} ${input} --> ${output}"
+            for ((benchmark=0;benchmark<3;benchmark++))
+            do
+                 ${patch} -y -v error -i debug/${input} -vf fillborders=${borders}:${mode} debug/${output}
+            done
+        done
+    done
+done
diff --git a/libavfilter/vf_fillborders.c b/libavfilter/vf_fillborders.c
index 8b7ad18..e06b8e8 100644
--- a/libavfilter/vf_fillborders.c
+++ b/libavfilter/vf_fillborders.c
@@ -277,8 +277,23 @@
 {
     FillBordersContext *s = inlink->dst->priv;
 
+    char testcase[128];
+    const char *mode;
+    switch (s->mode) {
+        case FM_SMEAR:  mode = "smear";  break;
+        case FM_MIRROR: mode = "mirror"; break;
+        case FM_FIXED:  mode = "fixed";  break;
+    }
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+    sprintf(testcase, "fillborders=%d:%d:%d:%d:%s %dp-%dbit-%dx%d",
+            s->left, s->right, s->top, s->bottom, mode,
+            s->nb_planes, s->depth, desc->log2_chroma_w, desc->log2_chroma_h);
+    START_TIMER
+
     s->fillborders(s, frame);
 
+    STOP_TIMER(testcase)
+    
     return ff_filter_frame(inlink->dst->outputs[0], frame);
 }
 
>From 8201c51ced164efdcee292f71cc94d0a7ab38b18 Mon Sep 17 00:00:00 2001
From: Ulf Zibis <ulf.zi...@cosoco.de>
Date: 19.03.2019, 02:52:44

avfilter/fillborders: avoid needless calculations for performance; added ffmpeg-p2 and rgba64le-lzw.tif to benchmark

diff --git a/debug/fillborders.sh b/debug/fillborders.sh
index 671032b..1bd7e12 100755
--- a/debug/fillborders.sh
+++ b/debug/fillborders.sh
@@ -1,8 +1,9 @@
 #!/bin/bash
 i=0
-test[i++]="3-plane 8-bit YUV-colour:    CYD_1005.jpg"
-test[i++]="4-plane 8-bit RGB-colour:    8.jpg"
-test[i++]="4-plane 16-bit RGB-colour:   16.jpg"
+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
@@ -13,10 +14,10 @@
     for borders in "0:0:5:5" "5:5:0:0" "5:5:5:5"
     do
         output="ZZ_${input%.*}_${mode%:*}-${borders//:/-}.${input##*.}"
-        for patch in "ffmpeg     " "./ffmpeg-p1"
+        for patch in "./ffmpeg-p1" "./ffmpeg-p2"
         do
-            echo "${patch} ${input} --> ${output}"
-            for ((benchmark=0;benchmark<3;benchmark++))
+            echo "${patch} : ${input} --> ${output}"
+            for ((benchmark=0;benchmark<6;benchmark++))
             do
                  ${patch} -y -v error -i debug/${input} -vf fillborders=${borders}:${mode} debug/${output}
             done
diff --git a/libavfilter/vf_fillborders.c b/libavfilter/vf_fillborders.c
index e06b8e8..15cf5d9 100644
--- a/libavfilter/vf_fillborders.c
+++ b/libavfilter/vf_fillborders.c
@@ -93,14 +93,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++) {
@@ -124,15 +126,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++) {
@@ -156,15 +160,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++) {
@@ -189,16 +195,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++) {
@@ -224,11 +232,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++) {
@@ -250,14 +260,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++) {
@@ -303,6 +315,20 @@
     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;
 
@@ -326,40 +352,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;
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to