X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Fvf_fade.c;h=6fa02e6bfa922f46d1389411d8d06dcff35957ab;hb=8d861cd850597c009b6d947a556209f4ac7469d9;hp=c30c41db0da4a42a05dfdd98dba332fca21a8331;hpb=64425e005edf3bdd77c34c078c3e74ab5ecef557;p=ffmpeg diff --git a/libavfilter/vf_fade.c b/libavfilter/vf_fade.c index c30c41db0da..6fa02e6bfa9 100644 --- a/libavfilter/vf_fade.c +++ b/libavfilter/vf_fade.c @@ -56,9 +56,11 @@ typedef struct FadeContext { int start_frame, nb_frames; int hsub, vsub, bpp; unsigned int black_level, black_level_scaled; + uint8_t is_rgb; uint8_t is_packed_rgb; uint8_t rgba_map[4]; int alpha; + int is_planar; 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 @@ -107,23 +109,27 @@ static int query_formats(AVFilterContext *ctx) 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_GBRP, AV_PIX_FMT_GBRAP, 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_GBRP, AV_PIX_FMT_NONE }; static const enum AVPixelFormat pix_fmts_alpha[] = { AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P, AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR, AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA, + AV_PIX_FMT_GBRAP, AV_PIX_FMT_NONE }; static const enum AVPixelFormat pix_fmts_rgba[] = { AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR, AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA, + AV_PIX_FMT_GBRAP, AV_PIX_FMT_NONE }; AVFilterFormats *fmts_list; @@ -159,11 +165,15 @@ static int config_props(AVFilterLink *inlink) s->hsub = pixdesc->log2_chroma_w; s->vsub = pixdesc->log2_chroma_h; + ff_fill_rgba_map(s->rgba_map, inlink->format); + s->bpp = pixdesc->flags & AV_PIX_FMT_FLAG_PLANAR ? 1 : av_get_bits_per_pixel(pixdesc) >> 3; s->alpha &= !!(pixdesc->flags & AV_PIX_FMT_FLAG_ALPHA); - s->is_packed_rgb = ff_fill_rgba_map(s->rgba_map, inlink->format) >= 0; + s->is_planar = pixdesc->flags & AV_PIX_FMT_FLAG_PLANAR; + s->is_rgb = pixdesc->flags & AV_PIX_FMT_FLAG_RGB; + s->is_packed_rgb = !s->is_planar && s->is_rgb; /* use CCIR601/709 black level for studio-level pixel non-alpha components */ s->black_level = @@ -199,6 +209,29 @@ static av_always_inline void filter_rgb(FadeContext *s, const AVFrame *frame, } } +static av_always_inline void filter_rgb_planar(FadeContext *s, const AVFrame *frame, + int slice_start, int slice_end, + int do_alpha) +{ + int i, j; + const uint8_t *c = s->color_rgba; + + for (i = slice_start; i < slice_end; i++) { + uint8_t *pg = frame->data[0] + i * frame->linesize[0]; + uint8_t *pb = frame->data[1] + i * frame->linesize[1]; + uint8_t *pr = frame->data[2] + i * frame->linesize[2]; + uint8_t *pa = frame->data[3] + i * frame->linesize[3]; + for (j = 0; j < frame->width; j++) { +#define INTERPP(c_name, c_idx) av_clip_uint8(((c[c_idx]<<16) + ((int)c_name - (int)c[c_idx]) * s->factor + (1<<15)) >> 16) + pr[j] = INTERPP(pr[j], 1); + pg[j] = INTERPP(pg[j], 0); + pb[j] = INTERPP(pb[j], 2); + if (do_alpha) + pa[j] = INTERPP(pa[j], 3); + } + } +} + static int filter_slice_rgb(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) { @@ -207,7 +240,11 @@ static int filter_slice_rgb(AVFilterContext *ctx, void *arg, int jobnr, 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); + if (s->is_planar && s->alpha) + filter_rgb_planar(s, frame, slice_start, slice_end, 1); + else if (s->is_planar) + filter_rgb_planar(s, frame, slice_start, slice_end, 0); + else 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); @@ -224,14 +261,16 @@ static int filter_slice_luma(AVFilterContext *ctx, void *arg, int jobnr, 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[0] + i * frame->linesize[0]; - for (j = 0; j < frame->width * s->bpp; 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++; + for (int k = 0; k < 1 + 2 * (s->is_planar && s->is_rgb); k++) { + for (i = slice_start; i < slice_end; i++) { + uint8_t *p = frame->data[k] + i * frame->linesize[k]; + for (j = 0; j < frame->width * s->bpp; 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++; + } } } @@ -348,7 +387,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) if (s->alpha) { ctx->internal->execute(ctx, filter_slice_alpha, frame, NULL, FFMIN(frame->height, ff_filter_get_nb_threads(ctx))); - } else if (s->is_packed_rgb && !s->black_fade) { + } else if (s->is_rgb && !s->black_fade) { ctx->internal->execute(ctx, filter_slice_rgb, frame, NULL, FFMIN(frame->height, ff_filter_get_nb_threads(ctx))); } else { @@ -356,7 +395,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) ctx->internal->execute(ctx, filter_slice_luma, frame, NULL, FFMIN(frame->height, ff_filter_get_nb_threads(ctx))); - if (frame->data[1] && frame->data[2]) { + if (frame->data[1] && frame->data[2] && !s->is_rgb) { /* chroma planes */ ctx->internal->execute(ctx, filter_slice_chroma, frame, NULL, FFMIN(frame->height, ff_filter_get_nb_threads(ctx))); @@ -381,18 +420,18 @@ static const AVOption fade_options[] = { { "s", "Number of the first frame to which to apply the effect.", OFFSET(start_frame), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS }, { "nb_frames", "Number of frames to which the effect should be applied.", - OFFSET(nb_frames), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, INT_MAX, FLAGS }, + OFFSET(nb_frames), AV_OPT_TYPE_INT, { .i64 = 25 }, 1, INT_MAX, FLAGS }, { "n", "Number of frames to which the effect should be applied.", - OFFSET(nb_frames), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, INT_MAX, FLAGS }, + OFFSET(nb_frames), AV_OPT_TYPE_INT, { .i64 = 25 }, 1, INT_MAX, FLAGS }, { "alpha", "fade alpha if it is available on the input", OFFSET(alpha), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FLAGS }, { "start_time", "Number of seconds of the beginning of the effect.", - OFFSET(start_time), AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT32_MAX, FLAGS }, + OFFSET(start_time), AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT64_MAX, FLAGS }, { "st", "Number of seconds of the beginning of the effect.", - OFFSET(start_time), AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT32_MAX, FLAGS }, + OFFSET(start_time), AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT64_MAX, FLAGS }, { "duration", "Duration of the effect in seconds.", - OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT32_MAX, FLAGS }, + OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT64_MAX, FLAGS }, { "d", "Duration of the effect in seconds.", - OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT32_MAX, FLAGS }, + OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT64_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 }