10 #include "img_format.h"
14 #include "libvo/video_out.h"
19 static struct vf_priv_s
{
23 } const vf_priv_dflt
= {
30 static void process_MMX(unsigned char *dest
, int dstride
, unsigned char *src
, int sstride
,
31 int w
, int h
, int brightness
, int contrast
)
35 int dstep
= dstride
-w
;
36 int sstep
= sstride
-w
;
40 contrast
= ((contrast
+100)*256*16)/100;
41 brightness
= ((brightness
+100)*511)/200-128 - contrast
/32;
43 brvec
[0] = brvec
[1] = brvec
[2] = brvec
[3] = brightness
;
44 contvec
[0] = contvec
[1] = contvec
[2] = contvec
[3] = contrast
;
48 "movq (%5), %%mm3 \n\t"
49 "movq (%6), %%mm4 \n\t"
50 "pxor %%mm0, %%mm0 \n\t"
54 "movq (%0), %%mm1 \n\t"
55 "movq (%0), %%mm2 \n\t"
56 "punpcklbw %%mm0, %%mm1 \n\t"
57 "punpckhbw %%mm0, %%mm2 \n\t"
58 "psllw $4, %%mm1 \n\t"
59 "psllw $4, %%mm2 \n\t"
60 "pmulhw %%mm4, %%mm1 \n\t"
61 "pmulhw %%mm4, %%mm2 \n\t"
62 "paddw %%mm3, %%mm1 \n\t"
63 "paddw %%mm3, %%mm2 \n\t"
64 "packuswb %%mm2, %%mm1 \n\t"
66 "movq %%mm1, (%1) \n\t"
70 : "=r" (src
), "=r" (dest
)
71 : "0" (src
), "1" (dest
), "r" (w
>>3), "r" (brvec
), "r" (contvec
)
77 pel
= ((*src
++* contrast
)>>12) + brightness
;
78 if(pel
&768) pel
= (-pel
)>>31;
85 asm volatile ( "emms \n\t" ::: "memory" );
89 static void process_C(unsigned char *dest
, int dstride
, unsigned char *src
, int sstride
,
90 int w
, int h
, int brightness
, int contrast
)
94 int dstep
= dstride
-w
;
95 int sstep
= sstride
-w
;
97 contrast
= ((contrast
+100)*256*256)/100;
98 brightness
= ((brightness
+100)*511)/200-128 - contrast
/512;
103 pel
= ((*src
++* contrast
)>>16) + brightness
;
104 if(pel
&768) pel
= (-pel
)>>31;
112 static void (*process
)(unsigned char *dest
, int dstride
, unsigned char *src
, int sstride
,
113 int w
, int h
, int brightness
, int contrast
);
115 /* FIXME: add packed yuv version of process */
117 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
)
121 dmpi
=vf_get_image(vf
->next
, mpi
->imgfmt
,
122 MP_IMGTYPE_EXPORT
, 0,
125 dmpi
->stride
[0] = mpi
->stride
[0];
126 dmpi
->planes
[1] = mpi
->planes
[1];
127 dmpi
->planes
[2] = mpi
->planes
[2];
128 dmpi
->stride
[1] = mpi
->stride
[1];
129 dmpi
->stride
[2] = mpi
->stride
[2];
131 if (!vf
->priv
->buf
) vf
->priv
->buf
= malloc(mpi
->stride
[0]*mpi
->h
);
133 if ((vf
->priv
->brightness
== 0) && (vf
->priv
->contrast
== 0))
134 dmpi
->planes
[0] = mpi
->planes
[0];
136 dmpi
->planes
[0] = vf
->priv
->buf
;
137 process(dmpi
->planes
[0], dmpi
->stride
[0],
138 mpi
->planes
[0], mpi
->stride
[0],
139 mpi
->w
, mpi
->h
, vf
->priv
->brightness
,
143 return vf_next_put_image(vf
,dmpi
, pts
);
146 static int control(struct vf_instance_s
* vf
, int request
, void* data
)
151 case VFCTRL_SET_EQUALIZER
:
153 if (!strcmp(eq
->item
,"brightness")) {
154 vf
->priv
->brightness
= eq
->value
;
157 else if (!strcmp(eq
->item
,"contrast")) {
158 vf
->priv
->contrast
= eq
->value
;
162 case VFCTRL_GET_EQUALIZER
:
164 if (!strcmp(eq
->item
,"brightness")) {
165 eq
->value
= vf
->priv
->brightness
;
168 else if (!strcmp(eq
->item
,"contrast")) {
169 eq
->value
= vf
->priv
->contrast
;
174 return vf_next_control(vf
, request
, data
);
177 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
)
193 return vf_next_query_format(vf
, fmt
);
198 static void uninit(struct vf_instance_s
* vf
)
200 if (vf
->priv
->buf
) free(vf
->priv
->buf
);
204 static int open(vf_instance_t
*vf
, char* args
)
207 vf
->query_format
=query_format
;
208 vf
->put_image
=put_image
;
212 vf
->priv
= malloc(sizeof(struct vf_priv_s
));
213 memset(vf
->priv
, 0, sizeof(struct vf_priv_s
));
215 if (args
) sscanf(args
, "%d:%d", &vf
->priv
->brightness
, &vf
->priv
->contrast
);
219 if(gCpuCaps
.hasMMX
) process
= process_MMX
;
225 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
226 static m_option_t vf_opts_fields
[] = {
227 {"brightness", ST_OFF(brightness
), CONF_TYPE_INT
, M_OPT_RANGE
,-100 ,100, NULL
},
228 {"contrast", ST_OFF(contrast
), CONF_TYPE_INT
, M_OPT_RANGE
,-100 ,100, NULL
},
229 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
232 static m_struct_t vf_opts
= {
234 sizeof(struct vf_priv_s
),
239 const vf_info_t vf_info_eq
= {
240 "soft video equalizer",