[FFmpeg-cvslog] avfilter/vf_waveform: make possible to change background opacity
Paul B Mahol
git at videolan.org
Wed Sep 7 23:38:30 EEST 2016
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Wed Sep 7 22:19:45 2016 +0200| [4fb6f9de0cfcbeb51684e5754bea8f10d4a8a9bf] | committer: Paul B Mahol
avfilter/vf_waveform: make possible to change background opacity
Only useful if output pixel format have alpha.
Signed-off-by: Paul B Mahol <onemda at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4fb6f9de0cfcbeb51684e5754bea8f10d4a8a9bf
---
doc/filters.texi | 3 +++
libavfilter/vf_waveform.c | 25 +++++++++++++++++--------
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index a3158be..86a9599 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -14162,6 +14162,9 @@ Set scale used for displaying graticule.
@item ire
@end table
Default is digital.
+
+ at item bgopacity, b
+Set background opacity.
@end table
@section weave
diff --git a/libavfilter/vf_waveform.c b/libavfilter/vf_waveform.c
index c2b84fb..64abbf2 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;
}
}
}
More information about the ffmpeg-cvslog
mailing list