[FFmpeg-devel] [PATCH] colorbalance filter

Stefano Sabatini stefasab at gmail.com
Mon Apr 15 23:13:28 CEST 2013


On date Monday 2013-04-15 11:02:34 +0000, Paul B Mahol encoded:
> Signed-off-by: Paul B Mahol <onemda at gmail.com>
> ---
>  doc/filters.texi              |  25 ++++
>  libavfilter/Makefile          |   1 +
>  libavfilter/allfilters.c      |   1 +
>  libavfilter/vf_colorbalance.c | 282 ++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 309 insertions(+)
>  create mode 100644 libavfilter/vf_colorbalance.c
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index b766985..566745e 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -2043,6 +2043,31 @@ boxblur=luma_radius=min(h\,w)/10:luma_power=1:chroma_radius=min(cw\,ch)/10:chrom
>  @end example
>  @end itemize
>  
> + at section colorbalance
> +
> +Modify color balance of input video.
> +
> +The filter accepts the following options:
> +
> + at table @option
> + at item rs
> + at item gs
> + at item bs
> +Adjust red, green and blue shadows (darkest pixels).
> +
> + at item rm
> + at item gm
> + at item bm
> +Adjust red, green and blue midtones (medium pixels).
> +
> + at item rh
> + at item gh
> + at item bh
> +Adjust red, green and blue highlights (brightest pixels).

Please expand on what "adjust" means in this context.

> +

> +Allowed range is from -100: complementary colors: cyan for red, magenta for green and yellow for blue to 100: red, green and blue.

confusing

> + at end table




> +
>  @section colormatrix
>  
>  Convert color matrix.
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 949972d..0927986 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -104,6 +104,7 @@ OBJS-$(CONFIG_BLACKDETECT_FILTER)            += vf_blackdetect.o
>  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_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 95bd270..bebbf2b 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -102,6 +102,7 @@ void avfilter_register_all(void)
>      REGISTER_FILTER(BLACKFRAME,     blackframe,     vf);
>      REGISTER_FILTER(BLEND,          blend,          vf);
>      REGISTER_FILTER(BOXBLUR,        boxblur,        vf);
> +    REGISTER_FILTER(COLORBALANCE,   colorbalance,   vf);
>      REGISTER_FILTER(COLORMATRIX,    colormatrix,    vf);
>      REGISTER_FILTER(COPY,           copy,           vf);
>      REGISTER_FILTER(CROP,           crop,           vf);
> diff --git a/libavfilter/vf_colorbalance.c b/libavfilter/vf_colorbalance.c
> new file mode 100644
> index 0000000..cd7839c
> --- /dev/null
> +++ b/libavfilter/vf_colorbalance.c
> @@ -0,0 +1,282 @@
> +/*
> + * 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/avassert.h"
> +#include "avfilter.h"
> +#include "formats.h"
> +#include "internal.h"
> +#include "video.h"
> +
> +typedef struct {
> +    double shadows;
> +    double midtones;
> +    double highlights;
> +} Range;
> +
> +typedef struct {
> +    const AVClass *class;
> +    Range cyan_red;
> +    Range magenta_green;
> +    Range yellow_blue;
> +
> +    uint8_t  lookup8[3][256];
> +    uint16_t lookup16[3][256 * 256];
> +} ColorBalanceContext;
> +
> +#define OFFSET(x) offsetof(ColorBalanceContext, x)
> +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
> +static const AVOption colorbalance_options[] = {

> +    { "rs", "red shadows",       OFFSET(cyan_red.shadows),         AV_OPT_TYPE_DOUBLE, {.dbl=0}, -100, 100, FLAGS },
> +    { "gs", "green shadows",     OFFSET(magenta_green.shadows),    AV_OPT_TYPE_DOUBLE, {.dbl=0}, -100, 100, FLAGS },
> +    { "bs", "blue shadows",      OFFSET(yellow_blue.shadows),      AV_OPT_TYPE_DOUBLE, {.dbl=0}, -100, 100, FLAGS },
> +    { "rm", "red midtones",      OFFSET(cyan_red.midtones),        AV_OPT_TYPE_DOUBLE, {.dbl=0}, -100, 100, FLAGS },
> +    { "gm", "green midtones",    OFFSET(magenta_green.midtones),   AV_OPT_TYPE_DOUBLE, {.dbl=0}, -100, 100, FLAGS },
> +    { "bm", "blue midtones",     OFFSET(yellow_blue.midtones),     AV_OPT_TYPE_DOUBLE, {.dbl=0}, -100, 100, FLAGS },
> +    { "rh", "red hightlights",   OFFSET(cyan_red.highlights),      AV_OPT_TYPE_DOUBLE, {.dbl=0}, -100, 100, FLAGS },
> +    { "gh", "green hightlights", OFFSET(magenta_green.highlights), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -100, 100, FLAGS },
> +    { "bh", "blue hightlights",  OFFSET(yellow_blue.highlights),   AV_OPT_TYPE_DOUBLE, {.dbl=0}, -100, 100, FLAGS },

set X shadows for grammatical overall consistency

[...]
-- 
FFmpeg = Fiendish & Fast Murdering Pitiless EniGma


More information about the ffmpeg-devel mailing list