X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswftools.c;h=5526d31f9301df5d3e9dea34b4a777757302194e;hb=7aa6239f42b65e0cd200e251fc2c59037589e7a0;hp=e92b44f0c7b7ef65b395c670cb617ffa1870b200;hpb=c26001dfc8c4f363c9f2ef1a6ba9d50cde7a235c;p=swftools.git diff --git a/lib/modules/swftools.c b/lib/modules/swftools.c index e92b44f..5526d31 100644 --- a/lib/modules/swftools.c +++ b/lib/modules/swftools.c @@ -136,6 +136,7 @@ SRECT swf_GetDefineBBox(TAG * t) U32 oldTagPos; U16 id = 0; SRECT b1,b2; + memset(&b1, 0, sizeof(b1)); oldTagPos = swf_GetTagPos(t); swf_SetTagPos(t,0); @@ -560,7 +561,7 @@ void enumerateUsedIDs(TAG * tag, int base, void (*callback)(TAG*, int, void*), v if(id == ST_END) break; tag2->len = tag2->memsize = len; - tag2->data = malloc(len); + tag2->data = rfx_alloc(len); memcpy(tag2->data, &tag->data[tag->pos], len); /* I never saw recursive sprites, but they are (theoretically) possible, so better add base here again */ @@ -844,17 +845,19 @@ void swf_Relocate (SWF*swf, char*bitmap) } num = swf_GetNumUsedIDs(tag); - ptr = malloc(sizeof(int)*num); - swf_GetUsedIDs(tag, ptr); - - for(t=0;tdata[ptr[t]]); - if(slaveids[id]<0) { - fprintf(stderr, "swf_Relocate: Mapping id never encountered before: %d\n", id); - return ; + if(num) { + ptr = rfx_alloc(sizeof(int)*num); + swf_GetUsedIDs(tag, ptr); + + for(t=0;tdata[ptr[t]]); + if(slaveids[id]<0) { + fprintf(stderr, "swf_Relocate: Mapping id never encountered before: %d\n", id); + return ; + } + id = slaveids[id]; + PUT16(&tag->data[ptr[t]], id); } - id = slaveids[id]; - PUT16(&tag->data[ptr[t]], id); } tag=tag->next; } @@ -891,6 +894,26 @@ void swf_RelocateDepth(SWF*swf, char*bitmap) } } +U8 swf_isShapeTag(TAG*tag) +{ + if(tag->id == ST_DEFINESHAPE || + tag->id == ST_DEFINESHAPE2 || + tag->id == ST_DEFINESHAPE3) + return 1; + return 0; +} + +U8 swf_isImageTag(TAG*tag) +{ + if(tag->id == ST_DEFINEBITSJPEG || + tag->id == ST_DEFINEBITSJPEG2 || + tag->id == ST_DEFINEBITSJPEG3 || + tag->id == ST_DEFINEBITSLOSSLESS || + tag->id == ST_DEFINEBITSLOSSLESS2) + return 1; + return 0; +} + TAG* swf_Concatenate (TAG*list1,TAG*list2) { TAG*tag=0,*lasttag=0; @@ -944,20 +967,17 @@ static int tagHash(TAG*tag) a >>= 8; a += tag->data[t]*0xefbc35a5*b*(t+1); } - return a; + return a&0x7fffffff; //always return positive number } void swf_Optimize(SWF*swf) { const int hash_size = 131072; - char* dontremap = malloc(sizeof(char)*65536); - U16* remap = malloc(sizeof(U16)*65536); - TAG* id2tag = malloc(sizeof(TAG*)*65536); - TAG** hashmap = malloc(sizeof(TAG*)*hash_size); + char* dontremap = rfx_calloc(sizeof(char)*65536); + U16* remap = rfx_alloc(sizeof(U16)*65536); + TAG* id2tag = rfx_calloc(sizeof(TAG*)*65536); + TAG** hashmap = rfx_calloc(sizeof(TAG*)*hash_size); TAG* tag; - memset(dontremap, 0, sizeof(char)*65536); - memset(hashmap, 0, sizeof(TAG*)*hash_size); - memset(id2tag, 0, sizeof(TAG*)*65536); int t; for(t=0;t<65536;t++) { remap[t] = t; @@ -972,8 +992,9 @@ void swf_Optimize(SWF*swf) FIXME: a better way would be to compare the helper tags, too. */ - if(swf_isPseudoDefiningTag(tag)) { - //dontremap[swf_GetDefineID(tag)] = 1; //FIXME + if(swf_isPseudoDefiningTag(tag) && + tag->id != ST_NAMECHARACTER) { + dontremap[swf_GetDefineID(tag)] = 1; } tag=tag->next; } @@ -982,7 +1003,22 @@ void swf_Optimize(SWF*swf) int doremap=1; TAG*next = tag->next; - + + /* remap the tag */ + int num = swf_GetNumUsedIDs(tag); + int*positions = rfx_alloc(sizeof(int)*num); + int t; + swf_GetUsedIDs(tag, positions); + for(t=0;tdata[positions[t]]); + id = remap[id]; + PUT16(&tag->data[positions[t]], id); + } + rfx_free(positions); + tag = tag->next; + + /* now look for previous tags with the same + content */ if(swf_isDefiningTag(tag)) { TAG*tag2; int id = swf_GetDefineID(tag); @@ -1031,25 +1067,10 @@ void swf_Optimize(SWF*swf) } } - if(doremap) - { - int num = swf_GetNumUsedIDs(tag); - int*positions = malloc(sizeof(int)*num); - int t; - swf_GetUsedIDs(tag, positions); - for(t=0;tdata[positions[t]]); - id = remap[id]; - PUT16(&tag->data[positions[t]], id); - } - free(positions); - tag = tag->next; - } - tag = next; } - free(dontremap); - free(remap); - free(id2tag); - free(hashmap); + rfx_free(dontremap); + rfx_free(remap); + rfx_free(id2tag); + rfx_free(hashmap); }