2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "cpudetect.h"
28 #include "img_format.h"
32 #include "libvo/video_out.h"
34 static struct vf_priv_s {
41 static void process_MMX(unsigned char *dest, int dstride, unsigned char *src, int sstride,
42 int w, int h, int brightness, int contrast)
46 int dstep = dstride-w;
47 int sstep = sstride-w;
51 contrast = ((contrast+100)*256*16)/100;
52 brightness = ((brightness+100)*511)/200-128 - contrast/32;
54 brvec[0] = brvec[1] = brvec[2] = brvec[3] = brightness;
55 contvec[0] = contvec[1] = contvec[2] = contvec[3] = contrast;
59 "movq (%5), %%mm3 \n\t"
60 "movq (%6), %%mm4 \n\t"
61 "pxor %%mm0, %%mm0 \n\t"
65 "movq (%0), %%mm1 \n\t"
66 "movq (%0), %%mm2 \n\t"
67 "punpcklbw %%mm0, %%mm1 \n\t"
68 "punpckhbw %%mm0, %%mm2 \n\t"
69 "psllw $4, %%mm1 \n\t"
70 "psllw $4, %%mm2 \n\t"
71 "pmulhw %%mm4, %%mm1 \n\t"
72 "pmulhw %%mm4, %%mm2 \n\t"
73 "paddw %%mm3, %%mm1 \n\t"
74 "paddw %%mm3, %%mm2 \n\t"
75 "packuswb %%mm2, %%mm1 \n\t"
77 "movq %%mm1, (%1) \n\t"
81 : "=r" (src), "=r" (dest)
82 : "0" (src), "1" (dest), "r" (w>>3), "r" (brvec), "r" (contvec)
88 pel = ((*src++* contrast)>>12) + brightness;
89 if(pel&768) pel = (-pel)>>31;
96 __asm__ volatile ( "emms \n\t" ::: "memory" );
100 static void process_C(unsigned char *dest, int dstride, unsigned char *src, int sstride,
101 int w, int h, int brightness, int contrast)
105 int dstep = dstride-w;
106 int sstep = sstride-w;
108 contrast = ((contrast+100)*256*256)/100;
109 brightness = ((brightness+100)*511)/200-128 - contrast/512;
114 pel = ((*src++* contrast)>>16) + brightness;
115 if(pel&768) pel = (-pel)>>31;
123 static void (*process)(unsigned char *dest, int dstride, unsigned char *src, int sstride,
124 int w, int h, int brightness, int contrast);
126 /* FIXME: add packed yuv version of process */
128 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
132 dmpi=vf_get_image(vf->next, mpi->imgfmt,
133 MP_IMGTYPE_EXPORT, 0,
136 dmpi->stride[0] = mpi->stride[0];
137 dmpi->planes[1] = mpi->planes[1];
138 dmpi->planes[2] = mpi->planes[2];
139 dmpi->stride[1] = mpi->stride[1];
140 dmpi->stride[2] = mpi->stride[2];
142 if (!vf->priv->buf) vf->priv->buf = malloc(mpi->stride[0]*mpi->h);
144 if ((vf->priv->brightness == 0) && (vf->priv->contrast == 0))
145 dmpi->planes[0] = mpi->planes[0];
147 dmpi->planes[0] = vf->priv->buf;
148 process(dmpi->planes[0], dmpi->stride[0],
149 mpi->planes[0], mpi->stride[0],
150 mpi->w, mpi->h, vf->priv->brightness,
154 return vf_next_put_image(vf,dmpi, pts);
157 static int control(struct vf_instance *vf, int request, void* data)
162 case VFCTRL_SET_EQUALIZER:
164 if (!strcmp(eq->item,"brightness")) {
165 vf->priv->brightness = eq->value;
168 else if (!strcmp(eq->item,"contrast")) {
169 vf->priv->contrast = eq->value;
173 case VFCTRL_GET_EQUALIZER:
175 if (!strcmp(eq->item,"brightness")) {
176 eq->value = vf->priv->brightness;
179 else if (!strcmp(eq->item,"contrast")) {
180 eq->value = vf->priv->contrast;
185 return vf_next_control(vf, request, data);
188 static int query_format(struct vf_instance *vf, unsigned int fmt)
204 return vf_next_query_format(vf, fmt);
209 static void uninit(struct vf_instance *vf)
215 static int vf_open(vf_instance_t *vf, char *args)
218 vf->query_format=query_format;
219 vf->put_image=put_image;
222 vf->priv = malloc(sizeof(struct vf_priv_s));
223 memset(vf->priv, 0, sizeof(struct vf_priv_s));
224 if (args) sscanf(args, "%d:%d", &vf->priv->brightness, &vf->priv->contrast);
228 if(gCpuCaps.hasMMX) process = process_MMX;
234 const vf_info_t vf_info_eq = {
235 "soft video equalizer",