vd_xanim.c

来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 823 行 · 第 1/2 页

C
823
字号
/*  XAnim Video Codec DLL support  It partly emulates the Xanim codebase.  You need the -rdynamic flag to use this with gcc.  (C) 2001-2002 Alex Beregszaszi            and Arpad Gereoffy <arpi@thot.banki.hu>*/#include <uclib.h>#include <uclib.h>#include <uclib.h> /* strerror */#include "config.h"#include "mp_msg.h"#include "vd_internal.h"static vd_info_t info = {	"XAnim codecs",	"xanim",	"A'rpi & Alex",	"Xanim (http://xanim.va.pubnix.com/)",	"binary codec plugins"};LIBVD_EXTERN(xanim)#ifdef __FreeBSD__#include <uclib.h>#endif#include <dlfcn.h> /* dlsym, dlopen, dlclose */#include <stdarg.h> /* va_alist, va_start, va_end */#include <errno.h> /* strerror, errno */#include "mp_msg.h"#include "bswap.h"#include "osdep/timer.h"#if 0/* this should be removed */#ifndef RTLD_NOW#define RLTD_NOW 2#endif#ifndef RTLD_LAZY#define RLTD_LAZY 1#endif#ifndef RTLD_GLOBAL#define RLTD_GLOBAL 256#endif#endiftypedef struct{  unsigned int		what;  unsigned int		id;  int			(*iq_func)();	/* init/query function */  unsigned int		(*dec_func)();  /* opt decode function */} XAVID_FUNC_HDR;#define XAVID_WHAT_NO_MORE	0x0000#define XAVID_AVI_QUERY		0x0001#define XAVID_QT_QUERY		0x0002#define XAVID_DEC_FUNC		0x0100#define XAVID_API_REV		0x0003typedef struct{  unsigned int		api_rev;  char			*desc;  char			*rev;  char			*copyright;  char			*mod_author;  char			*authors;  unsigned int		num_funcs;  XAVID_FUNC_HDR	*funcs;} XAVID_MOD_HDR;/* XA CODEC .. */typedef struct{  void			*anim_hdr;  unsigned int		compression;  unsigned int		x, y;  unsigned int		depth;  void			*extra;  unsigned int		xapi_rev;  unsigned int		(*decoder)();  char			*description;  unsigned int		avi_ctab_flag;  unsigned int		(*avi_read_ext)();} XA_CODEC_HDR;#define CODEC_SUPPORTED 1#define CODEC_UNKNOWN 0#define CODEC_UNSUPPORTED -1/* fuckin colormap structures for xanim */typedef struct{  unsigned short	red;  unsigned short	green;  unsigned short	blue;  unsigned short	gray;} ColorReg;typedef struct XA_ACTION_STRUCT{  int			type;  int			cmap_rev;  unsigned char		*data;  struct XA_ACTION_STRUCT *next;  struct XA_CHDR_STRUCT	*chdr;  ColorReg		*h_cmap;  unsigned int		*map;  struct XA_ACTION_STRUCT *next_same_chdr;} XA_ACTION;typedef struct XA_CHDR_STRUCT{  unsigned int		rev;  ColorReg		*cmap;  unsigned int		csize, coff;  unsigned int		*map;  unsigned int		msize, moff;  struct XA_CHDR_STRUCT	*next;  XA_ACTION		*acts;  struct XA_CHDR_STRUCT	*new_chdr;} XA_CHDR;typedef struct{  unsigned int		cmd;  unsigned int		skip_flag;  unsigned int		imagex, imagey;	/* image buffer size */  unsigned int		imaged;		/* image depth */  XA_CHDR		*chdr;		/* color map header */  unsigned int		map_flag;  unsigned int		*map;  unsigned int		xs, ys;  unsigned int		xe, ye;  unsigned int		special;  void			*extra;} XA_DEC_INFO;typedef struct{    unsigned int	file_num;    unsigned int	anim_type;    unsigned int	imagex;    unsigned int	imagey;    unsigned int	imagec;    unsigned int	imaged;} XA_ANIM_HDR;typedef struct {    XA_DEC_INFO *decinfo;    void *file_handler;    long (*iq_func)(XA_CODEC_HDR *codec_hdr);    unsigned int (*dec_func)(unsigned char *image, unsigned char *delta,	unsigned int dsize, XA_DEC_INFO *dec_info);    mp_image_t *mpi;} vd_xanim_ctx;#if 0typedef char xaBYTE;typedef short xaSHORT;typedef int xaLONG;typedef unsigned char xaUBYTE;typedef unsigned short xaUSHORT;typedef unsigned int xaULONG;#endif#define xaFALSE 0#define xaTRUE 1#define ACT_DLTA_NORM	0x00000000#define ACT_DLTA_BODY	0x00000001#define ACT_DLTA_XOR	0x00000002#define ACT_DLTA_NOP	0x00000004#define ACT_DLTA_MAPD	0x00000008#define ACT_DLTA_DROP	0x00000010#define ACT_DLTA_BAD	0x80000000#define XA_CLOSE_FUNCS 5int xa_close_funcs = 0;void *xa_close_func[XA_CLOSE_FUNCS];/* load, init and query */static int xacodec_load(sh_video_t *sh, char *filename){    vd_xanim_ctx *priv = sh->context;    void *(*what_the)();    char *error;    XAVID_MOD_HDR *mod_hdr;    XAVID_FUNC_HDR *func;    int i;//    priv->file_handler = dlopen(filename, RTLD_NOW|RTLD_GLOBAL);    priv->file_handler = dlopen(filename, RTLD_LAZY);    if (!priv->file_handler)    {	error = dlerror();	if (error)	    mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: failed to dlopen %s while %s\n", filename, error);	else	    mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: failed to dlopen %s\n", filename);	return(0);    }    what_the = dlsym(priv->file_handler, "What_The");    if ((error = dlerror()) != NULL)    {	mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: failed to init %s while %s\n", filename, error);	dlclose(priv->file_handler);	return(0);    }	    mod_hdr = what_the();    if (!mod_hdr)    {	mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: initializer function failed in %s\n", filename);	dlclose(priv->file_handler);	return(0);    }        mp_msg(MSGT_DECVIDEO, MSGL_V, "=== XAnim Codec ===\n");    mp_msg(MSGT_DECVIDEO, MSGL_V, " Filename: %s (API revision: %x)\n", filename, mod_hdr->api_rev);    mp_msg(MSGT_DECVIDEO, MSGL_V, " Codec: %s. Rev: %s\n", mod_hdr->desc, mod_hdr->rev);    if (mod_hdr->copyright)	mp_msg(MSGT_DECVIDEO, MSGL_V, " %s\n", mod_hdr->copyright);    if (mod_hdr->mod_author)	mp_msg(MSGT_DECVIDEO, MSGL_V, " Module Author(s): %s\n", mod_hdr->mod_author);    if (mod_hdr->authors)	mp_msg(MSGT_DECVIDEO, MSGL_V, " Codec Author(s): %s\n", mod_hdr->authors);    if (mod_hdr->api_rev > XAVID_API_REV)    {	mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: not supported api revision (%d) in %s\n",	    mod_hdr->api_rev, filename);	dlclose(priv->file_handler);	return(0);    }    func = mod_hdr->funcs;    if (!func)    {	mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: function table error in %s\n", filename);	dlclose(priv->file_handler);	return(0);    }        mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "Exported functions by codec: [functable: %p entries: %d]\n",	mod_hdr->funcs, mod_hdr->num_funcs);    for (i = 0; i < (int)mod_hdr->num_funcs; i++)    {	mp_msg(MSGT_DECVIDEO, MSGL_DBG2, " %d: %d %d [iq:%p d:%p]\n",		i, func[i].what, func[i].id, func[i].iq_func, func[i].dec_func);	if (func[i].what & XAVID_AVI_QUERY)	{	    mp_msg(MSGT_DECVIDEO, MSGL_DBG2, " %p: avi init/query func (id: %d)\n",		func[i].iq_func, func[i].id);	    priv->iq_func = (void *)func[i].iq_func;	}	if (func[i].what & XAVID_QT_QUERY)	{	    mp_msg(MSGT_DECVIDEO, MSGL_DBG2, " %p: qt init/query func (id: %d)\n",		func[i].iq_func, func[i].id);	    priv->iq_func = (void *)func[i].iq_func;	}	if (func[i].what & XAVID_DEC_FUNC)	{	    mp_msg(MSGT_DECVIDEO, MSGL_DBG2, " %p: decoder func (init/query: %p) (id: %d)\n",		func[i].dec_func, func[i].iq_func, func[i].id);	    priv->dec_func = (void *)func[i].dec_func;	}    }    return(1);}static int xacodec_query(sh_video_t *sh, XA_CODEC_HDR *codec_hdr){    vd_xanim_ctx *priv = sh->context;    long ret;#if 0    /* the brute one */    if (priv->dec_func)    {	codec_hdr->decoder = priv->dec_func;	mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "We got decoder's address at init! %p\n", codec_hdr->decoder);	return(1);    }#endif    ret = priv->iq_func(codec_hdr);    switch(ret)    {	case CODEC_SUPPORTED:	    priv->dec_func = (void *)codec_hdr->decoder;	    mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "Codec is supported: found decoder for %s at %p\n",		codec_hdr->description, codec_hdr->decoder);	    return(1);	case CODEC_UNSUPPORTED:	    mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "Codec (%s) is unsupported by dll\n",		codec_hdr->description);	    return(0);	case CODEC_UNKNOWN:	default:	    mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "Codec (%s) is unknown by dll\n",		codec_hdr->description);	    return(0);    }}void XA_Print(char *fmt, ...){    va_list vallist;    char buf[1024];    va_start(vallist, fmt);    vsnprintf(buf, 1024, fmt, vallist);    mp_msg(MSGT_XACODEC, MSGL_DBG2, "[xacodec] %s\n", buf);    va_end(vallist);    return;}/* 0 is no debug (needed by 3ivX) */long xa_debug = 0;void TheEnd1(char *err_mess){    XA_Print("error: %s - exiting\n", err_mess);    /* we should exit here... */    return;}void XA_Add_Func_To_Free_Chain(XA_ANIM_HDR *anim_hdr, void (*function)()){//    XA_Print("XA_Add_Func_To_Free_Chain('anim_hdr: %08x', 'function: %08x')",//	    anim_hdr, function);    xa_close_func[xa_close_funcs] = function;    if (xa_close_funcs+1 < XA_CLOSE_FUNCS)	xa_close_funcs++;    return;}unsigned long XA_Time_Read(void){    return GetTimer(); //(GetRelativeTime());}void XA_dummy(void){    XA_Print("dummy() called");}void XA_Gen_YUV_Tabs(XA_ANIM_HDR *anim_hdr){    XA_Print("XA_Gen_YUV_Tabs('anim_hdr: %08x')", anim_hdr);    return;}void JPG_Setup_Samp_Limit_Table(XA_ANIM_HDR *anim_hdr){    XA_Print("JPG_Setup_Samp_Limit_Table('anim_hdr: %08x')", anim_hdr);    return;}void JPG_Alloc_MCU_Bufs(XA_ANIM_HDR *anim_hdr, unsigned int width,	unsigned int height, unsigned int full_flag){    XA_Print("JPG_Alloc_MCU_Bufs('anim_hdr: %08x', 'width: %d', 'height: %d', 'full_flag: %d')",	    anim_hdr, width, height, full_flag);    return;}/* ---------------  4x4 pixel YUV block fillers [CVID] ----------------- */typedef struct{    unsigned char r0, g0, b0;    unsigned char r1, g1, b1;    unsigned char r2, g2, b2;    unsigned char r3, g3, b3;    unsigned int clr0_0, clr0_1, clr0_2, clr0_3;    unsigned int clr1_0, clr1_1, clr1_2, clr1_3;    unsigned int clr2_0, clr2_1, clr2_2, clr2_3;    unsigned int clr3_0, clr3_1, clr3_2, clr3_3;} XA_2x2_Color;#define SET_4_YUV_PIXELS(image,x,y,cmap2x2) \    image->planes[0][((x)+0)+((y)+0)*image->stride[0]]=cmap2x2->clr0_0;\    image->planes[0][((x)+1)+((y)+0)*image->stride[0]]=cmap2x2->clr0_1;\    image->planes[0][((x)+0)+((y)+1)*image->stride[0]]=cmap2x2->clr0_2;\    image->planes[0][((x)+1)+((y)+1)*image->stride[0]]=cmap2x2->clr0_3;\    image->planes[1][((x)>>1)+((y)>>1)*image->stride[1]]=cmap2x2->clr1_0;\    image->planes[2][((x)>>1)+((y)>>1)*image->stride[2]]=cmap2x2->clr1_1;void XA_2x2_OUT_1BLK_Convert(unsigned char *image_p, unsigned int x, unsigned int y,    unsigned int imagex, XA_2x2_Color *cmap2x2){

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?