X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=src%2Fswfextract.c;h=3550731eb00e1ba0618073250867008ec9990f4d;hp=a5794c65ae678c764fae96aca74c79bc0c2f8b89;hb=70dd52c811db9f1a38a472a37135986accc4c06e;hpb=32f13e61458ba5f8c29c0a06636a3cc14ee4cb95 diff --git a/src/swfextract.c b/src/swfextract.c index a5794c6..3550731 100644 --- a/src/swfextract.c +++ b/src/swfextract.c @@ -114,6 +114,7 @@ int args_callback_option(char*name,char*val) fprintf(stderr, "Only one --jpegs argument is allowed. (Try to use a range, e.g. -j 1,2,3)\n"); exit(1); } + /* TODO: count number of IDs in val range */ numextracts++; extractjpegids = val; return 1; @@ -340,6 +341,8 @@ void extractTag(SWF*swf, char*filename) } if(srctag->id == ST_DEFINESPRITE) sprite = 1; + if(srctag->id == ST_JPEGTABLES) + copy = 1; if(swf_isDefiningTag(srctag)) { int id = swf_GetDefineID(srctag); if(used[id]) { @@ -590,14 +593,16 @@ void handlefont(SWF*swf, TAG*tag) swf_FontFree(f); } -U8*jpegtables = 0; -int jpegtablessize; +static char has_jpegtables=0; +static U8*jpegtables = 0; +static int jpegtablessize = 0; void handlejpegtables(TAG*tag) { if(tag->id == ST_JPEGTABLES) { jpegtables = tag->data; jpegtablessize = tag->len; + has_jpegtables = 1; } } @@ -615,7 +620,7 @@ int findjpegboundary(U8*data, int len) { int t; int pos=-1; - for(t=0;t bytes out, so that one stream remains */ - if(tag->id == ST_DEFINEBITSJPEG && tag->len>2 && jpegtables) { + if(tag->id == ST_DEFINEBITSJPEG && tag->len>2 && has_jpegtables) { fi = save_fopen(filename, "wb"); - fwrite(jpegtables, 1, jpegtablessize-2, fi); //don't write end tag (ff,d8) - fwrite(&tag->data[2+2], tag->len-2-2, 1, fi); //don't write start tag (ff,d9) + if(jpegtablessize>=2) { + fwrite(jpegtables, 1, jpegtablessize-2, fi); //don't write end tag (ff,d8) + fwrite(&tag->data[2+2], tag->len-2-2, 1, fi); //don't write start tag (ff,d9) + } else { + fwrite(tag->data+2, tag->len-2, 1, fi); + } fclose(fi); } else if(tag->id == ST_DEFINEBITSJPEG2 && tag->len>2) { @@ -666,17 +675,21 @@ void handlejpeg(TAG*tag) else if(tag->id == ST_DEFINEBITSJPEG3 && tag->len>6) { U32 end = GET32(&tag->data[2])+6; int pos = findjpegboundary(&tag->data[6], tag->len-6); - if(pos<0) - return; - pos+=6; - fi = save_fopen(filename, "wb"); - fwrite(&tag->data[6], pos-6, 1, fi); - fwrite(&tag->data[pos+4], end-(pos+4), 1, fi); - fclose(fi); + if(pos<0) { + fi = save_fopen(filename, "wb"); + fwrite(&tag->data[6], end-6, 1, fi); + fclose(fi); + } else { + pos+=6; + fi = save_fopen(filename, "wb"); + fwrite(&tag->data[6], pos-6, 1, fi); + fwrite(&tag->data[pos+4], end-(pos+4), 1, fi); + fclose(fi); + } } else { int id = GET16(tag->data); - fprintf(stderr, "Object %d is not a JPEG picture!\n",id); + fprintf(stderr, "Object %d is not a JPEG picture!\n",id, jpegtables); exit(1); } } @@ -931,7 +944,7 @@ void handlelossless(TAG*tag) } #endif -FILE*mp3file; +static FILE*mp3file=0; void handlesoundstream(TAG*tag) { char*filename = "output.mp3"; @@ -1110,8 +1123,9 @@ int main (int argc,char ** argv) handlesoundstream(tag); } - if(tag->id == ST_JPEGTABLES) + if(tag->id == ST_JPEGTABLES) { handlejpegtables(tag); + } if(swf_isDefiningTag(tag)) { int id = swf_GetDefineID(tag); @@ -1173,8 +1187,13 @@ int main (int argc,char ** argv) if (found) extractTag(&swf, destfilename); - if(mp3file) + if(mp3file) { fclose(mp3file); + } else { + if(extractmp3) { + msg(" Didn't find a soundstream in file"); + } + } swf_FreeTags(&swf); return 0;