1 
2 /*
3  * xa_iff.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 
19 typedef struct
20 {
21  xaLONG id;
22  xaLONG size;
23 } Chunk_Header;
24 
25 /* Graphic Stuff */
26 #define IFF_ANHD 0x414e4844
27 #define IFF_ANIM 0x414e494d
28 #define IFF_ANSQ 0x414e5351
29 #define IFF_BMHD 0x424d4844
30 #define IFF_BODY 0x424f4459
31 #define IFF_TINY 0x54494E59
32 #define IFF_CAMG 0x43414d47
33 #define IFF_CMAP 0x434d4150
34 #define IFF_CRNG 0x43524e47
35 #define IFF_DLTA 0x444c5441
36 #define IFF_DPAN 0x4450414e
37 #define IFF_DPPS 0x44505053
38 #define IFF_DPPV 0x44505056
39 #define IFF_DRNG 0x44524e47
40 #define IFF_FORM 0x464f524d
41 #define IFF_GRAB 0x47524142
42 #define IFF_ILBM 0x494c424d
43 #define IFF_IMRT 0x494d5254
44 #define IFF_DPI  0x44504920
45 #define IFF_ANFI 0x414e4649
46 #define IFF_NAME 0x4e414d45
47 
48 /* Grouping Stuff */
49 #define IFF_LIST 0x4c495354
50 #define IFF_PROP 0x50524f50
51 #define IFF_FACE 0x46414345
52 
53 /* Sound stuff */
54 #define IFF_VHDR 0x56484452
55 #define IFF_ANNO 0x414e4e4f
56 #define IFF_CHAN 0x4348414e
57 #define IFF_8SVX 0x38535658
58 
59 
60 typedef struct
61 {
62  xaUSHORT width, height;
63  xaSHORT x, y;
64  xaUBYTE depth;
65  xaUBYTE masking;
66  xaUBYTE compression;
67  xaUBYTE pad1;
68  xaUSHORT transparentColor;
69  xaUBYTE xAspect, yAspect;
70  xaSHORT pageWidth, pageHeight;
71 } Bit_Map_Header;
72 
73 #define BMHD_COMP_NONE 0L
74 #define BMHD_COMP_BYTERUN 1L
75 
76 #define BMHD_MSK_NONE 0L
77 #define BMHD_MSK_HAS 1L
78 #define BMHD_MSK_TRANS 2L
79 #define BMHD_MSK_LASSO 3L
80 
81 #define mskNone                 0
82 #define mskHasMask              1
83 #define mskHasTransparentColor  2
84 #define mskLasso                3
85 
86 #define cmpNone      0
87 #define cmpByteRun1  1
88 
89 /* Aspect ratios: The proper fraction xAspect/yAspect represents the pixel
90  * aspect ratio pixel_width/pixel_height.
91  *
92  * For the 4 Amiga display modes:
93  *   320 x 200: 10/11  (these pixels are taller than they are wide)
94  *   320 x 400: 20/11
95  *   640 x 200:  5/11
96  *   640 x 400: 10/11      */
97 #define x320x200Aspect 10
98 #define y320x200Aspect 11
99 #define x320x400Aspect 20
100 #define y320x400Aspect 11
101 #define x640x200Aspect  5
102 #define y640x200Aspect 11
103 #define x640x400Aspect 10
104 #define y640x400Aspect 11
105 
106 /* CRNG Stuff */
107 #define IFF_CRNG_ACTIVE   1
108 #define IFF_CRNG_REVERSE  2
109 /* 16384 * 16.6667 ms */
110 #define IFF_CRNG_INTERVAL (273065)
111 #define IFF_CRNG_HDR_SIZE 8
112 #define IFF_CRNG_DPII_KLUDGE 36
113 
114 /* CAMG Stuff */
115 #define IFF_CAMG_NOP   0x00000001
116 #define IFF_CAMG_EHB   0x00000080
117 #define IFF_CAMG_HAM   0x00000800
118 #define IFF_CAMG_LACE  0x00004000
119 
120 typedef struct
121 {
122  xaUSHORT width,height;
123  xaSHORT x, y;
124  xaSHORT xoff, yoff;
125 } Face_Header;
126 
127 typedef struct
128 {
129  xaLONG id;
130  xaLONG size;
131  xaLONG subid;
132 } Group_Header;
133 
134 typedef struct
135 {
136  xaLONG id;
137  xaLONG size;
138  xaLONG subid;
139  xaUBYTE grpData[ 1 ];
140 } Group_Chunk;
141 
142 typedef struct
143 {
144  xaUBYTE op;
145  xaUBYTE mask;
146  xaUSHORT w,h;
147  xaUSHORT x,y;
148  xaULONG abstime;
149  xaULONG reltime;
150  xaUBYTE interleave;
151  xaUBYTE pad0;
152  xaULONG bits;
153  xaUBYTE pad[16];
154 } Anim_Header;
155 #define Anim_Header_SIZE 40
156 #define IFF_ANHD_LDATA  0x0001
157 #define IFF_ANHD_XOR    0x0002
158 #define IFF_ANHD_1LIST  0x0002
159 #define IFF_ANHD_RLC    0x0008
160 #define IFF_ANHD_VERT   0x0010
161 #define IFF_ANHD_LIOFF  0x0020
162 
163 typedef struct
164 {
165  xaLONG minx;
166  xaLONG miny;
167  xaLONG maxx;
168  xaLONG maxy;
169 } IFF_DLTA_HDR;
170 
171 typedef struct
172 {
173   xaULONG dnum;
174   xaULONG time;
175   xaULONG frame;
176 } IFF_ANSQ_HDR;
177 
178 typedef struct IFF_ACT_LST_STRUCT
179 {
180   xaULONG type;
181   XA_ACTION *act;
182   struct IFF_ACT_LST_STRUCT *next;
183 } IFF_ACT_LST;
184 
185 typedef struct
186 {
187   xaULONG cnt;
188   xaULONG frame;
189   IFF_ACT_LST *start;
190   IFF_ACT_LST *end;
191 } IFF_DLTA_TABLE;
192 
193 extern xaULONG IFF_Read_File();
194 extern xaULONG IFF_Delta3();
195 extern xaULONG IFF_Delta5();
196 extern xaULONG IFF_Delta7();
197 extern xaULONG IFF_Delta8();
198 extern xaULONG IFF_Deltal();
199 extern xaULONG IFF_DeltaJ();
200 extern xaLONG Is_IFF_File();
201 extern xaLONG UnPackRow();
202 
203 /* POD NOTE: further optimization would be to have
204  * IFF_Byte_Mod and IFF_Byte_Mod_with_XOR_flag
205  */
206 #define IFF_Byte_Mod(ptr,data,dmask,xorflag) { register xaUBYTE *_iptr = ptr; \
207 if (xorflag) { \
208   if (0x80 & data) *_iptr++ ^= dmask; else _iptr++; \
209   if (0x40 & data) *_iptr++ ^= dmask; else _iptr++; \
210   if (0x20 & data) *_iptr++ ^= dmask; else _iptr++; \
211   if (0x10 & data) *_iptr++ ^= dmask; else _iptr++; \
212   if (0x08 & data) *_iptr++ ^= dmask; else _iptr++; \
213   if (0x04 & data) *_iptr++ ^= dmask; else _iptr++; \
214   if (0x02 & data) *_iptr++ ^= dmask; else _iptr++; \
215   if (0x01 & data) *_iptr   ^= dmask; \
216 } else { \
217   register xaUBYTE dmaskoff = ~dmask; \
218   if (0x80 & data) *_iptr++ |= dmask; else *_iptr++  &= dmaskoff; \
219   if (0x40 & data) *_iptr++ |= dmask; else *_iptr++  &= dmaskoff; \
220   if (0x20 & data) *_iptr++ |= dmask; else *_iptr++  &= dmaskoff; \
221   if (0x10 & data) *_iptr++ |= dmask; else *_iptr++  &= dmaskoff; \
222   if (0x08 & data) *_iptr++ |= dmask; else *_iptr++  &= dmaskoff; \
223   if (0x04 & data) *_iptr++ |= dmask; else *_iptr++  &= dmaskoff; \
224   if (0x02 & data) *_iptr++ |= dmask; else *_iptr++  &= dmaskoff; \
225   if (0x01 & data) *_iptr   |= dmask; else *_iptr    &= dmaskoff; \
226 } }
227 
228 
229 #define IFF_Short_Mod(ptr,data,dmask,xorflag) { register xaUBYTE *_iptr = ptr; \
230 if (xorflag) { \
231   if (0x8000 & data) *_iptr++  ^= dmask; else _iptr++; \
232   if (0x4000 & data) *_iptr++  ^= dmask; else _iptr++; \
233   if (0x2000 & data) *_iptr++  ^= dmask; else _iptr++; \
234   if (0x1000 & data) *_iptr++  ^= dmask; else _iptr++; \
235   if (0x0800 & data) *_iptr++  ^= dmask; else _iptr++; \
236   if (0x0400 & data) *_iptr++  ^= dmask; else _iptr++; \
237   if (0x0200 & data) *_iptr++  ^= dmask; else _iptr++; \
238   if (0x0100 & data) *_iptr++  ^= dmask; else _iptr++; \
239   if (0x0080 & data) *_iptr++  ^= dmask; else _iptr++; \
240   if (0x0040 & data) *_iptr++  ^= dmask; else _iptr++; \
241   if (0x0020 & data) *_iptr++   ^= dmask; else _iptr++; \
242   if (0x0010 & data) *_iptr++   ^= dmask; else _iptr++; \
243   if (0x0008 & data) *_iptr++   ^= dmask; else _iptr++; \
244   if (0x0004 & data) *_iptr++   ^= dmask; else _iptr++; \
245   if (0x0002 & data) *_iptr++   ^= dmask; else _iptr++; \
246   if (0x0001 & data) *_iptr     ^= dmask; \
247 } else { \
248   register xaUBYTE dmaskoff = ~dmask; \
249   if (0x8000 & data) *_iptr++  |= dmask; else *_iptr++  &= dmaskoff; \
250   if (0x4000 & data) *_iptr++  |= dmask; else *_iptr++  &= dmaskoff; \
251   if (0x2000 & data) *_iptr++  |= dmask; else *_iptr++  &= dmaskoff; \
252   if (0x1000 & data) *_iptr++  |= dmask; else *_iptr++  &= dmaskoff; \
253   if (0x0800 & data) *_iptr++  |= dmask; else *_iptr++  &= dmaskoff; \
254   if (0x0400 & data) *_iptr++  |= dmask; else *_iptr++  &= dmaskoff; \
255   if (0x0200 & data) *_iptr++  |= dmask; else *_iptr++  &= dmaskoff; \
256   if (0x0100 & data) *_iptr++  |= dmask; else *_iptr++  &= dmaskoff; \
257   if (0x0080 & data) *_iptr++  |= dmask; else *_iptr++  &= dmaskoff; \
258   if (0x0040 & data) *_iptr++  |= dmask; else *_iptr++  &= dmaskoff; \
259   if (0x0020 & data) *_iptr++   |= dmask; else *_iptr++   &= dmaskoff; \
260   if (0x0010 & data) *_iptr++   |= dmask; else *_iptr++   &= dmaskoff; \
261   if (0x0008 & data) *_iptr++   |= dmask; else *_iptr++   &= dmaskoff; \
262   if (0x0004 & data) *_iptr++   |= dmask; else *_iptr++   &= dmaskoff; \
263   if (0x0002 & data) *_iptr++   |= dmask; else *_iptr++   &= dmaskoff; \
264   if (0x0001 & data) *_iptr     |= dmask; else *_iptr     &= dmaskoff; \
265 } }
266 
267