2372
|
1 /*
|
|
2 xacodec.c
|
|
3 XAnim Video Codec DLL support
|
|
4
|
|
5 (C) 2001 Alex Beregszaszi <alex@naxine.org>
|
|
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) */
|
|
81 long xa_debug = 2;
|
|
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 {
|
|
91 XA_Print("XA_Add_Func_To_Free_Chain('anim_hdr: %08x', 'function: %08x')",
|
|
92 anim_hdr, function);
|
|
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:
|
2382
|
200 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "Codec is unsupported by driver\n");
|
2372
|
201 return(0);
|
|
202 case CODEC_UNKNOWN:
|
|
203 default:
|
2382
|
204 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "Codec is unknown by driver\n");
|
2372
|
205 return(0);
|
|
206 }
|
|
207 }
|
|
208
|
|
209 char *xacodec_def_path = XACODEC_PATH;
|
|
210
|
|
211 int xacodec_init_video(sh_video_t *vidinfo, int out_format)
|
|
212 {
|
|
213 char dll[1024];
|
|
214 XA_CODEC_HDR codec_hdr;
|
2382
|
215 int i;
|
2372
|
216
|
|
217 xacodec_driver = realloc(xacodec_driver, sizeof(struct xacodec_driver));
|
|
218 if (xacodec_driver == NULL)
|
|
219 return(0);
|
|
220
|
|
221 xacodec_driver->iq_func = NULL;
|
|
222 xacodec_driver->dec_func = NULL;
|
2382
|
223
|
|
224 for (i=0; i < XA_CLOSE_FUNCS; i++)
|
|
225 xacodec_driver->close_func[i] = NULL;
|
2372
|
226
|
|
227 snprintf(dll, 1024, "%s/%s", xacodec_def_path, vidinfo->codec->dll);
|
|
228 if (xacodec_init(dll, xacodec_driver) == 0)
|
|
229 return(0);
|
|
230
|
|
231 codec_hdr.anim_hdr = malloc(4096);
|
|
232 codec_hdr.description = vidinfo->codec->info;
|
|
233 codec_hdr.compression = bswap_32(vidinfo->format);
|
|
234 codec_hdr.decoder = NULL;
|
|
235 codec_hdr.avi_ctab_flag = 0;
|
|
236 codec_hdr.avi_read_ext = NULL;
|
|
237 codec_hdr.xapi_rev = 0x0001;
|
|
238 codec_hdr.extra = NULL;
|
|
239 codec_hdr.x = vidinfo->disp_w;
|
|
240 codec_hdr.y = vidinfo->disp_h;
|
|
241
|
|
242 switch(out_format)
|
|
243 {
|
|
244 case IMGFMT_RGB8:
|
|
245 codec_hdr.depth = 8;
|
|
246 break;
|
|
247 case IMGFMT_RGB15:
|
|
248 codec_hdr.depth = 15;
|
|
249 break;
|
|
250 case IMGFMT_RGB16:
|
|
251 codec_hdr.depth = 16;
|
|
252 break;
|
|
253 case IMGFMT_RGB24:
|
|
254 codec_hdr.depth = 24;
|
|
255 break;
|
|
256 case IMGFMT_RGB32:
|
|
257 codec_hdr.depth = 32;
|
|
258 break;
|
|
259 case IMGFMT_BGR8:
|
|
260 codec_hdr.depth = 8;
|
|
261 break;
|
|
262 case IMGFMT_BGR15:
|
|
263 codec_hdr.depth = 15;
|
|
264 break;
|
|
265 case IMGFMT_BGR16:
|
|
266 codec_hdr.depth = 16;
|
|
267 break;
|
|
268 case IMGFMT_BGR24:
|
|
269 codec_hdr.depth = 24;
|
|
270 break;
|
|
271 case IMGFMT_BGR32:
|
|
272 codec_hdr.depth = 32;
|
|
273 break;
|
2383
|
274 case IMGFMT_IYUV:
|
2382
|
275 case IMGFMT_I420:
|
2383
|
276 case IMGFMT_YV12:
|
|
277 codec_hdr.depth = 12;
|
2382
|
278 break;
|
2372
|
279 default:
|
2382
|
280 mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: not supported image format (%s)\n",
|
2372
|
281 vo_format_name(out_format));
|
|
282 return(0);
|
|
283 }
|
2382
|
284 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "xacodec: querying for %dx%d %dbit [fourcc: %4x] (%s)...\n",
|
2372
|
285 codec_hdr.x, codec_hdr.y, codec_hdr.depth, codec_hdr.compression,
|
|
286 codec_hdr.description);
|
|
287
|
|
288 if (xacodec_query(xacodec_driver, &codec_hdr) == 0)
|
|
289 return(0);
|
|
290
|
|
291 // free(codec_hdr.anim_hdr);
|
|
292
|
|
293 xacodec_driver->decinfo = malloc(sizeof(XA_DEC_INFO));
|
|
294 xacodec_driver->decinfo->cmd = 0;
|
|
295 xacodec_driver->decinfo->skip_flag = 0;
|
|
296 xacodec_driver->decinfo->imagex = xacodec_driver->decinfo->xe = codec_hdr.x;
|
|
297 xacodec_driver->decinfo->imagey = xacodec_driver->decinfo->ye = codec_hdr.y;
|
|
298 xacodec_driver->decinfo->imaged = codec_hdr.depth;
|
|
299 xacodec_driver->decinfo->chdr = NULL;
|
|
300 xacodec_driver->decinfo->map_flag = 0; /* xaFALSE */
|
|
301 xacodec_driver->decinfo->map = NULL;
|
|
302 xacodec_driver->decinfo->xs = xacodec_driver->decinfo->ys = 0;
|
|
303 xacodec_driver->decinfo->special = 0;
|
|
304 xacodec_driver->decinfo->extra = codec_hdr.extra;
|
|
305
|
2377
|
306 // vidinfo->our_out_buffer = malloc(codec_hdr.y * codec_hdr.x * ((codec_hdr.depth+7)/8));
|
2384
|
307 // vidinfo->our_out_buffer = malloc(codec_hdr.y * codec_hdr.x * codec_hdr.depth);
|
|
308 xacodec_driver->image.out_fmt=out_format;
|
|
309 xacodec_driver->image.bpp=codec_hdr.depth;
|
|
310 xacodec_driver->image.width=codec_hdr.x;
|
|
311 xacodec_driver->image.height=codec_hdr.y;
|
2387
|
312 xacodec_driver->image.mem=malloc(codec_hdr.y * ((codec_hdr.x+3)&(~3)) * ((codec_hdr.depth+7)/8));
|
2372
|
313
|
2377
|
314 // printf("out_buf size: %d\n", codec_hdr.y * codec_hdr.x * codec_hdr.depth);
|
2372
|
315
|
2384
|
316 #if 0
|
2372
|
317 if (vidinfo->our_out_buffer == NULL)
|
|
318 {
|
2382
|
319 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "cannot allocate memory for output: %s",
|
2372
|
320 strerror(errno));
|
|
321 return(0);
|
|
322 }
|
2384
|
323 #endif
|
2372
|
324
|
2382
|
325 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "extra: %08x - %dx%d %dbit\n", codec_hdr.extra,
|
2372
|
326 codec_hdr.x, codec_hdr.y, codec_hdr.depth);
|
|
327 return(1);
|
|
328 }
|
|
329
|
|
330 #define ACT_DLT_NORM 0x00000000
|
|
331 #define ACT_DLT_BODY 0x00000001
|
|
332 #define ACT_DLT_XOR 0x00000002
|
|
333 #define ACT_DLT_NOP 0x00000004
|
|
334 #define ACT_DLT_MAPD 0x00000008
|
|
335 #define ACT_DLT_DROP 0x00000010
|
|
336 #define ACT_DLT_BAD 0x80000000
|
|
337
|
|
338 // unsigned int (*dec_func)(unsigned char *image, unsigned char *delta,
|
|
339 // unsigned int dsize, XA_DEC_INFO *dec_info);
|
|
340
|
2384
|
341 xacodec_image_t* xacodec_decode_frame(uint8_t *frame, int frame_size, int skip_flag)
|
2372
|
342 {
|
|
343 unsigned int ret;
|
|
344 int i;
|
2387
|
345 xacodec_image_t *image=&xacodec_driver->image;
|
2384
|
346
|
2372
|
347 if (skip_flag > 0)
|
|
348 printf("frame will be dropped..\n");
|
|
349
|
|
350 xacodec_driver->decinfo->skip_flag = skip_flag;
|
|
351
|
2387
|
352 image->planes[0]=image->mem;
|
|
353 image->stride[0]=image->width;
|
|
354 image->stride[1]=image->stride[2]=image->width/2;
|
|
355 switch(image->out_fmt){
|
|
356 case IMGFMT_YV12:
|
|
357 image->planes[2]=image->planes[0]+image->width*image->height;
|
|
358 image->planes[1]=image->planes[2]+image->width*image->height/4;
|
|
359 break;
|
|
360 case IMGFMT_I420:
|
|
361 case IMGFMT_IYUV:
|
|
362 image->planes[1]=image->planes[0]+image->width*image->height;
|
|
363 image->planes[2]=image->planes[1]+image->width*image->height/4;
|
|
364 break;
|
|
365 }
|
|
366
|
2384
|
367 // printf("frame: %08x (size: %d) - dest: %08x\n", frame, frame_size, dest);
|
|
368
|
|
369 ret = xacodec_driver->dec_func((uint8_t*)&xacodec_driver->image, frame, frame_size, xacodec_driver->decinfo);
|
2372
|
370
|
2384
|
371 // printf("ret: %lu : ", ret);
|
2372
|
372
|
2384
|
373 #if 0
|
2372
|
374 for (i = 0; i < 10; i++)
|
|
375 {
|
|
376 if (frame[i] != dest[i])
|
|
377 printf("%d: [%02x] != [%02x] ", i, frame[i], dest[i]);
|
|
378 else
|
|
379 printf("%d: [%02x] ", frame[i]);
|
|
380 }
|
2384
|
381 #endif
|
2372
|
382
|
|
383 if (ret == ACT_DLT_NORM)
|
|
384 {
|
|
385 printf("norm\n");
|
2384
|
386 return &xacodec_driver->image;
|
2372
|
387 }
|
|
388
|
|
389 /*
|
|
390 if (!(ret & ACT_DLT_MAPD))
|
|
391 xacodec_driver->decinfo->map_flag = 0;
|
|
392 else
|
|
393 {
|
|
394 xacodec_driver->decinfo->map_flag = 1;
|
|
395 xacodec_driver->decinfo->map = ...
|
|
396 }
|
|
397 */
|
|
398
|
|
399 if (ret & ACT_DLT_NOP)
|
|
400 {
|
|
401 printf("nop\n");
|
2384
|
402 return NULL; /* dst = 0 */
|
2372
|
403 }
|
|
404
|
|
405 if (ret & ACT_DLT_DROP) /* by skip frames and errors */
|
|
406 {
|
|
407 printf("drop\n");
|
2384
|
408 return NULL;
|
2372
|
409 }
|
|
410
|
|
411
|
|
412 if (ret & ACT_DLT_BAD)
|
|
413 {
|
|
414 printf("bad\n");
|
2384
|
415 return NULL;
|
2372
|
416 }
|
|
417
|
|
418 if (ret & ACT_DLT_BODY)
|
|
419 {
|
|
420 printf("body\n");
|
2384
|
421 return NULL;
|
2372
|
422 }
|
|
423
|
|
424 if (ret & ACT_DLT_XOR)
|
|
425 {
|
|
426 printf("xor\n");
|
2384
|
427 return &xacodec_driver->image;
|
2372
|
428 }
|
|
429
|
2384
|
430 return NULL;
|
2372
|
431 }
|
|
432
|
|
433 int xacodec_exit()
|
|
434 {
|
2382
|
435 int i;
|
|
436 void (*close_func)();
|
|
437
|
|
438 for (i=0; i < XA_CLOSE_FUNCS; i++)
|
|
439 if (xacodec_driver->close_func[i])
|
|
440 {
|
|
441 close_func = xacodec_driver->close_func[i];
|
|
442 close_func();
|
|
443 }
|
|
444 // if (xacodec_driver->close_func)
|
|
445 // xacodec_driver->close_func();
|
2372
|
446 dlclose(xacodec_driver->file_handler);
|
|
447 if (xacodec_driver->decinfo != NULL)
|
|
448 free(xacodec_driver->decinfo);
|
|
449 if (xacodec_driver != NULL)
|
|
450 free(xacodec_driver);
|
|
451 return(TRUE);
|
|
452 }
|
2373
|
453
|
|
454
|
|
455 /* *** XANIM SHIT *** */
|
|
456 /* like loader/win32.c - mini XANIM library */
|
|
457
|
2382
|
458
|
|
459 unsigned long XA_Time_Read()
|
|
460 {
|
2384
|
461 return GetTimer(); //(GetRelativeTime());
|
2382
|
462 }
|
|
463
|
|
464 void XA_dummy()
|
|
465 {
|
|
466 XA_Print("dummy() called");
|
|
467 }
|
|
468
|
2373
|
469 typedef struct
|
|
470 {
|
|
471 unsigned char r0, g0, b0;
|
|
472 unsigned char r1, g1, b1;
|
|
473 unsigned char r2, g2, b2;
|
|
474 unsigned char r3, g3, b3;
|
|
475 unsigned int clr0_0, clr0_1, clr0_2, clr0_3;
|
|
476 unsigned int clr1_0, clr1_1, clr1_2, clr1_3;
|
|
477 unsigned int clr2_0, clr2_1, clr2_2, clr2_3;
|
|
478 unsigned int clr3_0, clr3_1, clr3_2, clr3_3;
|
|
479 } XA_2x2_Color;
|
|
480
|
|
481 #define ip_OUT_2x2_1BLK(ip, CAST, cmap2x2, rinc) { register CAST d0, d1; \
|
|
482 *ip++ = d0 = (CAST)(cmap2x2->clr0_0); *ip++ = d0; \
|
|
483 *ip++ = d1 = (CAST)(cmap2x2->clr1_0); *ip = d1; \
|
|
484 ip += rinc; \
|
|
485 *ip++ = d0; *ip++ = d0; *ip++ = d1; *ip = d1; ip += rinc; \
|
|
486 *ip++ = d0 = (CAST)(cmap2x2->clr2_0); *ip++ = d0; \
|
|
487 *ip++ = d1 = (CAST)(cmap2x2->clr3_0); *ip = d1; \
|
|
488 ip += rinc; *ip++ = d0; *ip++ = d0; *ip++ = d1; *ip++ = d1; }
|
|
489
|
|
490 #define ip_OUT_2x2_2BLKS(ip, CAST, c2x2map0, c2x2map1, rinc) { \
|
|
491 *ip++ = (CAST)(c2x2map0->clr0_0); \
|
|
492 *ip++ = (CAST)(c2x2map0->clr1_0); \
|
|
493 *ip++ = (CAST)(c2x2map1->clr0_0); \
|
|
494 *ip = (CAST)(c2x2map1->clr1_0); ip += rinc; \
|
|
495 *ip++ = (CAST)(c2x2map0->clr2_0); \
|
|
496 *ip++ = (CAST)(c2x2map0->clr3_0); \
|
|
497 *ip++ = (CAST)(c2x2map1->clr2_0); \
|
|
498 *ip = (CAST)(c2x2map1->clr3_0); }
|
|
499
|
2387
|
500 void XA_2x2_OUT_1BLK_clr8(unsigned char *image_p, unsigned int x, unsigned int y,
|
2373
|
501 unsigned int imagex, XA_2x2_Color *cmap2x2)
|
|
502 {
|
2387
|
503 //unsigned int row_inc = imagex - 3;
|
|
504 xacodec_image_t *image=(xacodec_image_t*)image_p;
|
2373
|
505
|
2381
|
506 // XA_Print("XA_2x2_OUT_1BLK_clr8('image: %08x', 'x: %d', 'y: %d', 'imagex: %d', 'cmap2x2: %08x')",
|
|
507 // image, x, y, imagex, cmap2x2);
|
|
508 //ip_OUT_2x2_1BLK(ip, unsigned char, cmap2x2, row_inc);
|
|
509
|
|
510 // simplified yv12->rgb32bpp converter (Y only)
|
2387
|
511 // ip[0]=ip[1]=ip[2]=cmap2x2->clr0_0;
|
|
512 // ip[4]=ip[5]=ip[6]=cmap2x2->clr1_0;
|
|
513 // ip+=4*imagex;
|
|
514 // ip[0]=ip[1]=ip[2]=cmap2x2->clr2_0;
|
|
515 // ip[4]=ip[5]=ip[6]=cmap2x2->clr3_0;
|
|
516
|
|
517 image->planes[0][(x+0)+(y+0)*image->stride[0]]=cmap2x2->clr0_0;
|
|
518 image->planes[0][(x+1)+(y+0)*image->stride[0]]=cmap2x2->clr1_0;
|
|
519 image->planes[0][(x+0)+(y+1)*image->stride[0]]=cmap2x2->clr2_0;
|
|
520 image->planes[0][(x+1)+(y+1)*image->stride[0]]=cmap2x2->clr3_0;
|
|
521
|
|
522 image->planes[1][(x>>1)+(y>>1)*image->stride[1]]=cmap2x2->clr0_1;
|
|
523 image->planes[2][(x>>1)+(y>>1)*image->stride[2]]=cmap2x2->clr0_2;
|
2381
|
524
|
2373
|
525 }
|
|
526
|
|
527 void XA_2x2_OUT_4BLKS_clr8(unsigned char *image, unsigned int x, unsigned int y,
|
|
528 unsigned int imagex, XA_2x2_Color *cm0, XA_2x2_Color *cm1, XA_2x2_Color *cm2,
|
|
529 XA_2x2_Color *cm3)
|
|
530 {
|
2381
|
531 /*
|
2373
|
532 unsigned int row_inc = imagex - 3;
|
|
533 unsigned char *ip = (unsigned char *)(image + y * imagex + x);
|
|
534
|
2381
|
535 XA_Print("XA_2x2_OUT_4BLKS_clr8('image: %08x', 'x: %d', 'y: %d', 'imagex: %d', 'cm0: %08x', 'cm1: %08x', 'cm2: %08x', 'cm3: %08x')",
|
2373
|
536 image, x, y, imagex, cm0, cm1, cm2, cm3);
|
|
537 ip_OUT_2x2_2BLKS(ip, unsigned char, cm0, cm1, row_inc);
|
|
538 ip += row_inc;
|
|
539 ip_OUT_2x2_2BLKS(ip, unsigned char, cm2, cm3, row_inc);
|
2381
|
540 */
|
|
541
|
|
542 XA_2x2_OUT_1BLK_clr8(image,x,y,imagex,cm0);
|
|
543 XA_2x2_OUT_1BLK_clr8(image,x+2,y,imagex,cm1);
|
|
544 XA_2x2_OUT_1BLK_clr8(image,x,y+2,imagex,cm2);
|
|
545 XA_2x2_OUT_1BLK_clr8(image,x+2,y+2,imagex,cm3);
|
|
546
|
|
547 }
|
|
548
|
2373
|
549
|
|
550 void *YUV2x2_Blk_Func(unsigned int image_type, int blks, unsigned int dith_flag)
|
|
551 {
|
|
552 void (*color_func)();
|
|
553
|
2381
|
554 // XA_Print("YUV2x2_Blk_Func('image_type: %d', 'blks: %d', 'dith_flag: %d')",
|
|
555 // image_type, blks, dith_flag);
|
2373
|
556
|
|
557 if (blks == 1)
|
|
558 {
|
|
559 switch(image_type)
|
|
560 {
|
|
561 default:
|
|
562 color_func = XA_2x2_OUT_1BLK_clr8;
|
|
563 break;
|
|
564 }
|
|
565 }
|
2381
|
566 else if(blks == 4)
|
2373
|
567 {
|
|
568 switch(image_type)
|
|
569 {
|
|
570 default:
|
|
571 color_func = XA_2x2_OUT_4BLKS_clr8;
|
|
572 break;
|
|
573 }
|
|
574 }
|
2381
|
575 else printf("Ajajj!\n");
|
2373
|
576
|
2381
|
577 // XA_Print("YUV2x2_Blk_Func -> %08x", color_func);
|
2373
|
578
|
|
579 return((void *)color_func);
|
|
580 }
|
|
581
|
2381
|
582
|
|
583 /*****************************************************************************
|
|
584 * Take Four Y's and UV and put them into a 2x2 Color structure.
|
|
585 * Convert to display clr.
|
|
586 ******************/
|
|
587
|
|
588 void XA_YUV_2x2_clr(cmap2x2,Y0,Y1,Y2,Y3,U,V,map_flag,map,chdr)
|
|
589 XA_2x2_Color *cmap2x2;
|
|
590 xaULONG Y0,Y1,Y2,Y3,U,V;
|
|
591 xaULONG map_flag,*map;
|
|
592 XA_CHDR *chdr;
|
|
593 { xaLONG cr,cg,cb; xaULONG r,g,b;
|
|
594
|
|
595 // printf("XA_YUV_2x2_clr(%p [%d,%d,%d,%d][%d][%d] %d %p %p)\n",
|
|
596 // cmap2x2,Y0,Y1,Y2,Y3,U,V,map_flag,map,chdr);
|
|
597
|
|
598 cmap2x2->clr0_0=Y0;
|
|
599 cmap2x2->clr1_0=Y1;
|
|
600 cmap2x2->clr2_0=Y2;
|
|
601 cmap2x2->clr3_0=Y3;
|
|
602 cmap2x2->clr0_1=U;
|
|
603 cmap2x2->clr0_2=V;
|
|
604
|
|
605 // cmap2x2->clr0_0 = 0x1111;
|
|
606 // cmap2x2->clr1_0 = 0x3535;
|
|
607 // cmap2x2->clr2_0 = 0x7272;
|
|
608 // cmap2x2->clr3_0 = 0xbfbf;
|
|
609
|
|
610 /*
|
|
611 xaUBYTE *rl = xa_byte_limit;
|
|
612
|
|
613 cr = YUV2_VR_tab[V];
|
|
614 cb = YUV2_UB_tab[U];
|
|
615 cg = YUV2_UG_tab[U] + YUV2_VG_tab[V];
|
|
616
|
|
617 YUV_TO_RGB(Y0,cr,cg,cb,rl,r,g,b);
|
|
618 cmap2x2->clr0_0 = XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
|
|
619 YUV_TO_RGB(Y1,cr,cg,cb,rl,r,g,b);
|
|
620 cmap2x2->clr1_0 = XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
|
|
621 YUV_TO_RGB(Y2,cr,cg,cb,rl,r,g,b);
|
|
622 cmap2x2->clr2_0 = XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
|
|
623 YUV_TO_RGB(Y3,cr,cg,cb,rl,r,g,b);
|
|
624 cmap2x2->clr3_0 = XA_RGB24_To_CLR32(r,g,b,map_flag,map,chdr);
|
|
625 */
|
2377
|
626 }
|
|
627
|
2381
|
628
|
|
629
|
2373
|
630 void *YUV2x2_Map_Func(unsigned int image_type, unsigned int dith_type)
|
|
631 {
|
2381
|
632 // XA_Print("YUV2x2_Map_Func('image_type: %d', 'dith_type: %d')",
|
|
633 // image_type, dith_type);
|
|
634 if(image_type!=0)printf("izeeeeee!\n");
|
|
635 return (void*)XA_YUV_2x2_clr;
|
2373
|
636 }
|
|
637
|
|
638
|
|
639 int XA_Gen_YUV_Tabs(XA_ANIM_HDR *anim_hdr)
|
|
640 {
|
|
641 XA_Print("XA_Gen_YUV_Tabs('anim_hdr: %08x')", anim_hdr);
|
|
642
|
|
643 // XA_Print("anim type: %d - img[x: %d, y: %d, c: %d, d: %d]",
|
|
644 // anim_hdr->anim_type, anim_hdr->imagex, anim_hdr->imagey,
|
|
645 // anim_hdr->imagec, anim_hdr->imaged);
|
|
646 }
|
|
647
|
|
648 void JPG_Setup_Samp_Limit_Table(XA_ANIM_HDR *anim_hdr)
|
|
649 {
|
|
650 XA_Print("JPG_Setup_Samp_Limit_Table('anim_hdr: %08x')", anim_hdr);
|
2381
|
651 // xa_byte_limit = jpg_samp_limit + (MAXJSAMPLE + 1);
|
2373
|
652 }
|
|
653
|
|
654 void JPG_Alloc_MCU_Bufs(XA_ANIM_HDR *anim_hdr, unsigned int width,
|
|
655 unsigned int height, unsigned int full_flag)
|
|
656 {
|
|
657 XA_Print("JPG_Alloc_MCU_Bufs('anim_hdr: %08x', 'width: %d', 'height: %d', 'full_flag: %d')",
|
|
658 anim_hdr, width, height, full_flag);
|
|
659 }
|
|
660
|
|
661 typedef struct
|
|
662 {
|
|
663 unsigned char *Ybuf;
|
|
664 unsigned char *Ubuf;
|
|
665 unsigned char *Vbuf;
|
|
666 unsigned char *the_buf;
|
|
667 unsigned int the_buf_size;
|
|
668 unsigned short y_w, y_h;
|
|
669 unsigned short uv_w, uv_h;
|
|
670 } YUVBufs;
|
|
671
|
|
672 typedef struct
|
|
673 {
|
|
674 unsigned long Uskip_mask;
|
|
675 long *YUV_Y_tab;
|
|
676 long *YUV_UB_tab;
|
|
677 long *YUV_VR_tab;
|
|
678 long *YUV_UG_tab;
|
|
679 long *YUV_VG_tab;
|
|
680 } YUVTabs;
|
|
681
|
|
682 #define XA_IMTYPE_RGB 0x0001
|
|
683
|
|
684 void XA_YUV1611_To_RGB(unsigned char *image, unsigned int imagex, unsigned int imagey,
|
|
685 unsigned int i_x, unsigned int i_y, YUVBufs *yuv_bufs, YUVTabs *yuv_tabs,
|
|
686 unsigned int map_flag, unsigned int *map, XA_CHDR *chdr)
|
|
687 {
|
|
688 XA_Print("XA_YUV1611_To_RGB('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')",
|
|
689 image, imagex, imagey, i_x, i_y, yuv_bufs, yuv_tabs, map_flag, map, chdr);
|
|
690 }
|
|
691
|
|
692 void XA_YUV1611_To_CLR8(unsigned char *image, unsigned int imagex, unsigned int imagey,
|
|
693 unsigned int i_x, unsigned int i_y, YUVBufs *yuv_bufs, YUVTabs *yuv_tabs,
|
|
694 unsigned int map_flag, unsigned int *map, XA_CHDR *chdr)
|
|
695 {
|
|
696 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')",
|
|
697 image, imagex, imagey, i_x, i_y, yuv_bufs, yuv_tabs, map_flag, map, chdr);
|
|
698 }
|
|
699
|
|
700 void *XA_YUV1611_Func(unsigned int image_type)
|
|
701 {
|
|
702 void (*color_func)();
|
|
703
|
|
704 XA_Print("XA_YUV1611_Func('image_type: %d')", image_type);
|
|
705
|
|
706 switch(image_type)
|
|
707 {
|
|
708 case XA_IMTYPE_RGB:
|
|
709 color_func = XA_YUV1611_To_RGB;
|
|
710 break;
|
|
711 default:
|
|
712 color_func = XA_YUV1611_To_CLR8;
|
|
713 break;
|
|
714 }
|
|
715
|
|
716 return((void *)color_func);
|
|
717 }
|
|
718
|
|
719 /* YUV 41 11 11 routines */
|
|
720 void XA_YUV411111_To_RGB(unsigned char *image, unsigned int imagex, unsigned int imagey,
|
|
721 unsigned int i_x, unsigned int i_y, YUVBufs *yuv_bufs, YUVTabs *yuv_tabs,
|
|
722 unsigned int map_flag, unsigned int *map, XA_CHDR *chdr)
|
|
723 {
|
|
724 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')",
|
|
725 image, imagex, imagey, i_x, i_y, yuv_bufs, yuv_tabs, map_flag, map, chdr);
|
|
726 }
|
|
727
|
|
728
|
|
729 void *XA_YUV411111_Func(unsigned int image_type)
|
|
730 {
|
|
731 void (*color_func)();
|
|
732
|
|
733 XA_Print("XA_YUV411111_Func('image_type: %d')", image_type);
|
|
734
|
|
735 switch(image_type)
|
|
736 {
|
|
737 case XA_IMTYPE_RGB: color_func = XA_YUV411111_To_RGB; break;
|
|
738 }
|
|
739
|
|
740 return((void *)color_func);
|
|
741 }
|
|
742
|
2384
|
743 void XA_YUV221111_To_CLR8(image_p,imagex,imagey,i_x,i_y,yuv,yuv_tabs,map_flag,map,chdr)
|
|
744 xaUBYTE *image_p; xaULONG imagex,imagey,i_x,i_y;
|
2383
|
745 YUVBufs *yuv; YUVTabs *yuv_tabs;
|
|
746 xaULONG map_flag,*map; XA_CHDR *chdr;
|
|
747 {
|
2384
|
748 xacodec_image_t *image=(xacodec_image_t*)image_p;
|
|
749
|
|
750 #if 0
|
|
751 printf("XA_YUV221111_To_CLR8(%p %dx%d %d;%d [%dx%d] %p %p %d %p %p)\n",
|
|
752 image,imagex,imagey,i_x,i_y, image->width,image->height,
|
|
753 yuv,yuv_tabs,map_flag,map,chdr);
|
2383
|
754
|
|
755 printf("YUV: %p %p %p %X (%X) %Xx%X %Xx%X\n",
|
|
756 yuv->Ybuf,yuv->Ubuf,yuv->Vbuf,yuv->the_buf,yuv->the_buf_size,
|
|
757 yuv->y_w,yuv->y_h,yuv->uv_w,yuv->uv_h);
|
2384
|
758 #endif
|
2383
|
759
|
2384
|
760 if(imagex==image->width && imagey==image->height){
|
|
761 // printf("Direct render!!!\n");
|
|
762 image->planes[0]=yuv->Ybuf;
|
|
763 if(image->out_fmt==IMGFMT_YV12){
|
|
764 image->planes[1]=yuv->Ubuf;
|
|
765 image->planes[2]=yuv->Vbuf;
|
|
766 } else {
|
|
767 image->planes[1]=yuv->Vbuf;
|
|
768 image->planes[2]=yuv->Ubuf;
|
|
769 }
|
|
770 image->stride[0]=imagex; // yuv->y_w
|
|
771 image->stride[1]=image->stride[2]=imagex/2; // yuv->uv_w
|
|
772 } else {
|
|
773 int y;
|
|
774 printf("partial YV12 not implemented!!!!!!\n");
|
2387
|
775
|
2384
|
776 }
|
|
777
|
|
778 // memcpy(image,yuv->Ybuf,imagex*imagey);
|
|
779 // memcpy(image+imagex*imagey,yuv->Vbuf,imagex*imagey/4);
|
|
780 // memcpy(image+imagex*imagey*5/4,yuv->Ubuf,imagex*imagey/4);
|
2383
|
781
|
|
782 /*
|
|
783 unsigned char *Ybuf;
|
|
784 unsigned char *Ubuf;
|
|
785 unsigned char *Vbuf;
|
|
786 unsigned char *the_buf;
|
|
787 unsigned int the_buf_size;
|
|
788 unsigned short y_w, y_h;
|
|
789 unsigned short uv_w, uv_h;
|
|
790 */
|
|
791
|
|
792 }
|
|
793
|
2382
|
794 /* YUV 22 11 11 routines */
|
|
795 void *XA_YUV221111_Func(unsigned int image_type)
|
|
796 {
|
|
797 XA_Print("XA_YUV221111_Func('image_type: %d')", image_type);
|
2383
|
798 return((void *)XA_YUV221111_To_CLR8);
|
2382
|
799 }
|
2373
|
800
|
|
801 YUVBufs jpg_YUVBufs;
|
|
802 YUVTabs def_yuv_tabs;
|
|
803
|
|
804 /* *** EOF XANIM SHIT *** */
|