removed the ttf2pt1 binary.
[swftools.git] / lib / modules / swftools.c
1 /* swftools.c
2
3    Math and matrix functions, misc tools
4
5    Extension module for the rfxswf library.
6    Part of the swftools package.
7
8    Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>
9  
10    This file is distributed under the GPL, see file COPYING for details 
11
12 */
13
14 // Matrix & Math tools for SWF files
15
16 #define S64 long long
17 SFIXED RFXSWF_SP(SFIXED a1,SFIXED a2,SFIXED b1,SFIXED b2)
18 { S64 a;
19   a = (S64)a1*(S64)b1+(S64)a2*(S64)b2;
20   return (SFIXED)(a>>16);
21 }
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;
25   return (SFIXED)a;
26 }
27 #undef S64
28
29 MATRIX * swf_MatrixJoin(MATRIX * d,MATRIX * s1,MATRIX * s2)
30 {        
31   if (!d) return NULL;
32   if (!s1) return (s2)?(MATRIX *)memcpy(d,s2,sizeof(MATRIX)):NULL;
33   if (!s2) return (MATRIX *)memcpy(d,s1,sizeof(MATRIX));
34   
35   d->tx = s1->tx + s2->tx;
36   d->ty = s1->ty + s2->ty;
37   
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);
42
43   //DumpMatrix(NULL,d);
44   
45   return d;
46 }
47
48 MATRIX * swf_MatrixMapTriangle(MATRIX * m,int dx,int dy,int x0,int y0,
49                                int x1,int y1,int x2,int y2)
50 { int dx1 = x1 - x0;
51   int dy1 = y1 - y0;
52   int dx2 = x2 - x0;
53   int dy2 = y2 - y0;
54   
55   if (!m) return NULL;
56   if ((!dx)||(!dy)) return NULL; // check DIV by zero
57
58   m->tx = x0;
59   m->ty = y0;
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);
64   
65   return m;
66 }
67
68 void swf_SetDefineID(TAG * tag, U16 newid)
69 {
70   int oldlen = tag->len;
71   tag->len = 0;
72   swf_SetU16(tag, newid); /* set defining ID */
73   tag->len = oldlen;
74 }
75
76 U16 swf_GetDefineID(TAG * t)
77 // up to SWF 4.0
78 { U32 oldTagPos;
79   U16 id = 0;
80
81   oldTagPos = swf_GetTagPos(t);
82   swf_SetTagPos(t,0);
83
84   switch (swf_GetTagID(t))
85   { case ST_DEFINESHAPE:
86     case ST_DEFINESHAPE2:
87     case ST_DEFINESHAPE3:
88     case ST_DEFINEMORPHSHAPE:
89     case ST_DEFINEEDITTEXT:
90     case ST_DEFINEBITS:
91     case ST_DEFINEBITSJPEG2:
92     case ST_DEFINEBITSJPEG3:
93     case ST_DEFINEBITSLOSSLESS:
94     case ST_DEFINEBITSLOSSLESS2:
95     case ST_DEFINEBUTTON:
96     case ST_DEFINEBUTTON2:
97     case ST_DEFINEBUTTONCXFORM: //pseudodefine
98     case ST_DEFINEBUTTONSOUND: //pseudodefine
99     case ST_DEFINEFONT:
100     case ST_DEFINEFONT2:
101     case ST_DEFINEFONTINFO: //pseudodefine
102     case ST_DEFINETEXT:
103     case ST_DEFINETEXT2:
104     case ST_DEFINESOUND:
105     case ST_DEFINESPRITE:
106     case ST_NAMECHARACTER: //pseudodefine
107       id = swf_GetU16(t);
108       break;
109   }
110
111   swf_SetTagPos(t,oldTagPos);
112
113   return id;
114 }
115
116 U16 swf_GetPlaceID(TAG * t)
117 // up to SWF 4.0
118 { U32 oldTagPos;
119   U16 id = 0;
120
121   oldTagPos = swf_GetTagPos(t);
122   swf_SetTagPos(t,0);
123
124   switch (swf_GetTagID(t))
125   { case ST_PLACEOBJECT:
126     case ST_REMOVEOBJECT:
127     case ST_FREECHARACTER:
128     case ST_STARTSOUND:
129       id = swf_GetU16(t);
130       break;
131
132     case ST_PLACEOBJECT2:
133     { U8 flags = swf_GetU8(t);
134       U16 d = swf_GetU16(t);
135       id = (flags&PF_CHAR)?swf_GetU16(t):id;
136     } break;
137
138   }
139
140   swf_SetTagPos(t,oldTagPos);
141
142   return id;
143 }
144
145 static int swf_definingtagids[] =
146 {ST_DEFINESHAPE,
147  ST_DEFINESHAPE2,
148  ST_DEFINESHAPE3,
149  ST_DEFINEMORPHSHAPE,
150  ST_DEFINEFONT,
151  ST_DEFINEFONT2,
152  ST_DEFINETEXT,
153  ST_DEFINETEXT2,
154  ST_DEFINEEDITTEXT,
155  ST_DEFINEBITS,
156  ST_DEFINEBITSJPEG2,
157  ST_DEFINEBITSJPEG3,
158  ST_DEFINEBITSLOSSLESS,
159  ST_DEFINEBITSLOSSLESS2,
160  ST_DEFINEMOVIE,
161  ST_DEFINESPRITE,
162  ST_DEFINEBUTTON,
163  ST_DEFINEBUTTON2,
164  ST_DEFINESOUND,
165  -1
166 };
167
168 // tags which may be used inside a sprite definition
169 static int swf_spritetagids[] =
170 {ST_SHOWFRAME,
171  ST_PLACEOBJECT,
172  ST_PLACEOBJECT2,
173  ST_REMOVEOBJECT,
174  ST_REMOVEOBJECT2, //?
175  ST_DOACTION,
176  ST_STARTSOUND,
177  ST_FRAMELABEL,
178  ST_SOUNDSTREAMHEAD,
179  ST_SOUNDSTREAMHEAD2,
180  ST_SOUNDSTREAMBLOCK,
181  ST_END,
182  -1
183 };
184
185 static int swf_pseudodefiningtagids[] = 
186 {
187  ST_DEFINEFONTINFO,
188  ST_DEFINEBUTTONCXFORM,
189  ST_DEFINEBUTTONSOUND,
190  ST_NAMECHARACTER,
191  -1
192 };
193
194 U8 swf_isAllowedSpriteTag(TAG * tag)
195 {
196     int id = tag->id;
197     int t=0;
198     while(swf_spritetagids[t]>=0)
199     {
200         if(swf_spritetagids[t] == id) 
201             return 1;
202         t++;
203     }
204     return 0; 
205 }
206
207 U8 swf_isDefiningTag(TAG * tag)
208 {
209     int id = tag->id;
210     int t=0;
211     while(swf_definingtagids[t]>=0)
212     {
213         if(swf_definingtagids[t] == id) 
214             return 1;
215         t++;
216     }
217     return 0; 
218 }
219
220 U8 swf_isPseudoDefiningTag(TAG * tag)
221 {
222     int id = tag->id;
223     int t=0;
224     while(swf_pseudodefiningtagids[t]>=0)
225     {
226         if(swf_pseudodefiningtagids[t] == id) 
227             return 1;
228         t++;
229     }
230     return 0; 
231 }
232
233 U16 swf_GetDepth(TAG * t)
234 // up to SWF 4.0
235
236   U16 depth = 0;
237   U32 oldTagPos;
238   oldTagPos = swf_GetTagPos(t);
239   swf_SetTagPos(t,0);
240
241   switch (swf_GetTagID(t))
242   { case ST_PLACEOBJECT:
243     case ST_REMOVEOBJECT:
244       swf_GetU16(t); //id
245       depth = swf_GetU16(t);
246       break;
247     case ST_REMOVEOBJECT2:
248       depth = swf_GetU16(t);
249       break;
250     case ST_PLACEOBJECT2:
251     { U8 flags = swf_GetU8(t);
252       depth = swf_GetU16(t);
253     } break;
254   }
255   swf_SetTagPos(t,oldTagPos);
256   return depth;
257 }
258
259 char* swf_GetName(TAG * t)
260 {
261     char* name = 0;
262     U32 oldTagPos;
263     MATRIX m;
264     CXFORM c;
265     oldTagPos = swf_GetTagPos(t);
266     swf_SetTagPos(t,0);
267     switch(swf_GetTagID(t))
268     {
269         case ST_FRAMELABEL:
270             name = &t->data[swf_GetTagPos(t)];
271         break;
272         case ST_PLACEOBJECT2: {   
273             U8 flags = swf_GetU8(t);
274             swf_GetU16(t); //depth;
275             if(flags&PF_CHAR) 
276               swf_GetU16(t); //id
277             if(flags&PF_MATRIX)
278               swf_GetMatrix(t, &m);
279             if(flags&PF_CXFORM)
280               swf_GetCXForm(t, &c, 1);
281             if(flags&PF_RATIO)
282               swf_GetU16(t);
283             if(flags&PF_NAME) {
284               swf_ResetReadBits(t);
285               name = &t->data[swf_GetTagPos(t)];
286             }
287         }
288         break;
289     }
290     swf_SetTagPos(t,oldTagPos);
291     return name;
292 }
293
294 #define DEBUG_ENUMERATE if(0)
295
296 static void enumerateUsedIDs_styles(TAG * tag, void (*callback)(TAG*, int, void*), void*callback_data, int num, int morph)
297 {
298     U16 count;
299     int t;
300     count = swf_GetU8(tag);
301     if(count == 0xff && num>1) // defineshape2,3 only
302         count = swf_GetU16(tag);
303
304     for(t=0;t<count;t++)
305     {
306         int type;
307         U8*pos;
308         swf_ResetReadBits(tag);
309         type = swf_GetU8(tag); //type
310         if(type == 0) {
311             if(num == 3)
312                 {swf_GetRGBA(tag, NULL);if(morph) swf_GetRGBA(tag, NULL);}
313             else 
314                 {swf_GetRGB(tag, NULL);if(morph) swf_GetRGB(tag, NULL);}
315         }
316         else if(type == 0x10 || type == 0x12)
317         {
318             swf_ResetReadBits(tag);
319             swf_GetMatrix(tag, NULL);
320             if(morph)
321                 swf_GetMatrix(tag, NULL);
322             swf_ResetReadBits(tag);
323             if(morph)
324                 swf_GetMorphGradient(tag, NULL, NULL);
325             else
326                 swf_GetGradient(tag, NULL, /*alpha*/ num>=3?1:0);
327         }
328         else if(type == 0x40 || type == 0x41)
329         {
330             swf_ResetReadBits(tag);
331             // we made it.
332             if(tag->data[tag->pos] != 0xff ||
333                tag->data[tag->pos+1] != 0xff)
334             (callback)(tag, tag->pos, callback_data);
335
336             swf_GetU16(tag);
337             swf_ResetReadBits(tag);
338             swf_GetMatrix(tag, NULL);
339             if(morph)
340                 swf_GetMatrix(tag, NULL);
341         }
342         else {
343             fprintf(stderr, "rfxswf:swftools.c Unknown fillstyle:0x%02x\n",type);
344         }
345     }
346     swf_ResetReadBits(tag);
347     count = swf_GetU8(tag); // line style array
348     if(count == 0xff)
349         count = swf_GetU16(tag);
350     for(t=0;t<count;t++) 
351     {
352         swf_GetU16(tag);
353         if(morph)
354             swf_GetU16(tag);
355         if(num == 3)
356             {swf_GetRGBA(tag, NULL);if(morph) swf_GetRGBA(tag, NULL);}
357         else
358             {swf_GetRGB(tag, NULL);if(morph) swf_GetRGB(tag, NULL);}
359     }
360 }
361
362 void enumerateUsedIDs(TAG * tag, int base, void (*callback)(TAG*, int, void*), void*callback_data)
363 {
364     int num = 1;
365     swf_ResetReadBits(tag);
366     tag->pos = 0;
367     switch(tag->id)
368     {
369         case ST_DEFINEBUTTONCXFORM: {
370             int t;
371             callback(tag, tag->pos + base, callback_data);
372             for(t=0;t<4;t++) {
373                 int flags;
374                 callback(tag, tag->pos + base, callback_data);
375                 swf_GetU16(tag); //sound id
376                 flags = swf_GetU8(tag);
377                 if(flags&1)
378                     swf_GetU32(tag); // in point
379                 if(flags&2)
380                     swf_GetU32(tag); // out points
381                 if(flags&4)
382                     swf_GetU16(tag); // loop count
383                 if(flags&8)
384                 {
385                     int npoints = swf_GetU8(tag);
386                     int s;
387                     for(s=0;s<npoints;s++)
388                     {
389                         swf_GetU32(tag);
390                         swf_GetU16(tag);
391                         swf_GetU16(tag);
392                     }
393                 }
394             }
395         } break;
396         case ST_DEFINEBUTTONSOUND:
397             callback(tag, tag->pos + base, callback_data); //button id
398         break;
399
400         case ST_FREECHARACTER: /* unusual tags, which all start with an ID */
401         case ST_NAMECHARACTER:
402         case ST_GENERATORTEXT:
403         case ST_MX3:
404             callback(tag, tag->pos + base, callback_data);
405         break;
406         case ST_PLACEOBJECT:
407             callback(tag, tag->pos + base, callback_data);
408         break;
409         case ST_PLACEOBJECT2:
410             // only if placeflaghascharacter
411             if(!(tag->data[0]&2))
412                 break;
413             callback(tag, 3 + base, callback_data);
414         break;
415         case ST_REMOVEOBJECT:
416             callback(tag, tag->pos + base, callback_data);
417         break;
418         case ST_STARTSOUND:
419             callback(tag, tag->pos + base, callback_data);
420         break;
421         case ST_DEFINESPRITE: {
422             if(tag->len <= 4)
423                 break; // sprite is expanded
424
425             swf_GetU16(tag); // id
426             swf_GetU16(tag); // framenum
427
428             while(1) {
429                 U16 flags = swf_GetU16(tag);
430                 U32 len;
431                 U16 id = flags>>6;
432                 TAG *tag2 = swf_InsertTag(NULL, id);
433                 len = flags&0x3f;
434                 if(len == 63)
435                     len = swf_GetU32(tag);
436                 if(id == ST_END)
437                     break;
438                 tag2->len = tag2->memsize = len;
439                 tag2->data = malloc(len);
440                 memcpy(tag2->data, &tag->data[tag->pos], len);
441                 /* I never saw recursive sprites, but they are (theoretically) 
442                    possible, so better add base here again */
443                 enumerateUsedIDs(tag2, tag->pos + base, callback, callback_data);
444                 swf_DeleteTag(tag2);
445                 swf_GetBlock(tag, NULL, len);
446             }
447         } 
448         break;
449         case ST_DEFINEBUTTON2: // has some font ids in the button records
450             num++; 
451         //fallthrough
452         case ST_DEFINEBUTTON: {
453             swf_GetU16(tag); //button id
454             if(num>1)
455             { 
456                 int offset;
457                 swf_GetU8(tag); //flag
458                 offset = swf_GetU16(tag); //offset
459             }
460             while(1)
461             {
462                 U16 charid;
463                 if(!swf_GetU8(tag)) //flags
464                     break; 
465                 callback(tag, tag->pos + base, callback_data);
466                 swf_GetU16(tag); //char
467                 swf_GetU16(tag); //layer
468                 swf_ResetReadBits(tag);
469                 swf_GetMatrix(tag, NULL);
470                 if(num>1) {
471                   swf_ResetReadBits(tag);
472                   swf_GetCXForm(tag, NULL, 1);
473                 }
474             }
475             // ...
476         }
477         break;
478         case ST_DEFINEEDITTEXT:  {
479             U8 flags1,flags2;
480             swf_GetU16(tag); //id
481             swf_GetRect(tag, NULL); //bounding box
482             swf_ResetReadBits(tag);
483             flags1 = swf_GetU8(tag);
484             flags2 = swf_GetU8(tag);
485             if(flags1 & 1)
486                 callback(tag, tag->pos + base, callback_data);
487         }
488         break;
489         case ST_DEFINETEXT2:
490             num ++;
491         case ST_DEFINETEXT: { 
492             int glyphbits, advancebits;
493             int id;
494             id = swf_GetU16(tag); //id
495             swf_GetRect(tag, NULL); //bounding box
496             swf_ResetReadBits(tag);
497             swf_GetMatrix(tag, NULL); //matrix
498             swf_ResetReadBits(tag);
499             glyphbits = swf_GetU8(tag); //glyphbits
500             advancebits = swf_GetU8(tag); //advancebits
501             while(1) {
502                 U16 flags;
503                 swf_ResetReadBits(tag);
504                 flags = swf_GetBits(tag, 8);
505                 if(!flags) break;
506                 if(flags & 128) // text style record
507                 {
508                     swf_ResetReadBits(tag);
509                     if(flags & 8) { // hasfont
510                         callback(tag, tag->pos + base, callback_data);
511                         id = swf_GetU16(tag);
512                     }
513                     if(flags & 4) { // hascolor
514                         if(num==1) swf_GetRGB(tag, NULL);
515                         else       swf_GetRGBA(tag, NULL);
516                     }
517                     if(flags & 2) { //has x offset
518                         swf_ResetReadBits(tag);
519                         swf_GetU16(tag);
520                     }
521                     if(flags & 1) { //has y offset
522                         swf_ResetReadBits(tag);
523                         swf_GetU16(tag);
524                     }
525                     if(flags & 8) { //has height
526                         swf_ResetReadBits(tag);
527                         swf_GetU16(tag);
528                     }
529                 } else { // glyph record
530                     int t;
531                     swf_ResetReadBits(tag);
532                     for(t=0;t<flags;t++) {
533                         swf_GetBits(tag, glyphbits);
534                         swf_GetBits(tag, advancebits);
535                     }
536                 }
537             }
538             break;
539         }
540         case ST_DEFINEFONTINFO:
541             callback(tag, tag->pos + base, callback_data);
542         break;
543
544         case ST_DEFINEMORPHSHAPE:
545         case ST_DEFINESHAPE3: // these thingies might have bitmap ids in their fillstyles
546         num++; //fallthrough
547         case ST_DEFINESHAPE2:
548         num++; //fallthrough
549         case ST_DEFINESHAPE: {
550             int fillbits;
551             int linebits;
552             int id; 
553             int morph = 0;
554             if(tag->id == ST_DEFINEMORPHSHAPE)
555                 morph = 1;
556
557             id = swf_GetU16(tag); // id;
558             swf_GetRect(tag, NULL); // bounds
559             if(morph) {
560                 swf_GetRect(tag, NULL); // bounds2
561                 swf_GetU32(tag); //offset to endedges
562             }
563     
564             DEBUG_ENUMERATE printf("Tag:%d Name:%s ID:%d\n", tag->id, swf_TagGetName(tag), id);
565
566             enumerateUsedIDs_styles(tag, callback, callback_data, num, morph);
567             DEBUG_ENUMERATE printf("-------\n");
568             while(--morph>=0) /* morph shapes define two shapes */
569             {
570                 swf_ResetReadBits(tag); //?
571                 fillbits = swf_GetBits(tag, 4);
572                 linebits = swf_GetBits(tag, 4);
573                 DEBUG_ENUMERATE printf("%d %d\n", fillbits, linebits);
574                 swf_ResetReadBits(tag);
575                 while(1) {
576                     int flags;
577                     flags = swf_GetBits(tag, 1);
578                     if(!flags) { //style change
579                         flags = swf_GetBits(tag, 5);
580                         if(!flags)
581                             break;
582                         if(flags&1) { //move
583                             int n = swf_GetBits(tag, 5); 
584                             int x,y;
585                             x = swf_GetBits(tag, n); //x
586                             y = swf_GetBits(tag, n); //y
587                             DEBUG_ENUMERATE printf("move %f %f\n",x/20.0,y/20.0);
588                         }
589                         if(flags&2) { //fill0
590                             int fill0;
591                             fill0 = swf_GetBits(tag, fillbits); 
592                             DEBUG_ENUMERATE printf("fill0 %d\n", fill0);
593                         }
594                         if(flags&4) { //fill1
595                             int fill1;
596                             fill1 = swf_GetBits(tag, fillbits); 
597                             DEBUG_ENUMERATE printf("fill1 %d\n", fill1);
598                         }
599                         if(flags&8) { //linestyle
600                             int line;
601                             line = swf_GetBits(tag, linebits); 
602                             DEBUG_ENUMERATE printf("linestyle %d\n",line);
603                         }
604                         if(flags&16) {
605                             DEBUG_ENUMERATE printf("more fillstyles\n");
606                             enumerateUsedIDs_styles(tag, callback, callback_data, num, 0);
607                             fillbits = swf_GetBits(tag, 4);
608                             linebits = swf_GetBits(tag, 4);
609                         }
610                     } else {
611                         flags = swf_GetBits(tag, 1);
612                         if(flags) { //straight edge
613                             int n = swf_GetBits(tag, 4) + 2;
614                             if(swf_GetBits(tag, 1)) { //line flag
615                                 int x,y;
616                                 x = swf_GetSBits(tag, n); //delta x
617                                 y = swf_GetSBits(tag, n); //delta y
618                                 DEBUG_ENUMERATE printf("line %f %f\n",x/20.0,y/20.0);
619                             } else {
620                                 int v=swf_GetBits(tag, 1);
621                                 int d;
622                                 d = swf_GetSBits(tag, n); //vert/horz
623                                 DEBUG_ENUMERATE printf("%s %f\n",v?"vertical":"horizontal", d/20.0);
624                             }
625                         } else { //curved edge
626                             int n = swf_GetBits(tag, 4) + 2;
627                             int x1,y1,x2,y2;
628                             x1 = swf_GetSBits(tag, n);
629                             y1 = swf_GetSBits(tag, n);
630                             x2 = swf_GetSBits(tag, n);
631                             y2 = swf_GetSBits(tag, n);
632                             DEBUG_ENUMERATE printf("curve %f %f %f %f\n", x1/20.0, y1/20.0, x2/20.0, y2/20.0);
633                         }
634                     }
635                 }
636             }
637         }
638         break;
639         default:
640         break;
641     }
642 }
643
644 void callbackCount(TAG * t,int pos, void*ptr)
645 {
646     (*(int*)ptr)++;
647     DEBUG_ENUMERATE printf("callback(%d) %d\n", pos, *(U16*)&t->data[pos]);
648 }
649
650 void callbackFillin(TAG * t,int pos, void*ptr)
651 {
652     **(int**)ptr = pos;
653     (*(int**)ptr)++;
654     DEBUG_ENUMERATE printf("callback(%d) %d\n", pos, *(U16*)&t->data[pos]);
655 }
656
657 int swf_GetNumUsedIDs(TAG * t)
658 {
659     int num = 0;
660     enumerateUsedIDs(t, 0, callbackCount, &num);
661     return num;
662 }
663
664 void swf_GetUsedIDs(TAG * t, int * positions)
665 {
666     int * ptr = positions;
667     enumerateUsedIDs(t, 0, callbackFillin, &ptr);
668 }
669
670 void swf_Relocate (SWF*swf, char*bitmap)
671 {
672     TAG*tag;
673     int slaveids[65536];
674     memset(slaveids, -1, sizeof(slaveids));
675     tag = swf->firstTag;
676     while(tag)
677     {
678         int num; 
679         int *ptr;
680         int t;
681
682         if(swf_isDefiningTag(tag))
683         {
684             int newid;
685             int id;
686             
687             id = swf_GetDefineID(tag); //own id
688
689             if(!bitmap[id]) { //free
690                 newid = id;
691             }
692             else {
693                 newid = 0;
694                 for (t=1;t<65536;t++)
695                 {
696                     if(!bitmap[t])
697                     {
698                         newid = t;
699                         break;
700                     }
701                 }
702             }
703             bitmap[newid] = 1;
704             slaveids[id] = newid;
705
706             swf_SetDefineID(tag, newid);
707         } 
708         
709         num = swf_GetNumUsedIDs(tag);
710         ptr = malloc(sizeof(int)*num);
711         swf_GetUsedIDs(tag, ptr);
712
713         for(t=0;t<num;t++) {
714             int id = GET16(&tag->data[ptr[t]]);
715             if(slaveids[id]<0) {
716                 fprintf(stderr, "swf_Relocate: Mapping id never encountered before: %d\n", id);
717                 return ;
718             }
719             id = slaveids[id];
720             PUT16(&tag->data[ptr[t]], id);
721         }
722         tag=tag->next;
723     }
724 }
725