changeset 11249:7fdf58d10719

vf_hue
author michael
date Thu, 23 Oct 2003 18:36:02 +0000
parents 100fc2ca895e
children 3254d102d31a
files libmpcodecs/Makefile libmpcodecs/vf.c libmpcodecs/vf_hue.c
diffstat 3 files changed, 198 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/Makefile	Thu Oct 23 14:26:29 2003 +0000
+++ b/libmpcodecs/Makefile	Thu Oct 23 18:36:02 2003 +0000
@@ -14,7 +14,7 @@
 VIDEO_SRCS_OPT=vd_realvid.c vd_ffmpeg.c vd_dshow.c vd_dmo.c vd_vfw.c vd_vfwex.c vd_odivx.c vd_divx4.c vd_xanim.c vd_xvid.c vd_libdv.c vd_qtvideo.c vd_theora.c
 VIDEO_SRCS=dec_video.c vd.c $(VIDEO_SRCS_NAT) $(VIDEO_SRCS_LIB) $(VIDEO_SRCS_OPT)
 
-VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.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 vf_eq2.c vf_halfpack.c vf_dint.c vf_1bpp.c vf_bmovl.c vf_2xsai.c vf_unsharp.c vf_swapuv.c vf_il.c vf_boxblur.c vf_sab.c vf_smartblur.c vf_perspective.c vf_down3dright.c vf_field.c vf_denoise3d.c vf_hqdn3d.c vf_detc.c vf_telecine.c vf_tfields.c vf_ivtc.c vf_ilpack.c vf_dsize.c vf_decimate.c vf_softpulldown.c vf_tinterlace.c vf_pullup.c pullup.c vf_framestep.c vf_tile.c vf_delogo.c vf_fil.c
+VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.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 vf_eq2.c vf_halfpack.c vf_dint.c vf_1bpp.c vf_bmovl.c vf_2xsai.c vf_unsharp.c vf_swapuv.c vf_il.c vf_boxblur.c vf_sab.c vf_smartblur.c vf_perspective.c vf_down3dright.c vf_field.c vf_denoise3d.c vf_hqdn3d.c vf_detc.c vf_telecine.c vf_tfields.c vf_ivtc.c vf_ilpack.c vf_dsize.c vf_decimate.c vf_softpulldown.c vf_tinterlace.c vf_pullup.c pullup.c vf_framestep.c vf_tile.c vf_delogo.c vf_fil.c vf_hue.c
 ifeq ($(HAVE_FFPOSTPROCESS),yes)
 VFILTER_SRCS += vf_pp.c
 endif
--- a/libmpcodecs/vf.c	Thu Oct 23 14:26:29 2003 +0000
+++ b/libmpcodecs/vf.c	Thu Oct 23 18:36:02 2003 +0000
@@ -78,6 +78,7 @@
 extern vf_info_t vf_info_framestep;
 extern vf_info_t vf_info_tile;
 extern vf_info_t vf_info_delogo;
+extern vf_info_t vf_info_hue;
 
 // list of available filters:
 static vf_info_t* filter_list[]={
@@ -143,6 +144,7 @@
     &vf_info_framestep,
     &vf_info_tile,
     &vf_info_delogo,
+    &vf_info_hue,
     NULL
 };
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpcodecs/vf_hue.c	Thu Oct 23 18:36:02 2003 +0000
@@ -0,0 +1,195 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <math.h>
+
+#include "../config.h"
+#include "../mp_msg.h"
+#include "../cpudetect.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "../libvo/video_out.h"
+
+#include "m_option.h"
+#include "m_struct.h"
+
+static struct vf_priv_s {
+	uint8_t *buf[2];
+	float hue;
+	float saturation;
+} vf_priv_dflt = {
+  {NULL, NULL},
+  0.0,
+  1.0,
+};
+
+static void process_C(uint8_t *udst, uint8_t *vdst, uint8_t *usrc, uint8_t *vsrc, int dststride, int srcstride,
+		    int w, int h, float hue, float sat)
+{
+	int i;
+	const int s= rint(sin(hue) * (1<<16) * sat);
+	const int c= rint(cos(hue) * (1<<16) * sat);
+
+	while (h--) {
+		for (i = 0; i<w; i++)
+		{
+			const int u= usrc[i] - 128;
+			const int v= vsrc[i] - 128;
+			int new_u= (c*u - s*v + (1<<15) + (128<<16))>>16;
+			int new_v= (s*u + c*v + (1<<15) + (128<<16))>>16;
+			if(new_u & 768) new_u= (-new_u)>>31;
+			if(new_v & 768) new_v= (-new_v)>>31;
+			udst[i]= new_u;
+			vdst[i]= new_v;
+		}
+		usrc += srcstride;
+		vsrc += srcstride;
+		udst += dststride;
+		vdst += dststride;
+	}
+}
+
+static void (*process)(uint8_t *udst, uint8_t *vdst, uint8_t *usrc, uint8_t *vsrc, int dststride, int srcstride,
+		    int w, int h, float hue, float sat);
+
+/* FIXME: add packed yuv version of process */
+
+static int 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->planes[0] = mpi->planes[0];
+	dmpi->stride[0] = mpi->stride[0];
+	dmpi->stride[1] = mpi->stride[1];
+	dmpi->stride[2] = mpi->stride[2];
+
+	if (!vf->priv->buf[0]){
+		vf->priv->buf[0] = malloc(mpi->stride[1]*mpi->h >> mpi->chroma_y_shift);
+		vf->priv->buf[1] = malloc(mpi->stride[2]*mpi->h >> mpi->chroma_y_shift);
+	}
+	
+	if (vf->priv->hue == 0){
+		dmpi->planes[1] = mpi->planes[1];
+		dmpi->planes[2] = mpi->planes[2];
+	}else {
+		dmpi->planes[1] = vf->priv->buf[0];
+		dmpi->planes[2] = vf->priv->buf[1];
+		process(dmpi->planes[1], dmpi->planes[2],
+			mpi->planes[1], mpi->planes[2],
+			dmpi->stride[1],mpi->stride[1],
+			mpi->w>> mpi->chroma_x_shift, mpi->h>> mpi->chroma_y_shift, 
+			vf->priv->hue, vf->priv->saturation);
+	}
+
+	return 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,"hue")) {
+			vf->priv->hue = eq->value * M_PI / 100;
+			return CONTROL_TRUE;
+		} else if (!strcmp(eq->item,"saturation")) {
+			vf->priv->saturation = eq->value/100.0 + 100;
+			return CONTROL_TRUE;
+		}
+		break;
+	case VFCTRL_GET_EQUALIZER:
+		eq = data;
+		if (!strcmp(eq->item,"hue")) {
+			eq->value = rint(vf->priv->hue *100 / M_PI);
+			return CONTROL_TRUE;
+		}else if (!strcmp(eq->item,"saturation")) {
+			eq->value = rint(vf->priv->saturation*100 - 100);
+			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[0]) free(vf->priv->buf[0]);
+	if (vf->priv->buf[1]) free(vf->priv->buf[1]);
+	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;
+	
+	if(!vf->priv) {
+	vf->priv = malloc(sizeof(struct vf_priv_s));
+	memset(vf->priv, 0, sizeof(struct vf_priv_s));
+	}
+	if (args) sscanf(args, "%f:%f", &vf->priv->hue, &vf->priv->saturation);
+        vf->priv->hue *= M_PI / 180.0;
+
+	process = process_C;
+#ifdef HAVE_MMXX
+	if(gCpuCaps.hasMMX) process = process_MMX;
+#endif
+	
+	return 1;
+}
+
+#define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
+static m_option_t vf_opts_fields[] = {
+  {"hue", ST_OFF(hue), CONF_TYPE_FLOAT, M_OPT_RANGE,-180.0 ,180.0, NULL},
+  {"saturation", ST_OFF(saturation), CONF_TYPE_FLOAT, M_OPT_RANGE,-10.0 ,10.0, NULL},
+  { NULL, NULL, 0, 0, 0, 0,  NULL }
+};
+
+static m_struct_t vf_opts = {
+  "hue",
+  sizeof(struct vf_priv_s),
+  &vf_priv_dflt,
+  vf_opts_fields
+};
+
+vf_info_t vf_info_hue = {
+	"hue changer",
+	"hue",
+	"Michael Niedermayer",
+	"",
+	open,
+	&vf_opts
+};
+