X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fswfc.c;h=131c794d6eccab29070eb4f46ed40400b18d5aee;hb=2c9f24cd50973dd2b69395fb284ca2e8981f93c2;hp=caa2a52cd732cfc0d8ffd44ee717b6da1e5e2e96;hpb=301540637a34d16cb61ef68208b3db160243a98c;p=swftools.git diff --git a/src/swfc.c b/src/swfc.c index caa2a52..131c794 100644 --- a/src/swfc.c +++ b/src/swfc.c @@ -32,8 +32,10 @@ #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 @@ -1022,12 +1024,7 @@ void s_image(char*name, char*type, char*filename, int quality) SRECT r; int imageID = id; int width, height; - if(type=="png") { - warning("image type \"png\" not supported yet!"); - s_box(name, 0, 0, black, 20, 0); - return; - } - if(type=="jpeg") { + if(!strcmp(type,"jpeg")) { #ifndef HAVE_LIBJPEG warning("no jpeg support compiled in"); s_box(name, 0, 0, black, 20, 0); @@ -1050,6 +1047,31 @@ void s_image(char*name, char*type, char*filename, int quality) s_addimage(name, id, tag, r); incrementid(); #endif + } else if(!strcmp(type,"png")) { + RGBA*data = 0; + swf_SetU16(tag, imageID); + + getPNG(filename, &width, &height, (unsigned char**)&data); + + if(!data) { + syntaxerror("Image \"%s\" not found, or contains errors", filename); + } + + /*tag = swf_AddImage(tag, imageID, data, width, height, quality)*/ + tag = swf_InsertTag(tag, ST_DEFINEBITSLOSSLESS); + swf_SetU16(tag, imageID); + swf_SetLosslessImage(tag, data, width, height); + + r.xmin = 0; + r.ymin = 0; + r.xmax = width*20; + r.ymax = height*20; + s_addimage(name, id, tag, r); + incrementid(); + } else { + warning("image type \"%s\" not supported yet!", type); + s_box(name, 0, 0, black, 20, 0); + return; } /* step 2: the character */ @@ -1180,18 +1202,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(filename, &wav)) { + int t; + wav_convert2mono(&wav, &wav2, 44100); samples = (U16*)wav2.data; numsamples = wav2.size/2; free(wav.data); @@ -1201,6 +1221,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) @@ -1219,7 +1249,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;