X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fswfc.c;h=301f542a6f335640f411d6ad871c2cf6fc973aaf;hb=e3147ae362f22e9627c7eace0b33d01c09e30f25;hp=1a1afb4c71d5522eb63cb855bc95388c33127558;hpb=12c0a48dd16767c28e87d21b2265ba1de9837f60;p=swftools.git diff --git a/src/swfc.c b/src/swfc.c index 1a1afb4..301f542 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 @@ -727,11 +729,13 @@ 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(nr == 0 && currentframe == 0 && name) { tag = swf_InsertTag(tag, ST_FRAMELABEL); swf_SetString(tag, name); + swf_SetU8(tag, 1); //make this an anchor } if(cut) { @@ -979,7 +983,7 @@ void s_quicktime(char*name, char*url) incrementid(); } -void s_edittext(char*name, char*fontname, int size, int width, int height, char*text, RGBA*color, int maxlength, char*variable, int flags) +void s_edittext(char*name, char*fontname, int size, int width, int height, char*text, RGBA*color, int maxlength, char*variable, int flags, int align) { SWFFONT*font = 0; EditTextLayout layout; @@ -993,7 +997,7 @@ void s_edittext(char*name, char*fontname, int size, int width, int height, char* } tag = swf_InsertTag(tag, ST_DEFINEEDITTEXT); swf_SetU16(tag, id); - layout.align = 0; + layout.align = align; layout.leftmargin = 0; layout.rightmargin = 0; layout.indent = 0; @@ -1020,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); @@ -1048,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 */ @@ -1156,6 +1180,10 @@ void s_font(char*name, char*filename) font->id = id; tag = swf_InsertTag(tag, ST_DEFINEFONT2); swf_FontSetDefine2(tag, font); + tag = swf_InsertTag(tag, ST_EXPORTASSETS); + swf_SetU16(tag, 1); + swf_SetU16(tag, id); + swf_SetString(tag, name); incrementid(); if(dictionary_lookup(&fonts, name)) @@ -1174,16 +1202,15 @@ 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; + U16*samples = NULL; + unsigned numsamples; + unsigned blocksize = 1152; + int is_mp3 = 0; - if(!readWAV(filename, &wav)) { - warning("Couldn't read wav file \"%s\"", filename); - samples = 0; - numsamples = 0; - } else { + if(readWAV(filename, &wav)) { + int t; convertWAV2mono(&wav, &wav2, 44100); samples = (U16*)wav2.data; numsamples = wav2.size/2; @@ -1194,11 +1221,47 @@ 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) + { + // apply padding, so that block is a multiple of blocksize + int numblocks = (numsamples+blocksize-1)/blocksize; + int numsamples2; + U16* samples2; + numsamples2 = numblocks * blocksize; + samples2 = malloc(sizeof(U16)*numsamples2); + memcpy(samples2, samples, numsamples*sizeof(U16)); + memset(&samples2[numsamples], 0, sizeof(U16)*(numsamples2 - numsamples)); + numsamples = numsamples2; + samples = samples2; } 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; @@ -2708,7 +2771,7 @@ static int c_on_key(map_t*args) static int c_edittext(map_t*args) { - //"name font size width height text="" color=black maxlength=0 variable="" @password=0 @wordwrap=0 @multiline=0 @html=0 @noselect=0 @readonly=0"}, + //"name font size width height text="" color=black maxlength=0 variable="" @password=0 @wordwrap=0 @multiline=0 @html=0 @noselect=0 @readonly=0 @autosize=0"}, char*name = lu(args, "name"); char*font = lu(args, "font"); int size = (int)(1024*parsePxOrPercent(font, lu(args, "size"))); @@ -2725,6 +2788,9 @@ static int c_edittext(map_t*args) char*noselectstr = lu(args, "noselect"); char*readonlystr = lu(args, "readonly"); char*borderstr = lu(args, "border"); + char*autosizestr = lu(args, "autosize"); + char*alignstr = lu(args, "align"); + int align = -1; int flags = 0; if(!strcmp(passwordstr, "password")) flags |= ET_PASSWORD; @@ -2734,8 +2800,14 @@ static int c_edittext(map_t*args) if(!strcmp(htmlstr, "html")) flags |= ET_HTML; if(!strcmp(noselectstr, "noselect")) flags |= ET_NOSELECT; if(!strcmp(borderstr, "border")) flags |= ET_BORDER; - - s_edittext(name, font, size, width, height, text, &color, maxlength, variable, flags); + if(!strcmp(autosizestr, "autosize")) flags |= ET_AUTOSIZE; + if(!strcmp(alignstr, "left") || !*alignstr) align = ET_ALIGN_LEFT; + else if(!strcmp(alignstr, "right")) align = ET_ALIGN_RIGHT; + else if(!strcmp(alignstr, "center")) align = ET_ALIGN_CENTER; + else if(!strcmp(alignstr, "justify")) align = ET_ALIGN_JUSTIFY; + else syntaxerror("Unknown alignment: %s", alignstr); + + s_edittext(name, font, size, width, height, text, &color, maxlength, variable, flags, align); return 0; } @@ -2824,7 +2896,7 @@ static struct { {"egon", c_egon, "name vertices color=white line=1 @fill=none"}, {"text", c_text, "name text font size=100% color=white"}, - {"edittext", c_edittext, "name font= size=100% width height text="" color=white maxlength=0 variable="" @password=0 @wordwrap=0 @multiline=0 @html=0 @noselect=0 @readonly=0 @border=0"}, + {"edittext", c_edittext, "name font= size=100% width height text="" color=white maxlength=0 variable="" @password=0 @wordwrap=0 @multiline=0 @html=0 @noselect=0 @readonly=0 @border=0 @autosize=0 align="}, {"morphshape", c_morphshape, "name start end"}, {"button", c_button, "name"}, {"show", c_show, "name x=0 y=0 red=+0 green=+0 blue=+0 alpha=+0 luminance= scale= scalex= scaley= pivot= pin= shear= rotate= ratio= above= below= as="},