summaryrefslogtreecommitdiffstats
path: root/libmpcodecs
diff options
context:
space:
mode:
authorrfelker <rfelker@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-08-21 23:08:20 +0000
committerrfelker <rfelker@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-08-21 23:08:20 +0000
commit6a04e6e54ce9ebcbab429b92cba1e43ba5e5ad05 (patch)
tree20d1b313dd5dd95030711617a1eb81ade4cb24f8 /libmpcodecs
parentcb5b781d528f4046a9c43ec39509061c0fa5ee73 (diff)
downloadmpv-6a04e6e54ce9ebcbab429b92cba1e43ba5e5ad05.tar.bz2
mpv-6a04e6e54ce9ebcbab429b92cba1e43ba5e5ad05.tar.xz
soft video equalizer filter, currently supports brightness and
contrast adjustment for all planar yuv formats git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@7063 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpcodecs')
-rw-r--r--libmpcodecs/Makefile2
-rw-r--r--libmpcodecs/vf.c2
-rw-r--r--libmpcodecs/vf_eq.c154
3 files changed, 157 insertions, 1 deletions
diff --git a/libmpcodecs/Makefile b/libmpcodecs/Makefile
index bc3ff0d596..194f74f6a2 100644
--- a/libmpcodecs/Makefile
+++ b/libmpcodecs/Makefile
@@ -6,7 +6,7 @@ LIBNAME2 = libmpencoders.a
AUDIO_SRCS=dec_audio.c ad.c ad_a52.c ad_acm.c ad_alaw.c ad_dk3adpcm.c ad_dshow.c ad_dvdpcm.c ad_ffmpeg.c ad_hwac3.c ad_imaadpcm.c ad_mp3.c ad_msadpcm.c ad_pcm.c ad_roqaudio.c ad_msgsm.c ad_faad.c ad_vorbis.c ad_libmad.c ad_real.c ad_libdv.c
VIDEO_SRCS=dec_video.c vd.c vd_null.c vd_real.c vd_cinepak.c vd_qtrpza.c vd_ffmpeg.c vd_dshow.c vd_vfw.c vd_odivx.c vd_divx4.c vd_raw.c vd_xanim.c vd_msvidc.c vd_fli.c vd_qtrle.c vd_qtsmc.c vd_roqvideo.c vd_cyuv.c vd_nuv.c vd_libmpeg2.c vd_msrle.c vd_huffyuv.c vd_zlib.c vd_mpegpes.c vd_svq1.c vd_xvid.c vd_libdv.c
-VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c
+VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c vf_eq.c
ENCODER_SRCS=ve.c ve_divx4.c ve_lavc.c ve_vfw.c ve_rawrgb.c ve_libdv.c
NATIVE_SRCS=native/RTjpegN.c native/cinepak.c native/cyuv.c native/fli.c native/minilzo.c native/msvidc.c native/nuppelvideo.c native/qtrle.c native/qtrpza.c native/qtsmc.c native/roqav.c native/xa_gsm.c native/svq1.c
diff --git a/libmpcodecs/vf.c b/libmpcodecs/vf.c
index d00a9ef30b..5cd56cfce9 100644
--- a/libmpcodecs/vf.c
+++ b/libmpcodecs/vf.c
@@ -38,6 +38,7 @@ extern vf_info_t vf_info_test;
extern vf_info_t vf_info_noise;
extern vf_info_t vf_info_yvu9;
extern vf_info_t vf_info_lavcdeint;
+extern vf_info_t vf_info_eq;
char** vo_plugin_args=(char**) NULL;
@@ -69,6 +70,7 @@ static vf_info_t* filter_list[]={
&vf_info_test,
&vf_info_noise,
&vf_info_yvu9,
+ &vf_info_eq,
NULL
};
diff --git a/libmpcodecs/vf_eq.c b/libmpcodecs/vf_eq.c
new file mode 100644
index 0000000000..93fb194c04
--- /dev/null
+++ b/libmpcodecs/vf_eq.c
@@ -0,0 +1,154 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "../config.h"
+#include "../mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "../libvo/video_out.h"
+#include "../libvo/fastmemcpy.h"
+#include "../postproc/rgb2rgb.h"
+
+struct vf_priv_s {
+ unsigned char *buf;
+ int brightness;
+ int contrast;
+};
+
+static void process(unsigned char *dest, int dstride, unsigned char *src, int sstride,
+ int w, int h, int brightness, int contrast)
+{
+ int i;
+ int pel;
+ int dstep = dstride-w;
+ int sstep = sstride-w;
+
+ brightness = ((brightness+100)*511)/200-128;
+ contrast = ((contrast+100)*512)/200;
+
+ while (h--) {
+ for (i = w; i; i--)
+ {
+ /* slow */
+ pel = ((*src++ - 128) * contrast)/256 + brightness;
+ *dest++ = pel > 255 ? 255 : (pel < 0 ? 0 : pel);
+ }
+ src += sstep;
+ dest += dstep;
+ }
+}
+
+/* FIXME: add packed yuv version of process, and optimized code! */
+
+static void put_image(struct vf_instance_s* vf, mp_image_t *mpi)
+{
+ mp_image_t *dmpi;
+
+ dmpi=vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_EXPORT, 0,
+ mpi->w, mpi->h);
+
+ dmpi->stride[0] = mpi->stride[0];
+ dmpi->planes[1] = mpi->planes[1];
+ dmpi->planes[2] = mpi->planes[2];
+ dmpi->stride[1] = mpi->stride[1];
+ dmpi->stride[2] = mpi->stride[2];
+
+ if (!vf->priv->buf) vf->priv->buf = malloc(mpi->stride[0]*mpi->h);
+
+ if ((vf->priv->brightness == 0) && (vf->priv->contrast == 0))
+ dmpi->planes[0] = mpi->planes[0];
+ else {
+ dmpi->planes[0] = vf->priv->buf;
+ process(dmpi->planes[0], dmpi->stride[0],
+ mpi->planes[0], mpi->stride[0],
+ mpi->w, mpi->h, vf->priv->brightness,
+ vf->priv->contrast);
+ }
+
+ vf_next_put_image(vf,dmpi);
+}
+
+static int control(struct vf_instance_s* vf, int request, void* data)
+{
+ vf_equalizer_t *eq;
+
+ switch (request) {
+ case VFCTRL_SET_EQUALIZER:
+ eq = data;
+ if (!strcmp(eq->item,"brightness")) {
+ vf->priv->brightness = eq->value;
+ return CONTROL_TRUE;
+ }
+ else if (!strcmp(eq->item,"contrast")) {
+ vf->priv->contrast = eq->value;
+ return CONTROL_TRUE;
+ }
+ break;
+ case VFCTRL_GET_EQUALIZER:
+ eq = data;
+ if (!strcmp(eq->item,"brightness")) {
+ eq->value = vf->priv->brightness;
+ return CONTROL_TRUE;
+ }
+ else if (!strcmp(eq->item,"contrast")) {
+ eq->value = vf->priv->contrast;
+ return CONTROL_TRUE;
+ }
+ break;
+ }
+ return vf_next_control(vf, request, data);
+}
+
+static int query_format(struct vf_instance_s* vf, unsigned int fmt)
+{
+ switch (fmt) {
+ case IMGFMT_YVU9:
+ case IMGFMT_IF09:
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_CLPL:
+ case IMGFMT_Y800:
+ case IMGFMT_Y8:
+ case IMGFMT_NV12:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static void uninit(struct vf_instance_s* vf)
+{
+ if (vf->priv->buf) free(vf->priv->buf);
+ free(vf->priv);
+}
+
+static int open(vf_instance_t *vf, char* args)
+{
+ vf->control=control;
+ vf->query_format=query_format;
+ vf->put_image=put_image;
+ vf->uninit=uninit;
+
+ vf->priv = malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+ if (args) sscanf(args, "%d:%d", &vf->priv->brightness, &vf->priv->contrast);
+ return 1;
+}
+
+vf_info_t vf_info_eq = {
+ "soft video equalizer",
+ "eq",
+ "Richard Felker",
+ "",
+ open
+};
+