diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-05-24 20:02:34 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-05-24 20:21:40 +0200 |
commit | 0cbfbdef4a0701c162569808b8a50ff462e788d8 (patch) | |
tree | bbf2f2787dbfdaeb45d594ab03bfad1b28d5b84b | |
parent | a3d62f3377b2ead0c6f9a00f720b2c3a5395e71c (diff) | |
download | ffmpeg-0cbfbdef4a0701c162569808b8a50ff462e788d8.tar.gz |
vf_fade: Support slice threaded alpha
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavfilter/vf_fade.c | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/libavfilter/vf_fade.c b/libavfilter/vf_fade.c index 44170fd026..b899dc1db9 100644 --- a/libavfilter/vf_fade.c +++ b/libavfilter/vf_fade.c @@ -208,6 +208,31 @@ static int filter_slice_chroma(AVFilterContext *ctx, void *arg, int jobnr, return 0; } +static int filter_slice_alpha(AVFilterContext *ctx, void *arg, int jobnr, + int nb_jobs) +{ + FadeContext *s = ctx->priv; + AVFrame *frame = arg; + int plane = s->is_packed_rgb ? 0 : A; + int slice_start = (frame->height * jobnr ) / nb_jobs; + int slice_end = (frame->height * (jobnr+1)) / nb_jobs; + int i, j; + + for (i = slice_start; i < slice_end; i++) { + uint8_t *p = frame->data[plane] + i * frame->linesize[plane] + s->is_packed_rgb*s->rgba_map[A]; + int step = s->is_packed_rgb ? 4 : 1; + for (j = 0; j < frame->width; j++) { + /* s->factor is using 16 lower-order bits for decimal + * places. 32768 = 1 << 15, it is an integer representation + * of 0.5 and is for rounding. */ + *p = ((*p - s->black_level) * s->factor + s->black_level_scaled) >> 16; + p += step; + } + } + + return 0; +} + static int filter_frame(AVFilterLink *inlink, AVFrame *frame) { AVFilterContext *ctx = inlink->dst; @@ -264,14 +289,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) if (s->factor < UINT16_MAX) { if (s->alpha) { - // alpha only - int plane = s->is_packed_rgb ? 0 : A; // alpha is on plane 0 for packed formats - // or plane 3 for planar formats - fade_plane(0, frame->height, inlink->w, - s->factor, s->black_level, s->black_level_scaled, - s->is_packed_rgb ? s->rgba_map[A] : 0, // alpha offset for packed formats - s->is_packed_rgb ? 4 : 1, // pixstep for 8 bit packed formats - 1, frame->data[plane], frame->linesize[plane]); + ctx->internal->execute(ctx, filter_slice_alpha, frame, NULL, + FFMIN(frame->height, ctx->graph->nb_threads)); } else { /* luma or rgb plane */ ctx->internal->execute(ctx, filter_slice_luma, frame, NULL, |