diff options
author | Paul B Mahol <onemda@gmail.com> | 2016-09-07 22:19:45 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2016-09-07 22:38:14 +0200 |
commit | 4fb6f9de0cfcbeb51684e5754bea8f10d4a8a9bf (patch) | |
tree | fcfe19654e8fc217c312c9d372d9780462d7e07b /libavfilter/vf_waveform.c | |
parent | 4b290078e4c6ab48847cb65b9ff48b720a5ac8d6 (diff) | |
download | ffmpeg-4fb6f9de0cfcbeb51684e5754bea8f10d4a8a9bf.tar.gz |
avfilter/vf_waveform: make possible to change background opacity
Only useful if output pixel format have alpha.
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavfilter/vf_waveform.c')
-rw-r--r-- | libavfilter/vf_waveform.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/libavfilter/vf_waveform.c b/libavfilter/vf_waveform.c index c2b84fbff5..64abbf2226 100644 --- a/libavfilter/vf_waveform.c +++ b/libavfilter/vf_waveform.c @@ -66,9 +66,10 @@ typedef struct WaveformContext { const AVClass *class; int mode; int acomp; + int dcomp; int ncomp; int pcomp; - const uint8_t *bg_color; + uint8_t bg_color[4]; float fintensity; int intensity; int mirror; @@ -76,6 +77,7 @@ typedef struct WaveformContext { int envelope; int graticule; float opacity; + float bgopacity; int estart[4]; int eend[4]; int *emax[4][4]; @@ -97,6 +99,7 @@ typedef struct WaveformContext { int column, int mirror); void (*graticulef)(struct WaveformContext *s, AVFrame *out); const AVPixFmtDescriptor *desc; + const AVPixFmtDescriptor *odesc; } WaveformContext; #define OFFSET(x) offsetof(WaveformContext, x) @@ -147,6 +150,8 @@ static const AVOption waveform_options[] = { { "digital", NULL, 0, AV_OPT_TYPE_CONST, {.i64=DIGITAL}, 0, 0, FLAGS, "scale" }, { "millivolts", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MILLIVOLTS}, 0, 0, FLAGS, "scale" }, { "ire", NULL, 0, AV_OPT_TYPE_CONST, {.i64=IRE}, 0, 0, FLAGS, "scale" }, + { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS }, + { "b", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS }, { NULL } }; @@ -2650,13 +2655,15 @@ static int config_input(AVFilterLink *inlink) case AV_PIX_FMT_GBRP9: case AV_PIX_FMT_GBRP10: case AV_PIX_FMT_GBRP12: - s->bg_color = black_gbrp_color; + memcpy(s->bg_color, black_gbrp_color, sizeof(s->bg_color)); s->graticulef = graticule_none; break; default: - s->bg_color = black_yuva_color; + memcpy(s->bg_color, black_yuva_color, sizeof(s->bg_color)); } + s->bg_color[3] *= s->bgopacity; + return 0; } @@ -2672,6 +2679,8 @@ static int config_output(AVFilterLink *outlink) comp++; } s->acomp = comp; + s->odesc = av_pix_fmt_desc_get(outlink->format); + s->dcomp = s->odesc->nb_components; av_freep(&s->peak); @@ -2733,20 +2742,20 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) out->pts = in->pts; av_frame_set_color_range(out, AVCOL_RANGE_JPEG); - for (k = 0; k < s->ncomp; k++) { + for (k = 0; k < s->dcomp; k++) { if (s->bits <= 8) { for (i = 0; i < outlink->h ; i++) - memset(out->data[s->desc->comp[k].plane] + - i * out->linesize[s->desc->comp[k].plane], + memset(out->data[s->odesc->comp[k].plane] + + i * out->linesize[s->odesc->comp[k].plane], s->bg_color[k], outlink->w); } else { const int mult = s->max / 256; - uint16_t *dst = (uint16_t *)out->data[s->desc->comp[k].plane]; + uint16_t *dst = (uint16_t *)out->data[s->odesc->comp[k].plane]; for (i = 0; i < outlink->h ; i++) { for (j = 0; j < outlink->w; j++) dst[j] = s->bg_color[k] * mult; - dst += out->linesize[s->desc->comp[k].plane] / 2; + dst += out->linesize[s->odesc->comp[k].plane] / 2; } } } |