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