X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fcombine.c;h=4847a583e5c3046c55df2b3bbc9d3f09b51cacce;hb=22a49dfc00af6fc1b43057b44790f2087a09b6f2;hp=a6a695a4ecfb40d3feb80c5a842a9b788251ccfc;hpb=caacc3b7bc77a04e35891f73908f9c0a7c8c64fa;p=swftools.git diff --git a/src/combine.c b/src/combine.c index a6a695a..4847a58 100644 --- a/src/combine.c +++ b/src/combine.c @@ -12,6 +12,7 @@ #include #include #include "../lib/log.h" +#include "../lib/rfxswf.h" #include "./flash.h" #include "./reloc.h" #include "./settings.h" @@ -57,17 +58,56 @@ void changedepth(struct swf_tag*tag, int add) { /* fucking big endian byte order */ if(tag->id == TAGID_PLACEOBJECT) - (*(u16*)&tag->data[2]) = - SWAP16(SWAP16(*(u16*)&tag->data[2]) + add); + PUT16(&tag->data[2],GET16(&tag->data[2])+add); if(tag->id == TAGID_PLACEOBJECT2) - (*(u16*)&tag->data[1]) = - SWAP16(SWAP16(*(u16*)&tag->data[1]) + add); + PUT16(&tag->data[1],GET16(&tag->data[1])+add); if(tag->id == TAGID_REMOVEOBJECT) - (*(u16*)&tag->data[2]) = - SWAP16(SWAP16(*(u16*)&tag->data[2]) + add); + PUT16(&tag->data[2],GET16(&tag->data[2])+add); if(tag->id == TAGID_REMOVEOBJECT2) - (*(u16*)&tag->data[0]) = - SWAP16(SWAP16(*(u16*)&tag->data[0]) + add); + PUT16(&tag->data[0],GET16(&tag->data[0])+add); +} + +void jpeg_assert() +{ + /* TODO: if there's a jpegtable found, store it + and handle it together with the flash file + headers */ + /* check that master and slave don't have both + jpegtables (which would be fatal) */ + int pos; + int mpos=-1, spos=-1; + pos = 0; + while(master.tags[pos].id != 0) + { + if(master.tags[pos].id == TAGID_JPEGTABLES) + mpos = pos; + pos++; + } + pos = 0; + while(master.tags[pos].id != 0) + { + if(slave.tags[pos].id == TAGID_JPEGTABLES) + spos = pos; + pos++; + } + if(spos>=0 && mpos>=0) + { + if(slave.tags[pos].length == + master.tags[pos].length && + !memcmp(slave.tags[pos].data, master.tags[pos].data, + master.tags[pos].length)) + { + // ok, both have jpegtables, but they're identical. + // delete one and don't make an error + for(;spos=0 && mpos>=0) { + logf(" Master and slave have incompatible JPEGTABLES."); + } } /* applies the config move and scale parameters to @@ -165,9 +205,9 @@ void write_sprite_defines(struct writer_t*w) break; } case TAGID_JPEGTABLES: - /* according to the flash specs, there may only - be one JPEGTABLES tag per swf. This is maybe - a big FIXME */ + /* if we get here, jpeg_assert has already run, + ensuring this is the only one of it's kind, + so we may safely write it out */ writer_write(w, tag->fulldata, tag->fulllength); break; case TAGID_EXPORTASSETS: @@ -209,9 +249,9 @@ void write_sprite(struct writer_t*w, int spriteid, int replaceddefine) startpos = (u8*)writer_getpos(w); logf (" sprite id is %d", spriteid); - tmp = spriteid; + tmp = SWAP16(spriteid); writer_write(w, &tmp, 2); - tmp = slave.header.count; + tmp = SWAP16(slave.header.count); writer_write(w, &tmp, 2); @@ -261,8 +301,8 @@ void write_sprite(struct writer_t*w, int spriteid, int replaceddefine) } while(slave.tags[pos++].id != TAGID_END); - *tagidpos = SWAP32((u8*)writer_getpos(w) - startpos); // set length of sprite (in header) - logf(" sprite length is %d",SWAP32(*tagidpos)); + PUT32(tagidpos, (u8*)writer_getpos(w) - startpos); // set length of sprite (in header) + logf(" sprite length is %d",GET32(tagidpos)); } static char tag_ok_for_slave(int id) @@ -309,7 +349,7 @@ void write_master(struct writer_t*w, int spriteid, int replaceddefine, int flags { if(config.overlay) { - *(u16*)master.tags[pos].data = SWAP16(replaceddefine); + PUT16(master.tags[pos].data, replaceddefine); writer_write(w, master.tags[pos].fulldata, master.tags[pos].fulllength); } else { /* don't write this tag */ @@ -344,10 +384,10 @@ void write_master(struct writer_t*w, int spriteid, int replaceddefine, int flags if(config.clip) { logf(" Can't combine --clip and --frame"); } - *(u16*)&data[0] = SWAP16((u16)(TAGID_PLACEOBJECT2<<6) + 5); - *(u8*)&data[2]= SWAP16(2); //flags: id - *(u16*)&data[3]= SWAP16(depth); // depth - *(u16*)&data[5]= SWAP16(id); + PUT16(&data[0], (u16)(TAGID_PLACEOBJECT2<<6) + 5); + *(u8*)&data[2]= 2; //flags: id + PUT16(&data[3], depth); + PUT16(&data[5], id); write_sprite_defines(w); write_sprite(w, id, -1); writer_write(w,data,7); @@ -456,6 +496,7 @@ uchar * catcombine(uchar*masterdata, int masterlength, char*_slavename, uchar*sl swf_relocate (slavedata, slavelength, masterids); read_swf(&slave, slavedata, slavelength); + jpeg_assert(); writer_write(&w, "FWS",3); headlength = (u32*)(writer_getpos(&w) + 1); @@ -509,8 +550,8 @@ uchar * catcombine(uchar*masterdata, int masterlength, char*_slavename, uchar*sl { char data[16]; int len; - *(u16*)(&data[0]) = SWAP16((TAGID_REMOVEOBJECT2<<6) + 2); - *(u16*)(&data[2]) = SWAP16(t); + PUT16(&data[0], (TAGID_REMOVEOBJECT2<<6) + 2); + PUT16(&data[2], t); writer_write(&w, data, 4); } free(depths); @@ -525,7 +566,7 @@ uchar * catcombine(uchar*masterdata, int masterlength, char*_slavename, uchar*sl tmp32 = (u8*)writer_getpos(&w) - (u8*)newdata; //length *newlength = tmp32; - *headlength = SWAP32(tmp32); // set the header to the correct length + PUT32(headlength, tmp32); // set the header to the correct length return newdata; //length } @@ -602,8 +643,8 @@ uchar * normalcombine(uchar*masterdata, int masterlength, char*_slavename, uchar } swf_relocate (slavedata, slavelength, masterids); - read_swf(&slave, slavedata, slavelength); + jpeg_assert(); if (config.overlay) replaceddefine = get_free_id(); @@ -633,7 +674,7 @@ uchar * normalcombine(uchar*masterdata, int masterlength, char*_slavename, uchar tmp32 = (u8*)writer_getpos(&w) - (u8*)newdata; //length *newlength = tmp32; - *headlength = SWAP32(tmp32); // set the header to the correct length + PUT32(headlength, tmp32); return newdata; //length } @@ -660,8 +701,8 @@ uchar * combine(uchar*masterdata, int masterlength, char*_slavename, uchar*slave logf(" move x (%d)", config.movex); logf(" move y (%d)", config.movey); - logf(" scale x (%d)", config.scalex); - logf(" scale y (%d)", config.scaley); + logf(" scale x (%f)", config.scalex); + logf(" scale y (%f)", config.scaley); logf(" is frame (%d)", config.isframe); memset(masterids, -1, sizeof(masterids));