X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fswfc.c;h=a34c3113ad6bb81050b5d7451ba0c224a81dbd8a;hb=d2aa0656488e174f69aa7e4fd0106648931533e4;hp=4313903139b06d08e79010770f41eab37b4e7f5a;hpb=78efc99ad38ff7d00da545c57449e164ac026d25;p=swftools.git diff --git a/src/swfc.c b/src/swfc.c index 4313903..a34c311 100644 --- a/src/swfc.c +++ b/src/swfc.c @@ -44,10 +44,12 @@ static char * outputname = "output.swf"; static int verbose = 2; static int optimize = 0; static int override_outputname = 0; +static int do_cgi = 0; static struct options_t options[] = { {"h", "help"}, {"V", "version"}, +{"C", "cgi"}, {"v", "verbose"}, {"o", "output"}, {0,0} @@ -68,6 +70,10 @@ int args_callback_option(char*name,char*val) optimize = 1; return 0; } + else if(!strcmp(name, "C")) { + do_cgi = 1; + return 0; + } else if(!strcmp(name, "v")) { verbose ++; return 0; @@ -89,6 +95,7 @@ void args_callback_usage(char *name) printf("\n"); printf("-h , --help Print short help message and exit\n"); printf("-V , --version Print version info and exit\n"); + printf("-C , --cgi Output to stdout (for use in CGI environments)\n"); printf("-v , --verbose Increase verbosity. \n"); printf("-o , --output Set output file to .\n"); printf("\n"); @@ -119,7 +126,7 @@ static void syntaxerror(char*format, ...) va_start(arglist, format); vsprintf(buf, format, arglist); va_end(arglist); - printf("\"%s\", line %d column %d: error- %s\n", filename, line, column, buf); + fprintf(stderr, "\"%s\", line %d column %d: error- %s\n", filename, line, column, buf); exit(1); } @@ -130,7 +137,7 @@ static void warning(char*format, ...) va_start(arglist, format); vsprintf(buf, format, arglist); va_end(arglist); - printf("\"%s\", line %d column %d: warning- %s\n", filename, line, column, buf); + fprintf(stderr, "\"%s\", line %d column %d: warning- %s\n", filename, line, column, buf); } static void readToken() @@ -215,6 +222,7 @@ typedef struct _parameters { float shear; SPOINT pivot; SPOINT pin; + U8 blendmode; //not interpolated } parameters_t; typedef struct _character { @@ -338,6 +346,7 @@ static void parameters_clear(parameters_t*p) p->pivot.x = 0; p->pivot.y = 0; p->rotate = 0; p->shear = 0; + p->blendmode = 0; swf_GetCXForm(0, &p->cxform, 1); } @@ -673,11 +682,16 @@ static void s_endSWF() warning("Empty bounding box for movie"); } - fi = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644); + if(do_cgi) + fi = fileno(stdout); + else + fi = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644); if(fi<0) { syntaxerror("couldn't create output file %s", filename); } - if(swf->compressed) + if(do_cgi) + {if(swf_WriteCGI(swf)<0) syntaxerror("WriteCGI() failed.\n");} + else if(swf->compressed) {if(swf_WriteSWC(fi, swf)<0) syntaxerror("WriteSWC() failed.\n");} else {if(swf_WriteSWF(fi, swf)<0) syntaxerror("WriteSWF() failed.\n");} @@ -715,7 +729,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; @@ -729,13 +743,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) { @@ -1025,7 +1041,7 @@ void s_image(char*name, char*type, char*filename, int quality) int imageID = id; int width, height; if(!strcmp(type,"jpeg")) { -#ifndef HAVE_LIBJPEG +#ifndef HAVE_JPEGLIB warning("no jpeg support compiled in"); s_box(name, 0, 0, black, 20, 0); return; @@ -1114,6 +1130,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; @@ -1262,7 +1280,15 @@ void s_sound(char*name, char*filename) { swf_SetSoundDefine(tag, samples, numsamples); } - + + tag = swf_InsertTag(tag, ST_NAMECHARACTER); + swf_SetU16(tag, id); + swf_SetString(tag, name); + tag = swf_InsertTag(tag, ST_EXPORTASSETS); + swf_SetU16(tag, 1); + swf_SetU16(tag, id); + swf_SetString(tag, name); + sound = (sound_t*)malloc(sizeof(sound_t)); /* mem leak */ sound->tag = tag; sound->id = id; @@ -1382,7 +1408,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; @@ -1498,13 +1524,17 @@ void s_includeswf(char*name, char*filename) level--; if(!level) break; - /* We simply dump all tags right after the sprite - header, relying on the fact that swf_OptimizeTagOrder() will - sort things out for us later. - We also rely on the fact that the imported SWF is well-formed. - */ - tag = swf_InsertTag(tag, ftag->id); - swf_SetBlock(tag, ftag->data, ftag->len); + + if(ftag->id != ST_SETBACKGROUNDCOLOR) { + /* We simply dump all tags right after the sprite + header, relying on the fact that swf_OptimizeTagOrder() will + sort things out for us later. + We also rely on the fact that the imported SWF is well-formed. + */ + tag = swf_InsertTag(tag, ftag->id); + swf_SetBlock(tag, ftag->data, ftag->len); + } + ftag = ftag->next; } if(!ftag) @@ -1586,9 +1616,15 @@ void s_put(char*instance, char*character, parameters_t p) i = s_addinstance(instance, c, currentdepth); i->parameters = p; m = s_instancepos(i->character->size, &p); - - tag = swf_InsertTag(tag, ST_PLACEOBJECT2); - swf_ObjectPlace(tag, c->id, currentdepth, &m, &p.cxform, instance); + + if(p.blendmode) { + tag = swf_InsertTag(tag, ST_PLACEOBJECT3); + swf_ObjectPlaceBlend(tag, c->id, currentdepth, &m, &p.cxform, instance, p.blendmode); + } else { + tag = swf_InsertTag(tag, ST_PLACEOBJECT2); + swf_ObjectPlace(tag, c->id, currentdepth, &m, &p.cxform, instance); + } + i->lastTag = tag; i->lastFrame = currentframe; currentdepth++; @@ -1729,7 +1765,7 @@ typedef int command_func_t(map_t*args); SRECT parseBox(char*str) { - SRECT r; + SRECT r = {0,0,0,0}; float xmin, xmax, ymin, ymax; char*x = strchr(str, 'x'); char*d1=0,*d2=0; @@ -1799,8 +1835,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); @@ -1809,10 +1847,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) @@ -2260,6 +2300,8 @@ static int c_placement(map_t*args, int type) char* astr = lu(args, "alpha"); char* pinstr = lu(args, "pin"); char* as = map_lookup(args, "as"); + char* blendmode = lu(args, "blend"); + U8 blend; MULADD r,g,b,a; float oldwidth; float oldheight; @@ -2413,6 +2455,21 @@ static int c_placement(map_t*args, int type) p.cxform.a0 = a.mul;p.cxform.a1 = a.add; } + if(blendmode[0]) { + int t; + blend = 255; + for(t=0;blendModeNames[t];t++) { + if(!strcmp(blendModeNames[t], blendmode)) { + blend = t; + break; + } + } + if(blend == 255) { + syntaxerror("unknown blend mode: '%s'", blendmode); + } + p.blendmode = blend; + } + if(type == 0) s_put(instance, character, p); else if(type == 1) @@ -2488,7 +2545,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")) @@ -2505,7 +2569,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) @@ -2870,7 +2934,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"}, @@ -2899,7 +2963,7 @@ static struct { {"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="}, + {"show", c_show, "name x=0 y=0 red=+0 green=+0 blue=+0 alpha=+0 luminance= scale= scalex= scaley= blend= pivot= pin= shear= rotate= ratio= above= below= as="}, {"on_press", c_on_press, "position=inside"}, {"on_release", c_on_release, "position=anywhere"}, {"on_move_in", c_on_move_in, "state=not_pressed"}, @@ -2913,12 +2977,12 @@ static struct { {"previousframe", c_previousframe, "name"}, // object placement tags - {"put", c_put, " x=0 y=0 red=+0 green=+0 blue=+0 alpha=+0 luminance= scale= scalex= scaley= pivot= pin= shear= rotate= ratio= above= below="}, - {"startclip", c_startclip, " x=0 y=0 red=+0 green=+0 blue=+0 alpha=+0 luminance= scale= scalex= scaley= pivot= pin= shear= rotate= ratio= above= below="}, - {"change", c_change, "name x= y= red= green= blue= alpha= luminance= scale= scalex= scaley= pivot= pin= shear= rotate= ratio= above= below="}, - {"arcchange", c_arcchange, "name pivot= angle= red= green= blue= alpha= luminance= scale= scalex= scaley= pivot= pin= shear= rotate= ratio= above= below="}, - {"qchange", c_qchange, "name x= y= red= green= blue= alpha= luminance= scale= scalex= scaley= pivot= pin= shear= rotate= ratio= above= below="}, - {"jump", c_jump, "name x= y= red= green= blue= alpha= luminance= scale= scalex= scaley= pivot= pin= shear= rotate= ratio= above= below="}, + {"put", c_put, " x=0 y=0 red=+0 green=+0 blue=+0 alpha=+0 luminance= scale= scalex= scaley= blend= pivot= pin= shear= rotate= ratio= above= below="}, + {"startclip", c_startclip, " x=0 y=0 red=+0 green=+0 blue=+0 alpha=+0 luminance= scale= scalex= scaley= blend= pivot= pin= shear= rotate= ratio= above= below="}, + {"change", c_change, "name x= y= red= green= blue= alpha= luminance= scale= scalex= scaley= blend= pivot= pin= shear= rotate= ratio= above= below="}, + {"arcchange", c_arcchange, "name pivot= angle= red= green= blue= alpha= luminance= scale= scalex= scaley= blend= pivot= pin= shear= rotate= ratio= above= below="}, + {"qchange", c_qchange, "name x= y= red= green= blue= alpha= luminance= scale= scalex= scaley= blend= pivot= pin= shear= rotate= ratio= above= below="}, + {"jump", c_jump, "name x= y= red= green= blue= alpha= luminance= scale= scalex= scaley= blend= pivot= pin= shear= rotate= ratio= above= below="}, {"del", c_del, "name"}, // virtual object placement {"texture", c_texture, " x=0 y=0 width= height= scale= scalex= scaley= r= shear= rotate="}, @@ -3169,7 +3233,7 @@ int main (int argc,char ** argv) file = generateTokens(filename); if(!file) { - printf("parser returned error.\n"); + fprintf(stderr, "parser returned error.\n"); return 1; } pos=0;