X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=sidebyside;f=src%2Fswfc.c;h=db29f85aec0801076ef65389c85356c2aab669f4;hb=7edca02a3680420b351f19b1d26eaf7b9e730e4e;hp=009a21564ef70e0d4037b15d53df3146202deec2;hpb=15d5047042b1e32aaf85f565e8e77eb91128b757;p=swftools.git diff --git a/src/swfc.c b/src/swfc.c index 009a215..db29f85 100644 --- a/src/swfc.c +++ b/src/swfc.c @@ -32,8 +32,9 @@ #include "../lib/log.h" #include "../lib/args.h" #include "../lib/q.h" +#include "../lib/mp3.h" +#include "../lib/wav.h" #include "parser.h" -#include "wav.h" #include "../lib/png.h" //#define DEBUG @@ -714,7 +715,7 @@ int s_getframe() return currentframe+1; } -void s_frame(int nr, int cut, char*name) +void s_frame(int nr, int cut, char*name, char anchor) { int t; TAG*now = tag; @@ -728,13 +729,15 @@ void s_frame(int nr, int cut, char*name) if(t==nr-1 && name && *name) { tag = swf_InsertTag(tag, ST_FRAMELABEL); swf_SetString(tag, name); - swf_SetU8(tag, 1); //make this an anchor + if(anchor) + swf_SetU8(tag, 1); //make this an anchor } } - if(nr == 0 && currentframe == 0 && name) { + if(nr == 0 && currentframe == 0 && name && *name) { tag = swf_InsertTag(tag, ST_FRAMELABEL); swf_SetString(tag, name); - swf_SetU8(tag, 1); //make this an anchor + if(anchor) + swf_SetU8(tag, 1); //make this an anchor } if(cut) { @@ -1113,6 +1116,8 @@ void s_texture(char*name, char*object, int x, int y, float scalex, float scaley, parameters_t p; FILLSTYLE*fs = &texture->fs; + memset(&p, 0, sizeof(parameters_t)); + if(bitmap) { fs->type = FILL_TILED; fs->id_bitmap = bitmap->id; @@ -1201,18 +1206,16 @@ typedef struct _sound_t void s_sound(char*name, char*filename) { struct WAV wav, wav2; + struct MP3 mp3; sound_t* sound; - U16*samples; - int numsamples; - int t; - int blocksize = 1152; - - if(!readWAV(filename, &wav)) { - warning("Couldn't read wav file \"%s\"", filename); - samples = 0; - numsamples = 0; - } else { - convertWAV2mono(&wav, &wav2, 44100); + U16*samples = NULL; + unsigned numsamples; + unsigned blocksize = 1152; + int is_mp3 = 0; + + if(wav_read(&wav, filename)) { + int t; + wav_convert2mono(&wav, &wav2, 44100); samples = (U16*)wav2.data; numsamples = wav2.size/2; free(wav.data); @@ -1222,6 +1225,16 @@ void s_sound(char*name, char*filename) samples[t] = (samples[t]>>8)&0xff | (samples[t]<<8)&0xff00; } #endif + } else if(mp3_read(&mp3, filename)) { + fprintf(stderr, "\"%s\" seems to work as a MP3 file...\n", filename); + blocksize = 1; + is_mp3 = 1; + } + else + { + warning("Couldn't read WAV/MP3 file \"%s\"", filename); + samples = 0; + numsamples = 0; } if(numsamples%blocksize != 0) @@ -1240,7 +1253,19 @@ void s_sound(char*name, char*filename) tag = swf_InsertTag(tag, ST_DEFINESOUND); swf_SetU16(tag, id); //id - swf_SetSoundDefine(tag, samples, numsamples); + if(is_mp3) + { + swf_SetSoundDefineMP3( + tag, mp3.data, mp3.size, + mp3.SampRate, + mp3.Channels, + mp3.NumFrames); + mp3_clear(&mp3); + } + else + { + swf_SetSoundDefine(tag, samples, numsamples); + } sound = (sound_t*)malloc(sizeof(sound_t)); /* mem leak */ sound->tag = tag; @@ -1361,7 +1386,7 @@ int s_swf3action(char*name, char*action) ActionTAG* a = 0; instance_t* object = 0; if(name) - dictionary_lookup(&instances, name); + object = (instance_t*)dictionary_lookup(&instances, name); if(!object && name && *name) { /* we have a name, but couldn't find it. Abort. */ return 0; @@ -1778,8 +1803,10 @@ int parseTwip(char*str) int t; return sign*parseInt(str)*20; } else { - int l=strlen(++dot); + char* old = strdup(str); + int l=strlen(dot+1); char*s; + *dot++ = 0; for(s=str;s'9') syntaxerror("Not a coordinate: \"%s\"", str); @@ -1788,10 +1815,12 @@ int parseTwip(char*str) syntaxerror("Not a coordinate: \"%s\"", str); } if(l>2 || (l==2 && (dot[1]!='0' && dot[1]!='5'))) { - warning("precision loss: %s converted to twip: %s", str, dot); + dot[1] = ((dot[1]-0x30)/5)*5 + 0x30; dot[2] = 0; l=2; + warning("precision loss: %s converted to twip: %s.%s", old, str, dot); } + free(old); if(l==0) return sign*atoi(str)*20; if(l==1) @@ -2467,7 +2496,14 @@ static int c_frame(map_t*args) { char*framestr = lu(args, "n"); char*cutstr = lu(args, "cut"); + char*name = lu(args, "name"); + char*anchor = lu(args, "anchor"); + char buf[40]; + + if(!strcmp(anchor, "anchor") && !*name) + name = framestr; + int frame; int cut = 0; if(strcmp(cutstr, "no")) @@ -2484,7 +2520,7 @@ static int c_frame(map_t*args) && !(frame==1 && s_getframe()==frame)) // equality is o.k. for frame 0 syntaxerror("frame expression must be >%d (is:%s)", s_getframe(), framestr); } - s_frame(frame, cut, name); + s_frame(frame, cut, name, !strcmp(anchor, "anchor")); return 0; } static int c_primitive(map_t*args) @@ -2849,7 +2885,7 @@ static struct { char*arguments; } arguments[] = {{"flash", c_flash, "bbox=autocrop background=black version=6 fps=50 name= filename= @compress=default"}, - {"frame", c_frame, "n=1 name= @cut=no"}, + {"frame", c_frame, "n=1 name= @cut=no @anchor=no"}, // "import" type stuff {"swf", c_swf, "name filename"}, {"shape", c_swf, "name filename"},