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:
90 case ST_DEFINEBUTTONSOUND:
93 case ST_DEFINEFONTINFO:
102 swf_SetTagPos(t,oldTagPos);
107 U16 swf_GetPlaceID(TAG * t)
112 oldTagPos = swf_GetTagPos(t);
115 switch (swf_GetTagID(t))
116 { case ST_PLACEOBJECT:
117 case ST_REMOVEOBJECT:
122 case ST_PLACEOBJECT2:
123 { U8 flags = swf_GetU8(t);
124 U16 d = swf_GetU16(t);
125 id = (flags&PF_CHAR)?swf_GetU16(t):id;
130 swf_SetTagPos(t,oldTagPos);
135 int definingtagids[] =
148 ST_DEFINEBITSLOSSLESS,
149 ST_DEFINEBITSLOSSLESS2,
158 // tags which may be used inside a sprite definition
164 ST_REMOVEOBJECT2, //?
175 U8 swf_isAllowedSpriteTag(TAG * tag)
179 while(spritetagids[t]>=0)
181 if(spritetagids[t] == id)
188 U8 swf_isDefiningTag(TAG * tag)
192 while(definingtagids[t]>=0)
194 if(definingtagids[t] == id)
201 U16 swf_GetDepth(TAG * t)
206 oldTagPos = swf_GetTagPos(t);
209 switch (swf_GetTagID(t))
210 { case ST_PLACEOBJECT:
211 case ST_REMOVEOBJECT:
213 depth = swf_GetU16(t);
215 case ST_REMOVEOBJECT2:
216 depth = swf_GetU16(t);
218 case ST_PLACEOBJECT2:
219 { U8 flags = swf_GetU8(t);
220 depth = swf_GetU16(t);
223 swf_SetTagPos(t,oldTagPos);
227 char* swf_GetName(TAG * t)
233 oldTagPos = swf_GetTagPos(t);
235 switch(swf_GetTagID(t))
238 name = &t->data[swf_GetTagPos(t)];
240 case ST_PLACEOBJECT2: {
241 U8 flags = swf_GetU8(t);
242 swf_GetU16(t); //depth;
246 swf_GetMatrix(t, &m);
248 swf_GetCXForm(t, &c, 1);
252 swf_ResetReadBits(t);
253 name = &t->data[swf_GetTagPos(t)];
258 swf_SetTagPos(t,oldTagPos);