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
21 #define DEBUG_RFXSWF
\r
25 typedef unsigned long U32;
\r
26 typedef signed long S32;
\r
27 typedef unsigned short U16;
\r
28 typedef signed short S16;
\r
29 typedef unsigned char U8;
\r
30 typedef signed char S8;
\r
31 typedef signed long SFIXED;
\r
32 typedef signed long SCOORD;
\r
36 typedef struct _SPOINT
\r
39 } SPOINT, * LPSPOINT;
\r
41 typedef struct _RGBA
\r
48 typedef struct _SRECT
\r
55 typedef struct _MATRIX
\r
56 { SFIXED sx; // factor x
\r
58 SFIXED r0; // rotation
\r
60 SCOORD tx; // delta x
\r
62 } MATRIX, * LPMATRIX;
\r
64 typedef struct _CXFORM
\r
69 } CXFORM, * LPCXFORM;
\r
71 typedef struct _TAG // NEVER access a Tag-Struct directly !
\r
81 U32 memsize; // to minimize realloc() calls
\r
82 U32 pos; // for Get/Set-Access
\r
83 U8 bitmask; // for Bit-Manipulating Functions [read]
\r
84 U8 bitcount; // [write]
\r
89 U32 FileSize; // valid after load and save
\r
92 U16 FrameCount; // valid after load and save
\r
98 int ReadSWF(int handle,LPSWF swf); // Reads SWF to memory (malloc'ed), returns length or <0 if fails
\r
99 int WriteSWF(int handle,LPSWF swf); // Writes SWF to file, returns length or <0 if fails
\r
100 int WriteCGI(LPSWF swf); // Outputs SWF with valid CGI header to stdout
\r
101 void FreeTags(LPSWF swf); // Frees all malloc'ed memory for swf
\r
103 LPTAG InsertTag(LPTAG after,U16 id); // updates frames, if necessary
\r
104 int DeleteTag(LPTAG t);
\r
106 void SetTagPos(LPTAG t,U32 pos); // resets Bitcount
\r
107 U32 GetTagPos(LPTAG t);
\r
109 LPTAG NextTag(LPTAG t);
\r
110 LPTAG PrevTag(LPTAG t);
\r
112 int GetFrameNo(LPTAG t);
\r
113 U16 GetTagID(LPTAG t);
\r
114 U32 GetDataSize(LPTAG t);
\r
115 U8* GetDataSizePtr(LPTAG t);
\r
117 U32 GetBits(LPTAG t,int nbits);
\r
118 S32 GetSBits(LPTAG t,int nbits);
\r
119 int SetBits(LPTAG t,U32 v,int nbits);
\r
121 int GetBlock(LPTAG t,U8 * b,int l); // resets Bitcount
\r
122 int SetBlock(LPTAG t,U8 * b,int l);
\r
124 U8 GetU8(LPTAG t); // resets Bitcount
\r
125 U16 GetU16(LPTAG t);
\r
126 U32 GetU32(LPTAG t);
\r
128 int SetU8(LPTAG t,U8 v); // resets Bitcount
\r
129 int SetU16(LPTAG t,U16 v);
\r
130 int SetU32(LPTAG t,U32 v);
\r
132 int GetPoint(LPTAG t,LPSPOINT p); // resets Bitcount
\r
133 int GetRect(LPTAG t,LPSRECT r);
\r
134 int GetMatrix(LPTAG t,LPMATRIX m);
\r
135 int GetCXForm(LPTAG t,LPCXFORM cx,U8 alpha);
\r
137 int SetPoint(LPTAG t,LPSPOINT p); // resets Bitcount
\r
138 int SetRect(LPTAG t,LPSRECT r);
\r
139 int SetMatrix(LPTAG t,LPMATRIX m);
\r
140 int SetCXForm(LPTAG t,LPCXFORM cx,U8 alpha);
\r
141 int SetRGB(LPTAG t,LPRGBA col);
\r
142 int SetRGBA(LPTAG t,LPRGBA col);
\r
146 #define GetS8(tag) ((S8)GetU8(tag))
\r
147 #define GetS16(tag) ((S16)GetU16(tag))
\r
148 #define GetS32(tag) ((S32)GetU32(tag))
\r
149 #define GetCoord(tag) ((SCOORD)GetU32(tag))
\r
150 #define GetFixed(tag) ((SFIXED)GetU32(tag))
\r
152 #define SetS8(tag,v) SetU8(tag,(U8)v)
\r
153 #define SetS16(tag,v) SetU16(tag,(U16)v)
\r
154 #define SetS32(tag,v) SetU32(tag,(U32)v)
\r
155 #define SetCoord(tag,v) SetU32(tag,(U32)v)
\r
156 #define SetFixed(tag,v) SetU32(tag,(U32)v)
\r
157 #define SetString(t,s) SetBlock(t,s,strlen(s)+1)
\r
159 #define FAILED(b) ((b)<0)
\r
160 #define SUCCEDED(b) ((b)>=0)
\r
162 // Tag IDs (adopted from J. C. Kessels' Form2Flash)
\r
165 #define ST_SHOWFRAME 1
\r
166 #define ST_DEFINESHAPE 2
\r
167 #define ST_FREECHARACTER 3
\r
168 #define ST_PLACEOBJECT 4
\r
169 #define ST_REMOVEOBJECT 5
\r
170 #define ST_DEFINEBITS 6
\r
171 #define ST_DEFINEBUTTON 7
\r
172 #define ST_JPEGTABLES 8
\r
173 #define ST_SETBACKGROUNDCOLOR 9
\r
174 #define ST_DEFINEFONT 10
\r
175 #define ST_DEFINETEXT 11
\r
176 #define ST_DOACTION 12
\r
177 #define ST_DEFINEFONTINFO 13
\r
178 #define ST_DEFINESOUND 14 /* Event sound tags. */
\r
179 #define ST_STARTSOUND 15
\r
180 #define ST_DEFINEBUTTONSOUND 17
\r
181 #define ST_SOUNDSTREAMHEAD 18
\r
182 #define ST_SOUNDSTREAMBLOCK 19
\r
183 #define ST_DEFINEBITSLOSSLESS 20 /* A bitmap using lossless zlib compression. */
\r
184 #define ST_DEFINEBITSJPEG2 21 /* A bitmap using an internal JPEG compression table. */
\r
185 #define ST_DEFINESHAPE2 22
\r
186 #define ST_DEFINEBUTTONCXFORM 23
\r
187 #define ST_PROTECT 24 /* This file should not be importable for editing. */
\r
188 #define ST_PLACEOBJECT2 26 /* The new style place w/ alpha color transform and name. */
\r
189 #define ST_REMOVEOBJECT2 28 /* A more compact remove object that omits the character tag (just depth). */
\r
190 #define ST_DEFINESHAPE3 32 /* A shape V3 includes alpha values. */
\r
191 #define ST_DEFINETEXT2 33 /* A text V2 includes alpha values. */
\r
192 #define ST_DEFINEBUTTON2 34 /* A button V2 includes color transform, alpha and multiple actions */
\r
193 #define ST_DEFINEBITSJPEG3 35 /* A JPEG bitmap with alpha info. */
\r
194 #define ST_DEFINEBITSLOSSLESS2 36 /* A lossless bitmap with alpha info. */
\r
195 #define ST_DEFINEEDITTEXT 37
\r
196 #define ST_DEFINEMOVIE 38
\r
197 #define ST_DEFINESPRITE 39 /* Define a sequence of tags that describe the behavior of a sprite. */
\r
198 #define ST_NAMECHARACTER 40 /* Name a character definition, character id and a string, (used for buttons, bitmaps, sprites and sounds). */
\r
199 #define ST_SERIALNUMBER 41
\r
200 #define ST_GENERATORTEXT 42 /* contains an id */
\r
201 #define ST_FRAMELABEL 43 /* A string label for the current frame. */
\r
202 #define ST_SOUNDSTREAMHEAD2 45 /* For lossless streaming sound, should not have needed this... */
\r
203 #define ST_DEFINEMORPHSHAPE 46 /* A morph shape definition */
\r
204 #define ST_DEFINEFONT2 48
\r
205 #define ST_TEMPLATECOMMAND 49
\r
206 #define ST_GENERATOR3 51
\r
207 #define ST_EXTERNALFONT 52
\r
209 #define ST_REFLEX 777 /* to identify generator software */
\r
211 // Advanced Funtions
\r
215 void DumpHeader(FILE * f,LPSWF swf);
\r
216 void DumpMatrix(FILE * f,LPMATRIX m);
\r
217 void DumpTag(FILE * f,LPTAG t);
\r
218 char* getTagName(TAG*tag);
\r
222 typedef struct _LINESTYLE
\r
225 } LINESTYLE, * LPLINESTYLE;
\r
227 typedef struct _FILLSTYLE
\r
232 } FILLSTYLE, * LPFILLSTYLE;
\r
234 typedef struct _SHAPE // NEVER access a Shape-Struct directly !
\r
237 { LPLINESTYLE data;
\r
240 // note: changes of shape structure
\r
241 struct // lead to incompatible .efont formats
\r
242 { LPFILLSTYLE data;
\r
255 U32 bitlen; // length of data in bits
\r
256 } SHAPE, * LPSHAPE;
\r
260 int NewShape(LPSHAPE * s);
\r
261 void ShapeFree(LPSHAPE s);
\r
263 int GetSimpleShape(LPTAG t,LPSHAPE * s); // without Linestyle/Fillstyle Record
\r
264 int SetSimpleShape(LPTAG t,LPSHAPE s); // without Linestyle/Fillstyle Record
\r
266 int ShapeAddLineStyle(LPSHAPE s,U16 width,LPRGBA color);
\r
267 int ShapeAddSolidFillStyle(LPSHAPE s,LPRGBA color);
\r
268 int ShapeAddBitmapFillStyle(LPSHAPE s,LPMATRIX m,U16 id_bitmap,int clip);
\r
270 int SetShapeStyles(LPTAG t,LPSHAPE s);
\r
271 int ShapeCountBits(LPSHAPE s,U8 * fbits,U8 * lbits);
\r
272 int SetShapeBits(LPTAG t,LPSHAPE s);
\r
273 int SetShapeHeader(LPTAG t,LPSHAPE s); // one call for upper three functions
\r
275 int ShapeSetMove(LPTAG t,LPSHAPE s,S32 x,S32 y);
\r
276 int ShapeSetStyle(LPTAG t,LPSHAPE s,U16 line,U16 fill0,U16 fill1);
\r
277 int ShapeSetAll(LPTAG t,LPSHAPE s,S32 x,S32 y,U16 line,U16 fill0,U16 fill1);
\r
279 int ShapeSetLine(LPTAG t,LPSHAPE s,S32 x,S32 y);
\r
280 int ShapeSetCurve(LPTAG t,LPSHAPE s,S32 x,S32 y,S32 ax,S32 ay);
\r
281 int ShapeSetCircle(LPTAG t,LPSHAPE s,S32 x,S32 y,S32 rx,S32 ry);
\r
282 int ShapeSetEnd(LPTAG t);
\r
287 // does not support wide characters !
\r
289 #define MAX_CHAR_PER_FONT 256
\r
291 typedef struct _SWFLAYOUT
\r
295 SRECT bounds[MAX_CHAR_PER_FONT];
\r
298 U8 * data; // size = count*4 bytes
\r
300 } SWFLAYOUT, * LPSWFLAYOUT;
\r
302 typedef struct _SWFFONT
\r
305 LPSWFLAYOUT layout;
\r
307 U8 flags; // bold/italic/unicode/ansi ...
\r
309 U16 codes[MAX_CHAR_PER_FONT];
\r
313 U16 gid; // Glyph-ID after DefineFont
\r
315 } glyph[MAX_CHAR_PER_FONT];
\r
316 } SWFFONT, * LPSWFFONT;
\r
318 typedef struct _FONTUSAGE
\r
319 { U8 code[MAX_CHAR_PER_FONT];
\r
320 } FONTUSAGE, * LPFONTUSAGE;
\r
322 int FontEnumerate(LPSWF swf,void (*FontCallback) (U16,U8*));
\r
323 // -> void fontcallback(U16 id,U8 * name); returns number of defined fonts
\r
325 int FontExtract(LPSWF swf,int id,LPSWFFONT * f);
\r
326 // Fetches all available information from DefineFont, DefineFontInfo, DefineText, ...
\r
327 // id = FontID, id=0 -> Extract first Font
\r
329 int FontIsItalic(LPSWFFONT f);
\r
330 int FontIsBold(LPSWFFONT f);
\r
332 int FontSetID(LPSWFFONT f,U16 id);
\r
333 int FontReduce(LPSWFFONT f,LPFONTUSAGE use);
\r
335 int FontInitUsage(LPFONTUSAGE use);
\r
336 int FontUse(LPFONTUSAGE use,U8 * s);
\r
338 int FontSetDefine(LPTAG t,LPSWFFONT f);
\r
339 int FontSetInfo(LPTAG t,LPSWFFONT f);
\r
341 int FontExport(int handle,LPSWFFONT f);
\r
342 int FontImport(int handle,LPSWFFONT * f);
\r
344 void FontFree(LPSWFFONT f);
\r
346 U32 TextGetWidth(LPSWFFONT font,U8 * s,int scale);
\r
347 int TextCountBits(LPSWFFONT font,U8 * s,int scale,U8 * gbits,U8 * abits);
\r
349 int TextSetInfoRecord(LPTAG t,LPSWFFONT font,U16 size,LPRGBA color,S16 dx,S16 dy);
\r
350 int TextSetCharRecord(LPTAG t,LPSWFFONT font,U8 * s,int scale,U8 gbits,U8 abits);
\r
352 int TextPrintDefineText(LPTAG t,LPSWFFONT f);
\r
353 // Prints text defined in tag t with font f to stdout
\r
358 // Always use ST_PLACEOBJECT2 !!!
\r
360 int ObjectPlace(LPTAG t,U16 id,U16 depth,LPMATRIX m,LPCXFORM cx,U8 * name);
\r
361 int PlaceObject(LPTAG t,U16 id,U16 depth,LPMATRIX m,LPCXFORM cx,U8 * name, U16 clipaction);
\r
362 int ObjectMove(LPTAG t,U16 depth,LPMATRIX m,LPCXFORM cx);
\r
368 #define BS_HIT 0x08
\r
369 #define BS_DOWN 0x04
\r
370 #define BS_OVER 0x02
\r
373 // Button Conditions
\r
375 #define BC_OVERDOWN_IDLE 0x0100
\r
376 #define BC_IDLE_OVERDOWN 0x0080
\r
377 #define BC_OUTDOWN_IDLE 0x0040
\r
378 #define BC_OUTDOWN_OVERDOWN 0x0020
\r
379 #define BC_OVERDOWN_OUTDOWN 0x0010
\r
380 #define BC_OVERDOWN_OVERUP 0x0008
\r
381 #define BC_OVERUP_OVERDOWN 0x0004
\r
382 #define BC_OVERUP_IDLE 0x0002
\r
383 #define BC_IDLE_OVERUP 0x0001
\r
385 #define BC_KEY(c) (c<<9)
\r
387 #define BC_CURSORLEFT 0x0200
\r
388 #define BC_CURSORRIGHT 0x0400
\r
389 #define BC_POS1 0x0600
\r
390 #define BC_END 0x0800
\r
391 #define BC_INSERT 0x0a00
\r
392 #define BC_DELETE 0x0c00
\r
393 #define BC_BACKSPACE 0x1000
\r
394 #define BC_ENTER 0x1a00
\r
395 #define BC_CURSORUP 0x1c00
\r
396 #define BC_CURSORDOWN 0x1e00
\r
397 #define BC_PAGEUP 0x2000
\r
398 #define BC_PAGEDOWN 0x2200
\r
399 #define BC_TAB 0x2400
\r
400 #define BC_SPACE 0x4000
\r
404 #define BF_TRACKMENU 0x01
\r
406 int ButtonSetRecord(LPTAG t,U8 state,U16 id,U16 layer,LPMATRIX m,LPCXFORM cx);
\r
407 int ButtonSetCondition(LPTAG t,U16 condition); // for DefineButton2
\r
408 int ButtonSetFlags(LPTAG t,U8 flags); // necessary for DefineButton2
\r
409 int ButtonPostProcess(LPTAG t,int anz_action); // Set all offsets in DefineButton2-Tags (how many conditions to process)
\r
413 typedef int * LPJPEGBITS; // cover libjpeg structures
\r
415 LPJPEGBITS SetJPEGBitsStart(LPTAG t,int width,int height,int quality);
\r
416 int SetJPEGBitsLines(LPJPEGBITS jpegbits,U8 ** data,int n);
\r
417 int SetJPEGBitsLine(LPJPEGBITS jpegbits,U8 * data);
\r
418 int SetJPEGBitsFinish(LPJPEGBITS jpegbits);
\r
420 int SetJPEGBits(LPTAG t,char * fname,int quality); // paste jpg file into swf stream
\r
424 char isDefiningTag(LPTAG t);
\r
425 char isAllowedSpriteTag(LPTAG t);
\r
426 U16 GetDefineID(LPTAG t);
\r
427 U16 GetPlaceID(LPTAG t); //PLACEOBJECT, PLACEOBJECT2 (sometimes), REMOVEOBJECT
\r
428 U16 GetDepth(LPTAG t); //PLACEOBJECT,PLACEOBJECT2,REMOVEOBJECT,REMOVEOBJECT2
\r
429 char* GetName(LPTAG t); //PLACEOBJECT2, FRAMELABEL
\r
430 LPMATRIX MatrixJoin(LPMATRIX d,LPMATRIX s1,LPMATRIX s2);
\r
431 LPMATRIX MatrixMapTriangle(LPMATRIX m,int dx,int dy,
\r
432 int x0,int y0,int x1,int y1,int x2,int y2);
\r
437 void uncgi(); // same behaviour as Steven Grimm's uncgi-library
\r