X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Fvf_colorchannelmixer.c;h=3bbe44d6ef7d906c8d9aceff021d0911b75860ec;hb=16766bf8a8e477da09337801b96f732740a0b279;hp=3a9cd37b78aeef29d9acfc1c4a99fae8b2d07ebc;hpb=409e684e79b6ee0c511292326f09b13fe230e58e;p=ffmpeg diff --git a/libavfilter/vf_colorchannelmixer.c b/libavfilter/vf_colorchannelmixer.c index 3a9cd37b78a..3bbe44d6ef7 100644 --- a/libavfilter/vf_colorchannelmixer.c +++ b/libavfilter/vf_colorchannelmixer.c @@ -52,7 +52,8 @@ typedef struct ColorChannelMixerContext { } ColorChannelMixerContext; #define OFFSET(x) offsetof(ColorChannelMixerContext, x) -#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM + static const AVOption colorchannelmixer_options[] = { { "rr", "set the red gain for the red channel", OFFSET(rr), AV_OPT_TYPE_DOUBLE, {.dbl=1}, -2, 2, FLAGS }, { "rg", "set the green gain for the red channel", OFFSET(rg), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -2, 2, FLAGS }, @@ -124,7 +125,7 @@ static av_always_inline int filter_slice_rgba_planar(AVFilterContext *ctx, void const uint8_t rin = srcr[j]; const uint8_t gin = srcg[j]; const uint8_t bin = srcb[j]; - const uint8_t ain = srca[j]; + const uint8_t ain = have_alpha ? srca[j] : 0; dstr[j] = av_clip_uint8(s->lut[R][R][rin] + s->lut[R][G][gin] + @@ -183,7 +184,7 @@ static av_always_inline int filter_slice_rgba16_planar(AVFilterContext *ctx, voi const uint16_t rin = srcr[j]; const uint16_t gin = srcg[j]; const uint16_t bin = srcb[j]; - const uint16_t ain = srca[j]; + const uint16_t ain = have_alpha ? srca[j] : 0; dstr[j] = av_clip_uintp2(s->lut[R][R][rin] + s->lut[R][G][gin] + @@ -408,18 +409,20 @@ static int config_output(AVFilterLink *outlink) ColorChannelMixerContext *s = ctx->priv; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format); const int depth = desc->comp[0].depth; - int i, j, size, *buffer; + int i, j, size, *buffer = s->buffer; ff_fill_rgba_map(s->rgba_map, outlink->format); size = 1 << depth; - s->buffer = buffer = av_malloc(16 * size * sizeof(*s->buffer)); - if (!s->buffer) - return AVERROR(ENOMEM); + if (!s->buffer) { + s->buffer = buffer = av_malloc(16 * size * sizeof(*s->buffer)); + if (!s->buffer) + return AVERROR(ENOMEM); - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++, buffer += size) - s->lut[i][j] = buffer; + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++, buffer += size) + s->lut[i][j] = buffer; + } for (i = 0; i < size; i++) { s->lut[R][R][i] = lrint(i * s->rr); @@ -531,6 +534,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) return ff_filter_frame(outlink, out); } +static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, + char *res, int res_len, int flags) +{ + int ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags); + + if (ret < 0) + return ret; + + return config_output(ctx->outputs[0]); +} + static av_cold void uninit(AVFilterContext *ctx) { ColorChannelMixerContext *s = ctx->priv; @@ -566,4 +580,5 @@ AVFilter ff_vf_colorchannelmixer = { .inputs = colorchannelmixer_inputs, .outputs = colorchannelmixer_outputs, .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS, + .process_command = process_command, };