X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswftools.c;h=0a5564530dd1fec9e9418165a804098fedeac690;hb=56d7005a7ccc3d41c333a0c508a9aef43bc02522;hp=1b01357d425b4b34934f2d5d3fa4a6a1b6ff6344;hpb=6edd030417e792d2325d5d6b89a6495ab8798cba;p=swftools.git diff --git a/lib/modules/swftools.c b/lib/modules/swftools.c index 1b01357..0a55645 100644 --- a/lib/modules/swftools.c +++ b/lib/modules/swftools.c @@ -23,12 +23,14 @@ // Matrix & Math tools for SWF files +#include "../rfxswf.h" + #define S64 long long SFIXED RFXSWF_SP(SFIXED a1,SFIXED a2,SFIXED b1,SFIXED b2) { S64 a = ((S64)a1*(S64)b1+(S64)a2*(S64)b2)>>16; SFIXED result = (SFIXED)(a); if(a!=result) - fprintf(stderr, "Warning: overflow in matrix multiplication"); + fprintf(stderr, "Warning: overflow in matrix multiplication\n"); return result; } SFIXED RFXSWF_QFIX(int zaehler,int nenner) // bildet Quotient von zwei INTs in SFIXED @@ -121,6 +123,7 @@ U16 swf_GetDefineID(TAG * t) case ST_DEFINEFONTALIGNZONES: //pseudodefine case ST_DEFINEFONTNAME: //pseudodefine case ST_DEFINETEXT: + case ST_DEFINEBINARY: case ST_DEFINETEXT2: case ST_DEFINESOUND: case ST_DEFINESPRITE: @@ -633,6 +636,10 @@ void enumerateUsedIDs(TAG * tag, int base, void (*callback)(TAG*, int, void*), v } } break; + case ST_DOABC: + case ST_RAWABC: + break; + case ST_FREECHARACTER: /* unusual tags, which all start with an ID */ case ST_NAMECHARACTER: case ST_DEFINEBINARY: @@ -684,7 +691,7 @@ void enumerateUsedIDs(TAG * tag, int base, void (*callback)(TAG*, int, void*), v /* I never saw recursive sprites, but they are (theoretically) possible, so better add base here again */ enumerateUsedIDs(tag2, tag->pos + base, callback, callback_data); - swf_DeleteTag(tag2); + swf_DeleteTag(0, tag2); swf_GetBlock(tag, NULL, len); } } @@ -959,12 +966,13 @@ void swf_GetUsedIDs(TAG * t, int * positions) enumerateUsedIDs(t, 0, callbackFillin, &ptr); } -void swf_Relocate (SWF*swf, char*bitmap) +char swf_Relocate (SWF*swf, char*bitmap) { TAG*tag; int slaveids[65536]; memset(slaveids, -1, sizeof(slaveids)); tag = swf->firstTag; + char ok = 1; while(tag) { int num; @@ -980,8 +988,7 @@ void swf_Relocate (SWF*swf, char*bitmap) if(!bitmap[id]) { //free newid = id; - } - else { + } else { newid = 0; for (t=1;t<65536;t++) { @@ -991,6 +998,10 @@ void swf_Relocate (SWF*swf, char*bitmap) break; } } + if(t==65536) { + fprintf(stderr, "swf_Relocate: Couldn't relocate: Out of IDs\n"); + return 0; + } } bitmap[newid] = 1; slaveids[id] = newid; @@ -1008,14 +1019,17 @@ void swf_Relocate (SWF*swf, char*bitmap) if(slaveids[id]<0) { fprintf(stderr, "swf_Relocate: Mapping id (%d) never encountered before in %s\n", id, swf_TagGetName(tag)); + ok = 0; } else { id = slaveids[id]; PUT16(&tag->data[ptr[t]], id); } } + free(ptr); } tag=tag->next; } + return ok; } /* untested */ @@ -1044,6 +1058,7 @@ void swf_Relocate2(SWF*swf, int*id2id) PUT16(&tag->data[ptr[t]], id); } } + free(ptr); } } } @@ -1266,9 +1281,7 @@ void swf_Optimize(SWF*swf) /* we found two identical tags- remap one of them */ remap[id] = swf_GetDefineID(tag2); - swf_DeleteTag(tag); - if(tag == swf->firstTag) - swf->firstTag = next; + swf_DeleteTag(swf, tag); } } else if(swf_isPseudoDefiningTag(tag)) { int id = swf_GetDefineID(tag); @@ -1276,9 +1289,7 @@ void swf_Optimize(SWF*swf) /* if this tag was remapped, we don't need the helper tag anymore. Discard it. */ - swf_DeleteTag(tag); - if(tag == swf->firstTag) - swf->firstTag = next; + swf_DeleteTag(swf, tag); } }