+void swf_UnFoldSprite(TAG * t)
+{
+ U16 id,tmp;
+ U32 len;
+ TAG*next = t;
+ U16 spriteid,spriteframes;
+ if(t->id!=ST_DEFINESPRITE)
+ return;
+ if(t->len<=4) // not folded
+ return;
+
+ swf_SetTagPos(t,0);
+
+ spriteid = swf_GetU16(t); //id
+ spriteframes = swf_GetU16(t); //frames
+
+ tmp = swf_GetU16(t);
+ len = tmp&0x3f;
+ id = tmp>>6;
+ while(id)
+ {
+ TAG*it = 0;
+ if (len==0x3f)
+ len = swf_GetU32(t);
+ it = swf_InsertTag(next, id);
+ next = it;
+ it->len = len;
+ it->id = id;
+ if (it->len)
+ { it->data = (U8*)malloc(t->len);
+ it->memsize = it->len;
+ swf_GetBlock(t, it->data, it->len);
+ }
+ tmp = swf_GetU16(t);
+ len = tmp&0x3f;
+ id = tmp>>6;
+ }
+
+ free(t->data); t->data = 0;
+ t->memsize = t->len = t->pos = 0;
+
+ swf_SetU16(t, spriteid);
+ swf_SetU16(t, spriteframes);
+}
+
+void swf_FoldSprite(TAG * t)
+{
+ TAG*sprtag=t,*tmp;
+ U16 id,frames,tmpid;
+ if(t->id!=ST_DEFINESPRITE)
+ return;
+ if(!t->len) {
+ fprintf(stderr, "Error: Sprite has no ID!");
+ return;
+ }
+ if(t->len>4) {
+ /* sprite is already folded */
+ return;
+ }
+
+ t->pos = 0;
+ id = swf_GetU16(t);
+ //frames = swf_GetU16(t);
+ free(t->data);
+ t->len = t->pos = t->memsize = 0;
+ t->data = 0;
+
+ frames = 0;
+
+ do
+ {
+ if(t->id==ST_SHOWFRAME) frames++;
+ t = swf_NextTag(t);
+ } while(t&&t!=ST_END);
+
+ t = swf_NextTag(sprtag);
+ swf_SetU16(sprtag, id);
+ swf_SetU16(sprtag, frames);
+
+ do
+ {
+ tmpid= t->id;
+ if(t->len<0x3f) {
+ swf_SetU16(sprtag,t->len|(t->id<<6));
+ } else {
+ swf_SetU16(sprtag,0x3f|(t->id<<6));
+ swf_SetU32(sprtag,t->len);
+ }
+ if(t->len)
+ swf_SetBlock(sprtag,t->data, t->len);
+ tmp = t;
+ t = swf_NextTag(t);
+ swf_DeleteTag(tmp);
+ }
+ while (t&&(tmpid!=ST_END));
+
+// sprtag->next = t;
+// t->prev = sprtag;
+}
+
+void swf_FoldAll(SWF*swf)
+{
+ TAG*tag = swf->firstTag;
+ while(tag) {
+ if(tag->id == ST_DEFINESPRITE)
+ swf_FoldSprite(tag);
+ tag = swf_NextTag(tag);
+ }
+}
+
+void swf_UnFoldAll(SWF*swf)
+{
+ TAG*tag = swf->firstTag;
+ while(tag) {
+ TAG*next = swf_NextTag(tag);
+ if(tag->id == ST_DEFINESPRITE)
+ swf_UnFoldSprite(tag);
+ tag = next;
+ }
+}