X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fswfextract.c;h=80ca272096eeb0cae320791686011229b28c1f5d;hb=9a82ed9f9c7189bc59a84a1326dc4a7e9d06ee0e;hp=81b7a48132278bb191a4c6e5af66dfcf8faab0d3;hpb=aee9de2c6eb23628e54b6896f5b441d9b39317c1;p=swftools.git diff --git a/src/swfextract.c b/src/swfextract.c index 81b7a48..80ca272 100644 --- a/src/swfextract.c +++ b/src/swfextract.c @@ -285,7 +285,9 @@ void extractTag(SWF*swf, char*filename) changed = 0; for(t=0;t<65536;t++) { if(used[t] && !(used[t]&2)) { - if(tags[t]->id==ST_DEFINESPRITE) { + if(tags[t]==0) { + msg(" ID %d is referenced, but never defined.", t); + } else if(tags[t]->id==ST_DEFINESPRITE) { TAG*tag = tags[t]; while(tag->id != ST_END) { @@ -591,7 +593,7 @@ static void make_crc32_table(void) crc32_table[t] = c; } } -static void png_write_byte(FILE*fi, U8 byte) +static inline void png_write_byte(FILE*fi, U8 byte) { fwrite(&byte,1,1,fi); mycrc32 = crc32_table[(mycrc32 ^ byte) & 0xff] ^ (mycrc32 >> 8); @@ -736,8 +738,10 @@ void handlelossless(TAG*tag) png_write_byte(fi,8); if(format == 3) png_write_byte(fi,3); //indexed - else if(format == 5) + else if(format == 5 && alpha==0) png_write_byte(fi,2); //rgb + else if(format == 5 && alpha==1) + png_write_byte(fi,6); //rgba else return; png_write_byte(fi,0); //compression mode @@ -747,6 +751,7 @@ void handlelossless(TAG*tag) if(format == 3) { png_start_chunk(fi, "PLTE", 768); + for(t=0;t<256;t++) { png_write_byte(fi,palette[t].r); png_write_byte(fi,palette[t].g); @@ -764,12 +769,22 @@ void handlelossless(TAG*tag) { data3[pos2++]=0; //filter type if(bpp==32) { - // 32 bit to 24 bit "conversion" - for(x=0;x>4; + rate = (flags>>2)&3; + bits = flags&2?16:8; + stereo = flags&1; + + samples = swf_GetU32(tag); + if(format == 2) { // mp3 + swf_GetU16(tag); //numsamples_seek + extension = "mp3"; + } else if(format == 0) { // raw + printf("Sound is RAW, format: %s samples/sec, %d bit, %s\n", rates[rate], bits, stereo?"stereo":"mono"); + // TODO: convert to WAV + extension = "raw"; + } else if(format == 1) { // adpcm + printf("Sound is ADPCM, format: %s samples/sec, %d bit, %s\n", rates[rate], bits, stereo?"stereo":"mono"); + extension = "adpcm"; + } + sprintf(buf, "sound%d.%s", id, extension); if(numextracts==1) { filename = destfilename; - if(!strcmp(filename,"output.swf")) - filename = "output.mp3"; - } - flags = swf_GetU8(tag); - if((flags>>4)!=2) { - printf("Sorry, can only extract MP3 sounds. Sound %d is ADPCM or RAW.\n", id); - /* not mp3 */ - return; + if(!strcmp(filename,"output.swf")) { + sprintf(buf, "output.%s", extension); + filename = buf; + } } - samples = swf_GetU32(tag); - - swf_GetU16(tag); //(only for mp3) numsamples_seek - fi = save_fopen(filename, "wb"); fwrite(&tag->data[tag->pos], tag->len - tag->pos, 1, fi); fclose(fi);