| 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 ReverseOpts) |
| |
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" }, |
| 2001: REVEALV_TRANSITION(down, 8, uint8_t, 1, ) |
2010: REVEALV_TRANSITION(down, 8, uint8_t, 1, ) |
| 2002: REVEALV_TRANSITION(down, 16, uint16_t, 2, ) |
2011: REVEALV_TRANSITION(down, 16, uint16_t, 2, ) |
| 2003: |
2012: |
| |
2013: #include "xfade-easing.h" // easing & extended transitions |
| |
2014: |
|
2004: static inline double getpix(void *priv, double x, double y, int plane, int nb) |
2015: static inline double getpix(void *priv, double x, double y, int plane, int nb) |
| 2005: { |
2016: { |
| 2006: XFadeContext *s = priv; |
2017: XFadeContext *s = priv; |
|
2007: AVFrame *in = s->xf[nb]; |
2018: AVFrame *in = s->xf[nb ^ (s->reverse & REVERSE_TRANSITION)]; |
|
2008: const uint8_t *src = in->data[FFMIN(plane, s->nb_planes - 1)]; |
2019: const uint8_t *src = in->data[FFMIN(plane, s->nb_planes - 1)]; |
|
2009: int linesize = in->linesize[FFMIN(plane, s->nb_planes - 1)]; |
2020: int linesize = in->linesize[FFMIN(plane, s->nb_planes - 1)]; |
| 2010: const int w = in->width; |
2021: const int w = in->width; |
| 2102: if (s->duration) |
2113: if (s->duration) |
|
2103: s->duration_pts = av_rescale_q(s->duration, AV_TIME_BASE_Q, outlink->time_base); |
2114: s->duration_pts = av_rescale_q(s->duration, AV_TIME_BASE_Q, outlink->time_base); |
| 2104: |
2115: |
| |
2116: int ret = config_xfade_easing(ctx); |
| |
2117: if (ret <= 0) return ret; // error or extended transition |
| |
2118: |
| 2105: switch (s->transition) { |
2119: switch (s->transition) { |
|
2106: case CUSTOM: s->transitionf = s->depth <= 8 ? custom8_transition : custom16_transition; break; |
2120: case CUSTOM: s->transitionf = s->depth <= 8 ? custom8_transition : custom16_transition; break; |
|
2107: case FADE: s->transitionf = s->depth <= 8 ? fade8_transition : fade16_transition; break; |
2121: case FADE: s->transitionf = s->depth <= 8 ? fade8_transition : fade16_transition; break; |
| 2195: ThreadData *td = arg; |
2209: ThreadData *td = arg; |
|
2196: int slice_start = (outlink->h * jobnr ) / nb_jobs; |
2210: int slice_start = (outlink->h * jobnr ) / nb_jobs; |
|
2197: int slice_end = (outlink->h * (jobnr+1)) / nb_jobs; |
2211: int slice_end = (outlink->h * (jobnr+1)) / nb_jobs; |
| |
2212: int i = s->reverse & REVERSE_TRANSITION; // input 0 or 1 |
| |
2213: float p = td->progress; |
| 2198: |
2214: |
|
2199: s->transitionf(ctx, td->xf[0], td->xf[1], td->out, td->progress, slice_start, slice_end, jobnr); |
2215: p = (s->reverse & REVERSE_EASING) ? 1 - ease(s, 1 - p) : ease(s, p); // eased progress |
| |
2216: if (i) p = 1 - p; |
| |
2217: s->transitionf(ctx, td->xf[i], td->xf[i ^ 1], td->out, p, slice_start, slice_end, jobnr); |
| 2200: |
2218: |
| 2201: return 0; |
2219: return 0; |
| 2202: } |
2220: } |