3 Math and matrix functions, misc tools
5 Extension module for the rfxswf library.
6 Part of the swftools package.
8 Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>
10 This file is distributed under the GPL, see file COPYING for details
14 // Matrix & Math tools for SWF files
17 SFIXED RFXSWF_SP(SFIXED a1,SFIXED a2,SFIXED b1,SFIXED b2)
19 a = (S64)a1*(S64)b1+(S64)a2*(S64)b2;
20 return (SFIXED)(a>>16);
22 SFIXED RFXSWF_QFIX(int zaehler,int nenner) // bildet Quotient von zwei INTs in SFIXED
23 { S64 z = zaehler<<16;
24 S64 a = z/(S64)nenner;
29 MATRIX * swf_MatrixJoin(MATRIX * d,MATRIX * s1,MATRIX * s2)
32 if (!s1) return (s2)?(MATRIX *)memcpy(d,s2,sizeof(MATRIX)):NULL;
33 if (!s2) return (MATRIX *)memcpy(d,s1,sizeof(MATRIX));
35 d->tx = s1->tx + s2->tx;
36 d->ty = s1->ty + s2->ty;
38 d->sx = RFXSWF_SP(s1->sx,s1->r1,s2->sx,s2->r0);
39 d->sy = RFXSWF_SP(s1->r0,s1->sy,s2->r1,s2->sy);
40 d->r0 = RFXSWF_SP(s1->r0,s1->sy,s2->sx,s2->r0);
41 d->r1 = RFXSWF_SP(s1->sx,s1->r1,s2->r1,s2->sy);
48 MATRIX * swf_MatrixMapTriangle(MATRIX * m,int dx,int dy,int x0,int y0,
49 int x1,int y1,int x2,int y2)
56 if ((!dx)||(!dy)) return NULL; // check DIV by zero
60 m->sx = RFXSWF_QFIX(dx1,dx);
61 m->sy = RFXSWF_QFIX(dy2,dy);
62 m->r0 = RFXSWF_QFIX(dy1,dx);
63 m->r1 = RFXSWF_QFIX(dx2,dy);
68 U16 swf_GetDefineID(TAG * t)
73 oldTagPos = swf_GetTagPos(t);
76 switch (swf_GetTagID(t))
77 { case ST_DEFINESHAPE:
80 case ST_DEFINEMORPHSHAPE:
81 case ST_DEFINEEDITTEXT:
83 case ST_DEFINEBITSJPEG2:
84 case ST_DEFINEBITSJPEG3:
85 case ST_DEFINEBITSLOSSLESS:
86 case ST_DEFINEBITSLOSSLESS2:
88 case ST_DEFINEBUTTON2:
89 case ST_DEFINEBUTTONCXFORM: //pseudodefine
90 case ST_DEFINEBUTTONSOUND: //pseudodefine
93 case ST_DEFINEFONTINFO: //pseudodefine
98 case ST_NAMECHARACTER: //pseudodefine
103 swf_SetTagPos(t,oldTagPos);
108 U16 swf_GetPlaceID(TAG * t)
113 oldTagPos = swf_GetTagPos(t);
116 switch (swf_GetTagID(t))
117 { case ST_PLACEOBJECT:
118 case ST_REMOVEOBJECT:
123 case ST_PLACEOBJECT2:
124 { U8 flags = swf_GetU8(t);
125 U16 d = swf_GetU16(t);
126 id = (flags&PF_CHAR)?swf_GetU16(t):id;
131 swf_SetTagPos(t,oldTagPos);
136 static int swf_definingtagids[] =
149 ST_DEFINEBITSLOSSLESS,
150 ST_DEFINEBITSLOSSLESS2,
159 // tags which may be used inside a sprite definition
160 static int swf_spritetagids[] =
165 ST_REMOVEOBJECT2, //?
176 static int swf_pseudodefiningtagids[] =
179 ST_DEFINEBUTTONCXFORM,
180 ST_DEFINEBUTTONSOUND,
185 U8 swf_isAllowedSpriteTag(TAG * tag)
189 while(swf_spritetagids[t]>=0)
191 if(swf_spritetagids[t] == id)
198 U8 swf_isDefiningTag(TAG * tag)
202 while(swf_definingtagids[t]>=0)
204 if(swf_definingtagids[t] == id)
211 U8 swf_isPseudoDefiningTag(TAG * tag)
215 while(swf_pseudodefiningtagids[t]>=0)
217 if(swf_pseudodefiningtagids[t] == id)
224 U16 swf_GetDepth(TAG * t)
229 oldTagPos = swf_GetTagPos(t);
232 switch (swf_GetTagID(t))
233 { case ST_PLACEOBJECT:
234 case ST_REMOVEOBJECT:
236 depth = swf_GetU16(t);
238 case ST_REMOVEOBJECT2:
239 depth = swf_GetU16(t);
241 case ST_PLACEOBJECT2:
242 { U8 flags = swf_GetU8(t);
243 depth = swf_GetU16(t);
246 swf_SetTagPos(t,oldTagPos);
250 char* swf_GetName(TAG * t)
256 oldTagPos = swf_GetTagPos(t);
258 switch(swf_GetTagID(t))
261 name = &t->data[swf_GetTagPos(t)];
263 case ST_PLACEOBJECT2: {
264 U8 flags = swf_GetU8(t);
265 swf_GetU16(t); //depth;
269 swf_GetMatrix(t, &m);
271 swf_GetCXForm(t, &c, 1);
275 swf_ResetReadBits(t);
276 name = &t->data[swf_GetTagPos(t)];
281 swf_SetTagPos(t,oldTagPos);