[MPlayer-dev-eng] [patch] -vop halfpack
D Richard Felker III
dalias at aerifal.cx
Tue Aug 27 06:31:50 CEST 2002
I asked about getting this in CVS again a while back and didn't get
any responses, so I'm posting the actual (updated) code. There's now
some (probably naive) mmx code to make it a bit faster. Should I
commit or leave this out for now? As I wrote a few days ago, there's
currently no way to duplicate this functionality with existing
filters, and it looks like even if some were fixed/improved, it would
still be very slow to do this with -vop yuy2,format=422p,scale.
Rich
-------------- next part --------------
Index: libmpcodecs/Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/Makefile,v
retrieving revision 1.55
diff -u -r1.55 Makefile
--- libmpcodecs/Makefile 22 Aug 2002 23:29:41 -0000 1.55
+++ libmpcodecs/Makefile 27 Aug 2002 04:26:13 -0000
@@ -6,7 +6,7 @@
AUDIO_SRCS=dec_audio.c ad.c ad_a52.c ad_acm.c ad_alaw.c ad_dk3adpcm.c ad_dshow.c ad_dvdpcm.c ad_ffmpeg.c ad_hwac3.c ad_imaadpcm.c ad_mp3.c ad_msadpcm.c ad_pcm.c ad_roqaudio.c ad_msgsm.c ad_faad.c ad_vorbis.c ad_libmad.c ad_real.c ad_libdv.c
VIDEO_SRCS=dec_video.c vd.c vd_null.c vd_real.c vd_cinepak.c vd_qtrpza.c vd_ffmpeg.c vd_dshow.c vd_vfw.c vd_odivx.c vd_divx4.c vd_raw.c vd_xanim.c vd_msvidc.c vd_fli.c vd_qtrle.c vd_qtsmc.c vd_roqvideo.c vd_cyuv.c vd_nuv.c vd_libmpeg2.c vd_msrle.c vd_huffyuv.c vd_zlib.c vd_mpegpes.c vd_svq1.c vd_xvid.c vd_libdv.c
-VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c vf_eq.c
+VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c vf_eq.c vf_halfpack.c
ENCODER_SRCS=ve.c ve_divx4.c ve_lavc.c ve_vfw.c ve_rawrgb.c ve_libdv.c
NATIVE_SRCS=native/RTjpegN.c native/cinepak.c native/cyuv.c native/fli.c native/minilzo.c native/msvidc.c native/nuppelvideo.c native/qtrle.c native/qtrpza.c native/qtsmc.c native/roqav.c native/xa_gsm.c native/svq1.c
Index: libmpcodecs/vf.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vf.c,v
retrieving revision 1.45
diff -u -r1.45 vf.c
--- libmpcodecs/vf.c 21 Aug 2002 23:08:20 -0000 1.45
+++ libmpcodecs/vf.c 27 Aug 2002 04:26:13 -0000
@@ -39,6 +39,7 @@
extern vf_info_t vf_info_yvu9;
extern vf_info_t vf_info_lavcdeint;
extern vf_info_t vf_info_eq;
+extern vf_info_t vf_info_halfpack;
char** vo_plugin_args=(char**) NULL;
@@ -71,6 +72,7 @@
&vf_info_noise,
&vf_info_yvu9,
&vf_info_eq,
+ &vf_info_halfpack,
NULL
};
-------------- next part --------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include "../config.h"
#include "../mp_msg.h"
#include "../cpudetect.h"
#include "img_format.h"
#include "mp_image.h"
#include "vf.h"
#include "../libvo/fastmemcpy.h"
#include "../postproc/rgb2rgb.h"
#ifdef HAVE_MMX
static void halfpack_MMX(unsigned char *dst, unsigned char *src[3],
unsigned int dststride, unsigned int srcstride[3],
int w, int h)
{
int j;
unsigned char *y1, *y2, *u, *v;
unsigned int dstinc, yinc, uinc, vinc;
y1 = src[0];
y2 = src[0] + srcstride[0];
u = src[1];
v = src[2];
dstinc = dststride - 2*w;
yinc = 2*srcstride[0] - w;
uinc = srcstride[1] - w/2;
vinc = srcstride[2] - w/2;
for (h/=2; h; h--) {
asm (
"pxor %%mm0, %%mm0 \n\t"
".align 16 \n\t"
"1: \n\t"
"movq (%0), %%mm1 \n\t"
"movq (%0), %%mm2 \n\t"
"movq (%1), %%mm3 \n\t"
"movq (%1), %%mm4 \n\t"
"punpcklbw %%mm0, %%mm1 \n\t"
"punpckhbw %%mm0, %%mm2 \n\t"
"punpcklbw %%mm0, %%mm3 \n\t"
"punpckhbw %%mm0, %%mm4 \n\t"
"paddw %%mm3, %%mm1 \n\t"
"paddw %%mm4, %%mm2 \n\t"
"psrlw $1, %%mm1 \n\t"
"psrlw $1, %%mm2 \n\t"
"movq (%2), %%mm3 \n\t"
"movq (%3), %%mm5 \n\t"
"punpcklbw %%mm0, %%mm3 \n\t"
"punpcklbw %%mm0, %%mm5 \n\t"
"movq %%mm3, %%mm4 \n\t"
"movq %%mm5, %%mm6 \n\t"
"punpcklwd %%mm0, %%mm3 \n\t"
"punpckhwd %%mm0, %%mm4 \n\t"
"punpcklwd %%mm0, %%mm5 \n\t"
"punpckhwd %%mm0, %%mm6 \n\t"
"pslld $8, %%mm3 \n\t"
"pslld $8, %%mm4 \n\t"
"pslld $24, %%mm5 \n\t"
"pslld $24, %%mm6 \n\t"
"por %%mm3, %%mm1 \n\t"
"por %%mm4, %%mm2 \n\t"
"por %%mm5, %%mm1 \n\t"
"por %%mm6, %%mm2 \n\t"
"addl $8, %0 \n\t"
"addl $8, %1 \n\t"
"addl $4, %2 \n\t"
"addl $4, %3 \n\t"
"movq %%mm1, (%8) \n\t"
"movq %%mm2, 8(%8) \n\t"
"addl $16, %8 \n\t"
"decl %9 \n\t"
"jnz 1b \n\t"
: "=r" (y1), "=r" (y2), "=r" (u), "=r" (v)
: "0" (y1), "1" (y2), "2" (u), "3" (v), "r" (dst), "r" (w/8)
: "memory"
);
for (j = (w&7)/2; j; j--) {
*dst++ = (*y1++ + *y2++)/2;
*dst++ = *u++;
*dst++ = (*y1++ + *y2++)/2;
*dst++ = *v++;
}
y1 += yinc;
y2 += yinc;
u += uinc;
v += vinc;
dst += dstinc;
}
asm volatile ( "emms \n\t" ::: "memory" );
}
#endif
static void halfpack_C(unsigned char *dst, unsigned char *src[3],
unsigned int dststride, unsigned int srcstride[3],
int w, int h)
{
int i, j;
unsigned char *y1, *y2, *u, *v;
unsigned int dstinc, yinc, uinc, vinc;
y1 = src[0];
y2 = src[0] + srcstride[0];
u = src[1];
v = src[2];
dstinc = dststride - 2*w;
yinc = 2*srcstride[0] - w;
uinc = srcstride[1] - w/2;
vinc = srcstride[2] - w/2;
for (i = h/2; i; i--) {
for (j = w/2; j; j--) {
*dst++ = (*y1++ + *y2++)>>1;
*dst++ = *u++;
*dst++ = (*y1++ + *y2++)>>1;
*dst++ = *v++;
}
y1 += yinc;
y2 += yinc;
u += uinc;
v += vinc;
dst += dstinc;
}
}
static void (*halfpack)(unsigned char *dst, unsigned char *src[3],
unsigned int dststride, unsigned int srcstride[3], int w, int h);
static void put_image(struct vf_instance_s* vf, mp_image_t *mpi)
{
mp_image_t *dmpi;
// hope we'll get DR buffer:
dmpi=vf_get_image(vf->next, IMGFMT_YUY2,
MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
mpi->w, mpi->h/2);
halfpack(dmpi->planes[0], mpi->planes,
dmpi->stride[0], mpi->stride,
mpi->w, mpi->h);
vf_next_put_image(vf,dmpi);
}
static int config(struct vf_instance_s* vf,
int width, int height, int d_width, int d_height,
unsigned int flags, unsigned int outfmt)
{
/* FIXME - also support UYVY output? */
return vf_next_config(vf, width, height/2, d_width, d_height, flags, IMGFMT_YUY2);
}
static int query_format(struct vf_instance_s* vf, unsigned int fmt)
{
/* FIXME - really any YUV 4:2:0 input format should work */
switch (fmt) {
case IMGFMT_YV12:
case IMGFMT_IYUV:
case IMGFMT_I420:
return vf_next_query_format(vf,IMGFMT_YUY2);
}
return 0;
}
static int open(vf_instance_t *vf, char* args)
{
vf->config=config;
vf->query_format=query_format;
vf->put_image=put_image;
halfpack = halfpack_C;
#ifdef HAVE_MMX
if(gCpuCaps.hasMMX) halfpack = halfpack_MMX;
#endif
return 1;
}
vf_info_t vf_info_halfpack = {
"yuv planar 4:2:0 -> packed 4:2:2, half height",
"halfpack",
"Richard Felker",
"",
open
};
More information about the MPlayer-dev-eng
mailing list