From 85e02b6d9addbec563d25892c7bb49bb3f5995aa Mon Sep 17 00:00:00 2001 From: arpi Date: Fri, 21 Dec 2001 17:49:31 +0000 Subject: [PATCH] Cinepak YUY2 support git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@3647 b3059339-0415-0410-9bf9-f77b7e298cf2 --- cinepak.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ dec_video.c | 2 +- etc/codecs.conf | 1 + 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/cinepak.c b/cinepak.c index 71c621972c..895f86e2fa 100644 --- a/cinepak.c +++ b/cinepak.c @@ -51,6 +51,88 @@ static unsigned char *in_buffer, uiclip[1024], *uiclp = NULL; (in_buffer[-4] << 24 | in_buffer[-3] << 16 | in_buffer[-2] << 8 | in_buffer[-1]))) +/* ---------------------------------------------------------------------- */ +static inline void read_codebook_yuy2(cvid_codebook *c, int mode) +{ + + if(mode) /* black and white */ + { + c->y0 = get_byte(); + c->y1 = get_byte(); + c->y2 = get_byte(); + c->y3 = get_byte(); + c->u = c->v = 128; + } + else /* colour */ + { + c->y0 = get_byte(); /* luma */ + c->y1 = get_byte(); + c->y2 = get_byte(); + c->y3 = get_byte(); + c->u = 128+get_byte(); /* chroma */ + c->v = 128+get_byte(); + } +} + +//#define PACK_YUV(cb,y0,y1,u,v) ((cb->y0<<24)|(((unsigned char)cb->u)<<16)|(cb->y1<<8)|(((unsigned char)cb->v))) +#define PACK_YUV(cb,y0,y1,u,v) ((((unsigned char)cb->v)<<24)|(cb->y1<<16)|(((unsigned char)cb->u)<<8)|(cb->y0)) + +#define TO_YUY2_U0(cb) PACK_YUV(cb,y0,y0,u,v) +#define TO_YUY2_U1(cb) PACK_YUV(cb,y1,y1,u,v) +#define TO_YUY2_L0(cb) PACK_YUV(cb,y2,y2,u,v) +#define TO_YUY2_L1(cb) PACK_YUV(cb,y3,y3,u,v) + +#define TO_YUY2_U(cb) PACK_YUV(cb,y0,y1,u,v) +#define TO_YUY2_L(cb) PACK_YUV(cb,y2,y3,u,v) + +/* ------------------------------------------------------------------------ */ +inline void cvid_v1_yuy2(unsigned char *frm, unsigned char *end, int stride, cvid_codebook *cb) +{ +unsigned long *vptr = (unsigned long *)frm, rgb; +int row_inc = stride/4; + + vptr[0] = TO_YUY2_U0(cb); + vptr[1] = TO_YUY2_U1(cb); + vptr += row_inc; if(vptr > (unsigned long *)end) return; + + vptr[0] = TO_YUY2_U0(cb); + vptr[1] = TO_YUY2_U1(cb); + vptr += row_inc; if(vptr > (unsigned long *)end) return; + + vptr[0] = TO_YUY2_L0(cb); + vptr[1] = TO_YUY2_L1(cb); + vptr += row_inc; if(vptr > (unsigned long *)end) return; + + vptr[0] = TO_YUY2_L0(cb); + vptr[1] = TO_YUY2_L1(cb); +} + + +/* ------------------------------------------------------------------------ */ +inline void cvid_v4_yuy2(unsigned char *frm, unsigned char *end, int stride, cvid_codebook *cb0, + cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3) +{ +unsigned long *vptr = (unsigned long *)frm; +int row_inc = stride/4; + + vptr[0] = TO_YUY2_U(cb0); + vptr[1] = TO_YUY2_U(cb1); + vptr += row_inc; if(vptr > (unsigned long *)end) return; + + vptr[0] = TO_YUY2_L(cb0); + vptr[1] = TO_YUY2_L(cb1); + vptr += row_inc; if(vptr > (unsigned long *)end) return; + + vptr[0] = TO_YUY2_U(cb2); + vptr[1] = TO_YUY2_U(cb3); + vptr += row_inc; if(vptr > (unsigned long *)end) return; + + vptr[0] = TO_YUY2_L(cb2); + vptr[1] = TO_YUY2_L(cb3); + +} + + /* ---------------------------------------------------------------------- */ static inline void read_codebook_32(cvid_codebook *c, int mode) { @@ -139,6 +221,7 @@ int row_inc = stride/4; } + /* ---------------------------------------------------------------------- */ static inline void read_codebook_24(cvid_codebook *c, int mode) { @@ -294,6 +377,12 @@ void (*cvid_v4)(unsigned char *frm, unsigned char *end, int stride, cvid_codeboo switch(bit_per_pixel) { + case 16: + bpp = 2; + read_codebook = read_codebook_yuy2; + cvid_v1 = cvid_v1_yuy2; + cvid_v4 = cvid_v4_yuy2; + break; case 24: bpp = 3; read_codebook = read_codebook_24; diff --git a/dec_video.c b/dec_video.c index 0d2644e4a5..9050921646 100644 --- a/dec_video.c +++ b/dec_video.c @@ -564,7 +564,7 @@ unsigned int t2; switch(sh_video->codec->driver){ case VFM_CINEPAK: decode_cinepak(sh_video->context, start, in_size, sh_video->our_out_buffer, - sh_video->disp_w, sh_video->disp_h, out_fmt&255); + sh_video->disp_w, sh_video->disp_h, (out_fmt==IMGFMT_YUY2)?16:(out_fmt&255)); blit_frame = 3; break; #ifdef USE_XANIM diff --git a/etc/codecs.conf b/etc/codecs.conf index be16973005..ecba18047b 100644 --- a/etc/codecs.conf +++ b/etc/codecs.conf @@ -266,6 +266,7 @@ videocodec cvid status working fourcc cvid,CVID driver cinepak + out YUY2 out BGR32,BGR24 videocodec msrle