* some endianess fixes
[swftools.git] / src / flash.h
1 /* flash.h
2    Header file for flash.c
3
4    Part of the swftools package.
5
6    Copyright (c) 2001 Matthias Kramm <kramm@quiss.org> 
7
8    This file is distributed under the GPL, see file COPYING for details */
9
10 #ifndef __flash_h__
11 #define __flash_h__
12
13 #include "types.h"
14
15 #define TAGID_END 0
16 #define TAGID_SHOWFRAME 1
17 #define TAGID_DEFINESHAPE 2
18 #define TAGID_PLACEOBJECT 4
19 #define TAGID_REMOVEOBJECT 5
20 #define TAGID_DEFINEBITS 6
21 #define TAGID_DEFINEBUTTON 7
22 #define TAGID_JPEGTABLES 8
23 #define TAGID_BACKGROUNDCOLOR 9
24 #define TAGID_DEFINEFONT 10
25 #define TAGID_DEFINETEXT 11
26 #define TAGID_DOACTION 12
27 #define TAGID_DEFINEFONTINFO 13
28 #define TAGID_DEFINESOUND 14
29 #define TAGID_STARTSOUND 15
30 #define TAGID_DEFINEBUTTONSOUND 17
31 #define TAGID_SOUNDSTREAMHEAD 18
32 #define TAGID_SOUNDSTREAMHEAD2 18
33 #define TAGID_SOUNDSTREAMBLOCK 19
34 #define TAGID_DEFINEBITSLOSSLESS 20
35 #define TAGID_DEFINEBITSJPEG2 21
36 #define TAGID_DEFINESHAPE2 22
37 #define TAGID_DEFINEBUTTONCXFORM 23
38 #define TAGID_PROTECT 24
39 #define TAGID_PLACEOBJECT2 26
40 #define TAGID_REMOVEOBJECT2 28
41 #define TAGID_DEFINESHAPE3 32
42 #define TAGID_DEFINETEXT2 33
43 #define TAGID_DEFINEBUTTON2 34
44 #define TAGID_DEFINEBITSJPEG3 35
45 #define TAGID_DEFINEBITSLOSSLESS2 36
46 #define TAGID_DEFINEEDITTEXT 37
47 #define TAGID_DEFINEMOVIE 38
48 #define TAGID_DEFINESPRITE 39
49 #define TAGID_FRAMELABEL 43
50 #define TAGID_DEFINEMORPHSHAPE 46
51 #define TAGID_DEFINEFONT2 48
52 #define TAGID_EXPORTASSETS   56
53 #define TAGID_IMPORTASSETS   57
54 #define TAGID_ENABLEDEBUGGER 58
55
56 #include "bitio.h"
57
58 struct swf_tag;
59 struct RECT;
60 struct RGB;
61 struct MATRIX;
62 struct CXFORM;
63 struct CLIPACTIONS;
64
65 struct swf_tag
66 {
67     u8 id;
68     u32 length;
69     u8*data;
70     u32 fulllength; // includes id
71     u8*fulldata; // likewise
72 };
73
74 struct RGB
75 {
76     byte r,g,b;
77 };
78
79 struct RGBA
80 {
81     byte r,g,b,a;
82 };
83
84 struct RECT
85 {
86     int x1, y1, x2, y2;
87 };
88
89 struct MATRIX 
90 {
91     u8 hasscale;
92     u8 hasrotate;
93     float a[2][2];
94     int b[2];
95 };
96
97 struct CXFORM 
98 {
99     u8 hasadd;
100     u8 hasmult;
101     float rmult, gmult, bmult, amult;
102     float radd, gadd, badd, aadd;
103     u8 alpha;
104 };
105
106 struct GRADIENT
107 {
108     int num;
109     u8 ratios[8];
110     struct RGB rgb[8];
111     struct RGBA rgba[8];
112 };
113
114 struct RECT readRECT();
115 struct RGB readRGB();
116 struct MATRIX readMATRIX();
117 unsigned char* readSTRING();
118 struct CLIPACTIONS readCLIPACTIONS();
119
120 void writeRECT(u8**pos, struct RECT*r);
121
122 void swf_init(struct reader_t*,uchar*newdata, int newlength);
123 struct flash_header
124 {
125     int version;
126     u32 length;
127     struct RECT boundingBox;
128     u16 rate;
129     u16 count;
130
131     u8*headerdata;
132     int headerlength;
133 };
134
135 struct swffile
136 {
137     struct flash_header header;
138     int tagnum;
139     struct swf_tag* tags;
140 };
141
142 struct flash_header swf_read_header(struct reader_t*);
143 struct RGB readRGB(struct reader_t*);
144 struct RGBA readRGBA(struct reader_t*);
145 struct GRADIENT readGRADIENT(struct reader_t*,int shape);
146 struct RECT readRECT(struct reader_t*);
147 struct CXFORM readCXFORM(struct reader_t*,char alpha);
148 struct MATRIX readMATRIX(struct reader_t*);
149 unsigned char* readSTRING(struct reader_t*);
150 int swf_read_tag(struct reader_t*,struct swf_tag* swftag);
151 int swf_count_tags(struct reader_t*);
152
153
154 struct PlaceObject
155 {
156     u16 id;
157     u16 depth;
158     struct MATRIX matrix;
159     struct CXFORM cxform;
160     u8 hascxform;
161 };
162
163 struct PlaceObject2
164 {
165     u8 reserved;
166     u8 hasclipactions;
167     u8 hasname;
168     u8 hasratio;
169     u8 hascolortransform;
170     u8 hasmatrix;
171     u8 hascharacter;
172     u8 hasmove;
173
174     u16 depth;
175     int id;
176     struct MATRIX matrix;
177     struct CXFORM cxform;
178     u16 ratio;
179     char * name;
180     u16 clipactions;
181 };
182
183
184 void placeobject_init (struct PlaceObject*obj, struct swf_tag*tag);
185 void placeobject_write (struct PlaceObject*obj, struct writer_t*w);
186
187 void placeobject2_init (struct PlaceObject2*obj, struct swf_tag*tag);
188
189 void read_swf(struct swffile*swf, uchar*data, int length);
190
191 int getidfromtag(struct swf_tag* tag);
192 void setidintag(struct swf_tag* tag, int id);
193 char is_sprite_tag (int id);
194 char is_defining_tag (int id);
195 struct swf_tag* duptag(struct swf_tag*tag);
196
197 #endif //__flash_h__