History

avfilter/vf_fillborders: add more fill modes

Paul B Mahol committed 5 years ago

Commit 90720da1 parent 20b09b22 files · +146 −2Browse files

Unified · Split

2 files
  1. doc/filters.texi +7 −1
  2. libavfilter/vf_fillborders.c +139 −1
doc/filters.texi+7−1
@@ -11756,10 +11756,16 @@ It accepts the following values: · 11755 unmodified lines
1175611756 fill pixels using outermost pixels
1175711757
1175811758 @item mirror
11759−fill pixels using mirroring
11759+fill pixels using mirroring (half sample symmetric)
1176011760
1176111761 @item fixed
1176211762 fill pixels with constant value
11763+
11764+@item reflect
11765+fill pixels using reflecting (whole sample symmetric)
11766+
11767+@item wrap
11768+fill pixels using wrapping
1176311769 @end table
1176411770
1176511771 Default is @var{smear}.
libavfilter/vf_fillborders.c+139−1
@@ -18,6 +18,7 @@ · 17 unmodified lines
1818 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1919 */
2020
21+#include "libavutil/avassert.h"
2122 #include "libavutil/colorspace.h"
2223 #include "libavutil/common.h"
2324 #include "libavutil/opt.h"
@@ -31,7 +32,7 @@ · 7 unmodified lines
3132 enum { Y, U, V, A };
3233 enum { R, G, B };
3334
34−enum FillMode { FM_SMEAR, FM_MIRROR, FM_FIXED, FM_NB_MODES };
35+enum FillMode { FM_SMEAR, FM_MIRROR, FM_FIXED, FM_REFLECT, FM_WRAP, FM_NB_MODES };
3536
3637 typedef struct Borders {
3738 int left, right, top, bottom;
@@ -269,6 +270,138 @@ static void fixed_borders16(FillBordersContext *s, AVFrame *frame) · 231 unmodified lines
269270 }
270271 }
271272
273+static void reflect_borders8(FillBordersContext *s, AVFrame *frame)
274+{
275+ int p, y, x;
276+
277+ for (p = 0; p < s->nb_planes; p++) {
278+ uint8_t *ptr = frame->data[p];
279+ int linesize = frame->linesize[p];
280+
281+ for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
282+ for (x = 0; x < s->borders[p].left; x++) {
283+ ptr[y * linesize + x] = ptr[y * linesize + s->borders[p].left * 2 - x];
284+ }
285+
286+ for (x = 0; x < s->borders[p].right; x++) {
287+ ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
288+ ptr[y * linesize + s->planewidth[p] - s->borders[p].right - 2 - x];
289+ }
290+ }
291+
292+ for (y = 0; y < s->borders[p].top; y++) {
293+ memcpy(ptr + y * linesize,
294+ ptr + (s->borders[p].top * 2 - y) * linesize,
295+ s->planewidth[p]);
296+ }
297+
298+ for (y = 0; y < s->borders[p].bottom; y++) {
299+ memcpy(ptr + (s->planeheight[p] - s->borders[p].bottom + y) * linesize,
300+ ptr + (s->planeheight[p] - s->borders[p].bottom - 2 - y) * linesize,
301+ s->planewidth[p]);
302+ }
303+ }
304+}
305+
306+static void reflect_borders16(FillBordersContext *s, AVFrame *frame)
307+{
308+ int p, y, x;
309+
310+ for (p = 0; p < s->nb_planes; p++) {
311+ uint16_t *ptr = (uint16_t *)frame->data[p];
312+ int linesize = frame->linesize[p] / 2;
313+
314+ for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
315+ for (x = 0; x < s->borders[p].left; x++) {
316+ ptr[y * linesize + x] = ptr[y * linesize + s->borders[p].left * 2 - x];
317+ }
318+
319+ for (x = 0; x < s->borders[p].right; x++) {
320+ ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
321+ ptr[y * linesize + s->planewidth[p] - s->borders[p].right - 2 - x];
322+ }
323+ }
324+
325+ for (y = 0; y < s->borders[p].top; y++) {
326+ memcpy(ptr + y * linesize,
327+ ptr + (s->borders[p].top * 2 - y) * linesize,
328+ s->planewidth[p] * 2);
329+ }
330+
331+ for (y = 0; y < s->borders[p].bottom; y++) {
332+ memcpy(ptr + (s->planeheight[p] - s->borders[p].bottom + y) * linesize,
333+ ptr + (s->planeheight[p] - s->borders[p].bottom - 2 - y) * linesize,
334+ s->planewidth[p] * 2);
335+ }
336+ }
337+}
338+
339+static void wrap_borders8(FillBordersContext *s, AVFrame *frame)
340+{
341+ int p, y, x;
342+
343+ for (p = 0; p < s->nb_planes; p++) {
344+ uint8_t *ptr = frame->data[p];
345+ int linesize = frame->linesize[p];
346+
347+ for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
348+ for (x = 0; x < s->borders[p].left; x++) {
349+ ptr[y * linesize + x] = ptr[y * linesize + s->planewidth[p] - s->borders[p].right - s->borders[p].left + x];
350+ }
351+
352+ for (x = 0; x < s->borders[p].right; x++) {
353+ ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
354+ ptr[y * linesize + s->borders[p].left + x];
355+ }
356+ }
357+
358+ for (y = 0; y < s->borders[p].top; y++) {
359+ memcpy(ptr + y * linesize,
360+ ptr + (s->planeheight[p] - s->borders[p].bottom - s->borders[p].top + y) * linesize,
361+ s->planewidth[p]);
362+ }
363+
364+ for (y = 0; y < s->borders[p].bottom; y++) {
365+ memcpy(ptr + (s->planeheight[p] - s->borders[p].bottom + y) * linesize,
366+ ptr + (s->borders[p].top + y) * linesize,
367+ s->planewidth[p]);
368+ }
369+ }
370+}
371+
372+static void wrap_borders16(FillBordersContext *s, AVFrame *frame)
373+{
374+ int p, y, x;
375+
376+ for (p = 0; p < s->nb_planes; p++) {
377+ uint16_t *ptr = (uint16_t *)frame->data[p];
378+ int linesize = frame->linesize[p] / 2;
379+
380+ for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
381+ for (x = 0; x < s->borders[p].left; x++) {
382+ ptr[y * linesize + x] = ptr[y * linesize + s->planewidth[p] - s->borders[p].right - s->borders[p].left + x];
383+ }
384+
385+ for (x = 0; x < s->borders[p].right; x++) {
386+ ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
387+ ptr[y * linesize + s->borders[p].left + x];
388+ }
389+ }
390+
391+ for (y = 0; y < s->borders[p].top; y++) {
392+ memcpy(ptr + y * linesize,
393+ ptr + (s->planeheight[p] - s->borders[p].bottom - s->borders[p].top + y) * linesize,
394+ s->planewidth[p] * 2);
395+ }
396+
397+ for (y = 0; y < s->borders[p].bottom; y++) {
398+ memcpy(ptr + (s->planeheight[p] - s->borders[p].bottom + y) * linesize,
399+ ptr + (s->borders[p].top + y) * linesize,
400+ s->planewidth[p] * 2);
401+ }
402+ }
403+}
404+
272405 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
273406 {
274407 FillBordersContext *s = inlink->dst->priv;
@@ -325,6 +458,9 @@ static int config_input(AVFilterLink *inlink) · 50 unmodified lines
325458 case FM_SMEAR: s->fillborders = s->depth <= 8 ? smear_borders8 : smear_borders16; break;
326459 case FM_MIRROR: s->fillborders = s->depth <= 8 ? mirror_borders8 : mirror_borders16; break;
327460 case FM_FIXED: s->fillborders = s->depth <= 8 ? fixed_borders8 : fixed_borders16; break;
461+ case FM_REFLECT:s->fillborders = s->depth <= 8 ? reflect_borders8: reflect_borders16;break;
462+ case FM_WRAP: s->fillborders = s->depth <= 8 ? wrap_borders8 : wrap_borders16; break;
463+ default: av_assert0(0);
328464 }
329465
330466 s->yuv_color[Y] = RGB_TO_Y_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B]);
@@ -370,6 +506,8 @@ static const AVOption fillborders_options[] = { · 39 unmodified lines
370506 { "smear", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_SMEAR}, 0, 0, FLAGS, "mode" },
371507 { "mirror", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_MIRROR}, 0, 0, FLAGS, "mode" },
372508 { "fixed", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_FIXED}, 0, 0, FLAGS, "mode" },
509+ { "reflect",NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_REFLECT},0, 0, FLAGS, "mode" },
510+ { "wrap", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_WRAP}, 0, 0, FLAGS, "mode" },
373511 { "color", "set the color for the fixed mode", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS },
374512 { NULL }
375513 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t