X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fswfextract.c;h=f66dd83ffae1660a6d5ef4d5f88a46455ff78872;hb=918a290574399a88456bbc70d7064c04ab8f6819;hp=a5794c65ae678c764fae96aca74c79bc0c2f8b89;hpb=32f13e61458ba5f8c29c0a06636a3cc14ee4cb95;p=swftools.git diff --git a/src/swfextract.c b/src/swfextract.c index a5794c6..f66dd83 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) { @@ -676,7 +685,7 @@ void handlejpeg(TAG*tag) } 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 +940,7 @@ void handlelossless(TAG*tag) } #endif -FILE*mp3file; +static FILE*mp3file=0; void handlesoundstream(TAG*tag) { char*filename = "output.mp3"; @@ -1110,8 +1119,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 +1183,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;