1 
2 /*
3  * xanim.h
4  *
5  * Copyright (C) 1990-1998,1999 by Mark Podlipec.
6  * All rights reserved.
7  *
8  * This software may be freely used, copied and redistributed without
9  * fee for non-commerical purposes provided that this copyright
10  * notice is preserved intact on all copies.
11  *
12  * There is no warranty or other guarantee of fitness of this software.
13  * It is provided solely "as is". The author disclaims all
14  * responsibility and liability with respect to this software's usage
15  * or its effect upon hardware or computer systems.
16  *
17  */
18 #include <Xos.h>
19 #include <stdio.h>
20 #include <sys/types.h>
21 #include <stdio.h>
22 
23 #ifndef VMS
24 
25 #ifndef __QNX__
26 #include <sys/param.h>
27 #include <memory.h>
28 #endif
29 
30 #ifdef __bsdi__
31 #include <sys/malloc.h>
32 #else
33 #ifndef __CYGWIN32__
34 #ifndef __FreeBSD__
35 #include <malloc.h>
36 #endif
37 #endif
38 #endif
39 
40 
41 #include <unistd.h>
42 #else
43 #include <unixio.h>
44 #endif
45 #include <stdlib.h>
46 #include <Xlib.h>
47 #include "xa_config.h"
48 
49 #ifdef XA_XTPOINTER
50 typedef void* XtPointer;
51 #endif
52 
53 #ifdef XA_PETUNIA
54 #define XA_REMOTE_CONTROL 1
55 #endif
56 
57 #ifdef XA_ATHENA
58 #define XA_REMOTE_CONTROL 1
59 #endif
60 
61 #ifdef XA_MOTIF
62 #define XA_REMOTE_CONTROL 1
63 #endif
64 
65 /*
66  * Win32 utilizatizes same defines as MSDOS does
67  */
68 #ifdef _WIN32
69 #define MSDOS 1
70 #endif
71 
72 /*
73  * MSDOS and Win32 needs to be specifically told to open file for binary
74  * reading.  For VMS systems, specify "Stream_LF" mode for VAX C.
75  */
76 #ifdef MSDOS
77 #define XA_OPEN_MODE "rb"
78 #else
79 #ifdef VMS
80 #define XA_OPEN_MODE "r","ctx=stm"
81 #else
82 #define XA_OPEN_MODE "r"
83 #endif
84 #endif
85 
86 typedef int		xaLONG;
87 typedef unsigned int	xaULONG;
88 typedef short		xaSHORT;
89 typedef unsigned short	xaUSHORT;
90 typedef char		xaBYTE;
91 typedef unsigned char	xaUBYTE;
92 
93 #define xaFALSE  0
94 #define xaTRUE   1
95 #define xaNOFILE 2
96 #define xaERROR  3
97 #define xaPAUSE  4
98 
99 
100 #define xaMIN(x,y)   ( ((x)>(y))?(y):(x) )
101 #define xaMAX(x,y)   ( ((x)>(y))?(x):(y) )
102 #define xaABS(x)     (((x)<0)?(-(x)):(x))
103 
104 /* X11 variables */
105 
106 #define XA_GRAYSCALE	0x06
107 #define XA_STATICGRAY	0x03
108 #define XA_PSEUDOCOLOR	0x14
109 #define XA_STATICCOLOR	0x11
110 #define XA_DIRECTCOLOR	0x18
111 #define XA_TRUECOLOR	0x19
112 #define XA_MONOCHROME	0x00
113 
114 #define XA_X11_STATIC	0x01
115 #define XA_X11_GRAY	0x02
116 #define XA_X11_CMAP	0x04
117 #define XA_X11_TRUE	0x08
118 #define XA_X11_COLOR	0x10
119 
120 extern xaLONG x11_depth;
121 extern xaLONG x11_class;
122 extern xaLONG x11_bytes_pixel;
123 extern xaLONG x11_bits_per_pixel;
124 extern xaLONG x11_bitmap_pad;
125 extern xaLONG x11_bitmap_unit;
126 extern xaLONG x11_bit_order;
127 extern xaLONG x11_byte_order;
128 extern xaLONG xam_byte_order;
129 extern xaLONG x11_byte_mismatch;
130 extern xaLONG x11_pack_flag;
131 extern xaLONG x11_cmap_flag;
132 extern xaLONG x11_cmap_size;
133 extern xaLONG x11_disp_bits;
134 extern xaLONG x11_cmap_type;
135 extern xaLONG x11_depth_mask;
136 extern xaLONG x11_display_type;
137 extern xaLONG x11_red_mask;
138 extern xaLONG x11_green_mask;
139 extern xaLONG x11_blue_mask;
140 extern xaLONG x11_red_shift;
141 extern xaLONG x11_green_shift;
142 extern xaLONG x11_blue_shift;
143 extern xaLONG x11_red_bits;
144 extern xaLONG x11_green_bits;
145 extern xaLONG x11_blue_bits;
146 extern xaLONG x11_black;
147 extern xaLONG x11_white;
148 extern xaLONG x11_verbose_flag;
149 extern xaULONG x11_kludge_1;
150 extern xaLONG xa_root;
151 
152 #define XA_MSBIT_1ST  1
153 #define XA_LSBIT_1ST  0
154 
155 #define XA_MSBYTE_1ST  1
156 #define XA_LSBYTE_1ST  0
157 
158 extern xaLONG xa_anim_holdoff;
159 extern xaLONG xa_anim_status;
160 
161 /*------*/
162 #define XA_NEXT_MASK	0x01
163 #define XA_STOP_MASK	0x02
164 #define XA_STEP_MASK	0x04
165 #define XA_RUN_MASK	0x08
166 #define XA_ISTP_MASK	0x10
167 #define XA_FILE_MASK	0x20
168 #define XA_CLEAR_MASK	0x01
169 #define XA_BEGIN_MASK	0x01
170 /*------*/
171 #define XA_UNSTARTED   0x00
172 #define XA_BEGINNING   0x80
173 #define XA_STOP_PREV   0x02
174 #define XA_STOP_NEXT   0x03
175 #define XA_STEP_PREV   0x04
176 #define XA_STEP_NEXT   0x05
177 #define XA_RUN_PREV    0x08
178 #define XA_RUN_NEXT    0x09
179 #define XA_ISTP_PREV   0x14
180 #define XA_ISTP_NEXT   0x15
181 #define XA_FILE_PREV   0x24
182 #define XA_FILE_NEXT   0x25
183 
184 #define XA_SHOW_NORM   0
185 #define XA_SHOW_SKIP   1
186 
187 #define XA_SPEED_NORM (1<<4)
188 #define XA_SPEED_MIN  (1)
189 #define XA_SPEED_MAX  (1<<8)
190 #define XA_SPEED_ADJ(x,s)  (((x)*(s))>>4)
191 
192 #define NOFILE_ANIM   0xffff
193 #define UNKNOWN_ANIM  0
194 /*************************** VIDEO FILES *************/
195 #define XA_IFF_ANIM      1
196 #define XA_FLI_ANIM      2
197 #define XA_GIF_ANIM      3
198 #define XA_TXT_ANIM      4
199 #define XA_FADE_ANIM     5
200 #define XA_DL_ANIM       6
201 #define XA_JFIF_ANIM     7
202 #define XA_PFX_ANIM      8
203 #define XA_SET_ANIM      9
204 #define XA_RLE_ANIM     10
205 #define XA_AVI_ANIM     11
206 #define XA_OLDQT_ANIM	12
207 #define XA_MPG_ANIM     13
208 #define XA_JMOV_ANIM    14
209 #define XA_ARM_ANIM     15
210 #define XA_SGI_ANIM     16
211 #define XA_RAW_ANIM     17
212 #define XA_J6I_ANIM     18
213 #define XA_QT_ANIM	19
214 /*************************** AUDIO FILES *************/
215 #define XA_WAV_ANIM     128
216 #define XA_AU_ANIM      129
217 #define XA_8SVX_ANIM    130
218 
219 typedef struct
220 {
221   xaUSHORT red,green,blue,gray;
222 } ColorReg;
223 
224 typedef struct XA_ACTION_STRUCT
225 {
226  xaLONG type;		/* type of action */
227  xaLONG cmap_rev;          /* rev of cmap */
228  xaUBYTE *data;		/* data ptr */
229  struct XA_ACTION_STRUCT *next;
230  struct XA_CHDR_STRUCT *chdr;
231  ColorReg *h_cmap;	/* For IFF HAM images */
232  xaULONG *map;
233  struct XA_ACTION_STRUCT *next_same_chdr; /*ptr to next action with same cmap*/
234 } XA_ACTION;
235 
236 typedef struct XA_CHDR_STRUCT
237 {
238  xaLONG rev;
239  ColorReg *cmap;
240  xaULONG csize,coff;
241  xaULONG *map;
242  xaULONG msize,moff;
243  struct XA_CHDR_STRUCT *next;
244  XA_ACTION *acts;
245  struct XA_CHDR_STRUCT *new_chdr;
246 } XA_CHDR;
247 
248 typedef struct
249 {
250  xaULONG csize,coff;
251  xaUBYTE data[4];
252 } ACT_CMAP_HDR;
253 
254 typedef struct XA_FRAME_STRUCT
255 {
256   XA_ACTION *act;	/* ptr to relevant Action. */
257   xaLONG time_dur;	/* duration of Frame in ms. */
258   xaLONG zztime;		/* time at start of Frame in ms. */
259 } XA_FRAME;
260 
261 typedef struct
262 {
263   xaULONG count;    /* number of loops */
264   xaLONG cnt_var;   /* var to keep track of loops */
265   xaULONG end_frame; /* last frame of loop */
266 } ACT_BEG_LP_HDR;
267 
268 typedef struct ACT_END_LP_STRUCT
269 {
270   xaULONG *count;       /* points back to beg_lp->count */
271   xaLONG *cnt_var;      /* points back to beg_lp->cnt_var */
272   xaULONG begin_frame;  /* first frame of loop */
273   xaULONG *end_frame;   /* points back to beg_lp->end_frame */
274   XA_ACTION *prev_end_act; /* used to nest loops during creation */
275 } ACT_END_LP_HDR;
276 
277 /** AUDIO SECTION ************************/
278 
279 typedef struct
280 {
281   xaULONG enable;
282   xaULONG mute;
283   xaLONG  volume;
284   xaULONG newvol;
285   xaULONG port;
286   xaULONG playrate;
287   xaULONG divtest;
288   xaULONG synctst;
289   xaULONG fromfile;
290   xaULONG bufferit;
291   double scale;
292   char *device;
293 } XA_AUD_FLAGS;
294 
295 
296 /* POD temporary til complete overhaul */
297 #define XAAUD audiof
298 
299 #ifdef XA_SPARC_AUDIO
300 #define XA_AUDIO 1
301 #endif
302 #ifdef XA_MMS_AUDIO
303 #define XA_AUDIO 1
304 #endif
305 #ifdef XA_AIX_AUDIO
306 #define XA_AUDIO 1
307 #endif
308 #ifdef XA_NetBSD_AUDIO
309 #define XA_AUDIO 1
310 #endif
311 #ifdef XA_LINUX_AUDIO
312 #define XA_AUDIO 1
313 #endif
314 #ifdef XA_SGI_AUDIO
315 #define XA_AUDIO 1
316 #endif
317 #ifdef XA_HPDEV_AUDIO
318 #define XA_AUDIO 1
319 #endif
320 #ifdef XA_HP_AUDIO
321 #define XA_AUDIO 1
322 #endif
323 #ifdef XA_EWS_AUDIO
324 #define XA_AUDIO 1
325 #endif
326 #ifdef XA_SONY_AUDIO
327 #define XA_AUDIO 1
328 #endif
329 #ifdef XA_AF_AUDIO
330 #define XA_AUDIO 1
331 #endif
332 #ifdef XA_NAS_AUDIO
333 #define XA_AUDIO 1
334 #endif
335 #ifdef XA_TOWNS_AUDIO
336 #define XA_AUDIO 1
337 #endif
338 #ifdef XA_TOWNS8_AUDIO
339 #define XA_AUDIO 1
340 #endif
341 
342 
343 /* AUDIO PORT MASKS */
344 #define XA_AUDIO_PORT_INT	1
345 #define XA_AUDIO_PORT_HEAD	2
346 #define XA_AUDIO_PORT_EXT	4
347 #define XA_AUDIO_PORT_NONE	8
348 
349 #define XA_AUDIO_STEREO_MSK	0x000001
350 #define XA_AUDIO_BPS_2_MSK	0x000002
351 #define XA_AUDIO_BIGEND_MSK	0x000004
352 #define XA_AUDIO_INVALID	0x000000
353 #define XA_AUDIO_LINEAR		0x000010
354 #define XA_AUDIO_SIGNED		0x000020
355 #define XA_AUDIO_ULAW  		0x000030
356 #define XA_AUDIO_ADPCM		0x000040
357 #define XA_AUDIO_NOP  		0x000050
358 #define XA_AUDIO_ARMLAW		0x000060
359 #define XA_AUDIO_IMA4 		0x000070
360 #define XA_AUDIO_DVI  		0x000080
361 #define XA_AUDIO_GSM  		0x000090
362 #define XA_AUDIO_MSGSM 		0x0000A0
363 #define XA_AUDIO_ALAW  		0x0000B0
364 #define XA_AUDIO_TYPE_MASK  	0xfffff0
365 
366 /*NOTES:
367  * last ending is [1|2](BPS),[M|S](Mono/Stereo),[B|L](big/little endian)
368  */
369 
370 #define XA_AUDIO_LINEAR_1M	0x000010
371 #define XA_AUDIO_LINEAR_1S	0x000011
372 #define XA_AUDIO_LINEAR_2ML	0x000012
373 #define XA_AUDIO_LINEAR_2SL	0x000013
374 #define XA_AUDIO_LINEAR_2MB	0x000016
375 #define XA_AUDIO_LINEAR_2SB	0x000017
376 
377 #define XA_AUDIO_SIGNED_1M	0x000020
378 #define XA_AUDIO_SIGNED_1S	0x000021
379 #define XA_AUDIO_SIGNED_2ML	0x000022
380 #define XA_AUDIO_SIGNED_2SL	0x000023
381 #define XA_AUDIO_SIGNED_2MB	0x000026
382 #define XA_AUDIO_SIGNED_2SB	0x000027
383 
384 #define XA_AUDIO_SUN_AU		0x000030
385 #define XA_AUDIO_ULAWM 		0x000030
386 #define XA_AUDIO_ULAWS 		0x000031
387 
388 #define XA_AUDIO_ARMLAWM	0x000060
389 #define XA_AUDIO_ARMLAWS	0x000061
390 
391 #define XA_AUDIO_ADPCM_M	0x000040
392 #define XA_AUDIO_ADPCM_S	0x000041
393 
394 #define XA_AUDIO_IMA4_M 	0x000070
395 #define XA_AUDIO_IMA4_S 	0x000071
396 
397 #define XA_AUDIO_DVI_M		0x000080
398 #define XA_AUDIO_DVI_S		0x000081
399 
400 #define XA_AUDIO_GSM_M		0x000090
401 #define XA_AUDIO_MSGSM_M	0x0000A0
402 
403 #define XA_AUDIO_ALAWM 		0x0000B0
404 #define XA_AUDIO_ALAWS 		0x0000B1
405 
406 #define XA_AUDIO_FILE_FLAG   0x0001
407 
408 typedef struct XA_SND_STRUCT
409 {
410   xaULONG type;		/* type, chans, bps, */
411   xaULONG flag;		/* flags */
412   xaLONG  fpos;		/* starting file position */
413   xaULONG itype;		/* input sample type */
414   xaULONG ifreq;		/* input sample freq */
415   xaULONG hfreq;		/* closest hardware freq */
416   xaULONG inc;		/* inc for i to h converstion << 24 */
417   xaULONG tot_bytes;	/* total size in bytes*/
418   xaULONG tot_samps;	/* total samples in chunk */
419   xaULONG inc_cnt;	/* dynamic var for freq conv */
420   xaULONG bit_cnt;	/* dynamic var for partial bytes - not used yet */
421   xaULONG byte_cnt;	/* dynamic var for counting bytes */
422   xaULONG samp_cnt;	/* samples used so far */
423   xaULONG blk_size;	/* size of blocks - used by some codecs */
424   xaULONG blk_cnt;	/* dynamic var for cnting inside a block */
425   xaULONG (*delta)();	/* conversion routine */
426   xaULONG snd_time;	/* time at start of snd struct ms */
427   xaULONG ch_time;	/* chunk time ms */
428   xaULONG ch_timelo;	/* chunk time fractional ms */
429   xaULONG ch_size;	/* size of chunk */
430   xaULONG spec;		/* used by decoder */
431   xaLONG dataL;		/* data Left channel */
432   xaLONG dataR;		/* data Right channel */
433   xaUBYTE *snd;		/* sound if present */
434   struct XA_SND_STRUCT *prev;
435   struct XA_SND_STRUCT *next;
436 } XA_SND;
437 
438 #define XA_SND_CHUNK_SIZE 65536
439 
440 typedef struct
441 {
442   char		*file;		/* is this a duplication of xanim_hdr->file?*/
443   FILE		*fin;           /* buffer file */
444   int		csock;          /* control socket */
445   int		dsock;          /* data socket */
446   xaULONG	fpos;		/* bytes read so far */
447   xaLONG	eof;		/* size of file - set by client */
448   xaULONG	err_flag;	/* set on errors and/or EOF */
449   xaULONG	type_flag;	/* random/sequential access? */
450   xaULONG	load_flag;	/* from file, from memory, buffered? */
451   xaULONG	(*Open_File)();
452   xaULONG	(*Close_File)();
453   xaULONG	(*Read_U8)();
454   xaULONG	(*Read_LSB_U16)();
455   xaULONG	(*Read_MSB_U16)();
456   xaULONG	(*Read_LSB_U32)();
457   xaULONG	(*Read_MSB_U32)();
458   xaLONG	(*Read_Block)();
459   xaLONG	(*At_EOF)();
460   void		(*Set_EOF)();
461   xaLONG	(*Seek_FPos)();
462   xaLONG	(*Get_FPos)();
463 	/* This Buffer is used initially to Determine File type and later *
464 	 * to contruct u8, u16 and u32 entities for certain input methods */
465   xaUBYTE	*buf;
466   xaULONG	buf_size;
467   xaUBYTE	*buf_ptr;
468   xaULONG	buf_cnt;
469   void		*net;		/* generic structure for addition info */
470 } XA_INPUT;
471 
472 	/* load into memory and play from there */
473 #define XA_IN_LOAD_MEM		0x00
474 	/* don't load into mem, play from file */
475 #define XA_IN_LOAD_FILE		0x01
476 	/* decompress into X11 images and play those */
477 #define XA_IN_LOAD_BUF		0x02
478 
479 	/* Input Method supports Random access (otherwise Sequential only) */
480 #define XA_IN_TYPE_RANDOM	0x01
481 #define XA_IN_TYPE_SEQUENTIAL	0x00
482 
483 #define XA_IN_ERR_NONE		0x00
484 #define XA_IN_ERR_EOF		0x01
485 #define XA_IN_ERR_ERR		0x02
486 
487 typedef struct XA_PAUSE_STRUCT
488 {
489   xaULONG frame;
490   struct XA_PAUSE_STRUCT *next;
491 } XA_PAUSE;
492 
493 typedef struct XA_FUNC_STRUCT
494 {
495   xaULONG var1,var2;
496   void (*function)();
497   struct XA_FUNC_STRUCT *next;
498 } XA_FUNC_CHAIN;
499 
500 typedef struct XA_ANIM_HDR_STRUCT
501 {
502   xaLONG	file_num;
503   xaLONG	anim_type;	/* animation type */
504   xaLONG	imagex;		/* width */
505   xaLONG	imagey;		/* height */
506   xaLONG	imagec;		/* number of colors */
507   xaLONG	imaged;		/* depth in planes */
508   xaLONG	dispx;		/* display width */
509   xaLONG	dispy;		/* display height */
510   xaLONG	buffx;		/* buffered width */
511   xaLONG	buffy;		/* buffered height */
512   xaLONG	anim_flags;
513   xaLONG	loop_num;	/* number of times to loop animation */
514   xaLONG	loop_frame;	/* index of loop frame */
515   xaLONG	last_frame;	/* index of last frame */
516   xaLONG	total_time;	/* Length of Anim in ms */
517   char		*name;		/* name of anim */
518   char		*fname;		/* name of anim data file(video and audio) */
519   char		*desc;		/* descriptive string */
520 /* char		 *fsndname;	   eventually have separate sound file name */
521   XA_INPUT	*xin;		/* XAnim Input structure */
522   xaULONG	(*Read_File)();	/* Routine to Parse Animation */
523   xaLONG	max_fvid_size;	/* Largest video codec size */
524   xaLONG	max_faud_size;	/* Largest audio codec size */
525   XA_FRAME	*frame_lst;	/* array of Frames making up the animation */
526   XA_ACTION	*acts;		/* actions associated with this animation */
527   XA_SND	*first_snd;	/* ptr to first sound chunk */
528   XA_SND	*last_snd;	/* ptr to last sound chunk */
529   XA_PAUSE	*pause_lst;	/* pause list */
530   void		(*init_vid)();	/* routine to init video */
531   void		(*init_aud)();	/* routine to init audio */
532 
533   XA_FUNC_CHAIN *free_chain;	/* list of routines to call on exit */
534   struct XA_ANIM_HDR_STRUCT *next_file;
535   struct XA_ANIM_HDR_STRUCT *prev_file;
536 } XA_ANIM_HDR;
537 
538 #define ANIM_HAM	0x00000009
539 #define ANIM_HAM6	0x00000001
540 #define ANIM_LACE	0x00000002
541 #define ANIM_CYCLE	0x00000004
542 #define ANIM_HAM8	0x00000008
543 #define ANIM_PIXMAP	0x00000100
544 #define ANIM_FULL_IM	0x00001000
545 #define ANIM_PING	0x00010000
546 #define ANIM_NOLOOP	0x00020000
547 /* single buffered, x11_bytes_pixel */
548 #define ANIM_SNG_BUF	0x01000000
549 /* double buffered, 1 byte per pixel */
550 #define ANIM_DBL_BUF	0x02000000
551 #define ANIM_3RD_BUF	0x04000000
552 /* open anim_hdr->fname when starting anim */
553 #define ANIM_USE_FILE	0x08000000
554 
555 typedef struct
556 {
557  xaLONG imagex;
558  xaLONG imagey;
559  xaLONG xoff;
560  xaLONG yoff;
561 } SIZE_HDR;
562 
563 typedef struct
564 {
565  xaULONG flag;
566  xaLONG xpos;
567  xaLONG ypos;
568  xaLONG xsize;
569  xaLONG ysize;
570  XImage *image;
571  xaUBYTE *clip;
572 } ACT_IMAGE_HDR;
573 
574 typedef struct
575 {
576  xaULONG flag;
577  xaLONG xpos;
578  xaLONG ypos;
579  xaLONG xsize;
580  xaLONG ysize;
581  Pixmap pixmap;
582  Pixmap clip;
583 } ACT_PIXMAP_HDR;
584 
585 typedef struct
586 {
587  xaLONG xpos;
588  xaLONG ypos;
589  xaLONG xsize;
590  xaLONG ysize;
591  XA_ACTION *act;
592 } ACT_APTR_HDR;
593 
594 #define ACT_BUFF_VALID 0x01
595 
596 typedef struct
597 {
598   xaULONG xapi_rev;
599   xaULONG (*delta)();
600   xaULONG flags;
601   xaULONG xpos,ypos;
602   xaULONG xsize,ysize;
603   xaULONG special;
604   void *extra;
605   xaULONG fpos;
606   xaULONG fsize;
607   xaUBYTE data[4];
608 } ACT_DLTA_HDR;
609 
610 /* ACT_DLTA_HDR Flag Values */
611 /* ALSO ACT_BUFF_VALID  0x0001   defined above */
612 #define ACT_SNGL_BUF    0x0100   /* delta is from sngl buffer anim */
613 #define ACT_DBL_BUF     0x0200   /* delta is from sngl buffer anim */
614 #define ACT_3RD_BUF     0x0400   /* needs 3rd buffer for HAM or Dither */
615 #define DLTA_DATA	0x1000   /* delta data is present */
616 
617 /* DELTA Return VALUES */
618 #define ACT_DLTA_NORM   0x00000000   /* nothing special */
619 #define ACT_DLTA_BODY   0x00000001   /* IFF BODY - used for dbl buffer */
620 #define ACT_DLTA_XOR    0x00000002   /* delta work in both directions */
621 #define ACT_DLTA_NOP    0x00000004   /* delta didn't change anything */
622 #define ACT_DLTA_MAPD   0x00000008   /* delta was able to map image */
623 #define ACT_DLTA_DROP   0x00000010   /* drop this one */
624 #define ACT_DLTA_BAD    0x80000000   /* uninitialize value if needed */
625 
626 
627 typedef struct
628 {
629   xaULONG cfunc_type;
630   void (*color_RGB)();
631   void (*color_Gray)();
632   void (*color_CLR8)();
633   void (*color_CLR16)();
634   void (*color_CLR32)();
635   void (*color_332)();
636   void (*color_CF4)();
637   void (*color_332_Dither)();
638   void (*color_CF4_Dither)();
639 } XA_COLOR_FUNC;
640 
641 
642 typedef struct
643 {
644   xaULONG imagex,max_imagex;
645   xaULONG imagey,max_imagey;
646   xaULONG imagec;
647   xaULONG depth;
648   xaULONG compression;
649   xaUBYTE *pic;
650   xaULONG pic_size;
651   xaULONG max_fvid_size,max_faud_size;
652   xaULONG vid_time,vid_timelo;
653   xaULONG aud_time,aud_timelo;
654   xaULONG cmap_flag;
655   xaULONG cmap_cnt;
656   xaULONG color_cnt;
657   xaULONG color_retries;
658   xaULONG cmap_frame_num;
659   ColorReg cmap[256];
660   XA_CHDR  *chdr;
661 } XA_ANIM_SETUP;
662 
663 
664 typedef struct STRUCT_ACT_SETTER_HDR
665 {
666  XA_ACTION *work;
667  xaLONG xback,yback;
668  xaLONG xpback,ypback;
669  XA_ACTION *back;
670  xaLONG xface,yface;
671  xaLONG xpface,ypface;
672  xaLONG depth;
673  XA_ACTION *face;
674  struct STRUCT_ACT_SETTER_HDR *next;
675 } ACT_SETTER_HDR;
676 
677 typedef struct
678 {
679   xaLONG xpos;
680   xaLONG ypos;
681   xaLONG xsize;
682   xaLONG ysize;
683   xaLONG psize;
684   xaUBYTE *clip;
685   xaUBYTE *data;
686 } ACT_MAPPED_HDR;
687 
688 typedef struct
689 {
690   xaLONG xpos;
691   xaLONG ypos;
692   xaLONG xsize;
693   xaLONG ysize;
694   xaLONG psize;
695   xaLONG rbits;
696   xaLONG gbits;
697   xaLONG bbits;
698   xaUBYTE *clip;
699   xaUBYTE *data;
700 } ACT_TRUE_HDR;
701 
702 typedef struct
703 {
704   xaLONG xpos;
705   xaLONG ypos;
706   xaLONG xsize;
707   xaLONG ysize;
708   xaLONG pk_size;
709   xaUBYTE *clip;
710   xaUBYTE data[4];
711 } ACT_PACKED_HDR;
712 
713 typedef struct
714 {
715  xaLONG xpos;
716  xaLONG ypos;
717  xaLONG xsize;
718  xaLONG ysize;
719  XImage *image;
720  xaUBYTE *clip_ptr;
721 } ACT_CLIP_HDR;
722 
723 #define ACT_NOP		0x0000
724 #define ACT_DELAY	0x0001
725 #define ACT_IMAGE	0x0002
726 #define ACT_CMAP	0x0003
727 #define ACT_SIZE	0x0004
728 #define ACT_FADE	0x0005
729 #define ACT_CLIP	0x0006
730 #define ACT_PIXMAP	0x0007
731 #define ACT_SETTER	0x0008
732 #define ACT_RAW		0x0009
733 #define ACT_PACKED	0x000A
734 #define ACT_DISP	0x000B
735 #define ACT_MAPPED	0x000C
736 #define ACT_TRUE	0x000D
737 #define ACT_PIXMAPS	0x000E
738 #define ACT_IMAGES	0x000F
739 #define ACT_CYCLE	0x0010
740 #define ACT_DELTA	0x0011
741 #define ACT_APTR 	0x0012
742 #define ACT_BEG_LP	0x0100
743 #define ACT_END_LP	0x0101
744 #define ACT_JMP2END	0x0102
745 
746 /* flags */
747 extern xaLONG xa_verbose;
748 extern xaLONG xa_debug;
749 extern xaLONG xa_jiffy_flag;
750 extern xaLONG xa_buffer_flag;
751 extern xaLONG xa_file_flag;
752 extern xaLONG xa_optimize_flag;
753 extern xaLONG xa_use_depth_flag;
754 
755 #define DEBUG_LEVEL1   if (xa_debug >= 1)
756 #define DEBUG_LEVEL2   if (xa_debug >= 2)
757 #define DEBUG_LEVEL3   if (xa_debug >= 3)
758 #define DEBUG_LEVEL4   if (xa_debug >= 4)
759 #define DEBUG_LEVEL5   if (xa_debug >= 5)
760 
761 #define XA_CMAP_SIZE 256
762 #define XA_HMAP_SIZE  64
763 #define XA_HMAP6_SIZE 16
764 #define XA_HMAP8_SIZE 64
765 
766 /* CMAP function flags for ACT_Setup_CMAP */
767 #define CMAP_DIRECT		0x000000
768 #define CMAP_ALLOW_REMAP	0x000001
769 
770 
771 #define CMAP_SCALE4 4369
772 #define CMAP_SCALE5 2114
773 #define CMAP_SCALE6 1040
774 #define CMAP_SCALE8  257
775 #define CMAP_SCALE9  128
776 #define CMAP_SCALE10  64
777 #define CMAP_SCALE11  32
778 #define CMAP_SCALE13   8
779 extern xaULONG cmap_scale[17];
780 extern xaLONG cmap_true_to_332;
781 extern xaLONG cmap_true_to_gray;
782 extern xaLONG cmap_true_to_1st;
783 extern xaLONG cmap_true_to_all;
784 extern xaLONG cmap_true_map_flag;
785 extern xaLONG cmap_dither_type;
786 
787 extern xaULONG cmap_sample_cnt;  /* how many times to sample colors for +CF4 */
788 extern xaULONG cmap_color_func;
789 extern xaLONG cmap_luma_sort;
790 extern xaLONG cmap_map_to_1st_flag;
791 extern xaLONG cmap_play_nice;
792 extern XA_CHDR *xa_chdr_start;
793 extern XA_CHDR *xa_chdr_cur;
794 extern XA_CHDR *xa_chdr_now;
795 extern ColorReg *xa_cmap;
796 extern xaULONG xa_cmap_size;
797 extern xaULONG xa_cmap_off;
798 extern xaLONG cmap_median_type;
799 extern xaSHORT cmap_floyd_error;
800 extern xaLONG cmap_map_to_one_flag;
801 extern xaLONG pod_max_colors;
802 extern xaLONG cmap_hist_flag;
803 extern xaLONG cmap_median_bits;
804 extern xaULONG cmap_cache_size;
805 extern xaULONG cmap_cache_bits;
806 extern xaULONG cmap_cache_rmask;
807 extern xaULONG cmap_cache_gmask;
808 extern xaULONG cmap_cache_bmask;
809 extern xaUSHORT *cmap_cache,*cmap_cache2;
810 extern XA_CHDR *cmap_cache_chdr;
811 
812 extern xaULONG xa_gamma_flag;
813 extern xaUSHORT xa_gamma_adj[];
814 
815 
816 extern xaULONG xa_r_shift,xa_g_shift,xa_b_shift;
817 extern xaULONG xa_r_mask,xa_g_mask,xa_b_mask;
818 extern xaULONG xa_gray_bits,xa_gray_shift;
819 
820 #define XA_HAM_MAP_INVALID 0xffffffff
821 #define XA_HAM6_CACHE_SIZE   4096
822 #define XA_HAM8_CACHE_SIZE 262144
823 
824 typedef struct
825 {
826  xaULONG rate;	/* rate at which to cycle colors in milliseconds */
827  xaULONG flags;   /* flags */
828  xaULONG size;    /* size of color array */
829  xaULONG curpos;  /* curpos in array */
830  xaUBYTE data[4];  /* array of cmap pixel values to cycle */
831 } ACT_CYCLE_HDR;
832 
833 /* ACT_CYCLE flags values */
834 /* NOTE: ACTIVE isn't currently checked. It's assumed to be active or
835  *       else it shouldn't have been created by anim reader. */
836 #define ACT_CYCLE_ACTIVE  0x01
837 #define ACT_CYCLE_REVERSE 0x02
838 #define ACT_CYCLE_STARTED 0x80000000
839 
840 extern void TheEnd();
841 extern void TheEnd1();
842 extern void XAnim_Looped();
843 extern void Cycle_It();
844 extern xaULONG X11_Get_True_Color();
845 extern xaULONG X11_Get_Line_Size();
846 
847 
848 /* AUDIO STUFF */
849 
850 #define XA_AUDIO_STOPPED 0
851 #define XA_AUDIO_PREPPED 1
852 #define XA_AUDIO_STARTED 2
853 #define XA_AUDIO_NICHTDA 3
854 
855 #define XA_AUDIO_OK   0
856 #define XA_AUDIO_UNK  1
857 #define XA_AUDIO_NONE 2
858 #define XA_AUDIO_ERR  3
859 
860 #define XA_AUDIO_MAXVOL  100
861 #define XA_AUDIO_MINVOL  0
862 
863 extern xaULONG xa_audio_enable;
864 
865 
866 /*
867  * Useful Macros
868  */
869 
870 #define CMAP_GET_GRAY(r,g,b,scale) \
871 ( ((scale)*((r)*11+(g)*16+(b)*5) ) >> xa_gray_shift)
872 
873 #define CMAP_GET_332(r,g,b,scale) ( \
874 ( (((r)*(scale)) & xa_r_mask) >> xa_r_shift) | \
875 ( (((g)*(scale)) & xa_g_mask) >> xa_g_shift) | \
876 ( (((b)*(scale)) & xa_b_mask) >> xa_b_shift) )
877 
878 #define X11_Get_Bitmap_Width(x) \
879   ( ((x + x11_bitmap_unit - 1)/x11_bitmap_unit) * x11_bitmap_unit )
880 
881 #define X11_Make_Pixel(p)  (x11_cmap_type == 0)?(p): \
882 		( (((p)<<24)|((p)<<16)|((p)<<8)|(p)) & x11_depth_mask )
883 
884 #define XA_PIC_SIZE(p) ( (xa_use_depth_flag==xaTRUE)?((p) * x11_bytes_pixel): \
885 		(p) )
886 
887 #define XA_GET_TIME(t) ( (xa_jiffy_flag)?(xa_jiffy_flag):(t) )
888 
889 #define XA_MEMSET(p,d,size) \
890 { if (x11_bytes_pixel==4) { xaULONG _sz=(size); \
891     xaULONG *_lp=(xaULONG *)p; while(_sz--) *_lp++ = (xaULONG)(d); } \
892   else if (x11_bytes_pixel==2) { xaULONG _sz=(size); \
893     xaUSHORT *_sp=(xaUSHORT *)p; while(_sz--) *_sp++ = (xaUSHORT)(d); } \
894   else { memset(p,d,size); } \
895 }
896 
897 #define XA_REALLOC(p,cur_size,new_size) { if (new_size > cur_size) \
898 { char *_tmp; \
899   if (p == 0) _tmp=(char *)malloc(new_size); \
900   else _tmp=(char *)realloc(p,new_size); \
901   if (_tmp == 0) TheEnd1("XA_Realloc: malloc err"); \
902   p = _tmp; cur_size = new_size; } \
903 }
904 
905 #define FREE(_p,_q) free(_p)
906 /* For Debug
907 #include <errno.h>
908 #define FREE(_p,_q) { int ret; ret = free(_p); \
909 fprintf(stderr,"FREE %lx %lx ret=%ld err=%ld\n",_p,_q,ret,errno); }
910 */
911 
912 
913 /* REV 1 */
914 typedef struct
915 {
916   xaULONG cmd;			/* decode or query */
917   xaULONG skip_flag;		/* skip_flag */
918   xaULONG imagex,imagey;	/* Image Buffer Size */
919   xaULONG imaged; 		/* Image depth */
920   XA_CHDR *chdr;		/* Color Map Header */
921   xaULONG map_flag;		/* remap image? */
922   xaULONG *map;			/* map to use */
923   xaULONG xs,ys;		/* pos of changed area */
924   xaULONG xe,ye;		/* size of change area */
925   xaULONG special;		/* Special Info */
926   void *extra;			/* Decompression specific info */
927 } XA_DEC_INFO;
928 
929 #include "xa_dec2.h"
930 
931 
932 
933