--- Still a couple of things on the todo list (see the top of the new file) but I thought I would send the basics along for people to nit pick.
configure | 1 + libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_eq.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+) create mode 100644 libavfilter/vf_eq.c diff --git a/configure b/configure index b39b6d3..e49894d 100755 --- a/configure +++ b/configure @@ -2549,6 +2549,7 @@ delogo_filter_deps="gpl" deshake_filter_select="pixelutils" drawtext_filter_deps="libfreetype" ebur128_filter_deps="gpl" +eq_filter_deps="gpl" flite_filter_deps="libflite" frei0r_filter_deps="frei0r dlopen" frei0r_filter_extralibs='$ldl' diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 3241b76..d643b4b 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -116,6 +116,7 @@ OBJS-$(CONFIG_DRAWGRID_FILTER) += vf_drawbox.o OBJS-$(CONFIG_DRAWTEXT_FILTER) += vf_drawtext.o OBJS-$(CONFIG_ELBG_FILTER) += vf_elbg.o OBJS-$(CONFIG_EDGEDETECT_FILTER) += vf_edgedetect.o +OBJS-$(CONFIG_EQ_FILTER) += vf_eq.o OBJS-$(CONFIG_EXTRACTPLANES_FILTER) += vf_extractplanes.o OBJS-$(CONFIG_FADE_FILTER) += vf_fade.o OBJS-$(CONFIG_FIELD_FILTER) += vf_field.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 670f2d1..fa4e73b 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -134,6 +134,7 @@ void avfilter_register_all(void) REGISTER_FILTER(DRAWTEXT, drawtext, vf); REGISTER_FILTER(EDGEDETECT, edgedetect, vf); REGISTER_FILTER(ELBG, elbg, vf); + REGISTER_FILTER(EQ, eq, vf); REGISTER_FILTER(EXTRACTPLANES, extractplanes, vf); REGISTER_FILTER(FADE, fade, vf); REGISTER_FILTER(FIELD, field, vf); diff --git a/libavfilter/vf_eq.c b/libavfilter/vf_eq.c new file mode 100644 index 0000000..2dc21dc --- /dev/null +++ b/libavfilter/vf_eq.c @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2014 James Darnley <james.darn...@gmail.com> + * + * Original MPlayer filter by Richard Felker. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU 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. + */ + +/** + * @file + * very simple video equalizer + */ + +/* TODO: + * - change the options to be floats and change scale to -1..1 + * - copy chroma plane pointers rather than data + * - use SIMD + * - support alpha channels + */ + +#include "libavfilter/internal.h" +#include "libavutil/common.h" +#include "libavutil/imgutils.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" + +typedef struct { + const AVClass *class; + int brightness; + int contrast; +} EQContext; + +static int query_formats(AVFilterContext *ctx) +{ + static const enum AVPixelFormat pixel_fmts[] = { + /* Only IMGFMT_CLPL is missing. */ + AV_PIX_FMT_GRAY8, + AV_PIX_FMT_NV12, + AV_PIX_FMT_NV21, + AV_PIX_FMT_YUV410P, + AV_PIX_FMT_YUV411P, + AV_PIX_FMT_YUV420P, + AV_PIX_FMT_YUV422P, + AV_PIX_FMT_YUV444P, + AV_PIX_FMT_NONE + }; + + ff_set_common_formats(ctx, ff_make_format_list(pixel_fmts)); + + return 0; +} + +static void process_c(uint8_t *dst, int dst_stride, uint8_t *src, int src_stride, + int w, int h, int brightness, int contrast) +{ + int x, y, pel; + + contrast = ((contrast + 100) * 256 * 256) / 100; + brightness = ((brightness + 100) * 511) / 200 - 128 - contrast / 512; + + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + pel = ((src[y * src_stride + x] * contrast) >> 16) + brightness; + + if (pel & 768) + pel = (-pel) >> 31; + + dst[y * dst_stride + x] = pel; + } + } +} + +static int filter_frame(AVFilterLink *inlink, AVFrame *in) +{ + AVFilterContext *ctx = inlink->dst; + AVFilterLink *outlink = inlink->dst->outputs[0]; + EQContext *eq = ctx->priv; + AVFrame *out; + const AVPixFmtDescriptor *csp; + int i; + + if (eq->brightness == 0 && eq->contrast == 0) + return ff_filter_frame(outlink, in); + + out = ff_get_video_buffer(outlink, inlink->w, inlink->h); + if (!out) + return AVERROR(ENOMEM); + + av_frame_copy_props(out, in); + csp = av_pix_fmt_desc_get(inlink->format); + + for (i = 1; i < csp->nb_components; i++) { + int w = FF_CEIL_RSHIFT(inlink->w, csp->log2_chroma_w); + int h = FF_CEIL_RSHIFT(inlink->h, csp->log2_chroma_h); + av_image_copy_plane(out->data[i], out->linesize[i], + in->data[i], in->linesize[i], + w, h); + } + + process_c(out->data[0], out->linesize[0], + in->data[0], in->linesize[0], + inlink->w, inlink->h, + eq->brightness, eq->contrast); + + return ff_filter_frame(outlink, out); +} + +static const AVFilterPad eq_inputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .filter_frame = filter_frame, + }, + { NULL } +}; + +static const AVFilterPad eq_outputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + }, + { NULL } +}; + +#define OFFSET(x) offsetof(EQContext, x) +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM +static const AVOption eq_options[] = { + { "brightness", "", OFFSET(brightness), AV_OPT_TYPE_INT, {.i64 = 0}, -100, 100, FLAGS }, + { "contrast", "", OFFSET(contrast), AV_OPT_TYPE_INT, {.i64 = 0}, -100, 100, FLAGS }, + { NULL } +}; + +AVFILTER_DEFINE_CLASS(eq); + +AVFilter ff_vf_eq = { + .name = "eq", + .description = NULL_IF_CONFIG_SMALL("very simple video equalizer."), + .priv_size = sizeof(EQContext), + .priv_class = &eq_class, + .inputs = eq_inputs, + .outputs = eq_outputs, + .query_formats = query_formats, +}; -- 2.0.4 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel