11 #include "img_format.h"
15 #include "libvo/video_out.h"
16 #include "libvo/fastmemcpy.h"
17 #include "postproc/rgb2rgb.h"
22 static struct vf_priv_s
{
33 static void process_MMX(unsigned char *dest
, int dstride
, unsigned char *src
, int sstride
,
34 int w
, int h
, int brightness
, int contrast
)
38 int dstep
= dstride
-w
;
39 int sstep
= sstride
-w
;
43 contrast
= ((contrast
+100)*256*16)/100;
44 brightness
= ((brightness
+100)*511)/200-128 - contrast
/32;
46 brvec
[0] = brvec
[1] = brvec
[2] = brvec
[3] = brightness
;
47 contvec
[0] = contvec
[1] = contvec
[2] = contvec
[3] = contrast
;
51 "movq (%5), %%mm3 \n\t"
52 "movq (%6), %%mm4 \n\t"
53 "pxor %%mm0, %%mm0 \n\t"
57 "movq (%0), %%mm1 \n\t"
58 "movq (%0), %%mm2 \n\t"
59 "punpcklbw %%mm0, %%mm1 \n\t"
60 "punpckhbw %%mm0, %%mm2 \n\t"
61 "psllw $4, %%mm1 \n\t"
62 "psllw $4, %%mm2 \n\t"
63 "pmulhw %%mm4, %%mm1 \n\t"
64 "pmulhw %%mm4, %%mm2 \n\t"
65 "paddw %%mm3, %%mm1 \n\t"
66 "paddw %%mm3, %%mm2 \n\t"
67 "packuswb %%mm2, %%mm1 \n\t"
69 "movq %%mm1, (%1) \n\t"
73 : "=r" (src
), "=r" (dest
)
74 : "0" (src
), "1" (dest
), "r" (w
>>3), "r" (brvec
), "r" (contvec
)
80 pel
= ((*src
++* contrast
)>>12) + brightness
;
81 if(pel
&768) pel
= (-pel
)>>31;
88 asm volatile ( "emms \n\t" ::: "memory" );
92 static void process_C(unsigned char *dest
, int dstride
, unsigned char *src
, int sstride
,
93 int w
, int h
, int brightness
, int contrast
)
97 int dstep
= dstride
-w
;
98 int sstep
= sstride
-w
;
100 contrast
= ((contrast
+100)*256*256)/100;
101 brightness
= ((brightness
+100)*511)/200-128 - contrast
/512;
106 pel
= ((*src
++* contrast
)>>16) + brightness
;
107 if(pel
&768) pel
= (-pel
)>>31;
115 static void (*process
)(unsigned char *dest
, int dstride
, unsigned char *src
, int sstride
,
116 int w
, int h
, int brightness
, int contrast
);
118 /* FIXME: add packed yuv version of process */
120 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
)
124 dmpi
=vf_get_image(vf
->next
, mpi
->imgfmt
,
125 MP_IMGTYPE_EXPORT
, 0,
128 dmpi
->stride
[0] = mpi
->stride
[0];
129 dmpi
->planes
[1] = mpi
->planes
[1];
130 dmpi
->planes
[2] = mpi
->planes
[2];
131 dmpi
->stride
[1] = mpi
->stride
[1];
132 dmpi
->stride
[2] = mpi
->stride
[2];
134 if (!vf
->priv
->buf
) vf
->priv
->buf
= malloc(mpi
->stride
[0]*mpi
->h
);
136 if ((vf
->priv
->brightness
== 0) && (vf
->priv
->contrast
== 0))
137 dmpi
->planes
[0] = mpi
->planes
[0];
139 dmpi
->planes
[0] = vf
->priv
->buf
;
140 process(dmpi
->planes
[0], dmpi
->stride
[0],
141 mpi
->planes
[0], mpi
->stride
[0],
142 mpi
->w
, mpi
->h
, vf
->priv
->brightness
,
146 return vf_next_put_image(vf
,dmpi
, pts
);
149 static int control(struct vf_instance_s
* vf
, int request
, void* data
)
154 case VFCTRL_SET_EQUALIZER
:
156 if (!strcmp(eq
->item
,"brightness")) {
157 vf
->priv
->brightness
= eq
->value
;
160 else if (!strcmp(eq
->item
,"contrast")) {
161 vf
->priv
->contrast
= eq
->value
;
165 case VFCTRL_GET_EQUALIZER
:
167 if (!strcmp(eq
->item
,"brightness")) {
168 eq
->value
= vf
->priv
->brightness
;
171 else if (!strcmp(eq
->item
,"contrast")) {
172 eq
->value
= vf
->priv
->contrast
;
177 return vf_next_control(vf
, request
, data
);
180 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
)
196 return vf_next_query_format(vf
, fmt
);
201 static void uninit(struct vf_instance_s
* vf
)
203 if (vf
->priv
->buf
) free(vf
->priv
->buf
);
207 static int open(vf_instance_t
*vf
, char* args
)
210 vf
->query_format
=query_format
;
211 vf
->put_image
=put_image
;
215 vf
->priv
= malloc(sizeof(struct vf_priv_s
));
216 memset(vf
->priv
, 0, sizeof(struct vf_priv_s
));
218 if (args
) sscanf(args
, "%d:%d", &vf
->priv
->brightness
, &vf
->priv
->contrast
);
222 if(gCpuCaps
.hasMMX
) process
= process_MMX
;
228 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
229 static m_option_t vf_opts_fields
[] = {
230 {"brightness", ST_OFF(brightness
), CONF_TYPE_INT
, M_OPT_RANGE
,-100 ,100, NULL
},
231 {"contrast", ST_OFF(contrast
), CONF_TYPE_INT
, M_OPT_RANGE
,-100 ,100, NULL
},
232 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
235 static m_struct_t vf_opts
= {
237 sizeof(struct vf_priv_s
),
242 vf_info_t vf_info_eq
= {
243 "soft video equalizer",