summaryrefslogtreecommitdiff
path: root/libavfilter/vf_fillborders.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2021-07-24 20:20:52 +0200
committerPaul B Mahol <onemda@gmail.com>2021-07-24 20:23:58 +0200
commitd5c76450f813d16340c03500a9eaa5771eeb7fb4 (patch)
treef7c81a39faff9bb211b53969c717a75b48223883 /libavfilter/vf_fillborders.c
parent94c90b3261fe1eb8b8f4131c4eb135b611e10e30 (diff)
downloadffmpeg-d5c76450f813d16340c03500a9eaa5771eeb7fb4.tar.gz
avfilter/vf_fillborders: add another mode
Diffstat (limited to 'libavfilter/vf_fillborders.c')
-rw-r--r--libavfilter/vf_fillborders.c97
1 files changed, 96 insertions, 1 deletions
diff --git a/libavfilter/vf_fillborders.c b/libavfilter/vf_fillborders.c
index 36b96f9e51..2515bc9de9 100644
--- a/libavfilter/vf_fillborders.c
+++ b/libavfilter/vf_fillborders.c
@@ -32,7 +32,7 @@
enum { Y, U, V, A };
enum { R, G, B };
-enum FillMode { FM_SMEAR, FM_MIRROR, FM_FIXED, FM_REFLECT, FM_WRAP, FM_FADE, FM_NB_MODES };
+enum FillMode { FM_SMEAR, FM_MIRROR, FM_FIXED, FM_REFLECT, FM_WRAP, FM_FADE, FM_MARGINS, FM_NB_MODES };
typedef struct Borders {
int left, right, top, bottom;
@@ -495,6 +495,99 @@ static void fade_borders16(FillBordersContext *s, AVFrame *frame)
}
}
+static void margins_borders8(FillBordersContext *s, AVFrame *frame)
+{
+ for (int p = 0; p < s->nb_planes; p++) {
+ uint8_t *ptr = (uint8_t *)frame->data[p];
+ const int linesize = frame->linesize[p];
+ const int left = s->borders[p].left;
+ const int right = s->borders[p].right;
+ const int top = s->borders[p].top;
+ const int bottom = s->borders[p].bottom;
+ const int width = s->planewidth[p];
+ const int height = s->planeheight[p];
+
+ for (int y = top; y < height - bottom; y++) {
+ memset(ptr + linesize * y, ptr[linesize * y + left], left);
+ memset(ptr + linesize * y + width - right, (ptr + linesize * y + width - right)[-1], right);
+ }
+
+ for (int y = top - 1; y >= 0; y--) {
+ ptr[linesize * y] = ptr[linesize * (y + 1)];
+ memcpy(ptr + linesize * y + width - 8, ptr + linesize * (y + 1) + width - 8, 8);
+
+ for (int x = 1; x < width - 8; x++) {
+ int prev = ptr[linesize * (y + 1) + x - 1];
+ int cur = ptr[linesize * (y + 1) + x];
+ int next = ptr[linesize * (y + 1) + x + 1];
+
+ ptr[linesize * y + x] = (3 * prev + 2 * cur + 3 * next + 4) >> 3;
+ }
+ }
+
+ for (int y = height - bottom; y < height; y++) {
+ ptr[linesize * y] = ptr[linesize * (y - 1)];
+ memcpy(ptr + linesize * y + width - 8, ptr + linesize * (y - 1) + width - 8, 8);
+
+ for (int x = 1; x < width - 8; x++) {
+ int prev = ptr[linesize * (y - 1) + x - 1];
+ int cur = ptr[linesize * (y - 1) + x];
+ int next = ptr[linesize * (y - 1) + x + 1];
+
+ ptr[linesize * y + x] = (3 * prev + 2 * cur + 3 * next + 4) >> 3;
+ }
+ }
+ }
+}
+
+static void margins_borders16(FillBordersContext *s, AVFrame *frame)
+{
+ for (int p = 0; p < s->nb_planes; p++) {
+ uint16_t *ptr = (uint16_t *)frame->data[p];
+ const int linesize = frame->linesize[p] / 2;
+ const int left = s->borders[p].left;
+ const int right = s->borders[p].right;
+ const int top = s->borders[p].top;
+ const int bottom = s->borders[p].bottom;
+ const int width = s->planewidth[p];
+ const int height = s->planeheight[p];
+
+ for (int y = top; y < height - bottom; y++) {
+ for (int x = 0; x < left; x++)
+ ptr[linesize * y + x] = ptr[linesize * y + left];
+
+ for (int x = 0; x < right; x++)
+ ptr[linesize * y + width - right + x] = ptr[linesize * y + width - right - 1];
+ }
+
+ for (int y = top - 1; y >= 0; y--) {
+ ptr[linesize * y] = ptr[linesize * (y + 1)];
+ memcpy(ptr + linesize * y + width - 8, ptr + linesize * (y + 1) + width - 8, 16);
+
+ for (int x = 1; x < width - 8; x++) {
+ int prev = ptr[linesize * (y + 1) + x - 1];
+ int cur = ptr[linesize * (y + 1) + x];
+ int next = ptr[linesize * (y + 1) + x + 1];
+
+ ptr[linesize * y + x] = (3 * prev + 2 * cur + 3 * next + 4) >> 3;
+ }
+ }
+
+ for (int y = height - bottom; y < height; y++) {
+ ptr[linesize * y] = ptr[linesize * (y - 1)];
+ memcpy(ptr + linesize * y + width - 8, ptr + linesize * (y - 1) + width - 8, 16);
+
+ for (int x = 1; x < width - 8; x++) {
+ int prev = ptr[linesize * (y - 1) + x - 1];
+ int cur = ptr[linesize * (y - 1) + x];
+ int next = ptr[linesize * (y - 1) + x + 1];
+
+ ptr[linesize * y + x] = (3 * prev + 2 * cur + 3 * next + 4) >> 3;
+ }
+ }
+ }
+}
+
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
{
FillBordersContext *s = inlink->dst->priv;
@@ -554,6 +647,7 @@ static int config_input(AVFilterLink *inlink)
case FM_REFLECT:s->fillborders = s->depth <= 8 ? reflect_borders8: reflect_borders16;break;
case FM_WRAP: s->fillborders = s->depth <= 8 ? wrap_borders8 : wrap_borders16; break;
case FM_FADE: s->fillborders = s->depth <= 8 ? fade_borders8 : fade_borders16; break;
+ case FM_MARGINS:s->fillborders = s->depth <= 8 ? margins_borders8: margins_borders16;break;
default: av_assert0(0);
}
@@ -603,6 +697,7 @@ static const AVOption fillborders_options[] = {
{ "reflect",NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_REFLECT},0, 0, FLAGS, "mode" },
{ "wrap", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_WRAP}, 0, 0, FLAGS, "mode" },
{ "fade", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_FADE}, 0, 0, FLAGS, "mode" },
+ { "margins",NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_MARGINS},0, 0, FLAGS, "mode" },
{ "color", "set the color for the fixed/fade mode", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS },
{ NULL }
};