| Original vf_xfade.c |
Amended vf_xfade.c |
|
126: void (*transitionf)(AVFilterContext *ctx, const AVFrame *a, const AVFrame *b, AVFrame *out, float progress, |
126: void (*transitionf)(AVFilterContext *ctx, const AVFrame *a, const AVFrame *b, AVFrame *out, float progress, |
|
127: int slice_start, int slice_end, int jobnr); |
127: int slice_start, int slice_end, int jobnr); |
| 128: |
128: |
| |
129: char *easing_str; // easing name with optional args |
| |
130: char *transition_str; // transition name with optional args |
| |
131: int reverse; // reverse option bit flags (enum ReverseFlags) |
| |
132: struct XFadeEasingContext *k; // xfade-easing data |
| |
133: |
| 129: AVExpr *e; |
134: AVExpr *e; |
| 130: } XFadeContext; |
135: } XFadeContext; |
| 131: |
136: |
| 157: AV_PIX_FMT_NONE |
162: AV_PIX_FMT_NONE |
| 158: }; |
163: }; |
| 159: |
164: |
| |
165: static void xe_data_free(struct XFadeEasingContext *k); |
| 160: static av_cold void uninit(AVFilterContext *ctx) |
166: static av_cold void uninit(AVFilterContext *ctx) |
| 161: { |
167: { |
| 162: XFadeContext *s = ctx->priv; |
168: XFadeContext *s = ctx->priv; |
| 163: |
169: |
| 164: av_expr_free(s->e); |
170: av_expr_free(s->e); |
| |
171: xe_data_free(s->k); |
| 165: } |
172: } |
| 166: |
173: |
| 167: #define OFFSET(x) offsetof(XFadeContext, x) |
174: #define OFFSET(x) offsetof(XFadeContext, x) |
|
168: #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM) |
175: #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM) |
| 169: |
176: |
| 170: static const AVOption xfade_options[] = { |
177: static const AVOption xfade_options[] = { |
|
171: { "transition", "set cross fade transition", OFFSET(transition), AV_OPT_TYPE_INT, {.i64=FADE}, -1, NB_TRANSITIONS-1, FLAGS, .unit = "transition" }, |
178: { "easing", "set cross fade easing", OFFSET(easing_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, |
| |
179: { "reverse", "reverse easing/transition", OFFSET(reverse), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 3, FLAGS }, |
| |
180: { "transition", "set cross fade transition", OFFSET(transition_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS, .unit = "transition" }, |
|
172: { "custom", "custom transition", 0, AV_OPT_TYPE_CONST, {.i64=CUSTOM}, 0, 0, FLAGS, .unit = "transition" }, |
181: { "custom", "custom transition", 0, AV_OPT_TYPE_CONST, {.i64=CUSTOM}, 0, 0, FLAGS, .unit = "transition" }, |
|
173: { "fade", "fade transition", 0, AV_OPT_TYPE_CONST, {.i64=FADE}, 0, 0, FLAGS, .unit = "transition" }, |
182: { "fade", "fade transition", 0, AV_OPT_TYPE_CONST, {.i64=FADE}, 0, 0, FLAGS, .unit = "transition" }, |
|
174: { "wipeleft", "wipe left transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPELEFT}, 0, 0, FLAGS, .unit = "transition" }, |
183: { "wipeleft", "wipe left transition", 0, AV_OPT_TYPE_CONST, {.i64=WIPELEFT}, 0, 0, FLAGS, .unit = "transition" }, |
|
2007: REVEALV_TRANSITION(up, 16, uint16_t, 2, -) |
2016: REVEALV_TRANSITION(up, 16, uint16_t, 2, -) |
| 2008: REVEALV_TRANSITION(down, 8, uint8_t, 1, ) |
2017: REVEALV_TRANSITION(down, 8, uint8_t, 1, ) |
| 2009: REVEALV_TRANSITION(down, 16, uint16_t, 2, ) |
2018: REVEALV_TRANSITION(down, 16, uint16_t, 2, ) |
| |
2019: |
| |
2020: #include "xfade-easing.h" // easing & extended transitions |
| 2010: |
2021: |
|
2011: static inline double getpix(void *priv, double x, double y, int plane, int nb) |
2022: static inline double getpix(void *priv, double x, double y, int plane, int nb) |
| 2012: { |
2023: { |
| 2110: if (!s->duration_pts) |
2121: if (!s->duration_pts) |
|
2111: s->duration_pts = 1; |
2122: s->duration_pts = 1; |
| 2112: |
2123: |
| |
2124: int ret = config_xfade_easing(ctx); |
| |
2125: if (ret <= 0) return ret; // error or extended transition |
| |
2126: |
| 2113: switch (s->transition) { |
2127: switch (s->transition) { |
|
2114: case CUSTOM: s->transitionf = s->depth <= 8 ? custom8_transition : custom16_transition; break; |
2128: case CUSTOM: s->transitionf = s->depth <= 8 ? custom8_transition : custom16_transition; break; |
|
2115: case FADE: s->transitionf = s->depth <= 8 ? fade8_transition : fade16_transition; break; |
2129: case FADE: s->transitionf = s->depth <= 8 ? fade8_transition : fade16_transition; break; |
|
2222: return AVERROR(ENOMEM); |
2236: return AVERROR(ENOMEM); |
| 2223: av_frame_copy_props(out, a); |
2237: av_frame_copy_props(out, a); |
| 2224: |
2238: |
|
2225: td.xf[0] = a, td.xf[1] = b, td.out = out, td.progress = progress; |
2239: progress = (s->reverse & REVERSE_EASING) ? 1 - ease(s, 1 - progress) : ease(s, progress); // eased progress |
| |
2240: int i = s->reverse & REVERSE_TRANSITION; |
| |
2241: if (i) progress = 1 - progress; |
| |
2242: if (s->reverse & REVERSE_OVERSHOOT) { // internal flag |
| |
2243: if (progress < 0) progress += 1, i ^= 1; // undershoot |
| |
2244: else if (progress > 1) progress -= 1, i ^= 1; // overshoot |
| |
2245: } |
| |
2246: td.xf[i] = a, td.xf[i ^ 1] = b, td.out = out, td.progress = av_clipf(progress, 0, 1); |
|
2226: ff_filter_execute(ctx, xfade_slice, &td, NULL, |
2247: ff_filter_execute(ctx, xfade_slice, &td, NULL, |
|
2227: FFMIN(outlink->h, ff_filter_get_nb_threads(ctx))); |
2248: FFMIN(outlink->h, ff_filter_get_nb_threads(ctx))); |
| 2228: |
2249: |