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