diff options
author | Clément Bœsch <u@pkh.me> | 2013-11-08 23:59:40 +0100 |
---|---|---|
committer | Clément Bœsch <u@pkh.me> | 2013-11-10 19:05:08 +0100 |
commit | 3e1097b909e5d8b2bcbcbe0a761fc8ae1556c324 (patch) | |
tree | 33735cb3636af40c9d91d10cfef79b4a5684e9a4 /libavfilter | |
parent | 78e150c5e9bb5a628d00562ade1fd4bf3635fc4d (diff) | |
download | ffmpeg-3e1097b909e5d8b2bcbcbe0a761fc8ae1556c324.tar.gz |
avfilter/fade: add color option.
Fixes Ticket #1822.
Diffstat (limited to 'libavfilter')
-rw-r--r-- | libavfilter/vf_fade.c | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/libavfilter/vf_fade.c b/libavfilter/vf_fade.c index 088bd656b0..242ebb0cb8 100644 --- a/libavfilter/vf_fade.c +++ b/libavfilter/vf_fade.c @@ -25,6 +25,7 @@ * based heavily on vf_negate.c by Bobby Bingham */ +#include "libavutil/avassert.h" #include "libavutil/avstring.h" #include "libavutil/common.h" #include "libavutil/eval.h" @@ -61,6 +62,8 @@ typedef struct { int alpha; uint64_t start_time, duration; enum {VF_FADE_WAITING=0, VF_FADE_FADING, VF_FADE_DONE} fade_state; + uint8_t color_rgba[4]; ///< fade color + int black_fade; ///< if color_rgba is black } FadeContext; static av_cold int init(AVFilterContext *ctx) @@ -89,11 +92,13 @@ static av_cold int init(AVFilterContext *ctx) (s->duration / (double)AV_TIME_BASE),s->alpha); } + s->black_fade = !memcmp(s->color_rgba, "\x00\x00\x00\xff", 4); return 0; } static int query_formats(AVFilterContext *ctx) { + const FadeContext *s = ctx->priv; static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, @@ -105,8 +110,17 @@ static int query_formats(AVFilterContext *ctx) AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA, AV_PIX_FMT_NONE }; + static const enum AVPixelFormat pix_fmts_rgb[] = { + AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24, + AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR, + AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA, + AV_PIX_FMT_NONE + }; - ff_set_common_formats(ctx, ff_make_format_list(pix_fmts)); + if (s->black_fade) + ff_set_common_formats(ctx, ff_make_format_list(pix_fmts)); + else + ff_set_common_formats(ctx, ff_make_format_list(pix_fmts_rgb)); return 0; } @@ -138,6 +152,47 @@ static int config_props(AVFilterLink *inlink) return 0; } +static av_always_inline void filter_rgb(FadeContext *s, const AVFrame *frame, + int slice_start, int slice_end, + int do_alpha, int step) +{ + int i, j; + const uint8_t r_idx = s->rgba_map[R]; + const uint8_t g_idx = s->rgba_map[G]; + const uint8_t b_idx = s->rgba_map[B]; + const uint8_t a_idx = s->rgba_map[A]; + const uint8_t *c = s->color_rgba; + + for (i = slice_start; i < slice_end; i++) { + uint8_t *p = frame->data[0] + i * frame->linesize[0]; + for (j = 0; j < frame->width; j++) { +#define INTERP(c_name, c_idx) av_clip_uint8(((c[c_idx]<<16) + ((int)p[c_name] - (int)c[c_idx]) * s->factor + (1<<15)) >> 16) + p[r_idx] = INTERP(r_idx, 0); + p[g_idx] = INTERP(g_idx, 1); + p[b_idx] = INTERP(b_idx, 2); + if (do_alpha) + p[a_idx] = INTERP(a_idx, 3); + p += step; + } + } +} + +static int filter_slice_rgb(AVFilterContext *ctx, void *arg, int jobnr, + int nb_jobs) +{ + FadeContext *s = ctx->priv; + AVFrame *frame = arg; + int slice_start = (frame->height * jobnr ) / nb_jobs; + int slice_end = (frame->height * (jobnr+1)) / nb_jobs; + + if (s->alpha) filter_rgb(s, frame, slice_start, slice_end, 1, 4); + else if (s->bpp == 3) filter_rgb(s, frame, slice_start, slice_end, 0, 3); + else if (s->bpp == 4) filter_rgb(s, frame, slice_start, slice_end, 0, 4); + else av_assert0(0); + + return 0; +} + static int filter_slice_luma(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) { @@ -271,8 +326,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) if (s->alpha) { ctx->internal->execute(ctx, filter_slice_alpha, frame, NULL, FFMIN(frame->height, ctx->graph->nb_threads)); + } else if (s->is_packed_rgb && !s->black_fade) { + ctx->internal->execute(ctx, filter_slice_rgb, frame, NULL, + FFMIN(frame->height, ctx->graph->nb_threads)); } else { - /* luma or rgb plane */ + /* luma, or rgb plane in case of black */ ctx->internal->execute(ctx, filter_slice_luma, frame, NULL, FFMIN(frame->height, ctx->graph->nb_threads)); @@ -315,6 +373,8 @@ static const AVOption fade_options[] = { OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT32_MAX, FLAGS }, { "d", "Duration of the effect in seconds.", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT32_MAX, FLAGS }, + { "color", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, CHAR_MIN, CHAR_MAX, FLAGS }, + { "c", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, CHAR_MIN, CHAR_MAX, FLAGS }, { NULL } }; |