3 Headers for rfxswf.c and modules
\r
5 Part of the swftools package.
\r
7 Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>
\r
9 This file is distributed under the GPL, see file COPYING for details
\r
13 #ifndef __RFX_SWF_INCLUDED__
\r
14 #define __RFX_SWF_INCLUDED__
\r
19 #include "../config.h"
\r
20 #include "old_rfxswf.h"
\r
22 #define DEBUG_RFXSWF
\r
26 typedef unsigned long U32;
\r
27 typedef signed long S32;
\r
28 typedef unsigned short U16;
\r
29 typedef signed short S16;
\r
30 typedef unsigned char U8;
\r
31 typedef signed char S8;
\r
32 typedef signed long SFIXED;
\r
33 typedef signed long SCOORD;
\r
37 typedef struct _SPOINT
\r
40 } SPOINT, * LPSPOINT;
\r
42 typedef struct _RGBA
\r
49 typedef struct _SRECT
\r
56 typedef struct _MATRIX
\r
57 { SFIXED sx; // factor x
\r
59 SFIXED r0; // rotation
\r
61 SCOORD tx; // delta x
\r
63 } MATRIX, * LPMATRIX;
\r
65 typedef struct _CXFORM
\r
70 } CXFORM, * LPCXFORM;
\r
72 typedef struct _TAG // NEVER access a Tag-Struct directly !
\r
82 U32 memsize; // to minimize realloc() calls
\r
83 U32 pos; // for Get/Set-Access
\r
84 U8 bitmask; // for Bit-Manipulating Functions [read]
\r
85 U8 bitcount; // [write]
\r
90 U32 FileSize; // valid after load and save
\r
93 U16 FrameCount; // valid after load and save
\r
99 int ReadSWF(int handle,LPSWF swf); // Reads SWF to memory (malloc'ed), returns length or <0 if fails
\r
100 int WriteSWF(int handle,LPSWF swf); // Writes SWF to file, returns length or <0 if fails
\r
101 int WriteCGI(LPSWF swf); // Outputs SWF with valid CGI header to stdout
\r
102 void FreeTags(LPSWF swf); // Frees all malloc'ed memory for swf
\r
104 LPTAG InsertTag(LPTAG after,U16 id); // updates frames, if necessary
\r
105 int DeleteTag(LPTAG t);
\r
107 void SetTagPos(LPTAG t,U32 pos); // resets Bitcount
\r
108 U32 GetTagPos(LPTAG t);
\r
110 LPTAG NextTag(LPTAG t);
\r
111 LPTAG PrevTag(LPTAG t);
\r
113 int GetFrameNo(LPTAG t);
\r
114 U16 GetTagID(LPTAG t);
\r
115 U32 GetDataSize(LPTAG t);
\r
116 U8* GetDataSizePtr(LPTAG t);
\r
118 U32 GetBits(LPTAG t,int nbits);
\r
119 S32 GetSBits(LPTAG t,int nbits);
\r
120 int SetBits(LPTAG t,U32 v,int nbits);
\r
122 int GetBlock(LPTAG t,U8 * b,int l); // resets Bitcount
\r
123 int SetBlock(LPTAG t,U8 * b,int l);
\r
125 U8 GetU8(LPTAG t); // resets Bitcount
\r
126 U16 GetU16(LPTAG t);
\r
127 U32 GetU32(LPTAG t);
\r
129 int SetU8(LPTAG t,U8 v); // resets Bitcount
\r
130 int SetU16(LPTAG t,U16 v);
\r
131 int SetU32(LPTAG t,U32 v);
\r
133 int GetPoint(LPTAG t,LPSPOINT p); // resets Bitcount
\r
134 int GetRect(LPTAG t,LPSRECT r);
\r
135 int GetMatrix(LPTAG t,LPMATRIX m);
\r
136 int GetCXForm(LPTAG t,LPCXFORM cx,U8 alpha);
\r
138 int SetPoint(LPTAG t,LPSPOINT p); // resets Bitcount
\r
139 int SetRect(LPTAG t,LPSRECT r);
\r
140 int SetMatrix(LPTAG t,LPMATRIX m);
\r
141 int SetCXForm(LPTAG t,LPCXFORM cx,U8 alpha);
\r
142 int SetRGB(LPTAG t,LPRGBA col);
\r
143 int SetRGBA(LPTAG t,LPRGBA col);
\r
147 #define GetS8(tag) ((S8)GetU8(tag))
\r
148 #define GetS16(tag) ((S16)GetU16(tag))
\r
149 #define GetS32(tag) ((S32)GetU32(tag))
\r
150 #define GetCoord(tag) ((SCOORD)GetU32(tag))
\r
151 #define GetFixed(tag) ((SFIXED)GetU32(tag))
\r
153 #define SetS8(tag,v) SetU8(tag,(U8)v)
\r
154 #define SetS16(tag,v) SetU16(tag,(U16)v)
\r
155 #define SetS32(tag,v) SetU32(tag,(U32)v)
\r
156 #define SetCoord(tag,v) SetU32(tag,(U32)v)
\r
157 #define SetFixed(tag,v) SetU32(tag,(U32)v)
\r
158 #define SetString(t,s) SetBlock(t,s,strlen(s)+1)
\r
160 #define FAILED(b) ((b)<0)
\r
161 #define SUCCEDED(b) ((b)>=0)
\r
163 // Tag IDs (adopted from J. C. Kessels' Form2Flash)
\r
166 #define ST_SHOWFRAME 1
\r
167 #define ST_DEFINESHAPE 2
\r
168 #define ST_FREECHARACTER 3
\r
169 #define ST_PLACEOBJECT 4
\r
170 #define ST_REMOVEOBJECT 5
\r
171 #define ST_DEFINEBITS 6
\r
172 #define ST_DEFINEBUTTON 7
\r
173 #define ST_JPEGTABLES 8
\r
174 #define ST_SETBACKGROUNDCOLOR 9
\r
175 #define ST_DEFINEFONT 10
\r
176 #define ST_DEFINETEXT 11
\r
177 #define ST_DOACTION 12
\r
178 #define ST_DEFINEFONTINFO 13
\r
179 #define ST_DEFINESOUND 14 /* Event sound tags. */
\r
180 #define ST_STARTSOUND 15
\r
181 #define ST_DEFINEBUTTONSOUND 17
\r
182 #define ST_SOUNDSTREAMHEAD 18
\r
183 #define ST_SOUNDSTREAMBLOCK 19
\r
184 #define ST_DEFINEBITSLOSSLESS 20 /* A bitmap using lossless zlib compression. */
\r
185 #define ST_DEFINEBITSJPEG2 21 /* A bitmap using an internal JPEG compression table. */
\r
186 #define ST_DEFINESHAPE2 22
\r
187 #define ST_DEFINEBUTTONCXFORM 23
\r
188 #define ST_PROTECT 24 /* This file should not be importable for editing. */
\r
189 #define ST_PLACEOBJECT2 26 /* The new style place w/ alpha color transform and name. */
\r
190 #define ST_REMOVEOBJECT2 28 /* A more compact remove object that omits the character tag (just depth). */
\r
191 #define ST_DEFINESHAPE3 32 /* A shape V3 includes alpha values. */
\r
192 #define ST_DEFINETEXT2 33 /* A text V2 includes alpha values. */
\r
193 #define ST_DEFINEBUTTON2 34 /* A button V2 includes color transform, alpha and multiple actions */
\r
194 #define ST_DEFINEBITSJPEG3 35 /* A JPEG bitmap with alpha info. */
\r
195 #define ST_DEFINEBITSLOSSLESS2 36 /* A lossless bitmap with alpha info. */
\r
196 #define ST_DEFINEEDITTEXT 37
\r
197 #define ST_DEFINEMOVIE 38
\r
198 #define ST_DEFINESPRITE 39 /* Define a sequence of tags that describe the behavior of a sprite. */
\r
199 #define ST_NAMECHARACTER 40 /* Name a character definition, character id and a string, (used for buttons, bitmaps, sprites and sounds). */
\r
200 #define ST_SERIALNUMBER 41
\r
201 #define ST_GENERATORTEXT 42 /* contains an id */
\r
202 #define ST_FRAMELABEL 43 /* A string label for the current frame. */
\r
203 #define ST_SOUNDSTREAMHEAD2 45 /* For lossless streaming sound, should not have needed this... */
\r
204 #define ST_DEFINEMORPHSHAPE 46 /* A morph shape definition */
\r
205 #define ST_DEFINEFONT2 48
\r
206 #define ST_TEMPLATECOMMAND 49
\r
207 #define ST_GENERATOR3 51
\r
208 #define ST_EXTERNALFONT 52
\r
210 #define ST_REFLEX 777 /* to identify generator software */
\r
212 // Advanced Funtions
\r
216 void DumpHeader(FILE * f,LPSWF swf);
\r
217 void DumpMatrix(FILE * f,LPMATRIX m);
\r
218 void DumpTag(FILE * f,LPTAG t);
\r
219 char* getTagName(TAG*tag);
\r
223 typedef struct _LINESTYLE
\r
226 } LINESTYLE, * LPLINESTYLE;
\r
228 typedef struct _FILLSTYLE
\r
233 } FILLSTYLE, * LPFILLSTYLE;
\r
235 typedef struct _SHAPE // NEVER access a Shape-Struct directly !
\r
238 { LPLINESTYLE data;
\r
241 // note: changes of shape structure
\r
242 struct // lead to incompatible .efont formats
\r
243 { LPFILLSTYLE data;
\r
256 U32 bitlen; // length of data in bits
\r
257 } SHAPE, * LPSHAPE;
\r
261 int NewShape(LPSHAPE * s);
\r
262 void ShapeFree(LPSHAPE s);
\r
264 int GetSimpleShape(LPTAG t,LPSHAPE * s); // without Linestyle/Fillstyle Record
\r
265 int SetSimpleShape(LPTAG t,LPSHAPE s); // without Linestyle/Fillstyle Record
\r
267 int ShapeAddLineStyle(LPSHAPE s,U16 width,LPRGBA color);
\r
268 int ShapeAddSolidFillStyle(LPSHAPE s,LPRGBA color);
\r
269 int ShapeAddBitmapFillStyle(LPSHAPE s,LPMATRIX m,U16 id_bitmap,int clip);
\r
271 int SetShapeStyles(LPTAG t,LPSHAPE s);
\r
272 int ShapeCountBits(LPSHAPE s,U8 * fbits,U8 * lbits);
\r
273 int SetShapeBits(LPTAG t,LPSHAPE s);
\r
274 int SetShapeHeader(LPTAG t,LPSHAPE s); // one call for upper three functions
\r
276 int ShapeSetMove(LPTAG t,LPSHAPE s,S32 x,S32 y);
\r
277 int ShapeSetStyle(LPTAG t,LPSHAPE s,U16 line,U16 fill0,U16 fill1);
\r
278 int ShapeSetAll(LPTAG t,LPSHAPE s,S32 x,S32 y,U16 line,U16 fill0,U16 fill1);
\r
280 int ShapeSetLine(LPTAG t,LPSHAPE s,S32 x,S32 y);
\r
281 int ShapeSetCurve(LPTAG t,LPSHAPE s,S32 x,S32 y,S32 ax,S32 ay);
\r
282 int ShapeSetCircle(LPTAG t,LPSHAPE s,S32 x,S32 y,S32 rx,S32 ry);
\r
283 int ShapeSetEnd(LPTAG t);
\r
288 // does not support wide characters !
\r
290 #define MAX_CHAR_PER_FONT 256
\r
292 typedef struct _SWFLAYOUT
\r
296 SRECT bounds[MAX_CHAR_PER_FONT];
\r
299 U8 * data; // size = count*4 bytes
\r
301 } SWFLAYOUT, * LPSWFLAYOUT;
\r
303 typedef struct _SWFFONT
\r
306 LPSWFLAYOUT layout;
\r
308 U8 flags; // bold/italic/unicode/ansi ...
\r
310 U16 codes[MAX_CHAR_PER_FONT];
\r
314 U16 gid; // Glyph-ID after DefineFont
\r
316 } glyph[MAX_CHAR_PER_FONT];
\r
317 } SWFFONT, * LPSWFFONT;
\r
319 typedef struct _FONTUSAGE
\r
320 { U8 code[MAX_CHAR_PER_FONT];
\r
321 } FONTUSAGE, * LPFONTUSAGE;
\r
323 int FontEnumerate(LPSWF swf,void (*FontCallback) (U16,U8*));
\r
324 // -> void fontcallback(U16 id,U8 * name); returns number of defined fonts
\r
326 int FontExtract(LPSWF swf,int id,LPSWFFONT * f);
\r
327 // Fetches all available information from DefineFont, DefineFontInfo, DefineText, ...
\r
328 // id = FontID, id=0 -> Extract first Font
\r
330 int FontIsItalic(LPSWFFONT f);
\r
331 int FontIsBold(LPSWFFONT f);
\r
333 int FontSetID(LPSWFFONT f,U16 id);
\r
334 int FontReduce(LPSWFFONT f,LPFONTUSAGE use);
\r
336 int FontInitUsage(LPFONTUSAGE use);
\r
337 int FontUse(LPFONTUSAGE use,U8 * s);
\r
339 int FontSetDefine(LPTAG t,LPSWFFONT f);
\r
340 int FontSetInfo(LPTAG t,LPSWFFONT f);
\r
342 int FontExport(int handle,LPSWFFONT f);
\r
343 int FontImport(int handle,LPSWFFONT * f);
\r
345 void FontFree(LPSWFFONT f);
\r
347 U32 TextGetWidth(LPSWFFONT font,U8 * s,int scale);
\r
348 int TextCountBits(LPSWFFONT font,U8 * s,int scale,U8 * gbits,U8 * abits);
\r
350 int TextSetInfoRecord(LPTAG t,LPSWFFONT font,U16 size,LPRGBA color,S16 dx,S16 dy);
\r
351 int TextSetCharRecord(LPTAG t,LPSWFFONT font,U8 * s,int scale,U8 gbits,U8 abits);
\r
353 int TextPrintDefineText(LPTAG t,LPSWFFONT f);
\r
354 // Prints text defined in tag t with font f to stdout
\r
359 // Always use ST_PLACEOBJECT2 !!!
\r
361 int ObjectPlace(LPTAG t,U16 id,U16 depth,LPMATRIX m,LPCXFORM cx,U8 * name);
\r
362 int PlaceObject(LPTAG t,U16 id,U16 depth,LPMATRIX m,LPCXFORM cx,U8 * name, U16 clipaction);
\r
363 int ObjectMove(LPTAG t,U16 depth,LPMATRIX m,LPCXFORM cx);
\r
369 #define BS_HIT 0x08
\r
370 #define BS_DOWN 0x04
\r
371 #define BS_OVER 0x02
\r
374 // Button Conditions
\r
376 #define BC_OVERDOWN_IDLE 0x0100
\r
377 #define BC_IDLE_OVERDOWN 0x0080
\r
378 #define BC_OUTDOWN_IDLE 0x0040
\r
379 #define BC_OUTDOWN_OVERDOWN 0x0020
\r
380 #define BC_OVERDOWN_OUTDOWN 0x0010
\r
381 #define BC_OVERDOWN_OVERUP 0x0008
\r
382 #define BC_OVERUP_OVERDOWN 0x0004
\r
383 #define BC_OVERUP_IDLE 0x0002
\r
384 #define BC_IDLE_OVERUP 0x0001
\r
386 #define BC_KEY(c) (c<<9)
\r
388 #define BC_CURSORLEFT 0x0200
\r
389 #define BC_CURSORRIGHT 0x0400
\r
390 #define BC_POS1 0x0600
\r
391 #define BC_END 0x0800
\r
392 #define BC_INSERT 0x0a00
\r
393 #define BC_DELETE 0x0c00
\r
394 #define BC_BACKSPACE 0x1000
\r
395 #define BC_ENTER 0x1a00
\r
396 #define BC_CURSORUP 0x1c00
\r
397 #define BC_CURSORDOWN 0x1e00
\r
398 #define BC_PAGEUP 0x2000
\r
399 #define BC_PAGEDOWN 0x2200
\r
400 #define BC_TAB 0x2400
\r
401 #define BC_SPACE 0x4000
\r
405 #define BF_TRACKMENU 0x01
\r
407 int ButtonSetRecord(LPTAG t,U8 state,U16 id,U16 layer,LPMATRIX m,LPCXFORM cx);
\r
408 int ButtonSetCondition(LPTAG t,U16 condition); // for DefineButton2
\r
409 int ButtonSetFlags(LPTAG t,U8 flags); // necessary for DefineButton2
\r
410 int ButtonPostProcess(LPTAG t,int anz_action); // Set all offsets in DefineButton2-Tags (how many conditions to process)
\r
414 typedef int * LPJPEGBITS; // cover libjpeg structures
\r
416 LPJPEGBITS SetJPEGBitsStart(LPTAG t,int width,int height,int quality);
\r
417 int SetJPEGBitsLines(LPJPEGBITS jpegbits,U8 ** data,int n);
\r
418 int SetJPEGBitsLine(LPJPEGBITS jpegbits,U8 * data);
\r
419 int SetJPEGBitsFinish(LPJPEGBITS jpegbits);
\r
421 int SetJPEGBits(LPTAG t,char * fname,int quality); // paste jpg file into swf stream
\r
425 char isDefiningTag(LPTAG t);
\r
426 char isAllowedSpriteTag(LPTAG t);
\r
427 U16 GetDefineID(LPTAG t);
\r
428 U16 GetPlaceID(LPTAG t); //PLACEOBJECT, PLACEOBJECT2 (sometimes), REMOVEOBJECT
\r
429 U16 GetDepth(LPTAG t); //PLACEOBJECT,PLACEOBJECT2,REMOVEOBJECT,REMOVEOBJECT2
\r
430 char* GetName(LPTAG t); //PLACEOBJECT2, FRAMELABEL
\r
431 LPMATRIX MatrixJoin(LPMATRIX d,LPMATRIX s1,LPMATRIX s2);
\r
432 LPMATRIX MatrixMapTriangle(LPMATRIX m,int dx,int dy,
\r
433 int x0,int y0,int x1,int y1,int x2,int y2);
\r
438 void uncgi(); // same behaviour as Steven Grimm's uncgi-library
\r