1 
2 /*
3  * xa_avi.h
4  *
5  * Copyright (C) 1993-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 
19 /* The following copyright applies to all Ultimotion Segments of the Code:
20  *
21  * "Copyright International Business Machines Corporation 1994, All rights
22  *  reserved. This product uses Ultimotion(tm) IBM video technology."
23  *
24  */
25 
26 
27 #include "xanim.h"
28 
29 #define RIFF_RIFF 0x52494646
30 #define RIFF_RIFX 0x52494658
31 #define RIFF_LIST 0x4C495354
32 #define RIFF_avih 0x61766968
33 #define RIFF_strd 0x73747264
34 #define RIFF_strh 0x73747268
35 #define RIFF_strf 0x73747266
36 #define RIFF_vedt 0x76656474
37 #define RIFF_JUNK 0x4A554E4B
38 #define RIFF_idx1 0x69647831
39 /*********List Types ***************/
40 #define RIFF_movi 0x6D6F7669
41 #define RIFF_hdrl 0x6864726C
42 #define RIFF_strl 0x7374726C
43 /*********Chunk Names***************/
44 #define RIFF_FF00 0xFFFF0000
45 #define RIFF_00   0x30300000
46 #define RIFF_01   0x30310000
47 #define RIFF_02   0x30320000
48 #define RIFF_03   0x30330000
49 #define RIFF_04   0x30340000
50 #define RIFF_05   0x30350000
51 #define RIFF_06   0x30360000
52 #define RIFF_07   0x30370000
53 #define RIFF_00pc 0x30307063
54 #define RIFF_01pc 0x30317063
55 #define RIFF_00dc 0x30306463
56 #define RIFF_00dx 0x30306478
57 #define RIFF_00db 0x30306462
58 #define RIFF_00xx 0x30307878
59 #define RIFF_00id 0x30306964
60 #define RIFF_00rt 0x30307274
61 #define RIFF_0021 0x30303231
62 #define RIFF_00iv 0x30306976
63 #define RIFF_0031 0x30303331
64 #define RIFF_0032 0x30303332
65 #define RIFF_00vc 0x30305643
66 #define RIFF_00xm 0x3030786D
67 #define RIFF_01wb 0x30317762
68 #define RIFF_01dc 0x30306463
69 /*********VIDEO CODECS**************/
70 #define RIFF_cram 0x6372616D
71 #define RIFF_CRAM 0x4352414D
72 #define RIFF_wham 0x7768616d
73 #define RIFF_WHAM 0x5748414d
74 #define RIFF_rgb  0x00000000
75 #define RIFF_RGB  0x52474220
76 #define RIFF_rle8 0x01000000
77 #define RIFF_RLE8 0x524c4538
78 #define RIFF_rle4 0x02000000
79 #define RIFF_RLE4 0x524c4534
80 #define RIFF_none 0x0000FFFF
81 #define RIFF_NONE 0x4e4f4e45
82 #define RIFF_pack 0x0100FFFF
83 #define RIFF_PACK 0x5041434b
84 #define RIFF_tran 0x0200FFFF
85 #define RIFF_TRAN 0x5452414e
86 #define RIFF_ccc  0x0300FFFF
87 #define RIFF_CCC  0x43434320
88 #define RIFF_cyuv 0x63797576
89 #define RIFF_CYUV 0x43595556
90 #define RIFF_jpeg 0x0400FFFF
91 #define RIFF_JPEG 0x4A504547
92 #define RIFF_MJPG 0x4d4a5047
93 #define RIFF_mJPG 0x6d4a5047
94 #define RIFF_IJPG 0x494a5047
95 #define RIFF_rt21 0x72743231
96 #define RIFF_RT21 0x52543231
97 #define RIFF_iv31 0x69763331
98 #define RIFF_IV31 0x49563331
99 #define RIFF_iv32 0x69763332
100 #define RIFF_IV32 0x49563332
101 #define RIFF_iv41 0x69763431
102 #define RIFF_IV41 0x49563431
103 #define RIFF_iv50 0x69763530
104 #define RIFF_IV50 0x49563530
105 #define RIFF_cvid 0x63766964
106 #define RIFF_CVID 0x43564944
107 #define RIFF_ulti 0x554c5449
108 #define RIFF_ULTI 0x756c7469
109 #define RIFF_YUV9 0x59565539
110 #define RIFF_YVU9 0x59555639
111 #define RIFF_XMPG 0x584D5047
112 #define RIFF_xmpg 0x786D7067
113 #define RIFF_VDOW 0x56444f57
114 #define RIFF_MVI1 0x4D564931
115 #define RIFF_v422 0x76343232
116 #define RIFF_V422 0x56343232
117 #define RIFF_mvi1 0x6D766931
118 #define RIFF_MPIX 0x04006931		/* MotionPixels munged their id */
119 #define RIFF_AURA 0x41555241
120 #define RIFF_DMB1 0x444d4231
121 #define RIFF_dmb1 0x646d6231
122 
123 #define RIFF_BW10 0x42573130
124 #define RIFF_bw10 0x62773130
125 
126 #define RIFF_yuy2 0x79757932
127 #define RIFF_YUY2 0x59555932
128 #define RIFF_YUV8 0x59555638
129 #define RIFF_WINX 0x57494e58
130 #define RIFF_WPY2 0x57505932
131 #define RIFF_m263 0x6d323633
132 #define RIFF_M263 0x4d323633
133 
134 #define RIFF_Q1_0 0x51312e30
135 #define RIFF_SFMC 0x53464D43
136 
137 #define RIFF_y41p 0x79343170
138 #define RIFF_Y41P 0x59343150
139 #define RIFF_yv12 0x79763132
140 #define RIFF_YV12 0x59563132
141 #define RIFF_vixl 0x7669786c
142 #define RIFF_VIXL 0x5649584c
143 #define RIFF_iyuv 0x69797576
144 #define RIFF_IYUV 0x49595556
145 #define RIFF_i420 0x69343230
146 #define RIFF_I420 0x49343230
147 #define RIFF_vyuy 0x76797579
148 #define RIFF_VYUY 0x56595559
149 
150 #define RIFF_rpza 0x72707a61
151 /* And this here's the mistakes that need to be supported */
152 #define RIFF_azpr 0x617a7072	/* recognize Apple's rpza mangled? */
153 /*********** WAV file stuff *************/
154 #define RIFF_fmt  0x666D7420
155 #define RIFF_data 0x64617461
156 /*********** FND in MJPG **********/
157 #define RIFF_ISFT 0x49534654
158 #define RIFF_IDIT 0x49444954
159 
160 #define RIFF_00AM 0x3030414d
161 #define RIFF_DISP 0x44495350
162 #define RIFF_ISBJ 0x4953424a
163 
164 #define RIFF_rec	72656320
165 /* RIFF Types */
166 #define RIFF_AVI  0x41564920
167 #define RIFF_WAVE 0x57415645
168 
169 /* fcc Types */
170 #define RIFF_vids 0x76696473
171 #define RIFF_auds 0x61756473
172 #define RIFF_pads 0x70616473
173 #define RIFF_txts 0x74787473
174 
175 /* fcc handlers */
176 #define RIFF_RLE  0x524c4520
177 #define RIFF_msvc 0x6D737663
178 #define RIFF_MSVC 0x4d535643
179 
180 typedef struct
181 {
182   xaULONG ckid;
183   xaULONG flags;
184   xaULONG offset;   /* position of chunk rel to movi list include 8b hdr*/
185   xaULONG size;     /* length of chunk excluding 8 bytes for RIFF hdr */
186 } AVI_INDEX_ENTRY;
187 
188 /* Flags for AVI_INDEX_ENTRY */
189 #define AVIIF_LIST          0x00000001L
190 #define AVIIF_TWOCC         0x00000002L
191         /* keyframe doesn't need previous info to be decompressed */
192 #define AVIIF_KEYFRAME      0x00000010L
193         /* this chunk needs the frames following it to be used */
194 #define AVIIF_FIRSTPART     0x00000020L
195         /* this chunk needs the frames before it to be used */
196 #define AVIIF_LASTPART      0x00000040L
197 #define AVIIF_MIDPART       (AVIIF_LASTPART|AVIIF_FIRSTPART)
198         /* this chunk doesn't affect timing ie palette change */
199 #define AVIIF_NOTIME        0x00000100L
200 #define AVIIF_COMPUSE       0x0FFF0000L
201 
202 typedef struct
203 {
204   xaULONG us_frame;       /* MicroSecPerFrame - timing between frames */
205   xaULONG max_bps;        /* MaxBytesPerSec - approx bps system must handle */
206   xaULONG pad_gran;       /* */
207   xaULONG flags;          /* Flags */
208   xaULONG tot_frames;     /* TotalFrames */
209   xaULONG init_frames;    /* InitialFrames - initial frame before interleaving */
210   xaULONG streams;        /* Streams */
211   xaULONG sug_bsize;      /* SuggestedBufferSize */
212   xaULONG width;          /* Width */
213   xaULONG height;         /* Height */
214   xaULONG scale;          /* Scale */
215   xaULONG rate;           /* Rate */
216   xaULONG start;          /* Start */
217   xaULONG length;         /* Length */
218 } AVI_HDR;
219 
220 /* AVI_HDR Flags */
221         /* had idx1 chunk */
222 #define AVIF_HASINDEX           0x00000010
223         /* must use idx1 chunk to determine order */
224 #define AVIF_MUSTUSEINDEX       0x00000020
225         /* AVI file is interleaved */
226 #define AVIF_ISINTERLEAVED      0x00000100
227         /* specially allocated used for capturing real time video */
228 #define AVIF_WASCAPTUREFILE     0x00010000
229         /* contains copyrighted data */
230 #define AVIF_COPYRIGHTED        0x00020000
231 
232 
233 typedef struct
234 {
235   xaULONG fcc_type;       /* fccType  {vids} */
236   xaULONG fcc_handler;    /* fccHandler {msvc,RLE} */
237   xaULONG flags;          /* Flags */
238   xaULONG priority;       /* Priority*/
239   xaULONG init_frames;    /* InitialFrames */
240   xaULONG scale;          /* Scale */
241   xaULONG rate;           /* Rate */
242   xaULONG start;          /* Start */
243   xaULONG length;         /* Length In units above...*/
244   xaULONG sug_bsize;      /* SuggestedBufferSize */
245   xaULONG quality;        /* Quality */
246   xaULONG samp_size;      /* SampleSize */
247 } AVI_STREAM_HDR;
248 /* AVI_STREAM_HDR Flags */
249 #define AVISF_DISABLED                  0x00000001
250 #define AVISF_VIDEO_PALCHANGES          0x00010000
251 
252 
253 typedef struct /* BitMapInfoHeader */
254 {
255   xaULONG size;           /* Size */
256   xaULONG width;          /* Width */
257   xaULONG height;         /* Height */
258   xaULONG planes;         /* short Planes */
259   xaULONG bit_cnt;        /* short BitCount */
260   xaULONG compression;    /* Compression {1} */
261   xaULONG image_size;     /* SizeImage */
262   xaULONG xpels_meter;    /* XPelsPerMeter */
263   xaULONG ypels_meter;    /* XPelsPerMeter */
264   xaULONG num_colors;     /* ClrUsed */
265   xaULONG imp_colors;     /* ClrImportant */
266 } VIDS_HDR;
267 
268 
269 typedef struct AVI_FRAME_STRUCT
270 {
271   xaULONG time;
272   xaULONG timelo;
273   XA_ACTION *act;
274   struct AVI_FRAME_STRUCT *next;
275 } AVI_FRAME;
276 
277 /* used by MSADPCM */
278 typedef struct WAVE_COEF_SET_STRUCT
279 {
280   xaSHORT	coef1;			/* S coef 1 */
281   xaSHORT	coef2;			/* S coef 2 */
282 } WAVE_COEF_SET;
283 
284 typedef struct /* BitMapInfoHeader */
285 {
286   xaULONG format;         /* S format */
287   xaULONG channels;       /* S channels */
288   xaULONG rate;           /* L rate */
289   xaULONG av_bps;         /* L average bytes/sec */
290   xaULONG blockalign;	  /* S block size of data */
291   xaULONG size;           /* S size */
292   xaULONG ext_size;       /* S size of following extenions - if any */
293   xaULONG samps_block;	  /* S Used by MSADPCM and Intel DVI */
294   xaULONG num_coefs;	  /* S Used by MSADPCM  num of follow sets */
295   WAVE_COEF_SET *coefs;	  /* Used by MSADPCM  coef1, coef2 */
296   xaULONG style;          /* - SIGN2 or unsigned */
297   xaULONG byte_cnt;	  /* used to keep track of length */
298 } AUDS_HDR;
299 
300 
301 
302 /**** from public Microsoft RIFF docs ******/
303 #define WAVE_FORMAT_UNKNOWN		(0x0000)
304 #define WAVE_FORMAT_PCM			(0x0001)
305 #define WAVE_FORMAT_ADPCM		(0x0002)
306 #define WAVE_FORMAT_IBM_CVSD		(0x0005)
307 #define WAVE_FORMAT_ALAW		(0x0006)
308 #define WAVE_FORMAT_MULAW		(0x0007)
309 #define WAVE_FORMAT_OKI_ADPCM		(0x0010)
310 #define WAVE_FORMAT_DVI_ADPCM		(0x0011)
311 #define WAVE_FORMAT_DIGISTD		(0x0015)
312 #define WAVE_FORMAT_DIGIFIX		(0x0016)
313 #define WAVE_FORMAT_YAMAHA_ADPCM        (0x0020)
314 #define WAVE_FORMAT_DSP_TRUESPEECH      (0x0022)
315 #define WAVE_FORMAT_GSM610		(0x0031)
316 #define IBM_FORMAT_MULAW		(0x0101)
317 #define IBM_FORMAT_ALAW			(0x0102)
318 #define IBM_FORMAT_ADPCM		(0x0103)
319 /*********************/
320 
321