History

avfilter/vf_fillborders: add another mode

Paul B Mahol committed 5 years ago

Commit d5c76451 parent 94c90b32 files · +99 −1Browse files

Unified · Split

2 files
  1. doc/filters.texi +3 −0
  2. libavfilter/vf_fillborders.c +96 −1
doc/filters.texi+3−0
@@ -12280,6 +12280,9 @@ fill pixels using wrapping · 12279 unmodified lines
12280 12280
12281@item fade12281@item fade
12282fade pixels to constant value12282fade pixels to constant value
12283
12284@item margins
12285fill pixels at top and bottom with weighted averages pixels near borders
12283@end table12286@end table
12284 12287
12285Default is @var{smear}.12288Default is @var{smear}.
libavfilter/vf_fillborders.c+96−1
@@ -32,7 +32,7 @@ · 31 unmodified lines
32enum { Y, U, V, A };32enum { Y, U, V, A };
33enum { R, G, B };33enum { R, G, B };
34 34
35enum FillMode { FM_SMEAR, FM_MIRROR, FM_FIXED, FM_REFLECT, FM_WRAP, FM_FADE, FM_NB_MODES };35enum FillMode { FM_SMEAR, FM_MIRROR, FM_FIXED, FM_REFLECT, FM_WRAP, FM_FADE, FM_MARGINS, FM_NB_MODES };
36 36
37typedef struct Borders {37typedef struct Borders {
38 int left, right, top, bottom;38 int left, right, top, bottom;
@@ -495,6 +495,99 @@ static void fade_borders16(FillBordersContext *s, AVFrame *frame) · 456 unmodified lines
495 }495 }
496}496}
497 497
498static void margins_borders8(FillBordersContext *s, AVFrame *frame)
499{
500 for (int p = 0; p < s->nb_planes; p++) {
501 uint8_t *ptr = (uint8_t *)frame->data[p];
502 const int linesize = frame->linesize[p];
503 const int left = s->borders[p].left;
504 const int right = s->borders[p].right;
505 const int top = s->borders[p].top;
506 const int bottom = s->borders[p].bottom;
507 const int width = s->planewidth[p];
508 const int height = s->planeheight[p];
509
510 for (int y = top; y < height - bottom; y++) {
511 memset(ptr + linesize * y, ptr[linesize * y + left], left);
512 memset(ptr + linesize * y + width - right, (ptr + linesize * y + width - right)[-1], right);
513 }
514
515 for (int y = top - 1; y >= 0; y--) {
516 ptr[linesize * y] = ptr[linesize * (y + 1)];
517 memcpy(ptr + linesize * y + width - 8, ptr + linesize * (y + 1) + width - 8, 8);
518
519 for (int x = 1; x < width - 8; x++) {
520 int prev = ptr[linesize * (y + 1) + x - 1];
521 int cur = ptr[linesize * (y + 1) + x];
522 int next = ptr[linesize * (y + 1) + x + 1];
523
524 ptr[linesize * y + x] = (3 * prev + 2 * cur + 3 * next + 4) >> 3;
525 }
526 }
527
528 for (int y = height - bottom; y < height; y++) {
529 ptr[linesize * y] = ptr[linesize * (y - 1)];
530 memcpy(ptr + linesize * y + width - 8, ptr + linesize * (y - 1) + width - 8, 8);
531
532 for (int x = 1; x < width - 8; x++) {
533 int prev = ptr[linesize * (y - 1) + x - 1];
534 int cur = ptr[linesize * (y - 1) + x];
535 int next = ptr[linesize * (y - 1) + x + 1];
536
537 ptr[linesize * y + x] = (3 * prev + 2 * cur + 3 * next + 4) >> 3;
538 }
539 }
540 }
541}
542
543static void margins_borders16(FillBordersContext *s, AVFrame *frame)
544{
545 for (int p = 0; p < s->nb_planes; p++) {
546 uint16_t *ptr = (uint16_t *)frame->data[p];
547 const int linesize = frame->linesize[p] / 2;
548 const int left = s->borders[p].left;
549 const int right = s->borders[p].right;
550 const int top = s->borders[p].top;
551 const int bottom = s->borders[p].bottom;
552 const int width = s->planewidth[p];
553 const int height = s->planeheight[p];
554
555 for (int y = top; y < height - bottom; y++) {
556 for (int x = 0; x < left; x++)
557 ptr[linesize * y + x] = ptr[linesize * y + left];
558
559 for (int x = 0; x < right; x++)
560 ptr[linesize * y + width - right + x] = ptr[linesize * y + width - right - 1];
561 }
562
563 for (int y = top - 1; y >= 0; y--) {
564 ptr[linesize * y] = ptr[linesize * (y + 1)];
565 memcpy(ptr + linesize * y + width - 8, ptr + linesize * (y + 1) + width - 8, 16);
566
567 for (int x = 1; x < width - 8; x++) {
568 int prev = ptr[linesize * (y + 1) + x - 1];
569 int cur = ptr[linesize * (y + 1) + x];
570 int next = ptr[linesize * (y + 1) + x + 1];
571
572 ptr[linesize * y + x] = (3 * prev + 2 * cur + 3 * next + 4) >> 3;
573 }
574 }
575
576 for (int y = height - bottom; y < height; y++) {
577 ptr[linesize * y] = ptr[linesize * (y - 1)];
578 memcpy(ptr + linesize * y + width - 8, ptr + linesize * (y - 1) + width - 8, 16);
579
580 for (int x = 1; x < width - 8; x++) {
581 int prev = ptr[linesize * (y - 1) + x - 1];
582 int cur = ptr[linesize * (y - 1) + x];
583 int next = ptr[linesize * (y - 1) + x + 1];
584
585 ptr[linesize * y + x] = (3 * prev + 2 * cur + 3 * next + 4) >> 3;
586 }
587 }
588 }
589}
590
498static int filter_frame(AVFilterLink *inlink, AVFrame *frame)591static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
499{592{
500 FillBordersContext *s = inlink->dst->priv;593 FillBordersContext *s = inlink->dst->priv;
@@ -554,6 +647,7 @@ static int config_input(AVFilterLink *inlink) · 53 unmodified lines
554 case FM_REFLECT:s->fillborders = s->depth <= 8 ? reflect_borders8: reflect_borders16;break;647 case FM_REFLECT:s->fillborders = s->depth <= 8 ? reflect_borders8: reflect_borders16;break;
555 case FM_WRAP: s->fillborders = s->depth <= 8 ? wrap_borders8 : wrap_borders16; break;648 case FM_WRAP: s->fillborders = s->depth <= 8 ? wrap_borders8 : wrap_borders16; break;
556 case FM_FADE: s->fillborders = s->depth <= 8 ? fade_borders8 : fade_borders16; break;649 case FM_FADE: s->fillborders = s->depth <= 8 ? fade_borders8 : fade_borders16; break;
650 case FM_MARGINS:s->fillborders = s->depth <= 8 ? margins_borders8: margins_borders16;break;
557 default: av_assert0(0);651 default: av_assert0(0);
558 }652 }
559 653
@@ -603,6 +697,7 @@ static const AVOption fillborders_options[] = { · 43 unmodified lines
603 { "reflect",NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_REFLECT},0, 0, FLAGS, "mode" },697 { "reflect",NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_REFLECT},0, 0, FLAGS, "mode" },
604 { "wrap", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_WRAP}, 0, 0, FLAGS, "mode" },698 { "wrap", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_WRAP}, 0, 0, FLAGS, "mode" },
605 { "fade", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_FADE}, 0, 0, FLAGS, "mode" },699 { "fade", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_FADE}, 0, 0, FLAGS, "mode" },
700 { "margins",NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_MARGINS},0, 0, FLAGS, "mode" },
606 { "color", "set the color for the fixed/fade mode", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS },701 { "color", "set the color for the fixed/fade mode", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS },
607 { NULL }702 { NULL }
608};703};

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