History

avfilter/vf_xfade: add reveal transitions

Paul B Mahol committed 3 years ago

Commit 4583a241 parent 8fe25b12 files · +84 −0Browse files

Unified · Split

2 files
  1. doc/filters.texi +4 −0
  2. libavfilter/vf_xfade.c +80 −0
doc/filters.texi+4−0
@@ -25263,6 +25263,10 @@ Set one of available transition effects: · 25262 unmodified lines
2526325263 @item coverright
2526425264 @item coverup
2526525265 @item coverdown
25266+@item revealleft
25267+@item revealright
25268+@item revealup
25269+@item revealdown
2526625270 @end table
2526725271 Default transition effect is fade.
2526825272
libavfilter/vf_xfade.c+80−0
@@ -84,6 +84,10 @@ enum XFadeTransitions { · 83 unmodified lines
8484 COVERRIGHT,
8585 COVERUP,
8686 COVERDOWN,
87+ REVEALLEFT,
88+ REVEALRIGHT,
89+ REVEALUP,
90+ REVEALDOWN,
8791 NB_TRANSITIONS,
8892 };
8993
@@ -222,6 +226,10 @@ static const AVOption xfade_options[] = { · 132 unmodified lines
222226 { "coverright", "cover right transition", 0, AV_OPT_TYPE_CONST, {.i64=COVERRIGHT}, 0, 0, FLAGS, "transition" },
223227 { "coverup", "cover up transition", 0, AV_OPT_TYPE_CONST, {.i64=COVERUP}, 0, 0, FLAGS, "transition" },
224228 { "coverdown", "cover down transition", 0, AV_OPT_TYPE_CONST, {.i64=COVERDOWN}, 0, 0, FLAGS, "transition" },
229+ { "revealleft", "reveal left transition", 0, AV_OPT_TYPE_CONST, {.i64=REVEALLEFT}, 0, 0, FLAGS, "transition" },
230+ { "revealright","reveal right transition",0, AV_OPT_TYPE_CONST, {.i64=REVEALRIGHT},0, 0, FLAGS, "transition" },
231+ { "revealup", "reveal up transition", 0, AV_OPT_TYPE_CONST, {.i64=REVEALUP}, 0, 0, FLAGS, "transition" },
232+ { "revealdown", "reveal down transition", 0, AV_OPT_TYPE_CONST, {.i64=REVEALDOWN}, 0, 0, FLAGS, "transition" },
225233 { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=1000000}, 0, 60000000, FLAGS },
226234 { "offset", "set cross fade start relative to first input stream", OFFSET(offset), AV_OPT_TYPE_DURATION, {.i64=0}, INT64_MIN, INT64_MAX, FLAGS },
227235 { "expr", "set expression for custom transition", OFFSET(custom_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
@@ -1927,6 +1935,74 @@ COVERV_TRANSITION(up, 16, uint16_t, 2, -) · 1699 unmodified lines
19271935 COVERV_TRANSITION(down, 8, uint8_t, 1, )
19281936 COVERV_TRANSITION(down, 16, uint16_t, 2, )
19291937
1938+#define REVEALH_TRANSITION(dir, name, type, div, expr) \
1939+static void reveal##dir##name##_transition(AVFilterContext *ctx, \
1940+ const AVFrame *a, const AVFrame *b, AVFrame *out, \
1941+ float progress, \
1942+ int slice_start, int slice_end, int jobnr) \
1943+{ \
1944+ XFadeContext *s = ctx->priv; \
1945+ const int height = slice_end - slice_start; \
1946+ const int width = out->width; \
1947+ const int z = (expr progress) * width; \
1948+ \
1949+ for (int p = 0; p < s->nb_planes; p++) { \
1950+ const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
1951+ const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
1952+ type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
1953+ \
1954+ for (int y = 0; y < height; y++) { \
1955+ for (int x = 0; x < width; x++) { \
1956+ const int zx = z + x; \
1957+ const int zz = zx % width + width * (zx < 0); \
1958+ dst[x] = (zx >= 0) && (zx < width) ? xf1[x] : xf0[zz]; \
1959+ } \
1960+ \
1961+ dst += out->linesize[p] / div; \
1962+ xf0 += a->linesize[p] / div; \
1963+ xf1 += b->linesize[p] / div; \
1964+ } \
1965+ } \
1966+}
1967+
1968+REVEALH_TRANSITION(left, 8, uint8_t, 1, -)
1969+REVEALH_TRANSITION(left, 16, uint16_t, 2, -)
1970+REVEALH_TRANSITION(right, 8, uint8_t, 1, )
1971+REVEALH_TRANSITION(right, 16, uint16_t, 2, )
1972+
1973+#define REVEALV_TRANSITION(dir, name, type, div, expr) \
1974+static void reveal##dir##name##_transition(AVFilterContext *ctx, \
1975+ const AVFrame *a, const AVFrame *b, AVFrame *out, \
1976+ float progress, \
1977+ int slice_start, int slice_end, int jobnr) \
1978+{ \
1979+ XFadeContext *s = ctx->priv; \
1980+ const int height = out->height; \
1981+ const int width = out->width; \
1982+ const int z = (expr progress) * height; \
1983+ \
1984+ for (int p = 0; p < s->nb_planes; p++) { \
1985+ type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]); \
1986+ \
1987+ for (int y = slice_start; y < slice_end; y++) { \
1988+ const int zy = z + y; \
1989+ const int zz = zy % height + height * (zy < 0); \
1990+ const type *xf0 = (const type *)(a->data[p] + zz * a->linesize[p]); \
1991+ const type *xf1 = (const type *)(b->data[p] + y * b->linesize[p]); \
1992+ \
1993+ for (int x = 0; x < width; x++) \
1994+ dst[x] = (zy >= 0) && (zy < height) ? xf1[x] : xf0[x]; \
1995+ \
1996+ dst += out->linesize[p] / div; \
1997+ } \
1998+ } \
1999+}
2000+
2001+REVEALV_TRANSITION(up, 8, uint8_t, 1, -)
2002+REVEALV_TRANSITION(up, 16, uint16_t, 2, -)
2003+REVEALV_TRANSITION(down, 8, uint8_t, 1, )
2004+REVEALV_TRANSITION(down, 16, uint16_t, 2, )
2005+
19302006 static inline double getpix(void *priv, double x, double y, int plane, int nb)
19312007 {
19322008 XFadeContext *s = priv;
@@ -2081,6 +2157,10 @@ static int config_output(AVFilterLink *outlink) · 148 unmodified lines
20812157 case COVERRIGHT: s->transitionf = s->depth <= 8 ? coverright8_transition : coverright16_transition; break;
20822158 case COVERUP: s->transitionf = s->depth <= 8 ? coverup8_transition : coverup16_transition; break;
20832159 case COVERDOWN: s->transitionf = s->depth <= 8 ? coverdown8_transition : coverdown16_transition; break;
2160+ case REVEALLEFT: s->transitionf = s->depth <= 8 ? revealleft8_transition : revealleft16_transition; break;
2161+ case REVEALRIGHT:s->transitionf = s->depth <= 8 ? revealright8_transition: revealright16_transition;break;
2162+ case REVEALUP: s->transitionf = s->depth <= 8 ? revealup8_transition : revealup16_transition; break;
2163+ case REVEALDOWN: s->transitionf = s->depth <= 8 ? revealdown8_transition : revealdown16_transition; break;
20842164 default: return AVERROR_BUG;
20852165 }
20862166

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