10 #include "img_format.h"
14 #include "libswscale/rgb2rgb.h"
21 static void halfpack_MMX(unsigned char *dst
, unsigned char *src
[3],
22 int dststride
, int srcstride
[3],
26 unsigned char *y1
, *y2
, *u
, *v
;
27 int dstinc
, yinc
, uinc
, vinc
;
30 y2
= src
[0] + srcstride
[0];
34 dstinc
= dststride
- 2*w
;
35 yinc
= 2*srcstride
[0] - w
;
36 uinc
= srcstride
[1] - w
/2;
37 vinc
= srcstride
[2] - w
/2;
41 "pxor %%mm0, %%mm0 \n\t"
44 "movq (%0), %%mm1 \n\t"
45 "movq (%0), %%mm2 \n\t"
46 "movq (%1), %%mm3 \n\t"
47 "movq (%1), %%mm4 \n\t"
48 "punpcklbw %%mm0, %%mm1 \n\t"
49 "punpckhbw %%mm0, %%mm2 \n\t"
50 "punpcklbw %%mm0, %%mm3 \n\t"
51 "punpckhbw %%mm0, %%mm4 \n\t"
52 "paddw %%mm3, %%mm1 \n\t"
53 "paddw %%mm4, %%mm2 \n\t"
54 "psrlw $1, %%mm1 \n\t"
55 "psrlw $1, %%mm2 \n\t"
57 "movq (%2), %%mm3 \n\t"
58 "movq (%3), %%mm5 \n\t"
59 "punpcklbw %%mm0, %%mm3 \n\t"
60 "punpcklbw %%mm0, %%mm5 \n\t"
61 "movq %%mm3, %%mm4 \n\t"
62 "movq %%mm5, %%mm6 \n\t"
63 "punpcklwd %%mm0, %%mm3 \n\t"
64 "punpckhwd %%mm0, %%mm4 \n\t"
65 "punpcklwd %%mm0, %%mm5 \n\t"
66 "punpckhwd %%mm0, %%mm6 \n\t"
67 "pslld $8, %%mm3 \n\t"
68 "pslld $8, %%mm4 \n\t"
69 "pslld $24, %%mm5 \n\t"
70 "pslld $24, %%mm6 \n\t"
72 "por %%mm3, %%mm1 \n\t"
73 "por %%mm4, %%mm2 \n\t"
74 "por %%mm5, %%mm1 \n\t"
75 "por %%mm6, %%mm2 \n\t"
81 "movq %%mm1, (%8) \n\t"
82 "movq %%mm2, 8(%8) \n\t"
86 : "=r" (y1
), "=r" (y2
), "=r" (u
), "=r" (v
)
87 : "0" (y1
), "1" (y2
), "2" (u
), "3" (v
), "r" (dst
), "r" (w
/8)
90 for (j
= (w
&7)/2; j
; j
--) {
91 *dst
++ = (*y1
++ + *y2
++)/2;
93 *dst
++ = (*y1
++ + *y2
++)/2;
102 __asm__
volatile ( "emms \n\t" ::: "memory" );
108 static void halfpack_C(unsigned char *dst
, unsigned char *src
[3],
109 int dststride
, int srcstride
[3],
113 unsigned char *y1
, *y2
, *u
, *v
;
114 int dstinc
, yinc
, uinc
, vinc
;
117 y2
= src
[0] + srcstride
[0];
121 dstinc
= dststride
- 2*w
;
122 yinc
= 2*srcstride
[0] - w
;
123 uinc
= srcstride
[1] - w
/2;
124 vinc
= srcstride
[2] - w
/2;
126 for (i
= h
/2; i
; i
--) {
127 for (j
= w
/2; j
; j
--) {
128 *dst
++ = (*y1
++ + *y2
++)>>1;
130 *dst
++ = (*y1
++ + *y2
++)>>1;
141 static void (*halfpack
)(unsigned char *dst
, unsigned char *src
[3],
142 int dststride
, int srcstride
[3], int w
, int h
);
145 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
)
149 // hope we'll get DR buffer:
150 dmpi
=vf_get_image(vf
->next
, IMGFMT_YUY2
,
151 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
154 switch(vf
->priv
->field
) {
157 yuv422ptoyuy2(mpi
->planes
[0] + mpi
->stride
[0]*vf
->priv
->field
,
158 mpi
->planes
[1], mpi
->planes
[2], dmpi
->planes
[0],
159 mpi
->w
, mpi
->h
/2, mpi
->stride
[0]*2, mpi
->stride
[1], dmpi
->stride
[0]);
162 halfpack(dmpi
->planes
[0], mpi
->planes
, dmpi
->stride
[0],
163 mpi
->stride
, mpi
->w
, mpi
->h
);
166 return vf_next_put_image(vf
,dmpi
, pts
);
169 static int config(struct vf_instance_s
* vf
,
170 int width
, int height
, int d_width
, int d_height
,
171 unsigned int flags
, unsigned int outfmt
)
173 /* FIXME - also support UYVY output? */
174 return vf_next_config(vf
, width
, height
/2, d_width
, d_height
, flags
, IMGFMT_YUY2
);
178 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
)
180 /* FIXME - really any YUV 4:2:0 input format should work */
185 return vf_next_query_format(vf
,IMGFMT_YUY2
);
190 static void uninit(struct vf_instance_s
* vf
)
195 static int open(vf_instance_t
*vf
, char* args
)
198 vf
->query_format
=query_format
;
199 vf
->put_image
=put_image
;
202 vf
->priv
= calloc(1, sizeof (struct vf_priv_s
));
204 if (args
) sscanf(args
, "%d", &vf
->priv
->field
);
206 halfpack
= halfpack_C
;
208 if(gCpuCaps
.hasMMX
) halfpack
= halfpack_MMX
;
213 const vf_info_t vf_info_halfpack
= {
214 "yuv planar 4:2:0 -> packed 4:2:2, half height",