History

avfilter/vf_xfade: add radial transition

Paul B Mahol committed 6 years ago

Commit 0a275fe1 parent b99ed6e2 files · +32 −0Browse files

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

Unified · Split

libavfilter/vf_xfade.c+31−0
@@ -45,6 +45,7 @@ enum XFadeTransitions { · 44 unmodified lines
4545 DISTANCE,
4646 FADEBLACK,
4747 FADEWHITE,
48+ RADIAL,
4849 NB_TRANSITIONS,
4950 };
5051
@@ -141,6 +142,7 @@ static const AVOption xfade_options[] = { · 90 unmodified lines
141142 { "distance", "distance transition", 0, AV_OPT_TYPE_CONST, {.i64=DISTANCE}, 0, 0, FLAGS, "transition" },
142143 { "fadeblack", "fadeblack transition", 0, AV_OPT_TYPE_CONST, {.i64=FADEBLACK}, 0, 0, FLAGS, "transition" },
143144 { "fadewhite", "fadewhite transition", 0, AV_OPT_TYPE_CONST, {.i64=FADEWHITE}, 0, 0, FLAGS, "transition" },
145+ { "radial", "radial transition", 0, AV_OPT_TYPE_CONST, {.i64=RADIAL}, 0, 0, FLAGS, "transition" },
144146 { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=1000000}, 0, 60000000, FLAGS },
145147 { "offset", "set cross fade start relative to first input stream", OFFSET(offset), AV_OPT_TYPE_DURATION, {.i64=0}, INT64_MIN, INT64_MAX, FLAGS },
146148 { "expr", "set expression for custom transition", OFFSET(custom_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
@@ -649,6 +651,34 @@ static void fadewhite##name##_transition(AVFilterContext *ctx, · 502 unmodified lines
649651 FADEWHITE_TRANSITION(8, uint8_t, 1)
650652 FADEWHITE_TRANSITION(16, uint16_t, 2)
651653
654+#define RADIAL_TRANSITION(name, type, div) \
655+static void radial##name##_transition(AVFilterContext *ctx, \
656+ const AVFrame *a, const AVFrame *b, AVFrame *out, \
657+ float progress, \
658+ int slice_start, int slice_end, int jobnr) \
659+{ \
660+ XFadeContext *s = ctx->priv; \
661+ const int width = out->width; \
662+ const int height = out->height; \
663+ \
664+ for (int y = slice_start; y < slice_end; y++) { \
665+ for (int x = 0; x < width; x++) { \
666+ const float smooth = atan2f(x - width / 2, y - height / 2) - \
667+ (progress - 0.5f) * (M_PI * 2.5f); \
668+ for (int p = 0; p < s->nb_planes; p++) { \
669+ const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
670+ const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
671+ type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
672+ \
673+ dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
674+ } \
675+ } \
676+ } \
677+}
678+
679+RADIAL_TRANSITION(8, uint8_t, 1)
680+RADIAL_TRANSITION(16, uint16_t, 2)
681+
652682 static inline double getpix(void *priv, double x, double y, int plane, int nb)
653683 {
654684 XFadeContext *s = priv;
@@ -754,6 +784,7 @@ static int config_output(AVFilterLink *outlink) · 99 unmodified lines
754784 case DISTANCE: s->transitionf = s->depth <= 8 ? distance8_transition : distance16_transition; break;
755785 case FADEBLACK: s->transitionf = s->depth <= 8 ? fadeblack8_transition : fadeblack16_transition; break;
756786 case FADEWHITE: s->transitionf = s->depth <= 8 ? fadewhite8_transition : fadewhite16_transition; break;
787+ case RADIAL: s->transitionf = s->depth <= 8 ? radial8_transition : radial16_transition; break;
757788 }
758789
759790 if (s->transition == CUSTOM) {

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