typo fixes
[mplayer/greg.git] / libmpcodecs / vd_xanim.c
blob54acdcbd938415b0cf81507ec856d53c743a06a4
1 /*
2 XAnim Video Codec DLL support
4 It partly emulates the Xanim codebase.
5 You need the -rdynamic flag to use this with gcc.
7 (C) 2001-2002 Alex Beregszaszi
8 and Arpad Gereoffy <arpi@thot.banki.hu>
9 */
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h> /* strerror */
15 #include "config.h"
17 #ifdef USE_XANIM
18 #include "mp_msg.h"
20 #include "vd_internal.h"
22 static vd_info_t info = {
23 "XAnim codecs",
24 "xanim",
25 "A'rpi & Alex",
26 "Xanim (http://xanim.va.pubnix.com/)",
27 "binary codec plugins"
30 LIBVD_EXTERN(xanim)
32 #ifdef __FreeBSD__
33 #include <unistd.h>
34 #endif
36 #include <dlfcn.h> /* dlsym, dlopen, dlclose */
37 #include <stdarg.h> /* va_alist, va_start, va_end */
38 #include <errno.h> /* strerror, errno */
40 #include "mp_msg.h"
41 #include "bswap.h"
43 #include "osdep/timer.h"
44 #include "libvo/fastmemcpy.h"
46 #if 0
47 /* this should be removed */
48 #ifndef RTLD_NOW
49 #define RLTD_NOW 2
50 #endif
51 #ifndef RTLD_LAZY
52 #define RLTD_LAZY 1
53 #endif
54 #ifndef RTLD_GLOBAL
55 #define RLTD_GLOBAL 256
56 #endif
57 #endif
59 typedef struct
61 unsigned int what;
62 unsigned int id;
63 int (*iq_func)(); /* init/query function */
64 unsigned int (*dec_func)(); /* opt decode function */
65 } XAVID_FUNC_HDR;
67 #define XAVID_WHAT_NO_MORE 0x0000
68 #define XAVID_AVI_QUERY 0x0001
69 #define XAVID_QT_QUERY 0x0002
70 #define XAVID_DEC_FUNC 0x0100
72 #define XAVID_API_REV 0x0003
74 typedef struct
76 unsigned int api_rev;
77 char *desc;
78 char *rev;
79 char *copyright;
80 char *mod_author;
81 char *authors;
82 unsigned int num_funcs;
83 XAVID_FUNC_HDR *funcs;
84 } XAVID_MOD_HDR;
86 /* XA CODEC .. */
87 typedef struct
89 void *anim_hdr;
90 unsigned int compression;
91 unsigned int x, y;
92 unsigned int depth;
93 void *extra;
94 unsigned int xapi_rev;
95 unsigned int (*decoder)();
96 char *description;
97 unsigned int avi_ctab_flag;
98 unsigned int (*avi_read_ext)();
99 } XA_CODEC_HDR;
101 #define CODEC_SUPPORTED 1
102 #define CODEC_UNKNOWN 0
103 #define CODEC_UNSUPPORTED -1
105 /* fuckin colormap structures for xanim */
106 typedef struct
108 unsigned short red;
109 unsigned short green;
110 unsigned short blue;
111 unsigned short gray;
112 } ColorReg;
114 typedef struct XA_ACTION_STRUCT
116 int type;
117 int cmap_rev;
118 unsigned char *data;
119 struct XA_ACTION_STRUCT *next;
120 struct XA_CHDR_STRUCT *chdr;
121 ColorReg *h_cmap;
122 unsigned int *map;
123 struct XA_ACTION_STRUCT *next_same_chdr;
124 } XA_ACTION;
126 typedef struct XA_CHDR_STRUCT
128 unsigned int rev;
129 ColorReg *cmap;
130 unsigned int csize, coff;
131 unsigned int *map;
132 unsigned int msize, moff;
133 struct XA_CHDR_STRUCT *next;
134 XA_ACTION *acts;
135 struct XA_CHDR_STRUCT *new_chdr;
136 } XA_CHDR;
138 typedef struct
140 unsigned int cmd;
141 unsigned int skip_flag;
142 unsigned int imagex, imagey; /* image buffer size */
143 unsigned int imaged; /* image depth */
144 XA_CHDR *chdr; /* color map header */
145 unsigned int map_flag;
146 unsigned int *map;
147 unsigned int xs, ys;
148 unsigned int xe, ye;
149 unsigned int special;
150 void *extra;
151 } XA_DEC_INFO;
153 typedef struct
155 unsigned int file_num;
156 unsigned int anim_type;
157 unsigned int imagex;
158 unsigned int imagey;
159 unsigned int imagec;
160 unsigned int imaged;
161 } XA_ANIM_HDR;
163 typedef struct {
164 XA_DEC_INFO *decinfo;
165 void *file_handler;
166 long (*iq_func)(XA_CODEC_HDR *codec_hdr);
167 unsigned int (*dec_func)(unsigned char *image, unsigned char *delta,
168 unsigned int dsize, XA_DEC_INFO *dec_info);
169 mp_image_t *mpi;
170 } vd_xanim_ctx;
172 #if 0
173 typedef char xaBYTE;
174 typedef short xaSHORT;
175 typedef int xaLONG;
177 typedef unsigned char xaUBYTE;
178 typedef unsigned short xaUSHORT;
179 typedef unsigned int xaULONG;
180 #endif
182 #define xaFALSE 0
183 #define xaTRUE 1
185 #define ACT_DLTA_NORM 0x00000000
186 #define ACT_DLTA_BODY 0x00000001
187 #define ACT_DLTA_XOR 0x00000002
188 #define ACT_DLTA_NOP 0x00000004
189 #define ACT_DLTA_MAPD 0x00000008
190 #define ACT_DLTA_DROP 0x00000010
191 #define ACT_DLTA_BAD 0x80000000
193 #define XA_CLOSE_FUNCS 5
194 int xa_close_funcs = 0;
195 void *xa_close_func[XA_CLOSE_FUNCS];
197 /* load, init and query */
198 static int xacodec_load(sh_video_t *sh, char *filename)
200 vd_xanim_ctx *priv = sh->context;
201 void *(*what_the)();
202 char *error;
203 XAVID_MOD_HDR *mod_hdr;
204 XAVID_FUNC_HDR *func;
205 int i;
207 // priv->file_handler = dlopen(filename, RTLD_NOW|RTLD_GLOBAL);
208 priv->file_handler = dlopen(filename, RTLD_LAZY);
209 if (!priv->file_handler)
211 error = dlerror();
212 if (error)
213 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: failed to dlopen %s while %s\n", filename, error);
214 else
215 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: failed to dlopen %s\n", filename);
216 return(0);
219 what_the = dlsym(priv->file_handler, "What_The");
220 if ((error = dlerror()) != NULL)
222 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: failed to init %s while %s\n", filename, error);
223 dlclose(priv->file_handler);
224 return(0);
227 mod_hdr = what_the();
228 if (!mod_hdr)
230 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: initializer function failed in %s\n", filename);
231 dlclose(priv->file_handler);
232 return(0);
235 mp_msg(MSGT_DECVIDEO, MSGL_V, "=== XAnim Codec ===\n");
236 mp_msg(MSGT_DECVIDEO, MSGL_V, " Filename: %s (API revision: %x)\n", filename, mod_hdr->api_rev);
237 mp_msg(MSGT_DECVIDEO, MSGL_V, " Codec: %s. Rev: %s\n", mod_hdr->desc, mod_hdr->rev);
238 if (mod_hdr->copyright)
239 mp_msg(MSGT_DECVIDEO, MSGL_V, " %s\n", mod_hdr->copyright);
240 if (mod_hdr->mod_author)
241 mp_msg(MSGT_DECVIDEO, MSGL_V, " Module Author(s): %s\n", mod_hdr->mod_author);
242 if (mod_hdr->authors)
243 mp_msg(MSGT_DECVIDEO, MSGL_V, " Codec Author(s): %s\n", mod_hdr->authors);
245 if (mod_hdr->api_rev > XAVID_API_REV)
247 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: not supported api revision (%d) in %s\n",
248 mod_hdr->api_rev, filename);
249 dlclose(priv->file_handler);
250 return(0);
253 func = mod_hdr->funcs;
254 if (!func)
256 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: function table error in %s\n", filename);
257 dlclose(priv->file_handler);
258 return(0);
261 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "Exported functions by codec: [functable: %p entries: %d]\n",
262 mod_hdr->funcs, mod_hdr->num_funcs);
263 for (i = 0; i < (int)mod_hdr->num_funcs; i++)
265 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, " %d: %d %d [iq:%p d:%p]\n",
266 i, func[i].what, func[i].id, func[i].iq_func, func[i].dec_func);
267 if (func[i].what & XAVID_AVI_QUERY)
269 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, " %p: avi init/query func (id: %d)\n",
270 func[i].iq_func, func[i].id);
271 priv->iq_func = (void *)func[i].iq_func;
273 if (func[i].what & XAVID_QT_QUERY)
275 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, " %p: qt init/query func (id: %d)\n",
276 func[i].iq_func, func[i].id);
277 priv->iq_func = (void *)func[i].iq_func;
279 if (func[i].what & XAVID_DEC_FUNC)
281 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, " %p: decoder func (init/query: %p) (id: %d)\n",
282 func[i].dec_func, func[i].iq_func, func[i].id);
283 priv->dec_func = (void *)func[i].dec_func;
286 return(1);
289 static int xacodec_query(sh_video_t *sh, XA_CODEC_HDR *codec_hdr)
291 vd_xanim_ctx *priv = sh->context;
292 long ret;
294 #if 0
295 /* the brute one */
296 if (priv->dec_func)
298 codec_hdr->decoder = priv->dec_func;
299 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "We got decoder's address at init! %p\n", codec_hdr->decoder);
300 return(1);
302 #endif
304 ret = priv->iq_func(codec_hdr);
305 switch(ret)
307 case CODEC_SUPPORTED:
308 priv->dec_func = (void *)codec_hdr->decoder;
309 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "Codec is supported: found decoder for %s at %p\n",
310 codec_hdr->description, codec_hdr->decoder);
311 return(1);
312 case CODEC_UNSUPPORTED:
313 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "Codec (%s) is unsupported by dll\n",
314 codec_hdr->description);
315 return(0);
316 case CODEC_UNKNOWN:
317 default:
318 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "Codec (%s) is unknown by dll\n",
319 codec_hdr->description);
320 return(0);
324 void XA_Print(char *fmt, ...)
326 va_list vallist;
327 char buf[1024];
329 va_start(vallist, fmt);
330 vsnprintf(buf, 1024, fmt, vallist);
331 mp_msg(MSGT_XACODEC, MSGL_DBG2, "[xacodec] %s\n", buf);
332 va_end(vallist);
334 return;
337 /* 0 is no debug (needed by 3ivX) */
338 long xa_debug = 0;
340 void TheEnd1(char *err_mess)
342 XA_Print("error: %s - exiting\n", err_mess);
343 /* we should exit here... */
345 return;
348 void XA_Add_Func_To_Free_Chain(XA_ANIM_HDR *anim_hdr, void (*function)())
350 // XA_Print("XA_Add_Func_To_Free_Chain('anim_hdr: %08x', 'function: %08x')",
351 // anim_hdr, function);
352 xa_close_func[xa_close_funcs] = function;
353 if (xa_close_funcs+1 < XA_CLOSE_FUNCS)
354 xa_close_funcs++;
356 return;
360 unsigned long XA_Time_Read()
362 return GetTimer(); //(GetRelativeTime());
365 void XA_dummy()
367 XA_Print("dummy() called");
370 void XA_Gen_YUV_Tabs(XA_ANIM_HDR *anim_hdr)
372 XA_Print("XA_Gen_YUV_Tabs('anim_hdr: %08x')", anim_hdr);
373 return;
376 void JPG_Setup_Samp_Limit_Table(XA_ANIM_HDR *anim_hdr)
378 XA_Print("JPG_Setup_Samp_Limit_Table('anim_hdr: %08x')", anim_hdr);
379 return;
382 void JPG_Alloc_MCU_Bufs(XA_ANIM_HDR *anim_hdr, unsigned int width,
383 unsigned int height, unsigned int full_flag)
385 XA_Print("JPG_Alloc_MCU_Bufs('anim_hdr: %08x', 'width: %d', 'height: %d', 'full_flag: %d')",
386 anim_hdr, width, height, full_flag);
387 return;
390 /* --------------- 4x4 pixel YUV block fillers [CVID] ----------------- */
392 typedef struct
394 unsigned char r0, g0, b0;
395 unsigned char r1, g1, b1;
396 unsigned char r2, g2, b2;
397 unsigned char r3, g3, b3;
398 unsigned int clr0_0, clr0_1, clr0_2, clr0_3;
399 unsigned int clr1_0, clr1_1, clr1_2, clr1_3;
400 unsigned int clr2_0, clr2_1, clr2_2, clr2_3;
401 unsigned int clr3_0, clr3_1, clr3_2, clr3_3;
402 } XA_2x2_Color;
404 #define SET_4_YUV_PIXELS(image,x,y,cmap2x2) \
405 image->planes[0][((x)+0)+((y)+0)*image->stride[0]]=cmap2x2->clr0_0;\
406 image->planes[0][((x)+1)+((y)+0)*image->stride[0]]=cmap2x2->clr0_1;\
407 image->planes[0][((x)+0)+((y)+1)*image->stride[0]]=cmap2x2->clr0_2;\
408 image->planes[0][((x)+1)+((y)+1)*image->stride[0]]=cmap2x2->clr0_3;\
409 image->planes[1][((x)>>1)+((y)>>1)*image->stride[1]]=cmap2x2->clr1_0;\
410 image->planes[2][((x)>>1)+((y)>>1)*image->stride[2]]=cmap2x2->clr1_1;
412 void XA_2x2_OUT_1BLK_Convert(unsigned char *image_p, unsigned int x, unsigned int y,
413 unsigned int imagex, XA_2x2_Color *cmap2x2)
415 mp_image_t *mpi = (mp_image_t *)image_p;
417 #if 0
418 SET_4_YUV_PIXELS(mpi,x,y,cmap2x2)
419 #else
420 SET_4_YUV_PIXELS(mpi,x,y,cmap2x2)
421 SET_4_YUV_PIXELS(mpi,x+2,y,cmap2x2)
422 SET_4_YUV_PIXELS(mpi,x,y+2,cmap2x2)
423 SET_4_YUV_PIXELS(mpi,x+2,y+2,cmap2x2)
424 #endif
426 return;
429 void XA_2x2_OUT_4BLKS_Convert(unsigned char *image_p, unsigned int x, unsigned int y,
430 unsigned int imagex, XA_2x2_Color *cm0, XA_2x2_Color *cm1, XA_2x2_Color *cm2,
431 XA_2x2_Color *cm3)
433 mp_image_t *mpi = (mp_image_t *)image_p;
435 SET_4_YUV_PIXELS(mpi,x,y,cm0)
436 SET_4_YUV_PIXELS(mpi,x+2,y,cm1)
437 SET_4_YUV_PIXELS(mpi,x,y+2,cm2)
438 SET_4_YUV_PIXELS(mpi,x+2,y+2,cm3)
439 return;
442 void *YUV2x2_Blk_Func(unsigned int image_type, int blks, unsigned int dith_flag)
444 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2, "YUV2x2_Blk_Func(image_type=%d, blks=%d, dith_flag=%d)\n",
445 image_type, blks, dith_flag);
446 switch(blks){
447 case 1:
448 return (void*) XA_2x2_OUT_1BLK_Convert;
449 case 4:
450 return (void*) XA_2x2_OUT_4BLKS_Convert;
453 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Unimplemented: YUV2x2_Blk_Func(image_type=%d blks=%d dith=%d)\n",image_type,blks,dith_flag);
454 return (void*) XA_dummy;
457 // Take Four Y's and UV and put them into a 2x2 Color structure.
459 void XA_YUV_2x2_clr(XA_2x2_Color *cmap2x2, unsigned int Y0, unsigned int Y1,
460 unsigned int Y2, unsigned int Y3, unsigned int U, unsigned int V,
461 unsigned int map_flag, unsigned int *map, XA_CHDR *chdr)
464 mp_dbg(MSGT_DECVIDEO,MSGL_DBG3, "XA_YUV_2x2_clr(%p [%d,%d,%d,%d][%d][%d] %d %p %p)\n",
465 cmap2x2,Y0,Y1,Y2,Y3,U,V,map_flag,map,chdr);
467 cmap2x2->clr0_0=Y0;
468 cmap2x2->clr0_1=Y1;
469 cmap2x2->clr0_2=Y2;
470 cmap2x2->clr0_3=Y3;
471 cmap2x2->clr1_0=U;
472 cmap2x2->clr1_1=V;
473 return;
476 void *YUV2x2_Map_Func(unsigned int image_type, unsigned int dith_type)
478 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2, "YUV2x2_Map_Func('image_type: %d', 'dith_type: %d')",
479 image_type, dith_type);
480 return((void*)XA_YUV_2x2_clr);
483 /* -------------------- whole YUV frame converters ------------------------- */
485 typedef struct
487 unsigned char *Ybuf;
488 unsigned char *Ubuf;
489 unsigned char *Vbuf;
490 unsigned char *the_buf;
491 unsigned int the_buf_size;
492 unsigned short y_w, y_h;
493 unsigned short uv_w, uv_h;
494 } YUVBufs;
496 typedef struct
498 unsigned long Uskip_mask;
499 long *YUV_Y_tab;
500 long *YUV_UB_tab;
501 long *YUV_VR_tab;
502 long *YUV_UG_tab;
503 long *YUV_VG_tab;
504 } YUVTabs;
506 YUVBufs jpg_YUVBufs;
507 YUVTabs def_yuv_tabs;
509 /* -------------- YUV 4x4 1x1 1x1 (4:1:0 aka YVU9) [Indeo 3,4,5] ------------------ */
511 void XA_YUV1611_Convert(unsigned char *image_p, unsigned int imagex, unsigned int imagey,
512 unsigned int i_x, unsigned int i_y, YUVBufs *yuv, YUVTabs *yuv_tabs,
513 unsigned int map_flag, unsigned int *map, XA_CHDR *chdr)
515 sh_video_t *sh = (sh_video_t*)image_p;
516 vd_xanim_ctx *priv = sh->context;
517 mp_image_t *mpi;
518 int y;
519 int ystride=(yuv->y_w)?yuv->y_w:imagex;
520 int uvstride=(yuv->uv_w)?yuv->uv_w:(imagex/4);
522 mp_dbg(MSGT_DECVIDEO,MSGL_DBG3, "YUVTabs: %d %p %p %p %p %p\n",yuv_tabs->Uskip_mask,
523 yuv_tabs->YUV_Y_tab,
524 yuv_tabs->YUV_UB_tab,
525 yuv_tabs->YUV_VR_tab,
526 yuv_tabs->YUV_UG_tab,
527 yuv_tabs->YUV_VG_tab );
529 mp_dbg(MSGT_DECVIDEO,MSGL_DBG3, "XA_YUV1611_Convert('image: %08x', 'imagex: %d', 'imagey: %d', 'i_x: %d', 'i_y: %d', 'yuv_bufs: %08x', 'yuv_tabs: %08x', 'map_flag: %d', 'map: %08x', 'chdr: %08x')",
530 image_p, imagex, imagey, i_x, i_y, yuv, yuv_tabs, map_flag, map, chdr);
532 mp_dbg(MSGT_DECVIDEO,MSGL_DBG3, "YUV: %p %p %p %X (%d) %dx%d %dx%d\n",
533 yuv->Ybuf,yuv->Ubuf,yuv->Vbuf,yuv->the_buf,yuv->the_buf_size,
534 yuv->y_w,yuv->y_h,yuv->uv_w,yuv->uv_h);
536 if(!yuv_tabs->YUV_Y_tab){
537 // standard YVU9 - simply export it!
538 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0,
539 sh->disp_w, sh->disp_h);
540 priv->mpi=mpi; if(!mpi) return; // ERROR!
541 mpi->planes[0]=yuv->Ybuf;
542 mpi->planes[1]=yuv->Ubuf;
543 mpi->planes[2]=yuv->Vbuf;
544 mpi->width=imagex;
545 mpi->stride[0]=ystride; //i_x; // yuv->y_w
546 mpi->stride[1]=mpi->stride[2]=uvstride; //i_x/4; // yuv->uv_w
547 return;
550 // allocate TEMP buffer and convert the image:
551 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
552 sh->disp_w, sh->disp_h);
553 priv->mpi=mpi; if(!mpi) return; // ERROR!
555 // convert the Y plane:
556 for(y=0;y<(int)imagey;y++){
557 unsigned int x;
558 unsigned char* s=yuv->Ybuf+ystride*y;
559 unsigned char* d=mpi->planes[0]+mpi->stride[0]*y;
560 for(x=0;x<imagex;x++) d[x]=s[x]<<1;
563 imagex>>=2;
564 imagey>>=2;
566 // convert the U plane:
567 for(y=0;y<(int)imagey;y++){
568 unsigned int x;
569 unsigned char* s=yuv->Ubuf+uvstride*y;
570 unsigned char* d=mpi->planes[1]+mpi->stride[1]*y;
571 for(x=0;x<imagex;x++) d[x]=s[x]<<1;
574 // convert the V plane:
575 for(y=0;y<(int)imagey;y++){
576 unsigned int x;
577 unsigned char* s=yuv->Vbuf+uvstride*y;
578 unsigned char* d=mpi->planes[2]+mpi->stride[2]*y;
579 for(x=0;x<imagex;x++) d[x]=s[x]<<1;
583 void *XA_YUV1611_Func(unsigned int image_type)
585 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2, "XA_YUV1611_Func('image_type: %d')", image_type);
586 return((void *)XA_YUV1611_Convert);
589 /* --------------- YUV 2x2 1x1 1x1 (4:2:0 aka YV12) [3ivX,H263] ------------ */
591 void XA_YUV221111_Convert(unsigned char *image_p, unsigned int imagex, unsigned int imagey,
592 unsigned int i_x, unsigned int i_y, YUVBufs *yuv, YUVTabs *yuv_tabs, unsigned int map_flag,
593 unsigned int *map, XA_CHDR *chdr)
595 sh_video_t *sh = (sh_video_t*)image_p;
596 vd_xanim_ctx *priv = sh->context;
597 mp_image_t *mpi;
598 // note: 3ivX codec doesn't set y_w, uv_w, they are random junk :(
599 int ystride=imagex; //(yuv->y_w)?yuv->y_w:imagex;
600 int uvstride=imagex/2; //(yuv->uv_w)?yuv->uv_w:(imagex/2);
602 mp_dbg(MSGT_DECVIDEO,MSGL_DBG3, "XA_YUV221111_Convert(%p %dx%d %d;%d [%dx%d] %p %p %d %p %p)\n",
603 image_p,imagex,imagey,i_x,i_y, sh->disp_w, sh->disp_h,
604 yuv,yuv_tabs,map_flag,map,chdr);
606 mp_dbg(MSGT_DECVIDEO,MSGL_DBG3, "YUV: %p %p %p %X (%X) %Xx%X %Xx%X\n",
607 yuv->Ybuf,yuv->Ubuf,yuv->Vbuf,yuv->the_buf,yuv->the_buf_size,
608 yuv->y_w,yuv->y_h,yuv->uv_w,yuv->uv_h);
610 // standard YV12 - simply export it!
611 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0, sh->disp_w, sh->disp_h);
612 priv->mpi=mpi; if(!mpi) return; // ERROR!
613 mpi->planes[0]=yuv->Ybuf;
614 mpi->planes[1]=yuv->Ubuf;
615 mpi->planes[2]=yuv->Vbuf;
616 mpi->width=imagex;
617 mpi->stride[0]=ystride; //i_x; // yuv->y_w
618 mpi->stride[1]=mpi->stride[2]=uvstride; //=i_x/4; // yuv->uv_w
621 void *XA_YUV221111_Func(unsigned int image_type)
623 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2, "XA_YUV221111_Func('image_type: %d')\n",image_type);
624 return((void *)XA_YUV221111_Convert);
627 /* *** EOF XANIM *** */
629 // to set/get/query special features/parameters
630 static int control(sh_video_t *sh,int cmd,void* arg,...){
631 return CONTROL_UNKNOWN;
634 // init driver
635 static int init(sh_video_t *sh)
637 vd_xanim_ctx *priv;
638 char *def_path = XACODEC_PATH;
639 char dll[1024];
640 XA_CODEC_HDR codec_hdr;
641 int i;
643 priv = malloc(sizeof(vd_xanim_ctx));
644 if (!priv)
645 return 0;
646 sh->context = priv;
647 memset(priv, 0, sizeof(vd_xanim_ctx));
649 if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12)) return 0;
651 priv->iq_func = NULL;
652 priv->dec_func = NULL;
654 for (i=0; i < XA_CLOSE_FUNCS; i++)
655 xa_close_func[i] = NULL;
657 if (getenv("XANIM_MOD_DIR"))
658 def_path = getenv("XANIM_MOD_DIR");
660 snprintf(dll, 1024, "%s/%s", def_path, sh->codec->dll);
661 if (xacodec_load(sh, dll) == 0)
662 return(0);
664 codec_hdr.xapi_rev = XAVID_API_REV;
665 codec_hdr.anim_hdr = malloc(4096);
666 codec_hdr.description = sh->codec->info;
667 codec_hdr.compression = bswap_32(sh->bih->biCompression);
668 codec_hdr.decoder = NULL;
669 codec_hdr.x = sh->bih->biWidth; /* ->disp_w */
670 codec_hdr.y = sh->bih->biHeight; /* ->disp_h */
671 /* extra fields to store palette */
672 codec_hdr.avi_ctab_flag = 0;
673 codec_hdr.avi_read_ext = NULL;
674 codec_hdr.extra = NULL;
676 switch(sh->codec->outfmt[sh->outfmtidx])
678 case IMGFMT_BGR32:
679 codec_hdr.depth = 32;
680 break;
681 case IMGFMT_BGR24:
682 codec_hdr.depth = 24;
683 break;
684 case IMGFMT_IYUV:
685 case IMGFMT_I420:
686 case IMGFMT_YV12:
687 codec_hdr.depth = 12;
688 break;
689 case IMGFMT_YVU9:
690 codec_hdr.depth = 9;
691 break;
692 default:
693 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: not supported image out format (%s)\n",
694 vo_format_name(sh->codec->outfmt[sh->outfmtidx]));
695 return(0);
697 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "xacodec: querying for input %dx%d %dbit [fourcc: %4x] (%s)...\n",
698 codec_hdr.x, codec_hdr.y, codec_hdr.depth, codec_hdr.compression, codec_hdr.description);
700 if (xacodec_query(sh, &codec_hdr) == 0)
701 return(0);
703 // free(codec_hdr.anim_hdr);
705 priv->decinfo = malloc(sizeof(XA_DEC_INFO));
706 if (priv->decinfo == NULL)
708 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: memory allocation error: %s\n",
709 strerror(errno));
710 return(0);
712 priv->decinfo->cmd = 0;
713 priv->decinfo->skip_flag = 0;
714 priv->decinfo->imagex = priv->decinfo->xe = codec_hdr.x;
715 priv->decinfo->imagey = priv->decinfo->ye = codec_hdr.y;
716 priv->decinfo->imaged = codec_hdr.depth;
717 priv->decinfo->chdr = NULL;
718 priv->decinfo->map_flag = 0; /* xaFALSE */
719 priv->decinfo->map = NULL;
720 priv->decinfo->xs = priv->decinfo->ys = 0;
721 priv->decinfo->special = 0;
722 priv->decinfo->extra = codec_hdr.extra;
723 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "decinfo->extra, filled by codec: %p [%s]\n",
724 &priv->decinfo->extra, (char *)priv->decinfo->extra);
726 return(1);
729 // uninit driver
730 static void uninit(sh_video_t *sh)
732 vd_xanim_ctx *priv = sh->context;
733 int i;
734 void (*close_func)();
736 for (i=0; i < XA_CLOSE_FUNCS; i++)
737 if (xa_close_func[i])
739 close_func = xa_close_func[i];
740 close_func();
742 dlclose(priv->file_handler);
743 if (priv->decinfo != NULL)
744 free(priv->decinfo);
745 free(priv);
748 // unsigned int (*dec_func)(unsigned char *image, unsigned char *delta,
749 // unsigned int dsize, XA_DEC_INFO *dec_info);
751 // decode a frame
752 static mp_image_t* decode(sh_video_t *sh, void *data, int len, int flags)
754 vd_xanim_ctx *priv = sh->context;
755 unsigned int ret;
757 if (len <= 0)
758 return NULL; // skipped frame
760 priv->decinfo->skip_flag = (flags&3)?1:0;
762 if(sh->codec->outflags[sh->outfmtidx] & CODECS_FLAG_STATIC){
763 // allocate static buffer for cvid-like codecs:
764 priv->mpi = mpcodecs_get_image(sh, MP_IMGTYPE_STATIC,
765 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
766 (sh->disp_w+3)&(~3), (sh->disp_h+3)&(~3));
767 if (!priv->mpi) return NULL;
768 ret = priv->dec_func((uint8_t*)priv->mpi, data, len, priv->decinfo);
769 } else {
770 // left the buffer allocation to the codecs, pass sh_video && priv
771 priv->mpi=NULL;
772 ret = priv->dec_func((uint8_t*)sh, data, len, priv->decinfo);
775 if (ret == ACT_DLTA_NORM)
776 return priv->mpi;
778 if (ret & ACT_DLTA_MAPD)
779 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "mapd\n");
781 if (!(ret & ACT_DLT_MAPD))
782 xacodec_driver->decinfo->map_flag = 0;
783 else
785 xacodec_driver->decinfo->map_flag = 1;
786 xacodec_driver->decinfo->map = ...
790 if (ret & ACT_DLTA_XOR)
792 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "xor\n");
793 return priv->mpi;
796 /* nothing changed */
797 if (ret & ACT_DLTA_NOP)
799 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "nop\n");
800 return NULL;
803 /* frame dropped (also display latest frame) */
804 if (ret & ACT_DLTA_DROP)
806 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "drop\n");
807 return NULL;
810 if (ret & ACT_DLTA_BAD)
812 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "bad\n");
813 return NULL;
816 /* used for double buffer */
817 if (ret & ACT_DLTA_BODY)
819 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "body\n");
820 return NULL;
823 return priv->mpi;
825 #endif