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:
82 case ST_DEFINEBITSJPEG2:
83 case ST_DEFINEBITSJPEG3:
84 case ST_DEFINEBITSLOSSLESS:
85 case ST_DEFINEBITSLOSSLESS2:
87 case ST_DEFINEBUTTON2:
88 case ST_DEFINEBUTTONCXFORM:
89 case ST_DEFINEBUTTONSOUND:
92 case ST_DEFINEFONTINFO:
101 swf_SetTagPos(t,oldTagPos);
106 U16 swf_GetPlaceID(TAG * t)
111 oldTagPos = swf_GetTagPos(t);
114 switch (swf_GetTagID(t))
115 { case ST_PLACEOBJECT:
116 case ST_REMOVEOBJECT:
121 case ST_PLACEOBJECT2:
122 { U8 flags = swf_GetU8(t);
123 U16 d = swf_GetU16(t);
124 id = (flags&PF_CHAR)?swf_GetU16(t):id;
129 swf_SetTagPos(t,oldTagPos);
134 int definingtagids[] =
147 ST_DEFINEBITSLOSSLESS,
148 ST_DEFINEBITSLOSSLESS2,
157 // tags which may be used inside a sprite definition
163 ST_REMOVEOBJECT2, //?
174 U8 swf_isAllowedSpriteTag(TAG * tag)
178 while(spritetagids[t]>=0)
180 if(spritetagids[t] == id)
187 U8 swf_isDefiningTag(TAG * tag)
191 while(definingtagids[t]>=0)
193 if(definingtagids[t] == id)
200 U16 swf_GetDepth(TAG * t)
205 oldTagPos = swf_GetTagPos(t);
208 switch (swf_GetTagID(t))
209 { case ST_PLACEOBJECT:
210 case ST_REMOVEOBJECT:
212 depth = swf_GetU16(t);
214 case ST_REMOVEOBJECT2:
215 depth = swf_GetU16(t);
217 case ST_PLACEOBJECT2:
218 { U8 flags = swf_GetU8(t);
219 depth = swf_GetU16(t);
222 swf_SetTagPos(t,oldTagPos);
226 char* swf_GetTagName(TAG * t)
232 oldTagPos = swf_GetTagPos(t);
234 switch(swf_GetTagID(t))
237 name = &t->data[swf_GetTagPos(t)];
239 case ST_PLACEOBJECT2: {
240 U8 flags = swf_GetU8(t);
241 swf_GetU16(t); //depth;
245 swf_GetMatrix(t, &m);
247 swf_GetCXForm(t, &c, 1);
252 name = &t->data[swf_GetTagPos(t)];
257 swf_SetTagPos(t,oldTagPos);