History

avfilter/vf_xfade: add circleopen & circleclose transition

Paul B Mahol committed 6 years ago

Commit efee86f1 parent fb385532 files · +66 −0Browse files

Unified · Split

2 files
  1. doc/filters.texi +2 −0
  2. libavfilter/vf_xfade.c +64 −0
doc/filters.texi+2−0
@@ -19929,6 +19929,8 @@ Set one of available transition effects: · 19928 unmodified lines
1992919929 @item smoothright
1993019930 @item smoothup
1993119931 @item smoothdown
19932+@item circleopen
19933+@item circleclose
1993219934 @end table
1993319935 Default transition effect is fade.
1993419936
libavfilter/vf_xfade.c+64−0
@@ -49,6 +49,8 @@ enum XFadeTransitions { · 48 unmodified lines
4949 SMOOTHRIGHT,
5050 SMOOTHUP,
5151 SMOOTHDOWN,
52+ CIRCLEOPEN,
53+ CIRCLECLOSE,
5254 NB_TRANSITIONS,
5355 };
5456
@@ -150,6 +152,8 @@ static const AVOption xfade_options[] = { · 95 unmodified lines
150152 { "smoothright","smoothright transition", 0, AV_OPT_TYPE_CONST, {.i64=SMOOTHRIGHT},0, 0, FLAGS, "transition" },
151153 { "smoothup", "smoothup transition", 0, AV_OPT_TYPE_CONST, {.i64=SMOOTHUP}, 0, 0, FLAGS, "transition" },
152154 { "smoothdown", "smoothdown transition", 0, AV_OPT_TYPE_CONST, {.i64=SMOOTHDOWN}, 0, 0, FLAGS, "transition" },
155+ { "circleopen", "circleopen transition", 0, AV_OPT_TYPE_CONST, {.i64=CIRCLEOPEN}, 0, 0, FLAGS, "transition" },
156+ { "circleclose","circleclose transition", 0, AV_OPT_TYPE_CONST, {.i64=CIRCLECLOSE},0, 0, FLAGS, "transition" },
153157 { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=1000000}, 0, 60000000, FLAGS },
154158 { "offset", "set cross fade start relative to first input stream", OFFSET(offset), AV_OPT_TYPE_DURATION, {.i64=0}, INT64_MIN, INT64_MAX, FLAGS },
155159 { "expr", "set expression for custom transition", OFFSET(custom_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
@@ -796,6 +800,64 @@ static void smoothdown##name##_transition(AVFilterContext *ctx, · 640 unmodified lines
796800 SMOOTHDOWN_TRANSITION(8, uint8_t, 1)
797801 SMOOTHDOWN_TRANSITION(16, uint16_t, 2)
798802
803+#define CIRCLEOPEN_TRANSITION(name, type, div) \
804+static void circleopen##name##_transition(AVFilterContext *ctx, \
805+ const AVFrame *a, const AVFrame *b, AVFrame *out, \
806+ float progress, \
807+ int slice_start, int slice_end, int jobnr) \
808+{ \
809+ XFadeContext *s = ctx->priv; \
810+ const int width = out->width; \
811+ const int height = out->height; \
812+ const float z = hypotf(width / 2, height / 2); \
813+ const float p = (progress - 0.5f) * 3.f; \
814+ \
815+ for (int y = slice_start; y < slice_end; y++) { \
816+ for (int x = 0; x < width; x++) { \
817+ const float smooth = hypotf(x - width / 2, y - height / 2) / z + p; \
818+ for (int p = 0; p < s->nb_planes; p++) { \
819+ const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
820+ const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
821+ type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
822+ \
823+ dst[x] = mix(xf0[x], xf1[x], smoothstep(0.f, 1.f, smooth)); \
824+ } \
825+ } \
826+ } \
827+}
828+
829+CIRCLEOPEN_TRANSITION(8, uint8_t, 1)
830+CIRCLEOPEN_TRANSITION(16, uint16_t, 2)
831+
832+#define CIRCLECLOSE_TRANSITION(name, type, div) \
833+static void circleclose##name##_transition(AVFilterContext *ctx, \
834+ const AVFrame *a, const AVFrame *b, AVFrame *out, \
835+ float progress, \
836+ int slice_start, int slice_end, int jobnr) \
837+{ \
838+ XFadeContext *s = ctx->priv; \
839+ const int width = out->width; \
840+ const int height = out->height; \
841+ const float z = hypotf(width / 2, height / 2); \
842+ const float p = (1.f - progress - 0.5f) * 3.f; \
843+ \
844+ for (int y = slice_start; y < slice_end; y++) { \
845+ for (int x = 0; x < width; x++) { \
846+ const float smooth = hypotf(x - width / 2, y - height / 2) / z + p; \
847+ for (int p = 0; p < s->nb_planes; p++) { \
848+ const type *xf0 = (const type *)(a->data[p] + y * a->linesize[p]); \
849+ const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
850+ type *dst = (type *)(out->data[p] + y * out->linesize[p]); \
851+ \
852+ dst[x] = mix(xf1[x], xf0[x], smoothstep(0.f, 1.f, smooth)); \
853+ } \
854+ } \
855+ } \
856+}
857+
858+CIRCLECLOSE_TRANSITION(8, uint8_t, 1)
859+CIRCLECLOSE_TRANSITION(16, uint16_t, 2)
860+
799861 static inline double getpix(void *priv, double x, double y, int plane, int nb)
800862 {
801863 XFadeContext *s = priv;
@@ -906,6 +968,8 @@ static int config_output(AVFilterLink *outlink) · 104 unmodified lines
906968 case SMOOTHRIGHT:s->transitionf = s->depth <= 8 ? smoothright8_transition: smoothright16_transition;break;
907969 case SMOOTHUP: s->transitionf = s->depth <= 8 ? smoothup8_transition : smoothup16_transition; break;
908970 case SMOOTHDOWN: s->transitionf = s->depth <= 8 ? smoothdown8_transition : smoothdown16_transition; break;
971+ case CIRCLEOPEN: s->transitionf = s->depth <= 8 ? circleopen8_transition : circleopen16_transition; break;
972+ case CIRCLECLOSE:s->transitionf = s->depth <= 8 ? circleclose8_transition: circleclose16_transition;break;
909973 }
910974
911975 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