From: kramm Date: Sat, 16 Feb 2002 17:44:54 +0000 (+0000) Subject: Added sprite folding X-Git-Tag: release-0-2-3~17 X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;h=fcb4a9475268e19036bca32bec316d3d5402dc9a;p=swftools.git Added sprite folding --- diff --git a/lib/rfxswf.c b/lib/rfxswf.c index f560f95..9a568fd 100644 --- a/lib/rfxswf.c +++ b/lib/rfxswf.c @@ -668,6 +668,9 @@ int swf_WriteTag(int handle,TAG * t) int RFXSWF_DefineSprite_GetRealSize(TAG * t) // Sprite Handling: Helper function to pack DefineSprite-Tag { U32 len = t->len; + if(len>4) { // folded sprite + return t->len; + } do { t = swf_NextTag(t); if (t->id!=ST_DEFINESPRITE) len += RFXSWF_WriteTag(-1,t); @@ -676,6 +679,67 @@ int RFXSWF_DefineSprite_GetRealSize(TAG * t) return len; } +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; + } + + 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); + } +} + #define swf_ReadTag(a,b) RFXSWF_ReadTag(a,b) #define swf_WriteTag(a,b) RFXSWF_WriteTag(a,b) diff --git a/lib/rfxswf.h b/lib/rfxswf.h index 4ad76cb..9b775f9 100644 --- a/lib/rfxswf.h +++ b/lib/rfxswf.h @@ -154,6 +154,11 @@ void swf_FreeTags(SWF * swf); // Frees all malloc'ed memory for sw // for streaming: int swf_WriteHeader(int handle,SWF * swf); // Writes Header of swf to file int swf_WriteTag(int handle,TAG * tag); // Writes TAG to file + +// folding/unfolding: + +void swf_FoldAll(SWF*swf); +void swf_FoldSprite(TAG*tag); TAG * swf_InsertTag(TAG * after,U16 id); // updates frames, if necessary int swf_DeleteTag(TAG * t);