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