10 #include "img_format.h"
14 #include "libvo/fastmemcpy.h"
15 #include "libswscale/rgb2rgb.h"
22 static void halfpack_MMX(unsigned char *dst
, unsigned char *src
[3],
23 int dststride
, int srcstride
[3],
27 unsigned char *y1
, *y2
, *u
, *v
;
28 int dstinc
, yinc
, uinc
, vinc
;
31 y2
= src
[0] + srcstride
[0];
35 dstinc
= dststride
- 2*w
;
36 yinc
= 2*srcstride
[0] - w
;
37 uinc
= srcstride
[1] - w
/2;
38 vinc
= srcstride
[2] - w
/2;
42 "pxor %%mm0, %%mm0 \n\t"
45 "movq (%0), %%mm1 \n\t"
46 "movq (%0), %%mm2 \n\t"
47 "movq (%1), %%mm3 \n\t"
48 "movq (%1), %%mm4 \n\t"
49 "punpcklbw %%mm0, %%mm1 \n\t"
50 "punpckhbw %%mm0, %%mm2 \n\t"
51 "punpcklbw %%mm0, %%mm3 \n\t"
52 "punpckhbw %%mm0, %%mm4 \n\t"
53 "paddw %%mm3, %%mm1 \n\t"
54 "paddw %%mm4, %%mm2 \n\t"
55 "psrlw $1, %%mm1 \n\t"
56 "psrlw $1, %%mm2 \n\t"
58 "movq (%2), %%mm3 \n\t"
59 "movq (%3), %%mm5 \n\t"
60 "punpcklbw %%mm0, %%mm3 \n\t"
61 "punpcklbw %%mm0, %%mm5 \n\t"
62 "movq %%mm3, %%mm4 \n\t"
63 "movq %%mm5, %%mm6 \n\t"
64 "punpcklwd %%mm0, %%mm3 \n\t"
65 "punpckhwd %%mm0, %%mm4 \n\t"
66 "punpcklwd %%mm0, %%mm5 \n\t"
67 "punpckhwd %%mm0, %%mm6 \n\t"
68 "pslld $8, %%mm3 \n\t"
69 "pslld $8, %%mm4 \n\t"
70 "pslld $24, %%mm5 \n\t"
71 "pslld $24, %%mm6 \n\t"
73 "por %%mm3, %%mm1 \n\t"
74 "por %%mm4, %%mm2 \n\t"
75 "por %%mm5, %%mm1 \n\t"
76 "por %%mm6, %%mm2 \n\t"
82 "movq %%mm1, (%8) \n\t"
83 "movq %%mm2, 8(%8) \n\t"
87 : "=r" (y1
), "=r" (y2
), "=r" (u
), "=r" (v
)
88 : "0" (y1
), "1" (y2
), "2" (u
), "3" (v
), "r" (dst
), "r" (w
/8)
91 for (j
= (w
&7)/2; j
; j
--) {
92 *dst
++ = (*y1
++ + *y2
++)/2;
94 *dst
++ = (*y1
++ + *y2
++)/2;
103 asm volatile ( "emms \n\t" ::: "memory" );
109 static void halfpack_C(unsigned char *dst
, unsigned char *src
[3],
110 int dststride
, int srcstride
[3],
114 unsigned char *y1
, *y2
, *u
, *v
;
115 int dstinc
, yinc
, uinc
, vinc
;
118 y2
= src
[0] + srcstride
[0];
122 dstinc
= dststride
- 2*w
;
123 yinc
= 2*srcstride
[0] - w
;
124 uinc
= srcstride
[1] - w
/2;
125 vinc
= srcstride
[2] - w
/2;
127 for (i
= h
/2; i
; i
--) {
128 for (j
= w
/2; j
; j
--) {
129 *dst
++ = (*y1
++ + *y2
++)>>1;
131 *dst
++ = (*y1
++ + *y2
++)>>1;
142 static void (*halfpack
)(unsigned char *dst
, unsigned char *src
[3],
143 int dststride
, int srcstride
[3], int w
, int h
);
146 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
)
150 // hope we'll get DR buffer:
151 dmpi
=vf_get_image(vf
->next
, IMGFMT_YUY2
,
152 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
155 switch(vf
->priv
->field
) {
158 yuv422ptoyuy2(mpi
->planes
[0] + mpi
->stride
[0]*vf
->priv
->field
,
159 mpi
->planes
[1], mpi
->planes
[2], dmpi
->planes
[0],
160 mpi
->w
, mpi
->h
/2, mpi
->stride
[0]*2, mpi
->stride
[1], dmpi
->stride
[0]);
163 halfpack(dmpi
->planes
[0], mpi
->planes
, dmpi
->stride
[0],
164 mpi
->stride
, mpi
->w
, mpi
->h
);
167 return vf_next_put_image(vf
,dmpi
, pts
);
170 static int config(struct vf_instance_s
* vf
,
171 int width
, int height
, int d_width
, int d_height
,
172 unsigned int flags
, unsigned int outfmt
)
174 /* FIXME - also support UYVY output? */
175 return vf_next_config(vf
, width
, height
/2, d_width
, d_height
, flags
, IMGFMT_YUY2
);
179 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
)
181 /* FIXME - really any YUV 4:2:0 input format should work */
186 return vf_next_query_format(vf
,IMGFMT_YUY2
);
191 static void uninit(struct vf_instance_s
* vf
)
196 static int open(vf_instance_t
*vf
, char* args
)
199 vf
->query_format
=query_format
;
200 vf
->put_image
=put_image
;
203 vf
->priv
= calloc(1, sizeof (struct vf_priv_s
));
205 if (args
) sscanf(args
, "%d", &vf
->priv
->field
);
207 halfpack
= halfpack_C
;
209 if(gCpuCaps
.hasMMX
) halfpack
= halfpack_MMX
;
214 vf_info_t vf_info_halfpack
= {
215 "yuv planar 4:2:0 -> packed 4:2:2, half height",