2372
|
1 /*
|
2388
|
2 xacodec.c -- XAnim Video Codec DLL support
|
2372
|
3
|
|
4 (C) 2001 Alex Beregszaszi <alex@naxine.org>
|
2388
|
5 and Arpad Gereoffy <arpi@thot.banki.hu>
|
2372
|
6 */
|
|
7
|
|
8 #include <stdio.h>
|
2376
|
9 #include <stdlib.h>
|
|
10
|
2372
|
11 #include <dlfcn.h> /* dlsym, dlopen, dlclose */
|
|
12 #include <stdarg.h> /* va_alist, va_start, va_end */
|
|
13 #include <errno.h> /* strerror, errno */
|
|
14
|
2376
|
15 #include "config.h"
|
2382
|
16 #define XACODEC_PATH "/usr/lib/xanim/mods"
|
2376
|
17
|
2373
|
18 #include "mp_msg.h"
|
2376
|
19 #include "bswap.h"
|
2372
|
20
|
|
21 #include "stream.h"
|
|
22 #include "demuxer.h"
|
|
23 #include "codec-cfg.h"
|
|
24 #include "stheader.h"
|
2376
|
25
|
2372
|
26 #include "libvo/img_format.h"
|
|
27 #include "xacodec.h"
|
|
28
|
2381
|
29 typedef char xaBYTE;
|
|
30 typedef short xaSHORT;
|
|
31 typedef int xaLONG;
|
|
32
|
|
33 typedef unsigned char xaUBYTE;
|
|
34 typedef unsigned short xaUSHORT;
|
|
35 typedef unsigned int xaULONG;
|
|
36
|
|
37 #define xaFALSE 0
|
|
38 #define xaTRUE 1
|
|
39
|
2372
|
40 #ifndef RTLD_NOW
|
|
41 #define RLTD_NOW 2
|
|
42 #endif
|
|
43 #ifndef RTLD_LAZY
|
|
44 #define RLTD_LAZY 1
|
|
45 #endif
|
|
46 #ifndef RTLD_GLOBAL
|
|
47 #define RLTD_GLOBAL 256
|
|
48 #endif
|
|
49
|
|
50 extern int verbose;
|
|
51
|
2382
|
52 #define XA_CLOSE_FUNCS 5
|
|
53 int xa_close_func = 0;
|
|
54
|
2372
|
55 typedef struct xacodec_driver
|
|
56 {
|
|
57 XA_DEC_INFO *decinfo;
|
|
58 void *file_handler;
|
|
59 long (*iq_func)(XA_CODEC_HDR *codec_hdr);
|
|
60 unsigned int (*dec_func)(unsigned char *image, unsigned char *delta,
|
|
61 unsigned int dsize, XA_DEC_INFO *dec_info);
|
2382
|
62 void *close_func[XA_CLOSE_FUNCS];
|
2384
|
63 xacodec_image_t image;
|
2372
|
64 } xacodec_driver_t;
|
|
65
|
|
66 xacodec_driver_t *xacodec_driver = NULL;
|
|
67
|
|
68 /* Needed by XAnim DLLs */
|
|
69 int XA_Print(char *fmt, ...)
|
|
70 {
|
|
71 va_list vallist;
|
|
72 char buf[1024];
|
|
73
|
|
74 va_start(vallist, fmt);
|
|
75 vsnprintf(buf, 1024, fmt, vallist);
|
2377
|
76 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "[xacodec] %s\n", buf);
|
2372
|
77 va_end(vallist);
|
|
78 }
|
|
79
|
2382
|
80 /* 0 is no debug (needed by 3ivX) */
|
2388
|
81 long xa_debug = 0;
|
2382
|
82
|
2372
|
83 int TheEnd1(char *err_mess)
|
|
84 {
|
|
85 XA_Print("error: %s - exiting\n", err_mess);
|
|
86 xacodec_exit();
|
|
87 }
|
2382
|
88
|
|
89 int XA_Add_Func_To_Free_Chain(XA_ANIM_HDR *anim_hdr, void (*function)())
|
|
90 {
|
2388
|
91 // XA_Print("XA_Add_Func_To_Free_Chain('anim_hdr: %08x', 'function: %08x')",
|
|
92 // anim_hdr, function);
|
2382
|
93 xacodec_driver->close_func[xa_close_func] = function;
|
|
94 if (xa_close_func+1 < XA_CLOSE_FUNCS)
|
|
95 xa_close_func++;
|
|
96 }
|
2372
|
97 /* end of crap */
|
|
98
|
|
99 /* load, init and query */
|
|
100 int xacodec_init(char *filename, xacodec_driver_t *codec_driver)
|
|
101 {
|
|
102 void *(*what_the)();
|
|
103 char *error;
|
|
104 XAVID_MOD_HDR *mod_hdr;
|
|
105 XAVID_FUNC_HDR *func;
|
|
106 int i;
|
|
107
|
|
108 codec_driver->file_handler = dlopen(filename, RTLD_NOW|RTLD_GLOBAL);
|
|
109 if (!codec_driver->file_handler)
|
|
110 {
|
|
111 error = dlerror();
|
|
112 if (error)
|
2373
|
113 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: failed to init %s while %s\n", filename, error);
|
2372
|
114 else
|
2373
|
115 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: failed ot init (dlopen) %s\n", filename);
|
2372
|
116 return(0);
|
|
117 }
|
|
118
|
|
119 what_the = dlsym(codec_driver->file_handler, "What_The");
|
|
120 if ((error = dlerror()) != NULL)
|
|
121 {
|
2373
|
122 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: failed to init %s while %s\n", filename, error);
|
2372
|
123 dlclose(codec_driver->file_handler);
|
|
124 return(0);
|
|
125 }
|
|
126
|
|
127 mod_hdr = what_the();
|
|
128 if (!mod_hdr)
|
|
129 {
|
2373
|
130 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: 'What_The' function failed in %s\n", filename);
|
2372
|
131 dlclose(codec_driver->file_handler);
|
|
132 return(0);
|
|
133 }
|
|
134
|
2373
|
135 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "=== XAnim Codec ===\n");
|
|
136 mp_msg(MSGT_DECVIDEO, MSGL_INFO, " Filename: %s (API revision: %x)\n", filename, mod_hdr->api_rev);
|
|
137 mp_msg(MSGT_DECVIDEO, MSGL_INFO, " Codec: %s. Rev: %s\n", mod_hdr->desc, mod_hdr->rev);
|
2372
|
138 if (mod_hdr->copyright)
|
2373
|
139 mp_msg(MSGT_DECVIDEO, MSGL_INFO, " %s\n", mod_hdr->copyright);
|
2372
|
140 if (mod_hdr->mod_author)
|
2373
|
141 mp_msg(MSGT_DECVIDEO, MSGL_INFO, " Module Author(s): %s\n", mod_hdr->mod_author);
|
2372
|
142 if (mod_hdr->authors)
|
2373
|
143 mp_msg(MSGT_DECVIDEO, MSGL_INFO, " Codec Author(s): %s\n", mod_hdr->authors);
|
2372
|
144
|
|
145 if (mod_hdr->api_rev > XAVID_API_REV)
|
|
146 {
|
2373
|
147 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: not supported api revision in %s\n", filename);
|
2372
|
148 dlclose(codec_driver->file_handler);
|
|
149 return(0);
|
|
150 }
|
|
151
|
|
152 func = mod_hdr->funcs;
|
|
153 if (!func)
|
|
154 {
|
2373
|
155 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: function table error in %s\n", filename);
|
2372
|
156 dlclose(codec_driver->file_handler);
|
|
157 return(0);
|
|
158 }
|
|
159
|
2382
|
160 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "dump: funcs: 0x%08x (num %d)\n", mod_hdr->funcs, mod_hdr->num_funcs);
|
2372
|
161 for (i = 0; i < mod_hdr->num_funcs; i++)
|
|
162 {
|
2382
|
163 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "dump(%d): %d %d [iq:0x%08x d:0x%08x]\n", i,
|
2372
|
164 func[i].what, func[i].id, func[i].iq_func, func[i].dec_func);
|
|
165 if (func[i].what & XAVID_AVI_QUERY)
|
|
166 {
|
2382
|
167 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "0x%08x: avi init/query func (id: %d)\n",
|
2372
|
168 func[i].iq_func, func[i].id);
|
|
169 codec_driver->iq_func = func[i].iq_func;
|
|
170 }
|
|
171 if (func[i].what & XAVID_QT_QUERY)
|
|
172 {
|
2382
|
173 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "0x%08x: qt init/query func (id: %d)\n",
|
2372
|
174 func[i].iq_func, func[i].id);
|
|
175 codec_driver->iq_func = func[i].iq_func;
|
|
176 }
|
|
177 if (func[i].what & XAVID_DEC_FUNC)
|
|
178 {
|
2382
|
179 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "0x%08x: decoder func (init/query: 0x%08x) (id: %d)\n",
|
2372
|
180 func[i].dec_func, func[i].iq_func, func[i].id);
|
|
181 codec_driver->dec_func = func[i].dec_func;
|
|
182 }
|
|
183 }
|
|
184 return(1);
|
|
185 }
|
|
186
|
|
187 int xacodec_query(xacodec_driver_t *codec_driver, XA_CODEC_HDR *codec_hdr)
|
|
188 {
|
|
189 long codec_ret;
|
|
190
|
|
191 codec_ret = codec_driver->iq_func(codec_hdr);
|
|
192 switch(codec_ret)
|
|
193 {
|
|
194 case CODEC_SUPPORTED:
|
|
195 codec_driver->dec_func = codec_hdr->decoder;
|
2382
|
196 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "Codec is supported: found decoder for %s at 0x%08x\n",
|
2372
|
197 codec_hdr->description, codec_hdr->decoder);
|
|
198 return(1);
|
|
199 case CODEC_UNSUPPORTED:
|
2388
|
200 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "Codec (%s) is unsupported by driver\n",
|
|
201 codec_hdr->description);
|
2372
|
202 return(0);
|
|
203 case CODEC_UNKNOWN:
|
|
204 default:
|
2388
|
205 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "Codec (%s) is unknown by driver\n",
|
|
206 codec_hdr->description);
|
2372
|
207 return(0);
|
|
208 }
|
|
209 }
|
|
210
|
|
211 char *xacodec_def_path = XACODEC_PATH;
|
|
212
|
|
213 int xacodec_init_video(sh_video_t *vidinfo, int out_format)
|
|
214 {
|
|
215 char dll[1024];
|
|
216 XA_CODEC_HDR codec_hdr;
|
2382
|
217 int i;
|
2372
|
218
|
|
219 xacodec_driver = realloc(xacodec_driver, sizeof(struct xacodec_driver));
|
|
220 if (xacodec_driver == NULL)
|
|
221 return(0);
|
|
222
|
|
223 xacodec_driver->iq_func = NULL;
|
|
224 xacodec_driver->dec_func = NULL;
|
2382
|
225
|
|
226 for (i=0; i < XA_CLOSE_FUNCS; i++)
|
|
227 xacodec_driver->close_func[i] = NULL;
|
2372
|
228
|
|
229 snprintf(dll, 1024, "%s/%s", xacodec_def_path, vidinfo->codec->dll);
|
|
230 if (xacodec_init(dll, xacodec_driver) == 0)
|
|
231 return(0);
|
|
232
|
|
233 codec_hdr.anim_hdr = malloc(4096);
|
|
234 codec_hdr.description = vidinfo->codec->info;
|
|
235 codec_hdr.compression = bswap_32(vidinfo->format);
|
|
236 codec_hdr.decoder = NULL;
|
|
237 codec_hdr.avi_ctab_flag = 0;
|
|
238 codec_hdr.avi_read_ext = NULL;
|
|
239 codec_hdr.xapi_rev = 0x0001;
|
|
240 codec_hdr.extra = NULL;
|
|
241 codec_hdr.x = vidinfo->disp_w;
|
|
242 codec_hdr.y = vidinfo->disp_h;
|
|
243
|
|
244 switch(out_format)
|
|
245 {
|
|
246 case IMGFMT_RGB8:
|
|
247 codec_hdr.depth = 8;
|
|
248 break;
|
|
249 case IMGFMT_RGB15:
|
|
250 codec_hdr.depth = 15;
|
|
251 break;
|
|
252 case IMGFMT_RGB16:
|
|
253 codec_hdr.depth = 16;
|
|
254 break;
|
|
255 case IMGFMT_RGB24:
|
|
256 codec_hdr.depth = 24;
|
|
257 break;
|
|
258 case IMGFMT_RGB32:
|
|
259 codec_hdr.depth = 32;
|
|
260 break;
|
|
261 case IMGFMT_BGR8:
|
|
262 codec_hdr.depth = 8;
|
|
263 break;
|
|
264 case IMGFMT_BGR15:
|
|
265 codec_hdr.depth = 15;
|
|
266 break;
|
|
267 case IMGFMT_BGR16:
|
|
268 codec_hdr.depth = 16;
|
|
269 break;
|
|
270 case IMGFMT_BGR24:
|
|
271 codec_hdr.depth = 24;
|
|
272 break;
|
|
273 case IMGFMT_BGR32:
|
|
274 codec_hdr.depth = 32;
|
|
275 break;
|
2383
|
276 case IMGFMT_IYUV:
|
2382
|
277 case IMGFMT_I420:
|
2383
|
278 case IMGFMT_YV12:
|
|
279 codec_hdr.depth = 12;
|
2382
|
280 break;
|
2372
|
281 default:
|
2382
|
282 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: not supported image format (%s)\n",
|
2372
|
283 vo_format_name(out_format));
|
|
284 return(0);
|
|
285 }
|
2382
|
286 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "xacodec: querying for %dx%d %dbit [fourcc: %4x] (%s)...\n",
|
2372
|
287 codec_hdr.x, codec_hdr.y, codec_hdr.depth, codec_hdr.compression,
|
|
288 codec_hdr.description);
|
|
289
|
|
290 if (xacodec_query(xacodec_driver, &codec_hdr) == 0)
|
|
291 return(0);
|
|
292
|
|
293 // free(codec_hdr.anim_hdr);
|
|
294
|
|
295 xacodec_driver->decinfo = malloc(sizeof(XA_DEC_INFO));
|
|
296 xacodec_driver->decinfo->cmd = 0;
|
|
297 xacodec_driver->decinfo->skip_flag = 0;
|
|
298 xacodec_driver->decinfo->imagex = xacodec_driver->decinfo->xe = codec_hdr.x;
|
|
299 xacodec_driver->decinfo->imagey = xacodec_driver->decinfo->ye = codec_hdr.y;
|
|
300 xacodec_driver->decinfo->imaged = codec_hdr.depth;
|
|
301 xacodec_driver->decinfo->chdr = NULL;
|
|
302 xacodec_driver->decinfo->map_flag = 0; /* xaFALSE */
|
|
303 xacodec_driver->decinfo->map = NULL;
|
|
304 xacodec_driver->decinfo->xs = xacodec_driver->decinfo->ys = 0;
|
|
305 xacodec_driver->decinfo->special = 0;
|
|
306 xacodec_driver->decinfo->extra = codec_hdr.extra;
|
|
307
|
2377
|
308 // vidinfo->our_out_buffer = malloc(codec_hdr.y * codec_hdr.x * ((codec_hdr.depth+7)/8));
|
2384
|
309 // vidinfo->our_out_buffer = malloc(codec_hdr.y * codec_hdr.x * codec_hdr.depth);
|
|
310 xacodec_driver->image.out_fmt=out_format;
|
|
311 xacodec_driver->image.bpp=codec_hdr.depth;
|
|
312 xacodec_driver->image.width=codec_hdr.x;
|
|
313 xacodec_driver->image.height=codec_hdr.y;
|
2391
|
314 xacodec_driver->image.mem=malloc(codec_hdr.y * codec_hdr.x * ((codec_hdr.depth+7)/8));
|
2372
|
315
|
2388
|
316 if (xacodec_driver->image.mem == NULL)
|
2372
|
317 {
|
2382
|
318 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "cannot allocate memory for output: %s",
|
2372
|
319 strerror(errno));
|
|
320 return(0);
|
|
321 }
|
|
322
|
2382
|
323 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "extra: %08x - %dx%d %dbit\n", codec_hdr.extra,
|
2372
|
324 codec_hdr.x, codec_hdr.y, codec_hdr.depth);
|
|
325 return(1);
|
|
326 }
|
|
327
|
|
328 #define ACT_DLT_NORM 0x00000000
|
|
329 #define ACT_DLT_BODY 0x00000001
|
|
330 #define ACT_DLT_XOR 0x00000002
|
|
331 #define ACT_DLT_NOP 0x00000004
|
|
332 #define ACT_DLT_MAPD 0x00000008
|
|
333 #define ACT_DLT_DROP 0x00000010
|
|
334 #define ACT_DLT_BAD 0x80000000
|
|
335
|
|
336 // unsigned int (*dec_func)(unsigned char *image, unsigned char *delta,
|
|
337 // unsigned int dsize, XA_DEC_INFO *dec_info);
|
|
338
|
2384
|
339 xacodec_image_t* xacodec_decode_frame(uint8_t *frame, int frame_size, int skip_flag)
|
2372
|
340 {
|
|
341 unsigned int ret;
|
|
342 int i;
|
2387
|
343 xacodec_image_t *image=&xacodec_driver->image;
|
2384
|
344
|
2372
|
345 if (skip_flag > 0)
|
2388
|
346 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "frame will be dropped..\n");
|
2372
|
347
|
|
348 xacodec_driver->decinfo->skip_flag = skip_flag;
|
|
349
|
2387
|
350 image->planes[0]=image->mem;
|
|
351 image->stride[0]=image->width;
|
|
352 image->stride[1]=image->stride[2]=image->width/2;
|
|
353 switch(image->out_fmt){
|
|
354 case IMGFMT_YV12:
|
|
355 image->planes[2]=image->planes[0]+image->width*image->height;
|
|
356 image->planes[1]=image->planes[2]+image->width*image->height/4;
|
|
357 break;
|
|
358 case IMGFMT_I420:
|
|
359 case IMGFMT_IYUV:
|
|
360 image->planes[1]=image->planes[0]+image->width*image->height;
|
|
361 image->planes[2]=image->planes[1]+image->width*image->height/4;
|
|
362 break;
|
|
363 }
|
|
364
|
2384
|
365 // printf("frame: %08x (size: %d) - dest: %08x\n", frame, frame_size, dest);
|
|
366
|
|
367 ret = xacodec_driver->dec_func((uint8_t*)&xacodec_driver->image, frame, frame_size, xacodec_driver->decinfo);
|
2372
|
368
|
2384
|
369 // printf("ret: %lu : ", ret);
|
2372
|
370
|
|
371
|
|
372 if (ret == ACT_DLT_NORM)
|
|
373 {
|
2388
|
374 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "norm\n");
|
2384
|
375 return &xacodec_driver->image;
|
2372
|
376 }
|
|
377
|
|
378 /*
|
|
379 if (!(ret & ACT_DLT_MAPD))
|
|
380 xacodec_driver->decinfo->map_flag = 0;
|
|
381 else
|
|
382 {
|
|
383 xacodec_driver->decinfo->map_flag = 1;
|
|
384 xacodec_driver->decinfo->map = ...
|
|
385 }
|
|
386 */
|
|
387
|
|
388 if (ret & ACT_DLT_NOP)
|
|
389 {
|
2388
|
390 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "nop\n");
|
2384
|
391 return NULL; /* dst = 0 */
|
2372
|
392 }
|
|
393
|
|
394 if (ret & ACT_DLT_DROP) /* by skip frames and errors */
|
|
395 {
|
2388
|
396 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "drop\n");
|
2384
|
397 return NULL;
|
2372
|
398 }
|
|
399
|
|
400 if (ret & ACT_DLT_BAD)
|
|
401 {
|
2388
|
402 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "bad\n");
|
2384
|
403 return NULL;
|
2372
|
404 }
|
|
405
|
|
406 if (ret & ACT_DLT_BODY)
|
|
407 {
|
2388
|
408 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "body\n");
|
2384
|
409 return NULL;
|
2372
|
410 }
|
|
411
|
|
412 if (ret & ACT_DLT_XOR)
|
|
413 {
|
2388
|
414 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "xor\n");
|
2384
|
415 return &xacodec_driver->image;
|
2372
|
416 }
|
|
417
|
2384
|
418 return NULL;
|
2372
|
419 }
|
|
420
|
|
421 int xacodec_exit()
|
|
422 {
|
2382
|
423 int i;
|
|
424 void (*close_func)();
|
|
425
|
|
426 for (i=0; i < XA_CLOSE_FUNCS; i++)
|
|
427 if (xacodec_driver->close_func[i])
|
|
428 {
|
|
429 close_func = xacodec_driver->close_func[i];
|
|
430 close_func();
|
|
431 }
|
2372
|
432 dlclose(xacodec_driver->file_handler);
|
|
433 if (xacodec_driver->decinfo != NULL)
|
|
434 free(xacodec_driver->decinfo);
|
2388
|
435 free(xacodec_driver);
|
2372
|
436 return(TRUE);
|
|
437 }
|
2373
|
438
|
|
439
|
|
440 /* *** XANIM SHIT *** */
|
|
441 /* like loader/win32.c - mini XANIM library */
|
|
442
|
2382
|
443 unsigned long XA_Time_Read()
|
|
444 {
|
2384
|
445 return GetTimer(); //(GetRelativeTime());
|
2382
|
446 }
|
|
447
|
|
448 void XA_dummy()
|
|
449 {
|
|
450 XA_Print("dummy() called");
|
|
451 }
|
|
452
|
2373
|
453 int XA_Gen_YUV_Tabs(XA_ANIM_HDR *anim_hdr)
|
|
454 {
|
|
455 XA_Print("XA_Gen_YUV_Tabs('anim_hdr: %08x')", anim_hdr);
|
|
456
|
|
457 // XA_Print("anim type: %d - img[x: %d, y: %d, c: %d, d: %d]",
|
|
458 // anim_hdr->anim_type, anim_hdr->imagex, anim_hdr->imagey,
|
|
459 // anim_hdr->imagec, anim_hdr->imaged);
|
|
460 }
|
|
461
|
|
462 void JPG_Setup_Samp_Limit_Table(XA_ANIM_HDR *anim_hdr)
|
|
463 {
|
|
464 XA_Print("JPG_Setup_Samp_Limit_Table('anim_hdr: %08x')", anim_hdr);
|
2381
|
465 // xa_byte_limit = jpg_samp_limit + (MAXJSAMPLE + 1);
|
2373
|
466 }
|
|
467
|
|
468 void JPG_Alloc_MCU_Bufs(XA_ANIM_HDR *anim_hdr, unsigned int width,
|
|
469 unsigned int height, unsigned int full_flag)
|
|
470 {
|
|
471 XA_Print("JPG_Alloc_MCU_Bufs('anim_hdr: %08x', 'width: %d', 'height: %d', 'full_flag: %d')",
|
|
472 anim_hdr, width, height, full_flag);
|
|
473 }
|
|
474
|
2391
|
475
|
|
476 /* --------------- 4x4 pixel YUV block fillers (CVID) ----------------- */
|
|
477
|
|
478 typedef struct
|
|
479 {
|
|
480 unsigned char r0, g0, b0;
|
|
481 unsigned char r1, g1, b1;
|
|
482 unsigned char r2, g2, b2;
|
|
483 unsigned char r3, g3, b3;
|
|
484 unsigned int clr0_0, clr0_1, clr0_2, clr0_3;
|
|
485 unsigned int clr1_0, clr1_1, clr1_2, clr1_3;
|
|
486 unsigned int clr2_0, clr2_1, clr2_2, clr2_3;
|
|
487 unsigned int clr3_0, clr3_1, clr3_2, clr3_3;
|
|
488 } XA_2x2_Color;
|
|
489
|
|
490 #define SET_4_YUV_PIXELS(image,x,y,cmap2x2) \
|
|
491 image->planes[0][((x)+0)+((y)+0)*image->stride[0]]=cmap2x2->clr0_0;\
|
|
492 image->planes[0][((x)+1)+((y)+0)*image->stride[0]]=cmap2x2->clr0_1;\
|
|
493 image->planes[0][((x)+0)+((y)+1)*image->stride[0]]=cmap2x2->clr0_2;\
|
|
494 image->planes[0][((x)+1)+((y)+1)*image->stride[0]]=cmap2x2->clr0_3;\
|
|
495 image->planes[1][((x)>>1)+((y)>>1)*image->stride[1]]=cmap2x2->clr1_0;\
|
|
496 image->planes[2][((x)>>1)+((y)>>1)*image->stride[2]]=cmap2x2->clr1_1;
|
|
497
|
|
498 void XA_2x2_OUT_1BLK_clr8(unsigned char *image_p, unsigned int x, unsigned int y,
|
|
499 unsigned int imagex, XA_2x2_Color *cmap2x2)
|
|
500 {
|
|
501 xacodec_image_t *image=(xacodec_image_t*)image_p;
|
|
502
|
|
503 #if 0
|
|
504 SET_4_YUV_PIXELS(image,x,y,cmap2x2)
|
|
505 #else
|
|
506 SET_4_YUV_PIXELS(image,x,y,cmap2x2)
|
|
507 SET_4_YUV_PIXELS(image,x+2,y,cmap2x2)
|
|
508 SET_4_YUV_PIXELS(image,x,y+2,cmap2x2)
|
|
509 SET_4_YUV_PIXELS(image,x+2,y+2,cmap2x2)
|
|
510 #endif
|
|
511
|
|
512 }
|
|
513
|
|
514 void XA_2x2_OUT_4BLKS_clr8(unsigned char *image_p, unsigned int x, unsigned int y,
|
|
515 unsigned int imagex, XA_2x2_Color *cm0, XA_2x2_Color *cm1, XA_2x2_Color *cm2,
|
|
516 XA_2x2_Color *cm3)
|
|
517 {
|
|
518 xacodec_image_t *image=(xacodec_image_t*)image_p;
|
|
519
|
|
520 SET_4_YUV_PIXELS(image,x,y,cm0)
|
|
521 SET_4_YUV_PIXELS(image,x+2,y,cm1)
|
|
522 SET_4_YUV_PIXELS(image,x,y+2,cm2)
|
|
523 SET_4_YUV_PIXELS(image,x+2,y+2,cm3)
|
|
524 }
|
|
525
|
|
526 void *YUV2x2_Blk_Func(unsigned int image_type, int blks, unsigned int dith_flag)
|
|
527 {
|
|
528 void (*color_func)();
|
|
529
|
|
530 switch(blks){
|
|
531 case 1:
|
|
532 return (void*) XA_2x2_OUT_1BLK_clr8;
|
|
533 case 4:
|
|
534 return (void*) XA_2x2_OUT_4BLKS_clr8;
|
|
535 }
|
|
536
|
|
537 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Unimplemented: YUV2x2_Blk_Func(image_type=%d blks=%d dith=%d)\n",image_type,blks,dith_flag);
|
|
538 return (void*) XA_dummy;
|
|
539 }
|
|
540
|
|
541 // Take Four Y's and UV and put them into a 2x2 Color structure.
|
|
542
|
|
543 void XA_YUV_2x2_clr(cmap2x2,Y0,Y1,Y2,Y3,U,V,map_flag,map,chdr)
|
|
544 XA_2x2_Color *cmap2x2;
|
|
545 xaULONG Y0,Y1,Y2,Y3,U,V;
|
|
546 xaULONG map_flag,*map;
|
|
547 XA_CHDR *chdr;
|
|
548 {
|
|
549
|
|
550 // printf("XA_YUV_2x2_clr(%p [%d,%d,%d,%d][%d][%d] %d %p %p)\n",
|
|
551 // cmap2x2,Y0,Y1,Y2,Y3,U,V,map_flag,map,chdr);
|
|
552
|
|
553 cmap2x2->clr0_0=Y0;
|
|
554 cmap2x2->clr0_1=Y1;
|
|
555 cmap2x2->clr0_2=Y2;
|
|
556 cmap2x2->clr0_3=Y3;
|
|
557 cmap2x2->clr1_0=U;
|
|
558 cmap2x2->clr1_1=V;
|
|
559
|
|
560 }
|
|
561
|
|
562 void *YUV2x2_Map_Func(unsigned int image_type, unsigned int dith_type)
|
|
563 {
|
|
564 // XA_Print("YUV2x2_Map_Func('image_type: %d', 'dith_type: %d')",
|
|
565 // image_type, dith_type);
|
|
566 return (void*)XA_YUV_2x2_clr;
|
|
567 }
|
|
568
|
|
569 /* -------------------- whole YV12 frame converter ------------------- */
|
|
570
|
2373
|
571 typedef struct
|
|
572 {
|
|
573 unsigned char *Ybuf;
|
|
574 unsigned char *Ubuf;
|
|
575 unsigned char *Vbuf;
|
|
576 unsigned char *the_buf;
|
|
577 unsigned int the_buf_size;
|
|
578 unsigned short y_w, y_h;
|
|
579 unsigned short uv_w, uv_h;
|
|
580 } YUVBufs;
|
|
581
|
|
582 typedef struct
|
|
583 {
|
|
584 unsigned long Uskip_mask;
|
|
585 long *YUV_Y_tab;
|
|
586 long *YUV_UB_tab;
|
|
587 long *YUV_VR_tab;
|
|
588 long *YUV_UG_tab;
|
|
589 long *YUV_VG_tab;
|
|
590 } YUVTabs;
|
|
591
|
2395
|
592 // Here's are the YUV 16 1 1 routines.
|
2391
|
593 void XA_YUV1611_To_CLR8(unsigned char *image_p, unsigned int imagex, unsigned int imagey,
|
|
594 unsigned int i_x, unsigned int i_y, YUVBufs *yuv, YUVTabs *yuv_tabs,
|
2373
|
595 unsigned int map_flag, unsigned int *map, XA_CHDR *chdr)
|
|
596 {
|
2391
|
597 xacodec_image_t *image=(xacodec_image_t*)image_p;
|
2395
|
598 int y;
|
|
599 int uvstride;
|
2391
|
600
|
2395
|
601 #if 0
|
2397
|
602 printf("YUVTabs: %d %p %p %p %p %p\n",yuv_tabs->Uskip_mask,
|
|
603 yuv_tabs->YUV_Y_tab,
|
|
604 yuv_tabs->YUV_UB_tab,
|
|
605 yuv_tabs->YUV_VR_tab,
|
|
606 yuv_tabs->YUV_UG_tab,
|
|
607 yuv_tabs->YUV_VG_tab );
|
|
608
|
2391
|
609 XA_Print("XA_YUV1611_To_CLR8('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')",
|
|
610 image, imagex, imagey, i_x, i_y, yuv, yuv_tabs, map_flag, map, chdr);
|
2373
|
611
|
2395
|
612 printf("YUV: %p %p %p %X (%d) %dx%d %dx%d\n",
|
|
613 yuv->Ybuf,yuv->Ubuf,yuv->Vbuf,yuv->the_buf,yuv->the_buf_size,
|
|
614 yuv->y_w,yuv->y_h,yuv->uv_w,yuv->uv_h);
|
|
615 #endif
|
|
616
|
|
617 // copy Y plane:
|
2397
|
618 if(yuv_tabs->YUV_Y_tab){ // dirty hack to detect iv32:
|
|
619 for(y=0;y<imagey*imagex;y++)
|
|
620 image->planes[0][y]=yuv->Ybuf[y]<<1;
|
|
621 } else
|
|
622 memcpy(image->planes[0],yuv->Ybuf,imagex*imagey);
|
2395
|
623
|
|
624 // scale U,V planes by 2:
|
|
625 imagex>>=2;
|
|
626 imagey>>=2;
|
2391
|
627
|
2395
|
628 uvstride=(yuv->uv_w)?yuv->uv_w:imagex;
|
|
629
|
|
630 for(y=0;y<imagey;y++){
|
|
631 unsigned char *su=yuv->Ubuf+uvstride*y;
|
|
632 unsigned char *sv=yuv->Vbuf+uvstride*y;
|
|
633 unsigned int strideu=image->stride[1];
|
|
634 unsigned int stridev=image->stride[2];
|
|
635 unsigned char *du=image->planes[1]+2*y*strideu;
|
|
636 unsigned char *dv=image->planes[2]+2*y*stridev;
|
|
637 int x;
|
2397
|
638 if(yuv_tabs->YUV_Y_tab){ // dirty hack to detect iv32:
|
|
639 for(x=0;x<imagex;x++){
|
|
640 du[2*x]=du[2*x+1]=du[2*x+strideu]=du[2*x+strideu+1]=su[x]*2;
|
|
641 dv[2*x]=dv[2*x+1]=dv[2*x+stridev]=dv[2*x+stridev+1]=sv[x]*2;
|
|
642 }
|
|
643 } else {
|
|
644 for(x=0;x<imagex;x++){
|
|
645 du[2*x]=du[2*x+1]=du[2*x+strideu]=du[2*x+strideu+1]=su[x];
|
|
646 dv[2*x]=dv[2*x+1]=dv[2*x+stridev]=dv[2*x+stridev+1]=sv[x];
|
|
647 }
|
2395
|
648 }
|
|
649 }
|
2391
|
650
|
2373
|
651 }
|
|
652
|
|
653 void *XA_YUV1611_Func(unsigned int image_type)
|
|
654 {
|
|
655 void (*color_func)();
|
|
656
|
|
657 XA_Print("XA_YUV1611_Func('image_type: %d')", image_type);
|
|
658
|
2391
|
659 return XA_YUV1611_To_CLR8;
|
2373
|
660 }
|
|
661
|
2395
|
662
|
2373
|
663 /* YUV 41 11 11 routines */
|
|
664 void XA_YUV411111_To_RGB(unsigned char *image, unsigned int imagex, unsigned int imagey,
|
|
665 unsigned int i_x, unsigned int i_y, YUVBufs *yuv_bufs, YUVTabs *yuv_tabs,
|
|
666 unsigned int map_flag, unsigned int *map, XA_CHDR *chdr)
|
|
667 {
|
|
668 XA_Print("XA_YUV411111_To_RGB('image: %d', 'imagex: %d', 'imagey: %d', 'i_x: %d', 'i_y: %d', 'yuv_bufs: %08x', 'yuv_tabs: %08x', 'map_flag: %d', 'map: %08x', 'chdr: %08x')",
|
|
669 image, imagex, imagey, i_x, i_y, yuv_bufs, yuv_tabs, map_flag, map, chdr);
|
|
670 }
|
|
671
|
|
672
|
|
673 void *XA_YUV411111_Func(unsigned int image_type)
|
|
674 {
|
|
675
|
2395
|
676 XA_Print("XA_YUV411111_Func('image_type: %d')", image_type);
|
2373
|
677
|
2395
|
678 return (void*) XA_YUV411111_To_RGB;
|
2373
|
679 }
|
|
680
|
2391
|
681
|
|
682 // input frame format: YUV 4:2:0 (YV12)
|
2384
|
683 void XA_YUV221111_To_CLR8(image_p,imagex,imagey,i_x,i_y,yuv,yuv_tabs,map_flag,map,chdr)
|
|
684 xaUBYTE *image_p; xaULONG imagex,imagey,i_x,i_y;
|
2383
|
685 YUVBufs *yuv; YUVTabs *yuv_tabs;
|
|
686 xaULONG map_flag,*map; XA_CHDR *chdr;
|
|
687 {
|
2384
|
688 xacodec_image_t *image=(xacodec_image_t*)image_p;
|
|
689
|
|
690 #if 0
|
|
691 printf("XA_YUV221111_To_CLR8(%p %dx%d %d;%d [%dx%d] %p %p %d %p %p)\n",
|
|
692 image,imagex,imagey,i_x,i_y, image->width,image->height,
|
|
693 yuv,yuv_tabs,map_flag,map,chdr);
|
2383
|
694
|
|
695 printf("YUV: %p %p %p %X (%X) %Xx%X %Xx%X\n",
|
|
696 yuv->Ybuf,yuv->Ubuf,yuv->Vbuf,yuv->the_buf,yuv->the_buf_size,
|
|
697 yuv->y_w,yuv->y_h,yuv->uv_w,yuv->uv_h);
|
2384
|
698 #endif
|
2383
|
699
|
2384
|
700 if(imagex==image->width && imagey==image->height){
|
|
701 // printf("Direct render!!!\n");
|
|
702 image->planes[0]=yuv->Ybuf;
|
|
703 if(image->out_fmt==IMGFMT_YV12){
|
|
704 image->planes[1]=yuv->Ubuf;
|
|
705 image->planes[2]=yuv->Vbuf;
|
|
706 } else {
|
|
707 image->planes[1]=yuv->Vbuf;
|
|
708 image->planes[2]=yuv->Ubuf;
|
|
709 }
|
|
710 image->stride[0]=imagex; // yuv->y_w
|
|
711 image->stride[1]=image->stride[2]=imagex/2; // yuv->uv_w
|
|
712 } else {
|
|
713 printf("partial YV12 not implemented!!!!!!\n");
|
2387
|
714
|
2384
|
715 }
|
|
716
|
2383
|
717 }
|
|
718
|
2382
|
719 /* YUV 22 11 11 routines */
|
|
720 void *XA_YUV221111_Func(unsigned int image_type)
|
|
721 {
|
|
722 XA_Print("XA_YUV221111_Func('image_type: %d')", image_type);
|
2383
|
723 return((void *)XA_YUV221111_To_CLR8);
|
2382
|
724 }
|
2373
|
725
|
|
726 YUVBufs jpg_YUVBufs;
|
|
727 YUVTabs def_yuv_tabs;
|
|
728
|
|
729 /* *** EOF XANIM SHIT *** */
|