I have updated the patch. I checked the output with many combinations of parameters. It is bitexact now. I am facing problems in rebasing against the latest master.
From f6c6a66b306475e3bc7977f59287c920f5e867a7 Mon Sep 17 00:00:00 2001 From: Arwa Arif <arwaarif1...@gmail.com> Date: Mon, 19 Jan 2015 03:56:48 +0530 Subject: [PATCH] Port mp=eq/eq2 to FFmpeg
--- configure | 38 +++---- doc/filters.texi | 43 +++++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_eq.c | 285 ++++++++++++++++++++++++++++++++++++++++++++++ libavfilter/vf_eq.h | 63 ++++++++++ libavfilter/x86/Makefile | 1 + libavfilter/x86/vf_eq.c | 96 ++++++++++++++++ 8 files changed, 503 insertions(+), 25 deletions(-) create mode 100644 libavfilter/vf_eq.c create mode 100644 libavfilter/vf_eq.h create mode 100644 libavfilter/x86/vf_eq.c diff --git a/configure b/configure index c73562b..d122720 100755 --- a/configure +++ b/configure @@ -60,7 +60,6 @@ show_help(){ cat <<EOF Usage: configure [options] Options: [defaults in brackets after descriptions] - Help options: --help print this message --list-decoders show all available decoders @@ -74,7 +73,6 @@ Help options: --list-indevs show all available input devices --list-outdevs show all available output devices --list-filters show all available filters - Standard options: --logfile=FILE log tests and output to FILE [config.log] --disable-logging do not log configure debug information @@ -90,14 +88,12 @@ Standard options: --enable-rpath use rpath to allow installing libraries in paths not part of the dynamic linker search path use rpath when linking programs [USE WITH CARE] - Licensing options: --enable-gpl allow use of GPL code, the resulting libs and binaries will be under GPL [no] --enable-version3 upgrade (L)GPL to version 3 [no] --enable-nonfree allow use of nonfree code, the resulting libs and binaries will be unredistributable [no] - Configuration options: --disable-static do not build static libraries [no] --enable-shared build shared libraries [no] @@ -108,21 +104,18 @@ Configuration options: --disable-all disable building components, libraries and programs --enable-incompatible-libav-abi enable incompatible Libav fork ABI [no] --enable-raise-major increase major version numbers in sonames [no] - Program options: --disable-programs do not build command line programs --disable-ffmpeg disable ffmpeg build --disable-ffplay disable ffplay build --disable-ffprobe disable ffprobe build --disable-ffserver disable ffserver build - Documentation options: --disable-doc do not build documentation --disable-htmlpages do not build HTML documentation pages --disable-manpages do not build man documentation pages --disable-podpages do not build POD documentation pages --disable-txtpages do not build text documentation pages - Component options: --disable-avdevice disable libavdevice build --disable-avcodec disable libavcodec build @@ -147,13 +140,11 @@ Component options: --disable-fft disable FFT code --disable-faan disable floating point AAN (I)DCT code --disable-pixelutils disable pixel utils in libavutil - Hardware accelerators: --disable-dxva2 disable DXVA2 code [autodetect] --disable-vaapi disable VAAPI code [autodetect] --disable-vda disable VDA code [autodetect] --disable-vdpau disable VDPAU code [autodetect] - Individual component options: --disable-everything disable all components listed below --disable-encoder=NAME disable encoder NAME @@ -190,7 +181,6 @@ Individual component options: --enable-filter=NAME enable filter NAME --disable-filter=NAME disable filter NAME --disable-filters disable all filters - External library support: --enable-avisynth enable reading of AviSynth script files [no] --disable-bzlib disable bzlib [autodetect] @@ -226,6 +216,7 @@ External library support: --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no] --enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no] --enable-libopencv enable video filtering via libopencv [no] + --enable-libopenh264 enable H.264 encoding via OpenH264 [no] --enable-libopenjpeg enable JPEG 2000 de/encoding via OpenJPEG [no] --enable-libopus enable Opus de/encoding via libopus [no] --enable-libpulse enable Pulseaudio input via libpulse [no] @@ -273,7 +264,6 @@ External library support: --enable-x11grab enable X11 grabbing (legacy) [no] --disable-xlib disable xlib [autodetect] --disable-zlib disable zlib [autodetect] - Toolchain options: --arch=ARCH select architecture [$arch] --cpu=CPU select the minimum required CPU (affects @@ -320,7 +310,6 @@ Toolchain options: --enable-pic build position-independent code --enable-thumb compile for Thumb instruction set --enable-lto use link-time optimization - Advanced options (experts only): --malloc-prefix=PREFIX prefix malloc and related names with PREFIX --disable-symver disable symbol versioning @@ -330,7 +319,6 @@ Advanced options (experts only): (faster, but may crash) --enable-memalign-hack emulate memalign, interferes with memory debuggers --sws-max-filter-size=N the max filter size swscale uses [$sws_max_filter_size_default] - Optimization options (experts only): --disable-asm disable all assembly optimizations --disable-altivec disable AltiVec optimizations @@ -361,7 +349,6 @@ Optimization options (experts only): --disable-mipsdspr2 disable MIPS DSP ASE R2 optimizations --disable-mipsfpu disable floating point MIPS optimizations --disable-fast-unaligned consider unaligned accesses slow - Developer options (useful when working on FFmpeg itself): --disable-debug disable debugging symbols --enable-debug=LEVEL set the debug level [$debuglevel] @@ -389,7 +376,6 @@ Developer options (useful when working on FFmpeg itself): (group) and PROB the probability associated with NAME (default 0.5). --random-seed=VALUE seed value for --enable/disable-random - NOTE: Object files are built at the place where configure is launched. EOF exit 0 @@ -420,7 +406,6 @@ warn(){ die(){ echolog "$@" cat <<EOF - If you think configure made a mistake, make sure you are using the latest version from Git. If the latest version fails, report the problem to the ffmpeg-u...@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net. @@ -1367,6 +1352,7 @@ EXTERNAL_LIBRARY_LIST=" libopencore_amrnb libopencore_amrwb libopencv + libopenh264 libopenjpeg libopus libpulse @@ -1640,7 +1626,6 @@ HEADERS_LIST=" asm_types_h cdio_paranoia_h cdio_paranoia_paranoia_h - CL_cl_h dev_bktr_ioctl_bt848_h dev_bktr_ioctl_meteor_h dev_ic_bt8xx_h @@ -2363,6 +2348,7 @@ libopencore_amrnb_decoder_deps="libopencore_amrnb" libopencore_amrnb_encoder_deps="libopencore_amrnb" libopencore_amrnb_encoder_select="audio_frame_queue" libopencore_amrwb_decoder_deps="libopencore_amrwb" +libopenh264_encoder_deps="libopenh264" libopenjpeg_decoder_deps="libopenjpeg" libopenjpeg_encoder_deps="libopenjpeg" libopus_decoder_deps="libopus" @@ -2579,6 +2565,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_src_filter_deps="frei0r dlopen" @@ -2686,7 +2673,6 @@ docdir_default='${prefix}/share/doc/ffmpeg' incdir_default='${prefix}/include' libdir_default='${prefix}/lib' mandir_default='${prefix}/share/man' -shlibdir_default='${LIBDIR}' # toolchain ar_default="ar" @@ -3220,6 +3206,7 @@ msvc_common_flags(){ -lavifil32) echo vfw32.lib ;; -lavicap32) echo vfw32.lib user32.lib ;; -l*) echo ${flag#-l}.lib ;; + -L*) echo -libpath:${flag#-L} ;; *) echo $flag ;; esac done @@ -4326,6 +4313,9 @@ echo "config:$arch:$subarch:$cpu:$target_os:$(esc $cc_ident):$(esc $FFMPEG_CONFI check_cpp_condition stdlib.h "defined(__PIC__) || defined(__pic__) || defined(PIC)" && enable_weak pic +set_default libdir +: ${shlibdir_default:="$libdir"} + set_default $PATHS_LIST set_default nm @@ -4426,7 +4416,7 @@ unsigned int endian = 'B' << 24 | 'I' << 16 | 'G' << 8 | 'E'; EOF od -t x1 $TMPO | grep -q '42 *49 *47 *45' && enable bigendian -if [ "$cpu" = "power7" ] || [ "$cpu" = "power8" ] ;then +if [ "$cpu" = "power7" ] || [ "$cpu" = "power8" ] || enabled ppc64; then if ! enabled bigendian && enabled altivec ;then enable vsx fi @@ -4769,7 +4759,6 @@ check_func_headers glob.h glob enabled xlib && check_func_headers "X11/Xlib.h X11/extensions/Xvlib.h" XvGetPortAttribute -lXv -lX11 -lXext -check_header cl/cl.h check_header direct.h check_header dlfcn.h check_header dxva.h @@ -4886,6 +4875,7 @@ enabled libnut && require libnut libnut.h nut_demuxer_init -lnut enabled libopencore_amrnb && require libopencore_amrnb opencore-amrnb/interf_dec.h Decoder_Interface_init -lopencore-amrnb enabled libopencore_amrwb && require libopencore_amrwb opencore-amrwb/dec_if.h D_IF_init -lopencore-amrwb enabled libopencv && require_pkg_config opencv opencv/cxcore.h cvCreateImageHeader +enabled libopenh264 && require_pkg_config openh264 wels/codec_api.h WelsGetCodecVersion enabled libopenjpeg && { check_lib openjpeg.h opj_version -lopenmj2 -DOPJ_STATIC || check_lib openjpeg-1.5/openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC || check_lib openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC || @@ -5058,8 +5048,8 @@ enabled xlib && check_lib X11/Xlib.h XOpenDisplay -lX11 || disable xlib if ! disabled libxcb; then - check_pkg_config xcb xcb/xcb.h xcb_connect || { - enabled libxcb && die "ERROR: libxcb not found"; + check_pkg_config "xcb >= 1.4" xcb/xcb.h xcb_connect || { + enabled libxcb && die "ERROR: libxcb >= 1.4 not found"; } && disable x11grab && enable libxcb if enabled libxcb; then @@ -5694,7 +5684,7 @@ cat > $TMPH <<EOF #define FFMPEG_CONFIG_H #define FFMPEG_CONFIGURATION "$(c_escape $FFMPEG_CONFIGURATION)" #define FFMPEG_LICENSE "$(c_escape $license)" -#define CONFIG_THIS_YEAR 2014 +#define CONFIG_THIS_YEAR 2015 #define FFMPEG_DATADIR "$(eval c_escape $datadir)" #define AVCONV_DATADIR "$(eval c_escape $datadir)" #define CC_IDENT "$(c_escape ${cc_ident:-Unknown compiler})" @@ -5778,7 +5768,6 @@ prefix=$prefix exec_prefix=\${prefix} libdir=$libdir includedir=$incdir - Name: $name Description: $comment Version: $version @@ -5798,7 +5787,6 @@ prefix= exec_prefix= libdir=\${pcfiledir}/../../../$name includedir=${includedir} - Name: $name Description: $comment Version: $version diff --git a/doc/filters.texi b/doc/filters.texi index d7b2273..f3c15ad 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -4320,6 +4320,49 @@ edgedetect=mode=colormix:high=0 @end example @end itemize +@section eq +Set brightness, contrast, saturation and gamma adjustment. + +The filter accepts the following options: + +@table @option +@item gamma +Set the gamma value. It accepts a float value in range @code{0.1} to @code{10.0}. +The default value is @code{1.0}. + +@item contrast +Set the contrast value. It accepts a float value in range @code{-2.0} to +@code{2.0}. The default value is @code{0.0}. + +@item brightness +Set the brightness value. It accepts a float value in range @code{-1.0} to +@code{1.0}. The default value is @code{0.0}. + +@item saturation +Set the saturation value. It accepts a float value in range @code{0.0} to +@code{3.0}. The default value is @code{1.0}. + +@item gamma_y +Set the gamma value for the luma plane. It accepts a float value in range +@code{0.1} to @code{10.0}. The default value is @code{1.0}. + +@item gamma_u +Set the gamma value for 1st chroma plane. It accepts a float value in range +@code{0.1} to @code{10.0}. The default value is @code{1.0}. + +@item gamma_v +Set the gamma value for 2nd chroma plane. It accepts a float value in range +@code{0.1} to @code{10.0}. The default value is @code{1.0}. + +@item gamma_weight +Can be used to reduce the effect of a high gamma value on bright image areas, +e.g. keep them from getting overamplified and just plain white. It accepts a +float value in range @code{0.0} to @code{1.0}.A value of @code{0.0} turns the +gamma correction all the way down while @code{1.0} leaves it at its full strength. +Default is @code{1.0}. + +@end table + @section extractplanes Extract color channel components from input video stream into diff --git a/libavfilter/Makefile b/libavfilter/Makefile index e43d76d..8e94033 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 381da4f..db34cb9 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -132,6 +132,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..f8b6fcb --- /dev/null +++ b/libavfilter/vf_eq.c @@ -0,0 +1,285 @@ +/* + * Original MPlayer filters by Richard Felker, Hampa Hug, Daniel Moreno, + * and Michael Niedermeyer. + * + * Copyright (c) 2014 James Darnley <james.darn...@gmail.com> + * Copyright (c) 2015 Arwa Arif <arwaarif1...@gmail.com> + * + * 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: + * - Add support to process_command + */ + +#include "libavfilter/internal.h" +#include "libavutil/common.h" +#include "libavutil/imgutils.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" +#include "vf_eq.h" + +static void create_lut(EQParameters *param) +{ + unsigned i; + double g, v; + double lw, gw; + + g = param->gamma; + gw = param->gamma_weight; + lw = 1.0 - gw; + + g = 1.0 / g; + + for (i = 0; i < 256; i++) { + v = (double) i / 255.0; + v = param->contrast * (v - 0.5) + 0.5 + param->brightness; + + if (v <= 0.0) + param->lut[i] = 0; + + else { + v = v*lw + pow(v, g)*gw; + if (v >= 1.0) + param->lut[i] = 255; + else + param->lut[i] = (unsigned char) (256.0 * v); + } + } + + for (i = 0; i < 256 * 256; i++) + param->lut16[i] = param->lut[i & 0xFF] + (param->lut[i >> 8] << 8); + + param->lut_clean = 1; +} + +static void apply_lut(EQParameters *param, uint8_t *dst, int dst_stride, + uint8_t *src, int src_stride, int w, int h) +{ + int x, y; + + if (!param->lut_clean) + create_lut(param); + + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + dst[y * dst_stride + x] = param->lut[src[y * src_stride + x]]; + } + } +} + +static void process_c(EQParameters *param, uint8_t *dst, int dst_stride, + uint8_t *src, int src_stride, int w, int h) +{ + int x, y, pel; + + int contrast = (int) (param->contrast * 256 * 16); + int brightness = ((int) (100.0 * param->brightness + 100.0) * 511) / 200 - 128 - contrast / 32; + + 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 void check_values(EQParameters *param, EQContext *eq) +{ + if (param->contrast == 1.0 && param->brightness == 0.0 && param->gamma == 1.0) + param->adjust = NULL; + else if (param->gamma == 1.0) + param->adjust = eq->process; + else + param->adjust = apply_lut; +} + +static void set_contrast(EQContext *eq) +{ + eq->param[0].contrast = eq->contrast; + eq->param[0].lut_clean = 0; + check_values(&eq->param[0], eq); +} + +static void set_brightness(EQContext *eq) +{ + eq->param[0].brightness = eq->brightness; + eq->param[0].lut_clean = 0; + check_values(&eq->param[0], eq); +} + +static void set_gamma(EQContext *eq) +{ + int i; + eq->param[0].gamma = eq->gamma * eq->gamma_u; + eq->param[1].gamma = sqrt(eq->gamma_v / eq->gamma_u); + eq->param[2].gamma = sqrt(eq->gamma_y / eq->gamma_u); + + for (i = 0; i < 3; i++) { + eq->param[i].gamma_weight = eq->gamma_weight; + eq->param[i].lut_clean = 0; + check_values(&eq->param[i], eq); + } +} + +static void set_saturation(EQContext *eq) +{ + int i; + for (i = 1; i < 3; i++) { + eq->param[i].contrast = eq->saturation; + eq->param[i].lut_clean = 0; + check_values(&eq->param[i], eq); + } +} + +static int initialize(AVFilterContext *ctx) +{ + EQContext *eq = ctx->priv; + int i; + + for (i = 0; i < 3; i++) { + eq->param[i].contrast = eq->param[i].contrast; + eq->param[i].brightness = eq->param[i].brightness; + } + + eq->process = process_c; + + if (ARCH_X86) + ff_eq_init_x86(eq); + + set_gamma(eq); + set_contrast(eq); + set_brightness(eq); + set_saturation(eq); + + return 0; +} + +static int query_formats(AVFilterContext *ctx) +{ + static const enum AVPixelFormat pixel_fmts_eq[] = { + AV_PIX_FMT_GRAY8, + 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_eq)); + + return 0; +} + +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 *desc; + int i; + + out = ff_get_video_buffer(outlink, inlink->w, inlink->h); + if (!out) + return AVERROR(ENOMEM); + + av_frame_copy_props(out, in); + desc = av_pix_fmt_desc_get(inlink->format); + + for (i = 0; i < desc->nb_components; i++) { + int w = inlink->w; + int h = inlink->h; + + if (i == 1 || i == 2) { + w = FF_CEIL_RSHIFT(w, desc->log2_chroma_w); + h = FF_CEIL_RSHIFT(h, desc->log2_chroma_h); + } + + if (eq->param[i].adjust) + eq->param[i].adjust(&eq->param[i], out->data[i], out->linesize[i], + in->data[i], in->linesize[i], w, h); + else + av_image_copy_plane(out->data[i], out->linesize[i], + in->data[i], in->linesize[i], w, h); + } + + 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[] = { + { "gamma", "set the initial gamma value", + OFFSET(gamma), AV_OPT_TYPE_DOUBLE, {.dbl = 1.0}, 0.1, 10.0, FLAGS }, + { "contrast", "set the contrast adjustment, negative values give a negative image", + OFFSET(contrast), AV_OPT_TYPE_DOUBLE, {.dbl = 1.0}, -2.0, 2.0, FLAGS }, + { "brightness", "set the brightness adjustment", + OFFSET(brightness), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, -1.0, 1.0, FLAGS }, + { "saturation", "set the saturation adjustment", + OFFSET(saturation), AV_OPT_TYPE_DOUBLE, {.dbl = 1.0}, 0.0, 3.0, FLAGS }, + { "gamma_y", "gamma value for the luma plane", + OFFSET(gamma_y), AV_OPT_TYPE_DOUBLE, {.dbl = 1.0}, 0.1, 10.0, FLAGS }, + { "gamma_u", "gamma value for the 1st chroma plane", + OFFSET(gamma_u), AV_OPT_TYPE_DOUBLE, {.dbl = 1.0}, 0.1, 10.0, FLAGS }, + { "gamma_v", "gamma value for the 2nd chroma plane", + OFFSET(gamma_v), AV_OPT_TYPE_DOUBLE, {.dbl = 1.0}, 0.1, 10.0, FLAGS }, + { "gamma_weight", "set the gamma weight which reduces the effect of gamma on bright areas", + OFFSET(gamma_weight), AV_OPT_TYPE_DOUBLE, {.dbl = 1.0}, 0.0, 1.0, FLAGS }, + { NULL } +}; + +AVFILTER_DEFINE_CLASS(eq); + +AVFilter ff_vf_eq = { + .name = "eq", + .description = NULL_IF_CONFIG_SMALL("Adjust brightness, contrast, gamma, and saturation."), + .priv_size = sizeof(EQContext), + .priv_class = &eq_class, + .inputs = eq_inputs, + .outputs = eq_outputs, + .query_formats = query_formats, + .init = initialize, +}; diff --git a/libavfilter/vf_eq.h b/libavfilter/vf_eq.h new file mode 100644 index 0000000..cf172cc --- /dev/null +++ b/libavfilter/vf_eq.h @@ -0,0 +1,63 @@ +/* + * Original MPlayer filters by Richard Felker, Hampa Hug, Daniel Moreno, + * and Michael Niedermeyer. + * + * Copyright (c) 2014 James Darnley <james.darn...@gmail.com> + * Copyright (c) 2015 Arwa Arif <arwaarif1...@gmail.com> + * + * 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. + */ + +#ifndef AVFILTER_EQ_H +#define AVFILTER_EQ_H + +#include "avfilter.h" + +typedef struct EQParameters { + + void (*adjust)(struct EQParameters *eq, uint8_t *dst, int dst_stride, + uint8_t *src, int src_stride, int w, int h); + + uint8_t lut[256]; + uint16_t lut16[256*256]; + + double brightness, contrast, gamma, gamma_weight; + int lut_clean; + +} EQParameters; + +typedef struct { + const AVClass *class; + + EQParameters param[3]; + + double contrast; + double brightness; + double saturation; + + double gamma; + double gamma_weight; + double gamma_y, gamma_u, gamma_v; + + void (*process)(struct EQParameters *par, uint8_t *dst, int dst_stride, + uint8_t *src, int src_stride, int w, int h); + +} EQContext; + +void ff_eq_init_x86(EQContext *eq); + +#endif /* AVFILTER_EQ_H */ diff --git a/libavfilter/x86/Makefile b/libavfilter/x86/Makefile index b93154e..8222e3f 100644 --- a/libavfilter/x86/Makefile +++ b/libavfilter/x86/Makefile @@ -1,3 +1,4 @@ +OBJS-$(CONFIG_EQ_FILTER) += x86/vf_eq.o OBJS-$(CONFIG_FSPP_FILTER) += x86/vf_fspp.o OBJS-$(CONFIG_GRADFUN_FILTER) += x86/vf_gradfun_init.o OBJS-$(CONFIG_HQDN3D_FILTER) += x86/vf_hqdn3d_init.o diff --git a/libavfilter/x86/vf_eq.c b/libavfilter/x86/vf_eq.c new file mode 100644 index 0000000..492f2ab --- /dev/null +++ b/libavfilter/x86/vf_eq.c @@ -0,0 +1,96 @@ +/* + * + * Original MPlayer filters 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. + */ + +#include "libavutil/attributes.h" +#include "libavutil/cpu.h" +#include "libavutil/mem.h" +#include "libavutil/x86/asm.h" +#include "libavfilter/vf_eq.h" + +#if HAVE_MMX_INLINE && HAVE_6REGS +static void process_MMX(EQParameters *param, uint8_t *dst, int dst_stride, + uint8_t *src, int src_stride, int w, int h) +{ + int i; + int pel; + int dstep = dst_stride - w; + int sstep = src_stride - w; + short brvec[4]; + short contvec[4]; + int contrast = (int) (param->contrast * 256 * 16); + int brightness = ((int) (100.0 * param->brightness + 100.0) * 511) / 200 - 128 - contrast / 32; + + brvec[0] = brvec[1] = brvec[2] = brvec[3] = brightness; + contvec[0] = contvec[1] = contvec[2] = contvec[3] = contrast; + + while (h--) { + __asm__ volatile ( + "movq (%5), %%mm3 \n\t" + "movq (%6), %%mm4 \n\t" + "pxor %%mm0, %%mm0 \n\t" + "movl %4, %%eax \n\t" + ".p2align 4 \n\t" + "1: \n\t" + "movq (%0), %%mm1 \n\t" + "movq (%0), %%mm2 \n\t" + "punpcklbw %%mm0, %%mm1\n\t" + "punpckhbw %%mm0, %%mm2\n\t" + "psllw $4, %%mm1 \n\t" + "psllw $4, %%mm2 \n\t" + "pmulhw %%mm4, %%mm1 \n\t" + "pmulhw %%mm4, %%mm2 \n\t" + "paddw %%mm3, %%mm1 \n\t" + "paddw %%mm3, %%mm2 \n\t" + "packuswb %%mm2, %%mm1 \n\t" + "add $8, %0 \n\t" + "movq %%mm1, (%1) \n\t" + "add $8, %1 \n\t" + "decl %%eax \n\t" + "jnz 1b \n\t" + : "=r" (src), "=r" (dst) + : "0" (src), "1" (dst), "r" (w>>3), "r" (brvec), "r" (contvec) + : "%eax" + ); + + for (i = w&7; i; i--) { + pel = ((*src++ * contrast) >> 12) + brightness; + if (pel & 768) + pel = (-pel) >> 31; + *dst++ = pel; + } + + src += sstep; + dst += dstep; + } + __asm__ volatile ( "emms \n\t" ::: "memory" ); +} +#endif + +av_cold void ff_eq_init_x86(EQContext *eq) +{ +#if HAVE_MMX_INLINE + int cpu_flags = av_get_cpu_flags(); + + if (cpu_flags & AV_CPU_FLAG_MMX) { + eq->process = process_MMX; + } +#endif +} -- 1.7.9.5
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel