[FFmpeg-devel] [PATCH 2/2] colorchannelmixer filter

Stefano Sabatini stefasab at gmail.com
Wed Apr 17 00:19:52 CEST 2013


On date Tuesday 2013-04-16 12:23:31 +0000, Paul B Mahol encoded:
> Signed-off-by: Paul B Mahol <onemda at gmail.com>
> ---
>  doc/filters.texi                   |  28 ++++++
>  libavfilter/Makefile               |   1 +
>  libavfilter/allfilters.c           |   1 +
>  libavfilter/vf_colorchannelmixer.c | 180 +++++++++++++++++++++++++++++++++++++
>  4 files changed, 210 insertions(+)
>  create mode 100644 libavfilter/vf_colorchannelmixer.c
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 87811df..11880e4 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -2078,6 +2078,34 @@ Adjust red, green and blue highlights (brightest pixels).
>  Allowed range is from -100 to 100, default is 0.
>  @end table
>  
> + at section colorchannelmixer
> +
> +This filter adjust video input frames by re-mixing color channels.

First sentence is usually impersonal:

Adjust video input frames by re-mixing color channels.

> +
> +The filter accepts the following options:
> +
> + at table @option
> + at item rr
> + at item rg
> + at item rb
> +Adjust contribution of input red, green and blue channels for output red channel.
> +Default is @code{100} for @var{rr}, and @code{0} for @var{rg} and @var{rb}.
> +
> + at item gr
> + at item gg
> + at item gb
> +Adjust contribution of input red, green and blue channels for output green channel.
> +Default is @code{100} for @var{gg}, and @code{0} for @var{gr} and @var{gb}.
> +
> + at item br
> + at item bg
> + at item bb
> +Adjust contribution of input red, green and blue channels for output blue channel.
> +Default is @code{100} for @var{bb}, and @code{0} for @var{br} and @var{bg}.

Supporting alpha as well may allow some cool effects.

> +
> +Allowed ranges are from @code{-200} to @code{200}.

Again, a range [-2, 2] seems more mathematically friendly and simplify
computations a bit. Also you should specify it is a double.

Also I suggest something like this close to the introductory blurb:

This filter modify a color channel by adding the values associated to
the other channels of the same pixels. For example if the value to
modify is red, the output value will be:
@example
@var{red}=@var{red}*@var{rr} + @var{blue}*@var{rb} + @var{green}*@var{rg}
@end example

A few examples are welcome.

> + at end table
> +
>  @section colormatrix
>  
>  Convert color matrix.
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 0927986..ef40836 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -105,6 +105,7 @@ OBJS-$(CONFIG_BLACKFRAME_FILTER)             += vf_blackframe.o
>  OBJS-$(CONFIG_BLEND_FILTER)                  += vf_blend.o
>  OBJS-$(CONFIG_BOXBLUR_FILTER)                += vf_boxblur.o
>  OBJS-$(CONFIG_COLORBALANCE_FILTER)           += vf_colorbalance.o
> +OBJS-$(CONFIG_COLORCHANNELMIXER_FILTER)      += vf_colorchannelmixer.o
>  OBJS-$(CONFIG_COLORMATRIX_FILTER)            += vf_colormatrix.o
>  OBJS-$(CONFIG_COPY_FILTER)                   += vf_copy.o
>  OBJS-$(CONFIG_CROP_FILTER)                   += vf_crop.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index bebbf2b..a6c8597 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -103,6 +103,7 @@ void avfilter_register_all(void)
>      REGISTER_FILTER(BLEND,          blend,          vf);
>      REGISTER_FILTER(BOXBLUR,        boxblur,        vf);
>      REGISTER_FILTER(COLORBALANCE,   colorbalance,   vf);
> +    REGISTER_FILTER(COLORCHANNELMIXER, colorchannelmixer, vf);
>      REGISTER_FILTER(COLORMATRIX,    colormatrix,    vf);
>      REGISTER_FILTER(COPY,           copy,           vf);
>      REGISTER_FILTER(CROP,           crop,           vf);
> diff --git a/libavfilter/vf_colorchannelmixer.c b/libavfilter/vf_colorchannelmixer.c
> new file mode 100644
> index 0000000..c146bb6
> --- /dev/null
> +++ b/libavfilter/vf_colorchannelmixer.c
> @@ -0,0 +1,180 @@
> +/*
> + * Copyright (c) 2013 Paul B Mahol
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "libavutil/opt.h"
> +#include "libavutil/pixdesc.h"
> +#include "avfilter.h"
> +#include "drawutils.h"
> +#include "formats.h"
> +#include "internal.h"
> +#include "video.h"
> +
> +typedef struct {
> +    const AVClass *class;
> +    double rr, rg, rb;
> +    double gr, gg, gb;
> +    double br, bg, bb;
> +
> +    int RR[256], RG[256], RB[256];
> +    int GR[256], GG[256], GB[256];
> +    int BR[256], BG[256], BB[256];
> +
> +    uint8_t rgba_map[4];
> +    int nb_components;
> +} ColorChannelMixerContext;
> +
> +#define OFFSET(x) offsetof(ColorChannelMixerContext, x)
> +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
> +static const AVOption colorchannelmixer_options[] = {
> +    { "rr", "", OFFSET(rr), AV_OPT_TYPE_DOUBLE, {.dbl=100}, -200, 200, FLAGS },
> +    { "rg", "", OFFSET(rg), AV_OPT_TYPE_DOUBLE, {.dbl=  0}, -200, 200, FLAGS },
> +    { "rb", "", OFFSET(rb), AV_OPT_TYPE_DOUBLE, {.dbl=  0}, -200, 200, FLAGS },
> +    { "gr", "", OFFSET(gr), AV_OPT_TYPE_DOUBLE, {.dbl=  0}, -200, 200, FLAGS },
> +    { "gg", "", OFFSET(gg), AV_OPT_TYPE_DOUBLE, {.dbl=100}, -200, 200, FLAGS },
> +    { "gb", "", OFFSET(gb), AV_OPT_TYPE_DOUBLE, {.dbl=  0}, -200, 200, FLAGS },
> +    { "br", "", OFFSET(br), AV_OPT_TYPE_DOUBLE, {.dbl=  0}, -200, 200, FLAGS },
> +    { "bg", "", OFFSET(bg), AV_OPT_TYPE_DOUBLE, {.dbl=  0}, -200, 200, FLAGS },
> +    { "bb", "", OFFSET(bb), AV_OPT_TYPE_DOUBLE, {.dbl=100}, -200, 200, FLAGS },
> +    { NULL }

missing help messages

[...]
-- 
FFmpeg = Fundamental & Fundamental Most Philosophical Elected Governor


More information about the ffmpeg-devel mailing list