History

avfilter/vf_fillborders: add another mode

Paul B Mahol committed 5 years ago

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

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/vf_fillborders.c+96−1
@@ -32,7 +32,7 @@ · 31 unmodified lines
3232 enum { Y, U, V, A };
3333 enum { R, G, B };
3434
35−enum FillMode { FM_SMEAR, FM_MIRROR, FM_FIXED, FM_REFLECT, FM_WRAP, FM_FADE, FM_NB_MODES };
35+enum FillMode { FM_SMEAR, FM_MIRROR, FM_FIXED, FM_REFLECT, FM_WRAP, FM_FADE, FM_MARGINS, FM_NB_MODES };
3636
3737 typedef struct Borders {
3838 int left, right, top, bottom;
@@ -495,6 +495,99 @@ static void fade_borders16(FillBordersContext *s, AVFrame *frame) · 456 unmodified lines
495495 }
496496 }
497497
498+static 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+
543+static 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+
498591 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
499592 {
500593 FillBordersContext *s = inlink->dst->priv;
@@ -554,6 +647,7 @@ static int config_input(AVFilterLink *inlink) · 53 unmodified lines
554647 case FM_REFLECT:s->fillborders = s->depth <= 8 ? reflect_borders8: reflect_borders16;break;
555648 case FM_WRAP: s->fillborders = s->depth <= 8 ? wrap_borders8 : wrap_borders16; break;
556649 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;
557651 default: av_assert0(0);
558652 }
559653
@@ -603,6 +697,7 @@ static const AVOption fillborders_options[] = { · 43 unmodified lines
603697 { "reflect",NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_REFLECT},0, 0, FLAGS, "mode" },
604698 { "wrap", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_WRAP}, 0, 0, FLAGS, "mode" },
605699 { "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" },
606701 { "color", "set the color for the fixed/fade mode", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS },
607702 { NULL }
608703 };

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