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 program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
24 // Matrix & Math tools for SWF files
27 SFIXED RFXSWF_SP(SFIXED a1,SFIXED a2,SFIXED b1,SFIXED b2)
29 a = (S64)a1*(S64)b1+(S64)a2*(S64)b2;
30 return (SFIXED)(a>>16);
32 SFIXED RFXSWF_QFIX(int zaehler,int nenner) // bildet Quotient von zwei INTs in SFIXED
33 { S64 z = zaehler<<16;
34 S64 a = z/(S64)nenner;
39 MATRIX * swf_MatrixJoin(MATRIX * d,MATRIX * s1,MATRIX * s2)
42 if (!s1) return (s2)?(MATRIX *)memcpy(d,s2,sizeof(MATRIX)):NULL;
43 if (!s2) return (MATRIX *)memcpy(d,s1,sizeof(MATRIX));
45 d->tx = s1->tx + RFXSWF_SP(s1->sx,s1->r1,s2->tx,s2->ty);
46 d->ty = s1->ty + RFXSWF_SP(s1->r0,s1->sy,s2->tx,s2->ty);
48 d->sx = RFXSWF_SP(s1->sx,s1->r1,s2->sx,s2->r0);
49 d->r0 = RFXSWF_SP(s1->r0,s1->sy,s2->sx,s2->r0);
51 d->r1 = RFXSWF_SP(s1->sx,s1->r1,s2->r1,s2->sy);
52 d->sy = RFXSWF_SP(s1->r0,s1->sy,s2->r1,s2->sy);
59 MATRIX * swf_MatrixMapTriangle(MATRIX * m,int dx,int dy,int x0,int y0,
60 int x1,int y1,int x2,int y2)
67 if ((!dx)||(!dy)) return NULL; // check DIV by zero
71 m->sx = RFXSWF_QFIX(dx1,dx);
72 m->sy = RFXSWF_QFIX(dy2,dy);
73 m->r0 = RFXSWF_QFIX(dy1,dx);
74 m->r1 = RFXSWF_QFIX(dx2,dy);
79 void swf_SetDefineID(TAG * tag, U16 newid)
81 int oldlen = tag->len;
83 swf_SetU16(tag, newid); /* set defining ID */
87 U16 swf_GetDefineID(TAG * t)
92 oldTagPos = swf_GetTagPos(t);
95 switch (swf_GetTagID(t))
96 { case ST_DEFINESHAPE:
99 case ST_DEFINEMORPHSHAPE:
100 case ST_DEFINEEDITTEXT:
102 case ST_DEFINEBITSJPEG2:
103 case ST_DEFINEBITSJPEG3:
104 case ST_DEFINEBITSLOSSLESS:
105 case ST_DEFINEBITSLOSSLESS2:
106 case ST_DEFINEBUTTON:
107 case ST_DEFINEBUTTON2:
108 case ST_DEFINEBUTTONCXFORM: //pseudodefine
109 case ST_DEFINEBUTTONSOUND: //pseudodefine
112 case ST_DEFINEFONTINFO: //pseudodefine
113 case ST_DEFINEFONTINFO2: //pseudodefine
117 case ST_DEFINESPRITE:
119 case ST_DEFINEVIDEOSTREAM:
120 case ST_GLYPHNAMES: //pseudodefine
121 case ST_VIDEOFRAME: //pseudodefine
122 case ST_NAMECHARACTER: //pseudodefine
123 case ST_DOINITACTION: //pseudodefine
127 fprintf(stderr, "rfxswf: Error: tag %d (%s) has no id\n", t->id, swf_TagGetName(t));
130 swf_SetTagPos(t,oldTagPos);
135 SRECT swf_GetDefineBBox(TAG * t)
140 memset(&b1, 0, sizeof(b1));
142 oldTagPos = swf_GetTagPos(t);
147 switch (swf_GetTagID(t))
148 { case ST_DEFINESHAPE:
149 case ST_DEFINESHAPE2:
150 case ST_DEFINESHAPE3:
151 case ST_DEFINEEDITTEXT:
154 case ST_DEFINEVIDEOSTREAM:
158 case ST_DEFINEMORPHSHAPE:
162 swf_ExpandRect2(&b1, &b2);
164 case ST_DEFINEBITSLOSSLESS:
165 case ST_DEFINEBITSLOSSLESS2:
167 case ST_DEFINEBITSJPEG2:
168 case ST_DEFINEBITSJPEG3:
173 swf_SetTagPos(t,oldTagPos);
178 U16 swf_GetPlaceID(TAG * t)
183 oldTagPos = swf_GetTagPos(t);
186 switch (swf_GetTagID(t))
187 { case ST_PLACEOBJECT:
188 case ST_REMOVEOBJECT:
189 case ST_FREECHARACTER:
194 case ST_PLACEOBJECT2:
195 { U8 flags = swf_GetU8(t);
196 U16 d = swf_GetU16(t);
197 id = (flags&PF_CHAR)?swf_GetU16(t):id;
202 swf_SetTagPos(t,oldTagPos);
207 static int swf_definingtagids[] =
220 ST_DEFINEBITSLOSSLESS,
221 ST_DEFINEBITSLOSSLESS2,
227 ST_DEFINEVIDEOSTREAM,
231 // tags which may be used inside a sprite definition
232 static int swf_spritetagids[] =
237 ST_REMOVEOBJECT2, //?
248 static int swf_pseudodefiningtagids[] =
252 ST_DEFINEBUTTONCXFORM,
253 ST_DEFINEBUTTONSOUND,
261 U8 swf_isAllowedSpriteTag(TAG * tag)
265 while(swf_spritetagids[t]>=0)
267 if(swf_spritetagids[t] == id)
274 U8 swf_isDefiningTag(TAG * tag)
278 while(swf_definingtagids[t]>=0)
280 if(swf_definingtagids[t] == id)
287 U8 swf_isPseudoDefiningTag(TAG * tag)
291 while(swf_pseudodefiningtagids[t]>=0)
293 if(swf_pseudodefiningtagids[t] == id)
300 int swf_GetDepth(TAG * t)
304 oldTagPos = swf_GetTagPos(t);
307 switch (swf_GetTagID(t))
308 { case ST_PLACEOBJECT:
309 case ST_REMOVEOBJECT:
311 depth = swf_GetU16(t);
313 case ST_REMOVEOBJECT2:
314 depth = swf_GetU16(t);
316 case ST_PLACEOBJECT2:
317 { U8 flags = swf_GetU8(t);
318 depth = swf_GetU16(t);
322 depth = swf_GetU16(t);
325 swf_SetTagPos(t,oldTagPos);
329 void swf_SetDepth(TAG * t, U16 depth)
331 switch (swf_GetTagID(t))
332 { case ST_PLACEOBJECT:
333 case ST_REMOVEOBJECT:
334 PUT16(t->data, depth);
336 case ST_REMOVEOBJECT2:
337 PUT16(t->data, depth);
339 case ST_PLACEOBJECT2:
340 PUT16(&t->data[1], depth);
343 PUT16(t->data, depth);
346 fprintf(stderr, "rfxswf: Error: tag %d has no depth\n", t->id);
350 char* swf_GetName(TAG * t)
356 oldTagPos = swf_GetTagPos(t);
358 switch(swf_GetTagID(t))
361 name = &t->data[swf_GetTagPos(t)];
363 case ST_PLACEOBJECT2: {
364 U8 flags = swf_GetU8(t);
365 swf_GetU16(t); //depth;
369 swf_GetMatrix(t, &m);
371 swf_GetCXForm(t, &c, 1);
374 if(flags&PF_CLIPACTION)
377 swf_ResetReadBits(t);
378 name = &t->data[swf_GetTagPos(t)];
383 swf_SetTagPos(t,oldTagPos);
387 /* used in enumerateUsedIDs */
388 void swf_GetMorphGradient(TAG * tag, GRADIENT * gradient1, GRADIENT * gradient2)
398 gradient2->num = swf_GetU8(tag);
399 for(t=0;t<gradient1->num;t++)
404 gradient1->ratios[t] = swf_GetU8(tag);
405 swf_GetRGBA(tag, &gradient1->rgba[t]);
406 gradient2->ratios[t] = swf_GetU8(tag);
407 swf_GetRGBA(tag, &gradient2->rgba[t]);
411 #define DEBUG_ENUMERATE if(0)
413 void enumerateUsedIDs_styles(TAG * tag, void (*callback)(TAG*, int, void*), void*callback_data, int num, int morph)
417 count = swf_GetU8(tag);
418 if(count == 0xff && num>1) // defineshape2,3 only
419 count = swf_GetU16(tag);
425 swf_ResetReadBits(tag);
426 type = swf_GetU8(tag); //type
429 {swf_GetRGBA(tag, NULL);if(morph) swf_GetRGBA(tag, NULL);}
431 {swf_GetRGB(tag, NULL);if(morph) swf_GetRGB(tag, NULL);}
433 else if(type == 0x10 || type == 0x12)
435 swf_ResetReadBits(tag);
436 swf_GetMatrix(tag, NULL);
438 swf_GetMatrix(tag, NULL);
439 swf_ResetReadBits(tag);
441 swf_GetMorphGradient(tag, NULL, NULL);
443 swf_GetGradient(tag, NULL, /*alpha*/ num>=3?1:0);
445 else if(type == 0x40 || type == 0x41)
447 swf_ResetReadBits(tag);
449 if(tag->data[tag->pos] != 0xff ||
450 tag->data[tag->pos+1] != 0xff)
451 (callback)(tag, tag->pos, callback_data);
454 swf_ResetReadBits(tag);
455 swf_GetMatrix(tag, NULL);
457 swf_GetMatrix(tag, NULL);
460 fprintf(stderr, "rfxswf:swftools.c Unknown fillstyle:0x%02x\n",type);
463 swf_ResetReadBits(tag);
464 count = swf_GetU8(tag); // line style array
466 count = swf_GetU16(tag);
473 {swf_GetRGBA(tag, NULL);if(morph) swf_GetRGBA(tag, NULL);}
475 {swf_GetRGB(tag, NULL);if(morph) swf_GetRGB(tag, NULL);}
479 void enumerateUsedIDs(TAG * tag, int base, void (*callback)(TAG*, int, void*), void*callback_data)
482 swf_ResetReadBits(tag);
486 case ST_DEFINEBUTTONCXFORM: {
488 callback(tag, tag->pos + base, callback_data);
491 callback(tag, tag->pos + base, callback_data);
492 swf_GetU16(tag); //sound id
493 flags = swf_GetU8(tag);
495 swf_GetU32(tag); // in point
497 swf_GetU32(tag); // out points
499 swf_GetU16(tag); // loop count
502 int npoints = swf_GetU8(tag);
504 for(s=0;s<npoints;s++)
513 case ST_DEFINEBUTTONSOUND:
514 callback(tag, tag->pos + base, callback_data); //button id
517 case ST_EXPORTASSETS: {
518 int num = swf_GetU16(tag);
521 callback(tag, tag->pos + base, callback_data); //button id
522 swf_GetU16(tag); //id
523 while(swf_GetU8(tag)); //name
527 case ST_FREECHARACTER: /* unusual tags, which all start with an ID */
528 case ST_NAMECHARACTER:
529 case ST_GENERATORTEXT:
530 callback(tag, tag->pos + base, callback_data);
533 callback(tag, tag->pos + base, callback_data);
535 case ST_PLACEOBJECT2:
536 // only if placeflaghascharacter
537 if(!(tag->data[0]&2))
539 callback(tag, 3 + base, callback_data);
541 case ST_REMOVEOBJECT:
542 callback(tag, tag->pos + base, callback_data);
545 callback(tag, tag->pos + base, callback_data);
547 case ST_DEFINESPRITE: {
549 break; // sprite is expanded
551 swf_GetU16(tag); // id
552 swf_GetU16(tag); // framenum
555 U16 flags = swf_GetU16(tag);
558 TAG *tag2 = swf_InsertTag(NULL, id);
561 len = swf_GetU32(tag);
564 tag2->len = tag2->memsize = len;
565 tag2->data = rfx_alloc(len);
566 memcpy(tag2->data, &tag->data[tag->pos], len);
567 /* I never saw recursive sprites, but they are (theoretically)
568 possible, so better add base here again */
569 enumerateUsedIDs(tag2, tag->pos + base, callback, callback_data);
571 swf_GetBlock(tag, NULL, len);
575 case ST_DEFINEBUTTON2: // has some font ids in the button records
578 case ST_DEFINEBUTTON: {
579 swf_GetU16(tag); //button id
583 swf_GetU8(tag); //flag
584 offset = swf_GetU16(tag); //offset
589 if(!swf_GetU8(tag)) //flags
591 callback(tag, tag->pos + base, callback_data);
592 swf_GetU16(tag); //char
593 swf_GetU16(tag); //layer
594 swf_ResetReadBits(tag);
595 swf_GetMatrix(tag, NULL);
597 swf_ResetReadBits(tag);
598 swf_GetCXForm(tag, NULL, 1);
604 case ST_DEFINEEDITTEXT: {
606 swf_GetU16(tag); //id
607 swf_GetRect(tag, NULL); //bounding box
608 swf_ResetReadBits(tag);
609 flags1 = swf_GetU8(tag);
610 flags2 = swf_GetU8(tag);
612 callback(tag, tag->pos + base, callback_data);
617 case ST_DEFINETEXT: {
618 int glyphbits, advancebits;
620 id = swf_GetU16(tag); //id
621 swf_GetRect(tag, NULL); //bounding box
622 swf_ResetReadBits(tag);
623 swf_GetMatrix(tag, NULL); //matrix
624 swf_ResetReadBits(tag);
625 glyphbits = swf_GetU8(tag); //glyphbits
626 advancebits = swf_GetU8(tag); //advancebits
629 swf_ResetReadBits(tag);
630 flags = swf_GetBits(tag, 8);
632 if(flags & 128) // text style record
634 swf_ResetReadBits(tag);
635 if(flags & 8) { // hasfont
636 callback(tag, tag->pos + base, callback_data);
637 id = swf_GetU16(tag);
639 if(flags & 4) { // hascolor
640 if(num==1) swf_GetRGB(tag, NULL);
641 else swf_GetRGBA(tag, NULL);
643 if(flags & 2) { //has x offset
644 swf_ResetReadBits(tag);
647 if(flags & 1) { //has y offset
648 swf_ResetReadBits(tag);
651 if(flags & 8) { //has height
652 swf_ResetReadBits(tag);
655 } else { // glyph record
657 swf_ResetReadBits(tag);
658 for(t=0;t<flags;t++) {
659 swf_GetBits(tag, glyphbits);
660 swf_GetBits(tag, advancebits);
667 case ST_DEFINEFONTINFO:
668 case ST_DEFINEFONTINFO2:
670 callback(tag, tag->pos + base, callback_data);
672 case ST_DEFINEVIDEOSTREAM:
675 case ST_DOINITACTION:
676 callback(tag, tag->pos + base, callback_data);
679 case ST_DEFINEMORPHSHAPE:
680 case ST_DEFINESHAPE3:
682 case ST_DEFINESHAPE2:
684 case ST_DEFINESHAPE: {
690 if(tag->id == ST_DEFINEMORPHSHAPE) {
695 id = swf_GetU16(tag); // id;
696 swf_GetRect(tag, NULL); // bounds
698 swf_ResetReadBits(tag);
699 swf_GetRect(tag, NULL); // bounds2
700 swf_GetU32(tag); //offset to endedges
703 DEBUG_ENUMERATE printf("Tag:%d Name:%s ID:%d\n", tag->id, swf_TagGetName(tag), id);
705 enumerateUsedIDs_styles(tag, callback, callback_data, num, morph);
706 DEBUG_ENUMERATE printf("-------\n");
707 while(--numshapes>=0) /* morph shapes define two shapes */
709 DEBUG_ENUMERATE printf("shape:%d\n", numshapes);
710 fillbits = swf_GetBits(tag, 4);
711 linebits = swf_GetBits(tag, 4);
712 DEBUG_ENUMERATE printf("%d %d\n", fillbits, linebits);
713 swf_ResetReadBits(tag);
716 flags = swf_GetBits(tag, 1);
717 if(!flags) { //style change
718 flags = swf_GetBits(tag, 5);
722 int n = swf_GetBits(tag, 5);
724 x = swf_GetBits(tag, n); //x
725 y = swf_GetBits(tag, n); //y
726 DEBUG_ENUMERATE printf("move %f %f\n",x/20.0,y/20.0);
728 if(flags&2) { //fill0
730 fill0 = swf_GetBits(tag, fillbits);
731 DEBUG_ENUMERATE printf("fill0 %d\n", fill0);
733 if(flags&4) { //fill1
735 fill1 = swf_GetBits(tag, fillbits);
736 DEBUG_ENUMERATE printf("fill1 %d\n", fill1);
738 if(flags&8) { //linestyle
740 line = swf_GetBits(tag, linebits);
741 DEBUG_ENUMERATE printf("linestyle %d\n",line);
744 DEBUG_ENUMERATE printf("more fillstyles\n");
745 enumerateUsedIDs_styles(tag, callback, callback_data, num, 0);
746 fillbits = swf_GetBits(tag, 4);
747 linebits = swf_GetBits(tag, 4);
750 flags = swf_GetBits(tag, 1);
751 if(flags) { //straight edge
752 int n = swf_GetBits(tag, 4) + 2;
753 if(swf_GetBits(tag, 1)) { //line flag
755 x = swf_GetSBits(tag, n); //delta x
756 y = swf_GetSBits(tag, n); //delta y
757 DEBUG_ENUMERATE printf("line %f %f\n",x/20.0,y/20.0);
759 int v=swf_GetBits(tag, 1);
761 d = swf_GetSBits(tag, n); //vert/horz
762 DEBUG_ENUMERATE printf("%s %f\n",v?"vertical":"horizontal", d/20.0);
764 } else { //curved edge
765 int n = swf_GetBits(tag, 4) + 2;
767 x1 = swf_GetSBits(tag, n);
768 y1 = swf_GetSBits(tag, n);
769 x2 = swf_GetSBits(tag, n);
770 y2 = swf_GetSBits(tag, n);
771 DEBUG_ENUMERATE printf("curve %f %f %f %f\n", x1/20.0, y1/20.0, x2/20.0, y2/20.0);
783 void callbackCount(TAG * t,int pos, void*ptr)
786 DEBUG_ENUMERATE printf("callback(%d) %d\n", pos, *(U16*)&t->data[pos]);
789 void callbackFillin(TAG * t,int pos, void*ptr)
793 DEBUG_ENUMERATE printf("callback(%d) %d\n", pos, *(U16*)&t->data[pos]);
796 int swf_GetNumUsedIDs(TAG * t)
799 enumerateUsedIDs(t, 0, callbackCount, &num);
803 void swf_GetUsedIDs(TAG * t, int * positions)
805 int * ptr = positions;
806 enumerateUsedIDs(t, 0, callbackFillin, &ptr);
809 void swf_Relocate (SWF*swf, char*bitmap)
813 memset(slaveids, -1, sizeof(slaveids));
821 if(swf_isDefiningTag(tag))
826 id = swf_GetDefineID(tag); //own id
828 if(!bitmap[id]) { //free
833 for (t=1;t<65536;t++)
843 slaveids[id] = newid;
845 swf_SetDefineID(tag, newid);
848 num = swf_GetNumUsedIDs(tag);
850 ptr = rfx_alloc(sizeof(int)*num);
851 swf_GetUsedIDs(tag, ptr);
854 int id = GET16(&tag->data[ptr[t]]);
856 fprintf(stderr, "swf_Relocate: Mapping id (%d) never encountered before in %s\n", id,
857 swf_TagGetName(tag));
861 PUT16(&tag->data[ptr[t]], id);
868 void swf_RelocateDepth(SWF*swf, char*bitmap)
873 for(nr=65535;nr>=0;nr--) {
877 // now nr is the highest used depth. So we start
878 // assigning depths at nr+1
883 /* TODO * clip depths
886 int depth = swf_GetDepth(tag);
888 int newdepth = depth+nr;
890 fprintf(stderr, "Couldn't relocate depths: too large values\n");
893 swf_SetDepth(tag, newdepth);
899 U8 swf_isShapeTag(TAG*tag)
901 if(tag->id == ST_DEFINESHAPE ||
902 tag->id == ST_DEFINESHAPE2 ||
903 tag->id == ST_DEFINESHAPE3)
908 U8 swf_isPlaceTag(TAG*tag)
910 if(tag->id == ST_PLACEOBJECT ||
911 tag->id == ST_PLACEOBJECT2)
915 U8 swf_isTextTag(TAG*tag)
917 if(tag->id == ST_DEFINETEXT ||
918 tag->id == ST_DEFINETEXT2)
923 U8 swf_isFontTag(TAG*tag)
925 if(tag->id == ST_DEFINEFONT ||
926 tag->id == ST_DEFINEFONT2 ||
927 tag->id == ST_DEFINEFONTINFO)
932 U8 swf_isImageTag(TAG*tag)
934 if(tag->id == ST_DEFINEBITSJPEG ||
935 tag->id == ST_DEFINEBITSJPEG2 ||
936 tag->id == ST_DEFINEBITSJPEG3 ||
937 tag->id == ST_DEFINEBITSLOSSLESS ||
938 tag->id == ST_DEFINEBITSLOSSLESS2)
943 TAG* swf_Concatenate (TAG*list1,TAG*list2)
945 TAG*tag=0,*lasttag=0;
947 char depthmap[65536];
949 memset(bitmap, 0, sizeof(bitmap));
950 memset(depthmap, 0, sizeof(depthmap));
951 memset(&swf1, 0, sizeof(swf1));
952 memset(&swf2, 0, sizeof(swf2));
954 swf1.firstTag = list1;
956 swf2.firstTag = list2;
961 if(!swf_isDefiningTag(tag)) {
962 int id = swf_GetDefineID(tag);
965 if(tag->id == ST_PLACEOBJECT ||
966 tag->id == ST_PLACEOBJECT2) {
967 int depth = swf_GetDepth(tag);
970 if(tag->id == ST_REMOVEOBJECT ||
971 tag->id == ST_REMOVEOBJECT2) {
972 int depth = swf_GetDepth(tag);
978 swf_Relocate(&swf2, bitmap);
979 swf_RelocateDepth(&swf2, depthmap);
980 lasttag->next = swf2.firstTag;
981 swf2.firstTag->prev = lasttag;
983 return swf1.firstTag;
986 static int tagHash(TAG*tag)
989 unsigned int a = 0x6b973e5a;
990 /* start at pos 2, as 0 and 1 are the id */
991 for(t=2;t<tag->len;t++) {
994 a += tag->data[t]*0xefbc35a5*b*(t+1);
996 return a&0x7fffffff; //always return positive number
999 void swf_Optimize(SWF*swf)
1001 const int hash_size = 131072;
1002 char* dontremap = rfx_calloc(sizeof(char)*65536);
1003 U16* remap = rfx_alloc(sizeof(U16)*65536);
1004 TAG* id2tag = rfx_calloc(sizeof(TAG*)*65536);
1005 TAG** hashmap = rfx_calloc(sizeof(TAG*)*hash_size);
1008 for(t=0;t<65536;t++) {
1014 tag = swf->firstTag;
1016 /* make sure we don't remap to this tag,
1017 as it might have different "helper tags"
1018 FIXME: a better way would be to compare
1019 the helper tags, too.
1021 if(swf_isPseudoDefiningTag(tag) &&
1022 tag->id != ST_NAMECHARACTER) {
1023 dontremap[swf_GetDefineID(tag)] = 1;
1027 tag = swf->firstTag;
1031 TAG*next = tag->next;
1034 int num = swf_GetNumUsedIDs(tag);
1035 int*positions = rfx_alloc(sizeof(int)*num);
1037 swf_GetUsedIDs(tag, positions);
1038 for(t=0;t<num;t++) {
1039 int id = GET16(&tag->data[positions[t]]);
1041 PUT16(&tag->data[positions[t]], id);
1043 rfx_free(positions);
1046 /* now look for previous tags with the same
1048 if(swf_isDefiningTag(tag)) {
1050 int id = swf_GetDefineID(tag);
1051 int hash = tagHash(tag);
1054 while((tag2 = hashmap[hash%hash_size])) {
1055 if(tag2 != (TAG*)(-1) && tag->len == tag2->len) {
1057 /* start at pos 2, as 0 and 1 are the id */
1058 for(t=2;t<tag->len;t++) {
1059 if(tag->data[t] != tag2->data[t])
1067 /* we found two identical tags- remap one
1069 remap[id] = swf_GetDefineID(tag2);
1075 while(hashmap[hash%hash_size]) hash++;
1076 hashmap[hash%hash_size] = tag;
1079 if(tag == swf->firstTag)
1080 swf->firstTag = next;
1083 } else if(swf_isPseudoDefiningTag(tag)) {
1084 int id = swf_GetDefineID(tag);
1086 /* if this tag was remapped, we don't
1087 need the helper tag anymore. Discard
1090 if(tag == swf->firstTag)
1091 swf->firstTag = next;
1098 rfx_free(dontremap);
1104 void swf_SetDefineBBox(TAG * tag, SRECT newbbox)
1108 swf_SetTagPos(tag,0);
1110 switch (swf_GetTagID(tag))
1112 case ST_DEFINESHAPE:
1113 case ST_DEFINESHAPE2:
1114 case ST_DEFINESHAPE3:
1115 case ST_DEFINEEDITTEXT:
1117 case ST_DEFINETEXT2:
1118 case ST_DEFINEVIDEOSTREAM: {
1119 U32 after_bbox_offset = 0, len;
1121 id = swf_GetU16(tag);
1122 swf_GetRect(tag, &b1);
1123 swf_ResetReadBits(tag);
1124 after_bbox_offset = tag->pos;
1125 len = tag->len - after_bbox_offset;
1127 memcpy(data, &tag->data[after_bbox_offset], len);
1130 swf_SetRect(tag, &newbbox);
1131 swf_SetBlock(tag, data, len);
1133 tag->pos = tag->readBit = 0;
1137 fprintf(stderr, "rfxswf: Tag %d (%s) has no bbox\n", tag->id, swf_TagGetName(tag));
1141 RGBA swf_GetSWFBackgroundColor(SWF*swf)
1143 TAG*t=swf->firstTag;
1145 color.r = color.b = color.g = 0;
1148 if(t->id == ST_SETBACKGROUNDCOLOR) {
1149 swf_SetTagPos(t, 0);
1150 color.r = swf_GetU8(t);
1151 color.g = swf_GetU8(t);
1152 color.b = swf_GetU8(t);